When transport mode requests follow a tunnel mode request in a bundle,
ipsec_process_done() sets the flow label of the outer IPv6 header from
the outermost SA. It checks only that the policy has such a tunnel
request, not that it was applied. A tunnel request at level use
without an SA is skipped, and a transport request after it, unless it
names a destination other than the packet's, is then applied to the
packet's own header. With a policy such as
"esp/tunnel/A-B/use ah/transport//require", an AH SA between the hosts
and no ESP SA, every IPv6 packet leaves with the label of the AH SA. A
forwarded packet loses the label its source chose, which RFC 6437 asks
forwarding nodes to leave alone, and every flow through that SA gets
the same one.
Record in the packet's output history the mode of the request each SA
was applied for, rather than the SA's own, which may be "any", and
relabel only when the history holds a record of one of the policy's
earlier tunnel mode requests. Nothing else reads the mode in the
output history.
Add tests for a skipped tunnel request and for tunnel SAs with mode
"any".
Reported by: llm-postcr
Fixes: d1e14cba4a79 ("netipsec: Set the outer IPv6 flow label from the SA")
MFC with: d1e14cba4a79
Sponsored by: Rubicon Communications, LLC ("Netgate")