diff options
Diffstat (limited to 'src/vnet/ip-neighbor/ip_neighbor.c')
-rw-r--r-- | src/vnet/ip-neighbor/ip_neighbor.c | 230 |
1 files changed, 172 insertions, 58 deletions
diff --git a/src/vnet/ip-neighbor/ip_neighbor.c b/src/vnet/ip-neighbor/ip_neighbor.c index 6c97356dd98..d340037a15d 100644 --- a/src/vnet/ip-neighbor/ip_neighbor.c +++ b/src/vnet/ip-neighbor/ip_neighbor.c @@ -27,6 +27,74 @@ #include <vnet/fib/fib_table.h> #include <vnet/adj/adj_mcast.h> +ip_neighbor_counters_t ip_neighbor_counters[] = +{ + [AF_IP4] = { + .ipnc = { + [VLIB_RX] = { + [IP_NEIGHBOR_CTR_REPLY] = { + .name = "arp-rx-replies", + .stat_segment_name = "/net/arp/rx/replies", + }, + [IP_NEIGHBOR_CTR_REQUEST] = { + .name = "arp-rx-requests", + .stat_segment_name = "/net/arp/rx/requests", + }, + [IP_NEIGHBOR_CTR_GRAT] = { + .name = "arp-rx-gratuitous", + .stat_segment_name = "/net/arp/rx/gratuitous", + }, + }, + [VLIB_TX] = { + [IP_NEIGHBOR_CTR_REPLY] = { + .name = "arp-tx-replies", + .stat_segment_name = "/net/arp/tx/replies", + }, + [IP_NEIGHBOR_CTR_REQUEST] = { + .name = "arp-tx-requests", + .stat_segment_name = "/net/arp/tx/requests", + }, + [IP_NEIGHBOR_CTR_GRAT] = { + .name = "arp-tx-gratuitous", + .stat_segment_name = "/net/arp/tx/gratuitous", + }, + }, + }, + }, + [AF_IP6] = { + .ipnc = { + [VLIB_RX] = { + [IP_NEIGHBOR_CTR_REPLY] = { + .name = "ip6-nd-rx-replies", + .stat_segment_name = "/net/ip6-nd/rx/replies", + }, + [IP_NEIGHBOR_CTR_REQUEST] = { + .name = "ip6-nd-rx-requests", + .stat_segment_name = "/net/ip6-nd/rx/requests", + }, + [IP_NEIGHBOR_CTR_GRAT] = { + .name = "ip6-nd-rx-gratuitous", + .stat_segment_name = "/net/ip6-nd/rx/gratuitous", + }, + }, + [VLIB_TX] = { + [IP_NEIGHBOR_CTR_REPLY] = { + .name = "ip6-nd-tx-replies", + .stat_segment_name = "/net/ip6-nd/tx/replies", + }, + [IP_NEIGHBOR_CTR_REQUEST] = { + .name = "ip6-nd-tx-requests", + .stat_segment_name = "/net/ip6-nd/tx/requests", + }, + [IP_NEIGHBOR_CTR_GRAT] = { + .name = "ip6-nd-tx-gratuitous", + .stat_segment_name = "/net/ip6-nd/tx/gratuitous", + }, + }, + }, + }, +}; + /** Pool for All IP neighbors */ static ip_neighbor_t *ip_neighbor_pool; @@ -62,7 +130,6 @@ typedef struct ip_neighbor_db_t_ static vlib_log_class_t ipn_logger; /* DBs of neighbours one per AF */ -/* *INDENT-OFF* */ static ip_neighbor_db_t ip_neighbor_db[N_AF] = { [AF_IP4] = { .ipndb_limit = 50000, @@ -77,7 +144,6 @@ static ip_neighbor_db_t ip_neighbor_db[N_AF] = { .ipndb_recycle = false, } }; -/* *INDENT-ON* */ #define IP_NEIGHBOR_DBG(...) \ vlib_log_debug (ipn_logger, __VA_ARGS__); @@ -729,7 +795,7 @@ ip_neighbor_cmd (vlib_main_t * vm, vnet_main_t *vnm = vnet_get_main (); ip_neighbor_flags_t flags; u32 sw_if_index = ~0; - int is_add = 1; + int is_add = 1, is_flush = 0; int count = 1; flags = IP_NEIGHBOR_FLAG_DYNAMIC; @@ -743,6 +809,8 @@ ip_neighbor_cmd (vlib_main_t * vm, ; else if (unformat (input, "delete") || unformat (input, "del")) is_add = 0; + else if (unformat (input, "flush")) + is_flush = 1; else if (unformat (input, "static")) { flags |= IP_NEIGHBOR_FLAG_STATIC; @@ -756,6 +824,13 @@ ip_neighbor_cmd (vlib_main_t * vm, break; } + if (is_flush) + { + ip_neighbor_del_all (AF_IP4, sw_if_index); + ip_neighbor_del_all (AF_IP6, sw_if_index); + return NULL; + } + if (sw_if_index == ~0 || ip_address_is_zero (&ip) || mac_address_is_zero (&mac)) return clib_error_return (0, @@ -778,11 +853,10 @@ ip_neighbor_cmd (vlib_main_t * vm, return NULL; } -/* *INDENT-OFF* */ /*? * Add or delete IPv4 ARP cache entries. * - * @note 'set ip neighbor' options (e.g. delete, static, 'fib-id <id>', + * @note 'set ip neighbor' options (e.g. delete, static, * 'count <number>', 'interface ip4_addr mac_addr') can be added in * any order and combination. * @@ -791,35 +865,39 @@ ip_neighbor_cmd (vlib_main_t * vm, * Add or delete IPv4 ARP cache entries as follows. MAC Address can be in * either aa:bb:cc:dd:ee:ff format or aabb.ccdd.eeff format. * @cliexcmd{set ip neighbor GigabitEthernet2/0/0 6.0.0.3 dead.beef.babe} - * @cliexcmd{set ip neighbor delete GigabitEthernet2/0/0 6.0.0.3 de:ad:be:ef:ba:be} + * @cliexcmd{set ip neighbor delete GigabitEthernet2/0/0 6.0.0.3 + * de:ad:be:ef:ba:be} * - * To add or delete an IPv4 ARP cache entry to or from a specific fib + * To add or delete an IPv4 ARP cache entry * table: - * @cliexcmd{set ip neighbor fib-id 1 GigabitEthernet2/0/0 6.0.0.3 dead.beef.babe} - * @cliexcmd{set ip neighbor fib-id 1 delete GigabitEthernet2/0/0 6.0.0.3 dead.beef.babe} + * @cliexcmd{set ip neighbor GigabitEthernet2/0/0 6.0.0.3 dead.beef.babe} + * @cliexcmd{set ip neighbor delete GigabitEthernet2/0/0 6.0.0.3 + * dead.beef.babe} * * Add or delete IPv4 static ARP cache entries as follows: - * @cliexcmd{set ip neighbor static GigabitEthernet2/0/0 6.0.0.3 dead.beef.babe} - * @cliexcmd{set ip neighbor static delete GigabitEthernet2/0/0 6.0.0.3 dead.beef.babe} + * @cliexcmd{set ip neighbor static GigabitEthernet2/0/0 6.0.0.3 + * dead.beef.babe} + * @cliexcmd{set ip neighbor static delete GigabitEthernet2/0/0 6.0.0.3 + * dead.beef.babe} * * For testing / debugging purposes, the 'set ip neighbor' command can add or * delete multiple entries. Supply the 'count N' parameter: - * @cliexcmd{set ip neighbor count 10 GigabitEthernet2/0/0 6.0.0.3 dead.beef.babe} + * @cliexcmd{set ip neighbor count 10 GigabitEthernet2/0/0 6.0.0.3 + * dead.beef.babe} * @endparblock ?*/ VLIB_CLI_COMMAND (ip_neighbor_command, static) = { .path = "set ip neighbor", - .short_help = - "set ip neighbor [del] <intfc> <ip-address> <mac-address> [static] [no-fib-entry] [count <count>] [fib-id <fib-id>] [proxy <lo-addr> - <hi-addr>]", + .short_help = "set ip neighbor [del] <intfc> <ip-address> <mac-address> " + "[static] [no-fib-entry] [count <count>]", .function = ip_neighbor_cmd, }; VLIB_CLI_COMMAND (ip_neighbor_command2, static) = { .path = "ip neighbor", - .short_help = - "ip neighbor [del] <intfc> <ip-address> <mac-address> [static] [no-fib-entry] [count <count>] [fib-id <fib-id>] [proxy <lo-addr> - <hi-addr>]", + .short_help = "ip neighbor [del] [flush] <intfc> <ip-address> <mac-address> " + "[static] [no-fib-entry] [count <count>]", .function = ip_neighbor_cmd, }; -/* *INDENT-ON* */ static int ip_neighbor_sort (void *a1, void *a2) @@ -845,7 +923,6 @@ ip_neighbor_entries (u32 sw_if_index, ip_address_family_t af) index_t *ipnis = NULL; ip_neighbor_t *ipn; - /* *INDENT-OFF* */ pool_foreach (ipn, ip_neighbor_pool) { if ((sw_if_index == ~0 || @@ -855,7 +932,6 @@ ip_neighbor_entries (u32 sw_if_index, ip_address_family_t af) vec_add1 (ipnis, ip_neighbor_get_index(ipn)); } - /* *INDENT-ON* */ if (ipnis) vec_sort_with_function (ipnis, ip_neighbor_sort); @@ -875,7 +951,6 @@ ip_neighbor_show_sorted_i (vlib_main_t * vm, vlib_cli_output (vm, "%=12s%=40s%=6s%=20s%=24s", "Time", "IP", "Flags", "Ethernet", "Interface"); - /* *INDENT-OFF*/ /* the list is time sorted, newest first, so start from the back * and work forwards. Stop when we get to one that is alive */ clib_llist_foreach_reverse(ip_neighbor_elt_pool, @@ -883,7 +958,6 @@ ip_neighbor_show_sorted_i (vlib_main_t * vm, ({ vlib_cli_output (vm, "%U", format_ip_neighbor, elt->ipne_index); })); - /* *INDENT-ON*/ return (NULL); } @@ -965,7 +1039,6 @@ ip4_neighbor_show_sorted (vlib_main_t * vm, * Fib_index 0 6.0.0.1 - 6.0.0.11 * @cliexend ?*/ -/* *INDENT-OFF* */ VLIB_CLI_COMMAND (show_ip_neighbors_cmd_node, static) = { .path = "show ip neighbors", .function = ip_neighbor_show, @@ -1006,7 +1079,6 @@ VLIB_CLI_COMMAND (show_ip6_neighbor_sorted_cmd_node, static) = { .function = ip6_neighbor_show_sorted, .short_help = "show ip6 neighbor-sorted", }; -/* *INDENT-ON* */ static ip_neighbor_vft_t ip_nbr_vfts[N_AF]; @@ -1017,8 +1089,8 @@ ip_neighbor_register (ip_address_family_t af, const ip_neighbor_vft_t * vft) } void -ip_neighbor_probe_dst (u32 sw_if_index, - ip_address_family_t af, const ip46_address_t * dst) +ip_neighbor_probe_dst (u32 sw_if_index, u32 thread_index, + ip_address_family_t af, const ip46_address_t *dst) { if (!vnet_sw_interface_is_admin_up (vnet_get_main (), sw_if_index)) return; @@ -1026,10 +1098,10 @@ ip_neighbor_probe_dst (u32 sw_if_index, switch (af) { case AF_IP6: - ip6_neighbor_probe_dst (sw_if_index, &dst->ip6); + ip6_neighbor_probe_dst (sw_if_index, thread_index, &dst->ip6); break; case AF_IP4: - ip4_neighbor_probe_dst (sw_if_index, &dst->ip4); + ip4_neighbor_probe_dst (sw_if_index, thread_index, &dst->ip4); break; } } @@ -1038,6 +1110,7 @@ void ip_neighbor_probe (const ip_adjacency_t * adj) { ip_neighbor_probe_dst (adj->rewrite_header.sw_if_index, + vlib_get_thread_index (), ip_address_family_from_fib_proto (adj->ia_nh_proto), &adj->sub_type.nbr.next_hop); } @@ -1055,13 +1128,11 @@ ip_neighbor_walk (ip_address_family_t af, vec_foreach (hash, ip_neighbor_db[af].ipndb_hash) { - /* *INDENT-OFF* */ hash_foreach (key, ipni, *hash, ({ if (WALK_STOP == cb (ipni, ctx)) break; })); - /* *INDENT-ON* */ } } else @@ -1072,13 +1143,11 @@ ip_neighbor_walk (ip_address_family_t af, return; hash = ip_neighbor_db[af].ipndb_hash[sw_if_index]; - /* *INDENT-OFF* */ hash_foreach (key, ipni, hash, ({ if (WALK_STOP == cb (ipni, ctx)) break; })); - /* *INDENT-ON* */ } } @@ -1157,14 +1226,12 @@ ip_neighbor_populate (ip_address_family_t af, u32 sw_if_index) format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index, format_ip_address_family, af); - /* *INDENT-OFF* */ pool_foreach (ipn, ip_neighbor_pool) { if (ip_neighbor_get_af(ipn) == af && ipn->ipn_key->ipnk_sw_if_index == sw_if_index) vec_add1 (ipnis, ipn - ip_neighbor_pool); } - /* *INDENT-ON* */ vec_foreach (ipni, ipnis) { @@ -1190,7 +1257,6 @@ ip_neighbor_flush (ip_address_family_t af, u32 sw_if_index) format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index, format_ip_address_family, af); - /* *INDENT-OFF* */ pool_foreach (ipn, ip_neighbor_pool) { if (ip_neighbor_get_af(ipn) == af && @@ -1198,13 +1264,12 @@ ip_neighbor_flush (ip_address_family_t af, u32 sw_if_index) ip_neighbor_is_dynamic (ipn)) vec_add1 (ipnis, ipn - ip_neighbor_pool); } - /* *INDENT-ON* */ vec_foreach (ipni, ipnis) ip_neighbor_destroy (ip_neighbor_get (*ipni)); vec_free (ipnis); } -static walk_rc_t +walk_rc_t ip_neighbor_mark_one (index_t ipni, void *ctx) { ip_neighbor_t *ipn; @@ -1291,8 +1356,8 @@ VNET_SW_INTERFACE_ADMIN_UP_DOWN_FUNCTION (ip_neighbor_interface_admin_change); * Remove any arp entries associated with the specified interface */ static clib_error_t * -ip_neighbor_delete_sw_interface (vnet_main_t * vnm, - u32 sw_if_index, u32 is_add) +ip_neighbor_add_del_sw_interface (vnet_main_t *vnm, u32 sw_if_index, + u32 is_add) { IP_NEIGHBOR_DBG ("interface-change: %U %s", format_vnet_sw_if_index_name, vnet_get_main (), @@ -1305,10 +1370,16 @@ ip_neighbor_delete_sw_interface (vnet_main_t * vnm, FOR_EACH_IP_ADDRESS_FAMILY (af) ip_neighbor_flush (af, sw_if_index); } + if (is_add) + { + ip_neighbor_alloc_ctr (&ip_neighbor_counters[AF_IP4], sw_if_index); + ip_neighbor_alloc_ctr (&ip_neighbor_counters[AF_IP6], sw_if_index); + } + return (NULL); } -VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip_neighbor_delete_sw_interface); +VNET_SW_INTERFACE_ADD_DEL_FUNCTION (ip_neighbor_add_del_sw_interface); typedef struct ip_neighbor_walk_covered_ctx_t_ { @@ -1366,14 +1437,12 @@ ip_neighbor_add_del_interface_address_v4 (ip4_main_t * im, * Flush the ARP cache of all entries covered by the address * that is being removed. */ - IP_NEIGHBOR_DBG ("addr-%d: %U, %U/%d", - (is_del ? "del" : "add"), - format_vnet_sw_if_index_name, vnet_get_main (), - sw_if_index, format_ip4_address, address, address_length); + IP_NEIGHBOR_DBG ("addr-%s: %U, %U/%d", (is_del ? "del" : "add"), + format_vnet_sw_if_index_name, vnet_get_main (), sw_if_index, + format_ip4_address, address, address_length); if (is_del) { - /* *INDENT-OFF* */ ip_neighbor_walk_covered_ctx_t ctx = { .addr = { .ip.ip4 = *address, @@ -1381,7 +1450,6 @@ ip_neighbor_add_del_interface_address_v4 (ip4_main_t * im, }, .length = address_length, }; - /* *INDENT-ON* */ index_t *ipni; ip_neighbor_walk (AF_IP4, sw_if_index, ip_neighbor_walk_covered, &ctx); @@ -1415,7 +1483,6 @@ ip_neighbor_add_del_interface_address_v6 (ip6_main_t * im, if (is_del) { - /* *INDENT-OFF* */ ip_neighbor_walk_covered_ctx_t ctx = { .addr = { .ip.ip6 = *address, @@ -1423,7 +1490,6 @@ ip_neighbor_add_del_interface_address_v6 (ip6_main_t * im, }, .length = address_length, }; - /* *INDENT-ON* */ index_t *ipni; ip_neighbor_walk (AF_IP6, sw_if_index, ip_neighbor_walk_covered, &ctx); @@ -1520,7 +1586,8 @@ ip_neighbour_age_out (index_t ipni, f64 now, f64 * wait) else { ip_neighbor_probe_dst (ip_neighbor_get_sw_if_index (ipn), - af, &ip_addr_46 (&ipn->ipn_key->ipnk_ip)); + vlib_get_thread_index (), af, + &ip_addr_46 (&ipn->ipn_key->ipnk_ip)); ipn->ipn_n_probes++; *wait = 1; @@ -1578,7 +1645,6 @@ ip_neighbor_age_loop (vlib_main_t * vm, head = pool_elt_at_index (ip_neighbor_elt_pool, ip_neighbor_list_head[af]); - /* *INDENT-OFF*/ /* the list is time sorted, newest first, so start from the back * and work forwards. Stop when we get to one that is alive */ restart: @@ -1603,7 +1669,6 @@ ip_neighbor_age_loop (vlib_main_t * vm, timeout = clib_min (wait, timeout); })); - /* *INDENT-ON* */ break; } case IP_NEIGHBOR_AGE_PROCESS_WAKEUP: @@ -1650,7 +1715,6 @@ ip6_neighbor_age_process (vlib_main_t * vm, return (ip_neighbor_age_loop (vm, rt, f, AF_IP6)); } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (ip4_neighbor_age_process_node,static) = { .function = ip4_neighbor_age_process, .type = VLIB_NODE_TYPE_PROCESS, @@ -1661,7 +1725,6 @@ VLIB_REGISTER_NODE (ip6_neighbor_age_process_node,static) = { .type = VLIB_NODE_TYPE_PROCESS, .name = "ip6-neighbor-age-process", }; -/* *INDENT-ON* */ int ip_neighbor_config (ip_address_family_t af, u32 limit, u32 age, bool recycle) @@ -1679,13 +1742,23 @@ ip_neighbor_config (ip_address_family_t af, u32 limit, u32 age, bool recycle) return (0); } +int +ip_neighbor_get_config (ip_address_family_t af, u32 *limit, u32 *age, + bool *recycle) +{ + *limit = ip_neighbor_db[af].ipndb_limit; + *age = ip_neighbor_db[af].ipndb_age; + *recycle = ip_neighbor_db[af].ipndb_recycle; + + return (0); +} + static clib_error_t * ip_neighbor_config_show (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { ip_address_family_t af; - /* *INDENT-OFF* */ FOR_EACH_IP_ADDRESS_FAMILY(af) { vlib_cli_output (vm, "%U:", format_ip_address_family, af); vlib_cli_output (vm, " limit:%d, age:%d, recycle:%d", @@ -1694,7 +1767,6 @@ ip_neighbor_config_show (vlib_main_t * vm, ip_neighbor_db[af].ipndb_recycle); } - /* *INDENT-ON* */ return (NULL); } @@ -1745,7 +1817,47 @@ done: return error; } -/* *INDENT-OFF* */ +static void +ip_neighbor_stats_show_one (vlib_main_t *vm, vnet_main_t *vnm, u32 sw_if_index) +{ + vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name, vnm, sw_if_index); + vlib_cli_output (vm, " arp:%U", format_ip_neighbor_counters, + &ip_neighbor_counters[AF_IP4], sw_if_index); + vlib_cli_output (vm, " nd: %U", format_ip_neighbor_counters, + &ip_neighbor_counters[AF_IP6], sw_if_index); +} + +static walk_rc_t +ip_neighbor_stats_show_cb (vnet_main_t *vnm, vnet_sw_interface_t *si, + void *ctx) +{ + ip_neighbor_stats_show_one (ctx, vnm, si->sw_if_index); + + return (WALK_CONTINUE); +} + +static clib_error_t * +ip_neighbor_stats_show (vlib_main_t *vm, unformat_input_t *input, + vlib_cli_command_t *cmd) +{ + vnet_main_t *vnm; + u32 sw_if_index; + + vnm = vnet_get_main (); + sw_if_index = ~0; + (void) unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index); + + if (~0 == sw_if_index) + { + vnet_sw_interface_walk (vnm, ip_neighbor_stats_show_cb, vm); + } + else + { + ip_neighbor_stats_show_one (vm, vnm, sw_if_index); + } + return (NULL); +} + VLIB_CLI_COMMAND (show_ip_neighbor_cfg_cmd_node, static) = { .path = "show ip neighbor-config", .function = ip_neighbor_config_show, @@ -1757,7 +1869,11 @@ VLIB_CLI_COMMAND (set_ip_neighbor_cfg_cmd_node, static) = { .short_help = "set ip neighbor-config ip4|ip6 [limit <limit>] [age <age>] " "[recycle|norecycle]", }; -/* *INDENT-ON* */ +VLIB_CLI_COMMAND (show_ip_neighbor_stats_cmd_node, static) = { + .path = "show ip neighbor-stats", + .function = ip_neighbor_stats_show, + .short_help = "show ip neighbor-stats [interface]", +}; static clib_error_t * ip_neighbor_init (vlib_main_t * vm) @@ -1797,12 +1913,10 @@ ip_neighbor_init (vlib_main_t * vm) return (NULL); } -/* *INDENT-OFF* */ VLIB_INIT_FUNCTION (ip_neighbor_init) = { .runs_after = VLIB_INITS("ip_main_init"), }; -/* *INDENT-ON* */ /* * fd.io coding-style-patch-verification: ON |