: nf_nat: add helpers for common NAT protocol operations
Subsystems (2)
I've queued this and the following two patches for 2.6.26 to add UDP-Lite NAT support. I'm also have some unfinished conntrack/NAT support for DCCP and almost-finished NAT support for SCTP. I'll post those patches once I've completed them.
[NETFILTER]: nf_nat: add helpers for common NAT protocol operations
Add generic ->in_range and ->unique_tuple ops to avoid duplicating them again and again for future NAT modules and save a few bytes of text:
net/ipv4/netfilter/nf_nat_proto_tcp.c:
tcp_in_range | -62 (removed)
tcp_unique_tuple | -259 # 271 -> 12, # inlines: 1 -> 0, size inlines: 7 -> 0
2 functions changed, 321 bytes removed
net/ipv4/netfilter/nf_nat_proto_udp.c:
udp_in_range | -62 (removed)
udp_unique_tuple | -259 # 271 -> 12, # inlines: 1 -> 0, size inlines: 7 -> 0
2 functions changed, 321 bytes removed
net/ipv4/netfilter/nf_nat_proto_gre.c:
gre_in_range | -62 (removed)
1 function changed, 62 bytes removed
vmlinux:
5 functions changed, 704 bytes removed
---
commit bde9b6732e54a36d59a85dcf2fbcc29e202185fb
tree 6d61196d0e75bfa0a54d47fe583a9234e3170655
parent 072a69bf9f5cdf316b6d49b7ae943827ecc3eaf8
author Patrick McHardy <[email protected]> Mon, 25 Feb 2008 14:20:28 +0100 committer Patrick McHardy <[email protected]> Mon, 25 Feb 2008 14:20:28 +0100
include/net/netfilter/nf_nat_protocol.h | 11 ++++ net/ipv4/netfilter/Makefile | 2 - net/ipv4/netfilter/nf_nat_proto_common.c | 87 ++++++++++++++++++++++++++++++ net/ipv4/netfilter/nf_nat_proto_gre.c | 20 ------- net/ipv4/netfilter/nf_nat_proto_tcp.c | 65 +--------------------- net/ipv4/netfilter/nf_nat_proto_udp.c | 64 +--------------------- 6 files changed, 108 insertions(+), 141 deletions(-)
include/net/netfilter/nf_nat_protocol.h +11 -0
@@ -62,6 +62,17 @@ extern int init_protocols(void) __init;extern void cleanup_protocols (void );extern const struct nf_nat_protocol *find_nat_proto (u_int16_t protonum); +extern int nf_nat_proto_in_range (const struct nf_conntrack_tuple *tuple, +enum nf_nat_manip_type maniptype, +const union nf_conntrack_man_proto *min, +const union nf_conntrack_man_proto *max); + +extern int nf_nat_proto_unique_tuple (struct nf_conntrack_tuple *tuple, +const struct nf_nat_range *range, +enum nf_nat_manip_type maniptype, +const struct nf_conn *ct, +u_int16_t *rover); +extern int nf_nat_port_range_to_nlattr (struct sk_buff *skb,const struct nf_nat_range *range); extern int nf_nat_port_nlattr_to_range(struct nlattr *tb[],
net/ipv4/netfilter/Makefile +1 -1
@@ -10,7 +10,7 @@ nf_conntrack_ipv4-objs += nf_conntrack_l3proto_ipv4_compat.o endif endif -nf_nat-objs := nf_nat_core.o nf_nat_helper.o nf_nat_proto_unknown.o nf_nat_proto_tcp.o nf_nat_proto_udp.o nf_nat_proto_icmp.o +nf_nat-objs := nf_nat_core.o nf_nat_helper.o nf_nat_proto_unknown.o nf_nat_proto_common.o nf_nat_proto_tcp.o nf_nat_proto_udp.o nf_nat_proto_icmp.o iptable_nat-objs := nf_nat_rule.o nf_nat_standalone.o # connection tracking
net/ipv4/netfilter/nf_nat_proto_common.c new file +87 -0
87 lines not on this page · raw message
net/ipv4/netfilter/nf_nat_proto_gre.c +1 -19
@@ -36,24 +36,6 @@ MODULE_LICENSE("GPL");MODULE_AUTHOR ("Harald Welte <[email protected]>" );MODULE_DESCRIPTION ("Netfilter NAT protocol helper module for GRE" ); -/* is key in given range between min and max */ -static int -gre_in_range (const struct nf_conntrack_tuple *tuple, -enum nf_nat_manip_type maniptype, -const union nf_conntrack_man_proto *min, -const union nf_conntrack_man_proto *max) -{ -__be16 key; - -if (maniptype ==IP_NAT_MANIP_SRC ) - key = tuple->src.u.gre.key; -else - key = tuple->dst.u.gre.key; - -return ntohs (key) >=ntohs (min->gre.key) && -ntohs (key) <=ntohs (max->gre.key); -} -/* generate unique tuple ... */ static int gre_unique_tuple(struct nf_conntrack_tuple *tuple,
@@ -140,7 +122,7 @@ static const struct nf_nat_protocol gre = { .protonum = IPPROTO_GRE, .me = THIS_MODULE, .manip_pkt = gre_manip_pkt, - .in_range = gre_in_range, + .in_range = nf_nat_proto_in_range, .unique_tuple = gre_unique_tuple,#if defined(CONFIG_NF_CT_NETLINK ) || defined(CONFIG_NF_CT_NETLINK_MODULE ) .range_to_nlattr = nf_nat_port_range_to_nlattr,
net/ipv4/netfilter/nf_nat_proto_tcp.c +4 -61
89 lines not on this page · raw message
net/ipv4/netfilter/nf_nat_proto_udp.c +4 -60
88 lines not on this page · raw message