Add SOCK_SEQPACKET to PL_LOCAL sockets. Based on patch from Jesse Off,

submitted 8 years ago:
http://mail-index.netbsd.org/tech-kern/2003/04/14/0006.html
This commit is contained in:
manu 2011-05-29 03:32:46 +00:00
parent 662aaad8a2
commit d1c4787eb6
3 changed files with 64 additions and 14 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: uipc_domain.c,v 1.85 2009/10/03 20:24:39 elad Exp $ */
/* $NetBSD: uipc_domain.c,v 1.86 2011/05/29 03:32:46 manu Exp $ */
/*
* Copyright (c) 1982, 1986, 1993
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_domain.c,v 1.85 2009/10/03 20:24:39 elad Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_domain.c,v 1.86 2011/05/29 03:32:46 manu Exp $");
#include <sys/param.h>
#include <sys/socket.h>
@ -516,6 +516,12 @@ sysctl_net_setup(void)
SYSCTL_DESCR("SOCK_STREAM settings"),
NULL, 0, NULL, 0,
CTL_NET, PF_LOCAL, SOCK_STREAM, CTL_EOL);
sysctl_createv(&domain_sysctllog, 0, NULL, NULL,
CTLFLAG_PERMANENT,
CTLTYPE_NODE, "seqpacket",
SYSCTL_DESCR("SOCK_SEQPACKET settings"),
NULL, 0, NULL, 0,
CTL_NET, PF_LOCAL, SOCK_SEQPACKET, CTL_EOL);
sysctl_createv(&domain_sysctllog, 0, NULL, NULL,
CTLFLAG_PERMANENT,
CTLTYPE_NODE, "dgram",
@ -529,6 +535,13 @@ sysctl_net_setup(void)
SYSCTL_DESCR("SOCK_STREAM protocol control block list"),
sysctl_unpcblist, 0, NULL, 0,
CTL_NET, PF_LOCAL, SOCK_STREAM, CTL_CREATE, CTL_EOL);
sysctl_createv(&domain_sysctllog, 0, NULL, NULL,
CTLFLAG_PERMANENT,
CTLTYPE_STRUCT, "pcblist",
SYSCTL_DESCR("SOCK_SEQPACKET protocol control "
"block list"),
sysctl_unpcblist, 0, NULL, 0,
CTL_NET, PF_LOCAL, SOCK_SEQPACKET, CTL_CREATE, CTL_EOL);
sysctl_createv(&domain_sysctllog, 0, NULL, NULL,
CTLFLAG_PERMANENT,
CTLTYPE_STRUCT, "pcblist",

View File

@ -1,4 +1,4 @@
/* $NetBSD: uipc_proto.c,v 1.21 2008/04/24 11:38:36 ad Exp $ */
/* $NetBSD: uipc_proto.c,v 1.22 2011/05/29 03:32:46 manu Exp $ */
/*-
* Copyright (c) 1982, 1986, 1993
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_proto.c,v 1.21 2008/04/24 11:38:36 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_proto.c,v 1.22 2011/05/29 03:32:46 manu Exp $");
#include <sys/param.h>
#include <sys/socket.h>
@ -64,6 +64,13 @@ const struct protosw unixsw[] = {
.pr_flags = PR_ATOMIC|PR_ADDR|PR_RIGHTS,
.pr_ctloutput = uipc_ctloutput,
.pr_usrreq = uipc_usrreq,
}, {
.pr_type = SOCK_SEQPACKET,
.pr_domain = &unixdomain,
.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS|PR_LISTEN|
PR_ATOMIC,
.pr_ctloutput = uipc_ctloutput,
.pr_usrreq = uipc_usrreq,
}, {
.pr_input = raw_input,
.pr_ctlinput = raw_ctlinput,

View File

@ -1,4 +1,4 @@
/* $NetBSD: uipc_usrreq.c,v 1.133 2010/11/19 06:44:43 dholland Exp $ */
/* $NetBSD: uipc_usrreq.c,v 1.134 2011/05/29 03:32:46 manu Exp $ */
/*-
* Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc.
@ -96,7 +96,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.133 2010/11/19 06:44:43 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.134 2011/05/29 03:32:46 manu Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -124,7 +124,7 @@ __KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.133 2010/11/19 06:44:43 dholland E
* Unix communications domain.
*
* TODO:
* SEQPACKET, RDM
* RDM
* rethink name space problems
* need a proper out-of-band
*
@ -487,6 +487,7 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
panic("uipc 1");
/*NOTREACHED*/
case SOCK_SEQPACKET: /* FALLTHROUGH */
case SOCK_STREAM:
#define rcv (&so->so_rcv)
#define snd (&so2->so_snd)
@ -567,6 +568,7 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
break;
}
case SOCK_SEQPACKET: /* FALLTHROUGH */
case SOCK_STREAM:
#define rcv (&so2->so_rcv)
#define snd (&so->so_snd)
@ -579,7 +581,7 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
if (unp->unp_conn->unp_flags & UNP_WANTCRED) {
/*
* Credentials are passed only once on
* SOCK_STREAM.
* SOCK_STREAM and SOCK_SEQPACKET.
*/
unp->unp_conn->unp_flags &= ~UNP_WANTCRED;
control = unp_addsockcred(l, control);
@ -592,8 +594,19 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
if (control) {
if (sbappendcontrol(rcv, m, control) != 0)
control = NULL;
} else
sbappend(rcv, m);
} else {
switch(so->so_type) {
case SOCK_SEQPACKET:
sbappendrecord(rcv, m);
break;
case SOCK_STREAM:
sbappend(rcv, m);
break;
default:
panic("uipc_usrreq");
break;
}
}
snd->sb_mbmax -=
rcv->sb_mbcnt - unp->unp_conn->unp_mbcnt;
unp->unp_conn->unp_mbcnt = rcv->sb_mbcnt;
@ -629,10 +642,18 @@ uipc_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
case PRU_SENSE:
((struct stat *) m)->st_blksize = so->so_snd.sb_hiwat;
if (so->so_type == SOCK_STREAM && unp->unp_conn != 0) {
switch (so->so_type) {
case SOCK_SEQPACKET: /* FALLTHROUGH */
case SOCK_STREAM:
if (unp->unp_conn == 0)
break;
so2 = unp->unp_conn->unp_socket;
KASSERT(solocked2(so, so2));
((struct stat *) m)->st_blksize += so2->so_rcv.sb_cc;
break;
default:
break;
}
((struct stat *) m)->st_dev = NODEV;
if (unp->unp_ino == 0)
@ -767,6 +788,7 @@ unp_attach(struct socket *so)
int error;
switch (so->so_type) {
case SOCK_SEQPACKET: /* FALLTHROUGH */
case SOCK_STREAM:
if (so->so_lock == NULL) {
/*
@ -1093,6 +1115,7 @@ unp_connect2(struct socket *so, struct socket *so2, int req)
soisconnected(so);
break;
case SOCK_SEQPACKET: /* FALLTHROUGH */
case SOCK_STREAM:
unp2->unp_conn = unp;
if (req == PRU_CONNECT &&
@ -1150,6 +1173,7 @@ unp_disconnect(struct unpcb *unp)
so->so_state &= ~SS_ISCONNECTED;
break;
case SOCK_SEQPACKET: /* FALLTHROUGH */
case SOCK_STREAM:
KASSERT(solocked2(so, unp2->unp_socket));
soisdisconnected(so);
@ -1171,9 +1195,15 @@ unp_shutdown(struct unpcb *unp)
{
struct socket *so;
if (unp->unp_socket->so_type == SOCK_STREAM && unp->unp_conn &&
(so = unp->unp_conn->unp_socket))
socantrcvmore(so);
switch(unp->unp_socket->so_type) {
case SOCK_SEQPACKET: /* FALLTHROUGH */
case SOCK_STREAM:
if (unp->unp_conn && (so = unp->unp_conn->unp_socket))
socantrcvmore(so);
break;
default:
break;
}
}
bool