Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 14 Jan 2020 11:30:31 +0000 (UTC)
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r356728 - head/sys/compat/linux
Message-ID:  <202001141130.00EBUVtR033681@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: trasz
Date: Tue Jan 14 11:30:30 2020
New Revision: 356728
URL: https://svnweb.freebsd.org/changeset/base/356728

Log:
  Make linux(4) use kern_getsockopt(9) instead of going through
  sys_getsockopt().  It's a cleanup; no functional changes.
  
  Reviewed by:	kib (earlier version)
  MFC after:	2 weeks
  Sponsored by:	The FreeBSD Foundation
  Differential Revision:	https://reviews.freebsd.org/D22813

Modified:
  head/sys/compat/linux/linux_socket.c

Modified: head/sys/compat/linux/linux_socket.c
==============================================================================
--- head/sys/compat/linux/linux_socket.c	Tue Jan 14 11:24:06 2020	(r356727)
+++ head/sys/compat/linux/linux_socket.c	Tue Jan 14 11:30:30 2020	(r356728)
@@ -1471,13 +1471,6 @@ linux_setsockopt(struct thread *td, struct linux_setso
 int
 linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args)
 {
-	struct getsockopt_args /* {
-		int s;
-		int level;
-		int name;
-		caddr_t val;
-		int *avalsize;
-	} */ bsd_args;
 	l_timeval linux_tv;
 	struct timeval tv;
 	socklen_t tv_len, xulen, len;
@@ -1485,11 +1478,10 @@ linux_getsockopt(struct thread *td, struct linux_getso
 	struct sockaddr *sa;
 	struct xucred xu;
 	struct l_ucred lxu;
-	int error, name, newval;
+	int error, level, name, newval;
 
-	bsd_args.s = args->s;
-	bsd_args.level = linux_to_bsd_sockopt_level(args->level);
-	switch (bsd_args.level) {
+	level = linux_to_bsd_sockopt_level(args->level);
+	switch (level) {
 	case SOL_SOCKET:
 		name = linux_to_bsd_so_sockopt(args->optname);
 		switch (name) {
@@ -1497,7 +1489,7 @@ linux_getsockopt(struct thread *td, struct linux_getso
 			/* FALLTHROUGH */
 		case SO_SNDTIMEO:
 			tv_len = sizeof(tv);
-			error = kern_getsockopt(td, args->s, bsd_args.level,
+			error = kern_getsockopt(td, args->s, level,
 			    name, &tv, UIO_SYSSPACE, &tv_len);
 			if (error != 0)
 				return (error);
@@ -1513,9 +1505,9 @@ linux_getsockopt(struct thread *td, struct linux_getso
 			 * LOCAL_PEERCRED is not served at the SOL_SOCKET level,
 			 * but by the Unix socket's level 0.
 			 */
-			bsd_args.level = 0;
+			level = 0;
 			xulen = sizeof(xu);
-			error = kern_getsockopt(td, args->s, bsd_args.level,
+			error = kern_getsockopt(td, args->s, level,
 			    name, &xu, UIO_SYSSPACE, &xulen);
 			if (error != 0)
 				return (error);
@@ -1526,7 +1518,7 @@ linux_getsockopt(struct thread *td, struct linux_getso
 			/* NOTREACHED */
 		case SO_ERROR:
 			len = sizeof(newval);
-			error = kern_getsockopt(td, args->s, bsd_args.level,
+			error = kern_getsockopt(td, args->s, level,
 			    name, &newval, UIO_SYSSPACE, &len);
 			if (error != 0)
 				return (error);
@@ -1553,16 +1545,13 @@ linux_getsockopt(struct thread *td, struct linux_getso
 	if (name == -1)
 		return (EINVAL);
 
-	bsd_args.name = name;
-	bsd_args.avalsize = PTRIN(args->optlen);
-
 	if (name == IPV6_NEXTHOP) {
 		error = copyin(PTRIN(args->optlen), &len, sizeof(len));
                 if (error != 0)
                         return (error);
 		sa = malloc(len, M_SONAME, M_WAITOK);
 
-		error = kern_getsockopt(td, args->s, bsd_args.level,
+		error = kern_getsockopt(td, args->s, level,
 		    name, sa, UIO_SYSSPACE, &len);
 		if (error != 0)
 			goto out;
@@ -1577,8 +1566,16 @@ linux_getsockopt(struct thread *td, struct linux_getso
 out:
 		free(sa, M_SONAME);
 	} else {
-		bsd_args.val = PTRIN(args->optval);
-		error = sys_getsockopt(td, &bsd_args);
+		if (args->optval) {
+			error = copyin(PTRIN(args->optlen), &len, sizeof(len));
+			if (error != 0)
+				return (error);
+		}
+		error = kern_getsockopt(td, args->s, level,
+		    name, PTRIN(args->optval), UIO_USERSPACE, &len);
+		if (error == 0)
+			error = copyout(&len, PTRIN(args->optlen),
+			    sizeof(len));
 	}
 
 	return (error);



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