source: rtems-libbsd/freebsd/sys/net/if_iso88025subr.c @ 09bbedc

55-freebsd-126-freebsd-12
Last change on this file since 09bbedc was 0237319, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/17 at 11:18:31

Update due to Newlib 2017-06-07 changes

The following files are now provided by Newlib:

  • arpa/inet.h
  • net/if.h
  • netinet/in.h
  • netinet/tcp.h
  • sys/socket.h
  • sys/uio.h
  • sys/un.h

The <sys/param.h> and <sys/cpuset.h> are now compatible enough to be
used directly.

Update #2833.

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