diff options
-rw-r--r-- | lib/netns_linux.c | 16 | ||||
-rw-r--r-- | lib/netns_other.c | 2 | ||||
-rw-r--r-- | lib/ns.h | 11 | ||||
-rw-r--r-- | zebra/main.c | 4 | ||||
-rw-r--r-- | zebra/zebra_ns.c | 35 | ||||
-rw-r--r-- | zebra/zebra_ns.h | 17 | ||||
-rw-r--r-- | zebra/zebra_vxlan.c | 98 |
7 files changed, 93 insertions, 90 deletions
diff --git a/lib/netns_linux.c b/lib/netns_linux.c index 82e0c4d8e..e1c0159fc 100644 --- a/lib/netns_linux.c +++ b/lib/netns_linux.c @@ -51,7 +51,7 @@ static struct ns *ns_lookup_name_internal(const char *name); 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; @@ -379,12 +379,20 @@ struct ns *ns_lookup(ns_id_t ns_id) 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) diff --git a/lib/netns_other.c b/lib/netns_other.c index b0aae4f8d..740d2b621 100644 --- a/lib/netns_other.c +++ b/lib/netns_other.c @@ -34,7 +34,7 @@ static inline int ns_compare(const struct ns *ns, const struct ns *ns2); 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) { @@ -76,8 +76,6 @@ struct ns { 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... @@ -127,7 +125,14 @@ int ns_socket(int domain, int type, int protocol, ns_id_t ns_id); 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); diff --git a/zebra/main.c b/zebra/main.c index e230a744f..f447e9aa0 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -177,7 +177,7 @@ static void sigint(void) 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(); @@ -208,7 +208,7 @@ int zebra_finalize(struct thread *dummy) 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(); diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index 13864cd42..6462daf68 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -153,20 +153,25 @@ static int zebra_ns_disable_internal(struct zebra_ns *zns, bool complete) /* 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; @@ -175,7 +180,7 @@ int zebra_ns_final_shutdown(struct ns *ns) kernel_terminate(zns, true); - return 0; + return NS_WALK_CONTINUE; } int zebra_ns_init(const char *optional_default_name) @@ -233,25 +238,3 @@ int zebra_ns_config_write(struct vty *vty, struct ns *ns) 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; - } -} diff --git a/zebra/zebra_ns.h b/zebra/zebra_ns.h index fa2fd47c2..f7d1f4078 100644 --- a/zebra/zebra_ns.h +++ b/zebra/zebra_ns.h @@ -67,19 +67,14 @@ struct zebra_ns *zebra_ns_lookup(ns_id_t ns_id); 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 diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index 4d2dc85b7..244b398e4 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -3535,10 +3535,11 @@ struct zvni_from_svi_param { vlanid_t vid; }; -static int zvni_map_vlan_zns(struct zebra_ns *zns, - void *_in_param, - void **_p_zvni) +static int zvni_map_vlan_ns(struct ns *ns, + void *_in_param, + void **_p_zvni) { + struct zebra_ns *zns = ns->info; struct route_node *rn; struct interface *br_if; zebra_vni_t **p_zvni = (zebra_vni_t **)_p_zvni; @@ -3551,7 +3552,7 @@ static int zvni_map_vlan_zns(struct zebra_ns *zns, 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); @@ -3580,12 +3581,12 @@ static int zvni_map_vlan_zns(struct zebra_ns *zns, } } if (!found) - return ZNS_WALK_CONTINUE; + return NS_WALK_CONTINUE; zvni = zvni_lookup(vxl->vni); if (p_zvni) *p_zvni = zvni; - return ZNS_WALK_STOP; + return NS_WALK_STOP; } /* @@ -3611,15 +3612,17 @@ static zebra_vni_t *zvni_map_vlan(struct interface *ifp, in_param.zif = zif; p_zvni = &zvni; - zebra_ns_list_walk(zvni_map_vlan_zns, (void *)&in_param, - (void **)p_zvni); + ns_walk_func(zvni_map_vlan_ns, + (void *)&in_param, + (void **)p_zvni); return zvni; } -static int zvni_from_svi_zns(struct zebra_ns *zns, - void *_in_param, - void **_p_zvni) +static int zvni_from_svi_ns(struct ns *ns, + void *_in_param, + void **_p_zvni) { + struct zebra_ns *zns = ns->info; struct route_node *rn; struct interface *br_if; zebra_vni_t **p_zvni = (zebra_vni_t **)_p_zvni; @@ -3632,7 +3635,7 @@ static int zvni_from_svi_zns(struct zebra_ns *zns, 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); @@ -3660,12 +3663,12 @@ static int zvni_from_svi_zns(struct zebra_ns *zns, } if (!found) - return ZNS_WALK_CONTINUE; + return NS_WALK_CONTINUE; zvni = zvni_lookup(vxl->vni); if (p_zvni) *p_zvni = zvni; - return ZNS_WALK_STOP; + return NS_WALK_STOP; } /* @@ -3711,15 +3714,17 @@ static zebra_vni_t *zvni_from_svi(struct interface *ifp, in_param.zif = zif; p_zvni = &zvni; /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */ - zebra_ns_list_walk(zvni_from_svi_zns, (void *)&in_param, - (void **)p_zvni); + ns_walk_func(zvni_from_svi_ns, + (void *)&in_param, + (void **)p_zvni); return zvni; } -static int zvni_map_to_svi_zns(struct zebra_ns *zns, - void *_in_param, - void **_p_ifp) +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 zvni_from_svi_param *in_param = (struct zvni_from_svi_param *)_in_param; @@ -3729,7 +3734,7 @@ static int zvni_map_to_svi_zns(struct zebra_ns *zns, 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)) { @@ -3746,10 +3751,10 @@ static int zvni_map_to_svi_zns(struct zebra_ns *zns, 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 @@ -3784,8 +3789,9 @@ static struct interface *zvni_map_to_svi(vlanid_t vid, struct interface *br_if) in_param.zif = NULL; p_ifp = &tmp_if; /* Identify corresponding VLAN interface. */ - zebra_ns_list_walk(zvni_map_to_svi_zns, (void *)&in_param, - (void **)p_ifp); + ns_walk_func(zvni_map_to_svi_ns, + (void *)&in_param, + (void **)p_ifp); return tmp_if; } @@ -4206,10 +4212,11 @@ static int zvni_send_del_to_client(vni_t vni) return zserv_send_message(client, s); } -static int zvni_build_hash_table_zns(struct zebra_ns *zns, +static int zvni_build_hash_table_ns(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; @@ -4217,7 +4224,7 @@ static int zvni_build_hash_table_zns(struct zebra_ns *zns, zvrf = zebra_vrf_get_evpn(); if (!zvrf) - return ZNS_WALK_STOP; + return NS_WALK_STOP; /* Walk VxLAN interfaces and create VNI hash. */ for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { @@ -4313,7 +4320,7 @@ static int zvni_build_hash_table_zns(struct zebra_ns *zns, zlog_debug( "Failed to add VNI hash, IF %s(%u) L2-VNI %u", ifp->name, ifp->ifindex, vni); - return ZNS_WALK_CONTINUE; + return NS_WALK_CONTINUE; } if (zvni->local_vtep_ip.s_addr != @@ -4350,7 +4357,7 @@ static int zvni_build_hash_table_zns(struct zebra_ns *zns, } } } - return ZNS_WALK_CONTINUE; + return NS_WALK_CONTINUE; } /* @@ -4360,9 +4367,9 @@ static int zvni_build_hash_table_zns(struct zebra_ns *zns, static void zvni_build_hash_table(void) { - zebra_ns_list_walk(zvni_build_hash_table_zns, - (void *)NULL, - (void **)NULL); + ns_walk_func(zvni_build_hash_table_ns, + (void *)NULL, + (void **)NULL); } /* @@ -5147,10 +5154,11 @@ static int zl3vni_del(zebra_l3vni_t *zl3vni) return 0; } -static int zl3vni_map_to_vxlan_if_zns(struct zebra_ns *zns, +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; @@ -5159,7 +5167,7 @@ static int zl3vni_map_to_vxlan_if_zns(struct zebra_ns *zns, 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)) { @@ -5193,10 +5201,10 @@ static int zl3vni_map_to_vxlan_if_zns(struct zebra_ns *zns, 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) @@ -5206,8 +5214,8 @@ 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; } @@ -9775,20 +9783,24 @@ stream_failure: return; } -static int macfdb_read_zns(struct zebra_ns *zns, +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, +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; } /* @@ -9839,10 +9851,10 @@ void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS) 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 VNIs - uninstall from * kernel and free entries. |