* [PATCH net-next] ipv6: sit: Add ipip6_tunnel_dst_find() for cleanup
@ 2025-08-27 4:00 Yue Haibing
2025-08-27 14:45 ` Alexander Lobakin
0 siblings, 1 reply; 5+ messages in thread
From: Yue Haibing @ 2025-08-27 4:00 UTC (permalink / raw)
To: davem, dsahern, edumazet, kuba, pabeni, horms
Cc: netdev, linux-kernel, yuehaibing
Extract the dst lookup logic from ipip6_tunnel_xmit() into new helper
ipip6_tunnel_dst_find() to reduce code duplication and enhance readability.
No functional change intended.
Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
---
net/ipv6/sit.c | 93 +++++++++++++++++++++++---------------------------
1 file changed, 43 insertions(+), 50 deletions(-)
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 12496ba1b7d4..bcd261ff985b 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -848,6 +848,47 @@ static inline __be32 try_6rd(struct ip_tunnel *tunnel,
return dst;
}
+static bool ipip6_tunnel_dst_find(struct sk_buff *skb, __be32 *dst,
+ bool is_isatap)
+{
+ const struct ipv6hdr *iph6 = ipv6_hdr(skb);
+ struct neighbour *neigh = NULL;
+ const struct in6_addr *addr6;
+ bool found = false;
+ int addr_type;
+
+ if (skb_dst(skb))
+ neigh = dst_neigh_lookup(skb_dst(skb), &iph6->daddr);
+
+ if (!neigh) {
+ net_dbg_ratelimited("nexthop == NULL\n");
+ return found;
+ }
+
+ addr6 = (const struct in6_addr *)&neigh->primary_key;
+ addr_type = ipv6_addr_type(addr6);
+
+ if (is_isatap) {
+ if ((addr_type & IPV6_ADDR_UNICAST) &&
+ ipv6_addr_is_isatap(addr6)) {
+ *dst = addr6->s6_addr32[3];
+ found = true;
+ }
+ } else {
+ if (addr_type == IPV6_ADDR_ANY) {
+ addr6 = &ipv6_hdr(skb)->daddr;
+ addr_type = ipv6_addr_type(addr6);
+ }
+
+ if ((addr_type & IPV6_ADDR_COMPATv4) != 0) {
+ *dst = addr6->s6_addr32[3];
+ found = true;
+ }
+ }
+ neigh_release(neigh);
+ return found;
+}
+
/*
* This function assumes it is being called from dev_queue_xmit()
* and that skb is filled properly by that function.
@@ -867,8 +908,6 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
__be32 dst = tiph->daddr;
struct flowi4 fl4;
int mtu;
- const struct in6_addr *addr6;
- int addr_type;
u8 ttl;
u8 protocol = IPPROTO_IPV6;
int t_hlen = tunnel->hlen + sizeof(struct iphdr);
@@ -878,28 +917,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
/* ISATAP (RFC4214) - must come before 6to4 */
if (dev->priv_flags & IFF_ISATAP) {
- struct neighbour *neigh = NULL;
- bool do_tx_error = false;
-
- if (skb_dst(skb))
- neigh = dst_neigh_lookup(skb_dst(skb), &iph6->daddr);
-
- if (!neigh) {
- net_dbg_ratelimited("nexthop == NULL\n");
- goto tx_error;
- }
-
- addr6 = (const struct in6_addr *)&neigh->primary_key;
- addr_type = ipv6_addr_type(addr6);
-
- if ((addr_type & IPV6_ADDR_UNICAST) &&
- ipv6_addr_is_isatap(addr6))
- dst = addr6->s6_addr32[3];
- else
- do_tx_error = true;
-
- neigh_release(neigh);
- if (do_tx_error)
+ if (!ipip6_tunnel_dst_find(skb, &dst, true))
goto tx_error;
}
@@ -907,32 +925,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb,
dst = try_6rd(tunnel, &iph6->daddr);
if (!dst) {
- struct neighbour *neigh = NULL;
- bool do_tx_error = false;
-
- if (skb_dst(skb))
- neigh = dst_neigh_lookup(skb_dst(skb), &iph6->daddr);
-
- if (!neigh) {
- net_dbg_ratelimited("nexthop == NULL\n");
- goto tx_error;
- }
-
- addr6 = (const struct in6_addr *)&neigh->primary_key;
- addr_type = ipv6_addr_type(addr6);
-
- if (addr_type == IPV6_ADDR_ANY) {
- addr6 = &ipv6_hdr(skb)->daddr;
- addr_type = ipv6_addr_type(addr6);
- }
-
- if ((addr_type & IPV6_ADDR_COMPATv4) != 0)
- dst = addr6->s6_addr32[3];
- else
- do_tx_error = true;
-
- neigh_release(neigh);
- if (do_tx_error)
+ if (!ipip6_tunnel_dst_find(skb, &dst, false))
goto tx_error;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] ipv6: sit: Add ipip6_tunnel_dst_find() for cleanup
2025-08-27 4:00 [PATCH net-next] ipv6: sit: Add ipip6_tunnel_dst_find() for cleanup Yue Haibing
@ 2025-08-27 14:45 ` Alexander Lobakin
2025-08-28 6:13 ` Yue Haibing
0 siblings, 1 reply; 5+ messages in thread
From: Alexander Lobakin @ 2025-08-27 14:45 UTC (permalink / raw)
To: Yue Haibing
Cc: davem, dsahern, edumazet, kuba, pabeni, horms, netdev,
linux-kernel
From: Yue Haibing <yuehaibing@huawei.com>
Date: Wed, 27 Aug 2025 12:00:27 +0800
> Extract the dst lookup logic from ipip6_tunnel_xmit() into new helper
> ipip6_tunnel_dst_find() to reduce code duplication and enhance readability.
>
> No functional change intended.
...but bloat-o-meter stats would be nice to see here. I'm curious
whether the object code got any changes or the compilers still just
inline this function to both call sites.
>
> Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
> ---
> net/ipv6/sit.c | 93 +++++++++++++++++++++++---------------------------
> 1 file changed, 43 insertions(+), 50 deletions(-)
>
> diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
> index 12496ba1b7d4..bcd261ff985b 100644
> --- a/net/ipv6/sit.c
> +++ b/net/ipv6/sit.c
> @@ -848,6 +848,47 @@ static inline __be32 try_6rd(struct ip_tunnel *tunnel,
> return dst;
> }
>
> +static bool ipip6_tunnel_dst_find(struct sk_buff *skb, __be32 *dst,
> + bool is_isatap)
> +{
> + const struct ipv6hdr *iph6 = ipv6_hdr(skb);
> + struct neighbour *neigh = NULL;
> + const struct in6_addr *addr6;
> + bool found = false;
> + int addr_type;
> +
> + if (skb_dst(skb))
> + neigh = dst_neigh_lookup(skb_dst(skb), &iph6->daddr);
> +
> + if (!neigh) {
> + net_dbg_ratelimited("nexthop == NULL\n");
> + return found;
Return false here right away.
> + }
> +
> + addr6 = (const struct in6_addr *)&neigh->primary_key;
> + addr_type = ipv6_addr_type(addr6);
> +
> + if (is_isatap) {
> + if ((addr_type & IPV6_ADDR_UNICAST) &&
> + ipv6_addr_is_isatap(addr6)) {
> + *dst = addr6->s6_addr32[3];
> + found = true;
> + }
> + } else {
> + if (addr_type == IPV6_ADDR_ANY) {
> + addr6 = &ipv6_hdr(skb)->daddr;
> + addr_type = ipv6_addr_type(addr6);
> + }
> +
> + if ((addr_type & IPV6_ADDR_COMPATv4) != 0) {
> + *dst = addr6->s6_addr32[3];
> + found = true;
> + }
> + }
> + neigh_release(neigh);
> + return found;
I'd put 2 additional newlines here:
}
neigh_release(neigh);
return found;
}
for readability purposes and also a NL before the final `return` is
usually mandatory.
Thanks,
Olek
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] ipv6: sit: Add ipip6_tunnel_dst_find() for cleanup
2025-08-27 14:45 ` Alexander Lobakin
@ 2025-08-28 6:13 ` Yue Haibing
2025-08-28 6:44 ` Yue Haibing
0 siblings, 1 reply; 5+ messages in thread
From: Yue Haibing @ 2025-08-28 6:13 UTC (permalink / raw)
To: Alexander Lobakin
Cc: davem, dsahern, edumazet, kuba, pabeni, horms, netdev,
linux-kernel
On 2025/8/27 22:45, Alexander Lobakin wrote:
> From: Yue Haibing <yuehaibing@huawei.com>
> Date: Wed, 27 Aug 2025 12:00:27 +0800
>
>> Extract the dst lookup logic from ipip6_tunnel_xmit() into new helper
>> ipip6_tunnel_dst_find() to reduce code duplication and enhance readability.
>>
>> No functional change intended.
>
> ...but bloat-o-meter stats would be nice to see here. I'm curious
> whether the object code got any changes or the compilers still just
> inline this function to both call sites.
On a x86_64, with allmodconfig:
before:
text data bss dec hex filename
96973 14687 256 111916 1b52c net/ipv6/sit.o
after:
text data bss dec hex filename
96699 14599 256 111554 1b3c2 net/ipv6/sit.o
I will add this in v2.
>
>>
>> Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
>> ---
>> net/ipv6/sit.c | 93 +++++++++++++++++++++++---------------------------
>> 1 file changed, 43 insertions(+), 50 deletions(-)
>>
>> diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
>> index 12496ba1b7d4..bcd261ff985b 100644
>> --- a/net/ipv6/sit.c
>> +++ b/net/ipv6/sit.c
>> @@ -848,6 +848,47 @@ static inline __be32 try_6rd(struct ip_tunnel *tunnel,
>> return dst;
>> }
>>
>> +static bool ipip6_tunnel_dst_find(struct sk_buff *skb, __be32 *dst,
>> + bool is_isatap)
>> +{
>> + const struct ipv6hdr *iph6 = ipv6_hdr(skb);
>> + struct neighbour *neigh = NULL;
>> + const struct in6_addr *addr6;
>> + bool found = false;
>> + int addr_type;
>> +
>> + if (skb_dst(skb))
>> + neigh = dst_neigh_lookup(skb_dst(skb), &iph6->daddr);
>> +
>> + if (!neigh) {
>> + net_dbg_ratelimited("nexthop == NULL\n");
>> + return found;
>
> Return false here right away.
>
>> + }
>> +
>> + addr6 = (const struct in6_addr *)&neigh->primary_key;
>> + addr_type = ipv6_addr_type(addr6);
>> +
>> + if (is_isatap) {
>> + if ((addr_type & IPV6_ADDR_UNICAST) &&
>> + ipv6_addr_is_isatap(addr6)) {
>> + *dst = addr6->s6_addr32[3];
>> + found = true;
>> + }
>> + } else {
>> + if (addr_type == IPV6_ADDR_ANY) {
>> + addr6 = &ipv6_hdr(skb)->daddr;
>> + addr_type = ipv6_addr_type(addr6);
>> + }
>> +
>> + if ((addr_type & IPV6_ADDR_COMPATv4) != 0) {
>> + *dst = addr6->s6_addr32[3];
>> + found = true;
>> + }
>> + }
>> + neigh_release(neigh);
>> + return found;
>
> I'd put 2 additional newlines here:
>
> }
>
> neigh_release(neigh);
>
> return found;
> }
>
> for readability purposes and also a NL before the final `return` is
> usually mandatory.
OK, thanks.
>
> Thanks,
> Olek
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] ipv6: sit: Add ipip6_tunnel_dst_find() for cleanup
2025-08-28 6:13 ` Yue Haibing
@ 2025-08-28 6:44 ` Yue Haibing
2025-08-28 15:33 ` Alexander Lobakin
0 siblings, 1 reply; 5+ messages in thread
From: Yue Haibing @ 2025-08-28 6:44 UTC (permalink / raw)
To: Alexander Lobakin
Cc: davem, dsahern, edumazet, kuba, pabeni, horms, netdev,
linux-kernel
On 2025/8/28 14:13, Yue Haibing wrote:
> On 2025/8/27 22:45, Alexander Lobakin wrote:
>> From: Yue Haibing <yuehaibing@huawei.com>
>> Date: Wed, 27 Aug 2025 12:00:27 +0800
>>
>>> Extract the dst lookup logic from ipip6_tunnel_xmit() into new helper
>>> ipip6_tunnel_dst_find() to reduce code duplication and enhance readability.
>>>
>>> No functional change intended.
>>
>> ...but bloat-o-meter stats would be nice to see here. I'm curious
>> whether the object code got any changes or the compilers still just
>> inline this function to both call sites.
On a x86_64, with allmodconfig:
./scripts/bloat-o-meter -c net/ipv6/sit.o net/ipv6/sit-after.o
add/remove: 2/0 grow/shrink: 1/1 up/down: 1770/-2152 (-382)
Function old new delta
ipip6_tunnel_dst_find - 1697 +1697
__pfx_ipip6_tunnel_dst_find - 64 +64
ipip6_tunnel_xmit.isra.cold 79 88 +9
ipip6_tunnel_xmit.isra 9910 7758 -2152
Total: Before=70060, After=69678, chg -0.55%
add/remove: 2/2 grow/shrink: 0/1 up/down: 16/-72 (-56)
Data old new delta
__UNIQUE_ID___addressable_init_module2092 - 8 +8
__UNIQUE_ID___addressable_cleanup_module2093 - 8 +8
__UNIQUE_ID___addressable_init_module2093 8 - -8
__UNIQUE_ID___addressable_cleanup_module2094 8 - -8
descriptor 112 56 -56
Total: Before=752, After=696, chg -7.45%
add/remove: 1/1 grow/shrink: 2/2 up/down: 55/-51 (4)
RO Data old new delta
__UNIQUE_ID_modinfo2094 - 43 +43
__UNIQUE_ID_modinfo2096 12 20 +8
__func__ 55 59 +4
__UNIQUE_ID_modinfo2097 20 18 -2
__UNIQUE_ID_modinfo2098 18 - -18
__UNIQUE_ID_modinfo2095 43 12 -31
Total: Before=1725, After=1729, chg +0.23%
>
> On a x86_64, with allmodconfig:
> before:
> text data bss dec hex filename
> 96973 14687 256 111916 1b52c net/ipv6/sit.o
>
> after:
> text data bss dec hex filename
> 96699 14599 256 111554 1b3c2 net/ipv6/sit.o
>
> I will add this in v2.
>
>>
>>>
>>> Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
>>> ---
>>> net/ipv6/sit.c | 93 +++++++++++++++++++++++---------------------------
>>> 1 file changed, 43 insertions(+), 50 deletions(-)
>>>
>>> diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
>>> index 12496ba1b7d4..bcd261ff985b 100644
>>> --- a/net/ipv6/sit.c
>>> +++ b/net/ipv6/sit.c
>>> @@ -848,6 +848,47 @@ static inline __be32 try_6rd(struct ip_tunnel *tunnel,
>>> return dst;
>>> }
>>>
>>> +static bool ipip6_tunnel_dst_find(struct sk_buff *skb, __be32 *dst,
>>> + bool is_isatap)
>>> +{
>>> + const struct ipv6hdr *iph6 = ipv6_hdr(skb);
>>> + struct neighbour *neigh = NULL;
>>> + const struct in6_addr *addr6;
>>> + bool found = false;
>>> + int addr_type;
>>> +
>>> + if (skb_dst(skb))
>>> + neigh = dst_neigh_lookup(skb_dst(skb), &iph6->daddr);
>>> +
>>> + if (!neigh) {
>>> + net_dbg_ratelimited("nexthop == NULL\n");
>>> + return found;
>>
>> Return false here right away.
>>
>>> + }
>>> +
>>> + addr6 = (const struct in6_addr *)&neigh->primary_key;
>>> + addr_type = ipv6_addr_type(addr6);
>>> +
>>> + if (is_isatap) {
>>> + if ((addr_type & IPV6_ADDR_UNICAST) &&
>>> + ipv6_addr_is_isatap(addr6)) {
>>> + *dst = addr6->s6_addr32[3];
>>> + found = true;
>>> + }
>>> + } else {
>>> + if (addr_type == IPV6_ADDR_ANY) {
>>> + addr6 = &ipv6_hdr(skb)->daddr;
>>> + addr_type = ipv6_addr_type(addr6);
>>> + }
>>> +
>>> + if ((addr_type & IPV6_ADDR_COMPATv4) != 0) {
>>> + *dst = addr6->s6_addr32[3];
>>> + found = true;
>>> + }
>>> + }
>>> + neigh_release(neigh);
>>> + return found;
>>
>> I'd put 2 additional newlines here:
>>
>> }
>>
>> neigh_release(neigh);
>>
>> return found;
>> }
>>
>> for readability purposes and also a NL before the final `return` is
>> usually mandatory.
>
> OK, thanks.
>>
>> Thanks,
>> Olek
>>
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] ipv6: sit: Add ipip6_tunnel_dst_find() for cleanup
2025-08-28 6:44 ` Yue Haibing
@ 2025-08-28 15:33 ` Alexander Lobakin
0 siblings, 0 replies; 5+ messages in thread
From: Alexander Lobakin @ 2025-08-28 15:33 UTC (permalink / raw)
To: Yue Haibing
Cc: davem, dsahern, edumazet, kuba, pabeni, horms, netdev,
linux-kernel
From: Yue Haibing <yuehaibing@huawei.com>
Date: Thu, 28 Aug 2025 14:44:07 +0800
> On 2025/8/28 14:13, Yue Haibing wrote:
>> On 2025/8/27 22:45, Alexander Lobakin wrote:
>>> From: Yue Haibing <yuehaibing@huawei.com>
>>> Date: Wed, 27 Aug 2025 12:00:27 +0800
>>>
>>>> Extract the dst lookup logic from ipip6_tunnel_xmit() into new helper
>>>> ipip6_tunnel_dst_find() to reduce code duplication and enhance readability.
>>>>
>>>> No functional change intended.
>>>
>>> ...but bloat-o-meter stats would be nice to see here. I'm curious
>>> whether the object code got any changes or the compilers still just
>>> inline this function to both call sites.
>
> On a x86_64, with allmodconfig:
>
> ./scripts/bloat-o-meter -c net/ipv6/sit.o net/ipv6/sit-after.o
> add/remove: 2/0 grow/shrink: 1/1 up/down: 1770/-2152 (-382)
> Function old new delta
> ipip6_tunnel_dst_find - 1697 +1697
> __pfx_ipip6_tunnel_dst_find - 64 +64
> ipip6_tunnel_xmit.isra.cold 79 88 +9
> ipip6_tunnel_xmit.isra 9910 7758 -2152
Oh okay, so it doesn't inline the function due to its size. Maybe it's
even better since we have a good object code reduction now and that
branch inside the func shouldn't hurt the performance much.
> Total: Before=70060, After=69678, chg -0.55%
Thanks,
Olek
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-28 15:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-27 4:00 [PATCH net-next] ipv6: sit: Add ipip6_tunnel_dst_find() for cleanup Yue Haibing
2025-08-27 14:45 ` Alexander Lobakin
2025-08-28 6:13 ` Yue Haibing
2025-08-28 6:44 ` Yue Haibing
2025-08-28 15:33 ` Alexander Lobakin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).