]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
nft: compare layer 4 protocol in first place
authorGiuseppe Longo <giuseppelng@gmail.com>
Fri, 22 Aug 2014 09:16:31 +0000 (11:16 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sun, 24 Aug 2014 13:29:47 +0000 (15:29 +0200)
Currently the protocol is tested after the ip address,
this fixes the order testing the protocol before the ip address.

Now the code generated is incorrect:

ip filter INPUT 16
  [ payload load 4b @ network header + 12 => reg 1 ]
  [ cmp eq reg 1 0x0100a8c0 ]
  [ payload load 1b @ network header + 9 => reg 1 ]
  [ cmp eq reg 1 0x00000006 ]
  [ match name tcp rev 0 ]
  [ match name conntrack rev 3 ]
  [ counter pkts 0 bytes 0 ]
  [ immediate reg 0 accept ]

With this patch, the code generated is:
ip filter INPUT 16
  [ payload load 1b @ network header + 9 => reg 1 ]
  [ cmp eq reg 1 0x00000006 ]
  [ payload load 4b @ network header + 12 => reg 1 ]
  [ cmp eq reg 1 0x0100a8c0 ]
  [ bitwise reg 1 = (reg=1 & 0xffffffff ) ^ 0x00000000 ]
  [ match name tcp rev 0 ]
  [ match name conntrack rev 3 ]
  [ counter pkts 0 bytes 0 ]
  [ immediate reg 0 accept ]

Signed-off-by: Giuseppe Longo <giuseppelng@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
iptables/nft-ipv4.c
iptables/nft-ipv6.c

index 33bc581ade15c955102baa344013613caf025b20..70050ba5fafe64ab3e905eae62268ae46a3be77d 100644 (file)
@@ -37,6 +37,10 @@ static int nft_ipv4_add(struct nft_rule *r, void *data)
        if (cs->fw.ip.outiface[0] != '\0')
                add_outiface(r, cs->fw.ip.outiface, cs->fw.ip.invflags);
 
+       if (cs->fw.ip.proto != 0)
+               add_proto(r, offsetof(struct iphdr, protocol), 1,
+                         cs->fw.ip.proto, cs->fw.ip.invflags);
+
        if (cs->fw.ip.src.s_addr != 0)
                add_addr(r, offsetof(struct iphdr, saddr),
                         &cs->fw.ip.src.s_addr, 4, cs->fw.ip.invflags);
@@ -45,10 +49,6 @@ static int nft_ipv4_add(struct nft_rule *r, void *data)
                add_addr(r, offsetof(struct iphdr, daddr),
                         &cs->fw.ip.dst.s_addr, 4, cs->fw.ip.invflags);
 
-       if (cs->fw.ip.proto != 0)
-               add_proto(r, offsetof(struct iphdr, protocol), 1,
-                         cs->fw.ip.proto, cs->fw.ip.invflags);
-
        if (cs->fw.ip.flags & IPT_F_FRAG) {
                add_payload(r, offsetof(struct iphdr, frag_off), 2);
                /* get the 13 bits that contain the fragment offset */
index 00f1bf8e794bc2be3ba675994632a45875bdc3fb..52de5b699be27cc8dfad65432f73ddea0e86f418 100644 (file)
@@ -34,6 +34,10 @@ static int nft_ipv6_add(struct nft_rule *r, void *data)
        if (cs->fw6.ipv6.outiface[0] != '\0')
                add_outiface(r, cs->fw6.ipv6.outiface, cs->fw6.ipv6.invflags);
 
+       if (cs->fw6.ipv6.proto != 0)
+               add_proto(r, offsetof(struct ip6_hdr, ip6_nxt), 1,
+                         cs->fw6.ipv6.proto, cs->fw6.ipv6.invflags);
+
        if (!IN6_IS_ADDR_UNSPECIFIED(&cs->fw6.ipv6.src))
                add_addr(r, offsetof(struct ip6_hdr, ip6_src),
                         &cs->fw6.ipv6.src, 16, cs->fw6.ipv6.invflags);
@@ -42,10 +46,6 @@ static int nft_ipv6_add(struct nft_rule *r, void *data)
                add_addr(r, offsetof(struct ip6_hdr, ip6_dst),
                         &cs->fw6.ipv6.dst, 16, cs->fw6.ipv6.invflags);
 
-       if (cs->fw6.ipv6.proto != 0)
-               add_proto(r, offsetof(struct ip6_hdr, ip6_nxt), 1,
-                         cs->fw6.ipv6.proto, cs->fw6.ipv6.invflags);
-
        add_compat(r, cs->fw6.ipv6.proto, cs->fw6.ipv6.invflags);
 
        for (matchp = cs->matches; matchp; matchp = matchp->next) {