ipv4: don't call upper-layer disconnect function if not connected
Subsystems (2)
PATCH 1/1 ipv4: don't call upper-layer disconnect function if not connected
Calling connect() with AF_UNSPEC will disconnect a socket, but we don't need to do any work if the socket isn't currently connected.
net/ipv4/af_inet.c +12 -5
@@ -480,12 +480,16 @@ int inet_dgram_connect(struct socket *so {struct sock *sk = sock->sk; -if (uaddr->sa_family ==AF_UNSPEC ) -return sk->sk_prot->disconnect (sk, flags); +if (uaddr->sa_family ==AF_UNSPEC ) { +if (sock->state !=SS_UNCONNECTED ) +return sk->sk_prot->disconnect (sk, flags); +else +return 0 ; + }if (!inet_sk (sk)->num &&inet_autobind (sk))return -EAGAIN ; -return sk->sk_prot->connect (sk, (struct sockaddr *)uaddr, addr_len); +return sk->sk_prot->connect (sk, uaddr, addr_len); }static long inet_wait_for_connect (struct sock *sk,long timeo)
@@ -525,8 +529,11 @@ int inet_stream_connect(struct socket *slock_sock (sk);if (uaddr->sa_family ==AF_UNSPEC ) { - err = sk->sk_prot->disconnect (sk, flags); - sock->state = err ?SS_DISCONNECTING :SS_UNCONNECTED ; +if (sock->state !=SS_UNCONNECTED ) { + err = sk->sk_prot->disconnect (sk, flags); + sock->state = err ?SS_DISCONNECTING :SS_UNCONNECTED ; + }else + err =0 ; goto out; }
David Miller
maintainerFrom: Brian Haley <[email protected]>
Date: Tue, 01 Aug 2006 15:48:54 -0400
Quoted 4 lines
Calling
connect()withAF_UNSPECwill disconnect a socket, but we don't need to do any work if the socket isn't currently connected.Signed-off-by Brian Haley <[email protected]>
The socket could have been bind()'d to, in which case it will not move to connected state and we still need to invoke the disconnect methods such as udp_disconnect() to clear out that binding.
You seem to be groveling in random areas of the ipv4 and ipv6 stack, what are you working on?
Quoted 5 lines
The socket could have been bind()'d to, in which case it will not move to connected state and we still need to invoke the disconnect methods such as
udp_disconnect()to clear out that binding.
Ok.
Quoted 2 lines
You seem to be groveling in random areas of the ipv4 and ipv6 stack, what are you working on?
Was looking into a customer-reported memory leak that seemed to be in this code path. It wasn't, but this tweak seemed sane at the time.
-Brian