mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-12-31 12:14:11 +00:00
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 <sharpd@cumulusnetworks.com> Reviewed-by: Don Slice <dslice@cumulusnetworks.com>
This commit is contained in:
parent
dc1810914c
commit
a3d21ef32e
@ -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
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user