summaryrefslogtreecommitdiff
path: root/zebra/zebra_rib.c
diff options
context:
space:
mode:
Diffstat (limited to 'zebra/zebra_rib.c')
-rw-r--r--zebra/zebra_rib.c162
1 files changed, 44 insertions, 118 deletions
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index d5b1f82343..1859661c13 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -147,8 +147,6 @@ rib_copy_nexthops (struct rib *rib, struct nexthop *nh)
nexthop->flags = nh->flags;
nexthop->type = nh->type;
nexthop->ifindex = nh->ifindex;
- if (nh->ifname)
- nexthop->ifname = XSTRDUP(0, nh->ifname);
memcpy(&(nexthop->gate), &(nh->gate), sizeof(union g_addr));
memcpy(&(nexthop->src), &(nh->src), sizeof(union g_addr));
rib_nexthop_add(rib, nexthop);
@@ -186,20 +184,6 @@ rib_nexthop_ifindex_add (struct rib *rib, unsigned int ifindex)
}
struct nexthop *
-rib_nexthop_ifname_add (struct rib *rib, char *ifname)
-{
- struct nexthop *nexthop;
-
- nexthop = nexthop_new();
- nexthop->type = NEXTHOP_TYPE_IFNAME;
- nexthop->ifname = XSTRDUP (0, ifname);
-
- rib_nexthop_add (rib, nexthop);
-
- return nexthop;
-}
-
-struct nexthop *
rib_nexthop_ipv4_add (struct rib *rib, struct in_addr *ipv4, struct in_addr *src)
{
struct nexthop *nexthop;
@@ -253,22 +237,6 @@ rib_nexthop_ipv6_add (struct rib *rib, struct in6_addr *ipv6)
}
struct nexthop *
-rib_nexthop_ipv6_ifname_add (struct rib *rib, struct in6_addr *ipv6,
- char *ifname)
-{
- struct nexthop *nexthop;
-
- nexthop = nexthop_new();
- nexthop->type = NEXTHOP_TYPE_IPV6_IFNAME;
- nexthop->gate.ipv6 = *ipv6;
- nexthop->ifname = XSTRDUP (0, ifname);
-
- rib_nexthop_add (rib, nexthop);
-
- return nexthop;
-}
-
-struct nexthop *
rib_nexthop_ipv6_ifindex_add (struct rib *rib, struct in6_addr *ipv6,
unsigned int ifindex)
{
@@ -445,8 +413,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set,
SET_FLAG (resolved_hop->flags, NEXTHOP_FLAG_ACTIVE);
/* If the resolving route specifies a gateway, use it */
if (newhop->type == NEXTHOP_TYPE_IPV4
- || newhop->type == NEXTHOP_TYPE_IPV4_IFINDEX
- || newhop->type == NEXTHOP_TYPE_IPV4_IFNAME)
+ || newhop->type == NEXTHOP_TYPE_IPV4_IFINDEX)
{
resolved_hop->type = newhop->type;
resolved_hop->gate.ipv4 = newhop->gate.ipv4;
@@ -468,8 +435,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set,
*
* On Linux, we have to set the onlink netlink flag because
* otherwise, the kernel won't accept the route. */
- if (newhop->type == NEXTHOP_TYPE_IFINDEX
- || newhop->type == NEXTHOP_TYPE_IFNAME)
+ if (newhop->type == NEXTHOP_TYPE_IFINDEX)
{
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
@@ -497,8 +463,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set,
SET_FLAG (resolved_hop->flags, NEXTHOP_FLAG_ACTIVE);
/* If the resolving route specifies a gateway, use it */
if (newhop->type == NEXTHOP_TYPE_IPV4
- || newhop->type == NEXTHOP_TYPE_IPV4_IFINDEX
- || newhop->type == NEXTHOP_TYPE_IPV4_IFNAME)
+ || newhop->type == NEXTHOP_TYPE_IPV4_IFINDEX)
{
resolved_hop->type = newhop->type;
resolved_hop->gate.ipv4 = newhop->gate.ipv4;
@@ -521,8 +486,7 @@ nexthop_active_ipv4 (struct rib *rib, struct nexthop *nexthop, int set,
* On Linux, we have to set the onlink netlink flag because
* otherwise, the kernel won't accept the route.
*/
- if (newhop->type == NEXTHOP_TYPE_IFINDEX
- || newhop->type == NEXTHOP_TYPE_IFNAME)
+ if (newhop->type == NEXTHOP_TYPE_IFINDEX)
{
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
@@ -656,8 +620,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set,
/* See nexthop_active_ipv4 for a description how the
* resolved nexthop is constructed. */
if (newhop->type == NEXTHOP_TYPE_IPV6
- || newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX
- || newhop->type == NEXTHOP_TYPE_IPV6_IFNAME)
+ || newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX)
{
resolved_hop->type = newhop->type;
resolved_hop->gate.ipv6 = newhop->gate.ipv6;
@@ -669,8 +632,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set,
}
}
- if (newhop->type == NEXTHOP_TYPE_IFINDEX
- || newhop->type == NEXTHOP_TYPE_IFNAME)
+ if (newhop->type == NEXTHOP_TYPE_IFINDEX)
{
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
@@ -699,8 +661,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set,
/* See nexthop_active_ipv4 for a description how the
* resolved nexthop is constructed. */
if (newhop->type == NEXTHOP_TYPE_IPV6
- || newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX
- || newhop->type == NEXTHOP_TYPE_IPV6_IFNAME)
+ || newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX)
{
resolved_hop->type = newhop->type;
resolved_hop->gate.ipv6 = newhop->gate.ipv6;
@@ -712,8 +673,7 @@ nexthop_active_ipv6 (struct rib *rib, struct nexthop *nexthop, int set,
}
}
- if (newhop->type == NEXTHOP_TYPE_IFINDEX
- || newhop->type == NEXTHOP_TYPE_IFNAME)
+ if (newhop->type == NEXTHOP_TYPE_IFINDEX)
{
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
@@ -1020,23 +980,6 @@ nexthop_active_check (struct route_node *rn, struct rib *rib,
else
UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
break;
- case NEXTHOP_TYPE_IPV6_IFNAME:
- family = AFI_IP6;
- case NEXTHOP_TYPE_IFNAME:
- ifp = if_lookup_by_name_vrf (nexthop->ifname, rib->vrf_id);
- if (ifp && if_is_operative(ifp))
- {
- if (set)
- nexthop->ifindex = ifp->ifindex;
- SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
- }
- else
- {
- if (set)
- nexthop->ifindex = 0;
- UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
- }
- break;
case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX:
family = AFI_IP;
@@ -1108,7 +1051,8 @@ nexthop_active_check (struct route_node *rn, struct rib *rib,
{
inet_ntop (rn->p.family, &rn->p.u.prefix, buf, sizeof (buf));
zlog_debug("%u:%s/%d: Filtering out with NH out %s due to route map",
- rib->vrf_id, buf, rn->p.prefixlen, nexthop->ifname);
+ rib->vrf_id, buf, rn->p.prefixlen,
+ ifindex2ifname_vrf (nexthop->ifindex, rib->vrf_id));
}
UNSET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
}
@@ -2602,8 +2546,8 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro
nh_p.u.prefix4 = si->addr.ipv4;
zebra_register_rnh_static_nh(&nh_p, rn);
break;
- case STATIC_IPV4_IFNAME:
- rib_nexthop_ifname_add (rib, si->ifname);
+ case STATIC_IFINDEX:
+ rib_nexthop_ifindex_add (rib, si->ifindex);
break;
case STATIC_IPV4_BLACKHOLE:
rib_nexthop_blackhole_add (rib);
@@ -2615,11 +2559,8 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro
nh_p.u.prefix6 = si->addr.ipv6;
zebra_register_rnh_static_nh(&nh_p, rn);
break;
- case STATIC_IPV6_IFNAME:
- rib_nexthop_ifname_add (rib, si->ifname);
- break;
- case STATIC_IPV6_GATEWAY_IFNAME:
- rib_nexthop_ipv6_ifname_add (rib, &si->addr.ipv6, si->ifname);
+ case STATIC_IPV6_GATEWAY_IFINDEX:
+ rib_nexthop_ipv6_ifindex_add (rib, &si->addr.ipv6, si->ifindex);
break;
}
@@ -2663,8 +2604,8 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro
nh_p.u.prefix4 = si->addr.ipv4;
zebra_register_rnh_static_nh(&nh_p, rn);
break;
- case STATIC_IPV4_IFNAME:
- rib_nexthop_ifname_add (rib, si->ifname);
+ case STATIC_IFINDEX:
+ rib_nexthop_ifindex_add (rib, si->ifindex);
break;
case STATIC_IPV4_BLACKHOLE:
rib_nexthop_blackhole_add (rib);
@@ -2676,11 +2617,8 @@ static_install_route (afi_t afi, safi_t safi, struct prefix *p, struct static_ro
nh_p.u.prefix6 = si->addr.ipv6;
zebra_register_rnh_static_nh(&nh_p, rn);
break;
- case STATIC_IPV6_IFNAME:
- rib_nexthop_ifname_add (rib, si->ifname);
- break;
- case STATIC_IPV6_GATEWAY_IFNAME:
- rib_nexthop_ipv6_ifname_add (rib, &si->addr.ipv6, si->ifname);
+ case STATIC_IPV6_GATEWAY_IFINDEX:
+ rib_nexthop_ipv6_ifindex_add (rib, &si->addr.ipv6, si->ifindex);
break;
}
@@ -2718,9 +2656,9 @@ static_nexthop_same (struct nexthop *nexthop, struct static_route *si)
&& si->type == STATIC_IPV4_GATEWAY
&& IPV4_ADDR_SAME (&nexthop->gate.ipv4, &si->addr.ipv4))
return 1;
- if (nexthop->type == NEXTHOP_TYPE_IFNAME
- && si->type == STATIC_IPV4_IFNAME
- && strcmp (nexthop->ifname, si->ifname) == 0)
+ if (nexthop->type == NEXTHOP_TYPE_IFINDEX
+ && si->type == STATIC_IFINDEX
+ && nexthop->ifindex == si->ifindex)
return 1;
if (nexthop->type == NEXTHOP_TYPE_BLACKHOLE
&& si->type == STATIC_IPV4_BLACKHOLE)
@@ -2729,14 +2667,10 @@ static_nexthop_same (struct nexthop *nexthop, struct static_route *si)
&& si->type == STATIC_IPV6_GATEWAY
&& IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->addr.ipv6))
return 1;
- if (nexthop->type == NEXTHOP_TYPE_IFNAME
- && si->type == STATIC_IPV6_IFNAME
- && strcmp (nexthop->ifname, si->ifname) == 0)
- return 1;
- if (nexthop->type == NEXTHOP_TYPE_IPV6_IFNAME
- && si->type == STATIC_IPV6_GATEWAY_IFNAME
+ if (nexthop->type == NEXTHOP_TYPE_IPV6_IFINDEX
+ && si->type == STATIC_IPV6_GATEWAY_IFINDEX
&& IPV6_ADDR_SAME (&nexthop->gate.ipv6, &si->addr.ipv6)
- && strcmp (nexthop->ifname, si->ifname) == 0)
+ && nexthop->ifindex == si->ifindex)
return 1;
return 0;
}
@@ -2847,7 +2781,7 @@ 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, const char *ifname,
+static_add_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex,
u_char flags, u_short tag, u_char distance, vrf_id_t vrf_id)
{
u_char type = 0;
@@ -2868,8 +2802,8 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
/* Make flags. */
if (gate)
type = STATIC_IPV4_GATEWAY;
- else if (ifname)
- type = STATIC_IPV4_IFNAME;
+ else if (ifindex)
+ type = STATIC_IFINDEX;
else
type = STATIC_IPV4_BLACKHOLE;
@@ -2878,7 +2812,7 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
{
if (type == si->type
&& (! gate || IPV4_ADDR_SAME (gate, &si->addr.ipv4))
- && (! ifname || strcmp (ifname, si->ifname) == 0))
+ && (! ifindex || ifindex == si->ifindex))
{
if ((distance == si->distance) && (tag == si->tag))
{
@@ -2892,7 +2826,7 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
/* Distance or tag changed. */
if (update)
- static_delete_ipv4 (p, gate, ifname, update->tag, update->distance, vrf_id);
+ static_delete_ipv4 (p, gate, ifindex, update->tag, update->distance, vrf_id);
/* Make new static route structure. */
si = XCALLOC (MTYPE_STATIC_ROUTE, sizeof (struct static_route));
@@ -2902,11 +2836,10 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
si->flags = flags;
si->tag = tag;
si->vrf_id = vrf_id;
+ si->ifindex = ifindex;
if (gate)
si->addr.ipv4 = *gate;
- if (ifname)
- si->ifname = XSTRDUP (0, ifname);
/* Add new static route information to the tree with sort by
distance value and gateway address. */
@@ -2943,7 +2876,7 @@ static_add_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
/* Delete static route from static route configuration. */
int
-static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
+static_delete_ipv4 (struct prefix *p, struct in_addr *gate, unsigned int ifindex,
u_short tag, u_char distance, vrf_id_t vrf_id)
{
u_char type = 0;
@@ -2964,8 +2897,8 @@ static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
/* Make flags. */
if (gate)
type = STATIC_IPV4_GATEWAY;
- else if (ifname)
- type = STATIC_IPV4_IFNAME;
+ else if (ifindex)
+ type = STATIC_IFINDEX;
else
type = STATIC_IPV4_BLACKHOLE;
@@ -2973,7 +2906,7 @@ static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
for (si = rn->info; si; si = si->next)
if (type == si->type
&& (! gate || IPV4_ADDR_SAME (gate, &si->addr.ipv4))
- && (! ifname || strcmp (ifname, si->ifname) == 0)
+ && (! ifindex || ifindex == si->ifindex)
&& (! tag || (tag == si->tag)))
break;
@@ -2997,8 +2930,6 @@ static_delete_ipv4 (struct prefix *p, struct in_addr *gate, const char *ifname,
route_unlock_node (rn);
/* Free static route configuration. */
- if (ifname)
- XFREE (0, si->ifname);
XFREE (MTYPE_STATIC_ROUTE, si);
route_unlock_node (rn);
@@ -3395,7 +3326,7 @@ 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,
- const char *ifname, u_char flags, u_short tag,
+ unsigned int ifindex, u_char flags, u_short tag,
u_char distance, vrf_id_t vrf_id)
{
struct route_node *rn;
@@ -3410,11 +3341,11 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
return -1;
if (!gate &&
- (type == STATIC_IPV6_GATEWAY || type == STATIC_IPV6_GATEWAY_IFNAME))
+ (type == STATIC_IPV6_GATEWAY || type == STATIC_IPV6_GATEWAY_IFINDEX))
return -1;
- if (!ifname &&
- (type == STATIC_IPV6_GATEWAY_IFNAME || type == STATIC_IPV6_IFNAME))
+ if (!ifindex &&
+ (type == STATIC_IPV6_GATEWAY_IFINDEX || type == STATIC_IFINDEX))
return -1;
/* Lookup static route prefix. */
@@ -3425,7 +3356,7 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
{
if (type == si->type
&& (! gate || IPV6_ADDR_SAME (gate, &si->addr.ipv6))
- && (! ifname || strcmp (ifname, si->ifname) == 0))
+ && (! ifindex || ifindex == si->ifindex))
{
if ((distance == si->distance) && (tag == si->tag))
{
@@ -3439,7 +3370,7 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
/* Distance or tag changed. */
if (update)
- static_delete_ipv6 (p, type, gate, ifname, update->tag, update->distance, vrf_id);
+ static_delete_ipv6 (p, type, gate, ifindex, update->tag, update->distance, vrf_id);
/* Make new static route structure. */
si = XCALLOC (MTYPE_STATIC_ROUTE, sizeof (struct static_route));
@@ -3449,18 +3380,15 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
si->flags = flags;
si->tag = tag;
si->vrf_id = vrf_id;
+ si->ifindex = ifindex;
switch (type)
{
case STATIC_IPV6_GATEWAY:
si->addr.ipv6 = *gate;
break;
- case STATIC_IPV6_IFNAME:
- si->ifname = XSTRDUP (0, ifname);
- break;
- case STATIC_IPV6_GATEWAY_IFNAME:
+ case STATIC_IPV6_GATEWAY_IFINDEX:
si->addr.ipv6 = *gate;
- si->ifname = XSTRDUP (0, ifname);
break;
}
@@ -3493,7 +3421,7 @@ static_add_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
/* Delete static route from static route configuration. */
int
static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
- const char *ifname, u_short tag, u_char distance,
+ unsigned int ifindex, u_short tag, u_char distance,
vrf_id_t vrf_id)
{
struct route_node *rn;
@@ -3515,7 +3443,7 @@ static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
if (distance == si->distance
&& type == si->type
&& (! gate || IPV6_ADDR_SAME (gate, &si->addr.ipv6))
- && (! ifname || strcmp (ifname, si->ifname) == 0)
+ && (! ifindex || ifindex == si->ifindex)
&& (! tag || (tag == si->tag)))
break;
@@ -3538,8 +3466,6 @@ static_delete_ipv6 (struct prefix *p, u_char type, struct in6_addr *gate,
si->next->prev = si->prev;
/* Free static route configuration. */
- if (ifname)
- XFREE (0, si->ifname);
XFREE (MTYPE_STATIC_ROUTE, si);
return 1;