aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2008-04-14 05:15:47 -0400
committerPatrick McHardy <kaber@trash.net>2008-04-14 05:15:47 -0400
commit535b57c7c1524125444aa1b874332f6ff1608ef5 (patch)
treec127d9bce1b29158343447967c50edd51e357890
parent5abd363f738dcd048ee790fb9b84d0768a8a407f (diff)
[NETFILTER]: nf_nat: move NAT ctnetlink helpers to nf_nat_proto_common
Move to nf_nat_proto_common and rename to nf_nat_proto_... since they're also used by protocols that don't have port numbers. Signed-off-by: Patrick McHardy <kaber@trash.net>
-rw-r--r--include/net/netfilter/nf_nat_protocol.h8
-rw-r--r--net/ipv4/netfilter/nf_nat_core.c40
-rw-r--r--net/ipv4/netfilter/nf_nat_proto_common.c38
-rw-r--r--net/ipv4/netfilter/nf_nat_proto_gre.c4
-rw-r--r--net/ipv4/netfilter/nf_nat_proto_icmp.c4
-rw-r--r--net/ipv4/netfilter/nf_nat_proto_tcp.c4
-rw-r--r--net/ipv4/netfilter/nf_nat_proto_udp.c4
7 files changed, 50 insertions, 52 deletions
diff --git a/include/net/netfilter/nf_nat_protocol.h b/include/net/netfilter/nf_nat_protocol.h
index fa06f6d0de54..8ce227624eac 100644
--- a/include/net/netfilter/nf_nat_protocol.h
+++ b/include/net/netfilter/nf_nat_protocol.h
@@ -73,9 +73,9 @@ extern int nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple,
73 const struct nf_conn *ct, 73 const struct nf_conn *ct,
74 u_int16_t *rover); 74 u_int16_t *rover);
75 75
76extern int nf_nat_port_range_to_nlattr(struct sk_buff *skb, 76extern int nf_nat_proto_range_to_nlattr(struct sk_buff *skb,
77 const struct nf_nat_range *range); 77 const struct nf_nat_range *range);
78extern int nf_nat_port_nlattr_to_range(struct nlattr *tb[], 78extern int nf_nat_proto_nlattr_to_range(struct nlattr *tb[],
79 struct nf_nat_range *range); 79 struct nf_nat_range *range);
80 80
81#endif /*_NF_NAT_PROTO_H*/ 81#endif /*_NF_NAT_PROTO_H*/
diff --git a/net/ipv4/netfilter/nf_nat_core.c b/net/ipv4/netfilter/nf_nat_core.c
index 9c8aa8df2d5e..9320c7ac5729 100644
--- a/net/ipv4/netfilter/nf_nat_core.c
+++ b/net/ipv4/netfilter/nf_nat_core.c
@@ -544,46 +544,6 @@ void nf_nat_protocol_unregister(const struct nf_nat_protocol *proto)
544} 544}
545EXPORT_SYMBOL(nf_nat_protocol_unregister); 545EXPORT_SYMBOL(nf_nat_protocol_unregister);
546 546
547#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
548int
549nf_nat_port_range_to_nlattr(struct sk_buff *skb,
550 const struct nf_nat_range *range)
551{
552 NLA_PUT_BE16(skb, CTA_PROTONAT_PORT_MIN, range->min.tcp.port);
553 NLA_PUT_BE16(skb, CTA_PROTONAT_PORT_MAX, range->max.tcp.port);
554
555 return 0;
556
557nla_put_failure:
558 return -1;
559}
560EXPORT_SYMBOL_GPL(nf_nat_port_nlattr_to_range);
561
562int
563nf_nat_port_nlattr_to_range(struct nlattr *tb[], struct nf_nat_range *range)
564{
565 int ret = 0;
566
567 /* we have to return whether we actually parsed something or not */
568
569 if (tb[CTA_PROTONAT_PORT_MIN]) {
570 ret = 1;
571 range->min.tcp.port = nla_get_be16(tb[CTA_PROTONAT_PORT_MIN]);
572 }
573
574 if (!tb[CTA_PROTONAT_PORT_MAX]) {
575 if (ret)
576 range->max.tcp.port = range->min.tcp.port;
577 } else {
578 ret = 1;
579 range->max.tcp.port = nla_get_be16(tb[CTA_PROTONAT_PORT_MAX]);
580 }
581
582 return ret;
583}
584EXPORT_SYMBOL_GPL(nf_nat_port_range_to_nlattr);
585#endif
586
587/* Noone using conntrack by the time this called. */ 547/* Noone using conntrack by the time this called. */
588static void nf_nat_cleanup_conntrack(struct nf_conn *ct) 548static void nf_nat_cleanup_conntrack(struct nf_conn *ct)
589{ 549{
diff --git a/net/ipv4/netfilter/nf_nat_proto_common.c b/net/ipv4/netfilter/nf_nat_proto_common.c
index 871ab0eb325d..ef4dc3988925 100644
--- a/net/ipv4/netfilter/nf_nat_proto_common.c
+++ b/net/ipv4/netfilter/nf_nat_proto_common.c
@@ -88,3 +88,41 @@ int nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple,
88 return 0; 88 return 0;
89} 89}
90EXPORT_SYMBOL_GPL(nf_nat_proto_unique_tuple); 90EXPORT_SYMBOL_GPL(nf_nat_proto_unique_tuple);
91
92#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
93int nf_nat_proto_range_to_nlattr(struct sk_buff *skb,
94 const struct nf_nat_range *range)
95{
96 NLA_PUT_BE16(skb, CTA_PROTONAT_PORT_MIN, range->min.all);
97 NLA_PUT_BE16(skb, CTA_PROTONAT_PORT_MAX, range->max.all);
98 return 0;
99
100nla_put_failure:
101 return -1;
102}
103EXPORT_SYMBOL_GPL(nf_nat_proto_nlattr_to_range);
104
105int nf_nat_proto_nlattr_to_range(struct nlattr *tb[],
106 struct nf_nat_range *range)
107{
108 int ret = 0;
109
110 /* we have to return whether we actually parsed something or not */
111
112 if (tb[CTA_PROTONAT_PORT_MIN]) {
113 ret = 1;
114 range->min.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MIN]);
115 }
116
117 if (!tb[CTA_PROTONAT_PORT_MAX]) {
118 if (ret)
119 range->max.all = range->min.all;
120 } else {
121 ret = 1;
122 range->max.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MAX]);
123 }
124
125 return ret;
126}
127EXPORT_SYMBOL_GPL(nf_nat_proto_range_to_nlattr);
128#endif
diff --git a/net/ipv4/netfilter/nf_nat_proto_gre.c b/net/ipv4/netfilter/nf_nat_proto_gre.c
index 87af63d9e692..71b0935ee1c8 100644
--- a/net/ipv4/netfilter/nf_nat_proto_gre.c
+++ b/net/ipv4/netfilter/nf_nat_proto_gre.c
@@ -125,8 +125,8 @@ static const struct nf_nat_protocol gre = {
125 .in_range = nf_nat_proto_in_range, 125 .in_range = nf_nat_proto_in_range,
126 .unique_tuple = gre_unique_tuple, 126 .unique_tuple = gre_unique_tuple,
127#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE) 127#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
128 .range_to_nlattr = nf_nat_port_range_to_nlattr, 128 .range_to_nlattr = nf_nat_proto_range_to_nlattr,
129 .nlattr_to_range = nf_nat_port_nlattr_to_range, 129 .nlattr_to_range = nf_nat_proto_nlattr_to_range,
130#endif 130#endif
131}; 131};
132 132
diff --git a/net/ipv4/netfilter/nf_nat_proto_icmp.c b/net/ipv4/netfilter/nf_nat_proto_icmp.c
index 03a02969aa57..ca601f84c4dc 100644
--- a/net/ipv4/netfilter/nf_nat_proto_icmp.c
+++ b/net/ipv4/netfilter/nf_nat_proto_icmp.c
@@ -79,7 +79,7 @@ const struct nf_nat_protocol nf_nat_protocol_icmp = {
79 .in_range = icmp_in_range, 79 .in_range = icmp_in_range,
80 .unique_tuple = icmp_unique_tuple, 80 .unique_tuple = icmp_unique_tuple,
81#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE) 81#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
82 .range_to_nlattr = nf_nat_port_range_to_nlattr, 82 .range_to_nlattr = nf_nat_proto_range_to_nlattr,
83 .nlattr_to_range = nf_nat_port_nlattr_to_range, 83 .nlattr_to_range = nf_nat_proto_nlattr_to_range,
84#endif 84#endif
85}; 85};
diff --git a/net/ipv4/netfilter/nf_nat_proto_tcp.c b/net/ipv4/netfilter/nf_nat_proto_tcp.c
index f8c498fc24fd..1d73a11f55d9 100644
--- a/net/ipv4/netfilter/nf_nat_proto_tcp.c
+++ b/net/ipv4/netfilter/nf_nat_proto_tcp.c
@@ -88,7 +88,7 @@ const struct nf_nat_protocol nf_nat_protocol_tcp = {
88 .in_range = nf_nat_proto_in_range, 88 .in_range = nf_nat_proto_in_range,
89 .unique_tuple = tcp_unique_tuple, 89 .unique_tuple = tcp_unique_tuple,
90#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE) 90#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
91 .range_to_nlattr = nf_nat_port_range_to_nlattr, 91 .range_to_nlattr = nf_nat_proto_range_to_nlattr,
92 .nlattr_to_range = nf_nat_port_nlattr_to_range, 92 .nlattr_to_range = nf_nat_proto_nlattr_to_range,
93#endif 93#endif
94}; 94};
diff --git a/net/ipv4/netfilter/nf_nat_proto_udp.c b/net/ipv4/netfilter/nf_nat_proto_udp.c
index a182f5ac3177..f36ce552a161 100644
--- a/net/ipv4/netfilter/nf_nat_proto_udp.c
+++ b/net/ipv4/netfilter/nf_nat_proto_udp.c
@@ -79,7 +79,7 @@ const struct nf_nat_protocol nf_nat_protocol_udp = {
79 .in_range = nf_nat_proto_in_range, 79 .in_range = nf_nat_proto_in_range,
80 .unique_tuple = udp_unique_tuple, 80 .unique_tuple = udp_unique_tuple,
81#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE) 81#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
82 .range_to_nlattr = nf_nat_port_range_to_nlattr, 82 .range_to_nlattr = nf_nat_proto_range_to_nlattr,
83 .nlattr_to_range = nf_nat_port_nlattr_to_range, 83 .nlattr_to_range = nf_nat_proto_nlattr_to_range,
84#endif 84#endif
85}; 85};