Skip to content

Commit

Permalink
net: Avoid unnecessary inet_addr_type() call when addr is INADDR_ANY
Browse files Browse the repository at this point in the history
We can avoid unnecessary inet_addr_type() call by check addr against
INADDR_ANY first.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Miaohe Lin authored and David S. Miller committed Aug 25, 2020
1 parent 0316a21 commit 0ce779a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/ipv4/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,10 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
pr_debug("ping_check_bind_addr(sk=%p,addr=%pI4,port=%d)\n",
sk, &addr->sin_addr.s_addr, ntohs(addr->sin_port));

chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);

if (addr->sin_addr.s_addr == htonl(INADDR_ANY))
chk_addr_ret = RTN_LOCAL;
else
chk_addr_ret = inet_addr_type(net, addr->sin_addr.s_addr);

if ((!inet_can_nonlocal_bind(net, isk) &&
chk_addr_ret != RTN_LOCAL) ||
Expand Down

0 comments on commit 0ce779a

Please sign in to comment.