]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
meta: add slave device matching
authorFlorian Westphal <fw@strlen.de>
Wed, 18 Dec 2019 11:10:41 +0000 (12:10 +0100)
committerFlorian Westphal <fw@strlen.de>
Fri, 3 Jan 2020 12:09:56 +0000 (13:09 +0100)
Adds "meta sdif" and "meta sdifname".
Both only work in input/forward hook of ipv4/ipv6/inet family.

Cc: Martin Willi <martin@strongswan.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
doc/primary-expression.txt
include/linux/netfilter/nf_tables.h
src/meta.c
tests/py/ip/meta.t
tests/py/ip/meta.t.payload
tests/py/ip6/meta.t
tests/py/ip6/meta.t.payload

index 6f636e13f5b5b66248bc1ef48e5244e413e69a5f..94eccc20241a226569fdec4377d59be05549559d 100644 (file)
@@ -76,6 +76,12 @@ ifname
 |oiftype|
 Output interface hardware type|
 iface_type
+|sdif|
+Slave device input interface index |
+iface_index
+|sdifname|
+Slave device interface name|
+ifname
 |skuid|
 UID associated with originating socket|
 uid
index ed8881ad18edd07ad799c387e0c76b754fd54c0f..c556ccd3dbf7235fbc2de9b24ef8002d24dc32b4 100644 (file)
@@ -803,6 +803,8 @@ enum nft_exthdr_attributes {
  * @NFT_META_TIME_NS: time since epoch (in nanoseconds)
  * @NFT_META_TIME_DAY: day of week (from 0 = Sunday to 6 = Saturday)
  * @NFT_META_TIME_HOUR: hour of day (in seconds)
+ * @NFT_META_SDIF: slave device interface index
+ * @NFT_META_SDIFNAME: slave device interface name
  */
 enum nft_meta_keys {
        NFT_META_LEN,
@@ -838,6 +840,8 @@ enum nft_meta_keys {
        NFT_META_TIME_NS,
        NFT_META_TIME_DAY,
        NFT_META_TIME_HOUR,
+       NFT_META_SDIF,
+       NFT_META_SDIFNAME,
 };
 
 /**
index 135f84b51c55574ae20e59f7514310afea0d651d..acc348eb264ddad92a6af77b5ccd8834d898640d 100644 (file)
@@ -700,6 +700,12 @@ const struct meta_template meta_templates[] = {
                                                BYTEORDER_HOST_ENDIAN),
        [NFT_META_SECMARK]      = META_TEMPLATE("secmark", &integer_type,
                                                32, BYTEORDER_HOST_ENDIAN),
+       [NFT_META_SDIF]         = META_TEMPLATE("sdif", &ifindex_type,
+                                               sizeof(int) * BITS_PER_BYTE,
+                                               BYTEORDER_HOST_ENDIAN),
+       [NFT_META_SDIFNAME]     = META_TEMPLATE("sdifname", &ifname_type,
+                                               IFNAMSIZ * BITS_PER_BYTE,
+                                               BYTEORDER_HOST_ENDIAN),
 };
 
 static bool meta_key_is_unqualified(enum nft_meta_keys key)
index 4db88354463e88d13828d3eebe20999fb1280a42..f733d22de2c3b6658e8709ca51624d0131746584 100644 (file)
@@ -10,3 +10,6 @@ icmpv6 type nd-router-advert;ok
 
 meta ibrname "br0";fail
 meta obrname "br0";fail
+
+meta sdif "lo" accept;ok
+meta sdifname != "vrf1" accept;ok
index 322c0878f2c90bb4fd8831ac849147dc02df1532..7bc69a290d24e59ca37f898f6dd4551adb6eff13 100644 (file)
@@ -33,3 +33,14 @@ ip test-ip4 input
   [ payload load 1b @ transport header + 0 => reg 1 ]
   [ cmp eq reg 1 0x00000086 ]
 
+# meta sdif "lo" accept
+ip6 test-ip4 input
+  [ meta load sdif => reg 1 ]
+  [ cmp eq reg 1 0x00000001 ]
+  [ immediate reg 0 accept ]
+
+# meta sdifname != "vrf1" accept
+ip6 test-ip4 input
+  [ meta load sdifname => reg 1 ]
+  [ cmp neq reg 1 0x31667276 0x00000000 0x00000000 0x00000000 ]
+  [ immediate reg 0 accept ]
index 24445084890bbbbc2dd09bfa9c428926a4cc5c30..dce97f5b0fd0a1f20f4e6dd0389ca7122f4efdca 100644 (file)
@@ -8,3 +8,6 @@ meta l4proto ipv6-icmp icmpv6 type nd-router-advert;ok;icmpv6 type nd-router-adv
 meta l4proto icmp icmp type echo-request;ok;icmp type echo-request
 meta l4proto 1 icmp type echo-request;ok;icmp type echo-request
 icmp type echo-request;ok
+
+meta sdif "lo" accept;ok
+meta sdifname != "vrf1" accept;ok
index f203baaba16ae0f9ae4a06c956da90be3643dfc3..be04816eeec2489e795ebf88b5ed6229e3b40455 100644 (file)
@@ -32,3 +32,15 @@ ip6 test-ip6 input
   [ cmp eq reg 1 0x00000001 ]
   [ payload load 1b @ transport header + 0 => reg 1 ]
   [ cmp eq reg 1 0x00000008 ]
+
+# meta sdif "lo" accept
+ip6 test-ip6 input
+  [ meta load sdif => reg 1 ]
+  [ cmp eq reg 1 0x00000001 ]
+  [ immediate reg 0 accept ]
+
+# meta sdifname != "vrf1" accept
+ip6 test-ip6 input
+  [ meta load sdifname => reg 1 ]
+  [ cmp neq reg 1 0x31667276 0x00000000 0x00000000 0x00000000 ]
+  [ immediate reg 0 accept ]