netfilter: built-in NAT support for DCCP, SCTP, UDPlite
Subsystems (2)
cover netfilter: built-in NAT support for DCCP, SCTP, UDPlite
The above L4 protocols usually need an explicit modprobe command (e.g "modprobe nf_nat_proto_sctp") to provide full functionality of REDIRECT targets and SNAT/DNAT targets where port number translation is explicitly configured.
In order to remove such limitation, this series converts CONFIG_NF_NAT_PROTO_{DCCP,SCTP,UDPLITE} from tristate to boolean: in case NAT support for these protocols is enabled in the kernel configuration, it will be built into nf_nat.ko.
Davide Caratti (3):
netfilter: built-in NAT support for DCCP
netfilter: built-in NAT support for SCTP
netfilter: built-in NAT support for UDPlite
include/net/netfilter/nf_nat_l4proto.h | 9 +++++++++ net/netfilter/Kconfig | 6 +++--- net/netfilter/Makefile | 10 +++++----- net/netfilter/nf_nat_core.c | 12 ++++++++++++ net/netfilter/nf_nat_proto_dccp.c | 36 +--------------------------------- net/netfilter/nf_nat_proto_sctp.c | 35 +-------------------------------- net/netfilter/nf_nat_proto_udplite.c | 35 +-------------------------------- 7 files changed, 32 insertions(+), 111 deletions(-)
Signature · 1 line
2.5.5
PATCH 1/3 netfilter: built-in NAT support for DCCP
CONFIG_NF_NAT_PROTO_DCCP is no more a tristate. When set to y, NAT support for DCCP protocol is built-in into nf_nat.ko.
--- include/net/netfilter/nf_nat_l4proto.h | 3 +++ net/netfilter/Kconfig | 2 +- net/netfilter/Makefile | 3 ++- net/netfilter/nf_nat_core.c | 4 ++++ net/netfilter/nf_nat_proto_dccp.c | 36 +--------------------------------- 5 files changed, 11 insertions(+), 37 deletions(-)
include/net/netfilter/nf_nat_l4proto.h +3 -0
@@ -54,6 +54,9 @@ extern const struct nf_nat_l4proto nf_nat_l4proto_udp;extern const struct nf_nat_l4proto nf_nat_l4proto_icmp;extern const struct nf_nat_l4proto nf_nat_l4proto_icmpv6;extern const struct nf_nat_l4proto nf_nat_l4proto_unknown; +#if IS_ENABLED (CONFIG_NF_NAT_PROTO_DCCP ) +extern const struct nf_nat_l4proto nf_nat_l4proto_dccp; +#endif bool nf_nat_l4proto_in_range(const struct nf_conntrack_tuple *tuple, enum nf_nat_manip_type maniptype,
net/netfilter/Kconfig +1 -1
@@ -380,7 +380,7 @@ config NF_NAT_NEEDED default y config NF_NAT_PROTO_DCCP - tristate + bool depends on NF_NAT && NF_CT_PROTO_DCCP default NF_NAT && NF_CT_PROTO_DCCP
net/netfilter/Makefile +2 -1
@@ -45,6 +45,8 @@ obj-$(CONFIG_NF_CONNTRACK_TFTP) += nf_conntrack_tftp.o nf_nat-y := nf_nat_core.o nf_nat_proto_unknown.o nf_nat_proto_common.o \ nf_nat_proto_udp.o nf_nat_proto_tcp.o nf_nat_helper.o +nf_nat-$(CONFIG_NF_NAT_PROTO_DCCP) += nf_nat_proto_dccp.o + # generic transport layer logging obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o
@@ -52,7 +54,6 @@ obj-$(CONFIG_NF_NAT) += nf_nat.o obj-$(CONFIG_NF_NAT_REDIRECT) += nf_nat_redirect.o # NAT protocols (nf_nat) -obj-$(CONFIG_NF_NAT_PROTO_DCCP) += nf_nat_proto_dccp.o obj-$(CONFIG_NF_NAT_PROTO_UDPLITE) += nf_nat_proto_udplite.o obj-$(CONFIG_NF_NAT_PROTO_SCTP) += nf_nat_proto_sctp.o
net/netfilter/nf_nat_core.c +4 -0
@@ -671,6 +671,10 @@ int nf_nat_l3proto_register(const struct nf_nat_l3proto *l3proto) &nf_nat_l4proto_tcp);RCU_INIT_POINTER (nf_nat_l4protos[l3proto->l3proto][IPPROTO_UDP ], &nf_nat_l4proto_udp); +#if IS_ENABLED (CONFIG_NF_NAT_PROTO_DCCP ) +RCU_INIT_POINTER (nf_nat_l4protos[l3proto->l3proto][IPPROTO_DCCP ], + &nf_nat_l4proto_dccp); +#endif mutex_unlock (&nf_nat_proto_mutex);RCU_INIT_POINTER (nf_nat_l3protos[l3proto->l3proto], l3proto);
net/netfilter/nf_nat_proto_dccp.c +1 -35
@@ -10,8 +10,6 @@*/ #include <linux/kernel.h> -#include <linux/module.h> -#include <linux/init.h> #include <linux/skbuff.h> #include <linux/dccp.h>
@@ -73,7 +71,7 @@ dccp_manip_pkt(struct sk_buff *skb,return true; } -static const struct nf_nat_l4proto nf_nat_l4proto_dccp = { +const struct nf_nat_l4proto nf_nat_l4proto_dccp = { .l4proto =IPPROTO_DCCP , .manip_pkt = dccp_manip_pkt, .in_range = nf_nat_l4proto_in_range,
@@ -82,35 +80,3 @@ static const struct nf_nat_l4proto nf_nat_l4proto_dccp = { .nlattr_to_range = nf_nat_l4proto_nlattr_to_range,#endif }; - -static int __init nf_nat_proto_dccp_init (void ) -{ -int err; - - err =nf_nat_l4proto_register (NFPROTO_IPV4 , &nf_nat_l4proto_dccp); -if (err <0 ) - goto err1; - err =nf_nat_l4proto_register (NFPROTO_IPV6 , &nf_nat_l4proto_dccp); -if (err <0 ) - goto err2; -return 0 ; - -err2: -nf_nat_l4proto_unregister (NFPROTO_IPV4 , &nf_nat_l4proto_dccp); -err1: -return err; -} - -static void __exit nf_nat_proto_dccp_fini(void) -{ -nf_nat_l4proto_unregister (NFPROTO_IPV6 , &nf_nat_l4proto_dccp); -nf_nat_l4proto_unregister (NFPROTO_IPV4 , &nf_nat_l4proto_dccp); - -} - -module_init (nf_nat_proto_dccp_init); -module_exit (nf_nat_proto_dccp_fini); - -MODULE_AUTHOR ("Patrick McHardy <[email protected]>" ); -MODULE_DESCRIPTION ("DCCP NAT protocol helper" ); -MODULE_LICENSE ("GPL" );
Signature · 1 line
2.5.5
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 1/3] netfilter: built-in NAT support for DCCP
Quoted 17 lines · Davide Caratti
CONFIG_NF_NAT_PROTO_DCCPis no more a tristate. When set to y, NAT support for DCCP protocol is built-in into nf_nat.ko.Signed-off-by Davide Caratti <[email protected]>--- include/net/netfilter/nf_nat_l4proto.h | 3 +++ net/netfilter/Kconfig | 2 +- net/netfilter/Makefile | 3 ++- net/netfilter/nf_nat_core.c | 4 ++++ net/netfilter/nf_nat_proto_dccp.c | 36 +--------------------------------- 5 files changed, 11 insertions(+), 37 deletions(-)include/net/netfilter/nf_nat_l4proto.h +0
-0
include/net/netfilter/nf_nat_l4proto.h extern const struct nf_nat_l4proto nf_nat_l4proto_udp; · line 57
Quoted 4 lines
include/net/netfilter/nf_nat_l4proto.h +1
-0@@ -54,6 +54,9 @@ extern const struct nf_nat_l4proto nf_nat_l4proto_udp;extern const struct nf_nat_l4proto nf_nat_l4proto_icmp;extern const struct nf_nat_l4proto nf_nat_l4proto_icmpv6;extern const struct nf_nat_l4proto nf_nat_l4proto_unknown; +#if IS_ENABLED (CONFIG_NF_NAT_PROTO_DCCP )
I think you can replace this by:
#ifdef CONFIG_NF_NAT_PROTO_DCCP
given that IS_ENABLED catches the module case too.
This is is just a code readability nitpick, so whoever reads this code understands that we have no module support for this anymore.
Re: [PATCH nf-next 1/3] netfilter: built-in NAT support for DCCP
Quoted 5 lines · Pablo Neira Ayuso
I think you can replace this by:
#ifdef
CONFIG_NF_NAT_PROTO_DCCPgiven that
IS_ENABLEDcatches the module case too.
That's right, so all IS_ENABLED(...) are going to be replaced with #ifdef ... in v2.
regards,
--
davide
PATCH 2/3 netfilter: built-in NAT support for SCTP
In reply to Davide CarattiCONFIG_NF_NAT_PROTO_SCTP is no more a tristate. When set to y, NAT support for SCTP protocol is built-in into nf_nat.ko.
--- include/net/netfilter/nf_nat_l4proto.h | 3 +++ net/netfilter/Kconfig | 2 +- net/netfilter/Makefile | 2 +- net/netfilter/nf_nat_core.c | 4 ++++ net/netfilter/nf_nat_proto_sctp.c | 35 +--------------------------------- 5 files changed, 10 insertions(+), 36 deletions(-)
include/net/netfilter/nf_nat_l4proto.h +3 -0
@@ -57,6 +57,9 @@ extern const struct nf_nat_l4proto nf_nat_l4proto_unknown;#if IS_ENABLED (CONFIG_NF_NAT_PROTO_DCCP )extern const struct nf_nat_l4proto nf_nat_l4proto_dccp;#endif +#if IS_ENABLED (CONFIG_NF_NAT_PROTO_SCTP ) +extern const struct nf_nat_l4proto nf_nat_l4proto_sctp; +#endif bool nf_nat_l4proto_in_range(const struct nf_conntrack_tuple *tuple, enum nf_nat_manip_type maniptype,
net/netfilter/Kconfig +1 -1
@@ -390,7 +390,7 @@ config NF_NAT_PROTO_UDPLITE default NF_NAT && NF_CT_PROTO_UDPLITE config NF_NAT_PROTO_SCTP - tristate + bool default NF_NAT && NF_CT_PROTO_SCTP depends on NF_NAT && NF_CT_PROTO_SCTP select LIBCRC32C
net/netfilter/Makefile +1 -1
@@ -46,6 +46,7 @@ nf_nat-y := nf_nat_core.o nf_nat_proto_unknown.o nf_nat_proto_common.o \ nf_nat_proto_udp.o nf_nat_proto_tcp.o nf_nat_helper.o nf_nat-$(CONFIG_NF_NAT_PROTO_DCCP) += nf_nat_proto_dccp.o +nf_nat-$(CONFIG_NF_NAT_PROTO_SCTP) += nf_nat_proto_sctp.o # generic transport layer logging obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o
@@ -55,7 +56,6 @@ obj-$(CONFIG_NF_NAT_REDIRECT) += nf_nat_redirect.o # NAT protocols (nf_nat) obj-$(CONFIG_NF_NAT_PROTO_UDPLITE) += nf_nat_proto_udplite.o -obj-$(CONFIG_NF_NAT_PROTO_SCTP) += nf_nat_proto_sctp.o # NAT helpers obj-$(CONFIG_NF_NAT_AMANDA) += nf_nat_amanda.o
net/netfilter/nf_nat_core.c +4 -0
@@ -675,6 +675,10 @@ int nf_nat_l3proto_register(const struct nf_nat_l3proto *l3proto)RCU_INIT_POINTER (nf_nat_l4protos[l3proto->l3proto][IPPROTO_DCCP ], &nf_nat_l4proto_dccp);#endif +#if IS_ENABLED (CONFIG_NF_NAT_PROTO_SCTP ) +RCU_INIT_POINTER (nf_nat_l4protos[l3proto->l3proto][IPPROTO_SCTP ], + &nf_nat_l4proto_sctp); +#endif mutex_unlock (&nf_nat_proto_mutex);RCU_INIT_POINTER (nf_nat_l3protos[l3proto->l3proto], l3proto);
net/netfilter/nf_nat_proto_sctp.c +1 -34
@@ -7,9 +7,7 @@*/ #include <linux/types.h> -#include <linux/init.h> #include <linux/sctp.h> -#include <linux/module.h> #include <net/sctp/checksum.h> #include <net/netfilter/nf_nat_l4proto.h>
@@ -54,7 +52,7 @@ sctp_manip_pkt(struct sk_buff *skb,return true; } -static const struct nf_nat_l4proto nf_nat_l4proto_sctp = { +const struct nf_nat_l4proto nf_nat_l4proto_sctp = { .l4proto =IPPROTO_SCTP , .manip_pkt = sctp_manip_pkt, .in_range = nf_nat_l4proto_in_range,
@@ -63,34 +61,3 @@ static const struct nf_nat_l4proto nf_nat_l4proto_sctp = { .nlattr_to_range = nf_nat_l4proto_nlattr_to_range,#endif }; - -static int __init nf_nat_proto_sctp_init (void ) -{ -int err; - - err =nf_nat_l4proto_register (NFPROTO_IPV4 , &nf_nat_l4proto_sctp); -if (err <0 ) - goto err1; - err =nf_nat_l4proto_register (NFPROTO_IPV6 , &nf_nat_l4proto_sctp); -if (err <0 ) - goto err2; -return 0 ; - -err2: -nf_nat_l4proto_unregister (NFPROTO_IPV4 , &nf_nat_l4proto_sctp); -err1: -return err; -} - -static void __exit nf_nat_proto_sctp_exit(void) -{ -nf_nat_l4proto_unregister (NFPROTO_IPV6 , &nf_nat_l4proto_sctp); -nf_nat_l4proto_unregister (NFPROTO_IPV4 , &nf_nat_l4proto_sctp); -} - -module_init (nf_nat_proto_sctp_init); -module_exit (nf_nat_proto_sctp_exit); - -MODULE_LICENSE ("GPL" ); -MODULE_DESCRIPTION ("SCTP NAT protocol helper" ); -MODULE_AUTHOR ("Patrick McHardy <[email protected]>" );
Signature · 1 line
2.5.5
PATCH 3/3 netfilter: built-in NAT support for UDPlite
In reply to Davide CarattiCONFIG_NF_NAT_PROTO_UDPLITE is no more a tristate. When set to y, NAT support for UDPlite protocol is built-in into nf_nat.ko.
--- include/net/netfilter/nf_nat_l4proto.h | 3 +++ net/netfilter/Kconfig | 2 +- net/netfilter/Makefile | 5 ++--- net/netfilter/nf_nat_core.c | 4 ++++ net/netfilter/nf_nat_proto_udplite.c | 35 +--------------------------------- 5 files changed, 11 insertions(+), 38 deletions(-)
include/net/netfilter/nf_nat_l4proto.h +3 -0
@@ -60,6 +60,9 @@ extern const struct nf_nat_l4proto nf_nat_l4proto_dccp;#if IS_ENABLED (CONFIG_NF_NAT_PROTO_SCTP )extern const struct nf_nat_l4proto nf_nat_l4proto_sctp;#endif +#if IS_ENABLED (CONFIG_NF_NAT_PROTO_UDPLITE ) +extern const struct nf_nat_l4proto nf_nat_l4proto_udplite; +#endif bool nf_nat_l4proto_in_range(const struct nf_conntrack_tuple *tuple, enum nf_nat_manip_type maniptype,
net/netfilter/Kconfig +1 -1
@@ -385,7 +385,7 @@ config NF_NAT_PROTO_DCCP default NF_NAT && NF_CT_PROTO_DCCP config NF_NAT_PROTO_UDPLITE - tristate + bool depends on NF_NAT && NF_CT_PROTO_UDPLITE default NF_NAT && NF_CT_PROTO_UDPLITE
net/netfilter/Makefile +2 -3
@@ -45,8 +45,10 @@ obj-$(CONFIG_NF_CONNTRACK_TFTP) += nf_conntrack_tftp.o nf_nat-y := nf_nat_core.o nf_nat_proto_unknown.o nf_nat_proto_common.o \ nf_nat_proto_udp.o nf_nat_proto_tcp.o nf_nat_helper.o +# NAT protocols (nf_nat) nf_nat-$(CONFIG_NF_NAT_PROTO_DCCP) += nf_nat_proto_dccp.o nf_nat-$(CONFIG_NF_NAT_PROTO_SCTP) += nf_nat_proto_sctp.o +nf_nat-$(CONFIG_NF_NAT_PROTO_UDPLITE) += nf_nat_proto_udplite.o # generic transport layer logging obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o
@@ -54,9 +56,6 @@ obj-$(CONFIG_NF_LOG_COMMON) += nf_log_common.o obj-$(CONFIG_NF_NAT) += nf_nat.o obj-$(CONFIG_NF_NAT_REDIRECT) += nf_nat_redirect.o -# NAT protocols (nf_nat) -obj-$(CONFIG_NF_NAT_PROTO_UDPLITE) += nf_nat_proto_udplite.o - # NAT helpers obj-$(CONFIG_NF_NAT_AMANDA) += nf_nat_amanda.o obj-$(CONFIG_NF_NAT_FTP) += nf_nat_ftp.o
net/netfilter/nf_nat_core.c +4 -0
@@ -679,6 +679,10 @@ int nf_nat_l3proto_register(const struct nf_nat_l3proto *l3proto)RCU_INIT_POINTER (nf_nat_l4protos[l3proto->l3proto][IPPROTO_SCTP ], &nf_nat_l4proto_sctp);#endif +#if IS_ENABLED (CONFIG_NF_NAT_PROTO_UDPLITE ) +RCU_INIT_POINTER (nf_nat_l4protos[l3proto->l3proto][IPPROTO_UDPLITE ], + &nf_nat_l4proto_udplite); +#endif mutex_unlock (&nf_nat_proto_mutex);RCU_INIT_POINTER (nf_nat_l3protos[l3proto->l3proto], l3proto);
net/netfilter/nf_nat_proto_udplite.c +1 -34
@@ -8,11 +8,9 @@*/ #include <linux/types.h> -#include <linux/init.h> #include <linux/udp.h> #include <linux/netfilter.h> -#include <linux/module.h> #include <net/netfilter/nf_nat.h> #include <net/netfilter/nf_nat_l3proto.h> #include <net/netfilter/nf_nat_l4proto.h>
@@ -64,7 +62,7 @@ udplite_manip_pkt(struct sk_buff *skb,return true; } -static const struct nf_nat_l4proto nf_nat_l4proto_udplite = { +const struct nf_nat_l4proto nf_nat_l4proto_udplite = { .l4proto =IPPROTO_UDPLITE , .manip_pkt = udplite_manip_pkt, .in_range = nf_nat_l4proto_in_range,
@@ -73,34 +71,3 @@ static const struct nf_nat_l4proto nf_nat_l4proto_udplite = { .nlattr_to_range = nf_nat_l4proto_nlattr_to_range,#endif }; - -static int __init nf_nat_proto_udplite_init (void ) -{ -int err; - - err =nf_nat_l4proto_register (NFPROTO_IPV4 , &nf_nat_l4proto_udplite); -if (err <0 ) - goto err1; - err =nf_nat_l4proto_register (NFPROTO_IPV6 , &nf_nat_l4proto_udplite); -if (err <0 ) - goto err2; -return 0 ; - -err2: -nf_nat_l4proto_unregister (NFPROTO_IPV4 , &nf_nat_l4proto_udplite); -err1: -return err; -} - -static void __exit nf_nat_proto_udplite_fini(void) -{ -nf_nat_l4proto_unregister (NFPROTO_IPV6 , &nf_nat_l4proto_udplite); -nf_nat_l4proto_unregister (NFPROTO_IPV4 , &nf_nat_l4proto_udplite); -} - -module_init (nf_nat_proto_udplite_init); -module_exit (nf_nat_proto_udplite_fini); - -MODULE_LICENSE ("GPL" ); -MODULE_DESCRIPTION ("UDP-Lite NAT protocol helper" ); -MODULE_AUTHOR ("Patrick McHardy <[email protected]>" );
Signature · 1 line
2.5.5
Florian Westphal
maintainerQuoted 8 lines · Davide Caratti
The above L4 protocols usually need an explicit modprobe command (e.g "modprobe
nf_nat_proto_sctp") to provide full functionality of REDIRECT targets and SNAT/DNAT targets where port number translation is explicitly configured.
In order to remove such limitation, this series converts CONFIG_NF_NAT_PROTO_{DCCP,SCTP,UDPLITE} from tristate to boolean: in case NAT support for these protocols is enabled in the kernel configuration, it will be built into nf_nat.ko.
Sorry for not thinking of this sooner, but it would be nice to record size increase of nat module in the commit message (and perhaps size of 'old' proto_foo nat module that is removed).
Quoted 3 lines · Florian Westphal
Sorry for not thinking of this sooner, but it would be nice to record size increase of nat module in the commit message (and perhaps size of 'old'
proto_foonat module that is removed).
hi,
yes - it makes sense. I will reword and post a v2 with test results. regards,
--
davide