Blame view
net/netfilter/nf_nat_proto_dccp.c
2.15 KB
4910a0879
|
1 2 3 |
/* * DCCP NAT protocol helper * |
c7232c997
|
4 |
* Copyright (c) 2005, 2006, 2008 Patrick McHardy <kaber@trash.net> |
4910a0879
|
5 6 7 8 9 10 11 12 |
* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * */ #include <linux/kernel.h> |
4910a0879
|
13 |
#include <linux/skbuff.h> |
4910a0879
|
14 15 16 17 |
#include <linux/dccp.h> #include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_nat.h> |
c7232c997
|
18 19 |
#include <net/netfilter/nf_nat_l3proto.h> #include <net/netfilter/nf_nat_l4proto.h> |
4910a0879
|
20 21 |
static u_int16_t dccp_port_rover; |
f43dc98b3
|
22 |
static void |
c7232c997
|
23 24 |
dccp_unique_tuple(const struct nf_nat_l3proto *l3proto, struct nf_conntrack_tuple *tuple, |
2eb0f624b
|
25 |
const struct nf_nat_range2 *range, |
4910a0879
|
26 27 28 |
enum nf_nat_manip_type maniptype, const struct nf_conn *ct) { |
c7232c997
|
29 30 |
nf_nat_l4proto_unique_tuple(l3proto, tuple, range, maniptype, ct, &dccp_port_rover); |
4910a0879
|
31 |
} |
f2ea825f4
|
32 |
static bool |
4910a0879
|
33 |
dccp_manip_pkt(struct sk_buff *skb, |
c7232c997
|
34 35 |
const struct nf_nat_l3proto *l3proto, unsigned int iphdroff, unsigned int hdroff, |
4910a0879
|
36 37 38 |
const struct nf_conntrack_tuple *tuple, enum nf_nat_manip_type maniptype) { |
4910a0879
|
39 |
struct dccp_hdr *hdr; |
4910a0879
|
40 41 42 43 44 45 46 |
__be16 *portptr, oldport, newport; int hdrsize = 8; /* DCCP connection tracking guarantees this much */ if (skb->len >= hdroff + sizeof(struct dccp_hdr)) hdrsize = sizeof(struct dccp_hdr); if (!skb_make_writable(skb, hdroff + hdrsize)) |
f2ea825f4
|
47 |
return false; |
4910a0879
|
48 |
|
4910a0879
|
49 |
hdr = (struct dccp_hdr *)(skb->data + hdroff); |
cbc9f2f4f
|
50 |
if (maniptype == NF_NAT_MANIP_SRC) { |
4910a0879
|
51 52 53 |
newport = tuple->src.u.dccp.port; portptr = &hdr->dccph_sport; } else { |
4910a0879
|
54 55 56 57 58 59 60 61 |
newport = tuple->dst.u.dccp.port; portptr = &hdr->dccph_dport; } oldport = *portptr; *portptr = newport; if (hdrsize < sizeof(*hdr)) |
f2ea825f4
|
62 |
return true; |
4910a0879
|
63 |
|
c7232c997
|
64 65 |
l3proto->csum_update(skb, iphdroff, &hdr->dccph_checksum, tuple, maniptype); |
4910a0879
|
66 |
inet_proto_csum_replace2(&hdr->dccph_checksum, skb, oldport, newport, |
4b048d6d9
|
67 |
false); |
f2ea825f4
|
68 |
return true; |
4910a0879
|
69 |
} |
0c4e966ea
|
70 |
const struct nf_nat_l4proto nf_nat_l4proto_dccp = { |
c7232c997
|
71 |
.l4proto = IPPROTO_DCCP, |
4910a0879
|
72 |
.manip_pkt = dccp_manip_pkt, |
c7232c997
|
73 |
.in_range = nf_nat_l4proto_in_range, |
4910a0879
|
74 |
.unique_tuple = dccp_unique_tuple, |
24de3d377
|
75 |
#if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
c7232c997
|
76 |
.nlattr_to_range = nf_nat_l4proto_nlattr_to_range, |
4910a0879
|
77 78 |
#endif }; |