From: Donald Sharp Date: Tue, 10 May 2016 12:49:28 +0000 (-0400) Subject: zebra: Fix interface based static routes X-Git-Tag: frr-2.0-rc1~926 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=a3d21ef32e7d5ca5e01dceaef4f8c8a3fbb78498;p=matthieu%2Ffrr.git zebra: Fix interface based static routes This commit fixes interface based static routes. static routes are now stored and if an interface comes up it finds the route and installs it. Ticket: CM-10869 Signed-off-by: Donald Sharp Reviewed-by: Don Slice --- diff --git a/zebra/interface.c b/zebra/interface.c index 7d3d0851a7..2efcbac571 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -102,6 +102,8 @@ if_zebra_new_hook (struct interface *ifp) zebra_if->ipv4_subnets = route_table_init (); ifp->info = zebra_if; + + zebra_vrf_static_route_interface_fixup (ifp); return 0; } @@ -816,6 +818,8 @@ 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/rib.h b/zebra/rib.h index d41519042e..95c6a506c8 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -389,7 +389,8 @@ static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ extern int static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex, - u_char flags, u_short tag, u_char distance, struct zebra_vrf *zvrf); + const char *ifname, u_char flags, u_short tag, + u_char distance, struct zebra_vrf *zvrf); extern int static_delete_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex, @@ -413,8 +414,8 @@ extern struct route_table *rib_table_ipv6; extern int static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, - unsigned int ifindex, u_char flags, u_short tag, - u_char distance, struct zebra_vrf *zvrf); + unsigned int ifindex, const char *ifname, u_char flags, + u_short tag, u_char distance, struct zebra_vrf *zvrf); extern int rib_add_ipv6_multipath (struct prefix *, struct rib *, safi_t, diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 312a90bc5f..f4dbb3877d 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -3020,7 +3020,8 @@ static_uninstall_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ /* Add static route into static route configuration. */ int static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex, - u_char flags, u_short tag, u_char distance, struct zebra_vrf *zvrf) + const char *ifname, u_char flags, u_short tag, + u_char distance, struct zebra_vrf *zvrf) { u_char type = 0; struct route_node *rn; @@ -3075,7 +3076,7 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex, si->vrf_id = zvrf->vrf_id; si->ifindex = ifindex; if (si->ifindex) - strcpy(si->ifname, ifindex2ifname_vrf (si->ifindex, si->vrf_id)); + strcpy(si->ifname, ifname); if (gate) si->addr.ipv4 = *gate; @@ -3540,8 +3541,8 @@ rib_delete_ipv6 (int type, u_short instance, int flags, struct prefix_ipv6 *p, /* Add static route into static route configuration. */ int static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, - unsigned int ifindex, u_char flags, u_short tag, - u_char distance, struct zebra_vrf *zvrf) + unsigned int ifindex, const char *ifname, u_char flags, + u_short tag, u_char distance, struct zebra_vrf *zvrf) { struct route_node *rn; struct static_route *si; @@ -3594,6 +3595,8 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate, si->tag = tag; si->vrf_id = zvrf->vrf_id; si->ifindex = ifindex; + if (si->ifindex) + strcpy (si->ifname, ifname); switch (type) { diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index 04aa16f71b..382d5e4a52 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -345,12 +345,14 @@ zebra_vrf_list_lookup_by_name (const char *name) struct listnode *node; struct zebra_vrf *zvrf; - if (name) - for (ALL_LIST_ELEMENTS_RO (zvrf_list, node, zvrf)) - { - if (strcmp(name, zvrf->name) == 0) - return zvrf; - } + if (!name) + name = VRF_DEFAULT_NAME; + + for (ALL_LIST_ELEMENTS_RO (zvrf_list, node, zvrf)) + { + if (strcmp(name, zvrf->name) == 0) + return zvrf; + } return NULL; } diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 6da085b28f..1b5de1dc5d 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -38,26 +38,6 @@ extern int allow_delete; -static struct zebra_vrf * -zebra_vty_vrf_lookup (const char *vrf_id_str) -{ - struct vrf *vrf = NULL; - - if (vrf_id_str) - { - vrf = vrf_list_lookup_by_name (vrf_id_str); //Pending: create VRF if the given vrf doesnt exist? - } - else - { - vrf = vrf_list_lookup_by_name (VRF_DEFAULT_NAME); - } - - if (vrf) - return (struct zebra_vrf *)vrf->info; - - return NULL; -} - /* General fucntion for static route. */ static int zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str, @@ -74,6 +54,7 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str, u_short tag = 0; struct zebra_vrf *zvrf = NULL; unsigned int ifindex = 0; + const char *ifname = NULL; ret = str2prefix (dest_str, &p); if (ret <= 0) @@ -108,7 +89,7 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str, tag = atoi(tag_str); /* VRF id */ - zvrf = zebra_vty_vrf_lookup (vrf_id_str); + zvrf = zebra_vrf_list_lookup_by_name (vrf_id_str); if (!zvrf) { @@ -125,7 +106,7 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str, return CMD_WARNING; } if (add_cmd) - static_add_ipv4 (&p, NULL, ifindex, ZEBRA_FLAG_BLACKHOLE, tag, distance, zvrf); + static_add_ipv4 (&p, NULL, ifindex, ifname, ZEBRA_FLAG_BLACKHOLE, tag, distance, zvrf); else static_delete_ipv4 (&p, NULL, ifindex, tag, distance, zvrf); return CMD_SUCCESS; @@ -151,7 +132,7 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str, if (gate_str == NULL) { if (add_cmd) - static_add_ipv4 (&p, NULL, ifindex, flag, tag, distance, zvrf); + static_add_ipv4 (&p, NULL, ifindex, ifname, flag, tag, distance, zvrf); else static_delete_ipv4 (&p, NULL, ifindex, tag, distance, zvrf); @@ -165,15 +146,17 @@ zebra_static_ipv4 (struct vty *vty, int add_cmd, const char *dest_str, { struct interface *ifp = if_lookup_by_name_vrf (gate_str, zvrf->vrf_id); if (!ifp) - { + { vty_out (vty, "%% Unknown interface: %s%s", gate_str, VTY_NEWLINE); - return CMD_WARNING; - } - ifindex = ifp->ifindex; + ifindex = IFINDEX_DELETED; + } + else + ifindex = ifp->ifindex; + ifname = gate_str; } if (add_cmd) - static_add_ipv4 (&p, ifindex ? NULL : &gate, ifindex, flag, tag, distance, zvrf); + static_add_ipv4 (&p, ifindex ? NULL : &gate, ifindex, ifname, flag, tag, distance, zvrf); else static_delete_ipv4 (&p, ifindex ? NULL : &gate, ifindex, tag, distance, zvrf); @@ -3435,7 +3418,7 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str, ret = inet_pton (AF_INET6, gate_str, &gate_addr); /* VRF id */ - zvrf = zebra_vty_vrf_lookup (vrf_id_str); + zvrf = zebra_vrf_list_lookup_by_name (vrf_id_str); if (!zvrf) { @@ -3476,14 +3459,16 @@ static_ipv6_func (struct vty *vty, int add_cmd, const char *dest_str, if (!ifp) { vty_out (vty, "%% Malformed Interface name %s%s", gate_str, VTY_NEWLINE); - return CMD_WARNING; + ifindex = IFINDEX_DELETED; } - ifindex = ifp->ifindex; + else + ifindex = ifp->ifindex; + ifname = gate_str; } } if (add_cmd) - static_add_ipv6 (&p, type, gate, ifindex, flag, tag, distance, zvrf); + static_add_ipv6 (&p, type, gate, ifindex, ifname, flag, tag, distance, zvrf); else static_delete_ipv6 (&p, type, gate, ifindex, tag, distance, zvrf);