Annotation of src/sys/netinet/raw_ip.c, Revision 1.70.2.4
1.70.2.4! skrll 1: /* $NetBSD: raw_ip.c,v 1.70.2.2 2004/08/03 10:54:43 skrll 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.70.2.2 skrll 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.70.2.4! skrll 64: __KERNEL_RCSID(0, "$NetBSD: raw_ip.c,v 1.70.2.2 2004/08/03 10:54:43 skrll Exp $");
1.40 scottr 65:
1.70.2.2 skrll 66: #include "opt_inet.h"
1.45 thorpej 67: #include "opt_ipsec.h"
1.40 scottr 68: #include "opt_mrouting.h"
1.1 cgd 69:
1.7 mycroft 70: #include <sys/param.h>
71: #include <sys/malloc.h>
72: #include <sys/mbuf.h>
73: #include <sys/socket.h>
74: #include <sys/protosw.h>
75: #include <sys/socketvar.h>
76: #include <sys/errno.h>
1.13 mycroft 77: #include <sys/systm.h>
1.26 mycroft 78: #include <sys/proc.h>
1.1 cgd 79:
1.7 mycroft 80: #include <net/if.h>
81: #include <net/route.h>
1.1 cgd 82:
1.7 mycroft 83: #include <netinet/in.h>
84: #include <netinet/in_systm.h>
85: #include <netinet/ip.h>
86: #include <netinet/ip_var.h>
1.13 mycroft 87: #include <netinet/ip_mroute.h>
1.44 darrenr 88: #include <netinet/ip_icmp.h>
1.7 mycroft 89: #include <netinet/in_pcb.h>
1.24 christos 90: #include <netinet/in_var.h>
91:
92: #include <machine/stdarg.h>
1.13 mycroft 93:
1.43 itojun 94: #ifdef IPSEC
95: #include <netinet6/ipsec.h>
96: #endif /*IPSEC*/
97:
1.70.2.2 skrll 98: #ifdef FAST_IPSEC
99: #include <netipsec/ipsec.h>
100: #include <netipsec/ipsec_var.h> /* XXX ipsecstat namespace */
101: #endif /* FAST_IPSEC*/
102:
1.20 mycroft 103: struct inpcbtable rawcbtable;
1.30 pk 104:
1.60 itojun 105: int rip_pcbnotify __P((struct inpcbtable *, struct in_addr,
106: struct in_addr, int, int, void (*) __P((struct inpcb *, int))));
1.30 pk 107: int rip_bind __P((struct inpcb *, struct mbuf *));
108: int rip_connect __P((struct inpcb *, struct mbuf *));
109: void rip_disconnect __P((struct inpcb *));
1.13 mycroft 110:
111: /*
112: * Nominal space allocated to a raw ip socket.
113: */
114: #define RIPSNDQ 8192
115: #define RIPRCVQ 8192
1.1 cgd 116:
117: /*
118: * Raw interface to IP protocol.
119: */
1.13 mycroft 120:
121: /*
122: * Initialize raw connection block q.
123: */
124: void
125: rip_init()
126: {
127:
1.33 mycroft 128: in_pcbinit(&rawcbtable, 1, 1);
1.13 mycroft 129: }
130:
1.1 cgd 131: /*
132: * Setup generic address and protocol structures
133: * for raw_input routine, then pass them along with
134: * mbuf chain.
135: */
1.9 mycroft 136: void
1.24 christos 137: rip_input(struct mbuf *m, ...)
1.1 cgd 138: {
1.63 simonb 139: int proto;
1.53 augustss 140: struct ip *ip = mtod(m, struct ip *);
1.70.2.2 skrll 141: struct inpcb_hdr *inph;
1.53 augustss 142: struct inpcb *inp;
1.36 thorpej 143: struct inpcb *last = 0;
144: struct mbuf *opts = 0;
1.32 mycroft 145: struct sockaddr_in ripsrc;
1.43 itojun 146: va_list ap;
147:
148: va_start(ap, m);
1.64 simonb 149: (void)va_arg(ap, int); /* ignore value, advance ap */
1.43 itojun 150: proto = va_arg(ap, int);
151: va_end(ap);
1.1 cgd 152:
1.32 mycroft 153: ripsrc.sin_family = AF_INET;
154: ripsrc.sin_len = sizeof(struct sockaddr_in);
1.1 cgd 155: ripsrc.sin_addr = ip->ip_src;
1.34 mycroft 156: ripsrc.sin_port = 0;
157: bzero((caddr_t)ripsrc.sin_zero, sizeof(ripsrc.sin_zero));
1.42 thorpej 158:
159: /*
160: * XXX Compatibility: programs using raw IP expect ip_len
1.62 itojun 161: * XXX to have the header length subtracted, and in host order.
162: * XXX ip_off is also expected to be host order.
1.42 thorpej 163: */
1.62 itojun 164: ip->ip_len = ntohs(ip->ip_len) - (ip->ip_hl << 2);
165: NTOHS(ip->ip_off);
1.32 mycroft 166:
1.70.2.2 skrll 167: CIRCLEQ_FOREACH(inph, &rawcbtable.inpt_queue, inph_queue) {
168: inp = (struct inpcb *)inph;
169: if (inp->inp_af != AF_INET)
170: continue;
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.70.2.2 skrll 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.70.2.2 skrll 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;
1.70.2.2 skrll 250: for (inp = (struct inpcb *)CIRCLEQ_FIRST(&table->inpt_queue);
1.60 itojun 251: inp != (struct inpcb *)&table->inpt_queue;
252: inp = ninp) {
1.70.2.2 skrll 253: ninp = (struct inpcb *)inp->inp_queue.cqe_next;
254: if (inp->inp_af != AF_INET)
255: continue;
1.60 itojun 256: if (inp->inp_ip.ip_p && inp->inp_ip.ip_p != proto)
257: continue;
258: if (in_hosteq(inp->inp_faddr, faddr) &&
259: in_hosteq(inp->inp_laddr, laddr)) {
260: (*notify)(inp, errno);
261: nmatch++;
262: }
263: }
264:
265: return nmatch;
266: }
267:
268: void *
269: rip_ctlinput(cmd, sa, v)
270: int cmd;
271: struct sockaddr *sa;
272: void *v;
273: {
274: struct ip *ip = v;
275: void (*notify) __P((struct inpcb *, int)) = in_rtchange;
276: int errno;
277:
278: if (sa->sa_family != AF_INET ||
279: sa->sa_len != sizeof(struct sockaddr_in))
280: return NULL;
281: if ((unsigned)cmd >= PRC_NCMDS)
282: return NULL;
283: errno = inetctlerrmap[cmd];
284: if (PRC_IS_REDIRECT(cmd))
285: notify = in_rtchange, ip = 0;
286: else if (cmd == PRC_HOSTDEAD)
287: ip = 0;
288: else if (errno == 0)
289: return NULL;
290: if (ip) {
291: rip_pcbnotify(&rawcbtable, satosin(sa)->sin_addr,
292: ip->ip_src, ip->ip_p, errno, notify);
293:
294: /* XXX mapped address case */
295: } else
296: in_pcbnotifyall(&rawcbtable, satosin(sa)->sin_addr, errno,
297: notify);
298: return NULL;
1.1 cgd 299: }
300:
301: /*
302: * Generate IP header and pass packet to ip_output.
303: * Tack on options user may have setup with control call.
304: */
1.9 mycroft 305: int
1.24 christos 306: rip_output(struct mbuf *m, ...)
307: {
1.53 augustss 308: struct inpcb *inp;
309: struct ip *ip;
1.10 mycroft 310: struct mbuf *opts;
1.24 christos 311: int flags;
312: va_list ap;
313:
314: va_start(ap, m);
1.27 mycroft 315: inp = va_arg(ap, struct inpcb *);
1.24 christos 316: va_end(ap);
317:
1.27 mycroft 318: flags =
1.37 matt 319: (inp->inp_socket->so_options & SO_DONTROUTE) | IP_ALLOWBROADCAST
320: | IP_RETURNMTU;
1.1 cgd 321:
322: /*
323: * If the user handed us a complete IP packet, use it.
324: * Otherwise, allocate an mbuf for a header and fill it in.
325: */
1.13 mycroft 326: if ((inp->inp_flags & INP_HDRINCL) == 0) {
1.35 thorpej 327: if ((m->m_pkthdr.len + sizeof(struct ip)) > IP_MAXPACKET) {
328: m_freem(m);
329: return (EMSGSIZE);
330: }
1.68 itojun 331: M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);
332: if (!m)
333: return (ENOBUFS);
1.1 cgd 334: ip = mtod(m, struct ip *);
335: ip->ip_tos = 0;
1.62 itojun 336: ip->ip_off = htons(0);
1.13 mycroft 337: ip->ip_p = inp->inp_ip.ip_p;
1.62 itojun 338: ip->ip_len = htons(m->m_pkthdr.len);
1.13 mycroft 339: ip->ip_src = inp->inp_laddr;
1.27 mycroft 340: ip->ip_dst = inp->inp_faddr;
1.1 cgd 341: ip->ip_ttl = MAXTTL;
1.13 mycroft 342: opts = inp->inp_options;
343: } else {
1.35 thorpej 344: if (m->m_pkthdr.len > IP_MAXPACKET) {
345: m_freem(m);
346: return (EMSGSIZE);
347: }
1.13 mycroft 348: ip = mtod(m, struct ip *);
1.65 thorpej 349:
350: /*
351: * If the mbuf is read-only, we need to allocate
352: * a new mbuf for the header, since we need to
353: * modify the header.
354: */
355: if (M_READONLY(m)) {
356: int hlen = ip->ip_hl << 2;
357:
358: m = m_copyup(m, hlen, (max_linkhdr + 3) & ~3);
359: if (m == NULL)
360: return (ENOMEM); /* XXX */
361: ip = mtod(m, struct ip *);
362: }
363:
1.62 itojun 364: /* XXX userland passes ip_len and ip_off in host order */
1.38 mycroft 365: if (m->m_pkthdr.len != ip->ip_len) {
366: m_freem(m);
367: return (EINVAL);
368: }
1.62 itojun 369: HTONS(ip->ip_len);
370: HTONS(ip->ip_off);
1.13 mycroft 371: if (ip->ip_id == 0)
1.70.2.2 skrll 372: ip->ip_id = ip_newid();
1.13 mycroft 373: opts = NULL;
374: /* XXX prevent ip_output from overwriting header fields */
375: flags |= IP_RAWOUTPUT;
376: ipstat.ips_rawout++;
1.1 cgd 377: }
1.62 itojun 378: return (ip_output(m, opts, &inp->inp_route, flags, inp->inp_moptions,
1.70.2.2 skrll 379: inp->inp_socket, &inp->inp_errormtu));
1.1 cgd 380: }
381:
382: /*
383: * Raw IP socket option processing.
384: */
1.9 mycroft 385: int
1.1 cgd 386: rip_ctloutput(op, so, level, optname, m)
387: int op;
388: struct socket *so;
389: int level, optname;
390: struct mbuf **m;
391: {
1.53 augustss 392: struct inpcb *inp = sotoinpcb(so);
1.31 mycroft 393: int error = 0;
1.1 cgd 394:
1.15 mycroft 395: if (level != IPPROTO_IP) {
1.31 mycroft 396: error = ENOPROTOOPT;
397: if (op == PRCO_SETOPT && *m != 0)
398: (void) m_free(*m);
399: } else switch (op) {
400:
401: case PRCO_SETOPT:
402: switch (optname) {
403: case IP_HDRINCL:
404: if (*m == 0 || (*m)->m_len < sizeof (int))
405: error = EINVAL;
406: else {
1.13 mycroft 407: if (*mtod(*m, int *))
408: inp->inp_flags |= INP_HDRINCL;
409: else
410: inp->inp_flags &= ~INP_HDRINCL;
411: }
1.31 mycroft 412: if (*m != 0)
413: (void) m_free(*m);
414: break;
415:
416: #ifdef MROUTING
417: case MRT_INIT:
418: case MRT_DONE:
419: case MRT_ADD_VIF:
420: case MRT_DEL_VIF:
421: case MRT_ADD_MFC:
422: case MRT_DEL_MFC:
423: case MRT_ASSERT:
1.70.2.3 skrll 424: case MRT_API_CONFIG:
425: case MRT_ADD_BW_UPCALL:
426: case MRT_DEL_BW_UPCALL:
1.31 mycroft 427: error = ip_mrouter_set(so, optname, m);
428: break;
429: #endif
430:
431: default:
432: error = ip_ctloutput(op, so, level, optname, m);
433: break;
1.13 mycroft 434: }
435: break;
1.1 cgd 436:
1.31 mycroft 437: case PRCO_GETOPT:
438: switch (optname) {
439: case IP_HDRINCL:
1.66 thorpej 440: *m = m_get(M_WAIT, MT_SOOPTS);
1.67 matt 441: MCLAIM((*m), so->so_mowner);
1.31 mycroft 442: (*m)->m_len = sizeof (int);
443: *mtod(*m, int *) = inp->inp_flags & INP_HDRINCL ? 1 : 0;
444: break;
445:
1.6 hpeyerl 446: #ifdef MROUTING
1.31 mycroft 447: case MRT_VERSION:
448: case MRT_ASSERT:
1.70.2.3 skrll 449: case MRT_API_SUPPORT:
450: case MRT_API_CONFIG:
1.31 mycroft 451: error = ip_mrouter_get(so, optname, m);
1.18 mycroft 452: break;
1.31 mycroft 453: #endif
454:
1.18 mycroft 455: default:
1.31 mycroft 456: error = ip_ctloutput(op, so, level, optname, m);
1.18 mycroft 457: break;
458: }
1.31 mycroft 459: break;
1.1 cgd 460: }
1.31 mycroft 461: return (error);
1.1 cgd 462: }
463:
1.27 mycroft 464: int
1.29 mycroft 465: rip_bind(inp, nam)
466: struct inpcb *inp;
467: struct mbuf *nam;
468: {
469: struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *);
470:
471: if (nam->m_len != sizeof(*addr))
472: return (EINVAL);
1.58 matt 473: if (TAILQ_FIRST(&ifnet) == 0)
1.29 mycroft 474: return (EADDRNOTAVAIL);
475: if (addr->sin_family != AF_INET &&
476: addr->sin_family != AF_IMPLINK)
477: return (EAFNOSUPPORT);
1.32 mycroft 478: if (!in_nullhost(addr->sin_addr) &&
1.29 mycroft 479: ifa_ifwithaddr(sintosa(addr)) == 0)
480: return (EADDRNOTAVAIL);
481: inp->inp_laddr = addr->sin_addr;
482: return (0);
483: }
484:
485: int
1.27 mycroft 486: rip_connect(inp, nam)
487: struct inpcb *inp;
488: struct mbuf *nam;
489: {
490: struct sockaddr_in *addr = mtod(nam, struct sockaddr_in *);
491:
492: if (nam->m_len != sizeof(*addr))
493: return (EINVAL);
1.58 matt 494: if (TAILQ_FIRST(&ifnet) == 0)
1.27 mycroft 495: return (EADDRNOTAVAIL);
496: if (addr->sin_family != AF_INET &&
497: addr->sin_family != AF_IMPLINK)
498: return (EAFNOSUPPORT);
499: inp->inp_faddr = addr->sin_addr;
500: return (0);
501: }
502:
503: void
504: rip_disconnect(inp)
505: struct inpcb *inp;
506: {
507:
1.32 mycroft 508: inp->inp_faddr = zeroin_addr;
1.27 mycroft 509: }
510:
1.13 mycroft 511: u_long rip_sendspace = RIPSNDQ;
512: u_long rip_recvspace = RIPRCVQ;
513:
1.1 cgd 514: /*ARGSUSED*/
1.9 mycroft 515: int
1.70.2.4! skrll 516: rip_usrreq(so, req, m, nam, control, l)
1.53 augustss 517: struct socket *so;
1.1 cgd 518: int req;
1.2 cgd 519: struct mbuf *m, *nam, *control;
1.70.2.4! skrll 520: struct lwp *l;
1.1 cgd 521: {
1.53 augustss 522: struct inpcb *inp;
1.70.2.4! skrll 523: struct proc *p;
1.27 mycroft 524: int s;
1.53 augustss 525: int error = 0;
1.13 mycroft 526: #ifdef MROUTING
1.6 hpeyerl 527: extern struct socket *ip_mrouter;
528: #endif
1.27 mycroft 529:
1.70.2.4! skrll 530: p = l ? l->l_proc : NULL;
1.22 pk 531: if (req == PRU_CONTROL)
532: return (in_control(so, (long)m, (caddr_t)nam,
1.26 mycroft 533: (struct ifnet *)control, p));
1.49 thorpej 534:
1.50 thorpej 535: if (req == PRU_PURGEIF) {
1.56 itojun 536: in_pcbpurgeif0(&rawcbtable, (struct ifnet *)control);
1.50 thorpej 537: in_purgeif((struct ifnet *)control);
538: in_pcbpurgeif(&rawcbtable, (struct ifnet *)control);
1.49 thorpej 539: return (0);
540: }
1.22 pk 541:
1.27 mycroft 542: s = splsoftnet();
543: inp = sotoinpcb(so);
1.28 mycroft 544: #ifdef DIAGNOSTIC
545: if (req != PRU_SEND && req != PRU_SENDOOB && control)
546: panic("rip_usrreq: unexpected control mbuf");
547: #endif
1.27 mycroft 548: if (inp == 0 && req != PRU_ATTACH) {
1.22 pk 549: error = EINVAL;
550: goto release;
551: }
552:
1.1 cgd 553: switch (req) {
554:
555: case PRU_ATTACH:
1.27 mycroft 556: if (inp != 0) {
557: error = EISCONN;
558: break;
559: }
1.26 mycroft 560: if (p == 0 || (error = suser(p->p_ucred, &p->p_acflag))) {
1.13 mycroft 561: error = EACCES;
562: break;
563: }
1.27 mycroft 564: if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
565: error = soreserve(so, rip_sendspace, rip_recvspace);
566: if (error)
567: break;
568: }
569: error = in_pcballoc(so, &rawcbtable);
570: if (error)
1.13 mycroft 571: break;
1.27 mycroft 572: inp = sotoinpcb(so);
1.17 cgd 573: inp->inp_ip.ip_p = (long)nam;
1.1 cgd 574: break;
575:
576: case PRU_DETACH:
1.13 mycroft 577: #ifdef MROUTING
1.6 hpeyerl 578: if (so == ip_mrouter)
579: ip_mrouter_done();
580: #endif
1.13 mycroft 581: in_pcbdetach(inp);
1.1 cgd 582: break;
583:
584: case PRU_BIND:
1.29 mycroft 585: error = rip_bind(inp, nam);
1.27 mycroft 586: break;
587:
588: case PRU_LISTEN:
589: error = EOPNOTSUPP;
590: break;
591:
592: case PRU_CONNECT:
593: error = rip_connect(inp, nam);
594: if (error)
1.13 mycroft 595: break;
1.1 cgd 596: soisconnected(so);
1.13 mycroft 597: break;
598:
599: case PRU_CONNECT2:
600: error = EOPNOTSUPP;
601: break;
602:
1.27 mycroft 603: case PRU_DISCONNECT:
604: soisdisconnected(so);
605: rip_disconnect(inp);
606: break;
607:
1.13 mycroft 608: /*
609: * Mark the connection as being incapable of further input.
610: */
611: case PRU_SHUTDOWN:
612: socantsendmore(so);
613: break;
614:
1.27 mycroft 615: case PRU_RCVD:
616: error = EOPNOTSUPP;
617: break;
618:
1.13 mycroft 619: /*
620: * Ship a packet out. The appropriate raw output
621: * routine handles any massaging necessary.
622: */
623: case PRU_SEND:
1.28 mycroft 624: if (control && control->m_len) {
625: m_freem(control);
626: m_freem(m);
627: error = EINVAL;
628: break;
629: }
630: {
1.27 mycroft 631: if (nam) {
632: if ((so->so_state & SS_ISCONNECTED) != 0) {
1.13 mycroft 633: error = EISCONN;
1.28 mycroft 634: goto die;
1.13 mycroft 635: }
1.27 mycroft 636: error = rip_connect(inp, nam);
637: if (error) {
1.28 mycroft 638: die:
1.27 mycroft 639: m_freem(m);
640: break;
641: }
1.13 mycroft 642: } else {
1.27 mycroft 643: if ((so->so_state & SS_ISCONNECTED) == 0) {
1.13 mycroft 644: error = ENOTCONN;
1.28 mycroft 645: goto die;
1.13 mycroft 646: }
647: }
1.27 mycroft 648: error = rip_output(m, inp);
649: if (nam)
650: rip_disconnect(inp);
1.28 mycroft 651: }
1.13 mycroft 652: break;
653:
654: case PRU_SENSE:
655: /*
656: * stat: don't bother with a blocksize.
657: */
1.27 mycroft 658: splx(s);
1.1 cgd 659: return (0);
1.13 mycroft 660:
661: case PRU_RCVOOB:
1.27 mycroft 662: error = EOPNOTSUPP;
663: break;
664:
1.13 mycroft 665: case PRU_SENDOOB:
1.28 mycroft 666: m_freem(control);
1.27 mycroft 667: m_freem(m);
1.13 mycroft 668: error = EOPNOTSUPP;
669: break;
670:
671: case PRU_SOCKADDR:
672: in_setsockaddr(inp, nam);
673: break;
674:
675: case PRU_PEERADDR:
676: in_setpeeraddr(inp, nam);
677: break;
678:
679: default:
680: panic("rip_usrreq");
1.1 cgd 681: }
1.27 mycroft 682:
1.22 pk 683: release:
1.27 mycroft 684: splx(s);
1.1 cgd 685: return (error);
686: }
CVSweb <webmaster@jp.NetBSD.org>