raw_ip6.c revision 1.1.2.3 1 /*
2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the project nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30 /*
31 * Copyright (c) 1982, 1986, 1988, 1993
32 * The Regents of the University of California. All rights reserved.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)raw_ip.c 8.2 (Berkeley) 1/4/94
63 */
64
65 #ifdef __NetBSD__ /*XXX*/
66 #include "opt_ipsec.h"
67 #endif
68
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>
76 #include <sys/systm.h>
77 #ifdef __NetBSD__
78 #include <sys/proc.h>
79 #endif
80
81 #include <net/if.h>
82 #include <net/route.h>
83 #include <net/if_types.h>
84
85 #include <netinet/in.h>
86 #include <netinet/in_var.h>
87 #include <netinet6/ip6.h>
88 #include <netinet6/ip6_var.h>
89 #include <netinet6/ip6_mroute.h>
90 #include <netinet6/icmp6.h>
91 #include <netinet6/in6_pcb.h>
92 #include <netinet6/nd6.h>
93
94 #ifdef IPSEC
95 #include <netinet6/ipsec.h>
96 #endif /*IPSEC*/
97
98 #include <machine/stdarg.h>
99
100 #include "faith.h"
101
102 struct in6pcb rawin6pcb;
103 #define ifatoia6(ifa) ((struct in6_ifaddr *)(ifa))
104
105 /*
106 * Raw interface to IP6 protocol.
107 */
108
109 /*
110 * Initialize raw connection block queue.
111 */
112 void
113 rip6_init()
114 {
115 rawin6pcb.in6p_next = rawin6pcb.in6p_prev = &rawin6pcb;
116 }
117
118 /*
119 * Setup generic address and protocol structures
120 * for raw_input routine, then pass them along with
121 * mbuf chain.
122 */
123 int
124 rip6_input(mp, offp, proto)
125 struct mbuf **mp;
126 int *offp, proto;
127 {
128 struct mbuf *m = *mp;
129 register struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *);
130 register struct in6pcb *in6p;
131 struct in6pcb *last = NULL;
132 struct sockaddr_in6 rip6src;
133 struct mbuf *opts = NULL;
134
135 #if defined(NFAITH) && 0 < NFAITH
136 if (m->m_pkthdr.rcvif) {
137 if (m->m_pkthdr.rcvif->if_type == IFT_FAITH) {
138 /* send icmp6 host unreach? */
139 m_freem(m);
140 return IPPROTO_DONE;
141 }
142 }
143 #endif
144 bzero(&rip6src, sizeof(rip6src));
145 rip6src.sin6_len = sizeof(struct sockaddr_in6);
146 rip6src.sin6_family = AF_INET6;
147 rip6src.sin6_addr = ip6->ip6_src;
148 if (IN6_IS_SCOPE_LINKLOCAL(&rip6src.sin6_addr))
149 rip6src.sin6_addr.s6_addr16[1] = 0;
150 if (m->m_pkthdr.rcvif) {
151 if (IN6_IS_SCOPE_LINKLOCAL(&rip6src.sin6_addr))
152 rip6src.sin6_scope_id = m->m_pkthdr.rcvif->if_index;
153 else
154 rip6src.sin6_scope_id = 0;
155 } else
156 rip6src.sin6_scope_id = 0;
157
158 for (in6p = rawin6pcb.in6p_next;
159 in6p != &rawin6pcb; in6p = in6p->in6p_next) {
160 if (in6p->in6p_ip6.ip6_nxt &&
161 in6p->in6p_ip6.ip6_nxt != proto)
162 continue;
163 if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) &&
164 !IN6_ARE_ADDR_EQUAL(&in6p->in6p_laddr, &ip6->ip6_dst))
165 continue;
166 if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr) &&
167 !IN6_ARE_ADDR_EQUAL(&in6p->in6p_faddr, &ip6->ip6_src))
168 continue;
169 if (in6p->in6p_cksum != -1
170 && in6_cksum(m, ip6->ip6_nxt, *offp, m->m_pkthdr.len - *offp))
171 {
172 /* XXX bark something */
173 continue;
174 }
175 if (last) {
176 struct mbuf *n;
177 if ((n = m_copy(m, 0, (int)M_COPYALL)) != NULL) {
178 if (last->in6p_flags & IN6P_CONTROLOPTS)
179 ip6_savecontrol(last, &opts, ip6, n);
180 /* strip intermediate headers */
181 m_adj(n, *offp);
182 if (sbappendaddr(&last->in6p_socket->so_rcv,
183 (struct sockaddr *)&rip6src,
184 n, opts) == 0) {
185 /* should notify about lost packet */
186 m_freem(n);
187 if (opts)
188 m_freem(opts);
189 } else
190 sorwakeup(last->in6p_socket);
191 opts = NULL;
192 }
193 }
194 last = in6p;
195 }
196 if (last) {
197 if (last->in6p_flags & IN6P_CONTROLOPTS)
198 ip6_savecontrol(last, &opts, ip6, m);
199 /* strip intermediate headers */
200 m_adj(m, *offp);
201 if (sbappendaddr(&last->in6p_socket->so_rcv,
202 (struct sockaddr *)&rip6src, m, opts) == 0) {
203 m_freem(m);
204 if (opts)
205 m_freem(opts);
206 } else
207 sorwakeup(last->in6p_socket);
208 } else {
209 if (proto == IPPROTO_NONE)
210 m_freem(m);
211 else {
212 char *prvnxtp = ip6_get_prevhdr(m, *offp); /* XXX */
213 icmp6_error(m, ICMP6_PARAM_PROB,
214 ICMP6_PARAMPROB_NEXTHEADER,
215 prvnxtp - mtod(m, char *));
216 }
217 ip6stat.ip6s_delivered--;
218 }
219 return IPPROTO_DONE;
220 }
221
222 /*
223 * Generate IPv6 header and pass packet to ip6_output.
224 * Tack on options user may have setup with control call.
225 */
226 int
227 #if __STDC__
228 rip6_output(struct mbuf *m, ...)
229 #else
230 rip6_output(m, va_alist)
231 struct mbuf *m;
232 va_dcl
233 #endif
234 {
235 struct socket *so;
236 struct sockaddr_in6 *dstsock;
237 struct mbuf *control;
238 struct in6_addr *dst;
239 struct ip6_hdr *ip6;
240 struct in6pcb *in6p;
241 u_int plen = m->m_pkthdr.len;
242 int error = 0;
243 struct ip6_pktopts opt, *optp = NULL;
244 struct ifnet *oifp = NULL;
245 int type, code; /* for ICMPv6 output statistics only */
246 int priv = 0;
247 va_list ap;
248
249 va_start(ap, m);
250 so = va_arg(ap, struct socket *);
251 dstsock = va_arg(ap, struct sockaddr_in6 *);
252 control = va_arg(ap, struct mbuf *);
253 va_end(ap);
254
255 in6p = sotoin6pcb(so);
256
257 priv = 0;
258 #if defined(__NetBSD__) || (defined(__FreeBSD__) && __FreeBSD__ >= 3)
259 {
260 struct proc *p = curproc; /* XXX */
261
262 if (p && !suser(p->p_ucred, &p->p_acflag))
263 priv = 1;
264 }
265 #else
266 if ((so->so_state & SS_PRIV) != 0)
267 priv = 1;
268 #endif
269 dst = &dstsock->sin6_addr;
270 if (control) {
271 if ((error = ip6_setpktoptions(control, &opt, priv)) != 0)
272 goto bad;
273 optp = &opt;
274 } else
275 optp = in6p->in6p_outputopts;
276
277 /*
278 * For an ICMPv6 packet, we should know its type and code
279 * to update statistics.
280 */
281 if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) {
282 struct icmp6_hdr *icmp6;
283 if (m->m_len < sizeof(struct icmp6_hdr) &&
284 (m = m_pullup(m, sizeof(struct icmp6_hdr))) == NULL) {
285 error = ENOBUFS;
286 goto bad;
287 }
288 icmp6 = mtod(m, struct icmp6_hdr *);
289 type = icmp6->icmp6_type;
290 code = icmp6->icmp6_code;
291 }
292
293 M_PREPEND(m, sizeof(*ip6), M_WAIT);
294 ip6 = mtod(m, struct ip6_hdr *);
295
296 /*
297 * Next header might not be ICMP6 but use its pseudo header anyway.
298 */
299 ip6->ip6_dst = *dst;
300
301 /*
302 * If the scope of the destination is link-local, embed the interface
303 * index in the address.
304 *
305 * XXX advanced-api value overrides sin6_scope_id
306 */
307 if (IN6_IS_ADDR_LINKLOCAL(&ip6->ip6_dst) ||
308 IN6_IS_ADDR_MC_LINKLOCAL(&ip6->ip6_dst)) {
309 struct in6_pktinfo *pi;
310
311 /*
312 * XXX Boundary check is assumed to be already done in
313 * ip6_setpktoptions().
314 */
315 if (optp && (pi = optp->ip6po_pktinfo) && pi->ipi6_ifindex) {
316 ip6->ip6_dst.s6_addr16[1] = htons(pi->ipi6_ifindex);
317 oifp = ifindex2ifnet[pi->ipi6_ifindex];
318 }
319 else if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst) &&
320 in6p->in6p_moptions &&
321 in6p->in6p_moptions->im6o_multicast_ifp) {
322 oifp = in6p->in6p_moptions->im6o_multicast_ifp;
323 ip6->ip6_dst.s6_addr16[1] = htons(oifp->if_index);
324 } else if (dstsock->sin6_scope_id) {
325 /* boundary check */
326 if (dstsock->sin6_scope_id < 0
327 || if_index < dstsock->sin6_scope_id) {
328 error = ENXIO; /* XXX EINVAL? */
329 goto bad;
330 }
331 ip6->ip6_dst.s6_addr16[1]
332 = htons(dstsock->sin6_scope_id & 0xffff);/*XXX*/
333 }
334 }
335
336 /*
337 * Source address selection.
338 */
339 {
340 struct in6_addr *in6a;
341
342 if ((in6a = in6_selectsrc(dstsock, optp,
343 in6p->in6p_moptions,
344 &in6p->in6p_route,
345 &in6p->in6p_laddr,
346 &error)) == 0) {
347 if (error == 0)
348 error = EADDRNOTAVAIL;
349 goto bad;
350 }
351 ip6->ip6_src = *in6a;
352 if (in6p->in6p_route.ro_rt)
353 oifp = ifindex2ifnet[in6p->in6p_route.ro_rt->rt_ifp->if_index];
354 }
355
356 ip6->ip6_flow = in6p->in6p_flowinfo & IPV6_FLOWINFO_MASK;
357 ip6->ip6_vfc = IPV6_VERSION;
358 #if 0 /* ip6_plen will be filled in ip6_output. */
359 ip6->ip6_plen = htons((u_short)plen);
360 #endif
361 ip6->ip6_nxt = in6p->in6p_ip6.ip6_nxt;
362 ip6->ip6_hlim = in6_selecthlim(in6p, oifp);
363
364 if (so->so_proto->pr_protocol == IPPROTO_ICMPV6 ||
365 in6p->in6p_cksum != -1) {
366 struct mbuf *n;
367 int off;
368 u_int16_t *p;
369
370 #define offsetof(type, member) ((size_t)(&((type *)0)->member)) /* XXX */
371
372 /* compute checksum */
373 if (so->so_proto->pr_protocol == IPPROTO_ICMPV6)
374 off = offsetof(struct icmp6_hdr, icmp6_cksum);
375 else
376 off = in6p->in6p_cksum;
377 if (plen < off + 1) {
378 error = EINVAL;
379 goto bad;
380 }
381 off += sizeof(struct ip6_hdr);
382
383 n = m;
384 while (n && n->m_len <= off) {
385 off -= n->m_len;
386 n = n->m_next;
387 }
388 if (!n)
389 goto bad;
390 p = (u_int16_t *)(mtod(n, caddr_t) + off);
391 *p = 0;
392 *p = in6_cksum(m, ip6->ip6_nxt, sizeof(*ip6), plen);
393 }
394
395 #ifdef IPSEC
396 m->m_pkthdr.rcvif = (struct ifnet *)so;
397 #endif /*IPSEC*/
398
399 error = ip6_output(m, optp, &in6p->in6p_route, 0, in6p->in6p_moptions,
400 &oifp);
401 if (so->so_proto->pr_protocol == IPPROTO_ICMPV6) {
402 if (oifp)
403 icmp6_ifoutstat_inc(oifp, type, code);
404 icmp6stat.icp6s_outhist[type]++;
405 }
406
407 goto freectl;
408
409 bad:
410 if (m)
411 m_freem(m);
412
413 freectl:
414 if (optp == &opt && optp->ip6po_rthdr && optp->ip6po_route.ro_rt)
415 RTFREE(optp->ip6po_route.ro_rt);
416 if (control)
417 m_freem(control);
418 return(error);
419 }
420
421 /*
422 * Raw IPv6 socket option processing.
423 */
424 int
425 rip6_ctloutput(op, so, level, optname, m)
426 int op;
427 struct socket *so;
428 int level, optname;
429 struct mbuf **m;
430 {
431 int error = 0;
432
433 switch(level) {
434 case IPPROTO_IPV6:
435 switch(optname) {
436 case MRT6_INIT:
437 case MRT6_DONE:
438 case MRT6_ADD_MIF:
439 case MRT6_DEL_MIF:
440 case MRT6_ADD_MFC:
441 case MRT6_DEL_MFC:
442 case MRT6_PIM:
443 if (op == PRCO_SETOPT) {
444 error = ip6_mrouter_set(optname, so, *m);
445 if (*m)
446 (void)m_free(*m);
447 } else if (op == PRCO_GETOPT) {
448 error = ip6_mrouter_get(optname, so, m);
449 } else
450 error = EINVAL;
451 return (error);
452 }
453 return (ip6_ctloutput(op, so, level, optname, m));
454 /* NOTREACHED */
455
456 case IPPROTO_ICMPV6:
457 /*
458 * XXX: is it better to call icmp6_ctloutput() directly
459 * from protosw?
460 */
461 return(icmp6_ctloutput(op, so, level, optname, m));
462
463 default:
464 if (op == PRCO_SETOPT && *m)
465 (void)m_free(*m);
466 return(EINVAL);
467 }
468 }
469
470 extern u_long rip6_sendspace;
471 extern u_long rip6_recvspace;
472
473 int
474 rip6_usrreq(so, req, m, nam, control, p)
475 register struct socket *so;
476 int req;
477 struct mbuf *m, *nam, *control;
478 struct proc *p;
479 {
480 register struct in6pcb *in6p = sotoin6pcb(so);
481 int s;
482 int error = 0;
483 /* extern struct socket *ip6_mrouter; */ /* xxx */
484 int priv;
485
486 priv = 0;
487 #if defined(__NetBSD__) || (defined(__FreeBSD__) && __FreeBSD__ >= 3)
488 if (p && !suser(p->p_ucred, &p->p_acflag))
489 priv++;
490 #else
491 if ((so->so_state & SS_PRIV) != 0)
492 priv++;
493 #endif
494
495 if (req == PRU_CONTROL)
496 return (in6_control(so, (u_long)m, (caddr_t)nam,
497 (struct ifnet *)control
498 #if defined(__NetBSD__) || (defined(__FreeBSD__) && __FreeBSD__ >= 3)
499 , p
500 #endif
501 ));
502
503 switch (req) {
504 case PRU_ATTACH:
505 if (in6p)
506 panic("rip6_attach");
507 if (!priv) {
508 error = EACCES;
509 break;
510 }
511 #ifdef __NetBSD__
512 s = splsoftnet();
513 #else
514 s = splnet();
515 #endif
516 if ((error = soreserve(so, rip6_sendspace, rip6_recvspace)) ||
517 (error = in6_pcballoc(so, &rawin6pcb))) {
518 splx(s);
519 break;
520 }
521 splx(s);
522 in6p = sotoin6pcb(so);
523 in6p->in6p_ip6.ip6_nxt = (long)nam;
524 in6p->in6p_cksum = -1;
525 #ifdef IPSEC
526 error = ipsec_init_policy(so, &in6p->in6p_sp);
527 if (error != 0) {
528 in6_pcbdetach(in6p);
529 break;
530 }
531 #endif /*IPSEC*/
532
533 MALLOC(in6p->in6p_icmp6filt, struct icmp6_filter *,
534 sizeof(struct icmp6_filter), M_PCB, M_NOWAIT);
535 if (in6p->in6p_icmp6filt == NULL) {
536 in6_pcbdetach(in6p);
537 error = ENOMEM;
538 break;
539 }
540 ICMP6_FILTER_SETPASSALL(in6p->in6p_icmp6filt);
541 break;
542
543 case PRU_DISCONNECT:
544 if ((so->so_state & SS_ISCONNECTED) == 0) {
545 error = ENOTCONN;
546 break;
547 }
548 in6p->in6p_faddr = in6addr_any;
549 so->so_state &= ~SS_ISCONNECTED; /* XXX */
550 break;
551
552 case PRU_ABORT:
553 soisdisconnected(so);
554 /* Fallthrough */
555 case PRU_DETACH:
556 if (in6p == 0)
557 panic("rip6_detach");
558 if (so == ip6_mrouter)
559 ip6_mrouter_done();
560 /* xxx: RSVP */
561 if (in6p->in6p_icmp6filt) {
562 FREE(in6p->in6p_icmp6filt, M_PCB);
563 in6p->in6p_icmp6filt = NULL;
564 }
565 in6_pcbdetach(in6p);
566 break;
567
568 case PRU_BIND:
569 {
570 struct sockaddr_in6 *addr = mtod(nam, struct sockaddr_in6 *);
571 struct ifaddr *ia = NULL;
572
573 if (nam->m_len != sizeof(*addr)) {
574 error = EINVAL;
575 break;
576 }
577 if (
578 #if defined(__bsdi__) || (defined(__FreeBSD__) && __FreeBSD__ < 3)
579 (ifnet == 0) ||
580 #else
581 (ifnet.tqh_first == 0) ||
582 #endif
583 (addr->sin6_family != AF_INET6) ||
584 (!IN6_IS_ADDR_UNSPECIFIED(&addr->sin6_addr) &&
585 (ia = ifa_ifwithaddr((struct sockaddr *)addr)) == 0)) {
586 error = EADDRNOTAVAIL;
587 break;
588 }
589 if (ia &&
590 ((struct in6_ifaddr *)ia)->ia6_flags &
591 (IN6_IFF_ANYCAST|IN6_IFF_NOTREADY|
592 IN6_IFF_DETACHED|IN6_IFF_DEPRECATED)) {
593 error = EADDRNOTAVAIL;
594 break;
595 }
596 in6p->in6p_laddr = addr->sin6_addr;
597 break;
598 }
599
600 case PRU_CONNECT:
601 {
602 struct sockaddr_in6 *addr = mtod(nam, struct sockaddr_in6 *);
603 struct in6_addr *in6a = NULL;
604
605 if (nam->m_len != sizeof(*addr)) {
606 error = EINVAL;
607 break;
608 }
609 #if defined(__bsdi__) || (defined(__FreeBSD__) && __FreeBSD__ < 3)
610 if (ifnet == 0)
611 #else
612 if (ifnet.tqh_first == 0)
613 #endif
614 {
615 error = EADDRNOTAVAIL;
616 break;
617 }
618 if (addr->sin6_family != AF_INET6) {
619 error = EAFNOSUPPORT;
620 break;
621 }
622
623 /* Source address selection. XXX: need pcblookup? */
624 in6a = in6_selectsrc(addr, in6p->in6p_outputopts,
625 in6p->in6p_moptions,
626 &in6p->in6p_route,
627 &in6p->in6p_laddr,
628 &error);
629 if (in6a == NULL) {
630 if (error == 0)
631 error = EADDRNOTAVAIL;
632 break;
633 }
634 in6p->in6p_laddr = *in6a;
635 in6p->in6p_faddr = addr->sin6_addr;
636 soisconnected(so);
637 break;
638 }
639
640 case PRU_CONNECT2:
641 error = EOPNOTSUPP;
642 break;
643
644 /*
645 * Mark the connection as being incapable of futther input.
646 */
647 case PRU_SHUTDOWN:
648 socantsendmore(so);
649 break;
650 /*
651 * Ship a packet out. The appropriate raw output
652 * routine handles any messaging necessary.
653 */
654 case PRU_SEND:
655 {
656 struct sockaddr_in6 tmp;
657 struct sockaddr_in6 *dst;
658
659 if (so->so_state & SS_ISCONNECTED) {
660 if (nam) {
661 error = EISCONN;
662 break;
663 }
664 /* XXX */
665 bzero(&tmp, sizeof(tmp));
666 tmp.sin6_family = AF_INET6;
667 tmp.sin6_len = sizeof(struct sockaddr_in6);
668 bcopy(&in6p->in6p_faddr, &tmp.sin6_addr,
669 sizeof(struct in6_addr));
670 dst = &tmp;
671 } else {
672 if (nam == NULL) {
673 error = ENOTCONN;
674 break;
675 }
676 dst = mtod(nam, struct sockaddr_in6 *);
677 }
678 error = rip6_output(m, so, dst, control);
679 m = NULL;
680 break;
681 }
682
683 case PRU_SENSE:
684 /*
685 * stat: don't bother with a blocksize
686 */
687 return(0);
688 /*
689 * Not supported.
690 */
691 case PRU_RCVOOB:
692 case PRU_RCVD:
693 case PRU_LISTEN:
694 case PRU_ACCEPT:
695 case PRU_SENDOOB:
696 error = EOPNOTSUPP;
697 break;
698
699 case PRU_SOCKADDR:
700 in6_setsockaddr(in6p, nam);
701 break;
702
703 case PRU_PEERADDR:
704 in6_setpeeraddr(in6p, nam);
705 break;
706
707 default:
708 panic("rip6_usrreq");
709 }
710 if (m != NULL)
711 m_freem(m);
712 return(error);
713 }
714