Skip to contentSkip to conversation

ipv4: don't call upper-layer disconnect function if not connected

PATCH In review Brian Haley 2 participants 3 messages Aug 1, 2006 – Aug 2, 2006

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index c84a320..b294b92 100644
@@ -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 *s
 	lock_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;
 	}
 
maintainer
#1 lore raw

From: Brian Haley <[email protected]>
Date: Tue, 01 Aug 2006 15:48:54 -0400

Quoted 4 lines

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.

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?

#2 lore raw
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