Skip to content

Commit

Permalink
zebra: use rib_add_multipath in rt_netlink.c
Browse files Browse the repository at this point in the history
The new route code path was using a combination of
both rib_add() and rib_add_multipath() let's clean
it up some to use rib_add_multipath()

Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Aug 17, 2022
1 parent b038587 commit 07fd1f7
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions zebra/rt_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,36 +937,38 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id,
afi = AFI_IP6;

if (h->nlmsg_type == RTM_NEWROUTE) {
struct route_entry *re;
struct nexthop_group *ng = NULL;

re = zebra_rib_route_entry_new(vrf_id, proto, 0, flags, nhe_id,
table, metric, mtu, distance,
tag);
if (!nhe_id)
ng = nexthop_group_new();

if (!tb[RTA_MULTIPATH]) {
struct nexthop nh = {0};
struct nexthop *nexthop, nh;

if (!nhe_id) {
nh = parse_nexthop_unicast(
ns_id, rtm, tb, bh_type, index, prefsrc,
gate, afi, vrf_id);

nexthop = nexthop_new();
*nexthop = nh;
nexthop_group_add_sorted(ng, nexthop);
}
rib_add(afi, SAFI_UNICAST, vrf_id, proto, 0, flags, &p,
&src_p, &nh, nhe_id, table, metric, mtu,
distance, tag, startup);
} else {
/* This is a multipath route */
struct route_entry *re;
struct nexthop_group *ng = NULL;
struct rtnexthop *rtnh =
(struct rtnexthop *)RTA_DATA(tb[RTA_MULTIPATH]);

re = zebra_rib_route_entry_new(vrf_id, proto, 0, flags,
nhe_id, table, metric,
mtu, distance, tag);

if (!nhe_id) {
uint8_t nhop_num;

/* Use temporary list of nexthops; parse
* message payload's nexthops.
*/
ng = nexthop_group_new();
nhop_num =
parse_multipath_nexthops_unicast(
ns_id, ng, rtm, rtnh, tb,
Expand All @@ -981,23 +983,22 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id,
ng = NULL;
}
}

if (nhe_id || ng)
rib_add_multipath(afi, SAFI_UNICAST, &p,
&src_p, re, ng, startup);
else {
/*
* I really don't see how this is possible
* but since we are testing for it let's
* let the end user know why the route
* that was just received was swallowed
* up and forgotten
*/
zlog_err(
"%s: %pFX multipath RTM_NEWROUTE has a invalid nexthop group from the kernel",
__func__, &p);
XFREE(MTYPE_RE, re);
}
}
if (nhe_id || ng)
rib_add_multipath(afi, SAFI_UNICAST, &p, &src_p, re, ng,
startup);
else {
/*
* I really don't see how this is possible
* but since we are testing for it let's
* let the end user know why the route
* that was just received was swallowed
* up and forgotten
*/
zlog_err(
"%s: %pFX multipath RTM_NEWROUTE has a invalid nexthop group from the kernel",
__func__, &p);
XFREE(MTYPE_RE, re);
}
} else {
if (nhe_id) {
Expand Down

0 comments on commit 07fd1f7

Please sign in to comment.