]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame_incremental - net/netfilter/nf_nat_proto_sctp.c
Merge tag 'char-misc-4.10-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/gregk...
[mirror_ubuntu-zesty-kernel.git] / net / netfilter / nf_nat_proto_sctp.c
... / ...
CommitLineData
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/sctp.h>
11#include <net/sctp/checksum.h>
12
13#include <net/netfilter/nf_nat_l4proto.h>
14
15static u_int16_t nf_sctp_port_rover;
16
17static void
18sctp_unique_tuple(const struct nf_nat_l3proto *l3proto,
19 struct nf_conntrack_tuple *tuple,
20 const struct nf_nat_range *range,
21 enum nf_nat_manip_type maniptype,
22 const struct nf_conn *ct)
23{
24 nf_nat_l4proto_unique_tuple(l3proto, tuple, range, maniptype, ct,
25 &nf_sctp_port_rover);
26}
27
28static bool
29sctp_manip_pkt(struct sk_buff *skb,
30 const struct nf_nat_l3proto *l3proto,
31 unsigned int iphdroff, unsigned int hdroff,
32 const struct nf_conntrack_tuple *tuple,
33 enum nf_nat_manip_type maniptype)
34{
35 sctp_sctphdr_t *hdr;
36
37 if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
38 return false;
39
40 hdr = (struct sctphdr *)(skb->data + hdroff);
41
42 if (maniptype == NF_NAT_MANIP_SRC) {
43 /* Get rid of src port */
44 hdr->source = tuple->src.u.sctp.port;
45 } else {
46 /* Get rid of dst port */
47 hdr->dest = tuple->dst.u.sctp.port;
48 }
49
50 if (skb->ip_summed != CHECKSUM_PARTIAL) {
51 hdr->checksum = sctp_compute_cksum(skb, hdroff);
52 skb->ip_summed = CHECKSUM_NONE;
53 }
54
55 return true;
56}
57
58const struct nf_nat_l4proto nf_nat_l4proto_sctp = {
59 .l4proto = IPPROTO_SCTP,
60 .manip_pkt = sctp_manip_pkt,
61 .in_range = nf_nat_l4proto_in_range,
62 .unique_tuple = sctp_unique_tuple,
63#if IS_ENABLED(CONFIG_NF_CT_NETLINK)
64 .nlattr_to_range = nf_nat_l4proto_nlattr_to_range,
65#endif
66};