Allow compiling an IPv6-only kernel network stack
Subsystems (48)
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 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.
Finally, CONFIG_IPV4 is exposed in Kconfig as an explicit boolean, defaulting to 'y' to preserve existing configurations.
The bloat-o-meter diff for x86_64 with dualstack and IPv6 disabled:
text data bss dec hex filename
31211950 8946390 1121076 41279416 275dfb8 vmlinux.dual 27464679 8008670 1069040 36542389 22d97b5 vmlinux.ipv6
add/remove: 52/25057 grow/shrink: 58/565 up/down: 937258/-4632671 (-3695413)
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 on this series:
If this architectural direction is accepted, immediate follow-up work within this series will focus on cleaning up header inclusions in files where code was split, and resolving formatting warnings inherited from the moved code. Additionally, work will be done to minimize function guarding churn and ensure that IPv4-specific sysctls like IGMP are completely removed when CONFIG_IPV4=n. Network drivers carrying hard IPv4 assumptions will also be adapted.
Follow-up out of the 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.
Open questions:
1. Would it be preferable to introduce a dedicated NIPA build job with an IPv6-only configuration to prevent future compilation regressions?
2. Where is the preferred architectural location for ip_generic_getfrag(), as it currently resides out-of-place in net/ipv4/af_inet.c?
3. To eliminate noise in this series, files like udp.c, tcp.c, and raw.c remain in net/ipv4/. Would you prefer to relocate these shared transport files to net/core/?
Conclusions:
Looking at the numbers we have so far, the overall change is positive in my opinion. Having said so, the main burden it introduces is the noise in git which will be cumbersome when trying to identify breaking commits or blames.
Fernando Fernandez Mancera (13):
net: 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
net: tcp: move protocol agnostic TCP functions out of tcp_ipv4.c
net: raw: split IPv4 specific logic into raw_ipv4.c
net: udp: split IPv4 specific logic into udp_ipv4.c
net: icmp: split IPv4 specific logic into icmp_ipv4.c
net: ping: split IPv4 specific logic into ping_ipv4.c
net: fib: split common nexthop logic to fib_core.c
net: tunnel: guard IPv4 tunnel functions with CONFIG_IPV4
net: cipso: guard IPv4 packet manipulation functions
netfilter: ipv4: guard ip_route_me_harder() with CONFIG_IPV4
net: ipv4: make CONFIG_IPV4 boolean
drivers/infiniband/Kconfig | 2 +- drivers/net/Kconfig | 24 +- drivers/net/ethernet/broadcom/Kconfig | 2 + 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/netronome/Kconfig | 1 + drivers/net/ethernet/qlogic/Kconfig | 2 + 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/bnx2fc/Kconfig | 1 + drivers/scsi/bnx2i/Kconfig | 1 + drivers/scsi/cxgbi/cxgb3i/Kconfig | 2 +- drivers/scsi/cxgbi/cxgb4i/Kconfig | 2 +- drivers/target/iscsi/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/icmp.h | 1 + include/net/ip.h | 104 +- include/net/ip_fib.h | 43 + include/net/route.h | 14 + include/net/tcp.h | 16 +- net/Kconfig | 6 +- net/batman-adv/Kconfig | 1 + net/bridge/Kconfig | 3 +- net/bridge/netfilter/Kconfig | 6 +- net/core/Makefile | 2 +- net/core/dev_ioctl.c | 4 + net/core/fib_core.c | 146 ++ net/core/filter.c | 22 +- net/core/neighbour.c | 4 + net/ipv4/Kconfig | 29 +- net/ipv4/Makefile | 24 +- net/ipv4/af_inet.c | 114 +- net/ipv4/cipso_ipv4.c | 10 + net/ipv4/fib_semantics.c | 142 -- net/ipv4/icmp.c | 1407 +------------ net/ipv4/icmp_ipv4.c | 1425 +++++++++++++ net/ipv4/inet_connection_sock.c | 2 +- net/ipv4/inet_hashtables.c | 4 + net/ipv4/ip_output.c | 18 - net/ipv4/ip_tunnel_core.c | 11 + net/ipv4/netfilter.c | 4 + net/ipv4/netfilter/Kconfig | 2 +- net/ipv4/netlink.c | 2 + net/ipv4/nexthop.c | 2 +- net/ipv4/ping.c | 215 +- net/ipv4/ping_ipv4.c | 225 +++ net/ipv4/proc.c | 2 + net/ipv4/raw.c | 844 -------- net/ipv4/raw_diag.c | 4 + net/ipv4/raw_ipv4.c | 875 ++++++++ net/ipv4/sysctl_net_ipv4.c | 2 + net/ipv4/tcp.c | 1291 ++++++++++++ net/ipv4/tcp_bpf.c | 2 + net/ipv4/tcp_ipv4.c | 1299 +----------- net/ipv4/udp.c | 1733 ---------------- net/ipv4/udp_bpf.c | 6 + net/ipv4/udp_diag.c | 12 + net/ipv4/udp_ipv4.c | 1773 +++++++++++++++++ net/ipv4/udp_offload.c | 10 + net/ipv6/Kconfig | 17 +- net/ipv6/af_inet6.c | 5 + net/ipv6/datagram.c | 14 + net/ipv6/ip6_fib.c | 2 + net/ipv6/ipv6_sockglue.c | 5 + net/ipv6/netfilter/Kconfig | 2 +- net/ipv6/tcp_ipv6.c | 25 +- net/ipv6/udp.c | 18 + net/l2tp/Kconfig | 2 +- net/mac80211/Kconfig | 2 +- net/mpls/Kconfig | 1 + net/mptcp/Kconfig | 2 +- net/netfilter/Kconfig | 2 +- net/netfilter/ipset/Kconfig | 2 +- net/netfilter/ipvs/Kconfig | 2 +- net/openvswitch/Kconfig | 2 +- net/packet/Kconfig | 1 + net/rds/Kconfig | 2 +- net/rxrpc/Kconfig | 2 +- net/sched/Kconfig | 2 +- net/sctp/Kconfig | 2 +- net/smc/Kconfig | 2 +- net/sunrpc/Kconfig | 2 +- net/tipc/Kconfig | 2 +- net/xfrm/Kconfig | 12 +- 97 files changed, 6314 insertions(+), 5750 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.54.0
RFC PATCH 1/13 net: 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/net/Kconfig | 24 ++++++++++--------- drivers/net/ethernet/broadcom/Kconfig | 2 ++ 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/netronome/Kconfig | 1 + drivers/net/ethernet/qlogic/Kconfig | 2 ++ 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/bnx2fc/Kconfig | 1 + drivers/scsi/bnx2i/Kconfig | 1 + drivers/scsi/cxgbi/cxgb3i/Kconfig | 2 +- drivers/scsi/cxgbi/cxgb4i/Kconfig | 2 +- drivers/target/iscsi/Kconfig | 2 +- fs/Kconfig | 1 + fs/afs/Kconfig | 2 +- fs/nfs/Kconfig | 2 +- fs/nfsd/Kconfig | 2 +- net/Kconfig | 6 ++--- net/batman-adv/Kconfig | 1 + net/bridge/Kconfig | 3 ++- net/bridge/netfilter/Kconfig | 6 ++--- 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/mac80211/Kconfig | 2 +- net/mpls/Kconfig | 1 + net/mptcp/Kconfig | 2 +- net/netfilter/Kconfig | 2 +- net/netfilter/ipset/Kconfig | 2 +- net/netfilter/ipvs/Kconfig | 2 +- net/openvswitch/Kconfig | 2 +- net/packet/Kconfig | 1 + net/rds/Kconfig | 2 +- net/rxrpc/Kconfig | 2 +- net/sched/Kconfig | 2 +- net/sctp/Kconfig | 2 +- net/smc/Kconfig | 2 +- net/sunrpc/Kconfig | 2 +- net/tipc/Kconfig | 2 +- net/xfrm/Kconfig | 12 ++++++++-- 53 files changed, 121 insertions(+), 65 deletions(-)
drivers/infiniband/Kconfig +1 -1
@@ -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/net/Kconfig +13 -11
@@ -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
@@ -164,6 +164,7 @@ source "drivers/net/team/Kconfig" config MACVLAN tristate "MAC-VLAN support" + depends on IPV4 help This allows one to create virtual interfaces that map packets to or from specific MAC addresses to a particular interface.
@@ -198,7 +199,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 +230,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 +245,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 +260,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 +272,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 +289,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 +302,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 +472,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 +606,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/broadcom/Kconfig +2 -0
@@ -97,6 +97,7 @@ config BNX2 config CNIC tristate "QLogic CNIC support" + depends on IPV4 depends on PCI select BNX2 select UIO
@@ -208,6 +209,7 @@ config BNXT tristate "Broadcom NetXtreme-C/E support" depends on PCI depends on PTP_1588_CLOCK_OPTIONAL + depends on IPV4 select FW_LOADER select CRC32 select NET_DEVLINK
drivers/net/ethernet/chelsio/Kconfig +1 -1
@@ -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
@@ -193,6 +193,7 @@ config IXGBE_DCB config IXGBE_IPSEC bool "IPSec XFRM cryptography-offload acceleration" + depends on IPV4 depends on IXGBE depends on XFRM_OFFLOAD default y
@@ -219,6 +220,7 @@ config IXGBEVF config IXGBEVF_IPSEC bool "IPSec XFRM cryptography-offload acceleration" + depends on IPV4 depends on IXGBEVF depends on XFRM_OFFLOAD default y
drivers/net/ethernet/marvell/prestera/Kconfig +1 -0
@@ -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 select NET_DEVLINK select PHYLINK help
drivers/net/ethernet/mellanox/mlx5/core/Kconfig +2 -1
@@ -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 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
@@ -53,6 +53,7 @@ config MLXSW_I2C config MLXSW_SPECTRUM tristate "Mellanox Technologies Spectrum family support" + depends on IPV4 depends on MLXSW_CORE && MLXSW_PCI && NET_SWITCHDEV && VLAN_8021Q depends on PSAMPLE || PSAMPLE=n depends on BRIDGE || BRIDGE=n
drivers/net/ethernet/netronome/Kconfig +1 -0
@@ -18,6 +18,7 @@ if NET_VENDOR_NETRONOME config NFP tristate "Netronome(R) NFP4000/NFP6000 NIC driver" + depends on IPV4 depends on PCI_MSI depends on VXLAN || VXLAN=n depends on TLS && TLS_DEVICE || TLS_DEVICE=n
drivers/net/ethernet/qlogic/Kconfig +2 -0
@@ -29,6 +29,7 @@ config QLA3XXX config QLCNIC tristate "QLOGIC QLCNIC 1/10Gb Converged Ethernet NIC Support" depends on PCI + depends on IPV4 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 depends on PCI select FW_LOADER help
drivers/net/ethernet/sfc/Kconfig +1 -0
@@ -18,6 +18,7 @@ if NET_VENDOR_SOLARFLARE config SFC tristate "Solarflare SFC9100/EF100-family support" + depends on IPV4 depends on PCI depends on PTP_1588_CLOCK_OPTIONAL select MDIO
drivers/net/ethernet/stmicro/stmmac/Kconfig +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config STMMAC_ETH tristate "STMicroelectronics Multi-Gigabit Ethernet driver" + depends on IPV4 depends on HAS_IOMEM && HAS_DMA depends on PTP_1588_CLOCK_OPTIONAL depends on ETHTOOL_NETLINK
drivers/net/ethernet/via/Kconfig +1 -0
@@ -45,6 +45,7 @@ config VIA_RHINE_MMIO config VIA_VELOCITY tristate "VIA Velocity support" + depends on IPV4 depends on (PCI || (OF_ADDRESS && OF_IRQ)) depends on HAS_DMA select CRC32
drivers/net/ppp/Kconfig +1 -0
@@ -160,6 +160,7 @@ config PPPOE_HASH_BITS config PPTP tristate "PPP over IPv4 (PPTP)" + depends on IPV4 depends on NET_IPGRE_DEMUX select PPPOX help
drivers/net/wireless/broadcom/brcm80211/brcmfmac/Kconfig +1 -0
@@ -1,6 +1,7 @@ config BRCMFMAC tristate "Broadcom FullMAC WLAN driver" depends on CFG80211 + depends on IPV4 select BRCMUTIL help This module adds support for wireless adapters based on Broadcom
drivers/net/wireless/intel/iwlwifi/Kconfig +1 -0
@@ -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 depends on IWLMEI || !IWLMEI select FW_LOADER help
drivers/nvme/host/Kconfig +1 -1
@@ -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
@@ -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/bnx2fc/Kconfig +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config SCSI_BNX2X_FCOE tristate "QLogic FCoE offload support" + depends on IPV4 depends on PCI depends on LIBFC depends on LIBFCOE
drivers/scsi/bnx2i/Kconfig +1 -0
@@ -2,6 +2,7 @@ config SCSI_BNX2_ISCSI tristate "QLogic NetXtreme II iSCSI support" depends on NET + depends on IPV4 depends on PCI select SCSI_ISCSI_ATTRS select NETDEVICES
drivers/scsi/cxgbi/cxgb3i/Kconfig +1 -1
@@ -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
@@ -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
@@ -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
fs/Kconfig +1 -0
@@ -360,6 +360,7 @@ config GRACE_PERIOD config LOCKD tristate + depends on IPV4 depends on FILE_LOCKING select CRC32 select GRACE_PERIOD
fs/afs/Kconfig +1 -1
@@ -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
@@ -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
@@ -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 +3 -3
@@ -385,7 +385,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
@@ -452,7 +452,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
@@ -474,7 +474,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 +1 -0
@@ -9,6 +9,7 @@ config BATMAN_ADV tristate "B.A.T.M.A.N. Advanced Meshing Protocol" + depends on IPV4 select CRC32 help B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is
net/bridge/Kconfig +2 -1
@@ -7,6 +7,7 @@ config BRIDGE tristate "802.1d Ethernet Bridging" select LLC select STP + depends on IPV4 help If you say Y here, then your Linux box will be able to act as an Ethernet bridge, which means that the different Ethernet segments it
@@ -36,7 +37,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 +3 -3
@@ -4,7 +4,7 @@ # # menuconfig NF_TABLES_BRIDGE - depends on BRIDGE && NETFILTER && NF_TABLES + depends on BRIDGE && NETFILTER && NF_TABLES && IPV4 select NETFILTER_FAMILY_BRIDGE tristate "Ethernet Bridge nf_tables support"
@@ -43,7 +43,7 @@ config NF_CONNTRACK_BRIDGE config BRIDGE_NF_EBTABLES_LEGACY tristate "Legacy EBTABLES support" depends on BRIDGE && NETFILTER_XTABLES_LEGACY - depends on NETFILTER_XTABLES + depends on NETFILTER_XTABLES && IPV4 default n help Legacy ebtables packet/frame classifier.
@@ -52,7 +52,7 @@ config BRIDGE_NF_EBTABLES_LEGACY menuconfig BRIDGE_NF_EBTABLES tristate "Ethernet Bridge tables (ebtables) support" - depends on BRIDGE && NETFILTER && NETFILTER_XTABLES + depends on BRIDGE && NETFILTER && NETFILTER_XTABLES && IPV4 select NETFILTER_FAMILY_BRIDGE help ebtables is a general, extensible frame/packet identification
net/ipv4/Kconfig +18 -3
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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/mac80211/Kconfig +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config MAC80211 tristate "Generic IEEE 802.11 Networking Stack (mac80211)" - depends on CFG80211 + depends on CFG80211 && IPV4 select CRYPTO select CRYPTO_LIB_AES_CBC_MACS select CRYPTO_LIB_ARC4
net/mpls/Kconfig +1 -0
@@ -25,6 +25,7 @@ config NET_MPLS_GSO config MPLS_ROUTING tristate "MPLS: routing support" + depends on IPV4 depends on NET_IP_TUNNEL || NET_IP_TUNNEL=n depends on PROC_SYSCTL help
net/mptcp/Kconfig +1 -1
@@ -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
@@ -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
@@ -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
@@ -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/openvswitch/Kconfig +1 -1
@@ -5,7 +5,7 @@ config OPENVSWITCH tristate "Open vSwitch" - depends on INET + depends on INET && IPV4 depends on !NF_CONNTRACK || \ (NF_CONNTRACK && ((!NF_DEFRAG_IPV6 || NF_DEFRAG_IPV6) && \ (!NF_NAT || NF_NAT) && \
net/packet/Kconfig +1 -0
@@ -5,6 +5,7 @@ config PACKET tristate "Packet socket" + depends on IPV4 help The Packet protocol is used by applications which communicate directly with network devices without an intermediate network
net/rds/Kconfig +1 -1
@@ -2,7 +2,7 @@ config RDS tristate "The Reliable Datagram Sockets Protocol" - depends on INET + depends on INET && IPV4 help The RDS (Reliable Datagram Sockets) protocol provides reliable, sequenced delivery of datagrams over Infiniband or TCP.
net/rxrpc/Kconfig +1 -1
@@ -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
@@ -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
@@ -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/smc/Kconfig +1 -1
@@ -1,7 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only config SMC tristate "SMC socket protocol family" - depends on INET && INFINIBAND && DIBS + depends on INET && INFINIBAND && DIBS && IPV4 help SMC-R provides a "sockets over RDMA" solution making use of RDMA over Converged Ethernet (RoCE) technology to upgrade
net/sunrpc/Kconfig +1 -1
@@ -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 -1
@@ -5,7 +5,7 @@ menuconfig TIPC tristate "The TIPC Protocol" - depends on INET + depends on INET && IPV4 help The Transparent Inter Process Communication (TIPC) protocol is specially designed for intra cluster communication. This protocol
net/xfrm/Kconfig +10 -2
@@ -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.
@@ -140,6 +146,7 @@ config NET_KEY_MIGRATE config XFRM_IPTFS tristate "IPsec IP-TFS/AGGFRAG (RFC 9347) encapsulation support" + depends on IPV4 depends on XFRM help Information on the IP-TFS/AGGFRAG encapsulation can be found
@@ -156,5 +163,6 @@ config XFRM_IPTFS config XFRM_ESPINTCP bool + depends on IPV4 endif # INET
Signature · 1 line
2.54.0
Re: [PATCH 01/13 RFC net-next] net: ipv4: introduce CONFIG_IPV4 to decouple the IPv4 stack
Quoted 9 lines · Fernando Fernandez Mancera
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_IPV4Kconfigsymbol, which is set to 'def_booly' for now. This does not allow to completely disable the IPv4 stack yet but it lays the necessary build-system work for that goal.
I expect this will cause additional (trivial) build regression in the next step when randconfig builds run into obscure corner cases, either with INET=y IPV4=n IPV6=y or with INET=y IPV4=n IPV6=n.
I can probably give your patch (with IPV4 visible or disabled) an early go on the randconfig tree to find these more quickly. If I run into regressions, should I just add more 'depends on IPV4', or do you have other plans?
Should we have some logic to ensure that at least one of IPV4 or IPV6 is enabled? I think this would work
config IPV4
bool "The IPv4 protocol" if IPV6
default INET
which only allows turning IPV4 off if IPV6 has enabled.
Arnd
Re: [PATCH 01/13 RFC net-next] net: ipv4: introduce CONFIG_IPV4 to decouple the IPv4 stack
Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · Fernando Fernandez Mancera
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_IPV4Kconfigsymbol, which is set to 'def_booly' for now. This does not allow to completely disable the IPv4 stack yet but it lays the necessary build-system work for that goal.
Quoted 9 lines
I expect this will cause additional (trivial) build regression in the next step when randconfig builds run into obscure corner cases, either with INET=y IPV4=n IPV6=y or with INET=y IPV4=n IPV6=n.
I can probably give your patch (with IPV4 visible or disabled) an early go on the randconfig tree to find these more quickly. If I run into regressions, should I just add more 'depends on IPV4', or do you have other plans?
Yes, I have a job running randconfig and verifying nothing breaks. If something breaks and it isn't core networking stack I would just make the Kconfig symbol depend on IPv4.
Then later we will have more time to write a dedicate patch so it does not depend on IPv4.
Quoted 9 lines
Should we have some logic to ensure that at least one of IPV4 or IPV6 is enabled? I think this would work
config IPV4
bool "The IPv4 protocol" if IPV6
default INETwhich only allows turning IPV4 off if IPV6 has enabled.
I do wonder, should we? I mean, I didn't try it off but I don't see why we should not allow a pure L2 system..
Thanks,
Fernando.
Re: [PATCH 01/13 RFC net-next] net: ipv4: introduce CONFIG_IPV4 to decouple the IPv4 stack
Quoted 22 lines · Fernando Fernandez Mancera
Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · Fernando Fernandez Mancera
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_IPV4Kconfigsymbol, which is set to 'def_booly' for now. This does not allow to completely disable the IPv4 stack yet but it lays the necessary build-system work for that goal.Quoted 9 lines
I expect this will cause additional (trivial) build regression in the next step when randconfig builds run into obscure corner cases, either with INET=y IPV4=n IPV6=y or with INET=y IPV4=n IPV6=n.
I can probably give your patch (with IPV4 visible or disabled) an early go on the randconfig tree to find these more quickly. If I run into regressions, should I just add more 'depends on IPV4', or do you have other plans?
Quoted 6 lines
Yes, I have a job running randconfig and verifying nothing breaks. If something breaks and it isn't core networking stack I would just make the
Kconfigsymbol depend on IPv4.Then later we will have more time to write a dedicate patch so it does not depend on IPv4.
Ok
Quoted 7 lines
Quoted 7 lines
Should we have some logic to ensure that at least one of IPV4 or IPV6 is enabled? I think this would work
config IPV4
bool "The IPv4 protocol" if IPV6
default INET
Quoted 5 lines
Quoted 2 lines
which only allows turning IPV4 off if IPV6 has enabled.
I do wonder, should we? I mean, I didn't try it off but I don't see why we should not allow a pure L2 system..
I expected a pure L2 system to be CONFIG_ETHERNET=y CONFIG_INET=n.
Which user-visible parts of CONFIG_INET would you want keep working when both v4 and v6 are disabled?
Arnd
Re: [PATCH 01/13 RFC net-next] net: ipv4: introduce CONFIG_IPV4 to decouple the IPv4 stack
Quoted 42 lines · Arnd Bergmann
Quoted 22 lines · Fernando Fernandez Mancera
Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · Fernando Fernandez Mancera
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_IPV4Kconfigsymbol, which is set to 'def_booly' for now. This does not allow to completely disable the IPv4 stack yet but it lays the necessary build-system work for that goal.Quoted 9 lines
I expect this will cause additional (trivial) build regression in the next step when randconfig builds run into obscure corner cases, either with INET=y IPV4=n IPV6=y or with INET=y IPV4=n IPV6=n.
I can probably give your patch (with IPV4 visible or disabled) an early go on the randconfig tree to find these more quickly. If I run into regressions, should I just add more 'depends on IPV4', or do you have other plans?
Quoted 6 lines
Yes, I have a job running randconfig and verifying nothing breaks. If something breaks and it isn't core networking stack I would just make the
Kconfigsymbol depend on IPv4.Then later we will have more time to write a dedicate patch so it does not depend on IPv4.
Ok
Quoted 10 lines
Quoted 9 lines
Should we have some logic to ensure that at least one of IPV4 or IPV6 is enabled? I think this would work
config IPV4
bool "The IPv4 protocol" if IPV6
default INETwhich only allows turning IPV4 off if IPV6 has enabled.
Quoted 8 lines
Quoted 2 lines
I do wonder, should we? I mean, I didn't try it off but I don't see why we should not allow a pure L2 system..
I expected a pure L2 system to be
CONFIG_ETHERNET=yCONFIG_INET=n.Which user-visible parts of
CONFIG_INETwould you want keep working when both v4 and v6 are disabled?
Yes, you are right. So I think introducing something as you proposed makes sense. Right now I cannot think about something needed from INET for pure L2.
Thank you!
Fernando.
[email protected]
AI reviewRe: [PATCH 01/13 RFC net-next] net: ipv4: introduce CONFIG_IPV4 to decouple the IPv4 stack
In reply to Fernando Fernandez ManceraSashiko has reviewed this patch and found no issues.
Quoted 10 lines
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_IPV4Kconfigsymbol, which is set to 'def_booly' for now. This does not allow to completely disable the IPv4 stack yet but it lays the necessary build-system work for that goal.
Quoted 7 lines
In addition, multiple subsystems
Kconfigsymbols 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 theKconfigsymbol to bool and remove the dependency on IPv4 where it makes sense.Signed-off-by Fernando Fernandez Mancera <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
RFC PATCH 2/13 net: core: add IPv4 fallback stubs and guards for CONFIG_IPV4=n
In reply to Fernando Fernandez ManceraTo 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 | 104 ++++++++++++++++++++++---- include/net/route.h | 8 ++ net/core/dev_ioctl.c | 4 + net/core/filter.c | 18 ++--- net/core/neighbour.c | 4 + net/ipv4/inet_hashtables.c | 4 + 7 files changed, 122 insertions(+), 28 deletions(-)
include/linux/indirect_call_wrapper.h +5 -3
@@ -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 +88 -16
153 lines not on this page · raw message
include/net/route.h +8 -0
@@ -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 +4 -0
@@ -39,6 +39,7 @@ static int dev_ifname(struct net *net, struct ifreq *ifr)*/ int dev_ifconf (struct net *net,struct ifconf __user *uifc) { +#if IS_ENABLED (CONFIG_IPV4 )struct net_device *dev;void __user *pos;size_t size;
@@ -82,6 +83,9 @@ int dev_ifconf(struct net *net, struct ifconf __user *uifc)rtnl_net_unlock (net);return put_user (total, &uifc->ifc_len); +#else +return -EAFNOSUPPORT ; +#endif }static int dev_getifmap (struct net_device *dev,struct ifreq *ifr)
net/core/filter.c +9 -9
@@ -2314,7 +2314,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) {
@@ -2423,7 +2423,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)
@@ -5685,7 +5685,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);
@@ -5722,7 +5722,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);
@@ -6212,7 +6212,7 @@ static int bpf_fib_set_fwd_params(struct bpf_fib_lookup *params, u32 mtu) }#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) {
@@ -6504,7 +6504,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);
@@ -6545,7 +6545,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 ;
@@ -12076,7 +12076,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
@@ -12099,7 +12099,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
net/core/neighbour.c +4 -0
@@ -3208,9 +3208,13 @@ int neigh_xmit(int index, struct net_device *dev, goto out_kfree_skb; }if (index ==NEIGH_ARP_TABLE ) { +#if IS_ENABLED (CONFIG_IPV4 )u32 key = *((u32 *)addr); neigh =__ipv4_neigh_lookup_noref (dev, key); +#else + goto out_kfree_skb; +#endif }else { neigh =__neigh_lookup_noref (tbl, addr, dev); }
net/ipv4/inet_hashtables.c +4 -0
@@ -581,6 +581,7 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row, bool rcu_lookup, u32 hash) { +#if IS_ENABLED (CONFIG_IPV4 )//TODO: should this be moved out of here? struct inet_hashinfo *hinfo = death_row->hashinfo;struct inet_sock *inet =inet_sk (sk);__be32 daddr = inet->inet_rcv_saddr;
@@ -651,6 +652,9 @@ static int __inet_check_established(struct inet_timewait_death_row *death_row, not_unique:spin_unlock (lock);return -EADDRNOTAVAIL ; +#else +return -EAFNOSUPPORT ; +#endif }static u64 inet_sk_port_offset (const struct sock *sk)
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 02/13 RFC net-next] net: core: add IPv4 fallback stubs and guards for CONFIG_IPV4=n
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider: - [Critical] The `SIOCGIFCONF` ioctl handler returns `-EAFNOSUPPORT` instead of an empty list, breaking…
Thank you for your contribution! Sashiko AI review found 5 potential issue(s) to consider:
- [Critical] The SIOCGIFCONF ioctl handler returns -EAFNOSUPPORT instead of an empty list, breaking UAPI.
- [High] RCU read lock leak in neigh_xmit() when CONFIG_IPV4 is disabled.
- [Low] Missing stubs for IPv4 functions called by IPv6 code leads to undefined references.
- [Low] Missing stubs for IP output functions and unconditional tcp_prot reference lead to undefined reference linker errors.
- [Low] Undefined reference to tcp_twsk_unique in IPv6 hashtables when CONFIG_IPV4 is disabled.
--
--- Patch [2]: [PATCH 02/13 RFC net-next] net: core: add IPv4 fallback stubs and guards for CONFIG_IPV4=n --- commit c3ba15b9e372b7ea2df4737d8f114c24f3baec0c
Author: Fernando Fernandez Mancera <[email protected]>
net: core: add IPv4 fallback stubs and guards for CONFIG_IPV4=n
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.
Quoted 4 lines
include/net/ip.h +0
-0
[ ... ]
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 289
Quoted 10 lines
include/net/ip.h +10
-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]
Could these un-stubbed declarations cause undefined reference errors during linking?
The declarations for ip_generic_getfrag(), ip_send_skb(), ip_push_pending_frames(), and ip_queue_xmit() are placed outside the CONFIG_IPV4 guard without providing static inline stubs. If net/ipv4/af_inet.c and net/ipv4/udp.c are compiled without CONFIG_IPV4, references to these functions and tcp_prot will break the build.
Additionally, are there missing stubs for IPv4 functions called directly by the IPv6 subsystem? When building with CONFIG_IPV6=y and CONFIG_IPV4=n, IPv6 mapped socket code directly calls IPv4 functions:
net/ipv6/datagram.c:ipv6_mapped_datagram_connect() calls __ip4_datagram_connect() net/ipv6/tcp_ipv6.c:tcp_v6_connect() calls tcp_v4_connect() net/ipv6/inet6_hashtables.c:__inet6_check_established() calls tcp_twsk_unique()
Without stubs for these functions, or proper guards in the IPv6 code, the linker will fail.
Quoted 12 lines
net/core/dev_ioctl.c +1
-0@@ -39,6 +39,7 @@ static int dev_ifname(struct net *net, struct ifreq *ifr)*/ int dev_ifconf (struct net *net,struct ifconf __user *uifc) { +#if IS_ENABLED (CONFIG_IPV4 )struct net_device *dev;void __user *pos;size_t size;
[ ... ]
net/core/dev_ioctl.c int dev_ifconf(struct net *net, struct ifconf __user *uifc) · line 89
Quoted 8 lines
net/core/dev_ioctl.c +3
-0@@ -82,6 +83,9 @@ int dev_ifconf(struct net *net, struct ifconf __user *uifc)rtnl_net_unlock (net);return put_user (total, &uifc->ifc_len); +#else +return -EAFNOSUPPORT ; +#endif }
[Severity: Critical]
Will this break legacy userspace applications that enumerate interfaces?
By returning -EAFNOSUPPORT instead of an empty list, the behavior changes for the SIOCGIFCONF ioctl when the kernel is compiled without IPv4.
Could this branch instead return 0 interfaces via put_user(0, &uifc->ifc_len) to maintain backwards compatibility for tools expecting the ioctl to succeed?
Quoted 8 lines
net/core/neighbour.c +0
-0@@ -3208,9 +3208,13 @@ int neigh_xmit(int index, struct net_device *dev, goto out_kfree_skb; }if (index ==NEIGH_ARP_TABLE ) {
net/core/neighbour.c int neigh_xmit(int index, struct net_device *dev, · line 3220
Quoted 10 lines
net/core/neighbour.c +4
-0+#if IS_ENABLED (CONFIG_IPV4 )u32 key = *((u32 *)addr); neigh =__ipv4_neigh_lookup_noref (dev, key); +#else + goto out_kfree_skb; +#endif }else { neigh =__neigh_lookup_noref (tbl, addr, dev); }
[Severity: High]
Does this error path leak the RCU read lock?
The function neigh_xmit() acquires the rcu_read_lock() earlier, and this goto out_kfree_skb jumps directly to the cleanup label, missing the rcu_read_unlock() call.
Could this stall RCU grace periods if a packet is transmitted where index == NEIGH_ARP_TABLE when CONFIG_IPV4 is disabled?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
RFC PATCH 3/13 net: inet: relocate ip_generic_getfrag and guard IPv4 socket logic
In reply to Fernando Fernandez ManceraTo 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 | 96 +++++++++++++++++++++++++++++++++++++------- net/ipv4/ip_output.c | 18 --------- net/ipv6/af_inet6.c | 5 +++ net/ipv6/datagram.c | 12 ++++++ 4 files changed, 99 insertions(+), 32 deletions(-)
net/ipv4/af_inet.c +82 -14
@@ -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. */
@@ -425,8 +447,10 @@ int inet_release(struct socket *sock)if (!sk->sk_kern_sock)BPF_CGROUP_RUN_PROG_INET_SOCK_RELEASE (sk); +#if IS_ENABLED (CONFIG_IPV4 )/* Applications forget to leave groups before exiting */ ip_mc_drop_socket (sk); +#endif /* If linger is set, we don't return until the close * is complete. Otherwise we return immediately. The
@@ -478,6 +502,7 @@ EXPORT_SYMBOL(inet_bind);int __inet_bind (struct sock *sk,struct sockaddr_unsized *uaddr,int addr_len,u32 flags) { +#if IS_ENABLED (CONFIG_IPV4 )struct sockaddr_in *addr = (struct sockaddr_in *)uaddr;struct inet_sock *inet =inet_sk (sk);struct net *net =sock_net (sk);
@@ -570,6 +595,9 @@ int __inet_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len,release_sock (sk); out:return err; +#else +return -EAFNOSUPPORT ; +#endif } int inet_dgram_connect(struct socket *sock, struct sockaddr_unsized *uaddr,
@@ -965,18 +993,24 @@ EXPORT_SYMBOL(inet_shutdown);int inet_ioctl (struct socket *sock,unsigned int cmd,unsigned long arg) {struct sock *sk = sock->sk; -int err =0 ; -struct net *net =sock_net (sk); +#if IS_ENABLED (CONFIG_IPV4 )void __user *p = (void __user *)arg; -struct ifreq ifr; +struct net *net =sock_net (sk);struct rtentry rt; +struct ifreq ifr; +#endif +int err =0 ;switch (cmd) {case SIOCADDRT :case SIOCDELRT : +#if IS_ENABLED (CONFIG_IPV4 )if (copy_from_user (&rt, p,sizeof (struct rtentry )))return -EFAULT ; err =ip_rt_ioctl (net, cmd, &rt); +#else + err = -EOPNOTSUPP ; +#endif break ;case SIOCRTMSG : err = -EINVAL ;
@@ -984,18 +1018,26 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)case SIOCDARP :case SIOCGARP :case SIOCSARP : +#if IS_ENABLED (CONFIG_IPV4 ) err =arp_ioctl (net, cmd, (void __user *)arg); +#else + err = -EOPNOTSUPP ; +#endif break ;case SIOCGIFADDR :case SIOCGIFBRDADDR :case SIOCGIFNETMASK :case SIOCGIFDSTADDR :case SIOCGIFPFLAGS : +#if IS_ENABLED (CONFIG_IPV4 )if (get_user_ifreq (&ifr,NULL , p))return -EFAULT ; err =devinet_ioctl (net, cmd, &ifr);if (!err &&put_user_ifreq (&ifr, p)) err = -EFAULT ; +#else + err = -EOPNOTSUPP ; +#endif break ;case SIOCSIFADDR :
@@ -1004,9 +1046,13 @@ int inet_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)case SIOCSIFDSTADDR :case SIOCSIFPFLAGS :case SIOCSIFFLAGS : +#if IS_ENABLED (CONFIG_IPV4 )if (get_user_ifreq (&ifr,NULL , p))return -EFAULT ; err =devinet_ioctl (net, cmd, &ifr); +#else + err = -EOPNOTSUPP ; +#endif break ;default :if (sk->sk_prot->ioctl)
@@ -1023,6 +1069,7 @@ EXPORT_SYMBOL(inet_ioctl);static int inet_compat_routing_ioctl (struct sock *sk,unsigned int cmd,struct compat_rtentry __user *ur) { +#if IS_ENABLED (CONFIG_IPV4 )compat_uptr_t rtdev;struct rtentry rt;
@@ -1038,6 +1085,9 @@ static int inet_compat_routing_ioctl(struct sock *sk, unsigned int cmd, rt.rt_dev =compat_ptr (rtdev);return ip_rt_ioctl (sock_net (sk), cmd, &rt); +#else +return -EOPNOTSUPP ; +#endif }static int inet_compat_ioctl (struct socket *sock,unsigned int cmd,unsigned long arg)
@@ -1156,6 +1206,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. */
@@ -1169,7 +1220,6 @@ static struct inet_protosw inetsw_array[] = .flags = INET_PROTOSW_PERMANENT | INET_PROTOSW_ICSK, }, - { .type = SOCK_DGRAM, .protocol = IPPROTO_UDP,
@@ -1196,6 +1246,7 @@ static struct inet_protosw inetsw_array[] = };#define INETSW_ARRAY_LEN ARRAY_SIZE(inetsw_array) +#endif void inet_register_protosw (struct inet_protosw *p) {
@@ -1261,6 +1312,7 @@ EXPORT_SYMBOL(inet_unregister_protosw);static int inet_sk_reselect_saddr (struct sock *sk) { +#if IS_ENABLED (CONFIG_IPV4 )struct inet_sock *inet =inet_sk (sk);__be32 old_saddr = inet->inet_saddr;__be32 daddr = inet->inet_daddr;
@@ -1312,6 +1364,9 @@ static int inet_sk_reselect_saddr(struct sock *sk)* uniqueness. Wait for troubles. */ return __sk_prot_rehash (sk); +#else +return -EAFNOSUPPORT ; +#endif }int inet_sk_rebuild_header (struct sock *sk)
@@ -1364,6 +1419,7 @@ void inet_sk_state_store(struct sock *sk, int newstate)struct sk_buff *inet_gso_segment (struct sk_buff *skb,netdev_features_t features) { +#if IS_ENABLED (CONFIG_IPV4 )bool udpfrag = false, fixedid = false, gso_partial, encap;struct sk_buff *segs =ERR_PTR (-EINVAL );const struct net_offload *ops;
@@ -1454,6 +1510,9 @@ struct sk_buff *inet_gso_segment(struct sk_buff *skb, out:return segs; +#else +return ERR_PTR (-EPROTONOSUPPORT ); +#endif } static struct sk_buff *ipip_gso_segment(struct sk_buff *skb,
@@ -1777,6 +1836,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) {/*
@@ -1827,8 +1890,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 */
@@ -1873,26 +1934,30 @@ 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 );if (rc) goto out; - rc =proto_register (&udp_prot,1 );if (rc) goto out_unregister_tcp_proto;
@@ -1929,7 +1994,6 @@ static int __init inet_init(void) };if (inet_add_protocol (&net_hotdata.udp_protocol,IPPROTO_UDP ) <0 )pr_crit ("%s: Cannot add UDP protocol\n" , __func__); - net_hotdata.tcp_protocol = (struct net_protocol ) { .handler = tcp_v4_rcv, .err_handler = tcp_v4_err,
@@ -1961,7 +2025,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__);
@@ -1983,6 +2047,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 */
@@ -1990,19 +2057,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:
@@ -2012,12 +2077,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) {
@@ -2054,3 +2121,4 @@ static int __init ipv4_proc_init(void)return 0 ; }#endif /* CONFIG_PROC_FS */ +#endif
net/ipv4/ip_output.c +0 -18
@@ -928,24 +928,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
@@ -299,6 +299,7 @@ int __inet6_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len,/* Check if the address belongs to the host. */ if (addr_type ==IPV6_ADDR_MAPPED ) { +#if IS_ENABLED (CONFIG_IPV4 )struct net_device *dev =NULL ;int chk_addr_ret;
@@ -329,6 +330,10 @@ int __inet6_bind(struct sock *sk, struct sockaddr_unsized *uaddr, int addr_len, err = -EADDRNOTAVAIL ; goto out; } +#else + err = -EADDRNOTAVAIL ; + goto out; +#endif }else {if (addr_type !=IPV6_ADDR_ANY ) {struct net_device *dev =NULL ;
net/ipv6/datagram.c +12 -0
@@ -33,10 +33,12 @@#include <linux/errqueue.h> #include <linux/uaccess.h> +#if IS_ENABLED (CONFIG_IPV4 )static bool ipv6_mapped_addr_any (const struct in6_addr *a) {return ipv6_addr_v4mapped (a) && (a->s6_addr32[3 ] ==0 ); } +#endif static void ip6_datagram_flow_key_init (struct flowi6 *fl6,const struct sock *sk)
@@ -153,10 +155,14 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr_unsized *uaddr,int err;if (usin->sin6_family ==AF_INET ) { +#if IS_ENABLED (CONFIG_IPV4 )if (ipv6_only_sock (sk))return -EAFNOSUPPORT ; err =__ip4_datagram_connect (sk, uaddr, addr_len); goto ipv4_connected; +#else +return -EAFNOSUPPORT ; +#endif }if (addr_len <SIN6_LEN_RFC2133 )
@@ -184,6 +190,7 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr_unsized *uaddr, daddr = &usin->sin6_addr;if (addr_type &IPV6_ADDR_MAPPED ) { +#if IS_ENABLED (CONFIG_IPV4 )struct sockaddr_in sin;if (ipv6_only_sock (sk)) {
@@ -217,6 +224,9 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr_unsized *uaddr, } goto out; +#else +return -ENETUNREACH ; +#endif }if (__ipv6_addr_needs_scope_id (addr_type)) {
@@ -522,10 +532,12 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len)ipv6_iface_scope_id (&sin->sin6_addr,IP6CB (skb)->iif); }else { +#if IS_ENABLED (CONFIG_IPV4 )ipv6_addr_set_v4mapped (ip_hdr (skb)->saddr, &sin->sin6_addr);if (inet_cmsg_flags (inet_sk (sk)))ip_cmsg_recv (msg, skb); +#endif } }
Signature · 1 line
2.54.0
RFC PATCH 4/13 net: tcp: move protocol agnostic TCP functions out of tcp_ipv4.c
In reply to Fernando Fernandez ManceraAs 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.
--- include/net/tcp.h | 16 +- net/ipv4/af_inet.c | 8 + net/ipv4/inet_connection_sock.c | 2 +- net/ipv4/proc.c | 2 + net/ipv4/tcp.c | 1291 ++++++++++++++++++++++++++++++ net/ipv4/tcp_bpf.c | 2 + net/ipv4/tcp_ipv4.c | 1299 +------------------------------ net/ipv6/ipv6_sockglue.c | 5 + net/ipv6/tcp_ipv6.c | 25 +- 9 files changed, 1348 insertions(+), 1302 deletions(-)
include/net/tcp.h +15 -1
@@ -2420,7 +2420,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);
@@ -2838,6 +2838,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 +8 -0
@@ -1955,6 +1955,7 @@ static int __init inet_init(void)#if IS_ENABLED (CONFIG_IPV4 )raw_hashinfo_init (&raw_v4_hashinfo); +#if IS_ENABLED (CONFIG_IPV4 ) rc =proto_register (&tcp_prot,1 );if (rc) goto out;
@@ -2002,6 +2003,7 @@ static int __init inet_init(void) };if (inet_add_protocol (&net_hotdata.tcp_protocol,IPPROTO_TCP ) <0 )pr_crit ("%s: Cannot add TCP protocol\n" , __func__); +#endif #ifdef CONFIG_IP_MULTICAST if (inet_add_protocol (&igmp_protocol,IPPROTO_IGMP ) <0 )pr_crit ("%s: Cannot add IGMP protocol\n" , __func__);
@@ -2075,7 +2077,9 @@ static int __init inet_init(void) out_unregister_udp_proto:proto_unregister (&udp_prot); out_unregister_tcp_proto: +#if IS_ENABLED (CONFIG_IPV4 )proto_unregister (&tcp_prot); +#endif goto out;#endif }
@@ -2092,8 +2096,10 @@ static int __init ipv4_proc_init(void)if (raw_proc_init ()) goto out_raw; +#if IS_ENABLED (CONFIG_IPV4 )if (tcp4_proc_init ()) goto out_tcp; +#endif if (udp4_proc_init ()) goto out_udp;if (ping_proc_init ())
@@ -2107,8 +2113,10 @@ static int __init ipv4_proc_init(void) out_ping:udp4_proc_exit (); out_udp: +#if IS_ENABLED(CONFIG_IPV4)tcp4_proc_exit (); out_tcp: +#endifraw_proc_exit (); out_raw: rc = -ENOMEM ;
net/ipv4/inet_connection_sock.c +1 -1
@@ -1371,7 +1371,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 +2 -0
@@ -50,6 +50,7 @@*/ static int sockstat_seq_show (struct seq_file *seq,void *v) { +#if IS_ENABLED (CONFIG_IPV4 )struct net *net = seq->private;int orphans, sockets;
@@ -69,6 +70,7 @@ static int sockstat_seq_show(struct seq_file *seq, void *v)seq_printf (seq,"FRAG: inuse %u memory %lu\n" ,atomic_read (&net->ipv4.fqdir->rhashtable.nelems),frag_mem_limit (net->ipv4.fqdir)); +#endif return 0 ; }
net/ipv4/tcp.c +1291 -0
1,322 lines not on this page · raw message
net/ipv4/tcp_bpf.c +2 -0
@@ -652,12 +652,14 @@ static void tcp_bpf_check_v6_needs_rebuild(struct proto *ops) } } +#if IS_ENABLED (CONFIG_IPV4 )static int __init tcp_bpf_v4_build_proto (void ) {tcp_bpf_rebuild_protos (tcp_bpf_prots[TCP_BPF_IPV4 ], &tcp_prot);return 0 ; }late_initcall (tcp_bpf_v4_build_proto); +#endif static int tcp_bpf_assert_proto_ops (struct proto *ops) {
net/ipv4/tcp_ipv4.c +1 -1298
1,364 lines not on this page · raw message
net/ipv6/ipv6_sockglue.c +5 -0
@@ -559,6 +559,7 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname,if (optlen <sizeof (int )) goto e_inval;if (val ==PF_INET ) { +#if IS_ENABLED (CONFIG_IPV4 )if (sk->sk_type ==SOCK_RAW )break ;
@@ -624,6 +625,10 @@ int do_ipv6_setsockopt(struct sock *sk, int level, int optname,module_put (THIS_MODULE ); retv =0 ;break ; +#else + retv = -EAFNOSUPPORT ; +break ; +#endif } goto e_inval;
net/ipv6/tcp_ipv6.c +23 -2
@@ -217,6 +217,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr,*/ if (addr_type &IPV6_ADDR_MAPPED ) { +#if IS_ENABLED (CONFIG_IPV4 )u32 exthdrlen = icsk->icsk_ext_hdr_len;struct sockaddr_in sin;
@@ -253,6 +254,9 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr, np->saddr = sk->sk_v6_rcv_saddr;return err; +#else +return -ENETUNREACH ; +#endif }if (!ipv6_addr_any (&sk->sk_v6_rcv_saddr))
@@ -1314,7 +1318,11 @@ u16 tcp_v6_get_syncookie(struct sock *sk, struct ipv6hdr *iph,static int tcp_v6_conn_request (struct sock *sk,struct sk_buff *skb) { if (skb->protocol == htons(ETH_P_IP)) +#if IS_ENABLED (CONFIG_IPV4 )return tcp_v4_conn_request (sk, skb); +#else + goto drop; +#endif if (!ipv6_unicast_destination (skb)) goto drop;
@@ -1342,6 +1350,7 @@ static void tcp_v6_restore_cb(struct sk_buff *skb) sizeof(struct inet6_skb_parm)); } +#if IS_ENABLED (CONFIG_IPV4 )/* Called from tcp_v4_syn_recv_sock() for v6_mapped children. */ static void tcp_v6_mapped_child_init (struct sock *newsk,const struct sock *sk) {
@@ -1376,6 +1385,7 @@ static void tcp_v6_mapped_child_init(struct sock *newsk, const struct sock *sk)if (inet6_test_bit (REPFLOW , sk)) newnp->flow_label =0 ; } +#endif static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *skb, struct request_sock *req,
@@ -1400,9 +1410,14 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff *struct flowi6 fl6; if (skb->protocol == htons(ETH_P_IP)) +#if IS_ENABLED (CONFIG_IPV4 )return tcp_v4_syn_recv_sock (sk, skb, req, dst, req_unhash, own_req, tcp_v6_mapped_child_init); +#else +return NULL ; +#endif + ireq =inet_rsk (req);if (sk_acceptq_is_full (sk))
@@ -1577,8 +1592,14 @@ int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)tcp_v6_hnd_req and tcp_v6_send_reset(). --ANK */ -if (skb->protocol ==htons (ETH_P_IP )) +if (skb->protocol ==htons (ETH_P_IP )) { +#if IS_ENABLED (CONFIG_IPV4 )return tcp_v4_do_rcv (sk, skb); +#else +kfree_skb (skb); +return 0 ; +#endif + } reason =psp_sk_rx_policy_check (sk, skb);if (reason)
@@ -2279,7 +2300,7 @@ struct proto tcpv6_prot = { .accept = inet_csk_accept, .ioctl = tcp_ioctl, .init = tcp_v6_init_sock, - .destroy = tcp_v4_destroy_sock, + .destroy = tcp_destroy_sock, .shutdown = tcp_shutdown, .setsockopt = tcp_setsockopt, .getsockopt = tcp_getsockopt,
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 04/13 RFC net-next] net: tcp: move protocol agnostic TCP functions out of tcp_ipv4.c
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [Medium] Disabling CONFIG_IPV4 completely hides `/proc/net/sockstat` and `/proc/net/snmp`, causing a…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] Disabling CONFIG_IPV4 completely hides /proc/net/sockstat and /proc/net/snmp, causing a total loss of global TCP memory and SNMP metrics.
- [Low] Unused static structs ipv6_mapped and tcp_sock_ipv6_mapped_specific trigger -Wunused-variable and cause undefined references when CONFIG_IPV4 is disabled. --
--- Patch [4]: [PATCH 04/13 RFC net-next] net: tcp: move protocol agnostic TCP functions out of tcp_ipv4.c --- commit 75343bf3b73e175ff640d8d0645b680b7c8368bd
Author: Fernando Fernandez Mancera <[email protected]>
Subject: net: tcp: move protocol agnostic TCP functions out of tcp_ipv4.c
This patch moves generic TCP functions out of tcp_ipv4.c into tcp.c to allow compilation with CONFIG_IPV4=n. It renames tcp_v4_destroy_sock() to tcp_destroy_sock() to reflect its shared usage and guards IPv4-specific code in the IPv6 TCP implementation.
net/ipv4/proc.c line 55
Quoted 11 lines
net/ipv4/proc.c +1
-0@@ -50,6 +50,7 @@*/ static int sockstat_seq_show (struct seq_file *seq,void *v) { +#if IS_ENABLED (CONFIG_IPV4 )struct net *net = seq->private;int orphans, sockets;
[Severity: Medium]
By guarding the entire body of sockstat_seq_show() with CONFIG_IPV4, does this completely hide the output of /proc/net/sockstat when IPv4 is disabled?
Looking at inet_init() in net/ipv4/af_inet.c (around line 2062), the call to ipv4_proc_init() is already bypassed entirely when CONFIG_IPV4=n. This means ip_misc_proc_init() is never called to register the sockstat and snmp procfs files in the first place.
Since the IPv6 equivalents (sockstat6 and snmp6) do not report shared TCP global metrics, does this unintentionally leave administrators without visibility into global TCP memory limits (like orphans and allocated sockets) and TCP SNMP metrics?
net/ipv6/tcp_ipv6.c static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr, · line 222
Quoted 11 lines
net/ipv6/tcp_ipv6.c +1
-0@@ -217,6 +217,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr,*/ if (addr_type &IPV6_ADDR_MAPPED ) { +#if IS_ENABLED (CONFIG_IPV4 )u32 exthdrlen = icsk->icsk_ext_hdr_len;struct sockaddr_in sin;
[Severity: Low]
With this CONFIG_IPV4 guard, the references to ipv6_mapped and tcp_sock_ipv6_mapped_specific inside tcp_v6_connect() are compiled out.
However, the definitions of these static structs at lines 2055 and 2068 in net/ipv6/tcp_ipv6.c are left unguarded. Could this trigger compiler warnings for unused variables when CONFIG_IPV4 is disabled?
Furthermore, because these structs reference IPv4-specific functions like tcp_v4_md5_lookup, could this result in undefined reference linker errors if the compiler does not fully discard the unused structs?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
RFC PATCH 5/13 net: raw: split IPv4 specific logic into raw_ipv4.c
In reply to Fernando Fernandez ManceraTo 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 | 844 ------------------------------------------ net/ipv4/raw_diag.c | 4 + net/ipv4/raw_ipv4.c | 875 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 880 insertions(+), 845 deletions(-) create mode 100644 net/ipv4/raw_ipv4.c
net/ipv4/Makefile +1 -1
@@ -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 -844
887 lines not on this page · raw message
net/ipv4/raw_diag.c +4 -0
@@ -40,10 +40,14 @@ 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) +#if IS_ENABLED (CONFIG_IPV4 )return raw_v4_match (net, sk, r->sdiag_raw_protocol, r->id.idiag_dst[0 ], r->id.idiag_src[0 ], r->id.idiag_if,0 ); +#else +return false; +#endif #if IS_ENABLED (CONFIG_IPV6 ) else return raw_v6_match(net, sk, r->sdiag_raw_protocol,
net/ipv4/raw_ipv4.c new file +875 -0
875 lines not on this page · raw message
Signature · 1 line
2.54.0
RFC PATCH 6/13 net: udp: split IPv4 specific logic into udp_ipv4.c
In reply to Fernando Fernandez ManceraTo 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.
--- net/core/filter.c | 4 + net/ipv4/Makefile | 2 +- net/ipv4/af_inet.c | 10 + net/ipv4/udp.c | 1733 --------------------------------------- net/ipv4/udp_bpf.c | 6 + net/ipv4/udp_diag.c | 12 + net/ipv4/udp_ipv4.c | 1773 ++++++++++++++++++++++++++++++++++++++++ net/ipv4/udp_offload.c | 10 + net/ipv6/udp.c | 18 + 9 files changed, 1834 insertions(+), 1734 deletions(-) create mode 100644 net/ipv4/udp_ipv4.c
net/core/filter.c +4 -0
@@ -7003,9 +7003,13 @@ static struct sock *sk_lookup(struct net *net, struct bpf_sock_tuple *tuple, dst4, tuple->ipv4.dport, dif, sdif, &refcounted); else +#if IS_ENABLED(CONFIG_IPV4) sk =__udp4_lib_lookup (net, src4, tuple->ipv4.sport, dst4, tuple->ipv4.dport, dif, sdif,NULL ); +#else + sk =NULL ; +#endif #if IS_ENABLED (CONFIG_IPV6 ) } else {struct in6_addr *src6 = (struct in6_addr *)&tuple->ipv6.saddr;
net/ipv4/Makefile +1 -1
@@ -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
@@ -890,8 +890,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);
@@ -919,8 +924,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 +0 -1733
1,832 lines not on this page · raw message
net/ipv4/udp_bpf.c +6 -0
@@ -16,7 +16,11 @@ 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 udp_prot.recvmsg (sk, msg, len, flags); +#else +return -EAFNOSUPPORT ; +#endif }static bool udp_sk_has_data (struct sock *sk)
@@ -153,12 +157,14 @@ static void udp_bpf_check_v6_needs_rebuild(struct proto *ops) } } +#if IS_ENABLED (CONFIG_IPV4 )static int __init udp_bpf_v4_build_proto (void ) {udp_bpf_rebuild_protos (&udp_bpf_prots[UDP_BPF_IPV4 ], &udp_prot);return 0 ; }late_initcall (udp_bpf_v4_build_proto); +#endif int udp_bpf_update_proto (struct sock *sk,struct sk_psock *psock,bool restore) {
net/ipv4/udp_diag.c +12 -0
@@ -37,11 +37,15 @@ static int udp_diag_dump_one(struct netlink_callback *cb,rcu_read_lock (); if (req->sdiag_family == AF_INET) +#if IS_ENABLED (CONFIG_IPV4 )/* src and dst are swapped for historical reasons */ sk =__udp4_lib_lookup (net, req->id.idiag_src[0 ], req->id.idiag_sport, req->id.idiag_dst[0 ], req->id.idiag_dport, req->id.idiag_if,0 ,NULL ); +#else + sk =NULL ; +#endif #if IS_ENABLED (CONFIG_IPV6 ) else if (req->sdiag_family == AF_INET6) sk = __udp6_lib_lookup(net,
@@ -159,18 +163,26 @@ static int udp_diag_destroy(struct sk_buff *in_skb,rcu_read_lock (); if (req->sdiag_family == AF_INET) +#if IS_ENABLED (CONFIG_IPV4 ) sk =__udp4_lib_lookup (net, req->id.idiag_dst[0 ], req->id.idiag_dport, req->id.idiag_src[0 ], req->id.idiag_sport, req->id.idiag_if,0 ,NULL ); +#else + sk =NULL ; +#endif #if IS_ENABLED (CONFIG_IPV6 ) else if (req->sdiag_family == AF_INET6) {if (ipv6_addr_v4mapped ((struct in6_addr *)req->id.idiag_dst) && ipv6_addr_v4mapped((struct in6_addr *)req->id.idiag_src)) +#if IS_ENABLED (CONFIG_IPV4 ) sk =__udp4_lib_lookup (net, req->id.idiag_dst[3 ], req->id.idiag_dport, req->id.idiag_src[3 ], req->id.idiag_sport, req->id.idiag_if,0 ,NULL ); +#else + sk =NULL ; +#endif else sk = __udp6_lib_lookup(net, (struct in6_addr *)req->id.idiag_dst,
net/ipv4/udp_ipv4.c new file +1773 -0
1,055 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.54.0
Part of the diff is not shown here. View the raw message.
RFC PATCH 7/13 net: icmp: split IPv4 specific logic into icmp_ipv4.c
In reply to Fernando Fernandez ManceraTo 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 | 1407 +---------------------------------------- net/ipv4/icmp_ipv4.c | 1425 ++++++++++++++++++++++++++++++++++++++++++ net/ipv6/datagram.c | 2 + 5 files changed, 1441 insertions(+), 1403 deletions(-) create mode 100644 net/ipv4/icmp_ipv4.c
include/net/icmp.h +1 -0
@@ -57,6 +57,7 @@ static inline void icmp_ndo_send(struct sk_buff *skb_in, int type, int code, __bint 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
@@ -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 +8 -1399
1,454 lines not on this page · raw message
net/ipv4/icmp_ipv4.c new file +1425 -0
1,425 lines not on this page · raw message
net/ipv6/datagram.c +2 -0
@@ -205,7 +205,9 @@ int __ip6_datagram_connect(struct sock *sk, struct sockaddr_unsized *uaddr, (struct sockaddr_unsized *)&sin, sizeof(sin)); +#if IS_ENABLED (CONFIG_IPV4 ) ipv4_connected: +#endif if (err) goto out;
Signature · 1 line
2.54.0
RFC PATCH 8/13 net: ping: split IPv4 specific logic into ping_ipv4.c
In reply to Fernando Fernandez ManceraTo 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, error handling 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 | 215 +++-------------------------------------- net/ipv4/ping_ipv4.c | 225 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 238 insertions(+), 204 deletions(-) create mode 100644 net/ipv4/ping_ipv4.c
net/ipv4/Makefile +1 -1
@@ -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 +12 -203
292 lines not on this page · raw message
net/ipv4/ping_ipv4.c new file +225 -0
225 lines not on this page · raw message
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 08/13 RFC net-next] net: ping: split IPv4 specific logic into ping_ipv4.c
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The commit message inaccurately states that error handling functions were moved to the new file…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message inaccurately states that error handling functions were moved to the new file, but ping_err() remains in ping.c. --
--- Patch [8]: [PATCH 08/13 RFC net-next] net: ping: split IPv4 specific logic into ping_ipv4.c --- commit 3efab348e36b9a0fdec89cd6eb3bf8beee163acf
Author: Fernando Fernandez Mancera <[email protected]>
net: ping: split IPv4 specific logic into ping_ipv4.c
This commit isolates IPv4-specific ping functions into a new file, ping_ipv4.c, to allow compiling the INET subsystem without IPv4. It moves packet transmission routines and modifies ping.c to use CONFIG_IPV4 guards for the remaining shared logic.
Quoted 3 lines
This patch creates
ping_ipv4.cand move all the functions for packet transmission, error handling and theAF_INETping_protdefinition fromping.cto the new file.
[Severity: Medium]
Is this description accurate regarding the error handling functions?
Looking at the patch, the ICMP error handling function ping_err() was not moved to ping_ipv4.c. Instead, it was left in net/ipv4/ping.c and modified in-place with IS_ENABLED(CONFIG_IPV4) guards because it also serves as the error entry point for IPv6.
Could the commit message be updated to clarify that ping_err() remains in the generic ping.c file?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
RFC PATCH 9/13 net: fib: split common nexthop logic to fib_core.c
In reply to Fernando Fernandez ManceraTo 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 | 43 +++++++++++ include/net/route.h | 6 ++ net/core/Makefile | 2 +- net/core/fib_core.c | 146 +++++++++++++++++++++++++++++++++++++ net/ipv4/Makefile | 2 + net/ipv4/fib_semantics.c | 142 ------------------------------------ net/ipv4/netlink.c | 2 + net/ipv4/nexthop.c | 2 +- net/ipv4/sysctl_net_ipv4.c | 2 + net/ipv6/ip6_fib.c | 2 + 10 files changed, 205 insertions(+), 144 deletions(-) create mode 100644 net/core/fib_core.c
include/net/ip_fib.h +43 -0
@@ -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);
@@ -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 gfp, +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)
@@ -658,8 +683,26 @@ int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,struct fib_dump_filter *filter, struct netlink_callback *cb); +#if IS_ENABLED (CONFIG_IPV4 )int fib_nexthop_info (struct sk_buff *skb,const struct fib_nh_common *nh,u8 rt_family,unsigned char *flags,bool skip_oif);int fib_add_nexthop (struct sk_buff *skb,const struct fib_nh_common *nh,int nh_weight,u8 rt_family,u32 nh_tclassid); +#else +static inline int fib_nexthop_info (struct sk_buff *skb, +const struct fib_nh_common *nh, +u8 rt_family,unsigned char *flags, +bool skip_oif) +{ +return 0 ; +} + +static inline int fib_add_nexthop (struct sk_buff *skb, +const struct fib_nh_common *nh, +int nh_weight,u8 rt_family, +u32 nh_tclassid) +{ +return 0 ; +} +#endif #endif /* _NET_FIB_H */
include/net/route.h +6 -0
@@ -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
@@ -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 +146 -0
146 lines not on this page · raw message
net/ipv4/Makefile +2 -0
@@ -19,7 +19,9 @@ obj-$(CONFIG_IPV4) += route.o ip_input.o ip_fragment.o ip_forward.o ip_options.o obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o obj-$(CONFIG_PROC_FS) += proc.o +ifeq ($(CONFIG_IPV4),y) obj-$(CONFIG_IP_MULTIPLE_TABLES) += fib_rules.o +endif obj-$(CONFIG_IP_MROUTE) += ipmr.o obj-$(CONFIG_IP_MROUTE_COMMON) += ipmr_base.o obj-$(CONFIG_NET_IPIP) += ipip.o
net/ipv4/fib_semantics.c +0 -142
160 lines not on this page · raw message
net/ipv4/netlink.c +2 -0
@@ -16,10 +16,12 @@ int rtm_getroute_parse_ip_proto(struct nlattr *attr, u8 *ip_proto, u8 family,case IPPROTO_TCP :case IPPROTO_UDP :return 0 ; +#if IS_ENABLED (CONFIG_IPV4 )case IPPROTO_ICMP :if (family !=AF_INET )break ;return 0 ; +#endif #if IS_ENABLED (CONFIG_IPV6 )case IPPROTO_ICMPV6 :if (family !=AF_INET6 )
net/ipv4/nexthop.c +1 -1
@@ -1414,7 +1414,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); }
net/ipv4/sysctl_net_ipv4.c +2 -0
@@ -613,6 +613,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,
@@ -622,6 +623,7 @@ static struct ctl_table ipv4_table[] = { .extra1 = &sysctl_fib_sync_mem_min, .extra2 = &sysctl_fib_sync_mem_max, }, +#endif }; static struct ctl_table ipv4_net_table[] = {
net/ipv6/ip6_fib.c +2 -0
@@ -645,9 +645,11 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)rcu_read_lock ();if (cb->strict_check) { +#if IS_ENABLED (CONFIG_IPV4 ) err =ip_valid_fib_dump_req (net, nlh, &arg.filter, cb);if (err <0 ) goto unlock; +#endif }else if (nlmsg_len (nlh) >=sizeof (struct rtmsg )) {struct rtmsg *rtm =nlmsg_data (nlh);
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [PATCH 09/13 RFC net-next] net: fib: split common nexthop logic to fib_core.c
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] IPv6 route dumps silently omit nexthop gateway, interface, and encap information when IPv4 is…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] IPv6 route dumps silently omit nexthop gateway, interface, and encap information when IPv4 is disabled.
- [High] IPv6 strict route netlink dumps bypass filter parsing and ignore user filters when CONFIG_IPV4 is disabled.
- [High] Missing fallback stub for ip_valid_fib_dump_req causes undefined reference linker errors for IPv6 multicast routing and MPLS when compiled without IPv4. --
--- Patch [9]: [PATCH 09/13 RFC net-next] net: fib: split common nexthop logic to fib_core.c --- commit 8475b4cb1ca1bfc7fdd4717168ce4e1522e0104d
Author: Fernando Fernandez Mancera <[email protected]>
Subject: net: fib: split common nexthop logic to fib_core.c
This patch creates fib_core.c and moves common nexthop initialization and release functions from fib_semantics.c to fib_core.c. This enables compiling the INET subsystem without IPv4.
Quoted 4 lines
include/net/ip_fib.h +0
-0
[ ... ]
include/net/ip_fib.h int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh, · line 685
Quoted 4 lines
include/net/ip_fib.h +0
-0@@ -658,8 +683,26 @@ int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh,struct fib_dump_filter *filter, struct netlink_callback *cb);
[Severity: High]
Does this missing fallback stub cause undefined reference linker errors for IPv6 multicast routing and MPLS when compiled without IPv4?
ip6mr_rtm_dumproute() and mpls_valid_fib_dump_req() unconditionally call ip_valid_fib_dump_req(). Could a static inline stub be added for the !CONFIG_IPV4 case?
include/net/ip_fib.h int ip_valid_fib_dump_req(struct net *net, const struct nlmsghdr *nlh, · line 698
Quoted 13 lines
include/net/ip_fib.h +9
-0+#if IS_ENABLED (CONFIG_IPV4 )int fib_nexthop_info (struct sk_buff *skb,const struct fib_nh_common *nh,u8 rt_family,unsigned char *flags,bool skip_oif);int fib_add_nexthop (struct sk_buff *skb,const struct fib_nh_common *nh,int nh_weight,u8 rt_family,u32 nh_tclassid); +#else +static inline int fib_nexthop_info (struct sk_buff *skb, +const struct fib_nh_common *nh, +u8 rt_family,unsigned char *flags, +bool skip_oif) +{ +return 0 ; +}
[Severity: High]
Since the stub returns 0, will IPv6 route dumps silently omit the nexthop gateway, interface, and encap information when IPv4 is disabled?
IPv6 relies on this function to serialize its nexthop info in rt6_fill_node():
rt6_fill_node()
if (fib_nexthop_info(skb, &rt->fib6_nh->nh_common, AF_INET6, &nh_flags, false) < 0)
goto nla_put_failure;Could this be moved to fib_core.c instead of stubbed out so the RTA attributes aren't dropped?
Quoted 15 lines
include/net/ip_fib.h +9
-0+ +static inline int fib_add_nexthop (struct sk_buff *skb, +const struct fib_nh_common *nh, +int nh_weight,u8 rt_family, +u32 nh_tclassid) +{ +return 0 ; +} +#endif #endif /* _NET_FIB_H */ net/core/fib_core.c new file +0
-0
[ ... ]
Quoted 5 lines
net/core/fib_core.c new file +5
-0+void fib_nhc_update_mtu (struct fib_nh_common *nhc,u32 new,u32 orig) +{ +struct fnhe_hash_bucket *bucket; +int i; +
net/core/fib_core.c line 134
Quoted 10 lines
net/core/fib_core.c new file +10
-0+ bucket =rcu_dereference_protected (nhc->nhc_exceptions,1 ); +if (!bucket) +return ; + +for (i =0 ; i <FNHE_HASH_SIZE ; i++) { +struct fib_nh_exception *fnhe; + +for (fnhe =rcu_dereference_protected (bucket[i].chain,1 ); + fnhe; + fnhe =rcu_dereference_protected (fnhe->fnhe_next,1 )) {
[Severity: High]
This isn't a bug introduced by this patch, but does traversing the nhc_exceptions list here without holding rcu_read_lock() or fnhe_lock risk a use-after-free?
This loop traverses the fnhe_next chain using rcu_dereference_protected(..., 1). Concurrently, update_or_create_fnhe() running in softirq can unlink and free a fnhe entry via kfree_rcu(). Because rtnl_lock does not disable preemption, can a grace period elapse and cause the traversal to follow a freed pointer?
Quoted 12 lines
net/core/fib_core.c new file +12
-0+if (fnhe->fnhe_mtu_locked) { +if (new <= fnhe->fnhe_pmtu) { + fnhe->fnhe_pmtu = new; + fnhe->fnhe_mtu_locked = false; + } + }else if (new < fnhe->fnhe_pmtu || + orig == fnhe->fnhe_pmtu) { + fnhe->fnhe_pmtu = new; + } + } + } +}
[ ... ]
net/ipv6/ip6_fib.c static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb) · line 652
Quoted 13 lines
net/ipv6/ip6_fib.c +2
-0@@ -645,9 +645,11 @@ static int inet6_dump_fib(struct sk_buff *skb, struct netlink_callback *cb)rcu_read_lock ();if (cb->strict_check) { +#if IS_ENABLED (CONFIG_IPV4 ) err =ip_valid_fib_dump_req (net, nlh, &arg.filter, cb);if (err <0 ) goto unlock; +#endif
[Severity: High]
When IPv4 is disabled, does this skip filter parsing and cause strict route netlink dumps to unconditionally dump the entire routing table?
If the filter parsing is bypassed, arg.filter remains zero-initialized and userspace filters like table ID or device constraints are ignored. Could this break the NLM_F_STRICT_CHK uAPI guarantee?
Quoted 3 lines
net/ipv6/ip6_fib.c +0
-0}else if (nlmsg_len (nlh) >=sizeof (struct rtmsg )) {struct rtmsg *rtm =nlmsg_data (nlh);
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
RFC PATCH 10/13 net: tunnel: guard IPv4 tunnel functions with CONFIG_IPV4
In reply to Fernando Fernandez ManceraTo 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
@@ -52,6 +52,7 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb, __u8 tos, __u8 ttl, __be16 df, bool xnet, u16 ipcb_flags) { +#if IS_ENABLED(CONFIG_IPV4) int pkt_len = skb->len -skb_inner_network_offset (skb);struct net *net =dev_net (rt->dst.dev);struct net_device *dev = skb->dev;
@@ -103,6 +104,12 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb, }dev_xmit_recursion_dec (); +#else +if (skb->dev) +DEV_STATS_INC (skb->dev, tx_errors); +ip_rt_put (rt); +kfree_skb (skb); +#endif }EXPORT_SYMBOL_GPL (iptunnel_xmit);
@@ -212,6 +219,7 @@ EXPORT_SYMBOL_GPL(iptunnel_handle_offloads);*/ static int iptunnel_pmtud_build_icmp (struct sk_buff *skb,int mtu) { +#if IS_ENABLED (CONFIG_IPV4 )const struct iphdr *iph;struct icmphdr *icmph;struct iphdr *niph;
@@ -269,6 +277,9 @@ static int iptunnel_pmtud_build_icmp(struct sk_buff *skb, int mtu)skb_reset_mac_header (skb);return skb->len; +#else +return -EOPNOTSUPP ; +#endif }/**
Signature · 1 line
2.54.0
RFC PATCH 11/13 net: cipso: guard IPv4 packet manipulation functions
In reply to Fernando Fernandez ManceraTo enable compiling the network stack without IPv4, the CIPSO functions that manipulate IPv4 options and generate ICMP errors must be bypassed.
Ideally, CIPSO should not be compiled when IPv4 is disabled but currently it is too integrated within netlabel, so let's just bypassed the relevant functions.
--- net/ipv4/cipso_ipv4.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
net/ipv4/cipso_ipv4.c +10 -0
@@ -1714,6 +1714,7 @@ int cipso_v4_validate(const struct sk_buff *skb, unsigned char **option)*/ void cipso_v4_error (struct sk_buff *skb,int error,u32 gateway) { +#if IS_ENABLED (CONFIG_IPV4 )struct inet_skb_parm parm;int res;
@@ -1738,6 +1739,7 @@ void cipso_v4_error(struct sk_buff *skb, int error, u32 gateway)__icmp_send (skb,ICMP_DEST_UNREACH ,ICMP_NET_ANO ,0 , &parm); else __icmp_send(skb, ICMP_DEST_UNREACH, ICMP_HOST_ANO, 0, &parm); +#endif }/**
@@ -2171,6 +2173,7 @@ int cipso_v4_skbuff_setattr(struct sk_buff *skb,const struct cipso_v4_doi *doi_def, const struct netlbl_lsm_secattr *secattr) { +#if IS_ENABLED(CONFIG_IPV4) int ret_val; struct iphdr *iph;struct ip_options *opt = &IPCB (skb)->opt;
@@ -2235,6 +2238,9 @@ int cipso_v4_skbuff_setattr(struct sk_buff *skb,ip_send_check (iph);return 0 ; +#else +return -EOPNOTSUPP ; +#endif }/**
@@ -2248,6 +2254,7 @@ int cipso_v4_skbuff_setattr(struct sk_buff *skb,*/ int cipso_v4_skbuff_delattr (struct sk_buff *skb) { +#if IS_ENABLED (CONFIG_IPV4 )int ret_val, cipso_len, hdr_len_actual, new_hdr_len_actual, new_hdr_len, hdr_len_delta;struct iphdr *iph;
@@ -2296,6 +2303,9 @@ int cipso_v4_skbuff_delattr(struct sk_buff *skb)ip_send_check (iph);return 0 ; +#else +return -EOPNOTSUPP ; +#endif }/*
Signature · 1 line
2.54.0
Paul Moore
maintainerRe: [PATCH 11/13 RFC net-next] net: cipso: guard IPv4 packet manipulation functions
Quoted 4 lines · Fernando Fernandez Mancera
To enable compiling the network stack without IPv4, the CIPSO functions that manipulate IPv4 options and generate ICMP errors must be bypassed.
Quoted 8 lines
Ideally, CIPSO should not be compiled when IPv4 is disabled but currently it is too integrated within netlabel, so let's just bypassed the relevant functions.
Signed-off-by Fernando Fernandez Mancera <[email protected]>--- net/ipv4/cipso_ipv4.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
I think I would prefer to make CONFIG_NETLABEL dependent on CONFIG_IPV4 at this point in time. This will keep the code cleaner and allow time to do the proper work of wrapping the CIPSO code with CONFIG_CIPSO (or similar) and making that dependent on CONFIG_IPV4.
Signature · 1 line
paul-moore.com
Re: [PATCH 11/13 RFC net-next] net: cipso: guard IPv4 packet manipulation functions
Quoted 15 lines · Paul Moore
Quoted 4 lines · Fernando Fernandez Mancera
To enable compiling the network stack without IPv4, the CIPSO functions that manipulate IPv4 options and generate ICMP errors must be bypassed.
Quoted 8 lines
Ideally, CIPSO should not be compiled when IPv4 is disabled but currently it is too integrated within netlabel, so let's just bypassed the relevant functions.
Signed-off-by Fernando Fernandez Mancera <[email protected]>--- net/ipv4/cipso_ipv4.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
Quoted 5 lines
I think I would prefer to make
CONFIG_NETLABELdependent onCONFIG_IPV4at this point in time. This will keep the code cleaner and allow time to do the proper work of wrapping the CIPSO code withCONFIG_CIPSO(or similar) and making that dependent onCONFIG_IPV4.
Fair, that works for me too. I am gonna drop this on the v1.
Thank you!
Fernando.
[email protected]
AI reviewRe: [PATCH 11/13 RFC net-next] net: cipso: guard IPv4 packet manipulation functions
In reply to Fernando Fernandez ManceraSashiko has reviewed this patch and found no issues.
Quoted 8 lines
To enable compiling the network stack without IPv4, the CIPSO functions that manipulate IPv4 options and generate ICMP errors must be bypassed.
Ideally, CIPSO should not be compiled when IPv4 is disabled but currently it is too integrated within netlabel, so let's just bypassed the relevant functions.
Signed-off-by Fernando Fernandez Mancera <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
RFC PATCH 12/13 netfilter: ipv4: guard ip_route_me_harder() with CONFIG_IPV4
In reply to Fernando Fernandez ManceraTo 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 | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv4/netfilter.c +4 -0
@@ -21,6 +21,7 @@/* route_me_harder function, used by iptable_nat, iptable_mangle + ip_queue */ int ip_route_me_harder (struct net *net,struct sock *sk,struct sk_buff *skb,unsigned int addr_type) { +#if IS_ENABLED (CONFIG_IPV4 )struct net_device *dev =skb_dst_dev (skb);const struct iphdr *iph =ip_hdr (skb);struct rtable *rt;
@@ -85,6 +86,9 @@ int ip_route_me_harder(struct net *net, struct sock *sk, struct sk_buff *skb, unreturn -ENOMEM ;return 0 ; +#else +return -EPROTONOSUPPORT ; +#endif }EXPORT_SYMBOL (ip_route_me_harder);
Signature · 1 line
2.54.0
RFC PATCH 13/13 net: ipv4: make CONFIG_IPV4 boolean
In reply to Fernando Fernandez ManceraChange CONFIG_IPV4 from hidden 'def_bool y' into an exposed boolean. This allows users to explicitly disable IPv4 via Kconfig to build IPv6-only or pure L2 kernel network stack. The default is kept at 'y' to prevent breaking existing configurations.
--- net/ipv4/Kconfig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
net/ipv4/Kconfig +9 -1
@@ -3,7 +3,15 @@ # IP configuration # config IPV4 - def_bool y + bool "The IPv4 protocol" + default y + help + Support for IP version 4 (IPv4). + + Disabling this option compiles the kernel networking stack without + IPv4 support, resulting in a IPv6-only or pure L2 system. + + If unsure, say Y. config IP_MULTICAST bool "IP: multicasting"
Signature · 1 line
2.54.0