netfilter.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jacek Tomasiak <jtomasiak@arista.com>
To: netfilter@vger.kernel.org
Subject: Matching on protocols inside IPv6 IPSec AH (legacy vs nft)
Date: Thu, 22 Jun 2023 15:25:44 +0200	[thread overview]
Message-ID: <CAPEBPyMNe5dPTC9Dwp888M5RR-2ThC7ZtuaQPxNG+5VqbJinsQ@mail.gmail.com> (raw)

Hello,

I'm working on migrating from legacy iptables to iptables-nft and I encountered
a change in behaviour in handling the IPSec AH protocol.

With following two ipv6 rules:
-A INPUT -p ipv6-icmp --icmpv6-type echo-request -j ACCEPT
-A INPUT -m ipv6header --header ah --soft -j ACCEPT

After sending packets with following scapy code:
# ping6 without AH
pck = IPv6()/ICMPv6EchoRequest()
send(pck)
# ping6 with AH
sa = SecurityAssociation(AH, spi=0)
apck = sa.encrypt(pck)
send(apck)

I get this from ip6tables-nft -vS:
-P INPUT ACCEPT -c 0 0
-P FORWARD ACCEPT -c 0 0
-P OUTPUT ACCEPT -c 0 0
-A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type 128 -c 1 48 -j ACCEPT
-A INPUT -m ipv6header --header ah --soft -c 1 64 -j ACCEPT

Hovewer, with ip6tables-legacy -vS:
-P INPUT ACCEPT -c 1 48
-P FORWARD ACCEPT -c 0 0
-P OUTPUT ACCEPT -c 1 48
-A INPUT -p ipv6-icmp -m icmp6 --icmpv6-type 128 -c 2 112 -j ACCEPT
-A INPUT -m ipv6header --header ah --soft -c 0 0 -j ACCEPT

My main concern is that in the nft version the AH rule matches one of the ICMP
packets even though the ICMP rule is higher up on the list.

I tried to debug this and it seems to be related to this change:
https://github.com/torvalds/linux/commit/568af6de058cb2b0c5b98d98ffcf37cdc6bc38a7
IIUC, this "stop ipv6_find_hdr on AH" is not a regression but intended behavior.

Now the question: is there some way to define rules which will match
the same way
as it works in iptables-legacy? That is, look at the inner protocol
and not stop on
AH?

Best Regards,
Jacek Tomasiak

             reply	other threads:[~2023-06-22 13:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-22 13:25 Jacek Tomasiak [this message]
2023-06-22 22:00 ` Matching on protocols inside IPv6 IPSec AH (legacy vs nft) Pablo Neira Ayuso
2023-06-26 12:06   ` Jacek Tomasiak
2023-07-07  7:28     ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAPEBPyMNe5dPTC9Dwp888M5RR-2ThC7ZtuaQPxNG+5VqbJinsQ@mail.gmail.com \
    --to=jtomasiak@arista.com \
    --cc=netfilter@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).