Re: Level for Unix-domain socket options

2021-08-05 Thread Rhialto
On Thu 05 Aug 2021 at 13:22:55 +, nia wrote:
> The unix(4) man page incorrectly states:
> 
> "A UNIX-domain socket supports two socket-level options for use with
> setsockopt(2) and getsockopt(2): [...]"
> 
> In reality, the protocol level when using these socket options
> must be 0, which is a magic number not really documented anywhere
> except the test suite.

and getsockopt(2) says

DESCRIPTION
 getsockopt(), setsockopt() and getsockopt2() manipulate the options
 associated with a socket.  Options may exist at multiple protocol levels;
 they are always present at the uppermost "socket" level.

which I interpret to mean that even if you use SOL_SOCKET for these
options, it should work. Do I read that as intended? I understand from
the above that it is not true for these options. Perhaps it should be
fixed so that the options work for both SOL_LOCAL and SOL_SOCKET level:
compatible with both (at least some) practice and documentation.

-Olaf.
-- 
___ "Buying carbon credits is a bit like a serial killer paying someone else to
\X/  have kids to make his activity cost neutral." -The BOFHfalu.nl@rhialto



signature.asc
Description: PGP signature


Re: Level for Unix-domain socket options

2021-08-05 Thread Mouse
> "A UNIX-domain socket supports two SOL_LOCAL level options for use .."

> shouldn't this be something like "only supports SOL_LOCAL level"?  if
> not, what the "two" part now?

The "two" applies to "options".  "...supports two (multi-word
adjective) options...".

However, if this confused mrg, it probably will confuse plenty of other
people.  Maybe "...supports two options, at level SOL_LOCAL, for..."?

/~\ The ASCII Mouse
\ / Ribbon Campaign
 X  Against HTMLmo...@rodents-montreal.org
/ \ Email!   7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


re: Level for Unix-domain socket options

2021-08-05 Thread matthew green
i like it.

> Index: sys/sys/un.h
> ===
> RCS file: /cvsroot/src/sys/sys/un.h,v
> retrieving revision 1.59
> diff -u -r1.59 un.h
> --- sys/sys/un.h  6 Nov 2020 14:50:13 -   1.59
> +++ sys/sys/un.h  5 Aug 2021 13:19:20 -
> @@ -56,6 +56,7 @@
>   * Socket options for UNIX IPC domain.
>   */
>  #if defined(_NETBSD_SOURCE)
> +#define SOL_LOCAL0   /* options level for get/setsockopt */
>  #define  LOCAL_OCREDS0x0001  /* pass credentials to receiver 
> */
>  #define  LOCAL_CONNWAIT  0x0002  /* connects block until 
> accepted */
>  #define  LOCAL_PEEREID   0x0003  /* get peer identification */

please fix the space/tab issue here.

> Index: share/man/man4/unix.4
> ===
> RCS file: /cvsroot/src/share/man/man4/unix.4,v
> retrieving revision 1.26
> diff -u -r1.26 unix.4
> --- share/man/man4/unix.4   3 Jul 2017 21:30:58 -   1.26
> +++ share/man/man4/unix.4   5 Aug 2021 13:19:16 -
> @@ -173,8 +173,8 @@
>  when the destination socket is closed.
>  .Pp
>  A UNIX-domain socket supports two
> -.Tn socket-level
> -options for use with
> +.Dv SOL_LOCAL
> +level options for use with
>  .Xr setsockopt 2
>  and
>  .Xr getsockopt 2 :

now reads:

"A UNIX-domain socket supports two SOL_LOCAL level options for use .."

shouldn't this be something like "only supports SOL_LOCAL level"?
if not, what the "two" part now?

thanks.


.mrg.


Re: Native timerfd and eventfd

2021-08-05 Thread Mouse
> The code to implement these is quite small, and the APIs are not unreasonabl$

I agree that a descriptor interface to timer facilities is a Good
Thing.  I've been using AF_TIMER sockets for a decade now and they
really are much more convenient than setitimer() for lots of uses.
(Not API-compatible with timerfd; timerfds have read semantics that
don't match sockets well.)

/~\ The ASCII Mouse
\ / Ribbon Campaign
 X  Against HTMLmo...@rodents-montreal.org
/ \ Email!   7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B


Native timerfd and eventfd

2021-08-05 Thread Jason Thorpe
[Cross-posted to tech-userlevel because this is primarily about an API exposed 
to user-space.]

This past winter, I wrote NetBSD native implementations of the Linux timerfd[1] 
and eventfd[2] APIs, mainly to fill out gaps in COMPAT_LINUX.  Of course, I 
wanted to write ATF unit tests for them, so I needed them to be native 
syscalls, too.

The code to implement these is quite small, and the APIs are not unreasonable 
(eventfd is certainly less cumbersome to use for its intended purpose than a 
pair of pipes, and timerfd is a much better interface than EVFILT_TIMER and 
essentially serves as a descriptor-oriented interface to the regular POSIX 
timer support).  Because of this, I think they should be included as native 
syscalls.

If the consensus is that these are reasonable things to add as native syscalls, 
I’ll whip up man pages for them and do that.  Otherwise, I’ll just relegate 
them to COMPAT_LINUX and toss the ATF unit tests (I see no mechanism to run ATF 
unit tests against COMPAT_* syscalls, and I’m not particularly inclined to 
invent one).

[1] https://man7.org/linux/man-pages/man2/timerfd_create.2.html

[2] https://man7.org/linux/man-pages/man2/eventfd.2.html

-- thorpej



Re: Level for Unix-domain socket options

2021-08-05 Thread Jason Thorpe


> On Aug 5, 2021, at 6:22 AM, nia  wrote:
> 
> I think we should:
> 
> (a) introduce SOL_LOCAL to sys/un.h as an alias for 0, as in FreeBSD
> (b) document it
> (c) update all in-tree users of Unix-domain socket options to use
> SOL_LOCAL instead of hardcoding 0
> 

Agreed.  Patch looks good to me.

-- thorpej



Level for Unix-domain socket options

2021-08-05 Thread nia
The unix(4) man page incorrectly states:

"A UNIX-domain socket supports two socket-level options for use with
setsockopt(2) and getsockopt(2): [...]"

In reality, the protocol level when using these socket options
must be 0, which is a magic number not really documented anywhere
except the test suite.

I think we should:

(a) introduce SOL_LOCAL to sys/un.h as an alias for 0, as in FreeBSD
(b) document it
(c) update all in-tree users of Unix-domain socket options to use
SOL_LOCAL instead of hardcoding 0
Index: lib/libc/net/getpeereid.c
===
RCS file: /cvsroot/src/lib/libc/net/getpeereid.c,v
retrieving revision 1.3
diff -u -r1.3 getpeereid.c
--- lib/libc/net/getpeereid.c   16 Feb 2018 19:21:49 -  1.3
+++ lib/libc/net/getpeereid.c   5 Aug 2021 13:19:15 -
@@ -57,7 +57,7 @@
}
 
len = sizeof(cred);
-   if (getsockopt(s, 0, LOCAL_PEEREID, , ) == -1)
+   if (getsockopt(s, SOL_LOCAL, LOCAL_PEEREID, , ) == -1)
return -1;
 
if (euid != NULL)
Index: lib/libc/rpc/svc_vc.c
===
RCS file: /cvsroot/src/lib/libc/rpc/svc_vc.c,v
retrieving revision 1.34
diff -u -r1.34 svc_vc.c
--- lib/libc/rpc/svc_vc.c   10 Nov 2015 20:56:20 -  1.34
+++ lib/libc/rpc/svc_vc.c   5 Aug 2021 13:19:15 -
@@ -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, , (socklen_t)sizeof one)
-   == -1)
+   if (setsockopt(fd, SOL_LOCAL, LOCAL_CREDS, ,
+   (socklen_t)sizeof one) == -1)
goto cleanup_svc_vc_create;
 
xprt->xp_ltaddr.maxlen = xprt->xp_ltaddr.len = sslocal.ss_len;
Index: lib/libperfuse/perfuse.c
===
RCS file: /cvsroot/src/lib/libperfuse/perfuse.c,v
retrieving revision 1.42
diff -u -r1.42 perfuse.c
--- lib/libperfuse/perfuse.c17 Apr 2019 12:30:51 -  1.42
+++ lib/libperfuse/perfuse.c5 Aug 2021 13:19:15 -
@@ -255,7 +255,7 @@
 */
opt = 1;
optlen = sizeof(opt);
-   if (setsockopt(sv[1], 0, LOCAL_CREDS, , optlen) != 0)
+   if (setsockopt(sv[1], SOL_LOCAL, LOCAL_CREDS, , optlen) != 0)
DWARN("%s: setsockopt LOCAL_CREDS failed", __func__);
 
(void)sprintf(fdstr, "%d", sv[1]);
Index: regress/sys/kern/unfdpass/unfdpass.c
===
RCS file: /cvsroot/src/regress/sys/kern/unfdpass/unfdpass.c,v
retrieving revision 1.11
diff -u -r1.11 unfdpass.c
--- regress/sys/kern/unfdpass/unfdpass.c10 Jan 2017 22:37:44 -  
1.11
+++ regress/sys/kern/unfdpass/unfdpass.c5 Aug 2021 13:19:15 -
@@ -168,7 +168,7 @@
sun.sun_len = SUN_LEN();
 
i = 1;
-   if (setsockopt(listensock, 0, LOCAL_CREDS, , sizeof(i)) == -1)
+   if (setsockopt(listensock, SOL_LOCAL, LOCAL_CREDS, , sizeof(i)) == -1)
err(1, "setsockopt");
 
if (bind(listensock, (struct sockaddr *), sizeof(sun)) == -1)
Index: share/man/man4/unix.4
===
RCS file: /cvsroot/src/share/man/man4/unix.4,v
retrieving revision 1.26
diff -u -r1.26 unix.4
--- share/man/man4/unix.4   3 Jul 2017 21:30:58 -   1.26
+++ share/man/man4/unix.4   5 Aug 2021 13:19:16 -
@@ -173,8 +173,8 @@
 when the destination socket is closed.
 .Pp
 A UNIX-domain socket supports two
-.Tn socket-level
-options for use with
+.Dv SOL_LOCAL
+level options for use with
 .Xr setsockopt 2
 and
 .Xr getsockopt 2 :
Index: sys/kern/uipc_usrreq.c
===
RCS file: /cvsroot/src/sys/kern/uipc_usrreq.c,v
retrieving revision 1.200
diff -u -r1.200 uipc_usrreq.c
--- sys/kern/uipc_usrreq.c  6 Nov 2020 14:50:13 -   1.200
+++ sys/kern/uipc_usrreq.c  5 Aug 2021 13:19:20 -
@@ -608,7 +608,7 @@
 
KASSERT(solocked(so));
 
-   if (sopt->sopt_level != 0) {
+   if (sopt->sopt_level != SOL_LOCAL) {
error = ENOPROTOOPT;
} else switch (op) {
 
Index: sys/sys/un.h
===
RCS file: /cvsroot/src/sys/sys/un.h,v
retrieving revision 1.59
diff -u -r1.59 un.h
--- sys/sys/un.h6 Nov 2020 14:50:13 -   1.59
+++ sys/sys/un.h5 Aug 2021 13:19:20 -
@@ -56,6 +56,7 @@
  * Socket options for UNIX IPC domain.
  */
 #if defined(_NETBSD_SOURCE)
+#define SOL_LOCAL  0   /* options level for get/setsockopt */
 #defineLOCAL_OCREDS0x0001  /* pass credentials to receiver 
*/
 #defineLOCAL_CONNWAIT  0x0002  /* connects block until 
accepted */
 #defineLOCAL_PEEREID   0x0003  /* get 

Re: Some changes to autoconfiguration APIs

2021-08-05 Thread Jason Thorpe


> On Aug 4, 2021, at 10:19 PM, David Holland  wrote:
> 
> Seems like a definite improvement as long as .submatch and whatnot are
> typed (and not (void *)).

Yes, they’re typed.

-- thorpej