Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/sdpd introduce a SOL_LOCAL for unix-domain socket l...



details:   https://anonhg.NetBSD.org/src/rev/20ce62f728b0
branches:  trunk
changeset: 985132:20ce62f728b0
user:      nia <nia%NetBSD.org@localhost>
date:      Sun Aug 08 20:54:48 2021 +0000

description:
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.

diffstat:

 lib/libc/net/getpeereid.c            |   6 +++---
 lib/libc/rpc/svc_vc.c                |   8 ++++----
 lib/libc/sys/getsockopt.2            |   9 +++------
 lib/libperfuse/perfuse.c             |   4 ++--
 regress/sys/kern/unfdpass/unfdpass.c |   4 ++--
 share/man/man4/unix.4                |  10 +++++-----
 sys/kern/uipc_usrreq.c               |   6 +++---
 sys/sys/un.h                         |   3 ++-
 tests/net/net/t_unix.c               |   6 +++---
 usr.sbin/perfused/msg.c              |   4 ++--
 usr.sbin/sdpd/server.c               |   6 +++---
 11 files changed, 32 insertions(+), 34 deletions(-)

diffs (276 lines):

diff -r b3380cb9dab9 -r 20ce62f728b0 lib/libc/net/getpeereid.c
--- a/lib/libc/net/getpeereid.c Sun Aug 08 20:50:12 2021 +0000
+++ b/lib/libc/net/getpeereid.c Sun Aug 08 20:54:48 2021 +0000
@@ -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 @@
        }
 
        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)
diff -r b3380cb9dab9 -r 20ce62f728b0 lib/libc/rpc/svc_vc.c
--- a/lib/libc/rpc/svc_vc.c     Sun Aug 08 20:50:12 2021 +0000
+++ b/lib/libc/rpc/svc_vc.c     Sun Aug 08 20:54:48 2021 +0000
@@ -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 @@
         * 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;
diff -r b3380cb9dab9 -r 20ce62f728b0 lib/libc/sys/getsockopt.2
--- a/lib/libc/sys/getsockopt.2 Sun Aug 08 20:50:12 2021 +0000
+++ b/lib/libc/sys/getsockopt.2 Sun Aug 08 20:54:48 2021 +0000
@@ -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 @@
 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 @@
 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,
diff -r b3380cb9dab9 -r 20ce62f728b0 lib/libperfuse/perfuse.c
--- a/lib/libperfuse/perfuse.c  Sun Aug 08 20:50:12 2021 +0000
+++ b/lib/libperfuse/perfuse.c  Sun Aug 08 20:54:48 2021 +0000
@@ -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 @@
         */
        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]);
diff -r b3380cb9dab9 -r 20ce62f728b0 regress/sys/kern/unfdpass/unfdpass.c
--- a/regress/sys/kern/unfdpass/unfdpass.c      Sun Aug 08 20:50:12 2021 +0000
+++ b/regress/sys/kern/unfdpass/unfdpass.c      Sun Aug 08 20:54:48 2021 +0000
@@ -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 @@
        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)
diff -r b3380cb9dab9 -r 20ce62f728b0 share/man/man4/unix.4
--- a/share/man/man4/unix.4     Sun Aug 08 20:50:12 2021 +0000
+++ b/share/man/man4/unix.4     Sun Aug 08 20:54:48 2021 +0000
@@ -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 @@
 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 :
diff -r b3380cb9dab9 -r 20ce62f728b0 sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c    Sun Aug 08 20:50:12 2021 +0000
+++ b/sys/kern/uipc_usrreq.c    Sun Aug 08 20:54:48 2021 +0000
@@ -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 @@
 
        KASSERT(solocked(so));
 
-       if (sopt->sopt_level != 0) {
+       if (sopt->sopt_level != SOL_LOCAL) {
                error = ENOPROTOOPT;
        } else switch (op) {
 
diff -r b3380cb9dab9 -r 20ce62f728b0 sys/sys/un.h
--- a/sys/sys/un.h      Sun Aug 08 20:50:12 2021 +0000
+++ b/sys/sys/un.h      Sun Aug 08 20:54:48 2021 +0000
@@ -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 @@
  * 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 */
diff -r b3380cb9dab9 -r 20ce62f728b0 tests/net/net/t_unix.c
--- a/tests/net/net/t_unix.c    Sun Aug 08 20:50:12 2021 +0000
+++ b/tests/net/net/t_unix.c    Sun Aug 08 20:54:48 2021 +0000
@@ -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 @@
 # define LOCAL_PEEREID SO_PEERCRED
 # define LEVEL SOL_SOCKET
 #else
-# define LEVEL 0
+# define LEVEL SOL_LOCAL
 #endif
 
 #ifdef LOCAL_PEEREID
diff -r b3380cb9dab9 -r 20ce62f728b0 usr.sbin/perfused/msg.c
--- a/usr.sbin/perfused/msg.c   Sun Aug 08 20:50:12 2021 +0000
+++ b/usr.sbin/perfused/msg.c   Sun Aug 08 20:54:48 2021 +0000
@@ -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 @@
         * 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)
diff -r b3380cb9dab9 -r 20ce62f728b0 usr.sbin/sdpd/server.c
--- a/usr.sbin/sdpd/server.c    Sun Aug 08 20:50:12 2021 +0000
+++ b/usr.sbin/sdpd/server.c    Sun Aug 08 20:54:48 2021 +0000
@@ -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 @@
        }
 
        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));



Home | Main Index | Thread Index | Old Index