ct helper object name matching
Subsystems (2)
Pablo Neira Ayuso
maintainercover ct helper object name matching
Hi,
[ Compile tested-only and userspace update is missing ]
This patchset adds NFT_CT_HELPER_OBJNAME to match on the helper object name, ie.
From nftables, existing (inconsistent) syntax can be left in place for backward compatibility. The new proposed syntax would more explicitly refer to match the user wants to do, e.g.
ct helper name set "ftp-21"
ct helper name "ftp-21"
For NFT_CT_HELPER_TYPE (formerly NFT_CT_HELPER), syntax would be:
ct helper type "ftp"
It should be also possible to support for:
ct helper type set "ftp"
via implicit object, this infrastructure is missing in the kernel though, the idea would be to create an implicit object that is attached to the rule. Such object would be released when the rule is removed.
Let me know.
Pablo Neira Ayuso (2):
netfilter: nftables: rename NFT_CT_HELPER to NFT_CT_HELPER_TYPE
netfilter: nftables: add NFT_CT_HELPER_OBJNAME
include/net/netfilter/nf_conntrack_helper.h | 1 + include/uapi/linux/netfilter/nf_tables.h | 7 +++-- net/netfilter/nf_conntrack_helper.c | 1 + net/netfilter/nft_ct.c | 30 +++++++++++++++++---- 4 files changed, 32 insertions(+), 7 deletions(-)
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 1/2 netfilter: nftables: rename NFT_CT_HELPER to NFT_CT_HELPER_TYPE
The existing NFT_CT_HELPER allows to match on the helper type, rename this attribute to support for matching on the helper object name.
NFT_CT_HELPER is left in place for backward compatibility.
--- include/uapi/linux/netfilter/nf_tables.h | 5 +++-- net/netfilter/nft_ct.c | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-)
include/uapi/linux/netfilter/nf_tables.h +3 -2
@@ -1047,7 +1047,7 @@ enum nft_socket_keys {* @NFT_CT_MARK: conntrack mark value * @NFT_CT_SECMARK: conntrack secmark value * @NFT_CT_EXPIRATION: relative conntrack expiration time in ms -* @NFT_CT_HELPER: connection tracking helper assigned to conntrack +* @NFT_CT_HELPER_TYPE: connection tracking helper type assigned to conntrack * @NFT_CT_L3PROTOCOL: conntrack layer 3 protocol * @NFT_CT_SRC: conntrack layer 3 protocol source (IPv4/IPv6 address, deprecated) * @NFT_CT_DST: conntrack layer 3 protocol destination (IPv4/IPv6 address, deprecated)
@@ -1073,7 +1073,8 @@ enum nft_ct_keys {NFT_CT_MARK ,NFT_CT_SECMARK ,NFT_CT_EXPIRATION , -NFT_CT_HELPER , +NFT_CT_HELPER_TYPE , +#define NFT_CT_HELPER NFT_CT_HELPER_TYPENFT_CT_L3PROTOCOL ,NFT_CT_SRC , NFT_CT_DST,
net/netfilter/nft_ct.c +2 -2
@@ -107,7 +107,7 @@ static void nft_ct_get_eval(const struct nft_expr *expr,case NFT_CT_EXPIRATION : *dest =jiffies_to_msecs (nf_ct_expires (ct));return ; -case NFT_CT_HELPER : +case NFT_CT_HELPER_TYPE :if (ct->master ==NULL ) goto err; help =nfct_help (ct->master);
@@ -418,7 +418,7 @@ static int nft_ct_get_init(const struct nft_ctx *ctx, len =NF_CT_LABELS_MAX_SIZE ;break ;#endif -case NFT_CT_HELPER : +case NFT_CT_HELPER_TYPE :if (tb[NFTA_CT_DIRECTION ] !=NULL )return -EINVAL ; len =NF_CT_HELPER_NAME_LEN ;
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerPATCH 2/2 netfilter: nftables: add NFT_CT_HELPER_OBJNAME
In reply to Pablo Neira AyusoConntrack helper assignments refer to the helper object name, while NFT_CT_HELPER (now NFT_CT_HELPER_TYPE) refers to the helper type.
This patch allows to match on helper object name so the ct helper matching and the assignment are consistent.
--- include/net/netfilter/nf_conntrack_helper.h | 1 + include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nf_conntrack_helper.c | 1 + net/netfilter/nft_ct.c | 26 ++++++++++++++++++--- 4 files changed, 27 insertions(+), 3 deletions(-)
include/net/netfilter/nf_conntrack_helper.h +1 -0
@@ -70,6 +70,7 @@ struct nf_conntrack_helper {struct nf_conn_help {/* Helper. if any */ struct nf_conntrack_helper __rcu *helper; +const char *objname;struct hlist_head expectations;
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -1065,6 +1065,7 @@ enum nft_socket_keys {* @NFT_CT_SRC_IP6: conntrack layer 3 protocol source (IPv6 address) * @NFT_CT_DST_IP6: conntrack layer 3 protocol destination (IPv6 address) * @NFT_CT_ID: conntrack id +* @NFT_CT_HELPER_OBJNAME: connection tracking helper object assigned to conntrack */ enum nft_ct_keys {NFT_CT_STATE ,
@@ -1092,6 +1093,7 @@ enum nft_ct_keys {NFT_CT_SRC_IP6 ,NFT_CT_DST_IP6 ,NFT_CT_ID , +NFT_CT_HELPER_OBJNAME , __NFT_CT_MAX };#define NFT_CT_MAX (__NFT_CT_MAX - 1)
net/netfilter/nf_conntrack_helper.c +1 -0
@@ -311,6 +311,7 @@ void nf_ct_helper_destroy(struct nf_conn *ct)if (helper && helper->destroy) helper->destroy (ct);rcu_read_unlock (); +kfree (help->objname); } }
net/netfilter/nft_ct.c +23 -3
@@ -219,6 +219,17 @@ static void nft_ct_get_eval(const struct nft_expr *expr, goto err;memcpy (dest, tuple->dst.u3.ip6,sizeof (struct in6_addr ));return ; +case NFT_CT_HELPER_OBJNAME : +if (!ct->master) + goto err; + help =nfct_help (ct->master); +if (!help) + goto err; + helper =rcu_dereference (help->helper); +if (!helper || !help->objname) + goto err; +strncpy ((char *)dest, help->objname,NF_CT_HELPER_NAME_LEN ); +return ;default :break ; }
@@ -1063,6 +1074,7 @@ static void nft_ct_helper_obj_eval(struct nft_object *obj,struct nf_conn *ct = (struct nf_conn *)skb_nfct (pkt->skb);struct nf_conntrack_helper *to_assign =NULL ;struct nf_conn_help *help; +const char *objname; if (!ct || nf_ct_is_confirmed(ct) ||
@@ -1088,11 +1100,19 @@ static void nft_ct_helper_obj_eval(struct nft_object *obj,if (test_bit (IPS_HELPER_BIT , &ct->status))return ; + objname =kstrdup (obj->key.name,GFP_ATOMIC ); +if (!objname) +return ; + help =nf_ct_helper_ext_add (ct,GFP_ATOMIC ); -if (help) { -rcu_assign_pointer (help->helper, to_assign); -set_bit (IPS_HELPER_BIT , &ct->status); +if (!help) { +kfree (objname); +return ; } + + help->objname = objname; +rcu_assign_pointer (help->helper, to_assign); +set_bit (IPS_HELPER_BIT , &ct->status); } static int nft_ct_helper_obj_dump(struct sk_buff *skb,
Signature · 1 line
2.20.1
Florian Westphal
maintainerQuoted 5 lines · Pablo Neira Ayuso
From nftables, existing (inconsistent) syntax can be left in place for backward compatibility. The new proposed syntax would more explicitly refer to match the user wants to do, e.g.
ct helper name set "ftp-21"
That would be same as 'ct helper set "ftp-21" that we use at the moment, i.e. this generates same byte code, correct?
Quoted 1 line
ct helper name "ftp-21"
I see, kernel ct extension gains a pointer to the objref name.
Quoted 3 lines
For
NFT_CT_HELPER_TYPE(formerlyNFT_CT_HELPER), syntax would be:ct helper type "ftp"
That would be the 'new' name for existing 'ct helper', so same bytecode, correct?
Quoted 3 lines
It should be also possible to support for:
ct helper type set "ftp"
IIRC another argument for objref usage was that this won't work with set infra.
Quoted 3 lines
via implicit object, this infrastructure is missing in the kernel though, the idea would be to create an implicit object that is attached to the rule. Such object would be released when the rule is removed.
Ah, I see.
Yes, that would work.
Quoted 1 line
Let me know.
Looks good to me.
Pablo Neira Ayuso
maintainerQuoted 9 lines · Florian Westphal
Quoted 5 lines · Pablo Neira Ayuso
From nftables, existing (inconsistent) syntax can be left in place for backward compatibility. The new proposed syntax would more explicitly refer to match the user wants to do, e.g.
ct helper name set "ftp-21"
That would be same as 'ct helper set "ftp-21" that we use at the moment, i.e. this generates same byte code, correct?
Yes.
Quoted 10 lines
Quoted 1 line
ct helper name "ftp-21"
I see, kernel ct extension gains a pointer to the objref name.
Quoted 3 lines
For
NFT_CT_HELPER_TYPE(formerlyNFT_CT_HELPER), syntax would be:ct helper type "ftp"
That would be the 'new' name for existing 'ct helper', so same bytecode, correct?
Yes.
Quoted 6 lines
Quoted 3 lines
It should be also possible to support for:
ct helper type set "ftp"
IIRC another argument for objref usage was that this won't work with set infra.
Right. The (missing) implicit object support would make it fit into the set infrastructure.
Quoted 11 lines
Quoted 3 lines
via implicit object, this infrastructure is missing in the kernel though, the idea would be to create an implicit object that is attached to the rule. Such object would be released when the rule is removed.
Ah, I see.
Yes, that would work.
Quoted 1 line
Let me know.
Looks good to me.
Thanks for reviewing.