openvswitch: load and reference the NAT helper.
Subsystems (4)
cover openvswitch: load and reference the NAT helper.
The request_module() is quite expensive and triggers the usermode helper in userspace. Instead, load only if the module is not present and keep module references to avoid problems.
The first patch standardize the module alias which is already there, but not in a formal way.
The second patch adds an API to point to the NAT helper.
The following patches will register each NAT helper using the new API.
The last patch fixes openvswitch to use the new API to load and reference the NAT helper and also report an error if the operation fails.
Flavio Leitner (8):
netfilter: use macros to create module aliases.
netfilter: add API to manage NAT helpers.
netfilter: nf_nat: register amanda NAT helper.
netfilter: nf_nat: register ftp NAT helper.
netfilter: nf_nat: register irc NAT helper.
netfilter: nf_nat: register sip NAT helper.
netfilter: nf_nat: register tftp NAT helper.
openvswitch: load and reference the NAT helper.
include/net/netfilter/nf_conntrack_helper.h | 23 ++++- net/ipv4/netfilter/nf_nat_h323.c | 2 +- net/ipv4/netfilter/nf_nat_pptp.c | 2 +- net/netfilter/nf_conntrack_amanda.c | 2 + net/netfilter/nf_conntrack_ftp.c | 6 +- net/netfilter/nf_conntrack_helper.c | 108 +++++++++++++++++++- net/netfilter/nf_conntrack_irc.c | 3 +- net/netfilter/nf_conntrack_sane.c | 4 +- net/netfilter/nf_conntrack_sip.c | 12 ++- net/netfilter/nf_conntrack_tftp.c | 6 +- net/netfilter/nf_nat_amanda.c | 9 +- net/netfilter/nf_nat_ftp.c | 8 +- net/netfilter/nf_nat_irc.c | 8 +- net/netfilter/nf_nat_sip.c | 8 +- net/netfilter/nf_nat_tftp.c | 8 +- net/openvswitch/conntrack.c | 27 +++-- 16 files changed, 209 insertions(+), 27 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/8 netfilter: use macros to create module aliases.
Each NAT helper creates a module alias which follows a pattern. Use macros for consistency.
--- include/net/netfilter/nf_conntrack_helper.h | 4 ++++ net/ipv4/netfilter/nf_nat_h323.c | 2 +- net/ipv4/netfilter/nf_nat_pptp.c | 2 +- net/netfilter/nf_nat_amanda.c | 2 +- net/netfilter/nf_nat_ftp.c | 2 +- net/netfilter/nf_nat_irc.c | 2 +- net/netfilter/nf_nat_sip.c | 2 +- net/netfilter/nf_nat_tftp.c | 2 +- 8 files changed, 11 insertions(+), 7 deletions(-)
include/net/netfilter/nf_conntrack_helper.h +4 -0
@@ -15,6 +15,10 @@#include <net/netfilter/nf_conntrack_extend.h> #include <net/netfilter/nf_conntrack_expect.h> +#define NF_CT_NAT_HELPER_MOD_NAME (name) "ip_nat_" name +#define MODULE_ALIAS_NFCT_HELPER_NAT (name) \ + MODULE_ALIAS(NF_CT_NAT_HELPER_MOD_NAME(name)) +struct module ;enum nf_ct_helper_flags {
net/ipv4/netfilter/nf_nat_h323.c +1 -1
@@ -631,4 +631,4 @@ module_exit(fini);MODULE_AUTHOR ("Jing Min Zhao <[email protected]>" );MODULE_DESCRIPTION ("H.323 NAT helper" );MODULE_LICENSE ("GPL" ); -MODULE_ALIAS ("ip_nat_h323" ); +MODULE_ALIAS_NFCT_HELPER_NAT ("h323" );
net/ipv4/netfilter/nf_nat_pptp.c +1 -1
@@ -37,7 +37,7 @@MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Harald Welte <[email protected]>" );MODULE_DESCRIPTION ("Netfilter NAT helper module for PPTP" ); -MODULE_ALIAS ("ip_nat_pptp" ); +MODULE_ALIAS_NFCT_HELPER_NAT ("pptp" );static void pptp_nat_expected (struct nf_conn *ct,struct nf_conntrack_expect *exp)
net/netfilter/nf_nat_amanda.c +1 -1
@@ -22,7 +22,7 @@MODULE_AUTHOR ("Brian J. Murrell <[email protected]>" );MODULE_DESCRIPTION ("Amanda NAT helper" );MODULE_LICENSE ("GPL" ); -MODULE_ALIAS ("ip_nat_amanda" ); +MODULE_ALIAS_NFCT_HELPER_NAT ("amanda" ); static unsigned int help(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
net/netfilter/nf_nat_ftp.c +1 -1
@@ -24,7 +24,7 @@MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Rusty Russell <[email protected]>" );MODULE_DESCRIPTION ("ftp NAT helper" ); -MODULE_ALIAS ("ip_nat_ftp" ); +MODULE_ALIAS_NFCT_HELPER_NAT ("ftp" );/* FIXME: Time out? --RR */
net/netfilter/nf_nat_irc.c +1 -1
@@ -26,7 +26,7 @@MODULE_AUTHOR ("Harald Welte <[email protected]>" );MODULE_DESCRIPTION ("IRC (DCC) NAT helper" );MODULE_LICENSE ("GPL" ); -MODULE_ALIAS ("ip_nat_irc" ); +MODULE_ALIAS_NFCT_HELPER_NAT ("irc" ); static unsigned int help(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
net/netfilter/nf_nat_sip.c +1 -1
@@ -27,7 +27,7 @@MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Christian Hentschel <[email protected]>" );MODULE_DESCRIPTION ("SIP NAT helper" ); -MODULE_ALIAS ("ip_nat_sip" ); +MODULE_ALIAS_NFCT_HELPER_NAT ("sip" ); static unsigned int mangle_packet(struct sk_buff *skb, unsigned int protoff,
net/netfilter/nf_nat_tftp.c +1 -1
@@ -16,7 +16,7 @@MODULE_AUTHOR ("Magnus Boden <[email protected]>" );MODULE_DESCRIPTION ("TFTP NAT helper" );MODULE_LICENSE ("GPL" ); -MODULE_ALIAS ("ip_nat_tftp" ); +MODULE_ALIAS_NFCT_HELPER_NAT ("tftp" ); static unsigned int help(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerRe: [PATCH net-next 1/8] netfilter: use macros to create module aliases.
Quoted 20 lines · Flavio Leitner
Each NAT helper creates a module alias which follows a pattern. Use macros for consistency.
Signed-off-by Flavio Leitner <[email protected]>--- include/net/netfilter/nf_conntrack_helper.h | 4 ++++ net/ipv4/netfilter/nf_nat_h323.c | 2 +- net/ipv4/netfilter/nf_nat_pptp.c | 2 +- net/netfilter/nf_nat_amanda.c | 2 +- net/netfilter/nf_nat_ftp.c | 2 +- net/netfilter/nf_nat_irc.c | 2 +- net/netfilter/nf_nat_sip.c | 2 +- net/netfilter/nf_nat_tftp.c | 2 +- 8 files changed, 11 insertions(+), 7 deletions(-)include/net/netfilter/nf_conntrack_helper.h +0
-0
include/net/netfilter/nf_conntrack_helper.h line 18
Quoted 4 lines
include/net/netfilter/nf_conntrack_helper.h +1
-0@@ -15,6 +15,10 @@#include <net/netfilter/nf_conntrack_extend.h> #include <net/netfilter/nf_conntrack_expect.h> +#define NF_CT_NAT_HELPER_MOD_NAME (name) "ip_nat_" name
I'd suggest a rename from NF_CT_NAT_HELPER_MOD_NAME() to NF_NAT_HELPER_NAME().
Please, also use "nf_nat_" prefix instead, "ip_nat" is legacy stuff.
include/net/netfilter/nf_conntrack_helper.h line 20
Quoted 2 lines
include/net/netfilter/nf_conntrack_helper.h +2
-0+#define MODULE_ALIAS_NFCT_HELPER_NAT (name) \ + MODULE_ALIAS(NF_CT_NAT_HELPER_MOD_NAME(name))
Probably:
MODULE_ALIAS_NF_NAT_HELPER
instead of MODULE_ALIAS_NFCT_HELPER_NAT.
Re: [PATCH net-next 1/8] netfilter: use macros to create module aliases.
Quoted 24 lines · Pablo Neira Ayuso
Quoted 23 lines · Flavio Leitner
Each NAT helper creates a module alias which follows a pattern. Use macros for consistency.
Signed-off-by Flavio Leitner <[email protected]>--- include/net/netfilter/nf_conntrack_helper.h | 4 ++++ net/ipv4/netfilter/nf_nat_h323.c | 2 +- net/ipv4/netfilter/nf_nat_pptp.c | 2 +- net/netfilter/nf_nat_amanda.c | 2 +- net/netfilter/nf_nat_ftp.c | 2 +- net/netfilter/nf_nat_irc.c | 2 +- net/netfilter/nf_nat_sip.c | 2 +- net/netfilter/nf_nat_tftp.c | 2 +- 8 files changed, 11 insertions(+), 7 deletions(-)include/net/netfilter/nf_conntrack_helper.h +0
-0@@ -15,6 +15,10 @@#include <net/netfilter/nf_conntrack_extend.h> #include <net/netfilter/nf_conntrack_expect.h>
Quoted 4 lines
include/net/netfilter/nf_conntrack_helper.h line 18
Quoted 1 line
include/net/netfilter/nf_conntrack_helper.h +1
-0+#define NF_CT_NAT_HELPER_MOD_NAME (name) "ip_nat_" nameI'd suggest a rename from
NF_CT_NAT_HELPER_MOD_NAME()toNF_NAT_HELPER_NAME().
OK.
Quoted 1 line
Please, also use "
nf_nat_" prefix instead, "ip_nat" is legacy stuff.
I don't think we can, because people might be using the current alias which is ip_nat_something. This patch is just making it more robust.
Quoted 8 lines
include/net/netfilter/nf_conntrack_helper.h line 20
Quoted 2 lines
include/net/netfilter/nf_conntrack_helper.h +2
-0+#define MODULE_ALIAS_NFCT_HELPER_NAT (name) \ + MODULE_ALIAS(NF_CT_NAT_HELPER_MOD_NAME(name))Probably:
MODULE_ALIAS_NF_NAT_HELPERinstead of
MODULE_ALIAS_NFCT_HELPER_NAT.
OK.
fbl
PATCH 2/8 netfilter: add API to manage NAT helpers.
In reply to Flavio LeitnerThe API allows a conntrack helper to indicate its corresponding NAT helper which then can be loaded and reference counted.
--- include/net/netfilter/nf_conntrack_helper.h | 19 +++- net/netfilter/nf_conntrack_amanda.c | 2 + net/netfilter/nf_conntrack_ftp.c | 6 +- net/netfilter/nf_conntrack_helper.c | 108 +++++++++++++++++++- net/netfilter/nf_conntrack_irc.c | 3 +- net/netfilter/nf_conntrack_sane.c | 4 +- net/netfilter/nf_conntrack_sip.c | 12 ++- net/netfilter/nf_conntrack_tftp.c | 6 +- 8 files changed, 147 insertions(+), 13 deletions(-)
include/net/netfilter/nf_conntrack_helper.h +18 -1
@@ -58,6 +58,8 @@ struct nf_conntrack_helper {unsigned int queue_num;/* length of userspace private data stored in nf_conn_help->data */ u16 data_len; +/* name of NAT helper module */ +char nat_mod_name[NF_CT_HELPER_NAME_LEN ]; };/* Must be kept in sync with the classes defined by helpers */
@@ -98,7 +100,8 @@ void nf_ct_helper_init(struct nf_conntrack_helper *helper, enum ip_conntrack_info ctinfo), int (*from_nlattr)(struct nlattr *attr,struct nf_conn *ct), - struct module *module); + struct module *module, + const char *nat_mod_name);int nf_conntrack_helper_register (struct nf_conntrack_helper *);void nf_conntrack_helper_unregister (struct nf_conntrack_helper *);
@@ -157,4 +160,18 @@ nf_ct_helper_expectfn_find_by_symbol(const void *symbol);extern struct hlist_head *nf_ct_helper_hash;extern unsigned int nf_ct_helper_hsize; +struct nf_conntrack_helper_nat { +struct list_head list; +char name[NF_CT_HELPER_NAME_LEN ]; +struct module *module;/* pointer to self */ +}; + +void nf_ct_helper_nat_init (struct nf_conntrack_helper_nat *nat, +const char *name,struct module *module); + +void nf_conntrack_helper_nat_register (struct nf_conntrack_helper_nat *nat); +void nf_conntrack_helper_nat_unregister (struct nf_conntrack_helper_nat *nat); +int nf_conntrack_helper_nat_try_module_get (const char *name,u16 l3num, +u8 protonum); +void nf_conntrack_helper_nat_put (struct nf_conntrack_helper *helper);#endif /*_NF_CONNTRACK_HELPER_H*/
net/netfilter/nf_conntrack_amanda.c +2 -0
@@ -186,6 +186,7 @@ static struct nf_conntrack_helper amanda_helper[2] __read_mostly = { .tuple.src.u.udp.port = cpu_to_be16(10080), .tuple.dst.protonum = IPPROTO_UDP, .expect_policy = &amanda_exp_policy, + .nat_mod_name = NF_CT_NAT_HELPER_MOD_NAME("amanda"), }, { .name = "amanda",
@@ -195,6 +196,7 @@ static struct nf_conntrack_helper amanda_helper[2] __read_mostly = { .tuple.src.u.udp.port = cpu_to_be16(10080), .tuple.dst.protonum = IPPROTO_UDP, .expect_policy = &amanda_exp_policy, + .nat_mod_name = NF_CT_NAT_HELPER_MOD_NAME("amanda"), }, };
net/netfilter/nf_conntrack_ftp.c +4 -2
@@ -590,10 +590,12 @@ static int __init nf_conntrack_ftp_init(void)for (i =0 ; i < ports_c; i++) {nf_ct_helper_init (&ftp[2 * i],AF_INET ,IPPROTO_TCP ,"ftp" ,FTP_PORT , ports[i], ports[i], &ftp_exp_policy, -0 , help, nf_ct_ftp_from_nlattr,THIS_MODULE ); +0 , help, nf_ct_ftp_from_nlattr,THIS_MODULE , +NF_CT_NAT_HELPER_MOD_NAME ("ftp" ));nf_ct_helper_init (&ftp[2 * i +1 ],AF_INET6 ,IPPROTO_TCP ,"ftp" ,FTP_PORT , ports[i], ports[i], &ftp_exp_policy, -0 , help, nf_ct_ftp_from_nlattr,THIS_MODULE ); +0 , help, nf_ct_ftp_from_nlattr,THIS_MODULE , +NF_CT_NAT_HELPER_MOD_NAME ("ftp" )); } ret =nf_conntrack_helpers_register (ftp, ports_c *2 );
net/netfilter/nf_conntrack_helper.c +107 -1
144 lines not on this page · raw message
net/netfilter/nf_conntrack_irc.c +2 -1
@@ -261,7 +261,8 @@ static int __init nf_conntrack_irc_init(void)for (i =0 ; i < ports_c; i++) {nf_ct_helper_init (&irc[i],AF_INET ,IPPROTO_TCP ,"irc" ,IRC_PORT , ports[i], i, &irc_exp_policy, -0 , help,NULL ,THIS_MODULE ); +0 , help,NULL ,THIS_MODULE , +NF_CT_NAT_HELPER_MOD_NAME ("irc" )); } ret =nf_conntrack_helpers_register (&irc[0 ], ports_c);
net/netfilter/nf_conntrack_sane.c +2 -2
@@ -198,11 +198,11 @@ static int __init nf_conntrack_sane_init(void)nf_ct_helper_init (&sane[2 * i],AF_INET ,IPPROTO_TCP ,"sane" ,SANE_PORT , ports[i], ports[i], &sane_exp_policy,0 , help,NULL , -THIS_MODULE ); +THIS_MODULE ,NULL );nf_ct_helper_init (&sane[2 * i +1 ],AF_INET6 ,IPPROTO_TCP ,"sane" ,SANE_PORT , ports[i], ports[i], &sane_exp_policy,0 , help,NULL , -THIS_MODULE ); +THIS_MODULE ,NULL ); } ret =nf_conntrack_helpers_register (sane, ports_c *2 );
net/netfilter/nf_conntrack_sip.c +8 -4
@@ -1677,19 +1677,23 @@ static int __init nf_conntrack_sip_init(void)nf_ct_helper_init (&sip[4 * i],AF_INET ,IPPROTO_UDP ,"sip" ,SIP_PORT , ports[i], i, sip_exp_policy,SIP_EXPECT_MAX , sip_help_udp, -NULL ,THIS_MODULE ); +NULL ,THIS_MODULE , +NF_CT_NAT_HELPER_MOD_NAME ("sip" ));nf_ct_helper_init (&sip[4 * i +1 ],AF_INET ,IPPROTO_TCP ,"sip" ,SIP_PORT , ports[i], i, sip_exp_policy,SIP_EXPECT_MAX , sip_help_tcp, -NULL ,THIS_MODULE ); +NULL ,THIS_MODULE , +NF_CT_NAT_HELPER_MOD_NAME ("sip" ));nf_ct_helper_init (&sip[4 * i +2 ],AF_INET6 ,IPPROTO_UDP ,"sip" ,SIP_PORT , ports[i], i, sip_exp_policy,SIP_EXPECT_MAX , sip_help_udp, -NULL ,THIS_MODULE ); +NULL ,THIS_MODULE , +NF_CT_NAT_HELPER_MOD_NAME ("sip" ));nf_ct_helper_init (&sip[4 * i +3 ],AF_INET6 ,IPPROTO_TCP ,"sip" ,SIP_PORT , ports[i], i, sip_exp_policy,SIP_EXPECT_MAX , sip_help_tcp, -NULL ,THIS_MODULE ); +NULL ,THIS_MODULE , +NF_CT_NAT_HELPER_MOD_NAME ("sip" )); } ret =nf_conntrack_helpers_register (sip, ports_c *4 );
net/netfilter/nf_conntrack_tftp.c +4 -2
@@ -121,10 +121,12 @@ static int __init nf_conntrack_tftp_init(void)for (i =0 ; i < ports_c; i++) {nf_ct_helper_init (&tftp[2 * i],AF_INET ,IPPROTO_UDP ,"tftp" ,TFTP_PORT , ports[i], i, &tftp_exp_policy, -0 , tftp_help,NULL ,THIS_MODULE ); +0 , tftp_help,NULL ,THIS_MODULE , +NF_CT_NAT_HELPER_MOD_NAME ("tftp" ));nf_ct_helper_init (&tftp[2 * i +1 ],AF_INET6 ,IPPROTO_UDP ,"tftp" ,TFTP_PORT , ports[i], i, &tftp_exp_policy, -0 , tftp_help,NULL ,THIS_MODULE ); +0 , tftp_help,NULL ,THIS_MODULE , +NF_CT_NAT_HELPER_MOD_NAME ("tftp" )); } ret =nf_conntrack_helpers_register (tftp, ports_c *2 );
Signature · 1 line
2.20.1
Pablo Neira Ayuso
maintainerRe: [PATCH net-next 2/8] netfilter: add API to manage NAT helpers.
Quoted 40 lines · Flavio Leitner
The API allows a conntrack helper to indicate its corresponding NAT helper which then can be loaded and reference counted.
Signed-off-by Flavio Leitner <[email protected]>--- include/net/netfilter/nf_conntrack_helper.h | 19 +++- net/netfilter/nf_conntrack_amanda.c | 2 + net/netfilter/nf_conntrack_ftp.c | 6 +- net/netfilter/nf_conntrack_helper.c | 108 +++++++++++++++++++- net/netfilter/nf_conntrack_irc.c | 3 +- net/netfilter/nf_conntrack_sane.c | 4 +- net/netfilter/nf_conntrack_sip.c | 12 ++- net/netfilter/nf_conntrack_tftp.c | 6 +- 8 files changed, 147 insertions(+), 13 deletions(-)include/net/netfilter/nf_conntrack_helper.h +4
-1@@ -58,6 +58,8 @@ struct nf_conntrack_helper {unsigned int queue_num;/* length of userspace private data stored in nf_conn_help->data */ u16 data_len; +/* name of NAT helper module */ +char nat_mod_name[NF_CT_HELPER_NAME_LEN ]; };/* Must be kept in sync with the classes defined by helpers */ @@ -98,7 +100,8 @@ void nf_ct_helper_init(struct nf_conntrack_helper *helper, enum ip_conntrack_info ctinfo), int (*from_nlattr)(struct nlattr *attr,struct nf_conn *ct), - struct module *module); + struct module *module, + const char *nat_mod_name);int nf_conntrack_helper_register (struct nf_conntrack_helper *);void nf_conntrack_helper_unregister (struct nf_conntrack_helper *);@@ -157,4 +160,18 @@ nf_ct_helper_expectfn_find_by_symbol(const void *symbol);extern struct hlist_head *nf_ct_helper_hash;
include/net/netfilter/nf_conntrack_helper.h nf_ct_helper_expectfn_find_by_symbol(const void *symbol); · line 170
Quoted 10 lines
include/net/netfilter/nf_conntrack_helper.h +8
-0extern unsigned int nf_ct_helper_hsize; +struct nf_conntrack_helper_nat { +struct list_head list; +char name[NF_CT_HELPER_NAME_LEN ]; +struct module *module;/* pointer to self */ +}; + +void nf_ct_helper_nat_init (struct nf_conntrack_helper_nat *nat, +const char *name,struct module *module);
Instead of this nf_ct_helper_nat_init() runtime initializer, define the structure in C99 as static in the NAT helper module?
Telling this because we can probably also extend this structure to remove the RCU hook between ct helper and nat helper at some point through this new definition.
include/net/netfilter/nf_conntrack_helper.h nf_ct_helper_expectfn_find_by_symbol(const void *symbol); · line 172
Quoted 1 line
include/net/netfilter/nf_conntrack_helper.h +1
-0+void nf_conntrack_helper_nat_register (struct nf_conntrack_helper_nat *nat);
Shorter name suggestion:
nf_nat_helper_register()
include/net/netfilter/nf_conntrack_helper.h nf_ct_helper_expectfn_find_by_symbol(const void *symbol); · line 173
Quoted 1 line
include/net/netfilter/nf_conntrack_helper.h +1
-0+void nf_conntrack_helper_nat_unregister (struct nf_conntrack_helper_nat *nat);
nf_nat_helper_unregister()
include/net/netfilter/nf_conntrack_helper.h nf_ct_helper_expectfn_find_by_symbol(const void *symbol); · line 175
Quoted 2 lines
include/net/netfilter/nf_conntrack_helper.h +2
-0+int nf_conntrack_helper_nat_try_module_get (const char *name,u16 l3num, +u8 protonum);
nf_nat_helper_try_module_get()
include/net/netfilter/nf_conntrack_helper.h nf_ct_helper_expectfn_find_by_symbol(const void *symbol); · line 176
Quoted 1 line
include/net/netfilter/nf_conntrack_helper.h +1
-0+void nf_conntrack_helper_nat_put (struct nf_conntrack_helper *helper);
nf_nat_helper_nat_put()
Re: [PATCH net-next 2/8] netfilter: add API to manage NAT helpers.
Quoted 55 lines · Pablo Neira Ayuso
Quoted 40 lines · Flavio Leitner
The API allows a conntrack helper to indicate its corresponding NAT helper which then can be loaded and reference counted.
Signed-off-by Flavio Leitner <[email protected]>--- include/net/netfilter/nf_conntrack_helper.h | 19 +++- net/netfilter/nf_conntrack_amanda.c | 2 + net/netfilter/nf_conntrack_ftp.c | 6 +- net/netfilter/nf_conntrack_helper.c | 108 +++++++++++++++++++- net/netfilter/nf_conntrack_irc.c | 3 +- net/netfilter/nf_conntrack_sane.c | 4 +- net/netfilter/nf_conntrack_sip.c | 12 ++- net/netfilter/nf_conntrack_tftp.c | 6 +- 8 files changed, 147 insertions(+), 13 deletions(-)include/net/netfilter/nf_conntrack_helper.h +4
-1@@ -58,6 +58,8 @@ struct nf_conntrack_helper {unsigned int queue_num;/* length of userspace private data stored in nf_conn_help->data */ u16 data_len; +/* name of NAT helper module */ +char nat_mod_name[NF_CT_HELPER_NAME_LEN ]; };/* Must be kept in sync with the classes defined by helpers */ @@ -98,7 +100,8 @@ void nf_ct_helper_init(struct nf_conntrack_helper *helper, enum ip_conntrack_info ctinfo), int (*from_nlattr)(struct nlattr *attr,struct nf_conn *ct), - struct module *module); + struct module *module, + const char *nat_mod_name);int nf_conntrack_helper_register (struct nf_conntrack_helper *);void nf_conntrack_helper_unregister (struct nf_conntrack_helper *);@@ -157,4 +160,18 @@ nf_ct_helper_expectfn_find_by_symbol(const void *symbol);extern struct hlist_head *nf_ct_helper_hash;include/net/netfilter/nf_conntrack_helper.h nf_ct_helper_expectfn_find_by_symbol(const void *symbol); · line 170
Quoted 10 lines
include/net/netfilter/nf_conntrack_helper.h +8
-0extern unsigned int nf_ct_helper_hsize; +struct nf_conntrack_helper_nat { +struct list_head list; +char name[NF_CT_HELPER_NAME_LEN ]; +struct module *module;/* pointer to self */ +}; + +void nf_ct_helper_nat_init (struct nf_conntrack_helper_nat *nat, +const char *name,struct module *module);Instead of this
nf_ct_helper_nat_init()runtime initializer, define the structure in C99 as static in the NAT helper module?
Quoted 3 lines
Telling this because we can probably also extend this structure to remove the RCU hook between ct helper and nat helper at some point through this new definition.
Sounds good, let me try that.
Quoted 10 lines
include/net/netfilter/nf_conntrack_helper.h nf_ct_helper_expectfn_find_by_symbol(const void *symbol); · line 172
Quoted 1 line
include/net/netfilter/nf_conntrack_helper.h +1
-0+void nf_conntrack_helper_nat_register (struct nf_conntrack_helper_nat *nat);Shorter name suggestion:
nf_nat_helper_register()include/net/netfilter/nf_conntrack_helper.h nf_ct_helper_expectfn_find_by_symbol(const void *symbol); · line 173
Quoted 1 line
include/net/netfilter/nf_conntrack_helper.h +1
-0+void nf_conntrack_helper_nat_unregister (struct nf_conntrack_helper_nat *nat);
nf_nat_helper_unregister()
Quoted 8 lines
include/net/netfilter/nf_conntrack_helper.h nf_ct_helper_expectfn_find_by_symbol(const void *symbol); · line 175
Quoted 2 lines
include/net/netfilter/nf_conntrack_helper.h +2
-0+int nf_conntrack_helper_nat_try_module_get (const char *name,u16 l3num, +u8 protonum);
nf_nat_helper_try_module_get()include/net/netfilter/nf_conntrack_helper.h nf_ct_helper_expectfn_find_by_symbol(const void *symbol); · line 176
Quoted 1 line
include/net/netfilter/nf_conntrack_helper.h +1
-0+void nf_conntrack_helper_nat_put (struct nf_conntrack_helper *helper);nf_nat_helper_nat_put()
Ok to all the above.
Thanks,
fbl
Pablo Neira Ayuso
maintainerRe: [PATCH net-next 2/8] netfilter: add API to manage NAT helpers.
In reply to Flavio LeitnerOn Tue, Mar 26, 2019 at 05:57:09PM -0300, Flavio Leitner wrote:
[...]
net/netfilter/nf_conntrack_helper.c module_param_named(nf_conntrack_helper, nf_ct_auto_assign_helper, bool, 0644); · line 46
Quoted 10 lines
net/netfilter/nf_conntrack_helper.c +2
-0@@ -42,6 +42,9 @@ module_param_named(nf_conntrack_helper, nf_ct_auto_assign_helper, bool, 0644);MODULE_PARM_DESC (nf_conntrack_helper,"Enable automatic conntrack helper assignment (default 0)" ); +static struct list_head nf_ct_nat_helpers__read_mostly ; +static DEFINE_SPINLOCK (nf_ct_nat_helpers_lock);
Why a spinlock here? Use mutex instead I'd suggest.
Thanks.
PATCH 3/8 netfilter: nf_nat: register amanda NAT helper.
In reply to Flavio Leitner--- net/netfilter/nf_nat_amanda.c | 7 +++++++ 1 file changed, 7 insertions(+)
net/netfilter/nf_nat_amanda.c +7 -0
@@ -24,6 +24,8 @@ MODULE_DESCRIPTION("Amanda NAT helper");MODULE_LICENSE ("GPL" );MODULE_ALIAS_NFCT_HELPER_NAT ("amanda" ); +static struct nf_conntrack_helper_nat helper_nat_amanda; + static unsigned int help(struct sk_buff *skb, enum ip_conntrack_info ctinfo, unsigned int protoff,
@@ -74,6 +76,7 @@ static unsigned int help(struct sk_buff *skb, static void __exit nf_nat_amanda_fini(void) { +nf_conntrack_helper_nat_unregister (&helper_nat_amanda);RCU_INIT_POINTER (nf_nat_amanda_hook,NULL );synchronize_rcu (); }
@@ -81,6 +84,10 @@ static void __exit nf_nat_amanda_fini(void)static int __init nf_nat_amanda_init (void ) {BUG_ON (nf_nat_amanda_hook !=NULL ); +nf_ct_helper_nat_init (&helper_nat_amanda, +NF_CT_NAT_HELPER_MOD_NAME ("amanda" ), +THIS_MODULE ); +nf_conntrack_helper_nat_register (&helper_nat_amanda);RCU_INIT_POINTER (nf_nat_amanda_hook, help);return 0 ; }
Signature · 1 line
2.20.1
PATCH 4/8 netfilter: nf_nat: register ftp NAT helper.
In reply to Flavio Leitner--- net/netfilter/nf_nat_ftp.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/nf_nat_ftp.c +6 -0
@@ -28,6 +28,8 @@ MODULE_ALIAS_NFCT_HELPER_NAT("ftp");/* FIXME: Time out? --RR */ +static struct nf_conntrack_helper_nat helper_nat_ftp; +static int nf_nat_ftp_fmt_cmd (struct nf_conn *ct,enum nf_ct_ftp_type type,char *buffer,size_t buflen,union nf_inet_addr *addr,u16 port)
@@ -124,6 +126,7 @@ static unsigned int nf_nat_ftp(struct sk_buff *skb, static void __exit nf_nat_ftp_fini(void) { +nf_conntrack_helper_nat_unregister (&helper_nat_ftp);RCU_INIT_POINTER (nf_nat_ftp_hook,NULL );synchronize_rcu (); }
@@ -131,6 +134,9 @@ static void __exit nf_nat_ftp_fini(void)static int __init nf_nat_ftp_init (void ) {BUG_ON (nf_nat_ftp_hook !=NULL ); +nf_ct_helper_nat_init (&helper_nat_ftp, +NF_CT_NAT_HELPER_MOD_NAME ("ftp" ),THIS_MODULE ); +nf_conntrack_helper_nat_register (&helper_nat_ftp);RCU_INIT_POINTER (nf_nat_ftp_hook, nf_nat_ftp);return 0 ; }
Signature · 1 line
2.20.1
PATCH 5/8 netfilter: nf_nat: register irc NAT helper.
In reply to Flavio Leitner--- net/netfilter/nf_nat_irc.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/nf_nat_irc.c +6 -0
@@ -28,6 +28,8 @@ MODULE_DESCRIPTION("IRC (DCC) NAT helper");MODULE_LICENSE ("GPL" );MODULE_ALIAS_NFCT_HELPER_NAT ("irc" ); +static struct nf_conntrack_helper_nat helper_nat_irc; + static unsigned int help(struct sk_buff *skb, enum ip_conntrack_info ctinfo, unsigned int protoff,
@@ -96,6 +98,7 @@ static unsigned int help(struct sk_buff *skb, static void __exit nf_nat_irc_fini(void) { +nf_conntrack_helper_nat_unregister (&helper_nat_irc);RCU_INIT_POINTER (nf_nat_irc_hook,NULL );synchronize_rcu (); }
@@ -103,6 +106,9 @@ static void __exit nf_nat_irc_fini(void)static int __init nf_nat_irc_init (void ) {BUG_ON (nf_nat_irc_hook !=NULL ); +nf_ct_helper_nat_init (&helper_nat_irc, +NF_CT_NAT_HELPER_MOD_NAME ("irc" ),THIS_MODULE ); +nf_conntrack_helper_nat_register (&helper_nat_irc);RCU_INIT_POINTER (nf_nat_irc_hook, help);return 0 ; }
Signature · 1 line
2.20.1
PATCH 6/8 netfilter: nf_nat: register sip NAT helper.
In reply to Flavio Leitner--- net/netfilter/nf_nat_sip.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
net/netfilter/nf_nat_sip.c +5 -1
@@ -29,6 +29,7 @@ MODULE_AUTHOR("Christian Hentschel <[email protected]>");MODULE_DESCRIPTION ("SIP NAT helper" );MODULE_ALIAS_NFCT_HELPER_NAT ("sip" ); +static struct nf_conntrack_helper_nat helper_nat_sip; static unsigned int mangle_packet(struct sk_buff *skb, unsigned int protoff, unsigned int dataoff,
@@ -656,8 +657,8 @@ static struct nf_ct_helper_expectfn sip_nat = { static void __exit nf_nat_sip_fini(void) { +nf_conntrack_helper_nat_unregister (&helper_nat_sip);RCU_INIT_POINTER (nf_nat_sip_hooks,NULL ); -nf_ct_helper_expectfn_unregister (&sip_nat);synchronize_rcu (); }
@@ -675,6 +676,9 @@ static const struct nf_nat_sip_hooks sip_hooks = {static int __init nf_nat_sip_init (void ) {BUG_ON (nf_nat_sip_hooks !=NULL ); +nf_ct_helper_nat_init (&helper_nat_sip, +NF_CT_NAT_HELPER_MOD_NAME ("sip" ),THIS_MODULE ); +nf_conntrack_helper_nat_register (&helper_nat_sip);RCU_INIT_POINTER (nf_nat_sip_hooks, &sip_hooks);nf_ct_helper_expectfn_register (&sip_nat);return 0 ;
Signature · 1 line
2.20.1
PATCH 7/8 netfilter: nf_nat: register tftp NAT helper.
In reply to Flavio Leitner--- net/netfilter/nf_nat_tftp.c | 6 ++++++ 1 file changed, 6 insertions(+)
net/netfilter/nf_nat_tftp.c +6 -0
@@ -18,6 +18,8 @@ MODULE_DESCRIPTION("TFTP NAT helper");MODULE_LICENSE ("GPL" );MODULE_ALIAS_NFCT_HELPER_NAT ("tftp" ); +static struct nf_conntrack_helper_nat helper_nat_tftp; +static unsigned int help (struct sk_buff *skb,enum ip_conntrack_info ctinfo,struct nf_conntrack_expect *exp)
@@ -37,6 +39,7 @@ static unsigned int help(struct sk_buff *skb, static void __exit nf_nat_tftp_fini(void) { +nf_conntrack_helper_nat_unregister (&helper_nat_tftp);RCU_INIT_POINTER (nf_nat_tftp_hook,NULL );synchronize_rcu (); }
@@ -44,6 +47,9 @@ static void __exit nf_nat_tftp_fini(void)static int __init nf_nat_tftp_init (void ) {BUG_ON (nf_nat_tftp_hook !=NULL ); +nf_ct_helper_nat_init (&helper_nat_tftp, +NF_CT_NAT_HELPER_MOD_NAME ("tftp" ),THIS_MODULE ); +nf_conntrack_helper_nat_register (&helper_nat_tftp);RCU_INIT_POINTER (nf_nat_tftp_hook, help);return 0 ; }
Signature · 1 line
2.20.1
PATCH 8/8 openvswitch: load and reference the NAT helper.
In reply to Flavio LeitnerThis improves the original commit 17c357efe5ec ("openvswitch: load NAT helper") where it unconditionally tries to load the module for every flow using NAT, so not efficient when loading multiple flows. It also doesn't hold any references to the NAT module while the flow is active.
This change fixes those problems. It will try to load the module only if it's not present. It grabs a reference to the NAT module and holds it while the flow is active. Finally, an error message shows up if either actions above fails.
--- net/openvswitch/conntrack.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-)
net/openvswitch/conntrack.c +21 -6
@@ -1305,6 +1305,7 @@ static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name, {struct nf_conntrack_helper *helper;struct nf_conn_help *help; +int ret =0 ; helper =nf_conntrack_helper_try_module_get (name, info->family, key->ip.proto);
@@ -1319,13 +1320,22 @@ static int ovs_ct_add_helper(struct ovs_conntrack_info *info, const char *name,return -ENOMEM ; } +#ifdef CONFIG_NF_NAT_NEEDED +if (info->nat) { + ret =nf_conntrack_helper_nat_try_module_get (name, + info->family, + key->ip.proto); +if (ret) { +nf_conntrack_helper_put (helper); +OVS_NLERR (log,"Failed to load \"%s\" NAT helper, err: %d" , + name, ret); +return ret; + } + } +#endif rcu_assign_pointer (help->helper, helper); info->helper = helper; - -if (info->nat) -request_module ("ip_nat_%s" , name); - -return 0 ; +return ret; }#ifdef CONFIG_NF_NAT_NEEDED
@@ -1776,8 +1786,13 @@ void ovs_ct_free_action(const struct nlattr *a)static void __ovs_ct_free_action (struct ovs_conntrack_info *ct_info) { -if (ct_info->helper) +if (ct_info->helper) { +#ifdef CONFIG_NF_NAT_NEEDED +if (ct_info->nat) +nf_conntrack_helper_nat_put (ct_info->helper); +#endif nf_conntrack_helper_put (ct_info->helper); + }if (ct_info->ct)nf_ct_tmpl_free (ct_info->ct); }
Signature · 1 line
2.20.1
David Miller
maintainerFrom: Flavio Leitner <[email protected]>
Date: Tue, 26 Mar 2019 17:57:07 -0300
Quoted 8 lines
The
request_module()is quite expensive and triggers the usermode helper in userspace. Instead, load only if the module is not present and keep module references to avoid problems.The first patch standardize the module alias which is already there, but not in a formal way.
Quoted 8 lines
The second patch adds an API to point to the NAT helper.
The following patches will register each NAT helper using the new API.
The last patch fixes openvswitch to use the new API to load and reference the NAT helper and also report an error if the operation fails.
These are mostly netfilter changes so I would like to see some reviews/ACKs from netfilter folks.
Thanks.
David Miller
maintainerFrom: Flavio Leitner <[email protected]>
Date: Tue, 26 Mar 2019 17:57:07 -0300
Quoted 8 lines
The
request_module()is quite expensive and triggers the usermode helper in userspace. Instead, load only if the module is not present and keep module references to avoid problems.The first patch standardize the module alias which is already there, but not in a formal way.
Quoted 8 lines
The second patch adds an API to point to the NAT helper.
The following patches will register each NAT helper using the new API.
The last patch fixes openvswitch to use the new API to load and reference the NAT helper and also report an error if the operation fails.
I haven't seen any netfilter reviews of this series, so I'm dropping it.