netfilter: nf_tables Add set op to nft_ct module
Subsystems (2)
PATCH 1/1 netfilter: nf_tables Add set op to nft_ct module
From: Kristian Evensen <[email protected]>
This patch adds kernel support for setting properties of tracked connections. Currently, only connmark is supported. One use-case for this feature is to provide the same functionality as -j CONNMARK --save-mark in iptables.
Some restructuring was needed to implement the set op. The new structure follows that of nft_meta.
--- include/uapi/linux/netfilter/nf_tables.h | 2 + net/netfilter/nft_ct.c | 161 +++++++++++++++++++++++++------ 2 files changed, 132 insertions(+), 31 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -605,12 +605,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)
net/netfilter/nft_ct.c +130 -31
221 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Florian Westphal
maintainerQuoted 10 lines · Kristian Evensen
net/netfilter/nft_ct.c +10
-0+static void nft_ct_set_eval (const struct nft_expr *expr, +struct nft_data data[NFT_REG_MAX +1 ], +const struct nft_pktinfo *pkt) +{ +const struct nft_ct *priv =nft_expr_priv (expr); +struct sk_buff *skb = pkt->skb; +u32 value = data[priv->sreg].data[0 ]; +enum ip_conntrack_info ctinfo; +struct nf_conn *ct; +
net/netfilter/nft_ct.c err: · line 149
Quoted 10 lines
net/netfilter/nft_ct.c +10
-0+ ct =nf_ct_get (skb, &ctinfo); + +if (ct ==NULL ) +return ; + +switch (priv->key) { +#ifdef CONFIG_NF_CONNTRACK_MARK +case NFT_CT_MARK : + ct->mark = value; +nf_conntrack_event_cache (IPCT_MARK , ct);
I think the event should only be raised when the mark value is altered, else one might get nfct event storm.
Thank you. I forgot to add the check for mark != value. I will submit a new version.
-Kristian
Quoted 24 lines · Florian Westphal
Quoted 10 lines · Kristian Evensen
net/netfilter/nft_ct.c +10
-0+static void nft_ct_set_eval (const struct nft_expr *expr, +struct nft_data data[NFT_REG_MAX +1 ], +const struct nft_pktinfo *pkt) +{ +const struct nft_ct *priv =nft_expr_priv (expr); +struct sk_buff *skb = pkt->skb; +u32 value = data[priv->sreg].data[0 ]; +enum ip_conntrack_info ctinfo; +struct nf_conn *ct; +net/netfilter/nft_ct.c err: · line 149
Quoted 10 lines
net/netfilter/nft_ct.c +10
-0+ ct =nf_ct_get (skb, &ctinfo); + +if (ct ==NULL ) +return ; + +switch (priv->key) { +#ifdef CONFIG_NF_CONNTRACK_MARK +case NFT_CT_MARK : + ct->mark = value; +nf_conntrack_event_cache (IPCT_MARK , ct);I think the event should only be raised when the mark value is altered, else one might get nfct event storm.