Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Oct 2019 14:18:02 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r353552 - stable/12/sys/netinet6
Message-ID:  <201910151418.x9FEI27n000709@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Tue Oct 15 14:18:01 2019
New Revision: 353552
URL: https://svnweb.freebsd.org/changeset/base/353552

Log:
  MFC r353295:
  Improve locking in the IPV6_V6ONLY socket option handler.

Modified:
  stable/12/sys/netinet6/ip6_output.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/netinet6/ip6_output.c
==============================================================================
--- stable/12/sys/netinet6/ip6_output.c	Tue Oct 15 14:13:01 2019	(r353551)
+++ stable/12/sys/netinet6/ip6_output.c	Tue Oct 15 14:18:01 2019	(r353552)
@@ -1717,21 +1717,24 @@ do {									\
 #endif
 
 				case IPV6_V6ONLY:
-					/*
-					 * make setsockopt(IPV6_V6ONLY)
-					 * available only prior to bind(2).
-					 * see ipng mailing list, Jun 22 2001.
-					 */
+					INP_WLOCK(inp);
 					if (in6p->inp_lport ||
 					    !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) {
+						/*
+						 * The socket is already bound.
+						 */
+						INP_WUNLOCK(inp);
 						error = EINVAL;
 						break;
 					}
-					OPTSET(IN6P_IPV6_V6ONLY);
-					if (optval)
+					if (optval) {
+						inp->inp_flags |= IN6P_IPV6_V6ONLY;
 						in6p->inp_vflag &= ~INP_IPV4;
-					else
+					} else {
+						inp->inp_flags &= ~IN6P_IPV6_V6ONLY;
 						in6p->inp_vflag |= INP_IPV4;
+					}
+					INP_WUNLOCK(inp);
 					break;
 				case IPV6_RECVTCLASS:
 					/* cannot mix with RFC2292 XXX */



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