ipv6: add IPV6_CALL() helper
Subsystems (20)
PATCH 1/1 ipv6: add IPV6_CALL() helper
ipv6_stub use is racy, we should add READ_ONCE() and WRITE_ONCE(), even if this pointer can only change once.
Add IPV6_CALL() macro to factorize the READ_ONCE(), and perform direct calls when CONFIG_IPV6=y.
ipv6_stub->nd_tbl will need a separate patch.
$ size vmlinux.old vmlinux.new text data bss dec hex filename 37705007 23152761 4747540 65605308 3e90ebc vmlinux.0 37702861 23152665 4747540 65603066 3e905fa vmlinux
$ scripts/bloat-o-meter -t vmlinux.old vmlinux.new add/remove: 0/22 grow/shrink: 0/25 up/down: 0/-1025 (-1025) Function old new delta nexthop_select_path 832 828 -4 ipv4_confirm_neigh 426 422 -4 fib_detect_death 348 344 -4 br_do_suppress_nd 671 667 -4 udp_lib_setsockopt 893 888 -5 set_xfrm_gro_udp_encap_rcv 117 112 -5 __ipv6_neigh_lookup_noref_stub 336 328 -8 udp_tunnel_encap_enable 57 45 -12 udp_tunnel6_dst_lookup 465 453 -12 setup_udp_tunnel_sock 251 239 -12 nexthop_free_rcu 254 242 -12 bpf_xmit 1203 1191 -12 bpf_input 500 488 -12 __remove_nexthop 1705 1693 -12 xfrm6_tunnel_check_size 631 616 -15 sch_frag_xmit_hook 1233 1218 -15 icmp_build_probe 922 907 -15 eafnosupport_fib6_select_path 15 - -15 ip_neigh_gw6 708 692 -16 __pfx_eafnosupport_ipv6_route_input 16 - -16 __pfx_eafnosupport_ipv6_fragment 16 - -16 __pfx_eafnosupport_ipv6_dst_lookup_flow 16 - -16 __pfx_eafnosupport_ipv6_dev_find 16 - -16 __pfx_eafnosupport_ip6_mtu_from_fib6 16 - -16 __pfx_eafnosupport_ip6_del_rt 16 - -16 __pfx_eafnosupport_fib6_table_lookup 16 - -16 __pfx_eafnosupport_fib6_select_path 16 - -16 __pfx_eafnosupport_fib6_nh_init 16 - -16 __pfx_eafnosupport_fib6_lookup 16 - -16 __pfx_eafnosupport_fib6_get_table 16 - -16 eafnosupport_ip6_mtu_from_fib6 17 - -17 eafnosupport_fib6_get_table 17 - -17 skb_do_redirect 2878 2858 -20 eafnosupport_ipv6_route_input 20 - -20 eafnosupport_ip6_del_rt 20 - -20 eafnosupport_fib6_table_lookup 20 - -20 eafnosupport_fib6_lookup 20 - -20 eafnosupport_ipv6_dst_lookup_flow 22 - -22 eafnosupport_ipv6_dev_find 22 - -22 nh_rt_cache_flush 191 167 -24 fib_check_nh 1580 1556 -24 nat_keepalive_work_single 1319 1292 -27 eafnosupport_ipv6_fragment 35 - -35 eafnosupport_fib6_nh_init 49 - -49 rtm_new_nexthop 8495 8441 -54 bpf_ipv6_fib_lookup 1107 1043 -64 .compoundliteral 5792 5592 -200 Total: Before=25219423, After=25218398, chg -0.00%
---
v2: rename fib6_update_sernum to fib6_update_sernum_stub (Jakub feedback)
v1: https://lore.kernel.org/netdev/[email protected]/
drivers/infiniband/core/addr.c | 2 +- drivers/infiniband/sw/rxe/rxe_net.c | 6 ++--- .../ethernet/mellanox/mlx5/core/en/tc_tun.c | 4 +-- .../ethernet/netronome/nfp/flower/action.c | 2 +- .../netronome/nfp/flower/tunnel_conf.c | 6 ++--- drivers/net/ethernet/sfc/tc_encap_actions.c | 4 +-- drivers/net/gtp.c | 2 +- drivers/net/ovpn/peer.c | 4 +-- drivers/net/ovpn/udp.c | 2 +- drivers/net/usb/cdc_mbim.c | 2 +- drivers/net/vxlan/vxlan_multicast.c | 4 +-- drivers/net/wireguard/socket.c | 4 +-- include/net/ipv6_stubs.h | 26 +++++++++++++------ include/net/udp_tunnel.h | 2 +- net/core/filter.c | 12 ++++----- net/core/lwt_bpf.c | 4 +-- net/ipv4/fib_semantics.c | 4 +-- net/ipv4/icmp.c | 5 +++- net/ipv4/nexthop.c | 15 ++++++----- net/ipv4/udp.c | 4 +-- net/ipv6/addrconf_core.c | 10 ++++--- net/ipv6/af_inet6.c | 14 +++++----- net/ipv6/ip6_fib.c | 2 +- net/ipv6/ip6_output.c | 1 + net/ipv6/ip6_udp_tunnel.c | 3 +-- net/ipv6/ndisc.c | 1 + net/mpls/af_mpls.c | 2 +- net/openvswitch/actions.c | 2 +- net/sched/sch_frag.c | 5 ++-- net/tipc/udp_media.c | 8 +++--- net/xfrm/espintcp.c | 2 +- net/xfrm/xfrm_nat_keepalive.c | 4 +-- net/xfrm/xfrm_output.c | 2 +- 33 files changed, 96 insertions(+), 74 deletions(-)
drivers/infiniband/core/addr.c +0 -0
@@ -411,7 +411,7 @@ static int addr6_resolve(struct sockaddr *src_sock,
fl6.saddr = src_in->sin6_addr; fl6.flowi6_oif = addr->bound_dev_if;
- dst = ipv6_stub->ipv6_dst_lookup_flow(addr->net, NULL, &fl6, NULL);
+ dst = IPV6_CALL(ip6_dst_lookup_flow)(addr->net, NULL, &fl6, NULL); if (IS_ERR(dst)) return PTR_ERR(dst);
drivers/infiniband/sw/rxe/rxe_net.c +0 -0
@@ -138,9 +138,9 @@ static struct dst_entry *rxe_find_route6(struct rxe_qp *qp,
memcpy(&fl6.daddr, daddr, sizeof(*daddr)); fl6.flowi6_proto = IPPROTO_UDP;
- ndst = ipv6_stub->ipv6_dst_lookup_flow(sock_net(recv_sockets.sk6->sk),
- recv_sockets.sk6->sk, &fl6,
- NULL);
+ ndst = IPV6_CALL(ip6_dst_lookup_flow)(sock_net(recv_sockets.sk6->sk),
+ recv_sockets.sk6->sk, &fl6,
+ NULL);
if (IS_ERR(ndst)) {
rxe_dbg_qp(qp, "no route to %pI6\n", daddr);
return NULL;drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +0 -0
@@ -453,8 +453,8 @@ static int mlx5e_route_lookup_ipv6_get(struct mlx5e_priv *priv,
if (tunnel && tunnel->get_remote_ifindex) attr->fl.fl6.flowi6_oif = tunnel->get_remote_ifindex(dev); - dst = ipv6_stub->ipv6_dst_lookup_flow(dev_net(dev), NULL, &attr->fl.fl6, - NULL); + dst = IPV6_CALL(ip6_dst_lookup_flow)(dev_net(dev), NULL, &attr->fl.fl6, + NULL); if (IS_ERR(dst)) return PTR_ERR(dst);
drivers/net/ethernet/netronome/nfp/flower/action.c +0 -0
@@ -470,7 +470,7 @@ nfp_fl_set_tun(struct nfp_app *app, struct nfp_fl_set_tun *set_tun,
flow.daddr = ip_tun->key.u.ipv6.dst;
flow.flowi4_proto = IPPROTO_UDP;
- dst = ipv6_stub->ipv6_dst_lookup_flow(net, NULL, &flow, NULL);
+ dst = IPV6_CALL(ip6_dst_lookup_flow)(net, NULL, &flow, NULL);
if (!IS_ERR(dst)) {
set_tun->ttl = ip6_dst_hoplimit(dst);
dst_release(dst);drivers/net/ethernet/netronome/nfp/flower/tunnel_conf.c +0 -0
@@ -650,7 +650,7 @@ static void nfp_tun_neigh_update(struct work_struct *work)
flow6.daddr = *(struct in6_addr *)n->primary_key;
if (!neigh_invalid) {
struct dst_entry *dst;- /* Use ipv6_dst_lookup_flow to populate flow6->saddr
+ /* Use ip6_dst_lookup_flow to populate flow6->saddr
* and other fields. This information is only needed
* for new entries, lookup can be skipped when an entry
* gets invalidated - as only the daddr is needed for
@@ -815,8 +815,8 @@ void nfp_tunnel_request_route_v6(struct nfp_app *app, struct sk_buff *skb)
flow.flowi6_proto = IPPROTO_UDP;
#if IS_ENABLED(CONFIG_INET) && IS_ENABLED(CONFIG_IPV6)
- dst = ipv6_stub->ipv6_dst_lookup_flow(dev_net(netdev), NULL, &flow,
- NULL);
+ dst = IPV6_CALL(ip6_dst_lookup_flow)(dev_net(netdev), NULL, &flow,
+ NULL); if (IS_ERR(dst)) goto fail_rcu_unlock;
#else
drivers/net/ethernet/sfc/tc_encap_actions.c +0 -0
@@ -149,8 +149,8 @@ static int efx_bind_neigh(struct efx_nic *efx,#if IS_ENABLED (CONFIG_IPV6 )
struct dst_entry *dst;
- dst = ipv6_stub->ipv6_dst_lookup_flow(net, NULL, &flow6,
- NULL);
+ dst = IPV6_CALL(ip6_dst_lookup_flow)(net, NULL, &flow6,
+ NULL);
rc = PTR_ERR_OR_ZERO(dst);
if (rc) {
NL_SET_ERR_MSG_MOD(extack, "Failed to lookup route for IPv6 encap");drivers/net/gtp.c +0 -0
@@ -374,7 +374,7 @@ static struct rt6_info *ip6_route_output_gtp(struct net *net,
fl6->saddr = *saddr; fl6->flowi6_proto = sk->sk_protocol;
- dst = ipv6_stub->ipv6_dst_lookup_flow(net, sk, fl6, NULL);
+ dst = IPV6_CALL(ip6_dst_lookup_flow)(net, sk, fl6, NULL); if (IS_ERR(dst)) return ERR_PTR(-ENETUNREACH);
drivers/net/ovpn/peer.c +0 -0
@@ -821,8 +821,8 @@ static struct in6_addr ovpn_nexthop_from_rt6(struct ovpn_priv *ovpn,
.daddr = dest, };
- entry = ipv6_stub->ipv6_dst_lookup_flow(dev_net(ovpn->dev), NULL, &fl,
- NULL);
+ entry = IPV6_CALL(ip6_dst_lookup_flow)(dev_net(ovpn->dev), NULL, &fl,
+ NULL);
if (IS_ERR(entry)) {
net_dbg_ratelimited("%s: no route to host %pI6c\n",
netdev_name(ovpn->dev), &dest);drivers/net/ovpn/udp.c +0 -0
@@ -251,7 +251,7 @@ static int ovpn_udp6_output(struct ovpn_peer *peer, struct ovpn_bind *bind,
dst_cache_reset(cache); }
- dst = ipv6_stub->ipv6_dst_lookup_flow(sock_net(sk), sk, &fl, NULL);
+ dst = IPV6_CALL(ip6_dst_lookup_flow)(sock_net(sk), sk, &fl, NULL);
if (IS_ERR(dst)) {
ret = PTR_ERR(dst);
net_dbg_ratelimited("%s: no route to host %pISpc: %d\n",drivers/net/usb/cdc_mbim.c +0 -0
@@ -343,7 +343,7 @@ static void do_neigh_solicit(struct usbnet *dev, u8 *buf, u16 tci)
in6_dev_put(in6_dev); /* ipv6_stub != NULL if in6_dev_get returned an inet6_dev */
- ipv6_stub->ndisc_send_na(netdev, &iph->saddr, &msg->target,
+ IPV6_CALL(ndisc_send_na)(netdev, &iph->saddr, &msg->target,
is_router /* router */, true /* solicited */, false /* override */,
drivers/net/vxlan/vxlan_multicast.c +0 -0
@@ -39,7 +39,7 @@ int vxlan_igmp_join(struct vxlan_dev *vxlan, union vxlan_addr *rip,
sk = sock6->sock->sk; lock_sock(sk); - ret = ipv6_stub->ipv6_sock_mc_join(sk, ifindex, + ret = IPV6_CALL(ipv6_sock_mc_join)(sk, ifindex, &ip->sin6.sin6_addr); release_sock(sk);
#endif
@@ -73,7 +73,7 @@ int vxlan_igmp_leave(struct vxlan_dev *vxlan, union vxlan_addr *rip,
sk = sock6->sock->sk; lock_sock(sk); - ret = ipv6_stub->ipv6_sock_mc_drop(sk, ifindex, + ret = IPV6_CALL(ipv6_sock_mc_drop)(sk, ifindex, &ip->sin6.sin6_addr); release_sock(sk);
#endif
drivers/net/wireguard/socket.c +0 -0
@@ -136,8 +136,8 @@ static int send6(struct wg_device *wg, struct sk_buff *skb,
if (cache)
dst_cache_reset(cache);
}
- dst = ipv6_stub->ipv6_dst_lookup_flow(sock_net(sock), sock, &fl,
- NULL);
+ dst = IPV6_CALL(ip6_dst_lookup_flow)(sock_net(sock), sock, &fl,
+ NULL);
if (IS_ERR(dst)) {
ret = PTR_ERR(dst);
net_dbg_ratelimited("%s: No route to %pISpfsc, error %d\n",include/net/ipv6_stubs.h +4 -0
@@ -17,18 +17,22 @@ struct fib6_nh;struct fib6_config ;struct fib6_result ; +int ipv6_route_input (struct sk_buff *skb); +/* This is ugly, ideally these symbols should be built * into the core kernel. */ struct ipv6_stub { +struct neigh_table *nd_tbl; +#if !defined(CONFIG_IPV6 )
int (*ipv6_sock_mc_join)(struct sock *sk, int ifindex,
const struct in6_addr *addr);
int (*ipv6_sock_mc_drop)(struct sock *sk, int ifindex,
const struct in6_addr *addr);
- struct dst_entry *(*ipv6_dst_lookup_flow)(struct net *net,
- const struct sock *sk,
- struct flowi6 *fl6,
- const struct in6_addr *final_dst);
+ struct dst_entry *(*ip6_dst_lookup_flow)(struct net *net,
+ const struct sock *sk,
+ struct flowi6 *fl6,
+ const struct in6_addr *final_dst);
int (*ipv6_route_input)(struct sk_buff *skb);
struct fib6_table *(*fib6_get_table)(struct net *net, u32 id);
@@ -49,7 +53,7 @@ struct ipv6_stub {
struct netlink_ext_ack *extack);
void (*fib6_nh_release)(struct fib6_nh *fib6_nh);
void (*fib6_nh_release_dsts)(struct fib6_nh *fib6_nh);
- void (*fib6_update_sernum)(struct net *net, struct fib6_info *rt);
+ void (*fib6_update_sernum_stub)(struct net *net, struct fib6_info *rt);
int (*ip6_del_rt)(struct net *net, struct fib6_info *rt, bool skip_notify);
void (*fib6_rt_update)(struct net *net, struct fib6_info *rt,
struct nl_info *info);
@@ -67,14 +71,14 @@ struct ipv6_stub {
int (*xfrm6_rcv_encap)(struct sk_buff *skb, int nexthdr, __be32 spi,
int encap_type); #endif
- struct neigh_table *nd_tbl;
- int (*ipv6_fragment)(struct net *net, struct sock *sk, struct sk_buff *skb,
- int (*output)(struct net *, struct sock *, struct sk_buff *));
+ int (*ip6_fragment)(struct net *net, struct sock *sk, struct sk_buff *skb,
+ int (*output)(struct net *, struct sock *, struct sk_buff *)); struct net_device *(*ipv6_dev_find)(struct net *net, const struct in6_addr *addr, struct net_device *dev); int (*ip6_xmit)(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6, __u32 mark, struct ipv6_txoptions *opt, int tclass, u32 priority);
+#endif
};
extern const struct ipv6_stub *ipv6_stub __read_mostly;
@@ -99,4 +103,10 @@ struct ipv6_bpf_stub {
};
extern const struct ipv6_bpf_stub *ipv6_bpf_stub __read_mostly;
+#if defined(CONFIG_IPV6)
+#define IPV6_CALL(X) (X)
+#else
+#define IPV6_CALL(X) (READ_ONCE(ipv6_stub)->X)
+#endif
+
#endif
include/net/udp_tunnel.h +0 -0
@@ -230,7 +230,7 @@ static inline void udp_tunnel_encap_enable(struct sock *sk)#if IS_ENABLED (CONFIG_IPV6 )
if (READ_ONCE(sk->sk_family) == PF_INET6) - ipv6_stub->udpv6_encap_enable(); + IPV6_CALL(udpv6_encap_enable)(); #endif udp_encap_enable();
}
net/core/filter.c +0 -0
@@ -2276,7 +2276,7 @@ static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev,
.saddr = ip6h->saddr, };
- dst = ipv6_stub->ipv6_dst_lookup_flow(net, NULL, &fl6, NULL);
+ dst = IPV6_CALL(ip6_dst_lookup_flow)(net, NULL, &fl6, NULL); if (IS_ERR(dst)) goto out_drop;
@@ -6281,11 +6281,11 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
params->tbid = 0; }
- tb = ipv6_stub->fib6_get_table(net, tbid);
+ tb = IPV6_CALL(fib6_get_table)(net, tbid); if (unlikely(!tb)) return BPF_FIB_LKUP_RET_NOT_FWDED;
- err = ipv6_stub->fib6_table_lookup(net, tb, oif, &fl6, &res,
+ err = IPV6_CALL(fib6_table_lookup)(net, tb, oif, &fl6, &res,
strict);
} else {
if (flags & BPF_FIB_LOOKUP_MARK)
@@ -6296,7 +6296,7 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
fl6.flowi6_tun_key.tun_id = 0;
fl6.flowi6_uid = sock_net_uid(net, NULL);- err = ipv6_stub->fib6_lookup(net, oif, &fl6, &res, strict);
+ err = IPV6_CALL(fib6_lookup)(net, oif, &fl6, &res, strict); } if (unlikely(err || IS_ERR_OR_NULL(res.f6i) || @@ -6317,11 +6317,11 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params, return BPF_FIB_LKUP_RET_NOT_FWDED; }
- ipv6_stub->fib6_select_path(net, &res, &fl6, fl6.flowi6_oif,
+ IPV6_CALL(fib6_select_path)(net, &res, &fl6, fl6.flowi6_oif,
fl6.flowi6_oif != 0, NULL, strict);
if (check_mtu) {
- mtu = ipv6_stub->ip6_mtu_from_fib6(&res, dst, src);
+ mtu = IPV6_CALL(ip6_mtu_from_fib6)(&res, dst, src);
if (params->tot_len > mtu) {
params->mtu_result = mtu; /* union with tot_len */
return BPF_FIB_LKUP_RET_FRAG_NEEDED;net/core/lwt_bpf.c +0 -0
@@ -103,7 +103,7 @@ static int bpf_lwt_input_reroute(struct sk_buff *skb)
dev_put(dev);
} else if (skb->protocol == htons(ETH_P_IPV6)) {
skb_dst_drop(skb);
- err = ipv6_stub->ipv6_route_input(skb);
+ err = IPV6_CALL(ipv6_route_input)(skb);
} else {
err = -EAFNOSUPPORT;
}
@@ -233,7 +233,7 @@ static int bpf_lwt_xmit_reroute(struct sk_buff *skb)
fl6.daddr = iph6->daddr;
fl6.saddr = iph6->saddr;- dst = ipv6_stub->ipv6_dst_lookup_flow(net, skb->sk, &fl6, NULL);
+ dst = IPV6_CALL(ip6_dst_lookup_flow)(net, skb->sk, &fl6, NULL);
if (IS_ERR(dst)) {
err = PTR_ERR(dst);
goto err;net/ipv4/fib_semantics.c +0 -0
@@ -1083,7 +1083,7 @@ static int fib_check_nh_v6_gw(struct net *net, struct fib_nh *nh,
struct fib6_nh fib6_nh = {};
int err;- err = ipv6_stub->fib6_nh_init(net, &fib6_nh, &cfg, GFP_KERNEL, extack);
+ err = IPV6_CALL(fib6_nh_init)(net, &fib6_nh, &cfg, GFP_KERNEL, extack);
if (!err) {
nh->fib_nh_dev = fib6_nh.fib_nh_dev;
netdev_hold(nh->fib_nh_dev, &nh->fib_nh_dev_tracker,
@@ -1091,7 +1091,7 @@ static int fib_check_nh_v6_gw(struct net *net, struct fib_nh *nh,
nh->fib_nh_oif = nh->fib_nh_dev->ifindex;
nh->fib_nh_scope = RT_SCOPE_LINK;- ipv6_stub->fib6_nh_release(&fib6_nh);
+ IPV6_CALL(fib6_nh_release)(&fib6_nh); } return err;
net/ipv4/icmp.c +0 -0
@@ -1342,7 +1342,10 @@ bool icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr)
case ICMP_AFI_IP6: if (iio->ident.addr.ctype3_hdr.addrlen != sizeof(struct in6_addr)) goto send_mal_query;
- dev = ipv6_stub->ipv6_dev_find(net, &iio->ident.addr.ip_addr.ipv6_addr, dev);
+ dev = IPV6_CALL(ipv6_dev_find)(
+ net,
+ &iio->ident.addr.ip_addr.ipv6_addr,
+ dev); dev_hold(dev); break;
#endif
net/ipv4/nexthop.c +1 -0
@@ -16,6 +16,7 @@#include <net/nexthop.h> #include <net/route.h> #include <net/sock.h> +#include <net/ip6_route.h> #define NH_RES_DEFAULT_IDLE_TIMER (120 * HZ)#define NH_RES_DEFAULT_UNBALANCED_TIMER 0/* No forced rebalancing. */
@@ -510,7 +511,7 @@ static void nexthop_free_single(struct nexthop *nh)
fib_nh_release(nh->net, &nhi->fib_nh); break; case AF_INET6: - ipv6_stub->fib6_nh_release(&nhi->fib6_nh); + IPV6_CALL(fib6_nh_release)(&nhi->fib6_nh); break; } kfree(nhi); @@ -2143,7 +2144,7 @@ static void __remove_nexthop_fib(struct net *net, struct nexthop *nh) fib6_info_hold(f6i); spin_unlock_bh(&nh->lock); - ipv6_stub->ip6_del_rt(net, f6i, + IPV6_CALL(ip6_del_rt)(net, f6i, !READ_ONCE(net->ipv4.sysctl_nexthop_compat_mode)); spin_lock_bh(&nh->lock); @@ -2201,7 +2202,7 @@ static void nh_rt_cache_flush(struct net *net, struct nexthop *nh, rt_cache_flush(net); list_for_each_entry(f6i, &nh->f6i_list, nh_list)
- ipv6_stub->fib6_update_sernum(net, f6i);
+ IPV6_CALL(fib6_update_sernum_stub)(net, f6i);
/* if an IPv6 group was replaced, we have to release all old * dsts to make sure all refcounts are released @@ -2215,7 +2216,7 @@ static void nh_rt_cache_flush(struct net *net, struct nexthop *nh, struct nh_info *nhi = rtnl_dereference(nhge->nh->nh_info); if (nhi->family == AF_INET6) - ipv6_stub->fib6_nh_release_dsts(&nhi->fib6_nh); + IPV6_CALL(fib6_nh_release_dsts)(&nhi->fib6_nh); }
}
@@ -2496,7 +2497,7 @@ static void __nexthop_replace_notify(struct net *net, struct nexthop *nh,
} list_for_each_entry(f6i, &nh->f6i_list, nh_list)
- ipv6_stub->fib6_rt_update(net, f6i, info);
+ IPV6_CALL(fib6_rt_update)(net, f6i, info);
}
/* send RTM_NEWROUTE with REPLACE flag set for all FIB entries
@@ -2869,13 +2870,13 @@ static int nh_create_ipv6(struct net *net, struct nexthop *nh,
fib6_cfg.fc_flags |= RTF_GATEWAY;
/* sets nh_dev if successful */
- err = ipv6_stub->fib6_nh_init(net, fib6_nh, &fib6_cfg, GFP_KERNEL,
+ err = IPV6_CALL(fib6_nh_init)(net, fib6_nh, &fib6_cfg, GFP_KERNEL,
extack);
if (err) {
/* IPv6 is not enabled, don't call fib6_nh_release */
if (err == -EAFNOSUPPORT)
goto out;
- ipv6_stub->fib6_nh_release(fib6_nh);
+ IPV6_CALL(fib6_nh_release)(fib6_nh);
} else {
nh->nh_flags = fib6_nh->fib_nh_flags;
}net/ipv4/udp.c +0 -0
@@ -2966,7 +2966,7 @@ static void set_xfrm_gro_udp_encap_rcv(__u16 encap_type, unsigned short family,
if (udp_test_bit(GRO_ENABLED, sk) && encap_type == UDP_ENCAP_ESPINUDP) {
if (IS_ENABLED(CONFIG_IPV6) && family == AF_INET6)
- new_gro_receive = ipv6_stub->xfrm6_gro_udp_encap_rcv;
+ new_gro_receive = IPV6_CALL(xfrm6_gro_udp_encap_rcv);
else
new_gro_receive = xfrm4_gro_udp_encap_rcv;@@ -3039,7 +3039,7 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
#if IS_ENABLED(CONFIG_IPV6) if (sk->sk_family == AF_INET6) WRITE_ONCE(up->encap_rcv, - ipv6_stub->xfrm6_udp_encap_rcv); + IPV6_CALL(xfrm6_udp_encap_rcv)); else #endif WRITE_ONCE(up->encap_rcv,
net/ipv6/addrconf_core.c +2 -1
@@ -129,7 +129,8 @@ int inet6addr_validator_notifier_call_chain(unsigned long val, void *v) }EXPORT_SYMBOL (inet6addr_validator_notifier_call_chain); -static struct dst_entry *eafnosupport_ipv6_dst_lookup_flow(struct net *net, +#if !defined(CONFIG_IPV6 ) +static struct dst_entry *eafnosupport_ip6_dst_lookup_flow(struct net *net,
const struct sock *sk, struct flowi6 *fl6,
const struct in6_addr *final_dst)
@@ -203,9 +204,11 @@ static struct net_device *eafnosupport_ipv6_dev_find(struct net *net, const stru
{
return ERR_PTR(-EAFNOSUPPORT); }
+#endif
const struct ipv6_stub *ipv6_stub __read_mostly = &(struct ipv6_stub) {
- .ipv6_dst_lookup_flow = eafnosupport_ipv6_dst_lookup_flow,
+#if !defined(CONFIG_IPV6)
+ .ip6_dst_lookup_flow = eafnosupport_ip6_dst_lookup_flow,
.ipv6_route_input = eafnosupport_ipv6_route_input,
.fib6_get_table = eafnosupport_fib6_get_table,
.fib6_table_lookup = eafnosupport_fib6_table_lookup,
@@ -214,8 +217,9 @@ const struct ipv6_stub *ipv6_stub __read_mostly = &(struct ipv6_stub) {
.ip6_mtu_from_fib6 = eafnosupport_ip6_mtu_from_fib6,
.fib6_nh_init = eafnosupport_fib6_nh_init,
.ip6_del_rt = eafnosupport_ip6_del_rt,- .ipv6_fragment = eafnosupport_ipv6_fragment,
+ .ip6_fragment = eafnosupport_ipv6_fragment,
.ipv6_dev_find = eafnosupport_ipv6_dev_find,
+#endif
};
EXPORT_SYMBOL_GPL(ipv6_stub);
net/ipv6/af_inet6.c +0 -0
@@ -1023,16 +1023,18 @@ static struct pernet_operations inet6_net_ops = {
.exit = inet6_net_exit,
};
-static int ipv6_route_input(struct sk_buff *skb)
+int ipv6_route_input(struct sk_buff *skb)
{
ip6_route_input(skb);
return skb_dst(skb)->error;}
static const struct ipv6_stub ipv6_stub_impl = {
+ .nd_tbl = &nd_tbl,
+#if !defined(CONFIG_IPV6)
.ipv6_sock_mc_join = ipv6_sock_mc_join, .ipv6_sock_mc_drop = ipv6_sock_mc_drop,
- .ipv6_dst_lookup_flow = ip6_dst_lookup_flow,
+ .ip6_dst_lookup_flow = ip6_dst_lookup_flow,
.ipv6_route_input = ipv6_route_input,
.fib6_get_table = fib6_get_table,
.fib6_table_lookup = fib6_table_lookup,
@@ -1042,7 +1044,7 @@ static const struct ipv6_stub ipv6_stub_impl = {
.fib6_nh_init = fib6_nh_init,
.fib6_nh_release = fib6_nh_release,
.fib6_nh_release_dsts = fib6_nh_release_dsts,
- .fib6_update_sernum = fib6_update_sernum_stub,
+ .fib6_update_sernum_stub = fib6_update_sernum_stub,
.fib6_rt_update = fib6_rt_update,
.ip6_del_rt = ip6_del_rt,
.udpv6_encap_enable = udpv6_encap_enable,
@@ -1053,10 +1055,10 @@ static const struct ipv6_stub ipv6_stub_impl = {
.xfrm6_gro_udp_encap_rcv = xfrm6_gro_udp_encap_rcv,
.xfrm6_rcv_encap = xfrm6_rcv_encap, #endif
- .nd_tbl = &nd_tbl,
- .ipv6_fragment = ip6_fragment,
+ .ip6_fragment = ip6_fragment,
.ipv6_dev_find = ipv6_dev_find, .ip6_xmit = ip6_xmit,
+#endif
};
static const struct ipv6_bpf_stub ipv6_bpf_stub_impl = {
@@ -1235,7 +1237,7 @@ static int __init inet6_init(void)
/* ensure that ipv6 stubs are visible only after ipv6 is ready */ wmb(); - ipv6_stub = &ipv6_stub_impl; + WRITE_ONCE(ipv6_stub, &ipv6_stub_impl); ipv6_bpf_stub = &ipv6_bpf_stub_impl; out: return err;
net/ipv6/ip6_fib.c +0 -0
@@ -1405,7 +1405,7 @@ void fib6_update_sernum_upto_root(struct net *net, struct fib6_info *rt)
__fib6_update_sernum_upto_root(rt, fib6_new_sernum(net));
}
-/* allow ipv4 to update sernum via ipv6_stub */
+/* allow ipv4 (from nh_rt_cache_flush()) to update sernum via ipv6_stub */
void fib6_update_sernum_stub(struct net *net, struct fib6_info *f6i)
{
spin_lock_bh(&f6i->fib6_table->tb6_lock);net/ipv6/ip6_output.c +0 -0
@@ -1045,6 +1045,7 @@ int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
kfree_skb(skb); return err;
}
+EXPORT_SYMBOL_GPL(ip6_fragment);
static inline int ip6_rt_check(const struct rt6key *rt_key,
const struct in6_addr *fl_addr,
net/ipv6/ip6_udp_tunnel.c +0 -0
@@ -162,8 +162,7 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb,
fl6.fl6_dport = dport; fl6.flowlabel = ip6_make_flowinfo(dsfield, key->label);
- dst = ipv6_stub->ipv6_dst_lookup_flow(net, sock->sk, &fl6,
- NULL);
+ dst = IPV6_CALL(ip6_dst_lookup_flow)(net, sock->sk, &fl6, NULL);
if (IS_ERR(dst)) {
netdev_dbg(dev, "no route to %pI6\n", &fl6.daddr);
return ERR_PTR(-ENETUNREACH);net/ipv6/ndisc.c +0 -0
@@ -576,6 +576,7 @@ void ndisc_send_na(struct net_device *dev, const struct in6_addr *daddr,
ndisc_send_skb(skb, daddr, src_addr);
}
+EXPORT_SYMBOL(ndisc_send_na);
static void ndisc_send_unsol_na(struct net_device *dev) {
net/mpls/af_mpls.c +0 -0
@@ -642,7 +642,7 @@ static struct net_device *inet6_fib_lookup_dev(struct net *net,
memset(&fl6, 0, sizeof(fl6)); memcpy(&fl6.daddr, addr, sizeof(struct in6_addr)); - dst = ipv6_stub->ipv6_dst_lookup_flow(net, NULL, &fl6, NULL); + dst = IPV6_CALL(ip6_dst_lookup_flow)(net, NULL, &fl6, NULL); if (IS_ERR(dst)) return ERR_CAST(dst);
net/openvswitch/actions.c +0 -0
@@ -810,7 +810,7 @@ static void ovs_fragment(struct net *net, struct vport *vport,
skb_dst_set_noref(skb, &ovs_rt.dst); IP6CB(skb)->frag_max_size = mru;
- ipv6_stub->ipv6_fragment(net, skb->sk, skb, ovs_vport_output);
+ IPV6_CALL(ip6_fragment)(net, skb->sk, skb, ovs_vport_output);
refdst_drop(orig_dst);
} else {
WARN_ONCE(1, "Failed fragment ->%s: eth=%04x, MRU=%d, MTU=%d.",net/sched/sch_frag.c +1 -0
@@ -6,6 +6,7 @@#include <net/dst.h> #include <net/ip.h> #include <net/ip6_fib.h> +#include <net/ip6_route.h> struct sch_frag_data {
unsigned long dst; @@ -127,8 +128,8 @@ static int sch_fragment(struct net *net, struct sk_buff *skb, skb_dst_set_noref(skb, &sch_frag_rt.dst); IP6CB(skb)->frag_max_size = mru;
- ret = ipv6_stub->ipv6_fragment(net, skb->sk, skb,
- sch_frag_xmit);
+ ret = IPV6_CALL(ip6_fragment)(net, skb->sk, skb,
+ sch_frag_xmit);
local_unlock_nested_bh(&sch_frag_data_storage.bh_lock);
refdst_drop(orig_dst);
} else {net/tipc/udp_media.c +0 -0
@@ -207,9 +207,9 @@ static int tipc_udp_xmit(struct net *net, struct sk_buff *skb,
.saddr = src->ipv6, .flowi6_proto = IPPROTO_UDP };
- ndst = ipv6_stub->ipv6_dst_lookup_flow(net,
- ub->ubsock->sk,
- &fl6, NULL);
+ ndst = IPV6_CALL(ip6_dst_lookup_flow)(net,
+ ub->ubsock->sk,
+ &fl6, NULL);
if (IS_ERR(ndst)) {
err = PTR_ERR(ndst);
goto tx_error;
@@ -418,7 +418,7 @@ static int enable_mcast(struct udp_bearer *ub, struct udp_media_addr *remote)
#if IS_ENABLED(CONFIG_IPV6)
} else {
lock_sock(sk);
- err = ipv6_stub->ipv6_sock_mc_join(sk, ub->ifindex,
+ err = IPV6_CALL(ipv6_sock_mc_join)(sk, ub->ifindex,
&remote->ipv6);
release_sock(sk);#endif
net/xfrm/espintcp.c +0 -0
@@ -43,7 +43,7 @@ static void handle_esp(struct sk_buff *skb, struct sock *sk)
local_bh_disable(); #if IS_ENABLED(CONFIG_IPV6) if (sk->sk_family == AF_INET6) - ipv6_stub->xfrm6_rcv_encap(skb, IPPROTO_ESP, 0, TCP_ENCAP_ESPINTCP); + IPV6_CALL(xfrm6_rcv_encap)(skb, IPPROTO_ESP, 0, TCP_ENCAP_ESPINTCP); else #endif xfrm4_rcv_encap(skb, IPPROTO_ESP, 0, TCP_ENCAP_ESPINTCP);
net/xfrm/xfrm_nat_keepalive.c +0 -0
@@ -98,14 +98,14 @@ static int nat_keepalive_send_ipv6(struct sk_buff *skb,
local_lock_nested_bh(&nat_keepalive_sk_ipv6.bh_lock);
sk = this_cpu_read(nat_keepalive_sk_ipv6.sock);
sock_net_set(sk, net);
- dst = ipv6_stub->ipv6_dst_lookup_flow(net, sk, &fl6, NULL);
+ dst = IPV6_CALL(ip6_dst_lookup_flow)(net, sk, &fl6, NULL);
if (IS_ERR(dst)) {
local_unlock_nested_bh(&nat_keepalive_sk_ipv6.bh_lock);
return PTR_ERR(dst);
}
skb_dst_set(skb, dst);
- err = ipv6_stub->ip6_xmit(sk, skb, &fl6, skb->mark, NULL, 0, 0);
+ err = IPV6_CALL(ip6_xmit)(sk, skb, &fl6, skb->mark, NULL, 0, 0);
sock_net_set(sk, &init_net);
local_unlock_nested_bh(&nat_keepalive_sk_ipv6.bh_lock);
return err;net/xfrm/xfrm_output.c +0 -0
@@ -900,7 +900,7 @@ int xfrm6_tunnel_check_size(struct sk_buff *skb)
skb->protocol = htons(ETH_P_IPV6); if (xfrm6_local_dontfrag(sk)) - ipv6_stub->xfrm6_local_rxpmtu(skb, mtu); + IPV6_CALL(xfrm6_local_rxpmtu)(skb, mtu); else if (sk) xfrm_local_error(skb, mtu); else
--
2.53.0.473.g4a7958ca14-goog
Quoted 66 lines · Eric Dumazet
ipv6_stubuse is racy, we should addREAD_ONCE()andWRITE_ONCE(), even if this pointer can only change once.Add
IPV6_CALL()macro to factorize theREAD_ONCE(), and perform direct calls whenCONFIG_IPV6=y.
ipv6_stub->nd_tblwill need a separate patch.$ size vmlinux.old vmlinux.new text data bss dec hex filename 37705007 23152761 4747540 65605308 3e90ebc vmlinux.0 37702861 23152665 4747540 65603066 3e905fa vmlinux$ scripts/bloat-o-meter -t vmlinux.old vmlinux.new add/remove: 0/22 grow/shrink: 0/25 up/down: 0/-1025 (-1025) Function old new delta nexthop_select_path 832 828 -4 ipv4_confirm_neigh 426 422 -4 fib_detect_death 348 344 -4 br_do_suppress_nd 671 667 -4 udp_lib_setsockopt 893 888 -5 set_xfrm_gro_udp_encap_rcv 117 112 -5 __ipv6_neigh_lookup_noref_stub 336 328 -8 udp_tunnel_encap_enable 57 45 -12 udp_tunnel6_dst_lookup 465 453 -12 setup_udp_tunnel_sock 251 239 -12 nexthop_free_rcu 254 242 -12 bpf_xmit 1203 1191 -12 bpf_input 500 488 -12 __remove_nexthop 1705 1693 -12 xfrm6_tunnel_check_size 631 616 -15 sch_frag_xmit_hook 1233 1218 -15 icmp_build_probe 922 907 -15 eafnosupport_fib6_select_path 15 - -15 ip_neigh_gw6 708 692 -16 __pfx_eafnosupport_ipv6_route_input 16 - -16 __pfx_eafnosupport_ipv6_fragment 16 - -16 __pfx_eafnosupport_ipv6_dst_lookup_flow 16 - -16 __pfx_eafnosupport_ipv6_dev_find 16 - -16 __pfx_eafnosupport_ip6_mtu_from_fib6 16 - -16 __pfx_eafnosupport_ip6_del_rt 16 - -16 __pfx_eafnosupport_fib6_table_lookup 16 - -16 __pfx_eafnosupport_fib6_select_path 16 - -16 __pfx_eafnosupport_fib6_nh_init 16 - -16 __pfx_eafnosupport_fib6_lookup 16 - -16 __pfx_eafnosupport_fib6_get_table 16 - -16 eafnosupport_ip6_mtu_from_fib6 17 - -17 eafnosupport_fib6_get_table 17 - -17 skb_do_redirect 2878 2858 -20 eafnosupport_ipv6_route_input 20 - -20 eafnosupport_ip6_del_rt 20 - -20 eafnosupport_fib6_table_lookup 20 - -20 eafnosupport_fib6_lookup 20 - -20 eafnosupport_ipv6_dst_lookup_flow 22 - -22 eafnosupport_ipv6_dev_find 22 - -22 nh_rt_cache_flush 191 167 -24 fib_check_nh 1580 1556 -24 nat_keepalive_work_single 1319 1292 -27 eafnosupport_ipv6_fragment 35 - -35 eafnosupport_fib6_nh_init 49 - -49 rtm_new_nexthop 8495 8441 -54 bpf_ipv6_fib_lookup 1107 1043 -64 .compoundliteral 5792 5592 -200 Total: Before=25219423, After=25218398, chg -0.00%
Quoted 1 line
Signed-off-by Eric Dumazet <[email protected]>
Jakub Kicinski
maintainerQuoted 5 lines · On Mon, 2 Mar 2026 15:42:01 +0000 Eric Dumazet wrote:
ipv6_stubuse is racy, we should addREAD_ONCE()andWRITE_ONCE(), even if this pointer can only change once.Add
IPV6_CALL()macro to factorize theREAD_ONCE(), and perform direct calls whenCONFIG_IPV6=y.
Does not apply to net-next.
It sounds like we're going to remove IPV6=m, however, perhaps transform this patch into that removal?
Signature · 1 line
pw-bot: cr
Quoted 11 lines · Jakub Kicinski
Quoted 5 lines · On Mon, 2 Mar 2026 15:42:01 +0000 Eric Dumazet wrote:
ipv6_stubuse is racy, we should addREAD_ONCE()andWRITE_ONCE(), even if this pointer can only change once.Add
IPV6_CALL()macro to factorize theREAD_ONCE(), and perform direct calls whenCONFIG_IPV6=y.Does not apply to net-next.
It sounds like we're going to remove IPV6=m, however, perhaps transform this patch into that removal?
This seems orthogonal, unless the plan is to force IPV6=y ?
Jakub Kicinski
maintainerQuoted 6 lines · On Wed, 4 Mar 2026 03:13:40 +0100 Eric Dumazet wrote:
Quoted 5 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 2 Mar 2026 15:42:01 +0000 Eric Dumazet wrote:
ipv6_stubuse is racy, we should addREAD_ONCE()andWRITE_ONCE(), even if this pointer can only change once.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Add
IPV6_CALL()macro to factorize theREAD_ONCE(), and perform direct calls whenCONFIG_IPV6=y.Does not apply to net-next.
It sounds like we're going to remove IPV6=m, however, perhaps transform this patch into that removal?This seems orthogonal, unless the plan is to force IPV6=y ?
I thought if we remove IPV6=m we would delete ipv6_stub completely?
Quoted 11 lines · Jakub Kicinski
Quoted 9 lines · On Wed, 4 Mar 2026 03:13:40 +0100 Eric Dumazet wrote:
Quoted 8 lines · Jakub Kicinski
Quoted 5 lines · On Mon, 2 Mar 2026 15:42:01 +0000 Eric Dumazet wrote:
ipv6_stubuse is racy, we should addREAD_ONCE()andWRITE_ONCE(), even if this pointer can only change once.Add
IPV6_CALL()macro to factorize theREAD_ONCE(), and perform direct calls whenCONFIG_IPV6=y.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Does not apply to net-next.
It sounds like we're going to remove IPV6=m, however, perhaps transform this patch into that removal?This seems orthogonal, unless the plan is to force IPV6=y ?
I thought if we remove IPV6=m we would delete
ipv6_stubcompletely?
So we will add #ifdef around helpers ?
Lets take :
drivers/infiniband/core/addr.c +0 -0
100644
drivers/infiniband/core/addr.c +1 -1
@@ -411,7 +411,7 @@ static int addr6_resolve(struct sockaddr *src_sock, fl6.saddr = src_in->sin6_addr; fl6.flowi6_oif = addr->bound_dev_if; - dst = ipv6_stub->ipv6_dst_lookup_flow (addr->net,NULL , &fl6,NULL ); + dst =ip6_dst_lookup_flow (addr->net,NULL , &fl6,NULL );if (IS_ERR (dst))return PTR_ERR (dst);
Is the plan to define ipv6_dst_lookup_flow() differently for IPV6=y and IPV6=n ?
Quoted 40 lines · Eric Dumazet
Quoted 11 lines · Jakub Kicinski
Quoted 9 lines · On Wed, 4 Mar 2026 03:13:40 +0100 Eric Dumazet wrote:
Quoted 8 lines · Jakub Kicinski
Quoted 5 lines · On Mon, 2 Mar 2026 15:42:01 +0000 Eric Dumazet wrote:
ipv6_stubuse is racy, we should addREAD_ONCE()andWRITE_ONCE(), even if this pointer can only change once.Add
IPV6_CALL()macro to factorize theREAD_ONCE(), and perform direct calls whenCONFIG_IPV6=y.Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Does not apply to net-next.
It sounds like we're going to remove IPV6=m, however, perhaps transform this patch into that removal?This seems orthogonal, unless the plan is to force IPV6=y ?
I thought if we remove IPV6=m we would delete
ipv6_stubcompletely?So we will add #ifdef around helpers ?
Lets take :
drivers/infiniband/core/addr.c +0
-0100644
drivers/infiniband/core/addr.c +1
-1@@ -411,7 +411,7 @@ static int addr6_resolve(struct sockaddr *src_sock, fl6.saddr = src_in->sin6_addr; fl6.flowi6_oif = addr->bound_dev_if; - dst = ipv6_stub->ipv6_dst_lookup_flow (addr->net,NULL , &fl6,NULL ); + dst =ip6_dst_lookup_flow (addr->net,NULL , &fl6,NULL );if (IS_ERR (dst))return PTR_ERR (dst);
Quoted 1 line
Is the plan to define
ipv6_dst_lookup_flow()differently for IPV6=y and IPV6=n ?
drivers/infiniband/core/addr.c was probably not a good example because addr6_resolve()
is guarded by #if IS_ENABLED(CONFIG_IPV6)
But other places do not have such preprocessor clauses.
Jakub Kicinski
maintainerQuoted 21 lines · On Wed, 4 Mar 2026 03:33:59 +0100 Eric Dumazet wrote:
Quoted 21 lines
Quoted 1 line
I thought if we remove IPV6=m we would delete
ipv6_stubcompletely?So we will add #ifdef around helpers ?
Lets take :
drivers/infiniband/core/addr.c +0
-0100644
drivers/infiniband/core/addr.c +1
-1@@ -411,7 +411,7 @@ static int addr6_resolve(struct sockaddr *src_sock, fl6.saddr = src_in->sin6_addr; fl6.flowi6_oif = addr->bound_dev_if; - dst = ipv6_stub->ipv6_dst_lookup_flow (addr->net,NULL , &fl6,NULL ); + dst =ip6_dst_lookup_flow (addr->net,NULL , &fl6,NULL );if (IS_ERR (dst))return PTR_ERR (dst);
Quoted 7 lines
Quoted 1 line
Is the plan to define
ipv6_dst_lookup_flow()differently for IPV6=y and IPV6=n ?
drivers/infiniband/core/addr.cwas probably not a good example becauseaddr6_resolve()
is guarded by #ifIS_ENABLED(CONFIG_IPV6)But other places do not have such preprocessor clauses.
"Normally" for code which is either in or out we add static inlines, no?
#if !IS_ENABLED(CONFIG_IPV6)
static inline struct dst_entry *ip6_dst_lookup_flow(...)
{
return ERR_PTR(-EAFNOSUPPORT);
}#else
struct dst_entry *ip6_dst_lookup_flow(...);
#endif