1 /*
2 * Copyright (c) 1998, Larry Lile
3 * All rights reserved.
4 *
5 * For latest sources and information on this driver, please
6 * go to http://anarchy.stdio.com.
7 *
8 * Questions, comments or suggestions should be directed to
9 * Larry Lile <lile@stdio.com>.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice unmodified, this list of conditions, and the following
16 * disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * $FreeBSD: releng/5.2/sys/net/if_iso88025subr.c 122702 2003-11-14 21:02:22Z andre $
34 *
35 */
36
37 /*
38 *
39 * General ISO 802.5 (Token Ring) support routines
40 *
41 */
42
43 #include "opt_inet.h"
44 #include "opt_inet6.h"
45 #include "opt_ipx.h"
46 #include "opt_mac.h"
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/kernel.h>
51 #include <sys/mac.h>
52 #include <sys/malloc.h>
53 #include <sys/mbuf.h>
54 #include <sys/module.h>
55 #include <sys/socket.h>
56 #include <sys/sockio.h>
57
58 #include <net/if.h>
59 #include <net/if_dl.h>
60 #include <net/if_llc.h>
61 #include <net/if_types.h>
62
63 #include <net/netisr.h>
64 #include <net/route.h>
65 #include <net/bpf.h>
66 #include <net/iso88025.h>
67
68 #if defined(INET) || defined(INET6)
69 #include <netinet/in.h>
70 #include <netinet/in_var.h>
71 #include <netinet/if_ether.h>
72 #endif
73 #ifdef INET6
74 #include <netinet6/nd6.h>
75 #endif
76
77 #ifdef IPX
78 #include <netipx/ipx.h>
79 #include <netipx/ipx_if.h>
80 #endif
81
82 static u_char iso88025_broadcastaddr[ISO88025_ADDR_LEN] =
83 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
84
85 static int iso88025_resolvemulti (struct ifnet *, struct sockaddr **,
86 struct sockaddr *);
87
88 #define IFP2AC(IFP) ((struct arpcom *)IFP)
89 #define senderr(e) do { error = (e); goto bad; } while (0)
90
91 /*
92 * Perform common duties while attaching to interface list
93 */
94 void
95 iso88025_ifattach(struct ifnet *ifp, int bpf)
96 {
97 struct ifaddr *ifa;
98 struct sockaddr_dl *sdl;
99
100 ifa = NULL;
101
102 ifp->if_type = IFT_ISO88025;
103 ifp->if_addrlen = ISO88025_ADDR_LEN;
104 ifp->if_hdrlen = ISO88025_HDR_LEN;
105
106 if_attach(ifp); /* Must be called before additional assignments */
107
108 ifp->if_output = iso88025_output;
109 ifp->if_input = iso88025_input;
110 ifp->if_resolvemulti = iso88025_resolvemulti;
111 ifp->if_broadcastaddr = iso88025_broadcastaddr;
112
113 if (ifp->if_baudrate == 0)
114 ifp->if_baudrate = TR_16MBPS; /* 16Mbit should be a safe default */
115 if (ifp->if_mtu == 0)
116 ifp->if_mtu = ISO88025_DEFAULT_MTU;
117
118 ifa = ifaddr_byindex(ifp->if_index);
119 if (ifa == 0) {
120 if_printf(ifp, "%s() no lladdr!\n", __func__);
121 return;
122 }
123
124 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
125 sdl->sdl_type = IFT_ISO88025;
126 sdl->sdl_alen = ifp->if_addrlen;
127 bcopy(IFP2AC(ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen);
128
129 if (bpf)
130 bpfattach(ifp, DLT_IEEE802, ISO88025_HDR_LEN);
131
132 return;
133 }
134
135 /*
136 * Perform common duties while detaching a Token Ring interface
137 */
138 void
139 iso88025_ifdetach(ifp, bpf)
140 struct ifnet *ifp;
141 int bpf;
142 {
143
144 if (bpf)
145 bpfdetach(ifp);
146
147 if_detach(ifp);
148
149 return;
150 }
151
152 int
153 iso88025_ioctl(struct ifnet *ifp, int command, caddr_t data)
154 {
155 struct ifaddr *ifa;
156 struct ifreq *ifr;
157 int error;
158
159 ifa = (struct ifaddr *) data;
160 ifr = (struct ifreq *) data;
161 error = 0;
162
163 switch (command) {
164 case SIOCSIFADDR:
165 ifp->if_flags |= IFF_UP;
166
167 switch (ifa->ifa_addr->sa_family) {
168 #ifdef INET
169 case AF_INET:
170 ifp->if_init(ifp->if_softc); /* before arpwhohas */
171 arp_ifinit(ifp, ifa);
172 break;
173 #endif /* INET */
174 #ifdef IPX
175 /*
176 * XXX - This code is probably wrong
177 */
178 case AF_IPX: {
179 struct ipx_addr *ina;
180 struct arpcom *ac;
181
182 ina = &(IA_SIPX(ifa)->sipx_addr);
183 ac = IFP2AC(ifp);
184
185 if (ipx_nullhost(*ina))
186 ina->x_host = *(union ipx_host *)
187 ac->ac_enaddr;
188 else
189 bcopy((caddr_t) ina->x_host.c_host,
190 (caddr_t) ac->ac_enaddr,
191 ISO88025_ADDR_LEN);
192
193 /*
194 * Set new address
195 */
196 ifp->if_init(ifp->if_softc);
197 }
198 break;
199 #endif /* IPX */
200 default:
201 ifp->if_init(ifp->if_softc);
202 break;
203 }
204 break;
205
206 case SIOCGIFADDR: {
207 struct sockaddr *sa;
208
209 sa = (struct sockaddr *) & ifr->ifr_data;
210 bcopy(IFP2AC(ifp)->ac_enaddr,
211 (caddr_t) sa->sa_data, ISO88025_ADDR_LEN);
212 }
213 break;
214
215 case SIOCSIFMTU:
216 /*
217 * Set the interface MTU.
218 */
219 if (ifr->ifr_mtu > ISO88025_MAX_MTU) {
220 error = EINVAL;
221 } else {
222 ifp->if_mtu = ifr->ifr_mtu;
223 }
224 break;
225 default:
226 error = EINVAL; /* XXX netbsd has ENOTTY??? */
227 break;
228 }
229
230 return (error);
231 }
232
233 /*
234 * ISO88025 encapsulation
235 */
236 int
237 iso88025_output(ifp, m, dst, rt0)
238 struct ifnet *ifp;
239 struct mbuf *m;
240 struct sockaddr *dst;
241 struct rtentry *rt0;
242 {
243 u_int16_t snap_type = 0;
244 int loop_copy = 0, error = 0, rif_len = 0;
245 u_char edst[ISO88025_ADDR_LEN];
246 struct iso88025_header *th;
247 struct iso88025_header gen_th;
248 struct sockaddr_dl *sdl = NULL;
249 struct rtentry *rt;
250 struct arpcom *ac = IFP2AC(ifp);
251
252 #ifdef MAC
253 error = mac_check_ifnet_transmit(ifp, m);
254 if (error)
255 senderr(error);
256 #endif
257
258 if (ifp->if_flags & IFF_MONITOR)
259 senderr(ENETDOWN);
260 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
261 senderr(ENETDOWN);
262 getmicrotime(&ifp->if_lastchange);
263
264 error = rt_check(&rt, &rt0, dst);
265 if (error)
266 goto bad;
267
268 /* Calculate routing info length based on arp table entry */
269 if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway))
270 if (SDL_ISO88025(sdl)->trld_rcf != 0)
271 rif_len = TR_RCF_RIFLEN(SDL_ISO88025(sdl)->trld_rcf);
272
273 /* Generate a generic 802.5 header for the packet */
274 gen_th.ac = TR_AC;
275 gen_th.fc = TR_LLC_FRAME;
276 (void)memcpy((caddr_t)gen_th.iso88025_shost, (caddr_t)ac->ac_enaddr,
277 ISO88025_ADDR_LEN);
278 if (rif_len) {
279 gen_th.iso88025_shost[0] |= TR_RII;
280 if (rif_len > 2) {
281 gen_th.rcf = SDL_ISO88025(sdl)->trld_rcf;
282 (void)memcpy((caddr_t)gen_th.rd,
283 (caddr_t)SDL_ISO88025(sdl)->trld_route,
284 rif_len - 2);
285 }
286 }
287
288 switch (dst->sa_family) {
289 #ifdef INET
290 case AF_INET:
291 if (!arpresolve(ifp, rt, m, dst, edst, rt0))
292 return (0); /* if not yet resolved */
293 snap_type = ETHERTYPE_IP;
294 break;
295 #endif /* INET */
296 #ifdef INET6
297 case AF_INET6:
298 if (!nd6_storelladdr(&ac->ac_if, rt, m, dst, (u_char *)edst)) {
299 /* Something bad happened */
300 return(0);
301 }
302 snap_type = ETHERTYPE_IPV6;
303 break;
304 #endif /* INET6 */
305 #ifdef IPX
306 case AF_IPX:
307 {
308 u_int8_t *cp;
309
310 bcopy((caddr_t)&(satoipx_addr(dst).x_host), (caddr_t)edst,
311 ISO88025_ADDR_LEN);
312
313 M_PREPEND(m, 3, M_TRYWAIT);
314 if (m == 0)
315 senderr(ENOBUFS);
316 m = m_pullup(m, 3);
317 if (m == 0)
318 senderr(ENOBUFS);
319 cp = mtod(m, u_int8_t *);
320 *cp++ = ETHERTYPE_IPX_8022;
321 *cp++ = ETHERTYPE_IPX_8022;
322 *cp++ = LLC_UI;
323 }
324 break;
325 #endif /* IPX */
326 case AF_UNSPEC:
327 {
328 struct iso88025_sockaddr_data *sd;
329 /*
330 * For AF_UNSPEC sockaddr.sa_data must contain all of the
331 * mac information needed to send the packet. This allows
332 * full mac, llc, and source routing function to be controlled.
333 * llc and source routing information must already be in the
334 * mbuf provided, ac/fc are set in sa_data. sockaddr.sa_data
335 * should be an iso88025_sockaddr_data structure see iso88025.h
336 */
337 loop_copy = -1;
338 sd = (struct iso88025_sockaddr_data *)dst->sa_data;
339 gen_th.ac = sd->ac;
340 gen_th.fc = sd->fc;
341 (void)memcpy((caddr_t)edst, (caddr_t)sd->ether_dhost,
342 ISO88025_ADDR_LEN);
343 (void)memcpy((caddr_t)gen_th.iso88025_shost,
344 (caddr_t)sd->ether_shost, ISO88025_ADDR_LEN);
345 rif_len = 0;
346 break;
347 }
348 default:
349 if_printf(ifp, "can't handle af%d\n", dst->sa_family);
350 senderr(EAFNOSUPPORT);
351 break;
352 }
353
354 /*
355 * Add LLC header.
356 */
357 if (snap_type != 0) {
358 struct llc *l;
359 M_PREPEND(m, LLC_SNAPFRAMELEN, M_DONTWAIT);
360 if (m == 0)
361 senderr(ENOBUFS);
362 l = mtod(m, struct llc *);
363 l->llc_control = LLC_UI;
364 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
365 l->llc_snap.org_code[0] =
366 l->llc_snap.org_code[1] =
367 l->llc_snap.org_code[2] = 0;
368 l->llc_snap.ether_type = htons(snap_type);
369 }
370
371 /*
372 * Add local net header. If no space in first mbuf,
373 * allocate another.
374 */
375 M_PREPEND(m, ISO88025_HDR_LEN + rif_len, M_DONTWAIT);
376 if (m == 0)
377 senderr(ENOBUFS);
378 th = mtod(m, struct iso88025_header *);
379 bcopy((caddr_t)edst, (caddr_t)&gen_th.iso88025_dhost, ISO88025_ADDR_LEN);
380
381 /* Copy as much of the generic header as is needed into the mbuf */
382 memcpy(th, &gen_th, ISO88025_HDR_LEN + rif_len);
383
384 /*
385 * If a simplex interface, and the packet is being sent to our
386 * Ethernet address or a broadcast address, loopback a copy.
387 * XXX To make a simplex device behave exactly like a duplex
388 * device, we should copy in the case of sending to our own
389 * ethernet address (thus letting the original actually appear
390 * on the wire). However, we don't do that here for security
391 * reasons and compatibility with the original behavior.
392 */
393 if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) {
394 if ((m->m_flags & M_BCAST) || (loop_copy > 0)) {
395 struct mbuf *n;
396 n = m_copy(m, 0, (int)M_COPYALL);
397 (void) if_simloop(ifp, n, dst->sa_family,
398 ISO88025_HDR_LEN);
399 } else if (bcmp(th->iso88025_dhost, th->iso88025_shost,
400 ETHER_ADDR_LEN) == 0) {
401 (void) if_simloop(ifp, m, dst->sa_family,
402 ISO88025_HDR_LEN);
403 return(0); /* XXX */
404 }
405 }
406
407 if (! IF_HANDOFF_ADJ(&ifp->if_snd, m, ifp, ISO88025_HDR_LEN + LLC_SNAPFRAMELEN) ) {
408 printf("iso88025_output: packet dropped QFULL.\n");
409 senderr(ENOBUFS);
410 }
411 return (error);
412
413 bad:
414 ifp->if_oerrors++;
415 if (m)
416 m_freem(m);
417 return (error);
418 }
419
420 /*
421 * ISO 88025 de-encapsulation
422 */
423 void
424 iso88025_input(ifp, m)
425 struct ifnet *ifp;
426 struct mbuf *m;
427 {
428 struct iso88025_header *th;
429 struct llc *l;
430 int isr;
431 int mac_hdr_len;
432
433 /*
434 * Do consistency checks to verify assumptions
435 * made by code past this point.
436 */
437 if ((m->m_flags & M_PKTHDR) == 0) {
438 if_printf(ifp, "discard frame w/o packet header\n");
439 ifp->if_ierrors++;
440 m_freem(m);
441 return;
442 }
443 if (m->m_pkthdr.rcvif == NULL) {
444 if_printf(ifp, "discard frame w/o interface pointer\n");
445 ifp->if_ierrors++;
446 m_freem(m);
447 return;
448 }
449
450 m = m_pullup(m, ISO88025_HDR_LEN);
451 if (m == NULL) {
452 ifp->if_ierrors++;
453 goto dropanyway;
454 }
455 th = mtod(m, struct iso88025_header *);
456 m->m_pkthdr.header = (void *)th;
457
458 /*
459 * Discard packet if interface is not up.
460 */
461 if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING))
462 goto dropanyway;
463
464 /*
465 * Give bpf a chance at the packet.
466 */
467 BPF_MTAP(ifp, m);
468
469 /*
470 * Interface marked for monitoring; discard packet.
471 */
472 if (ifp->if_flags & IFF_MONITOR) {
473 m_freem(m);
474 return;
475 }
476
477 #ifdef MAC
478 mac_create_mbuf_from_ifnet(ifp, m);
479 #endif
480
481 /*
482 * Update interface statistics.
483 */
484 ifp->if_ibytes += m->m_pkthdr.len;
485 getmicrotime(&ifp->if_lastchange);
486
487 /*
488 * Discard non local unicast packets when interface
489 * is in promiscuous mode.
490 */
491 if ((ifp->if_flags & IFF_PROMISC) &&
492 ((th->iso88025_dhost[0] & 1) == 0) &&
493 (bcmp(IFP2AC(ifp)->ac_enaddr, (caddr_t) th->iso88025_dhost,
494 ISO88025_ADDR_LEN) != 0))
495 goto dropanyway;
496
497 /*
498 * Set mbuf flags for bcast/mcast.
499 */
500 if (th->iso88025_dhost[0] & 1) {
501 if (bcmp((caddr_t)iso88025_broadcastaddr,
502 (caddr_t)th->iso88025_dhost, ISO88025_ADDR_LEN) == 0)
503 m->m_flags |= M_BCAST;
504 else
505 m->m_flags |= M_MCAST;
506 ifp->if_imcasts++;
507 }
508
509 mac_hdr_len = ISO88025_HDR_LEN;
510 /* Check for source routing info */
511 if (th->iso88025_shost[0] & TR_RII)
512 mac_hdr_len += TR_RCF_RIFLEN(th->rcf);
513
514 /* Strip off ISO88025 header. */
515 m_adj(m, mac_hdr_len);
516
517 m = m_pullup(m, LLC_SNAPFRAMELEN);
518 if (m == 0) {
519 ifp->if_ierrors++;
520 goto dropanyway;
521 }
522 l = mtod(m, struct llc *);
523
524 switch (l->llc_dsap) {
525 #ifdef IPX
526 case ETHERTYPE_IPX_8022: /* Thanks a bunch Novell */
527 if ((l->llc_control != LLC_UI) ||
528 (l->llc_ssap != ETHERTYPE_IPX_8022)) {
529 ifp->if_noproto++;
530 goto dropanyway;
531 }
532
533 th->iso88025_shost[0] &= ~(TR_RII);
534 m_adj(m, 3);
535 isr = NETISR_IPX;
536 break;
537 #endif /* IPX */
538 case LLC_SNAP_LSAP: {
539 u_int16_t type;
540 if ((l->llc_control != LLC_UI) ||
541 (l->llc_ssap != LLC_SNAP_LSAP)) {
542 ifp->if_noproto++;
543 goto dropanyway;
544 }
545
546 if (l->llc_snap.org_code[0] != 0 ||
547 l->llc_snap.org_code[1] != 0 ||
548 l->llc_snap.org_code[2] != 0) {
549 ifp->if_noproto++;
550 goto dropanyway;
551 }
552
553 type = ntohs(l->llc_snap.ether_type);
554 m_adj(m, LLC_SNAPFRAMELEN);
555 switch (type) {
556 #ifdef INET
557 case ETHERTYPE_IP:
558 th->iso88025_shost[0] &= ~(TR_RII);
559 if (ip_fastforward(m))
560 return;
561 isr = NETISR_IP;
562 break;
563
564 case ETHERTYPE_ARP:
565 if (ifp->if_flags & IFF_NOARP)
566 goto dropanyway;
567 isr = NETISR_ARP;
568 break;
569 #endif /* INET */
570 #ifdef IPX_SNAP /* XXX: Not supported! */
571 case ETHERTYPE_IPX:
572 th->iso88025_shost[0] &= ~(TR_RII);
573 isr = NETISR_IPX;
574 break;
575 #endif /* IPX_SNAP */
576 #ifdef INET6
577 case ETHERTYPE_IPV6:
578 th->iso88025_shost[0] &= ~(TR_RII);
579 isr = NETISR_IPV6;
580 break;
581 #endif /* INET6 */
582 default:
583 printf("iso88025_input: unexpected llc_snap ether_type 0x%02x\n", type);
584 ifp->if_noproto++;
585 goto dropanyway;
586 }
587 break;
588 }
589 #ifdef ISO
590 case LLC_ISO_LSAP:
591 switch (l->llc_control) {
592 case LLC_UI:
593 ifp->if_noproto++;
594 goto dropanyway;
595 break;
596 case LLC_XID:
597 case LLC_XID_P:
598 if(m->m_len < ISO88025_ADDR_LEN)
599 goto dropanyway;
600 l->llc_window = 0;
601 l->llc_fid = 9;
602 l->llc_class = 1;
603 l->llc_dsap = l->llc_ssap = 0;
604 /* Fall through to */
605 case LLC_TEST:
606 case LLC_TEST_P:
607 {
608 struct sockaddr sa;
609 struct arpcom *ac;
610 struct iso88025_sockaddr_data *th2;
611 int i;
612 u_char c;
613
614 ac = IFP2AC(ifp);
615 c = l->llc_dsap;
616
617 if (th->iso88025_shost[0] & TR_RII) { /* XXX */
618 printf("iso88025_input: dropping source routed LLC_TEST\n");
619 goto dropanyway;
620 }
621 l->llc_dsap = l->llc_ssap;
622 l->llc_ssap = c;
623 if (m->m_flags & (M_BCAST | M_MCAST))
624 bcopy((caddr_t)ac->ac_enaddr,
625 (caddr_t)th->iso88025_dhost,
626 ISO88025_ADDR_LEN);
627 sa.sa_family = AF_UNSPEC;
628 sa.sa_len = sizeof(sa);
629 th2 = (struct iso88025_sockaddr_data *)sa.sa_data;
630 for (i = 0; i < ISO88025_ADDR_LEN; i++) {
631 th2->ether_shost[i] = c = th->iso88025_dhost[i];
632 th2->ether_dhost[i] = th->iso88025_dhost[i] =
633 th->iso88025_shost[i];
634 th->iso88025_shost[i] = c;
635 }
636 th2->ac = TR_AC;
637 th2->fc = TR_LLC_FRAME;
638 ifp->if_output(ifp, m, &sa, NULL);
639 return;
640 }
641 default:
642 printf("iso88025_input: unexpected llc control 0x%02x\n", l->llc_control);
643 ifp->if_noproto++;
644 goto dropanyway;
645 break;
646 }
647 break;
648 #endif /* ISO */
649 default:
650 printf("iso88025_input: unknown dsap 0x%x\n", l->llc_dsap);
651 ifp->if_noproto++;
652 goto dropanyway;
653 break;
654 }
655
656 netisr_dispatch(isr, m);
657 return;
658
659 dropanyway:
660 ifp->if_iqdrops++;
661 if (m)
662 m_freem(m);
663 return;
664 }
665
666 static int
667 iso88025_resolvemulti (ifp, llsa, sa)
668 struct ifnet *ifp;
669 struct sockaddr **llsa;
670 struct sockaddr *sa;
671 {
672 struct sockaddr_dl *sdl;
673 struct sockaddr_in *sin;
674 #ifdef INET6
675 struct sockaddr_in6 *sin6;
676 #endif
677 u_char *e_addr;
678
679 switch(sa->sa_family) {
680 case AF_LINK:
681 /*
682 * No mapping needed. Just check that it's a valid MC address.
683 */
684 sdl = (struct sockaddr_dl *)sa;
685 e_addr = LLADDR(sdl);
686 if ((e_addr[0] & 1) != 1) {
687 return (EADDRNOTAVAIL);
688 }
689 *llsa = 0;
690 return (0);
691
692 #ifdef INET
693 case AF_INET:
694 sin = (struct sockaddr_in *)sa;
695 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) {
696 return (EADDRNOTAVAIL);
697 }
698 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
699 M_WAITOK|M_ZERO);
700 sdl->sdl_len = sizeof *sdl;
701 sdl->sdl_family = AF_LINK;
702 sdl->sdl_index = ifp->if_index;
703 sdl->sdl_type = IFT_ISO88025;
704 sdl->sdl_alen = ISO88025_ADDR_LEN;
705 e_addr = LLADDR(sdl);
706 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr);
707 *llsa = (struct sockaddr *)sdl;
708 return (0);
709 #endif
710 #ifdef INET6
711 case AF_INET6:
712 sin6 = (struct sockaddr_in6 *)sa;
713 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
714 /*
715 * An IP6 address of 0 means listen to all
716 * of the Ethernet multicast address used for IP6.
717 * (This is used for multicast routers.)
718 */
719 ifp->if_flags |= IFF_ALLMULTI;
720 *llsa = 0;
721 return (0);
722 }
723 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
724 return (EADDRNOTAVAIL);
725 }
726 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
727 M_WAITOK|M_ZERO);
728 sdl->sdl_len = sizeof *sdl;
729 sdl->sdl_family = AF_LINK;
730 sdl->sdl_index = ifp->if_index;
731 sdl->sdl_type = IFT_ISO88025;
732 sdl->sdl_alen = ISO88025_ADDR_LEN;
733 e_addr = LLADDR(sdl);
734 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
735 *llsa = (struct sockaddr *)sdl;
736 return (0);
737 #endif
738
739 default:
740 /*
741 * Well, the text isn't quite right, but it's the name
742 * that counts...
743 */
744 return (EAFNOSUPPORT);
745 }
746
747 return (0);
748 }
749
750 static moduledata_t iso88025_mod = {
751 "iso88025",
752 NULL,
753 0
754 };
755
756 DECLARE_MODULE(iso88025, iso88025_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
757 MODULE_VERSION(iso88025, 1);
Cache object: d138583a1384aaafa0d8cc522f8bb176
|