FreeBSD/Linux Kernel Cross Reference
sys/net/if_fddisubr.c
1 /*-
2 * Copyright (c) 1995, 1996
3 * Matt Thomas <matt@3am-software.com>. All rights reserved.
4 * Copyright (c) 1982, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
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. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * from: if_ethersubr.c,v 1.5 1994/12/13 22:31:45 wollman Exp
36 * $FreeBSD: releng/7.4/sys/net/if_fddisubr.c 163606 2006-10-22 11:52:19Z rwatson $
37 */
38
39 #include "opt_atalk.h"
40 #include "opt_inet.h"
41 #include "opt_inet6.h"
42 #include "opt_ipx.h"
43 #include "opt_mac.h"
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
48 #include <sys/malloc.h>
49 #include <sys/mbuf.h>
50 #include <sys/module.h>
51 #include <sys/socket.h>
52 #include <sys/sockio.h>
53
54 #include <net/if.h>
55 #include <net/if_dl.h>
56 #include <net/if_llc.h>
57 #include <net/if_types.h>
58
59 #include <net/netisr.h>
60 #include <net/route.h>
61 #include <net/bpf.h>
62 #include <net/fddi.h>
63
64 #if defined(INET) || defined(INET6)
65 #include <netinet/in.h>
66 #include <netinet/in_var.h>
67 #include <netinet/if_ether.h>
68 #endif
69 #ifdef INET6
70 #include <netinet6/nd6.h>
71 #endif
72
73 #ifdef IPX
74 #include <netipx/ipx.h>
75 #include <netipx/ipx_if.h>
76 #endif
77
78 #ifdef DECNET
79 #include <netdnet/dn.h>
80 #endif
81
82 #ifdef NETATALK
83 #include <netatalk/at.h>
84 #include <netatalk/at_var.h>
85 #include <netatalk/at_extern.h>
86
87 extern u_char at_org_code[ 3 ];
88 extern u_char aarp_org_code[ 3 ];
89 #endif /* NETATALK */
90
91 #include <security/mac/mac_framework.h>
92
93 static const u_char fddibroadcastaddr[FDDI_ADDR_LEN] =
94 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
95
96 static int fddi_resolvemulti(struct ifnet *, struct sockaddr **,
97 struct sockaddr *);
98 static int fddi_output(struct ifnet *, struct mbuf *, struct sockaddr *,
99 struct rtentry *);
100 static void fddi_input(struct ifnet *ifp, struct mbuf *m);
101
102 #define senderr(e) do { error = (e); goto bad; } while (0)
103
104 /*
105 * FDDI output routine.
106 * Encapsulate a packet of type family for the local net.
107 * Use trailer local net encapsulation if enough data in first
108 * packet leaves a multiple of 512 bytes of data in remainder.
109 * Assumes that ifp is actually pointer to arpcom structure.
110 */
111 static int
112 fddi_output(ifp, m, dst, rt0)
113 struct ifnet *ifp;
114 struct mbuf *m;
115 struct sockaddr *dst;
116 struct rtentry *rt0;
117 {
118 u_int16_t type;
119 int loop_copy = 0, error = 0, hdrcmplt = 0;
120 u_char esrc[FDDI_ADDR_LEN], edst[FDDI_ADDR_LEN];
121 struct fddi_header *fh;
122
123 #ifdef MAC
124 error = mac_check_ifnet_transmit(ifp, m);
125 if (error)
126 senderr(error);
127 #endif
128
129 if (ifp->if_flags & IFF_MONITOR)
130 senderr(ENETDOWN);
131 if (!((ifp->if_flags & IFF_UP) &&
132 (ifp->if_drv_flags & IFF_DRV_RUNNING)))
133 senderr(ENETDOWN);
134 getmicrotime(&ifp->if_lastchange);
135
136 switch (dst->sa_family) {
137 #ifdef INET
138 case AF_INET: {
139 error = arpresolve(ifp, rt0, m, dst, edst);
140 if (error)
141 return (error == EWOULDBLOCK ? 0 : error);
142 type = htons(ETHERTYPE_IP);
143 break;
144 }
145 case AF_ARP:
146 {
147 struct arphdr *ah;
148 ah = mtod(m, struct arphdr *);
149 ah->ar_hrd = htons(ARPHRD_ETHER);
150
151 loop_copy = -1; /* if this is for us, don't do it */
152
153 switch (ntohs(ah->ar_op)) {
154 case ARPOP_REVREQUEST:
155 case ARPOP_REVREPLY:
156 type = htons(ETHERTYPE_REVARP);
157 break;
158 case ARPOP_REQUEST:
159 case ARPOP_REPLY:
160 default:
161 type = htons(ETHERTYPE_ARP);
162 break;
163 }
164
165 if (m->m_flags & M_BCAST)
166 bcopy(ifp->if_broadcastaddr, edst, FDDI_ADDR_LEN);
167 else
168 bcopy(ar_tha(ah), edst, FDDI_ADDR_LEN);
169
170 }
171 break;
172 #endif /* INET */
173 #ifdef INET6
174 case AF_INET6:
175 error = nd6_storelladdr(ifp, rt0, m, dst, (u_char *)edst);
176 if (error)
177 return (error); /* Something bad happened */
178 type = htons(ETHERTYPE_IPV6);
179 break;
180 #endif /* INET6 */
181 #ifdef IPX
182 case AF_IPX:
183 type = htons(ETHERTYPE_IPX);
184 bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host),
185 (caddr_t)edst, FDDI_ADDR_LEN);
186 break;
187 #endif /* IPX */
188 #ifdef NETATALK
189 case AF_APPLETALK: {
190 struct at_ifaddr *aa;
191 if (!aarpresolve(ifp, m, (struct sockaddr_at *)dst, edst))
192 return (0);
193 /*
194 * ifaddr is the first thing in at_ifaddr
195 */
196 if ((aa = at_ifawithnet( (struct sockaddr_at *)dst)) == 0)
197 goto bad;
198
199 /*
200 * In the phase 2 case, we need to prepend an mbuf for the llc header.
201 * Since we must preserve the value of m, which is passed to us by
202 * value, we m_copy() the first mbuf, and use it for our llc header.
203 */
204 if (aa->aa_flags & AFA_PHASE2) {
205 struct llc llc;
206
207 M_PREPEND(m, LLC_SNAPFRAMELEN, M_TRYWAIT);
208 if (m == 0)
209 senderr(ENOBUFS);
210 llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP;
211 llc.llc_control = LLC_UI;
212 bcopy(at_org_code, llc.llc_snap.org_code, sizeof(at_org_code));
213 llc.llc_snap.ether_type = htons(ETHERTYPE_AT);
214 bcopy(&llc, mtod(m, caddr_t), LLC_SNAPFRAMELEN);
215 type = 0;
216 } else {
217 type = htons(ETHERTYPE_AT);
218 }
219 break;
220 }
221 #endif /* NETATALK */
222
223 case pseudo_AF_HDRCMPLT:
224 {
225 struct ether_header *eh;
226 hdrcmplt = 1;
227 eh = (struct ether_header *)dst->sa_data;
228 bcopy((caddr_t)eh->ether_shost, (caddr_t)esrc, FDDI_ADDR_LEN);
229 /* FALLTHROUGH */
230 }
231
232 case AF_UNSPEC:
233 {
234 struct ether_header *eh;
235 loop_copy = -1;
236 eh = (struct ether_header *)dst->sa_data;
237 bcopy((caddr_t)eh->ether_dhost, (caddr_t)edst, FDDI_ADDR_LEN);
238 if (*edst & 1)
239 m->m_flags |= (M_BCAST|M_MCAST);
240 type = eh->ether_type;
241 break;
242 }
243
244 case AF_IMPLINK:
245 {
246 fh = mtod(m, struct fddi_header *);
247 error = EPROTONOSUPPORT;
248 switch (fh->fddi_fc & (FDDIFC_C|FDDIFC_L|FDDIFC_F)) {
249 case FDDIFC_LLC_ASYNC: {
250 /* legal priorities are 0 through 7 */
251 if ((fh->fddi_fc & FDDIFC_Z) > 7)
252 goto bad;
253 break;
254 }
255 case FDDIFC_LLC_SYNC: {
256 /* FDDIFC_Z bits reserved, must be zero */
257 if (fh->fddi_fc & FDDIFC_Z)
258 goto bad;
259 break;
260 }
261 case FDDIFC_SMT: {
262 /* FDDIFC_Z bits must be non zero */
263 if ((fh->fddi_fc & FDDIFC_Z) == 0)
264 goto bad;
265 break;
266 }
267 default: {
268 /* anything else is too dangerous */
269 goto bad;
270 }
271 }
272 error = 0;
273 if (fh->fddi_dhost[0] & 1)
274 m->m_flags |= (M_BCAST|M_MCAST);
275 goto queue_it;
276 }
277 default:
278 if_printf(ifp, "can't handle af%d\n", dst->sa_family);
279 senderr(EAFNOSUPPORT);
280 }
281
282 /*
283 * Add LLC header.
284 */
285 if (type != 0) {
286 struct llc *l;
287 M_PREPEND(m, LLC_SNAPFRAMELEN, M_DONTWAIT);
288 if (m == 0)
289 senderr(ENOBUFS);
290 l = mtod(m, struct llc *);
291 l->llc_control = LLC_UI;
292 l->llc_dsap = l->llc_ssap = LLC_SNAP_LSAP;
293 l->llc_snap.org_code[0] =
294 l->llc_snap.org_code[1] =
295 l->llc_snap.org_code[2] = 0;
296 l->llc_snap.ether_type = htons(type);
297 }
298
299 /*
300 * Add local net header. If no space in first mbuf,
301 * allocate another.
302 */
303 M_PREPEND(m, FDDI_HDR_LEN, M_DONTWAIT);
304 if (m == 0)
305 senderr(ENOBUFS);
306 fh = mtod(m, struct fddi_header *);
307 fh->fddi_fc = FDDIFC_LLC_ASYNC|FDDIFC_LLC_PRIO4;
308 bcopy((caddr_t)edst, (caddr_t)fh->fddi_dhost, FDDI_ADDR_LEN);
309 queue_it:
310 if (hdrcmplt)
311 bcopy((caddr_t)esrc, (caddr_t)fh->fddi_shost, FDDI_ADDR_LEN);
312 else
313 bcopy(IF_LLADDR(ifp), (caddr_t)fh->fddi_shost,
314 FDDI_ADDR_LEN);
315
316 /*
317 * If a simplex interface, and the packet is being sent to our
318 * Ethernet address or a broadcast address, loopback a copy.
319 * XXX To make a simplex device behave exactly like a duplex
320 * device, we should copy in the case of sending to our own
321 * ethernet address (thus letting the original actually appear
322 * on the wire). However, we don't do that here for security
323 * reasons and compatibility with the original behavior.
324 */
325 if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) {
326 if ((m->m_flags & M_BCAST) || (loop_copy > 0)) {
327 struct mbuf *n;
328 n = m_copy(m, 0, (int)M_COPYALL);
329 (void) if_simloop(ifp, n, dst->sa_family,
330 FDDI_HDR_LEN);
331 } else if (bcmp(fh->fddi_dhost, fh->fddi_shost,
332 FDDI_ADDR_LEN) == 0) {
333 (void) if_simloop(ifp, m, dst->sa_family,
334 FDDI_HDR_LEN);
335 return (0); /* XXX */
336 }
337 }
338
339 IFQ_HANDOFF(ifp, m, error);
340 if (error)
341 ifp->if_oerrors++;
342
343 return (error);
344
345 bad:
346 ifp->if_oerrors++;
347 if (m)
348 m_freem(m);
349 return (error);
350 }
351
352 /*
353 * Process a received FDDI packet.
354 */
355 static void
356 fddi_input(ifp, m)
357 struct ifnet *ifp;
358 struct mbuf *m;
359 {
360 int isr;
361 struct llc *l;
362 struct fddi_header *fh;
363
364 /*
365 * Do consistency checks to verify assumptions
366 * made by code past this point.
367 */
368 if ((m->m_flags & M_PKTHDR) == 0) {
369 if_printf(ifp, "discard frame w/o packet header\n");
370 ifp->if_ierrors++;
371 m_freem(m);
372 return;
373 }
374 if (m->m_pkthdr.rcvif == NULL) {
375 if_printf(ifp, "discard frame w/o interface pointer\n");
376 ifp->if_ierrors++;
377 m_freem(m);
378 return;
379 }
380
381 m = m_pullup(m, FDDI_HDR_LEN);
382 if (m == NULL) {
383 ifp->if_ierrors++;
384 goto dropanyway;
385 }
386 fh = mtod(m, struct fddi_header *);
387 m->m_pkthdr.header = (void *)fh;
388
389 /*
390 * Discard packet if interface is not up.
391 */
392 if (!((ifp->if_flags & IFF_UP) &&
393 (ifp->if_drv_flags & IFF_DRV_RUNNING)))
394 goto dropanyway;
395
396 /*
397 * Give bpf a chance at the packet.
398 */
399 BPF_MTAP(ifp, m);
400
401 /*
402 * Interface marked for monitoring; discard packet.
403 */
404 if (ifp->if_flags & IFF_MONITOR) {
405 m_freem(m);
406 return;
407 }
408
409 #ifdef MAC
410 mac_create_mbuf_from_ifnet(ifp, m);
411 #endif
412
413 /*
414 * Update interface statistics.
415 */
416 ifp->if_ibytes += m->m_pkthdr.len;
417 getmicrotime(&ifp->if_lastchange);
418
419 /*
420 * Discard non local unicast packets when interface
421 * is in promiscuous mode.
422 */
423 if ((ifp->if_flags & IFF_PROMISC) && ((fh->fddi_dhost[0] & 1) == 0) &&
424 (bcmp(IF_LLADDR(ifp), (caddr_t)fh->fddi_dhost,
425 FDDI_ADDR_LEN) != 0))
426 goto dropanyway;
427
428 /*
429 * Set mbuf flags for bcast/mcast.
430 */
431 if (fh->fddi_dhost[0] & 1) {
432 if (bcmp(ifp->if_broadcastaddr, fh->fddi_dhost,
433 FDDI_ADDR_LEN) == 0)
434 m->m_flags |= M_BCAST;
435 else
436 m->m_flags |= M_MCAST;
437 ifp->if_imcasts++;
438 }
439
440 #ifdef M_LINK0
441 /*
442 * If this has a LLC priority of 0, then mark it so upper
443 * layers have a hint that it really came via a FDDI/Ethernet
444 * bridge.
445 */
446 if ((fh->fddi_fc & FDDIFC_LLC_PRIO7) == FDDIFC_LLC_PRIO0)
447 m->m_flags |= M_LINK0;
448 #endif
449
450 /* Strip off FDDI header. */
451 m_adj(m, FDDI_HDR_LEN);
452
453 m = m_pullup(m, LLC_SNAPFRAMELEN);
454 if (m == 0) {
455 ifp->if_ierrors++;
456 goto dropanyway;
457 }
458 l = mtod(m, struct llc *);
459
460 switch (l->llc_dsap) {
461 case LLC_SNAP_LSAP:
462 {
463 u_int16_t type;
464 if ((l->llc_control != LLC_UI) ||
465 (l->llc_ssap != LLC_SNAP_LSAP)) {
466 ifp->if_noproto++;
467 goto dropanyway;
468 }
469 #ifdef NETATALK
470 if (bcmp(&(l->llc_snap.org_code)[0], at_org_code,
471 sizeof(at_org_code)) == 0 &&
472 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AT) {
473 isr = NETISR_ATALK2;
474 m_adj(m, LLC_SNAPFRAMELEN);
475 break;
476 }
477
478 if (bcmp(&(l->llc_snap.org_code)[0], aarp_org_code,
479 sizeof(aarp_org_code)) == 0 &&
480 ntohs(l->llc_snap.ether_type) == ETHERTYPE_AARP) {
481 m_adj(m, LLC_SNAPFRAMELEN);
482 isr = NETISR_AARP;
483 break;
484 }
485 #endif /* NETATALK */
486 if (l->llc_snap.org_code[0] != 0 ||
487 l->llc_snap.org_code[1] != 0 ||
488 l->llc_snap.org_code[2] != 0) {
489 ifp->if_noproto++;
490 goto dropanyway;
491 }
492
493 type = ntohs(l->llc_snap.ether_type);
494 m_adj(m, LLC_SNAPFRAMELEN);
495
496 switch (type) {
497 #ifdef INET
498 case ETHERTYPE_IP:
499 if ((m = ip_fastforward(m)) == NULL)
500 return;
501 isr = NETISR_IP;
502 break;
503
504 case ETHERTYPE_ARP:
505 if (ifp->if_flags & IFF_NOARP)
506 goto dropanyway;
507 isr = NETISR_ARP;
508 break;
509 #endif
510 #ifdef INET6
511 case ETHERTYPE_IPV6:
512 isr = NETISR_IPV6;
513 break;
514 #endif
515 #ifdef IPX
516 case ETHERTYPE_IPX:
517 isr = NETISR_IPX;
518 break;
519 #endif
520 #ifdef DECNET
521 case ETHERTYPE_DECNET:
522 isr = NETISR_DECNET;
523 break;
524 #endif
525 #ifdef NETATALK
526 case ETHERTYPE_AT:
527 isr = NETISR_ATALK1;
528 break;
529 case ETHERTYPE_AARP:
530 isr = NETISR_AARP;
531 break;
532 #endif /* NETATALK */
533 default:
534 /* printf("fddi_input: unknown protocol 0x%x\n", type); */
535 ifp->if_noproto++;
536 goto dropanyway;
537 }
538 break;
539 }
540
541 default:
542 /* printf("fddi_input: unknown dsap 0x%x\n", l->llc_dsap); */
543 ifp->if_noproto++;
544 goto dropanyway;
545 }
546 netisr_dispatch(isr, m);
547 return;
548
549 dropanyway:
550 ifp->if_iqdrops++;
551 if (m)
552 m_freem(m);
553 return;
554 }
555
556 /*
557 * Perform common duties while attaching to interface list
558 */
559 void
560 fddi_ifattach(ifp, lla, bpf)
561 struct ifnet *ifp;
562 const u_int8_t *lla;
563 int bpf;
564 {
565 struct ifaddr *ifa;
566 struct sockaddr_dl *sdl;
567
568 ifp->if_type = IFT_FDDI;
569 ifp->if_addrlen = FDDI_ADDR_LEN;
570 ifp->if_hdrlen = 21;
571
572 if_attach(ifp); /* Must be called before additional assignments */
573
574 ifp->if_mtu = FDDIMTU;
575 ifp->if_output = fddi_output;
576 ifp->if_input = fddi_input;
577 ifp->if_resolvemulti = fddi_resolvemulti;
578 ifp->if_broadcastaddr = fddibroadcastaddr;
579 ifp->if_baudrate = 100000000;
580 #ifdef IFF_NOTRAILERS
581 ifp->if_flags |= IFF_NOTRAILERS;
582 #endif
583 ifa = ifp->if_addr;
584 KASSERT(ifa != NULL, ("%s: no lladdr!\n", __func__));
585
586 sdl = (struct sockaddr_dl *)ifa->ifa_addr;
587 sdl->sdl_type = IFT_FDDI;
588 sdl->sdl_alen = ifp->if_addrlen;
589 bcopy(lla, LLADDR(sdl), ifp->if_addrlen);
590
591 if (bpf)
592 bpfattach(ifp, DLT_FDDI, FDDI_HDR_LEN);
593
594 return;
595 }
596
597 void
598 fddi_ifdetach(ifp, bpf)
599 struct ifnet *ifp;
600 int bpf;
601 {
602
603 if (bpf)
604 bpfdetach(ifp);
605
606 if_detach(ifp);
607
608 return;
609 }
610
611 int
612 fddi_ioctl (ifp, command, data)
613 struct ifnet *ifp;
614 int command;
615 caddr_t data;
616 {
617 struct ifaddr *ifa;
618 struct ifreq *ifr;
619 int error;
620
621 ifa = (struct ifaddr *) data;
622 ifr = (struct ifreq *) data;
623 error = 0;
624
625 switch (command) {
626 case SIOCSIFADDR:
627 ifp->if_flags |= IFF_UP;
628
629 switch (ifa->ifa_addr->sa_family) {
630 #ifdef INET
631 case AF_INET: /* before arpwhohas */
632 ifp->if_init(ifp->if_softc);
633 arp_ifinit(ifp, ifa);
634 break;
635 #endif
636 #ifdef IPX
637 /*
638 * XXX - This code is probably wrong
639 */
640 case AF_IPX: {
641 struct ipx_addr *ina;
642
643 ina = &(IA_SIPX(ifa)->sipx_addr);
644
645 if (ipx_nullhost(*ina)) {
646 ina->x_host = *(union ipx_host *)
647 IF_LLADDR(ifp);
648 } else {
649 bcopy((caddr_t) ina->x_host.c_host,
650 (caddr_t) IF_LLADDR(ifp),
651 ETHER_ADDR_LEN);
652 }
653
654 /*
655 * Set new address
656 */
657 ifp->if_init(ifp->if_softc);
658 }
659 break;
660 #endif
661 default:
662 ifp->if_init(ifp->if_softc);
663 break;
664 }
665 break;
666 case SIOCGIFADDR: {
667 struct sockaddr *sa;
668
669 sa = (struct sockaddr *) & ifr->ifr_data;
670 bcopy(IF_LLADDR(ifp),
671 (caddr_t) sa->sa_data, FDDI_ADDR_LEN);
672
673 }
674 break;
675 case SIOCSIFMTU:
676 /*
677 * Set the interface MTU.
678 */
679 if (ifr->ifr_mtu > FDDIMTU) {
680 error = EINVAL;
681 } else {
682 ifp->if_mtu = ifr->ifr_mtu;
683 }
684 break;
685 default:
686 error = EINVAL;
687 break;
688 }
689
690 return (error);
691 }
692
693 static int
694 fddi_resolvemulti(ifp, llsa, sa)
695 struct ifnet *ifp;
696 struct sockaddr **llsa;
697 struct sockaddr *sa;
698 {
699 struct sockaddr_dl *sdl;
700 struct sockaddr_in *sin;
701 #ifdef INET6
702 struct sockaddr_in6 *sin6;
703 #endif
704 u_char *e_addr;
705
706 switch(sa->sa_family) {
707 case AF_LINK:
708 /*
709 * No mapping needed. Just check that it's a valid MC address.
710 */
711 sdl = (struct sockaddr_dl *)sa;
712 e_addr = LLADDR(sdl);
713 if ((e_addr[0] & 1) != 1)
714 return (EADDRNOTAVAIL);
715 *llsa = 0;
716 return (0);
717
718 #ifdef INET
719 case AF_INET:
720 sin = (struct sockaddr_in *)sa;
721 if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr)))
722 return (EADDRNOTAVAIL);
723 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
724 M_NOWAIT | M_ZERO);
725 if (sdl == NULL)
726 return (ENOMEM);
727 sdl->sdl_len = sizeof *sdl;
728 sdl->sdl_family = AF_LINK;
729 sdl->sdl_index = ifp->if_index;
730 sdl->sdl_type = IFT_FDDI;
731 sdl->sdl_nlen = 0;
732 sdl->sdl_alen = FDDI_ADDR_LEN;
733 sdl->sdl_slen = 0;
734 e_addr = LLADDR(sdl);
735 ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr);
736 *llsa = (struct sockaddr *)sdl;
737 return (0);
738 #endif
739 #ifdef INET6
740 case AF_INET6:
741 sin6 = (struct sockaddr_in6 *)sa;
742 if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
743 /*
744 * An IP6 address of 0 means listen to all
745 * of the Ethernet multicast address used for IP6.
746 * (This is used for multicast routers.)
747 */
748 ifp->if_flags |= IFF_ALLMULTI;
749 *llsa = 0;
750 return (0);
751 }
752 if (!IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
753 return (EADDRNOTAVAIL);
754 MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR,
755 M_NOWAIT | M_ZERO);
756 if (sdl == NULL)
757 return (ENOMEM);
758 sdl->sdl_len = sizeof *sdl;
759 sdl->sdl_family = AF_LINK;
760 sdl->sdl_index = ifp->if_index;
761 sdl->sdl_type = IFT_FDDI;
762 sdl->sdl_nlen = 0;
763 sdl->sdl_alen = FDDI_ADDR_LEN;
764 sdl->sdl_slen = 0;
765 e_addr = LLADDR(sdl);
766 ETHER_MAP_IPV6_MULTICAST(&sin6->sin6_addr, e_addr);
767 *llsa = (struct sockaddr *)sdl;
768 return (0);
769 #endif
770
771 default:
772 /*
773 * Well, the text isn't quite right, but it's the name
774 * that counts...
775 */
776 return (EAFNOSUPPORT);
777 }
778
779 return (0);
780 }
781
782 static moduledata_t fddi_mod = {
783 "fddi", /* module name */
784 NULL, /* event handler */
785 0 /* extra data */
786 };
787
788 DECLARE_MODULE(fddi, fddi_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
789 MODULE_VERSION(fddi, 1);
Cache object: 5856a926a8ccdab31a865953cb6da397
|