From 154a3944e806936c766052d44e85921be6f3c5d5 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Thu, 22 Mar 2018 17:00:48 +0100 Subject: [PATCH 1/4] zebra: fix misc changes related to link updates with correct zns Because vrf with netns backend may be used, the correct zns must be found prior any modifications. Signed-off-by: Philippe Guibert --- zebra/interface.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zebra/interface.c b/zebra/interface.c index 01283f9122..7795d34d0b 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -867,6 +867,7 @@ void if_up(struct interface *ifp) { struct zebra_if *zif; struct interface *link_if; + struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id); zif = ifp->info; zif->up_count++; @@ -909,7 +910,7 @@ void if_up(struct interface *ifp) link_if = ifp; zebra_vxlan_svi_up(ifp, link_if); } else if (IS_ZEBRA_IF_VLAN(ifp)) { - link_if = if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT), + link_if = if_lookup_by_index_per_ns(zvrf->zns, zif->link_ifindex); if (link_if) zebra_vxlan_svi_up(ifp, link_if); @@ -922,6 +923,7 @@ void if_down(struct interface *ifp) { struct zebra_if *zif; struct interface *link_if; + struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id); zif = ifp->info; zif->down_count++; @@ -938,7 +940,7 @@ void if_down(struct interface *ifp) link_if = ifp; zebra_vxlan_svi_down(ifp, link_if); } else if (IS_ZEBRA_IF_VLAN(ifp)) { - link_if = if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT), + link_if = if_lookup_by_index_per_ns(zvrf->zns, zif->link_ifindex); if (link_if) zebra_vxlan_svi_down(ifp, link_if); From 5e280e568809c18589cc58d785c7f49e0bab3945 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Thu, 22 Mar 2018 18:00:10 +0100 Subject: [PATCH 2/4] zebra: move hash rules creation to the vrf_enable place The vrf netns usage makes a crash, when deleting vrf, due to the hash list of rules not initialised for non default VRF. Signed-off-by: Philippe Guibert --- zebra/zebra_ns.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index 29c179245b..d841bdeec4 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -135,6 +135,10 @@ int zebra_ns_enable(ns_id_t ns_id, void **info) zns->ns_id = ns_id; + zns->rules_hash = + hash_create_size(8, zebra_pbr_rules_hash_key, + zebra_pbr_rules_hash_equal, "Rules Hash"); + #if defined(HAVE_RTADV) rtadv_init(zns); #endif @@ -287,9 +291,6 @@ int zebra_ns_init(void) /* Default NS is activated */ zebra_ns_enable(ns_id, (void **)&dzns); - dzns->rules_hash = - hash_create_size(8, zebra_pbr_rules_hash_key, - zebra_pbr_rules_hash_equal, "Rules Hash"); if (vrf_is_backend_netns()) { ns_add_hook(NS_NEW_HOOK, zebra_ns_new); ns_add_hook(NS_ENABLE_HOOK, zebra_ns_enabled); From 0c902ba575789472612c0e18eaa6f5a27daec5b1 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Thu, 22 Mar 2018 18:02:00 +0100 Subject: [PATCH 3/4] zebra: handle the zebra netns delete notifications Upon a 'ip netns del' event, the associated vrf with netns backend is looked for, then the internal contexts are first disabled, then suppressed. Signed-off-by: Philippe Guibert --- lib/vrf.h | 1 + zebra/zebra_netns_notify.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/vrf.h b/lib/vrf.h index 617405a77e..eb35d97fe1 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -279,5 +279,6 @@ extern int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf, */ extern void vrf_disable(struct vrf *vrf); extern int vrf_enable(struct vrf *vrf); +extern void vrf_delete(struct vrf *vrf); #endif /*_ZEBRA_VRF_H*/ diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index 98b36dd10f..3486bfacdd 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -120,6 +120,32 @@ static int zebra_ns_continue_read(struct zebra_netns_info *zns_info, return 0; } +static int zebra_ns_delete(char *name) +{ + struct vrf *vrf = vrf_lookup_by_name(name); + struct ns *ns; + + if (!vrf) { + zlog_warn( + "NS notify : no VRF found using NS %s", + name); + return 0; + } + /* Clear configured flag and invoke delete. */ + UNSET_FLAG(vrf->status, VRF_CONFIGURED); + ns = (struct ns *)vrf->ns_ctxt; + /* the deletion order is the same + * as the one used when siging signal is received + */ + vrf_delete(vrf); + if (ns) + ns_delete(ns); + + zlog_info("NS notify : deleted VRF %s", name); + return 0; +} + + static int zebra_ns_ready_read(struct thread *t) { struct zebra_netns_info *zns_info = THREAD_ARG(t); @@ -178,8 +204,10 @@ static int zebra_ns_notify_read(struct thread *t) char *netnspath; struct zebra_netns_info *netnsinfo; - if (!(event->mask & IN_CREATE)) + if (!(event->mask & (IN_CREATE | IN_DELETE))) continue; + if (event->mask & (IN_DELETE)) + return zebra_ns_delete(event->name); netnspath = ns_netns_pathname(NULL, event->name); if (!netnspath) continue; @@ -234,7 +262,8 @@ void zebra_ns_notify_init(void) zlog_warn("NS notify init: failed to initialize inotify (%s)", safe_strerror(errno)); } - if (inotify_add_watch(fd_monitor, NS_RUN_DIR, IN_CREATE) < 0) { + if (inotify_add_watch(fd_monitor, NS_RUN_DIR, + IN_CREATE | IN_DELETE) < 0) { zlog_warn("NS notify watch: failed to add watch (%s)", safe_strerror(errno)); } From b00592cb797dc14e2df56e63d3df2433cf89a2f4 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Sat, 24 Mar 2018 06:49:21 +0100 Subject: [PATCH 4/4] Update zebra_netns_notify.c --- zebra/zebra_netns_notify.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index 3486bfacdd..f9beb32ac4 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -206,7 +206,7 @@ static int zebra_ns_notify_read(struct thread *t) if (!(event->mask & (IN_CREATE | IN_DELETE))) continue; - if (event->mask & (IN_DELETE)) + if (event->mask & IN_DELETE) return zebra_ns_delete(event->name); netnspath = ns_netns_pathname(NULL, event->name); if (!netnspath)