Introducing ipxlat: a stateless IPv4/IPv6 translation device
Subsystems (5)
cover Introducing ipxlat: a stateless IPv4/IPv6 translation device
Hi all,
this RFC series introduces ipxlat, a virtual netdevice for stateless packet translation between IPv6 and IPv4.
This stateless IP/ICMP translation (SIIT, RFC 7915) device is a building block ultimately allowing suitably configured Linux systems to cover all IPv6<>IPv4 connectivity scenarios outlined in RFC 6144, "Framework for IPv4/IPv6 Translation".
While the packet translation function implemented in ipxlat itself is stateless, building stateful NAT64 translators is easy in combination with a sandwich of simple nft SNAT and MASQUERADE rules. Even SIIT-DC (RFC 7755 / 7756) ER/BR functions including EAMT (RFC 7757) are thought to be possible with suitable nft/iptables configuration, but this needs further testing.
The series contains patches covering driver core, translation paths, netlink API, selftests and documentation.
See Documentation/networking/ipxlat.rst for more details.
== Architecture ==
ipxlat sits at a boundary between two kernel models. It is exposed as a netdevice, so it has device semantics such as MTU and netdev statistics. However, most of its processing falls within protocol translation logic. The implementation therefore uses netdevice hooks for integration and lifecycle, while translation behavior follows RFC rules and reuses existing IP stack helpers for routing, fragmentation and checksum handling.
Feedback on the netdevice integration model is welcome, yet this series intentionally keeps scope limited to a self-contained module to make review and validation tractable.
ipxlat devices are created and destroyed via rtnl link operations. Per-device translation parameters are configured through a generic netlink family named ipxlat.
No generic networking core behavior is changed.
== RFCs ==
The ipxlat packet translation code considers:
- RFC 7915 - Stateless IP/ICMP translation (SIIT) behavior
- RFC 6052 - Address mapping for xlat-prefix sizes between /32 and /96
- RFC 6791 - Although we use standard ICMP source-address selection
- RFC 4884 - Translation painstakingly handles ICMP extensions
- RFC 5837 - Interface Information Objects from RFC 6791 are not implemented in this series and are planned as follow-up work
== Implementation ==
We enforce a strict processing contract: packet validation is done once, then translation runs on that validated layout. When translation cannot continue, the packet is either dropped or we switch to the ICMP error emission path.
Control-plane updates are serialized, while the data path reads configuration locklessly to keep per-packet overhead low.
During live reconfiguration, readers may transiently observe mixed old and new values; this may cause a small number of packet drops while configuration is being changed.
This tradeoff is intentional to keep the fast path simple and lightweight.
== Selftests ==
Selftests are added under tools/testing/selftests/net/ipxlat and cover ICMP, TCP and UDP translation in both directions, large-packet and fragmentation-sensitive paths, ICMP error translation and PMTUD-related emission paths.
== Points of Discussion ==
- Tighter stack integration?
== Work Planned for v1 ==
- icmp: Simplify FRAG_NEEDED / PKT_TOOBIG MTU calculation.
- translation: Prevent skb loops without TTL/HLIM decrement?
- netdevice: Decide on hardcoding MTU = 0xffff - $xlat_overhead
- UDPv4 defrag and csum recalc for NAT64 (RFC 6146 Sec 3.4.) "For incoming IPv4 packets carrying UDP packets with a zero checksum ... MUST calculate the checksum"
== Acknowledgements ==
The ipxlat translation code is based on the Jool project in order to benefit from years of accumulated experience and its golden-packet test-suite.
Thanks to Jool's Principal Author, Alberto Leiva Popper, for developing and maintaining Jool since IPv6 translation was last in-vogue and writing the initial "joolif" netdevice prototype our work was able to start from.
Thanks to NLnet's NGI0 Core Fund for supporting development of the ipxlat driver.
Thanks for your review,
Ralf Lici
Mandelbit SRL
---
Daniel Gröber (1):
Documentation: networking: add ipxlat translator guide
Ralf Lici (14):
drivers/net: add ipxlat netdevice skeleton and build plumbing
ipxlat: add RFC 6052 address conversion helpers
ipxlat: add packet metadata control block helpers
ipxlat: add IPv4 packet validation path
ipxlat: add IPv6 packet validation path
ipxlat: add transport checksum and offload helpers
ipxlat: add 4to6 and 6to4 TCP/UDP translation helpers
ipxlat: add translation engine and dispatch core
ipxlat: emit translator-generated ICMP errors on drop
ipxlat: add 4to6 pre-fragmentation path
ipxlat: add ICMP informational translation paths
ipxlat: add ICMP error translation and quoted-inner handling
ipxlat: add netlink control plane and uapi
selftests: net: add ipxlat coverage
Documentation/netlink/specs/ipxlat.yaml | 97 +++ Documentation/networking/ipxlat.rst | 190 +++++ drivers/net/Kconfig | 13 + drivers/net/Makefile | 1 + drivers/net/ipxlat/Makefile | 17 + drivers/net/ipxlat/address.c | 132 ++++ drivers/net/ipxlat/address.h | 59 ++ drivers/net/ipxlat/dispatch.c | 263 ++++++ drivers/net/ipxlat/dispatch.h | 78 ++ drivers/net/ipxlat/icmp.h | 45 ++ drivers/net/ipxlat/icmp_46.c | 552 +++++++++++++ drivers/net/ipxlat/icmp_64.c | 531 +++++++++++++ drivers/net/ipxlat/ipxlpriv.h | 53 ++ drivers/net/ipxlat/main.c | 148 ++++ drivers/net/ipxlat/main.h | 27 + drivers/net/ipxlat/netlink-gen.c | 71 ++ drivers/net/ipxlat/netlink-gen.h | 31 + drivers/net/ipxlat/netlink.c | 348 ++++++++ drivers/net/ipxlat/netlink.h | 27 + drivers/net/ipxlat/packet.c | 747 ++++++++++++++++++ drivers/net/ipxlat/packet.h | 166 ++++ drivers/net/ipxlat/translate_46.c | 256 ++++++ drivers/net/ipxlat/translate_46.h | 84 ++ drivers/net/ipxlat/translate_64.c | 206 +++++ drivers/net/ipxlat/translate_64.h | 56 ++ drivers/net/ipxlat/transport.c | 401 ++++++++++ drivers/net/ipxlat/transport.h | 122 +++ include/uapi/linux/ipxlat.h | 48 ++ tools/testing/selftests/net/ipxlat/.gitignore | 1 + tools/testing/selftests/net/ipxlat/Makefile | 25 + .../selftests/net/ipxlat/ipxlat_data.sh | 70 ++ .../selftests/net/ipxlat/ipxlat_frag.sh | 70 ++ .../selftests/net/ipxlat/ipxlat_icmp_err.sh | 54 ++ .../selftests/net/ipxlat/ipxlat_lib.sh | 273 +++++++ .../net/ipxlat/ipxlat_udp4_zero_csum_send.c | 119 +++ 35 files changed, 5381 insertions(+) create mode 100644 Documentation/netlink/specs/ipxlat.yaml create mode 100644 Documentation/networking/ipxlat.rst create mode 100644 drivers/net/ipxlat/Makefile create mode 100644 drivers/net/ipxlat/address.c create mode 100644 drivers/net/ipxlat/address.h create mode 100644 drivers/net/ipxlat/dispatch.c create mode 100644 drivers/net/ipxlat/dispatch.h create mode 100644 drivers/net/ipxlat/icmp.h create mode 100644 drivers/net/ipxlat/icmp_46.c create mode 100644 drivers/net/ipxlat/icmp_64.c create mode 100644 drivers/net/ipxlat/ipxlpriv.h create mode 100644 drivers/net/ipxlat/main.c create mode 100644 drivers/net/ipxlat/main.h create mode 100644 drivers/net/ipxlat/netlink-gen.c create mode 100644 drivers/net/ipxlat/netlink-gen.h create mode 100644 drivers/net/ipxlat/netlink.c create mode 100644 drivers/net/ipxlat/netlink.h create mode 100644 drivers/net/ipxlat/packet.c create mode 100644 drivers/net/ipxlat/packet.h create mode 100644 drivers/net/ipxlat/translate_46.c create mode 100644 drivers/net/ipxlat/translate_46.h create mode 100644 drivers/net/ipxlat/translate_64.c create mode 100644 drivers/net/ipxlat/translate_64.h create mode 100644 drivers/net/ipxlat/transport.c create mode 100644 drivers/net/ipxlat/transport.h create mode 100644 include/uapi/linux/ipxlat.h create mode 100644 tools/testing/selftests/net/ipxlat/.gitignore create mode 100644 tools/testing/selftests/net/ipxlat/Makefile create mode 100755 tools/testing/selftests/net/ipxlat/ipxlat_data.sh create mode 100755 tools/testing/selftests/net/ipxlat/ipxlat_frag.sh create mode 100755 tools/testing/selftests/net/ipxlat/ipxlat_icmp_err.sh create mode 100644 tools/testing/selftests/net/ipxlat/ipxlat_lib.sh create mode 100644 tools/testing/selftests/net/ipxlat/ipxlat_udp4_zero_csum_send.c
Signature · 1 line
2.53.0
RFC 1/15 drivers/net: add ipxlat netdevice skeleton and build plumbing
ipxlat is a virtual netdevice implementing stateless IPv4/IPv6 translation (SIIT). The translation model follows RFC 7915 behavior and RFC 6052 address embedding rules.
The netdevice form is intentional: it provides per-instance lifecycle, MTU/statistics semantics and explicit routing integration, so translated traffic can be steered through a dedicated device and configured per namespace.
This series targets ipxlat as a reusable kernel building block for SIIT deployments and for NAT64-style setups when combined with existing nftables rules in userspace policy.
This first patch introduces only the driver scaffolding:
- drivers/net/ipxlat/ directory and build integration
- Kconfig/Makefile entries
- basic private structures and defaults
- rtnl_link_ops and netdevice skeleton needed to create/register links
No translation logic is added in this patch yet. Follow-up patches add packet validation, transport/ICMP translation, error handling, fragmentation handling, generic netlink control plane, selftests and documentation.
--- drivers/net/Kconfig | 13 ++++ drivers/net/Makefile | 1 + drivers/net/ipxlat/Makefile | 7 ++ drivers/net/ipxlat/ipxlpriv.h | 53 +++++++++++++ drivers/net/ipxlat/main.c | 137 ++++++++++++++++++++++++++++++++++ drivers/net/ipxlat/main.h | 27 +++++++ 6 files changed, 238 insertions(+) create mode 100644 drivers/net/ipxlat/Makefile create mode 100644 drivers/net/ipxlat/ipxlpriv.h create mode 100644 drivers/net/ipxlat/main.c create mode 100644 drivers/net/ipxlat/main.h
drivers/net/Kconfig +13 -0
@@ -117,6 +117,19 @@ config OVPN This module enhances the performance of the OpenVPN userspace software by offloading the data channel processing to kernelspace. +config IPXLAT + tristate "IPv6<>IPv4 packet translation virtual device (SIIT)" + depends on NET && INET && IPV6 + help + Virtual network device driver for Stateless IP/ICMP Packet + Translation (RFC 7915). Useful for IPv6 focused networks. + Particularly NAT64, SIIT-DC, 464XLAT network architectures. + + See also <file:Documentation/networking/ipxlat.rst>. + + To compile this driver as a module, choose M here: the module will be + called ipxlat. + config EQUALIZER tristate "EQL (serial line load balancing) support" help
drivers/net/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_NET) += loopback.o obj-$(CONFIG_NETDEV_LEGACY_INIT) += Space.o obj-$(CONFIG_NETCONSOLE) += netconsole.o obj-$(CONFIG_NETKIT) += netkit.o +obj-$(CONFIG_IPXLAT) += ipxlat/ obj-y += phy/ obj-y += pse-pd/ obj-y += mdio/
drivers/net/ipxlat/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# IPXLAT - Stateless IP/ICMP Translation (SIIT) virtual device driver + +obj-$(CONFIG_IPXLAT) := ipxlat.o + +ipxlat-objs += main.o
drivers/net/ipxlat/ipxlpriv.h new file +53 -0
53 lines not on this page · raw message
drivers/net/ipxlat/main.c new file +137 -0
137 lines not on this page · raw message
drivers/net/ipxlat/main.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* IPXLAT - Stateless IP/ICMP Translation (SIIT) virtual device driver +* +* Copyright (C) 2024- Alberto Leiva Popper <[email protected]> +* Copyright (C) 2026- Mandelbit SRL +* Copyright (C) 2026- Daniel Gröber <[email protected]> +* +* Author: Alberto Leiva Popper <[email protected]> +* Antonio Quartulli <[email protected]> +* Daniel Gröber <[email protected]> +* Ralf Lici <[email protected]> +*/ + +#ifndef _NET_IPXLAT_MAIN_H_ +#define _NET_IPXLAT_MAIN_H_ + +#include <linux/netdevice.h> + +/** +* ipxlat_dev_is_valid - tell whether a netdev is an ipxlat interface +* @dev: netdevice to inspect +* +* Return: true if @dev was created with ipxlat link ops. +*/ +bool ipxlat_dev_is_valid (const struct net_device *dev); + +#endif /* _NET_IPXLAT_MAIN_H_ */
Signature · 1 line
2.53.0
RFC 2/15 ipxlat: add RFC 6052 address conversion helpers
In reply to Ralf LiciIntroduce IPv4/IPv6 stateless address mapping helpers used by the translation pipeline. Add the core 4<->6 conversion routines, including RFC 6052 prefix embedding/extraction and the RFC 6791 fallback source selection logic used by ICMP translation paths.
--- drivers/net/ipxlat/Makefile | 1 + drivers/net/ipxlat/address.c | 132 +++++++++++++++++++++++++++++++++++ drivers/net/ipxlat/address.h | 59 ++++++++++++++++ 3 files changed, 192 insertions(+) create mode 100644 drivers/net/ipxlat/address.c create mode 100644 drivers/net/ipxlat/address.h
drivers/net/ipxlat/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_IPXLAT) := ipxlat.o ipxlat-objs += main.o +ipxlat-objs += address.o
drivers/net/ipxlat/address.c new file +132 -0
132 lines not on this page · raw message
drivers/net/ipxlat/address.h new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC 3/15 ipxlat: add packet metadata control block helpers
In reply to Ralf LiciAdd the per-skb control-block layout and shared packet helper routines used by translation stages introducing common metadata bookkeeping (offset rebasing and invariant checks) plus protocol-fragment helper utilities.
--- drivers/net/ipxlat/Makefile | 1 + drivers/net/ipxlat/packet.c | 99 +++++++++++++++++++++ drivers/net/ipxlat/packet.h | 166 ++++++++++++++++++++++++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 drivers/net/ipxlat/packet.c create mode 100644 drivers/net/ipxlat/packet.h
drivers/net/ipxlat/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_IPXLAT) := ipxlat.o ipxlat-objs += main.o ipxlat-objs += address.o +ipxlat-objs += packet.o
drivers/net/ipxlat/packet.c new file +99 -0
99 lines not on this page · raw message
drivers/net/ipxlat/packet.h new file +166 -0
166 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC 4/15 ipxlat: add IPv4 packet validation path
In reply to Ralf LiciImplement IPv4 packet parsing and validation, including option inspection, fragment-sensitive L4 checks, and UDP checksum-zero handling consistent with translator constraints. The parser populates skb control-block metadata consumed by translation and marks RFC-driven drop reasons for later action handling.
--- drivers/net/ipxlat/packet.c | 312 +++++++++++++++++++++++++++++++++++- 1 file changed, 310 insertions(+), 2 deletions(-)
drivers/net/ipxlat/packet.c +310 -2
@@ -11,6 +11,8 @@* Ralf Lici <[email protected]> */ +#include <linux/icmp.h> +#include "packet.h" /* Shift cached skb cb offsets by the L3 header delta after in-place rewrite.
@@ -88,9 +90,315 @@ bool ipxlat_cb_offsets_valid(const struct ipxlat_cb *cb) }#endif -int ipxlat_v4_validate_skb (struct ipxlat_priv *ipxl,struct sk_buff *skb) +static bool ipxlat_v4_validate_addr (__be32 addr4) { -return -EOPNOTSUPP ; +return !(ipv4_is_zeronet (addr4) ||ipv4_is_loopback (addr4) || +ipv4_is_multicast (addr4) ||ipv4_is_lbcast (addr4)); +} + +/* RFC 7915 Section 4.1 requires ignoring IPv4 options unless an unexpired +* LSRR/SSRR is present, in which case we must send ICMPv4 SR_FAILED. +* We intentionally treat malformed option encoding as invalid input and +* drop early instead of continuing translation. +*/ +static int ipxlat_v4_srr_check (struct sk_buff *skb,const struct iphdr *hdr) +{ +const u8 *opt, *end; +u8 type, len, ptr; + +if (likely (hdr->ihl <=5 )) +return 0 ; + + opt = (const u8 *)(hdr +1 ); + end = (const u8 *)hdr + (hdr->ihl <<2 ); + +while (opt < end) { + type = opt[0 ]; +if (type ==IPOPT_END ) +return 0 ; +if (type ==IPOPT_NOOP ) { + opt++; +continue ; + } + +if (unlikely (end - opt <2 )) +return -EINVAL ; + + len = opt[1 ]; +if (unlikely (len <2 || opt + len > end)) +return -EINVAL ; + +if (type ==IPOPT_LSRR || type ==IPOPT_SSRR ) { +if (unlikely (len <3 )) +return -EINVAL ; + +/* points to the beginning of the next IP addr */ + ptr = opt[2 ]; +if (unlikely (ptr <4 )) +return -EINVAL ; +if (unlikely (ptr > len)) +return 0 ; +if (unlikely (ptr > len -3 )) +return -EINVAL ; + +return -EINVAL ; + } + + opt += len; + } + +return 0 ; +} + +static int ipxlat_v4_pull_l3 (struct sk_buff *skb,unsigned int l3_offset, +bool inner) +{ +const struct iphdr *iph; +unsigned int tot_len; +int l3_len; + +if (unlikely (!pskb_may_pull (skb, l3_offset +sizeof (*iph)))) +return -EINVAL ; + + iph = (const struct iphdr *)(skb->data + l3_offset); +if (unlikely (iph->version !=4 || iph->ihl <5 )) +return -EINVAL ; + + l3_len = iph->ihl <<2 ; +/* For inner packets use ntohs(iph->tot_len) instead of iph_totlen. +* If inner iph->tot_len is zero, iph_totlen would fall back to outer +* GSO metadata, which is unrelated to quoted inner packet length. +*/ + tot_len =unlikely (inner) ?ntohs (iph->tot_len) :iph_totlen (skb, iph); +if (unlikely (tot_len < l3_len)) +return -EINVAL ; + +if (unlikely (!pskb_may_pull (skb, l3_offset + l3_len))) +return -EINVAL ; + +return l3_len; +} + +static int ipxlat_v4_pull_l4 (struct sk_buff *skb,unsigned int l4_offset, +u8 l4_proto,bool *is_icmp_err) +{ +struct icmphdr *icmp; +struct udphdr *udp; +struct tcphdr *tcp; + + *is_icmp_err = false; + +switch (l4_proto) { +case IPPROTO_TCP : +if (unlikely (!pskb_may_pull (skb, l4_offset +sizeof (*tcp)))) +return -EINVAL ; + + tcp = (struct tcphdr *)(skb->data + l4_offset); +if (unlikely (tcp->doff <5 )) +return -EINVAL ; + +return __tcp_hdrlen (tcp); +case IPPROTO_UDP : +if (unlikely (!pskb_may_pull (skb, l4_offset +sizeof (*udp)))) +return -EINVAL ; + + udp = (struct udphdr *)(skb->data + l4_offset); +if (unlikely (ntohs (udp->len) <sizeof (*udp))) +return -EINVAL ; + +return sizeof (struct udphdr ); +case IPPROTO_ICMP : +if (unlikely (!pskb_may_pull (skb, l4_offset +sizeof (*icmp)))) +return -EINVAL ; + + icmp = (struct icmphdr *)(skb->data + l4_offset); + *is_icmp_err =icmp_is_err (icmp->type); +return sizeof (struct icmphdr ); +default : +return 0 ; + } +} + +static int ipxlat_v4_pull_icmp_inner (struct sk_buff *skb, +unsigned int inner_l3_off) +{ +struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +const struct iphdr *inner_l3_hdr; +unsigned int inner_l4_off; +int inner_l3_len, err; +bool is_icmp_err; + + inner_l3_len =ipxlat_v4_pull_l3 (skb, inner_l3_off, true); +if (unlikely (inner_l3_len <0 )) +return inner_l3_len; + inner_l3_hdr = (const struct iphdr *)(skb->data + inner_l3_off); + +/* accept non-first quoted fragments: only inner L3 is translatable */ + inner_l4_off = inner_l3_off + inner_l3_len; + cb->inner_l3_offset = inner_l3_off; + cb->inner_l3_hdr_len = inner_l3_len; + cb->inner_l4_offset = inner_l4_off; + +if (unlikely (!ipxlat_is_first_frag4 (inner_l3_hdr))) +return 0 ; + + err =ipxlat_v4_pull_l4 (skb, inner_l4_off, inner_l3_hdr->protocol, + &is_icmp_err); +if (unlikely (err <0 )) +return err; +if (unlikely (is_icmp_err)) +return -EINVAL ; + +return 0 ; +} + +static int ipxlat_v4_pull_hdrs (struct sk_buff *skb) +{ +const unsigned int l3_off =skb_network_offset (skb); +struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +int err, l3_len, l4_len =0 ; +const struct iphdr *l3_hdr; + +/* parse IPv4 header and get its full length including options */ + l3_len =ipxlat_v4_pull_l3 (skb, l3_off, false); +if (unlikely (l3_len <0 )) +return l3_len; + l3_hdr =ip_hdr (skb); + +if (unlikely (!ipxlat_v4_validate_addr (l3_hdr->daddr))) +return -EINVAL ; + +/* RFC 7915 Section 4.1 */ +if (unlikely (ipxlat_v4_srr_check (skb, l3_hdr))) +return -EINVAL ; +if (unlikely (l3_hdr->ttl <=1 )) +return -EINVAL ; + +/* RFC 7915 Section 1.2: +* Fragmented ICMP/ICMPv6 packets will not be translated by IP/ICMP +* translators. +*/ +if (unlikely (l3_hdr->protocol ==IPPROTO_ICMP && +ip_is_fragment (l3_hdr))) +return -EINVAL ; + + cb->l3_hdr_len = l3_len; + cb->l4_proto = l3_hdr->protocol; + cb->l4_off = l3_off + l3_len; + cb->payload_off = cb->l4_off; + cb->is_icmp_err = false; + +/* only non fragmented packets or first fragments have transport hdrs */ +if (unlikely (!ipxlat_is_first_frag4 (l3_hdr))) { +if (unlikely (!ipxlat_v4_validate_addr (l3_hdr->saddr))) +return -EINVAL ; +return 0 ; + } + + l4_len =ipxlat_v4_pull_l4 (skb, cb->l4_off, l3_hdr->protocol, + &cb->is_icmp_err); +if (unlikely (l4_len <0 )) +return l4_len; + +/* RFC 7915 Section 4.1: +* Illegal IPv4 sources are accepted only for ICMPv4 error translation. +*/ +if (unlikely (!ipxlat_v4_validate_addr (l3_hdr->saddr) && + !cb->is_icmp_err)) +return -EINVAL ; + + cb->payload_off = cb->l4_off + l4_len; + +if (unlikely (cb->is_icmp_err)) { +/* validate the quoted packet in an ICMP error */ + err =ipxlat_v4_pull_icmp_inner (skb, cb->payload_off); +if (unlikely (err)) +return err; + } + +return 0 ; +} + +static int ipxlat_v4_validate_icmp_csum (const struct sk_buff *skb) +{ +__sum16 csum; + +/* skip when checksum is not software-owned */ +if (skb->ip_summed !=CHECKSUM_NONE ) +return 0 ; + +/* compute checksum over ICMP header and payload, then fold to 16-bit +* Internet checksum to validate it +*/ + csum =csum_fold (skb_checksum (skb,skb_transport_offset (skb), +ipxlat_skb_datagram_len (skb),0 )); +return unlikely (csum) ? -EINVAL :0 ; +} + +/** +* ipxlat_v4_validate_skb - validate IPv4 input and fill parser metadata in cb +* @ipxlat: translator private context +* @skb: packet to validate +* +* Ensures required headers are present/consistent and stores parsed offsets +* into &struct ipxlat_cb for the translation path. +* +* Return: 0 on success, negative errno on validation failure. +*/ +int ipxlat_v4_validate_skb (struct ipxlat_priv *ipxlat,struct sk_buff *skb) +{ +struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +struct iphdr *l3_hdr; +struct udphdr *udph; +int err; + +if (unlikely (skb_shared (skb))) +return -EINVAL ; + + err =ipxlat_v4_pull_hdrs (skb); +if (unlikely (err)) +return err; + +skb_set_transport_header (skb, cb->l4_off); + +if (unlikely (cb->is_icmp_err)) { +if (unlikely (cb->l4_proto !=IPPROTO_ICMP )) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -EINVAL ; + } + +/* Translation path recomputes ICMPv6 checksum from scratch. +* Validate here so a corrupted ICMPv4 error is not converted +* into a translated packet with a valid checksum. +*/ +return ipxlat_v4_validate_icmp_csum (skb); + } + + l3_hdr =ip_hdr (skb); +if (likely (cb->l4_proto !=IPPROTO_UDP )) +return 0 ; +if (unlikely (!ipxlat_is_first_frag4 (l3_hdr))) +return 0 ; + + udph =udp_hdr (skb); +if (likely (udph->check !=0 )) +return 0 ; + +/* We are in the path where L4 header is present (unfragmented packets +* or first fragments) and is UDP. +* Fragmented checksum-less IPv4 UDP is rejected because 4->6 cannot +* reliably translate it. +*/ +if (unlikely (ip_is_fragment (l3_hdr))) +return -EINVAL ; + +/* udph->len bounds the span used to compute replacement checksum */ +if (unlikely (ntohs (udph->len) > skb->len - cb->l4_off)) +return -EINVAL ; + + cb->udp_zero_csum_len =ntohs (udph->len); + +return 0 ; }int ipxlat_v6_validate_skb (struct sk_buff *skb)
Signature · 1 line
2.53.0
RFC 5/15 ipxlat: add IPv6 packet validation path
In reply to Ralf LiciImplement IPv6 packet parsing and validation, including extension header traversal, fragment-header constraints, and ICMPv6 checksum handling for informational/error traffic. The parser fills skb control-block metadata for 6->4 translation and quoted-inner packet handling.
--- drivers/net/ipxlat/packet.c | 326 +++++++++++++++++++++++++++++++++++- 1 file changed, 325 insertions(+), 1 deletion(-)
drivers/net/ipxlat/packet.c +325 -1
@@ -401,7 +401,331 @@ int ipxlat_v4_validate_skb(struct ipxlat_priv *ipxlat, struct sk_buff *skb)return 0 ; } +static bool ipxlat_v6_validate_saddr (const struct in6_addr *addr6) +{ +return !(ipv6_addr_any (addr6) ||ipv6_addr_loopback (addr6) || +ipv6_addr_is_multicast (addr6)); +} + +static int ipxlat_v6_pull_l4 (struct sk_buff *skb,unsigned int l4_offset, +u8 l4_proto,bool *is_icmp_err) +{ +struct icmp6hdr *icmp; +struct udphdr *udp; +struct tcphdr *tcp; + + *is_icmp_err = false; + +switch (l4_proto) { +case NEXTHDR_TCP : +if (unlikely (!pskb_may_pull (skb, l4_offset +sizeof (*tcp)))) +return -EINVAL ; + tcp = (struct tcphdr *)(skb->data + l4_offset); +return __tcp_hdrlen (tcp); +case NEXTHDR_UDP : +if (unlikely (!pskb_may_pull (skb, l4_offset +sizeof (*udp)))) +return -EINVAL ; + udp = (struct udphdr *)(skb->data + l4_offset); +if (unlikely (ntohs (udp->len) <sizeof (*udp))) +return -EINVAL ; +return sizeof (struct udphdr ); +case NEXTHDR_ICMP : +if (unlikely (!pskb_may_pull (skb, l4_offset +sizeof (*icmp)))) +return -EINVAL ; + icmp = (struct icmp6hdr *)(skb->data + l4_offset); + *is_icmp_err =icmpv6_is_err (icmp->icmp6_type); +return sizeof (struct icmp6hdr ); +default : +return 0 ; + } +} + +/* Basic IPv6 header walk: parse only the packet starting at l3_offset. +* It does not inspect quoted inner packets carried by ICMP errors. +*/ +static int ipxlat_v6_walk_hdrs (struct sk_buff *skb,unsigned int l3_offset, +u8 *l4_proto,unsigned int *fhdr_offset, +unsigned int *l4_offset,bool *has_l4) +{ +unsigned int frag_hdr_off, l4hdr_off; +struct frag_hdr *frag; +struct ipv6hdr *ip6; +bool first_frag; +int err; + +/* cannot use default getter because this function is used both for +* outer and inner packets +*/ + ip6 = (struct ipv6hdr *)(skb->data + l3_offset); + +/* if present, locate Fragment Header first because it affects +* whether transport headers are available +*/ + frag_hdr_off = l3_offset; + err =ipv6_find_hdr (skb, &frag_hdr_off,NEXTHDR_FRAGMENT ,NULL ,NULL ); +if (unlikely (err <0 && err != -ENOENT )) +return -EINVAL ; + + *has_l4 = true; + *fhdr_offset =0 ; +if (unlikely (err ==NEXTHDR_FRAGMENT )) { +if (unlikely (!pskb_may_pull (skb, frag_hdr_off +sizeof (*frag)))) +return -EINVAL ; + frag = (struct frag_hdr *)(skb->data + frag_hdr_off); + +/* remember Fragment Header offset for downstream logic */ + *fhdr_offset = frag_hdr_off; + first_frag =ipxlat_is_first_frag6 (frag); + +/* ipv6 forbids chaining FHs */ +if (unlikely (frag->nexthdr ==NEXTHDR_FRAGMENT )) +return -EINVAL ; + +/* RFC 7915 Section 5.1.1 does not support extension headers +* after FH (except NEXTHDR_NONE) +*/ +if (unlikely (ipv6_ext_hdr (frag->nexthdr) && + frag->nexthdr !=NEXTHDR_NONE )) +return -EPROTONOSUPPORT ; + +/* non-first fragments do not carry a full transport header */ +if (!first_frag) { + *l4_proto = frag->nexthdr; +/* first byte after FH is fragment payload, +* not L4 header +*/ + *l4_offset = frag_hdr_off +sizeof (struct frag_hdr ); + *has_l4 = false; +return 0 ; + } + } + +/* walk extension headers to terminal protocol and compute offsets used +* by validation/translation +*/ + l4hdr_off = l3_offset; + err =ipv6_find_hdr (skb, &l4hdr_off,-1 ,NULL ,NULL ); +if (unlikely (err <0 )) +return -EINVAL ; + + *l4_proto = err; + *l4_offset = l4hdr_off; +return 0 ; +} + +/* RFC 7915 Section 5.1 says a Routing Header with Segments Left != 0 +* must not be translated. We detect it by asking ipv6_find_hdr not to +* skip RH, then emit ICMPv6 Parameter Problem pointing to segments_left. +*/ +static int ipxlat_v6_check_rh (struct sk_buff *skb) +{ +unsigned int rh_off; +int flags, nexthdr; + + rh_off =0 ; + flags =IP6_FH_F_SKIP_RH ; + nexthdr =ipv6_find_hdr (skb, &rh_off,NEXTHDR_ROUTING ,NULL , &flags); +if (unlikely (nexthdr <0 && nexthdr != -ENOENT )) +return -EINVAL ; +if (likely (nexthdr !=NEXTHDR_ROUTING )) +return 0 ; + +return -EINVAL ; +} + +static int ipxlat_v6_pull_outer_l3 (struct sk_buff *skb) +{ +const unsigned int l3_off =skb_network_offset (skb); +struct ipv6hdr *l3_hdr; + +if (unlikely (!pskb_may_pull (skb, l3_off +sizeof (*l3_hdr)))) +return -EINVAL ; + l3_hdr =ipv6_hdr (skb); + +/* translator does not support jumbograms; payload_len must match skb */ +if (unlikely (l3_hdr->version !=6 || + skb->len !=sizeof (*l3_hdr) + +be16_to_cpu (l3_hdr->payload_len) || + !ipxlat_v6_validate_saddr (&l3_hdr->saddr))) +return -EINVAL ; + +if (unlikely (l3_hdr->hop_limit <=1 )) +return -EINVAL ; + +return 0 ; +} + +static int ipxlat_v6_pull_icmp_inner (struct sk_buff *skb, +unsigned int outer_payload_off) +{ +unsigned int inner_fhdr_off, inner_l4_off; +struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +struct ipv6hdr *inner_ip6; +bool has_l4, is_icmp_err; +u8 inner_l4_proto; +int err; + +if (unlikely (!pskb_may_pull (skb, + outer_payload_off +sizeof (*inner_ip6)))) +return -EINVAL ; + + inner_ip6 = (struct ipv6hdr *)(skb->data + outer_payload_off); +if (unlikely (inner_ip6->version !=6 )) +return -EINVAL ; + + err =ipxlat_v6_walk_hdrs (skb, outer_payload_off, &inner_l4_proto, + &inner_fhdr_off, &inner_l4_off, &has_l4); +if (unlikely (err)) +return err; + + cb->inner_l3_offset = outer_payload_off; + cb->inner_l4_offset = inner_l4_off; + cb->inner_fragh_off = inner_fhdr_off; + cb->inner_l4_proto = inner_l4_proto; + +if (likely (has_l4)) { + err =ipxlat_v6_pull_l4 (skb, inner_l4_off, inner_l4_proto, + &is_icmp_err); +if (unlikely (err <0 )) +return err; +if (unlikely (is_icmp_err)) +return -EINVAL ; + } + +return 0 ; +} + +static int ipxlat_v6_pull_hdrs (struct sk_buff *skb) +{ +const unsigned int l3_off =skb_network_offset (skb); +unsigned int fragh_off, l4_off, payload_off; +struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +int l3_len, l4_len, err; +struct frag_hdr *frag; +bool has_l4; +u8 l4_proto; + +/* parse IPv6 base header and perform basic structural checks */ + err =ipxlat_v6_pull_outer_l3 (skb); +if (unlikely (err)) +return err; + +/* walk extension/fragment headers and locate the transport header */ + err =ipxlat_v6_walk_hdrs (skb, l3_off, &l4_proto, &fragh_off, &l4_off, + &has_l4); +/* -EPROTONOSUPPORT means packet layout is syntactically valid but +* unsupported by our RFC 7915 path +*/ +if (unlikely (err == -EPROTONOSUPPORT )) +return -EINVAL ; +if (unlikely (err)) +return err; + + l3_len = l4_off - l3_off; + payload_off = l4_off; + +if (likely (has_l4)) { + l4_len =ipxlat_v6_pull_l4 (skb, l4_off, l4_proto, + &cb->is_icmp_err); +if (unlikely (l4_len <0 )) +return l4_len; + payload_off += l4_len; + } + +/* RFC 7915 Section 5.1 */ + err =ipxlat_v6_check_rh (skb); +if (unlikely (err)) +return err; + +if (unlikely (l4_proto ==NEXTHDR_ICMP )) { +/* A stateless translator cannot reliably translate ICMP +* checksum across real IPv6 fragments, so fragmented ICMP is +* dropped. A Fragment Header alone, however, is not enough to +* decide: so-called atomic fragments (offset=0, M=0) carry a +* Fragment Header but are not actually fragmented. +*/ +if (unlikely (fragh_off)) { +if (unlikely (!pskb_may_pull (skb, + fragh_off +sizeof (*frag)))) +return -EINVAL ; + + frag = (struct frag_hdr *)(skb->data + fragh_off); +if (unlikely (ipxlat_get_frag6_offset (frag) || + (be16_to_cpu (frag->frag_off) &IP6_MF ))) +return -EINVAL ; + } + +if (unlikely (cb->is_icmp_err)) { +/* validate the quoted packet in an ICMP error */ + err =ipxlat_v6_pull_icmp_inner (skb, payload_off); +if (unlikely (err)) +return err; + } + } + + cb->l4_proto = l4_proto; + cb->l4_off = l4_off; + cb->fragh_off = fragh_off; + cb->payload_off = payload_off; + cb->l3_hdr_len = l3_len; + +return 0 ; +} + +static int ipxlat_v6_validate_icmp_csum (const struct sk_buff *skb) +{ +struct ipv6hdr *iph6; +unsigned int len; +__sum16 csum; + +if (skb->ip_summed !=CHECKSUM_NONE ) +return 0 ; + + iph6 =ipv6_hdr (skb); + len =ipxlat_skb_datagram_len (skb); + csum =csum_ipv6_magic (&iph6->saddr, &iph6->daddr, len,NEXTHDR_ICMP , +skb_checksum (skb,skb_transport_offset (skb), len, +0 )); + +return unlikely (csum) ? -EINVAL :0 ; +} + +/** +* ipxlat_v6_validate_skb - validate IPv6 input and fill parser metadata in cb +* @skb: packet to validate +* +* Ensures required headers are present/consistent and stores parsed offsets +* into &struct ipxlat_cb for the translation path. +* +* Return: 0 on success, negative errno on validation failure. +*/ int ipxlat_v6_validate_skb (struct sk_buff *skb) { -return -EOPNOTSUPP ; +struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +int err; + +if (unlikely (skb_shared (skb))) +return -EINVAL ; + + err =ipxlat_v6_pull_hdrs (skb); +if (unlikely (err)) +return err; + +skb_set_transport_header (skb, cb->l4_off); + +if (unlikely (cb->is_icmp_err)) { +if (unlikely (cb->l4_proto !=NEXTHDR_ICMP )) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -EINVAL ; + } + +/* The translated ICMPv4 checksum is recomputed from scratch, +* so reject bad ICMPv6 error checksums before conversion. +*/ + err =ipxlat_v6_validate_icmp_csum (skb); +if (unlikely (err)) +return err; + } + +return 0 ; }
Signature · 1 line
2.53.0
kernel test robot
build botRe: [RFC net-next 05/15] ipxlat: add IPv6 packet validation path
kernel test robot noticed the following build warnings:
Hi Ralf,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Ralf-Lici/drivers-net-add-ipxlat-netdevice-skeleton-and-build-plumbing/20260321-005756 base: net-next/main patch link: https://lore.kernel.org/r/20260319151230.655687-6-ralf%40mandelbit.com patch subject: [RFC net-next 05/15] ipxlat: add IPv6 packet validation path config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20260322/[email protected]/config) compiler: sh4-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260322/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/net/ipxlat/packet.c: In function 'ipxlat_v6_walk_hdrs':
>> drivers/net/ipxlat/packet.c:452:25: warning: variable 'ip6' set but not used [-Wunused-but-set-variable]
452 | struct ipv6hdr *ip6;
| ^~~vim +/ip6 +452 drivers/net/ipxlat/packet.c
442
443 /* Basic IPv6 header walk: parse only the packet starting at l3_offset.
444 * It does not inspect quoted inner packets carried by ICMP errors.
445 */
446 static int ipxlat_v6_walk_hdrs(struct sk_buff *skb, unsigned int l3_offset,
447 u8 *l4_proto, unsigned int *fhdr_offset,
448 unsigned int *l4_offset, bool *has_l4)
449 {
450 unsigned int frag_hdr_off, l4hdr_off;
451 struct frag_hdr *frag;
> 452 struct ipv6hdr *ip6;
453 bool first_frag;
454 int err;
455
456 /* cannot use default getter because this function is used both for
457 * outer and inner packets
458 */
459 ip6 = (struct ipv6hdr *)(skb->data + l3_offset);
460
461 /* if present, locate Fragment Header first because it affects
462 * whether transport headers are available
463 */
464 frag_hdr_off = l3_offset;
465 err = ipv6_find_hdr(skb, &frag_hdr_off, NEXTHDR_FRAGMENT, NULL, NULL);
466 if (unlikely(err < 0 && err != -ENOENT))
467 return -EINVAL;
468
469 *has_l4 = true;
470 *fhdr_offset = 0;
471 if (unlikely(err == NEXTHDR_FRAGMENT)) {
472 if (unlikely(!pskb_may_pull(skb, frag_hdr_off + sizeof(*frag))))
473 return -EINVAL;
474 frag = (struct frag_hdr *)(skb->data + frag_hdr_off);
475
476 /* remember Fragment Header offset for downstream logic */
477 *fhdr_offset = frag_hdr_off;
478 first_frag = ipxlat_is_first_frag6(frag);
479
480 /* ipv6 forbids chaining FHs */
481 if (unlikely(frag->nexthdr == NEXTHDR_FRAGMENT))
482 return -EINVAL;
483
484 /* RFC 7915 Section 5.1.1 does not support extension headers
485 * after FH (except NEXTHDR_NONE)
486 */
487 if (unlikely(ipv6_ext_hdr(frag->nexthdr) &&
488 frag->nexthdr != NEXTHDR_NONE))
489 return -EPROTONOSUPPORT;
490
491 /* non-first fragments do not carry a full transport header */
492 if (!first_frag) {
493 *l4_proto = frag->nexthdr;
494 /* first byte after FH is fragment payload,
495 * not L4 header
496 */
497 *l4_offset = frag_hdr_off + sizeof(struct frag_hdr);
498 *has_l4 = false;
499 return 0;
500 }
501 }
502
503 /* walk extension headers to terminal protocol and compute offsets used
504 * by validation/translation
505 */
506 l4hdr_off = l3_offset;
507 err = ipv6_find_hdr(skb, &l4hdr_off, -1, NULL, NULL);
508 if (unlikely(err < 0))
509 return -EINVAL;
510
511 *l4_proto = err;
512 *l4_offset = l4hdr_off;
513 return 0;
514 }
515
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [RFC net-next 05/15] ipxlat: add IPv6 packet validation path
In reply to Ralf Licikernel test robot noticed the following build errors:
Hi Ralf,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:
[auto build test ERROR on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Ralf-Lici/drivers-net-add-ipxlat-netdevice-skeleton-and-build-plumbing/20260321-005756 base: net-next/main patch link: https://lore.kernel.org/r/20260319151230.655687-6-ralf%40mandelbit.com patch subject: [RFC net-next 05/15] ipxlat: add IPv6 packet validation path config: hexagon-allmodconfig (https://download.01.org/0day-ci/archive/20260322/[email protected]/config) compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260322/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
drivers/net/ipxlat/packet.c:452:18: warning: variable 'ip6' set but not used [-Wunused-but-set-variable]
452 | struct ipv6hdr *ip6;
| ^
>> drivers/net/ipxlat/packet.c:686:9: error: call to undeclared function 'csum_ipv6_magic'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
686 | csum = csum_ipv6_magic(&iph6->saddr, &iph6->daddr, len, NEXTHDR_ICMP,
| ^
drivers/net/ipxlat/packet.c:686:9: note: did you mean 'csum_tcpudp_magic'?
arch/hexagon/include/asm/checksum.h:21:9: note: 'csum_tcpudp_magic' declared here
21 | __sum16 csum_tcpudp_magic(__be32 saddr, __be32 daddr,
| ^ arch/hexagon/include/asm/checksum.h:20:27: note: expanded from macro 'csum_tcpudp_magic'
20 | #define csum_tcpudp_magic csum_tcpudp_magic
| ^
1 warning and 1 error generated.
vim +/csum_ipv6_magic +686 drivers/net/ipxlat/packet.c
674
675 static int ipxlat_v6_validate_icmp_csum(const struct sk_buff *skb)
676 {
677 struct ipv6hdr *iph6;
678 unsigned int len;
679 __sum16 csum;
680
681 if (skb->ip_summed != CHECKSUM_NONE)
682 return 0;
683
684 iph6 = ipv6_hdr(skb);
685 len = ipxlat_skb_datagram_len(skb);
> 686 csum = csum_ipv6_magic(&iph6->saddr, &iph6->daddr, len, NEXTHDR_ICMP,
687 skb_checksum(skb, skb_transport_offset(skb), len,
688 0));
689
690 return unlikely(csum) ? -EINVAL : 0;
691 }
692
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [RFC net-next 05/15] ipxlat: add IPv6 packet validation path
In reply to Ralf LiciHi Ralf,
Quoted 7 lines
drivers/net/ipxlat/packet.c +7
-0+static int ipxlat_v6_validate_icmp_csum (const struct sk_buff *skb) +{ +struct ipv6hdr *iph6; +unsigned int len; +__sum16 csum; + +if (skb->ip_summed !=CHECKSUM_NONE )
drivers/net/ipxlat/packet.c int ipxlat_v4_validate_skb(struct ipxlat_priv *ipxlat, struct sk_buff *skb) · line 691
Quoted 10 lines
drivers/net/ipxlat/packet.c +10
-0+return 0 ; + + iph6 =ipv6_hdr (skb); + len =ipxlat_skb_datagram_len (skb); + csum =csum_ipv6_magic (&iph6->saddr, &iph6->daddr, len,NEXTHDR_ICMP , +skb_checksum (skb,skb_transport_offset (skb), len, +0 )); + +return unlikely (csum) ? -EINVAL :0 ; +}
We should include net/ip6_checksum.h to make x86_64 with KMSAN/KASAN and other architectures with optional _HAVE_ARCH_IPV6_CSUM happy.
Best regards,
Xavier
Re: [RFC net-next 05/15] ipxlat: add IPv6 packet validation path
Quoted 13 lines · Xavier HSINYUAN
Hi Ralf,
Quoted 11 lines
drivers/net/ipxlat/packet.c +11
-0+static int ipxlat_v6_validate_icmp_csum (const struct sk_buff *skb) +{ +struct ipv6hdr *iph6; +unsigned int len; +__sum16 csum; + +if (skb->ip_summed !=CHECKSUM_NONE ) +return 0 ; + + iph6 =ipv6_hdr (skb); + len =ipxlat_skb_datagram_len (skb);
Quoted 8 lines
drivers/net/ipxlat/packet.c int ipxlat_v4_validate_skb(struct ipxlat_priv *ipxlat, struct sk_buff *skb) · line 691
Quoted 6 lines
drivers/net/ipxlat/packet.c +6
-0+ csum =csum_ipv6_magic (&iph6->saddr, &iph6->daddr, len,NEXTHDR_ICMP , +skb_checksum (skb,skb_transport_offset (skb), len, +0 )); + +return unlikely (csum) ? -EINVAL :0 ; +}We should include
net/ip6_checksum.hto makex86_64with KMSAN/KASAN and other architectures with optional_HAVE_ARCH_IPV6_CSUMhappy.
Hi Xavier,
Yep, this showed up in patchwork build failures as well. I'll add the required header where needed (packet.c and icmp_{46,64}.c) in the next revision.
Thanks!
Quoted 4 lines
Best regards,
Xavier
Signature · 2 lines
Ralf Lici Mandelbit Srl
RFC 6/15 ipxlat: add transport checksum and offload helpers
In reply to Ralf LiciAdd shared transport-layer helpers for checksum manipulation and offload metadata normalization across family translation.
This introduces incremental and full checksum utilities plus generic ICMP relayout/offload finalization routines reused by later 4->6 and 6->4 transport translation paths.
--- drivers/net/ipxlat/transport.c | 146 +++++++++++++++++++++++++++++++++ drivers/net/ipxlat/transport.h | 83 +++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 drivers/net/ipxlat/transport.c create mode 100644 drivers/net/ipxlat/transport.h
drivers/net/ipxlat/transport.c new file +146 -0
@@ -0,0 +1,146 @@ +// SPDX-License-Identifier: GPL-2.0 +/* IPXLAT - Stateless IP/ICMP Translation (SIIT) virtual device driver +* +* Copyright (C) 2024- Alberto Leiva Popper <[email protected]> +* Copyright (C) 2026- Mandelbit SRL +* Copyright (C) 2026- Daniel Gröber <[email protected]> +* +* Author: Alberto Leiva Popper <[email protected]> +* Antonio Quartulli <[email protected]> +* Daniel Gröber <[email protected]> +* Ralf Lici <[email protected]> +*/ + +#include <net/ip.h> +#include <net/ip6_checksum.h> +#include <net/tcp.h> +#include <net/udp.h> + +#include "packet.h" +#include "transport.h" + +/* set CHECKSUM_PARTIAL metadata for transport checksum completion */ +int ipxlat_set_partial_csum (struct sk_buff *skb,u16 csum_offset) +{ +if (likely (skb_partial_csum_set (skb,skb_transport_offset (skb), + csum_offset))) +return 0 ; +return -EINVAL ; +} + +static __wsum ipxlat_pseudohdr6_csum (const struct ipv6hdr *hdr) +{ +return ~csum_unfold (csum_ipv6_magic (&hdr->saddr, &hdr->daddr,0 ,0 ,0 )); +} + +static __wsum ipxlat_pseudohdr4_csum (const struct iphdr *hdr) +{ +return csum_tcpudp_nofold (hdr->saddr, hdr->daddr,0 ,0 ,0 ); +} + +static __sum16 ipxlat_46_update_csum (__sum16 csum16, +const struct iphdr *in_ip4, +const void *in_l4_hdr, +const struct ipv6hdr *out_ip6, +const void *out_l4_hdr,size_t l4_hdr_len) +{ +__wsum csum; + + csum = ~csum_unfold (csum16); + +/* replace pseudohdr and L4 header contributions, payload unchanged */ + csum =csum_sub (csum,ipxlat_pseudohdr4_csum (in_ip4)); + csum =csum_sub (csum,csum_partial (in_l4_hdr, l4_hdr_len,0 )); + csum =csum_add (csum,ipxlat_pseudohdr6_csum (out_ip6)); + csum =csum_add (csum,csum_partial (out_l4_hdr, l4_hdr_len,0 )); +return csum_fold (csum); +} + +static __sum16 ipxlat_64_update_csum (__sum16 csum16, +const struct ipv6hdr *in_ip6, +const void *in_l4_hdr, +size_t in_l4_hdr_len, +const struct iphdr *out_ip4, +const void *out_l4_hdr, +size_t out_l4_hdr_len) +{ +__wsum csum; + + csum = ~csum_unfold (csum16); + +/* only address terms matter because L4 length/proto are unchanged */ + csum =csum_sub (csum,ipxlat_pseudohdr6_csum (in_ip6)); + csum =csum_sub (csum,csum_partial (in_l4_hdr, in_l4_hdr_len,0 )); + + csum =csum_add (csum,ipxlat_pseudohdr4_csum (out_ip4)); + csum =csum_add (csum,csum_partial (out_l4_hdr, out_l4_hdr_len,0 )); + +return csum_fold (csum); +} + +__sum16 ipxlat_l4_csum_ipv6 (const struct in6_addr *saddr, +const struct in6_addr *daddr, +const struct sk_buff *skb,unsigned int l4_off, +unsigned int l4_len,u8 proto) +{ +return csum_ipv6_magic (saddr, daddr, l4_len, proto, +skb_checksum (skb, l4_off, l4_len,0 )); +} + +/* Normalize checksum/offload metadata after address-family translation. +* +* Translation changes protocol family but keeps transport payload semantics +* intact, so TCP GSO only needs type remap (gso_from -> gso_to), while ICMP +* must clear stale GSO state because there is no ICMP GSO transform here. +* +* This mirrors forwarding expectations: reject LRO on xmit and clear hash +* when tuple semantics may have changed (fragments and non-TCP/UDP). +*/ +int ipxlat_finalize_offload (struct sk_buff *skb,u8 l4_proto,bool is_fragment, +u32 gso_from,u32 gso_to) +{ +struct skb_shared_info *shinfo; + +if (unlikely (skb->ip_summed ==CHECKSUM_COMPLETE )) + skb->ip_summed =CHECKSUM_NONE ; + +if (!skb_is_gso (skb)) + goto out_hash; + +/* align with forwarding paths that reject LRO skbs before xmit */ +if (unlikely (skb_warn_if_lro (skb))) +return -EINVAL ; + + shinfo =skb_shinfo (skb); +switch (l4_proto) { +case IPPROTO_TCP : +/* segment payload size is unchanged by address-family +* translation so there's no need to touch gso_size +*/ +if (shinfo->gso_type & gso_from) { + shinfo->gso_type &= ~gso_from; + shinfo->gso_type |= gso_to; + }else if (unlikely (!(shinfo->gso_type & gso_to))) { +return -EOPNOTSUPP ; + } +break ; +case IPPROTO_UDP : +break ; +case IPPROTO_ICMP : +/* for ICMP there is no GSO transform; clear stale offload +* metadata so the stack treats it as a normal frame +*/ +skb_gso_reset (skb); +break ; +default : +return -EPROTONOSUPPORT ; + } + +out_hash: +if (unlikely (is_fragment || + (l4_proto !=IPPROTO_TCP && l4_proto !=IPPROTO_UDP ))) +skb_clear_hash (skb); +else +skb_clear_hash_if_not_l4 (skb); +return 0 ; +}
drivers/net/ipxlat/transport.h new file +83 -0
83 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC 7/15 ipxlat: add 4to6 and 6to4 TCP/UDP translation helpers
In reply to Ralf LiciAdd protocol-specific transport translation entry points for both address-family directions.
This wires checksum adjustment for outer and quoted-inner TCP/UDP headers and provides the transport routines consumed by the translation engine.
--- drivers/net/ipxlat/transport.c | 194 +++++++++++++++++++++++++++++++++ drivers/net/ipxlat/transport.h | 20 ++++ 2 files changed, 214 insertions(+)
drivers/net/ipxlat/transport.c +194 -0
@@ -144,3 +144,197 @@ int ipxlat_finalize_offload(struct sk_buff *skb, u8 l4_proto, bool is_fragment,skb_clear_hash_if_not_l4 (skb);return 0 ; } + +int ipxlat_46_outer_tcp (struct sk_buff *skb,const struct iphdr *in4) +{ +const struct ipv6hdr *iph6 =ipv6_hdr (skb); +struct tcphdr *tcp_new =tcp_hdr (skb); +struct tcphdr tcp_old; +__sum16 csum16; + +/* CHECKSUM_PARTIAL keeps a pseudohdr seed in check, not a final +* transport checksum. For 4->6, we only re-seed it with IPv6 pseudohdr +* data and keep completion deferred to offload. +*/ +if (skb->ip_summed ==CHECKSUM_PARTIAL ) { + tcp_new->check = ~tcp_v6_check (ipxlat_skb_datagram_len (skb), + &iph6->saddr, &iph6->daddr,0 ); +return ipxlat_set_partial_csum (skb, + offsetof(struct tcphdr , check)); + } + +/* zeroing check in old/new headers avoids double-accounting it */ + csum16 = tcp_new->check; + tcp_old = *tcp_new; + tcp_old.check =0 ; + tcp_new->check =0 ; + tcp_new->check =ipxlat_46_update_csum (csum16, in4, + &tcp_old, iph6, tcp_new, +sizeof (*tcp_new)); + skb->ip_summed =CHECKSUM_NONE ; +return 0 ; +} + +int ipxlat_46_outer_udp (struct sk_buff *skb,const struct iphdr *in4) +{ +const struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +const struct ipv6hdr *iph6 =ipv6_hdr (skb); +struct udphdr *udp_new =udp_hdr (skb); +struct udphdr udp_old; +__sum16 csum16; + +/* outer path enforces UDP zero-checksum policy in validation */ +if (skb->ip_summed ==CHECKSUM_PARTIAL &&likely (udp_new->check !=0 )) { + udp_new->check = ~udp_v6_check (ipxlat_skb_datagram_len (skb), + &iph6->saddr, &iph6->daddr,0 ); +return ipxlat_set_partial_csum (skb, + offsetof(struct udphdr , check)); + } + +/* incoming UDP IPv4 has no checksum (legal in IPv4, not in IPv6) */ +if (unlikely (udp_new->check ==0 )) { +if (unlikely (!cb->udp_zero_csum_len)) +return -EINVAL ; + + udp_new->check = +ipxlat_l4_csum_ipv6 (&iph6->saddr, &iph6->daddr, skb, +skb_transport_offset (skb), + cb->udp_zero_csum_len,IPPROTO_UDP ); +/* 0x0000 on wire means "no checksum"; preserve computed zero */ +if (udp_new->check ==0 ) + udp_new->check =CSUM_MANGLED_0 ; + skb->ip_summed =CHECKSUM_NONE ; +return 0 ; + } + + csum16 = udp_new->check; + udp_old = *udp_new; + udp_old.check =0 ; + udp_new->check =0 ; + udp_new->check =ipxlat_46_update_csum (csum16, in4, + &udp_old, iph6, udp_new, +sizeof (*udp_new)); + skb->ip_summed =CHECKSUM_NONE ; +return 0 ; +} + +int ipxlat_46_inner_tcp (struct sk_buff *skb,const struct iphdr *in4, +const struct ipv6hdr *iph6,struct tcphdr *tcp_new) +{ +struct tcphdr tcp_old; +__sum16 csum16; + + csum16 = tcp_new->check; + tcp_old = *tcp_new; + tcp_old.check =0 ; + tcp_new->check =0 ; + tcp_new->check =ipxlat_46_update_csum (csum16, in4, &tcp_old, iph6, + tcp_new,sizeof (*tcp_new)); +return 0 ; +} + +int ipxlat_46_inner_udp (struct sk_buff *skb,const struct iphdr *in4, +const struct ipv6hdr *iph6,struct udphdr *udp_new) +{ +struct udphdr udp_old; +__sum16 csum16; + +if (unlikely (udp_new->check ==0 )) +return 0 ; + + csum16 = udp_new->check; + udp_old = *udp_new; + udp_old.check =0 ; + udp_new->check =0 ; + udp_new->check =ipxlat_46_update_csum (csum16, in4, &udp_old, iph6, + udp_new,sizeof (*udp_new)); +return 0 ; +} + +int ipxlat_64_outer_tcp (struct sk_buff *skb,const struct ipv6hdr *in6) +{ +struct tcphdr tcp_old, *tcp_new; +__sum16 csum16; + + tcp_new =tcp_hdr (skb); + +if (skb->ip_summed ==CHECKSUM_PARTIAL ) { + tcp_new->check = ~tcp_v4_check (ipxlat_skb_datagram_len (skb), +ip_hdr (skb)->saddr, +ip_hdr (skb)->daddr,0 ); +return ipxlat_set_partial_csum (skb, + offsetof(struct tcphdr , check)); + } + + csum16 = tcp_new->check; + tcp_old = *tcp_new; + tcp_old.check =0 ; + tcp_new->check =0 ; + tcp_new->check =ipxlat_64_update_csum (csum16, in6, &tcp_old, +sizeof (tcp_old),ip_hdr (skb), + tcp_new,sizeof (*tcp_new)); + skb->ip_summed =CHECKSUM_NONE ; +return 0 ; +} + +int ipxlat_64_outer_udp (struct sk_buff *skb,const struct ipv6hdr *in6) +{ +struct udphdr udp_old, *udp_new; +__sum16 csum16; + + udp_new =udp_hdr (skb); + +if (skb->ip_summed ==CHECKSUM_PARTIAL ) { + udp_new->check = ~udp_v4_check (ipxlat_skb_datagram_len (skb), +ip_hdr (skb)->saddr, +ip_hdr (skb)->daddr,0 ); +return ipxlat_set_partial_csum (skb, + offsetof(struct udphdr , check)); + } + + csum16 = udp_new->check; + udp_old = *udp_new; + udp_old.check =0 ; + udp_new->check =0 ; + udp_new->check =ipxlat_64_update_csum (csum16, in6, &udp_old, +sizeof (udp_old),ip_hdr (skb), + udp_new,sizeof (*udp_new)); +if (udp_new->check ==0 ) + udp_new->check =CSUM_MANGLED_0 ; + skb->ip_summed =CHECKSUM_NONE ; +return 0 ; +} + +int ipxlat_64_inner_tcp (struct sk_buff *skb,const struct ipv6hdr *in6, +const struct iphdr *out4,struct tcphdr *tcp_new) +{ +struct tcphdr tcp_old; +__sum16 csum16; + + csum16 = tcp_new->check; + tcp_old = *tcp_new; + tcp_old.check =0 ; + tcp_new->check =0 ; + tcp_new->check =ipxlat_64_update_csum (csum16, in6, &tcp_old, +sizeof (tcp_old), out4, tcp_new, +sizeof (*tcp_new)); +return 0 ; +} + +int ipxlat_64_inner_udp (struct sk_buff *skb,const struct ipv6hdr *in6, +const struct iphdr *out4,struct udphdr *udp_new) +{ +struct udphdr udp_old; +__sum16 csum16; + + csum16 = udp_new->check; + udp_old = *udp_new; + udp_old.check =0 ; + udp_new->check =0 ; + udp_new->check =ipxlat_64_update_csum (csum16, in6, &udp_old, +sizeof (udp_old), out4, udp_new, +sizeof (*udp_new)); +if (udp_new->check ==0 ) + udp_new->check =CSUM_MANGLED_0 ; +return 0 ; +}
drivers/net/ipxlat/transport.h +20 -0
@@ -80,4 +80,24 @@ __sum16 ipxlat_l4_csum_ipv6(const struct in6_addr *saddr,int ipxlat_finalize_offload (struct sk_buff *skb,u8 l4_proto,bool is_fragment,u32 gso_from,u32 gso_to); +/* outer transport translation helpers (packet L3 already translated) */ +int ipxlat_46_outer_tcp (struct sk_buff *skb,const struct iphdr *in4); +int ipxlat_46_outer_udp (struct sk_buff *skb,const struct iphdr *in4); + +/* quoted-inner transport translation helpers for ICMP error payloads */ +int ipxlat_46_inner_tcp (struct sk_buff *skb,const struct iphdr *in4, +const struct ipv6hdr *iph6,struct tcphdr *tcp_new); +int ipxlat_46_inner_udp (struct sk_buff *skb,const struct iphdr *in4, +const struct ipv6hdr *iph6,struct udphdr *udp_new); + +/* outer transport translation helpers (packet L3 already translated) */ +int ipxlat_64_outer_tcp (struct sk_buff *skb,const struct ipv6hdr *in6); +int ipxlat_64_outer_udp (struct sk_buff *skb,const struct ipv6hdr *in6); + +/* quoted-inner transport translation helpers for ICMP error payloads */ +int ipxlat_64_inner_tcp (struct sk_buff *skb,const struct ipv6hdr *in6, +const struct iphdr *out4,struct tcphdr *tcp_new); +int ipxlat_64_inner_udp (struct sk_buff *skb,const struct ipv6hdr *in6, +const struct iphdr *out4,struct udphdr *udp_new); +#endif /* _NET_IPXLAT_TRANSPORT_H_ */
Signature · 1 line
2.53.0
RFC 8/15 ipxlat: add translation engine and dispatch core
In reply to Ralf LiciThis commit introduces the core start_xmit processing flow: validate, select action, translate, and forward. It centralizes action resolution in the dispatch layer and keeps per-direction translation logic separate from device glue. The result is a single data-path entry point with explicit control over drop/forward/emit behavior.
--- drivers/net/ipxlat/Makefile | 4 + drivers/net/ipxlat/dispatch.c | 104 +++++++++++++++ drivers/net/ipxlat/dispatch.h | 71 +++++++++++ drivers/net/ipxlat/main.c | 6 +- drivers/net/ipxlat/packet.c | 1 + drivers/net/ipxlat/translate_46.c | 198 +++++++++++++++++++++++++++++ drivers/net/ipxlat/translate_46.h | 73 +++++++++++ drivers/net/ipxlat/translate_64.c | 205 ++++++++++++++++++++++++++++++ drivers/net/ipxlat/translate_64.h | 56 ++++++++ drivers/net/ipxlat/transport.c | 11 ++ drivers/net/ipxlat/transport.h | 5 + 11 files changed, 732 insertions(+), 2 deletions(-) create mode 100644 drivers/net/ipxlat/dispatch.c create mode 100644 drivers/net/ipxlat/dispatch.h create mode 100644 drivers/net/ipxlat/translate_46.c create mode 100644 drivers/net/ipxlat/translate_46.h create mode 100644 drivers/net/ipxlat/translate_64.c create mode 100644 drivers/net/ipxlat/translate_64.h
drivers/net/ipxlat/Makefile +4 -0
@@ -7,3 +7,7 @@ obj-$(CONFIG_IPXLAT) := ipxlat.o ipxlat-objs += main.o ipxlat-objs += address.o ipxlat-objs += packet.o +ipxlat-objs += transport.o +ipxlat-objs += dispatch.o +ipxlat-objs += translate_46.o +ipxlat-objs += translate_64.o
drivers/net/ipxlat/dispatch.c new file +104 -0
104 lines not on this page · raw message
drivers/net/ipxlat/dispatch.h new file +71 -0
71 lines not on this page · raw message
drivers/net/ipxlat/main.c +4 -2
@@ -15,6 +15,7 @@#include <net/ip.h> +#include "dispatch.h" #include "ipxlpriv.h" #include "main.h"
@@ -56,8 +57,9 @@ static void ipxlat_dev_uninit(struct net_device *dev)static int ipxlat_start_xmit (struct sk_buff *skb,struct net_device *dev) { -dev_dstats_tx_dropped (dev); -kfree_skb (skb); +struct ipxlat_priv *ipxlat =netdev_priv (dev); + +ipxlat_process_skb (ipxlat, skb, true);return NETDEV_TX_OK ; }
drivers/net/ipxlat/packet.c +1 -0
@@ -13,6 +13,7 @@#include <linux/icmp.h> +#include "dispatch.h" #include "packet.h" /* Shift cached skb cb offsets by the L3 header delta after in-place rewrite.
drivers/net/ipxlat/translate_46.c new file +198 -0
198 lines not on this page · raw message
drivers/net/ipxlat/translate_46.h new file +73 -0
73 lines not on this page · raw message
drivers/net/ipxlat/translate_64.c new file +205 -0
205 lines not on this page · raw message
drivers/net/ipxlat/translate_64.h new file +56 -0
56 lines not on this page · raw message
drivers/net/ipxlat/transport.c +11 -0
@@ -338,3 +338,14 @@ int ipxlat_64_inner_udp(struct sk_buff *skb, const struct ipv6hdr *in6, udp_new->check =CSUM_MANGLED_0 ;return 0 ; } + +int ipxlat_46_icmp (struct ipxlat_priv *ipxlat,struct sk_buff *skb) +{ +return -EPROTONOSUPPORT ; +} + +int ipxlat_64_icmp (struct ipxlat_priv *ipxlat,struct sk_buff *skb, +const struct ipv6hdr *outer6) +{ +return -EPROTONOSUPPORT ; +}
drivers/net/ipxlat/transport.h +5 -0
@@ -100,4 +100,9 @@ int ipxlat_64_inner_tcp(struct sk_buff *skb, const struct ipv6hdr *in6,int ipxlat_64_inner_udp (struct sk_buff *skb,const struct ipv6hdr *in6,const struct iphdr *out4,struct udphdr *udp_new); +/* temporary ICMP stubs until ICMP translation support is introduced */ +int ipxlat_46_icmp (struct ipxlat_priv *ipxlat,struct sk_buff *skb); +int ipxlat_64_icmp (struct ipxlat_priv *ipxlat,struct sk_buff *skb, +const struct ipv6hdr *outer6); +#endif /* _NET_IPXLAT_TRANSPORT_H_ */
Signature · 1 line
2.53.0
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Quoted 7 lines · Ralf Lici
This commit introduces the core
start_xmitprocessing flow: validate, select action, translate, and forward. It centralizes action resolution in the dispatch layer and keeps per-direction translation logic separate from device glue. The result is a single data-path entry point with explicit control over drop/forward/emit behavior.Signed-off-by Ralf Lici <[email protected]>
This is very cool! Going quickly through the series, this seems like thorough work that will be cool to have available in the kernel, so thanks for doing this! I'll be quite happy to retire my barebones BPF-based implementation once this lands :)
One comment on the device model below (which is also why I chose this patch to reply to):
drivers/net/ipxlat/dispatch.c line 73
Quoted 10 lines
drivers/net/ipxlat/dispatch.c new file +10
-0+static void ipxlat_forward_pkt (struct ipxlat_priv *ipxlat,struct sk_buff *skb) +{ +const unsigned int len = skb->len; +int err; + +/* reinject as a fresh packet with scrubbed metadata */ +skb_set_queue_mapping (skb,0 ); +skb_scrub_packet (skb, false); + + err =gro_cells_receive (&ipxlat->gro_cells, skb);
So given that you're not resetting skb->dev here, IIUC, this means that the translated packet will magically re-appear as if it arrived on the interface it first came in on, right?
That seems... a bit too magical? Sending a packet to one device making it suddenly reappear on a different, unrelated, device seems like it will just create confusion. It's like the ipxlat device can't really device if it's a device or a tunnel? :)
I think a better model is to treat the device as basically a loopback device that translates packets before looping them back (so when they come back they appear to be coming from that device).
Any reason why that wouldn't work?
-Toke
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Hi Toke,
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Ralf Lici
This commit introduces the core
start_xmitprocessing flow: validate, select action, translate, and forward. It centralizes action resolution in the dispatch layer and keeps per-direction translation logic separate from device glue. The result is a single data-path entry point with explicit control over drop/forward/emit behavior.
Quoted 7 lines
Quoted 1 line
Signed-off-by Ralf Lici <[email protected]>This is very cool! Going quickly through the series, this seems like thorough work that will be cool to have available in the kernel, so thanks for doing this! I'll be quite happy to retire my barebones BPF-based implementation once this lands :)
Thanks, glad to hear this looks useful. I have not had much time to work on ipxlat lately, but I hope to respin the RFC soon.
Quoted 18 lines
One comment on the device model below (which is also why I chose this patch to reply to):
drivers/net/ipxlat/dispatch.c line 73
Quoted 10 lines
drivers/net/ipxlat/dispatch.c new file +10
-0+static void ipxlat_forward_pkt (struct ipxlat_priv *ipxlat,struct sk_buff *skb) +{ +const unsigned int len = skb->len; +int err; + +/* reinject as a fresh packet with scrubbed metadata */ +skb_set_queue_mapping (skb,0 ); +skb_scrub_packet (skb, false); + + err =gro_cells_receive (&ipxlat->gro_cells, skb);So given that you're not resetting
skb->devhere, IIUC, this means that the translated packet will magically re-appear as if it arrived on the interface it first came in on, right?
Quoted 5 lines
That seems... a bit too magical? Sending a packet to one device making it suddenly reappear on a different, unrelated, device seems like it will just create confusion. It's like the ipxlat device can't really device if it's a device or a tunnel? :)
That's not quite what happens in the routed xmit path. There the stack sets skb->dev to the selected output device before handing the skb to the device. For IPv4 and IPv6 this happens in ip_output/ip6_output, where the output device is taken from the skb dst. So when the route selects the ipxlat device, the skb reaches ndo_start_xmit with skb->dev already pointing at the ipxlat device, not at the original ingress device.
The internal 4-to-6 pre-fragmentation path should preserve the same property as well: ip_do_fragment copies the skb metadata to the generated fragments, including skb->dev, and the temporary dst used for that path also points at the ipxlat device. The fragment callback then feeds those fragments back into the same ipxlat processing path.
That said, I agree that relying on this implicitly is not great. gro_cells_receive uses skb->dev directly, and the intended receive-side re-injection model should be obvious at the call site. I will set skb->dev = ipxlat->dev explicitly before gro_cells_receive in the next version.
Quoted 6 lines
I think a better model is to treat the device as basically a loopback device that translates packets before looping them back (so when they come back they appear to be coming from that device).
Any reason why that wouldn't work?
That's indeed the intended model for the ipxlat netdevice: route packets to it, translate them, then loop them back into the stack as packets received from that same device. That seemed like the simplest model and the one that exposes the translation point most clearly.
Thanks for your feedback!
Signature · 2 lines
Ralf Lici Mandelbit Srl
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Quoted 60 lines · Ralf Lici
Hi Toke,
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Ralf Lici
This commit introduces the core
start_xmitprocessing flow: validate, select action, translate, and forward. It centralizes action resolution in the dispatch layer and keeps per-direction translation logic separate from device glue. The result is a single data-path entry point with explicit control over drop/forward/emit behavior.Quoted 7 lines
Quoted 1 line
Signed-off-by Ralf Lici <[email protected]>This is very cool! Going quickly through the series, this seems like thorough work that will be cool to have available in the kernel, so thanks for doing this! I'll be quite happy to retire my barebones BPF-based implementation once this lands :)
Thanks, glad to hear this looks useful. I have not had much time to work on ipxlat lately, but I hope to respin the RFC soon.
Quoted 18 lines
One comment on the device model below (which is also why I chose this patch to reply to):
drivers/net/ipxlat/dispatch.c line 73
Quoted 10 lines
drivers/net/ipxlat/dispatch.c new file +10
-0+static void ipxlat_forward_pkt (struct ipxlat_priv *ipxlat,struct sk_buff *skb) +{ +const unsigned int len = skb->len; +int err; + +/* reinject as a fresh packet with scrubbed metadata */ +skb_set_queue_mapping (skb,0 ); +skb_scrub_packet (skb, false); + + err =gro_cells_receive (&ipxlat->gro_cells, skb);So given that you're not resetting
skb->devhere, IIUC, this means that the translated packet will magically re-appear as if it arrived on the interface it first came in on, right?Quoted 5 lines
That seems... a bit too magical? Sending a packet to one device making it suddenly reappear on a different, unrelated, device seems like it will just create confusion. It's like the ipxlat device can't really device if it's a device or a tunnel? :)
That's not quite what happens in the routed xmit path. There the stack sets
skb->devto the selected output device before handing the skb to the device. For IPv4 and IPv6 this happens in ip_output/ip6_output, where the output device is taken from the skb dst. So when the route selects the ipxlat device, the skb reachesndo_start_xmitwithskb->devalready pointing at the ipxlat device, not at the original ingress device.The internal 4-to-6 pre-fragmentation path should preserve the same property as well:
ip_do_fragmentcopies the skb metadata to the generated fragments, includingskb->dev, and the temporary dst used for that path also points at the ipxlat device. The fragment callback then feeds those fragments back into the same ipxlat processing path.
Quoted 5 lines
That said, I agree that relying on this implicitly is not great.
gro_cells_receiveusesskb->devdirectly, and the intended receive-side re-injection model should be obvious at the call site. I will setskb->dev=ipxlat->devexplicitly beforegro_cells_receivein the next version.
Right, sounds good. I'm also wondering if you actually need the gro_cells infrastructure at all? IIUC, the purpose of that is to allow tunnels to create GRO superframes of packets after they are decapsulated (and thus their l4 commonality becomes apparent). But you're not decapsulating anything, you're just translating between protocols the kernel already understands. So presumably any opportunity to coalesce GRO packets would already have happened pre-translation? So any reason why you can't just do what loopback.c does, and do a straight __netif_rx() call in the transmit function?
Quoted 11 lines
Quoted 6 lines
I think a better model is to treat the device as basically a loopback device that translates packets before looping them back (so when they come back they appear to be coming from that device).
Any reason why that wouldn't work?
That's indeed the intended model for the ipxlat netdevice: route packets to it, translate them, then loop them back into the stack as packets received from that same device. That seemed like the simplest model and the one that exposes the translation point most clearly.
Right. I think this could be made a bit more explicit in the documentation as well, since it's a bit of an unusual model.
And, well, taking a step back: is it really the right model? Regular NAT lives in netfilter, why can't this be a netfilter module as well? Seems to me you could have something like:
table ip xlat4 {
chain postrouting {
type nat hook postrouting priority srcnat; policy accept;
ip daddr 0.0.0.0/0 oifname "eth0" xlat to 64:ff9b::/96
}
}
table ip6 xlat6 {
chain prerouting {
type nat hook prerouting priority dstnat; policy accept;
ip6 saddr 64::ff0b::/96 iifname "eth0" xlat from 64::ff9b::/96
}
}and that would provide the functionality without having to implement a new interface type and the associated multiple traversals through the stack? Did you consider this as an alternative to the new device type?
-Toke
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Quoted 68 lines · Toke Høiland-Jørgensen
Quoted 60 lines · Ralf Lici
Hi Toke,
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Ralf Lici
This commit introduces the core
start_xmitprocessing flow: validate, select action, translate, and forward. It centralizes action resolution in the dispatch layer and keeps per-direction translation logic separate from device glue. The result is a single data-path entry point with explicit control over drop/forward/emit behavior.Quoted 7 lines
Quoted 1 line
Signed-off-by Ralf Lici <[email protected]>This is very cool! Going quickly through the series, this seems like thorough work that will be cool to have available in the kernel, so thanks for doing this! I'll be quite happy to retire my barebones BPF-based implementation once this lands :)
Thanks, glad to hear this looks useful. I have not had much time to work on ipxlat lately, but I hope to respin the RFC soon.
Quoted 18 lines
One comment on the device model below (which is also why I chose this patch to reply to):
drivers/net/ipxlat/dispatch.c line 73
Quoted 10 lines
drivers/net/ipxlat/dispatch.c new file +10
-0+static void ipxlat_forward_pkt (struct ipxlat_priv *ipxlat,struct sk_buff *skb) +{ +const unsigned int len = skb->len; +int err; + +/* reinject as a fresh packet with scrubbed metadata */ +skb_set_queue_mapping (skb,0 ); +skb_scrub_packet (skb, false); + + err =gro_cells_receive (&ipxlat->gro_cells, skb);So given that you're not resetting
skb->devhere, IIUC, this means that the translated packet will magically re-appear as if it arrived on the interface it first came in on, right?Quoted 5 lines
That seems... a bit too magical? Sending a packet to one device making it suddenly reappear on a different, unrelated, device seems like it will just create confusion. It's like the ipxlat device can't really device if it's a device or a tunnel? :)
That's not quite what happens in the routed xmit path. There the stack sets
skb->devto the selected output device before handing the skb to the device. For IPv4 and IPv6 this happens in ip_output/ip6_output, where the output device is taken from the skb dst. So when the route selects the ipxlat device, the skb reachesndo_start_xmitwithskb->devalready pointing at the ipxlat device, not at the original ingress device.The internal 4-to-6 pre-fragmentation path should preserve the same property as well:
ip_do_fragmentcopies the skb metadata to the generated fragments, includingskb->dev, and the temporary dst used for that path also points at the ipxlat device. The fragment callback then feeds those fragments back into the same ipxlat processing path.Quoted 5 lines
That said, I agree that relying on this implicitly is not great.
gro_cells_receiveusesskb->devdirectly, and the intended receive-side re-injection model should be obvious at the call site. I will setskb->dev=ipxlat->devexplicitly beforegro_cells_receivein the next version.
Quoted 10 lines
Right, sounds good. I'm also wondering if you actually need the
gro_cellsinfrastructure at all? IIUC, the purpose of that is to allow tunnels to create GRO superframes of packets after they are decapsulated (and thus their l4 commonality becomes apparent). But you're not decapsulating anything, you're just translating between protocols the kernel already understands. So presumably any opportunity to coalesce GRO packets would already have happened pre-translation? So any reason why you can't just do whatloopback.cdoes, and do a straight__netif_rx()call in the transmit function?
No, I think you're right that gro_cells is not justified here, I was probably biased by my work on tunnel interfaces. Unlike a tunnel decap path, ipxlat does not reveal a new same-family L4 flow after decapsulation, so I don't see a translation-specific GRO opportunity there, and a loopback-style receive handoff would be the simpler version of that design.
That said, after thinking more about the rest of your feedback, I think the right fix is probably not just replacing gro_cells with __netif_rx. The deeper issue is the netdevice/RX-reinjection model itself.
Quoted 32 lines
Quoted 11 lines
Quoted 6 lines
I think a better model is to treat the device as basically a loopback device that translates packets before looping them back (so when they come back they appear to be coming from that device).
Any reason why that wouldn't work?
That's indeed the intended model for the ipxlat netdevice: route packets to it, translate them, then loop them back into the stack as packets received from that same device. That seemed like the simplest model and the one that exposes the translation point most clearly.
Right. I think this could be made a bit more explicit in the documentation as well, since it's a bit of an unusual model.
And, well, taking a step back: is it really the right model? Regular NAT lives in netfilter, why can't this be a netfilter module as well? Seems to me you could have something like:
table ip xlat4 { chain postrouting { type nat hook postrouting priority srcnat; policy accept; ip daddr 0.0.0.0/0 oifname "eth0" xlat to 64:ff9b::/96 } } table ip6 xlat6 { chain prerouting { type nat hook prerouting priority dstnat; policy accept; ip6 saddr 64::ff0b::/96 iifname "eth0" xlat from 64::ff9b::/96 } }
Quoted 4 lines
and that would provide the functionality without having to implement a new interface type and the associated multiple traversals through the stack? Did you consider this as an alternative to the new device type?
We did consider netfilter, and your example is syntactically attractive, but I am no longer convinced it is the cleanest model for SIIT.
An nft expression cannot simply rewrite ETH_P_IP <-> ETH_P_IPV6 and return ACCEPT as if this were normal NAT because the current hook invocation, dst, and conntrack-related state were established for the packet as it entered that hook. A cross-family translator would need to consume the skb, clear or rebuild route and ct metadata as appropriate, do an other-family route lookup, and resume at a well-defined point in that family. That seems possible, but it would be a new stateless cross-family action, not just a new mode of the existing nft nat expression (which is built around nf_nat_setup_info and assumes the packet's L3 family does not change AFAICT).
My second concern is that the SIIT boundary would be a property of rule and hook placement. That gives flexibility, but it also means the translation point has to be constrained and documented very carefully to avoid ambiguous TTL/Hop Limit, PMTU/ICMP, and hook-order behavior. For this use case I would rather have the route that matches the translation prefix also be the object that says: leave this family here and continue in the other one.
After looking at the available kernel mechanisms again, I think the better model is probably LWT: routes carry an ipxlat encap referencing a named translator domain configured over netlink. That should represent the stateless, prefix-based and symmetric nature of ipxlat.
Very roughly, userspace could look like:
ip xlat add siit0 prefix6 64:ff9b::/96
ip route add ... encap ipxlat id siit0
ip -6 route add ... encap ipxlat id siit0
There are some useful precedents for this: ILA is stateless address translation as LWT, seg6_local already has cross-family LWT actions, and ioam6 has a similar split between separately configured objects and route attachments.
The invariant I would like v2 to follow is that the original-family route lookup selects translation as its terminal route action. The translated skb then gets a fresh lookup in the other family. From that point on, TTL/Hop Limit where applicable, PMTU, ICMP errors, and netfilter visibility belong to the translated family.
So I think your question addresses the core design issue in this RFC. My current preference is to rework the next version around an LWT/domain model instead of the virtual netdevice model, unless prototyping shows a fundamental problem with that approach.
Does that model make sense to you?
Thanks for pushing on this.
Signature · 2 lines
Ralf Lici Mandelbit Srl
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Quoted 40 lines
Quoted 32 lines
Quoted 11 lines
Quoted 6 lines
I think a better model is to treat the device as basically a loopback device that translates packets before looping them back (so when they come back they appear to be coming from that device).
Any reason why that wouldn't work?
That's indeed the intended model for the ipxlat netdevice: route packets to it, translate them, then loop them back into the stack as packets received from that same device. That seemed like the simplest model and the one that exposes the translation point most clearly.
Right. I think this could be made a bit more explicit in the documentation as well, since it's a bit of an unusual model.
And, well, taking a step back: is it really the right model? Regular NAT lives in netfilter, why can't this be a netfilter module as well? Seems to me you could have something like:
table ip xlat4 { chain postrouting { type nat hook postrouting priority srcnat; policy accept; ip daddr 0.0.0.0/0 oifname "eth0" xlat to 64:ff9b::/96 } } table ip6 xlat6 { chain prerouting { type nat hook prerouting priority dstnat; policy accept; ip6 saddr 64::ff0b::/96 iifname "eth0" xlat from 64::ff9b::/96 } }Quoted 4 lines
and that would provide the functionality without having to implement a new interface type and the associated multiple traversals through the stack? Did you consider this as an alternative to the new device type?
We did consider netfilter, and your example is syntactically attractive, but I am no longer convinced it is the cleanest model for SIIT.
Quoted 10 lines
An nft expression cannot simply rewrite
ETH_P_IP<->ETH_P_IPV6and return ACCEPT as if this were normal NAT because the current hook invocation, dst, and conntrack-related state were established for the packet as it entered that hook. A cross-family translator would need to consume the skb, clear or rebuild route and ct metadata as appropriate, do an other-family route lookup, and resume at a well-defined point in that family. That seems possible, but it would be a new stateless cross-family action, not just a new mode of the existing nft nat expression (which is built aroundnf_nat_setup_infoand assumes the packet's L3 family does not change AFAICT).
Right, I did not expect it would be possible to actually share code with the existing NAT functionality, but conceptually they're similar. I.e., if I was an admin trying to figure out if my system supported SIIT translation, my chain of thought would be something along the line of:
"SIIT is a variant of NAT, and I know NAT is a long-standing feature of netfilter, so I wonder if SIIT exists there as well".
Adding the netfilter folks to Cc to try to get their attention and an opinion on this :)
Quoted 7 lines
My second concern is that the SIIT boundary would be a property of rule and hook placement. That gives flexibility, but it also means the translation point has to be constrained and documented very carefully to avoid ambiguous TTL/Hop Limit, PMTU/ICMP, and hook-order behavior. For this use case I would rather have the route that matches the translation prefix also be the object that says: leave this family here and continue in the other one.
Yeah, with flexibility comes the ability to shoot yourself in the foot. But that's not really different from much of the other functionality we have in the kernel today, is it? For netfilter in particular it's certainly possible to configure a broken NAT configuration that leads to packet drops (or just invalid packets being sent out on a network device).
Quoted 4 lines
After looking at the available kernel mechanisms again, I think the better model is probably LWT: routes carry an ipxlat encap referencing a named translator domain configured over netlink. That should represent the stateless, prefix-based and symmetric nature of ipxlat.
I think this description actually hits the nail on the head: What are we implementing here? Is it a product feature, or a building block for one? The properties you mention wrt consistency, symmetry etc are properties of the high-level feature (which is also generally the level things are specified in RFCs). Whereas other packet mangling features in the kernel are more in the "building block" category, where it's possible to configure things to implement a particular feature set / compliance with a particular RFC, but it's also possible to do things that are outside of that.
I think this relates to the "mechanism, not policy" approach that we take to most things in the kernel: implement the building blocks to do something in the most general way we can, and then leave it up to userspace to configure things in a way that results in a consistent high-level system behaviour.
Quoted 17 lines · That being
Very roughly, userspace could look like:
ip xlat add siit0 prefix6 64:ff9b::/96
ip route add ... encap ipxlat id siit0
ip -6 route add ... encap ipxlat id siit0There are some useful precedents for this: ILA is stateless address translation as LWT,
seg6_localalready has cross-family LWT actions, and ioam6 has a similar split between separately configured objects and route attachments.The invariant I would like v2 to follow is that the original-family route lookup selects translation as its terminal route action. The translated skb then gets a fresh lookup in the other family. From that point on, TTL/Hop Limit where applicable, PMTU, ICMP errors, and netfilter visibility belong to the translated family.
Quoted 6 lines
So I think your question addresses the core design issue in this RFC. My current preference is to rework the next version around an LWT/domain model instead of the virtual netdevice model, unless prototyping shows a fundamental problem with that approach.
Does that model make sense to you?
I did consider this as well before suggesting netfilter as the right place to hook things, and I do think the route object model has some appeal. I agree it's a better model than the magical loopback interface, certainly.
I think in the end this comes down to whether flexibility in how to use this translation mechanism is a bug or a feature, as outlined above. I'm leaning towards "feature", but could probably be persuaded otherwise :)
Quoted 1 line
Thanks for pushing on this.
You're welcome! Thanks for working on it - will be cool to have this land in whatever form we end up agreeing on!
-Toke
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Quoted 58 lines · Toke Høiland-Jørgensen
Quoted 40 lines
Quoted 32 lines
Quoted 11 lines
Quoted 6 lines
I think a better model is to treat the device as basically a loopback device that translates packets before looping them back (so when they come back they appear to be coming from that device).
Any reason why that wouldn't work?
That's indeed the intended model for the ipxlat netdevice: route packets to it, translate them, then loop them back into the stack as packets received from that same device. That seemed like the simplest model and the one that exposes the translation point most clearly.
Right. I think this could be made a bit more explicit in the documentation as well, since it's a bit of an unusual model.
And, well, taking a step back: is it really the right model? Regular NAT lives in netfilter, why can't this be a netfilter module as well? Seems to me you could have something like:
table ip xlat4 { chain postrouting { type nat hook postrouting priority srcnat; policy accept; ip daddr 0.0.0.0/0 oifname "eth0" xlat to 64:ff9b::/96 } } table ip6 xlat6 { chain prerouting { type nat hook prerouting priority dstnat; policy accept; ip6 saddr 64::ff0b::/96 iifname "eth0" xlat from 64::ff9b::/96 } }Quoted 4 lines
and that would provide the functionality without having to implement a new interface type and the associated multiple traversals through the stack? Did you consider this as an alternative to the new device type?
We did consider netfilter, and your example is syntactically attractive, but I am no longer convinced it is the cleanest model for SIIT.
Quoted 10 lines
An nft expression cannot simply rewrite
ETH_P_IP<->ETH_P_IPV6and return ACCEPT as if this were normal NAT because the current hook invocation, dst, and conntrack-related state were established for the packet as it entered that hook. A cross-family translator would need to consume the skb, clear or rebuild route and ct metadata as appropriate, do an other-family route lookup, and resume at a well-defined point in that family. That seems possible, but it would be a new stateless cross-family action, not just a new mode of the existing nft nat expression (which is built aroundnf_nat_setup_infoand assumes the packet's L3 family does not change AFAICT).Right, I did not expect it would be possible to actually share code with the existing NAT functionality, but conceptually they're similar. I.e., if I was an admin trying to figure out if my system supported SIIT translation, my chain of thought would be something along the line of:
"SIIT is a variant of NAT, and I know NAT is a long-standing feature of netfilter, so I wonder if SIIT exists there as well".
Quoted 3 lines
Adding the netfilter folks to Cc to try to get their attention and an opinion on this :)
That's the right move, it would be great to have their opinion on these architectural questions.
For the netfilter folks just added: the context is a stateless IPv6<>IPv4 SIIT translator (RFC 7915). The open design question is whether the stateless cross-family translation should live as an nft action, or as a route/LWT action (ILA / seg6_local lineage).
Quoted 8 lines
Quoted 7 lines
My second concern is that the SIIT boundary would be a property of rule and hook placement. That gives flexibility, but it also means the translation point has to be constrained and documented very carefully to avoid ambiguous TTL/Hop Limit, PMTU/ICMP, and hook-order behavior. For this use case I would rather have the route that matches the translation prefix also be the object that says: leave this family here and continue in the other one.
Quoted 7 lines
Yeah, with flexibility comes the ability to shoot yourself in the foot. But that's not really different from much of the other functionality we have in the kernel today, is it? For netfilter in particular it's certainly possible to configure a broken NAT configuration that leads to packet drops (or just invalid packets being sent out on a network device).
True, misconfiguration is always possible and that alone is not an argument against the netfilter model. But what do we actually gain in capability from that flexibility? I agree on the UX argument (an admin would look in nft first), but in terms of what the feature can do, I can't yet see what the nft model unlocks. More on this just below.
Quoted 15 lines
Quoted 4 lines
After looking at the available kernel mechanisms again, I think the better model is probably LWT: routes carry an ipxlat encap referencing a named translator domain configured over netlink. That should represent the stateless, prefix-based and symmetric nature of ipxlat.
I think this description actually hits the nail on the head: What are we implementing here? Is it a product feature, or a building block for one? The properties you mention wrt consistency, symmetry etc are properties of the high-level feature (which is also generally the level things are specified in RFCs). Whereas other packet mangling features in the kernel are more in the "building block" category, where it's possible to configure things to implement a particular feature set / compliance with a particular RFC, but it's also possible to do things that are outside of that.
Quoted 6 lines
I think this relates to the "mechanism, not policy" approach that we take to most things in the kernel: implement the building blocks to do something in the most general way we can, and then leave it up to userspace to configure things in a way that results in a consistent high-level system behaviour.
That's a good point, and I agree that we should not bake a high-level product policy into the kernel if what we need is a reusable mechanism (the LWT idea was my attempt at exactly that). What I am still trying to understand is whether there is a useful generic trigger for stateless cross-family translation beyond the route/prefix/policy-routing cases.
Routes and policy routing already cover the selectors I can make coherent for a stateless, per-packet translator: destination/source prefix, iif/oif/VRF, mark, TOS/DSCP, and so on. nft can of course match much more than that, but the additional selectors that would materially change the translation decision seem to be selectors such as L4 fields, payload state, or conntrack state. Those are exactly the selectors I am struggling to make correct for a stateless translator:
- non-first fragments carry no L4 header at all, yet the translator must rewrite every fragment (an nft ... tcp dport trigger cannot fire on them);
- ICMP errors must be translated too, but the flow identity lives in the quoted inner header (reversed), not in anything an L4/ct match on the error packet can see and there is no conntrack to associate them, since this is stateless.
So an L4-conditional trigger does not look like a good primitive for correct stateless SIIT unless the action also defragments/refragments or uses conntrack-like state. Those may be valid mechanisms, but they move the design away from the stateless per-packet SIIT boundary this RFC is trying to model.
So my first question is: is there a useful nft configuration this should enable that is not naturally expressible as route selection, while still remaining stateless SIIT rather than a NAT64-like stateful feature? Maybe there is a real use case there, but I cannot construct one yet.
Quoted 26 lines
Quoted 17 lines · That being
Very roughly, userspace could look like:
ip xlat add siit0 prefix6 64:ff9b::/96
ip route add ... encap ipxlat id siit0
ip -6 route add ... encap ipxlat id siit0There are some useful precedents for this: ILA is stateless address translation as LWT,
seg6_localalready has cross-family LWT actions, and ioam6 has a similar split between separately configured objects and route attachments.The invariant I would like v2 to follow is that the original-family route lookup selects translation as its terminal route action. The translated skb then gets a fresh lookup in the other family. From that point on, TTL/Hop Limit where applicable, PMTU, ICMP errors, and netfilter visibility belong to the translated family.
Quoted 6 lines
So I think your question addresses the core design issue in this RFC. My current preference is to rework the next version around an LWT/domain model instead of the virtual netdevice model, unless prototyping shows a fundamental problem with that approach.
Does that model make sense to you?
Quoted 9 lines
I did consider this as well before suggesting netfilter as the right place to hook things, and I do think the route object model has some appeal. I agree it's a better model than the magical loopback interface, certainly.
I think in the end this comes down to whether flexibility in how to use this translation mechanism is a bug or a feature, as outlined above. I'm leaning towards "feature", but could probably be persuaded otherwise :)
I agree this is the tradeoff to settle now. The reason I suggested LWT is that making the family-A route lookup the handoff point gives the TTL/PMTU/ICMP-and-reroute semantics a natural place to live.
So my other question, where the netfilter maintainers' input would be very useful, is what semantics would be acceptable for changing address family inside a netfilter hook. Concretely:
- What verdict should such an expression return? My assumption is it has to consume the skb and reinject into the other family (NF_STOLEN
+ reinject), since ACCEPT would resume traversal in a family whose dst/chain no longer apply.
- What becomes of the original-family conntrack entry, which is now orphaned (and is pure overhead in the stateless case)?
- Where do TTL/Hop-Limit, PMTU/ICMP generation, and netfilter visibility end up belonging after the family changes?
All that said, the netfilter model has its own strengths, and once we settle the architectural questions it could turn into a very clean design. Curious to hear your thoughts on the points above.
Signature · 2 lines
Ralf Lici Mandelbit Srl
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
[ skipping some of the netfilter-related context until we hear from the netfilter devs ]
Quoted 58 lines
Quoted 8 lines
Quoted 7 lines
My second concern is that the SIIT boundary would be a property of rule and hook placement. That gives flexibility, but it also means the translation point has to be constrained and documented very carefully to avoid ambiguous TTL/Hop Limit, PMTU/ICMP, and hook-order behavior. For this use case I would rather have the route that matches the translation prefix also be the object that says: leave this family here and continue in the other one.
Quoted 7 lines
Yeah, with flexibility comes the ability to shoot yourself in the foot. But that's not really different from much of the other functionality we have in the kernel today, is it? For netfilter in particular it's certainly possible to configure a broken NAT configuration that leads to packet drops (or just invalid packets being sent out on a network device).
True, misconfiguration is always possible and that alone is not an argument against the netfilter model. But what do we actually gain in capability from that flexibility? I agree on the UX argument (an admin would look in nft first), but in terms of what the feature can do, I can't yet see what the nft model unlocks. More on this just below.
Quoted 15 lines
Quoted 4 lines
After looking at the available kernel mechanisms again, I think the better model is probably LWT: routes carry an ipxlat encap referencing a named translator domain configured over netlink. That should represent the stateless, prefix-based and symmetric nature of ipxlat.
I think this description actually hits the nail on the head: What are we implementing here? Is it a product feature, or a building block for one? The properties you mention wrt consistency, symmetry etc are properties of the high-level feature (which is also generally the level things are specified in RFCs). Whereas other packet mangling features in the kernel are more in the "building block" category, where it's possible to configure things to implement a particular feature set / compliance with a particular RFC, but it's also possible to do things that are outside of that.
Quoted 6 lines
I think this relates to the "mechanism, not policy" approach that we take to most things in the kernel: implement the building blocks to do something in the most general way we can, and then leave it up to userspace to configure things in a way that results in a consistent high-level system behaviour.
That's a good point, and I agree that we should not bake a high-level product policy into the kernel if what we need is a reusable mechanism (the LWT idea was my attempt at exactly that). What I am still trying to understand is whether there is a useful generic trigger for stateless cross-family translation beyond the route/prefix/policy-routing cases.
Routes and policy routing already cover the selectors I can make coherent for a stateless, per-packet translator: destination/source prefix, iif/oif/VRF, mark, TOS/DSCP, and so on. nft can of course match much more than that, but the additional selectors that would materially change the translation decision seem to be selectors such as L4 fields, payload state, or conntrack state. Those are exactly the selectors I am struggling to make correct for a stateless translator:
Quoted 8 lines
- non-first fragments carry no L4 header at all, yet the translator must rewrite every fragment (an nft ... tcp dport trigger cannot fire on them);
- ICMP errors must be translated too, but the flow identity lives in the quoted inner header (reversed), not in anything an L4/ct match on the error packet can see and there is no conntrack to associate them, since this is stateless.
True in principle, but if (say) you deploy this on a network that is configured so it will never fragment packets, this won't be an issue in practice.
I.e., you're quite right that arbitrary matching criteria cannot be guaranteed to result in coherent translation. But I think that goes into the "use it wrong, get wrong results" bin. E.g., if you match on something that results in only a subset of the packets of a flow being translated, well, only that subset of the packets will make it to the destination. The SIIT translator itself should not try to fix this, but neither should it prevent it; that's what I mean by "building block" - it's up to the builder using the blocks to make sure the building doesn't collapse, that's out of scope for the block manufacturer to worry about :)
Quoted 10 lines
So an L4-conditional trigger does not look like a good primitive for correct stateless SIIT unless the action also defragments/refragments or uses conntrack-like state. Those may be valid mechanisms, but they move the design away from the stateless per-packet SIIT boundary this RFC is trying to model.
So my first question is: is there a useful nft configuration this should enable that is not naturally expressible as route selection, while still remaining stateless SIIT rather than a NAT64-like stateful feature? Maybe there is a real use case there, but I cannot construct one yet.
So the poster child for "match on arbitrary criteria" is of course BPF. You can write BPF programs that match on arbitrary parts of the packet header, custom encapsulation headers,or even on out of band things like system state, phase of the moon, or what have you. And we should certainly allow a BPF program to make the decision on whether to perform the SIIT translation.
Which... maybe is an argument to keep it as a device like you do in this RFC series? Redirecting to a device is trivially supported from TC-BPF, which also makes it possible to use the translation mechanism without going through the routing subsystem at all, saving a bit of overhead. Whereas making it a route action ties it very closely to the routing subsystem.
WDYT?
-Toke
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Quoted 71 lines · Toke Høiland-Jørgensen
Quoted 58 lines
Quoted 8 lines
Quoted 7 lines
My second concern is that the SIIT boundary would be a property of rule and hook placement. That gives flexibility, but it also means the translation point has to be constrained and documented very carefully to avoid ambiguous TTL/Hop Limit, PMTU/ICMP, and hook-order behavior. For this use case I would rather have the route that matches the translation prefix also be the object that says: leave this family here and continue in the other one.
Quoted 7 lines
Yeah, with flexibility comes the ability to shoot yourself in the foot. But that's not really different from much of the other functionality we have in the kernel today, is it? For netfilter in particular it's certainly possible to configure a broken NAT configuration that leads to packet drops (or just invalid packets being sent out on a network device).
True, misconfiguration is always possible and that alone is not an argument against the netfilter model. But what do we actually gain in capability from that flexibility? I agree on the UX argument (an admin would look in nft first), but in terms of what the feature can do, I can't yet see what the nft model unlocks. More on this just below.
Quoted 15 lines
Quoted 4 lines
After looking at the available kernel mechanisms again, I think the better model is probably LWT: routes carry an ipxlat encap referencing a named translator domain configured over netlink. That should represent the stateless, prefix-based and symmetric nature of ipxlat.
I think this description actually hits the nail on the head: What are we implementing here? Is it a product feature, or a building block for one? The properties you mention wrt consistency, symmetry etc are properties of the high-level feature (which is also generally the level things are specified in RFCs). Whereas other packet mangling features in the kernel are more in the "building block" category, where it's possible to configure things to implement a particular feature set / compliance with a particular RFC, but it's also possible to do things that are outside of that.
Quoted 6 lines
I think this relates to the "mechanism, not policy" approach that we take to most things in the kernel: implement the building blocks to do something in the most general way we can, and then leave it up to userspace to configure things in a way that results in a consistent high-level system behaviour.
That's a good point, and I agree that we should not bake a high-level product policy into the kernel if what we need is a reusable mechanism (the LWT idea was my attempt at exactly that). What I am still trying to understand is whether there is a useful generic trigger for stateless cross-family translation beyond the route/prefix/policy-routing cases.
Routes and policy routing already cover the selectors I can make coherent for a stateless, per-packet translator: destination/source prefix, iif/oif/VRF, mark, TOS/DSCP, and so on. nft can of course match much more than that, but the additional selectors that would materially change the translation decision seem to be selectors such as L4 fields, payload state, or conntrack state. Those are exactly the selectors I am struggling to make correct for a stateless translator:
Quoted 8 lines
- non-first fragments carry no L4 header at all, yet the translator must rewrite every fragment (an nft ... tcp dport trigger cannot fire on them);
- ICMP errors must be translated too, but the flow identity lives in the quoted inner header (reversed), not in anything an L4/ct match on the error packet can see and there is no conntrack to associate them, since this is stateless.
True in principle, but if (say) you deploy this on a network that is configured so it will never fragment packets, this won't be an issue in practice.
Quoted 11 lines
I.e., you're quite right that arbitrary matching criteria cannot be guaranteed to result in coherent translation. But I think that goes into the "use it wrong, get wrong results" bin. E.g., if you match on something that results in only a subset of the packets of a flow being translated, well, only that subset of the packets will make it to the destination. The SIIT translator itself should not try to fix this, but neither should it prevent it; that's what I mean by "building block" - it's up to the builder using the blocks to make sure the building doesn't collapse, that's out of scope for the block manufacturer to worry about :)
I agree with that framing. The translation core should not try to prove that the surrounding policy describes a coherent SIIT deployment.
Quoted 18 lines
Quoted 10 lines
So an L4-conditional trigger does not look like a good primitive for correct stateless SIIT unless the action also defragments/refragments or uses conntrack-like state. Those may be valid mechanisms, but they move the design away from the stateless per-packet SIIT boundary this RFC is trying to model.
So my first question is: is there a useful nft configuration this should enable that is not naturally expressible as route selection, while still remaining stateless SIIT rather than a NAT64-like stateful feature? Maybe there is a real use case there, but I cannot construct one yet.
So the poster child for "match on arbitrary criteria" is of course BPF. You can write BPF programs that match on arbitrary parts of the packet header, custom encapsulation headers,or even on out of band things like system state, phase of the moon, or what have you. And we should certainly allow a BPF program to make the decision on whether to perform the SIIT translation.
Quoted 9 lines
Which... maybe is an argument to keep it as a device like you do in this RFC series? Redirecting to a device is trivially supported from TC-BPF, which also makes it possible to use the translation mechanism without going through the routing subsystem at all, saving a bit of overhead. Whereas making it a route action ties it very closely to the routing subsystem.
WDYT?
I see the netdevice appeal for this, especially as a BPF redirect target. But as we discussed earlier, the device model has some real
problems: the device selected by the first route is not the real post-translation egress, so the model ends up doing translation and reinjection rather than normal transmission. Concretely:
- it needs synthetic routing state purely to get things like MTU for fragmentation, because the real post-translation nexthop is not known at translation time;
- TTL/Hop Limit handling gets harder to reason about because the packet has effectively gone through two routing decisions;
- rx/tx stats can't be made meaningful for a direction-agnostic device whose ndo_start_xmit is really "translate and receive";
- and the setup is not very obvious: create an interface, route packets to it, then have them come back translated.
None of these is fatal on its own, but together they make me think the abstraction does not quite fit.
On the BPF point specifically: I agree a BPF program should be able to decide whether to translate. What I am less sure about is whether redirecting to a netdevice is the best way to expose that. A TC action (yet another model, I know :)) gives you the same thing in-pipeline and more directly:
tc filter add dev wwan0 egress \
bpf obj match.o action ipxlat4to6 domain clat0
Let BPF make the policy decision, with the native action doing the translation work that the current BPF CLAT implementations have trouble
with: fragmentation, checksum corner cases, and ICMP error inner headers (as explained by Beniamino).
So TC clsact looks like the natural in-kernel replacement for today's TC-BPF CLAT programs: no extra netdev, you attach to the existing uplink, direction is explicit, and on egress you sit on the real route dst, so the synthetic-dst and double-routing problems above just don't arise. The cost is more moving parts than a single bpf_redirect since userspace has to manage clsact, filters, priorities and action lifecycle/cleanup.
For a gateway translator, though, I still think a device-bound model is less natural. There the translation point is more like a forwarding decision across routes and nexthops, so a route/LWT attachment, or possibly a netfilter attachment seems easier to reason about. Also, as you already pointed out while discussing LWT, an admin setting up NAT64 is more likely to reach for an nft rule than for a clsact filter on a specific device.
Taking a step back, ipxlat is really a generic translation engine plus a thin harness around it. So rather than pick one attachment, it might be worth structuring the engine so different harnesses can drive it. There's interesting precedent for this shape:
- ILA, again, is the closest sibling: stateless IPv6 address translation with a shared core in ila_common.c, driven both by an LWT frontend in ila_lwt.c and by an inline netfilter hook with a netlink-configured mapping table in ila_xlat.c.
- act_ct is the precedent for the TC side specifically: a TC action that reuses the netfilter conntrack engine rather than reimplementing it.
And act_nat is the cautionary counter-example: a standalone TC reimplementation of stateless NAT that shares no code with nf_nat, and carries a "would be nice to share code" comment :)
So I am wondering whether the right direction is to factor the translation engine cleanly, land it with one harness first, and keep the other attachment points as follow-up work once the core semantics are settled.
Does that direction seem reasonable to you?
Signature · 2 lines
Ralf Lici Mandelbit Srl
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Quoted 84 lines · Ralf Lici
Quoted 71 lines · Toke Høiland-Jørgensen
Quoted 58 lines
Quoted 8 lines
Quoted 7 lines
My second concern is that the SIIT boundary would be a property of rule and hook placement. That gives flexibility, but it also means the translation point has to be constrained and documented very carefully to avoid ambiguous TTL/Hop Limit, PMTU/ICMP, and hook-order behavior. For this use case I would rather have the route that matches the translation prefix also be the object that says: leave this family here and continue in the other one.
Quoted 7 lines
Yeah, with flexibility comes the ability to shoot yourself in the foot. But that's not really different from much of the other functionality we have in the kernel today, is it? For netfilter in particular it's certainly possible to configure a broken NAT configuration that leads to packet drops (or just invalid packets being sent out on a network device).
True, misconfiguration is always possible and that alone is not an argument against the netfilter model. But what do we actually gain in capability from that flexibility? I agree on the UX argument (an admin would look in nft first), but in terms of what the feature can do, I can't yet see what the nft model unlocks. More on this just below.
Quoted 15 lines
Quoted 4 lines
After looking at the available kernel mechanisms again, I think the better model is probably LWT: routes carry an ipxlat encap referencing a named translator domain configured over netlink. That should represent the stateless, prefix-based and symmetric nature of ipxlat.
I think this description actually hits the nail on the head: What are we implementing here? Is it a product feature, or a building block for one? The properties you mention wrt consistency, symmetry etc are properties of the high-level feature (which is also generally the level things are specified in RFCs). Whereas other packet mangling features in the kernel are more in the "building block" category, where it's possible to configure things to implement a particular feature set / compliance with a particular RFC, but it's also possible to do things that are outside of that.
Quoted 6 lines
I think this relates to the "mechanism, not policy" approach that we take to most things in the kernel: implement the building blocks to do something in the most general way we can, and then leave it up to userspace to configure things in a way that results in a consistent high-level system behaviour.
That's a good point, and I agree that we should not bake a high-level product policy into the kernel if what we need is a reusable mechanism (the LWT idea was my attempt at exactly that). What I am still trying to understand is whether there is a useful generic trigger for stateless cross-family translation beyond the route/prefix/policy-routing cases.
Routes and policy routing already cover the selectors I can make coherent for a stateless, per-packet translator: destination/source prefix, iif/oif/VRF, mark, TOS/DSCP, and so on. nft can of course match much more than that, but the additional selectors that would materially change the translation decision seem to be selectors such as L4 fields, payload state, or conntrack state. Those are exactly the selectors I am struggling to make correct for a stateless translator:
Quoted 8 lines
- non-first fragments carry no L4 header at all, yet the translator must rewrite every fragment (an nft ... tcp dport trigger cannot fire on them);
- ICMP errors must be translated too, but the flow identity lives in the quoted inner header (reversed), not in anything an L4/ct match on the error packet can see and there is no conntrack to associate them, since this is stateless.
True in principle, but if (say) you deploy this on a network that is configured so it will never fragment packets, this won't be an issue in practice.
Quoted 11 lines
I.e., you're quite right that arbitrary matching criteria cannot be guaranteed to result in coherent translation. But I think that goes into the "use it wrong, get wrong results" bin. E.g., if you match on something that results in only a subset of the packets of a flow being translated, well, only that subset of the packets will make it to the destination. The SIIT translator itself should not try to fix this, but neither should it prevent it; that's what I mean by "building block" - it's up to the builder using the blocks to make sure the building doesn't collapse, that's out of scope for the block manufacturer to worry about :)
Quoted 2 lines
I agree with that framing. The translation core should not try to prove that the surrounding policy describes a coherent SIIT deployment.
Cool!
Quoted 41 lines
Quoted 18 lines
Quoted 10 lines
So an L4-conditional trigger does not look like a good primitive for correct stateless SIIT unless the action also defragments/refragments or uses conntrack-like state. Those may be valid mechanisms, but they move the design away from the stateless per-packet SIIT boundary this RFC is trying to model.
So my first question is: is there a useful nft configuration this should enable that is not naturally expressible as route selection, while still remaining stateless SIIT rather than a NAT64-like stateful feature? Maybe there is a real use case there, but I cannot construct one yet.
So the poster child for "match on arbitrary criteria" is of course BPF. You can write BPF programs that match on arbitrary parts of the packet header, custom encapsulation headers,or even on out of band things like system state, phase of the moon, or what have you. And we should certainly allow a BPF program to make the decision on whether to perform the SIIT translation.
Quoted 9 lines
Which... maybe is an argument to keep it as a device like you do in this RFC series? Redirecting to a device is trivially supported from TC-BPF, which also makes it possible to use the translation mechanism without going through the routing subsystem at all, saving a bit of overhead. Whereas making it a route action ties it very closely to the routing subsystem.
WDYT?
I see the netdevice appeal for this, especially as a BPF redirect target. But as we discussed earlier, the device model has some real
problems: the device selected by the first route is not the real post-translation egress, so the model ends up doing translation and reinjection rather than normal transmission. Concretely:- it needs synthetic routing state purely to get things like MTU for fragmentation, because the real post-translation nexthop is not known at translation time;
- TTL/Hop Limit handling gets harder to reason about because the packet has effectively gone through two routing decisions;
Quoted 8 lines
- rx/tx stats can't be made meaningful for a direction-agnostic device whose
ndo_start_xmitis really "translate and receive";- and the setup is not very obvious: create an interface, route packets to it, then have them come back translated.
None of these is fatal on its own, but together they make me think the abstraction does not quite fit.
Right, OK, you're right.
Quoted 14 lines
On the BPF point specifically: I agree a BPF program should be able to decide whether to translate. What I am less sure about is whether redirecting to a netdevice is the best way to expose that. A TC action (yet another model, I know :)) gives you the same thing in-pipeline and more directly:
tc filter add dev wwan0 egress \
bpf obj match.o action ipxlat4to6 domain clat0Let BPF make the policy decision, with the native action doing the translation work that the current BPF CLAT implementations have trouble
with: fragmentation, checksum corner cases, and ICMP error inner headers (as explained by Beniamino).
Quoted 7 lines
So TC clsact looks like the natural in-kernel replacement for today's TC-BPF CLAT programs: no extra netdev, you attach to the existing uplink, direction is explicit, and on egress you sit on the real route dst, so the synthetic-dst and double-routing problems above just don't arise. The cost is more moving parts than a single
bpf_redirectsince userspace has to manage clsact, filters, priorities and action lifecycle/cleanup.
Hmm, so no one really uses the bpf filter mechanism, since you can just do everything from an action anyway (and with TCX attachment, you can even avoid the overhead of the TC filter/action infrastructure entirely). However, point taken wrt how to integrate this with BPF. I guess the most flexible thing would be to expose the functionality directly (as a kfunc callable from a BPF program). Which also fits with your point below:
Quoted 25 lines
For a gateway translator, though, I still think a device-bound model is less natural. There the translation point is more like a forwarding decision across routes and nexthops, so a route/LWT attachment, or possibly a netfilter attachment seems easier to reason about. Also, as you already pointed out while discussing LWT, an admin setting up NAT64 is more likely to reach for an nft rule than for a clsact filter on a specific device.
Taking a step back, ipxlat is really a generic translation engine plus a thin harness around it. So rather than pick one attachment, it might be worth structuring the engine so different harnesses can drive it. There's interesting precedent for this shape:
- ILA, again, is the closest sibling: stateless IPv6 address translation with a shared core in
ila_common.c, driven both by an LWT frontend inila_lwt.cand by an inline netfilter hook with a netlink-configured mapping table inila_xlat.c.-
act_ctis the precedent for the TC side specifically: a TC action that reuses the netfilter conntrack engine rather than reimplementing it.And
act_natis the cautionary counter-example: a standalone TC reimplementation of stateless NAT that shares no code withnf_nat, and carries a "would be nice to share code" comment :)
Quoted 6 lines
So I am wondering whether the right direction is to factor the translation engine cleanly, land it with one harness first, and keep the other attachment points as follow-up work once the core semantics are settled.
Does that direction seem reasonable to you?
Yes, reusable functionality that can be called from multiple places sounds like a good fit; let's try to structure it that way!
As for which hook to start with, well, let's see if we hear back from the netfilter devs, but either netfilter or the routing subsystem (LWT style) would be OK for me I think.
-Toke
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Quoted 23 lines · Toke Høiland-Jørgensen
Quoted 14 lines · Ralf Lici
On the BPF point specifically: I agree a BPF program should be able to decide whether to translate. What I am less sure about is whether redirecting to a netdevice is the best way to expose that. A TC action (yet another model, I know :)) gives you the same thing in-pipeline and more directly:
tc filter add dev wwan0 egress \
bpf obj match.o action ipxlat4to6 domain clat0Let BPF make the policy decision, with the native action doing the translation work that the current BPF CLAT implementations have trouble
with: fragmentation, checksum corner cases, and ICMP error inner headers (as explained by Beniamino).Quoted 7 lines
So TC clsact looks like the natural in-kernel replacement for today's TC-BPF CLAT programs: no extra netdev, you attach to the existing uplink, direction is explicit, and on egress you sit on the real route dst, so the synthetic-dst and double-routing problems above just don't arise. The cost is more moving parts than a single
bpf_redirectsince userspace has to manage clsact, filters, priorities and action lifecycle/cleanup.
Quoted 8 lines
Hmm, so no one really uses the bpf filter mechanism, since you can just do everything from an action anyway (and with TCX attachment, you can even avoid the overhead of the TC filter/action infrastructure entirely). However, point taken wrt how to integrate this with BPF. I guess the most flexible thing would be to expose the functionality directly (as a kfunc callable from a BPF program). Which also fits with your point below:
Ah, I see, the cls_bpf example was dated, and I like the kfunc angle better than a new TC action.
I would probably keep that as the minimal per-packet interface: BPF can decide whether a packet should be translated, and the kfunc can do the actual translation work for packets whose translated form still fits the output MTU. The full 4->6 fragmentation case still looks like output-path/harness territory to me, since it is a 1->N fan-out operation.
Quoted 30 lines
Quoted 30 lines
For a gateway translator, though, I still think a device-bound model is less natural. There the translation point is more like a forwarding decision across routes and nexthops, so a route/LWT attachment, or possibly a netfilter attachment seems easier to reason about. Also, as you already pointed out while discussing LWT, an admin setting up NAT64 is more likely to reach for an nft rule than for a clsact filter on a specific device.
Taking a step back, ipxlat is really a generic translation engine plus a thin harness around it. So rather than pick one attachment, it might be worth structuring the engine so different harnesses can drive it. There's interesting precedent for this shape:
- ILA, again, is the closest sibling: stateless IPv6 address translation with a shared core in
ila_common.c, driven both by an LWT frontend inila_lwt.cand by an inline netfilter hook with a netlink-configured mapping table inila_xlat.c.-
act_ctis the precedent for the TC side specifically: a TC action that reuses the netfilter conntrack engine rather than reimplementing it.And
act_natis the cautionary counter-example: a standalone TC reimplementation of stateless NAT that shares no code withnf_nat, and carries a "would be nice to share code" comment :)So I am wondering whether the right direction is to factor the translation engine cleanly, land it with one harness first, and keep the other attachment points as follow-up work once the core semantics are settled.
Quoted 5 lines
Quoted 1 line
Does that direction seem reasonable to you?
Yes, reusable functionality that can be called from multiple places sounds like a good fit; let's try to structure it that way!
Great, that's the direction I'll take then.
Quoted 4 lines
As for which hook to start with, well, let's see if we hear back from the netfilter devs, but either netfilter or the routing subsystem (LWT style) would be OK for me I think.
Works for me. The engine factoring is common to all of them, so I'll start there. Once it's in shape I can sketch a harness against it to sanity-check the interface.
Signature · 2 lines
Ralf Lici Mandelbit Srl
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Quoted 36 lines · Ralf Lici
Quoted 23 lines · Toke Høiland-Jørgensen
Quoted 14 lines · Ralf Lici
On the BPF point specifically: I agree a BPF program should be able to decide whether to translate. What I am less sure about is whether redirecting to a netdevice is the best way to expose that. A TC action (yet another model, I know :)) gives you the same thing in-pipeline and more directly:
tc filter add dev wwan0 egress \
bpf obj match.o action ipxlat4to6 domain clat0Let BPF make the policy decision, with the native action doing the translation work that the current BPF CLAT implementations have trouble
with: fragmentation, checksum corner cases, and ICMP error inner headers (as explained by Beniamino).Quoted 7 lines
So TC clsact looks like the natural in-kernel replacement for today's TC-BPF CLAT programs: no extra netdev, you attach to the existing uplink, direction is explicit, and on egress you sit on the real route dst, so the synthetic-dst and double-routing problems above just don't arise. The cost is more moving parts than a single
bpf_redirectsince userspace has to manage clsact, filters, priorities and action lifecycle/cleanup.Quoted 8 lines
Hmm, so no one really uses the bpf filter mechanism, since you can just do everything from an action anyway (and with TCX attachment, you can even avoid the overhead of the TC filter/action infrastructure entirely). However, point taken wrt how to integrate this with BPF. I guess the most flexible thing would be to expose the functionality directly (as a kfunc callable from a BPF program). Which also fits with your point below:
Ah, I see, the
cls_bpfexample was dated, and I like the kfunc angle better than a new TC action.
Quoted 6 lines
I would probably keep that as the minimal per-packet interface: BPF can decide whether a packet should be translated, and the kfunc can do the actual translation work for packets whose translated form still fits the output MTU. The full 4->6 fragmentation case still looks like output-path/harness territory to me, since it is a 1->N fan-out operation.
Yeah, that would probably be fine; I would expect that in most cases you'd want to configure your MTU to avoid fragmentation anyway :)
Quoted 38 lines
Quoted 30 lines
Quoted 30 lines
For a gateway translator, though, I still think a device-bound model is less natural. There the translation point is more like a forwarding decision across routes and nexthops, so a route/LWT attachment, or possibly a netfilter attachment seems easier to reason about. Also, as you already pointed out while discussing LWT, an admin setting up NAT64 is more likely to reach for an nft rule than for a clsact filter on a specific device.
Taking a step back, ipxlat is really a generic translation engine plus a thin harness around it. So rather than pick one attachment, it might be worth structuring the engine so different harnesses can drive it. There's interesting precedent for this shape:
- ILA, again, is the closest sibling: stateless IPv6 address translation with a shared core in
ila_common.c, driven both by an LWT frontend inila_lwt.cand by an inline netfilter hook with a netlink-configured mapping table inila_xlat.c.-
act_ctis the precedent for the TC side specifically: a TC action that reuses the netfilter conntrack engine rather than reimplementing it.And
act_natis the cautionary counter-example: a standalone TC reimplementation of stateless NAT that shares no code withnf_nat, and carries a "would be nice to share code" comment :)So I am wondering whether the right direction is to factor the translation engine cleanly, land it with one harness first, and keep the other attachment points as follow-up work once the core semantics are settled.
Quoted 5 lines
Quoted 1 line
Does that direction seem reasonable to you?
Yes, reusable functionality that can be called from multiple places sounds like a good fit; let's try to structure it that way!
Great, that's the direction I'll take then.
Quoted 8 lines
Quoted 4 lines
As for which hook to start with, well, let's see if we hear back from the netfilter devs, but either netfilter or the routing subsystem (LWT style) would be OK for me I think.
Works for me. The engine factoring is common to all of them, so I'll start there. Once it's in shape I can sketch a harness against it to sanity-check the interface.
Awesome, sounds good!
-Toke
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
In reply to Toke Høiland-JørgensenQuoted 8 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Ralf Lici
This commit introduces the core
start_xmitprocessing flow: validate, select action, translate, and forward. It centralizes action resolution in the dispatch layer and keeps per-direction translation logic separate from device glue. The result is a single data-path entry point with explicit control over drop/forward/emit behavior.
Quoted 6 lines
Quoted 1 line
Signed-off-by Ralf Lici <[email protected]>This is very cool! Going quickly through the series, this seems like thorough work that will be cool to have available in the kernel, so thanks for doing this! I'll be quite happy to retire my barebones BPF-based implementation once this lands :)
Hi,
speaking as a maintainer of NetworkManager, I would also like to see this feature in the kernel!
In NetworkManager currently we are using a BPF program [1] to implement the CLAT, but that approach comes with limitations: for example, we can't fragment v4->v6 packets if needed, and it's not possible to recompute checksums in certain cases (e.g. for v4->v6 UDP packets with zero checksum, and for fragmented ICMP). systemd-networkd is also adding CLAT support via BPF [2], with a fallback to userspace for the cases that can't be handled in kernel.
It would be very useful to have a native in-kernel CLAT that solves the limitations of BPF-based solutions, and can be used by different tools without having to re-implement everything from scratch.
Beniamino
[1] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/blob/1.57.2-dev/src/core/bpf/clat.bpf.c
[2] https://github.com/systemd/systemd/pull/41412
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Quoted 2 lines · Beniamino Galvani
Hi,
Hi Beniamino,
Quoted 11 lines
speaking as a maintainer of NetworkManager, I would also like to see this feature in the kernel!
In NetworkManager currently we are using a BPF program [1] to implement the CLAT, but that approach comes with limitations: for example, we can't fragment
v4->v6packets if needed, and it's not possible to recompute checksums in certain cases (e.g. forv4->v6UDP packets with zero checksum, and for fragmented ICMP). systemd-networkd is also adding CLAT support via BPF [2], with a fallback to userspace for the cases that can't be handled in kernel.
Quoted 4 lines
It would be very useful to have a native in-kernel CLAT that solves the limitations of BPF-based solutions, and can be used by different tools without having to re-implement everything from scratch.
Thanks, this is really useful context.
CLAT is exactly the kind of consumer ipxlat aims to serve, and the gaps you hit in BPF line up directly with paths ipxlat already handles. I'll cite this as motivation in the next cover letter, if that's alright.
While reading the BPF programs, two things stood out that would help shape v2. On addressing, both implementations use a single NAT64/PLAT prefix for destinations plus an explicit local_v4<>local_v6 mapping for the host itself. ipxlat today maps both source and destination through one RFC 6052 prefix, so this suggests v2 should probably support explicit 1:1 address mappings (EAM, RFC 7757) alongside prefix embedding. Is a single local mapping enough for your case, or do you foresee needing several?
On the consumer side, is there anything in how NM models a connection that would make a particular kernel model awkward to drive, e.g. needing to attach to an already-managed interface, or conversely being able to create and own a dedicated device? We're still settling the kernel-facing model for v2, so consumer input here is genuinely valuable.
Thanks,
Signature · 2 lines
Ralf Lici Mandelbit Srl
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Quoted 16 lines · Ralf Lici
Quoted 11 lines
speaking as a maintainer of NetworkManager, I would also like to see this feature in the kernel!
In NetworkManager currently we are using a BPF program [1] to implement the CLAT, but that approach comes with limitations: for example, we can't fragment
v4->v6packets if needed, and it's not possible to recompute checksums in certain cases (e.g. forv4->v6UDP packets with zero checksum, and for fragmented ICMP). systemd-networkd is also adding CLAT support via BPF [2], with a fallback to userspace for the cases that can't be handled in kernel.Quoted 4 lines
It would be very useful to have a native in-kernel CLAT that solves the limitations of BPF-based solutions, and can be used by different tools without having to re-implement everything from scratch.
Quoted 5 lines
Thanks, this is really useful context.
CLAT is exactly the kind of consumer ipxlat aims to serve, and the gaps you hit in BPF line up directly with paths ipxlat already handles. I'll cite this as motivation in the next cover letter, if that's alright.
Yes, please do!
Quoted 8 lines
While reading the BPF programs, two things stood out that would help shape v2. On addressing, both implementations use a single NAT64/PLAT prefix for destinations plus an explicit local_v4<>local_v6 mapping for the host itself. ipxlat today maps both source and destination through one RFC 6052 prefix, so this suggests v2 should probably support explicit 1:1 address mappings (EAM, RFC 7757) alongside prefix embedding. Is a single local mapping enough for your case, or do you foresee needing several?
Based on these:
https://datatracker.ietf.org/doc/html/rfc6877#section-6.3
https://www.ietf.org/archive/id/draft-ietf-v6ops-claton-14.html#name-obtaining-clat-ipv6-address
there are two cases to consider for CLAT.
If the node doing CLAT extends the IPv4 connectivity downstream, it should acquire a dedicated prefix via DHCPv6-PD for the downstream network, and use this prefix to generate IPv4-Embedded IPv6 Addresses (RFC 6052 2.2) for downlink hosts. In this case, the ipxlat device would need to be configured with two prefixes: one is the NAT64 prefix used to synthesize IPv6 destinations for IPv4 Internet addresses, and the other is the delegated prefix used to synthesize IPv6 source addresses for hosts on the downstream IPv4 network. Ideally, the ipxlat device should also be aware of the address range of the downstream IPv4 network, and check that the source addresses of packets belong to that network.
If the node doing CLAT does not extend IPv4 connectivity downstream (or it does, but it also uses NAT44), the "downstream network" is basically just one host. The CLAT only needs to map a single locally-generated IPv4 address (usually in the 192.0.0.0/29 range) to a single SLAAC IPv6 address reserved for the CLAT. In this case, the ipxlat device would need to know the CLAT IPv4 address, the CLAT IPv6 address and the NAT64 prefix.
Currently, NetworkManager only uses a single IPv4 address and doesn't request a dedicated prefix via DHCPv6-PD for the CLAT. If it needs to provide downstream connectivity, it does IPv4 masquerading so that the traffic originates from a single IPv4 address. I think the ipxlat implementation should also support the delegated-prefix case, as this architecture is described in the standards.
Quoted 6 lines
On the consumer side, is there anything in how NM models a connection that would make a particular kernel model awkward to drive, e.g. needing to attach to an already-managed interface, or conversely being able to create and own a dedicated device? We're still settling the kernel-facing model for v2, so consumer input here is genuinely valuable.
Any of the solutions mentioned in the thread (dedicated device, netfilter, LWT) would be fine from NetworkManager's point of view. Compared to what we are doing now, they would be a great simplification ;)
Beniamino
Re: [RFC net-next 08/15] ipxlat: add translation engine and dispatch core
Quoted 37 lines · Beniamino Galvani
Quoted 8 lines · Ralf Lici
While reading the BPF programs, two things stood out that would help shape v2. On addressing, both implementations use a single NAT64/PLAT prefix for destinations plus an explicit local_v4<>local_v6 mapping for the host itself. ipxlat today maps both source and destination through one RFC 6052 prefix, so this suggests v2 should probably support explicit 1:1 address mappings (EAM, RFC 7757) alongside prefix embedding. Is a single local mapping enough for your case, or do you foresee needing several?
Based on these:
https://datatracker.ietf.org/doc/html/rfc6877#section-6.3
https://www.ietf.org/archive/id/draft-ietf-v6ops-claton-14.html#name-obtaining-clat-ipv6-addressthere are two cases to consider for CLAT.
If the node doing CLAT extends the IPv4 connectivity downstream, it should acquire a dedicated prefix via DHCPv6-PD for the downstream network, and use this prefix to generate IPv4-Embedded IPv6 Addresses (RFC 6052 2.2) for downlink hosts. In this case, the ipxlat device would need to be configured with two prefixes: one is the NAT64 prefix used to synthesize IPv6 destinations for IPv4 Internet addresses, and the other is the delegated prefix used to synthesize IPv6 source addresses for hosts on the downstream IPv4 network. Ideally, the ipxlat device should also be aware of the address range of the downstream IPv4 network, and check that the source addresses of packets belong to that network.
If the node doing CLAT does not extend IPv4 connectivity downstream (or it does, but it also uses NAT44), the "downstream network" is basically just one host. The CLAT only needs to map a single locally-generated IPv4 address (usually in the 192.0.0.0/29 range) to a single SLAAC IPv6 address reserved for the CLAT. In this case, the ipxlat device would need to know the CLAT IPv4 address, the CLAT IPv6 address and the NAT64 prefix.
Quoted 7 lines
Currently, NetworkManager only uses a single IPv4 address and doesn't request a dedicated prefix via DHCPv6-PD for the CLAT. If it needs to provide downstream connectivity, it does IPv4 masquerading so that the traffic originates from a single IPv4 address. I think the ipxlat implementation should also support the delegated-prefix case, as this architecture is described in the standards.
I see. Your CLAT breakdown makes it clear that the single-prefix model in this RFC is too narrow for v2. What I am currently thinking is to shape the config as a far-side prefix plus an optional near-side map. The 2 CLAT cases then can be represented roughly as:
remote-prefix6 64:ff9b::/96
local-map 192.0.0.1/32 2001:db8:1:2::1234/128for the single-host CLAT case (which is an explicit 1:1 mapping), and:
remote-prefix6 64:ff9b::/96
local-map 192.0.2.0/24 2001:db8:100:64::/96for the downstream/delegated-prefix case.
The idea is that remote-prefix6 is the RFC 6052 prefix used for the NAT64/PLAT side, while local-map optionally describes the near-side mapping. If local-map is omitted, the translator falls back to the symmetric v1 behavior where the same RFC 6052 prefix is used for both source and destination.
On the source-range check you mentioned: it falls out of the near-side map for free. In the 4->6 direction the source is resolved through local-map only, so a source outside its IPv4 domain (the /32 or the /24 above) simply has no near-side mapping and is dropped, so no separate anti-spoofing knob should be needed. Anything broader than "is this a valid near-side source" I'd leave to routing/nft rather than bake into the translator.
Names and exact attribute shape are still WIP, but does this capture the two CLAT cases you had in mind?
Quoted 7 lines
Quoted 6 lines
On the consumer side, is there anything in how NM models a connection that would make a particular kernel model awkward to drive, e.g. needing to attach to an already-managed interface, or conversely being able to create and own a dedicated device? We're still settling the kernel-facing model for v2, so consumer input here is genuinely valuable.
Quoted 5 lines
Any of the solutions mentioned in the thread (dedicated device, netfilter, LWT) would be fine from NetworkManager's point of view. Compared to what we are doing now, they would be a great simplification ;)
Nice, thanks for confirming!
Signature · 2 lines
Ralf Lici Mandelbit Srl
RFC 9/15 ipxlat: emit translator-generated ICMP errors on drop
In reply to Ralf LiciWhen validation or policy requires dropping a packet and generating an ICMP error, route that failure through explicit ICMP emission paths so the sender can be notified where appropriate. This commit adds translator-originated error generation for both directions and integrates it into dispatch action handling without changing normal forwarding behavior.
--- drivers/net/ipxlat/dispatch.c | 66 ++++++++++++++++++++++++++++++++++- drivers/net/ipxlat/dispatch.h | 7 ++++ drivers/net/ipxlat/packet.c | 25 ++++++++++--- 3 files changed, 92 insertions(+), 6 deletions(-)
drivers/net/ipxlat/dispatch.c +65 -1
@@ -11,7 +11,12 @@* Ralf Lici <[email protected]> */ +#include <linux/icmp.h> +#include <linux/icmpv6.h> +#include <net/icmp.h> #include <net/ip.h> +#include <net/route.h> +#include <net/ipv6.h> #include "dispatch.h" #include "packet.h"
@@ -21,7 +26,8 @@static enum ipxlat_action ipxlat_resolve_failed_action (const struct sk_buff *skb) { -return IPXLAT_ACT_DROP ; +return ipxlat_skb_cb (skb)->emit_icmp_err ?IPXLAT_ACT_ICMP_ERR : +IPXLAT_ACT_DROP ; } enum ipxlat_action ipxlat_translate(struct ipxlat_priv *ipxlat,
@@ -61,6 +67,59 @@ void ipxlat_mark_icmp_drop(struct sk_buff *skb, u8 type, u8 code, u32 info) cb->icmp_err.info = info; } +static void ipxlat_46_emit_icmp_err (struct ipxlat_priv *ipxlat, +struct sk_buff *inner) +{ +struct ipxlat_cb *cb =ipxlat_skb_cb (inner); +const struct iphdr *iph =ip_hdr (inner); +struct inet_skb_parm param = {}; + +/* build route metadata on demand when the packet has no dst */ +if (unlikely (!skb_dst (inner))) { +const int reason =ip_route_input_noref (inner, iph->daddr, + iph->saddr, +ip4h_dscp (iph), + inner->dev); + +if (unlikely (reason)) { +netdev_dbg (ipxlat->dev, +"icmp4 emit: route build failed reason=%d\n" , + reason); +return ; + } + } + +/* emit the ICMPv4 error */ +__icmp_send (inner, cb->icmp_err.type, cb->icmp_err.code, +htonl (cb->icmp_err.info), ¶m); +} + +static void ipxlat_64_emit_icmp_err (struct sk_buff *inner) +{ +struct ipxlat_cb *cb =ipxlat_skb_cb (inner); +struct inet6_skb_parm param = {}; + +/* emit the ICMPv6 error */ +icmp6_send (inner, cb->icmp_err.type, cb->icmp_err.code, + cb->icmp_err.info,NULL , ¶m); +} + +/* emit translator-generated ICMP errors for packets rejected by RFC rules */ +void ipxlat_emit_icmp_error (struct ipxlat_priv *ipxlat,struct sk_buff *inner) +{ +switch (ntohs (inner->protocol)) { +case ETH_P_IPV6 : +ipxlat_64_emit_icmp_err (inner); +return ; +case ETH_P_IP : +ipxlat_46_emit_icmp_err (ipxlat, inner); +return ; +default : +DEBUG_NET_WARN_ON_ONCE (1 ); +return ; + } +} +static void ipxlat_forward_pkt (struct ipxlat_priv *ipxlat,struct sk_buff *skb) {const unsigned int len = skb->len;
@@ -90,6 +149,11 @@ int ipxlat_process_skb(struct ipxlat_priv *ipxlat, struct sk_buff *skb,dev_dstats_tx_add (ipxlat->dev, skb->len);ipxlat_forward_pkt (ipxlat, skb);return 0 ; +case IPXLAT_ACT_ICMP_ERR : +dev_dstats_tx_dropped (ipxlat->dev); +ipxlat_emit_icmp_error (ipxlat, skb); +consume_skb (skb); +return 0 ;case IPXLAT_ACT_DROP : goto drop_free;default :
drivers/net/ipxlat/dispatch.h +7 -0
@@ -44,6 +44,13 @@ enum ipxlat_action {*/ void ipxlat_mark_icmp_drop (struct sk_buff *skb,u8 type,u8 code,u32 info); +/** +* ipxlat_emit_icmp_error - emit cached translator-generated ICMP error +* @ipxlat: translator private context +* @inner: offending packet used as quoted payload +*/ +void ipxlat_emit_icmp_error (struct ipxlat_priv *ipxlat,struct sk_buff *inner); +/** * ipxlat_translate - validate/translate one packet and return next action * @ipxlat: translator private context
drivers/net/ipxlat/packet.c +20 -5
@@ -142,6 +142,8 @@ static int ipxlat_v4_srr_check(struct sk_buff *skb, const struct iphdr *hdr)if (unlikely (ptr > len -3 ))return -EINVAL ; +ipxlat_mark_icmp_drop (skb,ICMP_DEST_UNREACH , +ICMP_SR_FAILED ,0 );return -EINVAL ; }
@@ -272,8 +274,10 @@ static int ipxlat_v4_pull_hdrs(struct sk_buff *skb)/* RFC 7915 Section 4.1 */ if (unlikely (ipxlat_v4_srr_check (skb, l3_hdr)))return -EINVAL ; -if (unlikely (l3_hdr->ttl <=1 )) +if (unlikely (l3_hdr->ttl <=1 )) { +ipxlat_mark_icmp_drop (skb,ICMP_TIME_EXCEEDED ,ICMP_EXC_TTL ,0 );return -EINVAL ; + }/* RFC 7915 Section 1.2: * Fragmented ICMP/ICMPv6 packets will not be translated by IP/ICMP
@@ -390,8 +394,11 @@ int ipxlat_v4_validate_skb(struct ipxlat_priv *ipxlat, struct sk_buff *skb)* Fragmented checksum-less IPv4 UDP is rejected because 4->6 cannot * reliably translate it. */ -if (unlikely (ip_is_fragment (l3_hdr))) +if (unlikely (ip_is_fragment (l3_hdr))) { +ipxlat_mark_icmp_drop (skb,ICMP_DEST_UNREACH ,ICMP_PKT_FILTERED , +0 );return -EINVAL ; + }/* udph->len bounds the span used to compute replacement checksum */ if (unlikely (ntohs (udph->len) > skb->len - cb->l4_off))
@@ -520,7 +527,7 @@ static int ipxlat_v6_walk_hdrs(struct sk_buff *skb, unsigned int l3_offset,*/ static int ipxlat_v6_check_rh (struct sk_buff *skb) { -unsigned int rh_off; +unsigned int rh_off, pointer;int flags, nexthdr; rh_off =0 ;
@@ -531,6 +538,8 @@ static int ipxlat_v6_check_rh(struct sk_buff *skb)if (likely (nexthdr !=NEXTHDR_ROUTING ))return 0 ; + pointer = rh_off + offsetof(struct ipv6_rt_hdr , segments_left); +ipxlat_mark_icmp_drop (skb,ICMPV6_PARAMPROB ,ICMPV6_HDR_FIELD , pointer);return -EINVAL ; }
@@ -550,8 +559,11 @@ static int ipxlat_v6_pull_outer_l3(struct sk_buff *skb) !ipxlat_v6_validate_saddr(&l3_hdr->saddr))) return -EINVAL; -if (unlikely (l3_hdr->hop_limit <=1 )) +if (unlikely (l3_hdr->hop_limit <=1 )) { +ipxlat_mark_icmp_drop (skb,ICMPV6_TIME_EXCEED , +ICMPV6_EXC_HOPLIMIT ,0 );return -EINVAL ; + }return 0 ; }
@@ -617,8 +629,11 @@ static int ipxlat_v6_pull_hdrs(struct sk_buff *skb)/* -EPROTONOSUPPORT means packet layout is syntactically valid but * unsupported by our RFC 7915 path */ -if (unlikely (err == -EPROTONOSUPPORT )) +if (unlikely (err == -EPROTONOSUPPORT )) { +ipxlat_mark_icmp_drop (skb,ICMPV6_DEST_UNREACH , +ICMPV6_ADM_PROHIBITED ,0 );return -EINVAL ; + }if (unlikely (err))return err;
Signature · 1 line
2.53.0
RFC 10/15 ipxlat: add 4to6 pre-fragmentation path
In reply to Ralf LiciRFC 7915 requires handling packets that would exceed the translated IPv6 size constraints. Add a pre-fragmentation planning/action path that invokes kernel fragmentation helpers before translation, carries fragment size through skb metadata, and then reinjects fragments into the normal translation path.
--- drivers/net/ipxlat/dispatch.c | 99 ++++++++++++++++++++++++++++++- drivers/net/ipxlat/translate_46.c | 59 +++++++++++++++++- drivers/net/ipxlat/translate_46.h | 11 ++++ 3 files changed, 166 insertions(+), 3 deletions(-)
drivers/net/ipxlat/dispatch.c +97 -2
@@ -47,6 +47,16 @@ enum ipxlat_action ipxlat_translate(struct ipxlat_priv *ipxlat,if (unlikely (ipxlat_v4_validate_skb (ipxlat, skb)))return ipxlat_resolve_failed_action (skb); +/* 4->6 prefrag plan stores per-skb frag_max_size +* when the packet must be split before translation +* (DF clear and translated size +* above PMTU/threshold). +*/ +if (unlikely (ipxlat_46_plan_prefrag (ipxlat, skb))) +return ipxlat_resolve_failed_action (skb); +if (unlikely (ipxlat_skb_cb (skb)->frag_max_size)) +return IPXLAT_ACT_PRE_FRAG ; +if (unlikely (ipxlat_46_translate (ipxlat, skb)))return ipxlat_resolve_failed_action (skb);
@@ -120,6 +130,76 @@ void ipxlat_emit_icmp_error(struct ipxlat_priv *ipxlat, struct sk_buff *inner) } } +static unsigned int ipxlat_frag_dst_get_mtu (const struct dst_entry *dst) +{ +return READ_ONCE (dst->dev->mtu); +} + +static struct dst_ops ipxlat_frag_dst_ops = { + .family =AF_UNSPEC , + .mtu = ipxlat_frag_dst_get_mtu, +}; + +/** +* ipxlat_46_frag_output - reinject one fragment produced by ip_do_fragment +* @net: network namespace of the transmitter +* @sk: originating socket +* @skb: fragment to reinject +* +* This callback mirrors ndo_start_xmit processing but runs with +* pre-fragmentation disabled to prevent recursive pre-fragment loops. +* +* Return: 0 on success, negative errno on processing failure. +*/ +static int ipxlat_46_frag_output (struct net *net,struct sock *sk, +struct sk_buff *skb) +{ +struct ipxlat_priv *ipxlat =netdev_priv (skb->dev); + +return ipxlat_process_skb (ipxlat, skb, false); +} + +/** +* ipxlat_46_fragment_pkt - fragment oversized 4->6 input before translation +* @ipxlat: translator private context +* @skb: original packet to fragment +* @frag_max_size: per-fragment payload cap for ip_do_fragment +* +* Installs a temporary synthetic dst so ip_do_fragment can read MTU and then +* reinjects each produced fragment back into ipxlat through +* ipxlat_46_frag_output. +* +* Return: 0 on success, negative errno on fragmentation failure. +*/ +static int ipxlat_46_fragment_pkt (struct ipxlat_priv *ipxlat, +struct sk_buff *skb,u16 frag_max_size) +{ +const unsigned long orig_dst = skb->_skb_refdst; +struct rtable ipxlat_rt = {}; +int err; + +/* ip_do_fragment needs a dst object to query mtu */ +dst_init (&ipxlat_rt.dst, &ipxlat_frag_dst_ops,NULL ,DST_OBSOLETE_NONE , +DST_NOCOUNT ); + +/* use translator netdev as mtu source for the temporary dst */ + ipxlat_rt.dst.dev = ipxlat->dev; + +/* setup the skb for fragmentation */ +skb_dst_set_noref (skb, &ipxlat_rt.dst); +memset (IPCB (skb),0 ,sizeof (struct inet_skb_parm )); +IPCB (skb)->frag_max_size = frag_max_size; + +/* fragment and reinject each frag in the translator */ + err =ip_do_fragment (dev_net (ipxlat->dev), skb->sk, skb, + ipxlat_46_frag_output); + +/* drop original dst ref replaced by the synthetic NOREF dst */ +refdst_drop (orig_dst); + +return err; +} +static void ipxlat_forward_pkt (struct ipxlat_priv *ipxlat,struct sk_buff *skb) {const unsigned int len = skb->len;
@@ -141,14 +221,29 @@ int ipxlat_process_skb(struct ipxlat_priv *ipxlat, struct sk_buff *skb,enum ipxlat_action action;int err = -EINVAL ; - (void )allow_pre_frag; - action =ipxlat_translate (ipxlat, skb);switch (action) {case IPXLAT_ACT_FWD :dev_dstats_tx_add (ipxlat->dev, skb->len);ipxlat_forward_pkt (ipxlat, skb);return 0 ; +case IPXLAT_ACT_PRE_FRAG : +/* prefrag is allowed only once to avoid unbounded loops */ +if (unlikely (!allow_pre_frag)) { + err = -ELOOP ; + goto drop_free; + } + +/* fragment first, then reinject each fragment through +* ipxlat_process_skb via ipxlat_46_frag_output +*/ + err =ipxlat_46_fragment_pkt (ipxlat, skb, +ipxlat_skb_cb (skb)->frag_max_size); +/* fragment path already consumed/freed skb */ + skb =NULL ; +if (unlikely (err)) + goto drop_free; +return 0 ;case IPXLAT_ACT_ICMP_ERR :dev_dstats_tx_dropped (ipxlat->dev);ipxlat_emit_icmp_error (ipxlat, skb);
drivers/net/ipxlat/translate_46.c +58 -1
71 lines not on this page · raw message
drivers/net/ipxlat/translate_46.h +11 -0
@@ -61,6 +61,17 @@ unsigned int ipxlat_46_lookup_pmtu6(struct ipxlat_priv *ipxlat,const struct sk_buff *skb, const struct iphdr *in4); +/** +* ipxlat_46_plan_prefrag - decide whether IPv4 packet must be pre-fragmented +* @ipxlat: translator private context +* @skb: packet being translated +* +* Sets cb->frag_max_size when pre-fragmentation is required. +* +* Return: 0 on success, negative errno on policy/validation failure. +*/ +int ipxlat_46_plan_prefrag (struct ipxlat_priv *ipxlat,struct sk_buff *skb); +/** * ipxlat_46_translate - translate outer packet from IPv4 to IPv6 in place * @ipxlat: translator private context
Signature · 1 line
2.53.0
Re: [RFC net-next 10/15] ipxlat: add 4to6 pre-fragmentation path
Hi Ralf,
Quoted 23 lines
drivers/net/ipxlat/translate_46.c +23
-0+int ipxlat_46_plan_prefrag (struct ipxlat_priv *ipxlat,struct sk_buff *skb) +{ +unsigned int pkt_len6, pmtu6, threshold6, frag_max_size, pkt_len4, + old_l3_len, new_l3_len; +struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +const struct iphdr *in4 =ip_hdr (skb); +int l3_delta, frag_l3_delta; + +if (unlikely (cb->frag_max_size)) { +DEBUG_NET_WARN_ON_ONCE (1 ); + cb->frag_max_size =0 ; + } + + pkt_len4 =iph_totlen (skb, in4); + old_l3_len = cb->l3_hdr_len; + new_l3_len =sizeof (struct ipv6hdr ) + + (ip_is_fragment (in4) ?sizeof (struct frag_hdr ) :0 ); + l3_delta = (int )new_l3_len - (int )old_l3_len; + pkt_len6 = pkt_len4 + l3_delta; + + pmtu6 =ipxlat_46_lookup_pmtu6 (ipxlat, skb, in4); + threshold6 =min (pmtu6,READ_ONCE (ipxlat->lowest_ipv6_mtu)); +
drivers/net/ipxlat/translate_46.c unsigned int ipxlat_46_lookup_pmtu6(struct ipxlat_priv *ipxlat, · line 132
Quoted 10 lines
drivers/net/ipxlat/translate_46.c +10
-0+if (likely (pkt_len6 <= threshold6)) +return 0 ; + +/* df packets are never locally pre-fragmented */ +if (likely (be16_to_cpu (in4->frag_off) &IP_DF )) { +/* Let the IPv6 forwarding path raise PTB when needed and rely +* on the reverse 6->4 ICMP translation path for feedback. +*/ +return 0 ; + }
How about putting the DF check before the PMTU lookup? ipxlat_46_lookup_pmtu6() requires ip6_route_output() and dst_release(), but the DF bit is much cheaper to test and is typically set on most TCP/QUIC packets. It looks like a pure reorder but I have not verified it carefully.
Best regards,
Xavier
Re: [RFC net-next 10/15] ipxlat: add 4to6 pre-fragmentation path
Quoted 2 lines · Xavier HSINYUAN
Hi Ralf,
Hi Xavier,
Sorry for the slow reply. This got buried while I was busy with other kernel work.
Quoted 31 lines
Quoted 31 lines
drivers/net/ipxlat/translate_46.c +31
-0+int ipxlat_46_plan_prefrag (struct ipxlat_priv *ipxlat,struct sk_buff *skb) +{ +unsigned int pkt_len6, pmtu6, threshold6, frag_max_size, pkt_len4, + old_l3_len, new_l3_len; +struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +const struct iphdr *in4 =ip_hdr (skb); +int l3_delta, frag_l3_delta; + +if (unlikely (cb->frag_max_size)) { +DEBUG_NET_WARN_ON_ONCE (1 ); + cb->frag_max_size =0 ; + } + + pkt_len4 =iph_totlen (skb, in4); + old_l3_len = cb->l3_hdr_len; + new_l3_len =sizeof (struct ipv6hdr ) + + (ip_is_fragment (in4) ?sizeof (struct frag_hdr ) :0 ); + l3_delta = (int )new_l3_len - (int )old_l3_len; + pkt_len6 = pkt_len4 + l3_delta; + + pmtu6 =ipxlat_46_lookup_pmtu6 (ipxlat, skb, in4); + threshold6 =min (pmtu6,READ_ONCE (ipxlat->lowest_ipv6_mtu)); + +if (likely (pkt_len6 <= threshold6)) +return 0 ; + +/* df packets are never locally pre-fragmented */ +if (likely (be16_to_cpu (in4->frag_off) &IP_DF )) { +/* Let the IPv6 forwarding path raise PTB when needed and rely +* on the reverse 6->4 ICMP translation path for feedback. +*/
Quoted 9 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ return 0; + }How about putting the DF check before the PMTU lookup?
ipxlat_46_lookup_pmtu6()requiresip6_route_output()anddst_release(), but the DF bit is much cheaper to test and is typically set on most TCP/QUIC packets. It looks like a pure reorder but I have not verified it carefully.
Yes, that looks right to me. The PMTU lookup is only needed for the non-DF path, where we may actually compute a pre-fragmentation cap. For DF packets ipxlat_46_plan_prefrag should leave frag_max_size unset and let the later IPv6 output path generate PTB if the translated packet is too large.
I'll move the DF check before ipxlat_46_lookup_pmtu6, after the stale frag_max_size clearing.
Thanks!
Signature · 2 lines
Ralf Lici Mandelbit Srl
RFC 11/15 ipxlat: add ICMP informational translation paths
In reply to Ralf LiciAdd ICMP informational message translation for both 4->6 and 6->4 paths and wire the new ICMP translation units into the engine.
This introduces the protocol mapping and checksum update logic for echo request/reply traffic, while ICMP error quoted-inner translation is added in a follow-up commit.
--- drivers/net/ipxlat/Makefile | 2 + drivers/net/ipxlat/icmp.h | 43 ++++++++++++++ drivers/net/ipxlat/icmp_46.c | 95 +++++++++++++++++++++++++++++++ drivers/net/ipxlat/icmp_64.c | 92 ++++++++++++++++++++++++++++++ drivers/net/ipxlat/translate_64.c | 1 + drivers/net/ipxlat/transport.c | 11 ---- drivers/net/ipxlat/transport.h | 5 -- 7 files changed, 233 insertions(+), 16 deletions(-) create mode 100644 drivers/net/ipxlat/icmp.h create mode 100644 drivers/net/ipxlat/icmp_46.c create mode 100644 drivers/net/ipxlat/icmp_64.c
drivers/net/ipxlat/Makefile +2 -0
@@ -11,3 +11,5 @@ ipxlat-objs += transport.o ipxlat-objs += dispatch.o ipxlat-objs += translate_46.o ipxlat-objs += translate_64.o +ipxlat-objs += icmp_46.o +ipxlat-objs += icmp_64.o
drivers/net/ipxlat/icmp.h new file +43 -0
43 lines not on this page · raw message
drivers/net/ipxlat/icmp_46.c new file +95 -0
95 lines not on this page · raw message
drivers/net/ipxlat/icmp_64.c new file +92 -0
92 lines not on this page · raw message
drivers/net/ipxlat/translate_64.c +1 -0
@@ -16,6 +16,7 @@#include "translate_64.h" #include "address.h" +#include "icmp.h" #include "packet.h" #include "transport.h"
drivers/net/ipxlat/transport.c +0 -11
@@ -338,14 +338,3 @@ int ipxlat_64_inner_udp(struct sk_buff *skb, const struct ipv6hdr *in6, udp_new->check =CSUM_MANGLED_0 ;return 0 ; } - -int ipxlat_46_icmp (struct ipxlat_priv *ipxlat,struct sk_buff *skb) -{ -return -EPROTONOSUPPORT ; -} - -int ipxlat_64_icmp (struct ipxlat_priv *ipxlat,struct sk_buff *skb, -const struct ipv6hdr *outer6) -{ -return -EPROTONOSUPPORT ; -}
drivers/net/ipxlat/transport.h +0 -5
@@ -100,9 +100,4 @@ int ipxlat_64_inner_tcp(struct sk_buff *skb, const struct ipv6hdr *in6,int ipxlat_64_inner_udp (struct sk_buff *skb,const struct ipv6hdr *in6,const struct iphdr *out4,struct udphdr *udp_new); -/* temporary ICMP stubs until ICMP translation support is introduced */ -int ipxlat_46_icmp (struct ipxlat_priv *ipxlat,struct sk_buff *skb); -int ipxlat_64_icmp (struct ipxlat_priv *ipxlat,struct sk_buff *skb, -const struct ipv6hdr *outer6); -#endif /* _NET_IPXLAT_TRANSPORT_H_ */
Signature · 1 line
2.53.0
RFC 12/15 ipxlat: add ICMP error translation and quoted-inner handling
In reply to Ralf LiciExtend ICMP translation with error-path support for both directions, including quoted-inner packet rewriting and RFC 4884 extension relayout/squeeze logic.
This adds the ICMP type/code/error-field mappings, inner L3/L4 rewrite paths, and final checksum handling required for translator ICMP error processing.
--- drivers/net/ipxlat/icmp.h | 14 +- drivers/net/ipxlat/icmp_46.c | 467 ++++++++++++++++++++++++++++++++- drivers/net/ipxlat/icmp_64.c | 453 +++++++++++++++++++++++++++++++- drivers/net/ipxlat/transport.c | 61 +++++ drivers/net/ipxlat/transport.h | 19 ++ 5 files changed, 996 insertions(+), 18 deletions(-)
drivers/net/ipxlat/icmp.h +8 -6
@@ -19,22 +19,24 @@#include "ipxlpriv.h" /** -* ipxlat_46_icmp - translate ICMP informational payload -* after outer 4->6 rewrite -* @ipxl: translator private context +* ipxlat_46_icmp - translate ICMP payload after outer 4->6 L3 rewrite +* @ipxlat: translator private context * @skb: packet carrying ICMPv4 transport payload * +* Handles both ICMP info translation and ICMP error quoted-inner rewriting. +* * Return: 0 on success, negative errno on translation failure. */ -int ipxlat_46_icmp (struct ipxlat_priv *ipxl,struct sk_buff *skb); +int ipxlat_46_icmp (struct ipxlat_priv *ipxlat,struct sk_buff *skb);/** -* ipxlat_64_icmp - translate ICMP informational payload -* after outer 6->4 rewrite +* ipxlat_64_icmp - translate ICMP payload after outer 6->4 L3 rewrite * @ipxlat: translator private context * @skb: packet carrying ICMPv6 transport payload * @in6: snapshot of original outer IPv6 header * +* Handles both ICMP info translation and ICMP error quoted-inner rewriting. +* * Return: 0 on success, negative errno on translation failure. */ int ipxlat_64_icmp(struct ipxlat_priv *ipxlat, struct sk_buff *skb,
drivers/net/ipxlat/icmp_46.c +462 -5
491 lines not on this page · raw message
drivers/net/ipxlat/icmp_64.c +446 -7
479 lines not on this page · raw message
drivers/net/ipxlat/transport.c +61 -0
67 lines not on this page · raw message
drivers/net/ipxlat/transport.h +19 -0
@@ -63,6 +63,25 @@ __sum16 ipxlat_l4_csum_ipv6(const struct in6_addr *saddr, const struct sk_buff *skb, unsigned int l4_off, unsigned int l4_len, u8 proto); +/** +* ipxlat_icmp_relayout - resize quoted ICMP payload/extensions in place +* @skb: packet buffer +* @outer_len: offset to quoted datagram start +* @in_ipl: input datagram payload length +* @in_iel: input extension length +* @out_ipl: output datagram payload length +* @out_pad: output pad bytes between datagram and extensions +* @out_iel: output extension length +* +* This helper may move payload bytes and adjust skb tail length. +* +* Return: 0 on success, negative errno on resize/memory failures. +*/ +int ipxlat_icmp_relayout (struct sk_buff *skb,unsigned int outer_len, +unsigned int in_ipl,unsigned int in_iel, +unsigned int out_ipl,unsigned int out_pad, +unsigned int out_iel); +/** * ipxlat_finalize_offload - normalize checksum/GSO metadata after translation * @skb: translated packet
Signature · 1 line
2.53.0
kernel test robot
build botRe: [RFC net-next 12/15] ipxlat: add ICMP error translation and quoted-inner handling
kernel test robot noticed the following build warnings:
Hi Ralf,
[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Ralf-Lici/drivers-net-add-ipxlat-netdevice-skeleton-and-build-plumbing/20260321-005756 base: net-next/main patch link: https://lore.kernel.org/r/20260319151230.655687-13-ralf%40mandelbit.com patch subject: [RFC net-next 12/15] ipxlat: add ICMP error translation and quoted-inner handling config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20260322/[email protected]/config) compiler: sh4-linux-gcc (GCC) 15.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260322/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/net/ipxlat/icmp_46.c: In function 'ipxlat_46_icmp_inner':
>> drivers/net/ipxlat/icmp_46.c:331:50: warning: variable 'inner_l4_off' set but not used [-Wunused-but-set-variable]
331 | unsigned int inner_l3_len, inner_l3_off, inner_l4_off, old_prefix,
| ^~~~~~~~~~~~
vim +/inner_l4_off +331 drivers/net/ipxlat/icmp_46.c
326
327 static int ipxlat_46_icmp_inner(struct ipxlat_priv *ipxlat,
328 struct sk_buff *skb, struct iphdr *inner4,
329 int *inner_delta)
330 {
> 331 unsigned int inner_l3_len, inner_l3_off, inner_l4_off, old_prefix,
332 new_prefix, inner_tot_len, inner_l3_payload, inner_l4_payload;
333 const unsigned int outer_l3_len = skb_transport_offset(skb);
334 const struct ipxlat_cb *cb = ipxlat_skb_cb(skb);
335 struct ipv6hdr outer_ip6_copy, *inner_ip6;
336 struct frag_hdr *fh6;
337 u8 next_hdr;
338 bool has_inner_frag;
339
340 inner_l3_off = cb->inner_l3_offset;
341 inner_l4_off = cb->inner_l4_offset;
342
343 /* inner header alignment is not guaranteed */
344 memcpy(inner4, skb->data + inner_l3_off, sizeof(*inner4));
345 inner_l3_len = inner4->ihl << 2;
346 has_inner_frag = ip_is_fragment(inner4);
347
348 /* save outer IPv6 hdr because pull+push destroys that hdr region */
349 outer_ip6_copy = *ipv6_hdr(skb);
350
351 old_prefix = inner_l3_off + inner_l3_len;
352 new_prefix = inner_l3_off + sizeof(struct ipv6hdr) +
353 (has_inner_frag ? sizeof(struct frag_hdr) : 0);
354 *inner_delta = (int)new_prefix - (int)old_prefix;
355
356 if (unlikely(skb_cow_head(skb, max_t(int, 0, *inner_delta))))
357 return -ENOMEM;
358
359 skb_pull(skb, old_prefix);
360 skb_push(skb, new_prefix);
361 /* outer 4->6 path already set header offsets, but inner relayout
362 * pulls/pushes change skb->data placement. Reinitialize outer header
363 * offsets so ip{,v6}_hdr/icmp{,6}_hdr and skb_transport_offset keep
364 * pointing to the outer packet.
365 */
366 skb_reset_network_header(skb);
367 skb_set_transport_header(skb, outer_l3_len);
368
369 *ipv6_hdr(skb) = outer_ip6_copy;
370 ipv6_hdr(skb)->payload_len = htons(skb->len - sizeof(struct ipv6hdr));
371
372 inner_ip6 = (struct ipv6hdr *)(skb->data + inner_l3_off);
373 /* use quoted IPv4 total-length, not skb->len:
374 * skb->len also includes ICMP extension bytes at the end, which are
375 * not part of the quoted inner IP datagram length.
376 */
377 inner_tot_len = ntohs(inner4->tot_len);
378 if (unlikely(inner_tot_len < inner_l3_len))
379 return -EINVAL;
380
381 inner_l3_payload = inner_tot_len - inner_l3_len +
382 (has_inner_frag ? sizeof(struct frag_hdr) : 0);
383 if (has_inner_frag)
384 next_hdr = NEXTHDR_FRAGMENT;
385 else
386 next_hdr = ipxlat_46_map_proto_to_nexthdr(inner4->protocol);
387
388 ipxlat_46_build_l3(inner_ip6, inner4, inner_l3_payload, next_hdr,
389 inner4->ttl);
390
391 ipxlat_46_convert_addrs(&ipxlat->xlat_prefix6, inner4, inner_ip6);
392
393 if (unlikely(has_inner_frag)) {
394 fh6 = (struct frag_hdr *)(inner_ip6 + 1);
395 ipxlat_46_build_frag_hdr(fh6, inner4, inner4->protocol);
396 }
397
398 if (unlikely(!ipxlat_is_first_frag4(inner4)))
399 return 0;
400
401 inner_l4_payload = new_prefix + ipxlat_l4_min_len(inner4->protocol);
402 if (unlikely(skb_ensure_writable(skb, inner_l4_payload)))
403 return -ENOMEM;
404
405 return ipxlat_46_icmp_inner_l4(skb, new_prefix, inner4, inner_ip6);
406 }
407
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
RFC 13/15 ipxlat: add netlink control plane and uapi
In reply to Ralf LiciExpose runtime configuration through netlink with validated set/get/dump operations and generated policy glue from the YAML spec. The API configures the translator prefix and MTU threshold used by the data path.
--- Documentation/netlink/specs/ipxlat.yaml | 97 +++++++ drivers/net/ipxlat/Makefile | 2 + drivers/net/ipxlat/main.c | 9 + drivers/net/ipxlat/netlink-gen.c | 71 +++++ drivers/net/ipxlat/netlink-gen.h | 31 +++ drivers/net/ipxlat/netlink.c | 348 ++++++++++++++++++++++++ drivers/net/ipxlat/netlink.h | 27 ++ drivers/net/ipxlat/translate_46.c | 3 +- include/uapi/linux/ipxlat.h | 48 ++++ 9 files changed, 635 insertions(+), 1 deletion(-) create mode 100644 Documentation/netlink/specs/ipxlat.yaml create mode 100644 drivers/net/ipxlat/netlink-gen.c create mode 100644 drivers/net/ipxlat/netlink-gen.h create mode 100644 drivers/net/ipxlat/netlink.c create mode 100644 drivers/net/ipxlat/netlink.h create mode 100644 include/uapi/linux/ipxlat.h
Documentation/netlink/specs/ipxlat.yaml new file +97 -0
@@ -0,0 +1,97 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +# +# Copyright (C) 2026- Mandelbit SRL +# +# Author: Antonio Quartulli <[email protected]> +# Ralf Lici <[email protected]> +# +--- +name: ipxlat +protocol: genetlink +doc: Netlink protocol to control IPXLAT (SIIT) network devices. + +definitions: + - + type: const + name: xlat-prefix6-max-prefix-len + value: 96 + doc: Maximum prefix length accepted for xlat-prefix6. + +attribute-sets: + - + name: pool + attributes: + - + name: prefix + type: binary + checks: + exact-len: 16 + - + name: prefix-len + type: u8 + checks: + max: xlat-prefix6-max-prefix-len + - + name: cfg + attributes: + - + name: xlat-prefix6 + type: nest + doc: IPv6 translation prefix. + nested-attributes: pool + - + name: lowest-ipv6-mtu + type: u32 + checks: + min: 1280 + - + name: dev + attributes: + - + name: ifindex + type: u32 + doc: Index of the ipxlat interface to operate on. + - + name: netnsid + type: s32 + doc: ID of the netns the device lives in. + - + name: config + type: nest + doc: Ipxlat device configuration. + nested-attributes: cfg + +operations: + list: + - + name: dev-get + attribute-set: dev + doc: Get / dump configuration of ipxlat devices. + do: + pre: ipxlat-nl-pre-doit + post: ipxlat-nl-post-doit + request: + attributes: + - ifindex + reply: &dev-all + attributes: + - ifindex + - netnsid + - config + dump: + reply: *dev-all + + - + name: dev-set + doc: Set configuration of an ipxlat device. + attribute-set: dev + flags: [admin-perm] + do: + request: + attributes: + - ifindex + - config + reply: + attributes: [] + pre: ipxlat-nl-pre-doit + post: ipxlat-nl-post-doit
drivers/net/ipxlat/Makefile +2 -0
@@ -13,3 +13,5 @@ ipxlat-objs += translate_46.o ipxlat-objs += translate_64.o ipxlat-objs += icmp_46.o ipxlat-objs += icmp_64.o +ipxlat-objs += netlink.o +ipxlat-objs += netlink-gen.o
drivers/net/ipxlat/main.c +9 -0
@@ -18,6 +18,7 @@#include "dispatch.h" #include "ipxlpriv.h" #include "main.h" +#include "netlink.h" MODULE_AUTHOR ("Alberto Leiva Popper <[email protected]>" );MODULE_AUTHOR ("Antonio Quartulli <[email protected]>" );
@@ -127,11 +128,19 @@ static int __init ipxlat_init(void)return err; } + err =ipxlat_nl_register (); +if (err) { +pr_err ("ipxlat: failed to register netlink family: %d\n" , err); +rtnl_link_unregister (&ipxlat_link_ops); +return err; + } +return 0 ; } static void __exit ipxlat_exit(void) { +ipxlat_nl_unregister ();rtnl_link_unregister (&ipxlat_link_ops); }
drivers/net/ipxlat/netlink-gen.c new file +71 -0
71 lines not on this page · raw message
drivers/net/ipxlat/netlink-gen.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/ipxlat.yaml */ +/* YNL-GEN kernel header */ +/* To regenerate run: tools/net/ynl/ynl-regen.sh */ + +#ifndef _LINUX_IPXLAT_GEN_H +#define _LINUX_IPXLAT_GEN_H + +#include <net/netlink.h> +#include <net/genetlink.h> + +#include <uapi/linux/ipxlat.h> + +/* Common nested types */ +extern const struct nla_policy ipxlat_cfg_nl_policy[IPXLAT_A_CFG_LOWEST_IPV6_MTU +1 ]; +extern const struct nla_policy ipxlat_pool_nl_policy[IPXLAT_A_POOL_PREFIX_LEN +1 ]; + +int ipxlat_nl_pre_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info); +void +ipxlat_nl_post_doit (const struct genl_split_ops *ops,struct sk_buff *skb, +struct genl_info *info); + +int ipxlat_nl_dev_get_doit (struct sk_buff *skb,struct genl_info *info); +int ipxlat_nl_dev_get_dumpit (struct sk_buff *skb,struct netlink_callback *cb); +int ipxlat_nl_dev_set_doit (struct sk_buff *skb,struct genl_info *info); + +extern struct genl_family ipxlat_nl_family; + +#endif /* _LINUX_IPXLAT_GEN_H */
drivers/net/ipxlat/netlink.c new file +348 -0
348 lines not on this page · raw message
drivers/net/ipxlat/netlink.h new file +27 -0
@@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* IPXLAT - Stateless IP/ICMP Translation (SIIT) virtual device driver +* +* Copyright (C) 2026- Mandelbit SRL +* Copyright (C) 2026- Daniel Gröber <[email protected]> +* +* Author: Antonio Quartulli <[email protected]> +* Daniel Gröber <[email protected]> +* Ralf Lici <[email protected]> +*/ + +#ifndef _NET_IPXLAT_NETLINK_H_ +#define _NET_IPXLAT_NETLINK_H_ + +/** +* ipxlat_nl_register - register ipxlat generic-netlink family +* +* Return: 0 on success, negative errno on registration failure. +*/ +int ipxlat_nl_register (void ); + +/** +* ipxlat_nl_unregister - unregister ipxlat generic-netlink family +*/ +void ipxlat_nl_unregister (void ); + +#endif /* _NET_IPXLAT_NETLINK_H_ */
drivers/net/ipxlat/translate_46.c +2 -1
@@ -14,6 +14,7 @@#include <net/ip6_route.h> #include "address.h" +#include "icmp.h" #include "packet.h" #include "transport.h" #include "translate_46.h"
@@ -239,7 +240,7 @@ int ipxlat_46_translate(struct ipxlat_priv *ipxlat, struct sk_buff *skb) err =ipxlat_46_outer_udp (skb, &outer4);break ;case IPPROTO_ICMP : - err = -EPROTONOSUPPORT ; + err =ipxlat_46_icmp (ipxlat, skb);break ;default : err =0 ;
include/uapi/linux/ipxlat.h new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC 14/15 selftests: net: add ipxlat coverage
In reply to Ralf LiciAdd selftests for ipxlat data plane behavior and control-plane setup.
The tests build an isolated netns topology, configure ipxlat through YNL, and exercise core traffic classes (TCP, UDP, ICMP info/error, and fragment-related paths). This provides reproducible end-to-end coverage for the translation pipeline and basic regression protection for future changes.
--- tools/testing/selftests/net/ipxlat/.gitignore | 1 + tools/testing/selftests/net/ipxlat/Makefile | 25 ++ .../selftests/net/ipxlat/ipxlat_data.sh | 70 +++++ .../selftests/net/ipxlat/ipxlat_frag.sh | 70 +++++ .../selftests/net/ipxlat/ipxlat_icmp_err.sh | 54 ++++ .../selftests/net/ipxlat/ipxlat_lib.sh | 273 ++++++++++++++++++ .../net/ipxlat/ipxlat_udp4_zero_csum_send.c | 119 ++++++++ 7 files changed, 612 insertions(+) create mode 100644 tools/testing/selftests/net/ipxlat/.gitignore create mode 100644 tools/testing/selftests/net/ipxlat/Makefile create mode 100755 tools/testing/selftests/net/ipxlat/ipxlat_data.sh create mode 100755 tools/testing/selftests/net/ipxlat/ipxlat_frag.sh create mode 100755 tools/testing/selftests/net/ipxlat/ipxlat_icmp_err.sh create mode 100644 tools/testing/selftests/net/ipxlat/ipxlat_lib.sh create mode 100644 tools/testing/selftests/net/ipxlat/ipxlat_udp4_zero_csum_send.c
tools/testing/selftests/net/ipxlat/.gitignore new file +1 -0
@@ -0,0 +1 @@ +ipxlat_udp4_zero_csum_send
tools/testing/selftests/net/ipxlat/Makefile new file +25 -0
@@ -0,0 +1,25 @@ +# SPDX-License-Identifier: GPL-2.0 +# IPXLAT - Stateless IP/ICMP Translation (SIIT) virtual device driver +# +# Copyright (C) 2026- Mandelbit SRL +# Copyright (C) 2026- Daniel Gröber <[email protected]> +# +# Author: Antonio Quartulli <[email protected]> +# Daniel Gröber <[email protected]> +# Ralf Lici <[email protected]> + +TEST_PROGS := \ + ipxlat_data.sh \ + ipxlat_frag.sh \ + ipxlat_icmp_err.sh \ +# end of TEST_PROGS + +TEST_FILES := \ + ipxlat_lib.sh \ +# end of TEST_FILES + +TEST_GEN_FILES := \ + ipxlat_udp4_zero_csum_send \ +# end of TEST_GEN_FILES + +include ../../lib.mk
tools/testing/selftests/net/ipxlat/ipxlat_data.sh new file +70 -0
70 lines not on this page · raw message
tools/testing/selftests/net/ipxlat/ipxlat_frag.sh new file +70 -0
70 lines not on this page · raw message
tools/testing/selftests/net/ipxlat/ipxlat_icmp_err.sh new file +54 -0
54 lines not on this page · raw message
tools/testing/selftests/net/ipxlat/ipxlat_lib.sh new file +273 -0
273 lines not on this page · raw message
tools/testing/selftests/net/ipxlat/ipxlat_udp4_zero_csum_send.c new file +119 -0
119 lines not on this page · raw message
Signature · 1 line
2.53.0
RFC 15/15 Documentation: networking: add ipxlat translator guide
In reply to Ralf LiciFrom: Daniel Gröber <[email protected]>
Add user and reviewer documentation for the ipxlat virtual netdevice in Documentation/networking/ipxlat.rst.
The document describes the datapath model, stateless IPv4/IPv6 address translation rules, ICMP handling, control-plane configuration, and test topology assumptions. It also records the intended runtime configuration contract and current behavior limits so deployment expectations are clear.
--- Documentation/networking/ipxlat.rst | 190 ++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 Documentation/networking/ipxlat.rst
Documentation/networking/ipxlat.rst new file +190 -0
@@ -0,0 +1,190 @@ +.. SPDX-License-Identifier: GPL-2.0+ +.. Copyright (C) 2026 Daniel Gröber <[email protected]> + +============================================== +IPXLAT - IPv6<>IPv4 IP/ICMP Translation (SIIT) +============================================== + +ipxlat (``CONFIG_IPXLAT=y``) provides a virtual netdevice implementing +stateless IP packet translation between IP versions 6 and 4. This is a +building block for establishing layer 3 connectivity between otherwise +uncommunicative IPv6-only and/or IPv4-only networks. + + +Creation and Configuration Parameters +===================================== + +An ipxlat netdevice can be created and configured using YNL like so:: + + $ ip link add siit0 type ipxlat + + $ IID=$(cat /sys/class/net/siit0/ifindex) + + $ ADDR_HEX=$(python3 -c 'import ipaddress,sys; \ + print(ipaddress.IPv6Address(sys.argv[1]).packed.hex())' \ + 64:ff9b:: | tee /dev/stderr) + 0064ff9b000000000000000000000000 + + $ ./tools/net/ynl/pyynl/cli.py --family ipxlat --json '{"ifindex": $IID, \ + "config": {"xlat-prefix6": "'$HEX_ADDR'", "prefix-len": 96} }' + +(TODO: Once implemented) A ipxlat netdevice can be configured using +iproute2:: + + $ ip link add siit0 type ipxlat [ OPTIONS ] + + # where OPTIONS can include (TODO: iproute2 patch): + # + # prefix ADDR (default 64:ff9b::/96) + # + # lowest-ipv6-mtu MTU (default 1280) + + +Introduction to Packet-level IPv6<>IPv4 Translation +=================================================== + +Translatable packets delivered into an ipxlat device as either of the IP +protocol versions loop-back as the other. Untranslatable packets are +rejected with ICMP errors of the same IP version as appropriate or dropped +silently if required by RFC-SIIT_. + +.. _RFC-SIIT: https://datatracker.ietf.org/doc/html/rfc7915 + +Supported upper layer protocols (TCP/UDP/ICMP) have their checksums +recomputed as-needed as part of translation. Unsupported IP protocols +(IPPROTO\_*) are passed through unmodified. This will make them fail at the +receiver except in special cases. + +Differences in IP layer semantic concerns are handled using several +different strategies, here we'll only give a high-level summary in the +areas of most friction: + Fragmentation approach, Path MTU Discovery (PMTUD), IP Options and Extension + Headers. + +**Fragmentation Approach** (v4: on-path vs v6: end-to-end) is smoothed over by: + | 4->6: Fragmenting (DF=0) IPv4 packets when needed. See "lowest-ipv6-mtu". + | 6->4: Using on-path frag. down the line for v4 pkts smaller than 1260. + Details are tedious, check RFC-SIIT_. + +**PMTUD** is maintained by recalculating advised MTU values in ICMP +PKT_TOO_BIG and FRAG_NEEDED messages as they're being translated. Taking +into account the necessary header re-sizing and post-translation nexthop +MTU in the main routing table. + +**IP Options and IPv6 Extension Headers** except the Fragment Header are +dropped or ignored expept where more specific behaviour is specified in +RFC-SIIT_. + + +Address Translation +------------------- + +The ipxlat address translation algorithm is stateless, per RFC-ADDR_, all +possible IPv4 addressess are mapped one-to-one into the translation prefix, +optionally including a non-standard "suffix". See `RFC-ADDR Section 2.2 +<https://datatracker.ietf.org/doc/html/rfc6052#section-2.2>`_. + +.. _RFC-ADDR: https://datatracker.ietf.org/doc/html/rfc6052 + +IPv6 addressess outside this prefix are rejected with ICMPv6 errors with +the notable exception of ICMPv6 errors originating from untranslatable +source addressess. These are translated to be sourced from the IPv4 Dummy +Address ``192.0.0.8`` (per I-D-dummy_) instead to maintain IPv4 traceroute +visibility. + +.. _I-D-dummy: + https://datatracker.ietf.org/doc/draft-ietf-v6ops-icmpext-xlat-v6only-source/ + +In a basic bidirectional 6<>4 connectivity scenario this means IPv6 hosts +must be addressed wholly from inside the translation prefix and per +RFC-ADDR_. Plain vanilla SLAAC doesn't cut it here, static addressing or +DHCPv6 is needed, unless that is we introduce statefulnes (RFC-NAT64_) into +the mix. See below on that. + +.. _RFC-NAT64: https://datatracker.ietf.org/doc/html/rfc6146 + + +Stateful Translation (NAT64) +---------------------------- + +Using NAT64 has several drawbacks, it's necessary only when your control +over IPv4 or IPv6 addressing of hosts is limited. + +Using nftables we can turn a system into a stateful translator. For example +to make the IPv4 internet reachable to a IPv6-only LAN having this system +as it's default route, further assuming we have an IPv4 default route and +``192.0.2.1/32`` is routed to this system:: + + $ ip link add siit0 type ipxlat + $ ip link set dev siit0 up + $ ip route 192.0.2.1/32 dev siit0 + $ ip route 64:ff9b::/96 dev siit0 + $ sysctl -w net.ipv4.conf.all.forwarding=1 + $ sysctl -w net.ipv6.conf.all.forwarding=1 + $ nft -f- <<EOF + table ip6 nat { + chain postrouting { + type nat hook postrouting priority filter; policy accept; + oifname "siit0" snat to 64:ff9b::c002:1 comment "::192.0.2.1" + } + } + table ip nat { + chain postrouting { + type nat hook postrouting priority filter; policy accept; + iifname "siit0" masquerade + } + } + EOF + +Note: Keep reading when replacing the 192.0.2.0/24 documentation +placeholder with RFC 1918 "private IPv4" space. + + +Translation Prefix Choice and Complications +------------------------------------------- + +Several prefix sizes between /32 and /96 are supported by ipxlat. Using +a /96 prefix is often convenient as it allows using the dotted quad IPv6 +notation, eg.: "64:ff9b::192.0.2.1". RFC-ADDR_ "3.3. Choice of Prefix for +Stateless Translation Deployments" has more detailed recommendations. + +The "Well-Known Prefix" (WKP) 64:ff9b::/96, while a convenient and short +choice for LANs, comes with some IETF baggage. As specified (at time of +writing) addressess drawn from RFC 1918 "private IPv4" space "MUST NOT" be +used with the WKP. While ipxlat does not enforce this other network +elements may. + +If I-D-WKP-1918_ makes it through the IETF process this complication for +the cautious network engineer may dissapear in the future. + +.. _I-D-WKP-1918: + https://datatracker.ietf.org/doc/draft-ietf-v6ops-nat64-wkp-1918/ + +In the meantime the newer and more lax prefix allocated by RFC-LWKP_ or an +entirely Network-Specific Prefix may be a better fit. We'd recommend using +the checksum-neutral ``64:ff9b:1:fffe::/96`` prefix from the larger /48 +allocation. + +.. _RFC-LWKP: https://datatracker.ietf.org/doc/html/rfc8215 + + +RFC Considerations for Userspace +-------------------------------- + +- Per `RFC 7915 + <https://datatracker.ietf.org/doc/html/rfc7915#section-4.5>`_, + ipxlat SHOULD drop UDPv4 zero checksum packets, yet we chose to always + recalculate checksums for unfragmented packets. + + If you want your translator to follow the SHOULD add a netfilter rule + dropping such packets. For example using ``nft(8)`` syntax:: + + nft add rule filter ip postrouting -- oifkind ipxlat udp checksum 0 log drop + +- Per `RFC 6146 + <https://datatracker.ietf.org/doc/html/rfc6146#section-3.4>`_, + Fragmented UDPv4 zero checksum recalculation by reassembly is not + supported. + +- I-D-dummy_: Adding a Node Identity Object to for IPv4-side traceroute + disambiguation is not yet supported.
Signature · 1 line
2.53.0
Jonathan Corbet
maintainerRe: [RFC net-next 15/15] Documentation: networking: add ipxlat translator guide
Quoted 11 lines · Ralf Lici
From: Daniel Gröber <[email protected]>
Add user and reviewer documentation for the ipxlat virtual netdevice in
Documentation/networking/ipxlat.rst.The document describes the datapath model, stateless IPv4/IPv6 address translation rules, ICMP handling, control-plane configuration, and test topology assumptions. It also records the intended runtime configuration contract and current behavior limits so deployment expectations are clear.
Quoted 6 lines
Signed-off-by Daniel Gröber <[email protected]>Signed-off-by Ralf Lici <[email protected]>--- Documentation/networking/ipxlat.rst | 190 ++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 Documentation/networking/ipxlat.rst
You need to add this new file to Documentation/networking/index.rst or it won't be included in the build (and you'll get a warning).
Thanks,
jon
Re: [RFC net-next 15/15] Documentation: networking: add ipxlat translator guide
Quoted 20 lines · Jonathan Corbet
Quoted 11 lines · Ralf Lici
From: Daniel Gröber <[email protected]>
Add user and reviewer documentation for the ipxlat virtual netdevice in
Documentation/networking/ipxlat.rst.The document describes the datapath model, stateless IPv4/IPv6 address translation rules, ICMP handling, control-plane configuration, and test topology assumptions. It also records the intended runtime configuration contract and current behavior limits so deployment expectations are clear.
Quoted 6 lines
Signed-off-by Daniel Gröber <[email protected]>Signed-off-by Ralf Lici <[email protected]>--- Documentation/networking/ipxlat.rst | 190 ++++++++++++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 Documentation/networking/ipxlat.rst
Quoted 6 lines
You need to add this new file to
Documentation/networking/index.rstor it won't be included in the build (and you'll get a warning).Thanks,
jon
Hi Jon,
Thanks for the heads-up.
I’ve fixed this for the next revision. While rechecking with 'make SPHINXDIRS=networking htmldocs', I also found and fixed a couple of 'ipxlat.rst' issues reported by Sphinx.
Thanks,
Signature · 2 lines
Ralf Lici Mandelbit Srl
Re: [RFC net-next 15/15] Documentation: networking: add ipxlat translator guide
In reply to Ralf LiciHi Ralf,
Documentation/networking/ipxlat.rst line 29
Quoted 2 lines
Documentation/networking/ipxlat.rst new file +2
-0+ $ ./tools/net/ynl/pyynl/cli.py --family ipxlat --json '{"ifindex": $IID, \ + "config": {"xlat-prefix6": "'$HEX_ADDR'", "prefix-len": 96} }'
Should this be like:
$ python3 /extends/pyynl/cli.py --spec ipxlat.yaml --do dev-set --json \
'{"ifindex": "'$IID'", "config": {"xlat-prefix6": \
{"prefix":"'$ADDR_HEX'", "prefix-len": 96}}}'Quoted 5 lines
Documentation/networking/ipxlat.rst new file +5
-0+Address Translation +------------------- + +The ipxlat address translation algorithm is stateless, per RFC-ADDR_, all +possible IPv4 addressess are mapped one-to-one into the translation prefix,
Documentation/networking/ipxlat.rst line 93
Quoted 10 lines
Documentation/networking/ipxlat.rst new file +10
-0+optionally including a non-standard "suffix". See `RFC-ADDR Section 2.2 +<https://datatracker.ietf.org/doc/html/rfc6052#section-2.2>`_. + +.. _RFC-ADDR: https://datatracker.ietf.org/doc/html/rfc6052 + +IPv6 addressess outside this prefix are rejected with ICMPv6 errors with +the notable exception of ICMPv6 errors originating from untranslatable +source addressess. These are translated to be sourced from the IPv4 Dummy +Address ``192.0.0.8`` (per I-D-dummy_) instead to maintain IPv4 traceroute +visibility.
Would it help to add a few example? For instance,
- Interface ipxlat0 with prefix6=64:ff9b::/96.
- A IPv6 packet with src=64:ff9b::192.0.2.1 dst=64:ff9b::198.51.100.1, was send to ipxlat0.
- Then a IPv4 packet with src=192.0.2.1 dst=198.51.100.1 was received from ipxlat0.
Best regards,
Xavier
Re: [RFC net-next 15/15] Documentation: networking: add ipxlat translator guide
Quoted 6 lines · Xavier Hsinyuan
Documentation/networking/ipxlat.rst line 29
Quoted 2 lines
Documentation/networking/ipxlat.rst new file +2
-0+ $ ./tools/net/ynl/pyynl/cli.py --family ipxlat --json '{"ifindex": $IID, \ + "config": {"xlat-prefix6": "'$HEX_ADDR'", "prefix-len": 96} }'Should this be like:
$ python3 /extends/pyynl/cli.py --spec ipxlat.yaml --do dev-set --json \ '{"ifindex": "'$IID'", "config": {"xlat-prefix6": \ {"prefix":"'$ADDR_HEX'", "prefix-len": 96}}}'
Indeed, the JSON is just wrong and --do dev-set is missing. However --family ipxlat works for me and looking at the code is basically the same as specifying --spec.
Could you try this:
$ JSON='{"ifindex": '"$IID"', "config": {"xlat-prefix6": { "prefix": "'$ADDR_HEX'", "prefix-len": 96}}}'
$ ./tools/net/ynl/pyynl/cli.py --family ipxlat --do dev-set --json "$JSON"Quoted 14 lines
Quoted 14 lines
Documentation/networking/ipxlat.rst new file +14
-0+Address Translation +------------------- + +The ipxlat address translation algorithm is stateless, per RFC-ADDR_, all +possible IPv4 addressess are mapped one-to-one into the translation prefix, +optionally including a non-standard "suffix". See `RFC-ADDR Section 2.2 +<https://datatracker.ietf.org/doc/html/rfc6052#section-2.2>`_. + +.. _RFC-ADDR: https://datatracker.ietf.org/doc/html/rfc6052 + +IPv6 addressess outside this prefix are rejected with ICMPv6 errors with +the notable exception of ICMPv6 errors originating from untranslatable +source addressess. These are translated to be sourced from the IPv4 Dummy +Address ``192.0.0.8`` (per I-D-dummy_) instead to maintain IPv4 traceroute
Quoted 8 lines
Quoted 1 line
+visibility.
Would it help to add a few example? For instance,
- Interface ipxlat0 with prefix6=64:ff9b::/96.
- A IPv6 packet with src=64:ff9b::192.0.2.1 dst=64:ff9b::198.51.100.1, was send to ipxlat0.
- Then a IPv4 packet with src=192.0.2.1 dst=198.51.100.1 was received from ipxlat0.
I worry once we start with that we're really just re-stating what's already extensively documented in the RFCs.
How about a reference to RFC 7915 Appendix A? This has a full bidirectional end-to-end example of how translation operates:
https://datatracker.ietf.org/doc/html/rfc7915#appendix-A
Admittedly using a /96 prefix (which the appendix doesn't) would make it easier to grok whats going on. Not sure that's reason enough to get into more detailed examples here.
WDYT?
Thanks,
--Daniel
Re: [RFC net-next 15/15] Documentation: networking: add ipxlat translator guide
Hi Daniel,
Quoted 8 lines
Indeed, the JSON is just wrong and --do dev-set is missing. However
--family ipxlatworks for me and looking at the code is basically the same as specifying --spec.Could you try this:
$ JSON='{"ifindex": '"$IID"', "config": {"xlat-prefix6": { "prefix": "'$ADDR_HEX'", "prefix-len": 96}}}' $ ./tools/net/ynl/pyynl/cli.py --family ipxlat --do dev-set --json "$JSON"
This looks good to me now. --family ipxlat is fine with me if this runs from the source tree.
Quoted 10 lines
I worry once we start with that we're really just re-stating what's already extensively documented in the RFCs.
How about a reference to RFC 7915 Appendix A? This has a full bidirectional end-to-end example of how translation operates:
https://datatracker.ietf.org/doc/html/rfc7915#appendix-AAdmittedly using a /96 prefix (which the appendix doesn't) would make it easier to grok whats going on. Not sure that's reason enough to get into more detailed examples here.
A reference to RFC 7915 Appendix A sounds good to me. Still, a short /96 mapping example would help readers quickly see how the translation works before reading the full RFC, and would make the following NAT64 section easier to follow as well.
Best regards,
Xavier