Skip to contentSkip to conversation

Allow compiling an IPv6-only kernel network stack

PATCH Superseded Fernando Fernandez Mancera 5 participants 37 messages Sep 28 – Oct 2

Subsystems (45)
Networking Network drivers VFS SCSI +41 more subsystems

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Allow compiling an IPv6-only kernel network stack

The primary goal of this patch series is to enable the compilation of an IPv6-only kernel by decoupling the core networking infrastructure from the IPv4 protocol.

Historically, IPv4 has been intertwined with the generic socket and transport layers. By untangling these dependencies, this series allows systems to be built with CONFIG_IPV4 disabled. This configuration targets strict IPv6-only deployments, constrained environments, and specialized appliances where removing the IPv4 subsystem reduces the network attack surface. To provide some numbers, 0.3% (32) of the released CVEs since 2025 were strictly related to IPv4 code. While the number is low, it is good for users to be able to disable it if they do not depend on it.

To achieve this, subsystems with hard dependencies on IPv4 were modified to use conditional compilation guards. When CONFIG_IPV4 is disabled, the affected packet manipulation routines and routing hooks evaluate to stubs returning standard error codes. The INDIRECT_CALL_INET macros within the transport layer were adapted to safely bypass IPv4 function pointers without penalizing the dual-stack fast paths. In addition, there has been several code splits for UDP, RAW, ICMP or Ping isolating the IPv4 specific code.

Every Kconfig symbol that gained a new depends on IPV4 was audited against the code it guards, distinguishing genuine hard link-time dependencies from options that were only conservatively gated. Where a symbol never depended on CONFIG_INET before, depends on IPV4 || !INET is used instead of a bare dependency, so pre-existing CONFIG_INET=n configurations remain buildable as before.

Finally, CONFIG_IPV4 is exposed in Kconfig as an explicit boolean, defaulting to 'y' to preserve existing configurations.

The bloat-o-meter diff and size output for x86_64 with dualstack and IPv6 disabled:

text data bss dec hex filename
31608053 8913174 1145484 41666711 27bc897 vmlinux.dual
28809691 8183494 1101724 38094909 245483d vmlinux.ipv6

add/remove: 53/19751 grow/shrink: 65/601 up/down: 740100/-3490467 (-2750367)

Performance testing:

Basic TCP performance validation was conducted using iperf3 on an AMD Ryzen 9 9950X between two bridged virtual machines. These benchmarks verify that there are no obvious performance regressions.

Kernel / Configuration Traffic Type Offloads ON Offloads OFF
-------------------------------------------------------------------------------

net-next (Dual-Stack Baseline)     IPv4            20.8 Gbps       7.22 Gbps
net-next (Dual-Stack Baseline)     IPv6            20.4 Gbps       7.55 Gbps
net-next (IPv4-Only Baseline)      IPv4            20.9 Gbps       7.86 Gbps
Patched (Dual-Stack)               IPv4            21.8 Gbps       7.77 Gbps
Patched (Dual-Stack)               IPv6            21.7 Gbps       7.35 Gbps
Patched (IPv4-Only)                IPv4            20.9 Gbps       7.91 Gbps
Patched (IPv6-Only)                IPv6            21.1 Gbps       8.06 Gbps

Follow-up for this series:

Future work decoupled from this initial series includes expanding Kconfig adaptations across remaining kernel subsystems to support an IPv6-only environment. This includes patches for network bonding modes that assume dual-stack availability and analyze Netfilter nftables expressions and connection tracking to ensure pure IPv6 operations are fully independent.

The main structural cost of this series is the code movement from splitting IPv4-specific logic into new files, which will make git blame and bisection across the affected files more cumbersome than a purely additive change. Where possible, IPv4-only branches were expressed as runtime IS_ENABLED() checks relying on dead-code elimination rather than ifdef blocks, to keep the preprocessor-guard footprint as small as possible.

Fernando Fernandez Mancera (16):
ipv4: introduce CONFIG_IPV4 to decouple the IPv4 stack
net: core: add IPv4 fallback stubs and guards for CONFIG_IPV4=n
net: inet: relocate ip_generic_getfrag and guard IPv4 socket logic
tcp: move protocol agnostic TCP functions out of tcp_ipv4.c
ipv4: raw: split IPv4 specific logic into raw_ipv4.c
ipv4: udp: split IPv4 specific logic into udp_ipv4.c
ipv4: icmp: split IPv4 specific logic into icmp_ipv4.c
ipv4: ping: split IPv4 specific logic into ping_ipv4.c
ipv4: fib: split common nexthop logic to fib_core.c
tunnels: guard IPv4 tunnel functions with CONFIG_IPV4
ipv4: disable IPv4-only sysctls when CONFIG_IPV4=n
netfilter: ipv4: guard ip_route_me_harder() with CONFIG_IPV4
net: bridge: guard ARP/RARP proxy and suppression with CONFIG_IPV4
wifi: mac80211: replace CONFIG_INET with CONFIG_IPV4 guards
netlabel: cipso: introduce CONFIG_CIPSO to decouple IPv4 dependency
ipv4: make CONFIG_IPV4 boolean

 drivers/infiniband/Kconfig                    |    2 +-
 drivers/infiniband/sw/rxe/Kconfig             |    2 +-
 drivers/net/Kconfig                           |   23 +-
 drivers/net/ethernet/chelsio/Kconfig          |    2 +-
 drivers/net/ethernet/intel/Kconfig            |    2 +
 drivers/net/ethernet/marvell/prestera/Kconfig |    1 +
 .../net/ethernet/mellanox/mlx5/core/Kconfig   |    3 +-
 drivers/net/ethernet/mellanox/mlxsw/Kconfig   |    1 +
 drivers/net/ethernet/qlogic/Kconfig           |    2 +
 drivers/net/ethernet/rocker/Kconfig           |    1 +
 drivers/net/ethernet/sfc/Kconfig              |    1 +
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |    1 +
 drivers/net/ethernet/via/Kconfig              |    1 +
 drivers/net/ppp/Kconfig                       |    1 +
 .../broadcom/brcm80211/brcmfmac/Kconfig       |    1 +
 drivers/net/wireless/intel/iwlwifi/Kconfig    |    1 +
 drivers/nvme/host/Kconfig                     |    2 +-
 drivers/nvme/target/Kconfig                   |    2 +-
 drivers/scsi/cxgbi/cxgb3i/Kconfig             |    2 +-
 drivers/scsi/cxgbi/cxgb4i/Kconfig             |    2 +-
 drivers/target/iscsi/Kconfig                  |    2 +-
 drivers/target/iscsi/cxgbit/Kconfig           |    2 +-
 fs/Kconfig                                    |    1 +
 fs/afs/Kconfig                                |    2 +-
 fs/nfs/Kconfig                                |    2 +-
 fs/nfsd/Kconfig                               |    2 +-
 include/linux/indirect_call_wrapper.h         |    8 +-
 include/net/cipso_ipv4.h                      |   18 +-
 include/net/icmp.h                            |    1 +
 include/net/ip.h                              |  111 +-
 include/net/ip_fib.h                          |   27 +-
 include/net/route.h                           |   14 +
 include/net/tcp.h                             |   16 +-
 include/net/udp.h                             |   11 +
 net/Kconfig                                   |    9 +-
 net/batman-adv/Kconfig                        |    6 +-
 net/bridge/Kconfig                            |    2 +-
 net/bridge/br_arp_nd_proxy.c                  |    2 +-
 net/bridge/br_device.c                        |    2 +-
 net/bridge/br_input.c                         |    2 +-
 net/bridge/netfilter/Kconfig                  |    3 +-
 net/core/Makefile                             |    2 +-
 net/core/dev_ioctl.c                          |    3 +
 net/core/fib_core.c                           |  307 +++
 net/core/filter.c                             |   20 +-
 net/core/neighbour.c                          |    4 +
 net/ipv4/Kconfig                              |   29 +-
 net/ipv4/Makefile                             |   24 +-
 net/ipv4/af_inet.c                            |  126 +-
 net/ipv4/fib_frontend.c                       |   96 -
 net/ipv4/fib_semantics.c                      |  205 --
 net/ipv4/icmp.c                               | 1418 +------------
 net/ipv4/icmp_ipv4.c                          | 1448 +++++++++++++
 net/ipv4/inet_connection_sock.c               |    2 +-
 net/ipv4/inet_hashtables.c                    |    3 +
 net/ipv4/ip_output.c                          |   18 -
 net/ipv4/ip_tunnel_core.c                     |   11 +
 net/ipv4/netfilter.c                          |    3 +
 net/ipv4/netfilter/Kconfig                    |    2 +-
 net/ipv4/nexthop.c                            |    5 +-
 net/ipv4/ping.c                               |  210 +-
 net/ipv4/ping_ipv4.c                          |  228 +++
 net/ipv4/proc.c                               |   45 +-
 net/ipv4/raw.c                                |  853 --------
 net/ipv4/raw_diag.c                           |    3 +-
 net/ipv4/raw_ipv4.c                           |  883 ++++++++
 net/ipv4/sysctl_net_ipv4.c                    |  413 ++--
 net/ipv4/tcp.c                                | 1300 +++++++++++-
 net/ipv4/tcp_bpf.c                            |    3 +-
 net/ipv4/tcp_ipv4.c                           | 1307 +-----------
 net/ipv4/udp.c                                | 1817 +----------------
 net/ipv4/udp_bpf.c                            |    5 +-
 net/ipv4/udp_ipv4.c                           | 1790 ++++++++++++++++
 net/ipv4/udp_offload.c                        |    3 +
 net/ipv6/Kconfig                              |   17 +-
 net/ipv6/af_inet6.c                           |    5 +
 net/ipv6/datagram.c                           |    4 +-
 net/ipv6/netfilter/Kconfig                    |    2 +-
 net/ipv6/tcp_ipv6.c                           |   23 +-
 net/ipv6/udp.c                                |   11 +-
 net/l2tp/Kconfig                              |    2 +-
 net/mac80211/main.c                           |   10 +-
 net/mptcp/Kconfig                             |    2 +-
 net/netfilter/Kconfig                         |    2 +-
 net/netfilter/ipset/Kconfig                   |    2 +-
 net/netfilter/ipvs/Kconfig                    |    2 +-
 net/netlabel/Kconfig                          |    4 +
 net/netlabel/Makefile                         |    2 +-
 net/netlabel/netlabel_cipso_v4.h              |    7 +
 net/netlabel/netlabel_kapi.c                  |    3 +
 net/rds/Kconfig                               |    1 +
 net/rxrpc/Kconfig                             |    2 +-
 net/sched/Kconfig                             |    2 +-
 net/sctp/Kconfig                              |    2 +-
 net/sunrpc/Kconfig                            |    2 +-
 net/tipc/Kconfig                              |    1 +
 net/xfrm/Kconfig                              |   10 +-
 97 files changed, 6738 insertions(+), 6262 deletions(-)
 create mode 100644 net/core/fib_core.c
 create mode 100644 net/ipv4/icmp_ipv4.c
 create mode 100644 net/ipv4/ping_ipv4.c
 create mode 100644 net/ipv4/raw_ipv4.c
 create mode 100644 net/ipv4/udp_ipv4.c
Signature · 1 line
2.55.0
#1 lore raw

PATCH v2 1/16 ipv4: introduce CONFIG_IPV4 to decouple the IPv4 stack

Historically, the IPv4 protocol has been linked to the core INET subsystem. Because shared infrastructure like the TCP/UDP engine, routing or INET hashtables live inside net/ipv4/, it has been impossible to compile a kernel with only IPv6 support.

This patch introduces the CONFIG_IPV4 Kconfig symbol, which is set to 'def_bool y' for now. This does not allow to completely disable the IPv4 stack yet but it lays the necessary build-system work for that goal.

In addition, multiple subsystems Kconfig symbols across networking features like tunnels, drivers and filesystems have been adjusted to depend on IPv4. Keep on mind that follow-up work is required to convert the Kconfig symbol to bool and remove the dependency on IPv4 where it makes sense.

---
 drivers/infiniband/Kconfig                    |  2 +-
 drivers/infiniband/sw/rxe/Kconfig             |  2 +-
 drivers/net/Kconfig                           | 23 ++++++++++---------
 drivers/net/ethernet/chelsio/Kconfig          |  2 +-
 drivers/net/ethernet/intel/Kconfig            |  2 ++
 drivers/net/ethernet/marvell/prestera/Kconfig |  1 +
 .../net/ethernet/mellanox/mlx5/core/Kconfig   |  3 ++-
 drivers/net/ethernet/mellanox/mlxsw/Kconfig   |  1 +
 drivers/net/ethernet/qlogic/Kconfig           |  2 ++
 drivers/net/ethernet/rocker/Kconfig           |  1 +
 drivers/net/ethernet/sfc/Kconfig              |  1 +
 drivers/net/ethernet/stmicro/stmmac/Kconfig   |  1 +
 drivers/net/ethernet/via/Kconfig              |  1 +
 drivers/net/ppp/Kconfig                       |  1 +
 .../broadcom/brcm80211/brcmfmac/Kconfig       |  1 +
 drivers/net/wireless/intel/iwlwifi/Kconfig    |  1 +
 drivers/nvme/host/Kconfig                     |  2 +-
 drivers/nvme/target/Kconfig                   |  2 +-
 drivers/scsi/cxgbi/cxgb3i/Kconfig             |  2 +-
 drivers/scsi/cxgbi/cxgb4i/Kconfig             |  2 +-
 drivers/target/iscsi/Kconfig                  |  2 +-
 drivers/target/iscsi/cxgbit/Kconfig           |  2 +-
 fs/Kconfig                                    |  1 +
 fs/afs/Kconfig                                |  2 +-
 fs/nfs/Kconfig                                |  2 +-
 fs/nfsd/Kconfig                               |  2 +-
 net/Kconfig                                   | 12 ++++++----
 net/batman-adv/Kconfig                        |  6 ++---
 net/bridge/Kconfig                            |  2 +-
 net/bridge/netfilter/Kconfig                  |  3 ++-
 net/ipv4/Kconfig                              | 21 ++++++++++++++---
 net/ipv4/Makefile                             | 21 ++++++++---------
 net/ipv4/netfilter/Kconfig                    |  2 +-
 net/ipv6/Kconfig                              | 17 ++++++++++----
 net/ipv6/netfilter/Kconfig                    |  2 +-
 net/l2tp/Kconfig                              |  2 +-
 net/mptcp/Kconfig                             |  2 +-
 net/netfilter/Kconfig                         |  2 +-
 net/netfilter/ipset/Kconfig                   |  2 +-
 net/netfilter/ipvs/Kconfig                    |  2 +-
 net/rds/Kconfig                               |  1 +
 net/rxrpc/Kconfig                             |  2 +-
 net/sched/Kconfig                             |  2 +-
 net/sctp/Kconfig                              |  2 +-
 net/sunrpc/Kconfig                            |  2 +-
 net/tipc/Kconfig                              |  1 +
 net/xfrm/Kconfig                              | 10 ++++++--
 security/smack/Kconfig                        |  1 +
 48 files changed, 117 insertions(+), 64 deletions(-)
drivers/infiniband/Kconfig +1 -1
index 086195758a8a..e9302002b6ea 100644
@@ -3,7 +3,7 @@ menuconfig INFINIBAND
 	tristate "InfiniBand support"
 	depends on HAS_IOMEM && HAS_DMA
 	depends on NET
-	depends on INET
+	depends on INET && IPV4
 	depends on !ALPHA
 	select DMA_SHARED_BUFFER
 	select IRQ_POLL
drivers/infiniband/sw/rxe/Kconfig +1 -1
index 1ed5b63f8afc..e4272f863944 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config RDMA_RXE
 	tristate "Software RDMA over Ethernet (RoCE) driver"
-	depends on INET && PCI && INFINIBAND && 64BIT
+	depends on INET && IPV4 && PCI && INFINIBAND && 64BIT
 	depends on INFINIBAND_VIRT_DMA
 	select NET_UDP_TUNNEL
 	select CRC32
drivers/net/Kconfig +12 -11
index ff79c466712d..5f60c3ff182b 100644
@@ -40,7 +40,7 @@ if NET_CORE
 
 config BONDING
 	tristate "Bonding driver support"
-	depends on INET
+	depends on INET && IPV4
 	depends on TLS || TLS_DEVICE=n
 	help
 	  Say 'Y' or 'M' if you wish to be able to 'bond' multiple Ethernet
@@ -73,7 +73,7 @@ config DUMMY
 
 config WIREGUARD
 	tristate "WireGuard secure network tunnel"
-	depends on NET && INET
+	depends on NET && INET && IPV4
 	select NET_UDP_TUNNEL
 	select DST_CACHE
 	select CRYPTO_LIB_CURVE25519
@@ -102,7 +102,7 @@ config WIREGUARD_DEBUG
 
 config OVPN
 	tristate "OpenVPN data channel offload"
-	depends on NET && INET
+	depends on NET && INET && IPV4
 	select DST_CACHE
 	select NET_UDP_TUNNEL
 	select CRYPTO
@@ -198,7 +198,7 @@ config IPVLAN_L3S
 
 config IPVLAN
 	tristate "IP-VLAN support"
-	depends on INET
+	depends on INET && IPV4
 	help
 	  This allows one to create virtual devices off of a main interface
 	  and packets will be delivered based on the dest L3 (IPv6/IPv4 addr)
@@ -229,7 +229,7 @@ config IPVTAP
 
 config VXLAN
 	tristate "Virtual eXtensible Local Area Network (VXLAN)"
-	depends on INET
+	depends on INET && IPV4
 	select NET_UDP_TUNNEL
 	select GRO_CELLS
 	help
@@ -244,7 +244,7 @@ config VXLAN
 
 config GENEVE
 	tristate "Generic Network Virtualization Encapsulation"
-	depends on INET
+	depends on INET && IPV4
 	select NET_UDP_TUNNEL
 	select GRO_CELLS
 	help
@@ -259,7 +259,7 @@ config GENEVE
 
 config BAREUDP
 	tristate "Bare UDP Encapsulation"
-	depends on INET
+	depends on INET && IPV4
 	select NET_UDP_TUNNEL
 	select GRO_CELLS
 	help
@@ -271,7 +271,7 @@ config BAREUDP
 
 config GTP
 	tristate "GPRS Tunneling Protocol datapath (GTP-U)"
-	depends on INET
+	depends on INET && IPV4
 	select NET_UDP_TUNNEL
 	help
 	  This allows one to create gtp virtual interfaces that provide
@@ -288,7 +288,7 @@ config GTP
 
 config PFCP
 	tristate "Packet Forwarding Control Protocol (PFCP)"
-	depends on INET
+	depends on INET && IPV4
 	select NET_UDP_TUNNEL
 	help
 	  This allows one to create PFCP virtual interfaces that allows to
@@ -301,7 +301,7 @@ config PFCP
 
 config AMT
 	tristate "Automatic Multicast Tunneling (AMT)"
-	depends on INET && IP_MULTICAST
+	depends on INET && IP_MULTICAST && IPV4
 	select NET_UDP_TUNNEL
 	help
 	  This allows one to create AMT(Automatic Multicast Tunneling)
@@ -471,6 +471,7 @@ config NETKIT
 
 config NET_VRF
 	tristate "Virtual Routing and Forwarding (Lite)"
+	depends on IPV4
 	depends on IP_MULTIPLE_TABLES
 	depends on NET_L3_MASTER_DEV
 	depends on IPV6_MULTIPLE_TABLES || IPV6=n
@@ -604,7 +605,7 @@ source "drivers/net/hyperv/Kconfig"
 config NETDEVSIM
 	tristate "Simulated networking device"
 	depends on DEBUG_FS
-	depends on INET
+	depends on INET && IPV4
 	depends on PSAMPLE || PSAMPLE=n
 	depends on PTP_1588_CLOCK_MOCK || PTP_1588_CLOCK_MOCK=n
 	select NET_DEVLINK
drivers/net/ethernet/chelsio/Kconfig +1 -1
index 96d7779cd2f0..c738820688e0 100644
@@ -48,7 +48,7 @@ config CHELSIO_T1_1G
 
 config CHELSIO_T3
 	tristate "Chelsio Communications T3 10Gb Ethernet support"
-	depends on PCI && INET
+	depends on PCI && INET && IPV4
 	select FW_LOADER
 	select MDIO
 	help
drivers/net/ethernet/intel/Kconfig +2 -0
index 780f113986ea..ce1c68e9cdf6 100644
@@ -195,6 +195,7 @@ config IXGBE_IPSEC
 	bool "IPSec XFRM cryptography-offload acceleration"
 	depends on IXGBE
 	depends on XFRM_OFFLOAD
+	depends on IPV4 || !INET
 	default y
 	select XFRM_ALGO
 	help
@@ -221,6 +222,7 @@ config IXGBEVF_IPSEC
 	bool "IPSec XFRM cryptography-offload acceleration"
 	depends on IXGBEVF
 	depends on XFRM_OFFLOAD
+	depends on IPV4 || !INET
 	default y
 	select XFRM_ALGO
 	help
drivers/net/ethernet/marvell/prestera/Kconfig +1 -0
index f2f7663c3d10..257afbb3c434 100644
@@ -7,6 +7,7 @@ config PRESTERA
 	tristate "Marvell Prestera Switch ASICs support"
 	depends on NET_SWITCHDEV && VLAN_8021Q
 	depends on BRIDGE || BRIDGE=n
+	depends on IPV4 || !INET
 	select NET_DEVLINK
 	select PHYLINK
 	help
drivers/net/ethernet/mellanox/mlx5/core/Kconfig +2 -1
index 925ee25d05b4..99d998aa7e9b 100644
@@ -12,6 +12,7 @@ config MLX5_CORE
 	depends on PTP_1588_CLOCK_OPTIONAL
 	depends on PCI_HYPERV_INTERFACE || !PCI_HYPERV_INTERFACE
 	depends on HWMON || !HWMON
+	depends on IPV4 || !INET
 	help
 	  Core driver for low level functionality of the ConnectX-4 and
 	  Connect-IB cards by Mellanox Technologies.
@@ -28,7 +29,7 @@ config MLX5_FPGA
 
 config MLX5_CORE_EN
 	bool "Mellanox 5th generation network adapters (ConnectX series) Ethernet support"
-	depends on NETDEVICES && ETHERNET && INET && PCI && MLX5_CORE
+	depends on NETDEVICES && ETHERNET && INET && PCI && MLX5_CORE && IPV4
 	select PAGE_POOL
 	select PAGE_POOL_STATS
 	select DIMLIB
drivers/net/ethernet/mellanox/mlxsw/Kconfig +1 -0
index 2229a2694aa5..fb3028600724 100644
@@ -53,6 +53,7 @@ config MLXSW_I2C
 
 config MLXSW_SPECTRUM
 	tristate "Mellanox Technologies Spectrum family support"
+	depends on IPV4 || !INET
 	depends on MLXSW_CORE && MLXSW_PCI && NET_SWITCHDEV && VLAN_8021Q
 	depends on PSAMPLE || PSAMPLE=n
 	depends on BRIDGE || BRIDGE=n
drivers/net/ethernet/qlogic/Kconfig +2 -0
index 1203353238e5..aed78311ecaf 100644
@@ -29,6 +29,7 @@ config QLA3XXX
 config QLCNIC
 	tristate "QLOGIC QLCNIC 1/10Gb Converged Ethernet NIC Support"
 	depends on PCI
+	depends on IPV4 || !INET
 	select FW_LOADER
 	help
 	  This driver supports QLogic QLE8240 and QLE8242 Converged Ethernet
@@ -68,6 +69,7 @@ config QLCNIC_HWMON
 
 config NETXEN_NIC
 	tristate "NetXen Multi port (1/10) Gigabit Ethernet NIC"
+	depends on IPV4 || !INET
 	depends on PCI
 	select FW_LOADER
 	help
drivers/net/ethernet/rocker/Kconfig +1 -0
index 2318811ff75a..2f994bd6f9bd 100644
@@ -19,6 +19,7 @@ if NET_VENDOR_ROCKER
 config ROCKER
 	tristate "Rocker switch driver (EXPERIMENTAL)"
 	depends on PCI && NET_SWITCHDEV && BRIDGE
+	depends on IPV4 || !INET
 	select CRC32
 	help
 	  This driver supports Rocker switch device.
drivers/net/ethernet/sfc/Kconfig +1 -0
index e2898ec2e6e9..2bf5c2a185d2 100644
@@ -18,6 +18,7 @@ if NET_VENDOR_SOLARFLARE
 
 config SFC
 	tristate "Solarflare SFC9100/EF100-family support"
+	depends on IPV4 || !INET
 	depends on PCI
 	depends on PTP_1588_CLOCK_OPTIONAL
 	select MDIO
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
index ab3c4cf96423..0b487786dad4 100644
@@ -1,6 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config STMMAC_ETH
 	tristate "STMicroelectronics Multi-Gigabit Ethernet driver"
+	depends on IPV4 || !INET
 	depends on HAS_IOMEM && HAS_DMA
 	depends on PTP_1588_CLOCK_OPTIONAL
 	depends on ETHTOOL_NETLINK
drivers/net/ethernet/via/Kconfig +1 -0
index 00773f5e4d7e..dbb24d35dfbd 100644
@@ -45,6 +45,7 @@ config VIA_RHINE_MMIO
 
 config VIA_VELOCITY
 	tristate "VIA Velocity support"
+	depends on IPV4 || !INET
 	depends on (PCI || (OF_ADDRESS && OF_IRQ))
 	depends on HAS_DMA
 	select CRC32
drivers/net/ppp/Kconfig +1 -0
index 4047f13b83dc..c5200fae5e4a 100644
@@ -160,6 +160,7 @@ config PPPOE_HASH_BITS
 
 config PPTP
 	tristate "PPP over IPv4 (PPTP)"
+	depends on IPV4 || !INET
 	depends on NET_IPGRE_DEMUX
 	select PPPOX
 	help
drivers/net/wireless/broadcom/brcm80211/brcmfmac/Kconfig +1 -0
index 32794c1eca23..01a5b3310e1e 100644
@@ -1,6 +1,7 @@
 config BRCMFMAC
 	tristate "Broadcom FullMAC WLAN driver"
 	depends on CFG80211
+	depends on IPV4 || !INET
 	select BRCMUTIL
 	help
 	  This module adds support for wireless adapters based on Broadcom
drivers/net/wireless/intel/iwlwifi/Kconfig +1 -0
index 153a8368b412..3719fa0727c2 100644
@@ -2,6 +2,7 @@
 config IWLWIFI
 	tristate "Intel Wireless WiFi Next Gen AGN - Wireless-N/Advanced-N/Ultimate-N (iwlwifi) "
 	depends on PCI && HAS_IOMEM && CFG80211
+	depends on IPV4 || !INET
 	depends on IWLMEI || !IWLMEI
 	select FW_LOADER
 	help
drivers/nvme/host/Kconfig +1 -1
index 31974c7dd20c..6e119cf475de 100644
@@ -82,7 +82,7 @@ config NVME_FC
 
 config NVME_TCP
 	tristate "NVM Express over Fabrics TCP host driver"
-	depends on INET
+	depends on INET && IPV4
 	depends on BLOCK
 	select CRC32
 	select NET_CRC32C
drivers/nvme/target/Kconfig +1 -1
index 69bde270115e..f731a043f6a9 100644
@@ -86,7 +86,7 @@ config NVME_TARGET_FCLOOP
 
 config NVME_TARGET_TCP
 	tristate "NVMe over Fabrics TCP target support"
-	depends on INET
+	depends on INET && IPV4
 	depends on NVME_TARGET
 	help
 	  This enables the NVMe TCP target support, which allows exporting NVMe
drivers/scsi/cxgbi/cxgb3i/Kconfig +1 -1
index 143e881ec77e..abb4a462cb37 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config SCSI_CXGB3_ISCSI
 	tristate "Chelsio T3 iSCSI support"
-	depends on PCI && INET
+	depends on PCI && INET && IPV4
 	select NETDEVICES
 	select ETHERNET
 	select NET_VENDOR_CHELSIO
drivers/scsi/cxgbi/cxgb4i/Kconfig +1 -1
index dd1c8ff36b00..04b3e7b053dc 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config SCSI_CXGB4_ISCSI
 	tristate "Chelsio T4 iSCSI support"
-	depends on PCI && INET
+	depends on PCI && INET && IPV4
 	depends on PTP_1588_CLOCK_OPTIONAL
 	depends on THERMAL || !THERMAL
 	depends on ETHERNET
drivers/target/iscsi/Kconfig +1 -1
index 70d76f3dd693..362edff80c15 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config ISCSI_TARGET
 	tristate "SCSI Target Mode Stack"
-	depends on INET
+	depends on INET && IPV4
 	select CRC32
 	select CRYPTO
 	select CRYPTO_HASH
drivers/target/iscsi/cxgbit/Kconfig +1 -1
index bdeefa75f29e..7a2e585d76d7 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config ISCSI_TARGET_CXGB4
 	tristate "Chelsio iSCSI target offload driver"
-	depends on ISCSI_TARGET && CHELSIO_T4 && INET
+	depends on ISCSI_TARGET && CHELSIO_T4 && INET && IPV4
 	select CHELSIO_LIB
 	help
 	To compile this driver as module, choose M here: the module
fs/Kconfig +1 -0
index e05917adcd60..2f492fa3a3fb 100644
@@ -358,6 +358,7 @@ config GRACE_PERIOD
 
 config LOCKD
 	tristate
+	depends on IPV4 || !INET
 	depends on FILE_LOCKING
 	select CRC32
 	select GRACE_PERIOD
fs/afs/Kconfig +1 -1
index 682bd8ec2c10..e7ed46426f81 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config AFS_FS
 	tristate "Andrew File System support (AFS)"
-	depends on INET
+	depends on INET && IPV4
 	select AF_RXRPC
 	select DNS_RESOLVER
 	select NETFS_SUPPORT
fs/nfs/Kconfig +1 -1
index 6bb30543eff0..52efd3664d21 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config NFS_FS
 	tristate "NFS client support"
-	depends on INET && FILE_LOCKING && MULTIUSER
+	depends on INET && FILE_LOCKING && MULTIUSER && IPV4
 	select CRC32
 	select LOCKD
 	select SUNRPC
fs/nfsd/Kconfig +1 -1
index ffb76761d6a8..153a9918214d 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config NFSD
 	tristate "NFS server support"
-	depends on INET
+	depends on INET && IPV4
 	depends on FILE_LOCKING
 	depends on FSNOTIFY
 	select CRC32
net/Kconfig +8 -4
index 76ab44aa439a..ca86f20540dd 100644
@@ -135,9 +135,12 @@ config INET
 if INET
 source "net/ipv4/Kconfig"
 source "net/ipv6/Kconfig"
-source "net/netlabel/Kconfig"
 source "net/mptcp/Kconfig"
 
+if IPV4
+source "net/netlabel/Kconfig"
+endif # if IPV4
+
 endif # if INET
 
 config NETWORK_SECMARK
@@ -232,6 +235,7 @@ config BRIDGE_NETFILTER
 	depends on BRIDGE
 	depends on NETFILTER && INET
 	depends on NETFILTER_ADVANCED
+	depends on IPV4
 	select NETFILTER_FAMILY_BRIDGE
 	select SKB_EXTENSIONS
 	help
@@ -384,7 +388,7 @@ menu "Network testing"
 
 config NET_PKTGEN
 	tristate "Packet Generator (USE WITH CAUTION)"
-	depends on INET && PROC_FS
+	depends on INET && IPV4 && PROC_FS
 	help
 	  This module will inject preconfigured packets, at a configurable
 	  rate, out of a given interface.  It is used for network interface
@@ -451,7 +455,7 @@ config LWTUNNEL
 
 config LWTUNNEL_BPF
 	bool "Execute BPF program as route nexthop action"
-	depends on LWTUNNEL && INET
+	depends on LWTUNNEL && INET && IPV4
 	default y if LWTUNNEL=y
 	help
 	  Allows to run BPF programs as a nexthop action following a route
@@ -473,7 +477,7 @@ config NET_IEEE8021Q_HELPERS
 
 config NET_SELFTESTS
 	def_tristate PHYLIB
-	depends on PHYLIB && INET
+	depends on PHYLIB && INET && IPV4
 
 config NET_SOCK_MSG
 	bool
net/batman-adv/Kconfig +3 -3
index 58c408b7a7d9..5c66122c137c 100644
@@ -33,7 +33,7 @@ config BATMAN_ADV_BATMAN_V
 
 config BATMAN_ADV_BLA
 	bool "Bridge Loop Avoidance"
-	depends on BATMAN_ADV && INET
+	depends on BATMAN_ADV && INET && IPV4
 	select CRC16
 	select NET_CRC32C
 	default y
@@ -46,7 +46,7 @@ config BATMAN_ADV_BLA
 
 config BATMAN_ADV_DAT
 	bool "Distributed ARP Table"
-	depends on BATMAN_ADV && INET
+	depends on BATMAN_ADV && INET && IPV4
 	default y
 	help
 	  This option enables DAT (Distributed ARP Table), a DHT based
@@ -56,7 +56,7 @@ config BATMAN_ADV_DAT
 
 config BATMAN_ADV_MCAST
 	bool "Multicast optimisation"
-	depends on BATMAN_ADV && INET && !(BRIDGE=m && BATMAN_ADV=y)
+	depends on BATMAN_ADV && INET && !(BRIDGE=m && BATMAN_ADV=y) && IPV4
 	default y
 	help
 	  This option enables the multicast optimisation which aims to
net/bridge/Kconfig +1 -1
index 318715c8fc9b..c7737d3ebac8 100644
@@ -36,7 +36,7 @@ config BRIDGE
 config BRIDGE_IGMP_SNOOPING
 	bool "IGMP/MLD snooping"
 	depends on BRIDGE
-	depends on INET
+	depends on INET && IPV4
 	default y
 	help
 	  If you say Y here, then the Ethernet bridge will be able selectively
net/bridge/netfilter/Kconfig +2 -1
index 4fd5a6ea26b4..31e388ce503f 100644
@@ -28,6 +28,7 @@ endif # NF_TABLES_BRIDGE
 config NF_CONNTRACK_BRIDGE
 	tristate "IPv4/IPV6 bridge connection tracking support"
 	depends on NF_CONNTRACK
+	depends on IPV4 || !INET
 	default n
 	help
 	  Connection tracking keeps a record of what packets have passed
@@ -188,7 +189,7 @@ config BRIDGE_EBT_VLAN
 #
 config BRIDGE_EBT_ARPREPLY
 	tristate "ebt: arp reply target support"
-	depends on BRIDGE_NF_EBTABLES && INET
+	depends on BRIDGE_NF_EBTABLES && INET && IPV4
 	help
 	  This option adds the arp reply target, which allows
 	  automatically sending arp replies to arp requests.
net/ipv4/Kconfig +18 -3
index 301b47660305..51bf05d9770c 100644
@@ -2,6 +2,9 @@
 #
 # IP configuration
 #
+config IPV4
+	def_bool y
+
 config IP_MULTICAST
 	bool "IP: multicasting"
 	help
@@ -62,7 +65,7 @@ config IP_FIB_TRIE_STATS
 
 config IP_MULTIPLE_TABLES
 	bool "IP: policy routing"
-	depends on IP_ADVANCED_ROUTER
+	depends on IPV4 && IP_ADVANCED_ROUTER
 	select FIB_RULES
 	help
 	  Normally, a router decides what to do with a received packet based
@@ -105,6 +108,7 @@ config IP_ROUTE_CLASSID
 
 config IP_PNP
 	bool "IP: kernel level autoconfiguration"
+	depends on IPV4
 	help
 	  This enables automatic configuration of IP addresses of devices and
 	  of the routing table during kernel boot, based on either information
@@ -161,6 +165,7 @@ config IP_PNP_RARP
 
 config NET_IPIP
 	tristate "IP: tunneling"
+	depends on IPV4
 	select INET_TUNNEL
 	select NET_IP_TUNNEL
 	help
@@ -185,12 +190,14 @@ config NET_IPGRE_DEMUX
 
 config NET_IP_TUNNEL
 	tristate
+	depends on IPV4
 	select DST_CACHE
 	select GRO_CELLS
 	default n
 
 config NET_IPGRE
 	tristate "IP: GRE tunnels over IP"
+	depends on IPV4
 	depends on NET_IPGRE_DEMUX
 	select NET_IP_TUNNEL
 	help
@@ -219,7 +226,7 @@ config IP_MROUTE_COMMON
 
 config IP_MROUTE
 	bool "IP: multicast routing"
-	depends on IP_MULTICAST
+	depends on IP_MULTICAST && IPV4
 	select IP_MROUTE_COMMON
 	help
 	  This is used if you want your machine to act as a router for IP
@@ -267,6 +274,7 @@ config IP_PIMSM_V2
 
 config SYN_COOKIES
 	bool "IP: TCP syncookie support"
+	depends on IPV4
 	help
 	  Normal TCP/IP networking is open to an attack known as "SYN
 	  flooding". This denial-of-service attack prevents legitimate remote
@@ -303,6 +311,7 @@ config SYN_COOKIES
 
 config NET_IPVTI
 	tristate "Virtual (secure) IP: tunneling"
+	depends on IPV4
 	select INET_TUNNEL
 	select NET_IP_TUNNEL
 	select XFRM
@@ -315,11 +324,13 @@ config NET_IPVTI
 
 config NET_UDP_TUNNEL
 	tristate
+	depends on IPV4
 	select NET_IP_TUNNEL
 	default n
 
 config NET_FOU
 	tristate "IP: Foo (IP protocols) over UDP"
+	depends on IPV4
 	select NET_UDP_TUNNEL
 	help
 	  Foo over UDP allows any IP protocol to be directly encapsulated
@@ -338,6 +349,7 @@ config NET_FOU_IP_TUNNELS
 
 config INET_AH
 	tristate "IP: AH transformation"
+	depends on IPV4
 	select XFRM_AH
 	help
 	  Support for IPsec AH (Authentication Header).
@@ -353,6 +365,7 @@ config INET_AH
 
 config INET_ESP
 	tristate "IP: ESP transformation"
+	depends on IPV4
 	select XFRM_ESP
 	help
 	  Support for IPsec ESP (Encapsulating Security Payload).
@@ -393,6 +406,7 @@ config INET_ESPINTCP
 
 config INET_IPCOMP
 	tristate "IP: IPComp transformation"
+	depends on IPV4
 	select INET_XFRM_TUNNEL
 	select XFRM_IPCOMP
 	help
@@ -747,7 +761,7 @@ config TCP_AO
 	select CRYPTO_LIB_SHA1
 	select CRYPTO_LIB_SHA256
 	select CRYPTO_LIB_UTILS
-	depends on 64BIT # seq-number extension needs WRITE_ONCE(u64)
+	depends on IPV4 && 64BIT # seq-number extension needs WRITE_ONCE(u64)
 	help
 	  TCP-AO specifies the use of stronger Message Authentication Codes (MACs),
 	  protects against replays for long-lived TCP connections, and
@@ -758,6 +772,7 @@ config TCP_AO
 
 config TCP_MD5SIG
 	bool "TCP: MD5 Signature Option support (RFC2385)"
+	depends on IPV4
 	select CRYPTO_LIB_MD5
 	select CRYPTO_LIB_UTILS
 	help
net/ipv4/Makefile +10 -11
index 06e21c26b76f..8b148be79fa4 100644
@@ -3,18 +3,17 @@
 # Makefile for the Linux TCP/IP (INET) layer.
 #
 
-obj-y     := route.o inetpeer.o protocol.o \
-	     ip_input.o ip_fragment.o ip_forward.o ip_options.o \
-	     ip_output.o ip_sockglue.o inet_hashtables.o \
-	     inet_timewait_sock.o inet_connection_sock.o \
-	     tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \
+obj-y     := inetpeer.o protocol.o inet_hashtables.o inet_timewait_sock.o \
+	     inet_connection_sock.o tcp.o tcp_input.o tcp_output.o tcp_timer.o \
 	     tcp_minisocks.o tcp_cong.o tcp_metrics.o tcp_fastopen.o \
-	     tcp_recovery.o tcp_ulp.o \
-	     tcp_offload.o tcp_plb.o datagram.o raw.o udp.o \
-	     udp_offload.o arp.o icmp.o devinet.o af_inet.o igmp.o \
-	     fib_frontend.o fib_semantics.o fib_trie.o fib_notifier.o \
-	     inet_fragment.o ping.o ip_tunnel_core.o gre_offload.o \
-	     metrics.o netlink.o nexthop.o udp_tunnel_stub.o
+	     tcp_recovery.o tcp_ulp.o tcp_offload.o tcp_plb.o raw.o udp.o \
+	     udp_offload.o af_inet.o inet_fragment.o ping.o ip_tunnel_core.o \
+	     gre_offload.o metrics.o netlink.o nexthop.o udp_tunnel_stub.o
+
+obj-$(CONFIG_IPV4) += route.o ip_input.o ip_fragment.o ip_forward.o ip_options.o \
+		      ip_sockglue.o tcp_ipv4.o datagram.o icmp.o arp.o devinet.o \
+		      igmp.o fib_notifier.o ip_output.o fib_frontend.o \
+		      fib_semantics.o fib_trie.o
 
 obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o
 obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o
net/ipv4/netfilter/Kconfig +1 -1
index 7dc9772fe2d8..ab4fa6a6d453 100644
@@ -4,7 +4,7 @@
 #
 
 menu "IP: Netfilter Configuration"
-	depends on INET && NETFILTER
+	depends on INET && NETFILTER && IPV4
 
 config NF_DEFRAG_IPV4
 	tristate
net/ipv6/Kconfig +13 -4
index c3806c6ac96f..f83efc1505cc 100644
@@ -47,6 +47,7 @@ config IPV6_OPTIMISTIC_DAD
 config INET6_AH
 	tristate "IPv6: AH transformation"
 	select XFRM_AH
+	depends on IPV4
 	help
 	  Support for IPsec AH (Authentication Header).
 
@@ -61,6 +62,7 @@ config INET6_AH
 
 config INET6_ESP
 	tristate "IPv6: ESP transformation"
+	depends on IPV4
 	select XFRM_ESP
 	help
 	  Support for IPsec ESP (Encapsulating Security Payload).
@@ -101,6 +103,7 @@ config INET6_ESPINTCP
 
 config INET6_IPCOMP
 	tristate "IPv6: IPComp transformation"
+	depends on IPV4
 	select INET6_XFRM_TUNNEL
 	select XFRM_IPCOMP
 	help
@@ -111,6 +114,7 @@ config INET6_IPCOMP
 
 config IPV6_MIP6
 	tristate "IPv6: Mobility"
+	depends on IPV4
 	select XFRM
 	help
 	  Support for IPv6 Mobility described in RFC 3775.
@@ -119,6 +123,7 @@ config IPV6_MIP6
 
 config IPV6_ILA
 	tristate "IPv6: Identifier Locator Addressing (ILA)"
+	depends on IPV4
 	depends on NETFILTER
 	select DST_CACHE
 	select LWTUNNEL
@@ -149,6 +154,7 @@ config INET6_TUNNEL
 
 config IPV6_VTI
 	tristate "Virtual (secure) IPv6: tunneling"
+	depends on IPV4
 	select IPV6_TUNNEL
 	select NET_IP_TUNNEL
 	select XFRM
@@ -161,6 +167,7 @@ config IPV6_VTI
 
 config IPV6_SIT
 	tristate "IPv6: IPv6-in-IPv4 tunnel (SIT driver)"
+	depends on IPV4
 	select INET_TUNNEL
 	select NET_IP_TUNNEL
 	select IPV6_NDISC_NODETYPE
@@ -198,6 +205,7 @@ config IPV6_NDISC_NODETYPE
 
 config IPV6_TUNNEL
 	tristate "IPv6: IP-in-IPv6 tunnel (RFC2473)"
+	depends on IPV4
 	select INET6_TUNNEL
 	select DST_CACHE
 	select GRO_CELLS
@@ -209,6 +217,7 @@ config IPV6_TUNNEL
 
 config IPV6_GRE
 	tristate "IPv6: GRE tunnel"
+	depends on IPV4
 	select IPV6_TUNNEL
 	select NET_IP_TUNNEL
 	depends on NET_IPGRE_DEMUX
@@ -256,7 +265,7 @@ config IPV6_SUBTREES
 
 config IPV6_MROUTE
 	bool "IPv6: multicast routing"
-	depends on IPV6
+	depends on IPV4 && IPV6
 	select IP_MROUTE_COMMON
 	help
 	  Support for IPv6 multicast forwarding.
@@ -285,7 +294,7 @@ config IPV6_PIMSM_V2
 
 config IPV6_SEG6_LWTUNNEL
 	bool "IPv6: Segment Routing Header encapsulation support"
-	depends on IPV6
+	depends on IPV4 && IPV6
 	select LWTUNNEL
 	select DST_CACHE
 	select IPV6_MULTIPLE_TABLES
@@ -316,7 +325,7 @@ config IPV6_SEG6_BPF
 
 config IPV6_RPL_LWTUNNEL
 	bool "IPv6: RPL Source Routing Header support"
-	depends on IPV6
+	depends on IPV4 && IPV6
 	select LWTUNNEL
 	select DST_CACHE
 	help
@@ -327,7 +336,7 @@ config IPV6_RPL_LWTUNNEL
 
 config IPV6_IOAM6_LWTUNNEL
 	bool "IPv6: IOAM Pre-allocated Trace insertion support"
-	depends on IPV6
+	depends on IPV4 && IPV6
 	select LWTUNNEL
 	select DST_CACHE
 	help
net/ipv6/netfilter/Kconfig +1 -1
index 81daf82ddc2d..f99a2176bf3d 100644
@@ -4,7 +4,7 @@
 #
 
 menu "IPv6: Netfilter Configuration"
-	depends on INET && IPV6 && NETFILTER
+	depends on INET && IPV6 && NETFILTER && IPV4
 
 # old sockopt interface and eval loop
 config IP6_NF_IPTABLES_LEGACY
net/l2tp/Kconfig +1 -1
index 0de178d5baba..e92cf6d94135 100644
@@ -5,7 +5,7 @@
 
 menuconfig L2TP
 	tristate "Layer Two Tunneling Protocol (L2TP)"
-	depends on INET
+	depends on INET && IPV4
 	select NET_UDP_TUNNEL
 	help
 	  Layer Two Tunneling Protocol
net/mptcp/Kconfig +1 -1
index be71fc9b4638..c5b660fdda4c 100644
@@ -1,7 +1,7 @@
 
 config MPTCP
 	bool "MPTCP: Multipath TCP"
-	depends on INET
+	depends on INET && IPV4
 	select SKB_EXTENSIONS
 	select CRYPTO_LIB_SHA256
 	select CRYPTO_LIB_UTILS
net/netfilter/Kconfig +1 -1
index 09874c26fd13..857af95fbb48 100644
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 menu "Core Netfilter Configuration"
-	depends on INET && NETFILTER
+	depends on INET && IPV4 && NETFILTER
 
 config NETFILTER_INGRESS
 	bool "Netfilter ingress support"
net/netfilter/ipset/Kconfig +1 -1
index 6c4d54758106..e6537c842a45 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 menuconfig IP_SET
 	tristate "IP set support"
-	depends on INET && NETFILTER
+	depends on INET && IPV4 && NETFILTER
 	select NETFILTER_NETLINK
 	help
 	  This option adds IP set support to the kernel.
net/netfilter/ipvs/Kconfig +1 -1
index 7724cb44e6de..fb09218d84d0 100644
@@ -4,7 +4,7 @@
 #
 menuconfig IP_VS
 	tristate "IP virtual server support"
-	depends on INET && NETFILTER
+	depends on INET && NETFILTER && IPV4
 	depends on (NF_CONNTRACK || NF_CONNTRACK=n)
 	help
 	  IP Virtual Server support will let you build a high-performance
net/rds/Kconfig +1 -0
index f007730aa2bb..af5632b37dd7 100644
@@ -17,6 +17,7 @@ config RDS_RDMA
 config RDS_TCP
 	tristate "RDS over TCP"
 	depends on RDS
+	depends on IPV4
 	depends on IPV6 || !IPV6
 	help
 	  Allow RDS to use TCP as a transport.
net/rxrpc/Kconfig +1 -1
index 2cebb666dc07..2029d2d1065f 100644
@@ -5,7 +5,7 @@
 
 config AF_RXRPC
 	tristate "RxRPC session sockets"
-	depends on INET
+	depends on INET && IPV4
 	select CRYPTO
 	select CRYPTO_LIB_DES if RXKAD
 	select KEYS
net/sched/Kconfig +1 -1
index 6ddff028b81a..bb782822c3fb 100644
@@ -807,7 +807,7 @@ config NET_ACT_SKBEDIT
 
 config NET_ACT_CSUM
 	tristate "Checksum Updating"
-	depends on NET_CLS_ACT && INET
+	depends on NET_CLS_ACT && INET && IPV4
 	select NET_CRC32C
 	help
 	  Say Y here to update some common checksum after some direct
net/sctp/Kconfig +1 -1
index fc989a3791b3..eb3e2bf1ec3a 100644
@@ -5,7 +5,7 @@
 
 menuconfig IP_SCTP
 	tristate "The SCTP Protocol"
-	depends on INET
+	depends on INET && IPV4
 	select CRYPTO_LIB_SHA1
 	select CRYPTO_LIB_SHA256
 	select CRYPTO_LIB_UTILS
net/sunrpc/Kconfig +1 -1
index e7808e5714dc..58e6f6db3100 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config SUNRPC
 	tristate
-	depends on MULTIUSER
+	depends on MULTIUSER && IPV4
 
 config SUNRPC_GSS
 	tristate
net/tipc/Kconfig +1 -0
index 18f62135e47b..2db479597c79 100644
@@ -30,6 +30,7 @@ config TIPC_MEDIA_IB
 config TIPC_MEDIA_UDP
 	bool "IP/UDP media type support"
 	depends on TIPC
+	depends on IPV4
 	select NET_UDP_TUNNEL
 	default y
 	help
net/xfrm/Kconfig +8 -2
index 4a62817a88f8..203188b05be4 100644
@@ -4,7 +4,7 @@
 #
 config XFRM
 	bool
-	depends on INET
+	depends on INET && IPV4
 	select GRO_CELLS
 	select SKB_EXTENSIONS
 
@@ -13,6 +13,7 @@ config XFRM_OFFLOAD
 
 config XFRM_ALGO
 	tristate
+	depends on IPV4
 	select XFRM
 	select CRYPTO
 	select CRYPTO_AEAD
@@ -23,6 +24,7 @@ if INET
 config XFRM_USER
 	tristate "Transformation user configuration interface"
 	select XFRM_ALGO
+	depends on IPV4
 	help
 	  Support for Transformation(XFRM) user configuration interface
 	  like IPsec used by native Linux tools.
@@ -42,7 +44,7 @@ config XFRM_USER_COMPAT
 
 config XFRM_INTERFACE
 	tristate "Transformation virtual interface"
-	depends on XFRM && IPV6
+	depends on XFRM && IPV4 && IPV6
 	help
 	  This provides a virtual interface to route IPsec traffic.
 
@@ -83,6 +85,7 @@ config XFRM_STATISTICS
 # RFC 8221 lists as MUST be implemented.
 config XFRM_AH
 	tristate
+	depends on IPV4
 	select XFRM_ALGO
 	select CRYPTO
 	select CRYPTO_HMAC
@@ -92,6 +95,7 @@ config XFRM_AH
 # algorithms that RFC 8221 lists as MUST be implemented.
 config XFRM_ESP
 	tristate
+	depends on IPV4
 	select XFRM_ALGO
 	select CRYPTO
 	select CRYPTO_AES
@@ -105,12 +109,14 @@ config XFRM_ESP
 
 config XFRM_IPCOMP
 	tristate
+	depends on IPV4
 	select XFRM_ALGO
 	select CRYPTO
 	select CRYPTO_DEFLATE
 
 config NET_KEY
 	tristate "PF_KEY sockets (deprecated)"
+	depends on IPV4
 	select XFRM_ALGO
 	help
 	  PF_KEYv2 socket family, compatible to KAME ones.
security/smack/Kconfig +1 -0
index 5a8dfad469c3..b4e6d0168bd1 100644
@@ -3,6 +3,7 @@ config SECURITY_SMACK
 	bool "Simplified Mandatory Access Control Kernel Support"
 	depends on NET
 	depends on INET
+	depends on IPV4
 	depends on SECURITY
 	select NETLABEL
 	select SECURITY_NETWORK
Signature · 1 line
2.55.0
#4 lore raw

PATCH v2 2/16 net: core: add IPv4 fallback stubs and guards for CONFIG_IPV4=n

In reply to Fernando Fernandez Mancera

To enable compiling the core network stack without IPv4, generic networking code must avoid referencing missing IPv4 symbols.

This patch provides static inline stubs in include/net/ip.h and include/net/route.h that return a proper error code when IPv4 is disabled. This behaves as IPv6 code does. In addition, it introduces guards around IPv4 specific code in generic implementations to prevent undefined reference errors while linking.

---
 include/linux/indirect_call_wrapper.h |   8 +-
 include/net/ip.h                      | 111 ++++++++++++++++++++++----
 include/net/route.h                   |   8 ++
 net/core/dev_ioctl.c                  |   3 +
 net/core/filter.c                     |  20 ++---
 net/core/neighbour.c                  |   4 +
 net/ipv4/inet_hashtables.c            |   3 +
 7 files changed, 127 insertions(+), 30 deletions(-)
include/linux/indirect_call_wrapper.h +5 -3
index 0e4340ecd857..583efbc03446 100644
@@ -57,16 +57,18 @@
  * builtin, this macro simplify dealing with indirect calls with only ipv4/ipv6
  * alternatives
  */
-#if IS_ENABLED(CONFIG_IPV6)
+#if IS_ENABLED(CONFIG_IPV4) && IS_ENABLED(CONFIG_IPV6)
 #define INDIRECT_CALL_INET(f, f2, f1, ...) \
 	INDIRECT_CALL_2(f, f2, f1, __VA_ARGS__)
-#elif IS_ENABLED(CONFIG_INET)
+#elif IS_ENABLED(CONFIG_IPV4)
 #define INDIRECT_CALL_INET(f, f2, f1, ...) INDIRECT_CALL_1(f, f1, __VA_ARGS__)
+#elif IS_ENABLED(CONFIG_IPV6)
+#define INDIRECT_CALL_INET(f, f2, f1, ...) INDIRECT_CALL_1(f, f2, __VA_ARGS__)
 #else
 #define INDIRECT_CALL_INET(f, f2, f1, ...) f(__VA_ARGS__)
 #endif
 
-#if IS_ENABLED(CONFIG_INET)
+#if IS_ENABLED(CONFIG_IPV4)
 #define INDIRECT_CALL_INET_1(f, f1, ...) INDIRECT_CALL_1(f, f1, __VA_ARGS__)
 #else
 #define INDIRECT_CALL_INET_1(f, f1, ...) f(__VA_ARGS__)
include/net/ip.h +94 -17

166 lines not on this page · raw message

include/net/route.h +8 -0
index 6b55de2e4df8..8c21881eb5f4 100644
@@ -169,8 +169,16 @@ static inline struct rtable *__ip_route_output_key(struct net *net,
 	return ip_route_output_key_hash(net, flp, NULL);
 }
 
+#if IS_ENABLED(CONFIG_IPV4)
 struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,
 				    const struct sock *sk);
+#else
+static inline struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,
+						  const struct sock *sk)
+{
+	return ERR_PTR(-EAFNOSUPPORT);
+}
+#endif
 struct dst_entry *ipv4_blackhole_route(struct net *net,
 				       struct dst_entry *dst_orig);
 
net/core/dev_ioctl.c +3 -0
index 164643140a52..a10921aa3e23 100644
@@ -44,6 +44,9 @@ int dev_ifconf(struct net *net, struct ifconf __user *uifc)
 	size_t size;
 	int len, total = 0, done;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EAFNOSUPPORT;
+
 	/* both the ifconf and the ifreq structures are slightly different */
 	if (in_compat_syscall()) {
 		struct compat_ifconf ifc32;
net/core/filter.c +10 -10
index 70dc621672f2..86d531c63683 100644
@@ -2318,7 +2318,7 @@ static int __bpf_redirect_neigh_v6(struct sk_buff *skb, struct net_device *dev,
 }
 #endif /* CONFIG_IPV6 */
 
-#if IS_ENABLED(CONFIG_INET)
+#if IS_ENABLED(CONFIG_IPV4)
 static int bpf_out_neigh_v4(struct net *net, struct sk_buff *skb,
 			    struct net_device *dev, struct bpf_nh_params *nh)
 {
@@ -2427,7 +2427,7 @@ static int __bpf_redirect_neigh_v4(struct sk_buff *skb, struct net_device *dev,
 	kfree_skb(skb);
 	return NET_XMIT_DROP;
 }
-#endif /* CONFIG_INET */
+#endif /* CONFIG_IPV4 */
 
 static int __bpf_redirect_neigh(struct sk_buff *skb, struct net_device *dev,
 				struct bpf_nh_params *nh)
@@ -5781,7 +5781,7 @@ static int __bpf_setsockopt(struct sock *sk, int level, int optname,
 
 	if (level == SOL_SOCKET)
 		return sol_socket_sockopt(sk, optname, optval, &optlen, false);
-	else if (IS_ENABLED(CONFIG_INET) && level == SOL_IP)
+	else if (IS_ENABLED(CONFIG_IPV4) && level == SOL_IP)
 		return sol_ip_sockopt(sk, optname, optval, &optlen, false);
 	else if (IS_ENABLED(CONFIG_IPV6) && level == SOL_IPV6)
 		return sol_ipv6_sockopt(sk, optname, optval, &optlen, false);
@@ -5818,7 +5818,7 @@ static int __bpf_getsockopt(struct sock *sk, int level, int optname,
 		err = sol_socket_sockopt(sk, optname, optval, &optlen, true);
 	else if (IS_ENABLED(CONFIG_INET) && level == SOL_TCP)
 		err = sol_tcp_sockopt(sk, optname, optval, &optlen, true);
-	else if (IS_ENABLED(CONFIG_INET) && level == SOL_IP)
+	else if (IS_ENABLED(CONFIG_IPV4) && level == SOL_IP)
 		err = sol_ip_sockopt(sk, optname, optval, &optlen, true);
 	else if (IS_ENABLED(CONFIG_IPV6) && level == SOL_IPV6)
 		err = sol_ipv6_sockopt(sk, optname, optval, &optlen, true);
@@ -6346,7 +6346,7 @@ static struct net_device *bpf_fib_vlan_input_dev(struct net_device *dev,
 }
 #endif
 
-#if IS_ENABLED(CONFIG_INET)
+#if IS_ENABLED(CONFIG_IPV4)
 static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
 			       u32 flags, bool check_mtu)
 {
@@ -6678,7 +6678,7 @@ BPF_CALL_4(bpf_xdp_fib_lookup, struct xdp_buff *, ctx,
 		return -EINVAL;
 
 	switch (params->family) {
-#if IS_ENABLED(CONFIG_INET)
+#if IS_ENABLED(CONFIG_IPV4)
 	case AF_INET:
 		return bpf_ipv4_fib_lookup(dev_net(ctx->rxq->dev), params,
 					   flags, true);
@@ -6722,7 +6722,7 @@ BPF_CALL_4(bpf_skb_fib_lookup, struct sk_buff *, skb,
 		check_mtu = true;
 
 	switch (params->family) {
-#if IS_ENABLED(CONFIG_INET)
+#if IS_ENABLED(CONFIG_IPV4)
 	case AF_INET:
 		rc = bpf_ipv4_fib_lookup(net, params, flags, check_mtu);
 		break;
@@ -12231,7 +12231,7 @@ BPF_CALL_1(bpf_skc_to_tcp_timewait_sock, struct sock *, sk)
 	BTF_TYPE_EMIT(struct inet_timewait_sock);
 	BTF_TYPE_EMIT(struct tcp_timewait_sock);
 
-#ifdef CONFIG_INET
+#ifdef CONFIG_IPV4
 	if (sk && sk->sk_prot == &tcp_prot && sk->sk_state == TCP_TIME_WAIT)
 		return (unsigned long)sk;
 #endif
@@ -12254,7 +12254,7 @@ const struct bpf_func_proto bpf_skc_to_tcp_timewait_sock_proto = {
 
 BPF_CALL_1(bpf_skc_to_tcp_request_sock, struct sock *, sk)
 {
-#ifdef CONFIG_INET
+#ifdef CONFIG_IPV4
 	if (sk && sk->sk_prot == &tcp_prot && sk->sk_state == TCP_NEW_SYN_RECV)
 		return (unsigned long)sk;
 #endif
@@ -12736,7 +12736,7 @@ __bpf_kfunc int bpf_icmp_send(struct __sk_buff *skb_ctx, int type, int code)
 		return -ENETUNREACH;
 
 	switch (skb->protocol) {
-#if IS_ENABLED(CONFIG_INET)
+#if IS_ENABLED(CONFIG_IPV4)
 	case htons(ETH_P_IP): {
 		struct sk_buff *nskb;
 
net/core/neighbour.c +4 -0
index 6ed8eb075146..63c2a1b86118 100644
@@ -3241,6 +3241,10 @@ int neigh_xmit(int index, struct net_device *dev,
 		if (index == NEIGH_ARP_TABLE) {
 			u32 key = *((u32 *)addr);
 
+			if (!IS_ENABLED(CONFIG_IPV4)) {
+				rcu_read_unlock();
+				goto out_kfree_skb;
+			}
 			neigh = __ipv4_neigh_lookup_noref(dev, key);
 		} else {
 			neigh = __neigh_lookup_noref(tbl, addr, dev);
net/ipv4/inet_hashtables.c +3 -0
index 5abcb0debb27..ae9f45368571 100644
@@ -596,6 +596,9 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
 	struct sock *sk2;
 	spinlock_t *lock;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EAFNOSUPPORT;
+
 	if (rcu_lookup) {
 		sk_nulls_for_each(sk2, node, &head->chain) {
 			if (sk2->sk_hash != hash ||
Signature · 1 line
2.55.0
#6 lore raw

PATCH v2 3/16 net: inet: relocate ip_generic_getfrag and guard IPv4 socket logic

In reply to Fernando Fernandez Mancera

To enable compiling the INET subsystem without IPv4, shared generic utilities must be relocated and IPv4 socket logic must be guarded for CONFIG_IPV4.

This patch moves the generic ip_generec_getfrag() from ip_output.c to af_inet.c. It also introduces CONFIG_IPV4 guards around af_inet.c to reject IPv4-specific ioctls, protocol registrations and bind requests. The same guard is added to reject IPv4-mapped IPv6.

---
 net/ipv4/af_inet.c   | 69 ++++++++++++++++++++++++++++++++++++++------
 net/ipv4/ip_output.c | 18 ------------
 net/ipv6/af_inet6.c  |  5 ++++
 net/ipv6/datagram.c  |  4 +--
 4 files changed, 67 insertions(+), 29 deletions(-)
net/ipv4/af_inet.c +60 -9
index d9421ac38d78..cf00386933d6 100644
@@ -129,6 +129,28 @@
 int disable_ipv6_mod;
 EXPORT_SYMBOL(disable_ipv6_mod);
 
+/* Keep the function here for now as it is generic, it should be moved
+ * to a common L3 place
+ */
+int
+ip_generic_getfrag(void *from, char *to, int offset, int len, int odd, struct sk_buff *skb)
+{
+	struct msghdr *msg = from;
+
+	if (skb->ip_summed == CHECKSUM_PARTIAL) {
+		if (!copy_from_iter_full(to, len, &msg->msg_iter))
+			return -EFAULT;
+	} else {
+		__wsum csum = 0;
+
+		if (!csum_and_copy_from_iter_full(to, len, &csum, &msg->msg_iter))
+			return -EFAULT;
+		skb->csum = csum_block_add(skb->csum, csum, odd);
+	}
+	return 0;
+}
+EXPORT_SYMBOL(ip_generic_getfrag);
+
 /* The inetsw table contains everything that inet_create needs to
  * build a new socket.
  */
@@ -426,7 +448,8 @@ int inet_release(struct socket *sock)
 			BPF_CGROUP_RUN_PROG_INET_SOCK_RELEASE(sk);
 
 		/* Applications forget to leave groups before exiting */
-		ip_mc_drop_socket(sk);
+		if (IS_ENABLED(CONFIG_IPV4))
+			ip_mc_drop_socket(sk);
 
 		/* If linger is set, we don't return until the close
 		 * is complete.  Otherwise we return immediately. The
@@ -486,6 +509,9 @@ int __inet_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len,
 	u32 tb_id = RT_TABLE_LOCAL;
 	int err;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EAFNOSUPPORT;
+
 	if (addr->sin_family != AF_INET) {
 		/* Compatibility games : accept AF_UNSPEC (mapped to AF_INET)
 		 * only if s_addr is INADDR_ANY.
@@ -968,6 +994,9 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 	struct ifreq ifr;
 	struct rtentry rt;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EOPNOTSUPP;
+
 	switch (cmd) {
 	case SIOCADDRT:
 	case SIOCDELRT:
@@ -1023,6 +1052,9 @@ static int inet_compat_routing_ioctl(struct sock *sk, unsigned int cmd,
 	compat_uptr_t rtdev;
 	struct rtentry rt;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EOPNOTSUPP;
+
 	if (copy_from_user(&rt.rt_dst, &ur->rt_dst,
 			3 * sizeof(struct sockaddr)) ||
 	    get_user(rt.rt_flags, &ur->rt_flags) ||
@@ -1153,6 +1185,7 @@ static const struct net_proto_family inet_family_ops = {
 	.owner	= THIS_MODULE,
 };
 
+#if IS_ENABLED(CONFIG_IPV4)
 /* Upon startup we insert all the elements in inetsw_array[] into
  * the linked list inetsw.
  */
@@ -1193,6 +1226,7 @@ static struct inet_protosw inetsw_array[] =
 };
 
 #define INETSW_ARRAY_LEN ARRAY_SIZE(inetsw_array)
+#endif
 
 void inet_register_protosw(struct inet_protosw *p)
 {
@@ -1267,6 +1301,9 @@ static int inet_sk_reselect_saddr(struct sock *sk)
 	struct ip_options_rcu *inet_opt;
 	int err;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EAFNOSUPPORT;
+
 	inet_opt = rcu_dereference_protected(inet->inet_opt,
 					     lockdep_sock_is_held(sk));
 	if (inet_opt && inet_opt->opt.srr)
@@ -1371,6 +1408,9 @@ struct sk_buff *inet_gso_segment(struct sk_buff *skb,
 	int ihl;
 	int id;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return ERR_PTR(-EPROTONOSUPPORT);
+
 	skb_reset_network_header(skb);
 	nhoff = skb_network_header(skb) - skb_mac_header(skb);
 	if (unlikely(!pskb_may_pull(skb, sizeof(*iph))))
@@ -1774,6 +1814,10 @@ static int __init init_ipv4_mibs(void)
 	return register_pernet_subsys(&ipv4_mib_ops);
 }
 
+#if IS_ENABLED(CONFIG_IPV4)
+static int ipv4_proc_init(void);
+#endif
+
 static __net_init int inet_init_net(struct net *net)
 {
 	/*
@@ -1824,8 +1868,6 @@ static int __init init_inet_pernet_ops(void)
 	return register_pernet_subsys(&af_inet_ops);
 }
 
-static int ipv4_proc_init(void);
-
 /*
  *	IP protocol layer initialiser
  */
@@ -1870,20 +1912,25 @@ static int __init ipv4_offload_init(void)
 
 fs_initcall(ipv4_offload_init);
 
+#if IS_ENABLED(CONFIG_IPV4)
 static struct packet_type ip_packet_type __read_mostly = {
 	.type = cpu_to_be16(ETH_P_IP),
 	.func = ip_rcv,
 	.list_func = ip_list_rcv,
 };
+#endif
 
 static int __init inet_init(void)
 {
+#if IS_ENABLED(CONFIG_IPV4)
 	struct inet_protosw *q;
 	struct list_head *r;
 	int rc;
+#endif
 
 	sock_skb_cb_check_size(sizeof(struct inet_skb_parm));
 
+#if IS_ENABLED(CONFIG_IPV4)
 	raw_hashinfo_init(&raw_v4_hashinfo);
 
 	rc = proto_register(&tcp_prot, 1);
@@ -1958,7 +2005,7 @@ static int __init inet_init(void)
 	 */
 
 	ip_init();
-
+#endif /* CONFIG_IPV4 */
 	/* Initialise per-cpu ipv4 mibs */
 	if (init_ipv4_mibs())
 		panic("%s: Cannot init ipv4 mibs\n", __func__);
@@ -1980,6 +2027,9 @@ static int __init inet_init(void)
 	if (icmp_init() < 0)
 		panic("Failed to create the ICMP control socket.\n");
 
+	if (init_inet_pernet_ops())
+		pr_crit("%s: Cannot init ipv4 inet pernet ops\n", __func__);
+#if IS_ENABLED(CONFIG_IPV4)
 	/*
 	 *	Initialise the multicast router
 	 */
@@ -1987,19 +2037,17 @@ static int __init inet_init(void)
 	if (ip_mr_init())
 		pr_crit("%s: Cannot init ipv4 mroute\n", __func__);
 #endif
-
-	if (init_inet_pernet_ops())
-		pr_crit("%s: Cannot init ipv4 inet pernet ops\n", __func__);
-
 	ipv4_proc_init();
 
 	ipfrag_init();
 
 	dev_add_pack(&ip_packet_type);
+#endif /* CONFIG_IPV4 */
 
 	ip_tunnel_core_init();
 
-	rc = 0;
+	return 0;
+#if IS_ENABLED(CONFIG_IPV4)
 out:
 	return rc;
 out_unregister_raw_proto:
@@ -2009,12 +2057,14 @@ static int __init inet_init(void)
 out_unregister_tcp_proto:
 	proto_unregister(&tcp_prot);
 	goto out;
+#endif
 }
 
 fs_initcall(inet_init);
 
 /* ------------------------------------------------------------------------ */
 
+#if IS_ENABLED(CONFIG_IPV4)
 #ifdef CONFIG_PROC_FS
 static int __init ipv4_proc_init(void)
 {
@@ -2051,3 +2101,4 @@ static int __init ipv4_proc_init(void)
 	return 0;
 }
 #endif /* CONFIG_PROC_FS */
+#endif
net/ipv4/ip_output.c +0 -18
index a24cc8ee11d3..4c6b34e70990 100644
@@ -932,24 +932,6 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
 }
 EXPORT_SYMBOL(ip_do_fragment);
 
-int
-ip_generic_getfrag(void *from, char *to, int offset, int len, int odd, struct sk_buff *skb)
-{
-	struct msghdr *msg = from;
-
-	if (skb->ip_summed == CHECKSUM_PARTIAL) {
-		if (!copy_from_iter_full(to, len, &msg->msg_iter))
-			return -EFAULT;
-	} else {
-		__wsum csum = 0;
-		if (!csum_and_copy_from_iter_full(to, len, &csum, &msg->msg_iter))
-			return -EFAULT;
-		skb->csum = csum_block_add(skb->csum, csum, odd);
-	}
-	return 0;
-}
-EXPORT_SYMBOL(ip_generic_getfrag);
-
 static int __ip_append_data(struct sock *sk,
 			    struct flowi4 *fl4,
 			    struct sk_buff_head *queue,
net/ipv6/af_inet6.c +5 -0
index f0efdc13baf4..f220eaab085b 100644
@@ -302,6 +302,11 @@ int __inet6_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len,
 		struct net_device *dev = NULL;
 		int chk_addr_ret;
 
+		if (!IS_ENABLED(CONFIG_IPV4)) {
+			err = -EADDRNOTAVAIL;
+			goto out;
+		}
+
 		/* Binding to v4-mapped address on a v6-only socket
 		 * makes no sense
 		 */
net/ipv6/datagram.c +2 -2
index 191c9733ff9f..079d1951405b 100644
@@ -153,7 +153,7 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
 	int			err;
 
 	if (usin->sin6_family == AF_INET) {
-		if (ipv6_only_sock(sk))
+		if (!IS_ENABLED(CONFIG_IPV4) || ipv6_only_sock(sk))
 			return -EAFNOSUPPORT;
 		err = __ip4_datagram_connect(sk, uaddr, addr_len);
 		goto ipv4_connected;
@@ -186,7 +186,7 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
 	if (addr_type & IPV6_ADDR_MAPPED) {
 		struct sockaddr_in sin;
 
-		if (ipv6_only_sock(sk)) {
+		if (!IS_ENABLED(CONFIG_IPV4) || ipv6_only_sock(sk)) {
 			err = -ENETUNREACH;
 			goto out;
 		}
Signature · 1 line
2.55.0
#8 lore raw

PATCH v2 4/16 tcp: move protocol agnostic TCP functions out of tcp_ipv4.c

In reply to Fernando Fernandez Mancera

As the tcp_ipv4.c file isn't compile anymore with CONFIG_IPV4=n, the generic TCP function must be moved out of tcp_ipv4.c file and they should be placed in tcp.c file.

As part of this migration, rename tcp_v4_destroy_sock() to tcp_destroy_sock() to reflect its shared usage by IPv4 and IPv6.

In addition, guard IPv4 code around IPv6 TCP implementation. This ensures that IPv4-mapped IPv6 sockects are rejected with a proper error code when IPv4 stack is disabled.

Please note that this commit also addresses how /proc/net/sockstat output is handled for all protocols. The implementation now force the inuse attrtibute to be zero when CONFIG_IPV4=n but the shared stats are represented correctly.

---
 include/net/tcp.h               |   16 +-
 net/ipv4/af_inet.c              |   93 +--
 net/ipv4/inet_connection_sock.c |    2 +-
 net/ipv4/proc.c                 |   45 +-
 net/ipv4/tcp.c                  | 1300 +++++++++++++++++++++++++++++-
 net/ipv4/tcp_bpf.c              |    3 +-
 net/ipv4/tcp_ipv4.c             | 1307 +------------------------------
 net/ipv6/tcp_ipv6.c             |   23 +-
 8 files changed, 1412 insertions(+), 1377 deletions(-)
include/net/tcp.h +15 -1
index 96a1a23e47fa..04d487a19b17 100644
@@ -2437,7 +2437,7 @@ struct tcp_iter_state {
 extern struct request_sock_ops tcp_request_sock_ops;
 extern struct request_sock_ops tcp6_request_sock_ops;
 
-void tcp_v4_destroy_sock(struct sock *sk);
+void tcp_destroy_sock(struct sock *sk);
 
 struct sk_buff *tcp_gso_segment(struct sk_buff *skb,
 				netdev_features_t features);
@@ -2855,6 +2855,20 @@ struct sk_psock;
 #ifdef CONFIG_BPF_SYSCALL
 int tcp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
 void tcp_bpf_clone(const struct sock *sk, struct sock *newsk);
+
+union bpf_tcp_iter_batch_item {
+	struct sock *sk;
+	__u64 cookie;
+};
+
+struct bpf_tcp_iter_state {
+	struct tcp_iter_state state;
+	unsigned int cur_sk;
+	unsigned int end_sk;
+	unsigned int max_sk;
+	union bpf_tcp_iter_batch_item *batch;
+};
+
 #ifdef CONFIG_BPF_STREAM_PARSER
 struct strparser;
 int tcp_bpf_strp_read_sock(struct strparser *strp, read_descriptor_t *desc,
net/ipv4/af_inet.c +49 -44

169 lines not on this page · raw message

net/ipv4/inet_connection_sock.c +1 -1
index c688c454422a..94ade387ad81 100644
@@ -1384,7 +1384,7 @@ static void inet_child_forget(struct sock *sk, struct request_sock *req,
 		 * an inbound pkt destined for child is
 		 * blocked by sock lock in tcp_v4_rcv().
 		 * Also to satisfy an assertion in
-		 * tcp_v4_destroy_sock().
+		 * tcp_destroy_sock().
 		 */
 		RCU_INIT_POINTER(tcp_sk(child)->fastopen_rsk, NULL);
 	}
net/ipv4/proc.c +28 -17

85 lines not on this page · raw message

net/ipv4/tcp.c +1299 -1

1,330 lines not on this page · raw message

net/ipv4/tcp_bpf.c +2 -1
index 2e234d155b5e..23748ec9cb9c 100644
@@ -671,7 +671,8 @@ static void tcp_bpf_check_v6_needs_rebuild(struct proto *ops)
 
 static int __init tcp_bpf_v4_build_proto(void)
 {
-	tcp_bpf_rebuild_protos(tcp_bpf_prots[TCP_BPF_IPV4], &tcp_prot);
+	if (IS_ENABLED(CONFIG_IPV4))
+		tcp_bpf_rebuild_protos(tcp_bpf_prots[TCP_BPF_IPV4], &tcp_prot);
 	return 0;
 }
 late_initcall(tcp_bpf_v4_build_proto);
net/ipv4/tcp_ipv4.c +1 -1306

1,371 lines not on this page · raw message

net/ipv6/tcp_ipv6.c +17 -6
index afb4d8e9fa67..07a4222e1712 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.55.0

Part of the diff is not shown here. View the raw message.

#10 lore raw

PATCH v2 5/16 ipv4: raw: split IPv4 specific logic into raw_ipv4.c

In reply to Fernando Fernandez Mancera

To enable compiling the INET subsystem without IPv4, RAW socket IPv4 specific functions must be isolated from the generic RAW socket infrastructure, similar to how it is done for TCP.

This patch creates raw_ipv4.c and move all the functions for packet matching, input/output processing, ICMP filtering and the AF_INET raw_prot definition from raw.c to the new file. The Makefile is updated to compile raw_ipv4.c only when CONFIG_IPV4 is enabled.

---
 net/ipv4/Makefile   |   2 +-
 net/ipv4/raw.c      | 853 ------------------------------------------
 net/ipv4/raw_diag.c |   3 +-
 net/ipv4/raw_ipv4.c | 883 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 886 insertions(+), 855 deletions(-)
 create mode 100644 net/ipv4/raw_ipv4.c
net/ipv4/Makefile +1 -1
index 8b148be79fa4..7ac882ec5d4f 100644
@@ -13,7 +13,7 @@ obj-y     := inetpeer.o protocol.o inet_hashtables.o inet_timewait_sock.o \
 obj-$(CONFIG_IPV4) += route.o ip_input.o ip_fragment.o ip_forward.o ip_options.o \
 		      ip_sockglue.o tcp_ipv4.o datagram.o icmp.o arp.o devinet.o \
 		      igmp.o fib_notifier.o ip_output.o fib_frontend.o \
-		      fib_semantics.o fib_trie.o
+		      fib_semantics.o fib_trie.o raw_ipv4.o
 
 obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o
 obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o
net/ipv4/raw.c +0 -853

896 lines not on this page · raw message

net/ipv4/raw_diag.c +2 -1
index 943e5998e0ad..38a1e74af7cd 100644
@@ -40,7 +40,8 @@ static bool raw_lookup(struct net *net, const struct sock *sk,
 	struct inet_diag_req_raw *r = (void *)req;
 
 	if (r->sdiag_family == AF_INET)
-		return raw_v4_match(net, sk, r->sdiag_raw_protocol,
+		return IS_ENABLED(CONFIG_IPV4) &&
+		       raw_v4_match(net, sk, r->sdiag_raw_protocol,
 				    r->id.idiag_dst[0],
 				    r->id.idiag_src[0],
 				    r->id.idiag_if, 0);
net/ipv4/raw_ipv4.c new file +883 -0

883 lines not on this page · raw message

Signature · 1 line
2.55.0
#12 lore raw

PATCH v2 6/16 ipv4: udp: split IPv4 specific logic into udp_ipv4.c

In reply to Fernando Fernandez Mancera

To enable compiling the INET subsystem without IPv4, UDP socket IPv4 specific functions must be isolated from the generic UDP socket infrastructure, similar to how it is done for TCP.

This patch creates udp_ipv4.c and move all the functions for packet matching, input/output processing, multicast and the AF_INET udp_prot from udp.c to the new file. The Makefile is updated to compile udp_ipv4.c only when CONFIG_IPV4 is enabled.

---
 include/net/udp.h      |   11 +
 net/ipv4/Makefile      |    2 +-
 net/ipv4/af_inet.c     |   10 +
 net/ipv4/udp.c         | 1817 +---------------------------------------
 net/ipv4/udp_bpf.c     |    5 +-
 net/ipv4/udp_ipv4.c    | 1790 +++++++++++++++++++++++++++++++++++++++
 net/ipv4/udp_offload.c |    3 +
 net/ipv6/udp.c         |   11 +-
 8 files changed, 1861 insertions(+), 1788 deletions(-)
 create mode 100644 net/ipv4/udp_ipv4.c
include/net/udp.h +11 -0
index 1fee17274745..9915e9b84c65 100644
@@ -436,9 +436,20 @@ int udp_lib_setsockopt(struct sock *sk, int level, int optname,
 		       int (*push_pending_frames)(struct sock *));
 struct sock *udp4_lib_lookup(const struct net *net, __be32 saddr, __be16 sport,
 			     __be32 daddr, __be16 dport, int dif);
+#if IS_ENABLED(CONFIG_IPV4)
 struct sock *__udp4_lib_lookup(const struct net *net, __be32 saddr,
 			       __be16 sport, __be32 daddr, __be16 dport,
 			       int dif, int sdif, struct sk_buff *skb);
+#else
+static inline struct sock *__udp4_lib_lookup(const struct net *net,
+					     __be32 saddr, __be16 sport,
+					     __be32 daddr, __be16 dport,
+					     int dif, int sdif,
+					     struct sk_buff *skb)
+{
+	return NULL;
+}
+#endif
 struct sock *udp4_lib_lookup_skb(const struct sk_buff *skb,
 				 __be16 sport, __be16 dport);
 struct sock *udp6_lib_lookup(const struct net *net,
net/ipv4/Makefile +1 -1
index 7ac882ec5d4f..48ef3fb3b164 100644
@@ -13,7 +13,7 @@ obj-y     := inetpeer.o protocol.o inet_hashtables.o inet_timewait_sock.o \
 obj-$(CONFIG_IPV4) += route.o ip_input.o ip_fragment.o ip_forward.o ip_options.o \
 		      ip_sockglue.o tcp_ipv4.o datagram.o icmp.o arp.o devinet.o \
 		      igmp.o fib_notifier.o ip_output.o fib_frontend.o \
-		      fib_semantics.o fib_trie.o raw_ipv4.o
+		      fib_semantics.o fib_trie.o raw_ipv4.o udp_ipv4.o
 
 obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o
 obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o
net/ipv4/af_inet.c +10 -0
index 6c7b0816f950..5a191d0a3bfc 100644
@@ -886,8 +886,13 @@ int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
 		return -EAGAIN;
 
 	prot = READ_ONCE(sk->sk_prot);
+#if IS_ENABLED(CONFIG_IPV4)
 	return INDIRECT_CALL_2(prot->sendmsg, tcp_sendmsg, udp_sendmsg,
 			       sk, msg, size);
+#else
+	return INDIRECT_CALL_1(prot->sendmsg, tcp_sendmsg,
+			       sk, msg, size);
+#endif
 }
 EXPORT_SYMBOL(inet_sendmsg);
 
@@ -914,8 +919,13 @@ int inet_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
 		sock_rps_record_flow(sk);
 
 	prot = READ_ONCE(sk->sk_prot);
+#if IS_ENABLED(CONFIG_IPV4)
 	return INDIRECT_CALL_2(prot->recvmsg, tcp_recvmsg, udp_recvmsg,
 			       sk, msg, size, flags);
+#else
+	return INDIRECT_CALL_1(prot->recvmsg, tcp_recvmsg,
+			       sk, msg, size, flags);
+#endif
 }
 EXPORT_SYMBOL(inet_recvmsg);
 
net/ipv4/udp.c +35 -1782

1,925 lines not on this page · raw message

net/ipv4/udp_bpf.c +4 -1
index ad57c4c9eaab..a5e9e6daad3a 100644
@@ -16,6 +16,8 @@ static int sk_udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len,
 	if (sk->sk_family == AF_INET6)
 		return udpv6_prot_saved->recvmsg(sk, msg, len, flags);
 #endif
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EAFNOSUPPORT;
 	return udp_prot.recvmsg(sk, msg, len, flags);
 }
 
@@ -155,7 +157,8 @@ static void udp_bpf_check_v6_needs_rebuild(struct proto *ops)
 
 static int __init udp_bpf_v4_build_proto(void)
 {
-	udp_bpf_rebuild_protos(&udp_bpf_prots[UDP_BPF_IPV4], &udp_prot);
+	if (IS_ENABLED(CONFIG_IPV4))
+		udp_bpf_rebuild_protos(&udp_bpf_prots[UDP_BPF_IPV4], &udp_prot);
 	return 0;
 }
 late_initcall(udp_bpf_v4_build_proto);
net/ipv4/udp_ipv4.c new file +1790 -0

1,004 lines not on this page · raw message

net/ipv4/udp_offload.c +3 -0
index cf07c3c6611a..bea037d6b4eb 100644

Lines of this file are not shown. View the raw message.

net/ipv6/udp.c +7 -4
index 59f9872c3552..8cdc24ed996a 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.55.0

Part of the diff is not shown here. View the raw message.

#16 lore raw

PATCH v2 7/16 ipv4: icmp: split IPv4 specific logic into icmp_ipv4.c

In reply to Fernando Fernandez Mancera

To enable compiling INET subsystem withot IPv4, ICMP protocol IPv4 specific functions must be isolated from the generic ICMP protocol infrastructure.

This patch creates icmp_ipv4.c and move all the functions for packet processing, error handling, and other from icmp.c to a new file. The Makefile is updated to compile icmp_ipv4.c only when CONFIG_IPV4 is enabled.

---
 include/net/icmp.h   |    1 +
 net/ipv4/Makefile    |    9 +-
 net/ipv4/icmp.c      | 1418 +----------------------------------------
 net/ipv4/icmp_ipv4.c | 1448 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1459 insertions(+), 1417 deletions(-)
 create mode 100644 net/ipv4/icmp_ipv4.c
include/net/icmp.h +1 -0
index 935ee13d9ae9..85ad655aea5f 100644
@@ -57,6 +57,7 @@ static inline void icmp_ndo_send(struct sk_buff *skb_in, int type, int code, __b
 
 int icmp_rcv(struct sk_buff *skb);
 int icmp_err(struct sk_buff *skb, u32 info);
+int icmp_init_ipv4(void);
 int icmp_init(void);
 void icmp_out_count(struct net *net, unsigned char type);
 bool icmp_build_probe(struct sk_buff *skb, struct icmphdr *icmphdr);
net/ipv4/Makefile +5 -4
index 48ef3fb3b164..651835073a29 100644
@@ -8,12 +8,13 @@ obj-y     := inetpeer.o protocol.o inet_hashtables.o inet_timewait_sock.o \
 	     tcp_minisocks.o tcp_cong.o tcp_metrics.o tcp_fastopen.o \
 	     tcp_recovery.o tcp_ulp.o tcp_offload.o tcp_plb.o raw.o udp.o \
 	     udp_offload.o af_inet.o inet_fragment.o ping.o ip_tunnel_core.o \
-	     gre_offload.o metrics.o netlink.o nexthop.o udp_tunnel_stub.o
+	     gre_offload.o metrics.o netlink.o nexthop.o udp_tunnel_stub.o \
+	     icmp.o
 
 obj-$(CONFIG_IPV4) += route.o ip_input.o ip_fragment.o ip_forward.o ip_options.o \
-		      ip_sockglue.o tcp_ipv4.o datagram.o icmp.o arp.o devinet.o \
-		      igmp.o fib_notifier.o ip_output.o fib_frontend.o \
-		      fib_semantics.o fib_trie.o raw_ipv4.o udp_ipv4.o
+		      ip_sockglue.o tcp_ipv4.o datagram.o arp.o devinet.o igmp.o \
+		      fib_notifier.o ip_output.o fib_frontend.o fib_semantics.o \
+		      fib_trie.o raw_ipv4.o udp_ipv4.o icmp_ipv4.o
 
 obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o
 obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o
net/ipv4/icmp.c +5 -1413

1,462 lines not on this page · raw message

net/ipv4/icmp_ipv4.c new file +1448 -0

1,448 lines not on this page · raw message

Signature · 1 line
2.55.0
#18 lore raw

PATCH v2 8/16 ipv4: ping: split IPv4 specific logic into ping_ipv4.c

In reply to Fernando Fernandez Mancera

To enable compiling INET subsystem withot IPv4, ping socket IPv4 specific functions must be isolated from the generic ping infrastructure.

This patch creates ping_ipv4.c and move all the functions for packet transmission and the AF_INET ping_prot definition from ping.c to the new file. The Makefile is updated to compile ping_ipv4.c only when CONFIG_IPV4 is enabled.

---
 net/ipv4/Makefile    |   2 +-
 net/ipv4/ping.c      | 210 +--------------------------------------
 net/ipv4/ping_ipv4.c | 228 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 234 insertions(+), 206 deletions(-)
 create mode 100644 net/ipv4/ping_ipv4.c
net/ipv4/Makefile +1 -1
index 651835073a29..83c25f52eb58 100644
@@ -14,7 +14,7 @@ obj-y     := inetpeer.o protocol.o inet_hashtables.o inet_timewait_sock.o \
 obj-$(CONFIG_IPV4) += route.o ip_input.o ip_fragment.o ip_forward.o ip_options.o \
 		      ip_sockglue.o tcp_ipv4.o datagram.o arp.o devinet.o igmp.o \
 		      fib_notifier.o ip_output.o fib_frontend.o fib_semantics.o \
-		      fib_trie.o raw_ipv4.o udp_ipv4.o icmp_ipv4.o
+		      fib_trie.o raw_ipv4.o udp_ipv4.o icmp_ipv4.o ping_ipv4.o
 
 obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o
 obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o
net/ipv4/ping.c +5 -205

252 lines not on this page · raw message

net/ipv4/ping_ipv4.c new file +228 -0

228 lines not on this page · raw message

Signature · 1 line
2.55.0
#19 lore raw

PATCH v2 9/16 ipv4: fib: split common nexthop logic to fib_core.c

In reply to Fernando Fernandez Mancera

To enable compiling INET subsystem without IPv4, shared FIB and nexthop logic must be accessible to IPv6 when IPv4 routing stack is omitted.

This patch creates fib_core.c and move all the functions for common nexthop initialization and release from fib_semantics.c to fib_core.c. Note that fib_core.c is under net/core.

---
 include/net/ip_fib.h       |  27 +++-
 include/net/route.h        |   6 +
 net/core/Makefile          |   2 +-
 net/core/fib_core.c        | 307 +++++++++++++++++++++++++++++++++++++
 net/ipv4/fib_frontend.c    |  96 ------------
 net/ipv4/fib_semantics.c   | 205 -------------------------
 net/ipv4/nexthop.c         |   5 +-
 net/ipv4/sysctl_net_ipv4.c |   2 +
 8 files changed, 345 insertions(+), 305 deletions(-)
 create mode 100644 net/core/fib_core.c
include/net/ip_fib.h +26 -1
index 0a35355fb0f3..6058e53fa3de 100644
@@ -250,7 +250,13 @@ int call_fib4_notifiers(struct net *net, enum fib_event_type event_type,
 int __net_init fib4_notifier_init(struct net *net);
 void __net_exit fib4_notifier_exit(struct net *net);
 
+#if IS_ENABLED(CONFIG_IPV4)
 void fib_info_notify_update(struct net *net, struct nl_info *info);
+#else
+static inline void fib_info_notify_update(struct net *net, struct nl_info *info)
+{
+}
+#endif
 int fib_notify(struct net *net, struct notifier_block *nb,
 	       struct netlink_ext_ack *extack);
 
@@ -442,7 +448,7 @@ static inline bool fib_dscp_masked_match(dscp_t dscp, const struct flowi4 *fl4)
 	return dscp == (fl4->flowi4_dscp & INET_DSCP_LEGACY_TOS_MASK);
 }
 
-/* Exported by fib_frontend.c */
+/* Exported by net/core/fib_core.c */
 extern const struct nla_policy rtm_ipv4_policy[];
 void ip_fib_init(void);
 int fib_gw_from_via(struct fib_config *cfg, struct nlattr *nla,
@@ -578,10 +584,23 @@ void fib_select_multipath(struct fib_result *res, int hash,
 void fib_select_path(struct net *net, struct fib_result *res,
 		     struct flowi4 *fl4, const struct sk_buff *skb);
 
+#if IS_ENABLED(CONFIG_IPV4)
 int fib_nh_init(struct net *net, struct fib_nh *fib_nh,
 		struct fib_config *cfg, int nh_weight,
 		struct netlink_ext_ack *extack);
 void fib_nh_release(struct net *net, struct fib_nh *fib_nh);
+#else
+static inline int fib_nh_init(struct net *net, struct fib_nh *fib_nh,
+			      struct fib_config *cfg, int nh_weight,
+			      struct netlink_ext_ack *extack)
+{
+	return -EAFNOSUPPORT;
+}
+
+static inline void fib_nh_release(struct net *net, struct fib_nh *fib_nh)
+{
+}
+#endif
 int fib_nh_common_init(struct net *net, struct fib_nh_common *nhc,
 		       struct nlattr *fc_encap, u16 fc_encap_type,
 		       void *cfg, gfp_t gfp_flags,
@@ -620,7 +639,13 @@ static inline void fib_combine_itag(u32 *itag, const struct fib_result *res)
 #endif
 }
 
+#if IS_ENABLED(CONFIG_IPV4)
 void fib_flush(struct net *net);
+#else
+static inline void fib_flush(struct net *net)
+{
+}
+#endif
 void free_fib_info(struct fib_info *fi);
 
 static inline void fib_info_hold(struct fib_info *fi)
include/net/route.h +6 -0
index 8c21881eb5f4..8788bf096c15 100644
@@ -128,7 +128,13 @@ extern struct ip_rt_acct __percpu *ip_rt_acct;
 struct in_device;
 
 int ip_rt_init(void);
+#if IS_ENABLED(CONFIG_IPV4)
 void rt_cache_flush(struct net *net);
+#else
+static inline void rt_cache_flush(struct net *net)
+{
+}
+#endif
 void rt_flush_dev(struct net_device *dev);
 
 static inline void inet_sk_init_flowi4(const struct inet_sock *inet,
net/core/Makefile +1 -1
index c20e520358b8..315e437a49d8 100644
@@ -12,7 +12,7 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o
 obj-y		     += dev.o dev_api.o dev_addr_lists.o dst.o netevent.o \
 			neighbour.o rtnetlink.o utils.o link_watch.o filter.o \
 			sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \
-			fib_notifier.o xdp.o flow_offload.o gro.o \
+			fib_notifier.o fib_core.o xdp.o flow_offload.o gro.o \
 			netdev-genl.o netdev-genl-gen.o netdev_work.o gso.o
 
 obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o
net/core/fib_core.c new file +307 -0

307 lines not on this page · raw message

net/ipv4/fib_frontend.c +0 -96

108 lines not on this page · raw message

net/ipv4/fib_semantics.c +0 -205

223 lines not on this page · raw message

net/ipv4/nexthop.c +3 -2
index 42e55b5a755e..ad79943376c5 100644
@@ -1421,7 +1421,7 @@ static bool nexthop_is_good_nh(const struct nexthop *nh)
 
 	switch (nhi->family) {
 	case AF_INET:
-		return ipv4_good_nh(&nhi->fib_nh);
+		return IS_ENABLED(CONFIG_IPV4) && ipv4_good_nh(&nhi->fib_nh);
 	case AF_INET6:
 		return IS_ENABLED(CONFIG_IPV6) && ipv6_good_nh(&nhi->fib6_nh);
 	}
@@ -4005,7 +4005,8 @@ static int nh_netdev_event(struct notifier_block *this,
 		break;
 	case NETDEV_CHANGEMTU:
 		info_ext = ptr;
-		nexthop_sync_mtu(dev, info_ext->ext.mtu);
+		if (IS_ENABLED(CONFIG_IPV4))
+			nexthop_sync_mtu(dev, info_ext->ext.mtu);
 		rt_cache_flush(dev_net(dev));
 		break;
 	}
net/ipv4/sysctl_net_ipv4.c +2 -0
index e3760daa3470..0e7fef5973db 100644
@@ -615,6 +615,7 @@ static struct ctl_table ipv4_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_doulongvec_minmax,
 	},
+#if IS_ENABLED(CONFIG_IPV4)
 	{
 		.procname	= "fib_sync_mem",
 		.data		= &sysctl_fib_sync_mem,
@@ -624,6 +625,7 @@ static struct ctl_table ipv4_table[] = {
 		.extra1		= &sysctl_fib_sync_mem_min,
 		.extra2		= &sysctl_fib_sync_mem_max,
 	},
+#endif
 };
 
 static const struct ctl_table ipv4_net_table[] = {
Signature · 1 line
2.55.0
#21 lore raw

PATCH v2 10/16 tunnels: guard IPv4 tunnel functions with CONFIG_IPV4

In reply to Fernando Fernandez Mancera

To enable compiling INET subsystem withou IPv4, IPv4 specific IP tunnel core functions must be bypassed when the protocol is disabled.

---
 net/ipv4/ip_tunnel_core.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
net/ipv4/ip_tunnel_core.c +11 -0
index bab42b9e277f..996e61243922 100644
@@ -58,6 +58,14 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
 	struct iphdr *iph;
 	int err;
 
+	if (!IS_ENABLED(CONFIG_IPV4)) {
+		if (dev)
+			DEV_STATS_INC(dev, tx_errors);
+		ip_rt_put(rt);
+		kfree_skb(skb);
+		return;
+	}
+
 	if (unlikely(dev_recursion_level() > IP_TUNNEL_RECURSION_LIMIT)) {
 		if (dev) {
 			net_crit_ratelimited("Dead loop on virtual device %s (net %llu), fix it urgently!\n",
@@ -218,6 +226,9 @@ static int iptunnel_pmtud_build_icmp(struct sk_buff *skb, int mtu)
 	struct ethhdr eh;
 	int len, err;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EOPNOTSUPP;
+
 	if (!pskb_may_pull(skb, ETH_HLEN + sizeof(struct iphdr)))
 		return -EINVAL;
 
Signature · 1 line
2.55.0
#22 lore raw

PATCH v2 11/16 ipv4: disable IPv4-only sysctls when CONFIG_IPV4=n

In reply to Fernando Fernandez Mancera

To avoid noise and unexpected problems, let's hide all the sysctls that are related to IPv4 only when the kernel is compiled without IPv4 support.

---
 net/ipv4/sysctl_net_ipv4.c | 407 +++++++++++++++++++------------------
 1 file changed, 205 insertions(+), 202 deletions(-)
net/ipv4/sysctl_net_ipv4.c +205 -202
index 0e7fef5973db..6096e9e4d82d 100644
@@ -31,8 +31,8 @@ static int tcp_min_snd_mss_max = 65535;
 static int tcp_rto_max_max = TCP_RTO_MAX_SEC * MSEC_PER_SEC;
 static int ip_privileged_port_min;
 static int ip_privileged_port_max = 65535;
-static int ip_ttl_min = 1;
-static int ip_ttl_max = 255;
+static int ip_ttl_min __maybe_unused = 1;
+static int ip_ttl_max __maybe_unused = 255;
 static int tcp_syn_retries_min = 1;
 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
 static int tcp_syn_linear_timeouts_max = MAX_TCP_SYNCNT;
@@ -48,7 +48,7 @@ static int tcp_plb_max_rounds = 31;
 static int tcp_plb_max_cong_thresh = 256;
 static unsigned int tcp_tw_reuse_delay_max = TCP_PAWS_MSL * MSEC_PER_SEC;
 static int tcp_ecn_mode_max = 5;
-static u32 icmp_errors_extension_mask_all =
+static u32 icmp_errors_extension_mask_all __maybe_unused =
 	GENMASK_U8(ICMP_ERR_EXT_COUNT - 1, 0);
 
 static int tcp_min_rcvbuf = 4096;
@@ -201,8 +201,9 @@ static int ipv4_ping_group_range(const struct ctl_table *table, int write,
 	return ret;
 }
 
-static int ipv4_fwd_update_priority(const struct ctl_table *table, int write,
-				    void *buffer, size_t *lenp, loff_t *ppos)
+static int __maybe_unused
+ipv4_fwd_update_priority(const struct ctl_table *table, int write,
+			 void *buffer, size_t *lenp, loff_t *ppos)
 {
 	struct net *net;
 	int ret;
@@ -441,9 +442,9 @@ static int proc_udp_hash_entries(const struct ctl_table *table, int write,
 }
 
 #ifdef CONFIG_IP_ROUTE_MULTIPATH
-static int proc_fib_multipath_hash_policy(const struct ctl_table *table, int write,
-					  void *buffer, size_t *lenp,
-					  loff_t *ppos)
+static int __maybe_unused
+proc_fib_multipath_hash_policy(const struct ctl_table *table, int write,
+			       void *buffer, size_t *lenp, loff_t *ppos)
 {
 	struct net *net = container_of(table->data, struct net,
 	    ipv4.sysctl_fib_multipath_hash_policy);
@@ -456,9 +457,9 @@ static int proc_fib_multipath_hash_policy(const struct ctl_table *table, int wri
 	return ret;
 }
 
-static int proc_fib_multipath_hash_fields(const struct ctl_table *table, int write,
-					  void *buffer, size_t *lenp,
-					  loff_t *ppos)
+static int __maybe_unused
+proc_fib_multipath_hash_fields(const struct ctl_table *table, int write,
+			       void *buffer, size_t *lenp, loff_t *ppos)
 {
 	struct net *net;
 	int ret;
@@ -492,9 +493,9 @@ static void proc_fib_multipath_hash_set_seed(struct net *net, u32 user_seed)
 	WRITE_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed.mp_seed, new.mp_seed);
 }
 
-static int proc_fib_multipath_hash_seed(const struct ctl_table *table, int write,
-					void *buffer, size_t *lenp,
-					loff_t *ppos)
+static int __maybe_unused
+proc_fib_multipath_hash_seed(const struct ctl_table *table, int write,
+			     void *buffer, size_t *lenp, loff_t *ppos)
 {
 	struct sysctl_fib_multipath_hash_seed *mphs;
 	struct net *net = table->data;
@@ -636,15 +637,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec
 	},
-	{
-		.procname	= "icmp_echo_ignore_all",
-		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_all,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE
-	},
 	{
 		.procname	= "icmp_echo_enable_probe",
 		.data		= &init_net.ipv4.sysctl_icmp_echo_enable_probe,
@@ -654,56 +646,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_ONE
 	},
-	{
-		.procname	= "icmp_echo_ignore_broadcasts",
-		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE
-	},
-	{
-		.procname	= "icmp_ignore_bogus_error_responses",
-		.data		= &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE
-	},
-	{
-		.procname	= "icmp_errors_use_inbound_ifaddr",
-		.data		= &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE
-	},
-	{
-		.procname	= "icmp_errors_extension_mask",
-		.data		= &init_net.ipv4.sysctl_icmp_errors_extension_mask,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= &icmp_errors_extension_mask_all,
-	},
-	{
-		.procname	= "icmp_ratelimit",
-		.data		= &init_net.ipv4.sysctl_icmp_ratelimit,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_ms_jiffies,
-	},
-	{
-		.procname	= "icmp_ratemask",
-		.data		= &init_net.ipv4.sysctl_icmp_ratemask,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec
-	},
 	{
 		.procname	= "icmp_msgs_per_sec",
 		.data		= &init_net.ipv4.sysctl_icmp_msgs_per_sec,
@@ -774,13 +716,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_ONE,
 	},
-	{
-		.procname	= "ip_dynaddr",
-		.data		= &init_net.ipv4.sysctl_ip_dynaddr,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
 	{
 		.procname	= "ip_early_demux",
 		.data		= &init_net.ipv4.sysctl_ip_early_demux,
@@ -811,15 +746,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_ONE,
 	},
-	{
-		.procname	= "ip_default_ttl",
-		.data		= &init_net.ipv4.sysctl_ip_default_ttl,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= &ip_ttl_min,
-		.extra2		= &ip_ttl_max,
-	},
 	{
 		.procname	= "ip_local_port_range",
 		.maxlen		= 0,
@@ -841,36 +767,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_do_large_bitmap,
 	},
-	{
-		.procname	= "ip_no_pmtu_disc",
-		.data		= &init_net.ipv4.sysctl_ip_no_pmtu_disc,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
-	{
-		.procname	= "ip_forward_use_pmtu",
-		.data		= &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
-	{
-		.procname	= "ip_forward_update_priority",
-		.data		= &init_net.ipv4.sysctl_ip_fwd_update_priority,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler   = ipv4_fwd_update_priority,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE,
-	},
-	{
-		.procname	= "ip_nonlocal_bind",
-		.data		= &init_net.ipv4.sysctl_ip_nonlocal_bind,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
 	{
 		.procname	= "ip_autobind_reuse",
 		.data		= &init_net.ipv4.sysctl_ip_autobind_reuse,
@@ -880,13 +776,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.extra1         = SYSCTL_ZERO,
 		.extra2         = SYSCTL_ONE,
 	},
-	{
-		.procname	= "fwmark_reflect",
-		.data		= &init_net.ipv4.sysctl_fwmark_reflect,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
 	{
 		.procname	= "tcp_fwmark_accept",
 		.data		= &init_net.ipv4.sysctl_tcp_fwmark_accept,
@@ -952,37 +841,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.proc_handler	= proc_douintvec_minmax,
 		.extra2		= &u32_max_div_HZ,
 	},
-	{
-		.procname	= "igmp_link_local_mcast_reports",
-		.data		= &init_net.ipv4.sysctl_igmp_llm_reports,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
-	{
-		.procname	= "igmp_max_memberships",
-		.data		= &init_net.ipv4.sysctl_igmp_max_memberships,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec
-	},
-	{
-		.procname	= "igmp_max_msf",
-		.data		= &init_net.ipv4.sysctl_igmp_max_msf,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec
-	},
-#ifdef CONFIG_IP_MULTICAST
-	{
-		.procname	= "igmp_qrv",
-		.data		= &init_net.ipv4.sysctl_igmp_qrv,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ONE
-	},
-#endif
 	{
 		.procname	= "tcp_congestion_control",
 		.data		= &init_net.ipv4.tcp_congestion_control,
@@ -1154,42 +1012,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.proc_handler	= proc_tfo_blackhole_detect_timeout,
 		.extra1		= SYSCTL_ZERO,
 	},
-#ifdef CONFIG_IP_ROUTE_MULTIPATH
-	{
-		.procname	= "fib_multipath_use_neigh",
-		.data		= &init_net.ipv4.sysctl_fib_multipath_use_neigh,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE,
-	},
-	{
-		.procname	= "fib_multipath_hash_policy",
-		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_policy,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_fib_multipath_hash_policy,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_THREE,
-	},
-	{
-		.procname	= "fib_multipath_hash_fields",
-		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_fields,
-		.maxlen		= sizeof(u32),
-		.mode		= 0644,
-		.proc_handler	= proc_fib_multipath_hash_fields,
-		.extra1		= SYSCTL_ONE,
-		.extra2		= &fib_multipath_hash_fields_all_mask,
-	},
-	{
-		.procname	= "fib_multipath_hash_seed",
-		.data		= &init_net,
-		.maxlen		= sizeof(u32),
-		.mode		= 0644,
-		.proc_handler	= proc_fib_multipath_hash_seed,
-	},
-#endif
 	{
 		.procname	= "ip_unprivileged_port_start",
 		.maxlen		= sizeof(int),
@@ -1563,15 +1385,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.proc_handler	= proc_dointvec_minmax,
 		.extra1		= SYSCTL_ONE
 	},
-	{
-		.procname	= "fib_notify_on_flag_change",
-		.data		= &init_net.ipv4.sysctl_fib_notify_on_flag_change,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_TWO,
-	},
 	{
 		.procname       = "tcp_plb_enabled",
 		.data           = &init_net.ipv4.sysctl_tcp_plb_enabled,
@@ -1656,6 +1469,196 @@ static const struct ctl_table ipv4_net_table[] = {
 		.extra1		= SYSCTL_ONE_THOUSAND,
 		.extra2		= &tcp_rto_max_max,
 	},
+#if IS_ENABLED(CONFIG_IPV4)
+	{
+		.procname	= "icmp_echo_ignore_all",
+		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_all,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
+	{
+		.procname	= "icmp_echo_ignore_broadcasts",
+		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
+	{
+		.procname	= "icmp_ignore_bogus_error_responses",
+		.data		= &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
+	{
+		.procname	= "icmp_errors_use_inbound_ifaddr",
+		.data		= &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
+	{
+		.procname	= "icmp_errors_extension_mask",
+		.data		= &init_net.ipv4.sysctl_icmp_errors_extension_mask,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= &icmp_errors_extension_mask_all,
+	},
+	{
+		.procname	= "icmp_ratelimit",
+		.data		= &init_net.ipv4.sysctl_icmp_ratelimit,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_ms_jiffies,
+	},
+	{
+		.procname	= "icmp_ratemask",
+		.data		= &init_net.ipv4.sysctl_icmp_ratemask,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec
+	},
+	{
+		.procname	= "ip_dynaddr",
+		.data		= &init_net.ipv4.sysctl_ip_dynaddr,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "ip_default_ttl",
+		.data		= &init_net.ipv4.sysctl_ip_default_ttl,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= &ip_ttl_min,
+		.extra2		= &ip_ttl_max,
+	},
+	{
+		.procname	= "ip_no_pmtu_disc",
+		.data		= &init_net.ipv4.sysctl_ip_no_pmtu_disc,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "ip_forward_use_pmtu",
+		.data		= &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "ip_forward_update_priority",
+		.data		= &init_net.ipv4.sysctl_ip_fwd_update_priority,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler   = ipv4_fwd_update_priority,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+	},
+	{
+		.procname	= "ip_nonlocal_bind",
+		.data		= &init_net.ipv4.sysctl_ip_nonlocal_bind,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "fwmark_reflect",
+		.data		= &init_net.ipv4.sysctl_fwmark_reflect,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "igmp_link_local_mcast_reports",
+		.data		= &init_net.ipv4.sysctl_igmp_llm_reports,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "igmp_max_memberships",
+		.data		= &init_net.ipv4.sysctl_igmp_max_memberships,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec
+	},
+	{
+		.procname	= "igmp_max_msf",
+		.data		= &init_net.ipv4.sysctl_igmp_max_msf,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec
+	},
+#ifdef CONFIG_IP_MULTICAST
+	{
+		.procname	= "igmp_qrv",
+		.data		= &init_net.ipv4.sysctl_igmp_qrv,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ONE
+	},
+#endif
+#ifdef CONFIG_IP_ROUTE_MULTIPATH
+	{
+		.procname	= "fib_multipath_use_neigh",
+		.data		= &init_net.ipv4.sysctl_fib_multipath_use_neigh,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+	},
+	{
+		.procname	= "fib_multipath_hash_policy",
+		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_policy,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_fib_multipath_hash_policy,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_THREE,
+	},
+	{
+		.procname	= "fib_multipath_hash_fields",
+		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_fields,
+		.maxlen		= sizeof(u32),
+		.mode		= 0644,
+		.proc_handler	= proc_fib_multipath_hash_fields,
+		.extra1		= SYSCTL_ONE,
+		.extra2		= &fib_multipath_hash_fields_all_mask,
+	},
+	{
+		.procname	= "fib_multipath_hash_seed",
+		.data		= &init_net,
+		.maxlen		= sizeof(u32),
+		.mode		= 0644,
+		.proc_handler	= proc_fib_multipath_hash_seed,
+	},
+#endif
+	{
+		.procname	= "fib_notify_on_flag_change",
+		.data		= &init_net.ipv4.sysctl_fib_notify_on_flag_change,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_TWO,
+	},
+#endif
 };
 
 static const struct ctl_table *ipv4_net_table_dup(struct net *net)
Signature · 1 line
2.55.0
#26 lore raw

PATCH v2 12/16 netfilter: ipv4: guard ip_route_me_harder() with CONFIG_IPV4

In reply to Fernando Fernandez Mancera

To enable compiling the network stack without IPv4, IPv4 specific packet rerouting logic inside netfilter must be bypassed. Therefore, guard ip_route_me_harder() with IS_ENABLED(CONFIG_IPV4) so it returns -EPROTONOSUPPORT when IPv4 is disabled.

---
 net/ipv4/netfilter.c | 3 +++
 1 file changed, 3 insertions(+)
net/ipv4/netfilter.c +3 -0
index ce9e1bfa4259..f2d9e0110b77 100644
@@ -30,6 +30,9 @@ int ip_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb, un
 	struct flow_keys flkeys;
 	unsigned int hh_len;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EPROTONOSUPPORT;
+
 	sk = sk_to_full_sk(sk);
 	flags = sk ? inet_sk_flowi_flags(sk) : 0;
 
Signature · 1 line
2.55.0
#28 lore raw

PATCH v2 13/16 net: bridge: guard ARP/RARP proxy and suppression with CONFIG_IPV4

In reply to Fernando Fernandez Mancera

Historically, the bridge subsystem relied on CONFIG_INET to guard ARP and RARP proxy and suppression routines. As CONFIG_IPV4 is decoupled from the core stack and made optional, relying on CONFIG_INET is no longer accurate, as ARP and RARP are exclusively IPv4 protocols.

---
 net/bridge/br_arp_nd_proxy.c | 2 +-
 net/bridge/br_device.c       | 2 +-
 net/bridge/br_input.c        | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
net/bridge/br_arp_nd_proxy.c +1 -1
index da15f4d7c1ae..d739b8697429 100644
@@ -39,7 +39,6 @@ void br_recalculate_neigh_suppress_enabled(struct net_bridge *br)
 	br_opt_toggle(br, BROPT_NEIGH_SUPPRESS_ENABLED, neigh_suppress);
 }
 
-#if IS_ENABLED(CONFIG_INET)
 static bool
 br_is_neigh_suppress_enabled_vid(const struct net_bridge_port *p, u16 vid)
 {
@@ -57,6 +56,7 @@ br_is_neigh_suppress_enabled_vid(const struct net_bridge_port *p, u16 vid)
 	return br_is_neigh_suppress_enabled(p, v);
 }
 
+#if IS_ENABLED(CONFIG_IPV4)
 static void br_arp_send(struct net_bridge *br, struct net_bridge_port *p,
 			struct net_device *dev, __be32 dest_ip, __be32 src_ip,
 			const unsigned char *dest_hw,
net/bridge/br_device.c +1 -1
index ce9ea9ac3d0a..a3e5a521178f 100644
@@ -69,7 +69,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
 				&state, &vlan))
 		goto out;
 
-	if (IS_ENABLED(CONFIG_INET) &&
+	if (IS_ENABLED(CONFIG_IPV4) &&
 	    (eth_hdr(skb)->h_proto == htons(ETH_P_ARP) ||
 	     eth_hdr(skb)->h_proto == htons(ETH_P_RARP)) &&
 	    br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED)) {
net/bridge/br_input.c +1 -1
index 4357d78524a6..584ac6c2215c 100644
@@ -166,7 +166,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb
 	BR_INPUT_SKB_CB(skb)->brdev = br->dev;
 	BR_INPUT_SKB_CB(skb)->src_port_isolated = test_bit(BR_ISOLATED_BIT, &p->flags);
 
-	if (IS_ENABLED(CONFIG_INET) &&
+	if (IS_ENABLED(CONFIG_IPV4) &&
 	    (skb->protocol == htons(ETH_P_ARP) ||
 	     skb->protocol == htons(ETH_P_RARP))) {
 		br_do_proxy_suppress_arp(skb, br, vid, p);
Signature · 1 line
2.55.0
#30 lore raw

PATCH v2 14/16 wifi: mac80211: replace CONFIG_INET with CONFIG_IPV4 guards

In reply to Fernando Fernandez Mancera

Historically, the mac80211 subsystem used CONFIG_INET to guard IPv4-specific address notifiers, assuming that if IP networking was enabled, IPv4 was guaranteed to be present. As part of the effort to make CONFIG_IPV4 optional, this assumption is no longer valid.

Update the conditional compilation guards around the IPv4 address change notifier and its associated registration routines to explicitly check for IS_ENABLED(CONFIG_IPV4). This ensures the mac80211 subsystem compiles successfully without undefined references when building an IPv6-only kernel.

---
 net/mac80211/main.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
net/mac80211/main.c +5 -5
index 7816395681fa..1a0fa55db861 100644
@@ -558,7 +558,7 @@ void ieee80211_restart_hw(struct ieee80211_hw *hw)
 }
 EXPORT_SYMBOL(ieee80211_restart_hw);
 
-#ifdef CONFIG_INET
+#if IS_ENABLED(CONFIG_IPV4)
 static int ieee80211_ifa_changed(struct notifier_block *nb,
 				 unsigned long data, void *arg)
 {
@@ -1655,7 +1655,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
 	wiphy_unlock(hw->wiphy);
 	rtnl_unlock();
 
-#ifdef CONFIG_INET
+#if IS_ENABLED(CONFIG_IPV4)
 	local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
 	result = register_inetaddr_notifier(&local->ifa_notifier);
 	if (result)
@@ -1673,11 +1673,11 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
 
 #if IS_ENABLED(CONFIG_IPV6)
  fail_ifa6:
-#ifdef CONFIG_INET
+#if IS_ENABLED(CONFIG_IPV4)
 	unregister_inetaddr_notifier(&local->ifa_notifier);
 #endif
 #endif
-#if defined(CONFIG_INET) || defined(CONFIG_IPV6)
+#if IS_ENABLED(CONFIG_IPV4)
  fail_ifa:
 #endif
 	wiphy_unregister(local->hw.wiphy);
@@ -1705,7 +1705,7 @@ void ieee80211_unregister_hw(struct ieee80211_hw *hw)
 	tasklet_kill(&local->tx_pending_tasklet);
 	tasklet_kill(&local->tasklet);
 
-#ifdef CONFIG_INET
+#if IS_ENABLED(CONFIG_IPV4)
 	unregister_inetaddr_notifier(&local->ifa_notifier);
 #endif
 #if IS_ENABLED(CONFIG_IPV6)
Signature · 1 line
2.55.0
#31 lore raw

PATCH v2 15/16 netlabel: cipso: introduce CONFIG_CIPSO to decouple IPv4 dependency

In reply to Fernando Fernandez Mancera

Currently, the Commercial IP Security Option (CIPSO) is unconditionally tied to CONFIG_NETLABEL. Because CIPSO is inherently an IPv4 protocol feature, this creates a transitive dependency where subsystems relying on NetLabel (such as Smack) are forced to depend on CONFIG_IPV4, even if the user only wants to utilize IPv6/CALIPSO.

This patch introduces a new CONFIG_CIPSO boolean that is automatically enabled only when both NETLABEL and IPV4 are selected. It abstracts the CIPSO-specific Makefile targets, sysctls, and kernel APIs behind this new config.

By safely stubbing out the CIPSO netlabel_kapi functions to return -ENOSYS when disabled, this allows NetLabel and Smack to be successfully built and used on IPv6-only kernels.

---
 include/net/cipso_ipv4.h         | 18 +++++++++++-------
 net/Kconfig                      |  3 ---
 net/ipv4/Makefile                |  2 +-
 net/ipv4/sysctl_net_ipv4.c       |  4 ++--
 net/netlabel/Kconfig             |  4 ++++
 net/netlabel/Makefile            |  2 +-
 net/netlabel/netlabel_cipso_v4.h |  7 +++++++
 net/netlabel/netlabel_kapi.c     |  3 +++
 security/smack/Kconfig           |  1 -
 9 files changed, 29 insertions(+), 15 deletions(-)
include/net/cipso_ipv4.h +11 -7
index d6780d7903f4..6f50a0a6951b 100644
@@ -100,7 +100,7 @@ struct cipso_v4_std_map_tbl {
  * Sysctl Variables
  */
 
-#ifdef CONFIG_NETLABEL
+#ifdef CONFIG_CIPSO
 extern int cipso_v4_cache_enabled;
 extern int cipso_v4_cache_bucketsize;
 extern int cipso_v4_rbm_optfmt;
@@ -111,7 +111,7 @@ extern int cipso_v4_rbm_strictvalid;
  * DOI List Functions
  */
 
-#ifdef CONFIG_NETLABEL
+#ifdef CONFIG_CIPSO
 int cipso_v4_doi_add(struct cipso_v4_doi *doi_def,
 		     struct netlbl_audit *audit_info);
 void cipso_v4_doi_free(struct cipso_v4_doi *doi_def);
@@ -144,19 +144,23 @@ static inline struct cipso_v4_doi *cipso_v4_doi_getdef(u32 doi)
 	return NULL;
 }
 
+static inline void cipso_v4_doi_putdef(struct cipso_v4_doi *doi_def)
+{
+}
+
 static inline int cipso_v4_doi_walk(u32 *skip_cnt,
 		     int (*callback) (struct cipso_v4_doi *doi_def, void *arg),
 		     void *cb_arg)
 {
 	return 0;
 }
-#endif /* CONFIG_NETLABEL */
+#endif /* CONFIG_CIPSO */
 
 /*
  * Label Mapping Cache Functions
  */
 
-#ifdef CONFIG_NETLABEL
+#ifdef CONFIG_CIPSO
 void cipso_v4_cache_invalidate(void);
 int cipso_v4_cache_add(const unsigned char *cipso_ptr,
 		       const struct netlbl_lsm_secattr *secattr);
@@ -171,13 +175,13 @@ static inline int cipso_v4_cache_add(const unsigned char *cipso_ptr,
 {
 	return 0;
 }
-#endif /* CONFIG_NETLABEL */
+#endif /* CONFIG_CIPSO */
 
 /*
  * Protocol Handling Functions
  */
 
-#ifdef CONFIG_NETLABEL
+#ifdef CONFIG_CIPSO
 void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway);
 int cipso_v4_getattr(const unsigned char *cipso,
 		     struct netlbl_lsm_secattr *secattr);
@@ -303,6 +307,6 @@ static inline int cipso_v4_validate(const struct sk_buff *skb,
 	return err_offset;
 
 }
-#endif /* CONFIG_NETLABEL */
+#endif /* CONFIG_CIPSO */
 
 #endif /* _CIPSO_IPV4_H */
net/Kconfig +0 -3
index ca86f20540dd..2ef4ea6ce056 100644
@@ -136,10 +136,7 @@ if INET
 source "net/ipv4/Kconfig"
 source "net/ipv6/Kconfig"
 source "net/mptcp/Kconfig"
-
-if IPV4
 source "net/netlabel/Kconfig"
-endif # if IPV4
 
 endif # if INET
 
net/ipv4/Makefile +1 -1
index 83c25f52eb58..871187937add 100644
@@ -62,7 +62,7 @@ obj-$(CONFIG_TCP_CONG_YEAH) += tcp_yeah.o
 obj-$(CONFIG_TCP_CONG_ILLINOIS) += tcp_illinois.o
 obj-$(CONFIG_NET_SOCK_MSG) += tcp_bpf.o
 obj-$(CONFIG_BPF_SYSCALL) += udp_bpf.o
-obj-$(CONFIG_NETLABEL) += cipso_ipv4.o
+obj-$(CONFIG_CIPSO) += cipso_ipv4.o
 
 obj-$(CONFIG_XFRM) += xfrm4_policy.o xfrm4_state.o xfrm4_input.o \
 		      xfrm4_output.o xfrm4_protocol.o
net/ipv4/sysctl_net_ipv4.c +2 -2
index 6096e9e4d82d..89b0caf5a9f5 100644
@@ -573,7 +573,7 @@ static struct ctl_table ipv4_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec
 	},
-#ifdef CONFIG_NETLABEL
+#ifdef CONFIG_CIPSO
 	{
 		.procname	= "cipso_cache_enable",
 		.data		= &cipso_v4_cache_enabled,
@@ -602,7 +602,7 @@ static struct ctl_table ipv4_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
 	},
-#endif /* CONFIG_NETLABEL */
+#endif /* CONFIG_CIPSO */
 	{
 		.procname	= "tcp_available_ulp",
 		.maxlen		= TCP_ULP_BUF_MAX,
net/netlabel/Kconfig +4 -0
index 4383ac29693e..bcc27196d5bd 100644
@@ -17,3 +17,7 @@ config NETLABEL
 	   * https://github.com/netlabel/netlabel_tools
 
 	  If you are unsure, say N.
+
+config CIPSO
+	def_bool y
+	depends on NETLABEL && IPV4
net/netlabel/Makefile +1 -1
index 5a46381a64e7..8afc1bf00424 100644
@@ -12,5 +12,5 @@ obj-y	+= netlabel_mgmt.o
 
 # protocol modules
 obj-y	+= netlabel_unlabeled.o
-obj-y	+= netlabel_cipso_v4.o
+obj-$(CONFIG_CIPSO) += netlabel_cipso_v4.o
 obj-$(subst m,y,$(CONFIG_IPV6)) += netlabel_calipso.o
net/netlabel/netlabel_cipso_v4.h +7 -0
index 9518ab56ec98..fb718f86bcbd 100644
@@ -147,6 +147,13 @@ enum {
 #define NLBL_CIPSOV4_A_MAX (__NLBL_CIPSOV4_A_MAX - 1)
 
 /* NetLabel protocol functions */
+#if IS_ENABLED(CONFIG_CIPSO)
 int netlbl_cipsov4_genl_init(void);
+#else
+static inline int netlbl_cipsov4_genl_init(void)
+{
+	return 0;
+}
+#endif
 
 #endif
net/netlabel/netlabel_kapi.c +3 -0
index 3583fa63dd01..c088f599b53d 100644
@@ -332,6 +332,9 @@ int netlbl_cfg_cipsov4_map_add(u32 doi,
 	struct netlbl_domaddr_map *addrmap = NULL;
 	struct netlbl_domaddr4_map *addrinfo = NULL;
 
+	if (!IS_ENABLED(CONFIG_CIPSO))
+		return -ENOSYS;
+
 	doi_def = cipso_v4_doi_getdef(doi);
 	if (doi_def == NULL)
 		return -ENOENT;
security/smack/Kconfig +0 -1
index b4e6d0168bd1..5a8dfad469c3 100644
@@ -3,7 +3,6 @@ config SECURITY_SMACK
 	bool "Simplified Mandatory Access Control Kernel Support"
 	depends on NET
 	depends on INET
-	depends on IPV4
 	depends on SECURITY
 	select NETLABEL
 	select SECURITY_NETWORK
Signature · 1 line
2.55.0
#35 lore raw

PATCH v2 16/16 ipv4: make CONFIG_IPV4 boolean

In reply to Fernando Fernandez Mancera

Change CONFIG_IPV4 from hidden 'def_bool y' into an exposed boolean. This allows users to explicitly disable IPv4 via Kconfig to build IPv6-only. The default is kept at 'INET' to prevent breaking existing configurations.

---
 net/ipv4/Kconfig | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
net/ipv4/Kconfig +9 -1
index 51bf05d9770c..c7d36cfa4a1d 100644
@@ -3,7 +3,15 @@
 # IP configuration
 #
 config IPV4
-	def_bool y
+	bool "The IPv4 protocol" if IPV6
+	default INET
+	help
+	  Support for IP version 4 (IPv4).
+
+	  Disabling this option compiles the kernel networking stack without
+	  IPv4 support, resulting in a IPv6-only system.
+
+	  If unsure, say Y.
 
 config IP_MULTICAST
 	bool "IP: multicasting"
Signature · 1 line
2.55.0
#23 lore raw

Re: [PATCH 11/16 net-next v2] ipv4: disable IPv4-only sysctls when CONFIG_IPV4=n

In reply to Fernando Fernandez Mancera
Quoted 3 lines · Fernando Fernandez Mancera

To avoid noise and unexpected problems, let's hide all the sysctls that are related to IPv4 only when the kernel is compiled without IPv4 support.

You are hiding the IPV4 sysctl with "#if IS_ENABLED(CONFIG_IPV4)" inside the sysctl_net_ipv4.c file. That is confusing as I would expect all sysctl_net_ipv4.c to be ipv4 specific. Wouldn't it be cleaner to just have an "ipv4" sysctl file and compile that when CONFIG_IPV4 is enabled?

I might be missing something obvious as I just got to see 3 patches of the series. Ignore, if this is addressed at some other point.

Best

Quoted 532 lines
---
 net/ipv4/sysctl_net_ipv4.c | 407 +++++++++++++++++++------------------
 1 file changed, 205 insertions(+), 202 deletions(-)
net/ipv4/sysctl_net_ipv4.c +205 -202
index 0e7fef5973db..6096e9e4d82d 100644
@@ -31,8 +31,8 @@ static int tcp_min_snd_mss_max = 65535;
 static int tcp_rto_max_max = TCP_RTO_MAX_SEC * MSEC_PER_SEC;
 static int ip_privileged_port_min;
 static int ip_privileged_port_max = 65535;
-static int ip_ttl_min = 1;
-static int ip_ttl_max = 255;
+static int ip_ttl_min __maybe_unused = 1;
+static int ip_ttl_max __maybe_unused = 255;
 static int tcp_syn_retries_min = 1;
 static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
 static int tcp_syn_linear_timeouts_max = MAX_TCP_SYNCNT;
@@ -48,7 +48,7 @@ static int tcp_plb_max_rounds = 31;
 static int tcp_plb_max_cong_thresh = 256;
 static unsigned int tcp_tw_reuse_delay_max = TCP_PAWS_MSL * MSEC_PER_SEC;
 static int tcp_ecn_mode_max = 5;
-static u32 icmp_errors_extension_mask_all =
+static u32 icmp_errors_extension_mask_all __maybe_unused =
 	GENMASK_U8(ICMP_ERR_EXT_COUNT - 1, 0);
 
 static int tcp_min_rcvbuf = 4096;
@@ -201,8 +201,9 @@ static int ipv4_ping_group_range(const struct ctl_table *table, int write,
 	return ret;
 }
 
-static int ipv4_fwd_update_priority(const struct ctl_table *table, int write,
-				    void *buffer, size_t *lenp, loff_t *ppos)
+static int __maybe_unused
+ipv4_fwd_update_priority(const struct ctl_table *table, int write,
+			 void *buffer, size_t *lenp, loff_t *ppos)
 {
 	struct net *net;
 	int ret;
@@ -441,9 +442,9 @@ static int proc_udp_hash_entries(const struct ctl_table *table, int write,
 }
 
 #ifdef CONFIG_IP_ROUTE_MULTIPATH
-static int proc_fib_multipath_hash_policy(const struct ctl_table *table, int write,
-					  void *buffer, size_t *lenp,
-					  loff_t *ppos)
+static int __maybe_unused
+proc_fib_multipath_hash_policy(const struct ctl_table *table, int write,
+			       void *buffer, size_t *lenp, loff_t *ppos)
 {
 	struct net *net = container_of(table->data, struct net,
 	    ipv4.sysctl_fib_multipath_hash_policy);
@@ -456,9 +457,9 @@ static int proc_fib_multipath_hash_policy(const struct ctl_table *table, int wri
 	return ret;
 }
 
-static int proc_fib_multipath_hash_fields(const struct ctl_table *table, int write,
-					  void *buffer, size_t *lenp,
-					  loff_t *ppos)
+static int __maybe_unused
+proc_fib_multipath_hash_fields(const struct ctl_table *table, int write,
+			       void *buffer, size_t *lenp, loff_t *ppos)
 {
 	struct net *net;
 	int ret;
@@ -492,9 +493,9 @@ static void proc_fib_multipath_hash_set_seed(struct net *net, u32 user_seed)
 	WRITE_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed.mp_seed, new.mp_seed);
 }
 
-static int proc_fib_multipath_hash_seed(const struct ctl_table *table, int write,
-					void *buffer, size_t *lenp,
-					loff_t *ppos)
+static int __maybe_unused
+proc_fib_multipath_hash_seed(const struct ctl_table *table, int write,
+			     void *buffer, size_t *lenp, loff_t *ppos)
 {
 	struct sysctl_fib_multipath_hash_seed *mphs;
 	struct net *net = table->data;
@@ -636,15 +637,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec
 	},
-	{
-		.procname	= "icmp_echo_ignore_all",
-		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_all,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE
-	},
 	{
 		.procname	= "icmp_echo_enable_probe",
 		.data		= &init_net.ipv4.sysctl_icmp_echo_enable_probe,
@@ -654,56 +646,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_ONE
 	},
-	{
-		.procname	= "icmp_echo_ignore_broadcasts",
-		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE
-	},
-	{
-		.procname	= "icmp_ignore_bogus_error_responses",
-		.data		= &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE
-	},
-	{
-		.procname	= "icmp_errors_use_inbound_ifaddr",
-		.data		= &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE
-	},
-	{
-		.procname	= "icmp_errors_extension_mask",
-		.data		= &init_net.ipv4.sysctl_icmp_errors_extension_mask,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= &icmp_errors_extension_mask_all,
-	},
-	{
-		.procname	= "icmp_ratelimit",
-		.data		= &init_net.ipv4.sysctl_icmp_ratelimit,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_ms_jiffies,
-	},
-	{
-		.procname	= "icmp_ratemask",
-		.data		= &init_net.ipv4.sysctl_icmp_ratemask,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec
-	},
 	{
 		.procname	= "icmp_msgs_per_sec",
 		.data		= &init_net.ipv4.sysctl_icmp_msgs_per_sec,
@@ -774,13 +716,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_ONE,
 	},
-	{
-		.procname	= "ip_dynaddr",
-		.data		= &init_net.ipv4.sysctl_ip_dynaddr,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
 	{
 		.procname	= "ip_early_demux",
 		.data		= &init_net.ipv4.sysctl_ip_early_demux,
@@ -811,15 +746,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= SYSCTL_ONE,
 	},
-	{
-		.procname	= "ip_default_ttl",
-		.data		= &init_net.ipv4.sysctl_ip_default_ttl,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= &ip_ttl_min,
-		.extra2		= &ip_ttl_max,
-	},
 	{
 		.procname	= "ip_local_port_range",
 		.maxlen		= 0,
@@ -841,36 +767,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_do_large_bitmap,
 	},
-	{
-		.procname	= "ip_no_pmtu_disc",
-		.data		= &init_net.ipv4.sysctl_ip_no_pmtu_disc,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
-	{
-		.procname	= "ip_forward_use_pmtu",
-		.data		= &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
-	{
-		.procname	= "ip_forward_update_priority",
-		.data		= &init_net.ipv4.sysctl_ip_fwd_update_priority,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler   = ipv4_fwd_update_priority,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE,
-	},
-	{
-		.procname	= "ip_nonlocal_bind",
-		.data		= &init_net.ipv4.sysctl_ip_nonlocal_bind,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
 	{
 		.procname	= "ip_autobind_reuse",
 		.data		= &init_net.ipv4.sysctl_ip_autobind_reuse,
@@ -880,13 +776,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.extra1         = SYSCTL_ZERO,
 		.extra2         = SYSCTL_ONE,
 	},
-	{
-		.procname	= "fwmark_reflect",
-		.data		= &init_net.ipv4.sysctl_fwmark_reflect,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
 	{
 		.procname	= "tcp_fwmark_accept",
 		.data		= &init_net.ipv4.sysctl_tcp_fwmark_accept,
@@ -952,37 +841,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.proc_handler	= proc_douintvec_minmax,
 		.extra2		= &u32_max_div_HZ,
 	},
-	{
-		.procname	= "igmp_link_local_mcast_reports",
-		.data		= &init_net.ipv4.sysctl_igmp_llm_reports,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
-	{
-		.procname	= "igmp_max_memberships",
-		.data		= &init_net.ipv4.sysctl_igmp_max_memberships,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec
-	},
-	{
-		.procname	= "igmp_max_msf",
-		.data		= &init_net.ipv4.sysctl_igmp_max_msf,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec
-	},
-#ifdef CONFIG_IP_MULTICAST
-	{
-		.procname	= "igmp_qrv",
-		.data		= &init_net.ipv4.sysctl_igmp_qrv,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ONE
-	},
-#endif
 	{
 		.procname	= "tcp_congestion_control",
 		.data		= &init_net.ipv4.tcp_congestion_control,
@@ -1154,42 +1012,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.proc_handler	= proc_tfo_blackhole_detect_timeout,
 		.extra1		= SYSCTL_ZERO,
 	},
-#ifdef CONFIG_IP_ROUTE_MULTIPATH
-	{
-		.procname	= "fib_multipath_use_neigh",
-		.data		= &init_net.ipv4.sysctl_fib_multipath_use_neigh,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE,
-	},
-	{
-		.procname	= "fib_multipath_hash_policy",
-		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_policy,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_fib_multipath_hash_policy,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_THREE,
-	},
-	{
-		.procname	= "fib_multipath_hash_fields",
-		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_fields,
-		.maxlen		= sizeof(u32),
-		.mode		= 0644,
-		.proc_handler	= proc_fib_multipath_hash_fields,
-		.extra1		= SYSCTL_ONE,
-		.extra2		= &fib_multipath_hash_fields_all_mask,
-	},
-	{
-		.procname	= "fib_multipath_hash_seed",
-		.data		= &init_net,
-		.maxlen		= sizeof(u32),
-		.mode		= 0644,
-		.proc_handler	= proc_fib_multipath_hash_seed,
-	},
-#endif
 	{
 		.procname	= "ip_unprivileged_port_start",
 		.maxlen		= sizeof(int),
@@ -1563,15 +1385,6 @@ static const struct ctl_table ipv4_net_table[] = {
 		.proc_handler	= proc_dointvec_minmax,
 		.extra1		= SYSCTL_ONE
 	},
-	{
-		.procname	= "fib_notify_on_flag_change",
-		.data		= &init_net.ipv4.sysctl_fib_notify_on_flag_change,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_TWO,
-	},
 	{
 		.procname       = "tcp_plb_enabled",
 		.data           = &init_net.ipv4.sysctl_tcp_plb_enabled,
@@ -1656,6 +1469,196 @@ static const struct ctl_table ipv4_net_table[] = {
 		.extra1		= SYSCTL_ONE_THOUSAND,
 		.extra2		= &tcp_rto_max_max,
 	},
+#if IS_ENABLED(CONFIG_IPV4)
+	{
+		.procname	= "icmp_echo_ignore_all",
+		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_all,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
+	{
+		.procname	= "icmp_echo_ignore_broadcasts",
+		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
+	{
+		.procname	= "icmp_ignore_bogus_error_responses",
+		.data		= &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
+	{
+		.procname	= "icmp_errors_use_inbound_ifaddr",
+		.data		= &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
+	{
+		.procname	= "icmp_errors_extension_mask",
+		.data		= &init_net.ipv4.sysctl_icmp_errors_extension_mask,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= &icmp_errors_extension_mask_all,
+	},
+	{
+		.procname	= "icmp_ratelimit",
+		.data		= &init_net.ipv4.sysctl_icmp_ratelimit,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_ms_jiffies,
+	},
+	{
+		.procname	= "icmp_ratemask",
+		.data		= &init_net.ipv4.sysctl_icmp_ratemask,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec
+	},
+	{
+		.procname	= "ip_dynaddr",
+		.data		= &init_net.ipv4.sysctl_ip_dynaddr,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "ip_default_ttl",
+		.data		= &init_net.ipv4.sysctl_ip_default_ttl,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= &ip_ttl_min,
+		.extra2		= &ip_ttl_max,
+	},
+	{
+		.procname	= "ip_no_pmtu_disc",
+		.data		= &init_net.ipv4.sysctl_ip_no_pmtu_disc,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "ip_forward_use_pmtu",
+		.data		= &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "ip_forward_update_priority",
+		.data		= &init_net.ipv4.sysctl_ip_fwd_update_priority,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler   = ipv4_fwd_update_priority,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+	},
+	{
+		.procname	= "ip_nonlocal_bind",
+		.data		= &init_net.ipv4.sysctl_ip_nonlocal_bind,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "fwmark_reflect",
+		.data		= &init_net.ipv4.sysctl_fwmark_reflect,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "igmp_link_local_mcast_reports",
+		.data		= &init_net.ipv4.sysctl_igmp_llm_reports,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "igmp_max_memberships",
+		.data		= &init_net.ipv4.sysctl_igmp_max_memberships,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec
+	},
+	{
+		.procname	= "igmp_max_msf",
+		.data		= &init_net.ipv4.sysctl_igmp_max_msf,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec
+	},
+#ifdef CONFIG_IP_MULTICAST
+	{
+		.procname	= "igmp_qrv",
+		.data		= &init_net.ipv4.sysctl_igmp_qrv,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ONE
+	},
+#endif
+#ifdef CONFIG_IP_ROUTE_MULTIPATH
+	{
+		.procname	= "fib_multipath_use_neigh",
+		.data		= &init_net.ipv4.sysctl_fib_multipath_use_neigh,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+	},
+	{
+		.procname	= "fib_multipath_hash_policy",
+		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_policy,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_fib_multipath_hash_policy,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_THREE,
+	},
+	{
+		.procname	= "fib_multipath_hash_fields",
+		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_fields,
+		.maxlen		= sizeof(u32),
+		.mode		= 0644,
+		.proc_handler	= proc_fib_multipath_hash_fields,
+		.extra1		= SYSCTL_ONE,
+		.extra2		= &fib_multipath_hash_fields_all_mask,
+	},
+	{
+		.procname	= "fib_multipath_hash_seed",
+		.data		= &init_net,
+		.maxlen		= sizeof(u32),
+		.mode		= 0644,
+		.proc_handler	= proc_fib_multipath_hash_seed,
+	},
+#endif
+	{
+		.procname	= "fib_notify_on_flag_change",
+		.data		= &init_net.ipv4.sysctl_fib_notify_on_flag_change,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_TWO,
+	},
+#endif
 };
 
 static const struct ctl_table *ipv4_net_table_dup(struct net *net)
Signature · 1 line
2.55.0
#24 lore raw

Re: [PATCH 11/16 net-next v2] ipv4: disable IPv4-only sysctls when CONFIG_IPV4=n

Quoted 5 lines · Joel Granados
Quoted 3 lines · Fernando Fernandez Mancera

To avoid noise and unexpected problems, let's hide all the sysctls that are related to IPv4 only when the kernel is compiled without IPv4 support.

Quoted 8 lines

You are hiding the IPV4 sysctl with "#if IS_ENABLED(CONFIG_IPV4)" inside the sysctl_net_ipv4.c file. That is confusing as I would expect all sysctl_net_ipv4.c to be ipv4 specific. Wouldn't it be cleaner to just have an "ipv4" sysctl file and compile that when CONFIG_IPV4 is enabled?

I might be missing something obvious as I just got to see 3 patches of the series. Ignore, if this is addressed at some other point.

Unfortunately, under net.ipv4.* sysctls there are plenty of them that are not exclusively related to IPv4. For example tcp_* or udp_* ones. These cannot be moved out of there because it would break plenty of systems. I think it is good to have them all at sysctl_net_ipv4.c and guard them with ifdefs..

Technically, nothing prevent us to split the generic ones to net/ipv4 sysctl_net.c or similar.

Thanks,
Fernando.

Quoted 534 lines

Best

Quoted 532 lines
---
  net/ipv4/sysctl_net_ipv4.c | 407 +++++++++++++++++++------------------
  1 file changed, 205 insertions(+), 202 deletions(-)
net/ipv4/sysctl_net_ipv4.c +205 -202
index 0e7fef5973db..6096e9e4d82d 100644
@@ -31,8 +31,8 @@ static int tcp_min_snd_mss_max = 65535;
  static int tcp_rto_max_max = TCP_RTO_MAX_SEC * MSEC_PER_SEC;
  static int ip_privileged_port_min;
  static int ip_privileged_port_max = 65535;
-static int ip_ttl_min = 1;
-static int ip_ttl_max = 255;
+static int ip_ttl_min __maybe_unused = 1;
+static int ip_ttl_max __maybe_unused = 255;
  static int tcp_syn_retries_min = 1;
  static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
  static int tcp_syn_linear_timeouts_max = MAX_TCP_SYNCNT;
@@ -48,7 +48,7 @@ static int tcp_plb_max_rounds = 31;
  static int tcp_plb_max_cong_thresh = 256;
  static unsigned int tcp_tw_reuse_delay_max = TCP_PAWS_MSL * MSEC_PER_SEC;
  static int tcp_ecn_mode_max = 5;
-static u32 icmp_errors_extension_mask_all =
+static u32 icmp_errors_extension_mask_all __maybe_unused =
  	GENMASK_U8(ICMP_ERR_EXT_COUNT - 1, 0);
 
  static int tcp_min_rcvbuf = 4096;
@@ -201,8 +201,9 @@ static int ipv4_ping_group_range(const struct ctl_table *table, int write,
  	return ret;
  }
 
-static int ipv4_fwd_update_priority(const struct ctl_table *table, int write,
-				    void *buffer, size_t *lenp, loff_t *ppos)
+static int __maybe_unused
+ipv4_fwd_update_priority(const struct ctl_table *table, int write,
+			 void *buffer, size_t *lenp, loff_t *ppos)
  {
  	struct net *net;
  	int ret;
@@ -441,9 +442,9 @@ static int proc_udp_hash_entries(const struct ctl_table *table, int write,
  }
 
  #ifdef CONFIG_IP_ROUTE_MULTIPATH
-static int proc_fib_multipath_hash_policy(const struct ctl_table *table, int write,
-					  void *buffer, size_t *lenp,
-					  loff_t *ppos)
+static int __maybe_unused
+proc_fib_multipath_hash_policy(const struct ctl_table *table, int write,
+			       void *buffer, size_t *lenp, loff_t *ppos)
  {
  	struct net *net = container_of(table->data, struct net,
  	    ipv4.sysctl_fib_multipath_hash_policy);
@@ -456,9 +457,9 @@ static int proc_fib_multipath_hash_policy(const struct ctl_table *table, int wri
  	return ret;
  }
 
-static int proc_fib_multipath_hash_fields(const struct ctl_table *table, int write,
-					  void *buffer, size_t *lenp,
-					  loff_t *ppos)
+static int __maybe_unused
+proc_fib_multipath_hash_fields(const struct ctl_table *table, int write,
+			       void *buffer, size_t *lenp, loff_t *ppos)
  {
  	struct net *net;
  	int ret;
@@ -492,9 +493,9 @@ static void proc_fib_multipath_hash_set_seed(struct net *net, u32 user_seed)
  	WRITE_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed.mp_seed, new.mp_seed);
  }
 
-static int proc_fib_multipath_hash_seed(const struct ctl_table *table, int write,
-					void *buffer, size_t *lenp,
-					loff_t *ppos)
+static int __maybe_unused
+proc_fib_multipath_hash_seed(const struct ctl_table *table, int write,
+			     void *buffer, size_t *lenp, loff_t *ppos)
  {
  	struct sysctl_fib_multipath_hash_seed *mphs;
  	struct net *net = table->data;
@@ -636,15 +637,6 @@ static const struct ctl_table ipv4_net_table[] = {
  		.mode		= 0644,
  		.proc_handler	= proc_dointvec
  	},
-	{
-		.procname	= "icmp_echo_ignore_all",
-		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_all,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE
-	},
  	{
  		.procname	= "icmp_echo_enable_probe",
  		.data		= &init_net.ipv4.sysctl_icmp_echo_enable_probe,
@@ -654,56 +646,6 @@ static const struct ctl_table ipv4_net_table[] = {
  		.extra1		= SYSCTL_ZERO,
  		.extra2		= SYSCTL_ONE
  	},
-	{
-		.procname	= "icmp_echo_ignore_broadcasts",
-		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE
-	},
-	{
-		.procname	= "icmp_ignore_bogus_error_responses",
-		.data		= &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE
-	},
-	{
-		.procname	= "icmp_errors_use_inbound_ifaddr",
-		.data		= &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE
-	},
-	{
-		.procname	= "icmp_errors_extension_mask",
-		.data		= &init_net.ipv4.sysctl_icmp_errors_extension_mask,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= &icmp_errors_extension_mask_all,
-	},
-	{
-		.procname	= "icmp_ratelimit",
-		.data		= &init_net.ipv4.sysctl_icmp_ratelimit,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_ms_jiffies,
-	},
-	{
-		.procname	= "icmp_ratemask",
-		.data		= &init_net.ipv4.sysctl_icmp_ratemask,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec
-	},
  	{
  		.procname	= "icmp_msgs_per_sec",
  		.data		= &init_net.ipv4.sysctl_icmp_msgs_per_sec,
@@ -774,13 +716,6 @@ static const struct ctl_table ipv4_net_table[] = {
  		.extra1		= SYSCTL_ZERO,
  		.extra2		= SYSCTL_ONE,
  	},
-	{
-		.procname	= "ip_dynaddr",
-		.data		= &init_net.ipv4.sysctl_ip_dynaddr,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
  	{
  		.procname	= "ip_early_demux",
  		.data		= &init_net.ipv4.sysctl_ip_early_demux,
@@ -811,15 +746,6 @@ static const struct ctl_table ipv4_net_table[] = {
  		.extra1		= SYSCTL_ZERO,
  		.extra2		= SYSCTL_ONE,
  	},
-	{
-		.procname	= "ip_default_ttl",
-		.data		= &init_net.ipv4.sysctl_ip_default_ttl,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= &ip_ttl_min,
-		.extra2		= &ip_ttl_max,
-	},
  	{
  		.procname	= "ip_local_port_range",
  		.maxlen		= 0,
@@ -841,36 +767,6 @@ static const struct ctl_table ipv4_net_table[] = {
  		.mode		= 0644,
  		.proc_handler	= proc_do_large_bitmap,
  	},
-	{
-		.procname	= "ip_no_pmtu_disc",
-		.data		= &init_net.ipv4.sysctl_ip_no_pmtu_disc,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
-	{
-		.procname	= "ip_forward_use_pmtu",
-		.data		= &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
-	{
-		.procname	= "ip_forward_update_priority",
-		.data		= &init_net.ipv4.sysctl_ip_fwd_update_priority,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler   = ipv4_fwd_update_priority,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE,
-	},
-	{
-		.procname	= "ip_nonlocal_bind",
-		.data		= &init_net.ipv4.sysctl_ip_nonlocal_bind,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
  	{
  		.procname	= "ip_autobind_reuse",
  		.data		= &init_net.ipv4.sysctl_ip_autobind_reuse,
@@ -880,13 +776,6 @@ static const struct ctl_table ipv4_net_table[] = {
  		.extra1         = SYSCTL_ZERO,
  		.extra2         = SYSCTL_ONE,
  	},
-	{
-		.procname	= "fwmark_reflect",
-		.data		= &init_net.ipv4.sysctl_fwmark_reflect,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
  	{
  		.procname	= "tcp_fwmark_accept",
  		.data		= &init_net.ipv4.sysctl_tcp_fwmark_accept,
@@ -952,37 +841,6 @@ static const struct ctl_table ipv4_net_table[] = {
  		.proc_handler	= proc_douintvec_minmax,
  		.extra2		= &u32_max_div_HZ,
  	},
-	{
-		.procname	= "igmp_link_local_mcast_reports",
-		.data		= &init_net.ipv4.sysctl_igmp_llm_reports,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-	},
-	{
-		.procname	= "igmp_max_memberships",
-		.data		= &init_net.ipv4.sysctl_igmp_max_memberships,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec
-	},
-	{
-		.procname	= "igmp_max_msf",
-		.data		= &init_net.ipv4.sysctl_igmp_max_msf,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec
-	},
-#ifdef CONFIG_IP_MULTICAST
-	{
-		.procname	= "igmp_qrv",
-		.data		= &init_net.ipv4.sysctl_igmp_qrv,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ONE
-	},
-#endif
  	{
  		.procname	= "tcp_congestion_control",
  		.data		= &init_net.ipv4.tcp_congestion_control,
@@ -1154,42 +1012,6 @@ static const struct ctl_table ipv4_net_table[] = {
  		.proc_handler	= proc_tfo_blackhole_detect_timeout,
  		.extra1		= SYSCTL_ZERO,
  	},
-#ifdef CONFIG_IP_ROUTE_MULTIPATH
-	{
-		.procname	= "fib_multipath_use_neigh",
-		.data		= &init_net.ipv4.sysctl_fib_multipath_use_neigh,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE,
-	},
-	{
-		.procname	= "fib_multipath_hash_policy",
-		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_policy,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_fib_multipath_hash_policy,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_THREE,
-	},
-	{
-		.procname	= "fib_multipath_hash_fields",
-		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_fields,
-		.maxlen		= sizeof(u32),
-		.mode		= 0644,
-		.proc_handler	= proc_fib_multipath_hash_fields,
-		.extra1		= SYSCTL_ONE,
-		.extra2		= &fib_multipath_hash_fields_all_mask,
-	},
-	{
-		.procname	= "fib_multipath_hash_seed",
-		.data		= &init_net,
-		.maxlen		= sizeof(u32),
-		.mode		= 0644,
-		.proc_handler	= proc_fib_multipath_hash_seed,
-	},
-#endif
  	{
  		.procname	= "ip_unprivileged_port_start",
  		.maxlen		= sizeof(int),
@@ -1563,15 +1385,6 @@ static const struct ctl_table ipv4_net_table[] = {
  		.proc_handler	= proc_dointvec_minmax,
  		.extra1		= SYSCTL_ONE
  	},
-	{
-		.procname	= "fib_notify_on_flag_change",
-		.data		= &init_net.ipv4.sysctl_fib_notify_on_flag_change,
-		.maxlen		= sizeof(u8),
-		.mode		= 0644,
-		.proc_handler	= proc_dou8vec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_TWO,
-	},
  	{
  		.procname       = "tcp_plb_enabled",
  		.data           = &init_net.ipv4.sysctl_tcp_plb_enabled,
@@ -1656,6 +1469,196 @@ static const struct ctl_table ipv4_net_table[] = {
  		.extra1		= SYSCTL_ONE_THOUSAND,
  		.extra2		= &tcp_rto_max_max,
  	},
+#if IS_ENABLED(CONFIG_IPV4)
+	{
+		.procname	= "icmp_echo_ignore_all",
+		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_all,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
+	{
+		.procname	= "icmp_echo_ignore_broadcasts",
+		.data		= &init_net.ipv4.sysctl_icmp_echo_ignore_broadcasts,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
+	{
+		.procname	= "icmp_ignore_bogus_error_responses",
+		.data		= &init_net.ipv4.sysctl_icmp_ignore_bogus_error_responses,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
+	{
+		.procname	= "icmp_errors_use_inbound_ifaddr",
+		.data		= &init_net.ipv4.sysctl_icmp_errors_use_inbound_ifaddr,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE
+	},
+	{
+		.procname	= "icmp_errors_extension_mask",
+		.data		= &init_net.ipv4.sysctl_icmp_errors_extension_mask,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= &icmp_errors_extension_mask_all,
+	},
+	{
+		.procname	= "icmp_ratelimit",
+		.data		= &init_net.ipv4.sysctl_icmp_ratelimit,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_ms_jiffies,
+	},
+	{
+		.procname	= "icmp_ratemask",
+		.data		= &init_net.ipv4.sysctl_icmp_ratemask,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec
+	},
+	{
+		.procname	= "ip_dynaddr",
+		.data		= &init_net.ipv4.sysctl_ip_dynaddr,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "ip_default_ttl",
+		.data		= &init_net.ipv4.sysctl_ip_default_ttl,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= &ip_ttl_min,
+		.extra2		= &ip_ttl_max,
+	},
+	{
+		.procname	= "ip_no_pmtu_disc",
+		.data		= &init_net.ipv4.sysctl_ip_no_pmtu_disc,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "ip_forward_use_pmtu",
+		.data		= &init_net.ipv4.sysctl_ip_fwd_use_pmtu,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "ip_forward_update_priority",
+		.data		= &init_net.ipv4.sysctl_ip_fwd_update_priority,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler   = ipv4_fwd_update_priority,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+	},
+	{
+		.procname	= "ip_nonlocal_bind",
+		.data		= &init_net.ipv4.sysctl_ip_nonlocal_bind,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "fwmark_reflect",
+		.data		= &init_net.ipv4.sysctl_fwmark_reflect,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "igmp_link_local_mcast_reports",
+		.data		= &init_net.ipv4.sysctl_igmp_llm_reports,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+	},
+	{
+		.procname	= "igmp_max_memberships",
+		.data		= &init_net.ipv4.sysctl_igmp_max_memberships,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec
+	},
+	{
+		.procname	= "igmp_max_msf",
+		.data		= &init_net.ipv4.sysctl_igmp_max_msf,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec
+	},
+#ifdef CONFIG_IP_MULTICAST
+	{
+		.procname	= "igmp_qrv",
+		.data		= &init_net.ipv4.sysctl_igmp_qrv,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ONE
+	},
+#endif
+#ifdef CONFIG_IP_ROUTE_MULTIPATH
+	{
+		.procname	= "fib_multipath_use_neigh",
+		.data		= &init_net.ipv4.sysctl_fib_multipath_use_neigh,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_ONE,
+	},
+	{
+		.procname	= "fib_multipath_hash_policy",
+		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_policy,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_fib_multipath_hash_policy,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_THREE,
+	},
+	{
+		.procname	= "fib_multipath_hash_fields",
+		.data		= &init_net.ipv4.sysctl_fib_multipath_hash_fields,
+		.maxlen		= sizeof(u32),
+		.mode		= 0644,
+		.proc_handler	= proc_fib_multipath_hash_fields,
+		.extra1		= SYSCTL_ONE,
+		.extra2		= &fib_multipath_hash_fields_all_mask,
+	},
+	{
+		.procname	= "fib_multipath_hash_seed",
+		.data		= &init_net,
+		.maxlen		= sizeof(u32),
+		.mode		= 0644,
+		.proc_handler	= proc_fib_multipath_hash_seed,
+	},
+#endif
+	{
+		.procname	= "fib_notify_on_flag_change",
+		.data		= &init_net.ipv4.sysctl_fib_notify_on_flag_change,
+		.maxlen		= sizeof(u8),
+		.mode		= 0644,
+		.proc_handler	= proc_dou8vec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= SYSCTL_TWO,
+	},
+#endif
  };
 
  static const struct ctl_table *ipv4_net_table_dup(struct net *net)
Signature · 1 line
2.55.0
#2 lore raw

Re: [PATCH 01/16 net-next v2] ipv4: introduce CONFIG_IPV4 to decouple the IPv4 stack

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] kconfig: core dual-stack and IPv6 features are forcibly disabled without IPv4 --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] kconfig: core dual-stack and IPv6 features are forcibly disabled without IPv4 --

commit e9e0ffe00541dede8370017851b597f6f3e1cfa2
Author: Fernando Fernandez Mancera <[email protected]>

ipv4: introduce CONFIG_IPV4 to decouple the IPv4 stack

This commit introduces the CONFIG_IPV4 symbol to decouple the IPv4 stack, currently defaulting it to yes. It adjusts multiple networking subsystems across tunnels, drivers, and filesystems to depend on this new IPv4 configuration symbol.

Quoted 4 lines
net/Kconfig +0 -0
index 76ab44aa439a6..ca86f20540dd1 100644

[ ... ]

net/Kconfig config BRIDGE_NETFILTER · line 239

Quoted 6 lines
net/Kconfig +1 -0
@@ -232,6 +235,7 @@ config BRIDGE_NETFILTER
 	depends on BRIDGE
 	depends on NETFILTER && INET
 	depends on NETFILTER_ADVANCED
+	depends on IPV4
 	select NETFILTER_FAMILY_BRIDGE

[Severity: High]
Does adding this dependency force bridge netfilter to be unavailable on kernels without IPv4?

Bridge netfilter handles both IPv4 and IPv6 bridged traffic. Tying it exclusively to CONFIG_IPV4 under config BRIDGE_NETFILTER might prevent filtering IPv6 traffic on an IPv6-only kernel.

[ ... ]

Quoted 4 lines
net/ipv6/Kconfig +0 -0
index c3806c6ac96f9..f83efc1505cc4 100644

[ ... ]

net/ipv6/Kconfig config IPV6_SUBTREES · line 269

Quoted 7 lines
net/ipv6/Kconfig +1 -1
@@ -256,7 +265,7 @@ config IPV6_SUBTREES
 
 config IPV6_MROUTE
 	bool "IPv6: multicast routing"
-	depends on IPV6
+	depends on IPV4 && IPV6
 	select IP_MROUTE_COMMON

[Severity: High]
Does this change break IPv6 multicast routing when CONFIG_IPV4 is disabled?

IPv6 multicast routing under config IPV6_MROUTE does not inherently require IPv4. Adding this dependency disables purely IPv6 functionality on an IPv6-only kernel.

[ ... ]

net/xfrm/Kconfig line 8

Quoted 11 lines
net/xfrm/Kconfig +1 -1
index 4a62817a88f8f..203188b05be40 100644
@@ -4,7 +4,7 @@
 #
 config XFRM
 	bool
-	depends on INET
+	depends on INET && IPV4
 	select GRO_CELLS

[Severity: High]
Will adding this dependency disable the global IPsec subsystem for IPv6-only kernels?

Tying config XFRM entirely to CONFIG_IPV4 restricts dual-stack infrastructure, making it impossible to use IPsec with IPv6 if IPv4 is disabled.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#13 lore raw

Re: [PATCH 06/16 net-next v2] ipv4: udp: split IPv4 specific logic into udp_ipv4.c

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] net: IPv4 BIG TCP UDP support broken by length extraction truncation in udp_rcv() --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: IPv4 BIG TCP UDP support broken by length extraction truncation in udp_rcv() --

commit 348e86f71529a8963fd2bec33bd3ebd366457c18
Author: Fernando Fernandez Mancera <[email protected]>

ipv4: udp: split IPv4 specific logic into udp_ipv4.c

This commit moves IPv4-specific UDP socket functions from the generic UDP infrastructure into a new file, udp_ipv4.c. This change enables compiling the INET subsystem without IPv4 support.

Quoted 4 lines
net/ipv4/udp_ipv4.c new file +0 -0
new file mode 100644

[ ... ]

Quoted 10 lines
net/ipv4/udp_ipv4.c new file +10 -0
+int udp_rcv(struct sk_buff *skb)
+{
+	struct rtable *rt = skb_rtable(skb);
+	struct net *net = dev_net(skb->dev);
+	struct sock *sk = NULL;
+	unsigned short ulen;
+	__be32 saddr, daddr;
+	struct udphdr *uh;
+	bool refcounted;
+	int drop_reason;

[ ... ]

net/ipv4/udp_ipv4.c line 1178

Quoted 10 lines
net/ipv4/udp_ipv4.c new file +10 -0
+	uh   = udp_hdr(skb);
+	ulen = ntohs(uh->len);
+	saddr = ip_hdr(skb)->saddr;
+	daddr = ip_hdr(skb)->daddr;
+
+	if (ulen > skb->len)
+		goto short_packet;
+
+	if (ulen < sizeof(*uh))
+		goto short_packet;

[Severity: High]
Does this change in udp_rcv() break support for IPv4 BIG TCP UDP packets?

By replacing the robust udp_get_len() helper with a direct ntohs(uh->len) call and downgrading ulen to a 16-bit unsigned short, ulen evaluates to 0 for BIG TCP packets (which intentionally have uh->len set to 0).

Because ulen evaluates to 0, the subsequent bounds check (ulen < sizeof(*uh)) will evaluate as true (0 < 8), causing valid BIG TCP packets to jump to the short_packet label and be incorrectly dropped with SKB_DROP_REASON_PKT_TOO_SMALL.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#32 lore raw

Re: [PATCH 15/16 net-next v2] netlabel: cipso: introduce CONFIG_CIPSO to decouple IPv4 dependency

In reply to Fernando Fernandez Mancera
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

Currently, the Commercial IP Security Option (CIPSO) is unconditionally tied to CONFIG_NETLABEL. Because CIPSO is inherently an IPv4 protocol feature, this creates a transitive dependency where subsystems relying on NetLabel (such as Smack) are forced to depend on CONFIG_IPV4, even if the user only wants to utilize IPv6/CALIPSO.

This patch introduces a new CONFIG_CIPSO boolean that is automatically enabled only when both NETLABEL and IPV4 are selected. It abstracts the CIPSO-specific Makefile targets, sysctls, and kernel APIs behind this new config.

Quoted 5 lines

By safely stubbing out the CIPSO netlabel_kapi functions to return -ENOSYS when disabled, this allows NetLabel and Smack to be successfully built and used on IPv6-only kernels.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
#14 lore raw

Re: [PATCH 06/16 net-next v2] ipv4: udp: split IPv4 specific logic into udp_ipv4.c

In reply to [email protected]
Quoted 43 lines · On 9/29/26 9:32 PM, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] net: IPv4 BIG TCP UDP support broken by length extraction truncation in udp_rcv() --

commit 348e86f71529a8963fd2bec33bd3ebd366457c18
Author: Fernando Fernandez Mancera <[email protected]>

ipv4: udp: split IPv4 specific logic into udp_ipv4.c

This commit moves IPv4-specific UDP socket functions from the generic UDP infrastructure into a new file, udp_ipv4.c. This change enables compiling the INET subsystem without IPv4 support.

Quoted 4 lines
net/ipv4/udp_ipv4.c new file +0 -0
new file mode 100644

[ ... ]

Quoted 10 lines
net/ipv4/udp_ipv4.c new file +10 -0
+int udp_rcv(struct sk_buff *skb)
+{
+	struct rtable *rt = skb_rtable(skb);
+	struct net *net = dev_net(skb->dev);
+	struct sock *sk = NULL;
+	unsigned short ulen;
+	__be32 saddr, daddr;
+	struct udphdr *uh;
+	bool refcounted;
+	int drop_reason;

[ ... ]

net/ipv4/udp_ipv4.c line 1178

Quoted 10 lines
net/ipv4/udp_ipv4.c new file +10 -0
+	uh   = udp_hdr(skb);
+	ulen = ntohs(uh->len);
+	saddr = ip_hdr(skb)->saddr;
+	daddr = ip_hdr(skb)->daddr;
+
+	if (ulen > skb->len)
+		goto short_packet;
+
+	if (ulen < sizeof(*uh))
+		goto short_packet;

[Severity: High]
Does this change in udp_rcv() break support for IPv4 BIG TCP UDP packets?

Quoted 8 lines

By replacing the robust udp_get_len() helper with a direct ntohs(uh->len) call and downgrading ulen to a 16-bit unsigned short, ulen evaluates to 0 for BIG TCP packets (which intentionally have uh->len set to 0).

Because ulen evaluates to 0, the subsequent bounds check (ulen < sizeof(*uh)) will evaluate as true (0 < 8), causing valid BIG TCP packets to jump to the short_packet label and be incorrectly dropped with SKB_DROP_REASON_PKT_TOO_SMALL.

This one is real I messed up when rebasing and resolving conflicts with:

efbc1aa8ed54d1f48d2855f8cff0017429531331

Will fix it on v3.

Thanks!

Quoted 1 line
maintainer Acked-by on v2 15/16
#33 lore raw

Re: [PATCH 15/16 net-next v2] netlabel: cipso: introduce CONFIG_CIPSO to decouple IPv4 dependency

In reply to Fernando Fernandez Mancera
Quoted 17 lines · Fernando Fernandez Mancera

Currently, the Commercial IP Security Option (CIPSO) is unconditionally tied to CONFIG_NETLABEL. Because CIPSO is inherently an IPv4 protocol feature, this creates a transitive dependency where subsystems relying on NetLabel (such as Smack) are forced to depend on CONFIG_IPV4, even if the user only wants to utilize IPv6/CALIPSO.

This patch introduces a new CONFIG_CIPSO boolean that is automatically enabled only when both NETLABEL and IPV4 are selected. It abstracts the CIPSO-specific Makefile targets, sysctls, and kernel APIs behind this new config.

By safely stubbing out the CIPSO netlabel_kapi functions to return -ENOSYS when disabled, this allows NetLabel and Smack to be successfully built and used on IPv6-only kernels.

Quoted 11 lines
---
 include/net/cipso_ipv4.h         | 18 +++++++++++-------
 net/Kconfig                      |  3 ---
 net/ipv4/Makefile                |  2 +-
 net/ipv4/sysctl_net_ipv4.c       |  4 ++--
 net/netlabel/Kconfig             |  4 ++++
 net/netlabel/Makefile            |  2 +-
 net/netlabel/netlabel_cipso_v4.h |  7 +++++++
 net/netlabel/netlabel_kapi.c     |  3 +++
 security/smack/Kconfig           |  1 -
 9 files changed, 29 insertions(+), 15 deletions(-)
Signature · 1 line
paul-moore.com
#3 lore raw

Re: [PATCH 01/16 net-next v2] ipv4: introduce CONFIG_IPV4 to decouple the IPv4 stack

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The patch moves route.o, arp.o, icmp and the other IPv4-only objects under obj-$(CONFIG_IPV4) and adds depends on IPV4 / `depends…

--

ipv4: introduce CONFIG_IPV4 to decouple the IPv4 stack

This commit adds a CONFIG_IPV4 symbol, which is def_bool y for now. It moves the IPv4-only objects in net/ipv4/Makefile under obj-$(CONFIG_IPV4). It also adds IPV4 (or IPV4 || !INET) dependencies to a number of drivers, filesystems and networking features that use those symbols.

Quoted 20 lines
net/ipv4/Makefile +2 -9
index 06e21c26b76f..8b148be79fa4 100644
@@ -3,18 +3,17 @@
 # Makefile for the Linux TCP/IP (INET) layer.
 #
 
-obj-y     := route.o inetpeer.o protocol.o \
-	     ip_input.o ip_fragment.o ip_forward.o ip_options.o \
-	     ip_output.o ip_sockglue.o inet_hashtables.o \
-	     inet_timewait_sock.o inet_connection_sock.o \
-	     tcp.o tcp_input.o tcp_output.o tcp_timer.o tcp_ipv4.o \
+obj-y     := inetpeer.o protocol.o inet_hashtables.o inet_timewait_sock.o \
+	     inet_connection_sock.o tcp.o tcp_input.o tcp_output.o tcp_timer.o \
 	     tcp_minisocks.o tcp_cong.o tcp_metrics.o tcp_fastopen.o \
-	     tcp_recovery.o tcp_ulp.o \
-	     tcp_offload.o tcp_plb.o datagram.o raw.o udp.o \
-	     udp_offload.o arp.o icmp.o devinet.o af_inet.o igmp.o \
-	     fib_frontend.o fib_semantics.o fib_trie.o fib_notifier.o \

net/ipv4/Makefile line 16

Quoted 10 lines
net/ipv4/Makefile +8 -2
-	     inet_fragment.o ping.o ip_tunnel_core.o gre_offload.o \
-	     metrics.o netlink.o nexthop.o udp_tunnel_stub.o
+	     tcp_recovery.o tcp_ulp.o tcp_offload.o tcp_plb.o raw.o udp.o \
+	     udp_offload.o af_inet.o inet_fragment.o ping.o ip_tunnel_core.o \
+	     gre_offload.o metrics.o netlink.o nexthop.o udp_tunnel_stub.o
+
+obj-$(CONFIG_IPV4) += route.o ip_input.o ip_fragment.o ip_forward.o ip_options.o \
+		      ip_sockglue.o tcp_ipv4.o datagram.o icmp.o arp.o devinet.o \
+		      igmp.o fib_notifier.o ip_output.o fib_frontend.o \
+		      fib_semantics.o fib_trie.o

[Severity: Low]
Is SUNVNET_COMMON missing from the list of consumers that gained an IPV4 dependency? Its Kconfig entry is unchanged:

drivers/net/ethernet/sun/Kconfig:
config SUNVNET_COMMON
tristate "Common routines to support Sun Virtual Networking" depends on SUN_LDOMS
depends on INET
default m

vnet_start_xmit() in drivers/net/ethernet/sun/sunvnet_common.c calls icmp_ndo_send(). The only guard is a runtime protocol check:

	if (skb->protocol == htons(ETH_P_IP))
		icmp_ndo_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
			      htonl(localmtu));

include/net/icmp.h has no !CONFIG_IPV4 stub for icmp_ndo_send() or __icmp_send(). The "Core Netfilter Configuration" menu now depends on IPV4, so NF_NAT is n when IPV4=n. In that case icmp_ndo_send() is the inline wrapper that calls __icmp_send() directly.

With IPV4 set to def_bool y, this can't happen yet. After the later "ipv4: make CONFIG_IPV4 boolean" change, __icmp_send() is defined only in net/ipv4/icmp_ipv4.c, and that file is built only through obj-$(CONFIG_IPV4).

Consider a sparc64 config with SUN_LDOMS=y, INET=y, IPV6=y and IPV4=n. SUNVNET_COMMON defaults to m there. Would that config fail at modpost with an undefined __icmp_send?

Nothing later in the series seems to add an IPV4 dependency to SUNVNET_COMMON, or a guard or stub for icmp_ndo_send(). Would a "depends on IPV4 || !INET" line, like the one used for sfc, stmmac and mlxsw, be appropriate here?

Other drivers with a similar pattern, such as bnxt, nfp and cnic, look fine at the end of the series. They reach ip_route_output_flow(), and "net: core: add IPv4 fallback stubs and guards for CONFIG_IPV4=n" stubs that function in include/net/route.h to return ERR_PTR(-EAFNOSUPPORT).

Quoted 3 lines
net/ipv4/Makefile +0 -0
 obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o
 obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de
#5 lore raw

Re: [PATCH 02/16 net-next v2] net: core: add IPv4 fallback stubs and guards for CONFIG_IPV4=n

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 6

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] dev_ifconf() in net/core/dev_ioctl.c now starts with if (!IS_ENABLED(CONFIG_IPV4)) return -EAFNOSUPPORT;.
- [Low] The CONFIG_IPV4=n stub of ip_finish_skb() in include/net/ip.h returns ERR_PTR(-EAFNOSUPPORT).
- [Low] The concern was that this patch moves declarations of ip_send_skb, ip_push_pending_frames, ip_generic_getfrag and…
- [Low] The concern was that __inet_check_established() gets a CONFIG_IPV4 guard to avoid referencing tcp_twsk_unique() (then in…
- [Low] The new CONFIG_IPV4=n stub of ip_route_output_flow() in include/net/route.h is a function definition whose first parameter has…
- [Low] INDIRECT_CALL_INET_1() in include/linux/indirect_call_wrapper.h is now gated on CONFIG_IPV4 instead of CONFIG_INET, but none of its…
- [Low] include/net/arp.h still picks the real __ipv4_neigh_lookup_noref() body under #ifdef CONFIG_INET, not…

--

net: core: add IPv4 fallback stubs and guards for CONFIG_IPV4=n

This patch adds static inline stubs to include/net/ip.h and include/net/route.h that return an error when IPv4 is disabled. It also switches several CONFIG_INET guards in generic networking code to CONFIG_IPV4, to avoid undefined references when linking without IPv4.

Quoted 5 lines
include/linux/indirect_call_wrapper.h +0 -0
index 0e4340ecd857..583efbc03446 100644
@@ -57,16 +57,18 @@

[ ... ]

include/linux/indirect_call_wrapper.h line 74

Quoted 5 lines
include/linux/indirect_call_wrapper.h +1 -1
-#if IS_ENABLED(CONFIG_INET)
+#if IS_ENABLED(CONFIG_IPV4)
 #define INDIRECT_CALL_INET_1(f, f1, ...) INDIRECT_CALL_1(f, f1, __VA_ARGS__)
 #else
 #define INDIRECT_CALL_INET_1(f, f1, ...) f(__VA_ARGS__)

[Severity: Low]
Is CONFIG_IPV4 the right gate for INDIRECT_CALL_INET_1()? Its four users all name TCP helpers that tcp_prot and tcpv6_prot share:

tcp_stream_memory_free in __sk_stream_memory_free() tcp_leave_memory_pressure in net/core/sock.c tcp_release_cb in release_sock() tcp_bpf_bypass_getsockopt in include/linux/bpf-cgroup.h

These live in net/ipv4/tcp.c and net/ipv4/tcp_output.c. Both are obj-y and are built whenever CONFIG_INET=y.

On an INET=y, IPV4=n kernel, callbacks such as release_sock()->release_cb would lose the direct call and go through a retpoline. Would keeping CONFIG_INET here avoid that?

Quoted 4 lines
include/net/ip.h +0 -0
index 6f602df72ee6..194a464c443a 100644

[ ... ]

Quoted 1 line
include/net/ip.h +0 -0
@@ -225,27 +235,58 @@ int ip_append_data(struct sock *sk, struct flowi4 *fl4,

[ ... ]

include/net/ip.h int ip_append_data(struct sock *sk, struct flowi4 *fl4, · line 278

Quoted 4 lines
include/net/ip.h +4 -0
+static inline struct sk_buff *ip_finish_skb(struct sock *sk, struct flowi4 *fl4)
+{
+	return ERR_PTR(-EAFNOSUPPORT);
+}

[Severity: Low]
Should this stub return NULL instead of an ERR_PTR?

The real ip_finish_skb() wraps __ip_make_skb(), which returns either NULL or a valid skb. Callers such as udp_push_pending_frames() only check for NULL:

    skb = ip_finish_skb(sk, fl4);
    if (!skb)
        goto out;

A future caller that reached this stub would go on to dereference the ERR_PTR in udp_send_skb() or ip_send_skb().

No current caller can reach it. At this patch the #else branch is only compiled for INET=n. By the end of the series the callers are all in obj-$(CONFIG_IPV4) files, and udp_v6_push_pending_frames() guards its call with IS_ENABLED(CONFIG_IPV4).

include/net/ip.h int ip_append_data(struct sock *sk, struct flowi4 *fl4, · line 289

Quoted 11 lines
include/net/ip.h +11 -0
+
+static inline void ip_flush_pending_frames(struct sock *sk)
+{
+}
+#endif
+
+int ip_generic_getfrag(void *from, char *to, int offset, int len, int odd,
+		       struct sk_buff *skb);
+int ip_send_skb(struct net *net, struct sk_buff *skb);
+int ip_push_pending_frames(struct sock *sk, struct flowi4 *fl4);
+int ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl);

[Severity: Low]
Are these meant to be left outside the CONFIG_IPV4 block without stubs? The __cookie_v4_* references in net/core/filter.c are also left unguarded. On their own, these would stop an IPV4=n kernel from linking.

Later patches in the series seem to handle all of them:

- "net: inet: relocate ip_generic_getfrag and guard IPv4 socket logic" moves ip_generic_getfrag() into net/ipv4/af_inet.c.

- The raw/udp/icmp/ping split patches move the ip_send_skb() and

    ip_push_pending_frames() callers into obj-$(CONFIG_IPV4) *_ipv4.c
    files.

- ip_queue_xmit is only referenced through INDIRECT_CALL_INET, which drops f1 when IPV4=n. The ipv6_mapped use in tcp_ipv6.c is only reachable from IS_ENABLED(CONFIG_IPV4) code.

- The __cookie_v4_* calls sit under CONFIG_SYN_COOKIES, which depends on IPV4.

So only the intermediate state of the series is affected, not the end state.

[ ... ]

Quoted 8 lines
include/net/route.h +0 -0
index 6b55de2e4df8..8c21881eb5f4 100644
@@ -169,8 +169,16 @@ static inline struct rtable *__ip_route_output_key(struct net *net,
 	return ip_route_output_key_hash(net, flp, NULL);
 }
 

include/net/route.h static inline struct rtable *__ip_route_output_key(struct net *net, · line 181

Quoted 10 lines
include/net/route.h +8 -0
+#if IS_ENABLED(CONFIG_IPV4)
 struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,
 				    const struct sock *sk);
+#else
+static inline struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp,
+						  const struct sock *sk)
+{
+	return ERR_PTR(-EAFNOSUPPORT);
+}
+#endif

[Severity: Low]
The first parameter of this definition has no name. Before C23, parameter names may only be omitted in prototypes. Under -std=gnu11, GCC 8 through 10 reject this with "parameter name omitted", and scripts/min-tool-version.sh lists 8.1 as the minimum GCC.

CONFIG_IPV4 is undefined on existing CONFIG_NET=y, CONFIG_INET=n kernels. That means this #else branch is compiled today wherever route.h is included, including the always-built net/core/rtnetlink.c.

Does this break those builds with older GCC? Naming the parameter (struct net *net) would avoid that.

net/core/dev_ioctl.c int dev_ifconf(struct net *net, struct ifconf __user *uifc) · line 49

Quoted 11 lines
net/core/dev_ioctl.c +3 -0
index 164643140a52..a10921aa3e23 100644
@@ -44,6 +44,9 @@ int dev_ifconf(struct net *net, struct ifconf __user *uifc)
 	size_t size;
 	int len, total = 0, done;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EAFNOSUPPORT;
+

[Severity: Medium]
Does this change how SIOCGIFCONF behaves on existing CONFIG_INET=n kernels? CONFIG_IPV4 is only defined inside "if INET" in net/Kconfig, so IS_ENABLED(CONFIG_IPV4) is 0 whenever INET=n.

sock_ioctl() passes SIOCGIFCONF to dev_ifconf() for sockets of every family:

    case SIOCGIFCONF:
        err = dev_ifconf(net, argp);

Before this patch, the !CONFIG_INET inet_gifconf() stub in include/linux/inetdevice.h returned 0, so the ioctl succeeded with ifc_len set to 0. It now fails with EAFNOSUPPORT. That also applies to AF_UNIX, AF_PACKET and other non-INET sockets, from unprivileged userspace.

The inline stub already existed, so there was no link error to avoid. Would changing the inet_gifconf() stub's guard from CONFIG_INET to CONFIG_IPV4 keep the empty-list result for the IPV4=n case as well?

The commit message also doesn't mention this user-visible change.

[ ... ]

net/core/neighbour.c int neigh_xmit(int index, struct net_device *dev, · line 3248

Quoted 13 lines
net/core/neighbour.c +4 -0
index 6ed8eb075146..63c2a1b86118 100644
@@ -3241,6 +3241,10 @@ int neigh_xmit(int index, struct net_device *dev,
 		if (index == NEIGH_ARP_TABLE) {
 			u32 key = *((u32 *)addr);
 
+			if (!IS_ENABLED(CONFIG_IPV4)) {
+				rcu_read_unlock();
+				goto out_kfree_skb;
+			}
 			neigh = __ipv4_neigh_lookup_noref(dev, key);

[Severity: Low]
Is this guard needed? When ARP isn't registered, tbl is NULL and the earlier "if (!tbl)" check in neigh_xmit() already bails out.

The underlying inconsistency seems to be in include/net/arp.h. The real __ipv4_neigh_lookup_noref() is still selected by CONFIG_INET:

    #ifdef CONFIG_INET
    static inline struct neighbour *__ipv4_neigh_lookup_noref(struct net_device *dev, u32 key)
    {
        struct neigh_table *tbl = arp_table(dev_net(dev));

With INET=y and IPV4=n, arp_table() returns the NULL neigh_tables[NEIGH_ARP_TABLE], and the lookup would dereference it.

This isn't reachable today. By the end of the series, every INET-common caller (filter.c, neigh_xmit(), nexthop_is_good_nh()) is guarded, and the vrf and rocker drivers depend on IPV4.

Should the arp.h gate be CONFIG_IPV4, so that callers don't each need their own guard?

net/ipv4/inet_hashtables.c static int __inet_check_established(struct inet_timewait_death_row *death_row, · line 601

Quoted 11 lines
net/ipv4/inet_hashtables.c +3 -0
index 5abcb0debb27..ae9f45368571 100644
@@ -596,6 +596,9 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row,
 	struct sock *sk2;
 	spinlock_t *lock;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EAFNOSUPPORT;
+

[Severity: Low]
This guard removes the tcp_twsk_unique() reference from __inet_check_established(). The IPv6 version, __inet6_check_established() in net/ipv6/inet6_hashtables.c, keeps the same call:

    if (tcp_twsk_unique(sk, sk2, twp))

At this point tcp_twsk_unique() lives in tcp_ipv4.c, which is obj-$(CONFIG_IPV4). Wouldn't an IPV6=y, IPV4=n build still fail to link?

Later in the series, "tcp: move protocol agnostic TCP functions out of tcp_ipv4.c" moves tcp_twsk_unique() into net/ipv4/tcp.c, so this is fixed by the end of the series.

Also, this isn't a bug, but the "net: core:" subject prefix doesn't cover this change to net/ipv4/inet_hashtables.c.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de
#7 lore raw

Re: [PATCH 03/16 net-next v2] net: inet: relocate ip_generic_getfrag and guard IPv4 socket logic

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider.

Critical: 1 · High: 0 · Medium: 2 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Critical] Remote NULL-pointer dereference when IPv4 is disabled.
- [Medium] The IPv4 offload ops table is left half-disabled when IPv4 is off.
- [Medium] With IPv4 disabled, inet_ioctl() returns -EOPNOTSUPP for every command before its switch (net/ipv4/af_inet.c:997-998).
- [Low] The commit message is incomplete and has a typo.
- [Low] (Baseline decision: false — fixed later in the series.) The commit message says the same guard rejects IPv4-mapped IPv6, but the…

--

net: inet: relocate ip_generic_getfrag and guard IPv4 socket logic

This patch moves ip_generic_getfrag() from ip_output.c to af_inet.c so it is available without IPv4. It adds CONFIG_IPV4 guards in af_inet.c around the ioctl, bind, protocol registration, GSO and init paths. It also rejects IPv4 and v4-mapped addresses in the IPv6 bind and datagram connect paths.

Quoted 3 lines

This patch moves the generic ip_generec_getfrag() from ip_output.c to af_inet.c. It also introduces CONFIG_IPV4 guards around af_inet.c to reject IPv4-specific ioctls, protocol registrations and bind requests.

[Severity: Low]
This isn't a bug, but there's a typo: ip_generec_getfrag() should be ip_generic_getfrag().

The description also leaves out some behavioural changes in the diff:

- inet_init() now calls init_inet_pernet_ops() before ip_mr_init(). This changes the pernet init order even with CONFIG_IPV4=y.
- inet_gso_segment() is disabled when CONFIG_IPV4 is off. That is a packet path change, not socket logic.
- inet_release() skips ip_mc_drop_socket().
- inet_sk_reselect_saddr() returns early.

Could the commit message mention these as well?

Quoted 4 lines
net/ipv4/af_inet.c +0 -0
index d9421ac38d78c..cf00386933d67 100644

[ ... ]

net/ipv4/af_inet.c int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) · line 1002

Quoted 10 lines
net/ipv4/af_inet.c +3 -0
@@ -968,6 +994,9 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 	struct ifreq ifr;
 	struct rtentry rt;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EOPNOTSUPP;
+
 	switch (cmd) {
 	case SIOCADDRT:
 	case SIOCDELRT:

[Severity: Medium]
Does this break SIOCSIFFLAGS on AF_PACKET sockets when CONFIG_IPV4 is disabled?

Under CONFIG_INET, packet_ioctl() still forwards SIOCSIFFLAGS and the IPv4 address ioctls to inet_dgram_ops.ioctl:

net/packet/af_packet.c:packet_ioctl() {
    ...
	case SIOCSIFFLAGS:
		return inet_dgram_ops.ioctl(sock, cmd, arg);
#endif
    ...
}

sock_do_ioctl() only falls back to dev_ioctl() when ops->ioctl returns -ENOIOCTLCMD:

net/socket.c:sock_do_ioctl() {
    ...
	err = ops->ioctl(sock, cmd, arg);
    ...
	if (err != -ENOIOCTLCMD)
		return err;
    ...
}

With IPV4=n, sock_do_ioctl()->packet_ioctl()->inet_ioctl() returns -EOPNOTSUPP. As a result, the call never reaches the dev_ioctl()->dev_ifsioc() path. That path handles SIOCSIFFLAGS through dev_change_flags() and does nothing IPv4-specific. With IPV4=y the same ioctl worked through devinet_ioctl()->dev_change_flags().

Would returning -ENOIOCTLCMD here, at least for commands that aren't IPv4-specific, keep the generic fallback? This code is unchanged at the end of the series.

[ ... ]

net/ipv4/af_inet.c struct sk_buff *inet_gso_segment(struct sk_buff *skb, · line 1416

Quoted 10 lines
net/ipv4/af_inet.c +3 -0
@@ -1371,6 +1408,9 @@ struct sk_buff *inet_gso_segment(struct sk_buff *skb,
 	int ihl;
 	int id;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return ERR_PTR(-EPROTONOSUPPORT);
+
 	skb_reset_network_header(skb);
 	nhoff = skb_network_header(skb) - skb_mac_header(skb);
 	if (unlikely(!pskb_may_pull(skb, sizeof(*iph))))

[Severity: Medium]
Does this leave the IPv4 offload half disabled?

ipv4_offload_init() has no guard. It still registers the TCPv4, UDPv4 and IPIP offloads, and it registers the IPv4 packet offload with the GRO callbacks:

	net_hotdata.ip_packet_offload = (struct packet_offload) {
		.type = cpu_to_be16(ETH_P_IP),
		.callbacks = {
			.gso_segment = inet_gso_segment,
			.gro_receive = inet_gro_receive,
			.gro_complete = inet_gro_complete,
		},
	};

Consider an IPV4=n kernel that forwards IPv4 frames at L2 (bridge, OVS, tc redirect). GRO can still merge IPv4 TCP segments into SKB_GSO_TCPV4 packets.

If the egress device lacks TSO, the chain is:

validate_xmit_skb()
skb_gso_segment()
inet_gso_segment()
return ERR_PTR(-EPROTONOSUPPORT)

The whole aggregate is then freed through out_kfree_skb. ip4ip6_gso_segment() in net/ipv6/ip6_offload.c also calls inet_gso_segment() and would fail the same way.

The guard appears to be needed only because inet_gso_segment() calls ip_send_check(), which is in the IPv4-only ip_output.c.

Could ip_send_check() move to generic code, the same way this patch moves ip_generic_getfrag()? Or could the IPv4 GRO callbacks stay unregistered when IPv4 is disabled? This code is unchanged at the end of the series.

[ ... ]

Quoted 1 line
net/ipv4/af_inet.c +0 -0
@@ -1870,20 +1912,25 @@ static int __init ipv4_offload_init(void)

[ ... ]

Quoted 15 lines

static int __init inet_init(void)
{

net/ipv4/af_inet.c +3 -0
+#if IS_ENABLED(CONFIG_IPV4)
 	struct inet_protosw *q;
 	struct list_head *r;
 	int rc;
+#endif
 
 	sock_skb_cb_check_size(sizeof(struct inet_skb_parm));
 
+#if IS_ENABLED(CONFIG_IPV4)
 	raw_hashinfo_init(&raw_v4_hashinfo);
 
 	rc = proto_register(&tcp_prot, 1);

net/ipv4/af_inet.c static int __init inet_init(void) · line 2008

Quoted 5 lines
net/ipv4/af_inet.c +1 -1
@@ -1958,7 +2005,7 @@ static int __init inet_init(void)
 	 */
 
 	ip_init();
-
+#endif /* CONFIG_IPV4 */

[Severity: Critical]
Does this leave peer_cachep NULL on IPV4=n kernels?

ip_init() is the only caller of inet_initpeers(), and inet_initpeers() is the only place that sets peer_cachep:

net/ipv4/inetpeer.c:inet_initpeers() {
    ...
	peer_cachep = KMEM_CACHE(inet_peer, SLAB_HWCACHE_ALIGN | SLAB_PANIC);
}

inetpeer.o is still built for every INET kernel. IPv6 still uses it through inet_getpeer_v6(), called from icmpv6_xrlim_allow(), ndisc_send_redirect() and ip6_forward().

On a lookup miss, inet_getpeer() does:

	p = kmem_cache_alloc(peer_cachep, GFP_ATOMIC);

kmem_cache_alloc_noprof() then dereferences s->object_size on the NULL cache.

A remote host could trigger this on an IPv6-only kernel by sending a UDPv6 datagram to a closed port:

__udp6_lib_rcv()
icmpv6_send(ICMPV6_DEST_UNREACH)

    icmp6_send()
      icmpv6_xrlim_allow()
        inet_getpeer_v6(net->ipv6.peers, &fl6->daddr)
          inet_getpeer()
            kmem_cache_alloc(NULL, GFP_ATOMIC)

DEST_UNREACH is in the default icmpv6_ratemask, so any non-loopback destination goes through the peer lookup.

At this commit CONFIG_IPV4 is still a hidden def_bool y, so the problem is latent. However, ip_init() is still inside inet4_init() at the end of the series, and 'ipv4: make CONFIG_IPV4 boolean' makes IPV4=n selectable.

Should inet_initpeers() be called outside the IPv4-only block?

[ ... ]

net/ipv6/af_inet6.c int __inet6_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len, · line 309

Quoted 13 lines
net/ipv6/af_inet6.c +5 -0
index f0efdc13baf4e..f220eaab085b1 100644
@@ -302,6 +302,11 @@ int __inet6_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len,
 		struct net_device *dev = NULL;
 		int chk_addr_ret;
 
+		if (!IS_ENABLED(CONFIG_IPV4)) {
+			err = -EADDRNOTAVAIL;
+			goto out;
+		}
+

[Severity: Low]
The commit message says "The same guard is added to reject IPv4-mapped IPv6". However, the guard is only added to __inet6_bind() and __ip6_datagram_connect().

At this commit, tcp_v6_connect(), udpv6_sendmsg() and SOL_IP setsockopt on IPv6 sockets still dispatch to IPv4 code.

There is no intermediate regression, because CONFIG_IPV4 is still a hidden def_bool y here. Later patches in the series add the missing guards:

- tcp_v6_connect(): 'tcp: move protocol agnostic TCP functions out of

    tcp_ipv4.c'
  - udpv6_sendmsg(): 'ipv4: udp: split IPv4 specific logic into
    udp_ipv4.c'

- ip_setsockopt() and ip_getsockopt(): -EAFNOSUPPORT stubs in include/net/ip.h

Could the commit message say more precisely which paths this patch covers?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de
#9 lore raw

Re: [PATCH 04/16 net-next v2] tcp: move protocol agnostic TCP functions out of tcp_ipv4.c

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message leaves out several behavioural and structural changes this patch makes.
- [Low] union bpf_tcp_iter_batch_item and struct bpf_tcp_iter_state were file-local to net/ipv4/tcp_ipv4.c.

Pre-existing issues:
- [Medium] This problem wasn't introduced by this patch, but the patch moves it verbatim from tcp_ipv4.c to tcp.c.

--

tcp: move protocol agnostic TCP functions out of tcp_ipv4.c

This moves the TCP functions that IPv4 and IPv6 share out of tcp_ipv4.c into tcp.c, so they still build with CONFIG_IPV4=n. It also renames tcp_v4_destroy_sock() to tcp_destroy_sock() and adds IPv4 guards to the IPv4-mapped paths in tcp_ipv6.c. The /proc/net/sockstat and /proc/net/snmp output is changed as well for CONFIG_IPV4=n.

Quoted 4 lines
include/net/tcp.h +0 -0
index 96a1a23e47fac..04d487a19b178 100644

[ ... ]

Quoted 8 lines
include/net/tcp.h +4 -0
@@ -2855,6 +2855,20 @@ struct sk_psock;
 #ifdef CONFIG_BPF_SYSCALL
 int tcp_bpf_update_proto(struct sock *sk, struct sk_psock *psock, bool restore);
 void tcp_bpf_clone(const struct sock *sk, struct sock *newsk);
+
+union bpf_tcp_iter_batch_item {
+	struct sock *sk;
+	__u64 cookie;

include/net/tcp.h struct sk_psock; · line 2871

Quoted 10 lines
include/net/tcp.h +10 -0
+};
+
+struct bpf_tcp_iter_state {
+	struct tcp_iter_state state;
+	unsigned int cur_sk;
+	unsigned int end_sk;
+	unsigned int max_sk;
+	union bpf_tcp_iter_batch_item *batch;
+};
+

[Severity: Low]
This isn't a bug, but why do union bpf_tcp_iter_batch_item and struct bpf_tcp_iter_state move into include/net/tcp.h?

After this patch, net/ipv4/tcp.c is the only user, next to the bpf iterator code. Could they stay local to that file? The commit message also doesn't mention this move.

Quoted 4 lines
net/ipv4/af_inet.c +0 -0
index cf00386933d67..6c7b0816f950e 100644

[ ... ]

Quoted 24 lines
net/ipv4/af_inet.c +6 -12
@@ -2029,42 +2057,24 @@ static int __init inet_init(void)
 
 	if (init_inet_pernet_ops())
 		pr_crit("%s: Cannot init ipv4 inet pernet ops\n", __func__);
-#if IS_ENABLED(CONFIG_IPV4)
-	/*
-	 *	Initialise the multicast router
-	 */
-#if defined(CONFIG_IP_MROUTE)
-	if (ip_mr_init())
-		pr_crit("%s: Cannot init ipv4 mroute\n", __func__);
-#endif
-	ipv4_proc_init();
 
-	ipfrag_init();
+#ifdef CONFIG_PROC_FS
+	if (ip_misc_proc_init())
+		pr_crit("%s: Cannot init ipv4 misc proc\n", __func__);
+#endif
 
-	dev_add_pack(&ip_packet_type);
-#endif /* CONFIG_IPV4 */
+	if (IS_ENABLED(CONFIG_IPV4))
+		inet4_late_init();

[ ... ]

net/ipv4/af_inet.c static int __init ipv4_proc_init(void) · line 2093

Quoted 11 lines
net/ipv4/af_inet.c +0 -4
@@ -2078,12 +2088,8 @@ static int __init ipv4_proc_init(void)
 		goto out_udp;
 	if (ping_proc_init())
 		goto out_ping;
-	if (ip_misc_proc_init())
-		goto out_misc;
 out:
 	return rc;
-out_misc:
-	ping_proc_exit();
 out_ping:

[Severity: Low]
The commit message covers the TCP function move, the tcp_destroy_sock() rename and the IPv4-mapped guards in tcp_ipv6.c. On procfs, it says only:

"The implementation now force the inuse attrtibute to be zero when CONFIG_IPV4=n but the shared stats are represented correctly."

Should it also describe the other changes this patch makes?

ip_misc_proc_init() registers /proc/net/snmp, netstat and sockstat. It now runs from inet_init() whenever CONFIG_PROC_FS is set, before ip_mr_init() and before the raw/tcp4/udp4/ping proc setup. The out_misc unwind is also gone, so if it fails the other proc entries are no longer rolled back.

inet_init() is split into inet4_init() and inet4_late_init(). The CONFIG_IPV4 #if guards around inetsw_array, ip_packet_type and the ipv4_proc_init() declaration are removed, and the code relies on IS_ENABLED() and dead code elimination instead.

With CONFIG_IPV4=n, snmp_seq_show() in net/ipv4/proc.c skips the Ip, Icmp and IcmpMsg sections, so /proc/net/snmp starts with "Tcp:". sockstat_seq_show() also drops the whole FRAG line, not just the inuse values.

The later "ipv4: make CONFIG_IPV4 boolean" commit makes CONFIG_IPV4 selectable. After that, tools like nstat and netstat -s will see these /proc format changes. Could they be documented in the commit message, or split into a separate patch?

Quoted 4 lines
net/ipv4/tcp.c +0 -0
index 3ac4856852794..1f0fc46136ead 100644

[ ... ]

Quoted 1 line
net/ipv4/tcp.c +0 -0
@@ -1458,6 +1464,1115 @@ int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size)

[ ... ]

Quoted 17 lines
net/ipv4/tcp.c +17 -0
+static int bpf_iter_tcp_realloc_batch(struct bpf_tcp_iter_state *iter,
+				      unsigned int new_batch_sz, gfp_t flags)
+{
+	union bpf_tcp_iter_batch_item *new_batch;
+
+	new_batch = kvmalloc_objs(*new_batch, new_batch_sz,
+				   flags | __GFP_NOWARN);
+	if (!new_batch)
+		return -ENOMEM;
+
+	memcpy(new_batch, iter->batch, sizeof(*iter->batch) * iter->end_sk);
+	kvfree(iter->batch);
+	iter->batch = new_batch;
+	iter->max_sk = new_batch_sz;
+
+	return 0;
+}

[ ... ]

Quoted 2 lines
net/ipv4/tcp.c +2 -0
+static struct sock *bpf_iter_tcp_batch(struct seq_file *seq)
+{

[ ... ]

Quoted 18 lines
net/ipv4/tcp.c +18 -0
+	/* Batch size was too small. */
+	bpf_iter_tcp_unlock_bucket(seq);
+	bpf_iter_tcp_put_batch(iter);
+	err = bpf_iter_tcp_realloc_batch(iter, expected * 3 / 2,
+					 GFP_USER);
+	if (err) {
+		iter->cur_sk = 0;
+		iter->end_sk = 0;
+		return ERR_PTR(err);
+	}
+
+	sk = bpf_iter_tcp_resume(seq);
+	if (!sk)
+		return NULL; /* Done */
+
+	expected = bpf_iter_fill_batch(seq, &sk);
+	if (likely(!sk))
+		goto done;

net/ipv4/tcp.c int tcp_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) · line 2028

Quoted 10 lines
net/ipv4/tcp.c +10 -0
+
+	/* Batch size was still too small. Hold onto the lock while we try
+	 * again with a larger batch to make sure the current bucket's size
+	 * does not change in the meantime.
+	 */
+	err = bpf_iter_tcp_realloc_batch(iter, expected, GFP_NOWAIT);
+	if (err) {
+		bpf_iter_tcp_unlock_bucket(seq);
+		return ERR_PTR(err);
+	}

[Severity: Medium]
This isn't a bug introduced by this patch, since the code moves over unchanged from tcp_ipv4.c. Still, can this path call vfree() while the listening hash spinlock is held?

The first bpf_iter_tcp_realloc_batch() call uses GFP_USER with the bucket lock dropped. A batch of more than 512 items is larger than PAGE_SIZE. For that size, __kvmalloc_node_noprof() falls back to vmalloc if the __GFP_NORETRY kmalloc attempt fails, so iter->batch can end up vmalloc backed.

If more listeners join the bucket before it is locked again, the second fill still doesn't fit. The GFP_NOWAIT realloc then runs with the lock held:

bpf_iter_tcp_batch()
bpf_iter_tcp_resume()

    listening_get_first()
      spin_lock(&ilb2->lock);
  bpf_iter_fill_batch()        /* still too small */
  bpf_iter_tcp_realloc_batch(iter, expected, GFP_NOWAIT)
    kvfree(iter->batch)
      vfree()

vfree() only hands off to vfree_atomic() when in_interrupt() is true:

mm/vmalloc.c:vfree() {
    ...
	if (unlikely(in_interrupt())) {
		vfree_atomic(addr);
		return;
	}

	BUG_ON(in_nmi());
	kmemleak_free(addr);
	might_sleep();
    ...
}

A plain spin_lock() does not make in_interrupt() true, so vfree() takes the synchronous path with might_sleep() and the spinlock held. With CONFIG_DEBUG_ATOMIC_SLEEP this gives a "sleeping function called from invalid context" splat.

The established hash path uses spin_lock_bh(), so there vfree() defers the free.

GFP_NOWAIT only applies to the new allocation. It does nothing for the free of the old buffer. Could the old batch be freed after bpf_iter_tcp_unlock_bucket() instead, or the free be deferred when the lock is held?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de
#11 lore raw

Re: [PATCH 05/16 net-next v2] ipv4: raw: split IPv4 specific logic into raw_ipv4.c

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The new file net/ipv4/raw_ipv4.c exports raw_v4_match() with EXPORT_SYMBOL_GPL(raw_v4_match) at line 60, but it never includes…
- [Low] The move is incomplete and leaves dead code in net/ipv4/raw.c.

--

ipv4: raw: split IPv4 specific logic into raw_ipv4.c

This commit moves the IPv4 specific RAW socket code out of raw.c and into a new file, net/ipv4/raw_ipv4.c. That covers packet matching, input/output processing, ICMP filtering and the AF_INET raw_prot definition. raw_ipv4.c is built only with CONFIG_IPV4, and raw_lookup() in raw_diag.c now guards raw_v4_match() with IS_ENABLED(CONFIG_IPV4).

Quoted 4 lines
net/ipv4/raw.c +0 -0
index 9d01006d8189e..dcd554d920825 100644

[ ... ]

Quoted 5 lines
net/ipv4/raw.c +0 -1
@@ -48,31 +47,25 @@
 #include <linux/sockios.h>
 #include <linux/socket.h>
 #include <linux/in.h>
-#include <linux/mroute.h>

[ ... ]

net/ipv4/raw.c line 70

Quoted 8 lines

#include <linux/rtnetlink.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>

net/ipv4/raw.c +0 -2
-#include <linux/netfilter.h>
-#include <linux/netfilter_ipv4.h>
 #include <linux/compat.h>
 #include <linux/uio.h>

[Severity: Low]
This isn't a bug, but some leftovers from the move seem to remain in raw.c.

Just below this include block, raw.c still has its own copy of the struct:

net/ipv4/raw.c:

    #include <linux/compat.h>
    #include <linux/uio.h>

    struct raw_frag_vec {
    	struct msghdr *msg;
    	union {
    		struct icmphdr icmph;
    		char c[1];
    	} hdr;
    	int hlen;
    };

    struct raw_hashinfo raw_v4_hashinfo;

All users of struct raw_frag_vec (raw_probe_proto_opt(), raw_getfrag() and raw_sendmsg()) now live in raw_ipv4.c, which adds an identical definition. Could the raw.c copy be removed, so the two private definitions can't drift apart?

Also, <linux/compat.h> stays in raw.c. Its only user was compat_raw_ioctl() via compat_ptr(), which has moved to raw_ipv4.c. <linux/sockios.h> is also still included, although the SIOCINQ and SIOCOUTQ handling moved out.

The other includes that are no longer needed (asm/ioctls.h, mroute.h, igmp.h, icmp.h, xfrm.h, netfilter*.h) were dropped. Should these ones be dropped as well?

[ ... ]

Quoted 6 lines
net/ipv4/raw_ipv4.c new file +0 -0
new file mode 100644
index 0000000000000..8d3d6f30b0e80
@@ -0,0 +1,883 @@

[ ... ]

Quoted 13 lines
net/ipv4/raw_ipv4.c new file +13 -0
+#include <asm/ioctls.h>
+#include <linux/igmp.h>
+#include <linux/mroute.h>
+#include <linux/netfilter.h>
+#include <linux/sockios.h>
+#include <linux/stddef.h>
+#include <linux/types.h>
+#include <net/icmp.h>
+#include <net/ip.h>
+#include <net/raw.h>
+#include <net/sock.h>
+#include <net/udp.h>
+#include <net/xfrm.h>

[ ... ]

Quoted 3 lines
net/ipv4/raw_ipv4.c new file +3 -0
+bool raw_v4_match(struct net *net, const struct sock *sk, unsigned short num,
+		  __be32 raddr, __be32 laddr, int dif, int sdif)
+{

[ ... ]

net/ipv4/raw_ipv4.c line 60

Quoted 4 lines
net/ipv4/raw_ipv4.c new file +4 -0
+	return raw_sk_bound_dev_eq(net, READ_ONCE(sk->sk_bound_dev_if),
+				   dif, sdif);
+}
+EXPORT_SYMBOL_GPL(raw_v4_match);

[Severity: Low]
The new file uses EXPORT_SYMBOL_GPL() for raw_v4_match(), but <linux/export.h> is not in the include list above. raw.c included <linux/export.h> directly, and still needs it for raw_v4_hashinfo.

In W=2 builds, check_missing_include_linux_export_h() in scripts/misc-check flags files like this one:

warning: EXPORT_SYMBOL() is used, but #include <linux/export.h> is missing

Would it make sense to add #include <linux/export.h> to raw_ipv4.c, so this new file doesn't bring in an extra W=2 warning?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de
#15 lore raw

Re: [PATCH 06/16 net-next v2] ipv4: udp: split IPv4 specific logic into udp_ipv4.c

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The patch moves udp_rcv() from net/ipv4/udp.c into the new net/ipv4/udp_ipv4.c, but the moved copy is stale and undoes commit…

--

ipv4: udp: split IPv4 specific logic into udp_ipv4.c

This patch moves the IPv4 specific UDP code (lookup, input/output, error handling, multicast and the AF_INET udp_prot) out of net/ipv4/udp.c and into a new net/ipv4/udp_ipv4.c. The new file is built only when CONFIG_IPV4 is enabled, which is a step toward building INET without IPv4.

Quoted 4 lines
net/ipv4/udp.c +0 -0
index b534b85bc623c..0f2ff5a9d4ae4 100644

[ ... ]

Quoted 21 lines
net/ipv4/udp.c +0 -21
-int udp_rcv(struct sk_buff *skb)
-{
-	struct rtable *rt = skb_rtable(skb);
-	struct net *net = dev_net(skb->dev);
-	struct sock *sk = NULL;
-	__be32 saddr, daddr;
-	unsigned int ulen;
-	struct udphdr *uh;
-	bool refcounted;
-	int drop_reason;
-
-	drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
-
-	/*
-	 *  Validate the packet.
-	 */
-	if (!pskb_may_pull(skb, sizeof(struct udphdr)))
-		goto drop;		/* No space for header. */
-
-	uh   = udp_hdr(skb);
-	ulen = udp_get_len(skb, uh, 0);

[ ... ]

Quoted 5 lines
net/ipv4/udp_ipv4.c new file +0 -0
new file mode 100644
index 0000000000000..466008c218df4

[ ... ]

Quoted 19 lines
net/ipv4/udp_ipv4.c new file +19 -0
+int udp_rcv(struct sk_buff *skb)
+{
+	struct rtable *rt = skb_rtable(skb);
+	struct net *net = dev_net(skb->dev);
+	struct sock *sk = NULL;
+	unsigned short ulen;
+	__be32 saddr, daddr;
+	struct udphdr *uh;
+	bool refcounted;
+	int drop_reason;
+
+	drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
+
+	/*
+	 *  Validate the packet.
+	 */
+	if (!pskb_may_pull(skb, sizeof(struct udphdr)))
+		goto drop;		/* No space for header. */
+

net/ipv4/udp_ipv4.c line 1178

Quoted 10 lines
net/ipv4/udp_ipv4.c new file +10 -0
+	uh   = udp_hdr(skb);
+	ulen = ntohs(uh->len);
+	saddr = ip_hdr(skb)->saddr;
+	daddr = ip_hdr(skb)->daddr;
+
+	if (ulen > skb->len)
+		goto short_packet;
+
+	if (ulen < sizeof(*uh))
+		goto short_packet;

[Severity: High]
The moved copy of udp_rcv() doesn't match the one being removed from net/ipv4/udp.c. Was this copied from a tree older than commit efbc1aa8ed54 ("udp: Support gro_ipv4_max_size > 65536")?

The removed version has:

	unsigned int ulen;
	...
	ulen = udp_get_len(skb, uh, 0);

The new version has:

	unsigned short ulen;
	...
	ulen = ntohs(uh->len);

Those are the two lines efbc1aa8ed54 replaced.

The GRO completion side still relies on the newer rule. Both udp_gro_complete() and the fraglist branch of udp4_gro_complete() call udp_set_len(), which writes a zero length for large aggregates:

include/linux/udp.h:udp_set_len() {
	uh->len = len < GRO_LEGACY_MAX_SIZE ? htons(len) : 0;
}

udp_get_len() is the helper that reads this marker back:

include/linux/udp.h:udp_get_len() {
	if (uh->len)
		return ntohs(uh->len);
	if (skb_is_gso(skb)) /* BIG TCP */
		return skb->len - dataoff;
	return 0;
}

Take gro_ipv4_max_size or gro_max_size set above 65536, with BIG TCP running over VXLAN or GENEVE. When a 64KB or larger aggregate reaches udp_rcv(), won't ulen be 0 here? The "ulen < sizeof(*uh)" check would then send it to short_packet, and the packet would be dropped with SKB_DROP_REASON_PKT_TOO_SMALL and counted in UDP_MIB_INERRORS.

__udp6_lib_rcv() in net/ipv6/udp.c still uses udp_get_len(), so IPv4 and IPv6 would now read the same header field differently.

Restoring only the udp_get_len() call would not be enough. With ulen still declared unsigned short, lengths above 65535 would be truncated. Could both the unsigned int declaration and the udp_get_len() call be carried over, so this stays a pure code move as the commit message describes?

Quoted 7 lines
net/ipv4/udp_ipv4.c new file +7 -0
+
+	if (ulen < skb->len) {
+		if (pskb_trim_rcsum(skb, ulen))
+			goto short_packet;
+
+		uh = udp_hdr(skb);
+	}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de
#17 lore raw

Re: [PATCH 07/16 net-next v2] ipv4: icmp: split IPv4 specific logic into icmp_ipv4.c

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The patch moves the per-CPU ICMP control socket setup (a for_each_possible_cpu() loop calling inet_ctl_sock_create()) out of…

--

ipv4: icmp: split IPv4 specific logic into icmp_ipv4.c

This commit moves the IPv4 specific ICMP code (packet processing, error handling, the icmp_pointers[] table and the per-CPU control socket setup) out of net/ipv4/icmp.c into a new file, net/ipv4/icmp_ipv4.c. The new file is built only when CONFIG_IPV4 is enabled, and icmp.c is moved to obj-y.

Quoted 4 lines
net/ipv4/icmp.c +0 -0
index 90c0e22c29bea..5e8dcf71d135f 100644

[ ... ]

Quoted 16 lines
net/ipv4/icmp.c +3 -7
@@ -1757,28 +366,11 @@ static struct pernet_operations __net_initdata icmp_sk_ops = {
 
 int __init icmp_init(void)
 {
-	int err, i;
-
-	for_each_possible_cpu(i) {
-		struct sock *sk;
+	if (IS_ENABLED(CONFIG_IPV4)) {
+		int err = icmp_init_ipv4();
 
-		err = inet_ctl_sock_create(&sk, PF_INET,
-					   SOCK_RAW, IPPROTO_ICMP, &init_net);
-		if (err < 0)
+		if (err)
 			return err;

[ ... ]

Quoted 5 lines
net/ipv4/icmp_ipv4.c new file +0 -0
new file mode 100644
index 0000000000000..24a1fb497cf6f

[ ... ]

net/ipv4/icmp_ipv4.c line 1429

Quoted 9 lines
net/ipv4/icmp_ipv4.c new file +9 -0
+int icmp_init_ipv4(void)
+{
+	int err, i;
+
+	for_each_possible_cpu(i) {
+		struct sock *sk;
+
+		err = inet_ctl_sock_create(&sk, PF_INET,
+					   SOCK_RAW, IPPROTO_ICMP, &init_net);

[Severity: Low]
Should icmp_init_ipv4() be marked __init?

The per-CPU control socket loop used to live directly in icmp_init(), which is __init, so it was freed with init memory after boot. It now sits in icmp_init_ipv4(), which has no annotation.

The only caller is still icmp_init(), which runs once at boot, so this code can never run again. It now stays in resident .text instead of being discarded. The commit message describes this as a plain move and doesn't mention the change.

Would it make sense to use int __init icmp_init_ipv4(void) here, and maybe put __init on the prototype in include/net/icmp.h as well?

Quoted 4 lines
net/ipv4/icmp_ipv4.c new file +4 -0
+		if (err < 0)
+			return err;
+
+		per_cpu(ipv4_icmp_sk, i) = sk;

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de
#20 lore raw

Re: [PATCH 09/16 net-next v2] ipv4: fib: split common nexthop logic to fib_core.c

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message undersells the patch.
- [Low] In include/net/ip_fib.h the patch changes the section comment "/* Exported by fib_frontend.c */" to "/* Exported by net/core/fib_core.c…
- [Low] fib_core.o is added to the unconditional obj-y list in net/core/Makefile (line 15).
- [Low] The patch adds !CONFIG_IPV4 stubs for fib_nh_init(), fib_nh_release(), fib_flush(), fib_info_notify_update() and…

--

ipv4: fib: split common nexthop logic to fib_core.c

This patch creates net/core/fib_core.c. It moves shared FIB and nexthop helpers there from net/ipv4/fib_semantics.c and net/ipv4/fib_frontend.c, so IPv6 can still use them when the IPv4 routing stack is not built. It also adds !CONFIG_IPV4 stubs and guards in ip_fib.h, route.h, nexthop.c and sysctl_net_ipv4.c.

Quoted 3 lines

This patch creates fib_core.c and move all the functions for common nexthop initialization and release from fib_semantics.c to fib_core.c. Note that fib_core.c is under net/core.

[Severity: Low]
This isn't a bug, but the description covers only part of what the patch does. Besides the init and release helpers, the patch also:

- moves rtm_ipv4_policy[] and the exported ip_valid_fib_dump_req() out of net/ipv4/fib_frontend.c
- moves fib_nexthop_info() and fib_add_nexthop(), which are netlink encoders and not init or release code
- adds !CONFIG_IPV4 stubs: fib_nh_init() returns -EAFNOSUPPORT, and fib_nh_release(), fib_flush(), fib_info_notify_update() and rt_cache_flush() become no-ops
- makes nexthop_is_good_nh() return false for AF_INET, and makes nh_netdev_event() skip nexthop_sync_mtu(), when CONFIG_IPV4 is disabled
- makes the net.ipv4.fib_sync_mem sysctl depend on CONFIG_IPV4, although a later patch in the series ("ipv4: disable IPv4-only sysctls when CONFIG_IPV4=n") exists for exactly that purpose

Once "ipv4: make CONFIG_IPV4 boolean" later in the series makes IPv4 selectable, users will see these changes. Creating an AF_INET nexthop fails with -EAFNOSUPPORT, IPv4 nexthop MTU sync is skipped, and /proc/sys/net/ipv4/fib_sync_mem goes away.

Could the commit message describe these extra changes, or could some of them move into their own patches?

Quoted 4 lines
include/net/ip_fib.h +0 -0
index 0a35355fb0f33..6058e53fa3dec 100644

[ ... ]

include/net/ip_fib.h static inline bool fib_dscp_masked_match(dscp_t dscp, const struct flowi4 *fl4) · line 454

Quoted 9 lines
include/net/ip_fib.h +1 -1
@@ -442,7 +448,7 @@ static inline bool fib_dscp_masked_match(dscp_t dscp, const struct flowi4 *fl4)
 	return dscp == (fl4->flowi4_dscp & INET_DSCP_LEGACY_TOS_MASK);
 }
 
-/* Exported by fib_frontend.c */
+/* Exported by net/core/fib_core.c */
 extern const struct nla_policy rtm_ipv4_policy[];
 void ip_fib_init(void);
 int fib_gw_from_via(struct fib_config *cfg, struct nlattr *nla,

[Severity: Low]
Is this comment accurate? Of the declarations under it, only rtm_ipv4_policy moved to fib_core.c. The rest are still defined in net/ipv4/fib_frontend.c, which is only built with CONFIG_IPV4:

    void ip_fib_init(void);
    int fib_gw_from_via(struct fib_config *cfg, struct nlattr *nla, ...);
    __be32 fib_compute_spec_dst(struct sk_buff *skb);
    bool fib_info_nh_uses_dev(struct fib_info *fi, ...);
    int fib_validate_source(struct sk_buff *skb, __be32 src, ...);

fib_unmerge() is in the same position.

The mismatch also goes the other way. fib_nh_common_init() and fib_nh_common_release() are now defined only in net/core/fib_core.c, but their declarations are still under the "Exported by fib_semantics.c" section. The declarations of ip_valid_fib_dump_req(), fib_nexthop_info() and fib_add_nexthop(), which also moved, have no attribution at all.

This series separates IPv4-only symbols from always-built ones. Could the new comment suggest that fib_validate_source() or fib_gw_from_via() can be called from code built with CONFIG_IPV4=n? Such a call would fail to link.

No later patch in the series touches include/net/ip_fib.h, so the comment is still wrong at the end of the series.

[ ... ]

Quoted 11 lines
include/net/ip_fib.h +3 -0
@@ -578,10 +584,23 @@ void fib_select_multipath(struct fib_result *res, int hash,
 void fib_select_path(struct net *net, struct fib_result *res,
 		     struct flowi4 *fl4, const struct sk_buff *skb);
 
+#if IS_ENABLED(CONFIG_IPV4)
 int fib_nh_init(struct net *net, struct fib_nh *fib_nh,
 		struct fib_config *cfg, int nh_weight,
 		struct netlink_ext_ack *extack);
 void fib_nh_release(struct net *net, struct fib_nh *fib_nh);
+#else
+static inline int fib_nh_init(struct net *net, struct fib_nh *fib_nh,

include/net/ip_fib.h void fib_select_multipath(struct fib_result *res, int hash, · line 603

Quoted 10 lines
include/net/ip_fib.h +10 -0
+			      struct fib_config *cfg, int nh_weight,
+			      struct netlink_ext_ack *extack)
+{
+	return -EAFNOSUPPORT;
+}
+
+static inline void fib_nh_release(struct net *net, struct fib_nh *fib_nh)
+{
+}
+#endif

[Severity: Low]
In net/ipv4/Makefile, nexthop.o is obj-y and fib_semantics.o is obj-$(CONFIG_IPV4). nexthop.c also calls three other fib_semantics.c functions that get no stub here: fib_check_nh(), fib_info_update_nhc_saddr() and fib_nhc_update_mtu().

For nh_create_ipv4(), does a CONFIG_IPV4=n build only link because the compiler inlines this stub, folds the constant -EAFNOSUPPORT, and drops the later calls?

net/ipv4/nexthop.c:nh_create_ipv4() {
    ...
	err = fib_nh_init(net, fib_nh, &fib_cfg, 1, extack);
	if (err) {
		fib_nh_release(net, fib_nh);
		goto out;
	}
    ...
	err = fib_check_nh(net, fib_nh, tb_id, 0, extack);
	if (!err) {
		nh->nh_flags = fib_nh->fib_nh_flags;
		fib_info_update_nhc_saddr(net, &fib_nh->nh_common,
    ...
}

The fib_nhc_update_mtu() call in nexthop_sync_mtu() is covered by the explicit IS_ENABLED(CONFIG_IPV4) check in nh_netdev_event(). fib_check_nh() and fib_info_update_nhc_saddr() have no such guard.

If err here ever stops being a constant, for example because some work is added before the stubbed call, wouldn't the link fail with undefined references to these two functions?

There is also a user-facing gap. With IPv4 disabled, an AF_INET nexthop request passes netlink parsing and then fails inside nh_create_ipv4() with a bare -EAFNOSUPPORT and no extack message. Could this be rejected earlier, with an extack message?

No later patch in the series changes nexthop.c or ip_fib.h.

[ ... ]

net/core/Makefile obj-$(CONFIG_SYSCTL) += sysctl_net_core.o · line 16

Quoted 11 lines
net/core/Makefile +1 -1
index c20e520358b8e..315e437a49d8c 100644
@@ -12,7 +12,7 @@ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o
 obj-y		     += dev.o dev_api.o dev_addr_lists.o dst.o netevent.o \
 			neighbour.o rtnetlink.o utils.o link_watch.o filter.o \
 			sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \
-			fib_notifier.o xdp.o flow_offload.o gro.o \
+			fib_notifier.o fib_core.o xdp.o flow_offload.o gro.o \
 			netdev-genl.o netdev-genl-gen.o netdev_work.o gso.o

[Severity: Low]
net/Makefile builds core/ for every CONFIG_NET kernel, and enters ipv4/ only when CONFIG_INET is set. With fib_core.o in the unconditional obj-y list, won't CONFIG_NET=y, CONFIG_INET=n kernels now include this code even though nothing in them calls it? That covers the rtable/fnhe freeing helpers, fib_nh_common_init() and fib_nh_common_release(), fib_nexthop_info() and fib_add_nexthop(), the rtm_ipv4_policy table, and the EXPORT_SYMBOL_GPL'd ip_valid_fib_dump_req().

All users need INET: nexthop.o, net/ipv6/route.c, ipmr/ip6mr and MPLS.

Could fib_core.o go in obj-y in net/ipv4/Makefile instead? Alternatively, it could be gated on CONFIG_INET here, as this Makefile already does for bpf_ksock.o with "ifdef CONFIG_INET".

The commit message only says "Note that fib_core.c is under net/core." and doesn't explain the placement. No later patch in the series changes net/core/Makefile.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de
#25 lore raw

Re: [PATCH 11/16 net-next v2] ipv4: disable IPv4-only sysctls when CONFIG_IPV4=n

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The patch moves the fib_multipath_hash_seed entry of ipv4_net_table (net/ipv4/sysctl_net_ipv4.c:1644-1650) into the new…

--

ipv4: disable IPv4-only sysctls when CONFIG_IPV4=n

This commit moves the IPv4-only entries of ipv4_net_table into a new IS_ENABLED(CONFIG_IPV4) block, so they are not registered when IPv4 support is compiled out. The handlers and limit variables that are now only used conditionally are marked __maybe_unused.

Quoted 4 lines
net/ipv4/sysctl_net_ipv4.c +0 -0
index 0e7fef5973db6..6096e9e4d82d8 100644

[ ... ]

Quoted 13 lines
net/ipv4/sysctl_net_ipv4.c +3 -3
@@ -492,9 +493,9 @@ static void proc_fib_multipath_hash_set_seed(struct net *net, u32 user_seed)
 	WRITE_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed.mp_seed, new.mp_seed);
 }
 
-static int proc_fib_multipath_hash_seed(const struct ctl_table *table, int write,
-					void *buffer, size_t *lenp,
-					loff_t *ppos)
+static int __maybe_unused
+proc_fib_multipath_hash_seed(const struct ctl_table *table, int write,
+			     void *buffer, size_t *lenp, loff_t *ppos)
 {
 	struct sysctl_fib_multipath_hash_seed *mphs;
 	struct net *net = table->data;

[ ... ]

Quoted 7 lines
net/ipv4/sysctl_net_ipv4.c +3 -0
@@ -1656,6 +1469,196 @@ static const struct ctl_table ipv4_net_table[] = {
 		.extra1		= SYSCTL_ONE_THOUSAND,
 		.extra2		= &tcp_rto_max_max,
 	},
+#if IS_ENABLED(CONFIG_IPV4)
+	{
+		.procname	= "icmp_echo_ignore_all",

[ ... ]

Quoted 3 lines
net/ipv4/sysctl_net_ipv4.c +3 -0
+#ifdef CONFIG_IP_ROUTE_MULTIPATH
+	{
+		.procname	= "fib_multipath_use_neigh",

[ ... ]

net/ipv4/sysctl_net_ipv4.c static const struct ctl_table ipv4_net_table[] = { · line 1651

Quoted 8 lines
net/ipv4/sysctl_net_ipv4.c +8 -0
+	{
+		.procname	= "fib_multipath_hash_seed",
+		.data		= &init_net,
+		.maxlen		= sizeof(u32),
+		.mode		= 0644,
+		.proc_handler	= proc_fib_multipath_hash_seed,
+	},
+#endif

[Severity: Medium]
Is fib_multipath_hash_seed really an IPv4-only sysctl?

The seed is read by the shared helper fib_multipath_hash_from_keys(), which is gated only by CONFIG_IP_ROUTE_MULTIPATH:

include/net/ip_fib.h:fib_multipath_hash_from_keys() {
    ...
	mp_seed = READ_ONCE(net->ipv4.sysctl_fib_multipath_hash_seed.mp_seed);
	fib_multipath_hash_construct_key(&hash_key, mp_seed);
    ...
}

The IPv6 datapath calls this helper for every multipath hash, through rt6_multipath_hash() in net/ipv6/route.c.

net/ipv6/sysctl_net_ipv6.c has its own fib_multipath_hash_policy and fib_multipath_hash_fields, but it has no seed knob. That makes this entry the only way to set the seed for either family. Documentation/networking/ip-sysctl.rst describes it the same way:

The seed value used when calculating hash for multipath routes. Applies to both IPv4 and IPv6 datapath. Only present for kernels built with CONFIG_IP_ROUTE_MULTIPATH enabled.

CONFIG_IP_ROUTE_MULTIPATH depends only on IP_ADVANCED_ROUTER, not on IPV4. After "ipv4: make CONFIG_IPV4 boolean" later in the series, CONFIG_IPV4 can be disabled when IPV6 is enabled. At the end of the series this entry is still inside the CONFIG_IPV4 block.

Take a kernel built with CONFIG_IPV4=n, CONFIG_IPV6=y and CONFIG_IP_ROUTE_MULTIPATH=y. ipv4_sysctl_init_net() still calls proc_fib_multipath_hash_set_seed(net, 0), so IPv6 ECMP keeps hashing with the random seed picked at boot. However, /proc/sys/net/ipv4/fib_multipath_hash_seed no longer exists, so the seed cannot be set to a fixed value. mlxsw programs its hardware ECMP seed from user_seed, so it would also always see 0.

Could the fib_multipath_hash_seed entry and proc_fib_multipath_hash_seed() stay outside the CONFIG_IPV4 block, under CONFIG_IP_ROUTE_MULTIPATH? That would match how icmp_echo_enable_probe, icmp_msgs_per_sec and ip_early_demux were left in place. fib_multipath_use_neigh, fib_multipath_hash_policy and fib_multipath_hash_fields do look IPv4-only and could stay inside the block.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de
#27 lore raw

Re: [PATCH 12/16 net-next v2] netfilter: ipv4: guard ip_route_me_harder() with CONFIG_IPV4

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In ip_route_me_harder() (net/ipv4/netfilter.c), the new if (!IS_ENABLED(CONFIG_IPV4)) return -EPROTONOSUPPORT; check (lines…

--

netfilter: ipv4: guard ip_route_me_harder() with CONFIG_IPV4

This commit adds an IS_ENABLED(CONFIG_IPV4) check to ip_route_me_harder() in net/ipv4/netfilter.c. When IPv4 is disabled, the function returns -EPROTONOSUPPORT and skips the IPv4 rerouting logic. The goal is to let the network stack build without IPv4.

net/ipv4/netfilter.c int ip_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb, un · line 35

Quoted 11 lines
net/ipv4/netfilter.c +3 -0
index ce9e1bfa4259f..f2d9e0110b779 100644
@@ -30,6 +30,9 @@ int ip_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb, un
 	struct flow_keys flkeys;
 	unsigned int hh_len;
 
+	if (!IS_ENABLED(CONFIG_IPV4))
+		return -EPROTONOSUPPORT;
+

[Severity: Low]
This isn't a bug, but would it be clearer to do this check before the declaration initializers in ip_route_me_harder()?

As placed, the initializers above the check still load from the dst and from the IPv4 header when CONFIG_IPV4=n:

net/ipv4/netfilter.c:ip_route_me_harder() {
	struct net_device *dev = skb_dst_dev(skb);
	const struct iphdr *iph = ip_hdr(skb);
	...
	__be32 saddr = iph->saddr;
	...
}

This doesn't look reachable in practice. With the rest of the series applied, every in-tree caller sits behind a Kconfig option that depends on IPV4. For example, the core netfilter menu in net/netfilter/Kconfig now has:

	depends on INET && IPV4 && NETFILTER

The callers also always pass an skb that has a dst set.

Moving the IS_ENABLED(CONFIG_IPV4) check above the initializers, or deferring those assignments until after it, would make it clearer that nothing IPv4-specific runs when IPv4 is disabled.

Quoted 3 lines
net/ipv4/netfilter.c +0 -0
 	sk = sk_to_full_sk(sk);
 	flags = sk ? inet_sk_flowi_flags(sk) : 0;
 
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de
#29 lore raw

Re: [PATCH 13/16 net-next v2] net: bridge: guard ARP/RARP proxy and suppression with CONFIG_IPV4

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In net/bridge/br_arp_nd_proxy.c, the patch removes #if IS_ENABLED(CONFIG_INET) from above the static helper…

--

net: bridge: guard ARP/RARP proxy and suppression with CONFIG_IPV4

This commit replaces the CONFIG_INET guards around the bridge ARP/RARP proxy and suppression code with CONFIG_IPV4. The reason given is that CONFIG_IPV4 is becoming optional and separate from the core stack.

Quoted 13 lines
net/bridge/br_arp_nd_proxy.c +0 -1
index da15f4d7c1aef..d739b86974299 100644
@@ -39,7 +39,6 @@ void br_recalculate_neigh_suppress_enabled(struct net_bridge *br)
 	br_opt_toggle(br, BROPT_NEIGH_SUPPRESS_ENABLED, neigh_suppress);
 }
 
-#if IS_ENABLED(CONFIG_INET)
 static bool
 br_is_neigh_suppress_enabled_vid(const struct net_bridge_port *p, u16 vid)
 {

net/bridge/br_arp_nd_proxy.c br_is_neigh_suppress_enabled_vid(const struct net_bridge_port *p, u16 vid) · line 59

Quoted 4 lines
net/bridge/br_arp_nd_proxy.c +1 -0
@@ -57,6 +56,7 @@ br_is_neigh_suppress_enabled_vid(const struct net_bridge_port *p, u16 vid)
 	return br_is_neigh_suppress_enabled(p, v);
 }
 
+#if IS_ENABLED(CONFIG_IPV4)

[Severity: Low]
After this change, the static helper br_is_neigh_suppress_enabled_vid() is always compiled. Does that give a "defined but not used" warning when CONFIG_INET=n?

All of its callers are still behind config guards:

br_do_proxy_suppress_arp() inside #if IS_ENABLED(CONFIG_IPV4)
br_do_suppress_nd() inside #if IS_ENABLED(CONFIG_IPV6)

config IPV4 and config IPV6 are only defined under "if INET" in net/Kconfig. config BRIDGE has no INET dependency, and br_arp_nd_proxy.o is always part of bridge-y:

net/bridge/Makefile:

bridge-y	:= br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \
			...
			br_netlink_tunnel.o br_arp_nd_proxy.o

With CONFIG_BRIDGE=y/m and CONFIG_INET=n, the file is still built, but both guarded blocks are compiled out. That leaves the helper with no callers and triggers -Wunused-function. With CONFIG_WERROR=y, which defaults to y under COMPILE_TEST, the build fails. At the baseline, the CONFIG_INET guard covered the helper, so this configuration built without warnings.

Moving the helper out of the IPv4 block makes sense, because the IPv6 block needs it once IPV4 can be disabled. Could the helper get its own guard instead, such as #if IS_ENABLED(CONFIG_INET) or
#if IS_ENABLED(CONFIG_IPV4) || IS_ENABLED(CONFIG_IPV6), closed before the IPv4 block starts?

This still happens at the end of the series. The only configuration that triggers it is INET=n. INET=y with both IPV4=n and IPV6=n cannot be selected, because config IPV4 is only user-selectable when IPV6 is enabled and defaults to INET.

Quoted 3 lines
net/bridge/br_arp_nd_proxy.c +0 -0
 static void br_arp_send(struct net_bridge *br, struct net_bridge_port *p,
 			struct net_device *dev, __be32 dest_ip, __be32 src_ip,
 			const unsigned char *dest_hw,

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de
#34 lore raw

Re: [PATCH 15/16 net-next v2] netlabel: cipso: introduce CONFIG_CIPSO to decouple IPv4 dependency

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The NetLabel management PROTOCOLS dump (netlbl_mgmt_protocols() in net/netlabel/netlabel_mgmt.c) always lists…
- [Low] Concern about commit-message accuracy.

--

I found two possible issues in this patch and wrote them up as an inline reply for the list, shown below:

- **Medium:** with CONFIG_CIPSO=n, the NetLabel PROTOCOLS dump in netlbl_mgmt_protocols() still lists CIPSOv4 as available, but the protocol cannot be used.
- **Low:** the commit message says NetLabel and Smack can run on IPv6-only kernels. At this commit that setup cannot be selected yet, and the message doesn't say that Smack loses CIPSO labelling in it.

I checked both against the code at this commit: the protocol dump, the CIPSOv4 add path in netlbl_mgmt_add_common(), and Smack's smk_cipso_doi() and its callers.

netlabel: cipso: introduce CONFIG_CIPSO to decouple IPv4 dependency

This commit adds a CONFIG_CIPSO symbol, enabled when both NETLABEL and IPV4 are set. The CIPSO objects, sysctls and kernel APIs are now gated on it. The IPV4 dependency is dropped from the NetLabel Kconfig sourcing and from Smack.

Quoted 3 lines

By safely stubbing out the CIPSO netlabel_kapi functions to return -ENOSYS when disabled, this allows NetLabel and Smack to be successfully built and used on IPv6-only kernels.

[Severity: Low]
This isn't a bug, but at this commit CONFIG_IPV4 is still def_bool y in net/ipv4/Kconfig, so a CIPSO=n configuration cannot be selected yet. The IPv6-only case only becomes reachable with the follow-up patch "ipv4: make CONFIG_IPV4 boolean". Should the commit message say that?

With CIPSO=n, Smack also runs without CIPSO labelling. The boot-time call in init_smk_fs() fails without any message, because its return value is cast to void:

security/smack/smackfs.c:init_smk_fs() {
    ...
	(void) smk_cipso_doi(SMACK_CIPSO_DOI_DEFAULT,
			     GFP_KERNEL | __GFP_NOFAIL);
    ...
}

Writes to /smack/doi return -ENOSYS through this path:

smk_write_doi()->smk_cipso_doi()->netlbl_cfg_cipsov4_add()->cipso_v4_doi_add()

Could the commit message mention this change in Smack's behaviour?

Quoted 29 lines
net/netlabel/Kconfig +4 -0
index 4383ac29693ec..bcc27196d5bd7 100644
@@ -17,3 +17,7 @@ config NETLABEL
 	   * https://github.com/netlabel/netlabel_tools
 
 	  If you are unsure, say N.
+
+config CIPSO
+	def_bool y
+	depends on NETLABEL && IPV4
net/netlabel/Makefile +1 -1
index 5a46381a64e77..8afc1bf004243 100644
@@ -12,5 +12,5 @@ obj-y	+= netlabel_mgmt.o
 
 # protocol modules
 obj-y	+= netlabel_unlabeled.o
-obj-y	+= netlabel_cipso_v4.o
+obj-$(CONFIG_CIPSO) += netlabel_cipso_v4.o
 obj-$(subst m,y,$(CONFIG_IPV6)) += netlabel_calipso.o
net/netlabel/netlabel_cipso_v4.h +0 -0
index 9518ab56ec98f..fb718f86bcbd7 100644
@@ -147,6 +147,13 @@ enum {
 #define NLBL_CIPSOV4_A_MAX (__NLBL_CIPSOV4_A_MAX - 1)

net/netlabel/netlabel_cipso_v4.h enum { · line 157

Quoted 10 lines
net/netlabel/netlabel_cipso_v4.h +7 -0
 
 /* NetLabel protocol functions */
+#if IS_ENABLED(CONFIG_CIPSO)
 int netlbl_cipsov4_genl_init(void);
+#else
+static inline int netlbl_cipsov4_genl_init(void)
+{
+	return 0;
+}
+#endif

[Severity: Medium]
With CIPSO=n, this stub returns 0 and does not register the NLBL_CIPSOv4 generic netlink family. Should netlbl_mgmt_protocols() in net/netlabel/netlabel_mgmt.c stop listing CIPSOv4 in that case? It still lists it with no config check:

net/netlabel/netlabel_mgmt.c:netlbl_mgmt_protocols() {
    ...
	if (protos_sent == 1) {
		if (netlbl_mgmt_protocols_cb(skb,
					     cb,
					     NETLBL_NLTYPE_CIPSOV4) < 0)
			goto protocols_return;
		protos_sent++;
	}
#if IS_ENABLED(CONFIG_IPV6)
	if (protos_sent == 2) {
    ...
}

So an NLBL_MGMT_C_PROTOCOLS dump (for example, "netlabelctl mgmt protocols") would report CIPSOv4 as supported on a kernel that cannot use it.

Any attempt to set up a CIPSOv4 mapping through the management interface then fails with -EINVAL. The cipso_v4_doi_getdef() stub always returns NULL:

net/netlabel/netlabel_mgmt.c:netlbl_mgmt_add_common() {
    ...
	case NETLBL_NLTYPE_CIPSOV4:
		...
		cipsov4 = cipso_v4_doi_getdef(tmp_val);
		if (cipsov4 == NULL)
			goto add_free_domain;
    ...
}

The kapi path, netlbl_cfg_cipsov4_map_add(), returns -ENOSYS for the same case.

The CALIPSO entry is wrapped in IS_ENABLED(CONFIG_IPV6), which matches how netlabel_calipso.o is built.

The dump resume cursor uses fixed indices, and CALIPSO is only sent when protos_sent == 2. Wrapping the CIPSOv4 block in #if IS_ENABLED(CONFIG_CIPSO) on its own would mean CALIPSO is never sent when CIPSO=n. Would the cursor handling need to change as well?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de
#36 lore raw

Re: [PATCH 16/16 net-next v2] ipv4: make CONFIG_IPV4 boolean

In reply to Fernando Fernandez Mancera
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The commit message says this patch lets users "build IPv6-only".
- [Low] This patch makes CONFIG_IPV4 user-selectable, but two IPv4-only options in net/ipv4/Kconfig still have no depends on IPV4:…

--

ipv4: make CONFIG_IPV4 boolean

This patch turns CONFIG_IPV4 from a hidden def_bool y into a prompt that users can see. The prompt appears when IPV6 is enabled and defaults to INET. The goal is to allow an IPv6-only kernel build.

Quoted 6 lines
net/ipv4/Kconfig +0 -0
index 51bf05d9770c5..c7d36cfa4a1d2 100644
@@ -3,7 +3,15 @@
 # IP configuration

net/ipv4/Kconfig line 12

Quoted 10 lines
net/ipv4/Kconfig +7 -1
 #
 config IPV4
-	def_bool y
+	bool "The IPv4 protocol" if IPV6
+	default INET
+	help
+	  Support for IP version 4 (IPv4).
+
+	  Disabling this option compiles the kernel networking stack without
+	  IPv4 support, resulting in a IPv6-only system.

[Severity: Medium]
Is "IPv6-only system" an accurate description of what IPV4=n produces?

This prompt makes IPV4=n reachable, so every existing "depends on IPV4" in the tree now takes effect. Several of those also gate IPv6 features.

Both netfilter menus depend on IPV4:

net/netfilter/Kconfig:
menu "Core Netfilter Configuration"

	depends on INET && IPV4 && NETFILTER

net/ipv6/netfilter/Kconfig:

	depends on INET && IPV6 && NETFILTER && IPV4

That means there is no ip6tables and no nftables for IPv6.

XFRM depends on IPV4 as well:

net/xfrm/Kconfig:
config XFRM

	bool
	depends on INET && IPV4

INET6_AH, INET6_ESP, INET6_IPCOMP, IPV6_MIP6 and IPV6_VTI in net/ipv6/Kconfig are gated the same way, so IPv6 IPsec is lost.

SYN_COOKIES has "depends on IPV4", and net/ipv6/Makefile builds the IPv6 side only under that symbol:

ipv6-$(CONFIG_SYN_COOKIES) += syncookies.o

As a result, IPv6 TCP listeners have no SYN cookies. TCP_MD5SIG and TCP_AO are also gated on IPV4, even though tcp_ipv6.c and ipv6/tcp_ao.o implement them for IPv6.

Other options that drop out:

- IPV6_MROUTE, IPV6_TUNNEL, IPV6_GRE, IPV6_SIT and ILA
- the SEG6, RPL and IOAM6 lwtunnels
- the drivers BONDING, WIREGUARD, OVPN, IPVLAN, VXLAN, GENEVE, BAREUDP, GTP, PFCP, AMT, NET_VRF and NETDEVSIM

A user who follows this help text gets an IPv6 host with no packet filter, no SYN cookies, no IPsec and no multicast routing. With olddefconfig, these options are also dropped without any message.

Could the help text and changelog mention these limitations? Or should the IPv6 side of these dependencies be relaxed before the prompt is exposed?

net/ipv4/Kconfig line 17

Quoted 5 lines
net/ipv4/Kconfig +2 -0
+
+	  If unsure, say Y.
 
 config IP_MULTICAST
 	bool "IP: multicasting"

[Severity: Low]
Now that IPV4 is optional, should IP_MULTICAST get a "depends on IPV4"? The same question applies to NET_IPGRE_DEMUX further down in this file.

Similar options such as NET_IPGRE, IP_MROUTE, IP_PNP, SYN_COOKIES and TCP_MD5SIG already have that dependency. With IPV4=n, these two prompts are still offered, and existing configs keep them enabled.

For IP_MULTICAST, this looks like it can break the s390 build. QETH uses IP_MULTICAST as its only IPv4 gate:

drivers/s390/net/Kconfig:
config QETH

	def_tristate y
	prompt "Gigabit Ethernet device support"
	depends on CCW && NETDEVICES && IP_MULTICAST && QDIO && ETHERNET

QETH_L3 builds qeth_l3_main.c, which calls devinet.c helpers without any condition:

drivers/s390/net/qeth_l3_main.c:qeth_l3_register_notifiers() {
	...
	rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
	if (rc)
		return rc;
	...
}

qeth_l3_unregister_notifiers() calls unregister_inetaddr_notifier() the same way.

devinet.o is only built under obj-$(CONFIG_IPV4) in net/ipv4/Makefile, and include/linux/inetdevice.h has no stubs for these functions.

Would a config with IPV6=y, IPV4=n, IP_MULTICAST=y and QETH_L3 enabled fail to link, with undefined references to register_inetaddr_notifier() and unregister_inetaddr_notifier()?

NET_IPGRE_DEMUX still builds gre.o, and gre_init() in net/ipv4/gre_demux.c still registers an IPv4 protocol handler:

	if (inet_add_protocol(&net_gre_protocol, IPPROTO_GRE) < 0) {

No IPv4 receive path exists in this configuration. The in-tree users of this module, NET_IPGRE and IPV6_GRE, both require IPV4, so the module does nothing.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260928193046.6698-1-fmancera%40suse.de