net: add moduleparam.h for users of module_param/MODULE_PARM_DESC
[deliverable/linux.git] / net / ipv4 / netfilter / nf_nat_proto_udp.c
CommitLineData
5b1158e9
JK
1/* (C) 1999-2001 Paul `Rusty' Russell
2 * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
8
9#include <linux/types.h>
10#include <linux/init.h>
11#include <linux/ip.h>
12#include <linux/udp.h>
13
14#include <linux/netfilter.h>
15#include <net/netfilter/nf_nat.h>
16#include <net/netfilter/nf_nat_core.h>
17#include <net/netfilter/nf_nat_rule.h>
18#include <net/netfilter/nf_nat_protocol.h>
19
937e0dfd 20static u_int16_t udp_port_rover;
5b1158e9 21
f43dc98b 22static void
5b1158e9
JK
23udp_unique_tuple(struct nf_conntrack_tuple *tuple,
24 const struct nf_nat_range *range,
25 enum nf_nat_manip_type maniptype,
26 const struct nf_conn *ct)
27{
f43dc98b 28 nf_nat_proto_unique_tuple(tuple, range, maniptype, ct, &udp_port_rover);
5b1158e9
JK
29}
30
f2ea825f 31static bool
3db05fea 32udp_manip_pkt(struct sk_buff *skb,
5b1158e9
JK
33 unsigned int iphdroff,
34 const struct nf_conntrack_tuple *tuple,
35 enum nf_nat_manip_type maniptype)
36{
da3f13c9 37 const struct iphdr *iph = (struct iphdr *)(skb->data + iphdroff);
5b1158e9
JK
38 struct udphdr *hdr;
39 unsigned int hdroff = iphdroff + iph->ihl*4;
40 __be32 oldip, newip;
41 __be16 *portptr, newport;
42
3db05fea 43 if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
f2ea825f 44 return false;
5b1158e9 45
3db05fea
HX
46 iph = (struct iphdr *)(skb->data + iphdroff);
47 hdr = (struct udphdr *)(skb->data + hdroff);
5b1158e9
JK
48
49 if (maniptype == IP_NAT_MANIP_SRC) {
50 /* Get rid of src ip and src pt */
51 oldip = iph->saddr;
52 newip = tuple->src.u3.ip;
53 newport = tuple->src.u.udp.port;
54 portptr = &hdr->source;
55 } else {
56 /* Get rid of dst ip and dst pt */
57 oldip = iph->daddr;
58 newip = tuple->dst.u3.ip;
59 newport = tuple->dst.u.udp.port;
60 portptr = &hdr->dest;
61 }
3db05fea 62 if (hdr->check || skb->ip_summed == CHECKSUM_PARTIAL) {
be0ea7d5
PM
63 inet_proto_csum_replace4(&hdr->check, skb, oldip, newip, 1);
64 inet_proto_csum_replace2(&hdr->check, skb, *portptr, newport,
65 0);
5b1158e9
JK
66 if (!hdr->check)
67 hdr->check = CSUM_MANGLED_0;
68 }
69 *portptr = newport;
f2ea825f 70 return true;
5b1158e9
JK
71}
72
2b628a08 73const struct nf_nat_protocol nf_nat_protocol_udp = {
5b1158e9
JK
74 .protonum = IPPROTO_UDP,
75 .me = THIS_MODULE,
76 .manip_pkt = udp_manip_pkt,
937e0dfd 77 .in_range = nf_nat_proto_in_range,
5b1158e9 78 .unique_tuple = udp_unique_tuple,
e281db5c 79#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
535b57c7
PM
80 .range_to_nlattr = nf_nat_proto_range_to_nlattr,
81 .nlattr_to_range = nf_nat_proto_nlattr_to_range,
5b1158e9
JK
82#endif
83};
This page took 0.442801 seconds and 5 git commands to generate.