netfilter: ctnetlink: attach expectations to unconfirmed conntracks
Subsystems (3)
Pablo Neira Ayuso
maintainerPATCH 1/3 netfilter: ctnetlink: attach expectations to unconfirmed conntracks
This patch adds the capability to attach expectations to unconfirmed conntrack entries. This patch is required by the DHCPv6 helper in user-space.
--- include/net/netfilter/nf_conntrack.h | 4 ++++ include/uapi/linux/netfilter/nfnetlink_conntrack.h | 1 + net/netfilter/nf_conntrack_core.c | 20 ++++++++++++++++++++ net/netfilter/nf_conntrack_netlink.c | 14 ++++++++++++-- 4 files changed, 37 insertions(+), 2 deletions(-)
include/net/netfilter/nf_conntrack.h +4 -0
@@ -180,6 +180,10 @@ extern struct nf_conntrack_tuple_hash * __nf_conntrack_find(struct net *net, u16 zone, const struct nf_conntrack_tuple *tuple); +struct nf_conntrack_tuple_hash * +nf_ct_unconfirmed_find (struct net *net,u16 zone, +const struct nf_conntrack_tuple *tuple); +extern int nf_conntrack_hash_check_insert (struct nf_conn *ct);extern void nf_ct_delete_from_lists (struct nf_conn *ct);extern void nf_ct_dying_timeout (struct nf_conn *ct);
include/uapi/linux/netfilter/nfnetlink_conntrack.h +1 -0
@@ -187,6 +187,7 @@ enum ctattr_expect {CTA_EXPECT_CLASS ,CTA_EXPECT_NAT ,CTA_EXPECT_FN , +CTA_EXPECT_MASTER_STATUS , __CTA_EXPECT_MAX };#define CTA_EXPECT_MAX (__CTA_EXPECT_MAX - 1)
net/netfilter/nf_conntrack_core.c +20 -0
@@ -401,6 +401,26 @@ nf_conntrack_find_get(struct net *net, u16 zone, }EXPORT_SYMBOL_GPL (nf_conntrack_find_get); +struct nf_conntrack_tuple_hash * +nf_ct_unconfirmed_find (struct net *net,u16 zone, +const struct nf_conntrack_tuple *tuple) +{ +struct nf_conntrack_tuple_hash *h, *ret =NULL ; +struct hlist_nulls_node *n; + +rcu_read_lock (); +hlist_nulls_for_each_entry_rcu (h, n, &net->ct.unconfirmed, hnnode) { +if (nf_ct_tuple_equal (tuple, &h->tuple) && +nf_ct_zone (nf_ct_tuplehash_to_ctrack (h)) == zone) { + ret = h; +break ; + } + } +rcu_read_unlock (); +return ret; +} +EXPORT_SYMBOL_GPL (nf_ct_unconfirmed_find); +static void __nf_conntrack_hash_insert (struct nf_conn *ct,unsigned int hash,unsigned int repl_hash)
net/netfilter/nf_conntrack_netlink.c +12 -2
@@ -2742,7 +2742,7 @@ ctnetlink_create_expect(struct net *net, u16 zone,struct nf_conn *ct;struct nf_conn_help *help;struct nf_conntrack_helper *helper =NULL ; -u_int32_t class =0 ; +u_int32_t class =0 , master_status;int err =0 ;/* caller guarantees that those three CTA_EXPECT_* exist */
@@ -2756,8 +2756,18 @@ ctnetlink_create_expect(struct net *net, u16 zone,if (err <0 )return err; +if (cda[CTA_EXPECT_MASTER_STATUS ]) { + master_status = +ntohl (nla_get_be32 (cda[CTA_EXPECT_MASTER_STATUS ])); + }else + master_status =IPS_CONFIRMED ; +/* Look for master conntrack of this expectation */ - h =nf_conntrack_find_get (net, zone, &master_tuple); +if (master_status &IPS_CONFIRMED ) + h =nf_conntrack_find_get (net, zone, &master_tuple); +else + h =nf_ct_unconfirmed_find (net, zone, &master_tuple); +if (!h)return -ENOENT ; ct =nf_ct_tuplehash_to_ctrack (h);
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/3 netfilter: don't panic on error while walking through the init path
Don't panic if we hit an error while adding the nf_log or pernet netfilter support, just bail out.
--- net/netfilter/core.c | 19 ++++++++++++++----- net/netfilter/nf_log.c | 5 +---- 2 files changed, 15 insertions(+), 9 deletions(-)
net/netfilter/core.c +14 -5
@@ -304,15 +304,24 @@ static struct pernet_operations netfilter_net_ops = {void __init netfilter_init (void ) { -int i, h; +int i, h, ret; +for (i =0 ; i <ARRAY_SIZE (nf_hooks); i++) {for (h =0 ; h <NF_MAX_HOOKS ; h++)INIT_LIST_HEAD (&nf_hooks[i][h]); } -if (register_pernet_subsys (&netfilter_net_ops) <0 ) -panic ("cannot create netfilter proc entry" ); + ret =register_pernet_subsys (&netfilter_net_ops); +if (ret <0 ) + goto err; + + ret =netfilter_log_init (); +if (ret <0 ) + goto err_pernet; -if (netfilter_log_init () <0 ) -panic ("cannot initialize nf_log" ); +return 0 ; +err_pernet: +unregister_pernet_subsys (&netfilter_net_ops); +err: +return ret; }
net/netfilter/nf_log.c +1 -4
@@ -368,10 +368,7 @@ static int __net_init nf_log_net_init(struct net *net)return 0 ; out_sysctl: -/* For init_net: errors will trigger panic, don't unroll on error. */ -if (!net_eq (net, &init_net)) -remove_proc_entry ("nf_log" , net->nf.proc_netfilter); - +remove_proc_entry ("nf_log" , net->nf.proc_netfilter);return ret; }
Signature · 1 line
1.7.10.4
Re: [PATCH 2/3] netfilter: don't panic on error while walking through the init path
Quoted 5 lines · Pablo Neira Ayuso
Don't panic if we hit an error while adding the
nf_logor pernet netfilter support, just bail out.Signed-off-by Pablo Neira Ayuso <[email protected]>---
Quoted 55 lines
net/netfilter/core.c | 19 ++++++++++++++----- net/netfilter/nf_log.c | 5 +---- 2 files changed, 15 insertions(+), 9 deletions(-)net/netfilter/core.c +14
-5@@ -304,15 +304,24 @@ static struct pernet_operations netfilter_net_ops = {void __init netfilter_init (void ) { -int i, h; +int i, h, ret; +for (i =0 ; i <ARRAY_SIZE (nf_hooks); i++) {for (h =0 ; h <NF_MAX_HOOKS ; h++)INIT_LIST_HEAD (&nf_hooks[i][h]); } -if (register_pernet_subsys (&netfilter_net_ops) <0 ) -panic ("cannot create netfilter proc entry" ); + ret =register_pernet_subsys (&netfilter_net_ops); +if (ret <0 ) + goto err; + + ret =netfilter_log_init (); +if (ret <0 ) + goto err_pernet; -if (netfilter_log_init () <0 ) -panic ("cannot initialize nf_log" ); +return 0 ; +err_pernet: +unregister_pernet_subsys (&netfilter_net_ops); +err: +return ret; }net/netfilter/nf_log.c +1
-4@@ -368,10 +368,7 @@ static int __net_init nf_log_net_init(struct net *net)return 0 ; out_sysctl: -/* For init_net: errors will trigger panic, don't unroll on error. */ -if (!net_eq (net, &init_net)) -remove_proc_entry ("nf_log" , net->nf.proc_netfilter); - +remove_proc_entry ("nf_log" , net->nf.proc_netfilter);return ret; }
Re: [PATCH 2/3] netfilter: don't panic on error while walking through the init path
Quoted 8 lines · Gao feng
Quoted 5 lines · Pablo Neira Ayuso
Don't panic if we hit an error while adding the
nf_logor pernet netfilter support, just bail out.Signed-off-by Pablo Neira Ayuso <[email protected]>---
Acked-by Gao feng <[email protected]>
Applied.
Pablo Neira Ayuso
maintainerPATCH 3/3 netfilter: {ipt,ebt}_ULOG: rise warning on deprecation
In reply to Pablo Neira AyusoThis target has been superseded by NFLOG. Spot a warning so we prepare removal in a couple of years.
--- include/net/netns/x_tables.h | 6 ++++++ net/bridge/netfilter/ebt_ulog.c | 6 ++++++ net/ipv4/netfilter/Kconfig | 2 +- net/ipv4/netfilter/ipt_ULOG.c | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-)
include/net/netns/x_tables.h +6 -0
@@ -15,5 +15,11 @@ struct netns_xt {struct ebt_table *frame_filter;struct ebt_table *frame_nat;#endif +#if IS_ENABLED (CONFIG_IP_NF_TARGET_ULOG ) +bool ulog_warn_deprecated; +#endif +#if IS_ENABLED (CONFIG_BRIDGE_EBT_ULOG ) +bool ebt_ulog_warn_deprecated; +#endif };#endif
net/bridge/netfilter/ebt_ulog.c +6 -0
@@ -267,6 +267,12 @@ static int ebt_ulog_tg_check(const struct xt_tgchk_param *par) {struct ebt_ulog_info *uloginfo = par->targinfo; +if (!par->net->nf.ebt_ulog_warn_deprecated) { +pr_info ("ebt_ulog is deprecated and it will be removed soon, " +"use ebt_nflog instead\n" ); + par->net->nf.ebt_ulog_warn_deprecated = true; + } +if (uloginfo->nlgroup >31 )return -EINVAL ;
net/ipv4/netfilter/Kconfig +1 -1
@@ -111,7 +111,7 @@ config IP_NF_TARGET_REJECT To compile it as a module, choose M here. If unsure, say N. config IP_NF_TARGET_ULOG - tristate "ULOG target support" + tristate "ULOG target support (obsolete)" default m if NETFILTER_ADVANCED=n ---help---
net/ipv4/netfilter/ipt_ULOG.c +6 -0
@@ -325,6 +325,12 @@ static int ulog_tg_check(const struct xt_tgchk_param *par) {const struct ipt_ulog_info *loginfo = par->targinfo; +if (!par->net->xt.ulog_warn_deprecated) { +pr_info ("ULOG is deprecated and it will be removed soon, " +"use NFLOG instead\n" ); + par->net->xt.ulog_warn_deprecated = true; + } +if (loginfo->prefix[sizeof (loginfo->prefix) -1 ] !='\0' ) {pr_debug ("prefix not null-terminated\n" );return -EINVAL ;
Signature · 1 line
1.7.10.4
Re: [PATCH 3/3] netfilter: {ipt,ebt}_ULOG: rise warning on deprecation
Quoted 32 lines · Pablo Neira Ayuso
This target has been superseded by NFLOG. Spot a warning so we prepare removal in a couple of years.
Signed-off-by Pablo Neira Ayuso <[email protected]>--- include/net/netns/x_tables.h | 6 ++++++ net/bridge/netfilter/ebt_ulog.c | 6 ++++++ net/ipv4/netfilter/Kconfig | 2 +- net/ipv4/netfilter/ipt_ULOG.c | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-)include/net/netns/x_tables.h +6
-0@@ -15,5 +15,11 @@ struct netns_xt {struct ebt_table *frame_filter;struct ebt_table *frame_nat;#endif +#if IS_ENABLED (CONFIG_IP_NF_TARGET_ULOG ) +bool ulog_warn_deprecated; +#endif +#if IS_ENABLED (CONFIG_BRIDGE_EBT_ULOG ) +bool ebt_ulog_warn_deprecated; +#endif };#endif net/bridge/netfilter/ebt_ulog.c +0
-0
net/bridge/netfilter/ebt_ulog.c static int ebt_ulog_tg_check(const struct xt_tgchk_param *par) · line 270
Quoted 4 lines
net/bridge/netfilter/ebt_ulog.c +1
-0@@ -267,6 +267,12 @@ static int ebt_ulog_tg_check(const struct xt_tgchk_param *par) {struct ebt_ulog_info *uloginfo = par->targinfo; +if (!par->net->nf.ebt_ulog_warn_deprecated) {
par->net->xt.ebt_ulog_warn_deprecated?
anyway
Quoted 39 lines
net/bridge/netfilter/ebt_ulog.c +5
-0+pr_info ("ebt_ulog is deprecated and it will be removed soon, " +"use ebt_nflog instead\n" ); + par->net->nf.ebt_ulog_warn_deprecated = true; + } +if (uloginfo->nlgroup >31 )return -EINVAL ;net/ipv4/netfilter/Kconfig +1
-1@@ -111,7 +111,7 @@ config IP_NF_TARGET_REJECT To compile it as a module, choose M here. If unsure, say N. config IP_NF_TARGET_ULOG - tristate "ULOG target support" + tristate "ULOG target support (obsolete)" default m if NETFILTER_ADVANCED=n ---help---net/ipv4/netfilter/ipt_ULOG.c +6
-0@@ -325,6 +325,12 @@ static int ulog_tg_check(const struct xt_tgchk_param *par) {const struct ipt_ulog_info *loginfo = par->targinfo; +if (!par->net->xt.ulog_warn_deprecated) { +pr_info ("ULOG is deprecated and it will be removed soon, " +"use NFLOG instead\n" ); + par->net->xt.ulog_warn_deprecated = true; + } +if (loginfo->prefix[sizeof (loginfo->prefix) -1 ] !='\0' ) {pr_debug ("prefix not null-terminated\n" );return -EINVAL ;
Pablo Neira Ayuso
maintainerRe: [PATCH 3/3] netfilter: {ipt,ebt}_ULOG: rise warning on deprecation
Quoted 36 lines · Gao feng
Quoted 35 lines · Pablo Neira Ayuso
This target has been superseded by NFLOG. Spot a warning so we prepare removal in a couple of years.
Signed-off-by Pablo Neira Ayuso <[email protected]>--- include/net/netns/x_tables.h | 6 ++++++ net/bridge/netfilter/ebt_ulog.c | 6 ++++++ net/ipv4/netfilter/Kconfig | 2 +- net/ipv4/netfilter/ipt_ULOG.c | 6 ++++++ 4 files changed, 19 insertions(+), 1 deletion(-)include/net/netns/x_tables.h +6
-0@@ -15,5 +15,11 @@ struct netns_xt {struct ebt_table *frame_filter;struct ebt_table *frame_nat;#endif +#if IS_ENABLED (CONFIG_IP_NF_TARGET_ULOG ) +bool ulog_warn_deprecated; +#endif +#if IS_ENABLED (CONFIG_BRIDGE_EBT_ULOG ) +bool ebt_ulog_warn_deprecated; +#endif };#endif net/bridge/netfilter/ebt_ulog.c +0
-0@@ -267,6 +267,12 @@ static int ebt_ulog_tg_check(const struct xt_tgchk_param *par) {struct ebt_ulog_info *uloginfo = par->targinfo;
Quoted 3 lines
net/bridge/netfilter/ebt_ulog.c static int ebt_ulog_tg_check(const struct xt_tgchk_param *par) · line 270
Quoted 1 line
net/bridge/netfilter/ebt_ulog.c +1
-0+if (!par->net->nf.ebt_ulog_warn_deprecated) {
par->net->xt.ebt_ulog_warn_deprecated?
Fixed and applied, thanks.
Quoted 49 lines · Pablo Neira Ayuso
This patch adds the capability to attach expectations to unconfirmed conntrack entries. This patch is required by the DHCPv6 helper in user-space.
Signed-off-by Pablo Neira Ayuso <[email protected]>--- include/net/netfilter/nf_conntrack.h | 4 ++++ include/uapi/linux/netfilter/nfnetlink_conntrack.h | 1 + net/netfilter/nf_conntrack_core.c | 20 ++++++++++++++++++++ net/netfilter/nf_conntrack_netlink.c | 14 ++++++++++++-- 4 files changed, 37 insertions(+), 2 deletions(-)include/net/netfilter/nf_conntrack.h +4
-0@@ -180,6 +180,10 @@ extern struct nf_conntrack_tuple_hash * __nf_conntrack_find(struct net *net, u16 zone, const struct nf_conntrack_tuple *tuple); +struct nf_conntrack_tuple_hash * +nf_ct_unconfirmed_find (struct net *net,u16 zone, +const struct nf_conntrack_tuple *tuple); +extern int nf_conntrack_hash_check_insert (struct nf_conn *ct);extern void nf_ct_delete_from_lists (struct nf_conn *ct);extern void nf_ct_dying_timeout (struct nf_conn *ct);include/uapi/linux/netfilter/nfnetlink_conntrack.h +1
-0@@ -187,6 +187,7 @@ enum ctattr_expect {CTA_EXPECT_CLASS ,CTA_EXPECT_NAT ,CTA_EXPECT_FN , +CTA_EXPECT_MASTER_STATUS , __CTA_EXPECT_MAX };#define CTA_EXPECT_MAX (__CTA_EXPECT_MAX - 1)net/netfilter/nf_conntrack_core.c +2
-0@@ -401,6 +401,26 @@ nf_conntrack_find_get(struct net *net, u16 zone, }EXPORT_SYMBOL_GPL (nf_conntrack_find_get); +struct nf_conntrack_tuple_hash * +nf_ct_unconfirmed_find(struct net *net, u16 zone,
net/netfilter/nf_conntrack_core.c nf_conntrack_find_get(struct net *net, u16 zone, · line 415
Quoted 10 lines
net/netfilter/nf_conntrack_core.c +10
-0+ const struct nf_conntrack_tuple *tuple) +{ +struct nf_conntrack_tuple_hash *h, *ret =NULL ; +struct hlist_nulls_node *n; + +rcu_read_lock (); +hlist_nulls_for_each_entry_rcu (h, n, &net->ct.unconfirmed, hnnode) { +if (nf_ct_tuple_equal (tuple, &h->tuple) && +nf_ct_zone (nf_ct_tuplehash_to_ctrack (h)) == zone) { + ret = h;
Shouldn't we get reference of nf_ct_tuplehash_to_ctrack(h) here? ctnetlink_create_expect will call nf_ct_put to release the reference finally.
or I miss something?
Quoted 45 lines
net/netfilter/nf_conntrack_core.c +8
-0+break ; + } + } +rcu_read_unlock (); +return ret; +} +EXPORT_SYMBOL_GPL (nf_ct_unconfirmed_find); +static void __nf_conntrack_hash_insert (struct nf_conn *ct,unsigned int hash,unsigned int repl_hash)net/netfilter/nf_conntrack_netlink.c +12
-2@@ -2742,7 +2742,7 @@ ctnetlink_create_expect(struct net *net, u16 zone,struct nf_conn *ct;struct nf_conn_help *help;struct nf_conntrack_helper *helper =NULL ; -u_int32_t class =0 ; +u_int32_t class =0 , master_status;int err =0 ;/* caller guarantees that those three CTA_EXPECT_* exist */ @@ -2756,8 +2756,18 @@ ctnetlink_create_expect(struct net *net, u16 zone,if (err <0 )return err; +if (cda[CTA_EXPECT_MASTER_STATUS ]) { + master_status = +ntohl (nla_get_be32 (cda[CTA_EXPECT_MASTER_STATUS ])); + }else + master_status =IPS_CONFIRMED ; +/* Look for master conntrack of this expectation */ - h =nf_conntrack_find_get (net, zone, &master_tuple); +if (master_status &IPS_CONFIRMED ) + h =nf_conntrack_find_get (net, zone, &master_tuple); +else + h =nf_ct_unconfirmed_find (net, zone, &master_tuple); +if (!h)return -ENOENT ; ct =nf_ct_tuplehash_to_ctrack (h);