]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables: Use meta l4proto for -p match
authorPhil Sutter <phil@nwl.cc>
Mon, 20 Aug 2018 13:30:03 +0000 (15:30 +0200)
committerFlorian Westphal <fw@strlen.de>
Tue, 21 Aug 2018 15:57:16 +0000 (17:57 +0200)
Use of payload expression to match against IPv6 nexthdr field does not
work if extension headers are present. A simple example for that is
matching for fragmented icmpv6 traffic. Instead, generate a 'meta
l4proto' expression which works even if extension headers are present.

For consistency, apply the same change to iptables-nft as well.

No adjustment to reverse path required as the needed bits were added by
commit 6ea7579e6fe24 ("nft: decode meta l4proto") already.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
iptables/nft-ipv4.c
iptables/nft-ipv6.c
iptables/nft-shared.c
iptables/nft-shared.h

index 105b1341549fa45750d50e18ffb09fbbc6dc76e9..2d1bd10e30aaa7056f9414c1895bb19096235c98 100644 (file)
@@ -45,8 +45,7 @@ static int nft_ipv4_add(struct nftnl_rule *r, void *data)
 
        if (cs->fw.ip.proto != 0) {
                op = nft_invflags2cmp(cs->fw.ip.invflags, XT_INV_PROTO);
-               add_proto(r, offsetof(struct iphdr, protocol), 1,
-                         cs->fw.ip.proto, op);
+               add_l4proto(r, cs->fw.ip.proto, op);
        }
 
        if (cs->fw.ip.src.s_addr != 0) {
index dd23557c7e6c00d6b113bcc06f2f7d27ac866e84..48a7cefe023bce14f18ed803a188227ae887b78e 100644 (file)
@@ -44,8 +44,7 @@ static int nft_ipv6_add(struct nftnl_rule *r, void *data)
 
        if (cs->fw6.ipv6.proto != 0) {
                op = nft_invflags2cmp(cs->fw6.ipv6.invflags, XT_INV_PROTO);
-               add_proto(r, offsetof(struct ip6_hdr, ip6_nxt), 1,
-                         cs->fw6.ipv6.proto, op);
+               add_l4proto(r, cs->fw6.ipv6.proto, op);
        }
 
        if (!IN6_IS_ADDR_UNSPECIFIED(&cs->fw6.ipv6.src)) {
index b31234ee8dfa43e470a7743afa264d89ce00e6c6..62a57dd5f02b4af7818d18dac53a4fc5d115c155 100644 (file)
@@ -188,6 +188,12 @@ void add_proto(struct nftnl_rule *r, int offset, size_t len,
        add_cmp_u8(r, proto, op);
 }
 
+void add_l4proto(struct nftnl_rule *r, uint8_t proto, uint32_t op)
+{
+       add_meta(r, NFT_META_L4PROTO);
+       add_cmp_u8(r, proto, op);
+}
+
 bool is_same_interfaces(const char *a_iniface, const char *a_outiface,
                        unsigned const char *a_iniface_mask,
                        unsigned const char *a_outiface_mask,
index 807507845fbafc2cf5a736d34db274e9bb44f67d..59e1062a725bf70ea5089c919bf699b042fb7c94 100644 (file)
@@ -122,6 +122,7 @@ void add_addr(struct nftnl_rule *r, int offset,
              void *data, void *mask, size_t len, uint32_t op);
 void add_proto(struct nftnl_rule *r, int offset, size_t len,
               uint8_t proto, uint32_t op);
+void add_l4proto(struct nftnl_rule *r, uint8_t proto, uint32_t op);
 void add_compat(struct nftnl_rule *r, uint32_t proto, bool inv);
 
 bool is_same_interfaces(const char *a_iniface, const char *a_outiface,