aboutsummaryrefslogtreecommitdiff
path: root/sys/modules
diff options
context:
space:
mode:
authorR. Christian McDonald <rcm@FreeBSD.org>2026-11-19 02:58:21 +0000
committerR. Christian McDonald <rcm@FreeBSD.org>2026-11-19 02:59:29 +0000
commitd1e14cba4a79c0b4fe7cff3c0afcc0ffb50f54b3 (patch)
treecc1a4dd2b0de4e870232d2bec93b1125bed5e4a9 /sys/modules
parent3ccfcdacd6ae7611dc0f2a1375713dc0111c3d5f (diff)
netipsec: Set the outer IPv6 flow label from the SA
Tunnel mode encapsulation leaves the flow label of the outer IPv6 header zero. ESP and AH have no transport ports (UDP-encapsulated ESP has them, but the same pair for every SA), so devices that hash IPv6 headers to spread traffic, link aggregates and ECMP routers alike, see no difference between the security associations of two gateways and put all of their tunnels on one path. lagg(4)'s own header hash does the same: for IPv6 its layer 4 input is the flow label. Set the label to the low 20 bits of the SA's flow ID, the hash of its SPI that the previous change introduced. Each SA then carries one label for its lifetime; SPIs are unique within the SADB, so distinct SAs carry distinct labels unless the 20-bit hashes collide. A hasher that includes the flow label then spreads SAs over its paths while keeping the packets of each SA on one, which avoids reordering their sequence numbers across paths. A rekey starts a new SA and a new label. The label is set whether or not net.inet.ipsec.sa_flowid is enabled: that sysctl governs the local transmit queue selection, this label what the network sees. In a bundle whose tunnel mode SA is followed by transport mode SAs the outer header stays in place; relabel it from the outermost SA when the packet leaves, as that SA's sequence numbers are the first the path choice reorders and the previous change already took the flow ID from it. One transport SA shared by several tunnel SAs then stays on one path. RFC 6437 leaves the definition of a flow to the source and recommends uniformly distributed labels, a hash of the packet's fields being one stateless way to get them. RFC 6438 describes labelling at a tunnel entry point from the inner flow, which Linux IPsec and gre(4) with UDP encapsulation do, so that one tunnel spreads over several paths. ESP carries sequence numbers, so that spreading reorders them and a receiver with a small anti-replay window drops the late packets; keying the label on the SA is the choice that fits. RFC 6437 asks that a hash-derived label be hard to predict; this one is a function of the SPI in the same packet, so keying the hash would hide nothing, and the label is meant to stay the same for the life of the SA. AH treats the flow label as mutable and zeroes it before computing and verifying the ICV, so the label does not affect AH. Transport mode and SAs offloaded to a NIC are not affected. ip6_output() leaves the label of packets without socket options alone. Document the label in ipsec(4). Reviewed by: kib, ae MFC after: 2 weeks Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D61196
Diffstat (limited to 'sys/modules')
0 files changed, 0 insertions, 0 deletions