xen-blkfront: don't add indirect pages to list when !feature_persistent
[linux-2.6-block.git] / net / 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>
9d908a69 11#include <linux/sctp.h>
3a9a231d 12#include <linux/module.h>
9d908a69
PM
13#include <net/sctp/checksum.h>
14
c7232c99 15#include <net/netfilter/nf_nat_l4proto.h>
9d908a69
PM
16
17static u_int16_t nf_sctp_port_rover;
18
f43dc98b 19static void
c7232c99
PM
20sctp_unique_tuple(const struct nf_nat_l3proto *l3proto,
21 struct nf_conntrack_tuple *tuple,
22 const struct nf_nat_range *range,
9d908a69
PM
23 enum nf_nat_manip_type maniptype,
24 const struct nf_conn *ct)
25{
c7232c99
PM
26 nf_nat_l4proto_unique_tuple(l3proto, tuple, range, maniptype, ct,
27 &nf_sctp_port_rover);
9d908a69
PM
28}
29
f2ea825f 30static bool
9d908a69 31sctp_manip_pkt(struct sk_buff *skb,
c7232c99
PM
32 const struct nf_nat_l3proto *l3proto,
33 unsigned int iphdroff, unsigned int hdroff,
9d908a69
PM
34 const struct nf_conntrack_tuple *tuple,
35 enum nf_nat_manip_type maniptype)
36{
9d908a69 37 sctp_sctphdr_t *hdr;
9d908a69
PM
38
39 if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
f2ea825f 40 return false;
9d908a69 41
9d908a69
PM
42 hdr = (struct sctphdr *)(skb->data + hdroff);
43
cbc9f2f4 44 if (maniptype == NF_NAT_MANIP_SRC) {
c7232c99 45 /* Get rid of src port */
9d908a69
PM
46 hdr->source = tuple->src.u.sctp.port;
47 } else {
c7232c99 48 /* Get rid of dst port */
9d908a69
PM
49 hdr->dest = tuple->dst.u.sctp.port;
50 }
51
024ec3de 52 hdr->checksum = sctp_compute_cksum(skb, hdroff);
9d908a69 53
f2ea825f 54 return true;
9d908a69
PM
55}
56
c7232c99
PM
57static const struct nf_nat_l4proto nf_nat_l4proto_sctp = {
58 .l4proto = IPPROTO_SCTP,
9d908a69 59 .manip_pkt = sctp_manip_pkt,
c7232c99 60 .in_range = nf_nat_l4proto_in_range,
9d908a69 61 .unique_tuple = sctp_unique_tuple,
24de3d37 62#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
c7232c99 63 .nlattr_to_range = nf_nat_l4proto_nlattr_to_range,
9d908a69
PM
64#endif
65};
66
67static int __init nf_nat_proto_sctp_init(void)
68{
c7232c99
PM
69 int err;
70
71 err = nf_nat_l4proto_register(NFPROTO_IPV4, &nf_nat_l4proto_sctp);
72 if (err < 0)
73 goto err1;
74 err = nf_nat_l4proto_register(NFPROTO_IPV6, &nf_nat_l4proto_sctp);
75 if (err < 0)
76 goto err2;
77 return 0;
78
79err2:
80 nf_nat_l4proto_unregister(NFPROTO_IPV4, &nf_nat_l4proto_sctp);
81err1:
82 return err;
9d908a69
PM
83}
84
85static void __exit nf_nat_proto_sctp_exit(void)
86{
c7232c99
PM
87 nf_nat_l4proto_unregister(NFPROTO_IPV6, &nf_nat_l4proto_sctp);
88 nf_nat_l4proto_unregister(NFPROTO_IPV4, &nf_nat_l4proto_sctp);
9d908a69
PM
89}
90
91module_init(nf_nat_proto_sctp_init);
92module_exit(nf_nat_proto_sctp_exit);
93
94MODULE_LICENSE("GPL");
95MODULE_DESCRIPTION("SCTP NAT protocol helper");
96MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");