Annotation of src/sys/netinet/raw_ip.c, Revision 1.74
1.74 ! itojun 1: /* $NetBSD: raw_ip.c,v 1.73 2003/08/22 21:53:05 itojun Exp $ */
1.43 itojun 2:
3: /*
4: * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5: * All rights reserved.
1.61 itojun 6: *
1.43 itojun 7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. Neither the name of the project nor the names of its contributors
16: * may be used to endorse or promote products derived from this software
17: * without specific prior written permission.
1.61 itojun 18: *
1.43 itojun 19: * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22: * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29: * SUCH DAMAGE.
30: */
1.14 cgd 31:
1.1 cgd 32: /*
1.13 mycroft 33: * Copyright (c) 1982, 1986, 1988, 1993
34: * The Regents of the University of California. All rights reserved.
1.1 cgd 35: *
36: * Redistribution and use in source and binary forms, with or without
37: * modification, are permitted provided that the following conditions
38: * are met:
39: * 1. Redistributions of source code must retain the above copyright
40: * notice, this list of conditions and the following disclaimer.
41: * 2. Redistributions in binary form must reproduce the above copyright
42: * notice, this list of conditions and the following disclaimer in the
43: * documentation and/or other materials provided with the distribution.
1.71 agc 44: * 3. Neither the name of the University nor the names of its contributors
1.1 cgd 45: * may be used to endorse or promote products derived from this software
46: * without specific prior written permission.
47: *
48: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58: * SUCH DAMAGE.
59: *
1.39 thorpej 60: * @(#)raw_ip.c 8.7 (Berkeley) 5/15/95
1.1 cgd 61: */
1.59 lukem 62:
63: #include <sys/cdefs.h>
1.74 ! itojun 64: __KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.73 2003/08/22 21:53:05 itojun Exp $");
1.40 scottr 65:
1.45 thorpej 66: #include "opt_ipsec.h"
1.40 scottr 67: #include "opt_mrouting.h"
1.1 cgd 68:
1.7 mycroft 69: #include <sys/param.h>
70: #include <sys/malloc.h>
71: #include <sys/mbuf.h>
72: #include <sys/socket.h>
73: #include <sys/protosw.h>
74: #include <sys/socketvar.h>
75: #include <sys/errno.h>
1.13 mycroft 76: #include <sys/systm.h>
1.26 mycroft 77: #include <sys/proc.h>
1.1 cgd 78:
1.7 mycroft 79: #include <net/if.h>
80: #include <net/route.h>
1.1 cgd 81:
1.7 mycroft 82: #include <netinet/in.h>
83: #include <netinet/in_systm.h>
84: #include <netinet/ip.h>
85: #include <netinet/ip_var.h>
1.13 mycroft 86: #include <netinet/ip_mroute.h>
1.44 darrenr 87: #include <netinet/ip_icmp.h>
1.7 mycroft 88: #include <netinet/in_pcb.h>
1.24 christos 89: #include <netinet/in_var.h>
90:
91: #include <machine/stdarg.h>
1.13 mycroft 92:
1.43 itojun 93: #ifdef IPSEC
94: #include <netinet6/ipsec.h>
95: #endif /*IPSEC*/
96:
1.72 jonathan 97: #ifdef FAST_IPSEC
98: #include <netipsec/ipsec.h>
99: #endif /* FAST_IPSEC*/
100:
1.20 mycroft 101: struct inpcbtable rawcbtable;
1.30 pk 102:
1.60 itojun 103: int rip_pcbnotify __P((struct inpcbtable *, struct in_addr,
104: struct in_addr, int, int, void (*) __P((struct inpcb *, int))));
1.30 pk 105: int rip_bind __P((struct inpcb *, struct mbuf *));
106: int rip_connect __P((struct inpcb *, struct mbuf *));
107: void rip_disconnect __P((struct inpcb *));
1.13 mycroft 108:
109: /*
110: * Nominal space allocated to a raw ip socket.
111: */
112: #define RIPSNDQ 8192
113: #define RIPRCVQ 8192
1.1 cgd 114:
115: /*
116: * Raw interface to IP protocol.
117: */
1.13 mycroft 118:
119: /*
120: * Initialize raw connection block q.
121: */
122: void
123: rip_init()
124: {
125:
1.33 mycroft 126: in_pcbinit(&rawcbtable, 1, 1);
1.13 mycroft 127: }
128:
1.1 cgd 129: /*
130: * Setup generic address and protocol structures
131: * for raw_input routine, then pass them along with
132: * mbuf chain.
133: */
1.9 mycroft 134: void
1.24 christos 135: #if __STDC__
136: rip_input(struct mbuf *m, ...)
137: #else
138: rip_input(m, va_alist)
1.1 cgd 139: struct mbuf *m;
1.24 christos 140: va_dcl
141: #endif
1.1 cgd 142: {
1.63 simonb 143: int proto;
1.53 augustss 144: struct ip *ip = mtod(m, struct ip *);
145: struct inpcb *inp;
1.36 thorpej 146: struct inpcb *last = 0;
147: struct mbuf *opts = 0;
1.32 mycroft 148: struct sockaddr_in ripsrc;
1.43 itojun 149: va_list ap;
150:
151: va_start(ap, m);
1.64 simonb 152: (void)va_arg(ap, int); /* ignore value, advance ap */
1.43 itojun 153: proto = va_arg(ap, int);
154: va_end(ap);
1.1 cgd 155:
1.32 mycroft 156: ripsrc.sin_family = AF_INET;
157: ripsrc.sin_len = sizeof(struct sockaddr_in);
1.1 cgd 158: ripsrc.sin_addr = ip->ip_src;
1.34 mycroft 159: ripsrc.sin_port = 0;
160: bzero((caddr_t)ripsrc.sin_zero, sizeof(ripsrc.sin_zero));
1.42 thorpej 161:
162: /*
163: * XXX Compatibility: programs using raw IP expect ip_len
1.62 itojun 164: * XXX to have the header length subtracted, and in host order.
165: * XXX ip_off is also expected to be host order.
1.42 thorpej 166: */
1.62 itojun 167: ip->ip_len = ntohs(ip->ip_len) - (ip->ip_hl << 2);
168: NTOHS(ip->ip_off);
1.32 mycroft 169:
1.58 matt 170: CIRCLEQ_FOREACH(inp, &rawcbtable.inpt_queue, inp_queue) {
1.43 itojun 171: if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != proto)
1.13 mycroft 172: continue;
1.32 mycroft 173: if (!in_nullhost(inp->inp_laddr) &&
174: !in_hosteq(inp->inp_laddr, ip->ip_dst))
1.13 mycroft 175: continue;
1.32 mycroft 176: if (!in_nullhost(inp->inp_faddr) &&
177: !in_hosteq(inp->inp_faddr, ip->ip_src))
1.13 mycroft 178: continue;
179: if (last) {
180: struct mbuf *n;
1.55 itojun 181:
1.72 jonathan 182: #if defined(IPSEC) || defined(FAST_IPSEC)
1.55 itojun 183: /* check AH/ESP integrity. */
184: if (ipsec4_in_reject_so(m, last->inp_socket)) {
185: ipsecstat.in_polvio++;
186: /* do not inject data to pcb */
187: } else
188: #endif /*IPSEC*/
1.24 christos 189: if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) {
1.36 thorpej 190: if (last->inp_flags & INP_CONTROLOPTS ||
191: last->inp_socket->so_options & SO_TIMESTAMP)
192: ip_savecontrol(last, &opts, ip, n);
193: if (sbappendaddr(&last->inp_socket->so_rcv,
194: sintosa(&ripsrc), n, opts) == 0) {
1.13 mycroft 195: /* should notify about lost packet */
196: m_freem(n);
1.36 thorpej 197: if (opts)
198: m_freem(opts);
199: } else
200: sorwakeup(last->inp_socket);
1.41 thorpej 201: opts = NULL;
1.13 mycroft 202: }
203: }
1.36 thorpej 204: last = inp;
1.13 mycroft 205: }
1.72 jonathan 206: #if defined(IPSEC) || defined(FAST_IPSEC)
1.55 itojun 207: /* check AH/ESP integrity. */
208: if (last && ipsec4_in_reject_so(m, last->inp_socket)) {
209: m_freem(m);
210: ipsecstat.in_polvio++;
211: ipstat.ips_delivered--;
212: /* do not inject data to pcb */
213: } else
214: #endif /*IPSEC*/
1.13 mycroft 215: if (last) {
1.36 thorpej 216: if (last->inp_flags & INP_CONTROLOPTS ||
217: last->inp_socket->so_options & SO_TIMESTAMP)
218: ip_savecontrol(last, &opts, ip, m);
219: if (sbappendaddr(&last->inp_socket->so_rcv,
220: sintosa(&ripsrc), m, opts) == 0) {
1.13 mycroft 221: m_freem(m);
1.36 thorpej 222: if (opts)
223: m_freem(opts);
224: } else
225: sorwakeup(last->inp_socket);
1.13 mycroft 226: } else {
1.44 darrenr 227: if (inetsw[ip_protox[ip->ip_p]].pr_input == rip_input) {
1.47 itojun 228: icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PROTOCOL,
229: 0, 0);
1.44 darrenr 230: ipstat.ips_noproto++;
231: ipstat.ips_delivered--;
232: } else
233: m_freem(m);
1.1 cgd 234: }
1.43 itojun 235: return;
1.60 itojun 236: }
237:
238: int
239: rip_pcbnotify(table, faddr, laddr, proto, errno, notify)
240: struct inpcbtable *table;
241: struct in_addr faddr, laddr;
242: int proto;
243: int errno;
244: void (*notify) __P((struct inpcb *, int));
245: {
246: struct inpcb *inp, *ninp;
247: int nmatch;
248:
249: nmatch = 0;
250: for (inp = CIRCLEQ_FIRST(&table->inpt_queue);
251: inp != (struct inpcb *)&table->inpt_queue;
252: inp = ninp) {
253: ninp = inp->inp_queue.cqe_next;
254: if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != proto)
255: continue;
256: if (in_hosteq(inp->inp_faddr, faddr) &&
257: in_hosteq(inp->inp_laddr, laddr)) {
258: (*notify)(inp, errno);
259: nmatch++;
260: }
261: }
262:
263: return nmatch;
264: }
265:
266: void *
267: rip_ctlinput(cmd, sa, v)
268: int cmd;
269: struct sockaddr *sa;
270: void *v;
271: {
272: struct ip *ip = v;
273: void (*notify) __P((struct inpcb *, int)) = in_rtchange;
274: int errno;
275:
276: if (sa->sa_family != AF_INET ||
277: sa->sa_len != sizeof(struct sockaddr_in))
278: return NULL;
279: if ((unsigned)cmd >= PRC_NCMDS)
280: return NULL;
281: errno = inetctlerrmap[cmd];
282: if (PRC_IS_REDIRECT(cmd))
283: notify = in_rtchange, ip = 0;
284: else if (cmd == PRC_HOSTDEAD)
285: ip = 0;
286: else if (errno == 0)
287: return NULL;
288: if (ip) {
289: rip_pcbnotify(&rawcbtable, satosin(sa)->sin_addr,
290: ip->ip_src, ip->ip_p, errno, notify);
291:
292: /* XXX mapped address case */
293: } else
294: in_pcbnotifyall(&rawcbtable, satosin(sa)->sin_addr, errno,
295: notify);
296: return NULL;
1.1 cgd 297: }
298:
299: /*
300: * Generate IP header and pass packet to ip_output.
301: * Tack on options user may have setup with control call.
302: */
1.9 mycroft 303: int
1.24 christos 304: #if __STDC__
305: rip_output(struct mbuf *m, ...)
306: #else
307: rip_output(m, va_alist)
308: struct mbuf *m;
309: va_dcl
310: #endif
311: {
1.53 augustss 312: struct inpcb *inp;
313: struct ip *ip;
1.10 mycroft 314: struct mbuf *opts;
1.24 christos 315: int flags;
316: va_list ap;
317:
318: va_start(ap, m);
1.27 mycroft 319: inp = va_arg(ap, struct inpcb *);
1.24 christos 320: va_end(ap);
321:
1.27 mycroft 322: flags =
1.37 matt 323: (inp->inp_socket->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST
324: | IP_RETURNMTU;
1.1 cgd 325:
326: /*
327: * If the user handed us a complete IP packet, use it.
328: * Otherwise, allocate an mbuf for a header and fill it in.
329: */
1.13 mycroft 330: if ((inp->inp_flags & INP_HDRINCL) == 0) {
1.35 thorpej 331: if ((m->m_pkthdr.len + sizeof(struct ip)) > IP_MAXPACKET) {
332: m_freem(m);
333: return (EMSGSIZE);
334: }
1.68 itojun 335: M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);
336: if (!m)
337: return (ENOBUFS);
1.1 cgd 338: ip = mtod(m, struct ip *);
339: ip->ip_tos = 0;
1.62 itojun 340: ip->ip_off = htons(0);
1.13 mycroft 341: ip->ip_p = inp->inp_ip.ip_p;
1.62 itojun 342: ip->ip_len = htons(m->m_pkthdr.len);
1.13 mycroft 343: ip->ip_src = inp->inp_laddr;
1.27 mycroft 344: ip->ip_dst = inp->inp_faddr;
1.1 cgd 345: ip->ip_ttl = MAXTTL;
1.13 mycroft 346: opts = inp->inp_options;
347: } else {
1.35 thorpej 348: if (m->m_pkthdr.len > IP_MAXPACKET) {
349: m_freem(m);
350: return (EMSGSIZE);
351: }
1.13 mycroft 352: ip = mtod(m, struct ip *);
1.65 thorpej 353:
354: /*
355: * If the mbuf is read-only, we need to allocate
356: * a new mbuf for the header, since we need to
357: * modify the header.
358: */
359: if (M_READONLY(m)) {
360: int hlen = ip->ip_hl << 2;
361:
362: m = m_copyup(m, hlen, (max_linkhdr + 3) & ~3);
363: if (m == NULL)
364: return (ENOMEM); /* XXX */
365: ip = mtod(m, struct ip *);
366: }
367:
1.62 itojun 368: /* XXX userland passes ip_len and ip_off in host order */
1.38 mycroft 369: if (m->m_pkthdr.len != ip->ip_len) {
370: m_freem(m);
371: return (EINVAL);
372: }
1.62 itojun 373: HTONS(ip->ip_len);
374: HTONS(ip->ip_off);
1.13 mycroft 375: if (ip->ip_id == 0)
376: ip->ip_id = htons(ip_id++);
377: opts = NULL;
378: /* XXX prevent ip_output from overwriting header fields */
379: flags |= IP_RAWOUTPUT;
380: ipstat.ips_rawout++;
1.1 cgd 381: }
1.62 itojun 382: return (ip_output(m, opts, &inp->inp_route, flags, inp->inp_moptions,
1.73 itojun 383: inp->inp_socket, &inp->inp_errormtu));
1.1 cgd 384: }
385:
386: /*
387: * Raw IP socket option processing.
388: */
1.9 mycroft 389: int
1.1 cgd 390: rip_ctloutput(op, so, level, optname, m)
391: int op;
392: struct socket *so;
393: int level, optname;
394: struct mbuf **m;
395: {
1.53 augustss 396: struct inpcb *inp = sotoinpcb(so);
1.31 mycroft 397: int error = 0;
1.1 cgd 398:
1.15 mycroft 399: if (level != IPPROTO_IP) {
1.31 mycroft 400: error = ENOPROTOOPT;
401: if (op == PRCO_SETOPT && *m != 0)
402: (void) m_free(*m);
403: } else switch (op) {
404:
405: case PRCO_SETOPT:
406: switch (optname) {
407: case IP_HDRINCL:
408: if (*m == 0 || (*m)->m_len < sizeof (int))
409: error = EINVAL;
410: else {
1.13 mycroft 411: if (*mtod(*m, int *))
412: inp->inp_flags |= INP_HDRINCL;
413: else
414: inp->inp_flags &= ~INP_HDRINCL;
415: }
1.31 mycroft 416: if (*m != 0)
417: (void) m_free(*m);
418: break;
419:
420: #ifdef MROUTING
421: case MRT_INIT:
422: case MRT_DONE:
423: case MRT_ADD_VIF:
424: case MRT_DEL_VIF:
425: case MRT_ADD_MFC:
426: case MRT_DEL_MFC:
427: case MRT_ASSERT:
428: error = ip_mrouter_set(so, optname, m);
429: break;
430: #endif
431:
432: default:
433: error = ip_ctloutput(op, so, level, optname, m);
434: break;
1.13 mycroft 435: }
436: break;
1.1 cgd 437:
1.31 mycroft 438: case PRCO_GETOPT:
439: switch (optname) {
440: case IP_HDRINCL:
1.66 thorpej 441: *m = m_get(M_WAIT, MT_SOOPTS);
1.67 matt 442: MCLAIM((*m), so->so_mowner);
1.31 mycroft 443: (*m)->m_len = sizeof (int);
444: *mtod(*m, int *) = inp->inp_flags & INP_HDRINCL ? 1 : 0;
445: break;
446:
1.6 hpeyerl 447: #ifdef MROUTING
1.31 mycroft 448: case MRT_VERSION:
449: case MRT_ASSERT:
450: error = ip_mrouter_get(so, optname, m);
1.18 mycroft 451: break;
1.31 mycroft 452: #endif
453:
1.18 mycroft 454: default:
1.31 mycroft 455: error = ip_ctloutput(op, so, level, optname, m);
1.18 mycroft 456: break;
457: }
1.31 mycroft 458: break;
1.1 cgd 459: }
1.31 mycroft 460: return (error);
1.1 cgd 461: }
462:
1.27 mycroft 463: int
1.29 mycroft 464: rip_bind(inp, nam)
465: struct inpcb *inp;
466: struct mbuf *nam;
467: {
468: struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *);
469:
470: if (nam->m_len != sizeof(*addr))
471: return (EINVAL);
1.58 matt 472: if (TAILQ_FIRST(&ifnet) == 0)
1.29 mycroft 473: return (EADDRNOTAVAIL);
474: if (addr->sin_family != AF_INET &&
475: addr->sin_family != AF_IMPLINK)
476: return (EAFNOSUPPORT);
1.32 mycroft 477: if (!in_nullhost(addr->sin_addr) &&
1.29 mycroft 478: ifa_ifwithaddr(sintosa(addr)) == 0)
479: return (EADDRNOTAVAIL);
480: inp->inp_laddr = addr->sin_addr;
481: return (0);
482: }
483:
484: int
1.27 mycroft 485: rip_connect(inp, nam)
486: struct inpcb *inp;
487: struct mbuf *nam;
488: {
489: struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *);
490:
491: if (nam->m_len != sizeof(*addr))
492: return (EINVAL);
1.58 matt 493: if (TAILQ_FIRST(&ifnet) == 0)
1.27 mycroft 494: return (EADDRNOTAVAIL);
495: if (addr->sin_family != AF_INET &&
496: addr->sin_family != AF_IMPLINK)
497: return (EAFNOSUPPORT);
498: inp->inp_faddr = addr->sin_addr;
499: return (0);
500: }
501:
502: void
503: rip_disconnect(inp)
504: struct inpcb *inp;
505: {
506:
1.32 mycroft 507: inp->inp_faddr = zeroin_addr;
1.27 mycroft 508: }
509:
1.13 mycroft 510: u_long rip_sendspace = RIPSNDQ;
511: u_long rip_recvspace = RIPRCVQ;
512:
1.1 cgd 513: /*ARGSUSED*/
1.9 mycroft 514: int
1.70 fvdl 515: rip_usrreq(so, req, m, nam, control, p)
1.53 augustss 516: struct socket *so;
1.1 cgd 517: int req;
1.2 cgd 518: struct mbuf *m, *nam, *control;
1.70 fvdl 519: struct proc *p;
1.1 cgd 520: {
1.53 augustss 521: struct inpcb *inp;
1.27 mycroft 522: int s;
1.53 augustss 523: int error = 0;
1.13 mycroft 524: #ifdef MROUTING
1.6 hpeyerl 525: extern struct socket *ip_mrouter;
526: #endif
1.27 mycroft 527:
1.22 pk 528: if (req == PRU_CONTROL)
529: return (in_control(so, (long)m, (caddr_t)nam,
1.26 mycroft 530: (struct ifnet *)control, p));
1.49 thorpej 531:
1.50 thorpej 532: if (req == PRU_PURGEIF) {
1.56 itojun 533: in_pcbpurgeif0(&rawcbtable, (struct ifnet *)control);
1.50 thorpej 534: in_purgeif((struct ifnet *)control);
535: in_pcbpurgeif(&rawcbtable, (struct ifnet *)control);
1.49 thorpej 536: return (0);
537: }
1.22 pk 538:
1.27 mycroft 539: s = splsoftnet();
540: inp = sotoinpcb(so);
1.28 mycroft 541: #ifdef DIAGNOSTIC
542: if (req != PRU_SEND && req != PRU_SENDOOB && control)
543: panic("rip_usrreq: unexpected control mbuf");
544: #endif
1.27 mycroft 545: if (inp == 0 && req != PRU_ATTACH) {
1.22 pk 546: error = EINVAL;
547: goto release;
548: }
549:
1.1 cgd 550: switch (req) {
551:
552: case PRU_ATTACH:
1.27 mycroft 553: if (inp != 0) {
554: error = EISCONN;
555: break;
556: }
1.26 mycroft 557: if (p == 0 || (error = suser(p->p_ucred, &p->p_acflag))) {
1.13 mycroft 558: error = EACCES;
559: break;
560: }
1.27 mycroft 561: if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
562: error = soreserve(so, rip_sendspace, rip_recvspace);
563: if (error)
564: break;
565: }
566: error = in_pcballoc(so, &rawcbtable);
567: if (error)
1.13 mycroft 568: break;
1.27 mycroft 569: inp = sotoinpcb(so);
1.17 cgd 570: inp->inp_ip.ip_p = (long)nam;
1.1 cgd 571: break;
572:
573: case PRU_DETACH:
1.13 mycroft 574: #ifdef MROUTING
1.6 hpeyerl 575: if (so == ip_mrouter)
576: ip_mrouter_done();
577: #endif
1.13 mycroft 578: in_pcbdetach(inp);
1.1 cgd 579: break;
580:
581: case PRU_BIND:
1.29 mycroft 582: error = rip_bind(inp, nam);
1.27 mycroft 583: break;
584:
585: case PRU_LISTEN:
586: error = EOPNOTSUPP;
587: break;
588:
589: case PRU_CONNECT:
590: error = rip_connect(inp, nam);
591: if (error)
1.13 mycroft 592: break;
1.1 cgd 593: soisconnected(so);
1.13 mycroft 594: break;
595:
596: case PRU_CONNECT2:
597: error = EOPNOTSUPP;
598: break;
599:
1.27 mycroft 600: case PRU_DISCONNECT:
601: soisdisconnected(so);
602: rip_disconnect(inp);
603: break;
604:
1.13 mycroft 605: /*
606: * Mark the connection as being incapable of further input.
607: */
608: case PRU_SHUTDOWN:
609: socantsendmore(so);
610: break;
611:
1.27 mycroft 612: case PRU_RCVD:
613: error = EOPNOTSUPP;
614: break;
615:
1.13 mycroft 616: /*
617: * Ship a packet out. The appropriate raw output
618: * routine handles any massaging necessary.
619: */
620: case PRU_SEND:
1.28 mycroft 621: if (control && control->m_len) {
622: m_freem(control);
623: m_freem(m);
624: error = EINVAL;
625: break;
626: }
627: {
1.27 mycroft 628: if (nam) {
629: if ((so->so_state & SS_ISCONNECTED) != 0) {
1.13 mycroft 630: error = EISCONN;
1.28 mycroft 631: goto die;
1.13 mycroft 632: }
1.27 mycroft 633: error = rip_connect(inp, nam);
634: if (error) {
1.28 mycroft 635: die:
1.27 mycroft 636: m_freem(m);
637: break;
638: }
1.13 mycroft 639: } else {
1.27 mycroft 640: if ((so->so_state & SS_ISCONNECTED) == 0) {
1.13 mycroft 641: error = ENOTCONN;
1.28 mycroft 642: goto die;
1.13 mycroft 643: }
644: }
1.27 mycroft 645: error = rip_output(m, inp);
646: if (nam)
647: rip_disconnect(inp);
1.28 mycroft 648: }
1.13 mycroft 649: break;
650:
651: case PRU_SENSE:
652: /*
653: * stat: don't bother with a blocksize.
654: */
1.27 mycroft 655: splx(s);
1.1 cgd 656: return (0);
1.13 mycroft 657:
658: case PRU_RCVOOB:
1.27 mycroft 659: error = EOPNOTSUPP;
660: break;
661:
1.13 mycroft 662: case PRU_SENDOOB:
1.28 mycroft 663: m_freem(control);
1.27 mycroft 664: m_freem(m);
1.13 mycroft 665: error = EOPNOTSUPP;
666: break;
667:
668: case PRU_SOCKADDR:
669: in_setsockaddr(inp, nam);
670: break;
671:
672: case PRU_PEERADDR:
673: in_setpeeraddr(inp, nam);
674: break;
675:
676: default:
677: panic("rip_usrreq");
1.1 cgd 678: }
1.27 mycroft 679:
1.22 pk 680: release:
1.27 mycroft 681: splx(s);
1.1 cgd 682: return (error);
683: }
CVSweb <webmaster@jp.NetBSD.org>