Module Name: src Committed By: christos Date: Thu Jan 4 01:42:26 UTC 2018
Modified Files: src/share/man/man9: sockopt.9 src/sys/kern: uipc_socket.c uipc_syscalls.c src/sys/sys: param.h socketvar.h Log Message: Add a new sockopt member to keep track of the actual size of the option that should be returned to the caller in getsockopt(2). (Tom Ivar Helbekkmo) To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/share/man/man9/sockopt.9 cvs rdiff -u -r1.258 -r1.259 src/sys/kern/uipc_socket.c cvs rdiff -u -r1.189 -r1.190 src/sys/kern/uipc_syscalls.c cvs rdiff -u -r1.555 -r1.556 src/sys/sys/param.h cvs rdiff -u -r1.145 -r1.146 src/sys/sys/socketvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/share/man/man9/sockopt.9 diff -u src/share/man/man9/sockopt.9:1.10 src/share/man/man9/sockopt.9:1.11 --- src/share/man/man9/sockopt.9:1.10 Mon Jan 16 07:54:25 2017 +++ src/share/man/man9/sockopt.9 Wed Jan 3 20:42:25 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: sockopt.9,v 1.10 2017/01/16 12:54:25 njoly Exp $ +.\" $NetBSD: sockopt.9,v 1.11 2018/01/04 01:42:25 christos Exp $ .\" .\" Copyright (c) 2008 Iain Hibbert .\" All rights reserved. @@ -23,7 +23,7 @@ .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd September 4, 2009 +.Dd January 3, 2018 .Dt SOCKOPT 9 .Os .Sh NAME @@ -57,6 +57,7 @@ struct sockopt { int sopt_level; /* option level */ int sopt_name; /* option name */ size_t sopt_size; /* data length */ + size_t sopt_retsize; /* returned data length */ void * sopt_data; /* data pointer */ uint8_t sopt_buf[sizeof(int)]; /* internal storage */ }; @@ -133,7 +134,7 @@ context using which will not fail. .It Fn sockopt_setint "sopt" "value" Common case of set sockopt integer value. -The sockpt structure must contain an int sized data field or be previously +The sockopt structure must contain an int sized data field or be previously unset, in which case the data pointer will be set to the internal storage. .El .Sh CODE REFERENCES Index: src/sys/kern/uipc_socket.c diff -u src/sys/kern/uipc_socket.c:1.258 src/sys/kern/uipc_socket.c:1.259 --- src/sys/kern/uipc_socket.c:1.258 Sun Dec 31 19:45:12 2017 +++ src/sys/kern/uipc_socket.c Wed Jan 3 20:42:25 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_socket.c,v 1.258 2018/01/01 00:45:12 christos Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.259 2018/01/04 01:42:25 christos Exp $ */ /*- * Copyright (c) 2002, 2007, 2008, 2009 The NetBSD Foundation, Inc. @@ -71,7 +71,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.258 2018/01/01 00:45:12 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_socket.c,v 1.259 2018/01/04 01:42:25 christos Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -2113,6 +2113,8 @@ sockopt_set(struct sockopt *sopt, const return EINVAL; memcpy(sopt->sopt_data, buf, len); + sopt->sopt_retsize = len; + return 0; } @@ -2176,6 +2178,7 @@ sockopt_setmbuf(struct sockopt *sopt, st m_copydata(m, 0, len, sopt->sopt_data); m_freem(m); + sopt->sopt_retsize = len; return 0; } Index: src/sys/kern/uipc_syscalls.c diff -u src/sys/kern/uipc_syscalls.c:1.189 src/sys/kern/uipc_syscalls.c:1.190 --- src/sys/kern/uipc_syscalls.c:1.189 Sun Dec 31 14:39:57 2017 +++ src/sys/kern/uipc_syscalls.c Wed Jan 3 20:42:25 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_syscalls.c,v 1.189 2017/12/31 19:39:57 christos Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.190 2018/01/04 01:42:25 christos Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -61,7 +61,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.189 2017/12/31 19:39:57 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.190 2018/01/04 01:42:25 christos Exp $"); #ifdef _KERNEL_OPT #include "opt_pipe.h" @@ -1249,7 +1249,7 @@ sys_getsockopt(struct lwp *l, const stru goto out; if (valsize > 0) { - len = min(valsize, sopt.sopt_size); + len = min(valsize, sopt.sopt_retsize); error = copyout(sopt.sopt_data, SCARG(uap, val), len); if (error) goto out; Index: src/sys/sys/param.h diff -u src/sys/sys/param.h:1.555 src/sys/sys/param.h:1.556 --- src/sys/sys/param.h:1.555 Sun Dec 31 19:51:36 2017 +++ src/sys/sys/param.h Wed Jan 3 20:42:25 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: param.h,v 1.555 2018/01/01 00:51:36 christos Exp $ */ +/* $NetBSD: param.h,v 1.556 2018/01/04 01:42:25 christos Exp $ */ /*- * Copyright (c) 1982, 1986, 1989, 1993 @@ -67,7 +67,7 @@ * 2.99.9 (299000900) */ -#define __NetBSD_Version__ 899001000 /* NetBSD 8.99.10 */ +#define __NetBSD_Version__ 899001100 /* NetBSD 8.99.11 */ #define __NetBSD_Prereq__(M,m,p) (((((M) * 100000000) + \ (m) * 1000000) + (p) * 100) <= __NetBSD_Version__) Index: src/sys/sys/socketvar.h diff -u src/sys/sys/socketvar.h:1.145 src/sys/sys/socketvar.h:1.146 --- src/sys/sys/socketvar.h:1.145 Thu Jul 6 13:08:57 2017 +++ src/sys/sys/socketvar.h Wed Jan 3 20:42:25 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: socketvar.h,v 1.145 2017/07/06 17:08:57 christos Exp $ */ +/* $NetBSD: socketvar.h,v 1.146 2018/01/04 01:42:25 christos Exp $ */ /*- * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. @@ -224,6 +224,7 @@ struct sockopt { int sopt_level; /* option level */ int sopt_name; /* option name */ size_t sopt_size; /* data length */ + size_t sopt_retsize; /* returned data length */ void * sopt_data; /* data pointer */ uint8_t sopt_buf[sizeof(int)]; /* internal storage */ };