Skip to contentSkip to conversation

src: update meta expr

PATCH Applied Arturo Borrero Gonzalez 2 participants 2 messages Dec 26, 2013 – Dec 28, 2013 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 src: update meta expr

This patch adds userspace support for the meta expression in the set flavour.

This expression indicates that the packet has to be set with a property, currently one of mark, priority or nftrace.

---
v1: initial release of the patch
v2: address comments from Tomasz in the kernel side: respect the order of the
enums. Also, other cleanups.
v3: use a nftables register to set the given packet value.

 include/libnftables/expr.h               |    1 
 include/linux/netfilter/nf_tables.h      |    4 +
 src/expr/meta.c                          |  116 ++++++++++++++++++++++++------
 tests/jsonfiles/65-rule-meta-target.json |    1 
 tests/xmlfiles/76-rule-meta_target.xml   |    1 
 5 files changed, 98 insertions(+), 25 deletions(-)
 create mode 100644 tests/jsonfiles/65-rule-meta-target.json
 create mode 100644 tests/xmlfiles/76-rule-meta_target.xml
include/libnftables/expr.h +1 -0
index 54de186..0194cbe 100644
@@ -50,6 +50,7 @@ enum {
 enum {
 	NFT_EXPR_META_KEY	= NFT_RULE_EXPR_ATTR_BASE,
 	NFT_EXPR_META_DREG,
+	NFT_EXPR_META_SREG,
 };
 
 enum {
include/linux/netfilter/nf_tables.h +3 -1
index fbfd229..4a02b8b 100644
@@ -552,12 +552,14 @@ enum nft_meta_keys {
  * enum nft_meta_attributes - nf_tables meta expression netlink attributes
  *
  * @NFTA_META_DREG: destination register (NLA_U32)
- * @NFTA_META_KEY: meta data item to load (NLA_U32: nft_meta_keys)
+ * @NFTA_META_KEY: meta data item to load or set (NLA_U32: nft_meta_keys)
+ * @NFTA_META_SREG: source register (NLA_U32)
  */
 enum nft_meta_attributes {
 	NFTA_META_UNSPEC,
 	NFTA_META_DREG,
 	NFTA_META_KEY,
+	NFTA_META_SREG,
 	__NFTA_META_MAX
 };
 #define NFTA_META_MAX		(__NFTA_META_MAX - 1)
src/expr/meta.c +92 -24

191 lines not on this page · raw message

tests/jsonfiles/65-rule-meta-target.json new file +1 -0
new file mode 100644
index 0000000..d058a1f
@@ -0,0 +1 @@
+{"rule":{"family":"ip","table":"filter","chain":"output","handle":1,"expr":[{"type":"meta","key":"mark","sreg":1},{"type":"cmp","sreg":1,"op":"eq","cmpdata":{"data_reg":{"type":"value","len":4,"data0":"0x000003e8"}}},{"type":"counter","pkts":0,"bytes":0}]}}
tests/xmlfiles/76-rule-meta_target.xml new file +1 -0
new file mode 100644
index 0000000..0c48ca5
@@ -0,0 +1 @@
+<rule><family>ip6</family><table>filter</table><chain>test</chain><handle>129</handle><expr type="meta"><key>mark</key><sreg>1</sreg></expr></rule>
maintainer Applied
#1 lore raw
Quoted 4 lines · Arturo Borrero Gonzalez

This patch adds userspace support for the meta expression in the set flavour.

This expression indicates that the packet has to be set with a property, currently one of mark, priority or nftrace.

Applied to next-3.14, thanks!