From: Yue Haibing <yuehaibing@huawei.com>
To: Alexander Lobakin <aleksander.lobakin@intel.com>
Cc: <davem@davemloft.net>, <dsahern@kernel.org>,
<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>,
<horms@kernel.org>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2 net-next] ipv6: sit: Add ipip6_tunnel_dst_find() for cleanup
Date: Mon, 1 Sep 2025 15:31:19 +0800 [thread overview]
Message-ID: <52416304-2334-4a61-971c-5d579b23ec51@huawei.com> (raw)
In-Reply-To: <18594f40-f86f-4a28-a97a-22d8d8b614b6@intel.com>
On 2025/8/29 23:46, Alexander Lobakin wrote:
> From: Yue Haibing <yuehaibing@huawei.com>
> Date: Fri, 29 Aug 2025 18:09:46 +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.
>
> Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>
>
>>
>> On a x86_64, with allmodconfig object size is also reduced:
>>
>> ./scripts/bloat-o-meter net/ipv6/sit.o net/ipv6/sit-new.o
>> add/remove: 5/3 grow/shrink: 3/4 up/down: 1841/-2275 (-434)
>> Function old new delta
>> ipip6_tunnel_dst_find - 1697 +1697
>> __pfx_ipip6_tunnel_dst_find - 64 +64
>> __UNIQUE_ID_modinfo2094 - 43 +43
>> ipip6_tunnel_xmit.isra.cold 79 88 +9
>> __UNIQUE_ID_modinfo2096 12 20 +8
>> __UNIQUE_ID___addressable_init_module2092 - 8 +8
>> __UNIQUE_ID___addressable_cleanup_module2093 - 8 +8
>> __func__ 55 59 +4
>> __UNIQUE_ID_modinfo2097 20 18 -2
>> __UNIQUE_ID___addressable_init_module2093 8 - -8
>> __UNIQUE_ID___addressable_cleanup_module2094 8 - -8
>> __UNIQUE_ID_modinfo2098 18 - -18
>> __UNIQUE_ID_modinfo2095 43 12 -31
>> descriptor 112 56 -56
>> ipip6_tunnel_xmit.isra 9910 7758 -2152
>> Total: Before=72537, After=72103, chg -0.60%
>>
>> Signed-off-by: Yue Haibing <yuehaibing@huawei.com>
>> ---
>> v2: add newlines before return in ipip6_tunnel_dst_find()
>> add bloat-o-meter info in commit log
>> ---
>> net/ipv6/sit.c | 95 ++++++++++++++++++++++++--------------------------
>> 1 file changed, 45 insertions(+), 50 deletions(-)
>>
>> diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
>> index 12496ba1b7d4..60bd7f01fa09 100644
>> --- a/net/ipv6/sit.c
>> +++ b/net/ipv6/sit.c
>> @@ -848,6 +848,49 @@ 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 false;
>> + }
>> +
>> + 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 +910,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 +919,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;
>> }
>
> Ooops, sorry that I didn't notice that before.
> You can flatten the conditions now:
Sorry for miss this, will resend with proposed changes, thanks.
>
> if ((dev->priv_flags & IFF_ISATAP) &&
> !ipip6_tunnel_dst_find(skb, &dst, true))
> goto tx_error;
>
>>
>> @@ -907,32 +927,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;
>> }
>
> Same here:
>
> if (!dst && !ipip6_tunnel_dst_find(skb, &dst, false))
> goto tx_error;
>
> Thanks,
> Olek
>
prev parent reply other threads:[~2025-09-01 7:31 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-29 10:09 Yue Haibing
2025-08-29 15:46 ` Alexander Lobakin
2025-09-01 7:31 ` Yue Haibing [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52416304-2334-4a61-971c-5d579b23ec51@huawei.com \
--to=yuehaibing@huawei.com \
--cc=aleksander.lobakin@intel.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®