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/module.h>
14 #include <linux/init.h>
15 #include <linux/skbuff.h>
16 #include <linux/dccp.h>
18 #include <net/netfilter/nf_conntrack.h>
19 #include <net/netfilter/nf_nat.h>
20 #include <net/netfilter/nf_nat_l3proto.h>
21 #include <net/netfilter/nf_nat_l4proto.h>
24 dccp_unique_tuple(const struct nf_nat_l3proto *l3proto,
25 struct nf_conntrack_tuple *tuple,
26 const struct nf_nat_range *range,
27 enum nf_nat_manip_type maniptype,
28 const struct nf_conn *ct)
30 nf_nat_l4proto_unique_tuple(l3proto, tuple, range, maniptype, ct);
34 dccp_manip_pkt(struct sk_buff *skb,
35 const struct nf_nat_l3proto *l3proto,
36 unsigned int iphdroff, unsigned int hdroff,
37 const struct nf_conntrack_tuple *tuple,
38 enum nf_nat_manip_type maniptype)
41 __be16 *portptr, oldport, newport;
42 int hdrsize = 8; /* DCCP connection tracking guarantees this much */
44 if (skb->len >= hdroff + sizeof(struct dccp_hdr))
45 hdrsize = sizeof(struct dccp_hdr);
47 if (!skb_make_writable(skb, hdroff + hdrsize))
50 hdr = (struct dccp_hdr *)(skb->data + hdroff);
52 if (maniptype == NF_NAT_MANIP_SRC) {
53 newport = tuple->src.u.dccp.port;
54 portptr = &hdr->dccph_sport;
56 newport = tuple->dst.u.dccp.port;
57 portptr = &hdr->dccph_dport;
63 if (hdrsize < sizeof(*hdr))
66 l3proto->csum_update(skb, iphdroff, &hdr->dccph_checksum,
68 inet_proto_csum_replace2(&hdr->dccph_checksum, skb, oldport, newport,
73 static const struct nf_nat_l4proto nf_nat_l4proto_dccp = {
74 .l4proto = IPPROTO_DCCP,
75 .manip_pkt = dccp_manip_pkt,
76 .in_range = nf_nat_l4proto_in_range,
77 .unique_tuple = dccp_unique_tuple,
78 #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
79 .nlattr_to_range = nf_nat_l4proto_nlattr_to_range,
83 static int __init nf_nat_proto_dccp_init(void)
87 err = nf_nat_l4proto_register(NFPROTO_IPV4, &nf_nat_l4proto_dccp);
90 err = nf_nat_l4proto_register(NFPROTO_IPV6, &nf_nat_l4proto_dccp);
96 nf_nat_l4proto_unregister(NFPROTO_IPV4, &nf_nat_l4proto_dccp);
101 static void __exit nf_nat_proto_dccp_fini(void)
103 nf_nat_l4proto_unregister(NFPROTO_IPV6, &nf_nat_l4proto_dccp);
104 nf_nat_l4proto_unregister(NFPROTO_IPV4, &nf_nat_l4proto_dccp);
108 module_init(nf_nat_proto_dccp_init);
109 module_exit(nf_nat_proto_dccp_fini);
111 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
112 MODULE_DESCRIPTION("DCCP NAT protocol helper");
113 MODULE_LICENSE("GPL");