X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvnet%2Fip%2Fip_neighbor.c;h=7d1998d25b85a1caa2f2a14afdb945aa217c61bc;hb=5a5a86987b1b5bd792e9615c3f26471abd4babb4;hp=c97fb2b3cd47184c71d96c43d8133a2592d3e568;hpb=3c22affe8b1c60b4d34a387331251f44c3db4fd3;p=vpp.git diff --git a/src/vnet/ip/ip_neighbor.c b/src/vnet/ip/ip_neighbor.c index c97fb2b3cd4..7d1998d25b8 100644 --- a/src/vnet/ip/ip_neighbor.c +++ b/src/vnet/ip/ip_neighbor.c @@ -47,6 +47,79 @@ typedef struct static ip_neighbor_scan_config_t ip_neighbor_scan_conf; +int +ip_neighbor_add (const ip46_address_t * ip, + u8 is_ip6, + const u8 * mac, + u32 sw_if_index, + ip_neighbor_flags_t flags, u32 * stats_index) +{ + fib_protocol_t fproto; + vnet_link_t linkt; + int rv; + + /* + * there's no validation here of the ND/ARP entry being added. + * The expectation is that the FIB will ensure that nothing bad + * will come of adding bogus entries. + */ + if (is_ip6) + { + rv = vnet_set_ip6_ethernet_neighbor (vlib_get_main (), + sw_if_index, &ip->ip6, mac, 6, + (flags & IP_NEIGHBOR_FLAG_STATIC), + (flags & + IP_NEIGHBOR_FLAG_NO_ADJ_FIB)); + fproto = FIB_PROTOCOL_IP6; + linkt = VNET_LINK_IP6; + } + else + { + ethernet_arp_ip4_over_ethernet_address_t a = { + .ip4 = ip->ip4, + }; + + clib_memcpy (&a.ethernet, mac, 6); + + rv = vnet_arp_set_ip4_over_ethernet (vnet_get_main (), + sw_if_index, + &a, + (flags & IP_NEIGHBOR_FLAG_STATIC), + (flags & + IP_NEIGHBOR_FLAG_NO_ADJ_FIB)); + fproto = FIB_PROTOCOL_IP4; + linkt = VNET_LINK_IP4; + } + + if (0 == rv && stats_index) + *stats_index = adj_nbr_find (fproto, linkt, ip, sw_if_index); + + return (rv); +} + +int +ip_neighbor_del (const ip46_address_t * ip, u8 is_ip6, u32 sw_if_index) +{ + int rv; + + if (is_ip6) + { + rv = vnet_unset_ip6_ethernet_neighbor (vlib_get_main (), + sw_if_index, &ip->ip6); + } + else + { + ethernet_arp_ip4_over_ethernet_address_t a = { + .ip4 = ip->ip4, + }; + + rv = + vnet_arp_unset_ip4_over_ethernet (vnet_get_main (), sw_if_index, &a); + } + + return (rv); +} + void ip_neighbor_scan_enable_disable (ip_neighbor_scan_arg_t * arg) { @@ -134,8 +207,7 @@ ip_neighbor_scan (vlib_main_t * vm, f64 start_time, u32 start_idx, else { vnet_unset_ip6_ethernet_neighbor - (vm, n6->key.sw_if_index, &n6->key.ip6_address, - n6->link_layer_address, 6); + (vm, n6->key.sw_if_index, &n6->key.ip6_address); } } else if (delta >= cfg->scan_interval) @@ -143,10 +215,10 @@ ip_neighbor_scan (vlib_main_t * vm, f64 start_time, u32 start_idx, update_count[0]++; /* probe neighbor */ if (!is_ip6) - ip4_probe_neighbor (vm, &n4->ip4_address, n4->sw_if_index); + ip4_probe_neighbor (vm, &n4->ip4_address, n4->sw_if_index, 1); else ip6_probe_neighbor (vm, &n6->key.ip6_address, - n6->key.sw_if_index); + n6->key.sw_if_index, 1); } next_neighbor: @@ -240,7 +312,7 @@ ip_neighbor_scan_cli (vlib_main_t * vm, unformat_input_t * input, u32 interval = 0, time = 0, update = 0, delay = 0, stale = 0; ip_neighbor_scan_arg_t arg; - memset (&arg, 0, sizeof (arg)); + clib_memset (&arg, 0, sizeof (arg)); arg.mode = IP_SCAN_V46_NEIGHBORS; /* Get a line of input. */