11 #include <linux/types.h>
12 #include <linux/module.h>
15 #include <linux/icmp.h>
16 #include <linux/netfilter.h>
17 #include <linux/netfilter_ipv4.h>
32 static void nf_nat_ipv4_decode_session(
struct sk_buff *
skb,
35 unsigned long statusbit,
41 if (ct->
status & statusbit) {
48 fl4->fl4_dport = t->
dst.u.all;
53 if (ct->
status & statusbit) {
60 fl4->fl4_sport = t->
src.u.all;
78 static bool nf_nat_ipv4_manip_pkt(
struct sk_buff *skb,
79 unsigned int iphdroff,
90 iph = (
void *)skb->
data + iphdroff;
91 hdroff = iphdroff + iph->ihl * 4;
93 if (!l4proto->
manip_pkt(skb, &nf_nat_l3proto_ipv4, iphdroff, hdroff,
96 iph = (
void *)skb->
data + iphdroff;
108 static void nf_nat_ipv4_csum_update(
struct sk_buff *skb,
118 newip = t->
src.u3.ip;
121 newip = t->
dst.u3.ip;
126 static void nf_nat_ipv4_csum_recalc(
struct sk_buff *skb,
130 const struct iphdr *iph = ip_hdr(skb);
131 struct rtable *rt = skb_rtable(skb);
138 skb_network_offset(skb) +
153 inet_proto_csum_replace2(check, skb,
157 static int nf_nat_ipv4_nlattr_to_range(
struct nlattr *
tb[],
161 range->
min_addr.
ip = nla_get_be32(tb[CTA_NAT_V4_MINIP]);
166 range->
max_addr.
ip = nla_get_be32(tb[CTA_NAT_V4_MAXIP]);
175 .in_range = nf_nat_ipv4_in_range,
176 .secure_port = nf_nat_ipv4_secure_port,
177 .manip_pkt = nf_nat_ipv4_manip_pkt,
178 .csum_update = nf_nat_ipv4_csum_update,
179 .csum_recalc = nf_nat_ipv4_csum_recalc,
180 .nlattr_to_range = nf_nat_ipv4_nlattr_to_range,
182 .decode_session = nf_nat_ipv4_decode_session,
197 unsigned int hdrlen = ip_hdrlen(skb);
200 unsigned long statusbit;
226 if (!(ct->
status & statusbit))
230 if (!nf_nat_ipv4_manip_pkt(skb, hdrlen +
sizeof(
inside->icmp),
231 l4proto, &ct->
tuplehash[!dir].tuple, !manip))
237 inside->icmp.checksum = 0;
240 skb->
len - hdrlen, 0));
246 if (!nf_nat_ipv4_manip_pkt(skb, 0, l4proto, &target, manip))
253 static int __init nf_nat_l3proto_ipv4_init(
void)
271 static void __exit nf_nat_l3proto_ipv4_exit(
void)