Skip to content

Commit f59cb04

Browse files
committed
netfilter: nf_nat: move alloc_null_binding to nf_nat_core.c
Similar to nat_decode_session, alloc_null_binding is needed for both ip_tables and nf_tables, so move it to nf_nat_core.c. This change is required by nf_tables. This is an adapted version of the original patch from Patrick McHardy. Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 795aa6e commit f59cb04

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

include/net/netfilter/nf_nat.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ unsigned int nf_nat_setup_info(struct nf_conn *ct,
4545
const struct nf_nat_range *range,
4646
enum nf_nat_manip_type maniptype);
4747

48+
extern unsigned int nf_nat_alloc_null_binding(struct nf_conn *ct,
49+
unsigned int hooknum);
50+
4851
/* Is this tuple already taken? (not by us)*/
4952
int nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple,
5053
const struct nf_conn *ignored_conntrack);

net/netfilter/nf_nat_core.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,26 @@ nf_nat_setup_info(struct nf_conn *ct,
432432
}
433433
EXPORT_SYMBOL(nf_nat_setup_info);
434434

435+
unsigned int
436+
nf_nat_alloc_null_binding(struct nf_conn *ct, unsigned int hooknum)
437+
{
438+
/* Force range to this IP; let proto decide mapping for
439+
* per-proto parts (hence not IP_NAT_RANGE_PROTO_SPECIFIED).
440+
* Use reply in case it's already been mangled (eg local packet).
441+
*/
442+
union nf_inet_addr ip =
443+
(HOOK2MANIP(hooknum) == NF_NAT_MANIP_SRC ?
444+
ct->tuplehash[IP_CT_DIR_REPLY].tuple.dst.u3 :
445+
ct->tuplehash[IP_CT_DIR_REPLY].tuple.src.u3);
446+
struct nf_nat_range range = {
447+
.flags = NF_NAT_RANGE_MAP_IPS,
448+
.min_addr = ip,
449+
.max_addr = ip,
450+
};
451+
return nf_nat_setup_info(ct, &range, HOOK2MANIP(hooknum));
452+
}
453+
EXPORT_SYMBOL_GPL(nf_nat_alloc_null_binding);
454+
435455
/* Do packet manipulations according to nf_nat_setup_info. */
436456
unsigned int nf_nat_packet(struct nf_conn *ct,
437457
enum ip_conntrack_info ctinfo,

0 commit comments

Comments
 (0)