#include <vnet/ip-neighbor/ip_neighbor_watch.h>
#include <vnet/ip/ip6_ll_table.h>
+#include <vnet/ip/ip46_address.h>
#include <vnet/fib/fib_table.h>
#include <vnet/adj/adj_mcast.h>
}
static void
-ip_neighbor_free (ip_neighbor_t * ipn)
+ip_neighbor_destroy (ip_neighbor_t * ipn)
{
ip_address_family_t af;
IP_NEIGHBOR_DBG ("free: %U", format_ip_neighbor,
ip_neighbor_get_index (ipn));
+ ip_neighbor_publish (ip_neighbor_get_index (ipn),
+ IP_NEIGHBOR_EVENT_REMOVED);
+
adj_nbr_walk_nh (ipn->ipn_key->ipnk_sw_if_index,
ip_address_family_to_fib_proto (af),
&ip_addr_46 (&ipn->ipn_key->ipnk_ip),
return (false);
elt = clib_llist_prev (ip_neighbor_elt_pool, ipne_anchor, head);
- ip_neighbor_free (ip_neighbor_get (elt->ipne_index));
+ ip_neighbor_destroy (ip_neighbor_get (elt->ipne_index));
return (true);
}
check_customers:
/* Customer(s) requesting event for this address? */
- ip_neighbor_publish (ip_neighbor_get_index (ipn));
+ ip_neighbor_publish (ip_neighbor_get_index (ipn), IP_NEIGHBOR_EVENT_ADDED);
if (stats_index)
*stats_index = adj_nbr_find (fproto,
if (NULL == ipn)
return (VNET_API_ERROR_NO_SUCH_ENTRY);
- ip_neighbor_free (ipn);
+ ip_neighbor_destroy (ipn);
return (0);
}
ip_neighbor_walk (af, sw_if_index, ip_neighbor_del_all_walk_cb, &ctx);
- vec_foreach (ipni, ctx.ipn_del) ip_neighbor_free (ip_neighbor_get (*ipni));
+ vec_foreach (ipni,
+ ctx.ipn_del) ip_neighbor_destroy (ip_neighbor_get (*ipni));
vec_free (ctx.ipn_del);
}
ip_neighbor_probe (adj);
}
break;
+ case IP_LOOKUP_NEXT_REWRITE:
+ /* Update of an existing rewrite adjacency happens e.g. when the
+ * interface's MAC address changes */
+ if (NULL != ipn)
+ ip_neighbor_mk_complete (ai, ipn);
+ break;
case IP_LOOKUP_NEXT_GLEAN:
case IP_LOOKUP_NEXT_BCAST:
case IP_LOOKUP_NEXT_MCAST:
case IP_LOOKUP_NEXT_DROP:
case IP_LOOKUP_NEXT_PUNT:
case IP_LOOKUP_NEXT_LOCAL:
- case IP_LOOKUP_NEXT_REWRITE:
case IP_LOOKUP_NEXT_MCAST_MIDCHAIN:
case IP_LOOKUP_NEXT_MIDCHAIN:
case IP_LOOKUP_NEXT_ICMP_ERROR:
ip_neighbor_t *ipn;
/* *INDENT-OFF* */
- pool_foreach (ipn, ip_neighbor_pool,
- ({
+ pool_foreach (ipn, ip_neighbor_pool)
+ {
if ((sw_if_index == ~0 ||
ipn->ipn_key->ipnk_sw_if_index == sw_if_index) &&
(N_AF == af ||
ip_neighbor_get_af(ipn) == af))
vec_add1 (ipnis, ip_neighbor_get_index(ipn));
- }));
+ }
/* *INDENT-ON* */
}
void
-ip_neighbor_probe_dst (const ip_adjacency_t * adj, const ip46_address_t * dst)
+ip_neighbor_probe_dst (u32 sw_if_index,
+ ip_address_family_t af, const ip46_address_t * dst)
{
- if (!vnet_sw_interface_is_admin_up (vnet_get_main (),
- adj->rewrite_header.sw_if_index))
+ if (!vnet_sw_interface_is_admin_up (vnet_get_main (), sw_if_index))
return;
- switch (adj->ia_nh_proto)
+ switch (af)
{
- case FIB_PROTOCOL_IP6:
- ip6_neighbor_probe_dst (adj, &dst->ip6);
+ case AF_IP6:
+ ip6_neighbor_probe_dst (sw_if_index, &dst->ip6);
break;
- case FIB_PROTOCOL_IP4:
- ip4_neighbor_probe_dst (adj, &dst->ip4);
- break;
- case FIB_PROTOCOL_MPLS:
- ASSERT (0);
+ case AF_IP4:
+ ip4_neighbor_probe_dst (sw_if_index, &dst->ip4);
break;
}
}
void
ip_neighbor_probe (const ip_adjacency_t * adj)
{
- ip_neighbor_probe_dst (adj, &adj->sub_type.nbr.next_hop);
+ ip_neighbor_probe_dst (adj->rewrite_header.sw_if_index,
+ ip_address_family_from_fib_proto (adj->ia_nh_proto),
+ &adj->sub_type.nbr.next_hop);
}
void
return -1;
}
-static void
-ip_neighbor_ethernet_change_mac (ethernet_main_t * em,
- u32 sw_if_index, uword opaque)
-{
- ip_neighbor_t *ipn;
- adj_index_t ai;
-
- IP_NEIGHBOR_DBG ("mac-change: %U",
- format_vnet_sw_if_index_name, vnet_get_main (),
- sw_if_index);
-
- /* *INDENT-OFF* */
- pool_foreach (ipn, ip_neighbor_pool,
- ({
- if (ipn->ipn_key->ipnk_sw_if_index == sw_if_index)
- adj_nbr_walk_nh (ipn->ipn_key->ipnk_sw_if_index,
- ip_address_family_to_fib_proto(ip_neighbor_get_af(ipn)),
- &ip_addr_46(&ipn->ipn_key->ipnk_ip),
- ip_neighbor_mk_complete_walk,
- ipn);
- }));
- /* *INDENT-ON* */
-
- ai = adj_glean_get (FIB_PROTOCOL_IP4, sw_if_index);
-
- if (ADJ_INDEX_INVALID != ai)
- adj_glean_update_rewrite (ai);
-}
-
void
ip_neighbor_populate (ip_address_family_t af, u32 sw_if_index)
{
sw_if_index, format_ip_address_family, af);
/* *INDENT-OFF* */
- pool_foreach (ipn, ip_neighbor_pool,
- ({
+ 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)
sw_if_index, format_ip_address_family, af);
/* *INDENT-OFF* */
- pool_foreach (ipn, ip_neighbor_pool,
- ({
+ pool_foreach (ipn, ip_neighbor_pool)
+ {
if (ip_neighbor_get_af(ipn) == af &&
ipn->ipn_key->ipnk_sw_if_index == sw_if_index &&
ip_neighbor_is_dynamic (ipn))
vec_add1 (ipnis, ipn - ip_neighbor_pool);
- }));
+ }
/* *INDENT-ON* */
- vec_foreach (ipni, ipnis) ip_neighbor_free (ip_neighbor_get (*ipni));
+ 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;
vec_foreach (ipni, ctx.ipnsc_stale)
{
- ip_neighbor_free (ip_neighbor_get (*ipni));
+ ip_neighbor_destroy (ip_neighbor_get (*ipni));
}
vec_free (ctx.ipnsc_stale);
}
ip_neighbor_walk (AF_IP4, sw_if_index, ip_neighbor_walk_covered, &ctx);
vec_foreach (ipni, ctx.ipnis)
- ip_neighbor_free (ip_neighbor_get (*ipni));
+ ip_neighbor_destroy (ip_neighbor_get (*ipni));
vec_free (ctx.ipnis);
}
ip_neighbor_walk (AF_IP6, sw_if_index, ip_neighbor_walk_covered, &ctx);
vec_foreach (ipni, ctx.ipnis)
- ip_neighbor_free (ip_neighbor_get (*ipni));
+ ip_neighbor_destroy (ip_neighbor_get (*ipni));
vec_free (ctx.ipnis);
}
}
else
{
- adj_index_t ai;
-
- ai = adj_glean_get (ip_address_family_to_fib_proto (af),
- ip_neighbor_get_sw_if_index (ipn));
-
- if (ADJ_INDEX_INVALID != ai)
- ip_neighbor_probe_dst (adj_get (ai),
- &ip_addr_46 (&ipn->ipn_key->ipnk_ip));
+ ip_neighbor_probe_dst (ip_neighbor_get_sw_if_index (ipn),
+ af, &ip_addr_46 (&ipn->ipn_key->ipnk_ip));
ipn->ipn_n_probes++;
*wait = 1;
else if (IP_NEIGHBOR_AGE_DEAD == res) {
/* the oldest neighbor is dead, pop it, then restart the walk
* again from the back */
- ip_neighbor_free (ip_neighbor_get(elt->ipne_index));
+ ip_neighbor_destroy (ip_neighbor_get(elt->ipne_index));
goto restart;
}
return (NULL);
}
+static clib_error_t *
+ip_neighbor_config_set (vlib_main_t *vm, unformat_input_t *input,
+ vlib_cli_command_t *cmd)
+{
+ unformat_input_t _line_input, *line_input = &_line_input;
+ clib_error_t *error = NULL;
+ ip_address_family_t af;
+ u32 limit, age;
+ bool recycle;
+
+ if (!unformat_user (input, unformat_line_input, line_input))
+ return 0;
+
+ if (!unformat (line_input, "%U", unformat_ip_address_family, &af))
+ {
+ error = unformat_parse_error (line_input);
+ goto done;
+ }
+
+ limit = ip_neighbor_db[af].ipndb_limit;
+ age = ip_neighbor_db[af].ipndb_age;
+ recycle = ip_neighbor_db[af].ipndb_recycle;
+
+ while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
+ {
+ if (unformat (line_input, "limit %u", &limit))
+ ;
+ else if (unformat (line_input, "age %u", &age))
+ ;
+ else if (unformat (line_input, "recycle"))
+ recycle = true;
+ else if (unformat (line_input, "norecycle"))
+ recycle = false;
+ else
+ {
+ error = unformat_parse_error (line_input);
+ goto done;
+ }
+ }
+
+ ip_neighbor_config (af, limit, age, recycle);
+
+done:
+ unformat_free (line_input);
+ return error;
+}
+
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (show_ip_neighbor_cfg_cmd_node, static) = {
.path = "show ip neighbor-config",
.function = ip_neighbor_config_show,
.short_help = "show ip neighbor-config",
};
+VLIB_CLI_COMMAND (set_ip_neighbor_cfg_cmd_node, static) = {
+ .path = "set ip neighbor-config",
+ .function = ip_neighbor_config_set,
+ .short_help = "set ip neighbor-config ip4|ip6 [limit <limit>] [age <age>] "
+ "[recycle|norecycle]",
+};
/* *INDENT-ON* */
static clib_error_t *
};
vec_add1 (ip6_main.table_bind_callbacks, cb);
}
- {
- ethernet_address_change_ctx_t ctx = {
- .function = ip_neighbor_ethernet_change_mac,
- .function_opaque = 0,
- };
- vec_add1 (ethernet_main.address_change_callbacks, ctx);
- }
-
ipn_logger = vlib_log_register_class ("ip", "neighbor");
ip_address_family_t af;