]>
Commit | Line | Data |
---|---|---|
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> | |
9d908a69 PM |
10 | #include <linux/sctp.h> |
11 | #include <net/sctp/checksum.h> | |
12 | ||
c7232c99 | 13 | #include <net/netfilter/nf_nat_l4proto.h> |
9d908a69 PM |
14 | |
15 | static u_int16_t nf_sctp_port_rover; | |
16 | ||
f43dc98b | 17 | static void |
c7232c99 PM |
18 | sctp_unique_tuple(const struct nf_nat_l3proto *l3proto, |
19 | struct nf_conntrack_tuple *tuple, | |
20 | const struct nf_nat_range *range, | |
9d908a69 PM |
21 | enum nf_nat_manip_type maniptype, |
22 | const struct nf_conn *ct) | |
23 | { | |
c7232c99 PM |
24 | nf_nat_l4proto_unique_tuple(l3proto, tuple, range, maniptype, ct, |
25 | &nf_sctp_port_rover); | |
9d908a69 PM |
26 | } |
27 | ||
f2ea825f | 28 | static bool |
9d908a69 | 29 | sctp_manip_pkt(struct sk_buff *skb, |
c7232c99 PM |
30 | const struct nf_nat_l3proto *l3proto, |
31 | unsigned int iphdroff, unsigned int hdroff, | |
9d908a69 PM |
32 | const struct nf_conntrack_tuple *tuple, |
33 | enum nf_nat_manip_type maniptype) | |
34 | { | |
ae146d9b | 35 | struct sctphdr *hdr; |
8e05ba7f | 36 | int hdrsize = 8; |
9d908a69 | 37 | |
8e05ba7f YX |
38 | /* This could be an inner header returned in imcp packet; in such |
39 | * cases we cannot update the checksum field since it is outside | |
40 | * of the 8 bytes of transport layer headers we are guaranteed. | |
41 | */ | |
42 | if (skb->len >= hdroff + sizeof(*hdr)) | |
43 | hdrsize = sizeof(*hdr); | |
44 | ||
45 | if (!skb_make_writable(skb, hdroff + hdrsize)) | |
f2ea825f | 46 | return false; |
9d908a69 | 47 | |
9d908a69 PM |
48 | hdr = (struct sctphdr *)(skb->data + hdroff); |
49 | ||
cbc9f2f4 | 50 | if (maniptype == NF_NAT_MANIP_SRC) { |
c7232c99 | 51 | /* Get rid of src port */ |
9d908a69 PM |
52 | hdr->source = tuple->src.u.sctp.port; |
53 | } else { | |
c7232c99 | 54 | /* Get rid of dst port */ |
9d908a69 PM |
55 | hdr->dest = tuple->dst.u.sctp.port; |
56 | } | |
57 | ||
8e05ba7f YX |
58 | if (hdrsize < sizeof(*hdr)) |
59 | return true; | |
60 | ||
3189a290 DC |
61 | if (skb->ip_summed != CHECKSUM_PARTIAL) { |
62 | hdr->checksum = sctp_compute_cksum(skb, hdroff); | |
63 | skb->ip_summed = CHECKSUM_NONE; | |
64 | } | |
9d908a69 | 65 | |
f2ea825f | 66 | return true; |
9d908a69 PM |
67 | } |
68 | ||
7a2dd28c | 69 | const struct nf_nat_l4proto nf_nat_l4proto_sctp = { |
c7232c99 | 70 | .l4proto = IPPROTO_SCTP, |
9d908a69 | 71 | .manip_pkt = sctp_manip_pkt, |
c7232c99 | 72 | .in_range = nf_nat_l4proto_in_range, |
9d908a69 | 73 | .unique_tuple = sctp_unique_tuple, |
24de3d37 | 74 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
c7232c99 | 75 | .nlattr_to_range = nf_nat_l4proto_nlattr_to_range, |
9d908a69 PM |
76 | #endif |
77 | }; |