summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authormycroft <mycroft@NetBSD.org>1994-05-13 06:01:27 +0000
committermycroft <mycroft@NetBSD.org>1994-05-13 06:01:27 +0000
commitd361acde189f4a167b7b6ec02287134e657f4eae (patch)
tree7bf8797a3a2b365a1ec7662c749ee5d882569858 /sys/kern
parent9d020030acb40952b5263c6813b0cd1cf8968258 (diff)
Update to 4.4-Lite networking code, with a few local changes.
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/sys_socket.c3
-rw-r--r--sys/kern/uipc_domain.c44
-rw-r--r--sys/kern/uipc_mbuf.c160
-rw-r--r--sys/kern/uipc_proto.c12
-rw-r--r--sys/kern/uipc_socket.c61
-rw-r--r--sys/kern/uipc_socket2.c3
6 files changed, 225 insertions, 58 deletions
diff --git a/sys/kern/sys_socket.c b/sys/kern/sys_socket.c
index 1cfc7c266f7..634738ba7e9 100644
--- a/sys/kern/sys_socket.c
+++ b/sys/kern/sys_socket.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* from: @(#)sys_socket.c 8.1 (Berkeley) 6/10/93
- * $Id: sys_socket.c,v 1.9 1994/05/11 10:27:22 mycroft Exp $
+ * $Id: sys_socket.c,v 1.10 1994/05/13 06:01:27 mycroft Exp $
*/
#include <sys/param.h>
@@ -43,7 +43,6 @@
#include <sys/socketvar.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
-#include <sys/select.h>
#include <net/if.h>
#include <net/route.h>
diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c
index d96b026a311..0345b84e099 100644
--- a/sys/kern/uipc_domain.c
+++ b/sys/kern/uipc_domain.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 1982, 1986 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,32 +30,31 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)uipc_domain.c 7.9 (Berkeley) 3/4/91
- * $Id: uipc_domain.c,v 1.10 1994/05/07 00:46:28 cgd Exp $
+ * from: @(#)uipc_domain.c 8.2 (Berkeley) 10/18/93
+ * $Id: uipc_domain.c,v 1.11 1994/05/13 06:01:30 mycroft Exp $
*/
-#include <sys/cdefs.h>
#include <sys/param.h>
-#include <sys/systm.h>
#include <sys/socket.h>
#include <sys/protosw.h>
#include <sys/domain.h>
#include <sys/mbuf.h>
#include <sys/time.h>
#include <sys/kernel.h>
+#include <sys/systm.h>
#include <sys/proc.h>
#include <vm/vm.h>
#include <sys/sysctl.h>
+void pffasttimo __P((void *));
+void pfslowtimo __P((void *));
+
#define ADDDOMAIN(x) { \
extern struct domain __CONCAT(x,domain); \
__CONCAT(x,domain.dom_next) = domains; \
domains = &__CONCAT(x,domain); \
}
-void pffasttimo __P((void *));
-void pfslowtimo __P((void *));
-
void
domaininit()
{
@@ -75,16 +74,16 @@ domaininit()
#ifdef ISO
ADDDOMAIN(iso);
#endif
-#ifdef RMP
- ADDDOMAIN(rmp);
-#endif
#ifdef CCITT
ADDDOMAIN(ccitt);
#endif
-#ifdef IMP
+#ifdef notdef /* XXXX */
+#include "imp.h"
+#if NIMP > 0
ADDDOMAIN(imp);
#endif
#endif
+#endif
for (dp = domains; dp; dp = dp->dom_next) {
if (dp->dom_init)
@@ -146,6 +145,7 @@ found:
return (maybe);
}
+int
net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
int *name;
u_int namelen;
@@ -166,6 +166,20 @@ net_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
*/
if (namelen < 3)
return (EISDIR); /* overloaded */
+ family = name[0];
+ protocol = name[1];
+
+ if (family == 0)
+ return (0);
+ for (dp = domains; dp; dp = dp->dom_next)
+ if (dp->dom_family == family)
+ goto found;
+ return (ENOPROTOOPT);
+found:
+ for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
+ if (pr->pr_protocol == protocol && pr->pr_sysctl)
+ return ((*pr->pr_sysctl)(name + 2, namelen - 2,
+ oldp, oldlenp, newp, newlen));
return (ENOPROTOOPT);
}
@@ -180,10 +194,9 @@ pfctlinput(cmd, sa)
for (dp = domains; dp; dp = dp->dom_next)
for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++)
if (pr->pr_ctlinput)
- (*pr->pr_ctlinput)(cmd, sa, (caddr_t) 0);
+ (*pr->pr_ctlinput)(cmd, sa, (caddr_t)0);
}
-/* ARGSUSED */
void
pfslowtimo(arg)
void *arg;
@@ -198,7 +211,6 @@ pfslowtimo(arg)
timeout(pfslowtimo, NULL, hz/2);
}
-/* ARGSUSED */
void
pffasttimo(arg)
void *arg;
diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c
index 0c660b7acc7..2f5aef7c6f0 100644
--- a/sys/kern/uipc_mbuf.c
+++ b/sys/kern/uipc_mbuf.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 1982, 1986, 1988, 1991 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1986, 1988, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,14 +30,15 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)uipc_mbuf.c 7.19 (Berkeley) 4/20/91
- * $Id: uipc_mbuf.c,v 1.8 1994/04/14 21:34:17 deraadt Exp $
+ * from: @(#)uipc_mbuf.c 8.2 (Berkeley) 1/4/94
+ * $Id: uipc_mbuf.c,v 1.9 1994/05/13 06:01:32 mycroft Exp $
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/malloc.h>
+#include <sys/map.h>
#define MBTYPES
#include <sys/mbuf.h>
#include <sys/kernel.h>
@@ -46,7 +47,6 @@
#include <sys/protosw.h>
#include <vm/vm.h>
-#include <vm/vm_kern.h>
extern vm_map_t mb_map;
struct mbuf *mbutl;
@@ -79,11 +79,12 @@ bad:
/* ARGSUSED */
m_clalloc(ncl, nowait)
register int ncl;
+ int nowait;
{
- int npg, mbx;
+ static int logged;
register caddr_t p;
register int i;
- static int logged;
+ int npg;
npg = ncl * CLSIZE;
p = (caddr_t)kmem_malloc(mb_map, ctob(npg), !nowait);
@@ -200,6 +201,7 @@ m_free(m)
return (n);
}
+void
m_freem(m)
register struct mbuf *m;
{
@@ -222,13 +224,13 @@ m_freem(m)
* copy junk along.
*/
struct mbuf *
-m_prepend(m, len, nowait)
+m_prepend(m, len, how)
register struct mbuf *m;
- int len, nowait;
+ int len, how;
{
struct mbuf *mn;
- MGET(mn, nowait, m->m_type);
+ MGET(mn, how, m->m_type);
if (mn == (struct mbuf *)NULL) {
m_freem(m);
return ((struct mbuf *)NULL);
@@ -295,7 +297,7 @@ m_copym(m, off0, len, wait)
n->m_pkthdr.len = len;
copyhdr = 0;
}
- n->m_len = MIN(len, m->m_len - off);
+ n->m_len = min(len, m->m_len - off);
if (m->m_flags & M_EXT) {
n->m_data = m->m_data + off;
mclrefcnt[mtocl(m->m_ext.ext_buf)]++;
@@ -344,7 +346,7 @@ m_copydata(m, off, len, cp)
while (len > 0) {
if (m == 0)
panic("m_copydata");
- count = MIN(m->m_len - off, len);
+ count = min(m->m_len - off, len);
bcopy(mtod(m, caddr_t) + off, cp, count);
len -= count;
cp += count;
@@ -519,3 +521,137 @@ bad:
MPFail++;
return (0);
}
+
+/*
+ * Partition an mbuf chain in two pieces, returning the tail --
+ * all but the first len0 bytes. In case of failure, it returns NULL and
+ * attempts to restore the chain to its original state.
+ */
+struct mbuf *
+m_split(m0, len0, wait)
+ register struct mbuf *m0;
+ int len0, wait;
+{
+ register struct mbuf *m, *n;
+ unsigned len = len0, remain;
+
+ for (m = m0; m && len > m->m_len; m = m->m_next)
+ len -= m->m_len;
+ if (m == 0)
+ return (0);
+ remain = m->m_len - len;
+ if (m0->m_flags & M_PKTHDR) {
+ MGETHDR(n, wait, m0->m_type);
+ if (n == 0)
+ return (0);
+ n->m_pkthdr.rcvif = m0->m_pkthdr.rcvif;
+ n->m_pkthdr.len = m0->m_pkthdr.len - len0;
+ m0->m_pkthdr.len = len0;
+ if (m->m_flags & M_EXT)
+ goto extpacket;
+ if (remain > MHLEN) {
+ /* m can't be the lead packet */
+ MH_ALIGN(n, 0);
+ n->m_next = m_split(m, len, wait);
+ if (n->m_next == 0) {
+ (void) m_free(n);
+ return (0);
+ } else
+ return (n);
+ } else
+ MH_ALIGN(n, remain);
+ } else if (remain == 0) {
+ n = m->m_next;
+ m->m_next = 0;
+ return (n);
+ } else {
+ MGET(n, wait, m->m_type);
+ if (n == 0)
+ return (0);
+ M_ALIGN(n, remain);
+ }
+extpacket:
+ if (m->m_flags & M_EXT) {
+ n->m_flags |= M_EXT;
+ n->m_ext = m->m_ext;
+ mclrefcnt[mtocl(m->m_ext.ext_buf)]++;
+ m->m_ext.ext_size = 0; /* For Accounting XXXXXX danger */
+ n->m_data = m->m_data + len;
+ } else {
+ bcopy(mtod(m, caddr_t) + len, mtod(n, caddr_t), remain);
+ }
+ n->m_len = remain;
+ m->m_len = len;
+ n->m_next = m->m_next;
+ m->m_next = 0;
+ return (n);
+}
+/*
+ * Routine to copy from device local memory into mbufs.
+ */
+struct mbuf *
+m_devget(buf, totlen, off0, ifp, copy)
+ char *buf;
+ int totlen, off0;
+ struct ifnet *ifp;
+ void (*copy)();
+{
+ register struct mbuf *m;
+ struct mbuf *top = 0, **mp = &top;
+ register int off = off0, len;
+ register char *cp;
+ char *epkt;
+
+ cp = buf;
+ epkt = cp + totlen;
+ if (off) {
+ cp += off + 2 * sizeof(u_short);
+ totlen -= 2 * sizeof(u_short);
+ }
+ MGETHDR(m, M_DONTWAIT, MT_DATA);
+ if (m == 0)
+ return (0);
+ m->m_pkthdr.rcvif = ifp;
+ m->m_pkthdr.len = totlen;
+ m->m_len = MHLEN;
+
+ while (totlen > 0) {
+ if (top) {
+ MGET(m, M_DONTWAIT, MT_DATA);
+ if (m == 0) {
+ m_freem(top);
+ return (0);
+ }
+ m->m_len = MLEN;
+ }
+ len = min(totlen, epkt - cp);
+ if (len >= MINCLSIZE) {
+ MCLGET(m, M_DONTWAIT);
+ if (m->m_flags & M_EXT)
+ m->m_len = len = min(len, MCLBYTES);
+ else
+ len = m->m_len;
+ } else {
+ /*
+ * Place initial small packet/header at end of mbuf.
+ */
+ if (len < m->m_len) {
+ if (top == 0 && len + max_linkhdr <= m->m_len)
+ m->m_data += max_linkhdr;
+ m->m_len = len;
+ } else
+ len = m->m_len;
+ }
+ if (copy)
+ copy(cp, mtod(m, caddr_t), (unsigned)len);
+ else
+ bcopy(cp, mtod(m, caddr_t), (unsigned)len);
+ cp += len;
+ *mp = m;
+ mp = &m->m_next;
+ totlen -= len;
+ if (cp == epkt)
+ cp = buf;
+ }
+ return (top);
+}
diff --git a/sys/kern/uipc_proto.c b/sys/kern/uipc_proto.c
index 7fa130d2163..7880710a087 100644
--- a/sys/kern/uipc_proto.c
+++ b/sys/kern/uipc_proto.c
@@ -1,6 +1,6 @@
/*-
- * Copyright (c) 1982, 1986 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,8 +30,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)uipc_proto.c 7.6 (Berkeley) 5/9/91
- * $Id: uipc_proto.c,v 1.3 1993/12/18 04:22:26 mycroft Exp $
+ * from: @(#)uipc_proto.c 8.1 (Berkeley) 6/10/93
+ * $Id: uipc_proto.c,v 1.4 1994/05/13 06:01:34 mycroft Exp $
*/
#include <sys/param.h>
@@ -44,8 +44,8 @@
* Definitions of protocols supported in the UNIX domain.
*/
-int uipc_usrreq();
-int raw_init(),raw_usrreq(),raw_input(),raw_ctlinput();
+int uipc_usrreq(), raw_usrreq();
+void raw_init(), raw_input(), raw_ctlinput();
extern struct domain unixdomain; /* or at least forward */
struct protosw unixsw[] = {
diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c
index 6d1cb5a539f..528a763157d 100644
--- a/sys/kern/uipc_socket.c
+++ b/sys/kern/uipc_socket.c
@@ -1,6 +1,6 @@
/*
- * Copyright (c) 1982, 1986, 1988, 1990 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1982, 1986, 1988, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -30,8 +30,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * from: @(#)uipc_socket.c 7.28 (Berkeley) 5/4/91
- * $Id: uipc_socket.c,v 1.14 1994/05/04 11:24:06 mycroft Exp $
+ * from: @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94
+ * $Id: uipc_socket.c,v 1.15 1994/05/13 06:01:37 mycroft Exp $
*/
#include <sys/param.h>
@@ -71,7 +71,7 @@ socreate(dom, aso, type, proto)
prp = pffindproto(dom, proto, type);
else
prp = pffindtype(dom, type);
- if (!prp || !prp->pr_usrreq)
+ if (prp == 0 || prp->pr_usrreq == 0)
return (EPROTONOSUPPORT);
if (prp->pr_type != type)
return (EPROTOTYPE);
@@ -299,6 +299,7 @@ bad:
return (error);
}
+#define SBLOCKWAIT(f) (((f) & MSG_DONTWAIT) ? M_NOWAIT : M_WAITOK)
/*
* Send on a socket.
* If send must go all at once and message is larger than
@@ -325,7 +326,7 @@ sosend(so, addr, uio, top, control, flags)
struct mbuf *control;
int flags;
{
- struct proc *p = curproc; /* XXX */
+ struct proc *p = curproc; /* XXX */
struct mbuf **mp;
register struct mbuf *m;
register long space, len, resid;
@@ -354,7 +355,7 @@ sosend(so, addr, uio, top, control, flags)
#define snderr(errno) { error = errno; splx(s); goto release; }
restart:
- if (error = sblock(&so->so_snd))
+ if (error = sblock(&so->so_snd, SBLOCKWAIT(flags)))
goto out;
do {
s = splnet();
@@ -408,15 +409,25 @@ restart:
MGET(m, M_WAIT, MT_DATA);
mlen = MLEN;
}
- if (resid >= MINCLSIZE) {
+ if (resid >= MINCLSIZE && space >= MCLBYTES) {
MCLGET(m, M_WAIT);
if ((m->m_flags & M_EXT) == 0)
goto nopages;
mlen = MCLBYTES;
- len = min(min(mlen, resid), space);
+#ifdef MAPPED_MBUFS
+ len = min(MCLBYTES, resid);
+#else
+ if (atomic && top == 0) {
+ len = min(MCLBYTES - max_hdr, resid);
+ m->m_data += max_hdr;
+ } else
+ len = min(MCLBYTES, resid);
+#endif
+ space -= MCLBYTES;
} else {
nopages:
len = min(min(mlen, resid), space);
+ space -= len;
/*
* For datagram protocols, leave room
* for protocol headers in first mbuf.
@@ -424,7 +435,6 @@ nopages:
if (atomic && top == 0 && len < mlen)
MH_ALIGN(m, len);
}
- space -= len;
error = uiomove(mtod(m, caddr_t), (int)len, uio);
resid = uio->uio_resid;
m->m_len = len;
@@ -492,7 +502,6 @@ soreceive(so, paddr, uio, mp0, controlp, flagsp)
struct mbuf **controlp;
int *flagsp;
{
- struct proc *p = curproc; /* XXX */
register struct mbuf *m, **mp;
register int flags, len, error, s, offset;
struct protosw *pr = so->so_proto;
@@ -532,7 +541,7 @@ bad:
(struct mbuf *)0, (struct mbuf *)0);
restart:
- if (error = sblock(&so->so_rcv))
+ if (error = sblock(&so->so_rcv, SBLOCKWAIT(flags)))
return (error);
s = splnet();
@@ -540,14 +549,16 @@ restart:
/*
* If we have less data than requested, block awaiting more
* (subject to any timeout) if:
- * 1. the current count is less than the low water mark, or
+ * 1. the current count is less than the low water mark,
* 2. MSG_WAITALL is set, and it is possible to do the entire
- * receive operation at once if we block (resid <= hiwat).
+ * receive operation at once if we block (resid <= hiwat), or
+ * 3. MSG_DONTWAIT is not set.
* If MSG_WAITALL is set but resid is larger than the receive buffer,
* we have to do the receive in sections, and thus risk returning
* a short count if a timeout or signal occurs after we start.
*/
- while (m == 0 || so->so_rcv.sb_cc < uio->uio_resid &&
+ if (m == 0 || ((flags & MSG_DONTWAIT) == 0 &&
+ so->so_rcv.sb_cc < uio->uio_resid) &&
(so->so_rcv.sb_cc < so->so_rcv.sb_lowat ||
((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) &&
m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0) {
@@ -557,7 +568,7 @@ restart:
#endif
if (so->so_error) {
if (m)
- break;
+ goto dontblock;
error = so->so_error;
if ((flags & MSG_PEEK) == 0)
so->so_error = 0;
@@ -565,7 +576,7 @@ restart:
}
if (so->so_state & SS_CANTRCVMORE) {
if (m)
- break;
+ goto dontblock;
else
goto release;
}
@@ -581,7 +592,7 @@ restart:
}
if (uio->uio_resid == 0)
goto release;
- if (so->so_state & SS_NBIO) {
+ if ((so->so_state & SS_NBIO) || (flags & MSG_DONTWAIT)) {
error = EWOULDBLOCK;
goto release;
}
@@ -593,7 +604,10 @@ restart:
goto restart;
}
dontblock:
- p->p_stats->p_ru.ru_msgrcv++;
+#ifdef notyet /* XXXX */
+ if (uio->uio_procp)
+ uio->uio_procp->p_stats->p_ru.ru_msgrcv++;
+#endif
nextrecord = m->m_nextpkt;
if (pr->pr_flags & PR_ADDR) {
#ifdef DIAGNOSTIC
@@ -806,7 +820,7 @@ sorflush(so)
struct sockbuf asb;
sb->sb_flags |= SB_NOINTR;
- (void) sblock(sb);
+ (void) sblock(sb, M_WAITOK);
s = splimp();
socantrcvmore(so);
sbunlock(sb);
@@ -849,6 +863,7 @@ sosetopt(so, level, optname, m0)
case SO_USELOOPBACK:
case SO_BROADCAST:
case SO_REUSEADDR:
+ case SO_REUSEPORT:
case SO_OOBINLINE:
if (m == NULL || m->m_len < sizeof (int)) {
error = EINVAL;
@@ -922,6 +937,11 @@ sosetopt(so, level, optname, m0)
error = ENOPROTOOPT;
break;
}
+ if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) {
+ (void) ((*so->so_proto->pr_ctloutput)
+ (PRCO_SETOPT, so, level, optname, &m0));
+ m = NULL; /* freed by protocol */
+ }
}
bad:
if (m)
@@ -961,6 +981,7 @@ sogetopt(so, level, optname, mp)
case SO_DEBUG:
case SO_KEEPALIVE:
case SO_REUSEADDR:
+ case SO_REUSEPORT:
case SO_BROADCAST:
case SO_OOBINLINE:
*mtod(m, int *) = so->so_options & optname;
diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c
index f0ecb914058..63ed94c289d 100644
--- a/sys/kern/uipc_socket2.c
+++ b/sys/kern/uipc_socket2.c
@@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* from: @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93
- * $Id: uipc_socket2.c,v 1.7 1994/05/04 11:04:58 mycroft Exp $
+ * $Id: uipc_socket2.c,v 1.8 1994/05/13 06:01:40 mycroft Exp $
*/
#include <sys/param.h>
@@ -40,7 +40,6 @@
#include <sys/file.h>
#include <sys/buf.h>
#include <sys/malloc.h>
-#include <sys/select.h>
#include <sys/mbuf.h>
#include <sys/protosw.h>
#include <sys/socket.h>