RB_GENERATE(ns_head, ns, entry, ns_compare)
-struct ns_head ns_tree = RB_INITIALIZER(&ns_tree);
+static struct ns_head ns_tree = RB_INITIALIZER(&ns_tree);
static struct ns *default_ns;
static int ns_current_ns_fd;
return ns_lookup_internal(ns_id);
}
-void ns_walk_func(int (*func)(struct ns *))
+void ns_walk_func(int (*func)(struct ns *,
+ void *param_in,
+ void **param_out),
+ void *param_in,
+ void **param_out)
{
struct ns *ns = NULL;
+ int ret;
- RB_FOREACH (ns, ns_head, &ns_tree)
- func(ns);
+ RB_FOREACH (ns, ns_head, &ns_tree) {
+ ret = func(ns, param_in, param_out);
+ if (ret == NS_WALK_STOP)
+ return;
+ }
}
const char *ns_get_name(struct ns *ns)
RB_GENERATE(ns_head, ns, entry, ns_compare)
-struct ns_head ns_tree = RB_INITIALIZER(&ns_tree);
+static struct ns_head ns_tree = RB_INITIALIZER(&ns_tree);
static inline int ns_compare(const struct ns *a, const struct ns *b)
{
RB_HEAD(ns_head, ns);
RB_PROTOTYPE(ns_head, ns, entry, ns_compare)
-extern struct ns_head ns_tree;
-
/*
* API for managing NETNS. eg from zebra daemon
* one want to manage the list of NETNS, etc...
extern char *ns_netns_pathname(struct vty *vty, const char *name);
/* Parse and execute a function on all the NETNS */
-extern void ns_walk_func(int (*func)(struct ns *));
+#define NS_WALK_CONTINUE 0
+#define NS_WALK_STOP 1
+
+extern void ns_walk_func(int (*func)(struct ns *,
+ void *,
+ void **),
+ void *param_in,
+ void **param_out);
/* API to get the NETNS name, from the ns pointer */
extern const char *ns_get_name(struct ns *ns);
vrf_terminate();
rtadv_terminate();
- ns_walk_func(zebra_ns_early_shutdown);
+ ns_walk_func(zebra_ns_early_shutdown, NULL, NULL);
zebra_ns_notify_close();
access_list_reset();
zlog_info("Zebra final shutdown");
/* Final shutdown of ns resources */
- ns_walk_func(zebra_ns_final_shutdown);
+ ns_walk_func(zebra_ns_final_shutdown, NULL, NULL);
/* Stop dplane thread and finish any cleanup */
zebra_dplane_shutdown();
return;
}
-static int zebra_evpn_map_vlan_zns(struct zebra_ns *zns,
- void *_in_param,
- void **_p_zevpn)
+static int zebra_evpn_map_vlan_ns(struct ns *ns,
+ void *_in_param,
+ void **_p_zevpn)
{
+ struct zebra_ns *zns = ns->info;
struct route_node *rn;
struct interface *br_if;
zebra_evpn_t **p_zevpn = (zebra_evpn_t **)_p_zevpn;
int found = 0;
if (!in_param)
- return ZNS_WALK_STOP;
+ return NS_WALK_STOP;
br_if = in_param->br_if;
zif = in_param->zif;
assert(zif);
}
}
if (!found)
- return ZNS_WALK_CONTINUE;
+ return NS_WALK_CONTINUE;
zevpn = zebra_evpn_lookup(vxl->vni);
if (p_zevpn)
*p_zevpn = zevpn;
- return ZNS_WALK_STOP;
+ return NS_WALK_STOP;
}
/*
in_param.zif = zif;
p_zevpn = &zevpn;
- zebra_ns_list_walk(zebra_evpn_map_vlan_zns,
- (void *)&in_param,
- (void **)p_zevpn);
+ ns_walk_func(zebra_evpn_map_vlan_ns,
+ (void *)&in_param,
+ (void **)p_zevpn);
return zevpn;
}
-static int zebra_evpn_from_svi_zns(struct zebra_ns *zns,
- void *_in_param,
- void **_p_zevpn)
+static int zebra_evpn_from_svi_ns(struct ns *ns,
+ void *_in_param,
+ void **_p_zevpn)
{
+ struct zebra_ns *zns = ns->info;
struct route_node *rn;
struct interface *br_if;
zebra_evpn_t **p_zevpn = (zebra_evpn_t **)_p_zevpn;
int found = 0;
if (!in_param)
- return ZNS_WALK_STOP;
+ return NS_WALK_STOP;
br_if = in_param->br_if;
zif = in_param->zif;
assert(zif);
}
if (!found)
- return ZNS_WALK_CONTINUE;
+ return NS_WALK_CONTINUE;
zevpn = zebra_evpn_lookup(vxl->vni);
if (p_zevpn)
*p_zevpn = zevpn;
- return ZNS_WALK_STOP;
+ return NS_WALK_STOP;
}
/*
in_param.zif = zif;
p_zevpn = &zevpn;
/* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
- zebra_ns_list_walk(zebra_evpn_from_svi_zns, (void *)&in_param,
- (void **)p_zevpn);
+ ns_walk_func(zebra_evpn_from_svi_ns, (void *)&in_param,
+ (void **)p_zevpn);
return zevpn;
}
/* During zebra shutdown, do partial cleanup while the async dataplane
* is still running.
*/
-int zebra_ns_early_shutdown(struct ns *ns)
+int zebra_ns_early_shutdown(struct ns *ns,
+ void *param_in __attribute__((unused)),
+ void **param_out __attribute__((unused)))
{
struct zebra_ns *zns = ns->info;
if (zns == NULL)
return 0;
- return zebra_ns_disable_internal(zns, false);
+ zebra_ns_disable_internal(zns, false);
+ return NS_WALK_CONTINUE;
}
/* During zebra shutdown, do final cleanup
* after all dataplane work is complete.
*/
-int zebra_ns_final_shutdown(struct ns *ns)
+int zebra_ns_final_shutdown(struct ns *ns,
+ void *param_in __attribute__((unused)),
+ void **param_out __attribute__((unused)))
{
struct zebra_ns *zns = ns->info;
kernel_terminate(zns, true);
- return 0;
+ return NS_WALK_CONTINUE;
}
int zebra_ns_init(const char *optional_default_name)
vty_out(vty, " netns %s\n", ns->name);
return 0;
}
-
-void zebra_ns_list_walk(int (*exec_for_each_zns)(struct zebra_ns *zns,
- void *param_in,
- void **param_out),
- void *param_in,
- void **param_out)
-{
- struct ns *ns;
- struct zebra_ns *zns;
- int ret;
-
- RB_FOREACH (ns, ns_head, &ns_tree) {
- zns = (struct zebra_ns *)ns->info;
- if (!zns && ns->ns_id == NS_DEFAULT)
- zns = zebra_ns_lookup(ns->ns_id);
- if (!zns)
- continue;
- ret = exec_for_each_zns(zns, param_in, param_out);
- if (ret == ZNS_WALK_STOP)
- return;
- }
-}
int zebra_ns_init(const char *optional_default_name);
int zebra_ns_enable(ns_id_t ns_id, void **info);
int zebra_ns_disabled(struct ns *ns);
-int zebra_ns_early_shutdown(struct ns *ns);
-int zebra_ns_final_shutdown(struct ns *ns);
-
+int zebra_ns_early_shutdown(struct ns *ns,
+ void *param_in __attribute__((unused)),
+ void **param_out __attribute__((unused)));
+int zebra_ns_final_shutdown(struct ns *ns,
+ void *param_in __attribute__((unused)),
+ void **param_out __attribute__((unused)));
int zebra_ns_config_write(struct vty *vty, struct ns *ns);
-#define ZNS_WALK_CONTINUE 0
-#define ZNS_WALK_STOP 1
-void zebra_ns_list_walk(int (*exec_for_each_zns)(struct zebra_ns *zns,
- void *param_in,
- void **param_out),
- void *param_in,
- void **param_out);
-
#ifdef __cplusplus
}
#endif
vty_out(vty, "\n");
}
-static int zvni_map_to_svi_ns(struct zebra_ns *zns,
+static int zvni_map_to_svi_ns(struct ns *ns,
void *_in_param,
void **_p_ifp)
{
+ struct zebra_ns *zns = ns->info;
struct route_node *rn;
struct zebra_from_svi_param *in_param =
(struct zebra_from_svi_param *)_in_param;
struct zebra_if *zif;
if (!in_param)
- return ZNS_WALK_STOP;
+ return NS_WALK_STOP;
/* TODO: Optimize with a hash. */
for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) {
if (vl->vid == in_param->vid) {
if (p_ifp)
*p_ifp = tmp_if;
- return ZNS_WALK_STOP;
+ return NS_WALK_STOP;
}
}
- return ZNS_WALK_CONTINUE;
+ return NS_WALK_CONTINUE;
}
/* Map to SVI on bridge corresponding to specified VLAN. This can be one
in_param.zif = NULL;
p_ifp = &tmp_if;
/* Identify corresponding VLAN interface. */
- zebra_ns_list_walk(zvni_map_to_svi_ns, (void *)&in_param,
- (void **)p_ifp);
+ ns_walk_func(zvni_map_to_svi_ns, (void *)&in_param,
+ (void **)p_ifp);
return tmp_if;
}
return zebra_evpn_del(zevpn);
}
-static int zevpn_build_hash_table_zns(struct zebra_ns *zns,
+static int zevpn_build_hash_table_zns(struct ns *ns,
void *param_in __attribute__((unused)),
void **param_out __attribute__((unused)))
{
+ struct zebra_ns *zns = ns->info;
struct route_node *rn;
struct interface *ifp;
struct zebra_vrf *zvrf;
zvrf = zebra_vrf_get_evpn();
if (!zvrf)
- return ZNS_WALK_STOP;
+ return NS_WALK_STOP;
/* Walk VxLAN interfaces and create EVPN hash. */
for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) {
zlog_debug(
"Failed to add EVPN hash, IF %s(%u) L2-VNI %u",
ifp->name, ifp->ifindex, vni);
- return ZNS_WALK_CONTINUE;
+ return NS_WALK_CONTINUE;
}
if (zevpn->local_vtep_ip.s_addr !=
}
}
}
- return ZNS_WALK_CONTINUE;
+ return NS_WALK_CONTINUE;
}
/*
static void zevpn_build_hash_table(void)
{
- zebra_ns_list_walk(zevpn_build_hash_table_zns,
- (void *)NULL,
- (void **)NULL);
+ ns_walk_func(zevpn_build_hash_table_zns,
+ (void *)NULL,
+ (void **)NULL);
}
/*
return 0;
}
-static int zl3vni_map_to_vxlan_if_zns(struct zebra_ns *zns,
- void *_zl3vni,
- void **_pifp)
+static int zl3vni_map_to_vxlan_if_ns(struct ns *ns,
+ void *_zl3vni,
+ void **_pifp)
{
+ struct zebra_ns *zns = ns->info;
zebra_l3vni_t *zl3vni = (zebra_l3vni_t *)_zl3vni;
struct route_node *rn = NULL;
struct interface *ifp = NULL;
zvrf = zebra_vrf_get_evpn();
if (!zvrf)
- return ZNS_WALK_STOP;
+ return NS_WALK_STOP;
/* loop through all vxlan-interface */
for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) {
zl3vni->local_vtep_ip = vxl->vtep_ip;
if (_pifp)
*_pifp = (void *)ifp;
- return ZNS_WALK_STOP;
+ return NS_WALK_STOP;
}
- return ZNS_WALK_CONTINUE;
+ return NS_WALK_CONTINUE;
}
struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni)
p_ifp = &ifp;
- zebra_ns_list_walk(zl3vni_map_to_vxlan_if_zns,
- (void *)zl3vni, (void **)p_ifp);
+ ns_walk_func(zl3vni_map_to_vxlan_if_ns,
+ (void *)zl3vni, (void **)p_ifp);
return ifp;
}
return;
}
-static int macfdb_read_zns(struct zebra_ns *zns,
- void *_in_param __attribute__((unused)),
- void **out_param __attribute__((unused)))
+static int macfdb_read_ns(struct ns *ns,
+ void *_in_param __attribute__((unused)),
+ void **out_param __attribute__((unused)))
{
+ struct zebra_ns *zns = ns->info;
+
macfdb_read(zns);
- return ZNS_WALK_CONTINUE;
+ return NS_WALK_CONTINUE;
}
-static int neigh_read_zns(struct zebra_ns *zns,
- void *_in_param __attribute__((unused)),
- void **out_param __attribute__((unused)))
+static int neigh_read_ns(struct ns *ns,
+ void *_in_param __attribute__((unused)),
+ void **out_param __attribute__((unused)))
{
+ struct zebra_ns *zns = ns->info;
+
neigh_read(zns);
- return ZNS_WALK_CONTINUE;
+ return NS_WALK_CONTINUE;
}
/*
zebra_evpn_gw_macip_add_for_evpn_hash, NULL);
/* Read the MAC FDB */
- zebra_ns_list_walk(macfdb_read_zns, NULL, NULL);
+ ns_walk_func(macfdb_read_ns, NULL, NULL);
/* Read neighbors */
- zebra_ns_list_walk(neigh_read_zns, NULL, NULL);
+ ns_walk_func(neigh_read_ns, NULL, NULL);
} else {
/* Cleanup VTEPs for all EVPNs - uninstall from
* kernel and free entries.