Module Name: src Committed By: nia Date: Sun Aug 8 20:54:49 UTC 2021
Modified Files: src/lib/libc/net: getpeereid.c src/lib/libc/rpc: svc_vc.c src/lib/libc/sys: getsockopt.2 src/lib/libperfuse: perfuse.c src/regress/sys/kern/unfdpass: unfdpass.c src/share/man/man4: unix.4 src/sys/kern: uipc_usrreq.c src/sys/sys: un.h src/tests/net/net: t_unix.c src/usr.sbin/perfused: msg.c src/usr.sbin/sdpd: server.c Log Message: introduce a SOL_LOCAL for unix-domain socket level socket options as an alias of the current 0 used for these options, as in FreeBSD. reviewed by many. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/lib/libc/net/getpeereid.c cvs rdiff -u -r1.34 -r1.35 src/lib/libc/rpc/svc_vc.c cvs rdiff -u -r1.41 -r1.42 src/lib/libc/sys/getsockopt.2 cvs rdiff -u -r1.42 -r1.43 src/lib/libperfuse/perfuse.c cvs rdiff -u -r1.11 -r1.12 src/regress/sys/kern/unfdpass/unfdpass.c cvs rdiff -u -r1.26 -r1.27 src/share/man/man4/unix.4 cvs rdiff -u -r1.200 -r1.201 src/sys/kern/uipc_usrreq.c cvs rdiff -u -r1.59 -r1.60 src/sys/sys/un.h cvs rdiff -u -r1.24 -r1.25 src/tests/net/net/t_unix.c cvs rdiff -u -r1.25 -r1.26 src/usr.sbin/perfused/msg.c cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/sdpd/server.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/net/getpeereid.c diff -u src/lib/libc/net/getpeereid.c:1.3 src/lib/libc/net/getpeereid.c:1.4 --- src/lib/libc/net/getpeereid.c:1.3 Fri Feb 16 19:21:49 2018 +++ src/lib/libc/net/getpeereid.c Sun Aug 8 20:54:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: getpeereid.c,v 1.3 2018/02/16 19:21:49 christos Exp $ */ +/* $NetBSD: getpeereid.c,v 1.4 2021/08/08 20:54:48 nia Exp $ */ /*- * Copyright (c) 2007 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: getpeereid.c,v 1.3 2018/02/16 19:21:49 christos Exp $"); +__RCSID("$NetBSD: getpeereid.c,v 1.4 2021/08/08 20:54:48 nia Exp $"); #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -57,7 +57,7 @@ getpeereid(int s, uid_t *euid, gid_t *eg } len = sizeof(cred); - if (getsockopt(s, 0, LOCAL_PEEREID, &cred, &len) == -1) + if (getsockopt(s, SOL_LOCAL, LOCAL_PEEREID, &cred, &len) == -1) return -1; if (euid != NULL) Index: src/lib/libc/rpc/svc_vc.c diff -u src/lib/libc/rpc/svc_vc.c:1.34 src/lib/libc/rpc/svc_vc.c:1.35 --- src/lib/libc/rpc/svc_vc.c:1.34 Tue Nov 10 20:56:20 2015 +++ src/lib/libc/rpc/svc_vc.c Sun Aug 8 20:54:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: svc_vc.c,v 1.34 2015/11/10 20:56:20 christos Exp $ */ +/* $NetBSD: svc_vc.c,v 1.35 2021/08/08 20:54:48 nia Exp $ */ /* * Copyright (c) 2010, Oracle America, Inc. @@ -37,7 +37,7 @@ static char *sccsid = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro"; static char *sccsid = "@(#)svc_tcp.c 2.2 88/08/01 4.0 RPCSRC"; #else -__RCSID("$NetBSD: svc_vc.c,v 1.34 2015/11/10 20:56:20 christos Exp $"); +__RCSID("$NetBSD: svc_vc.c,v 1.35 2021/08/08 20:54:48 nia Exp $"); #endif #endif @@ -178,8 +178,8 @@ svc_vc_create(int fd, u_int sendsize, u_ * We want to be able to check credentials on local sockets. */ if (sslocal.ss_family == AF_LOCAL) - if (setsockopt(fd, 0, LOCAL_CREDS, &one, (socklen_t)sizeof one) - == -1) + if (setsockopt(fd, SOL_LOCAL, LOCAL_CREDS, &one, + (socklen_t)sizeof one) == -1) goto cleanup_svc_vc_create; xprt->xp_ltaddr.maxlen = xprt->xp_ltaddr.len = sslocal.ss_len; Index: src/lib/libc/sys/getsockopt.2 diff -u src/lib/libc/sys/getsockopt.2:1.41 src/lib/libc/sys/getsockopt.2:1.42 --- src/lib/libc/sys/getsockopt.2:1.41 Thu May 9 09:09:38 2019 +++ src/lib/libc/sys/getsockopt.2 Sun Aug 8 20:54:48 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: getsockopt.2,v 1.41 2019/05/09 09:09:38 wiz Exp $ +.\" $NetBSD: getsockopt.2,v 1.42 2021/08/08 20:54:48 nia Exp $ .\" .\" Copyright (c) 1983, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)getsockopt.2 8.4 (Berkeley) 5/2/95 .\" -.Dd May 8, 2019 +.Dd August 7, 2021 .Dt GETSOCKOPT 2 .Os .Sh NAME @@ -55,10 +55,6 @@ and manipulate the .Em options associated with a socket. -Options may exist at multiple -protocol levels; they are always present at the uppermost -.Dq socket -level. .Pp When manipulating socket options the level at which the option resides and the name of the option must be specified. @@ -69,6 +65,7 @@ is specified as To manipulate options at any other level the protocol number of the appropriate protocol controlling the option is supplied. +Options may exist at multiple protocol levels. For example, to indicate that an option is to be interpreted by the .Tn TCP protocol, Index: src/lib/libperfuse/perfuse.c diff -u src/lib/libperfuse/perfuse.c:1.42 src/lib/libperfuse/perfuse.c:1.43 --- src/lib/libperfuse/perfuse.c:1.42 Wed Apr 17 12:30:51 2019 +++ src/lib/libperfuse/perfuse.c Sun Aug 8 20:54:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: perfuse.c,v 1.42 2019/04/17 12:30:51 maya Exp $ */ +/* $NetBSD: perfuse.c,v 1.43 2021/08/08 20:54:48 nia Exp $ */ /*- * Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved. @@ -255,7 +255,7 @@ perfuse_open(const char *path, int flags */ opt = 1; optlen = sizeof(opt); - if (setsockopt(sv[1], 0, LOCAL_CREDS, &opt, optlen) != 0) + if (setsockopt(sv[1], SOL_LOCAL, LOCAL_CREDS, &opt, optlen) != 0) DWARN("%s: setsockopt LOCAL_CREDS failed", __func__); (void)sprintf(fdstr, "%d", sv[1]); Index: src/regress/sys/kern/unfdpass/unfdpass.c diff -u src/regress/sys/kern/unfdpass/unfdpass.c:1.11 src/regress/sys/kern/unfdpass/unfdpass.c:1.12 --- src/regress/sys/kern/unfdpass/unfdpass.c:1.11 Tue Jan 10 22:37:44 2017 +++ src/regress/sys/kern/unfdpass/unfdpass.c Sun Aug 8 20:54:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: unfdpass.c,v 1.11 2017/01/10 22:37:44 christos Exp $ */ +/* $NetBSD: unfdpass.c,v 1.12 2021/08/08 20:54:48 nia Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -168,7 +168,7 @@ main(argc, argv) sun.sun_len = SUN_LEN(&sun); i = 1; - if (setsockopt(listensock, 0, LOCAL_CREDS, &i, sizeof(i)) == -1) + if (setsockopt(listensock, SOL_LOCAL, LOCAL_CREDS, &i, sizeof(i)) == -1) err(1, "setsockopt"); if (bind(listensock, (struct sockaddr *)&sun, sizeof(sun)) == -1) Index: src/share/man/man4/unix.4 diff -u src/share/man/man4/unix.4:1.26 src/share/man/man4/unix.4:1.27 --- src/share/man/man4/unix.4:1.26 Mon Jul 3 21:30:58 2017 +++ src/share/man/man4/unix.4 Sun Aug 8 20:54:48 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: unix.4,v 1.26 2017/07/03 21:30:58 wiz Exp $ +.\" $NetBSD: unix.4,v 1.27 2021/08/08 20:54:48 nia Exp $ .\" .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)unix.4 8.1 (Berkeley) 6/9/93 .\" -.Dd March 31, 2016 +.Dd August 7, 2021 .Dt UNIX 4 .Os .Sh NAME @@ -172,9 +172,9 @@ Descriptors that are awaiting delivery, purposely not received, are automatically closed by the system when the destination socket is closed. .Pp -A UNIX-domain socket supports two -.Tn socket-level -options for use with +A UNIX-domain socket supports several +.Dv SOL_LOCAL +level options for use with .Xr setsockopt 2 and .Xr getsockopt 2 : Index: src/sys/kern/uipc_usrreq.c diff -u src/sys/kern/uipc_usrreq.c:1.200 src/sys/kern/uipc_usrreq.c:1.201 --- src/sys/kern/uipc_usrreq.c:1.200 Fri Nov 6 14:50:13 2020 +++ src/sys/kern/uipc_usrreq.c Sun Aug 8 20:54:48 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: uipc_usrreq.c,v 1.200 2020/11/06 14:50:13 christos Exp $ */ +/* $NetBSD: uipc_usrreq.c,v 1.201 2021/08/08 20:54:48 nia Exp $ */ /*- * Copyright (c) 1998, 2000, 2004, 2008, 2009, 2020 The NetBSD Foundation, Inc. @@ -96,7 +96,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.200 2020/11/06 14:50:13 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.201 2021/08/08 20:54:48 nia Exp $"); #ifdef _KERNEL_OPT #include "opt_compat_netbsd.h" @@ -608,7 +608,7 @@ uipc_ctloutput(int op, struct socket *so KASSERT(solocked(so)); - if (sopt->sopt_level != 0) { + if (sopt->sopt_level != SOL_LOCAL) { error = ENOPROTOOPT; } else switch (op) { Index: src/sys/sys/un.h diff -u src/sys/sys/un.h:1.59 src/sys/sys/un.h:1.60 --- src/sys/sys/un.h:1.59 Fri Nov 6 14:50:13 2020 +++ src/sys/sys/un.h Sun Aug 8 20:54:49 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: un.h,v 1.59 2020/11/06 14:50:13 christos Exp $ */ +/* $NetBSD: un.h,v 1.60 2021/08/08 20:54:49 nia Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -56,6 +56,7 @@ struct sockaddr_un { * Socket options for UNIX IPC domain. */ #if defined(_NETBSD_SOURCE) +#define SOL_LOCAL 0 /* options level for getsockopt(2) */ #define LOCAL_OCREDS 0x0001 /* pass credentials to receiver */ #define LOCAL_CONNWAIT 0x0002 /* connects block until accepted */ #define LOCAL_PEEREID 0x0003 /* get peer identification */ Index: src/tests/net/net/t_unix.c diff -u src/tests/net/net/t_unix.c:1.24 src/tests/net/net/t_unix.c:1.25 --- src/tests/net/net/t_unix.c:1.24 Fri Aug 28 14:18:29 2020 +++ src/tests/net/net/t_unix.c Sun Aug 8 20:54:49 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: t_unix.c,v 1.24 2020/08/28 14:18:29 riastradh Exp $ */ +/* $NetBSD: t_unix.c,v 1.25 2021/08/08 20:54:49 nia Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ #define _GNU_SOURCE #include <sys/cdefs.h> #ifdef __RCSID -__RCSID("$Id: t_unix.c,v 1.24 2020/08/28 14:18:29 riastradh Exp $"); +__RCSID("$Id: t_unix.c,v 1.25 2021/08/08 20:54:49 nia Exp $"); #else #define getprogname() argv[0] #endif @@ -147,7 +147,7 @@ peercred(int s, uid_t *euid, gid_t *egid # define LOCAL_PEEREID SO_PEERCRED # define LEVEL SOL_SOCKET #else -# define LEVEL 0 +# define LEVEL SOL_LOCAL #endif #ifdef LOCAL_PEEREID Index: src/usr.sbin/perfused/msg.c diff -u src/usr.sbin/perfused/msg.c:1.25 src/usr.sbin/perfused/msg.c:1.26 --- src/usr.sbin/perfused/msg.c:1.25 Wed Apr 17 12:30:51 2019 +++ src/usr.sbin/perfused/msg.c Sun Aug 8 20:54:49 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: msg.c,v 1.25 2019/04/17 12:30:51 maya Exp $ */ +/* $NetBSD: msg.c,v 1.26 2021/08/08 20:54:49 nia Exp $ */ /*- * Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved. @@ -92,7 +92,7 @@ perfused_open_sock(void) * Request peer credentials */ opt = 1; - if (setsockopt(s, 0, LOCAL_CREDS, &opt, sizeof(opt)) != 0) + if (setsockopt(s, SOL_LOCAL, LOCAL_CREDS, &opt, sizeof(opt)) != 0) DWARN("%s: setsockopt LOCAL_CREDS failed", __func__); if (bind(s, sa, (socklen_t )sun.sun_len) == -1) Index: src/usr.sbin/sdpd/server.c diff -u src/usr.sbin/sdpd/server.c:1.11 src/usr.sbin/sdpd/server.c:1.12 --- src/usr.sbin/sdpd/server.c:1.11 Thu Mar 1 22:38:31 2012 +++ src/usr.sbin/sdpd/server.c Sun Aug 8 20:54:49 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: server.c,v 1.11 2012/03/01 22:38:31 joerg Exp $ */ +/* $NetBSD: server.c,v 1.12 2021/08/08 20:54:49 nia Exp $ */ /*- * Copyright (c) 2006 Itronix Inc. @@ -58,7 +58,7 @@ */ #include <sys/cdefs.h> -__RCSID("$NetBSD: server.c,v 1.11 2012/03/01 22:38:31 joerg Exp $"); +__RCSID("$NetBSD: server.c,v 1.12 2021/08/08 20:54:49 nia Exp $"); #include <sys/select.h> #include <sys/stat.h> @@ -165,7 +165,7 @@ server_open_control(server_t *srv, char } opt = 1; - if (setsockopt(fd, 0, LOCAL_CREDS, &opt, sizeof(opt)) == -1) + if (setsockopt(fd, SOL_LOCAL, LOCAL_CREDS, &opt, sizeof(opt)) == -1) log_crit("Warning: No credential checks on control socket"); memset(&un, 0, sizeof(un));