Skip to content

Commit

Permalink
net: Set ping saddr after we successfully get the ping port
Browse files Browse the repository at this point in the history
We can defer set ping saddr until we successfully get the ping port. So we
can avoid clear saddr when failed. Since ping_clear_saddr() is not used
anymore now, remove it.

Signed-off-by: Miaohe Lin <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
MiaoheLin authored and davem330 committed Aug 25, 2020
1 parent cca8528 commit 0316a21
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions net/ipv4/ping.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,20 +383,6 @@ static void ping_set_saddr(struct sock *sk, struct sockaddr *saddr)
}
}

static void ping_clear_saddr(struct sock *sk, int dif)
{
sk->sk_bound_dev_if = dif;
if (sk->sk_family == AF_INET) {
struct inet_sock *isk = inet_sk(sk);
isk->inet_rcv_saddr = isk->inet_saddr = 0;
#if IS_ENABLED(CONFIG_IPV6)
} else if (sk->sk_family == AF_INET6) {
struct ipv6_pinfo *np = inet6_sk(sk);
memset(&sk->sk_v6_rcv_saddr, 0, sizeof(sk->sk_v6_rcv_saddr));
memset(&np->saddr, 0, sizeof(np->saddr));
#endif
}
}
/*
* We need our own bind because there are no privileged id's == local ports.
* Moreover, we don't allow binding to multi- and broadcast addresses.
Expand All @@ -420,12 +406,13 @@ int ping_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
goto out;

err = -EADDRINUSE;
ping_set_saddr(sk, uaddr);
snum = ntohs(((struct sockaddr_in *)uaddr)->sin_port);
if (ping_get_port(sk, snum) != 0) {
ping_clear_saddr(sk, dif);
/* Restore possibly modified sk->sk_bound_dev_if by ping_check_bind_addr(). */
sk->sk_bound_dev_if = dif;
goto out;
}
ping_set_saddr(sk, uaddr);

pr_debug("after bind(): num = %hu, dif = %d\n",
isk->inet_num,
Expand Down

0 comments on commit 0316a21

Please sign in to comment.