From a3358cacb8ea549599198bf821acf8a3a462df73 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sun, 6 Aug 2017 05:14:39 +0200 Subject: zebra: static: update on ifindex changes Whenever an interface is created or deleted in the system, we need to check whether we have static routes referencing that interface by name. If so, we need to [un]install these routes. This has the unfortunate side effect of making static routes with non-existent interfaces disappear from "show ip route", but I think that's acceptable (and I don't see a "good" fix for that). Signed-off-by: David Lamparter --- zebra/interface.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'zebra/interface.c') diff --git a/zebra/interface.c b/zebra/interface.c index 317cc722b4..13ac85d43d 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -48,6 +48,7 @@ #include "zebra/zebra_ptm.h" #include "zebra/rt_netlink.h" #include "zebra/interface.h" +#include "zebra/zebra_static.h" #define ZEBRA_PTM_SUPPORT @@ -520,6 +521,7 @@ if_add_update (struct interface *ifp) if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug ("interface %s vrf %u index %d becomes active.", ifp->name, ifp->vrf_id, ifp->ifindex); + static_ifindex_update(ifp, true); } else { @@ -695,6 +697,8 @@ if_delete_update (struct interface *ifp) zlog_debug ("interface %s vrf %u index %d is now inactive.", ifp->name, ifp->vrf_id, ifp->ifindex); + static_ifindex_update(ifp, false); + /* Delete connected routes from the kernel. */ if_delete_connected (ifp); -- cgit v1.2.3 From 06e0a0cb3c630c2b221fecd2f081348b36943a6e Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sun, 6 Aug 2017 07:50:18 +0200 Subject: zebra: vrf: remove VRF-move static route updating This was incorrectly implemented to begin with (it only re-added routes, but didn't remove them) and is now covered in static_ifindex_update. Signed-off-by: David Lamparter --- zebra/interface.c | 10 ++++------ zebra/zebra_vrf.c | 44 -------------------------------------------- zebra/zebra_vrf.h | 1 - 3 files changed, 4 insertions(+), 51 deletions(-) (limited to 'zebra/interface.c') diff --git a/zebra/interface.c b/zebra/interface.c index 13ac85d43d..c629dfb3f3 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -119,8 +119,6 @@ if_zebra_new_hook (struct interface *ifp) zebra_if->ipv4_subnets = route_table_init_with_delegate (&zebra_if_table_delegate); ifp->info = zebra_if; - - zebra_vrf_static_route_interface_fixup (ifp); return 0; } @@ -727,6 +725,8 @@ if_handle_vrf_change (struct interface *ifp, vrf_id_t vrf_id) old_vrf_id = ifp->vrf_id; + static_ifindex_update(ifp, false); + /* Uninstall connected routes. */ if_uninstall_connected (ifp); @@ -750,6 +750,8 @@ if_handle_vrf_change (struct interface *ifp, vrf_id_t vrf_id) /* Install connected routes (in new VRF). */ if_install_connected (ifp); + static_ifindex_update(ifp, true); + /* Due to connected route change, schedule RIB processing for both old * and new VRF. */ @@ -758,8 +760,6 @@ if_handle_vrf_change (struct interface *ifp, vrf_id_t vrf_id) ifp->vrf_id, ifp->name); rib_update (old_vrf_id, RIB_UPDATE_IF_CHANGE); rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE); - - zebra_vrf_static_route_interface_fixup (ifp); } static void @@ -866,8 +866,6 @@ if_up (struct interface *ifp) zlog_debug ("%u: IF %s up, scheduling RIB processing", ifp->vrf_id, ifp->name); rib_update (ifp->vrf_id, RIB_UPDATE_IF_CHANGE); - - zebra_vrf_static_route_interface_fixup (ifp); } /* Interface goes down. We have to manage different behavior of based diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index 6b36891056..889c57e6ff 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -98,50 +98,6 @@ zebra_vrf_new (struct vrf *vrf) return 0; } -/* - * Moving an interface amongst different vrf's - * causes the interface to get a new ifindex - * so we need to find static routes with - * the old ifindex and replace with new - * ifindex to insert back into the table - */ -void -zebra_vrf_static_route_interface_fixup (struct interface *ifp) -{ - afi_t afi; - safi_t safi; - struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id (ifp->vrf_id); - struct route_table *stable = NULL; - struct route_node *rn = NULL; - struct static_route *si = NULL; - - if (!zvrf) - return; - - for (afi = AFI_IP; afi < AFI_MAX; afi++) - { - for (safi = SAFI_UNICAST ; safi < SAFI_MAX ; safi++) - { - stable = zvrf->stable[afi][safi]; - if (stable) - for (rn = route_top (stable); rn; rn = route_next (rn)) - { - if (rn->info) - { - si = rn->info; - if ((strcmp (si->ifname, ifp->name) == 0) && - (si->ifindex != ifp->ifindex)) - { - si->ifindex = ifp->ifindex; - static_install_route (afi, safi, &rn->p, NULL, si); - } - } - } - } - } - -} - /* Callback upon enabling a VRF. */ static int zebra_vrf_enable (struct vrf *vrf) diff --git a/zebra/zebra_vrf.h b/zebra/zebra_vrf.h index 96d631d646..8864f13052 100644 --- a/zebra/zebra_vrf.h +++ b/zebra/zebra_vrf.h @@ -100,7 +100,6 @@ struct route_table * zebra_vrf_table_with_table_id (afi_t afi, safi_t safi, vrf_id_t vrf_id, u_int32_t table_id); -extern void zebra_vrf_static_route_interface_fixup (struct interface *ifp); extern void zebra_vrf_update_all (struct zserv *client); extern struct zebra_vrf *zebra_vrf_lookup_by_id (vrf_id_t vrf_id); extern struct zebra_vrf *zebra_vrf_lookup_by_name (const char *); -- cgit v1.2.3