Re: [PATCH net v2] net: ipv4: Fix rtnexthop len when RTA_FLOW is present
From: David Ahern <hidden>
Date: 2021-09-23 14:22:13
On 9/23/21 1:22 AM, Xiao Liang wrote:
quoted hunk ↗ jump to hunk
diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c index b42c429cebbe..e9818faaff4d 100644 --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c@@ -1661,7 +1661,7 @@ EXPORT_SYMBOL_GPL(fib_nexthop_info); #if IS_ENABLED(CONFIG_IP_ROUTE_MULTIPATH) || IS_ENABLED(CONFIG_IPV6) int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc, - int nh_weight, u8 rt_family) + int nh_weight, u8 rt_family, u32 nh_tclassid) { const struct net_device *dev = nhc->nhc_dev; struct rtnexthop *rtnh;@@ -1679,6 +1679,12 @@ int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc, rtnh->rtnh_flags = flags; +#ifdef CONFIG_IP_ROUTE_CLASSID + if (nh_tclassid && + nla_put_u32(skb, RTA_FLOW, nh_tclassid)) + goto nla_put_failure; +#endif
I think we can drop the ifdef here if 0 is always passed when the CONFIG is not enabled.
quoted hunk ↗ jump to hunk
+ /* length of rtnetlink header + attributes */ rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *)rtnh;@@ -1707,13 +1713,8 @@ static int fib_add_multipath(struct sk_buff *skb, struct fib_info *fi) for_nexthops(fi) { if (fib_add_nexthop(skb, &nh->nh_common, nh->fib_nh_weight, - AF_INET) < 0) + AF_INET, nh->nh_tclassid) < 0)
This will fail to compile if the CONFIG is not enabled. Use a temp variable:
__u32 nh_tclassid = 0;
#ifdef CONFIG_IP_ROUTE_CLASSID
nh_tclassid = nh->nh_tclassid
#endif
then pass that to fib_add_nexthop
goto nla_put_failure; -#ifdef CONFIG_IP_ROUTE_CLASSID - if (nh->nh_tclassid && - nla_put_u32(skb, RTA_FLOW, nh->nh_tclassid)) - goto nla_put_failure; -#endif } endfor_nexthops(fi); mp_end: