aboutsummaryrefslogtreecommitdiffstats
path: root/vnet
diff options
context:
space:
mode:
authorDave Wallace <dwallacelf@gmail.com>2015-12-15 13:22:37 +0000
committerGerrit Code Review <gerrit@projectrotterdam.info>2015-12-15 13:22:37 +0000
commit317be0349275f1f461028853d936670729591796 (patch)
tree2423d844a2f9ed9176f54ce5d07a368e248e9e6f /vnet
parentec65a1afd3f118849a7629d99ab2a1dcd2dda341 (diff)
parentd2dc3df90d20419dfaee03f3096ed18d20fa391a (diff)
Merge "replacing all vec_sort() invocations to vec_sort_with_function()"
Diffstat (limited to 'vnet')
-rw-r--r--vnet/vnet/config.c11
-rw-r--r--vnet/vnet/ip/lookup.c27
-rw-r--r--vnet/vnet/mpls-gre/mpls.c34
3 files changed, 61 insertions, 11 deletions
diff --git a/vnet/vnet/config.c b/vnet/vnet/config.c
index 74c4caa8..9f98778f 100644
--- a/vnet/vnet/config.c
+++ b/vnet/vnet/config.c
@@ -217,6 +217,15 @@ remove_reference (vnet_config_main_t * cm, vnet_config_t * c)
}
}
+static int
+feature_cmp (void * a1, void * a2)
+{
+ vnet_config_feature_t * f1 = a1;
+ vnet_config_feature_t * f2 = a2;
+
+ return (int) f1->feature_index - f2->feature_index;
+}
+
always_inline u32 *
vnet_get_config_heap (vnet_config_main_t * cm, u32 ci)
{ return heap_elt_at_index (cm->config_string_heap, ci); }
@@ -259,7 +268,7 @@ u32 vnet_config_add_feature (vlib_main_t * vm,
/* Sort (prioritize) features. */
if (vec_len (new_features) > 1)
- vec_sort (new_features, f1, f2, (int) f1->feature_index - f2->feature_index);
+ vec_sort_with_function (new_features, feature_cmp);
if (old)
remove_reference (cm, old);
diff --git a/vnet/vnet/ip/lookup.c b/vnet/vnet/ip/lookup.c
index 80f0a33e..9c125c2e 100644
--- a/vnet/vnet/ip/lookup.c
+++ b/vnet/vnet/ip/lookup.c
@@ -1814,6 +1814,16 @@ typedef CLIB_PACKED (struct {
u32 index : 26;
}) ip4_route_t;
+static int
+ip4_route_cmp (void * a1, void * a2)
+{
+ ip4_route_t * r1 = a1;
+ ip4_route_t * r2 = a2;
+
+ int cmp = ip4_address_compare (&r1->address, &r2->address);
+ return cmp ? cmp : ((int) r1->address_length - (int) r2->address_length);
+}
+
static clib_error_t *
ip4_show_fib (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
{
@@ -1949,9 +1959,7 @@ ip4_show_fib (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * c
}
}
- vec_sort (routes, r1, r2,
- ({ int cmp = ip4_address_compare (&r1->address, &r2->address);
- cmp ? cmp : ((int) r1->address_length - (int) r2->address_length); }));
+ vec_sort_with_function (routes, ip4_route_cmp);
if (vec_len(routes)) {
if (include_empty_fibs == 0)
vlib_cli_output (vm, "Table %d, fib_index %d, flow hash: %U",
@@ -2104,6 +2112,15 @@ static void count_routes_in_fib_at_prefix_length
ap->count_by_prefix_length[mask_width]++;
}
+static int
+ip6_route_cmp (void * a1, void * a2)
+{
+ ip6_route_t * r1 = a1;
+ ip6_route_t * r2 = a2;
+
+ int cmp = ip6_address_compare (&r1->address, &r2->address);
+ return cmp ? cmp : ((int) r1->address_length - (int) r2->address_length);
+}
static clib_error_t *
ip6_show_fib (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
@@ -2172,9 +2189,7 @@ ip6_show_fib (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * c
BV(clib_bihash_foreach_key_value_pair)(h, add_routes_in_fib, a);
- vec_sort (routes, r1, r2,
- ({ int cmp = ip6_address_compare (&r1->address, &r2->address);
- cmp ? cmp : ((int) r1->address_length - (int) r2->address_length); }));
+ vec_sort_with_function (routes, ip6_route_cmp);
vlib_cli_output (vm, "%=45s%=16s%=16s%=16s",
"Destination", "Packets", "Bytes", "Adjacency");
diff --git a/vnet/vnet/mpls-gre/mpls.c b/vnet/vnet/mpls-gre/mpls.c
index 431a69b4..1e1a0970 100644
--- a/vnet/vnet/mpls-gre/mpls.c
+++ b/vnet/vnet/mpls-gre/mpls.c
@@ -585,6 +585,33 @@ typedef struct {
u32 label;
} show_mpls_fib_t;
+static int
+mpls_dest_cmp(void * a1, void * a2)
+{
+ show_mpls_fib_t * r1 = a1;
+ show_mpls_fib_t * r2 = a2;
+
+ return clib_net_to_host_u32(r1->dest) - clib_net_to_host_u32(r2->dest);
+}
+
+static int
+mpls_fib_index_cmp(void * a1, void * a2)
+{
+ show_mpls_fib_t * r1 = a1;
+ show_mpls_fib_t * r2 = a2;
+
+ return r1->fib_index - r2->fib_index;
+}
+
+static int
+mpls_label_cmp(void * a1, void * a2)
+{
+ show_mpls_fib_t * r1 = a1;
+ show_mpls_fib_t * r2 = a2;
+
+ return r1->label - r2->label;
+}
+
static clib_error_t *
show_mpls_fib_command_fn (vlib_main_t * vm,
unformat_input_t * input,
@@ -614,9 +641,8 @@ show_mpls_fib_command_fn (vlib_main_t * vm,
goto decap_table;
}
/* sort output by dst address within fib */
- vec_sort (records, r0, r1, clib_net_to_host_u32(r0->dest) -
- clib_net_to_host_u32(r1->dest));
- vec_sort (records, r0, r1, r0->fib_index - r1->fib_index);
+ vec_sort_with_function (records, mpls_dest_cmp);
+ vec_sort_with_function (records, mpls_fib_index_cmp);
vlib_cli_output (vm, "MPLS encap table");
vlib_cli_output (vm, "%=6s%=16s%=16s", "Table", "Dest address", "Labels");
vec_foreach (s, records)
@@ -645,7 +671,7 @@ show_mpls_fib_command_fn (vlib_main_t * vm,
goto out;
}
- vec_sort (records, r0, r1, r0->label - r1->label);
+ vec_sort_with_function (records, mpls_label_cmp);
vlib_cli_output (vm, "MPLS decap table");
vlib_cli_output (vm, "%=10s%=15s%=6s%=6s", "RX Table", "TX Table/Intfc",