if_stf.c revision 1.4 1 /* $NetBSD: if_stf.c,v 1.4 2000/06/10 08:02:20 itojun Exp $ */
2 /* $KAME: if_stf.c,v 1.39 2000/06/07 23:35:18 itojun Exp $ */
3
4 /*
5 * Copyright (C) 2000 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33 /*
34 * 6to4 interface, based on draft-ietf-ngtrans-6to4-06.txt.
35 *
36 * 6to4 interface is NOT capable of link-layer (I mean, IPv4) multicasting.
37 * There is no address mapping defined from IPv6 multicast address to IPv4
38 * address. Therefore, we do not have IFF_MULTICAST on the interface.
39 *
40 * Due to the lack of address mapping for link-local addresses, we cannot
41 * throw packets toward link-local addresses (fe80::x). Also, we cannot throw
42 * packets to link-local multicast addresses (ff02::x).
43 *
44 * Here are interesting symptoms due to the lack of link-local address:
45 *
46 * Unicast routing exchange:
47 * - RIPng: Impossible. Uses link-local multicast packet toward ff02::9,
48 * and link-local addresses as nexthop.
49 * - OSPFv6: Impossible. OSPFv6 assumes that there's link-local address
50 * assigned to the link, and makes use of them. Also, HELLO packets use
51 * link-local multicast addresses (ff02::5 and ff02::6).
52 * - BGP4+: Maybe. You can only use global address as nexthop, and global
53 * address as TCP endpoint address.
54 *
55 * Multicast routing protocols:
56 * - PIM: Hello packet cannot be used to discover adjacent PIM routers.
57 * Adjacent PIM routers must be configured manually (is it really spec-wise
58 * correct thing to do?).
59 *
60 * ICMPv6:
61 * - Redirects cannot be used due to the lack of link-local address.
62 *
63 * Starting from 04 draft, the specification suggests how to construct
64 * link-local address for 6to4 interface.
65 * However, it seems to have no real use and does not help the above symptom
66 * much. Even if we assign link-locals to interface, we cannot really
67 * use link-local unicast/multicast on top of 6to4 cloud, and the above
68 * analysis does not change.
69 *
70 * 6to4 interface has security issues. Refer to
71 * http://playground.iijlab.net/i-d/draft-itojun-ipv6-transition-abuse-00.txt
72 * for details. The code tries to filter out some of malicious packets.
73 * Note that there is no way to be 100% secure.
74 */
75
76 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
77 #include "opt_inet.h"
78 #include "opt_inet6.h"
79 #endif
80 #ifdef __NetBSD__
81 #include "opt_inet.h"
82 #endif
83
84 #include <sys/param.h>
85 #include <sys/systm.h>
86 #include <sys/socket.h>
87 #include <sys/sockio.h>
88 #include <sys/mbuf.h>
89 #include <sys/errno.h>
90 #if !(defined(__FreeBSD__) && __FreeBSD__ >= 3)
91 #include <sys/ioctl.h>
92 #endif
93 #include <sys/protosw.h>
94 #ifdef __FreeBSD__
95 #include <sys/kernel.h>
96 #endif
97 #include <machine/cpu.h>
98
99 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
100 #include <sys/malloc.h>
101 #endif
102
103 #include <net/if.h>
104 #include <net/route.h>
105 #include <net/netisr.h>
106 #include <net/if_types.h>
107 #include <net/if_stf.h>
108
109 #include <netinet/in.h>
110 #include <netinet/in_systm.h>
111 #include <netinet/ip.h>
112 #include <netinet/ip_var.h>
113 #include <netinet/in_var.h>
114
115 #include <netinet/ip6.h>
116 #include <netinet6/ip6_var.h>
117 #include <netinet6/in6_gif.h>
118 #include <netinet6/in6_var.h>
119 #include <netinet/ip_ecn.h>
120
121 #include <netinet/ip_encap.h>
122
123 #include <machine/stdarg.h>
124
125 #include <net/net_osdep.h>
126
127 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
128 #include "bpf.h"
129 #define NBPFILTER NBPF
130 #else
131 #include "bpfilter.h"
132 #endif
133 #include "stf.h"
134 #include "gif.h" /*XXX*/
135
136 #if NBPFILTER > 0
137 #include <net/bpf.h>
138 #endif
139
140 #if NGIF > 0
141 #include <net/if_gif.h>
142 #endif
143
144 #if NSTF > 0
145 #if NSTF != 1
146 # error only single stf interface allowed
147 #endif
148
149 #define IN6_IS_ADDR_6TO4(x) (ntohs((x)->s6_addr16[0]) == 0x2002)
150 #define GET_V4(x) ((struct in_addr *)(&(x)->s6_addr16[1]))
151
152 struct stf_softc {
153 struct ifnet sc_if; /* common area */
154 union {
155 struct route __sc_ro4;
156 struct route_in6 __sc_ro6; /* just for safety */
157 } __sc_ro46;
158 #define sc_ro __sc_ro46.__sc_ro4
159 const struct encaptab *encap_cookie;
160 };
161
162 static struct stf_softc *stf;
163 static int nstf;
164
165 #if NGIF > 0
166 extern int ip_gif_ttl; /*XXX*/
167 #else
168 static int ip_gif_ttl = 40; /*XXX*/
169 #endif
170
171 extern struct protosw in_stf_protosw;
172
173 #ifdef __FreeBSD__
174 void stfattach __P((void *));
175 #else
176 void stfattach __P((int));
177 #endif
178 static int stf_encapcheck __P((const struct mbuf *, int, int, void *));
179 static struct in6_ifaddr *stf_getsrcifa6 __P((struct ifnet *));
180 static int stf_output __P((struct ifnet *, struct mbuf *, struct sockaddr *,
181 struct rtentry *));
182 static int stf_checkaddr4 __P((struct in_addr *, struct ifnet *));
183 static int stf_checkaddr6 __P((struct in6_addr *, struct ifnet *));
184 #if defined(__bsdi__) && _BSDI_VERSION >= 199802
185 static void stf_rtrequest __P((int, struct rtentry *, struct rt_addrinfo *));
186 #else
187 static void stf_rtrequest __P((int, struct rtentry *, struct sockaddr *));
188 #endif
189 #if defined(__FreeBSD__) && __FreeBSD__ < 3
190 static int stf_ioctl __P((struct ifnet *, int, caddr_t));
191 #else
192 static int stf_ioctl __P((struct ifnet *, u_long, caddr_t));
193 #endif
194
195 void
196 stfattach(dummy)
197 #ifdef __FreeBSD__
198 void *dummy;
199 #else
200 int dummy;
201 #endif
202 {
203 struct stf_softc *sc;
204 int i;
205 const struct encaptab *p;
206
207 #ifdef __NetBSD__
208 nstf = dummy;
209 #else
210 nstf = NSTF;
211 #endif
212 stf = malloc(nstf * sizeof(struct stf_softc), M_DEVBUF, M_WAIT);
213 bzero(stf, nstf * sizeof(struct stf_softc));
214 sc = stf;
215
216 /* XXX just in case... */
217 for (i = 0; i < nstf; i++) {
218 sc = &stf[i];
219 bzero(sc, sizeof(*sc));
220 #if defined(__NetBSD__) || defined(__OpenBSD__)
221 sprintf(sc->sc_if.if_xname, "stf%d", i);
222 #else
223 sc->sc_if.if_name = "stf";
224 sc->sc_if.if_unit = i;
225 #endif
226
227 p = encap_attach_func(AF_INET, IPPROTO_IPV6, stf_encapcheck,
228 &in_stf_protosw, sc);
229 if (p == NULL) {
230 printf("%s: attach failed\n", if_name(&sc->sc_if));
231 continue;
232 }
233 sc->encap_cookie = p;
234
235 sc->sc_if.if_mtu = IPV6_MMTU;
236 sc->sc_if.if_flags = 0;
237 sc->sc_if.if_ioctl = stf_ioctl;
238 sc->sc_if.if_output = stf_output;
239 sc->sc_if.if_type = IFT_STF;
240 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
241 sc->sc_if.if_snd.ifq_maxlen = IFQ_MAXLEN;
242 #endif
243 if_attach(&sc->sc_if);
244 #if NBPFILTER > 0
245 #ifdef HAVE_OLD_BPF
246 bpfattach(&sc->sc_if, DLT_NULL, sizeof(u_int));
247 #else
248 bpfattach(&sc->sc_if.if_bpf, &sc->sc_if, DLT_NULL, sizeof(u_int));
249 #endif
250 #endif
251 }
252 }
253
254 #ifdef __FreeBSD__
255 PSEUDO_SET(stfattach, if_stf);
256 #endif
257
258 static int
259 stf_encapcheck(m, off, proto, arg)
260 const struct mbuf *m;
261 int off;
262 int proto;
263 void *arg;
264 {
265 struct ip ip;
266 struct in6_ifaddr *ia6;
267 struct stf_softc *sc;
268 struct in_addr a, b;
269
270 sc = (struct stf_softc *)arg;
271 if (sc == NULL)
272 return 0;
273
274 if ((sc->sc_if.if_flags & IFF_UP) == 0)
275 return 0;
276
277 if (proto != IPPROTO_IPV6)
278 return 0;
279
280 /* LINTED const cast */
281 m_copydata((struct mbuf *)m, 0, sizeof(ip), (caddr_t)&ip);
282
283 if (ip.ip_v != 4)
284 return 0;
285
286 ia6 = stf_getsrcifa6(&sc->sc_if);
287 if (ia6 == NULL)
288 return 0;
289
290 /*
291 * check if IPv4 dst matches the IPv4 address derived from the
292 * local 6to4 address.
293 * success on: dst = 10.1.1.1, ia6->ia_addr = 2002:0a01:0101:...
294 */
295 if (bcmp(GET_V4(&ia6->ia_addr.sin6_addr), &ip.ip_dst,
296 sizeof(ip.ip_dst)) != 0)
297 return 0;
298
299 /*
300 * check if IPv4 src matches the IPv4 address derived from the
301 * local 6to4 address masked by prefixmask.
302 * success on: src = 10.1.1.1, ia6->ia_addr = 2002:0a00:.../24
303 * fail on: src = 10.1.1.1, ia6->ia_addr = 2002:0b00:.../24
304 */
305 bzero(&a, sizeof(a));
306 a.s_addr = GET_V4(&ia6->ia_addr.sin6_addr)->s_addr;
307 a.s_addr &= GET_V4(&ia6->ia_prefixmask.sin6_addr)->s_addr;
308 b = ip.ip_src;
309 b.s_addr &= GET_V4(&ia6->ia_prefixmask.sin6_addr)->s_addr;
310 if (a.s_addr != b.s_addr)
311 return 0;
312
313 /* stf interface makes single side match only */
314 return 32;
315 }
316
317 static struct in6_ifaddr *
318 stf_getsrcifa6(ifp)
319 struct ifnet *ifp;
320 {
321 struct ifaddr *ia;
322 struct in_ifaddr *ia4;
323 struct sockaddr_in6 *sin6;
324 struct in_addr in;
325
326 #if defined(__bsdi__) || (defined(__FreeBSD__) && __FreeBSD__ < 3)
327 for (ia = ifp->if_addrlist; ia; ia = ia->ifa_next)
328 #else
329 for (ia = ifp->if_addrlist.tqh_first;
330 ia;
331 ia = ia->ifa_list.tqe_next)
332 #endif
333 {
334 if (ia->ifa_addr == NULL)
335 continue;
336 if (ia->ifa_addr->sa_family != AF_INET6)
337 continue;
338 sin6 = (struct sockaddr_in6 *)ia->ifa_addr;
339 if (!IN6_IS_ADDR_6TO4(&sin6->sin6_addr))
340 continue;
341
342 bcopy(GET_V4(&sin6->sin6_addr), &in, sizeof(in));
343 #ifdef __NetBSD__
344 INADDR_TO_IA(in, ia4);
345 #else
346 #ifdef __OpenBSD__
347 for (ia4 = in_ifaddr.tqh_first;
348 ia4;
349 ia4 = ia4->ia_list.tqe_next)
350 #elif defined(__FreeBSD__) && __FreeBSD__ >= 3
351 for (ia4 = TAILQ_FIRST(&in_ifaddrhead);
352 ia4;
353 ia4 = TAILQ_NEXT(ia4, ia_link))
354 #else
355 for (ia4 = in_ifaddr; ia4 != NULL; ia4 = ia4->ia_next)
356 #endif
357 {
358 if (ia4->ia_addr.sin_addr.s_addr == in.s_addr)
359 break;
360 }
361 #endif
362 if (ia4 == NULL)
363 continue;
364
365 return (struct in6_ifaddr *)ia;
366 }
367
368 return NULL;
369 }
370
371 static int
372 stf_output(ifp, m, dst, rt)
373 struct ifnet *ifp;
374 struct mbuf *m;
375 struct sockaddr *dst;
376 struct rtentry *rt;
377 {
378 struct stf_softc *sc;
379 struct sockaddr_in6 *dst6;
380 struct sockaddr_in *dst4;
381 u_int8_t tos;
382 struct ip *ip;
383 struct ip6_hdr *ip6;
384 struct in6_ifaddr *ia6;
385
386 sc = (struct stf_softc*)ifp;
387 dst6 = (struct sockaddr_in6 *)dst;
388
389 /* just in case */
390 if ((ifp->if_flags & IFF_UP) == 0) {
391 m_freem(m);
392 return ENETDOWN;
393 }
394
395 /*
396 * If we don't have an ip4 address that match my inner ip6 address,
397 * we shouldn't generate output. Without this check, we'll end up
398 * using wrong IPv4 source.
399 */
400 ia6 = stf_getsrcifa6(ifp);
401 if (ia6 == NULL) {
402 m_freem(m);
403 return ENETDOWN;
404 }
405
406 if (m->m_len < sizeof(*ip6)) {
407 m = m_pullup(m, sizeof(*ip6));
408 if (!m)
409 return ENOBUFS;
410 }
411 ip6 = mtod(m, struct ip6_hdr *);
412 tos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
413
414 M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);
415 if (m && m->m_len < sizeof(struct ip))
416 m = m_pullup(m, sizeof(struct ip));
417 if (m == NULL)
418 return ENOBUFS;
419 ip = mtod(m, struct ip *);
420
421 bzero(ip, sizeof(*ip));
422
423 bcopy(GET_V4(&((struct sockaddr_in6 *)&ia6->ia_addr)->sin6_addr),
424 &ip->ip_src, sizeof(ip->ip_src));
425 bcopy(GET_V4(&dst6->sin6_addr), &ip->ip_dst, sizeof(ip->ip_dst));
426 ip->ip_p = IPPROTO_IPV6;
427 ip->ip_ttl = ip_gif_ttl; /*XXX*/
428 ip->ip_len = m->m_pkthdr.len; /*host order*/
429 if (ifp->if_flags & IFF_LINK1)
430 ip_ecn_ingress(ECN_ALLOWED, &ip->ip_tos, &tos);
431
432 dst4 = (struct sockaddr_in *)&sc->sc_ro.ro_dst;
433 if (dst4->sin_family != AF_INET ||
434 bcmp(&dst4->sin_addr, &ip->ip_dst, sizeof(ip->ip_dst)) != 0) {
435 /* cache route doesn't match */
436 dst4->sin_family = AF_INET;
437 dst4->sin_len = sizeof(struct sockaddr_in);
438 bcopy(&ip->ip_dst, &dst4->sin_addr, sizeof(dst4->sin_addr));
439 if (sc->sc_ro.ro_rt) {
440 RTFREE(sc->sc_ro.ro_rt);
441 sc->sc_ro.ro_rt = NULL;
442 }
443 }
444
445 if (sc->sc_ro.ro_rt == NULL) {
446 rtalloc(&sc->sc_ro);
447 if (sc->sc_ro.ro_rt == NULL) {
448 m_freem(m);
449 return ENETUNREACH;
450 }
451 }
452
453 #ifndef __OpenBSD__
454 return ip_output(m, NULL, &sc->sc_ro, 0, NULL);
455 #else
456 return ip_output(m, NULL, &sc->sc_ro, 0, NULL, NULL);
457 #endif
458 }
459
460 static int
461 stf_checkaddr4(in, ifp)
462 struct in_addr *in;
463 struct ifnet *ifp; /* incoming interface */
464 {
465 struct in_ifaddr *ia4;
466
467 /*
468 * reject packets with the following address:
469 * 224.0.0.0/4 0.0.0.0/8 127.0.0.0/8 255.0.0.0/8
470 */
471 if (IN_MULTICAST(in->s_addr))
472 return -1;
473 switch ((ntohl(in->s_addr) & 0xff000000) >> 24) {
474 case 0: case 127: case 255:
475 return -1;
476 }
477
478 /*
479 * reject packets with broadcast
480 */
481 #if defined(__OpenBSD__) || defined(__NetBSD__)
482 for (ia4 = in_ifaddr.tqh_first; ia4; ia4 = ia4->ia_list.tqe_next)
483 #elif defined(__FreeBSD__) && __FreeBSD__ >= 3
484 for (ia4 = TAILQ_FIRST(&in_ifaddrhead);
485 ia4;
486 ia4 = TAILQ_NEXT(ia4, ia_link))
487 #else
488 for (ia4 = in_ifaddr; ia4 != NULL; ia4 = ia4->ia_next)
489 #endif
490 {
491 if ((ia4->ia_ifa.ifa_ifp->if_flags & IFF_BROADCAST) == 0)
492 continue;
493 if (in->s_addr == ia4->ia_broadaddr.sin_addr.s_addr)
494 return -1;
495 }
496
497 /*
498 * perform ingress filter
499 */
500 if (ifp) {
501 struct sockaddr_in sin;
502 struct rtentry *rt;
503
504 bzero(&sin, sizeof(sin));
505 sin.sin_family = AF_INET;
506 sin.sin_len = sizeof(struct sockaddr_in);
507 sin.sin_addr = *in;
508 #ifdef __FreeBSD__
509 rt = rtalloc1((struct sockaddr *)&sin, 0, 0UL);
510 #else
511 rt = rtalloc1((struct sockaddr *)&sin, 0);
512 #endif
513 if (!rt)
514 return -1;
515 if (rt->rt_ifp != ifp) {
516 rtfree(rt);
517 return -1;
518 }
519 rtfree(rt);
520 }
521
522 return 0;
523 }
524
525 static int
526 stf_checkaddr6(in6, ifp)
527 struct in6_addr *in6;
528 struct ifnet *ifp; /* incoming interface */
529 {
530 /*
531 * check 6to4 addresses
532 */
533 if (IN6_IS_ADDR_6TO4(in6))
534 return stf_checkaddr4(GET_V4(in6), ifp);
535
536 /*
537 * reject anything that look suspicious. the test is implemented
538 * in ip6_input too, but we check here as well to
539 * (1) reject bad packets earlier, and
540 * (2) to be safe against future ip6_input change.
541 */
542 if (IN6_IS_ADDR_V4COMPAT(in6) || IN6_IS_ADDR_V4MAPPED(in6))
543 return -1;
544
545 return 0;
546 }
547
548 void
549 #if __STDC__
550 in_stf_input(struct mbuf *m, ...)
551 #else
552 in_stf_input(m, va_alist)
553 register struct mbuf *m;
554 #endif
555 {
556 int off, proto;
557 struct stf_softc *sc;
558 struct ip *ip;
559 struct ip6_hdr *ip6;
560 u_int8_t otos, itos;
561 int s, isr;
562 struct ifqueue *ifq = NULL;
563 struct ifnet *ifp;
564 va_list ap;
565
566 va_start(ap, m);
567 off = va_arg(ap, int);
568 proto = va_arg(ap, int);
569 va_end(ap);
570
571 if (proto != IPPROTO_IPV6) {
572 m_freem(m);
573 return;
574 }
575
576 ip = mtod(m, struct ip *);
577
578 sc = (struct stf_softc *)encap_getarg(m);
579
580 if (sc == NULL || (sc->sc_if.if_flags & IFF_UP) == 0) {
581 m_freem(m);
582 return;
583 }
584
585 ifp = &sc->sc_if;
586
587 /*
588 * perform sanity check against outer src/dst.
589 * for source, perform ingress filter as well.
590 */
591 if (stf_checkaddr4(&ip->ip_dst, NULL) < 0 ||
592 stf_checkaddr4(&ip->ip_src, m->m_pkthdr.rcvif) < 0) {
593 m_freem(m);
594 return;
595 }
596
597 otos = ip->ip_tos;
598 m_adj(m, off);
599
600 if (m->m_len < sizeof(*ip6)) {
601 m = m_pullup(m, sizeof(*ip6));
602 if (!m)
603 return;
604 }
605 ip6 = mtod(m, struct ip6_hdr *);
606
607 /*
608 * perform sanity check against inner src/dst.
609 * for source, perform ingress filter as well.
610 */
611 if (stf_checkaddr6(&ip6->ip6_dst, NULL) < 0 ||
612 stf_checkaddr6(&ip6->ip6_src, m->m_pkthdr.rcvif) < 0) {
613 m_freem(m);
614 return;
615 }
616
617 itos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
618 if ((ifp->if_flags & IFF_LINK1) != 0)
619 ip_ecn_egress(ECN_ALLOWED, &otos, &itos);
620 ip6->ip6_flow &= ~htonl(0xff << 20);
621 ip6->ip6_flow |= htonl((u_int32_t)itos << 20);
622
623 m->m_pkthdr.rcvif = ifp;
624
625 #if NBPFILTER > 0
626 if (ifp->if_bpf) {
627 /*
628 * We need to prepend the address family as
629 * a four byte field. Cons up a dummy header
630 * to pacify bpf. This is safe because bpf
631 * will only read from the mbuf (i.e., it won't
632 * try to free it or keep a pointer a to it).
633 */
634 struct mbuf m0;
635 u_int af = AF_INET6;
636
637 m0.m_next = m;
638 m0.m_len = 4;
639 m0.m_data = (char *)⁡
640
641 #ifdef HAVE_OLD_BPF
642 bpf_mtap(ifp, &m0);
643 #else
644 bpf_mtap(ifp->if_bpf, &m0);
645 #endif
646 }
647 #endif /*NBPFILTER > 0*/
648
649 /*
650 * Put the packet to the network layer input queue according to the
651 * specified address family.
652 * See net/if_gif.c for possible issues with packet processing
653 * reorder due to extra queueing.
654 */
655 ifq = &ip6intrq;
656 isr = NETISR_IPV6;
657
658 s = splimp();
659 if (IF_QFULL(ifq)) {
660 IF_DROP(ifq); /* update statistics */
661 m_freem(m);
662 splx(s);
663 return;
664 }
665 IF_ENQUEUE(ifq, m);
666 schednetisr(isr);
667 ifp->if_ipackets++;
668 ifp->if_ibytes += m->m_pkthdr.len;
669 splx(s);
670 }
671
672 /* ARGSUSED */
673 static void
674 stf_rtrequest(cmd, rt, sa)
675 int cmd;
676 struct rtentry *rt;
677 #if defined(__bsdi__) && _BSDI_VERSION >= 199802
678 struct rt_addrinfo *sa;
679 #else
680 struct sockaddr *sa;
681 #endif
682 {
683
684 if (rt)
685 rt->rt_rmx.rmx_mtu = IPV6_MMTU;
686 }
687
688 static int
689 stf_ioctl(ifp, cmd, data)
690 struct ifnet *ifp;
691 #if defined(__FreeBSD__) && __FreeBSD__ < 3
692 int cmd;
693 #else
694 u_long cmd;
695 #endif
696 caddr_t data;
697 {
698 struct ifaddr *ifa;
699 struct ifreq *ifr;
700 struct sockaddr_in6 *sin6;
701 int error;
702
703 error = 0;
704 switch (cmd) {
705 case SIOCSIFADDR:
706 ifa = (struct ifaddr *)data;
707 if (ifa == NULL || ifa->ifa_addr->sa_family != AF_INET6) {
708 error = EAFNOSUPPORT;
709 break;
710 }
711 sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
712 if (IN6_IS_ADDR_6TO4(&sin6->sin6_addr)) {
713 ifa->ifa_rtrequest = stf_rtrequest;
714 ifp->if_flags |= IFF_UP;
715 } else
716 error = EINVAL;
717 break;
718
719 case SIOCADDMULTI:
720 case SIOCDELMULTI:
721 ifr = (struct ifreq *)data;
722 if (ifr && ifr->ifr_addr.sa_family == AF_INET6)
723 ;
724 else
725 error = EAFNOSUPPORT;
726 break;
727
728 default:
729 error = EINVAL;
730 break;
731 }
732
733 return error;
734 }
735
736 #endif /* NSTF > 0 */
737