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>
23 static u_int16_t dccp_port_rover
;
26 dccp_unique_tuple(const struct nf_nat_l3proto
*l3proto
,
27 struct nf_conntrack_tuple
*tuple
,
28 const struct nf_nat_range
*range
,
29 enum nf_nat_manip_type maniptype
,
30 const struct nf_conn
*ct
)
32 nf_nat_l4proto_unique_tuple(l3proto
, tuple
, range
, maniptype
, ct
,
37 dccp_manip_pkt(struct sk_buff
*skb
,
38 const struct nf_nat_l3proto
*l3proto
,
39 unsigned int iphdroff
, unsigned int hdroff
,
40 const struct nf_conntrack_tuple
*tuple
,
41 enum nf_nat_manip_type maniptype
)
44 __be16
*portptr
, oldport
, newport
;
45 int hdrsize
= 8; /* DCCP connection tracking guarantees this much */
47 if (skb
->len
>= hdroff
+ sizeof(struct dccp_hdr
))
48 hdrsize
= sizeof(struct dccp_hdr
);
50 if (!skb_make_writable(skb
, hdroff
+ hdrsize
))
53 hdr
= (struct dccp_hdr
*)(skb
->data
+ hdroff
);
55 if (maniptype
== NF_NAT_MANIP_SRC
) {
56 newport
= tuple
->src
.u
.dccp
.port
;
57 portptr
= &hdr
->dccph_sport
;
59 newport
= tuple
->dst
.u
.dccp
.port
;
60 portptr
= &hdr
->dccph_dport
;
66 if (hdrsize
< sizeof(*hdr
))
69 l3proto
->csum_update(skb
, iphdroff
, &hdr
->dccph_checksum
,
71 inet_proto_csum_replace2(&hdr
->dccph_checksum
, skb
, oldport
, newport
,
76 static const struct nf_nat_l4proto nf_nat_l4proto_dccp
= {
77 .l4proto
= IPPROTO_DCCP
,
78 .manip_pkt
= dccp_manip_pkt
,
79 .in_range
= nf_nat_l4proto_in_range
,
80 .unique_tuple
= dccp_unique_tuple
,
81 #if defined(CONFIG_NF_CT_NETLINK) || defined(CONFIG_NF_CT_NETLINK_MODULE)
82 .nlattr_to_range
= nf_nat_l4proto_nlattr_to_range
,
86 static int __init
nf_nat_proto_dccp_init(void)
90 err
= nf_nat_l4proto_register(NFPROTO_IPV4
, &nf_nat_l4proto_dccp
);
93 err
= nf_nat_l4proto_register(NFPROTO_IPV6
, &nf_nat_l4proto_dccp
);
99 nf_nat_l4proto_unregister(NFPROTO_IPV4
, &nf_nat_l4proto_dccp
);
104 static void __exit
nf_nat_proto_dccp_fini(void)
106 nf_nat_l4proto_unregister(NFPROTO_IPV6
, &nf_nat_l4proto_dccp
);
107 nf_nat_l4proto_unregister(NFPROTO_IPV4
, &nf_nat_l4proto_dccp
);
111 module_init(nf_nat_proto_dccp_init
);
112 module_exit(nf_nat_proto_dccp_fini
);
114 MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
115 MODULE_DESCRIPTION("DCCP NAT protocol helper");
116 MODULE_LICENSE("GPL");