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