All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net: ipv4: Fix rtnexthop len when RTA_FLOW is present
@ 2021-09-22 10:16 Xiao Liang
  2021-09-23  4:13 ` David Ahern
  0 siblings, 1 reply; 3+ messages in thread
From: Xiao Liang @ 2021-09-22 10:16 UTC (permalink / raw)
  To: netdev; +Cc: Xiao Liang, yoshfuji, dsahern, kuba, davem

Multipath RTA_FLOW is embedded in nexthop, thus add it to rtnexthop
length.

Fixes: b0f60193632e ("ipv4: Refactor nexthop attributes in fib_dump_info")
Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
---
 net/ipv4/fib_semantics.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index b42c429cebbe..62b74edb5240 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -1660,8 +1660,9 @@ int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nhc,
 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)
+static struct rtnexthop *__fib_add_nexthop(struct sk_buff *skb,
+					   const struct fib_nh_common *nhc,
+					   int nh_weight, u8 rt_family)
 {
 	const struct net_device *dev = nhc->nhc_dev;
 	struct rtnexthop *rtnh;
@@ -1682,10 +1683,17 @@ int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc,
 	/* length of rtnetlink header + attributes */
 	rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *)rtnh;
 
-	return 0;
+	return rtnh;
 
 nla_put_failure:
-	return -EMSGSIZE;
+	return ERR_PTR(-EMSGSIZE);
+}
+
+int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc,
+		    int nh_weight, u8 rt_family)
+{
+	return PTR_ERR_OR_ZERO(__fib_add_nexthop(skb, nhc, nh_weight,
+						 rt_family));
 }
 EXPORT_SYMBOL_GPL(fib_add_nexthop);
 #endif
@@ -1706,13 +1714,17 @@ 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)
+		struct rtnexthop *rtnh = __fib_add_nexthop(skb, &nh->nh_common,
+							   nh->fib_nh_weight,
+							   AF_INET);
+		if (IS_ERR(rtnh))
 			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;
+		if (nh->nh_tclassid) {
+			if (nla_put_u32(skb, RTA_FLOW, nh->nh_tclassid))
+				goto nla_put_failure;
+			rtnh->rtnh_len += nla_total_size(4);
+		}
 #endif
 	} endfor_nexthops(fi);
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] net: ipv4: Fix rtnexthop len when RTA_FLOW is present
  2021-09-22 10:16 [PATCH net] net: ipv4: Fix rtnexthop len when RTA_FLOW is present Xiao Liang
@ 2021-09-23  4:13 ` David Ahern
  0 siblings, 0 replies; 3+ messages in thread
From: David Ahern @ 2021-09-23  4:13 UTC (permalink / raw)
  To: Xiao Liang, netdev; +Cc: yoshfuji, dsahern, kuba, davem

On 9/22/21 4:16 AM, Xiao Liang wrote:
> @@ -1682,10 +1683,17 @@ int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc,
>  	/* length of rtnetlink header + attributes */
>  	rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *)rtnh;
>  
> -	return 0;
> +	return rtnh;
>  
>  nla_put_failure:
> -	return -EMSGSIZE;
> +	return ERR_PTR(-EMSGSIZE);
> +}
> +
> +int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc,
> +		    int nh_weight, u8 rt_family)

Adding classid as an input to fib_add_nexthop and checking it for non-0
before adding to the message is a better way to resolve this.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH net] net: ipv4: Fix rtnexthop len when RTA_FLOW is present
@ 2021-09-22  9:27 Xiao Liang
  0 siblings, 0 replies; 3+ messages in thread
From: Xiao Liang @ 2021-09-22  9:27 UTC (permalink / raw)
  To: netdev; +Cc: Xiao Liang

Multipath RTA_FLOW is embedded in nexthop, thus add it to rtnexthop
length.

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
---
 net/ipv4/fib_semantics.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index b42c429cebbe..a07883ba8748 100644
--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -1660,8 +1660,9 @@ int fib_nexthop_info(struct sk_buff *skb, const struct fib_nh_common *nhc,
 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)
+static inline struct rtnexthop *__fib_add_nexthop(struct sk_buff *skb,
+					const struct fib_nh_common *nhc,
+					int nh_weight, u8 rt_family)
 {
 	const struct net_device *dev = nhc->nhc_dev;
 	struct rtnexthop *rtnh;
@@ -1682,10 +1683,16 @@ int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc,
 	/* length of rtnetlink header + attributes */
 	rtnh->rtnh_len = nlmsg_get_pos(skb) - (void *)rtnh;
 
-	return 0;
+	return rtnh;
 
 nla_put_failure:
-	return -EMSGSIZE;
+	return ERR_PTR(-EMSGSIZE);
+}
+
+int fib_add_nexthop(struct sk_buff *skb, const struct fib_nh_common *nhc,
+		    int nh_weight, u8 rt_family)
+{
+	return PTR_ERR_OR_ZERO(__fib_add_nexthop(skb, nhc, nh_weight, rt_family));
 }
 EXPORT_SYMBOL_GPL(fib_add_nexthop);
 #endif
@@ -1706,13 +1713,17 @@ 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)
+		struct rtnexthop *rtnh = __fib_add_nexthop(skb, &nh->nh_common,
+							   nh->fib_nh_weight,
+							   AF_INET);
+		if (IS_ERR(rtnh))
 			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;
+		if (nh->nh_tclassid) {
+			if (nla_put_u32(skb, RTA_FLOW, nh->nh_tclassid))
+				goto nla_put_failure;
+			rtnh->rtnh_len += nla_total_size(4);
+		}
 #endif
 	} endfor_nexthops(fi);
 
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-23  4:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-22 10:16 [PATCH net] net: ipv4: Fix rtnexthop len when RTA_FLOW is present Xiao Liang
2021-09-23  4:13 ` David Ahern
  -- strict thread matches above, loose matches on Subject: below --
2021-09-22  9:27 Xiao Liang

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.