diff options
author | Florian Westphal <fw@strlen.de> | 2022-09-06 18:20:35 +0300 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2022-09-07 17:46:04 +0300 |
commit | c92c27171040554cfda7a3fc925e9dbcb5b4a698 (patch) | |
tree | 59d7fc3e6dbecbee86cb99add3454a1f999f5047 /net/netfilter/nf_nat_ftp.c | |
parent | 8556bceb9c409946eebd2303d2f19e87844195ae (diff) | |
download | linux-c92c27171040554cfda7a3fc925e9dbcb5b4a698.tar.xz |
netfilter: nat: move repetitive nat port reserve loop to a helper
Almost all nat helpers reserve an expecation port the same way:
Try the port inidcated by the peer, then move to next port if that
port is already in use.
We can squash this into a helper.
Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'net/netfilter/nf_nat_ftp.c')
-rw-r--r-- | net/netfilter/nf_nat_ftp.c | 17 |
1 files changed, 2 insertions, 15 deletions
diff --git a/net/netfilter/nf_nat_ftp.c b/net/netfilter/nf_nat_ftp.c index aace6768a64e..c92a436d9c48 100644 --- a/net/netfilter/nf_nat_ftp.c +++ b/net/netfilter/nf_nat_ftp.c @@ -86,22 +86,9 @@ static unsigned int nf_nat_ftp(struct sk_buff *skb, * this one. */ exp->expectfn = nf_nat_follow_master; - /* Try to get same port: if not, try to change it. */ - for (port = ntohs(exp->saved_proto.tcp.port); port != 0; port++) { - int ret; - - exp->tuple.dst.u.tcp.port = htons(port); - ret = nf_ct_expect_related(exp, 0); - if (ret == 0) - break; - else if (ret != -EBUSY) { - port = 0; - break; - } - } - + port = nf_nat_exp_find_port(exp, ntohs(exp->saved_proto.tcp.port)); if (port == 0) { - nf_ct_helper_log(skb, ct, "all ports in use"); + nf_ct_helper_log(skb, exp->master, "all ports in use"); return NF_DROP; } |