1 /* (C) 1999-2001 Paul `Rusty' Russell
2 * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org>
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.
9 #include <linux/types.h>
10 #include <linux/export.h>
11 #include <linux/init.h>
12 #include <linux/udp.h>
14 #include <linux/netfilter.h>
15 #include <net/netfilter/nf_nat.h>
16 #include <net/netfilter/nf_nat_core.h>
17 #include <net/netfilter/nf_nat_l3proto.h>
18 #include <net/netfilter/nf_nat_l4proto.h>
21 udp_unique_tuple(const struct nf_nat_l3proto *l3proto,
22 struct nf_conntrack_tuple *tuple,
23 const struct nf_nat_range *range,
24 enum nf_nat_manip_type maniptype,
25 const struct nf_conn *ct)
27 nf_nat_l4proto_unique_tuple(l3proto, tuple, range, maniptype, ct);
31 udp_manip_pkt(struct sk_buff *skb,
32 const struct nf_nat_l3proto *l3proto,
33 unsigned int iphdroff, unsigned int hdroff,
34 const struct nf_conntrack_tuple *tuple,
35 enum nf_nat_manip_type maniptype)
38 __be16 *portptr, newport;
40 if (!skb_make_writable(skb, hdroff + sizeof(*hdr)))
42 hdr = (struct udphdr *)(skb->data + hdroff);
44 if (maniptype == NF_NAT_MANIP_SRC) {
45 /* Get rid of src port */
46 newport = tuple->src.u.udp.port;
47 portptr = &hdr->source;
49 /* Get rid of dst port */
50 newport = tuple->dst.u.udp.port;
53 if (hdr->check || skb->ip_summed == CHECKSUM_PARTIAL) {
54 l3proto->csum_update(skb, iphdroff, &hdr->check,
56 inet_proto_csum_replace2(&hdr->check, skb, *portptr, newport,
59 hdr->check = CSUM_MANGLED_0;
65 const struct nf_nat_l4proto nf_nat_l4proto_udp = {
66 .l4proto = IPPROTO_UDP,
67 .manip_pkt = udp_manip_pkt,
68 .in_range = nf_nat_l4proto_in_range,
69 .unique_tuple = udp_unique_tuple,
70 #if IS_ENABLED(CONFIG_NF_CT_NETLINK)
71 .nlattr_to_range = nf_nat_l4proto_nlattr_to_range,