Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Jul 2020 16:46:25 +0000 (UTC)
From:      Michael Tuexen <tuexen@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r363256 - head/sys/netinet
Message-ID:  <202007161646.06GGkPfH043741@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tuexen
Date: Thu Jul 16 16:46:24 2020
New Revision: 363256
URL: https://svnweb.freebsd.org/changeset/base/363256

Log:
  (Re)-allow 0.0.0.0 to be used as an address in connect() for TCP
  In r361752 an error handling was introduced for using 0.0.0.0 or
  255.255.255.255 as the address in connect() for TCP, since both
  addresses can't be used. However, the stack maps 0.0.0.0 implicitly
  to a local address and at least two regressions were reported.
  Therefore, re-allow the usage of 0.0.0.0.
  While there, change the error indicated when using 255.255.255.255
  from EAFNOSUPPORT to EACCES as mentioned in the man-page of connect().
  
  Reviewed by:		rrs
  MFC after:		1 week
  Sponsored by:		Netflix, Inc.
  Differential Revision:	https://reviews.freebsd.org/D25401

Modified:
  head/sys/netinet/tcp_usrreq.c

Modified: head/sys/netinet/tcp_usrreq.c
==============================================================================
--- head/sys/netinet/tcp_usrreq.c	Thu Jul 16 16:32:16 2020	(r363255)
+++ head/sys/netinet/tcp_usrreq.c	Thu Jul 16 16:46:24 2020	(r363256)
@@ -553,9 +553,8 @@ tcp_usr_connect(struct socket *so, struct sockaddr *na
 	    && IN_MULTICAST(ntohl(sinp->sin_addr.s_addr)))
 		return (EAFNOSUPPORT);
 	if ((sinp->sin_family == AF_INET) &&
-	    ((ntohl(sinp->sin_addr.s_addr) == INADDR_BROADCAST) ||
-	     (sinp->sin_addr.s_addr == INADDR_ANY)))
-		return(EAFNOSUPPORT);
+	    (ntohl(sinp->sin_addr.s_addr) == INADDR_BROADCAST))
+		return (EACCES);
 	if ((error = prison_remote_ip4(td->td_ucred, &sinp->sin_addr)) != 0)
 		return (error);
 
@@ -656,9 +655,8 @@ tcp6_usr_connect(struct socket *so, struct sockaddr *n
 			error = EAFNOSUPPORT;
 			goto out;
 		}
-		if ((ntohl(sin.sin_addr.s_addr) == INADDR_BROADCAST) ||
-		    (sin.sin_addr.s_addr == INADDR_ANY)) {
-			error = EAFNOSUPPORT;
+		if (ntohl(sin.sin_addr.s_addr) == INADDR_BROADCAST) {
+			error = EACCES;
 			goto out;
 		}
 		if ((error = prison_remote_ip4(td->td_ucred,
@@ -1033,11 +1031,10 @@ tcp_usr_send(struct socket *so, int flags, struct mbuf
 				error = EAFNOSUPPORT;
 				goto out;
 			}
-			if ((ntohl(sinp->sin_addr.s_addr) == INADDR_BROADCAST) ||
-			    (sinp->sin_addr.s_addr == INADDR_ANY)) {
+			if (ntohl(sinp->sin_addr.s_addr) == INADDR_BROADCAST) {
 				if (m)
 					m_freem(m);
-				error = EAFNOSUPPORT;
+				error = EACCES;
 				goto out;
 			}
 			if ((error = prison_remote_ip4(td->td_ucred,



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202007161646.06GGkPfH043741>