net: Fix files explicitly needing to include module.h
[deliverable/linux.git] / net / ipv4 / netfilter / nf_nat_proto_sctp.c
CommitLineData
9d908a69
PM
1/*
2 * Copyright (c) 2008 Patrick McHardy <kaber@trash.net>
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/sctp.h>
3a9a231d 13#include <linux/module.h>
9d908a69
PM
14#include <net/sctp/checksum.h>
15
16#include <net/netfilter/nf_nat_protocol.h>
17
18static u_int16_t nf_sctp_port_rover;
19
f43dc98b 20static void
9d908a69
PM
21sctp_unique_tuple(struct nf_conntrack_tuple *tuple,
22 const struct nf_nat_range *range,
23 enum nf_nat_manip_type maniptype,
24 const struct nf_conn *ct)
25{
f43dc98b
CG
26 nf_nat_proto_unique_tuple(tuple, range, maniptype, ct,
27 &nf_sctp_port_rover);
9d908a69
PM
28}
29
f2ea825f 30static bool
9d908a69
PM
31sctp_manip_pkt(struct sk_buff *skb,
32 unsigned int iphdroff,
33 const struct nf_conntrack_tuple *tuple,
34 enum nf_nat_manip_type maniptype)
35{
36 const struct iphdr *iph = (struct iphdr *)(skb->data + iphdroff);
343a9972 37 struct sk_buff *frag;
9d908a69
PM
38 sctp_sctphdr_t *hdr;
39 unsigned int hdroff = iphdroff + iph->ihl*4;
40 __be32 oldip, newip;
336d3262 41 __be32 crc32;
9d908a69
PM
42
43 if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
f2ea825f 44 return false;
9d908a69
PM
45
46 iph = (struct iphdr *)(skb->data + iphdroff);
47 hdr = (struct sctphdr *)(skb->data + hdroff);
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 hdr->source = tuple->src.u.sctp.port;
54 } else {
55 /* Get rid of dst ip and dst pt */
56 oldip = iph->daddr;
57 newip = tuple->dst.u3.ip;
58 hdr->dest = tuple->dst.u.sctp.port;
59 }
60
61 crc32 = sctp_start_cksum((u8 *)hdr, skb_headlen(skb) - hdroff);
0808dc80 62 skb_walk_frags(skb, frag)
343a9972 63 crc32 = sctp_update_cksum((u8 *)frag->data, skb_headlen(frag),
9d908a69
PM
64 crc32);
65 crc32 = sctp_end_cksum(crc32);
336d3262 66 hdr->checksum = crc32;
9d908a69 67
f2ea825f 68 return true;
9d908a69
PM
69}
70
71static const struct nf_nat_protocol nf_nat_protocol_sctp = {
72 .protonum = IPPROTO_SCTP,
73 .me = THIS_MODULE,
74 .manip_pkt = sctp_manip_pkt,
75 .in_range = nf_nat_proto_in_range,
76 .unique_tuple = sctp_unique_tuple,
77#if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
78 .range_to_nlattr = nf_nat_proto_range_to_nlattr,
79 .nlattr_to_range = nf_nat_proto_nlattr_to_range,
80#endif
81};
82
83static int __init nf_nat_proto_sctp_init(void)
84{
85 return nf_nat_protocol_register(&nf_nat_protocol_sctp);
86}
87
88static void __exit nf_nat_proto_sctp_exit(void)
89{
90 nf_nat_protocol_unregister(&nf_nat_protocol_sctp);
91}
92
93module_init(nf_nat_proto_sctp_init);
94module_exit(nf_nat_proto_sctp_exit);
95
96MODULE_LICENSE("GPL");
97MODULE_DESCRIPTION("SCTP NAT protocol helper");
98MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
This page took 0.300834 seconds and 5 git commands to generate.