mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-13 21:10:28 +00:00
zebra: Refactor nexthop_active to remove duplicate code
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
326452238a
commit
4491a88f9e
@ -329,6 +329,69 @@ route_entry_nexthop_blackhole_add (struct route_entry *re)
|
|||||||
return nexthop;
|
return nexthop;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nexthop_set_resolved (afi_t afi, struct nexthop *newhop, struct nexthop *nexthop)
|
||||||
|
{
|
||||||
|
struct nexthop *resolved_hop;
|
||||||
|
|
||||||
|
resolved_hop = nexthop_new();
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
resolved_hop->type = newhop->type;
|
||||||
|
resolved_hop->gate.ipv4 = newhop->gate.ipv4;
|
||||||
|
|
||||||
|
if (newhop->ifindex)
|
||||||
|
{
|
||||||
|
resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
|
||||||
|
resolved_hop->ifindex = newhop->ifindex;
|
||||||
|
if (newhop->flags & NEXTHOP_FLAG_ONLINK)
|
||||||
|
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (newhop->type == NEXTHOP_TYPE_IPV6
|
||||||
|
|| newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX)
|
||||||
|
{
|
||||||
|
resolved_hop->type = newhop->type;
|
||||||
|
resolved_hop->gate.ipv6 = newhop->gate.ipv6;
|
||||||
|
|
||||||
|
if (newhop->ifindex)
|
||||||
|
{
|
||||||
|
resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
|
||||||
|
resolved_hop->ifindex = newhop->ifindex;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If the resolving route is an interface route,
|
||||||
|
* it means the gateway we are looking up is connected
|
||||||
|
* to that interface. (The actual network is _not_ onlink).
|
||||||
|
* Therefore, the resolved route should have the original
|
||||||
|
* gateway as nexthop as it is directly connected.
|
||||||
|
*
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
|
||||||
|
if (afi == AFI_IP)
|
||||||
|
{
|
||||||
|
resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
|
||||||
|
resolved_hop->gate.ipv4 = nexthop->gate.ipv4;
|
||||||
|
}
|
||||||
|
else if (afi == AFI_IP6)
|
||||||
|
{
|
||||||
|
resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
|
||||||
|
resolved_hop->gate.ipv6 = nexthop->gate.ipv6;
|
||||||
|
}
|
||||||
|
resolved_hop->ifindex = newhop->ifindex;
|
||||||
|
}
|
||||||
|
|
||||||
|
nexthop_add(&nexthop->resolved, resolved_hop);
|
||||||
|
}
|
||||||
|
|
||||||
/* If force flag is not set, do not modify falgs at all for uninstall
|
/* If force flag is not set, do not modify falgs at all for uninstall
|
||||||
the route from FIB. */
|
the route from FIB. */
|
||||||
static int
|
static int
|
||||||
@ -341,7 +404,6 @@ nexthop_active (afi_t afi, struct route_entry *re, struct nexthop *nexthop, int
|
|||||||
struct route_entry *match;
|
struct route_entry *match;
|
||||||
int resolved;
|
int resolved;
|
||||||
struct nexthop *newhop, *tnewhop;
|
struct nexthop *newhop, *tnewhop;
|
||||||
struct nexthop *resolved_hop;
|
|
||||||
int recursing = 0;
|
int recursing = 0;
|
||||||
struct interface *ifp;
|
struct interface *ifp;
|
||||||
|
|
||||||
@ -474,61 +536,7 @@ nexthop_active (afi_t afi, struct route_entry *re, struct nexthop *nexthop, int
|
|||||||
SET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
|
SET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
|
||||||
SET_FLAG(re->status, ROUTE_ENTRY_NEXTHOPS_CHANGED);
|
SET_FLAG(re->status, ROUTE_ENTRY_NEXTHOPS_CHANGED);
|
||||||
|
|
||||||
resolved_hop = nexthop_new();
|
nexthop_set_resolved(afi, newhop, nexthop);
|
||||||
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)
|
|
||||||
{
|
|
||||||
resolved_hop->type = newhop->type;
|
|
||||||
resolved_hop->gate.ipv4 = newhop->gate.ipv4;
|
|
||||||
|
|
||||||
if (newhop->ifindex)
|
|
||||||
{
|
|
||||||
resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
|
|
||||||
resolved_hop->ifindex = newhop->ifindex;
|
|
||||||
if (newhop->flags & NEXTHOP_FLAG_ONLINK)
|
|
||||||
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newhop->type == NEXTHOP_TYPE_IPV6
|
|
||||||
|| newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX)
|
|
||||||
{
|
|
||||||
resolved_hop->type = newhop->type;
|
|
||||||
resolved_hop->gate.ipv6 = newhop->gate.ipv6;
|
|
||||||
|
|
||||||
if (newhop->ifindex)
|
|
||||||
{
|
|
||||||
resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
|
|
||||||
resolved_hop->ifindex = newhop->ifindex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the resolving route is an interface route,
|
|
||||||
* it means the gateway we are looking up is connected
|
|
||||||
* to that interface. (The actual network is _not_ onlink).
|
|
||||||
* Therefore, the resolved route should have the original
|
|
||||||
* gateway as nexthop as it is directly connected.
|
|
||||||
*
|
|
||||||
* 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)
|
|
||||||
{
|
|
||||||
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
|
|
||||||
if (afi == AFI_IP)
|
|
||||||
{
|
|
||||||
resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
|
|
||||||
resolved_hop->gate.ipv4 = nexthop->gate.ipv4;
|
|
||||||
}
|
|
||||||
else if (afi == AFI_IP6)
|
|
||||||
{
|
|
||||||
resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
|
|
||||||
resolved_hop->gate.ipv6 = nexthop->gate.ipv6;
|
|
||||||
}
|
|
||||||
resolved_hop->ifindex = newhop->ifindex;
|
|
||||||
}
|
|
||||||
|
|
||||||
nexthop_add(&nexthop->resolved, resolved_hop);
|
|
||||||
}
|
}
|
||||||
resolved = 1;
|
resolved = 1;
|
||||||
}
|
}
|
||||||
@ -544,62 +552,7 @@ nexthop_active (afi_t afi, struct route_entry *re, struct nexthop *nexthop, int
|
|||||||
{
|
{
|
||||||
SET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
|
SET_FLAG (nexthop->flags, NEXTHOP_FLAG_RECURSIVE);
|
||||||
|
|
||||||
resolved_hop = nexthop_new();
|
nexthop_set_resolved(afi, newhop, nexthop);
|
||||||
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)
|
|
||||||
{
|
|
||||||
resolved_hop->type = newhop->type;
|
|
||||||
resolved_hop->gate.ipv4 = newhop->gate.ipv4;
|
|
||||||
|
|
||||||
if (newhop->ifindex)
|
|
||||||
{
|
|
||||||
resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
|
|
||||||
resolved_hop->ifindex = newhop->ifindex;
|
|
||||||
if (newhop->flags & NEXTHOP_FLAG_ONLINK)
|
|
||||||
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (newhop->type == NEXTHOP_TYPE_IPV6
|
|
||||||
|| newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX)
|
|
||||||
{
|
|
||||||
resolved_hop->type = newhop->type;
|
|
||||||
resolved_hop->gate.ipv6 = newhop->gate.ipv6;
|
|
||||||
|
|
||||||
if (newhop->ifindex)
|
|
||||||
{
|
|
||||||
resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
|
|
||||||
resolved_hop->ifindex = newhop->ifindex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If the resolving route is an interface route,
|
|
||||||
* it means the gateway we are looking up is connected
|
|
||||||
* to that interface. (The actual network is _not_ onlink).
|
|
||||||
* Therefore, the resolved route should have the original
|
|
||||||
* gateway as nexthop as it is directly connected.
|
|
||||||
*
|
|
||||||
* 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)
|
|
||||||
{
|
|
||||||
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
|
|
||||||
if (afi == AFI_IP)
|
|
||||||
{
|
|
||||||
resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
|
|
||||||
resolved_hop->gate.ipv4 = nexthop->gate.ipv4;
|
|
||||||
}
|
|
||||||
else if (afi == AFI_IP6)
|
|
||||||
{
|
|
||||||
resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
|
|
||||||
resolved_hop->gate.ipv6 = nexthop->gate.ipv6;
|
|
||||||
}
|
|
||||||
resolved_hop->ifindex = newhop->ifindex;
|
|
||||||
}
|
|
||||||
|
|
||||||
nexthop_add(&nexthop->resolved, resolved_hop);
|
|
||||||
}
|
}
|
||||||
resolved = 1;
|
resolved = 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user