* [PATCH net v2] net: ipv4: Fix rtnexthop len when RTA_FLOW is present
@ 2021-09-23 7:22 Xiao Liang
2021-09-23 14:22 ` David Ahern
0 siblings, 1 reply; 2+ messages in thread
From: Xiao Liang @ 2021-09-23 7:22 UTC (permalink / raw)
To: netdev
Cc: Xiao Liang, David S. Miller, Hideaki YOSHIFUJI, David Ahern,
Jakub Kicinski, Martin KaFai Lau
Multipath RTA_FLOW is embedded in nexthop. Dump it in fib_add_nexthop()
to get the length of rtnexthop correct.
Fixes: b0f60193632e ("ipv4: Refactor nexthop attributes in fib_dump_info")
Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
---
include/net/ip_fib.h | 2 +-
include/net/nexthop.h | 2 +-
net/ipv4/fib_semantics.c | 15 ++++++++-------
net/ipv6/route.c | 5 +++--
4 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
index 21c5386d4a6d..ab5348e57db1 100644
--- a/include/net/ip_fib.h
+++ b/include/net/ip_fib.h
@@ -597,5 +597,5 @@ int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,
int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nh,
u8 rt_family, unsigned char *flags, bool skip_oif);
int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nh,
- int nh_weight, u8 rt_family);
+ int nh_weight, u8 rt_family, u32 nh_tclassid);
#endif /* _NET_FIB_H */
diff --git a/include/net/nexthop.h b/include/net/nexthop.h
index 10e1777877e6..28085b995ddc 100644
--- a/include/net/nexthop.h
+++ b/include/net/nexthop.h
@@ -325,7 +325,7 @@ int nexthop_mpath_fill_node(struct sk_buff *skb, struct nexthop *nh,
struct fib_nh_common *nhc = &nhi->fib_nhc;
int weight = nhg->nh_entries[i].weight;
- if (fib_add_nexthop(skb, nhc, weight, rt_family) < 0)
+ if (fib_add_nexthop(skb, nhc, weight, rt_family, 0) < 0)
return -EMSGSIZE;
}
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
+
/* 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)
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:
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index dbc224023977..9b9ef09382ab 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -5681,14 +5681,15 @@ static int rt6_fill_node(struct net *net, struct sk_buff *skb,
goto nla_put_failure;
if (fib_add_nexthop(skb, &rt->fib6_nh->nh_common,
- rt->fib6_nh->fib_nh_weight, AF_INET6) < 0)
+ rt->fib6_nh->fib_nh_weight, AF_INET6,
+ 0) < 0)
goto nla_put_failure;
list_for_each_entry_safe(sibling, next_sibling,
&rt->fib6_siblings, fib6_siblings) {
if (fib_add_nexthop(skb, &sibling->fib6_nh->nh_common,
sibling->fib6_nh->fib_nh_weight,
- AF_INET6) < 0)
+ AF_INET6, 0) < 0)
goto nla_put_failure;
}
--
2.33.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net v2] net: ipv4: Fix rtnexthop len when RTA_FLOW is present
2021-09-23 7:22 [PATCH net v2] net: ipv4: Fix rtnexthop len when RTA_FLOW is present Xiao Liang
@ 2021-09-23 14:22 ` David Ahern
0 siblings, 0 replies; 2+ messages in thread
From: David Ahern @ 2021-09-23 14:22 UTC (permalink / raw)
To: Xiao Liang, netdev
Cc: David S. Miller, Hideaki YOSHIFUJI, David Ahern, Jakub Kicinski,
Martin KaFai Lau
On 9/23/21 1:22 AM, Xiao Liang wrote:
> 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.
> +
> /* 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:
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-09-23 14:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-23 7:22 [PATCH net v2] net: ipv4: Fix rtnexthop len when RTA_FLOW is present Xiao Liang
2021-09-23 14:22 ` David Ahern
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.