]>
Commit | Line | Data |
---|---|---|
c7232c99 PM |
1 | /* |
2 | * (C) 1999-2001 Paul `Rusty' Russell | |
5b1158e9 | 3 | * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org> |
c7232c99 | 4 | * (C) 2011 Patrick McHardy <kaber@trash.net> |
5b1158e9 JK |
5 | * |
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. | |
9 | */ | |
10 | ||
11 | #include <linux/module.h> | |
12 | #include <linux/types.h> | |
13 | #include <linux/timer.h> | |
14 | #include <linux/skbuff.h> | |
5a0e3ad6 | 15 | #include <linux/gfp.h> |
c7232c99 | 16 | #include <net/xfrm.h> |
5b1158e9 | 17 | #include <linux/jhash.h> |
c7232c99 | 18 | #include <linux/rtnetlink.h> |
5b1158e9 | 19 | |
5b1158e9 JK |
20 | #include <net/netfilter/nf_conntrack.h> |
21 | #include <net/netfilter/nf_conntrack_core.h> | |
22 | #include <net/netfilter/nf_nat.h> | |
c7232c99 PM |
23 | #include <net/netfilter/nf_nat_l3proto.h> |
24 | #include <net/netfilter/nf_nat_l4proto.h> | |
5b1158e9 JK |
25 | #include <net/netfilter/nf_nat_core.h> |
26 | #include <net/netfilter/nf_nat_helper.h> | |
27 | #include <net/netfilter/nf_conntrack_helper.h> | |
41d73ec0 | 28 | #include <net/netfilter/nf_conntrack_seqadj.h> |
5b1158e9 | 29 | #include <net/netfilter/nf_conntrack_l3proto.h> |
5d0aa2cc | 30 | #include <net/netfilter/nf_conntrack_zones.h> |
c7232c99 | 31 | #include <linux/netfilter/nf_nat.h> |
5b1158e9 | 32 | |
c7232c99 PM |
33 | static DEFINE_MUTEX(nf_nat_proto_mutex); |
34 | static const struct nf_nat_l3proto __rcu *nf_nat_l3protos[NFPROTO_NUMPROTO] | |
35 | __read_mostly; | |
36 | static const struct nf_nat_l4proto __rcu **nf_nat_l4protos[NFPROTO_NUMPROTO] | |
ce4b1ceb | 37 | __read_mostly; |
a76ae1c8 | 38 | |
870190a9 FW |
39 | struct nf_nat_conn_key { |
40 | const struct net *net; | |
41 | const struct nf_conntrack_tuple *tuple; | |
42 | const struct nf_conntrack_zone *zone; | |
43 | }; | |
44 | ||
7223ecd4 | 45 | static struct rhltable nf_nat_bysource_table; |
c7232c99 PM |
46 | |
47 | inline const struct nf_nat_l3proto * | |
48 | __nf_nat_l3proto_find(u8 family) | |
5b1158e9 | 49 | { |
c7232c99 | 50 | return rcu_dereference(nf_nat_l3protos[family]); |
5b1158e9 JK |
51 | } |
52 | ||
c7232c99 PM |
53 | inline const struct nf_nat_l4proto * |
54 | __nf_nat_l4proto_find(u8 family, u8 protonum) | |
55 | { | |
56 | return rcu_dereference(nf_nat_l4protos[family][protonum]); | |
57 | } | |
58 | EXPORT_SYMBOL_GPL(__nf_nat_l4proto_find); | |
59 | ||
60 | #ifdef CONFIG_XFRM | |
61 | static void __nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl) | |
62 | { | |
63 | const struct nf_nat_l3proto *l3proto; | |
64 | const struct nf_conn *ct; | |
65 | enum ip_conntrack_info ctinfo; | |
66 | enum ip_conntrack_dir dir; | |
67 | unsigned long statusbit; | |
68 | u8 family; | |
69 | ||
70 | ct = nf_ct_get(skb, &ctinfo); | |
71 | if (ct == NULL) | |
72 | return; | |
73 | ||
53890234 | 74 | family = nf_ct_l3num(ct); |
c7232c99 PM |
75 | l3proto = __nf_nat_l3proto_find(family); |
76 | if (l3proto == NULL) | |
53890234 | 77 | return; |
c7232c99 PM |
78 | |
79 | dir = CTINFO2DIR(ctinfo); | |
80 | if (dir == IP_CT_DIR_ORIGINAL) | |
81 | statusbit = IPS_DST_NAT; | |
82 | else | |
83 | statusbit = IPS_SRC_NAT; | |
84 | ||
85 | l3proto->decode_session(skb, ct, dir, statusbit, fl); | |
c7232c99 PM |
86 | } |
87 | ||
c7af6483 | 88 | int nf_xfrm_me_harder(struct net *net, struct sk_buff *skb, unsigned int family) |
c7232c99 PM |
89 | { |
90 | struct flowi fl; | |
91 | unsigned int hh_len; | |
92 | struct dst_entry *dst; | |
aaa795ad | 93 | int err; |
c7232c99 | 94 | |
aaa795ad | 95 | err = xfrm_decode_session(skb, &fl, family); |
e7e6f630 | 96 | if (err < 0) |
aaa795ad | 97 | return err; |
c7232c99 PM |
98 | |
99 | dst = skb_dst(skb); | |
100 | if (dst->xfrm) | |
101 | dst = ((struct xfrm_dst *)dst)->route; | |
102 | dst_hold(dst); | |
103 | ||
c7af6483 | 104 | dst = xfrm_lookup(net, dst, &fl, skb->sk, 0); |
c7232c99 | 105 | if (IS_ERR(dst)) |
aaa795ad | 106 | return PTR_ERR(dst); |
c7232c99 PM |
107 | |
108 | skb_dst_drop(skb); | |
109 | skb_dst_set(skb, dst); | |
110 | ||
111 | /* Change in oif may mean change in hh_len. */ | |
112 | hh_len = skb_dst(skb)->dev->hard_header_len; | |
113 | if (skb_headroom(skb) < hh_len && | |
114 | pskb_expand_head(skb, hh_len - skb_headroom(skb), 0, GFP_ATOMIC)) | |
aaa795ad | 115 | return -ENOMEM; |
c7232c99 PM |
116 | return 0; |
117 | } | |
118 | EXPORT_SYMBOL(nf_xfrm_me_harder); | |
119 | #endif /* CONFIG_XFRM */ | |
120 | ||
870190a9 | 121 | static u32 nf_nat_bysource_hash(const void *data, u32 len, u32 seed) |
5b1158e9 | 122 | { |
870190a9 FW |
123 | const struct nf_conntrack_tuple *t; |
124 | const struct nf_conn *ct = data; | |
7001c6d1 | 125 | |
870190a9 | 126 | t = &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple; |
5b1158e9 | 127 | /* Original src, to ensure we map it consistently if poss. */ |
8fc54f68 | 128 | |
870190a9 FW |
129 | seed ^= net_hash_mix(nf_ct_net(ct)); |
130 | return jhash2((const u32 *)&t->src, sizeof(t->src) / sizeof(u32), | |
131 | t->dst.protonum ^ seed); | |
5b1158e9 JK |
132 | } |
133 | ||
5b1158e9 JK |
134 | /* Is this tuple already taken? (not by us) */ |
135 | int | |
136 | nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple, | |
137 | const struct nf_conn *ignored_conntrack) | |
138 | { | |
139 | /* Conntrack tracking doesn't keep track of outgoing tuples; only | |
c7232c99 PM |
140 | * incoming ones. NAT means they don't have a fixed mapping, |
141 | * so we invert the tuple and look for the incoming reply. | |
142 | * | |
143 | * We could keep a separate hash if this proves too slow. | |
144 | */ | |
5b1158e9 JK |
145 | struct nf_conntrack_tuple reply; |
146 | ||
147 | nf_ct_invert_tuplepr(&reply, tuple); | |
148 | return nf_conntrack_tuple_taken(&reply, ignored_conntrack); | |
149 | } | |
150 | EXPORT_SYMBOL(nf_nat_used_tuple); | |
151 | ||
152 | /* If we source map this tuple so reply looks like reply_tuple, will | |
c7232c99 PM |
153 | * that meet the constraints of range. |
154 | */ | |
155 | static int in_range(const struct nf_nat_l3proto *l3proto, | |
156 | const struct nf_nat_l4proto *l4proto, | |
157 | const struct nf_conntrack_tuple *tuple, | |
158 | const struct nf_nat_range *range) | |
5b1158e9 | 159 | { |
5b1158e9 | 160 | /* If we are supposed to map IPs, then we must be in the |
c7232c99 PM |
161 | * range specified, otherwise let this drag us onto a new src IP. |
162 | */ | |
163 | if (range->flags & NF_NAT_RANGE_MAP_IPS && | |
164 | !l3proto->in_range(tuple, range)) | |
165 | return 0; | |
5b1158e9 | 166 | |
cbc9f2f4 | 167 | if (!(range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) || |
c7232c99 PM |
168 | l4proto->in_range(tuple, NF_NAT_MANIP_SRC, |
169 | &range->min_proto, &range->max_proto)) | |
170 | return 1; | |
5b1158e9 | 171 | |
c7232c99 | 172 | return 0; |
5b1158e9 JK |
173 | } |
174 | ||
175 | static inline int | |
176 | same_src(const struct nf_conn *ct, | |
177 | const struct nf_conntrack_tuple *tuple) | |
178 | { | |
179 | const struct nf_conntrack_tuple *t; | |
180 | ||
181 | t = &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple; | |
182 | return (t->dst.protonum == tuple->dst.protonum && | |
c7232c99 | 183 | nf_inet_addr_cmp(&t->src.u3, &tuple->src.u3) && |
5b1158e9 JK |
184 | t->src.u.all == tuple->src.u.all); |
185 | } | |
186 | ||
870190a9 FW |
187 | static int nf_nat_bysource_cmp(struct rhashtable_compare_arg *arg, |
188 | const void *obj) | |
189 | { | |
190 | const struct nf_nat_conn_key *key = arg->key; | |
191 | const struct nf_conn *ct = obj; | |
192 | ||
728e87b4 FW |
193 | if (!same_src(ct, key->tuple) || |
194 | !net_eq(nf_ct_net(ct), key->net) || | |
195 | !nf_ct_zone_equal(ct, key->zone, IP_CT_DIR_ORIGINAL)) | |
196 | return 1; | |
197 | ||
198 | return 0; | |
870190a9 FW |
199 | } |
200 | ||
201 | static struct rhashtable_params nf_nat_bysource_params = { | |
202 | .head_offset = offsetof(struct nf_conn, nat_bysource), | |
203 | .obj_hashfn = nf_nat_bysource_hash, | |
204 | .obj_cmpfn = nf_nat_bysource_cmp, | |
205 | .nelem_hint = 256, | |
206 | .min_size = 1024, | |
870190a9 FW |
207 | }; |
208 | ||
5b1158e9 JK |
209 | /* Only called for SRC manip */ |
210 | static int | |
308ac914 DB |
211 | find_appropriate_src(struct net *net, |
212 | const struct nf_conntrack_zone *zone, | |
c7232c99 PM |
213 | const struct nf_nat_l3proto *l3proto, |
214 | const struct nf_nat_l4proto *l4proto, | |
0c4c9288 | 215 | const struct nf_conntrack_tuple *tuple, |
5b1158e9 | 216 | struct nf_conntrack_tuple *result, |
c7232c99 | 217 | const struct nf_nat_range *range) |
5b1158e9 | 218 | { |
72b72949 | 219 | const struct nf_conn *ct; |
870190a9 FW |
220 | struct nf_nat_conn_key key = { |
221 | .net = net, | |
222 | .tuple = tuple, | |
223 | .zone = zone | |
224 | }; | |
7223ecd4 | 225 | struct rhlist_head *hl; |
5b1158e9 | 226 | |
7223ecd4 FW |
227 | hl = rhltable_lookup(&nf_nat_bysource_table, &key, |
228 | nf_nat_bysource_params); | |
229 | if (!hl) | |
870190a9 FW |
230 | return 0; |
231 | ||
7223ecd4 FW |
232 | ct = container_of(hl, typeof(*ct), nat_bysource); |
233 | ||
870190a9 FW |
234 | nf_ct_invert_tuplepr(result, |
235 | &ct->tuplehash[IP_CT_DIR_REPLY].tuple); | |
236 | result->dst = tuple->dst; | |
237 | ||
238 | return in_range(l3proto, l4proto, result, range); | |
5b1158e9 JK |
239 | } |
240 | ||
241 | /* For [FUTURE] fragmentation handling, we want the least-used | |
c7232c99 PM |
242 | * src-ip/dst-ip/proto triple. Fairness doesn't come into it. Thus |
243 | * if the range specifies 1.2.3.4 ports 10000-10005 and 1.2.3.5 ports | |
244 | * 1-65535, we don't do pro-rata allocation based on ports; we choose | |
245 | * the ip with the lowest src-ip/dst-ip/proto usage. | |
246 | */ | |
5b1158e9 | 247 | static void |
308ac914 DB |
248 | find_best_ips_proto(const struct nf_conntrack_zone *zone, |
249 | struct nf_conntrack_tuple *tuple, | |
c7232c99 | 250 | const struct nf_nat_range *range, |
5b1158e9 JK |
251 | const struct nf_conn *ct, |
252 | enum nf_nat_manip_type maniptype) | |
253 | { | |
c7232c99 PM |
254 | union nf_inet_addr *var_ipp; |
255 | unsigned int i, max; | |
5b1158e9 | 256 | /* Host order */ |
c7232c99 PM |
257 | u32 minip, maxip, j, dist; |
258 | bool full_range; | |
5b1158e9 JK |
259 | |
260 | /* No IP mapping? Do nothing. */ | |
cbc9f2f4 | 261 | if (!(range->flags & NF_NAT_RANGE_MAP_IPS)) |
5b1158e9 JK |
262 | return; |
263 | ||
cbc9f2f4 | 264 | if (maniptype == NF_NAT_MANIP_SRC) |
c7232c99 | 265 | var_ipp = &tuple->src.u3; |
5b1158e9 | 266 | else |
c7232c99 | 267 | var_ipp = &tuple->dst.u3; |
5b1158e9 JK |
268 | |
269 | /* Fast path: only one choice. */ | |
c7232c99 PM |
270 | if (nf_inet_addr_cmp(&range->min_addr, &range->max_addr)) { |
271 | *var_ipp = range->min_addr; | |
5b1158e9 JK |
272 | return; |
273 | } | |
274 | ||
c7232c99 PM |
275 | if (nf_ct_l3num(ct) == NFPROTO_IPV4) |
276 | max = sizeof(var_ipp->ip) / sizeof(u32) - 1; | |
277 | else | |
278 | max = sizeof(var_ipp->ip6) / sizeof(u32) - 1; | |
279 | ||
5b1158e9 JK |
280 | /* Hashing source and destination IPs gives a fairly even |
281 | * spread in practice (if there are a small number of IPs | |
282 | * involved, there usually aren't that many connections | |
283 | * anyway). The consistency means that servers see the same | |
284 | * client coming from the same IP (some Internet Banking sites | |
c7232c99 PM |
285 | * like this), even across reboots. |
286 | */ | |
5693d68d | 287 | j = jhash2((u32 *)&tuple->src.u3, sizeof(tuple->src.u3) / sizeof(u32), |
c7232c99 | 288 | range->flags & NF_NAT_RANGE_PERSISTENT ? |
308ac914 | 289 | 0 : (__force u32)tuple->dst.u3.all[max] ^ zone->id); |
c7232c99 PM |
290 | |
291 | full_range = false; | |
292 | for (i = 0; i <= max; i++) { | |
293 | /* If first bytes of the address are at the maximum, use the | |
294 | * distance. Otherwise use the full range. | |
295 | */ | |
296 | if (!full_range) { | |
297 | minip = ntohl((__force __be32)range->min_addr.all[i]); | |
298 | maxip = ntohl((__force __be32)range->max_addr.all[i]); | |
299 | dist = maxip - minip + 1; | |
300 | } else { | |
301 | minip = 0; | |
302 | dist = ~0; | |
303 | } | |
304 | ||
305 | var_ipp->all[i] = (__force __u32) | |
8fc54f68 | 306 | htonl(minip + reciprocal_scale(j, dist)); |
c7232c99 PM |
307 | if (var_ipp->all[i] != range->max_addr.all[i]) |
308 | full_range = true; | |
309 | ||
310 | if (!(range->flags & NF_NAT_RANGE_PERSISTENT)) | |
311 | j ^= (__force u32)tuple->dst.u3.all[i]; | |
312 | } | |
5b1158e9 JK |
313 | } |
314 | ||
c7232c99 PM |
315 | /* Manipulate the tuple into the range given. For NF_INET_POST_ROUTING, |
316 | * we change the source to map into the range. For NF_INET_PRE_ROUTING | |
6e23ae2a | 317 | * and NF_INET_LOCAL_OUT, we change the destination to map into the |
c7232c99 | 318 | * range. It might not be possible to get a unique tuple, but we try. |
5b1158e9 JK |
319 | * At worst (or if we race), we will end up with a final duplicate in |
320 | * __ip_conntrack_confirm and drop the packet. */ | |
321 | static void | |
322 | get_unique_tuple(struct nf_conntrack_tuple *tuple, | |
323 | const struct nf_conntrack_tuple *orig_tuple, | |
c7232c99 | 324 | const struct nf_nat_range *range, |
5b1158e9 JK |
325 | struct nf_conn *ct, |
326 | enum nf_nat_manip_type maniptype) | |
327 | { | |
308ac914 | 328 | const struct nf_conntrack_zone *zone; |
c7232c99 PM |
329 | const struct nf_nat_l3proto *l3proto; |
330 | const struct nf_nat_l4proto *l4proto; | |
0c4c9288 | 331 | struct net *net = nf_ct_net(ct); |
308ac914 DB |
332 | |
333 | zone = nf_ct_zone(ct); | |
5b1158e9 | 334 | |
c7232c99 PM |
335 | rcu_read_lock(); |
336 | l3proto = __nf_nat_l3proto_find(orig_tuple->src.l3num); | |
337 | l4proto = __nf_nat_l4proto_find(orig_tuple->src.l3num, | |
338 | orig_tuple->dst.protonum); | |
5b1158e9 | 339 | |
c7232c99 PM |
340 | /* 1) If this srcip/proto/src-proto-part is currently mapped, |
341 | * and that same mapping gives a unique tuple within the given | |
342 | * range, use that. | |
343 | * | |
344 | * This is only required for source (ie. NAT/masq) mappings. | |
345 | * So far, we don't do local source mappings, so multiple | |
346 | * manips not an issue. | |
347 | */ | |
cbc9f2f4 | 348 | if (maniptype == NF_NAT_MANIP_SRC && |
34ce3240 | 349 | !(range->flags & NF_NAT_RANGE_PROTO_RANDOM_ALL)) { |
41a7cab6 | 350 | /* try the original tuple first */ |
c7232c99 | 351 | if (in_range(l3proto, l4proto, orig_tuple, range)) { |
41a7cab6 CG |
352 | if (!nf_nat_used_tuple(orig_tuple, ct)) { |
353 | *tuple = *orig_tuple; | |
c7232c99 | 354 | goto out; |
41a7cab6 | 355 | } |
c7232c99 PM |
356 | } else if (find_appropriate_src(net, zone, l3proto, l4proto, |
357 | orig_tuple, tuple, range)) { | |
0d53778e | 358 | pr_debug("get_unique_tuple: Found current src map\n"); |
0dbff689 | 359 | if (!nf_nat_used_tuple(tuple, ct)) |
c7232c99 | 360 | goto out; |
5b1158e9 JK |
361 | } |
362 | } | |
363 | ||
c7232c99 | 364 | /* 2) Select the least-used IP/proto combination in the given range */ |
5b1158e9 | 365 | *tuple = *orig_tuple; |
5d0aa2cc | 366 | find_best_ips_proto(zone, tuple, range, ct, maniptype); |
5b1158e9 JK |
367 | |
368 | /* 3) The per-protocol part of the manip is made to map into | |
c7232c99 PM |
369 | * the range to make a unique tuple. |
370 | */ | |
5b1158e9 JK |
371 | |
372 | /* Only bother mapping if it's not already in range and unique */ | |
34ce3240 | 373 | if (!(range->flags & NF_NAT_RANGE_PROTO_RANDOM_ALL)) { |
cbc9f2f4 | 374 | if (range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) { |
c7232c99 PM |
375 | if (l4proto->in_range(tuple, maniptype, |
376 | &range->min_proto, | |
377 | &range->max_proto) && | |
378 | (range->min_proto.all == range->max_proto.all || | |
99ad3c53 CG |
379 | !nf_nat_used_tuple(tuple, ct))) |
380 | goto out; | |
381 | } else if (!nf_nat_used_tuple(tuple, ct)) { | |
382 | goto out; | |
383 | } | |
384 | } | |
5b1158e9 JK |
385 | |
386 | /* Last change: get protocol to try to obtain unique tuple. */ | |
c7232c99 | 387 | l4proto->unique_tuple(l3proto, tuple, range, maniptype, ct); |
e22a0548 PM |
388 | out: |
389 | rcu_read_unlock(); | |
5b1158e9 JK |
390 | } |
391 | ||
f768e5bd FW |
392 | struct nf_conn_nat *nf_ct_nat_ext_add(struct nf_conn *ct) |
393 | { | |
394 | struct nf_conn_nat *nat = nfct_nat(ct); | |
395 | if (nat) | |
396 | return nat; | |
397 | ||
398 | if (!nf_ct_is_confirmed(ct)) | |
399 | nat = nf_ct_ext_add(ct, NF_CT_EXT_NAT, GFP_ATOMIC); | |
400 | ||
401 | return nat; | |
402 | } | |
403 | EXPORT_SYMBOL_GPL(nf_ct_nat_ext_add); | |
404 | ||
5b1158e9 JK |
405 | unsigned int |
406 | nf_nat_setup_info(struct nf_conn *ct, | |
c7232c99 | 407 | const struct nf_nat_range *range, |
cc01dcbd | 408 | enum nf_nat_manip_type maniptype) |
5b1158e9 JK |
409 | { |
410 | struct nf_conntrack_tuple curr_tuple, new_tuple; | |
2d59e5ca | 411 | struct nf_conn_nat *nat; |
5b1158e9 | 412 | |
2d59e5ca | 413 | /* nat helper or nfctnetlink also setup binding */ |
f768e5bd FW |
414 | nat = nf_ct_nat_ext_add(ct); |
415 | if (nat == NULL) | |
416 | return NF_ACCEPT; | |
2d59e5ca | 417 | |
cbc9f2f4 PM |
418 | NF_CT_ASSERT(maniptype == NF_NAT_MANIP_SRC || |
419 | maniptype == NF_NAT_MANIP_DST); | |
5b1158e9 JK |
420 | BUG_ON(nf_nat_initialized(ct, maniptype)); |
421 | ||
422 | /* What we've got will look like inverse of reply. Normally | |
c7232c99 PM |
423 | * this is what is in the conntrack, except for prior |
424 | * manipulations (future optimization: if num_manips == 0, | |
425 | * orig_tp = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple) | |
426 | */ | |
5b1158e9 JK |
427 | nf_ct_invert_tuplepr(&curr_tuple, |
428 | &ct->tuplehash[IP_CT_DIR_REPLY].tuple); | |
429 | ||
430 | get_unique_tuple(&new_tuple, &curr_tuple, range, ct, maniptype); | |
431 | ||
432 | if (!nf_ct_tuple_equal(&new_tuple, &curr_tuple)) { | |
433 | struct nf_conntrack_tuple reply; | |
434 | ||
435 | /* Alter conntrack table so will recognize replies. */ | |
436 | nf_ct_invert_tuplepr(&reply, &new_tuple); | |
437 | nf_conntrack_alter_reply(ct, &reply); | |
438 | ||
439 | /* Non-atomic: we own this at the moment. */ | |
cbc9f2f4 | 440 | if (maniptype == NF_NAT_MANIP_SRC) |
5b1158e9 JK |
441 | ct->status |= IPS_SRC_NAT; |
442 | else | |
443 | ct->status |= IPS_DST_NAT; | |
41d73ec0 PM |
444 | |
445 | if (nfct_help(ct)) | |
4440a2ab GF |
446 | if (!nfct_seqadj_ext_add(ct)) |
447 | return NF_DROP; | |
5b1158e9 JK |
448 | } |
449 | ||
cbc9f2f4 | 450 | if (maniptype == NF_NAT_MANIP_SRC) { |
7223ecd4 FW |
451 | struct nf_nat_conn_key key = { |
452 | .net = nf_ct_net(ct), | |
453 | .tuple = &ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple, | |
454 | .zone = nf_ct_zone(ct), | |
455 | }; | |
870190a9 FW |
456 | int err; |
457 | ||
7223ecd4 FW |
458 | err = rhltable_insert_key(&nf_nat_bysource_table, |
459 | &key, | |
460 | &ct->nat_bysource, | |
461 | nf_nat_bysource_params); | |
870190a9 FW |
462 | if (err) |
463 | return NF_DROP; | |
5b1158e9 JK |
464 | } |
465 | ||
466 | /* It's done. */ | |
cbc9f2f4 | 467 | if (maniptype == NF_NAT_MANIP_DST) |
a7c2f4d7 | 468 | ct->status |= IPS_DST_NAT_DONE; |
5b1158e9 | 469 | else |
a7c2f4d7 | 470 | ct->status |= IPS_SRC_NAT_DONE; |
5b1158e9 JK |
471 | |
472 | return NF_ACCEPT; | |
473 | } | |
474 | EXPORT_SYMBOL(nf_nat_setup_info); | |
475 | ||
0eba801b PNA |
476 | static unsigned int |
477 | __nf_nat_alloc_null_binding(struct nf_conn *ct, enum nf_nat_manip_type manip) | |
f59cb045 PNA |
478 | { |
479 | /* Force range to this IP; let proto decide mapping for | |
480 | * per-proto parts (hence not IP_NAT_RANGE_PROTO_SPECIFIED). | |
481 | * Use reply in case it's already been mangled (eg local packet). | |
482 | */ | |
483 | union nf_inet_addr ip = | |
0eba801b | 484 | (manip == NF_NAT_MANIP_SRC ? |
f59cb045 PNA |
485 | ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3 : |
486 | ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.u3); | |
487 | struct nf_nat_range range = { | |
488 | .flags = NF_NAT_RANGE_MAP_IPS, | |
489 | .min_addr = ip, | |
490 | .max_addr = ip, | |
491 | }; | |
0eba801b PNA |
492 | return nf_nat_setup_info(ct, &range, manip); |
493 | } | |
494 | ||
495 | unsigned int | |
496 | nf_nat_alloc_null_binding(struct nf_conn *ct, unsigned int hooknum) | |
497 | { | |
498 | return __nf_nat_alloc_null_binding(ct, HOOK2MANIP(hooknum)); | |
f59cb045 PNA |
499 | } |
500 | EXPORT_SYMBOL_GPL(nf_nat_alloc_null_binding); | |
501 | ||
5b1158e9 JK |
502 | /* Do packet manipulations according to nf_nat_setup_info. */ |
503 | unsigned int nf_nat_packet(struct nf_conn *ct, | |
504 | enum ip_conntrack_info ctinfo, | |
505 | unsigned int hooknum, | |
3db05fea | 506 | struct sk_buff *skb) |
5b1158e9 | 507 | { |
c7232c99 PM |
508 | const struct nf_nat_l3proto *l3proto; |
509 | const struct nf_nat_l4proto *l4proto; | |
5b1158e9 JK |
510 | enum ip_conntrack_dir dir = CTINFO2DIR(ctinfo); |
511 | unsigned long statusbit; | |
512 | enum nf_nat_manip_type mtype = HOOK2MANIP(hooknum); | |
513 | ||
cbc9f2f4 | 514 | if (mtype == NF_NAT_MANIP_SRC) |
5b1158e9 JK |
515 | statusbit = IPS_SRC_NAT; |
516 | else | |
517 | statusbit = IPS_DST_NAT; | |
518 | ||
519 | /* Invert if this is reply dir. */ | |
520 | if (dir == IP_CT_DIR_REPLY) | |
521 | statusbit ^= IPS_NAT_MASK; | |
522 | ||
523 | /* Non-atomic: these bits don't change. */ | |
524 | if (ct->status & statusbit) { | |
525 | struct nf_conntrack_tuple target; | |
526 | ||
527 | /* We are aiming to look like inverse of other direction. */ | |
528 | nf_ct_invert_tuplepr(&target, &ct->tuplehash[!dir].tuple); | |
529 | ||
c7232c99 PM |
530 | l3proto = __nf_nat_l3proto_find(target.src.l3num); |
531 | l4proto = __nf_nat_l4proto_find(target.src.l3num, | |
532 | target.dst.protonum); | |
533 | if (!l3proto->manip_pkt(skb, 0, l4proto, &target, mtype)) | |
5b1158e9 JK |
534 | return NF_DROP; |
535 | } | |
536 | return NF_ACCEPT; | |
537 | } | |
538 | EXPORT_SYMBOL_GPL(nf_nat_packet); | |
539 | ||
c7232c99 PM |
540 | struct nf_nat_proto_clean { |
541 | u8 l3proto; | |
542 | u8 l4proto; | |
c7232c99 PM |
543 | }; |
544 | ||
c2d421e1 FW |
545 | /* kill conntracks with affected NAT section */ |
546 | static int nf_nat_proto_remove(struct nf_conn *i, void *data) | |
5b1158e9 | 547 | { |
c7232c99 | 548 | const struct nf_nat_proto_clean *clean = data; |
c2d421e1 | 549 | |
c7232c99 PM |
550 | if ((clean->l3proto && nf_ct_l3num(i) != clean->l3proto) || |
551 | (clean->l4proto && nf_ct_protonum(i) != clean->l4proto)) | |
5b1158e9 JK |
552 | return 0; |
553 | ||
c2d421e1 | 554 | return i->status & IPS_NAT_MASK ? 1 : 0; |
c7232c99 | 555 | } |
5b1158e9 | 556 | |
945b2b2d FW |
557 | static int nf_nat_proto_clean(struct nf_conn *ct, void *data) |
558 | { | |
945b2b2d FW |
559 | if (nf_nat_proto_remove(ct, data)) |
560 | return 1; | |
561 | ||
6e699867 | 562 | if ((ct->status & IPS_SRC_NAT_DONE) == 0) |
945b2b2d FW |
563 | return 0; |
564 | ||
565 | /* This netns is being destroyed, and conntrack has nat null binding. | |
566 | * Remove it from bysource hash, as the table will be freed soon. | |
567 | * | |
568 | * Else, when the conntrack is destoyed, nf_nat_cleanup_conntrack() | |
569 | * will delete entry from already-freed table. | |
570 | */ | |
945b2b2d | 571 | ct->status &= ~IPS_NAT_DONE_MASK; |
7223ecd4 FW |
572 | rhltable_remove(&nf_nat_bysource_table, &ct->nat_bysource, |
573 | nf_nat_bysource_params); | |
945b2b2d | 574 | |
945b2b2d FW |
575 | /* don't delete conntrack. Although that would make things a lot |
576 | * simpler, we'd end up flushing all conntracks on nat rmmod. | |
577 | */ | |
578 | return 0; | |
579 | } | |
580 | ||
c7232c99 PM |
581 | static void nf_nat_l4proto_clean(u8 l3proto, u8 l4proto) |
582 | { | |
583 | struct nf_nat_proto_clean clean = { | |
584 | .l3proto = l3proto, | |
585 | .l4proto = l4proto, | |
586 | }; | |
587 | struct net *net; | |
588 | ||
589 | rtnl_lock(); | |
c7232c99 | 590 | for_each_net(net) |
c655bc68 | 591 | nf_ct_iterate_cleanup(net, nf_nat_proto_remove, &clean, 0, 0); |
c7232c99 PM |
592 | rtnl_unlock(); |
593 | } | |
5b1158e9 | 594 | |
c7232c99 PM |
595 | static void nf_nat_l3proto_clean(u8 l3proto) |
596 | { | |
597 | struct nf_nat_proto_clean clean = { | |
598 | .l3proto = l3proto, | |
599 | }; | |
600 | struct net *net; | |
601 | ||
602 | rtnl_lock(); | |
5b1158e9 | 603 | |
c7232c99 | 604 | for_each_net(net) |
c655bc68 | 605 | nf_ct_iterate_cleanup(net, nf_nat_proto_remove, &clean, 0, 0); |
c7232c99 | 606 | rtnl_unlock(); |
5b1158e9 | 607 | } |
5b1158e9 JK |
608 | |
609 | /* Protocol registration. */ | |
c7232c99 | 610 | int nf_nat_l4proto_register(u8 l3proto, const struct nf_nat_l4proto *l4proto) |
5b1158e9 | 611 | { |
c7232c99 PM |
612 | const struct nf_nat_l4proto **l4protos; |
613 | unsigned int i; | |
5b1158e9 JK |
614 | int ret = 0; |
615 | ||
c7232c99 PM |
616 | mutex_lock(&nf_nat_proto_mutex); |
617 | if (nf_nat_l4protos[l3proto] == NULL) { | |
618 | l4protos = kmalloc(IPPROTO_MAX * sizeof(struct nf_nat_l4proto *), | |
619 | GFP_KERNEL); | |
620 | if (l4protos == NULL) { | |
621 | ret = -ENOMEM; | |
622 | goto out; | |
623 | } | |
624 | ||
625 | for (i = 0; i < IPPROTO_MAX; i++) | |
626 | RCU_INIT_POINTER(l4protos[i], &nf_nat_l4proto_unknown); | |
627 | ||
628 | /* Before making proto_array visible to lockless readers, | |
629 | * we must make sure its content is committed to memory. | |
630 | */ | |
631 | smp_wmb(); | |
632 | ||
633 | nf_nat_l4protos[l3proto] = l4protos; | |
634 | } | |
635 | ||
eb733162 | 636 | if (rcu_dereference_protected( |
c7232c99 PM |
637 | nf_nat_l4protos[l3proto][l4proto->l4proto], |
638 | lockdep_is_held(&nf_nat_proto_mutex) | |
639 | ) != &nf_nat_l4proto_unknown) { | |
5b1158e9 JK |
640 | ret = -EBUSY; |
641 | goto out; | |
642 | } | |
c7232c99 | 643 | RCU_INIT_POINTER(nf_nat_l4protos[l3proto][l4proto->l4proto], l4proto); |
5b1158e9 | 644 | out: |
c7232c99 | 645 | mutex_unlock(&nf_nat_proto_mutex); |
5b1158e9 JK |
646 | return ret; |
647 | } | |
c7232c99 | 648 | EXPORT_SYMBOL_GPL(nf_nat_l4proto_register); |
5b1158e9 | 649 | |
25985edc | 650 | /* No one stores the protocol anywhere; simply delete it. */ |
c7232c99 | 651 | void nf_nat_l4proto_unregister(u8 l3proto, const struct nf_nat_l4proto *l4proto) |
5b1158e9 | 652 | { |
c7232c99 PM |
653 | mutex_lock(&nf_nat_proto_mutex); |
654 | RCU_INIT_POINTER(nf_nat_l4protos[l3proto][l4proto->l4proto], | |
655 | &nf_nat_l4proto_unknown); | |
656 | mutex_unlock(&nf_nat_proto_mutex); | |
e22a0548 | 657 | synchronize_rcu(); |
c7232c99 PM |
658 | |
659 | nf_nat_l4proto_clean(l3proto, l4proto->l4proto); | |
5b1158e9 | 660 | } |
c7232c99 PM |
661 | EXPORT_SYMBOL_GPL(nf_nat_l4proto_unregister); |
662 | ||
663 | int nf_nat_l3proto_register(const struct nf_nat_l3proto *l3proto) | |
664 | { | |
665 | int err; | |
666 | ||
667 | err = nf_ct_l3proto_try_module_get(l3proto->l3proto); | |
668 | if (err < 0) | |
669 | return err; | |
670 | ||
671 | mutex_lock(&nf_nat_proto_mutex); | |
672 | RCU_INIT_POINTER(nf_nat_l4protos[l3proto->l3proto][IPPROTO_TCP], | |
673 | &nf_nat_l4proto_tcp); | |
674 | RCU_INIT_POINTER(nf_nat_l4protos[l3proto->l3proto][IPPROTO_UDP], | |
675 | &nf_nat_l4proto_udp); | |
0c4e966e DC |
676 | #ifdef CONFIG_NF_NAT_PROTO_DCCP |
677 | RCU_INIT_POINTER(nf_nat_l4protos[l3proto->l3proto][IPPROTO_DCCP], | |
678 | &nf_nat_l4proto_dccp); | |
7a2dd28c DC |
679 | #endif |
680 | #ifdef CONFIG_NF_NAT_PROTO_SCTP | |
681 | RCU_INIT_POINTER(nf_nat_l4protos[l3proto->l3proto][IPPROTO_SCTP], | |
682 | &nf_nat_l4proto_sctp); | |
b8ad652f DC |
683 | #endif |
684 | #ifdef CONFIG_NF_NAT_PROTO_UDPLITE | |
685 | RCU_INIT_POINTER(nf_nat_l4protos[l3proto->l3proto][IPPROTO_UDPLITE], | |
686 | &nf_nat_l4proto_udplite); | |
0c4e966e | 687 | #endif |
c7232c99 PM |
688 | mutex_unlock(&nf_nat_proto_mutex); |
689 | ||
690 | RCU_INIT_POINTER(nf_nat_l3protos[l3proto->l3proto], l3proto); | |
691 | return 0; | |
692 | } | |
693 | EXPORT_SYMBOL_GPL(nf_nat_l3proto_register); | |
694 | ||
695 | void nf_nat_l3proto_unregister(const struct nf_nat_l3proto *l3proto) | |
696 | { | |
697 | mutex_lock(&nf_nat_proto_mutex); | |
698 | RCU_INIT_POINTER(nf_nat_l3protos[l3proto->l3proto], NULL); | |
699 | mutex_unlock(&nf_nat_proto_mutex); | |
700 | synchronize_rcu(); | |
701 | ||
702 | nf_nat_l3proto_clean(l3proto->l3proto); | |
703 | nf_ct_l3proto_module_put(l3proto->l3proto); | |
704 | } | |
705 | EXPORT_SYMBOL_GPL(nf_nat_l3proto_unregister); | |
5b1158e9 | 706 | |
25985edc | 707 | /* No one using conntrack by the time this called. */ |
d8a0509a YK |
708 | static void nf_nat_cleanup_conntrack(struct nf_conn *ct) |
709 | { | |
6e699867 FW |
710 | if (ct->status & IPS_SRC_NAT_DONE) |
711 | rhltable_remove(&nf_nat_bysource_table, &ct->nat_bysource, | |
712 | nf_nat_bysource_params); | |
2d59e5ca YK |
713 | } |
714 | ||
61eb3107 | 715 | static struct nf_ct_ext_type nat_extend __read_mostly = { |
d8a0509a YK |
716 | .len = sizeof(struct nf_conn_nat), |
717 | .align = __alignof__(struct nf_conn_nat), | |
718 | .destroy = nf_nat_cleanup_conntrack, | |
d8a0509a | 719 | .id = NF_CT_EXT_NAT, |
2d59e5ca YK |
720 | }; |
721 | ||
24de3d37 | 722 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK) |
e6a7d3c0 PNA |
723 | |
724 | #include <linux/netfilter/nfnetlink.h> | |
725 | #include <linux/netfilter/nfnetlink_conntrack.h> | |
726 | ||
727 | static const struct nla_policy protonat_nla_policy[CTA_PROTONAT_MAX+1] = { | |
728 | [CTA_PROTONAT_PORT_MIN] = { .type = NLA_U16 }, | |
729 | [CTA_PROTONAT_PORT_MAX] = { .type = NLA_U16 }, | |
730 | }; | |
731 | ||
732 | static int nfnetlink_parse_nat_proto(struct nlattr *attr, | |
733 | const struct nf_conn *ct, | |
c7232c99 | 734 | struct nf_nat_range *range) |
e6a7d3c0 PNA |
735 | { |
736 | struct nlattr *tb[CTA_PROTONAT_MAX+1]; | |
c7232c99 | 737 | const struct nf_nat_l4proto *l4proto; |
e6a7d3c0 PNA |
738 | int err; |
739 | ||
740 | err = nla_parse_nested(tb, CTA_PROTONAT_MAX, attr, protonat_nla_policy); | |
741 | if (err < 0) | |
742 | return err; | |
743 | ||
c7232c99 PM |
744 | l4proto = __nf_nat_l4proto_find(nf_ct_l3num(ct), nf_ct_protonum(ct)); |
745 | if (l4proto->nlattr_to_range) | |
746 | err = l4proto->nlattr_to_range(tb, range); | |
747 | ||
e6a7d3c0 PNA |
748 | return err; |
749 | } | |
750 | ||
751 | static const struct nla_policy nat_nla_policy[CTA_NAT_MAX+1] = { | |
c7232c99 PM |
752 | [CTA_NAT_V4_MINIP] = { .type = NLA_U32 }, |
753 | [CTA_NAT_V4_MAXIP] = { .type = NLA_U32 }, | |
58a317f1 PM |
754 | [CTA_NAT_V6_MINIP] = { .len = sizeof(struct in6_addr) }, |
755 | [CTA_NAT_V6_MAXIP] = { .len = sizeof(struct in6_addr) }, | |
329fb58a | 756 | [CTA_NAT_PROTO] = { .type = NLA_NESTED }, |
e6a7d3c0 PNA |
757 | }; |
758 | ||
759 | static int | |
39938324 | 760 | nfnetlink_parse_nat(const struct nlattr *nat, |
0eba801b PNA |
761 | const struct nf_conn *ct, struct nf_nat_range *range, |
762 | const struct nf_nat_l3proto *l3proto) | |
e6a7d3c0 PNA |
763 | { |
764 | struct nlattr *tb[CTA_NAT_MAX+1]; | |
765 | int err; | |
766 | ||
767 | memset(range, 0, sizeof(*range)); | |
768 | ||
769 | err = nla_parse_nested(tb, CTA_NAT_MAX, nat, nat_nla_policy); | |
770 | if (err < 0) | |
771 | return err; | |
772 | ||
c7232c99 PM |
773 | err = l3proto->nlattr_to_range(tb, range); |
774 | if (err < 0) | |
0eba801b | 775 | return err; |
e6a7d3c0 PNA |
776 | |
777 | if (!tb[CTA_NAT_PROTO]) | |
0eba801b | 778 | return 0; |
e6a7d3c0 | 779 | |
0eba801b | 780 | return nfnetlink_parse_nat_proto(tb[CTA_NAT_PROTO], ct, range); |
e6a7d3c0 PNA |
781 | } |
782 | ||
0eba801b | 783 | /* This function is called under rcu_read_lock() */ |
e6a7d3c0 PNA |
784 | static int |
785 | nfnetlink_parse_nat_setup(struct nf_conn *ct, | |
786 | enum nf_nat_manip_type manip, | |
39938324 | 787 | const struct nlattr *attr) |
e6a7d3c0 | 788 | { |
c7232c99 | 789 | struct nf_nat_range range; |
0eba801b | 790 | const struct nf_nat_l3proto *l3proto; |
c7232c99 | 791 | int err; |
e6a7d3c0 | 792 | |
0eba801b PNA |
793 | /* Should not happen, restricted to creating new conntracks |
794 | * via ctnetlink. | |
795 | */ | |
796 | if (WARN_ON_ONCE(nf_nat_initialized(ct, manip))) | |
797 | return -EEXIST; | |
798 | ||
799 | /* Make sure that L3 NAT is there by when we call nf_nat_setup_info to | |
800 | * attach the null binding, otherwise this may oops. | |
801 | */ | |
802 | l3proto = __nf_nat_l3proto_find(nf_ct_l3num(ct)); | |
803 | if (l3proto == NULL) | |
804 | return -EAGAIN; | |
805 | ||
806 | /* No NAT information has been passed, allocate the null-binding */ | |
807 | if (attr == NULL) | |
7025bac4 | 808 | return __nf_nat_alloc_null_binding(ct, manip) == NF_DROP ? -ENOMEM : 0; |
0eba801b PNA |
809 | |
810 | err = nfnetlink_parse_nat(attr, ct, &range, l3proto); | |
c7232c99 PM |
811 | if (err < 0) |
812 | return err; | |
e6a7d3c0 | 813 | |
ecfcdfec | 814 | return nf_nat_setup_info(ct, &range, manip) == NF_DROP ? -ENOMEM : 0; |
e6a7d3c0 PNA |
815 | } |
816 | #else | |
817 | static int | |
818 | nfnetlink_parse_nat_setup(struct nf_conn *ct, | |
819 | enum nf_nat_manip_type manip, | |
39938324 | 820 | const struct nlattr *attr) |
e6a7d3c0 PNA |
821 | { |
822 | return -EOPNOTSUPP; | |
823 | } | |
824 | #endif | |
825 | ||
0c4c9288 AD |
826 | static void __net_exit nf_nat_net_exit(struct net *net) |
827 | { | |
c7232c99 PM |
828 | struct nf_nat_proto_clean clean = {}; |
829 | ||
945b2b2d | 830 | nf_ct_iterate_cleanup(net, nf_nat_proto_clean, &clean, 0, 0); |
0c4c9288 AD |
831 | } |
832 | ||
833 | static struct pernet_operations nf_nat_net_ops = { | |
0c4c9288 AD |
834 | .exit = nf_nat_net_exit, |
835 | }; | |
836 | ||
544d5c7d PNA |
837 | static struct nf_ct_helper_expectfn follow_master_nat = { |
838 | .name = "nat-follow-master", | |
839 | .expectfn = nf_nat_follow_master, | |
840 | }; | |
841 | ||
5b1158e9 JK |
842 | static int __init nf_nat_init(void) |
843 | { | |
2d59e5ca YK |
844 | int ret; |
845 | ||
7223ecd4 | 846 | ret = rhltable_init(&nf_nat_bysource_table, &nf_nat_bysource_params); |
870190a9 FW |
847 | if (ret) |
848 | return ret; | |
a76ae1c8 | 849 | |
2d59e5ca YK |
850 | ret = nf_ct_extend_register(&nat_extend); |
851 | if (ret < 0) { | |
7223ecd4 | 852 | rhltable_destroy(&nf_nat_bysource_table); |
2d59e5ca YK |
853 | printk(KERN_ERR "nf_nat_core: Unable to register extension\n"); |
854 | return ret; | |
855 | } | |
5b1158e9 | 856 | |
0c4c9288 AD |
857 | ret = register_pernet_subsys(&nf_nat_net_ops); |
858 | if (ret < 0) | |
2d59e5ca | 859 | goto cleanup_extend; |
5b1158e9 | 860 | |
c7232c99 | 861 | nf_ct_helper_expectfn_register(&follow_master_nat); |
5b1158e9 | 862 | |
e6a7d3c0 | 863 | BUG_ON(nfnetlink_parse_nat_setup_hook != NULL); |
a9b3cd7f | 864 | RCU_INIT_POINTER(nfnetlink_parse_nat_setup_hook, |
e6a7d3c0 | 865 | nfnetlink_parse_nat_setup); |
c7232c99 PM |
866 | #ifdef CONFIG_XFRM |
867 | BUG_ON(nf_nat_decode_session_hook != NULL); | |
868 | RCU_INIT_POINTER(nf_nat_decode_session_hook, __nf_nat_decode_session); | |
869 | #endif | |
5b1158e9 | 870 | return 0; |
2d59e5ca YK |
871 | |
872 | cleanup_extend: | |
7223ecd4 | 873 | rhltable_destroy(&nf_nat_bysource_table); |
2d59e5ca YK |
874 | nf_ct_extend_unregister(&nat_extend); |
875 | return ret; | |
5b1158e9 JK |
876 | } |
877 | ||
5b1158e9 JK |
878 | static void __exit nf_nat_cleanup(void) |
879 | { | |
c7232c99 PM |
880 | unsigned int i; |
881 | ||
0c4c9288 | 882 | unregister_pernet_subsys(&nf_nat_net_ops); |
2d59e5ca | 883 | nf_ct_extend_unregister(&nat_extend); |
544d5c7d | 884 | nf_ct_helper_expectfn_unregister(&follow_master_nat); |
a9b3cd7f | 885 | RCU_INIT_POINTER(nfnetlink_parse_nat_setup_hook, NULL); |
c7232c99 PM |
886 | #ifdef CONFIG_XFRM |
887 | RCU_INIT_POINTER(nf_nat_decode_session_hook, NULL); | |
888 | #endif | |
3b7dabf0 LZ |
889 | synchronize_rcu(); |
890 | ||
c7232c99 PM |
891 | for (i = 0; i < NFPROTO_NUMPROTO; i++) |
892 | kfree(nf_nat_l4protos[i]); | |
870190a9 | 893 | |
7223ecd4 | 894 | rhltable_destroy(&nf_nat_bysource_table); |
5b1158e9 JK |
895 | } |
896 | ||
897 | MODULE_LICENSE("GPL"); | |
898 | ||
899 | module_init(nf_nat_init); | |
900 | module_exit(nf_nat_cleanup); |