Netfilter updates for net-next
Subsystems (4)
Pablo Neira Ayuso
maintainercover Netfilter updates for net-next
Hi David,
The following batch contains Netfilter updates for net-next, they are:
1) Move nft_expr_clone() to nft_dynset, from Paul Gortmaker.
2) Do not include module.h from net/netfilter/nf_tables.h, also from Paul.
3) Restrict conntrack sysctl entries to boolean, from Tonghao Zhang.
4) Several patches to add infrastructure to autoload NAT helper modules from their respective conntrack helper, this also includes the first client of this code in OVS, patches from Flavio Leitner.
5) Add support to match for conntrack ID, from Brett Mastbergen.
6) Spelling fix in connlabel, from Colin Ian King.
7) Use struct_size() from hashlimit, from Gustavo A. R. Silva.
8) Add optimized version of nf_inet_addr_mask(), from Li RongQing.
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Thanks!
----------------------------------------------------------------
The following changes since commit 7a1d8390d015a13c42b1effa1f22fda0858fe6f9:
net: phy: micrel: make sure the factory test bit is cleared (2019-04-29 23:17:21 -0400)
are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git HEAD
for you to fetch changes up to 522e4077e8dcdfc5b8e96469d3bc2324bc5d6466:
netfilter: slightly optimize nf_inet_addr_mask (2019-05-06 01:18:58 +0200)
----------------------------------------------------------------
Brett Mastbergen (1):
netfilter: nft_ct: Add ct id support
Colin Ian King (1):
netfilter: connlabels: fix spelling mistake "trackling" -> "tracking"
Flavio Leitner (4):
netfilter: use macros to create module aliases.
netfilter: add API to manage NAT helpers.
netfilter: nf_nat: register NAT helpers.
openvswitch: load and reference the NAT helper.
Gustavo A. R. Silva (1):
netfilter: xt_hashlimit: use struct_size() helper
Li RongQing (1):
netfilter: slightly optimize nf_inet_addr_mask
Paul Gortmaker (3):
netfilter: nf_tables: relocate header content to consumer
netfilter: nf_tables: fix implicit include of module.h
netfilter: nf_tables: drop include of module.h from nf_tables.h
Tonghao Zhang (1):
netfilter: conntrack: limit sysctl setting for boolean options
include/linux/netfilter.h | 9 +++ include/net/netfilter/nf_conntrack_helper.h | 24 ++++++++ include/net/netfilter/nf_tables.h | 20 +------ include/net/netns/conntrack.h | 6 +- include/uapi/linux/netfilter/nf_tables.h | 2 + net/ipv4/netfilter/nf_nat_h323.c | 2 +- net/ipv4/netfilter/nf_nat_pptp.c | 2 +- net/netfilter/nf_conntrack_amanda.c | 8 ++- net/netfilter/nf_conntrack_ftp.c | 18 +++--- net/netfilter/nf_conntrack_helper.c | 86 +++++++++++++++++++++++++++++ net/netfilter/nf_conntrack_irc.c | 6 +- net/netfilter/nf_conntrack_sane.c | 12 ++-- net/netfilter/nf_conntrack_sip.c | 28 +++++----- net/netfilter/nf_conntrack_standalone.c | 48 +++++++++++----- net/netfilter/nf_conntrack_tftp.c | 18 +++--- net/netfilter/nf_nat_amanda.c | 9 ++- net/netfilter/nf_nat_ftp.c | 9 ++- net/netfilter/nf_nat_irc.c | 9 ++- net/netfilter/nf_nat_sip.c | 9 ++- net/netfilter/nf_nat_tftp.c | 9 ++- net/netfilter/nf_tables_set_core.c | 1 + net/netfilter/nft_ct.c | 8 +++ net/netfilter/nft_dynset.c | 17 ++++++ net/netfilter/xt_connlabel.c | 2 +- net/netfilter/xt_hashlimit.c | 3 +- net/openvswitch/conntrack.c | 26 +++++++-- 26 files changed, 302 insertions(+), 89 deletions(-)
Pablo Neira Ayuso
maintainerPATCH 1/12 netfilter: nf_tables: relocate header content to consumer
From: Paul Gortmaker <[email protected]>
The nf_tables.h header is used in a lot of files, but it turns out that there is only one actual user of nft_expr_clone().
Hence we relocate that function to be with the one consumer of it and avoid having to process it with CPP for all the other files.
This will also enable a reduction in the other headers that the nf_tables.h itself has to include just to be stand-alone, hence a pending further significant reduction in the CPP content that needs to get processed for each netfilter file.
Note that the explicit "inline" has been dropped as part of this relocation. In similar changes to this, I believe Dave has asked this be done, so we free up gcc to make the choice of whether to inline or not.
--- include/net/netfilter/nf_tables.h | 17 ----------------- net/netfilter/nft_dynset.c | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 17 deletions(-)
include/net/netfilter/nf_tables.h +0 -17
@@ -806,23 +806,6 @@ void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr);int nft_expr_dump (struct sk_buff *skb,unsigned int attr,const struct nft_expr *expr); -static inline int nft_expr_clone (struct nft_expr *dst,struct nft_expr *src) -{ -int err; - -if (src->ops->clone) { - dst->ops = src->ops; - err = src->ops->clone (dst, src); -if (err <0 ) -return err; - }else { -memcpy (dst, src, src->ops->size); - } - -__module_get (src->ops->type->owner); -return 0 ; -} -/** * struct nft_rule - nf_tables rule *
net/netfilter/nft_dynset.c +17 -0
@@ -28,6 +28,23 @@ struct nft_dynset {struct nft_set_binding binding; }; +static int nft_expr_clone (struct nft_expr *dst,struct nft_expr *src) +{ +int err; + +if (src->ops->clone) { + dst->ops = src->ops; + err = src->ops->clone (dst, src); +if (err <0 ) +return err; + }else { +memcpy (dst, src, src->ops->size); + } + +__module_get (src->ops->type->owner); +return 0 ; +} +static void *nft_dynset_new (struct nft_set *set,const struct nft_expr *expr,struct nft_regs *regs) {
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 2/12 netfilter: nf_tables: fix implicit include of module.h
In reply to Pablo Neira AyusoFrom: Paul Gortmaker <[email protected]>
This file clearly uses modular infrastructure but does not call out the inclusion of <linux/module.h> explicitly. We add that include explicitly here, so we can tidy up some header usage elsewhere w/o causing build breakage.
--- net/netfilter/nf_tables_set_core.c | 1 + 1 file changed, 1 insertion(+)
net/netfilter/nf_tables_set_core.c +1 -0
@@ -1,4 +1,5 @@/* SPDX-License-Identifier: GPL-2.0 */ +#include <linux/module.h> #include <net/netfilter/nf_tables_core.h> static int __init nf_tables_set_module_init (void )
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 3/12 netfilter: nf_tables: drop include of module.h from nf_tables.h
In reply to Pablo Neira AyusoFrom: Paul Gortmaker <[email protected]>
Ideally, header files under include/linux shouldn't be adding includes of other headers, in anticipation of their consumers, but just the headers needed for the header itself to pass parsing with CPP.
The module.h is particularly bad in this sense, as it itself does include a whole bunch of other headers, due to the complexity of module support.
Since nf_tables.h is not going into a module struct looking for specific fields, we can just let it know that module is a struct, just like about 60 other include/linux headers already do.
--- include/net/netfilter/nf_tables.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/net/netfilter/nf_tables.h +2 -1
@@ -2,7 +2,6 @@#ifndef _NET_NF_TABLES_H#define _NET_NF_TABLES_H -#include <linux/module.h> #include <linux/list.h> #include <linux/netfilter.h> #include <linux/netfilter/nfnetlink.h>
@@ -13,6 +12,8 @@#include <net/netfilter/nf_flow_table.h> #include <net/netlink.h> +struct module ; +#define NFT_JUMP_STACK_SIZE 16struct nft_pktinfo {
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 4/12 netfilter: conntrack: limit sysctl setting for boolean options
In reply to Pablo Neira AyusoFrom: Tonghao Zhang <[email protected]>
We use the zero and one to limit the boolean options setting. After this patch we only set 0 or 1 to boolean options for nf conntrack sysctl.
--- include/net/netns/conntrack.h | 6 ++--- net/netfilter/nf_conntrack_standalone.c | 48 ++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 18 deletions(-)
include/net/netns/conntrack.h +3 -3
@@ -24,9 +24,9 @@ struct nf_generic_net {struct nf_tcp_net {unsigned int timeouts[TCP_CONNTRACK_TIMEOUT_MAX ]; -unsigned int tcp_loose; -unsigned int tcp_be_liberal; -unsigned int tcp_max_retrans; +int tcp_loose; +int tcp_be_liberal; +int tcp_max_retrans; };enum udp_conntrack {
net/netfilter/nf_conntrack_standalone.c +33 -15
103 lines not on this page · raw message
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 5/12 netfilter: use macros to create module aliases.
In reply to Pablo Neira AyusoFrom: Flavio Leitner <[email protected]>
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_NAT_HELPER_NAME (name) "ip_nat_" name +#define MODULE_ALIAS_NF_NAT_HELPER (name) \ + MODULE_ALIAS(NF_NAT_HELPER_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_NF_NAT_HELPER ("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_NF_NAT_HELPER ("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_NF_NAT_HELPER ("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_NF_NAT_HELPER ("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_NF_NAT_HELPER ("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_NF_NAT_HELPER ("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_NF_NAT_HELPER ("tftp" ); static unsigned int help(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 6/12 netfilter: add API to manage NAT helpers.
In reply to Pablo Neira AyusoFrom: Flavio Leitner <[email protected]>
The 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 | 22 +++++++- net/netfilter/nf_conntrack_amanda.c | 8 ++- net/netfilter/nf_conntrack_ftp.c | 18 +++--- net/netfilter/nf_conntrack_helper.c | 86 +++++++++++++++++++++++++++++ net/netfilter/nf_conntrack_irc.c | 6 +- net/netfilter/nf_conntrack_sane.c | 12 ++-- net/netfilter/nf_conntrack_sip.c | 28 +++++----- net/netfilter/nf_conntrack_tftp.c | 18 +++--- 8 files changed, 161 insertions(+), 37 deletions(-)
include/net/netfilter/nf_conntrack_helper.h +21 -1
@@ -15,7 +15,8 @@#include <net/netfilter/nf_conntrack_extend.h> #include <net/netfilter/nf_conntrack_expect.h> -#define NF_NAT_HELPER_NAME (name) "ip_nat_" name +#define NF_NAT_HELPER_PREFIX "ip_nat_" +#define NF_NAT_HELPER_NAME (name) NF_NAT_HELPER_PREFIX name#define MODULE_ALIAS_NF_NAT_HELPER (name) \ MODULE_ALIAS(NF_NAT_HELPER_NAME(name))
@@ -58,6 +59,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 */
@@ -157,4 +160,21 @@ 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_nat_helper { +struct list_head list; +char mod_name[NF_CT_HELPER_NAME_LEN ];/* module name */ +struct module *module;/* pointer to self */ +}; + +#define NF_CT_NAT_HELPER_INIT (name) \ + { \ + .mod_name = NF_NAT_HELPER_NAME(name), \ + .module = THIS_MODULE \ + } + +void nf_nat_helper_register (struct nf_conntrack_nat_helper *nat); +void nf_nat_helper_unregister (struct nf_conntrack_nat_helper *nat); +int nf_nat_helper_try_module_get (const char *name,u16 l3num, +u8 protonum); +void nf_nat_helper_put (struct nf_conntrack_helper *helper);#endif /*_NF_CONNTRACK_HELPER_H*/
net/netfilter/nf_conntrack_amanda.c +6 -2
@@ -28,11 +28,13 @@static unsigned int master_timeout__read_mostly =300 ;static char *ts_algo ="kmp" ; +#define HELPER_NAME "amanda" +MODULE_AUTHOR ("Brian J. Murrell <[email protected]>" );MODULE_DESCRIPTION ("Amanda connection tracking module" );MODULE_LICENSE ("GPL" );MODULE_ALIAS ("ip_conntrack_amanda" ); -MODULE_ALIAS_NFCT_HELPER ("amanda" ); +MODULE_ALIAS_NFCT_HELPER (HELPER_NAME );module_param (master_timeout, uint,0600 );MODULE_PARM_DESC (master_timeout,"timeout for the master connection" );
@@ -179,13 +181,14 @@ static const struct nf_conntrack_expect_policy amanda_exp_policy = {static struct nf_conntrack_helper amanda_helper[2 ]__read_mostly = { { - .name ="amanda" , + .name =HELPER_NAME , .me =THIS_MODULE , .help = amanda_help, .tuple.src.l3num =AF_INET , .tuple.src.u.udp.port =cpu_to_be16 (10080 ), .tuple.dst.protonum =IPPROTO_UDP , .expect_policy = &amanda_exp_policy, + .nat_mod_name =NF_NAT_HELPER_NAME (HELPER_NAME ), }, { .name ="amanda" ,
@@ -195,6 +198,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_NAT_HELPER_NAME(HELPER_NAME), }, };
net/netfilter/nf_conntrack_ftp.c +11 -7
@@ -29,11 +29,13 @@#include <net/netfilter/nf_conntrack_helper.h> #include <linux/netfilter/nf_conntrack_ftp.h> +#define HELPER_NAME "ftp" +MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Rusty Russell <[email protected]>" );MODULE_DESCRIPTION ("ftp connection tracking helper" );MODULE_ALIAS ("ip_conntrack_ftp" ); -MODULE_ALIAS_NFCT_HELPER ("ftp" ); +MODULE_ALIAS_NFCT_HELPER (HELPER_NAME );/* This is slow, but it's simple. --RR */ static char *ftp_buffer;
@@ -588,12 +590,14 @@ static int __init nf_conntrack_ftp_init(void)/* FIXME should be configurable whether IPv4 and IPv6 FTP connections are tracked or not - YK */ 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 ); -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 ); +nf_ct_helper_init (&ftp[2 * i],AF_INET ,IPPROTO_TCP , +HELPER_NAME ,FTP_PORT , ports[i], ports[i], + &ftp_exp_policy,0 , help, + nf_ct_ftp_from_nlattr,THIS_MODULE ); +nf_ct_helper_init (&ftp[2 * i +1 ],AF_INET6 ,IPPROTO_TCP , +HELPER_NAME ,FTP_PORT , ports[i], ports[i], + &ftp_exp_policy,0 , help, + nf_ct_ftp_from_nlattr,THIS_MODULE ); } ret =nf_conntrack_helpers_register (ftp, ports_c *2 );
net/netfilter/nf_conntrack_helper.c +86 -0
116 lines not on this page · raw message
net/netfilter/nf_conntrack_irc.c +4 -2
@@ -42,11 +42,13 @@ unsigned int (*nf_nat_irc_hook)(struct sk_buff *skb, struct nf_conntrack_expect *exp) __read_mostly;EXPORT_SYMBOL_GPL (nf_nat_irc_hook); +#define HELPER_NAME "irc" +MODULE_AUTHOR ("Harald Welte <[email protected]>" );MODULE_DESCRIPTION ("IRC (DCC) connection tracking helper" );MODULE_LICENSE ("GPL" );MODULE_ALIAS ("ip_conntrack_irc" ); -MODULE_ALIAS_NFCT_HELPER ("irc" ); +MODULE_ALIAS_NFCT_HELPER (HELPER_NAME );module_param_array (ports, ushort, &ports_c,0400 );MODULE_PARM_DESC (ports,"port numbers of IRC servers" );
@@ -259,7 +261,7 @@ static int __init nf_conntrack_irc_init(void) ports[ports_c++] =IRC_PORT ;for (i =0 ; i < ports_c; i++) { -nf_ct_helper_init (&irc[i],AF_INET ,IPPROTO_TCP ,"irc" , +nf_ct_helper_init (&irc[i],AF_INET ,IPPROTO_TCP ,HELPER_NAME ,IRC_PORT , ports[i], i, &irc_exp_policy,0 , help,NULL ,THIS_MODULE ); }
net/netfilter/nf_conntrack_sane.c +7 -5
@@ -30,10 +30,12 @@#include <net/netfilter/nf_conntrack_expect.h> #include <linux/netfilter/nf_conntrack_sane.h> +#define HELPER_NAME "sane" +MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Michal Schmidt <[email protected]>" );MODULE_DESCRIPTION ("SANE connection tracking helper" ); -MODULE_ALIAS_NFCT_HELPER ("sane" ); +MODULE_ALIAS_NFCT_HELPER (HELPER_NAME );static char *sane_buffer;
@@ -195,12 +197,12 @@ static int __init nf_conntrack_sane_init(void)/* FIXME should be configurable whether IPv4 and IPv6 connections are tracked or not - YK */ for (i =0 ; i < ports_c; i++) { -nf_ct_helper_init (&sane[2 * i],AF_INET ,IPPROTO_TCP ,"sane" , -SANE_PORT , ports[i], ports[i], +nf_ct_helper_init (&sane[2 * i],AF_INET ,IPPROTO_TCP , +HELPER_NAME ,SANE_PORT , ports[i], ports[i], &sane_exp_policy,0 , help,NULL ,THIS_MODULE ); -nf_ct_helper_init (&sane[2 * i +1 ],AF_INET6 ,IPPROTO_TCP ,"sane" , -SANE_PORT , ports[i], ports[i], +nf_ct_helper_init (&sane[2 * i +1 ],AF_INET6 ,IPPROTO_TCP , +HELPER_NAME ,SANE_PORT , ports[i], ports[i], &sane_exp_policy,0 , help,NULL ,THIS_MODULE ); }
net/netfilter/nf_conntrack_sip.c +15 -13
@@ -30,11 +30,13 @@#include <net/netfilter/nf_conntrack_zones.h> #include <linux/netfilter/nf_conntrack_sip.h> +#define HELPER_NAME "sip" +MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Christian Hentschel <[email protected]>" );MODULE_DESCRIPTION ("SIP connection tracking helper" );MODULE_ALIAS ("ip_conntrack_sip" ); -MODULE_ALIAS_NFCT_HELPER ("sip" ); +MODULE_ALIAS_NFCT_HELPER (HELPER_NAME );#define MAX_PORTS 8static unsigned short ports[MAX_PORTS ];
@@ -1669,21 +1671,21 @@ static int __init nf_conntrack_sip_init(void) ports[ports_c++] =SIP_PORT ;for (i =0 ; i < ports_c; i++) { -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, +nf_ct_helper_init (&sip[4 * i],AF_INET ,IPPROTO_UDP , +HELPER_NAME ,SIP_PORT , ports[i], i, + sip_exp_policy,SIP_EXPECT_MAX , sip_help_udp,NULL ,THIS_MODULE ); -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, +nf_ct_helper_init (&sip[4 * i +1 ],AF_INET ,IPPROTO_TCP , +HELPER_NAME ,SIP_PORT , ports[i], i, + sip_exp_policy,SIP_EXPECT_MAX , sip_help_tcp,NULL ,THIS_MODULE ); -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, +nf_ct_helper_init (&sip[4 * i +2 ],AF_INET6 ,IPPROTO_UDP , +HELPER_NAME ,SIP_PORT , ports[i], i, + sip_exp_policy,SIP_EXPECT_MAX , sip_help_udp,NULL ,THIS_MODULE ); -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, +nf_ct_helper_init (&sip[4 * i +3 ],AF_INET6 ,IPPROTO_TCP , +HELPER_NAME ,SIP_PORT , ports[i], i, + sip_exp_policy,SIP_EXPECT_MAX , sip_help_tcp,NULL ,THIS_MODULE ); }
net/netfilter/nf_conntrack_tftp.c +11 -7
@@ -20,11 +20,13 @@#include <net/netfilter/nf_conntrack_helper.h> #include <linux/netfilter/nf_conntrack_tftp.h> +#define HELPER_NAME "tftp" +MODULE_AUTHOR ("Magnus Boden <[email protected]>" );MODULE_DESCRIPTION ("TFTP connection tracking helper" );MODULE_LICENSE ("GPL" );MODULE_ALIAS ("ip_conntrack_tftp" ); -MODULE_ALIAS_NFCT_HELPER ("tftp" ); +MODULE_ALIAS_NFCT_HELPER (HELPER_NAME );#define MAX_PORTS 8static unsigned short ports[MAX_PORTS ];
@@ -119,12 +121,14 @@ static int __init nf_conntrack_tftp_init(void) ports[ports_c++] =TFTP_PORT ;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 ); -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 ); +nf_ct_helper_init (&tftp[2 * i],AF_INET ,IPPROTO_UDP , +HELPER_NAME ,TFTP_PORT , ports[i], i, + &tftp_exp_policy,0 , tftp_help,NULL , +THIS_MODULE ); +nf_ct_helper_init (&tftp[2 * i +1 ],AF_INET6 ,IPPROTO_UDP , +HELPER_NAME ,TFTP_PORT , ports[i], i, + &tftp_exp_policy,0 , tftp_help,NULL , +THIS_MODULE ); } ret =nf_conntrack_helpers_register (tftp, ports_c *2 );
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 7/12 netfilter: nf_nat: register NAT helpers.
In reply to Pablo Neira AyusoFrom: Flavio Leitner <[email protected]>
Register amanda, ftp, irc, sip and tftp NAT helpers.
--- net/netfilter/nf_nat_amanda.c | 9 ++++++++- net/netfilter/nf_nat_ftp.c | 9 ++++++++- net/netfilter/nf_nat_irc.c | 9 ++++++++- net/netfilter/nf_nat_sip.c | 9 +++++++-- net/netfilter/nf_nat_tftp.c | 9 ++++++++- 5 files changed, 39 insertions(+), 6 deletions(-)
net/netfilter/nf_nat_amanda.c +8 -1
@@ -19,10 +19,15 @@#include <net/netfilter/nf_nat_helper.h> #include <linux/netfilter/nf_conntrack_amanda.h> +#define NAT_HELPER_NAME "amanda" +MODULE_AUTHOR ("Brian J. Murrell <[email protected]>" );MODULE_DESCRIPTION ("Amanda NAT helper" );MODULE_LICENSE ("GPL" ); -MODULE_ALIAS_NF_NAT_HELPER ("amanda" ); +MODULE_ALIAS_NF_NAT_HELPER (NAT_HELPER_NAME ); + +static struct nf_conntrack_nat_helper nat_helper_amanda = +NF_CT_NAT_HELPER_INIT (NAT_HELPER_NAME ); static unsigned int help(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
@@ -74,6 +79,7 @@ static unsigned int help(struct sk_buff *skb, static void __exit nf_nat_amanda_fini(void) { +nf_nat_helper_unregister (&nat_helper_amanda);RCU_INIT_POINTER (nf_nat_amanda_hook,NULL );synchronize_rcu (); }
@@ -81,6 +87,7 @@ static void __exit nf_nat_amanda_fini(void)static int __init nf_nat_amanda_init (void ) {BUG_ON (nf_nat_amanda_hook !=NULL ); +nf_nat_helper_register (&nat_helper_amanda);RCU_INIT_POINTER (nf_nat_amanda_hook, help);return 0 ; }
net/netfilter/nf_nat_ftp.c +8 -1
@@ -21,13 +21,18 @@#include <net/netfilter/nf_conntrack_expect.h> #include <linux/netfilter/nf_conntrack_ftp.h> +#define NAT_HELPER_NAME "ftp" +MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Rusty Russell <[email protected]>" );MODULE_DESCRIPTION ("ftp NAT helper" ); -MODULE_ALIAS_NF_NAT_HELPER ("ftp" ); +MODULE_ALIAS_NF_NAT_HELPER (NAT_HELPER_NAME );/* FIXME: Time out? --RR */ +static struct nf_conntrack_nat_helper nat_helper_ftp = +NF_CT_NAT_HELPER_INIT (NAT_HELPER_NAME ); +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 +129,7 @@ static unsigned int nf_nat_ftp(struct sk_buff *skb, static void __exit nf_nat_ftp_fini(void) { +nf_nat_helper_unregister (&nat_helper_ftp);RCU_INIT_POINTER (nf_nat_ftp_hook,NULL );synchronize_rcu (); }
@@ -131,6 +137,7 @@ static void __exit nf_nat_ftp_fini(void)static int __init nf_nat_ftp_init (void ) {BUG_ON (nf_nat_ftp_hook !=NULL ); +nf_nat_helper_register (&nat_helper_ftp);RCU_INIT_POINTER (nf_nat_ftp_hook, nf_nat_ftp);return 0 ; }
net/netfilter/nf_nat_irc.c +8 -1
@@ -23,10 +23,15 @@#include <net/netfilter/nf_conntrack_expect.h> #include <linux/netfilter/nf_conntrack_irc.h> +#define NAT_HELPER_NAME "irc" +MODULE_AUTHOR ("Harald Welte <[email protected]>" );MODULE_DESCRIPTION ("IRC (DCC) NAT helper" );MODULE_LICENSE ("GPL" ); -MODULE_ALIAS_NF_NAT_HELPER ("irc" ); +MODULE_ALIAS_NF_NAT_HELPER (NAT_HELPER_NAME ); + +static struct nf_conntrack_nat_helper nat_helper_irc = +NF_CT_NAT_HELPER_INIT (NAT_HELPER_NAME ); static unsigned int help(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
@@ -96,6 +101,7 @@ static unsigned int help(struct sk_buff *skb, static void __exit nf_nat_irc_fini(void) { +nf_nat_helper_unregister (&nat_helper_irc);RCU_INIT_POINTER (nf_nat_irc_hook,NULL );synchronize_rcu (); }
@@ -103,6 +109,7 @@ static void __exit nf_nat_irc_fini(void)static int __init nf_nat_irc_init (void ) {BUG_ON (nf_nat_irc_hook !=NULL ); +nf_nat_helper_register (&nat_helper_irc);RCU_INIT_POINTER (nf_nat_irc_hook, help);return 0 ; }
net/netfilter/nf_nat_sip.c +7 -2
@@ -24,11 +24,15 @@#include <net/netfilter/nf_conntrack_seqadj.h> #include <linux/netfilter/nf_conntrack_sip.h> +#define NAT_HELPER_NAME "sip" +MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Christian Hentschel <[email protected]>" );MODULE_DESCRIPTION ("SIP NAT helper" ); -MODULE_ALIAS_NF_NAT_HELPER ("sip" ); +MODULE_ALIAS_NF_NAT_HELPER (NAT_HELPER_NAME ); +static struct nf_conntrack_nat_helper nat_helper_sip = +NF_CT_NAT_HELPER_INIT (NAT_HELPER_NAME ); static unsigned int mangle_packet(struct sk_buff *skb, unsigned int protoff, unsigned int dataoff,
@@ -656,8 +660,8 @@ static struct nf_ct_helper_expectfn sip_nat = { static void __exit nf_nat_sip_fini(void) { +nf_nat_helper_unregister (&nat_helper_sip);RCU_INIT_POINTER (nf_nat_sip_hooks,NULL ); -nf_ct_helper_expectfn_unregister (&sip_nat);synchronize_rcu (); }
@@ -675,6 +679,7 @@ 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_nat_helper_register (&nat_helper_sip);RCU_INIT_POINTER (nf_nat_sip_hooks, &sip_hooks);nf_ct_helper_expectfn_register (&sip_nat);return 0 ;
net/netfilter/nf_nat_tftp.c +8 -1
@@ -13,10 +13,15 @@#include <net/netfilter/nf_nat_helper.h> #include <linux/netfilter/nf_conntrack_tftp.h> +#define NAT_HELPER_NAME "tftp" +MODULE_AUTHOR ("Magnus Boden <[email protected]>" );MODULE_DESCRIPTION ("TFTP NAT helper" );MODULE_LICENSE ("GPL" ); -MODULE_ALIAS_NF_NAT_HELPER ("tftp" ); +MODULE_ALIAS_NF_NAT_HELPER (NAT_HELPER_NAME ); + +static struct nf_conntrack_nat_helper nat_helper_tftp = +NF_CT_NAT_HELPER_INIT (NAT_HELPER_NAME ); static unsigned int help(struct sk_buff *skb, enum ip_conntrack_info ctinfo,
@@ -37,6 +42,7 @@ static unsigned int help(struct sk_buff *skb, static void __exit nf_nat_tftp_fini(void) { +nf_nat_helper_unregister (&nat_helper_tftp);RCU_INIT_POINTER (nf_nat_tftp_hook,NULL );synchronize_rcu (); }
@@ -44,6 +50,7 @@ static void __exit nf_nat_tftp_fini(void)static int __init nf_nat_tftp_init (void ) {BUG_ON (nf_nat_tftp_hook !=NULL ); +nf_nat_helper_register (&nat_helper_tftp);RCU_INIT_POINTER (nf_nat_tftp_hook, help);return 0 ; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 8/12 openvswitch: load and reference the NAT helper.
In reply to Pablo Neira AyusoFrom: Flavio Leitner <[email protected]>
This 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 | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
net/openvswitch/conntrack.c +20 -6
@@ -1307,6 +1307,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);
@@ -1321,13 +1322,21 @@ 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_nat_helper_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, error: %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; }#if IS_ENABLED (CONFIG_NF_NAT )
@@ -1801,8 +1810,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_nat_helper_put (ct_info->helper); +#endif nf_conntrack_helper_put (ct_info->helper); + }if (ct_info->ct) {if (ct_info->timeout[0 ])nf_ct_destroy_timeout (ct_info->ct);
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 9/12 netfilter: nft_ct: Add ct id support
In reply to Pablo Neira AyusoFrom: Brett Mastbergen <[email protected]>
The 'id' key returns the unique id of the conntrack entry as returned by nf_ct_get_id().
--- include/uapi/linux/netfilter/nf_tables.h | 2 ++ net/netfilter/nft_ct.c | 8 ++++++++ 2 files changed, 10 insertions(+)
include/uapi/linux/netfilter/nf_tables.h +2 -0
@@ -967,6 +967,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_TIMEOUT: connection tracking timeout policy assigned to conntrack +* @NFT_CT_ID: conntrack id */ enum nft_ct_keys {NFT_CT_STATE ,
@@ -993,6 +994,7 @@ enum nft_ct_keys {NFT_CT_SRC_IP6 ,NFT_CT_DST_IP6 ,NFT_CT_TIMEOUT , +NFT_CT_ID , __NFT_CT_MAX };#define NFT_CT_MAX (__NFT_CT_MAX - 1)
net/netfilter/nft_ct.c +8 -0
@@ -178,6 +178,11 @@ static void nft_ct_get_eval(const struct nft_expr *expr, return; }#endif +case NFT_CT_ID : +if (!nf_ct_is_confirmed (ct)) + goto err; + *dest =nf_ct_get_id (ct); +return ;default :break ; }
@@ -479,6 +484,9 @@ static int nft_ct_get_init(const struct nft_ctx *ctx, len =sizeof (u16);break ;#endif +case NFT_CT_ID : + len =sizeof (u32); +break ;default :return -EOPNOTSUPP ; }
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 10/12 netfilter: connlabels: fix spelling mistake "trackling" -> "tracking"
In reply to Pablo Neira AyusoFrom: Colin Ian King <[email protected]>
There is a spelling mistake in the module description. Fix this.
--- net/netfilter/xt_connlabel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/netfilter/xt_connlabel.c +1 -1
@@ -15,7 +15,7 @@MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Florian Westphal <[email protected]>" ); -MODULE_DESCRIPTION ("Xtables: add/match connection trackling labels" ); +MODULE_DESCRIPTION ("Xtables: add/match connection tracking labels" );MODULE_ALIAS ("ipt_connlabel" );MODULE_ALIAS ("ip6t_connlabel" );
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 11/12 netfilter: xt_hashlimit: use struct_size() helper
In reply to Pablo Neira AyusoFrom: "Gustavo A. R. Silva" <[email protected]>
Make use of the struct_size() helper instead of an open-coded version in order to avoid any potential type mistakes, in particular in the context in which this code is being used.
So, replace code of the following form:
sizeof(struct xt_hashlimit_htable) + sizeof(struct hlist_head) * size
with:
struct_size(hinfo, hash, size)
This code was detected with the help of Coccinelle.
--- net/netfilter/xt_hashlimit.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/netfilter/xt_hashlimit.c +1 -2
@@ -288,8 +288,7 @@ static int htable_create(struct net *net, struct hashlimit_cfg3 *cfg, size =16 ; }/* FIXME: don't use vmalloc() here or anywhere else -HW */ - hinfo =vmalloc (sizeof (struct xt_hashlimit_htable ) + -sizeof (struct hlist_head ) * size); + hinfo =vmalloc (struct_size (hinfo, hash, size));if (hinfo ==NULL )return -ENOMEM ; *out_hinfo = hinfo;
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH 12/12 netfilter: slightly optimize nf_inet_addr_mask
In reply to Pablo Neira AyusoFrom: Li RongQing <[email protected]>
using 64bit computation to slightly optimize nf_inet_addr_mask
--- include/linux/netfilter.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/linux/netfilter.h +9 -0
@@ -41,10 +41,19 @@ static inline void nf_inet_addr_mask(const union nf_inet_addr *a1, union nf_inet_addr *result, const union nf_inet_addr *mask) { +#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS ) &&BITS_PER_LONG ==64 +const unsigned long *ua = (const unsigned long *)a1; +unsigned long *ur = (unsigned long *)result; +const unsigned long *um = (const unsigned long *)mask; + + ur[0 ] = ua[0 ] & um[0 ]; + ur[1 ] = ua[1 ] & um[1 ]; +#else result->all[0 ] = a1->all[0 ] & mask->all[0 ]; result->all[1 ] = a1->all[1 ] & mask->all[1 ]; result->all[2 ] = a1->all[2 ] & mask->all[2 ]; result->all[3 ] = a1->all[3 ] & mask->all[3 ]; +#endif }int netfilter_init (void );
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Pablo Neira Ayuso <[email protected]>
Date: Mon, 6 May 2019 01:32:53 +0200
Quoted 1 line
The following batch contains Netfilter updates for net-next, they are:
...
Quoted 3 lines
You can pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git
Pulled, thanks.