1*6214Swnj /* uipc_socket.c 4.34 82/03/15 */ 24786Swnj 34786Swnj #include "../h/param.h" 44829Swnj #include "../h/systm.h" 54786Swnj #include "../h/dir.h" 64786Swnj #include "../h/user.h" 74829Swnj #include "../h/proc.h" 84829Swnj #include "../h/file.h" 94786Swnj #include "../h/inode.h" 104829Swnj #include "../h/buf.h" 114786Swnj #include "../h/mbuf.h" 124829Swnj #include "../h/protosw.h" 134829Swnj #include "../h/socket.h" 144829Swnj #include "../h/socketvar.h" 154916Swnj #include "../h/stat.h" 165281Sroot #include "../h/ioctl.h" 175095Swnj #include "../net/in.h" 185095Swnj #include "../net/in_systm.h" 194786Swnj 204786Swnj /* 214890Swnj * Socket support routines. 224890Swnj * 234890Swnj * DEAL WITH INTERRUPT NOTIFICATION. 244786Swnj */ 254786Swnj 264786Swnj /* 274786Swnj * Create a socket. 284786Swnj */ 294927Swnj socreate(aso, type, asp, asa, options) 304786Swnj struct socket **aso; 314786Swnj int type; 324927Swnj struct sockproto *asp; 334927Swnj struct sockaddr *asa; 344829Swnj int options; 354786Swnj { 364786Swnj register struct protosw *prp; 374786Swnj register struct socket *so; 384786Swnj struct mbuf *m; 394890Swnj int pf, proto, error; 404927Swnj COUNT(SOCREATE); 414786Swnj 424786Swnj /* 434890Swnj * Use process standard protocol/protocol family if none 444890Swnj * specified by address argument. 454786Swnj */ 464927Swnj if (asp == 0) { 474890Swnj pf = PF_INET; /* should be u.u_protof */ 484786Swnj proto = 0; 494786Swnj } else { 504927Swnj pf = asp->sp_family; 514927Swnj proto = asp->sp_protocol; 524786Swnj } 534786Swnj 544786Swnj /* 554890Swnj * If protocol specified, look for it, otherwise 564890Swnj * for a protocol of the correct type in the right family. 574890Swnj */ 584890Swnj if (proto) 594890Swnj prp = pffindproto(pf, proto); 604890Swnj else 614890Swnj prp = pffindtype(pf, type); 624890Swnj if (prp == 0) 634890Swnj return (EPROTONOSUPPORT); 644890Swnj 654890Swnj /* 664786Swnj * Get a socket structure. 674786Swnj */ 684890Swnj m = m_getclr(M_WAIT); 694786Swnj if (m == 0) 704786Swnj return (ENOBUFS); 714786Swnj so = mtod(m, struct socket *); 724829Swnj so->so_options = options; 73*6214Swnj so->so_state = 0; 74*6214Swnj if (u.u_uid == 0) 75*6214Swnj so->so_state = SS_PRIV; 764786Swnj 774786Swnj /* 784890Swnj * Attach protocol to socket, initializing 794890Swnj * and reserving resources. 804786Swnj */ 814786Swnj so->so_proto = prp; 824979Swnj error = (*prp->pr_usrreq)(so, PRU_ATTACH, 0, asa); 834979Swnj if (error) { 844971Swnj (void) m_free(dtom(so)); 854890Swnj return (error); 864786Swnj } 874786Swnj *aso = so; 884786Swnj return (0); 894786Swnj } 904786Swnj 914916Swnj sofree(so) 924916Swnj struct socket *so; 934916Swnj { 944916Swnj 954927Swnj COUNT(SOFREE); 964950Swnj if (so->so_pcb || (so->so_state & SS_USERGONE) == 0) 974950Swnj return; 984950Swnj sbrelease(&so->so_snd); 994950Swnj sbrelease(&so->so_rcv); 1004971Swnj (void) m_free(dtom(so)); 1014916Swnj } 1024916Swnj 1034786Swnj /* 1044890Swnj * Close a socket on last file table reference removal. 1054890Swnj * Initiate disconnect if connected. 1064890Swnj * Free socket when disconnect complete. 1075580Sroot * 1085580Sroot * THIS IS REALLY A UNIX INTERFACE ROUTINE 1094829Swnj */ 1105580Sroot soclose(so, exiting) 1114829Swnj register struct socket *so; 1125580Sroot int exiting; 1134829Swnj { 1144890Swnj int s = splnet(); /* conservative */ 1154829Swnj 1164927Swnj COUNT(SOCLOSE); 1174890Swnj if (so->so_pcb == 0) 1184890Swnj goto discard; 1194890Swnj if (so->so_state & SS_ISCONNECTED) { 1204890Swnj if ((so->so_state & SS_ISDISCONNECTING) == 0) { 1214927Swnj u.u_error = sodisconnect(so, (struct sockaddr *)0); 1224890Swnj if (u.u_error) { 1235580Sroot if (exiting) 1245580Sroot goto drop; 1254890Swnj splx(s); 1264890Swnj return; 1274890Swnj } 1284890Swnj } 1295388Sroot if ((so->so_options & SO_DONTLINGER) == 0) { 1305281Sroot if ((so->so_state & SS_ISDISCONNECTING) && 131*6214Swnj (so->so_state & SS_NBIO) && 1325580Sroot exiting == 0) { 1335281Sroot u.u_error = EINPROGRESS; 1345281Sroot splx(s); 1355281Sroot return; 1365281Sroot } 1375580Sroot /* should use tsleep here, for at most linger */ 1385281Sroot while (so->so_state & SS_ISCONNECTED) 1395281Sroot sleep((caddr_t)&so->so_timeo, PZERO+1); 1404890Swnj } 1414890Swnj } 1425580Sroot drop: 1434890Swnj u.u_error = (*so->so_proto->pr_usrreq)(so, PRU_DETACH, 0, 0); 1444890Swnj discard: 1454950Swnj so->so_state |= SS_USERGONE; 1464950Swnj sofree(so); 1474890Swnj splx(s); 1484829Swnj } 1494829Swnj 1504927Swnj sosplice(pso, so) 1514927Swnj struct socket *pso, *so; 1524927Swnj { 1534927Swnj 1544927Swnj COUNT(SOSPLICE); 1555168Swnj if (pso->so_proto->pr_family != PF_UNIX) { 1564927Swnj struct socket *tso; 1574927Swnj tso = pso; pso = so; so = tso; 1584927Swnj } 1595168Swnj if (pso->so_proto->pr_family != PF_UNIX) 1604927Swnj return (EOPNOTSUPP); 1614927Swnj /* check types and buffer space */ 1624927Swnj /* merge buffers */ 1634927Swnj return (0); 1644927Swnj } 1654927Swnj 1664916Swnj /*ARGSUSED*/ 1674890Swnj sostat(so, sb) 1684829Swnj struct socket *so; 1694890Swnj struct stat *sb; 1704829Swnj { 1714829Swnj 1724927Swnj COUNT(SOSTAT); 1735303Sroot bzero((caddr_t)sb, sizeof (*sb)); /* XXX */ 1745303Sroot return (0); /* XXX */ 1754829Swnj } 1764829Swnj 1774829Swnj /* 1784927Swnj * Accept connection on a socket. 1794927Swnj */ 1804927Swnj soaccept(so, asa) 1814927Swnj struct socket *so; 1824927Swnj struct sockaddr *asa; 1834927Swnj { 1844927Swnj int s = splnet(); 1854927Swnj int error; 1864927Swnj 1874927Swnj COUNT(SOACCEPT); 1884927Swnj if ((so->so_options & SO_ACCEPTCONN) == 0) { 1894927Swnj error = EINVAL; /* XXX */ 1904927Swnj goto bad; 1914927Swnj } 1925265Swnj if ((so->so_state & SS_CONNAWAITING) == 0) { 1935265Swnj error = ENOTCONN; 1945265Swnj goto bad; 1955265Swnj } 1965265Swnj so->so_state &= ~SS_CONNAWAITING; 1974927Swnj error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, 0, (caddr_t)asa); 1984927Swnj bad: 1994927Swnj splx(s); 2004927Swnj return (error); 2014927Swnj } 2024927Swnj 2034927Swnj /* 2044890Swnj * Connect socket to a specified address. 2054890Swnj * If already connected or connecting, then avoid 2064890Swnj * the protocol entry, to keep its job simpler. 2074786Swnj */ 2084927Swnj soconnect(so, asa) 2094786Swnj struct socket *so; 2104927Swnj struct sockaddr *asa; 2114786Swnj { 2124890Swnj int s = splnet(); 2134890Swnj int error; 2144786Swnj 2154927Swnj COUNT(SOCONNECT); 2164890Swnj if (so->so_state & (SS_ISCONNECTED|SS_ISCONNECTING)) { 2174890Swnj error = EISCONN; 2184890Swnj goto bad; 2194890Swnj } 2204927Swnj error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT, 0, (caddr_t)asa); 2214890Swnj bad: 2224890Swnj splx(s); 2234890Swnj return (error); 2244786Swnj } 2254786Swnj 2264786Swnj /* 2274890Swnj * Disconnect from a socket. 2284890Swnj * Address parameter is from system call for later multicast 2294890Swnj * protocols. Check to make sure that connected and no disconnect 2304890Swnj * in progress (for protocol's sake), and then invoke protocol. 2314786Swnj */ 2324927Swnj sodisconnect(so, asa) 2334786Swnj struct socket *so; 2344927Swnj struct sockaddr *asa; 2354786Swnj { 2364890Swnj int s = splnet(); 2374890Swnj int error; 2384786Swnj 2394927Swnj COUNT(SODISCONNECT); 2404890Swnj if ((so->so_state & SS_ISCONNECTED) == 0) { 2414890Swnj error = ENOTCONN; 2424890Swnj goto bad; 2434890Swnj } 2444890Swnj if (so->so_state & SS_ISDISCONNECTING) { 2454890Swnj error = EALREADY; 2464890Swnj goto bad; 2474890Swnj } 2484927Swnj error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT, 0, asa); 2494890Swnj bad: 2504890Swnj splx(s); 2514890Swnj return (error); 2524786Swnj } 2534786Swnj 2544786Swnj /* 2554890Swnj * Send on a socket. 2564890Swnj * If send must go all at once and message is larger than 2574890Swnj * send buffering, then hard error. 2584890Swnj * Lock against other senders. 2594890Swnj * If must go all at once and not enough room now, then 2604890Swnj * inform user that this would block and do nothing. 2614786Swnj */ 2624927Swnj sosend(so, asa) 2634786Swnj register struct socket *so; 2644927Swnj struct sockaddr *asa; 2654786Swnj { 2664890Swnj struct mbuf *top = 0; 2674890Swnj register struct mbuf *m, **mp = ⊤ 2684916Swnj register u_int len; 2694916Swnj int error = 0, space, s; 2704786Swnj 2714927Swnj COUNT(SOSEND); 2725950Swnj if (so->so_state & SS_CANTSENDMORE) { 2735950Swnj psignal(u.u_procp, SIGPIPE); 2744890Swnj return (EPIPE); 2755950Swnj } 2764890Swnj if (sosendallatonce(so) && u.u_count > so->so_snd.sb_hiwat) 2774890Swnj return (EMSGSIZE); 278*6214Swnj if ((so->so_snd.sb_flags & SB_LOCK) && (so->so_state & SS_NBIO)) 2794890Swnj return (EWOULDBLOCK); 2804890Swnj sblock(&so->so_snd); 2814890Swnj #define snderr(errno) { error = errno; splx(s); goto release; } 2824890Swnj 2834890Swnj s = splnet(); 2844890Swnj again: 2855168Swnj if (so->so_error) { 2865168Swnj error = so->so_error; 2875168Swnj so->so_error = 0; 2885168Swnj splx(s); 2895168Swnj goto release; 2905168Swnj } 2914890Swnj if ((so->so_state & SS_ISCONNECTED) == 0) { 2924890Swnj if (so->so_proto->pr_flags & PR_CONNREQUIRED) 2934890Swnj snderr(ENOTCONN); 2944927Swnj if (asa == 0) 2954890Swnj snderr(EDESTADDRREQ); 2964890Swnj } 2974890Swnj if (top) { 2984927Swnj error = (*so->so_proto->pr_usrreq)(so, PRU_SEND, top, asa); 2994890Swnj if (error) { 3004890Swnj splx(s); 3014786Swnj goto release; 3024786Swnj } 3034890Swnj top = 0; 3044890Swnj mp = ⊤ 3054786Swnj } 3064979Swnj if (u.u_count == 0) { 3074979Swnj splx(s); 3084979Swnj goto release; 3094979Swnj } 3105018Swnj space = sbspace(&so->so_snd); 3115610Swnj if (space <= 0 || sosendallatonce(so) && space < u.u_count) { 312*6214Swnj if (so->so_state & SS_NBIO) 3134890Swnj snderr(EWOULDBLOCK); 3144890Swnj sbunlock(&so->so_snd); 3154890Swnj sbwait(&so->so_snd); 3164890Swnj splx(s); 3174786Swnj goto again; 3184786Swnj } 3194890Swnj splx(s); 3205018Swnj while (u.u_count && space > 0) { 3214890Swnj MGET(m, 1); 3224890Swnj if (m == NULL) { 3234890Swnj error = ENOBUFS; 3244890Swnj m_freem(top); 3254890Swnj goto release; 3264786Swnj } 3275095Swnj if (u.u_count >= CLBYTES && space >= CLBYTES) { 3284890Swnj register struct mbuf *p; 3295095Swnj MCLGET(p, 1); 3304890Swnj if (p == 0) 3314890Swnj goto nopages; 3324890Swnj m->m_off = (int)p - (int)m; 3335095Swnj len = CLBYTES; 3344890Swnj } else { 3354786Swnj nopages: 3364890Swnj m->m_off = MMINOFF; 3374890Swnj len = MIN(MLEN, u.u_count); 3384786Swnj } 3394890Swnj iomove(mtod(m, caddr_t), len, B_WRITE); 3404890Swnj m->m_len = len; 3414890Swnj *mp = m; 3424890Swnj mp = &m->m_next; 3435018Swnj space = sbspace(&so->so_snd); 3444786Swnj } 3454890Swnj s = splnet(); 3464890Swnj goto again; 3474890Swnj 3484786Swnj release: 3494890Swnj sbunlock(&so->so_snd); 3504786Swnj return (error); 3514786Swnj } 3524786Swnj 3534927Swnj soreceive(so, asa) 3544786Swnj register struct socket *so; 3554927Swnj struct sockaddr *asa; 3564786Swnj { 3574786Swnj register struct mbuf *m, *n; 3584916Swnj u_int len; 3595423Swnj int eor, s, error = 0, cnt = u.u_count; 3605423Swnj caddr_t base = u.u_base; 3614786Swnj 3624927Swnj COUNT(SORECEIVE); 3634890Swnj restart: 3644890Swnj sblock(&so->so_rcv); 3654890Swnj s = splnet(); 3664890Swnj 3674890Swnj #define rcverr(errno) { error = errno; splx(s); goto release; } 3684786Swnj if (so->so_rcv.sb_cc == 0) { 3695168Swnj if (so->so_error) { 3705168Swnj error = so->so_error; 3715168Swnj so->so_error = 0; 3725168Swnj splx(s); 3735168Swnj goto release; 3745168Swnj } 3754890Swnj if (so->so_state & SS_CANTRCVMORE) { 3764890Swnj splx(s); 3774890Swnj goto release; 3784890Swnj } 3795015Sroot if ((so->so_state & SS_ISCONNECTED) == 0 && 3805015Sroot (so->so_proto->pr_flags & PR_CONNREQUIRED)) 3815015Sroot rcverr(ENOTCONN); 382*6214Swnj if (so->so_state & SS_NBIO) 3835168Swnj rcverr(EWOULDBLOCK); 3844890Swnj sbunlock(&so->so_rcv); 3854971Swnj sbwait(&so->so_rcv); 3865012Swnj splx(s); 3874890Swnj goto restart; 3884786Swnj } 3894829Swnj m = so->so_rcv.sb_mb; 3904786Swnj if (m == 0) 3914786Swnj panic("receive"); 3925039Swnj if (so->so_proto->pr_flags & PR_ADDR) { 3935039Swnj if (m->m_len != sizeof (struct sockaddr)) 3945039Swnj panic("soreceive addr"); 3955039Swnj if (asa) 3965039Swnj bcopy(mtod(m, caddr_t), (caddr_t)asa, sizeof (*asa)); 3975039Swnj so->so_rcv.sb_cc -= m->m_len; 3985039Swnj so->so_rcv.sb_mbcnt -= MSIZE; 3995018Swnj m = m_free(m); 4004890Swnj if (m == 0) 4014890Swnj panic("receive 2"); 4025018Swnj so->so_rcv.sb_mb = m; 4034890Swnj } 4045423Swnj so->so_state &= ~SS_RCVATMARK; 4055423Swnj if (so->so_oobmark && cnt > so->so_oobmark) 4065423Swnj cnt = so->so_oobmark; 4074786Swnj eor = 0; 4084786Swnj do { 4095423Swnj len = MIN(m->m_len, cnt); 4104786Swnj splx(s); 4114786Swnj iomove(mtod(m, caddr_t), len, B_READ); 4125423Swnj cnt -= len; 4134786Swnj s = splnet(); 4144786Swnj if (len == m->m_len) { 4156091Sroot eor = (int)m->m_act; 4166091Sroot sbfree(&so->so_rcv, m); 4176091Sroot so->so_rcv.sb_mb = m->m_next; 4184786Swnj MFREE(m, n); 4194786Swnj } else { 4204786Swnj m->m_off += len; 4214786Swnj m->m_len -= len; 4224829Swnj so->so_rcv.sb_cc -= len; 4234786Swnj } 4245423Swnj } while ((m = so->so_rcv.sb_mb) && cnt && !eor); 4254786Swnj if ((so->so_proto->pr_flags & PR_ATOMIC) && eor == 0) 4264786Swnj do { 4274786Swnj if (m == 0) 4284890Swnj panic("receive 3"); 4294890Swnj sbfree(&so->so_rcv, m); 4304786Swnj eor = (int)m->m_act; 4314786Swnj so->so_rcv.sb_mb = m->m_next; 4324786Swnj MFREE(m, n); 4334890Swnj m = n; 4344786Swnj } while (eor == 0); 4354890Swnj if ((so->so_proto->pr_flags & PR_WANTRCVD) && so->so_pcb) 4364890Swnj (*so->so_proto->pr_usrreq)(so, PRU_RCVD, 0, 0); 4375423Swnj if (so->so_oobmark) { 4385423Swnj so->so_oobmark -= u.u_base - base; 4395423Swnj if (so->so_oobmark == 0) 4405423Swnj so->so_state |= SS_RCVATMARK; 4415423Swnj } 4424890Swnj release: 4434916Swnj sbunlock(&so->so_rcv); 4444890Swnj splx(s); 4454916Swnj return (error); 4464786Swnj } 4474786Swnj 4485423Swnj sohasoutofband(so) 4495423Swnj struct socket *so; 4505423Swnj { 4515423Swnj 4525423Swnj if (so->so_pgrp == 0) 4535423Swnj return; 4545423Swnj if (so->so_pgrp > 0) 4555423Swnj gsignal(so->so_pgrp, SIGURG); 4565429Swnj else { 4575429Swnj struct proc *p = pfind(-so->so_pgrp); 4585429Swnj 4595429Swnj if (p) 4605429Swnj psignal(p, SIGURG); 4615429Swnj } 4625423Swnj } 4635423Swnj 4644916Swnj /*ARGSUSED*/ 4654916Swnj soioctl(so, cmd, cmdp) 4664829Swnj register struct socket *so; 4674829Swnj int cmd; 4684829Swnj register caddr_t cmdp; 4694786Swnj { 4704786Swnj 4714927Swnj COUNT(SOIOCTL); 4725358Sroot switch (cmd) { 4734829Swnj 4745388Sroot case FIONBIO: { 4755388Sroot int nbio; 4765388Sroot if (copyin(cmdp, (caddr_t)&nbio, sizeof (nbio))) { 4775388Sroot u.u_error = EFAULT; 4785388Sroot return; 4795388Sroot } 4805388Sroot if (nbio) 481*6214Swnj so->so_state |= SS_NBIO; 4825388Sroot else 483*6214Swnj so->so_state &= ~SS_NBIO; 4845388Sroot return; 4855388Sroot } 4865388Sroot 4875388Sroot case FIOASYNC: { 4885388Sroot int async; 4895388Sroot if (copyin(cmdp, (caddr_t)&async, sizeof (async))) { 4905388Sroot u.u_error = EFAULT; 4915388Sroot return; 4925388Sroot } 4935388Sroot if (async) 494*6214Swnj so->so_state |= SS_ASYNC; 4955388Sroot else 496*6214Swnj so->so_state &= ~SS_ASYNC; 4975388Sroot return; 4985388Sroot } 4995388Sroot 5005388Sroot case SIOCSKEEP: { 5015388Sroot int keep; 5025388Sroot if (copyin(cmdp, (caddr_t)&keep, sizeof (keep))) { 5035388Sroot u.u_error = EFAULT; 5045388Sroot return; 5055388Sroot } 5065388Sroot if (keep) 507*6214Swnj so->so_options &= ~SO_KEEPALIVE; 5085388Sroot else 509*6214Swnj so->so_options |= SO_KEEPALIVE; 5105388Sroot return; 5115388Sroot } 5125388Sroot 5135388Sroot case SIOCGKEEP: { 514*6214Swnj int keep = (so->so_options & SO_KEEPALIVE) != 0; 5155388Sroot if (copyout((caddr_t)&keep, cmdp, sizeof (keep))) 5165388Sroot u.u_error = EFAULT; 5175388Sroot return; 5185388Sroot } 5195388Sroot 5205388Sroot case SIOCSLINGER: { 5215388Sroot int linger; 5225388Sroot if (copyin(cmdp, (caddr_t)&linger, sizeof (linger))) { 5235388Sroot u.u_error = EFAULT; 5245388Sroot return; 5255388Sroot } 5265388Sroot so->so_linger = linger; 5275388Sroot if (so->so_linger) 5285388Sroot so->so_options &= ~SO_DONTLINGER; 5295388Sroot else 5305388Sroot so->so_options |= SO_DONTLINGER; 5315388Sroot return; 5325388Sroot } 5335388Sroot 5345388Sroot case SIOCGLINGER: { 5355388Sroot int linger = so->so_linger; 5365388Sroot if (copyout((caddr_t)&linger, cmdp, sizeof (linger))) { 5375388Sroot u.u_error = EFAULT; 5385388Sroot return; 5395388Sroot } 5405388Sroot } 5415423Swnj case SIOCSPGRP: { 5425423Swnj int pgrp; 5435423Swnj if (copyin(cmdp, (caddr_t)&pgrp, sizeof (pgrp))) { 5445423Swnj u.u_error = EFAULT; 5455423Swnj return; 5465423Swnj } 5475423Swnj so->so_pgrp = pgrp; 5485423Swnj return; 5495423Swnj } 5505388Sroot 5515423Swnj case SIOCGPGRP: { 5525423Swnj int pgrp = so->so_pgrp; 5535423Swnj if (copyout((caddr_t)&pgrp, cmdp, sizeof (pgrp))) { 5545423Swnj u.u_error = EFAULT; 5555423Swnj return; 5565423Swnj } 5575423Swnj } 5585423Swnj 5595281Sroot case SIOCDONE: { 5605281Sroot int flags; 5615281Sroot if (copyin(cmdp, (caddr_t)&flags, sizeof (flags))) { 5625281Sroot u.u_error = EFAULT; 5635281Sroot return; 5645281Sroot } 5655388Sroot flags++; 5665281Sroot if (flags & FREAD) { 5675281Sroot int s = splimp(); 5685281Sroot socantrcvmore(so); 5695281Sroot sbflush(&so->so_rcv); 5706140Ssam splx(s); 5715281Sroot } 5725281Sroot if (flags & FWRITE) 5735404Swnj u.u_error = (*so->so_proto->pr_usrreq)(so, PRU_SHUTDOWN, (struct mbuf *)0, 0); 5745281Sroot return; 5754829Swnj } 5765281Sroot 5775423Swnj case SIOCSENDOOB: { 5785423Swnj char oob; 5795423Swnj struct mbuf *m; 5805423Swnj if (copyin(cmdp, (caddr_t)&oob, sizeof (oob))) { 5815423Swnj u.u_error = EFAULT; 5825423Swnj return; 5835423Swnj } 5845423Swnj m = m_get(M_DONTWAIT); 5855423Swnj if (m == 0) { 5865423Swnj u.u_error = ENOBUFS; 5875423Swnj return; 5885423Swnj } 5895423Swnj m->m_off = MMINOFF; 5905423Swnj m->m_len = 1; 5915423Swnj *mtod(m, caddr_t) = oob; 5925423Swnj (*so->so_proto->pr_usrreq)(so, PRU_SENDOOB, m, 0); 5935423Swnj return; 5945281Sroot } 5955423Swnj 5965423Swnj case SIOCRCVOOB: { 5975423Swnj struct mbuf *m = m_get(M_DONTWAIT); 5985423Swnj if (m == 0) { 5995423Swnj u.u_error = ENOBUFS; 6005423Swnj return; 6015423Swnj } 6025423Swnj m->m_off = MMINOFF; *mtod(m, caddr_t) = 0; 6035423Swnj (*so->so_proto->pr_usrreq)(so, PRU_RCVOOB, m, 0); 6045423Swnj if (copyout(mtod(m, caddr_t), cmdp, sizeof (char))) { 6055423Swnj u.u_error = EFAULT; 6065423Swnj return; 6075423Swnj } 6085423Swnj m_free(m); 6095423Swnj return; 6105423Swnj } 6115423Swnj 6125423Swnj case SIOCATMARK: { 6135423Swnj int atmark = (so->so_state&SS_RCVATMARK) != 0; 6145423Swnj if (copyout((caddr_t)&atmark, cmdp, sizeof (atmark))) { 6155423Swnj u.u_error = EFAULT; 6165423Swnj return; 6175423Swnj } 6185423Swnj return; 6195423Swnj } 6205445Swnj /* type/protocol specific ioctls */ 6215423Swnj } 6225445Swnj u.u_error = EOPNOTSUPP; 6234786Swnj } 624