LOCAL_CREDS are broken ?

Alfred Perlstein bright at mu.org
Thu Aug 29 21:31:21 UTC 2013


On 8/29/13 11:48 AM, Yuri wrote:
> The example below breaks with "Protocol not available"
> But what is wrong? Isn't this the correct usage?
> LOCAL_CREDS are only handled in kern/uipc_usrreq.c for AF_LOCAL, so it 
> isn't clear why this doesn't work.
>
> Yuri
>
>
>
> --- example.c ---
> #include <sys/types.h>
> #include <sys/socket.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <sys/un.h>
>
> main() {
>   int sock;
>   int error;
>   int oval = 1;
>
>   error = socket(AF_LOCAL, SOCK_SEQPACKET, 0);
>   if (error == -1) {perror("socket"); exit(-1);}
>   sock = error;
>
>   error = setsockopt(sock, SOL_SOCKET, LOCAL_CREDS, &oval, sizeof(oval));
>   if (error) {perror("setsockopt"); exit(-1);}
> }
>

Looks like SOCK_SEQPACKET doesn't support LOCAL_CREDS because its 
protosw doesn't contain the entry for:
         .pr_ctloutput =         &uipc_ctloutput,

Have a look at src/sys/kern/uipc_usrreq.c at around lines 280-332:

> static struct protosw localsw[] = {
> {
>         .pr_type =              SOCK_STREAM,
>         .pr_domain =            &localdomain,
>         .pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS,
>         .pr_ctloutput =         &uipc_ctloutput,
>         .pr_usrreqs =           &uipc_usrreqs_stream
> },
> {
>         .pr_type =              SOCK_DGRAM,
>         .pr_domain =            &localdomain,
>         .pr_flags =             PR_ATOMIC|PR_ADDR|PR_RIGHTS,
>         .pr_ctloutput =         &uipc_ctloutput,
>         .pr_usrreqs =           &uipc_usrreqs_dgram
> },
> {
>         .pr_type =              SOCK_SEQPACKET,
>         .pr_domain =            &localdomain,
>
>         /*
>          * XXXRW: For now, PR_ADDR because soreceive will bump into them
>          * due to our use of sbappendaddr.  A new sbappend variants is 
> needed
>          * that supports both atomic record writes and control data.
>          */
>         .pr_flags = PR_ADDR|PR_ATOMIC|PR_CONNREQUIRED|PR_WANTRCVD|
>                                     PR_RIGHTS,
>         .pr_usrreqs =           &uipc_usrreqs_seqpacket,
> },
> };

I wonder if this is just a bug/missing code!?

-Alfred


> _______________________________________________
> freebsd-net at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-net
> To unsubscribe, send any mail to "freebsd-net-unsubscribe at freebsd.org"
>


-- 
Alfred Perlstein



More information about the freebsd-net mailing list