2 * DCCP NAT protocol helper
4 * Copyright (c) 2005, 2006, 2008 Patrick McHardy <kaber@trash.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/skbuff.h>
14 #include <linux/dccp.h>
16 #include <net/netfilter/nf_conntrack.h>
17 #include <net/netfilter/nf_nat.h>
18 #include <net/netfilter/nf_nat_l3proto.h>
19 #include <net/netfilter/nf_nat_l4proto.h>
22 dccp_unique_tuple(const struct nf_nat_l3proto *l3proto,
23 struct nf_conntrack_tuple *tuple,
24 const struct nf_nat_range2 *range,
25 enum nf_nat_manip_type maniptype,
26 const struct nf_conn *ct)
28 nf_nat_l4proto_unique_tuple(l3proto, tuple, range, maniptype, ct);
32 dccp_manip_pkt(struct sk_buff *skb,
33 const struct nf_nat_l3proto *l3proto,
34 unsigned int iphdroff, unsigned int hdroff,
35 const struct nf_conntrack_tuple *tuple,
36 enum nf_nat_manip_type maniptype)
39 __be16 *portptr, oldport, newport;
40 int hdrsize = 8; /* DCCP connection tracking guarantees this much */
42 if (skb->len >= hdroff + sizeof(struct dccp_hdr))
43 hdrsize = sizeof(struct dccp_hdr);
45 if (!skb_make_writable(skb, hdroff + hdrsize))
48 hdr = (struct dccp_hdr *)(skb->data + hdroff);
50 if (maniptype == NF_NAT_MANIP_SRC) {
51 newport = tuple->src.u.dccp.port;
52 portptr = &hdr->dccph_sport;
54 newport = tuple->dst.u.dccp.port;
55 portptr = &hdr->dccph_dport;
61 if (hdrsize < sizeof(*hdr))
64 l3proto->csum_update(skb, iphdroff, &hdr->dccph_checksum,
66 inet_proto_csum_replace2(&hdr->dccph_checksum, skb, oldport, newport,
71 const struct nf_nat_l4proto nf_nat_l4proto_dccp = {
72 .l4proto = IPPROTO_DCCP,
73 .manip_pkt = dccp_manip_pkt,
74 .in_range = nf_nat_l4proto_in_range,
75 .unique_tuple = dccp_unique_tuple,
76 #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
77 .nlattr_to_range = nf_nat_l4proto_nlattr_to_range,