The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/net/if_iso88025subr.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 8cb44415ec64b39aa5de2d673f31d88f


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.