Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ipv6: sit: Add ipip6_tunnel_dst_find() for cleanup

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.

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>
Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Link: https://patch.msgid.link/20250901114857.1968513-1-yuehaibing@huawei.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Yue Haibing and committed by
Paolo Abeni
61481d72 6bec791b

+48 -56
+48 -56
net/ipv6/sit.c
··· 848 848 return dst; 849 849 } 850 850 851 + static bool ipip6_tunnel_dst_find(struct sk_buff *skb, __be32 *dst, 852 + bool is_isatap) 853 + { 854 + const struct ipv6hdr *iph6 = ipv6_hdr(skb); 855 + struct neighbour *neigh = NULL; 856 + const struct in6_addr *addr6; 857 + bool found = false; 858 + int addr_type; 859 + 860 + if (skb_dst(skb)) 861 + neigh = dst_neigh_lookup(skb_dst(skb), &iph6->daddr); 862 + 863 + if (!neigh) { 864 + net_dbg_ratelimited("nexthop == NULL\n"); 865 + return false; 866 + } 867 + 868 + addr6 = (const struct in6_addr *)&neigh->primary_key; 869 + addr_type = ipv6_addr_type(addr6); 870 + 871 + if (is_isatap) { 872 + if ((addr_type & IPV6_ADDR_UNICAST) && 873 + ipv6_addr_is_isatap(addr6)) { 874 + *dst = addr6->s6_addr32[3]; 875 + found = true; 876 + } 877 + } else { 878 + if (addr_type == IPV6_ADDR_ANY) { 879 + addr6 = &ipv6_hdr(skb)->daddr; 880 + addr_type = ipv6_addr_type(addr6); 881 + } 882 + 883 + if ((addr_type & IPV6_ADDR_COMPATv4) != 0) { 884 + *dst = addr6->s6_addr32[3]; 885 + found = true; 886 + } 887 + } 888 + 889 + neigh_release(neigh); 890 + 891 + return found; 892 + } 893 + 851 894 /* 852 895 * This function assumes it is being called from dev_queue_xmit() 853 896 * and that skb is filled properly by that function. ··· 910 867 __be32 dst = tiph->daddr; 911 868 struct flowi4 fl4; 912 869 int mtu; 913 - const struct in6_addr *addr6; 914 - int addr_type; 915 870 u8 ttl; 916 871 u8 protocol = IPPROTO_IPV6; 917 872 int t_hlen = tunnel->hlen + sizeof(struct iphdr); ··· 918 877 tos = ipv6_get_dsfield(iph6); 919 878 920 879 /* ISATAP (RFC4214) - must come before 6to4 */ 921 - if (dev->priv_flags & IFF_ISATAP) { 922 - struct neighbour *neigh = NULL; 923 - bool do_tx_error = false; 924 - 925 - if (skb_dst(skb)) 926 - neigh = dst_neigh_lookup(skb_dst(skb), &iph6->daddr); 927 - 928 - if (!neigh) { 929 - net_dbg_ratelimited("nexthop == NULL\n"); 930 - goto tx_error; 931 - } 932 - 933 - addr6 = (const struct in6_addr *)&neigh->primary_key; 934 - addr_type = ipv6_addr_type(addr6); 935 - 936 - if ((addr_type & IPV6_ADDR_UNICAST) && 937 - ipv6_addr_is_isatap(addr6)) 938 - dst = addr6->s6_addr32[3]; 939 - else 940 - do_tx_error = true; 941 - 942 - neigh_release(neigh); 943 - if (do_tx_error) 944 - goto tx_error; 945 - } 880 + if ((dev->priv_flags & IFF_ISATAP) && 881 + !ipip6_tunnel_dst_find(skb, &dst, true)) 882 + goto tx_error; 946 883 947 884 if (!dst) 948 885 dst = try_6rd(tunnel, &iph6->daddr); 949 886 950 - if (!dst) { 951 - struct neighbour *neigh = NULL; 952 - bool do_tx_error = false; 953 - 954 - if (skb_dst(skb)) 955 - neigh = dst_neigh_lookup(skb_dst(skb), &iph6->daddr); 956 - 957 - if (!neigh) { 958 - net_dbg_ratelimited("nexthop == NULL\n"); 959 - goto tx_error; 960 - } 961 - 962 - addr6 = (const struct in6_addr *)&neigh->primary_key; 963 - addr_type = ipv6_addr_type(addr6); 964 - 965 - if (addr_type == IPV6_ADDR_ANY) { 966 - addr6 = &ipv6_hdr(skb)->daddr; 967 - addr_type = ipv6_addr_type(addr6); 968 - } 969 - 970 - if ((addr_type & IPV6_ADDR_COMPATv4) != 0) 971 - dst = addr6->s6_addr32[3]; 972 - else 973 - do_tx_error = true; 974 - 975 - neigh_release(neigh); 976 - if (do_tx_error) 977 - goto tx_error; 978 - } 887 + if (!dst && !ipip6_tunnel_dst_find(skb, &dst, false)) 888 + goto tx_error; 979 889 980 890 flowi4_init_output(&fl4, tunnel->parms.link, tunnel->fwmark, 981 891 tos & INET_DSCP_MASK, RT_SCOPE_UNIVERSE,