diff options
author | Dave Barach <dave@barachs.net> | 2016-12-09 09:52:16 -0500 |
---|---|---|
committer | Dave Barach <dave@barachs.net> | 2016-12-09 11:47:00 -0500 |
commit | d7cb1b5f22948eba272e1a8844c75a2b87706fc4 (patch) | |
tree | 20728b9b0e229ec43587f22fdbbcd4c2552b6965 /vnet/vnet/ip/lookup.c | |
parent | b78292efdfaf70baf89c778973d4bb3b822e95dd (diff) |
Coding standards cleanup for vnet/vnet/ip, VPP-255
Change-Id: I12892fa571cc50e0541d6463a8b68e1b618edd9f
Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'vnet/vnet/ip/lookup.c')
-rw-r--r-- | vnet/vnet/ip/lookup.c | 685 |
1 files changed, 355 insertions, 330 deletions
diff --git a/vnet/vnet/ip/lookup.c b/vnet/vnet/ip/lookup.c index 1a32b4a6467..126deef7dd0 100644 --- a/vnet/vnet/ip/lookup.c +++ b/vnet/vnet/ip/lookup.c @@ -58,56 +58,62 @@ clib_error_t * ip_interface_address_add_del (ip_lookup_main_t * lm, u32 sw_if_index, - void * addr_fib, + void *addr_fib, u32 address_length, - u32 is_del, - u32 * result_if_address_index) + u32 is_del, u32 * result_if_address_index) { - vnet_main_t * vnm = vnet_get_main(); - ip_interface_address_t * a, * prev, * next; - uword * p = mhash_get (&lm->address_to_if_address_index, addr_fib); + vnet_main_t *vnm = vnet_get_main (); + ip_interface_address_t *a, *prev, *next; + uword *p = mhash_get (&lm->address_to_if_address_index, addr_fib); - vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index, sw_if_index, ~0); + vec_validate_init_empty (lm->if_address_pool_index_by_sw_if_index, + sw_if_index, ~0); a = p ? pool_elt_at_index (lm->if_address_pool, p[0]) : 0; /* Verify given length. */ if ((a && (address_length != a->address_length)) || (address_length == 0)) { vnm->api_errno = VNET_API_ERROR_ADDRESS_LENGTH_MISMATCH; - return clib_error_create - ( "%U wrong length (expected %d) for interface %U", - lm->format_address_and_length, addr_fib, - address_length, a? a->address_length : -1, - format_vnet_sw_if_index_name, vnm, sw_if_index); + return clib_error_create + ("%U wrong length (expected %d) for interface %U", + lm->format_address_and_length, addr_fib, + address_length, a ? a->address_length : -1, + format_vnet_sw_if_index_name, vnm, sw_if_index); } if (is_del) { - if (!a) - { - vnet_sw_interface_t * si = vnet_get_sw_interface (vnm, sw_if_index); - vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE; - return clib_error_create ("%U not found for interface %U", - lm->format_address_and_length, - addr_fib, address_length, - format_vnet_sw_interface_name, vnm, si); - } + if (!a) + { + vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); + vnm->api_errno = VNET_API_ERROR_ADDRESS_NOT_FOUND_FOR_INTERFACE; + return clib_error_create ("%U not found for interface %U", + lm->format_address_and_length, + addr_fib, address_length, + format_vnet_sw_interface_name, vnm, si); + } if (a->prev_this_sw_interface != ~0) { - prev = pool_elt_at_index (lm->if_address_pool, a->prev_this_sw_interface); + prev = + pool_elt_at_index (lm->if_address_pool, + a->prev_this_sw_interface); prev->next_this_sw_interface = a->next_this_sw_interface; } if (a->next_this_sw_interface != ~0) { - next = pool_elt_at_index (lm->if_address_pool, a->next_this_sw_interface); + next = + pool_elt_at_index (lm->if_address_pool, + a->next_this_sw_interface); next->prev_this_sw_interface = a->prev_this_sw_interface; - if(a->prev_this_sw_interface == ~0) - lm->if_address_pool_index_by_sw_if_index[sw_if_index] = a->next_this_sw_interface; + if (a->prev_this_sw_interface == ~0) + lm->if_address_pool_index_by_sw_if_index[sw_if_index] = + a->next_this_sw_interface; } - if ((a->next_this_sw_interface == ~0) && (a->prev_this_sw_interface == ~0)) + if ((a->next_this_sw_interface == ~0) + && (a->prev_this_sw_interface == ~0)) lm->if_address_pool_index_by_sw_if_index[sw_if_index] = ~0; mhash_unset (&lm->address_to_if_address_index, addr_fib, @@ -118,11 +124,11 @@ ip_interface_address_add_del (ip_lookup_main_t * lm, *result_if_address_index = ~0; } - else if (! a) + else if (!a) { - u32 pi; /* previous index */ - u32 ai; - u32 hi; /* head index */ + u32 pi; /* previous index */ + u32 ai; + u32 hi; /* head index */ pool_get (lm->if_address_pool, a); memset (a, ~0, sizeof (a[0])); @@ -130,12 +136,12 @@ ip_interface_address_add_del (ip_lookup_main_t * lm, hi = pi = lm->if_address_pool_index_by_sw_if_index[sw_if_index]; prev = 0; - while (pi != (u32)~0) - { - prev = pool_elt_at_index(lm->if_address_pool, pi); - pi = prev->next_this_sw_interface; - } - pi = prev ? prev - lm->if_address_pool : (u32)~0; + while (pi != (u32) ~ 0) + { + prev = pool_elt_at_index (lm->if_address_pool, pi); + pi = prev->next_this_sw_interface; + } + pi = prev ? prev - lm->if_address_pool : (u32) ~ 0; a->address_key = mhash_set (&lm->address_to_if_address_index, addr_fib, ai, /* old_value */ 0); @@ -145,10 +151,10 @@ ip_interface_address_add_del (ip_lookup_main_t * lm, a->prev_this_sw_interface = pi; a->next_this_sw_interface = ~0; if (prev) - prev->next_this_sw_interface = ai; + prev->next_this_sw_interface = ai; - lm->if_address_pool_index_by_sw_if_index[sw_if_index] = - (hi != ~0) ? hi : ai; + lm->if_address_pool_index_by_sw_if_index[sw_if_index] = + (hi != ~0) ? hi : ai; if (result_if_address_index) *result_if_address_index = ai; } @@ -157,23 +163,25 @@ ip_interface_address_add_del (ip_lookup_main_t * lm, if (result_if_address_index) *result_if_address_index = a - lm->if_address_pool; } - + return /* no error */ 0; } -void ip_lookup_init (ip_lookup_main_t * lm, u32 is_ip6) +void +ip_lookup_init (ip_lookup_main_t * lm, u32 is_ip6) { /* ensure that adjacency is cacheline aligned and sized */ - STATIC_ASSERT(STRUCT_OFFSET_OF(ip_adjacency_t, cacheline0) == 0, - "Cache line marker must be 1st element in struct"); - STATIC_ASSERT(STRUCT_OFFSET_OF(ip_adjacency_t, cacheline1) == CLIB_CACHE_LINE_BYTES, - "Data in cache line 0 is bigger than cache line size"); + STATIC_ASSERT (STRUCT_OFFSET_OF (ip_adjacency_t, cacheline0) == 0, + "Cache line marker must be 1st element in struct"); + STATIC_ASSERT (STRUCT_OFFSET_OF (ip_adjacency_t, cacheline1) == + CLIB_CACHE_LINE_BYTES, + "Data in cache line 0 is bigger than cache line size"); /* Preallocate three "special" adjacencies */ lm->adjacency_heap = adj_pool; - if (! lm->fib_result_n_bytes) + if (!lm->fib_result_n_bytes) lm->fib_result_n_bytes = sizeof (uword); lm->is_ip6 = is_ip6; @@ -201,16 +209,21 @@ void ip_lookup_init (ip_lookup_main_t * lm, u32 is_ip6) } lm->local_next_by_ip_protocol[IP_PROTOCOL_UDP] = IP_LOCAL_NEXT_UDP_LOOKUP; - lm->local_next_by_ip_protocol[is_ip6 ? IP_PROTOCOL_ICMP6 : IP_PROTOCOL_ICMP] = IP_LOCAL_NEXT_ICMP; - lm->builtin_protocol_by_ip_protocol[IP_PROTOCOL_UDP] = IP_BUILTIN_PROTOCOL_UDP; - lm->builtin_protocol_by_ip_protocol[is_ip6 ? IP_PROTOCOL_ICMP6 : IP_PROTOCOL_ICMP] = IP_BUILTIN_PROTOCOL_ICMP; + lm->local_next_by_ip_protocol[is_ip6 ? IP_PROTOCOL_ICMP6 : + IP_PROTOCOL_ICMP] = IP_LOCAL_NEXT_ICMP; + lm->builtin_protocol_by_ip_protocol[IP_PROTOCOL_UDP] = + IP_BUILTIN_PROTOCOL_UDP; + lm->builtin_protocol_by_ip_protocol[is_ip6 ? IP_PROTOCOL_ICMP6 : + IP_PROTOCOL_ICMP] = + IP_BUILTIN_PROTOCOL_ICMP; } } -u8 * format_ip_flow_hash_config (u8 * s, va_list * args) +u8 * +format_ip_flow_hash_config (u8 * s, va_list * args) { flow_hash_config_t flow_hash_config = va_arg (*args, u32); - + #define _(n,v) if (flow_hash_config & v) s = format (s, "%s ", #n); foreach_flow_hash_bit; #undef _ @@ -218,10 +231,11 @@ u8 * format_ip_flow_hash_config (u8 * s, va_list * args) return s; } -u8 * format_ip_lookup_next (u8 * s, va_list * args) +u8 * +format_ip_lookup_next (u8 * s, va_list * args) { ip_lookup_next_t n = va_arg (*args, ip_lookup_next_t); - char * t = 0; + char *t = 0; switch (n) { @@ -229,11 +243,21 @@ u8 * format_ip_lookup_next (u8 * s, va_list * args) s = format (s, "unknown %d", n); return s; - case IP_LOOKUP_NEXT_DROP: t = "drop"; break; - case IP_LOOKUP_NEXT_PUNT: t = "punt"; break; - case IP_LOOKUP_NEXT_ARP: t = "arp"; break; - case IP_LOOKUP_NEXT_MIDCHAIN: t="midchain"; break; - case IP_LOOKUP_NEXT_GLEAN: t="glean"; break; + case IP_LOOKUP_NEXT_DROP: + t = "drop"; + break; + case IP_LOOKUP_NEXT_PUNT: + t = "punt"; + break; + case IP_LOOKUP_NEXT_ARP: + t = "arp"; + break; + case IP_LOOKUP_NEXT_MIDCHAIN: + t = "midchain"; + break; + case IP_LOOKUP_NEXT_GLEAN: + t = "glean"; + break; case IP_LOOKUP_NEXT_REWRITE: break; } @@ -244,20 +268,22 @@ u8 * format_ip_lookup_next (u8 * s, va_list * args) return s; } -u8 * format_ip_adjacency_packet_data (u8 * s, va_list * args) +u8 * +format_ip_adjacency_packet_data (u8 * s, va_list * args) { - vnet_main_t * vnm = va_arg (*args, vnet_main_t *); + vnet_main_t *vnm = va_arg (*args, vnet_main_t *); u32 adj_index = va_arg (*args, u32); - u8 * packet_data = va_arg (*args, u8 *); + u8 *packet_data = va_arg (*args, u8 *); u32 n_packet_data_bytes = va_arg (*args, u32); - ip_adjacency_t * adj = adj_get(adj_index); + ip_adjacency_t *adj = adj_get (adj_index); switch (adj->lookup_next_index) { case IP_LOOKUP_NEXT_REWRITE: s = format (s, "%U", format_vnet_rewrite_header, - vnm->vlib_main, &adj->rewrite_header, packet_data, n_packet_data_bytes); + vnm->vlib_main, &adj->rewrite_header, packet_data, + n_packet_data_bytes); break; default: @@ -267,38 +293,39 @@ u8 * format_ip_adjacency_packet_data (u8 * s, va_list * args) return s; } -static uword unformat_dpo (unformat_input_t * input, va_list * args) +static uword +unformat_dpo (unformat_input_t * input, va_list * args) { dpo_id_t *dpo = va_arg (*args, dpo_id_t *); fib_protocol_t fp = va_arg (*args, int); dpo_proto_t proto; - proto = fib_proto_to_dpo(fp); + proto = fib_proto_to_dpo (fp); if (unformat (input, "drop")) - dpo_copy(dpo, drop_dpo_get(proto)); + dpo_copy (dpo, drop_dpo_get (proto)); else if (unformat (input, "punt")) - dpo_copy(dpo, punt_dpo_get(proto)); + dpo_copy (dpo, punt_dpo_get (proto)); else if (unformat (input, "local")) - receive_dpo_add_or_lock(proto, ~0, NULL, dpo); + receive_dpo_add_or_lock (proto, ~0, NULL, dpo); else if (unformat (input, "null-send-unreach")) - ip_null_dpo_add_and_lock(proto, IP_NULL_ACTION_SEND_ICMP_UNREACH, dpo); + ip_null_dpo_add_and_lock (proto, IP_NULL_ACTION_SEND_ICMP_UNREACH, dpo); else if (unformat (input, "null-send-prohibit")) - ip_null_dpo_add_and_lock(proto, IP_NULL_ACTION_SEND_ICMP_PROHIBIT, dpo); + ip_null_dpo_add_and_lock (proto, IP_NULL_ACTION_SEND_ICMP_PROHIBIT, dpo); else if (unformat (input, "null")) - ip_null_dpo_add_and_lock(proto, IP_NULL_ACTION_NONE, dpo); + ip_null_dpo_add_and_lock (proto, IP_NULL_ACTION_NONE, dpo); else if (unformat (input, "classify")) { u32 classify_table_index; if (!unformat (input, "%d", &classify_table_index)) - { + { clib_warning ("classify adj must specify table index"); - return 0; + return 0; } - dpo_set(dpo, DPO_CLASSIFY, proto, - classify_dpo_create(proto, classify_table_index)); + dpo_set (dpo, DPO_CLASSIFY, proto, + classify_dpo_create (proto, classify_table_index)); } else return 0; @@ -307,69 +334,66 @@ static uword unformat_dpo (unformat_input_t * input, va_list * args) } const ip46_address_t zero_addr = { - .as_u64 = { - 0, 0 - }, + .as_u64 = { + 0, 0}, }; u32 -fib_table_id_find_fib_index (fib_protocol_t proto, - u32 table_id) +fib_table_id_find_fib_index (fib_protocol_t proto, u32 table_id) { - ip4_main_t *im4 = &ip4_main; - ip6_main_t *im6 = &ip6_main; - uword * p; + ip4_main_t *im4 = &ip4_main; + ip6_main_t *im6 = &ip6_main; + uword *p; - switch (proto) + switch (proto) { case FIB_PROTOCOL_IP4: - p = hash_get(im4->fib_index_by_table_id, table_id); - break; + p = hash_get (im4->fib_index_by_table_id, table_id); + break; case FIB_PROTOCOL_IP6: - p = hash_get(im6->fib_index_by_table_id, table_id); - break; + p = hash_get (im6->fib_index_by_table_id, table_id); + break; default: - p = NULL; - break; + p = NULL; + break; } - if (NULL != p) + if (NULL != p) { - return (p[0]); + return (p[0]); } - return (~0); + return (~0); } clib_error_t * vnet_ip_route_cmd (vlib_main_t * vm, - unformat_input_t * main_input, - vlib_cli_command_t * cmd) + unformat_input_t * main_input, vlib_cli_command_t * cmd) { - unformat_input_t _line_input, * line_input = &_line_input; + unformat_input_t _line_input, *line_input = &_line_input; fib_route_path_t *rpaths = NULL, rpath; dpo_id_t dpo = DPO_INVALID, *dpos = NULL; fib_prefix_t *prefixs = NULL, pfx; mpls_label_t out_label, via_label; - clib_error_t * error = NULL; + clib_error_t *error = NULL; u32 table_id, is_del; - vnet_main_t * vnm; + vnet_main_t *vnm; u32 fib_index; f64 count; int i; - vnm = vnet_get_main(); + vnm = vnet_get_main (); is_del = 0; table_id = 0; count = 1; - memset(&pfx, 0, sizeof(pfx)); + memset (&pfx, 0, sizeof (pfx)); out_label = via_label = MPLS_LABEL_INVALID; /* Get a line of input. */ - if (! unformat_user (main_input, unformat_line_input, line_input)) + if (!unformat_user (main_input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - memset(&rpath, 0, sizeof(rpath)); + memset (&rpath, 0, sizeof (rpath)); if (unformat (line_input, "table %d", &table_id)) ; @@ -378,129 +402,120 @@ vnet_ip_route_cmd (vlib_main_t * vm, else if (unformat (line_input, "add")) is_del = 0; else if (unformat (line_input, "resolve-via-host")) - { - if (vec_len(rpaths) == 0) - { - error = clib_error_return(0 , "Paths then flags"); + { + if (vec_len (rpaths) == 0) + { + error = clib_error_return (0, "Paths then flags"); goto done; - } - rpaths[vec_len(rpaths)-1].frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST; - } + } + rpaths[vec_len (rpaths) - 1].frp_flags |= + FIB_ROUTE_PATH_RESOLVE_VIA_HOST; + } else if (unformat (line_input, "resolve-via-attached")) - { - if (vec_len(rpaths) == 0) - { - error = clib_error_return(0 , "Paths then flags"); + { + if (vec_len (rpaths) == 0) + { + error = clib_error_return (0, "Paths then flags"); goto done; - } - rpaths[vec_len(rpaths)-1].frp_flags |= - FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED; - } + } + rpaths[vec_len (rpaths) - 1].frp_flags |= + FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED; + } else if (unformat (line_input, "out-label %U", - unformat_mpls_unicast_label, &out_label)) - { - if (vec_len(rpaths) == 0) - { - error = clib_error_return(0 , "Paths then labels"); + unformat_mpls_unicast_label, &out_label)) + { + if (vec_len (rpaths) == 0) + { + error = clib_error_return (0, "Paths then labels"); goto done; - } - vec_add1(rpaths[vec_len(rpaths)-1].frp_label_stack, out_label); - } + } + vec_add1 (rpaths[vec_len (rpaths) - 1].frp_label_stack, out_label); + } else if (unformat (line_input, "via-label %U", - unformat_mpls_unicast_label, - &rpath.frp_local_label)) - { + unformat_mpls_unicast_label, &rpath.frp_local_label)) + { rpath.frp_weight = 1; rpath.frp_proto = FIB_PROTOCOL_MPLS; rpath.frp_sw_if_index = ~0; - vec_add1(rpaths, rpath); - } + vec_add1 (rpaths, rpath); + } else if (unformat (line_input, "count %f", &count)) ; else if (unformat (line_input, "%U/%d", - unformat_ip4_address, - &pfx.fp_addr.ip4, - &pfx.fp_len)) - { + unformat_ip4_address, &pfx.fp_addr.ip4, &pfx.fp_len)) + { pfx.fp_proto = FIB_PROTOCOL_IP4; - vec_add1(prefixs, pfx); - } + vec_add1 (prefixs, pfx); + } else if (unformat (line_input, "%U/%d", - unformat_ip6_address, - &pfx.fp_addr.ip6, - &pfx.fp_len)) - { + unformat_ip6_address, &pfx.fp_addr.ip6, &pfx.fp_len)) + { pfx.fp_proto = FIB_PROTOCOL_IP6; - vec_add1(prefixs, pfx); - } + vec_add1 (prefixs, pfx); + } else if (unformat (line_input, "via %U %U weight %u", unformat_ip4_address, &rpath.frp_addr.ip4, unformat_vnet_sw_interface, vnm, - &rpath.frp_sw_if_index, - &rpath.frp_weight)) - { + &rpath.frp_sw_if_index, &rpath.frp_weight)) + { rpath.frp_proto = FIB_PROTOCOL_IP4; - vec_add1(rpaths, rpath); - } + vec_add1 (rpaths, rpath); + } else if (unformat (line_input, "via %U %U weight %u", unformat_ip6_address, &rpath.frp_addr.ip6, unformat_vnet_sw_interface, vnm, - &rpath.frp_sw_if_index, - &rpath.frp_weight)) - { + &rpath.frp_sw_if_index, &rpath.frp_weight)) + { rpath.frp_proto = FIB_PROTOCOL_IP6; - vec_add1(rpaths, rpath); - } + vec_add1 (rpaths, rpath); + } else if (unformat (line_input, "via %U %U", unformat_ip4_address, - &rpath.frp_addr.ip4, + &rpath.frp_addr.ip4, unformat_vnet_sw_interface, vnm, &rpath.frp_sw_if_index)) - { + { rpath.frp_weight = 1; rpath.frp_proto = FIB_PROTOCOL_IP4; - vec_add1(rpaths, rpath); - } - + vec_add1 (rpaths, rpath); + } + else if (unformat (line_input, "via %U %U", unformat_ip6_address, - &rpath.frp_addr.ip6, + &rpath.frp_addr.ip6, unformat_vnet_sw_interface, vnm, &rpath.frp_sw_if_index)) - { + { rpath.frp_weight = 1; rpath.frp_proto = FIB_PROTOCOL_IP6; - vec_add1(rpaths, rpath); - } + vec_add1 (rpaths, rpath); + } else if (unformat (line_input, "via %U next-hop-table %d", unformat_ip4_address, - &rpath.frp_addr.ip4, - &rpath.frp_fib_index)) - { + &rpath.frp_addr.ip4, &rpath.frp_fib_index)) + { rpath.frp_weight = 1; rpath.frp_sw_if_index = ~0; rpath.frp_proto = FIB_PROTOCOL_IP4; - vec_add1(rpaths, rpath); - } + vec_add1 (rpaths, rpath); + } else if (unformat (line_input, "via %U next-hop-table %d", unformat_ip6_address, - &rpath.frp_addr.ip6, - &rpath.frp_fib_index)) - { + &rpath.frp_addr.ip6, &rpath.frp_fib_index)) + { rpath.frp_weight = 1; rpath.frp_sw_if_index = ~0; rpath.frp_proto = FIB_PROTOCOL_IP6; - vec_add1(rpaths, rpath); - } + vec_add1 (rpaths, rpath); + } else if (unformat (line_input, "via %U", - unformat_ip4_address, - &rpath.frp_addr.ip4)) - { + unformat_ip4_address, &rpath.frp_addr.ip4)) + { /* * the recursive next-hops are by default in the same table * as the prefix @@ -509,44 +524,43 @@ vnet_ip_route_cmd (vlib_main_t * vm, rpath.frp_weight = 1; rpath.frp_sw_if_index = ~0; rpath.frp_proto = FIB_PROTOCOL_IP4; - vec_add1(rpaths, rpath); - } + vec_add1 (rpaths, rpath); + } else if (unformat (line_input, "via %U", - unformat_ip6_address, - &rpath.frp_addr.ip6)) - { + unformat_ip6_address, &rpath.frp_addr.ip6)) + { rpath.frp_fib_index = table_id; rpath.frp_weight = 1; rpath.frp_sw_if_index = ~0; rpath.frp_proto = FIB_PROTOCOL_IP6; - vec_add1(rpaths, rpath); - } + vec_add1 (rpaths, rpath); + } else if (unformat (line_input, - "lookup in table %d", - &rpath.frp_fib_index)) - { + "lookup in table %d", &rpath.frp_fib_index)) + { rpath.frp_proto = pfx.fp_proto; rpath.frp_sw_if_index = ~0; - vec_add1(rpaths, rpath); - } + vec_add1 (rpaths, rpath); + } else if (vec_len (prefixs) > 0 && unformat (line_input, "via %U", unformat_dpo, &dpo, prefixs[0].fp_proto)) - { + { vec_add1 (dpos, dpo); - } + } else - { + { error = unformat_parse_error (line_input); goto done; - } + } } - + unformat_free (line_input); if (vec_len (prefixs) == 0) - { - error = clib_error_return (0, "expected ip4/ip6 destination address/length."); + { + error = + clib_error_return (0, "expected ip4/ip6 destination address/length."); goto done; } @@ -557,50 +571,47 @@ vnet_ip_route_cmd (vlib_main_t * vm, } if (~0 == table_id) - { + { /* * if no table_id is passed we will manipulate the default */ fib_index = 0; - } + } else - { - fib_index = fib_table_id_find_fib_index(prefixs[0].fp_proto, - table_id); + { + fib_index = fib_table_id_find_fib_index (prefixs[0].fp_proto, table_id); if (~0 == fib_index) - { - error = clib_error_return (0, - "Nonexistent table id %d", - table_id); + { + error = clib_error_return (0, "Nonexistent table id %d", table_id); goto done; - } - } + } + } for (i = 0; i < vec_len (prefixs); i++) - { + { if (is_del && 0 == vec_len (rpaths)) - { - fib_table_entry_delete(fib_index, - &prefixs[i], - FIB_SOURCE_CLI); - } + { + fib_table_entry_delete (fib_index, &prefixs[i], FIB_SOURCE_CLI); + } else if (!is_del && 1 == vec_len (dpos)) - { - fib_table_entry_special_dpo_add(fib_index, - &prefixs[i], - FIB_SOURCE_CLI, - FIB_ENTRY_FLAG_EXCLUSIVE, - &dpos[0]); - dpo_reset(&dpos[0]); - } + { + fib_table_entry_special_dpo_add (fib_index, + &prefixs[i], + FIB_SOURCE_CLI, + FIB_ENTRY_FLAG_EXCLUSIVE, + &dpos[0]); + dpo_reset (&dpos[0]); + } else if (vec_len (dpos) > 0) - { - error = clib_error_return(0 , "Load-balancing over multiple special adjacencies is unsupported"); + { + error = + clib_error_return (0, + "Load-balancing over multiple special adjacencies is unsupported"); goto done; - } + } else if (0 < vec_len (rpaths)) - { + { u32 k, j, n, incr; ip46_address_t dst = prefixs[i].fp_addr; f64 t[2]; @@ -610,97 +621,106 @@ vnet_ip_route_cmd (vlib_main_t * vm, prefixs[i].fp_len); for (k = 0; k < n; k++) - { + { for (j = 0; j < vec_len (rpaths); j++) - { + { u32 fi; /* * the CLI parsing stored table Ids, swap to FIB indicies */ - fi = fib_table_id_find_fib_index(prefixs[i].fp_proto, - rpaths[i].frp_fib_index); + fi = fib_table_id_find_fib_index (prefixs[i].fp_proto, + rpaths[i].frp_fib_index); if (~0 == fi) - { - error = clib_error_return(0 , "Via table %d does not exist", - rpaths[i].frp_fib_index); + { + error = + clib_error_return (0, "Via table %d does not exist", + rpaths[i].frp_fib_index); goto done; - } + } rpaths[i].frp_fib_index = fi; fib_prefix_t rpfx = { - .fp_len = prefixs[i].fp_len, - .fp_proto = prefixs[i].fp_proto, - .fp_addr = dst, + .fp_len = prefixs[i].fp_len, + .fp_proto = prefixs[i].fp_proto, + .fp_addr = dst, }; - if (is_del) - fib_table_entry_path_remove2(fib_index, - &rpfx, - FIB_SOURCE_CLI, - &rpaths[j]); - else - fib_table_entry_path_add2(fib_index, - &rpfx, - FIB_SOURCE_CLI, - FIB_ENTRY_FLAG_NONE, - &rpaths[j]); - } + if (is_del) + fib_table_entry_path_remove2 (fib_index, + &rpfx, + FIB_SOURCE_CLI, &rpaths[j]); + else + fib_table_entry_path_add2 (fib_index, + &rpfx, + FIB_SOURCE_CLI, + FIB_ENTRY_FLAG_NONE, + &rpaths[j]); + } if (FIB_PROTOCOL_IP4 == prefixs[0].fp_proto) - { + { dst.ip4.as_u32 = - clib_host_to_net_u32(incr + - clib_net_to_host_u32 (dst.ip4.as_u32)); - } + clib_host_to_net_u32 (incr + + clib_net_to_host_u32 (dst. + ip4.as_u32)); + } else - { + { int bucket = (incr < 64 ? 0 : 1); dst.ip6.as_u64[bucket] = - clib_host_to_net_u64(incr + - clib_net_to_host_u64 ( - dst.ip6.as_u64[bucket])); + clib_host_to_net_u64 (incr + + clib_net_to_host_u64 (dst.ip6.as_u64 + [bucket])); - } - } + } + } t[1] = vlib_time_now (vm); if (count > 1) - vlib_cli_output (vm, "%.6e routes/sec", count / (t[1] - t[0])); - } + vlib_cli_output (vm, "%.6e routes/sec", count / (t[1] - t[0])); + } else - { - error = clib_error_return(0 , "Don't understand what you want..."); + { + error = clib_error_return (0, "Don't understand what you want..."); goto done; - } - } + } + } - done: +done: vec_free (dpos); vec_free (prefixs); vec_free (rpaths); return error; } +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (vlib_cli_ip_command, static) = { .path = "ip", .short_help = "Internet protocol (IP) commands", }; +/* *INDENT-ON* */ +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (vlib_cli_ip6_command, static) = { .path = "ip6", .short_help = "Internet protocol version 6 (IPv6) commands", }; +/* *INDENT-ON* */ +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (vlib_cli_show_ip_command, static) = { .path = "show ip", .short_help = "Internet protocol (IP) show commands", }; +/* *INDENT-ON* */ +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (vlib_cli_show_ip6_command, static) = { .path = "show ip6", .short_help = "Internet protocol version 6 (IPv6) show commands", }; +/* *INDENT-ON* */ /*? * This command is used to add or delete IPv4 or IPv6 routes. All @@ -744,22 +764,22 @@ VLIB_CLI_COMMAND (ip_route_command, static) = { * or dependent route-adds will simply fail. */ static clib_error_t * -ip6_probe_neighbor_wait (vlib_main_t *vm, ip6_address_t * a, u32 sw_if_index, +ip6_probe_neighbor_wait (vlib_main_t * vm, ip6_address_t * a, u32 sw_if_index, int retry_count) { - vnet_main_t * vnm = vnet_get_main(); - clib_error_t * e; + vnet_main_t *vnm = vnet_get_main (); + clib_error_t *e; int i; int resolved = 0; uword event_type; uword *event_data = 0; - ASSERT (vlib_in_process_context(vm)); + ASSERT (vlib_in_process_context (vm)); if (retry_count > 0) vnet_register_ip6_neighbor_resolution_event (vnm, a, vlib_get_current_process (vm)->node_runtime.node_index, - 1 /* event */, 0 /* data */); + 1 /* event */ , 0 /* data */ ); for (i = 0; i < retry_count; i++) { @@ -773,121 +793,118 @@ ip6_probe_neighbor_wait (vlib_main_t *vm, ip6_address_t * a, u32 sw_if_index, event_type = vlib_process_get_events (vm, &event_data); switch (event_type) { - case 1: /* resolved... */ - vlib_cli_output (vm, "Resolved %U", - format_ip6_address, a); - resolved = 1; - goto done; - - case ~0: /* timeout */ - break; - - default: - clib_warning ("unknown event_type %d", event_type); - } + case 1: /* resolved... */ + vlib_cli_output (vm, "Resolved %U", format_ip6_address, a); + resolved = 1; + goto done; + + case ~0: /* timeout */ + break; + + default: + clib_warning ("unknown event_type %d", event_type); + } vec_reset_length (event_data); } - - done: + +done: if (!resolved) return clib_error_return (0, "Resolution failed for %U", - format_ip6_address, a); + format_ip6_address, a); return 0; } static clib_error_t * -ip4_probe_neighbor_wait (vlib_main_t *vm, ip4_address_t * a, u32 sw_if_index, - int retry_count) +ip4_probe_neighbor_wait (vlib_main_t * vm, ip4_address_t * a, u32 sw_if_index, + int retry_count) { - vnet_main_t * vnm = vnet_get_main(); - clib_error_t * e; + vnet_main_t *vnm = vnet_get_main (); + clib_error_t *e; int i; int resolved = 0; uword event_type; uword *event_data = 0; - ASSERT (vlib_in_process_context(vm)); + ASSERT (vlib_in_process_context (vm)); if (retry_count > 0) - vnet_register_ip4_arp_resolution_event + vnet_register_ip4_arp_resolution_event (vnm, a, vlib_get_current_process (vm)->node_runtime.node_index, - 1 /* event */, 0 /* data */); - + 1 /* event */ , 0 /* data */ ); + for (i = 0; i < retry_count; i++) { /* The interface may be down, etc. */ e = ip4_probe_neighbor (vm, a, sw_if_index); - + if (e) - return e; - + return e; + vlib_process_wait_for_event_or_clock (vm, 1.0); event_type = vlib_process_get_events (vm, &event_data); - switch (event_type) - { - case 1: /* resolved... */ - vlib_cli_output (vm, "Resolved %U", - format_ip4_address, a); - resolved = 1; - goto done; - - case ~0: /* timeout */ - break; - - default: - clib_warning ("unknown event_type %d", event_type); - } + switch (event_type) + { + case 1: /* resolved... */ + vlib_cli_output (vm, "Resolved %U", format_ip4_address, a); + resolved = 1; + goto done; + + case ~0: /* timeout */ + break; + + default: + clib_warning ("unknown event_type %d", event_type); + } vec_reset_length (event_data); } - - done: + +done: vec_reset_length (event_data); if (!resolved) return clib_error_return (0, "Resolution failed for %U", - format_ip4_address, a); + format_ip4_address, a); return 0; } static clib_error_t * probe_neighbor_address (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) + unformat_input_t * input, vlib_cli_command_t * cmd) { - vnet_main_t * vnm = vnet_get_main(); - unformat_input_t _line_input, * line_input = &_line_input; + vnet_main_t *vnm = vnet_get_main (); + unformat_input_t _line_input, *line_input = &_line_input; ip4_address_t a4; ip6_address_t a6; - clib_error_t * error = 0; + clib_error_t *error = 0; u32 sw_if_index = ~0; int retry_count = 3; int is_ip4 = 1; int address_set = 0; /* Get a line of input. */ - if (! unformat_user (input, unformat_line_input, line_input)) + if (!unformat_user (input, unformat_line_input, line_input)) return 0; - while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) + while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { - if (unformat_user (line_input, unformat_vnet_sw_interface, vnm, - &sw_if_index)) - ; + if (unformat_user (line_input, unformat_vnet_sw_interface, vnm, + &sw_if_index)) + ; else if (unformat (line_input, "retry %d", &retry_count)) - ; + ; else if (unformat (line_input, "%U", unformat_ip4_address, &a4)) - address_set++; + address_set++; else if (unformat (line_input, "%U", unformat_ip6_address, &a6)) - { - address_set++; - is_ip4 = 0; - } + { + address_set++; + is_ip4 = 0; + } else - return clib_error_return (0, "unknown input '%U'", - format_unformat_error, line_input); + return clib_error_return (0, "unknown input '%U'", + format_unformat_error, line_input); } unformat_free (line_input); @@ -898,10 +915,10 @@ probe_neighbor_address (vlib_main_t * vm, return clib_error_return (0, "ip address required, not set."); if (address_set > 1) return clib_error_return (0, "Multiple ip addresses not supported."); - + if (is_ip4) error = ip4_probe_neighbor_wait (vm, &a4, sw_if_index, retry_count); - else + else error = ip6_probe_neighbor_wait (vm, &a6, sw_if_index, retry_count); return error; @@ -931,3 +948,11 @@ VLIB_CLI_COMMAND (ip_probe_neighbor_command, static) = { .is_mp_safe = 1, }; /* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ |