GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / net / ipv4 / netfilter / nf_nat_proto_udplite.c
blob3cc8c8af39ef2fe82905fdad69b0b64af0f4e770
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>
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 */
10 #include <linux/types.h>
11 #include <linux/init.h>
12 #include <linux/ip.h>
13 #include <linux/udp.h>
15 #include <linux/netfilter.h>
16 #include <net/netfilter/nf_nat.h>
17 #include <net/netfilter/nf_nat_protocol.h>
19 static u_int16_t udplite_port_rover;
21 static void
22 udplite_unique_tuple(struct nf_conntrack_tuple *tuple,
23 const struct nf_nat_range *range,
24 enum nf_nat_manip_type maniptype,
25 const struct nf_conn *ct)
27 nf_nat_proto_unique_tuple(tuple, range, maniptype, ct,
28 &udplite_port_rover);
31 static bool
32 udplite_manip_pkt(struct sk_buff *skb,
33 unsigned int iphdroff,
34 const struct nf_conntrack_tuple *tuple,
35 enum nf_nat_manip_type maniptype)
37 const struct iphdr *iph = (struct iphdr *)(skb->data + iphdroff);
38 struct udphdr *hdr;
39 unsigned int hdroff = iphdroff + iph->ihl*4;
40 __be32 oldip, newip;
41 __be16 *portptr, newport;
43 if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
44 return false;
46 iph = (struct iphdr *)(skb->data + iphdroff);
47 hdr = (struct udphdr *)(skb->data + hdroff);
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;
63 inet_proto_csum_replace4(&hdr->check, skb, oldip, newip, 1);
64 inet_proto_csum_replace2(&hdr->check, skb, *portptr, newport, 0);
65 if (!hdr->check)
66 hdr->check = CSUM_MANGLED_0;
68 *portptr = newport;
69 return true;
72 static const struct nf_nat_protocol nf_nat_protocol_udplite = {
73 .protonum = IPPROTO_UDPLITE,
74 .me = THIS_MODULE,
75 .manip_pkt = udplite_manip_pkt,
76 .in_range = nf_nat_proto_in_range,
77 .unique_tuple = udplite_unique_tuple,
78 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
79 .range_to_nlattr = nf_nat_proto_range_to_nlattr,
80 .nlattr_to_range = nf_nat_proto_nlattr_to_range,
81 #endif
84 static int __init nf_nat_proto_udplite_init(void)
86 return nf_nat_protocol_register(&nf_nat_protocol_udplite);
89 static void __exit nf_nat_proto_udplite_fini(void)
91 nf_nat_protocol_unregister(&nf_nat_protocol_udplite);
94 module_init(nf_nat_proto_udplite_init);
95 module_exit(nf_nat_proto_udplite_fini);
97 MODULE_LICENSE("GPL");
98 MODULE_DESCRIPTION("UDP-Lite NAT protocol helper");
99 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");