mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-08 14:34:22 +00:00
zebra: use a switch statement in nexthop_set_resolved()
This makes the function much easier to read, and also faster. Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
parent
cbdb74116f
commit
d855d11fad
@ -325,9 +325,11 @@ static void nexthop_set_resolved(afi_t afi, struct nexthop *newhop,
|
|||||||
|
|
||||||
resolved_hop = nexthop_new();
|
resolved_hop = nexthop_new();
|
||||||
SET_FLAG(resolved_hop->flags, NEXTHOP_FLAG_ACTIVE);
|
SET_FLAG(resolved_hop->flags, NEXTHOP_FLAG_ACTIVE);
|
||||||
|
|
||||||
|
switch (newhop->type) {
|
||||||
|
case NEXTHOP_TYPE_IPV4:
|
||||||
|
case NEXTHOP_TYPE_IPV4_IFINDEX:
|
||||||
/* If the resolving route specifies a gateway, use it */
|
/* 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->type = newhop->type;
|
||||||
resolved_hop->gate.ipv4 = newhop->gate.ipv4;
|
resolved_hop->gate.ipv4 = newhop->gate.ipv4;
|
||||||
|
|
||||||
@ -337,9 +339,9 @@ static void nexthop_set_resolved(afi_t afi, struct nexthop *newhop,
|
|||||||
if (newhop->flags & NEXTHOP_FLAG_ONLINK)
|
if (newhop->flags & NEXTHOP_FLAG_ONLINK)
|
||||||
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
|
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
if (newhop->type == NEXTHOP_TYPE_IPV6
|
case NEXTHOP_TYPE_IPV6:
|
||||||
|| newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX) {
|
case NEXTHOP_TYPE_IPV6_IFINDEX:
|
||||||
resolved_hop->type = newhop->type;
|
resolved_hop->type = newhop->type;
|
||||||
resolved_hop->gate.ipv6 = newhop->gate.ipv6;
|
resolved_hop->gate.ipv6 = newhop->gate.ipv6;
|
||||||
|
|
||||||
@ -347,8 +349,8 @@ static void nexthop_set_resolved(afi_t afi, struct nexthop *newhop,
|
|||||||
resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
|
resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX;
|
||||||
resolved_hop->ifindex = newhop->ifindex;
|
resolved_hop->ifindex = newhop->ifindex;
|
||||||
}
|
}
|
||||||
}
|
break;
|
||||||
|
case NEXTHOP_TYPE_IFINDEX:
|
||||||
/* If the resolving route is an interface route,
|
/* If the resolving route is an interface route,
|
||||||
* it means the gateway we are looking up is connected
|
* it means the gateway we are looking up is connected
|
||||||
* to that interface. (The actual network is _not_ onlink).
|
* to that interface. (The actual network is _not_ onlink).
|
||||||
@ -358,7 +360,6 @@ static void nexthop_set_resolved(afi_t afi, struct nexthop *newhop,
|
|||||||
* On Linux, we have to set the onlink netlink flag because
|
* On Linux, we have to set the onlink netlink flag because
|
||||||
* otherwise, the kernel won't accept the route.
|
* otherwise, the kernel won't accept the route.
|
||||||
*/
|
*/
|
||||||
if (newhop->type == NEXTHOP_TYPE_IFINDEX) {
|
|
||||||
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
|
resolved_hop->flags |= NEXTHOP_FLAG_ONLINK;
|
||||||
if (afi == AFI_IP) {
|
if (afi == AFI_IP) {
|
||||||
resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
|
resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX;
|
||||||
@ -368,12 +369,13 @@ static void nexthop_set_resolved(afi_t afi, struct nexthop *newhop,
|
|||||||
resolved_hop->gate.ipv6 = nexthop->gate.ipv6;
|
resolved_hop->gate.ipv6 = nexthop->gate.ipv6;
|
||||||
}
|
}
|
||||||
resolved_hop->ifindex = newhop->ifindex;
|
resolved_hop->ifindex = newhop->ifindex;
|
||||||
}
|
break;
|
||||||
|
case NEXTHOP_TYPE_BLACKHOLE:
|
||||||
if (newhop->type == NEXTHOP_TYPE_BLACKHOLE) {
|
|
||||||
resolved_hop->type = NEXTHOP_TYPE_BLACKHOLE;
|
resolved_hop->type = NEXTHOP_TYPE_BLACKHOLE;
|
||||||
resolved_hop->bh_type = nexthop->bh_type;
|
resolved_hop->bh_type = nexthop->bh_type;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
resolved_hop->rparent = nexthop;
|
resolved_hop->rparent = nexthop;
|
||||||
nexthop_add(&nexthop->resolved, resolved_hop);
|
nexthop_add(&nexthop->resolved, resolved_hop);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user