netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] connect() return value.
@ 2002-08-10 10:24 Geoffrey Lee
  2002-08-11 20:46 ` kuznet
  0 siblings, 1 reply; 23+ messages in thread
From: Geoffrey Lee @ 2002-08-10 10:24 UTC (permalink / raw)
  To: netdev

[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]

Hi,


I posted this on linux-kernel but didn't get a reply.

Anyway here's a patch for it.



Problem:

(1)

While you try to connect() to port 0 on ipv4 / ipv6, it happily does it.
This doesn't seem to be correct, as I remember port 0 is reserved.
For reference FreeBSD / Solaris / OSF return -EADDRNOTAVAIL for this.

This is what my patch fixes, for ipv4 and ipv6 for both tcp and udp,
I don't know what should be done for the other protocols that is 
supported.


(2)

connect() doesn't return -EINTR on signal, rather it exits the signal
handler after processing it and returns an error if an error occurred
for the connection or does the connect to completion. The Linux man page 
implies that we don't ever return an -EINTR on Linux, but I don't know what 
is the correct behavior.  For reference, FreeBSD / Solaris / OSF return
-EINTR for an interrupted connect().

The patch also addresses this. However, it is noted on OSF that even
though connect() returns with -EINTR if the connection succeeds you can
still send and receive through that socket.


(Please CC:, not on list. Thanks).

	-- G.
	

[-- Attachment #2: network-patch --]
[-- Type: text/plain, Size: 2385 bytes --]

diff -ruNp linux-2.4.19/net/ipv4/tcp_ipv4.c linux-2.4.19-glee/net/ipv4/tcp_ipv4.c
--- linux-2.4.19/net/ipv4/tcp_ipv4.c	2002-08-03 19:26:04.000000000 +1000
+++ linux-2.4.19-glee/net/ipv4/tcp_ipv4.c	2002-08-10 19:34:24.000000000 +1000
@@ -763,6 +763,9 @@ int tcp_v4_connect(struct sock *sk, stru
 	if (usin->sin_family != AF_INET)
 		return(-EAFNOSUPPORT);
 
+	if (usin->sin_port == 0)
+		return(-EADDRNOTAVAIL);
+
 	nexthop = daddr = usin->sin_addr.s_addr;
 	if (sk->protinfo.af_inet.opt && sk->protinfo.af_inet.opt->srr) {
 		if (daddr == 0)
diff -ruNp linux-2.4.19/net/ipv4/udp.c linux-2.4.19-glee/net/ipv4/udp.c
--- linux-2.4.19/net/ipv4/udp.c	2002-08-03 19:26:04.000000000 +1000
+++ linux-2.4.19-glee/net/ipv4/udp.c	2002-08-10 19:34:52.000000000 +1000
@@ -723,6 +723,9 @@ int udp_connect(struct sock *sk, struct 
 	if (usin->sin_family != AF_INET) 
 	  	return -EAFNOSUPPORT;
 
+	if (usin->sin_port == 0)
+		return -EADDRNOTAVAIL;
+
 	sk_dst_reset(sk);
 
 	oif = sk->bound_dev_if;
diff -ruNp linux-2.4.19/net/ipv6/tcp_ipv6.c linux-2.4.19-glee/net/ipv6/tcp_ipv6.c
--- linux-2.4.19/net/ipv6/tcp_ipv6.c	2002-08-03 19:26:04.000000000 +1000
+++ linux-2.4.19-glee/net/ipv6/tcp_ipv6.c	2002-08-10 19:35:57.000000000 +1000
@@ -539,6 +539,9 @@ static int tcp_v6_connect(struct sock *s
 	if (usin->sin6_family != AF_INET6) 
 		return(-EAFNOSUPPORT);
 
+	if (usin->sin6_port == 0)
+		return -EADDRNOTAVAIL;
+
 	fl.fl6_flowlabel = 0;
 	if (np->sndflow) {
 		fl.fl6_flowlabel = usin->sin6_flowinfo&IPV6_FLOWINFO_MASK;
diff -ruNp linux-2.4.19/net/ipv6/udp.c linux-2.4.19-glee/net/ipv6/udp.c
--- linux-2.4.19/net/ipv6/udp.c	2002-08-03 19:26:04.000000000 +1000
+++ linux-2.4.19-glee/net/ipv6/udp.c	2002-08-10 19:36:22.000000000 +1000
@@ -231,6 +231,9 @@ int udpv6_connect(struct sock *sk, struc
 	if (usin->sin6_family != AF_INET6) 
 	  	return -EAFNOSUPPORT;
 
+	if (usin->sin6_port == 0)
+		return -EADDRNOTAVAIL;
+
 	fl.fl6_flowlabel = 0;
 	if (np->sndflow) {
 		fl.fl6_flowlabel = usin->sin6_flowinfo&IPV6_FLOWINFO_MASK;
diff -ruNp linux-2.4.19/net/socket.c linux-2.4.19-glee/net/socket.c
--- linux-2.4.19/net/socket.c	2002-08-03 19:26:04.000000000 +1000
+++ linux-2.4.19-glee/net/socket.c	2002-08-10 19:37:23.000000000 +1000
@@ -1118,6 +1118,9 @@ asmlinkage long sys_connect(int fd, stru
 out_put:
 	sockfd_put(sock);
 out:
+	if (signal_pending(current))
+		return -EINTR;
+
 	return err;
 }
 

^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2002-08-16  1:08 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-10 10:24 [PATCH] connect() return value Geoffrey Lee
2002-08-11 20:46 ` kuznet
2002-08-11 23:25   ` Geoffrey Lee
2002-08-12  1:28     ` kuznet
2002-08-13  2:21       ` Geoffrey Lee
2002-08-13  4:44         ` kuznet
2002-08-13  5:37           ` Geoffrey Lee
2002-08-13 10:17             ` kuznet
2002-08-13 11:34               ` Geoffrey Lee
2002-08-13 13:47                 ` kuznet
2002-08-13 14:32                   ` Geoffrey Lee
2002-08-13 15:28                     ` kuznet
2002-08-13 23:51                       ` Geoffrey Lee
2002-08-14  0:36                         ` kuznet
2002-08-14  3:02                           ` Geoffrey Lee
2002-08-14  4:16                             ` kuznet
2002-08-14  4:57                               ` Geoffrey Lee
2002-08-14 17:25                                 ` kuznet
2002-08-15  3:25                                   ` glee
2002-08-15  3:15                                     ` David S. Miller
2002-08-15 11:02                                       ` Geoffrey Lee
2002-08-15 21:23                                         ` David S. Miller
2002-08-16  1:08                                           ` Geoffrey Lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).