]>
Commit | Line | Data |
---|---|---|
6185f870 PM |
1 | /* (C) 1999-2001 Paul `Rusty' Russell |
2 | * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org> | |
3 | * (C) 2008 Patrick McHardy <kaber@trash.net> | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License version 2 as | |
7 | * published by the Free Software Foundation. | |
8 | */ | |
9 | ||
10 | #include <linux/types.h> | |
6185f870 PM |
11 | #include <linux/udp.h> |
12 | ||
13 | #include <linux/netfilter.h> | |
14 | #include <net/netfilter/nf_nat.h> | |
c7232c99 PM |
15 | #include <net/netfilter/nf_nat_l3proto.h> |
16 | #include <net/netfilter/nf_nat_l4proto.h> | |
6185f870 | 17 | |
c7232c99 | 18 | static u16 udplite_port_rover; |
6185f870 | 19 | |
f43dc98b | 20 | static void |
c7232c99 PM |
21 | udplite_unique_tuple(const struct nf_nat_l3proto *l3proto, |
22 | struct nf_conntrack_tuple *tuple, | |
23 | const struct nf_nat_range *range, | |
6185f870 PM |
24 | enum nf_nat_manip_type maniptype, |
25 | const struct nf_conn *ct) | |
26 | { | |
c7232c99 PM |
27 | nf_nat_l4proto_unique_tuple(l3proto, tuple, range, maniptype, ct, |
28 | &udplite_port_rover); | |
6185f870 PM |
29 | } |
30 | ||
f2ea825f | 31 | static bool |
6185f870 | 32 | udplite_manip_pkt(struct sk_buff *skb, |
c7232c99 PM |
33 | const struct nf_nat_l3proto *l3proto, |
34 | unsigned int iphdroff, unsigned int hdroff, | |
6185f870 PM |
35 | const struct nf_conntrack_tuple *tuple, |
36 | enum nf_nat_manip_type maniptype) | |
37 | { | |
6185f870 | 38 | struct udphdr *hdr; |
6185f870 PM |
39 | __be16 *portptr, newport; |
40 | ||
41 | if (!skb_make_writable(skb, hdroff + sizeof(*hdr))) | |
f2ea825f | 42 | return false; |
6185f870 | 43 | |
6185f870 PM |
44 | hdr = (struct udphdr *)(skb->data + hdroff); |
45 | ||
cbc9f2f4 | 46 | if (maniptype == NF_NAT_MANIP_SRC) { |
c7232c99 | 47 | /* Get rid of source port */ |
6185f870 PM |
48 | newport = tuple->src.u.udp.port; |
49 | portptr = &hdr->source; | |
50 | } else { | |
c7232c99 | 51 | /* Get rid of dst port */ |
6185f870 PM |
52 | newport = tuple->dst.u.udp.port; |
53 | portptr = &hdr->dest; | |
54 | } | |
55 | ||
c7232c99 | 56 | l3proto->csum_update(skb, iphdroff, &hdr->check, tuple, maniptype); |
4b048d6d | 57 | inet_proto_csum_replace2(&hdr->check, skb, *portptr, newport, false); |
6185f870 PM |
58 | if (!hdr->check) |
59 | hdr->check = CSUM_MANGLED_0; | |
60 | ||
61 | *portptr = newport; | |
f2ea825f | 62 | return true; |
6185f870 PM |
63 | } |
64 | ||
b8ad652f | 65 | const struct nf_nat_l4proto nf_nat_l4proto_udplite = { |
c7232c99 | 66 | .l4proto = IPPROTO_UDPLITE, |
6185f870 | 67 | .manip_pkt = udplite_manip_pkt, |
c7232c99 | 68 | .in_range = nf_nat_l4proto_in_range, |
6185f870 | 69 | .unique_tuple = udplite_unique_tuple, |
24de3d37 | 70 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
c7232c99 | 71 | .nlattr_to_range = nf_nat_l4proto_nlattr_to_range, |
6185f870 PM |
72 | #endif |
73 | }; |