Skip to content

Commit faec18d

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nat: remove l4proto->manip_pkt
This removes the last l4proto indirection, the two callers, the l3proto packet mangling helpers for ipv4 and ipv6, now call the nf_nat_l4proto_manip_pkt() helper. nf_nat_proto_{dccp,tcp,sctp,gre,icmp,icmpv6} are left behind, even though they contain no functionality anymore to not clutter this patch. Next patch will remove the empty files and the nf_nat_l4proto struct. nf_nat_proto_udp.c is renamed to nf_nat_proto.c, as it now contains the other nat manip functionality as well, not just udp and udplite. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 76b9001 commit faec18d

16 files changed

Lines changed: 365 additions & 357 deletions

‎include/net/netfilter/nf_nat_l4proto.h‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ struct nf_nat_l4proto {
1212
/* Protocol number. */
1313
u8 l4proto;
1414

15-
/* Translate a packet to the target according to manip type.
16-
* Return true if succeeded.
17-
*/
18-
bool (*manip_pkt)(struct sk_buff *skb,
19-
const struct nf_nat_l3proto *l3proto,
20-
unsigned int iphdroff, unsigned int hdroff,
21-
const struct nf_conntrack_tuple *tuple,
22-
enum nf_nat_manip_type maniptype);
2315
};
2416

2517
/* Protocol registration. */
@@ -29,6 +21,13 @@ void nf_nat_l4proto_unregister(u8 l3proto,
2921

3022
const struct nf_nat_l4proto *__nf_nat_l4proto_find(u8 l3proto, u8 l4proto);
3123

24+
/* Translate a packet to the target according to manip type. Return on success. */
25+
bool nf_nat_l4proto_manip_pkt(struct sk_buff *skb,
26+
const struct nf_nat_l3proto *l3proto,
27+
unsigned int iphdroff, unsigned int hdroff,
28+
const struct nf_conntrack_tuple *tuple,
29+
enum nf_nat_manip_type maniptype);
30+
3231
/* Built-in protocols. */
3332
extern const struct nf_nat_l4proto nf_nat_l4proto_tcp;
3433
extern const struct nf_nat_l4proto nf_nat_l4proto_udp;

‎net/ipv4/netfilter/Kconfig‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,10 @@ config NF_NAT_SNMP_BASIC
156156

157157
To compile it as a module, choose M here. If unsure, say N.
158158

159-
config NF_NAT_PROTO_GRE
160-
tristate
161-
depends on NF_CT_PROTO_GRE
162-
163159
config NF_NAT_PPTP
164160
tristate
165161
depends on NF_CONNTRACK
166162
default NF_CONNTRACK_PPTP
167-
select NF_NAT_PROTO_GRE
168163

169164
config NF_NAT_H323
170165
tristate

‎net/ipv4/netfilter/nf_nat_l3proto_ipv4.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ static bool nf_nat_ipv4_manip_pkt(struct sk_buff *skb,
7777
iph = (void *)skb->data + iphdroff;
7878
hdroff = iphdroff + iph->ihl * 4;
7979

80-
if (!l4proto->manip_pkt(skb, &nf_nat_l3proto_ipv4, iphdroff, hdroff,
81-
target, maniptype))
80+
if (!nf_nat_l4proto_manip_pkt(skb, &nf_nat_l3proto_ipv4, iphdroff,
81+
hdroff, target, maniptype))
8282
return false;
8383
iph = (void *)skb->data + iphdroff;
8484

‎net/ipv4/netfilter/nf_nat_pptp.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,6 @@ pptp_inbound_pkt(struct sk_buff *skb,
299299

300300
static int __init nf_nat_helper_pptp_init(void)
301301
{
302-
nf_nat_need_gre();
303-
304302
BUG_ON(nf_nat_pptp_hook_outbound != NULL);
305303
RCU_INIT_POINTER(nf_nat_pptp_hook_outbound, pptp_outbound_pkt);
306304

‎net/ipv4/netfilter/nf_nat_proto_gre.c‎

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -37,49 +37,8 @@ MODULE_LICENSE("GPL");
3737
MODULE_AUTHOR("Harald Welte <laforge@gnumonks.org>");
3838
MODULE_DESCRIPTION("Netfilter NAT protocol helper module for GRE");
3939

40-
/* manipulate a GRE packet according to maniptype */
41-
static bool
42-
gre_manip_pkt(struct sk_buff *skb,
43-
const struct nf_nat_l3proto *l3proto,
44-
unsigned int iphdroff, unsigned int hdroff,
45-
const struct nf_conntrack_tuple *tuple,
46-
enum nf_nat_manip_type maniptype)
47-
{
48-
const struct gre_base_hdr *greh;
49-
struct pptp_gre_header *pgreh;
50-
51-
/* pgreh includes two optional 32bit fields which are not required
52-
* to be there. That's where the magic '8' comes from */
53-
if (!skb_make_writable(skb, hdroff + sizeof(*pgreh) - 8))
54-
return false;
55-
56-
greh = (void *)skb->data + hdroff;
57-
pgreh = (struct pptp_gre_header *)greh;
58-
59-
/* we only have destination manip of a packet, since 'source key'
60-
* is not present in the packet itself */
61-
if (maniptype != NF_NAT_MANIP_DST)
62-
return true;
63-
64-
switch (greh->flags & GRE_VERSION) {
65-
case GRE_VERSION_0:
66-
/* We do not currently NAT any GREv0 packets.
67-
* Try to behave like "nf_nat_proto_unknown" */
68-
break;
69-
case GRE_VERSION_1:
70-
pr_debug("call_id -> 0x%04x\n", ntohs(tuple->dst.u.gre.key));
71-
pgreh->call_id = tuple->dst.u.gre.key;
72-
break;
73-
default:
74-
pr_debug("can't nat unknown GRE version\n");
75-
return false;
76-
}
77-
return true;
78-
}
79-
8040
static const struct nf_nat_l4proto gre = {
8141
.l4proto = IPPROTO_GRE,
82-
.manip_pkt = gre_manip_pkt,
8342
};
8443

8544
static int __init nf_nat_proto_gre_init(void)

‎net/ipv4/netfilter/nf_nat_proto_icmp.c‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,12 @@
1010
#include <linux/init.h>
1111
#include <linux/export.h>
1212
#include <linux/ip.h>
13-
#include <linux/icmp.h>
1413

1514
#include <linux/netfilter.h>
1615
#include <net/netfilter/nf_nat.h>
1716
#include <net/netfilter/nf_nat_core.h>
1817
#include <net/netfilter/nf_nat_l4proto.h>
1918

20-
static bool
21-
icmp_manip_pkt(struct sk_buff *skb,
22-
const struct nf_nat_l3proto *l3proto,
23-
unsigned int iphdroff, unsigned int hdroff,
24-
const struct nf_conntrack_tuple *tuple,
25-
enum nf_nat_manip_type maniptype)
26-
{
27-
struct icmphdr *hdr;
28-
29-
if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
30-
return false;
31-
32-
hdr = (struct icmphdr *)(skb->data + hdroff);
33-
inet_proto_csum_replace2(&hdr->checksum, skb,
34-
hdr->un.echo.id, tuple->src.u.icmp.id, false);
35-
hdr->un.echo.id = tuple->src.u.icmp.id;
36-
return true;
37-
}
38-
3919
const struct nf_nat_l4proto nf_nat_l4proto_icmp = {
4020
.l4proto = IPPROTO_ICMP,
41-
.manip_pkt = icmp_manip_pkt,
4221
};

‎net/ipv6/netfilter/nf_nat_l3proto_ipv6.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ static bool nf_nat_ipv6_manip_pkt(struct sk_buff *skb,
8383
goto manip_addr;
8484

8585
if ((frag_off & htons(~0x7)) == 0 &&
86-
!l4proto->manip_pkt(skb, &nf_nat_l3proto_ipv6, iphdroff, hdroff,
87-
target, maniptype))
86+
!nf_nat_l4proto_manip_pkt(skb, &nf_nat_l3proto_ipv6, iphdroff, hdroff,
87+
target, maniptype))
8888
return false;
8989

9090
/* must reload, offset might have changed */

‎net/ipv6/netfilter/nf_nat_proto_icmpv6.c‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,6 @@
1919
#include <net/netfilter/nf_nat_l3proto.h>
2020
#include <net/netfilter/nf_nat_l4proto.h>
2121

22-
static bool
23-
icmpv6_manip_pkt(struct sk_buff *skb,
24-
const struct nf_nat_l3proto *l3proto,
25-
unsigned int iphdroff, unsigned int hdroff,
26-
const struct nf_conntrack_tuple *tuple,
27-
enum nf_nat_manip_type maniptype)
28-
{
29-
struct icmp6hdr *hdr;
30-
31-
if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
32-
return false;
33-
34-
hdr = (struct icmp6hdr *)(skb->data + hdroff);
35-
l3proto->csum_update(skb, iphdroff, &hdr->icmp6_cksum,
36-
tuple, maniptype);
37-
if (hdr->icmp6_type == ICMPV6_ECHO_REQUEST ||
38-
hdr->icmp6_type == ICMPV6_ECHO_REPLY) {
39-
inet_proto_csum_replace2(&hdr->icmp6_cksum, skb,
40-
hdr->icmp6_identifier,
41-
tuple->src.u.icmp.id, false);
42-
hdr->icmp6_identifier = tuple->src.u.icmp.id;
43-
}
44-
return true;
45-
}
46-
4722
const struct nf_nat_l4proto nf_nat_l4proto_icmpv6 = {
4823
.l4proto = IPPROTO_ICMPV6,
49-
.manip_pkt = icmpv6_manip_pkt,
5024
};

‎net/netfilter/Kconfig‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -403,21 +403,6 @@ config NF_NAT_NEEDED
403403
depends on NF_NAT
404404
default y
405405

406-
config NF_NAT_PROTO_DCCP
407-
bool
408-
depends on NF_NAT && NF_CT_PROTO_DCCP
409-
default NF_NAT && NF_CT_PROTO_DCCP
410-
411-
config NF_NAT_PROTO_UDPLITE
412-
bool
413-
depends on NF_NAT && NF_CT_PROTO_UDPLITE
414-
default NF_NAT && NF_CT_PROTO_UDPLITE
415-
416-
config NF_NAT_PROTO_SCTP
417-
bool
418-
default NF_NAT && NF_CT_PROTO_SCTP
419-
depends on NF_NAT && NF_CT_PROTO_SCTP
420-
421406
config NF_NAT_AMANDA
422407
tristate
423408
depends on NF_CONNTRACK && NF_NAT

‎net/netfilter/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ obj-$(CONFIG_NF_CONNTRACK_SIP) += nf_conntrack_sip.o
4848
obj-$(CONFIG_NF_CONNTRACK_TFTP) += nf_conntrack_tftp.o
4949

5050
nf_nat-y := nf_nat_core.o nf_nat_proto_unknown.o \
51-
nf_nat_proto_udp.o nf_nat_proto_tcp.o nf_nat_helper.o
51+
nf_nat_proto.o nf_nat_proto_tcp.o nf_nat_helper.o
5252

5353
# NAT protocols (nf_nat)
5454
nf_nat-$(CONFIG_NF_NAT_PROTO_DCCP) += nf_nat_proto_dccp.o

0 commit comments

Comments
 (0)