net: introduce ipxlat stateless IPv4/IPv6 translation
Subsystems (6)
v2 cover net: introduce ipxlat stateless IPv4/IPv6 translation
Hi all,
apologies for the long gap since RFC v1; the attachment redesign and the related fragmentation work took longer than expected.
This RFC introduces ipxlat, an in-kernel engine for stateless IPv4/IPv6 and ICMP translation, together with a lightweight-tunnel attachment.
ipxlat implements the SIIT algorithm from RFC 7915, RFC 6052 address embedding, optional RFC 7757 Explicit Address Mapping, transport checksum and GSO metadata, and ICMP translation including quoted packets and RFC 4884 extensions. It is intended as a common building block for CLAT, stateful NAT64, 464XLAT, and SIIT border translators.
NetworkManager currently provides CLAT with BPF [1], and systemd-networkd is developing a similar implementation [2]. Those implementations cannot cover some paths which need facilities outside the BPF program, including fragmentation, fragmented ICMP, and complete checksum generation for zero-checksum UDPv4. A reusable native translator lets network managers share those mechanisms rather than each maintaining another partial implementation.
This RFC has 18 patches. The first four are networking-core prerequisites for LWT continuation and IPv6 refragmentation. Keeping the remaining 14 changes separate makes the engine, LWT attachment, selftests, and documentation substantially easier to review. NIPA’s series_format will complain that the series is too long, but the split can be adjusted for a non-RFC posting once the design has settled.
See Documentation/networking/ipxlat.rst for the full configuration and operational model.
The latest code can also be found at:
https://codeberg.org/IPv6-Monostack/ipxlat-net-next
== Architecture ==
RFC v1 exposed ipxlat as a virtual netdevice which translated packets in ndo_start_xmit and injected them back into the receive path. Review identified that this required artificial device, MTU, routing, and statistics semantics and made the packet appear to have arrived from a device after translation.
v2 instead separates a reusable engine under net/ipxlat from its (first) attachment. An IPv4 or IPv6 route carrying encap ipxlat selects the packet and supplies immutable translation configuration. The selecting route terminates in translation; after the family switch, the packet gets a fresh route in the translated family. There is no translator device or ipxlat-specific netlink family.
The engine performs validation and translation but does not decide which traffic should use it. Routing rules and filters remain responsible for deployment policy such as CLAT source selection and downstream source validation. Keeping the engine independent also leaves room for later netfilter or BPF kfunc attachments without duplicating the translator.
== Address configuration ==
Each attachment has one required RFC 6052 prefix and an optional RFC 7757 Explicit Address Mapping. Each source and destination is considered
independently: an EAM match takes precedence, while an address outside the EAM uses RFC 6052 conversion.
This represents both CLAT addressing models requested during v1 review. A single-host CLAT maps one dedicated IPv4 address to one IPv6 address. A delegated-prefix CLAT maps the downstream IPv4 prefix into a prefix delegated to the CLAT, while remote IPv4 destinations continue to use the far-side NAT64 prefix. This v2 accepts at most one EAM per attachment and does not implement RFC 7757 hairpinning.
Configuration belongs to each selecting route rather than to a shared ipxlat object. A bidirectional setup therefore repeats the configuration on its original and translated family selecting routes. Userspace must update both routes whenever a configured address or prefix changes, for example after DHCPv6-PD assigns a new prefix.
The dev associated with an ipxlat route belongs only to the original family selecting route; it is not a translator interface and does not select the translated packet's egress device. The fresh translated family route lookup does that.
== Family switch and policy traversal ==
The original family route lookup ends at the LWT callback. The callback discards route, conntrack, security, socket, and other metadata which no longer describes the translated packet.
For received traffic, the translated packet enters the translated family's PRE_ROUTING hook and receives a fresh route lookup. For locally originated traffic, it enters translated family LOCAL_OUT with no socket. The normal translated family path then owns:
- forwarding,
- TTL or Hop Limit,
- PMTU,
- XFRM,
- conntrack, and
- NAT.
This allows a stateful NAT64 PLAT to be built from stateless ipxlat plus ordinary IPv4 conntrack and masquerading. No conntrack object crosses the family switch.
Translated output is socketless. It uses the normal kernel-originated UID and global XFRM policy; socket, cgroup, and per socket XFRM identity cannot cross the family switch.
If preparation determines that a packet is valid but unsupported, the LWT invokes the route's original input or output callback and leaves the packet in its original family. This is needed, for example, so native IPv6 Neighbor Discovery still works for a local address selected by an ipxlat route. Malformed packets and failures after translation begins are dropped.
This continuation is the central semantic choice in v2. Does PRE_ROUTING for received translated traffic and LOCAL_OUT for locally generated translated traffic provide the right policy visibility for a cross-family LWT action? And does the harness discard and retain the right skb metadata across the family switch?
== Fragmentation ==
v1 fragmented oversized DF-clear IPv4 packets before translation, using a synthetic route to supply an MTU. v2 translates first and lets IPv6 output use the real translated route and PMTU.
IPv4 packets which are already fragments carry an IPv6 Fragment Header after translation. This series extends IPv6 output so it can fragment that representation again while preserving the translated identification, base offset, and More Fragments state. IPv6 conntrack reassembly preserves the indication needed for the later output path to do the same. An MTU metric on a translated family route can be used as an administrative ceiling where Packet Too Big feedback is unreliable.
If an earlier original-family component has already reassembled a datagram, ipxlat cannot recover its previous fragment boundaries or identification. Fragmented ICMP and zero-checksum UDPv4 must likewise be reassembled before translation because their translated checksums need the complete datagram.
== Testing ==
The selftests use an iproute2-configured namespace topology and cover:
- local and forwarded translation,
- native fallback,
- zero-checksum UDPv4,
- translated family conntrack and masquerading,
- route-PMTU fragmentation,
- conntrack reassembly followed by refragmentation,
- PMTU feedback, and
- ICMP errors.
Along with this series, an iproute2 ipxlat-enabled tree is provided [3].
[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
[3] https://codeberg.org/IPv6-Monostack/iproute2/src/branch/ipxlat-lwt
== Points for discussion ==
- Is the translated-family continuation described above the right contract for an LWT family switch?
- Is an LWT attachment with inline immutable route configuration the right first harness for the reusable engine?
- Is reusing an existing IPv6 Fragment Header in the output fragmentation path a suitable general mechanism for translated IPv4 fragments?
== Acknowledgements ==
The ipxlat translation engine is derived from Jool so it can benefit from the project's accumulated implementation experience and golden-packet tests. Thanks to Jool's principal author, Alberto Leiva Popper, for maintaining that work and for writing the original joolif prototype from which ipxlat started.
Thanks to Toke Høiland-Jørgensen, Beniamino Galvani, Xavier Hsinyuan, and Jonathan Corbet for their RFC v1 review and deployment input.
Thanks to NLnet's NGI0 Core Fund for supporting ipxlat development.
Thanks for your review,
Ralf Lici
Mandelbit SRL
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Replaced the virtual netdevice and generic-netlink control plane with a reusable translation engine under net/ipxlat and a route-selected LWT attachment. Deployment policy remains outside the engine. (Toke)
- Added an optional RFC 7757 EAM before RFC 6052 conversion, covering both single-host and delegated-prefix CLAT addressing. (Beniamino)
- Defined received and local traffic continuations into the translated family, including fresh routing, conntrack, NAT, and XFRM processing. Added native LWT fallback for packets the engine does not support.
- Removed the lowest-ipv6-mtu parameter and IPv4 pre-fragmentation. The translated IPv6 route now owns PMTU and fragmentation, including refragmentation which preserves an existing Fragment Header across conntrack reassembly.
- Moved TTL and Hop Limit handling to the translated family forwarding path, so translation itself does not consume a hop.
- Replaced the v1 netdevice tests and documentation with LWT coverage and deployment examples.
Ralf Lici (18):
lwtunnel: track callback dispatch separately from return value ipv4/ipv6: add LWT receive helpers
ipv6: allow output fragmentation to reuse a Fragment Header
netfilter: preserve IPv6 refragmentation state across reassembly
net: ipxlat: add engine skeleton and configuration model
net: ipxlat: add RFC 6052 and EAM address translation
net: ipxlat: add packet metadata and header helpers
net: ipxlat: add IPv4 packet validation
net: ipxlat: add IPv6 packet validation
net: ipxlat: add checksum and offload helpers
net: ipxlat: add IPv4/IPv6 header and transport translation
net: ipxlat: add translation preparation and dispatch
net: ipxlat: add translator-generated ICMP errors
net: ipxlat: add ICMP informational translation
net: ipxlat: add ICMP error and quoted-packet translation
net: ipxlat: add lightweight tunnel attachment
selftests: net: add ipxlat coverage
docs: networking: add ipxlat guide
Documentation/networking/index.rst | 1 + Documentation/networking/ipxlat.rst | 333 ++++++++++ include/linux/ipv6.h | 2 + include/net/ip.h | 1 + include/net/ipv6.h | 2 + include/net/ipv6_frag.h | 2 + include/net/ipxlat.h | 113 ++++ include/uapi/linux/ipxlat.h | 56 ++ include/uapi/linux/lwtunnel.h | 1 + net/Kconfig | 1 + net/Makefile | 1 + net/core/lwtunnel.c | 15 +- net/ipv4/ip_input.c | 10 + net/ipv6/ip6_input.c | 11 + net/ipv6/ip6_output.c | 53 +- net/ipv6/netfilter/nf_conntrack_reasm.c | 11 +- net/ipxlat/Kconfig | 27 + net/ipxlat/Makefile | 19 + net/ipxlat/address.c | 218 +++++++ net/ipxlat/address.h | 57 ++ net/ipxlat/config.c | 82 +++ net/ipxlat/core.c | 156 +++++ net/ipxlat/icmp.h | 70 ++ net/ipxlat/icmp_46.c | 588 +++++++++++++++++ net/ipxlat/icmp_64.c | 615 ++++++++++++++++++ net/ipxlat/lwt.c | 643 +++++++++++++++++++ net/ipxlat/packet.h | 243 +++++++ net/ipxlat/packet4.c | 410 ++++++++++++ net/ipxlat/packet6.c | 468 ++++++++++++++ net/ipxlat/translate_46.c | 217 +++++++ net/ipxlat/translate_46.h | 77 +++ net/ipxlat/translate_64.c | 226 +++++++ net/ipxlat/translate_64.h | 96 +++ net/ipxlat/transport.c | 179 ++++++ net/ipxlat/transport.h | 127 ++++ tools/testing/selftests/Makefile | 1 + tools/testing/selftests/net/ipxlat/Makefile | 5 + tools/testing/selftests/net/ipxlat/config | 13 + tools/testing/selftests/net/ipxlat/ipxlat.sh | 554 ++++++++++++++++ 39 files changed, 5694 insertions(+), 10 deletions(-) create mode 100644 Documentation/networking/ipxlat.rst create mode 100644 include/net/ipxlat.h create mode 100644 include/uapi/linux/ipxlat.h create mode 100644 net/ipxlat/Kconfig create mode 100644 net/ipxlat/Makefile create mode 100644 net/ipxlat/address.c create mode 100644 net/ipxlat/address.h create mode 100644 net/ipxlat/config.c create mode 100644 net/ipxlat/core.c create mode 100644 net/ipxlat/icmp.h create mode 100644 net/ipxlat/icmp_46.c create mode 100644 net/ipxlat/icmp_64.c create mode 100644 net/ipxlat/lwt.c create mode 100644 net/ipxlat/packet.h create mode 100644 net/ipxlat/packet4.c create mode 100644 net/ipxlat/packet6.c create mode 100644 net/ipxlat/translate_46.c create mode 100644 net/ipxlat/translate_46.h create mode 100644 net/ipxlat/translate_64.c create mode 100644 net/ipxlat/translate_64.h create mode 100644 net/ipxlat/transport.c create mode 100644 net/ipxlat/transport.h create mode 100644 tools/testing/selftests/net/ipxlat/Makefile create mode 100644 tools/testing/selftests/net/ipxlat/config create mode 100755 tools/testing/selftests/net/ipxlat/ipxlat.sh
Signature · 1 line
2.55.0
RFC v2 1/18 lwtunnel: track callback dispatch separately from return value
LWT used -EOPNOTSUPP both as its missing-callback sentinel and as a valid callback error. Track whether an operation was invoked separately so callbacks can return meaningful errors without triggering the no-operation skb cleanup path.
---
New patch in RFC v2.
net/core/lwtunnel.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
net/core/lwtunnel.c +9 -3
@@ -322,6 +322,7 @@ int lwtunnel_output(struct net *net, struct sock *sk, struct sk_buff *skb) {const struct lwtunnel_encap_ops *ops;struct lwtunnel_state *lwtstate; +bool called_cb = false;struct dst_entry *dst;int ret;
@@ -353,13 +354,14 @@ int lwtunnel_output(struct net *net, struct sock *sk, struct sk_buff *skb)if (likely (ops && ops->output)) {/* Encap pushes outer headers over the metadata; drop it. */ skb_metadata_clear (skb); + called_cb = true;dev_xmit_recursion_inc (); ret = ops->output (net, sk, skb);dev_xmit_recursion_dec (); }rcu_read_unlock (); -if (ret == -EOPNOTSUPP ) +if (unlikely (!called_cb)) goto drop; goto out;
@@ -377,6 +379,7 @@ int lwtunnel_xmit(struct sk_buff *skb) {const struct lwtunnel_encap_ops *ops;struct lwtunnel_state *lwtstate; +bool called_cb = false;struct dst_entry *dst;int ret;
@@ -409,13 +412,14 @@ int lwtunnel_xmit(struct sk_buff *skb)if (likely (ops && ops->xmit)) {/* Encap pushes outer headers over the metadata; drop it. */ skb_metadata_clear (skb); + called_cb = true;dev_xmit_recursion_inc (); ret = ops->xmit (skb);dev_xmit_recursion_dec (); }rcu_read_unlock (); -if (ret == -EOPNOTSUPP ) +if (unlikely (!called_cb)) goto drop; goto out;
@@ -433,6 +437,7 @@ int lwtunnel_input(struct sk_buff *skb) {const struct lwtunnel_encap_ops *ops;struct lwtunnel_state *lwtstate; +bool called_cb = false;struct dst_entry *dst;int ret;
@@ -462,13 +467,14 @@ int lwtunnel_input(struct sk_buff *skb)if (likely (ops && ops->input)) {/* Encap pushes outer headers over the metadata; drop it. */ skb_metadata_clear (skb); + called_cb = true;dev_xmit_recursion_inc (); ret = ops->input (skb);dev_xmit_recursion_dec (); }rcu_read_unlock (); -if (ret == -EOPNOTSUPP ) +if (unlikely (!called_cb)) goto drop;return ret;
Signature · 1 line
2.55.0
RFC v2 2/18 ipv4/ipv6: add LWT receive helpers
In reply to Ralf LiciCross-family LWT translation constructs a validated target-family packet and needs to enter its receive path at PRE_ROUTING. Add helpers that invoke the hook and continue with normal input routing.
The continuation remains in IP core, so it stays valid if NFQUEUE holds a packet after the selecting LWT dst has been dropped.
---
New patch in RFC v2.
include/net/ip.h | 1 + include/net/ipv6.h | 1 + net/ipv4/ip_input.c | 10 ++++++++++ net/ipv6/ip6_input.c | 11 +++++++++++ 4 files changed, 23 insertions(+)
include/net/ip.h +1 -0
@@ -170,6 +170,7 @@ int ip_build_and_send_pkt(struct sk_buff *skb, const struct sock *sk, struct ip_options_rcu *opt, u8 tos);int ip_rcv (struct sk_buff *skb,struct net_device *dev,struct packet_type *pt,struct net_device *orig_dev); +int ip_rcv_lwt (struct sk_buff *skb);void ip_list_rcv (struct list_head *head,struct packet_type *pt,struct net_device *orig_dev);int ip_local_deliver (struct sk_buff *skb);
include/net/ipv6.h +1 -0
@@ -1016,6 +1016,7 @@ static inline __be32 flowi6_get_flowlabel(const struct flowi6 *fl6)int ipv6_rcv (struct sk_buff *skb,struct net_device *dev,struct packet_type *pt,struct net_device *orig_dev); +int ip6_rcv_lwt (struct sk_buff *skb);void ipv6_list_rcv (struct list_head *head,struct packet_type *pt,struct net_device *orig_dev);
net/ipv4/ip_input.c +10 -0
@@ -493,6 +493,16 @@ static int ip_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb)return ret; } +/* enter IPv4 PRE_ROUTING with a validated LWT packet */ +int ip_rcv_lwt (struct sk_buff *skb) +{ +struct net *net =dev_net (skb->dev); + +return NF_HOOK (NFPROTO_IPV4 ,NF_INET_PRE_ROUTING , net,NULL , skb, + skb->dev,NULL , ip_rcv_finish); +} +EXPORT_SYMBOL_GPL (ip_rcv_lwt); +/* * Main IP Receive routine. */
net/ipv6/ip6_input.c +11 -0
@@ -26,6 +26,7 @@#include <linux/mroute6.h> #include <linux/slab.h> #include <linux/indirect_call_wrapper.h> +#include <linux/module.h> #include <linux/netfilter.h> #include <linux/netfilter_ipv6.h>
@@ -119,6 +120,16 @@ int ip6_rcv_finish(struct net *net, struct sock *sk, struct sk_buff *skb)return dst_input (skb); } +/* enter IPv6 PRE_ROUTING with a validated LWT packet */ +int ip6_rcv_lwt (struct sk_buff *skb) +{ +struct net *net =dev_net (skb->dev); + +return NF_HOOK (NFPROTO_IPV6 ,NF_INET_PRE_ROUTING , net,NULL , skb, + skb->dev,NULL , ip6_rcv_finish); +} +EXPORT_SYMBOL_GPL (ip6_rcv_lwt); +static void ip6_sublist_rcv_finish (struct list_head *head) {struct sk_buff *skb, *next;
Signature · 1 line
2.55.0
RFC v2 3/18 ipv6: allow output fragmentation to reuse a Fragment Header
In reply to Ralf LiciIPv4-to-IPv6 translation constructs an IPv6 Fragment Header before the target route is selected. If that route has a smaller MTU, IPv6 output must split the translated fragment again. Adding another Fragment Header would create a new fragment domain instead of subfragmenting the original datagram representation.
Allow ip6_fragment to reuse a locally constructed Fragment Header, preserving its identification, datagram-relative offset and More Fragments state. This mirrors IPv4 refragmentation, whose fragment state carries the original offset and whether more fragments follow the input fragment.
---
New patch in RFC v2 replacing ipxlat's v1 IPv4 pre-fragmentation machinery.
include/linux/ipv6.h | 2 ++ include/net/ipv6.h | 1 + net/ipv6/ip6_output.c | 53 +++++++++++++++++++++++++++++++++++++++---- 3 files changed, 51 insertions(+), 5 deletions(-)
include/linux/ipv6.h +2 -0
@@ -177,6 +177,8 @@ struct inet6_skb_parm {#define IP6SKB_L3SLAVE 64#define IP6SKB_JUMBOGRAM 128#define IP6SKB_SEG6 256 +/* the local stack owns fragmentation of this IPv6 representation */ +#define IP6SKB_FRAG_SOURCE 512#define IP6SKB_MULTIPATH 1024#define IP6SKB_MCROUTE 2048 };
include/net/ipv6.h +1 -0
@@ -189,6 +189,7 @@ struct ip6_frag_state {int hroom;int troom;__be32 frag_id; +bool not_last_frag;u8 nexthdr; };
net/ipv6/ip6_output.c +48 -5
105 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC v2 4/18 netfilter: preserve IPv6 refragmentation state across reassembly
In reply to Ralf LiciRemember when all fragments describe a locally constructed IPv6 representation. Restore that state after conntrack reassembly so IPv6 output can fragment the datagram for its actual route without treating the old fragment size as a PMTU constraint.
---
New patch in RFC v2.
include/net/ipv6_frag.h | 2 ++ net/ipv6/netfilter/nf_conntrack_reasm.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-)
include/net/ipv6_frag.h +2 -0
@@ -26,6 +26,7 @@ struct frag_queue {int iif;__u16 nhoffset;u8 ecn; +bool frag_source; };#if IS_ENABLED (CONFIG_IPV6 )
@@ -36,6 +37,7 @@ static inline void ip6frag_init(struct inet_frag_queue *q, const void *a) q->key.v6 = *key; fq->ecn =0 ; + fq->frag_source = true; }static inline u32 ip6frag_key_hashfn (const void *data,u32 len,u32 seed)
net/ipv6/netfilter/nf_conntrack_reasm.c +10 -1
@@ -272,6 +272,7 @@ static int nf_ct_frag6_queue(struct frag_queue *fq, struct sk_buff *skb, fq->q.tstamp_type = skb->tstamp_type; fq->q.meat += skb->len; fq->ecn |= ecn; + fq->frag_source &= !!(IP6CB (skb)->flags &IP6SKB_FRAG_SOURCE );if (payload_len > fq->q.max_size) fq->q.max_size = payload_len;add_frag_mem_limit (fq->q.fqdir, skb->truesize);
@@ -360,8 +361,16 @@ static int nf_ct_frag6_reasm(struct frag_queue *fq, struct sk_buff *skb, skb->dev = dev;ipv6_hdr (skb)->payload_len =htons (payload_len);ipv6_change_dsfield (ipv6_hdr (skb),0xff , ecn); -IP6CB (skb)->frag_max_size =sizeof (struct ipv6hdr ) + fq->q.max_size;IP6CB (skb)->flags |=IP6SKB_FRAGMENTED ; +if (fq->frag_source) { +/* use the output route MTU instead of the old fragment size */ +IP6CB (skb)->frag_max_size =0 ; +IP6CB (skb)->flags |=IP6SKB_FRAG_SOURCE ; + }else { +IP6CB (skb)->frag_max_size =sizeof (struct ipv6hdr ) + + fq->q.max_size; +IP6CB (skb)->flags &= ~IP6SKB_FRAG_SOURCE ; + }/* Yes, and fold redundant checksum back. 8) */ if (skb->ip_summed ==CHECKSUM_COMPLETE )
Signature · 1 line
2.55.0
RFC v2 5/18 net: ipxlat: add engine skeleton and configuration model
In reply to Ralf LiciAdd the reusable ipxlat module, immutable RFC 6052/EAM configuration structures and validation helpers. Attachment-specific configuration is intentionally left for a later patch.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Move ipxlat from drivers/net to net/ipxlat, remove the virtual
netdevice and generic-netlink control plane, and make the engine
independent of any attachment. (Toke)
- Replace mutable per-device values with validated immutable RFC 6052
and EAM configuration structures supplied by the caller.
include/net/ipxlat.h | 66 +++++++++++++++++++++++++++++++++++ net/Kconfig | 1 + net/Makefile | 1 + net/ipxlat/Kconfig | 14 ++++++++ net/ipxlat/Makefile | 8 +++++ net/ipxlat/config.c | 82 ++++++++++++++++++++++++++++++++++++++++++++ net/ipxlat/core.c | 17 +++++++++ 7 files changed, 189 insertions(+) create mode 100644 include/net/ipxlat.h create mode 100644 net/ipxlat/Kconfig create mode 100644 net/ipxlat/Makefile create mode 100644 net/ipxlat/config.c create mode 100644 net/ipxlat/core.c
include/net/ipxlat.h new file +66 -0
@@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* IPXLAT - Stateless IP/ICMP Translation (SIIT) engine +* +* 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_H_ +#define _NET_IPXLAT_H_ + +#include <linux/in6.h> +#include <linux/types.h> + +struct ipxlat_prefix4 { +__be32 addr; +u8 len; +}; + +struct ipxlat_prefix6 { +struct in6_addr addr; +u8 len; +}; + +struct ipxlat_eam { +struct ipxlat_prefix4 prefix4; +struct ipxlat_prefix6 prefix6; +}; + +/** +* struct ipxlat_config - immutable translation configuration +* @rfc6052_prefix6: RFC 6052 fallback prefix +* @has_eam: whether @eam is present +* @eam: optional RFC 7757 explicit address mapping +*/ +struct ipxlat_config { +struct ipxlat_prefix6 rfc6052_prefix6; +bool has_eam; +struct ipxlat_eam eam; +}; + +/** +* ipxlat_prefix6_len_valid - check an RFC 6052 prefix length +* @len: prefix length in bits +* +* Return: true when @len is one of the RFC 6052 prefix lengths. +*/ +bool ipxlat_prefix6_len_valid (u8 len); + +/** +* ipxlat_config_validate - validate a complete translation configuration +* @cfg: configuration to validate +* +* If present, the EAM's IPv6 prefix must provide enough host bits for its IPv4 +* prefix. +* +* Return: 0 when valid, otherwise a negative errno. +*/ +int ipxlat_config_validate (const struct ipxlat_config *cfg); + +#endif /* _NET_IPXLAT_H_ */
net/Kconfig +1 -0
@@ -135,6 +135,7 @@ config INET if INET source "net/ipv4/Kconfig" source "net/ipv6/Kconfig" +source "net/ipxlat/Kconfig" source "net/netlabel/Kconfig" source "net/mptcp/Kconfig"
net/Makefile +1 -0
@@ -20,6 +20,7 @@ obj-$(CONFIG_XFRM) += xfrm/ obj-$(CONFIG_UNIX) += unix/ obj-$(CONFIG_INET_PSP) += psp/ obj-y += ipv6/ +obj-$(CONFIG_NET_IPXLAT) += ipxlat/ obj-$(CONFIG_PACKET) += packet/ obj-$(CONFIG_NET_KEY) += key/ obj-$(CONFIG_BRIDGE) += bridge/
net/ipxlat/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# IPXLAT - Stateless IP/ICMP Translation (SIIT) +# + +config NET_IPXLAT + tristate "IPv6<>IPv4 packet translation engine (SIIT)" + depends on IPV6 + help + Reusable stateless IP/ICMP packet translation engine implementing + RFC 7915. Useful for IPv6 focused networks. Particularly NAT64, + SIIT-DC, 464XLAT network architectures. + + To compile this engine as a module, choose M here.
net/ipxlat/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# IPXLAT - Stateless IP/ICMP Translation (SIIT) engine + +obj-$(CONFIG_NET_IPXLAT) += ipxlat.o + +ipxlat-objs += config.o +ipxlat-objs += core.o
net/ipxlat/config.c new file +82 -0
82 lines not on this page · raw message
net/ipxlat/core.c new file +17 -0
@@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0 +/* IPXLAT - Stateless IP/ICMP Translation (SIIT) engine +* +* 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 <linux/module.h> + +MODULE_DESCRIPTION ("IPv6<>IPv4 stateless translation engine (SIIT)" ); +MODULE_LICENSE ("GPL" );
Signature · 1 line
2.55.0
RFC v2 6/18 net: ipxlat: add RFC 6052 and EAM address translation
In reply to Ralf LiciTranslate each endpoint through a matching RFC 7757 EAM first and use the configured RFC 6052 prefix as fallback. Permit the RFC 7915 dummy IPv4 source only for otherwise unmappable ICMPv6 errors.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Extend the v1 symmetric RFC 6052 conversion with an optional RFC 7757
EAM. Each endpoint independently uses the EAM on a match and RFC 6052 otherwise, supporting both single-address and delegated-prefix CLAT. (Beniamino)
- Validate the reserved RFC 6052 u octet during 6-to-4 extraction.
net/ipxlat/Makefile | 1 + net/ipxlat/address.c | 218 +++++++++++++++++++++++++++++++++++++++++++ net/ipxlat/address.h | 57 +++++++++++ 3 files changed, 276 insertions(+) create mode 100644 net/ipxlat/address.c create mode 100644 net/ipxlat/address.h
net/ipxlat/Makefile +1 -0
@@ -6,3 +6,4 @@ obj-$(CONFIG_NET_IPXLAT) += ipxlat.o ipxlat-objs += config.o ipxlat-objs += core.o +ipxlat-objs += address.o
net/ipxlat/address.c new file +218 -0
218 lines not on this page · raw message
net/ipxlat/address.h new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC v2 7/18 net: ipxlat: add packet metadata and header helpers
In reply to Ralf LiciDefine the skb control block used while a packet is prepared, together with offset, length, fragment and pending-error helpers shared by the two protocol families.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Reshape the v1 control block for the prepare-translate engine contract,
remove netdevice actions and continuation policy from its metadata,
and split family-specific parsing into packet4.c and packet6.c.
- Make headers which expose IPv6 packet and Fragment Header types
include the declarations they use. (Sashiko)
net/ipxlat/packet.h | 243 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 net/ipxlat/packet.h
net/ipxlat/packet.h new file +243 -0
@@ -0,0 +1,243 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* IPXLAT - Stateless IP/ICMP Translation (SIIT) engine +* +* 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_PACKET_H_ +#define _NET_IPXLAT_PACKET_H_ + +#include <net/ip.h> +#include <net/ipv6.h> + +#include <net/ipxlat.h> + +/** +* struct ipxlat_cb - per-skb parser and control metadata stored in skb->cb +* @l4_off: outer L4 header offset +* @payload_off: outer payload offset +* @fragh_off: outer IPv6 Fragment Header offset, or 0 if absent +* @inner_l3_offset: quoted inner L3 offset for ICMP errors +* @inner_l4_offset: quoted inner L4 offset for ICMP errors +* @inner_fragh_off: quoted inner IPv6 Fragment Header offset, or 0 +* @l4_proto: outer L4 protocol (or nexthdr for IPv6) +* @inner_l4_proto: quoted inner L4 protocol +* @l3_hdr_len: outer L3 header length including extension headers +* @is_icmp_err: packet is ICMP error and carries quoted inner packet +* @emit_icmp_err: datapath must emit translator-generated ICMP on drop +* @saddr4: translated outer IPv4 source address for 6->4 +* @daddr4: translated outer IPv4 destination address for 6->4 +* @inner_saddr4: translated quoted IPv4 source address for ICMP 6->4 +* @inner_daddr4: translated quoted IPv4 destination address for ICMP 6->4 +* @pending_icmp_err: ICMP type/code/info cached for deferred emission +* @pending_icmp_err.type: ICMP type to emit +* @pending_icmp_err.code: ICMP code to emit +* @pending_icmp_err.info: ICMP auxiliary info (e.g. pointer/MTU) +*/ +struct ipxlat_cb { +u16 l4_off; +u16 payload_off; +u16 fragh_off; +u16 inner_l3_offset; +u16 inner_l4_offset; +u16 inner_fragh_off; +u16 l3_hdr_len; +u8 l4_proto; +u8 inner_l4_proto; +bool is_icmp_err; +bool emit_icmp_err; +__be32 saddr4; +__be32 daddr4; +__be32 inner_saddr4; +__be32 inner_daddr4; +struct { +u8 type; +u8 code; +u32 info; + } pending_icmp_err; +}; + +static inline struct ipxlat_cb *ipxlat_skb_cb (const struct sk_buff *skb) +{ +BUILD_BUG_ON (sizeof (struct ipxlat_cb ) >sizeof (skb->cb)); +return (struct ipxlat_cb *)(skb->cb); +} + +static inline unsigned int ipxlat_skb_l4_len (const struct sk_buff *skb) +{ +return skb->len -skb_transport_offset (skb); +} + +/* return the L4 length of one eventual segment rather than the GSO aggregate */ +static inline unsigned int ipxlat_skb_l4_seg_len (const struct sk_buff *skb, +const struct ipxlat_cb *cb) +{ +const struct skb_shared_info *shinfo; + +if (skb_is_gso (skb)) { + shinfo =skb_shinfo (skb); +/* legacy UFO's gso_size already includes the UDP header */ +if (shinfo->gso_type &SKB_GSO_UDP ) +return shinfo->gso_size; + +/* TCP and UDP-L4 GSO sizes describe payload bytes only */ +return cb->payload_off - cb->l4_off + shinfo->gso_size; + } +return skb->len - cb->l4_off; +} + +static inline u8 ipxlat_get_ipv6_tclass (const struct ipv6hdr *hdr) +{ +return (hdr->priority <<4 ) | (hdr->flow_lbl[0 ] >>4 ); +} + +static inline u16 ipxlat_get_frag6_offset (const struct frag_hdr *hdr) +{ +return be16_to_cpu (hdr->frag_off) &IP6_OFFSET ; +} + +static inline u16 ipxlat_get_frag4_offset (const struct iphdr *hdr) +{ +return (be16_to_cpu (hdr->frag_off) &IP_OFFSET ) <<3 ; +} + +static inline bool ipxlat_is_first_frag6 (const struct frag_hdr *hdr) +{ +return !hdr ||ipxlat_get_frag6_offset (hdr) ==0 ; +} + +static inline bool ipxlat_is_first_frag4 (const struct iphdr *hdr) +{ +return !(hdr->frag_off &htons (IP_OFFSET )); +} + +/** +* ipxlat_replace_l3 - replace an outer or quoted L3 header in place +* @skb: packet containing the L3 header +* @old_l3_end: current offset immediately after the L3 header +* @new_l3_end: desired offset immediately after the L3 header +* @transport_off: transport header offset after replacement +* +* The caller must provide valid offsets and enough headroom. Bytes following +* @old_l3_end remain unchanged, and the network header is reset to @skb->data. +*/ +static inline void ipxlat_replace_l3 (struct sk_buff *skb, +unsigned int old_l3_end, +unsigned int new_l3_end, +unsigned int transport_off) +{ +skb_pull (skb, old_l3_end); +skb_push (skb, new_l3_end); +skb_reset_network_header (skb); +skb_set_transport_header (skb, transport_off); +} + +/** +* ipxlat_cb_rebase_offsets - shift cached cb offsets after skb relayout +* @cb: parsed packet metadata +* @delta: signed byte delta applied to cached offsets +* +* All cached absolute offsets include the old outer L3 length. Apply the same +* delta to keep them pointing at the same logical fields after replacement. +*/ +static inline void ipxlat_cb_rebase_offsets (struct ipxlat_cb *cb,int delta) +{ + cb->l4_off += delta; + cb->payload_off += delta; + +if (unlikely (cb->is_icmp_err)) { + cb->inner_l3_offset += delta; + cb->inner_l4_offset += delta; + +if (cb->inner_fragh_off) + cb->inner_fragh_off += delta; + } +} + +#ifdef CONFIG_DEBUG_NET +/** +* ipxlat_cb_offsets_valid - validate monotonicity and bounds of cb offsets +* @cb: parsed packet metadata +* +* Checks that L4 precedes payload, quoted L3 follows the outer payload and a +* quoted Fragment Header lies inside the quoted L3 area before quoted L4. +* +* Return: true if cached offsets are internally consistent. +*/ +static inline bool ipxlat_cb_offsets_valid (const struct ipxlat_cb *cb) +{ +if (unlikely (cb->payload_off < cb->l4_off)) +return false; + +if (cb->is_icmp_err) { +if (unlikely (cb->inner_l3_offset < cb->payload_off)) +return false; +if (unlikely (cb->inner_l4_offset < cb->inner_l3_offset)) +return false; +if (unlikely (cb->inner_fragh_off && + cb->inner_fragh_off < cb->inner_l3_offset)) +return false; +if (unlikely (cb->inner_fragh_off && + cb->inner_fragh_off >= cb->inner_l4_offset)) +return false; + } + +return true; +} +#else +static inline bool ipxlat_cb_offsets_valid (const struct ipxlat_cb *cb) +{ +return true; +} +#endif + +/** +* ipxlat_mark_icmp_drop - record an ICMP error for a dropped packet +* @skb: packet carrying the translator metadata +* @type: ICMP or ICMPv6 type +* @code: ICMP or ICMPv6 code +* @info: ICMP or ICMPv6 auxiliary information +*/ +static inline void ipxlat_mark_icmp_drop (struct sk_buff *skb,u8 type,u8 code, +u32 info) +{ +struct ipxlat_cb *cb =ipxlat_skb_cb (skb); + + cb->emit_icmp_err = true; + cb->pending_icmp_err.type = type; + cb->pending_icmp_err.code = code; + cb->pending_icmp_err.info = info; +} + +/** +* ipxlat_v4_validate_skb - validate and summarize IPv4 packet into skb->cb +* @skb: packet to validate +* +* Ensures required headers are present and consistent, populates +* &struct ipxlat_cb for subsequent 4->6 translation, and may mark a +* translator-generated ICMP action on failure paths. +* +* Return: 0 on success, negative errno on validation failure. +*/ +int ipxlat_v4_validate_skb (struct sk_buff *skb); + +/** +* ipxlat_v6_validate_skb - validate and summarize IPv6 packet into skb->cb +* @skb: packet to validate +* +* Ensures required headers are present and consistent, populates +* &struct ipxlat_cb for subsequent 6->4 translation, and may mark a +* translator-generated ICMP action on failure paths. +* +* Return: 0 on success, negative errno on validation failure. +*/ +int ipxlat_v6_validate_skb (struct sk_buff *skb); + +#endif /* _NET_IPXLAT_PACKET_H_ */
Signature · 1 line
2.55.0
RFC v2 8/18 net: ipxlat: add IPv4 packet validation
In reply to Ralf LiciValidate IPv4 headers, options, transport headers, checksums and bounded ICMP quotes while caching the offsets needed by later translation stages.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Split IPv4 parsing out of the v1 combined packet.c implementation.
- Separate unsupported packet shapes from malformed packets so an
attachment can fall back before translation starts.
- Bound quoted-packet parsing to the quoted datagram.
- Pull the complete declared outer TCP header before later stages use it.
- Treat a CHECKSUM_PARTIAL UDP packet as checksum-present even when the
checksum field still contains zero. (Sashiko)
- Validate ICMP checksums represented by CHECKSUM_COMPLETE rather than
trusting all hardware checksum metadata. (Sashiko)
net/ipxlat/Makefile | 1 + net/ipxlat/packet4.c | 410 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 411 insertions(+) create mode 100644 net/ipxlat/packet4.c
net/ipxlat/Makefile +1 -0
@@ -7,3 +7,4 @@ obj-$(CONFIG_NET_IPXLAT) += ipxlat.o ipxlat-objs += config.o ipxlat-objs += core.o ipxlat-objs += address.o +ipxlat-objs += packet4.o
net/ipxlat/packet4.c new file +410 -0
410 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC v2 9/18 net: ipxlat: add IPv6 packet validation
In reply to Ralf LiciValidate IPv6 base and extension headers, transport headers, checksums and bounded ICMPv6 quotes while recording the headers that survive translation.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Split IPv6 parsing out of the v1 combined packet.c implementation.
- Replace the IPv6 header walk with one explicitly bounded by the packet
or quoted-datagram length.
- Include the IPv6 checksum declarations used by the ICMPv6 validator.
(Xavier)
- Validate the TCP data offset and pull the complete declared header
before later translation stages use it. (Sashiko)
- Accept a zero IPv6 payload length for the kernel's oversized GSO representation instead of rejecting it unconditionally. (Sashiko)
- Validate ICMPv6 checksums represented by CHECKSUM_COMPLETE. (Sashiko)
- Stop IPv6 header walking at an Authentication Header instead of
silently removing it from the translated packet.
- Reject a zero UDPv6 checksum unless CHECKSUM_PARTIAL indicates that
checksum completion is still pending.
net/ipxlat/Makefile | 1 + net/ipxlat/packet6.c | 468 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 469 insertions(+) create mode 100644 net/ipxlat/packet6.c
net/ipxlat/Makefile +1 -0
@@ -8,3 +8,4 @@ ipxlat-objs += config.o ipxlat-objs += core.o ipxlat-objs += address.o ipxlat-objs += packet4.o +ipxlat-objs += packet6.o
net/ipxlat/packet6.c new file +468 -0
468 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC v2 10/18 net: ipxlat: add checksum and offload helpers
In reply to Ralf LiciAdd incremental pseudo-header checksum replacement, CHECKSUM_PARTIAL setup, complete IPv6 checksums, RFC 4884 payload relayout and cross-family GSO metadata normalization.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Rework the v1 checksum helpers around the attachment-independent
engine.
- Distinguish GSO aggregate length from eventual segment length,
including legacy UFO's header-inclusive gso_size convention.
- Introduce helpers only in the patch containing their first caller,
keeping each intermediate build free of unused-static-function
warnings. (Sashiko)
net/ipxlat/Makefile | 1 + net/ipxlat/transport.c | 179 +++++++++++++++++++++++++++++++++++++++++ net/ipxlat/transport.h | 127 +++++++++++++++++++++++++++++ 3 files changed, 307 insertions(+) create mode 100644 net/ipxlat/transport.c create mode 100644 net/ipxlat/transport.h
net/ipxlat/Makefile +1 -0
@@ -9,3 +9,4 @@ ipxlat-objs += core.o ipxlat-objs += address.o ipxlat-objs += packet4.o ipxlat-objs += packet6.o +ipxlat-objs += transport.o
net/ipxlat/transport.c new file +179 -0
179 lines not on this page · raw message
net/ipxlat/transport.h new file +127 -0
127 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC v2 11/18 net: ipxlat: add IPv4/IPv6 header and transport translation
In reply to Ralf LiciRewrite IPv4 and IPv6 headers in place, map Fragment Headers and update TCP and UDP checksums for ordinary, partial-checksum and GSO packets.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Drive the L3 and TCP/UDP rewrite paths only from prepared metadata and configuration, without routing or device policy.
- Base 6-to-4 GSO DF selection on each eventual IPv4 segment and leave
DF clear for legacy UFO.
- Make the 6-to-4 skb writable before moving or changing headers.
(Sashiko)
- Reacquire header pointers after operations which can move packet
storage.
- Use the kernel's zero length-field convention for oversized GSO
packets instead of truncating translated lengths, and reject
unrepresentable non-GSO packets. (Sashiko)
- Preserve CSUM_MANGLED_0 when an outer 4-to-6 UDP checksum update
produces zero. (Sashiko)
net/ipxlat/Makefile | 2 + net/ipxlat/translate_46.c | 213 ++++++++++++++++++++++++++++++++++++ net/ipxlat/translate_46.h | 77 +++++++++++++ net/ipxlat/translate_64.c | 222 ++++++++++++++++++++++++++++++++++++++ net/ipxlat/translate_64.h | 96 +++++++++++++++++ 5 files changed, 610 insertions(+) create mode 100644 net/ipxlat/translate_46.c create mode 100644 net/ipxlat/translate_46.h create mode 100644 net/ipxlat/translate_64.c create mode 100644 net/ipxlat/translate_64.h
net/ipxlat/Makefile +2 -0
@@ -10,3 +10,5 @@ ipxlat-objs += address.o ipxlat-objs += packet4.o ipxlat-objs += packet6.o ipxlat-objs += transport.o +ipxlat-objs += translate_46.o +ipxlat-objs += translate_64.o
net/ipxlat/translate_46.c new file +213 -0
213 lines not on this page · raw message
net/ipxlat/translate_46.h new file +77 -0
77 lines not on this page · raw message
net/ipxlat/translate_64.c new file +222 -0
222 lines not on this page · raw message
net/ipxlat/translate_64.h new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [RFC net-next v2 11/18] net: ipxlat: add IPv4/IPv6 header and transport translation
Hi Ralf,
Quoted 33 lines
net/ipxlat/translate_46.c new file +33
-0+static int ipxlat_46_translate_tcp_csum (struct sk_buff *skb, +const struct iphdr *in4) +{ +const struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +const struct ipv6hdr *out6 =ipv6_hdr (skb); +struct tcphdr *tcp =tcp_hdr (skb); + +/* CHECKSUM_PARTIAL contains a pseudo-header seed rather than a final +* checksum. Replace it with the translated IPv6 pseudo-header and +* leave completion to the later output path. +*/ +if (skb->ip_summed ==CHECKSUM_PARTIAL ) { + tcp->check = ~tcp_v6_check (ipxlat_skb_l4_seg_len (skb, cb), + &out6->saddr, &out6->daddr,0 ); +return ipxlat_set_partial_csum (skb, + offsetof(struct tcphdr , check)); + } + + tcp->check =ipxlat_46_update_l4_csum (tcp->check, in4, out6); + skb->ip_summed =CHECKSUM_NONE ; +return 0 ; +} + +static int ipxlat_46_translate_udp_csum (struct sk_buff *skb, +const struct iphdr *in4) +{ +const struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +const struct ipv6hdr *out6 =ipv6_hdr (skb); +struct udphdr *udp =udp_hdr (skb); + +if (skb->ip_summed ==CHECKSUM_PARTIAL ) { + udp->check = ~udp_v6_check (ipxlat_skb_l4_seg_len (skb, cb), + &out6->saddr, &out6->daddr,0 );
net/ipxlat/translate_46.c line 130
Quoted 10 lines
net/ipxlat/translate_46.c new file +10
-0+return ipxlat_set_partial_csum (skb, + offsetof(struct udphdr , check)); + } + + udp->check =ipxlat_46_update_l4_csum (udp->check, in4, out6); +if (unlikely (!udp->check)) + udp->check =CSUM_MANGLED_0 ; + skb->ip_summed =CHECKSUM_NONE ; +return 0 ; +}
Pseudo-header seed in CHECKSUM_PARTIAL uses per-segment length instead of the aggregate length, resulting in bad checksums for almost every segments.
How about updating {tcp,udp}->check with a pseudo-header diff like inet_proto_csum_replace_by_diff() to preserve the existing seed?
Best regards,
Xavier
Re: [RFC net-next v2 11/18] net: ipxlat: add IPv4/IPv6 header and transport translation
Quoted 41 lines · Xavier HSINYUAN
Hi Ralf,
Quoted 39 lines
net/ipxlat/translate_46.c new file +39
-0+static int ipxlat_46_translate_tcp_csum (struct sk_buff *skb, +const struct iphdr *in4) +{ +const struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +const struct ipv6hdr *out6 =ipv6_hdr (skb); +struct tcphdr *tcp =tcp_hdr (skb); + +/* CHECKSUM_PARTIAL contains a pseudo-header seed rather than a final +* checksum. Replace it with the translated IPv6 pseudo-header and +* leave completion to the later output path. +*/ +if (skb->ip_summed ==CHECKSUM_PARTIAL ) { + tcp->check = ~tcp_v6_check (ipxlat_skb_l4_seg_len (skb, cb), + &out6->saddr, &out6->daddr,0 ); +return ipxlat_set_partial_csum (skb, + offsetof(struct tcphdr , check)); + } + + tcp->check =ipxlat_46_update_l4_csum (tcp->check, in4, out6); + skb->ip_summed =CHECKSUM_NONE ; +return 0 ; +} + +static int ipxlat_46_translate_udp_csum (struct sk_buff *skb, +const struct iphdr *in4) +{ +const struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +const struct ipv6hdr *out6 =ipv6_hdr (skb); +struct udphdr *udp =udp_hdr (skb); + +if (skb->ip_summed ==CHECKSUM_PARTIAL ) { + udp->check = ~udp_v6_check (ipxlat_skb_l4_seg_len (skb, cb), + &out6->saddr, &out6->daddr,0 ); +return ipxlat_set_partial_csum (skb, + offsetof(struct udphdr , check)); + } + + udp->check =ipxlat_46_update_l4_csum (udp->check, in4, out6); +if (unlikely (!udp->check))
Quoted 9 lines
net/ipxlat/translate_46.c line 130
Quoted 4 lines
net/ipxlat/translate_46.c new file +4
-0+ udp->check =CSUM_MANGLED_0 ; + skb->ip_summed =CHECKSUM_NONE ; +return 0 ; +}Pseudo-header seed in
CHECKSUM_PARTIALuses per-segment length instead of the aggregate length, resulting in bad checksums for almost every segments.
You're right, just reproduced this locally. I confused the eventual segment length with the length represented by the CHECKSUM_PARTIAL seed on a GSO skb (the 6->4 path has the same bug). The current tests didn't catch the bug because veth passes CHECKSUM_PARTIAL packets through, so nothing ever computes or verifies the checksum.
Quoted 3 lines
How about updating {tcp,udp}->check with a pseudo-header diff like
inet_proto_csum_replace_by_diff()to preserve the existing seed?
Yes, the next revision will preserve the existing seed in both directions by applying only the address delta, as the non-PARTIAL path already does.
Thanks for catching this!
Signature · 2 lines
Ralf Lici Mandelbit Srl
RFC v2 12/18 net: ipxlat: add translation preparation and dispatch
In reply to Ralf LiciExpose a two-stage engine interface which validates and caches packet metadata before rewriting. Mark translated DF-clear IPv4 packets so IPv6 output owns any required fragmentation or refragmentation.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Replace the v1 ndo_start_xmit dispatch/actions with the exported ipxlat_prepare and ipxlat_translate engine interface so attachments
other than the initial LWT harness can reuse the translator. (Toke)
- Complete eligibility checks and protocol preflight before mutation so unsupported packets can be returned untouched. Allocation failures
during the rewrite still leave the packet for the caller to discard.
- Stop decrementing TTL or Hop Limit inside the engine: the
translated-family forwarding path owns the one forwarding decrement.
(Sashiko)
- Remove pre-fragmentation and mark translated DF-clear IPv4
representations for fragmentation by the target IPv6 output route.
include/net/ipxlat.h | 35 +++++++++++++++++ net/ipxlat/core.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+)
include/net/ipxlat.h +35 -0
@@ -16,6 +16,7 @@#include <linux/in6.h> #include <linux/types.h> +#include <net/ip.h> struct ipxlat_prefix4 {__be32 addr;
@@ -63,4 +64,38 @@ bool ipxlat_prefix6_len_valid(u8 len);*/ int ipxlat_config_validate (const struct ipxlat_config *cfg); +/** +* ipxlat_prepare - validate a packet and cache translation metadata +* @cfg: validated, immutable translation configuration +* @skb: packet to prepare +* +* The caller must own @skb exclusively. This function uses @skb->cb as parser +* storage but does not rewrite packet bytes. On success it sets the transport +* header offset. %-EOPNOTSUPP means ipxlat does not handle the packet. A caller +* that passes such a packet back to the original stack must restore the old +* control buffer. +* +* Return: 0 when @skb is ready for ipxlat_translate, or a negative errno. +*/ +int ipxlat_prepare (const struct ipxlat_config *cfg,struct sk_buff *skb); + +/** +* ipxlat_translate - translate one prepared skb without consuming it +* @cfg: configuration used by the preceding ipxlat_prepare call +* @net: namespace in which translation runs and whose IPv4 ID state is used +* @skb: prepared packet to translate +* +* The caller must provide a non-NULL @net and must not change @cfg, @skb or +* its cached metadata between preparation and translation. Successful +* Translation of a DF-clear IPv4 packet sets @skb->ignore_df and marks the +* resulting IPv6 packet as locally owned for target-family fragmentation. A +* harness which scrubs the skb must preserve both properties. +* +* Return: 0 with @skb in the translated representation, or a negative errno +* with the packet representation unspecified, in which case the caller must +* discard it. +*/ +int ipxlat_translate (const struct ipxlat_config *cfg,struct net *net, +struct sk_buff *skb); +#endif /* _NET_IPXLAT_H_ */
net/ipxlat/core.c +92 -0
98 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC v2 13/18 net: ipxlat: add translator-generated ICMP errors
In reply to Ralf LiciLet validation record an ICMP error without emitting it immediately, and provide an input-side helper which sends the pending error while the original packet headers and ingress device are still available.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Replace the netdevice drop/action path with pending-error metadata
recorded during preparation.
- Add an input-side emission helper which runs while the original
headers and real ingress device are still available.
- Leave local-output failures to the originating stack instead of
inventing an ingress device solely to generate an ICMP error.
include/net/ipxlat.h | 12 ++++++++++++ net/ipxlat/core.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+)
include/net/ipxlat.h +12 -0
@@ -98,4 +98,16 @@ int ipxlat_prepare(const struct ipxlat_config *cfg, struct sk_buff *skb);int ipxlat_translate (const struct ipxlat_config *cfg,struct net *net,struct sk_buff *skb); +/** +* ipxlat_emit_icmp_error - emit a pending error for a received packet +* @dev: real ingress device, required for IPv4 ICMP routing +* @skb: original-family input packet; IPv6 emission also uses @skb->dev +* +* Callers must retain the original headers and must not use it for locally +* originated errors. A forwarded packet may reach an output LWT callback, but +* it still has an ingress device and a remote sender which needs the error. +* It does nothing when the engine did not record an ICMP error. +*/ +void ipxlat_emit_icmp_error (struct net_device *dev,struct sk_buff *skb); +#endif /* _NET_IPXLAT_H_ */
net/ipxlat/core.c +40 -0
@@ -11,8 +11,12 @@* Ralf Lici <[email protected]> */ +#include <linux/icmp.h> +#include <linux/icmpv6.h> #include <linux/module.h> +#include <net/icmp.h> #include <net/ip.h> +#include <net/route.h> #include <net/ipv6.h> #include <net/ipxlat.h>
@@ -105,5 +109,41 @@ int ipxlat_translate(const struct ipxlat_config *cfg, struct net *net, }EXPORT_SYMBOL_GPL (ipxlat_translate); +void ipxlat_emit_icmp_error (struct net_device *dev,struct sk_buff *skb) +{ +const struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +const struct iphdr *iph =ip_hdr (skb); +struct inet6_skb_parm param6 = {}; +struct inet_skb_parm param4 = {}; + +if (!cb->emit_icmp_err) +return ; + +switch (ntohs (skb->protocol)) { +case ETH_P_IP : +/* __icmp_send requires an input route on the offending packet. +* Rebuild it if the original route was dropped. +*/ +if (!skb_dst (skb)) { +if (ip_route_input_noref (skb, iph->daddr, iph->saddr, +ip4h_dscp (iph), dev)) +return ; + } +__icmp_send (skb, cb->pending_icmp_err.type, + cb->pending_icmp_err.code, +htonl (cb->pending_icmp_err.info), ¶m4); +break ; +case ETH_P_IPV6 : +icmp6_send (skb, cb->pending_icmp_err.type, + cb->pending_icmp_err.code, + cb->pending_icmp_err.info,NULL , ¶m6); +break ; +default : +DEBUG_NET_WARN_ON_ONCE (1 ); +break ; + } +} +EXPORT_SYMBOL_GPL (ipxlat_emit_icmp_error); +MODULE_DESCRIPTION ("IPv6<>IPv4 stateless translation engine (SIIT)" );MODULE_LICENSE ("GPL" );
Signature · 1 line
2.55.0
RFC v2 14/18 net: ipxlat: add ICMP informational translation
In reply to Ralf LiciTranslate ICMP echo requests and replies in both directions, including incremental conversion of complete checksums and reseeding of partial checksums. Decline ICMP errors until quoted-packet translation is available.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Remove the ICMPv6 pseudo-header seed before producing a
CHECKSUM_PARTIAL informational ICMPv4 packet. (Sashiko)
net/ipxlat/Makefile | 2 + net/ipxlat/core.c | 15 +++-- net/ipxlat/icmp.h | 70 +++++++++++++++++++++++ net/ipxlat/icmp_46.c | 106 +++++++++++++++++++++++++++++++++++ net/ipxlat/icmp_64.c | 114 ++++++++++++++++++++++++++++++++++++++ net/ipxlat/translate_46.c | 4 ++ net/ipxlat/translate_64.c | 4 ++ 7 files changed, 311 insertions(+), 4 deletions(-) create mode 100644 net/ipxlat/icmp.h create mode 100644 net/ipxlat/icmp_46.c create mode 100644 net/ipxlat/icmp_64.c
net/ipxlat/Makefile +2 -0
@@ -12,3 +12,5 @@ ipxlat-objs += packet6.o ipxlat-objs += transport.o ipxlat-objs += translate_46.o ipxlat-objs += translate_64.o +ipxlat-objs += icmp_46.o +ipxlat-objs += icmp_64.o
net/ipxlat/core.c +11 -4
@@ -22,6 +22,7 @@#include <net/ipxlat.h> #include "address.h" #include "packet.h" +#include "icmp.h" #include "translate_46.h" #include "translate_64.h"
@@ -49,16 +50,22 @@ int ipxlat_prepare(const struct ipxlat_config *cfg, struct sk_buff *skb)if (unlikely (ret))return -EOPNOTSUPP ; -if (unlikely (cb->l4_proto ==NEXTHDR_ICMP )) -return -EOPNOTSUPP ; +if (unlikely (cb->l4_proto ==NEXTHDR_ICMP )) { + ret =ipxlat_64_icmp_preflight (cfg, skb); +if (ret) +return ret; + }break ;case ETH_P_IP : ret =ipxlat_v4_validate_skb (skb);if (unlikely (ret))return ret; -if (unlikely (cb->l4_proto ==IPPROTO_ICMP )) -return -EOPNOTSUPP ; +if (unlikely (cb->l4_proto ==IPPROTO_ICMP )) { + ret =ipxlat_46_icmp_preflight (skb); +if (ret) +return ret; + }break ;default :return -EOPNOTSUPP ;
net/ipxlat/icmp.h new file +70 -0
70 lines not on this page · raw message
net/ipxlat/icmp_46.c new file +106 -0
106 lines not on this page · raw message
net/ipxlat/icmp_64.c new file +114 -0
114 lines not on this page · raw message
net/ipxlat/translate_46.c +4 -0
@@ -18,6 +18,7 @@#include <net/ipxlat.h> #include "address.h" +#include "icmp.h" #include "packet.h" #include "transport.h" #include "translate_46.h"
@@ -199,6 +200,9 @@ int ipxlat_46_translate(const struct ipxlat_config *cfg, struct sk_buff *skb)case IPPROTO_UDP : err =ipxlat_46_translate_udp_csum (skb, &outer4);break ; +case IPPROTO_ICMP : + err =ipxlat_46_icmp (cfg, skb); +break ;default : err =0 ;break ;
net/ipxlat/translate_64.c +4 -0
@@ -17,6 +17,7 @@#include <net/udp.h> #include "translate_64.h" +#include "icmp.h" #include "packet.h" #include "transport.h"
@@ -207,6 +208,9 @@ int ipxlat_64_translate(const struct ipxlat_config *cfg, struct net *net,case IPPROTO_UDP : err =ipxlat_64_translate_udp_csum (skb, &outer6);break ; +case IPPROTO_ICMP : + err =ipxlat_64_icmp (net, skb, &outer6); +break ;default : err =0 ;break ;
Signature · 1 line
2.55.0
RFC v2 15/18 net: ipxlat: add ICMP error and quoted-packet translation
In reply to Ralf LiciMap ICMP error types, codes, pointers and MTUs; translate quoted inner headers and checksums; and rebuild RFC 4884 quote, padding and extension layouts in both directions.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Accept the minimum eight-byte ICMP quote without requiring a complete
quoted TCP header, and update quoted TCP and UDP checksums only when
enough bytes are present. (Sashiko)
- Preserve CSUM_MANGLED_0 if an incremental quoted-inner UDP checksum
update produces zero. (Sashiko)
- Do not retain quoted-header pointers across operations which can
reallocate packet storage.
net/ipxlat/icmp_46.c | 490 ++++++++++++++++++++++++++++++++++++++++- net/ipxlat/icmp_64.c | 513 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 993 insertions(+), 10 deletions(-)
net/ipxlat/icmp_46.c +486 -4
@@ -13,10 +13,50 @@#include <net/ip6_checksum.h> +#include "address.h" #include "icmp.h" #include "packet.h" +#include "translate_46.h" #include "transport.h" +#define IPXLAT_ICMP4_PP_CODE_PTR 0 +#define IPXLAT_ICMP4_PP_CODE_BADLEN 2 + +/* RFC 7915 Section 4.2, Figure 3 */ +static const u8 ipxlat_46_icmp_param_prob_map[] = { +0 ,1 ,4 ,4 ,0xff ,0xff ,0xff ,0xff ,7 ,6 , +0xff ,0xff ,8 ,8 ,8 ,8 ,24 ,24 ,24 ,24 , +}; + +/* RFC 1191 plateau table used when ICMPv4 FRAG_NEEDED reports MTU=0 */ +static const u16 ipxlat_46_mtu_plateaus[] = { +65535 ,32000 ,17914 ,8166 ,4352 ,2002 ,1492 , +}; + +static u8 ipxlat_icmp4_get_param_ptr (const struct icmphdr *ic4) +{ +return ntohl (ic4->un.gateway) >>24 ; +} + +static int ipxlat_46_icmp_map_param_prob (const struct icmphdr *in, +struct icmp6hdr *out) +{ +u8 ptr; + +if (unlikely (in->code !=IPXLAT_ICMP4_PP_CODE_PTR && + in->code !=IPXLAT_ICMP4_PP_CODE_BADLEN )) +return -EPROTONOSUPPORT ; + + ptr =ipxlat_icmp4_get_param_ptr (in); +if (unlikely (ptr >=ARRAY_SIZE (ipxlat_46_icmp_param_prob_map) || + ipxlat_46_icmp_param_prob_map[ptr] ==0xff )) +return -EPROTONOSUPPORT ; + + out->icmp6_code =ICMPV6_HDR_FIELD ; + out->icmp6_pointer =cpu_to_be32 (ipxlat_46_icmp_param_prob_map[ptr]); +return 0 ; +} +static int ipxlat_46_icmp_map_info_type_code (const struct icmphdr *in,struct icmp6hdr *out) {
@@ -38,18 +78,153 @@ static int ipxlat_46_icmp_map_info_type_code(const struct icmphdr *in,return -EPROTONOSUPPORT ; } +static __be32 ipxlat_46_compute_icmp_mtu6 (unsigned int pkt_mtu, +u16 tot_len_field) +{ +unsigned int i; +u32 mtu6; + +/* RFC 7915 Section 4.2: +* If the IPv4 router set the MTU field to zero, then the translator +* MUST use the plateau values specified in RFC 1191 to determine a +* likely path MTU and include that path MTU in the ICMPv6 packet. +*/ +if (unlikely (pkt_mtu ==0 )) { +for (i =0 ; i <ARRAY_SIZE (ipxlat_46_mtu_plateaus); i++) { +if (ipxlat_46_mtu_plateaus[i] < tot_len_field) { + pkt_mtu = ipxlat_46_mtu_plateaus[i]; +break ; + } + } + } + +/* The engine has no authoritative next-hop routes for the quoted flow. +* Preserve the reported path information, adjust for the larger IPv6 +* header and enforce the IPv6 minimum MTU. The output path handles its +* own route PMTU after translation. +*/ + mtu6 = pkt_mtu +sizeof (struct ipv6hdr ) -sizeof (struct iphdr ); +if (mtu6 <IPV6_MIN_MTU ) + mtu6 =IPV6_MIN_MTU ; + +return cpu_to_be32 (mtu6); +} + +static int ipxlat_46_build_icmp_dest_unreach (const struct icmphdr *in, +struct icmp6hdr *out, +const struct iphdr *inner4, +bool *ie_forbidden) +{ +unsigned int inner4_tot_len, in_frag_mtu; + + *ie_forbidden = false; +switch (in->code) { +case ICMP_NET_UNREACH : +case ICMP_HOST_UNREACH : +case ICMP_SR_FAILED : +case ICMP_NET_UNKNOWN : +case ICMP_HOST_UNKNOWN : +case ICMP_HOST_ISOLATED : +case ICMP_NET_UNR_TOS : +case ICMP_HOST_UNR_TOS : + out->icmp6_type =ICMPV6_DEST_UNREACH ; + out->icmp6_code =ICMPV6_NOROUTE ; + out->icmp6_unused =0 ; +return 0 ; +case ICMP_PORT_UNREACH : + out->icmp6_type =ICMPV6_DEST_UNREACH ; + out->icmp6_code =ICMPV6_PORT_UNREACH ; + out->icmp6_unused =0 ; +return 0 ; +case ICMP_NET_ANO : +case ICMP_HOST_ANO : +case ICMP_PKT_FILTERED : +case ICMP_PREC_CUTOFF : + out->icmp6_type =ICMPV6_DEST_UNREACH ; + out->icmp6_code =ICMPV6_ADM_PROHIBITED ; + out->icmp6_unused =0 ; +return 0 ; +case ICMP_PROT_UNREACH : + out->icmp6_type =ICMPV6_PARAMPROB ; + out->icmp6_code =ICMPV6_UNK_NEXTHDR ; + out->icmp6_pointer = +cpu_to_be32 (offsetof(struct ipv6hdr , nexthdr)); + *ie_forbidden = true; +return 0 ; +case ICMP_FRAG_NEEDED : + out->icmp6_type =ICMPV6_PKT_TOOBIG ; + out->icmp6_code =0 ; + in_frag_mtu =be16_to_cpu (in->un.frag.mtu); + inner4_tot_len =be16_to_cpu (inner4->tot_len); + out->icmp6_mtu = +ipxlat_46_compute_icmp_mtu6 (in_frag_mtu, + inner4_tot_len); + *ie_forbidden = true; +return 0 ; +default : +return -EPROTONOSUPPORT ; + } +} + +static int ipxlat_46_icmp_map_error_type_code (const struct icmphdr *in, +struct icmp6hdr *out, +const struct iphdr *inner4, +bool *ie_forbidden) +{ +int err; + + *ie_forbidden = false; + +switch (in->type) { +case ICMP_DEST_UNREACH : +return ipxlat_46_build_icmp_dest_unreach (in, out, inner4, + ie_forbidden); +case ICMP_TIME_EXCEEDED : + out->icmp6_type =ICMPV6_TIME_EXCEED ; + out->icmp6_code = in->code; + out->icmp6_unused =0 ; +return 0 ; +case ICMP_PARAMETERPROB : + out->icmp6_type =ICMPV6_PARAMPROB ; + *ie_forbidden = true; + err =ipxlat_46_icmp_map_param_prob (in, out); +if (unlikely (err)) +return err; +return 0 ; + } + +return -EPROTONOSUPPORT ; +} +int ipxlat_46_icmp_preflight (struct sk_buff *skb) {const struct ipxlat_cb *cb =ipxlat_skb_cb (skb);const struct icmphdr *icmp4;struct icmp6hdr mapped = {}; +struct icmphdr inner_icmp4; +struct iphdr inner4; +bool ie_forbidden;int err; -if (cb->is_icmp_err) + icmp4 = (const struct icmphdr *)(skb->data + cb->l4_off); +if (!cb->is_icmp_err) { + err =ipxlat_46_icmp_map_info_type_code (icmp4, &mapped); +return err ? -EOPNOTSUPP :0 ; + } + +/* quoted headers are not guaranteed to be naturally aligned */ +memcpy (&inner4, skb->data + cb->inner_l3_offset,sizeof (inner4)); + err =ipxlat_46_icmp_map_error_type_code (icmp4, &mapped, &inner4, + &ie_forbidden); +if (err)return -EOPNOTSUPP ; - icmp4 = (const struct icmphdr *)(skb->data + cb->l4_off); - err =ipxlat_46_icmp_map_info_type_code (icmp4, &mapped); +if (!ipxlat_is_first_frag4 (&inner4) || inner4.protocol !=IPPROTO_ICMP ) +return 0 ; + +memcpy (&inner_icmp4, skb->data + cb->inner_l4_offset, +sizeof (inner_icmp4)); + err =ipxlat_46_icmp_map_info_type_code (&inner_icmp4, &mapped);return err ? -EOPNOTSUPP :0 ; }
@@ -97,10 +272,317 @@ static int ipxlat_46_icmp_info_outer(struct sk_buff *skb)return 0 ; } +struct ipxlat_46_quote { +struct iphdr ip4; +unsigned int l3_off; +unsigned int l4_off; +unsigned int l4_len; +unsigned int end; +bool is_frag; +}; + +static int ipxlat_46_icmp_inner_l3 (const struct ipxlat_config *cfg, +struct sk_buff *skb, +struct ipxlat_46_quote *quote, +int *inner_delta) +{ +unsigned int inner_l3_payload, inner_l3_len, inner_tot_len; +const struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +unsigned int input_quote_end, input_quote_len; +unsigned int old_l4_off, new_l4_off; +struct ipv6hdr outer_ip6_copy; +struct ipv6hdr *inner_ip6; +int adjusted_quote_end; +struct frag_hdr *fh6; +u8 next_hdr; + +/* inner header alignment is not guaranteed */ + quote->l3_off = cb->inner_l3_offset; +memcpy ("e->ip4, skb->data + quote->l3_off,sizeof (quote->ip4)); + inner_l3_len = quote->ip4.ihl <<2 ; + quote->is_frag =ip_is_fragment ("e->ip4); + input_quote_len =icmp_hdr (skb)->un.reserved[1 ] <<2 ; + input_quote_end = input_quote_len ? cb->payload_off + input_quote_len : + skb->len; + +/* save outer IPv6 hdr because pull+push destroys that hdr region */ + outer_ip6_copy = *ipv6_hdr (skb); + + old_l4_off = quote->l3_off + inner_l3_len; + new_l4_off = quote->l3_off +sizeof (struct ipv6hdr ) + + (quote->is_frag ?sizeof (struct frag_hdr ) :0 ); + *inner_delta = (int )new_l4_off - (int )old_l4_off; + adjusted_quote_end = (int )input_quote_end + *inner_delta; + quote->end = adjusted_quote_end; + +if (unlikely (skb_cow_head (skb,max_t (int,0 , *inner_delta)))) +return -ENOMEM ; + +ipxlat_replace_l3 (skb, old_l4_off, new_l4_off, +skb_transport_offset (skb)); + + *ipv6_hdr (skb) = outer_ip6_copy; +ipv6_hdr (skb)->payload_len =htons (skb->len -sizeof (struct ipv6hdr )); + + inner_ip6 = (struct ipv6hdr *)(skb->data + quote->l3_off); +/* Use quoted IPv4 total-length, not skb->len: skb->len also includes +* ICMP extension bytes at the end, which are not part of the quoted +* inner IP datagram length. +*/ + inner_tot_len =ntohs (quote->ip4.tot_len); + quote->l4_len = inner_tot_len - inner_l3_len; + quote->l4_off = new_l4_off; + quote->end =min (quote->end, quote->l4_off + quote->l4_len); + inner_l3_payload = inner_tot_len - inner_l3_len + + (quote->is_frag ?sizeof (struct frag_hdr ) :0 ); +if (quote->is_frag) + next_hdr =NEXTHDR_FRAGMENT ; +else + next_hdr =ipxlat_46_map_proto_to_nexthdr (quote->ip4.protocol); + +ipxlat_46_build_l3_hdr (inner_ip6, "e->ip4, inner_l3_payload, + next_hdr, quote->ip4.ttl); + +ipxlat_46_convert_endpoints (cfg, "e->ip4, &inner_ip6->saddr, + &inner_ip6->daddr); + +if (quote->is_frag) { + fh6 = (struct frag_hdr *)(inner_ip6 +1 ); +ipxlat_46_build_frag_hdr (fh6, "e->ip4, quote->ip4.protocol); + } + +return 0 ; +} + +static int ipxlat_46_icmp_inner_l4 (struct sk_buff *skb, +const struct ipxlat_46_quote *quote) +{ +struct icmp6hdr *inner_icmp6; +struct icmphdr inner_icmp4; +struct ipv6hdr *inner_ip6; +unsigned int write_end; +struct tcphdr *tcp; +struct udphdr *udp; +int err; + +if (unlikely (!ipxlat_is_first_frag4 ("e->ip4))) +return 0 ; + + inner_ip6 = (struct ipv6hdr *)(skb->data + quote->l3_off); +switch (quote->ip4.protocol) { +case IPPROTO_TCP : +/* Only the pseudo-header addresses change. If the quote reaches +* the checksum field, the rest of the TCP message is not needed +* for an incremental update. +*/ + write_end = quote->l4_off + offsetof(struct tcphdr , check) + +sizeof (tcp->check); +if (write_end > quote->end) +return 0 ; +if (unlikely (skb_ensure_writable (skb, write_end))) +return -ENOMEM ; + + inner_ip6 = (struct ipv6hdr *)(skb->data + quote->l3_off); + tcp = (struct tcphdr *)(skb->data + quote->l4_off); + tcp->check =ipxlat_46_update_l4_csum (tcp->check, "e->ip4, + inner_ip6); +return 0 ; +case IPPROTO_UDP : + write_end = quote->l4_off +sizeof (*udp); +if (unlikely (write_end > quote->end)) +return -EINVAL ; +if (unlikely (skb_ensure_writable (skb, write_end))) +return -ENOMEM ; + + inner_ip6 = (struct ipv6hdr *)(skb->data + quote->l3_off); + udp = (struct udphdr *)(skb->data + quote->l4_off); +if (!udp->check) +return 0 ; + udp->check =ipxlat_46_update_l4_csum (udp->check, "e->ip4, + inner_ip6); +if (!udp->check) + udp->check =CSUM_MANGLED_0 ; +return 0 ; +case IPPROTO_ICMP : + write_end = quote->l4_off +sizeof (inner_icmp4); +if (unlikely (write_end > quote->end)) +return -EINVAL ; +if (unlikely (skb_ensure_writable (skb, write_end))) +return -ENOMEM ; + + inner_ip6 = (struct ipv6hdr *)(skb->data + quote->l3_off); +/* inner header alignment is not guaranteed */ +memcpy (&inner_icmp4, skb->data + quote->l4_off, +sizeof (inner_icmp4)); + inner_icmp6 = (struct icmp6hdr *)(skb->data + quote->l4_off); + err =ipxlat_46_icmp_map_info_type_code (&inner_icmp4, + inner_icmp6); +if (unlikely (err)) +return -EINVAL ; +if (quote->is_frag) { +/* a first fragment contains enough bytes to map the +* ICMP header, but not enough to rebuild its checksum +* over the full datagram +*/ +return 0 ; + } +ipxlat_46_icmp_info_update_csum (&inner_icmp4, inner_icmp6, + inner_ip6, quote->l4_len); +return 0 ; +default : +return 0 ; + } +} + +/* Adjust ICMP error quoted-datagram/extensions after inner 4->6 translation. +* The inner rewrite changes quoted datagram length; this helper recomputes +* RFC 4884 delimiter/padding, preserves extensions only when allowed, and +* enforces IPv6 minimum-MTU packet size constraints. +*/ +static int ipxlat_46_icmp_squeeze_ext (struct sk_buff *skb, +unsigned int icmp4_ipl,int inner_delta, +bool ie_forbidden) +{ +unsigned int max_ext_len, output_quote_units =0 ; +unsigned int packet_len_cap, payload_len; +struct ipxlat_icmp_layout layout = {}; +int input_quote_len, err; +struct icmp6hdr *ic6; +struct ipv6hdr *iph6; + +/* icmp4_ipl marks where quoted dgram ends and extension area starts */ +if (likely (!icmp4_ipl)) + goto no_extensions; + + layout.outer_len =skb_transport_offset (skb) +sizeof (struct icmp6hdr ); + payload_len = skb->len - layout.outer_len; + input_quote_len = icmp4_ipl + inner_delta; +if (unlikely (input_quote_len <0 || input_quote_len > payload_len)) +return -EINVAL ; + layout.input_quote_len = input_quote_len; + +if (likely (layout.input_quote_len == payload_len)) + goto no_extensions; + + layout.input_ext_len = payload_len - layout.input_quote_len; + max_ext_len =IPV6_MIN_MTU - + (layout.outer_len +ICMP_EXT_ORIG_DGRAM_MIN_LEN ); + +if (unlikely (ie_forbidden || layout.input_ext_len > max_ext_len)) { + packet_len_cap = min_t(unsigned int, + skb->len - layout.input_ext_len, +IPV6_MIN_MTU ); + layout.output_quote_len = packet_len_cap - layout.outer_len; + }else { + packet_len_cap = min_t(unsigned int, skb->len, IPV6_MIN_MTU); + layout.output_quote_len = +round_down (packet_len_cap - layout.input_ext_len - + layout.outer_len, +sizeof (u64)); + layout.output_pad_len = + max_t(unsigned int, ICMP_EXT_ORIG_DGRAM_MIN_LEN, + layout.output_quote_len) - + layout.output_quote_len; + layout.output_ext_len = layout.input_ext_len; + output_quote_units = (layout.output_quote_len + + layout.output_pad_len) >>3 ; + } + +/* if no ext bytes are copied and no pad is written, relayout only +* trims/updates lengths and does not require full data writability +*/ +if (unlikely (layout.output_ext_len || layout.output_pad_len)) { + err =skb_ensure_writable (skb, skb->len); +if (unlikely (err)) +return err; + } + + err =ipxlat_icmp_relayout (skb, &layout); +if (unlikely (err)) +return err; + + iph6 =ipv6_hdr (skb); + iph6->payload_len =htons (skb->len -sizeof (*iph6)); + +no_extensions: +if (unlikely (skb->len >IPV6_MIN_MTU )) { + err =pskb_trim (skb,IPV6_MIN_MTU ); +if (unlikely (err)) +return err; + + iph6 =ipv6_hdr (skb); + iph6->payload_len =htons (skb->len -sizeof (*iph6)); + } + + ic6 =icmp6_hdr (skb); + ic6->icmp6_datagram_len = output_quote_units; +return 0 ; +} + +/** +* ipxlat_46_icmp_error - translate ICMPv4 error payload to ICMPv6 error form +* @cfg: immutable route translation configuration +* @skb: packet carrying outer ICMPv4 error +* +* Rewrites the quoted inner datagram in place, maps type/code/fields and +* adjusts RFC 4884 datagram/extension layout before recomputing outer checksum. +* +* Return: 0 on success, negative errno on translation failure. +*/ +static int ipxlat_46_icmp_error (const struct ipxlat_config *cfg, +struct sk_buff *skb) +{ +const struct ipxlat_cb *cb =ipxlat_skb_cb (skb); +const struct icmphdr icmp4 = *icmp_hdr (skb); +struct ipxlat_46_quote quote; +unsigned int l4_len, l4_off; +struct icmp6hdr *icmp6; +struct ipv6hdr *iph6; +int inner_delta, err; +bool ie_forbidden; + +if (unlikely (!cb->is_icmp_err)) { +DEBUG_NET_WARN_ON_ONCE (1 ); +return -EINVAL ; + } + +/* rewrite the quoted IP hdr, then repair transport data when present */ + err =ipxlat_46_icmp_inner_l3 (cfg, skb, "e, &inner_delta); +if (unlikely (err)) +return err; + err =ipxlat_46_icmp_inner_l4 (skb, "e); +if (unlikely (err)) +return err; + + err =ipxlat_46_icmp_map_error_type_code (&icmp4,icmp6_hdr (skb), + "e.ip4, &ie_forbidden); +if (unlikely (err)) +return err; + + err =ipxlat_46_icmp_squeeze_ext (skb, icmp4.un.reserved[1 ] <<2 , + inner_delta, ie_forbidden); +if (unlikely (err)) +return err; + +/* error path rewrites quoted packet bytes/lengths, so use full +* checksum recomputation instead of incremental update +*/ + iph6 =ipv6_hdr (skb); + icmp6 =icmp6_hdr (skb); + l4_off =skb_transport_offset (skb); + l4_len =ipxlat_skb_l4_len (skb); + icmp6->icmp6_cksum =0 ; + icmp6->icmp6_cksum =ipxlat_l4_csum_ipv6 (&iph6->saddr, &iph6->daddr, + skb, l4_off, l4_len, +IPPROTO_ICMPV6 ); + skb->ip_summed =CHECKSUM_NONE ; +return 0 ; +} +int ipxlat_46_icmp (const struct ipxlat_config *cfg,struct sk_buff *skb) {if (unlikely (ipxlat_skb_cb (skb)->is_icmp_err)) -return -EINVAL ; +return ipxlat_46_icmp_error (cfg, skb);return ipxlat_46_icmp_info_outer (skb); }
net/ipxlat/icmp_64.c +507 -6
548 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC v2 16/18 net: ipxlat: add lightweight tunnel attachment
In reply to Ralf LiciAttach the reusable translator to IPv4 and IPv6 routes. Parse immutable route configuration, support input and output LWT callbacks, return ineligible packets to the original route, and re-enter the translated family through routing and netfilter.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- New attachment replacing the v1 virtual netdevice. (Toke)
- Parse an immutable RFC 6052 prefix and optional one-element EAMT from
route LWT attributes (normal route, multipath, and nexthop-object
lifetimes own the state).
- Support both input and output LWT callbacks. Return packets rejected
as unsupported during preparation to the route's native callback.
- Scrub original-family metadata, perform a fresh translated-family
route and XFRM lookup, and continue received traffic through
PRE_ROUTING or local traffic through LOCAL_OUT. Populate only
fragment-stable flow selectors.
- Let translated-family forwarding own TTL/Hop Limit and PMTU behavior,
and expose translated packets to ordinary conntrack and NAT.
- Register the LWT module alias used by route-encapsulation autoloading
rather than retaining the v1 rtnl-link alias. (Sashiko)
include/uapi/linux/ipxlat.h | 56 +++ include/uapi/linux/lwtunnel.h | 1 + net/core/lwtunnel.c | 3 +- net/ipxlat/Kconfig | 11 + net/ipxlat/Makefile | 5 +- net/ipxlat/lwt.c | 643 ++++++++++++++++++++++++++++++++++ 6 files changed, 717 insertions(+), 2 deletions(-) create mode 100644 include/uapi/linux/ipxlat.h create mode 100644 net/ipxlat/lwt.c
include/uapi/linux/ipxlat.h new file +56 -0
@@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* IPXLAT - Stateless IP/ICMP Translation (SIIT) LWT configuration +* +* 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]> +*/ + +/* +* IPXLAT lightweight-tunnel configuration. +* +* The attributes below are carried in RTA_ENCAP for +* LWTUNNEL_ENCAP_IPXLAT. Prefix addresses are raw network-byte-order +* address values; prefix lengths are expressed in bits. +*/ +#ifndef _UAPI_LINUX_IPXLAT_H +#define _UAPI_LINUX_IPXLAT_H + +#include <linux/types.h> + +enum { +IPXLAT_A_UNSPEC , +IPXLAT_A_RFC6052_PREFIX6 , +/* nested array: each indexed element contains IPXLAT_A_EAM_* +* attributes +*/ +IPXLAT_A_EAMT , + __IPXLAT_A_MAX, +}; + +#define IPXLAT_A_MAX (__IPXLAT_A_MAX - 1) + +enum { +IPXLAT_A_PREFIX6_UNSPEC , +IPXLAT_A_PREFIX6_ADDR , +IPXLAT_A_PREFIX6_LEN , + __IPXLAT_A_PREFIX6_MAX, +}; + +#define IPXLAT_A_PREFIX6_MAX (__IPXLAT_A_PREFIX6_MAX - 1) + +enum { +IPXLAT_A_EAM_UNSPEC , +IPXLAT_A_EAM_PREFIX4 , +IPXLAT_A_EAM_PREFIX4_LEN , +IPXLAT_A_EAM_PREFIX6 , +IPXLAT_A_EAM_PREFIX6_LEN , + __IPXLAT_A_EAM_MAX, +}; + +#define IPXLAT_A_EAM_MAX (__IPXLAT_A_EAM_MAX - 1) + +#endif /* _UAPI_LINUX_IPXLAT_H */
include/uapi/linux/lwtunnel.h +1 -0
@@ -16,6 +16,7 @@ enum lwtunnel_encap_types {LWTUNNEL_ENCAP_RPL ,LWTUNNEL_ENCAP_IOAM6 ,LWTUNNEL_ENCAP_XFRM , +LWTUNNEL_ENCAP_IPXLAT , __LWTUNNEL_ENCAP_MAX, };
net/core/lwtunnel.c +2 -1
@@ -53,6 +53,8 @@ static const char *lwtunnel_encap_str(enum lwtunnel_encap_types encap_type)case LWTUNNEL_ENCAP_XFRM :/* module autoload not supported for encap type */ return NULL ; +case LWTUNNEL_ENCAP_IPXLAT : +return "IPXLAT" ;case LWTUNNEL_ENCAP_IP6 :case LWTUNNEL_ENCAP_IP :case LWTUNNEL_ENCAP_NONE :
@@ -200,7 +202,6 @@ int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int remaining,return -EINVAL ; } encap_type =nla_get_u16 (nla_entype); -if (lwtunnel_valid_encap_type (encap_type, extack))return -EOPNOTSUPP ; }
net/ipxlat/Kconfig +11 -0
@@ -12,3 +12,14 @@ config NET_IPXLAT SIIT-DC, 464XLAT network architectures. To compile this engine as a module, choose M here. + +config NET_IPXLAT_LWT + tristate "IPv6<>IPv4 packet translation LWT attachment" + depends on NET_IPXLAT + depends on LWTUNNEL + help + Attach the ipxlat translation engine to IPv4 or IPv6 routes using the + lightweight-tunnel route encapsulation. Routes select the packets to + translate and contain their address mapping. Translated packets then + enter normal routing and netfilter processing for their new address + family.
net/ipxlat/Makefile +4 -1
@@ -1,8 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 # -# IPXLAT - Stateless IP/ICMP Translation (SIIT) engine +# IPXLAT - Stateless IP/ICMP Translation (SIIT) engine and LWT attachment obj-$(CONFIG_NET_IPXLAT) += ipxlat.o +obj-$(CONFIG_NET_IPXLAT_LWT) += ipxlat_lwt.o ipxlat-objs += config.o ipxlat-objs += core.o
@@ -14,3 +15,5 @@ ipxlat-objs += translate_46.o ipxlat-objs += translate_64.o ipxlat-objs += icmp_46.o ipxlat-objs += icmp_64.o + +ipxlat_lwt-objs += lwt.o
net/ipxlat/lwt.c new file +643 -0
643 lines not on this page · raw message
Signature · 1 line
2.55.0
RFC v2 17/18 selftests: net: add ipxlat coverage
In reply to Ralf LiciExercise forwarded and local translation, native fallback, target-family conntrack and NAT, checksumless UDP, route-PMTU fragmentation, conntrack reassembly followed by refragmentation, PMTU feedback and ICMP errors.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Replace the v1 netdevice/YNL suite with an iproute2/LWT namespace
topology.
- Add coverage for local and forwarded LWT translation, native fallback, translated-family conntrack and masquerade, route-PMTU fragmentation, reassembly/refragmentation, and PMTU feedback.
- Verify zero-checksum UDPv4 at a real translated-family receiver
instead of treating a packet capture as proof of successful delivery. (Sashiko)
- Keep forwarding, sysctls, routes, and translator state inside
disposable network namespaces so a failed test cannot leave host
networking changed. (Sashiko)
- Remove the dedicated UDP generator and produce the required packet
shapes with existing selftest tools, avoiding the v1 helper's
undeclared padding bytes. Remove the old fragmented-ICMP capture
filter whose fixed offset could miss ICMP after an IPv6 Fragment
Header. (Sashiko)
tools/testing/selftests/Makefile | 1 + tools/testing/selftests/net/ipxlat/Makefile | 5 + tools/testing/selftests/net/ipxlat/config | 13 + tools/testing/selftests/net/ipxlat/ipxlat.sh | 554 +++++++++++++++++++ 4 files changed, 573 insertions(+) create mode 100644 tools/testing/selftests/net/ipxlat/Makefile create mode 100644 tools/testing/selftests/net/ipxlat/config create mode 100755 tools/testing/selftests/net/ipxlat/ipxlat.sh
tools/testing/selftests/Makefile +1 -0
@@ -90,6 +90,7 @@ TARGETS += net/af_unix TARGETS += net/can TARGETS += net/forwarding TARGETS += net/hsr +TARGETS += net/ipxlat TARGETS += net/mptcp TARGETS += net/netfilter TARGETS += net/openvswitch
tools/testing/selftests/net/ipxlat/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +TEST_PROGS := ipxlat.sh + +include ../../lib.mk
tools/testing/selftests/net/ipxlat/config new file +13 -0
@@ -0,0 +1,13 @@ +CONFIG_INET=y +CONFIG_IPV6=y +CONFIG_LWTUNNEL=y +CONFIG_NET_IPXLAT=m +CONFIG_NET_IPXLAT_LWT=m +CONFIG_NET_NS=y +CONFIG_NF_CONNTRACK=m +CONFIG_NF_NAT=m +CONFIG_NF_TABLES=m +CONFIG_NF_TABLES_IPV4=y +CONFIG_NF_TABLES_IPV6=y +CONFIG_NFT_NAT=m +CONFIG_VETH=m
tools/testing/selftests/net/ipxlat/ipxlat.sh new file +554 -0
554 lines not on this page · raw message
Signature · 1 line
2.55.0
Re: [RFC net-next v2 17/18] selftests: net: add ipxlat coverage
Hi Ralf,
How about adding a selftest variant that forces software GSO? This may help catch checksum issues.
Best regards,
Xavier
Re: [RFC net-next v2 17/18] selftests: net: add ipxlat coverage
Quoted 5 lines · Xavier HSINYUAN
Hi Ralf,
How about adding a selftest variant that forces software GSO? This may help catch checksum issues.
Will do. The iperf3 step already produces GSO skbs, but veth hands them to the peer as CHECKSUM_PARTIAL and the receiver treats them as already verified, so a bad seed is never caught. The next revision will add a variant with tx checksum offload disabled on the egress veth, so software GSO computes the final checksums and the receiver actually verifies them.
Thanks!
Signature · 2 lines
Ralf Lici Mandelbit Srl
RFC v2 18/18 docs: networking: add ipxlat guide
In reply to Ralf LiciDocument the route configuration model, address mapping, CLAT and NAT64 examples, packet continuation, conntrack, fragmentation, checksum handling and operational limitations.
---
Changes since RFC v1 https://lore.kernel.org/netdev/[email protected]/
- Rewrite the guide for the LWT route model and inline immutable
configuration; remove netdevice, generic-netlink/YNL, device MTU, and
device statistics documentation and the confusing receive-reinjection
model. (Toke)
- Document EAM-before-RFC6052 endpoint conversion, both CLAT addressing
models, and downstream source validation outside the engine.
(Beniamino)
- Add end-to-end single-host CLAT, delegated-prefix CLAT, stateful NAT64, 464XLAT, and SIIT border-router examples.
- Add short /96 examples which show both address-translation directions. (Xavier)
- Replace the broken v1 YNL example with iproute2 commands for LWT route configuration. (Xavier)
- Add the guide to Documentation/networking/index.rst. (Jonathan)
- Fix omitted route commands, inconsistent variable names, spelling, and
RST problems in the v1 guide. (Sashiko)
- Document native fallback, family-switch continuation, conntrack/NAT,
XFRM, TTL/Hop Limit, target-route fragmentation, checksumless UDP, and protocol handling.
Documentation/networking/index.rst | 1 + Documentation/networking/ipxlat.rst | 333 ++++++++++++++++++++++++++++ net/ipxlat/Kconfig | 2 + 3 files changed, 336 insertions(+) create mode 100644 Documentation/networking/ipxlat.rst
Documentation/networking/index.rst +1 -0
@@ -66,6 +66,7 @@ Contents: ipv6 ipvlan ipvs-sysctl + ipxlat kcm l2tp lapb-module
Documentation/networking/ipxlat.rst new file +333 -0
333 lines not on this page · raw message
net/ipxlat/Kconfig +2 -0
@@ -11,6 +11,8 @@ config NET_IPXLAT RFC 7915. Useful for IPv6 focused networks. Particularly NAT64, SIIT-DC, 464XLAT network architectures. + See also <file:Documentation/networking/ipxlat.rst>. + To compile this engine as a module, choose M here. config NET_IPXLAT_LWT
Signature · 1 line
2.55.0
Hi Ralf,
Thanks for your v2 series!
Here is a question about netfilter hooks in ipxlat-lwt. In RFC v1, netdev-based ipxlat allows POST_ROUTING rules to be applied for original-family before translation. Currently LWT path translates first and does not check nf_hooks_lwtunnel to optionally run original-family POST_ROUTING before translation.
Is this difference intentional since it keeps LWT path simple and leave such cases to netdev path, or would an optional pre-translation pass in LWT path also be worth considering?
Best regards,
Xavier
Quoted 2 lines · Xavier HSINYUAN
Hi Ralf,
Hi Xavier,
Quoted 2 lines
Thanks for your v2 series!
Thanks for the review.
Quoted 10 lines
Here is a question about netfilter hooks in ipxlat-lwt. In RFC v1, netdev-based ipxlat allows
POST_ROUTINGrules to be applied for original-family before translation. Currently LWT path translates first and does not checknf_hooks_lwtunnelto optionally run original-familyPOST_ROUTINGbefore translation.Is this difference intentional since it keeps LWT path simple and leave such cases to netdev path, or would an optional pre-translation pass in LWT path also be worth considering?
Actually v2 has no netdevice attachment any more, the LWT is the only harness in this series.
Aside from that, yes, the difference you describe follows from the v2 contract. The selecting route terminates original-family processing, so that family only sees PRE_ROUTING (received) or LOCAL_OUT (local), and FORWARD/POST_ROUTING/LOCAL_IN run in the translated family only. That is indeed the first open question in the cover letter.
Looking into it again, there seems to be two concrete problems with that contract:
- original-family conntrack entries are created at the entry hook and never confirmed, so stateful rules in that family see replies as new or invalid and a conventional ct state established firewall drops them;
- SNAT in the original family before translation is not possible, which rules out NAT44 in front of a CLAT and the NAPT66-based NAT64 recipe from the v1 documentation.
So I do not consider the current behaviour settled.
nf_hooks_lwtunnel is one way to add an original-family exit hook, and seg6 is a good precedent for the hook placement. I am less sure about the gate itself because it is global, cannot be switched off again, and is off by default, so the default configuration would keep the problem.
Two alternatives I am evaluating are calling the exit hook unconditionally, and moving the translation point to the LWT xmit stage so the original family completes its normal path. I will come back with a concrete proposal and a per-hook table.
Which setup do you have in mind: SNAT before translation, filtering, or accounting?
Signature · 2 lines
Ralf Lici Mandelbit Srl
Hi Ralf,
Thanks for looking into this!
Quoted 3 lines
Actually v2 has no netdevice attachment any more, the LWT is the only harness in this series.
Ah, I was thinking of a possible future netdev attachment at the time. Thanks again for pointing that out.
Quoted 24 lines
Aside from that, yes, the difference you describe follows from the v2 contract. The selecting route terminates original-family processing, so that family only sees
PRE_ROUTING(received) orLOCAL_OUT(local), and FORWARD/POST_ROUTING/LOCAL_IN run in the translated family only. That is indeed the first open question in the cover letter.Looking into it again, there seems to be two concrete problems with that contract:
- original-family conntrack entries are created at the entry hook and never confirmed, so stateful rules in that family see replies as new or invalid and a conventional ct state established firewall drops them;
- SNAT in the original family before translation is not possible, which rules out NAT44 in front of a CLAT and the NAPT66-based NAT64 recipe from the v1 documentation.So I do not consider the current behaviour settled.
nf_hooks_lwtunnelis one way to add an original-family exit hook, and seg6 is a good precedent for the hook placement. I am less sure about the gate itself because it is global, cannot be switched off again, and is off by default, so the default configuration would keep the problem.
Quoted 7 lines
Two alternatives I am evaluating are calling the exit hook unconditionally, and moving the translation point to the LWT xmit stage so the original family completes its normal path. I will come back with a concrete proposal and a per-hook table.
Which setup do you have in mind: SNAT before translation, filtering, or accounting?
My interest is mainly SNAT and counting before translation. Well, stateful SNAT seems a bit odd for IPv6, but with multiple upstreams we may need to adjust the source prefix based on the selected output interface for load balancing or failover.
That said, separating NAT and translation by utilizing netns and veth pairs could already provide this, but letting packets pass through original-family POST_ROUTING before translation would make setup (looks) simpler.
Best regards,
Xavier