Add support for ct set
PATCH 1/1 Add support for ct set
From: Kristian Evensen <[email protected]>
This patch adds userspace support for setting properties of tracked connections. Currently, the connection mark is supported. This can be used to implemented the same functionality as iptables -j CONNMARK --save-mark.
--- include/libnftables/expr.h | 1 + include/linux/netfilter/nf_tables.h | 2 + src/expr/ct.c | 118 ++++++++++++++++++++++++++++-------- 3 files changed, 96 insertions(+), 25 deletions(-)
include/libnftables/expr.h +1 -0
@@ -124,6 +124,7 @@ enum {NFT_EXPR_CT_DREG =NFT_RULE_EXPR_ATTR_BASE ,NFT_EXPR_CT_KEY ,NFT_EXPR_CT_DIR , + NFT_EXPR_CT_SREG, }; enum {
include/linux/netfilter/nf_tables.h +2 -0
@@ -526,12 +526,14 @@ enum nft_ct_keys {* @NFTA_CT_DREG: destination register (NLA_U32) * @NFTA_CT_KEY: conntrack data item to load (NLA_U32: nft_ct_keys) * @NFTA_CT_DIRECTION: direction in case of directional keys (NLA_U8) +* @NFTA_CT_SREG: source register (NLA_U32) */ enum nft_ct_attributes {NFTA_CT_UNSPEC ,NFTA_CT_DREG ,NFTA_CT_KEY ,NFTA_CT_DIRECTION , +NFTA_CT_SREG , __NFTA_CT_MAX };#define NFTA_CT_MAX (__NFTA_CT_MAX - 1)
src/expr/ct.c +93 -25
198 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Quoted 2 lines · Kristian Evensen
From: Kristian Evensen <[email protected]>
Hi Kristian,
some minor comments below.
Quoted 10 lines
This patch adds userspace support for setting properties of tracked connections. Currently, the connection mark is supported. This can be used to implemented the same functionality as iptables -j CONNMARK --save-mark.
Signed-off-by Kristian Evensen <[email protected]>src/expr/ct.c +0
-0
src/expr/ct.c line 27
Quoted 5 lines
src/expr/ct.c +1
-1@@ -24,7 +24,10 @@struct nft_expr_ct {enum nft_ct_keys key; -uint32_t dreg;/* enum nft_registers */ +union {
note the missing space after union definition.
Quoted 9 lines
src/expr/ct.c +3
-2@@ -235,11 +257,17 @@ static int nft_rule_expr_ct_xml_parse(struct nft_rule_expr *e, mxml_node_t *treeuint8_t dir; reg =nft_mxml_reg_parse (tree,"dreg" ,MXML_DESCEND_FIRST ); -if (reg <0 ) -return -1 ; +if (reg >=0 ) { + ct->dreg = reg; + e->flags |= (1 <<NFT_EXPR_CT_DREG );
src/expr/ct.c static int nft_rule_expr_ct_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree · line 270
Quoted 10 lines
src/expr/ct.c +7
-2+ }else { + reg =nft_mxml_reg_parse (tree,"sreg" ,MXML_DESCEND_FIRST ); +if (reg <0 ) +return -1 ; - ct->dreg = reg; - e->flags |= (1 <<NFT_EXPR_CT_DREG ); + ct->sreg = reg; + e->flags |= (1 <<NFT_EXPR_CT_SREG ); + }
Looking at this, I think we should fail if neither dreg nor sreg are present. I guess we need at least one of two and if not, the expression is invalid. Also in JSON parsing.
A similar improvement is required in src/expr/meta.c
regards
Signature · 5 lines
Arturo Borrero González -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Arturo,
Thank you very much for your comments.
Quoted 3 lines · Arturo Borrero Gonzalez
Looking at this, I think we should fail if neither dreg nor sreg are present. I guess we need at least one of two and if not, the expression is invalid. Also in JSON parsing.
Both meta and my patch fails if this is the case when XML is parsed. If the dreg-parse call fails, then sreg is checked. If the sreg-parse call also fails, then -1 is returned. The JSON parsing has this issue though, so I will fix it in the next version of the patch.
-Kristian