Linux Netfilter development
 help / color / mirror / Atom feed
* [PATCH libnftnl] expr: meta: add slave device matching
@ 2019-12-18 11:10 Florian Westphal
  2019-12-18 11:10 ` [PATCH nft] " Florian Westphal
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Westphal @ 2019-12-18 11:10 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal, Martin Willi

Cc: Martin Willi <martin@strongswan.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 include/linux/netfilter/nf_tables.h | 4 ++++
 src/expr/meta.c                     | 4 +++-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/include/linux/netfilter/nf_tables.h b/include/linux/netfilter/nf_tables.h
index bb9b049310df..e237ecbdcd8a 100644
--- a/include/linux/netfilter/nf_tables.h
+++ b/include/linux/netfilter/nf_tables.h
@@ -805,6 +805,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,
@@ -840,6 +842,8 @@ enum nft_meta_keys {
 	NFT_META_TIME_NS,
 	NFT_META_TIME_DAY,
 	NFT_META_TIME_HOUR,
+	NFT_META_SDIF,
+	NFT_META_SDIFNAME,
 };
 
 /**
diff --git a/src/expr/meta.c b/src/expr/meta.c
index 979019831f2b..6ed8ee5645c4 100644
--- a/src/expr/meta.c
+++ b/src/expr/meta.c
@@ -22,7 +22,7 @@
 #include <libnftnl/rule.h>
 
 #ifndef NFT_META_MAX
-#define NFT_META_MAX (NFT_META_TIME_HOUR + 1)
+#define NFT_META_MAX (NFT_META_SDIFNAME + 1)
 #endif
 
 struct nftnl_expr_meta {
@@ -166,6 +166,8 @@ static const char *meta_key2str_array[NFT_META_MAX] = {
 	[NFT_META_TIME_NS]	= "time",
 	[NFT_META_TIME_DAY]	= "day",
 	[NFT_META_TIME_HOUR]	= "hour",
+	[NFT_META_SDIF]		= "sdif",
+	[NFT_META_SDIFNAME]	= "sdifname",
 };
 
 static const char *meta_key2str(uint8_t key)
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH nft] meta: add slave device matching
  2019-12-18 11:10 [PATCH libnftnl] expr: meta: add slave device matching Florian Westphal
@ 2019-12-18 11:10 ` Florian Westphal
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Westphal @ 2019-12-18 11:10 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Florian Westphal, Martin Willi

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          |  6 ++++++
 include/linux/netfilter/nf_tables.h |  4 ++++
 src/meta.c                          |  5 +++++
 tests/py/ip/meta.t                  |  3 +++
 tests/py/ip/meta.t.payload          | 11 +++++++++++
 tests/py/ip6/meta.t                 |  3 +++
 tests/py/ip6/meta.t.payload         | 12 ++++++++++++
 7 files changed, 44 insertions(+)

diff --git a/doc/primary-expression.txt b/doc/primary-expression.txt
index 6f636e13f5b5..94eccc20241a 100644
--- a/doc/primary-expression.txt
+++ b/doc/primary-expression.txt
@@ -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
diff --git a/include/linux/netfilter/nf_tables.h b/include/linux/netfilter/nf_tables.h
index ed8881ad18ed..c556ccd3dbf7 100644
--- a/include/linux/netfilter/nf_tables.h
+++ b/include/linux/netfilter/nf_tables.h
@@ -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,
 };
 
 /**
diff --git a/src/meta.c b/src/meta.c
index 135f84b51c55..bc35f28fb2b6 100644
--- a/src/meta.c
+++ b/src/meta.c
@@ -700,6 +700,11 @@ 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,
+						4 * 8, 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)
diff --git a/tests/py/ip/meta.t b/tests/py/ip/meta.t
index 4db88354463e..f733d22de2c3 100644
--- a/tests/py/ip/meta.t
+++ b/tests/py/ip/meta.t
@@ -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
diff --git a/tests/py/ip/meta.t.payload b/tests/py/ip/meta.t.payload
index 322c0878f2c9..7bc69a290d24 100644
--- a/tests/py/ip/meta.t.payload
+++ b/tests/py/ip/meta.t.payload
@@ -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 ]
diff --git a/tests/py/ip6/meta.t b/tests/py/ip6/meta.t
index 24445084890b..dce97f5b0fd0 100644
--- a/tests/py/ip6/meta.t
+++ b/tests/py/ip6/meta.t
@@ -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
diff --git a/tests/py/ip6/meta.t.payload b/tests/py/ip6/meta.t.payload
index f203baaba16a..be04816eeec2 100644
--- a/tests/py/ip6/meta.t.payload
+++ b/tests/py/ip6/meta.t.payload
@@ -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 ]
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-18 11:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-18 11:10 [PATCH libnftnl] expr: meta: add slave device matching Florian Westphal
2019-12-18 11:10 ` [PATCH nft] " Florian Westphal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox