Skip to content

Commit

Permalink
netfilter: nat: remove l4proto->nlattr_to_range
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Pablo Neira Ayuso <[email protected]>
  • Loading branch information
Florian Westphal authored and ummakynes committed Dec 17, 2018
1 parent fe2d002 commit 76b9001
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 73 deletions.
6 changes: 0 additions & 6 deletions include/net/netfilter/nf_nat_l4proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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*/
3 changes: 0 additions & 3 deletions net/ipv4/netfilter/nf_nat_proto_gre.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions net/ipv4/netfilter/nf_nat_proto_icmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
3 changes: 0 additions & 3 deletions net/ipv6/netfilter/nf_nat_proto_icmpv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
2 changes: 1 addition & 1 deletion net/netfilter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 16 additions & 6 deletions net/netfilter/nf_nat_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,24 +946,34 @@ 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,
protonat_nla_policy, NULL);
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] = {
Expand Down
36 changes: 0 additions & 36 deletions net/netfilter/nf_nat_proto_common.c

This file was deleted.

3 changes: 0 additions & 3 deletions net/netfilter/nf_nat_proto_dccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
3 changes: 0 additions & 3 deletions net/netfilter/nf_nat_proto_sctp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
3 changes: 0 additions & 3 deletions net/netfilter/nf_nat_proto_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
6 changes: 0 additions & 6 deletions net/netfilter/nf_nat_proto_udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

0 comments on commit 76b9001

Please sign in to comment.