netfilter: nat: remove l4proto->nlattr_to_range
authorFlorian Westphal <fw@strlen.de>
Thu, 13 Dec 2018 15:01:32 +0000 (16:01 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 17 Dec 2018 22:33:23 +0000 (23:33 +0100)
all protocols did set this to nf_nat_l4proto_nlattr_to_range, so
just call it directly.

The important difference is that we'll now also call it for
protocols that we don't support (i.e., nf_nat_proto_unknown did
not provide .nlattr_to_range).

However, there should be no harm, even icmp provided this callback.
If we don't implement a specific l4nat for this, nothing would make
use of this information, so adding a big switch/case construct listing
all supported l4protocols seems a bit pointless.

This change leaves a single function pointer in the l4proto struct.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/net/netfilter/nf_nat_l4proto.h
net/ipv4/netfilter/nf_nat_proto_gre.c
net/ipv4/netfilter/nf_nat_proto_icmp.c
net/ipv6/netfilter/nf_nat_proto_icmpv6.c
net/netfilter/Makefile
net/netfilter/nf_nat_core.c
net/netfilter/nf_nat_proto_common.c [deleted file]
net/netfilter/nf_nat_proto_dccp.c
net/netfilter/nf_nat_proto_sctp.c
net/netfilter/nf_nat_proto_tcp.c
net/netfilter/nf_nat_proto_udp.c

index ebf7cbf605cb81f1482e312eedee781dd330c7cc..406f7effeb8e242c59b8aebe7cdb2d4e709ab5e7 100644 (file)
@@ -20,9 +20,6 @@ struct nf_nat_l4proto {
                          unsigned int iphdroff, unsigned int hdroff,
                          const struct nf_conntrack_tuple *tuple,
                          enum nf_nat_manip_type maniptype);
-
-       int (*nlattr_to_range)(struct nlattr *tb[],
-                              struct nf_nat_range2 *range);
 };
 
 /* Protocol registration. */
@@ -48,7 +45,4 @@ extern const struct nf_nat_l4proto nf_nat_l4proto_sctp;
 extern const struct nf_nat_l4proto nf_nat_l4proto_udplite;
 #endif
 
-int nf_nat_l4proto_nlattr_to_range(struct nlattr *tb[],
-                                  struct nf_nat_range2 *range);
-
 #endif /*_NF_NAT_L4PROTO_H*/
index 94b735dd570d14328259ed2619bd7e28f443b4b7..86af36651edde3ccf0805e5f7a9c632e67419466 100644 (file)
@@ -80,9 +80,6 @@ gre_manip_pkt(struct sk_buff *skb,
 static const struct nf_nat_l4proto gre = {
        .l4proto                = IPPROTO_GRE,
        .manip_pkt              = gre_manip_pkt,
-#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
-       .nlattr_to_range        = nf_nat_l4proto_nlattr_to_range,
-#endif
 };
 
 static int __init nf_nat_proto_gre_init(void)
index f532e22159708dbd2b0ce0e11a285fc3229b1222..4fecb3f2c55ad6d6ce33f1d6f457d5e69766cba9 100644 (file)
@@ -39,7 +39,4 @@ icmp_manip_pkt(struct sk_buff *skb,
 const struct nf_nat_l4proto nf_nat_l4proto_icmp = {
        .l4proto                = IPPROTO_ICMP,
        .manip_pkt              = icmp_manip_pkt,
-#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
-       .nlattr_to_range        = nf_nat_l4proto_nlattr_to_range,
-#endif
 };
index ffae55c1fb8d5af3cf3fd4b6ac6685a446a19013..14717c226cec418eb681c0899548107b8eed8b24 100644 (file)
@@ -47,7 +47,4 @@ icmpv6_manip_pkt(struct sk_buff *skb,
 const struct nf_nat_l4proto nf_nat_l4proto_icmpv6 = {
        .l4proto                = IPPROTO_ICMPV6,
        .manip_pkt              = icmpv6_manip_pkt,
-#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
-       .nlattr_to_range        = nf_nat_l4proto_nlattr_to_range,
-#endif
 };
index 4ddf3ef51ecef1262fe760934f5bb6ccca23d5ba..852e47cd769b38fd80a6cc2e2a1bdaa2233734d3 100644 (file)
@@ -47,7 +47,7 @@ obj-$(CONFIG_NF_CONNTRACK_SANE) += nf_conntrack_sane.o
 obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o
 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-y       := nf_nat_core.o nf_nat_proto_unknown.o \
                   nf_nat_proto_udp.o nf_nat_proto_tcp.o nf_nat_helper.o
 
 # NAT protocols (nf_nat)
index d0351e0f21ad0d3779534e473c676d89a10e5355..2d7fac80341b2906d323a45ddc53cd4a1d3682cf 100644 (file)
@@ -946,12 +946,26 @@ static const struct nla_policy protonat_nla_policy[CTA_PROTONAT_MAX+1] = {
        [CTA_PROTONAT_PORT_MAX] = { .type = NLA_U16 },
 };
 
+static int nf_nat_l4proto_nlattr_to_range(struct nlattr *tb[],
+                                         struct nf_nat_range2 *range)
+{
+       if (tb[CTA_PROTONAT_PORT_MIN]) {
+               range->min_proto.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MIN]);
+               range->max_proto.all = range->min_proto.all;
+               range->flags |= NF_NAT_RANGE_PROTO_SPECIFIED;
+       }
+       if (tb[CTA_PROTONAT_PORT_MAX]) {
+               range->max_proto.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MAX]);
+               range->flags |= NF_NAT_RANGE_PROTO_SPECIFIED;
+       }
+       return 0;
+}
+
 static int nfnetlink_parse_nat_proto(struct nlattr *attr,
                                     const struct nf_conn *ct,
                                     struct nf_nat_range2 *range)
 {
        struct nlattr *tb[CTA_PROTONAT_MAX+1];
-       const struct nf_nat_l4proto *l4proto;
        int err;
 
        err = nla_parse_nested(tb, CTA_PROTONAT_MAX, attr,
@@ -959,11 +973,7 @@ static int nfnetlink_parse_nat_proto(struct nlattr *attr,
        if (err < 0)
                return err;
 
-       l4proto = __nf_nat_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct));
-       if (l4proto->nlattr_to_range)
-               err = l4proto->nlattr_to_range(tb, range);
-
-       return err;
+       return nf_nat_l4proto_nlattr_to_range(tb, range);
 }
 
 static const struct nla_policy nat_nla_policy[CTA_NAT_MAX+1] = {
diff --git a/net/netfilter/nf_nat_proto_common.c b/net/netfilter/nf_nat_proto_common.c
deleted file mode 100644 (file)
index a155cfa..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/* (C) 1999-2001 Paul `Rusty' Russell
- * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org>
- * (C) 2008 Patrick McHardy <kaber@trash.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#include <linux/types.h>
-#include <linux/random.h>
-#include <linux/netfilter.h>
-#include <linux/export.h>
-
-#include <net/netfilter/nf_nat.h>
-#include <net/netfilter/nf_nat_core.h>
-#include <net/netfilter/nf_nat_l3proto.h>
-#include <net/netfilter/nf_nat_l4proto.h>
-
-#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
-int nf_nat_l4proto_nlattr_to_range(struct nlattr *tb[],
-                                  struct nf_nat_range2 *range)
-{
-       if (tb[CTA_PROTONAT_PORT_MIN]) {
-               range->min_proto.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MIN]);
-               range->max_proto.all = range->min_proto.all;
-               range->flags |= NF_NAT_RANGE_PROTO_SPECIFIED;
-       }
-       if (tb[CTA_PROTONAT_PORT_MAX]) {
-               range->max_proto.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MAX]);
-               range->flags |= NF_NAT_RANGE_PROTO_SPECIFIED;
-       }
-       return 0;
-}
-EXPORT_SYMBOL_GPL(nf_nat_l4proto_nlattr_to_range);
-#endif
index a5ed1e3e4f2288d35033f1bf0bdf8e707af5c84d..ab0b1384717d01e88b7274343992533f19089630 100644 (file)
@@ -61,7 +61,4 @@ dccp_manip_pkt(struct sk_buff *skb,
 const struct nf_nat_l4proto nf_nat_l4proto_dccp = {
        .l4proto                = IPPROTO_DCCP,
        .manip_pkt              = dccp_manip_pkt,
-#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
-       .nlattr_to_range        = nf_nat_l4proto_nlattr_to_range,
-#endif
 };
index ff5f5bbd2ff1164fa7e28812feddd41bdf49f704..37a9d347a0296a333fcde0ce22cf6fbb6f9ff002 100644 (file)
@@ -56,7 +56,4 @@ sctp_manip_pkt(struct sk_buff *skb,
 const struct nf_nat_l4proto nf_nat_l4proto_sctp = {
        .l4proto                = IPPROTO_SCTP,
        .manip_pkt              = sctp_manip_pkt,
-#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
-       .nlattr_to_range        = nf_nat_l4proto_nlattr_to_range,
-#endif
 };
index c938ecf7e0b009317714abfccb5fc6daf503118f..d378b6c31d34558cc79b6d5c6855bb02463e650d 100644 (file)
@@ -64,7 +64,4 @@ tcp_manip_pkt(struct sk_buff *skb,
 const struct nf_nat_l4proto nf_nat_l4proto_tcp = {
        .l4proto                = IPPROTO_TCP,
        .manip_pkt              = tcp_manip_pkt,
-#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
-       .nlattr_to_range        = nf_nat_l4proto_nlattr_to_range,
-#endif
 };
index 6703eb005c678bbab9d7425b88e55d0643a49366..25fc6138fbf7159173000fb340eb95156bbd614d 100644 (file)
@@ -85,16 +85,10 @@ static bool udplite_manip_pkt(struct sk_buff *skb,
 const struct nf_nat_l4proto nf_nat_l4proto_udplite = {
        .l4proto                = IPPROTO_UDPLITE,
        .manip_pkt              = udplite_manip_pkt,
-#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
-       .nlattr_to_range        = nf_nat_l4proto_nlattr_to_range,
-#endif
 };
 #endif /* CONFIG_NF_NAT_PROTO_UDPLITE */
 
 const struct nf_nat_l4proto nf_nat_l4proto_udp = {
        .l4proto                = IPPROTO_UDP,
        .manip_pkt              = udp_manip_pkt,
-#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
-       .nlattr_to_range        = nf_nat_l4proto_nlattr_to_range,
-#endif
 };