1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1989, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 6df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 7df8bae1dSRodney W. Grimes * are met: 8df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 9df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 10df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 12df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 13df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 14df8bae1dSRodney W. Grimes * must display the following acknowledgement: 15df8bae1dSRodney W. Grimes * This product includes software developed by the University of 16df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 17df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes * without specific prior written permission. 20df8bae1dSRodney W. Grimes * 21df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes * SUCH DAMAGE. 32df8bae1dSRodney W. Grimes * 33df8bae1dSRodney W. Grimes * @(#)if_ethersubr.c 8.1 (Berkeley) 6/10/93 34430df5f4SEivind Eklund * $Id: if_ethersubr.c,v 1.39 1997/11/07 08:53:18 phk Exp $ 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 37430df5f4SEivind Eklund #include "opt_ipx.h" 38430df5f4SEivind Eklund 39df8bae1dSRodney W. Grimes #include <sys/param.h> 40df8bae1dSRodney W. Grimes #include <sys/systm.h> 41df8bae1dSRodney W. Grimes #include <sys/kernel.h> 42df8bae1dSRodney W. Grimes #include <sys/malloc.h> 43df8bae1dSRodney W. Grimes #include <sys/mbuf.h> 44df8bae1dSRodney W. Grimes #include <sys/socket.h> 4551a53488SBruce Evans #include <sys/sockio.h> 46602d513cSGarrett Wollman #include <sys/sysctl.h> 47df8bae1dSRodney W. Grimes 48df8bae1dSRodney W. Grimes #include <net/if.h> 49df8bae1dSRodney W. Grimes #include <net/netisr.h> 50df8bae1dSRodney W. Grimes #include <net/route.h> 51df8bae1dSRodney W. Grimes #include <net/if_llc.h> 52df8bae1dSRodney W. Grimes #include <net/if_dl.h> 53df8bae1dSRodney W. Grimes #include <net/if_types.h> 54df8bae1dSRodney W. Grimes 55df8bae1dSRodney W. Grimes #ifdef INET 56df8bae1dSRodney W. Grimes #include <netinet/in.h> 57df8bae1dSRodney W. Grimes #include <netinet/in_var.h> 58df8bae1dSRodney W. Grimes #endif 59df8bae1dSRodney W. Grimes #include <netinet/if_ether.h> 60df8bae1dSRodney W. Grimes 61cc6a66f2SJulian Elischer #ifdef IPX 62cc6a66f2SJulian Elischer #include <netipx/ipx.h> 63cc6a66f2SJulian Elischer #include <netipx/ipx_if.h> 64cc6a66f2SJulian Elischer #endif 65cc6a66f2SJulian Elischer 66df8bae1dSRodney W. Grimes #ifdef NS 67df8bae1dSRodney W. Grimes #include <netns/ns.h> 68df8bae1dSRodney W. Grimes #include <netns/ns_if.h> 69d0ec898dSJordan K. Hubbard ushort ns_nettype; 7088e038feSJordan K. Hubbard int ether_outputdebug = 0; 7188e038feSJordan K. Hubbard int ether_inputdebug = 0; 72df8bae1dSRodney W. Grimes #endif 73df8bae1dSRodney W. Grimes 74df8bae1dSRodney W. Grimes #ifdef ISO 75df8bae1dSRodney W. Grimes #include <netiso/argo_debug.h> 76df8bae1dSRodney W. Grimes #include <netiso/iso.h> 77df8bae1dSRodney W. Grimes #include <netiso/iso_var.h> 78df8bae1dSRodney W. Grimes #include <netiso/iso_snpac.h> 79df8bae1dSRodney W. Grimes #endif 80df8bae1dSRodney W. Grimes 81655929bfSJulian Elischer /*#ifdef LLC 82df8bae1dSRodney W. Grimes #include <netccitt/dll.h> 83df8bae1dSRodney W. Grimes #include <netccitt/llc_var.h> 84655929bfSJulian Elischer #endif*/ 85df8bae1dSRodney W. Grimes 86df8bae1dSRodney W. Grimes #if defined(LLC) && defined(CCITT) 87df8bae1dSRodney W. Grimes extern struct ifqueue pkintrq; 88df8bae1dSRodney W. Grimes #endif 89df8bae1dSRodney W. Grimes 90655929bfSJulian Elischer #ifdef NETATALK 91655929bfSJulian Elischer #include <netatalk/at.h> 92655929bfSJulian Elischer #include <netatalk/at_var.h> 93655929bfSJulian Elischer #include <netatalk/at_extern.h> 94655929bfSJulian Elischer 95655929bfSJulian Elischer #define llc_snap_org_code llc_un.type_snap.org_code 96655929bfSJulian Elischer #define llc_snap_ether_type llc_un.type_snap.ether_type 97655929bfSJulian Elischer 98655929bfSJulian Elischer extern u_char at_org_code[ 3 ]; 99655929bfSJulian Elischer extern u_char aarp_org_code[ 3 ]; 100655929bfSJulian Elischer #endif NETATALK 101655929bfSJulian Elischer 1021158dfb7SGarrett Wollman static int ether_resolvemulti __P((struct ifnet *, struct sockaddr **, 1031158dfb7SGarrett Wollman struct sockaddr *)); 104df8bae1dSRodney W. Grimes u_char etherbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 105df8bae1dSRodney W. Grimes #define senderr(e) { error = (e); goto bad;} 106df8bae1dSRodney W. Grimes 107df8bae1dSRodney W. Grimes /* 108df8bae1dSRodney W. Grimes * Ethernet output routine. 109df8bae1dSRodney W. Grimes * Encapsulate a packet of type family for the local net. 110df8bae1dSRodney W. Grimes * Use trailer local net encapsulation if enough data in first 111df8bae1dSRodney W. Grimes * packet leaves a multiple of 512 bytes of data in remainder. 112df8bae1dSRodney W. Grimes * Assumes that ifp is actually pointer to arpcom structure. 113df8bae1dSRodney W. Grimes */ 114df8bae1dSRodney W. Grimes int 115df8bae1dSRodney W. Grimes ether_output(ifp, m0, dst, rt0) 116df8bae1dSRodney W. Grimes register struct ifnet *ifp; 117df8bae1dSRodney W. Grimes struct mbuf *m0; 118df8bae1dSRodney W. Grimes struct sockaddr *dst; 119df8bae1dSRodney W. Grimes struct rtentry *rt0; 120df8bae1dSRodney W. Grimes { 121df8bae1dSRodney W. Grimes short type; 122df8bae1dSRodney W. Grimes int s, error = 0; 1234a11ca4eSPoul-Henning Kamp u_char edst[6]; 1244a11ca4eSPoul-Henning Kamp register struct mbuf *m = m0; 125df8bae1dSRodney W. Grimes register struct rtentry *rt; 126df8bae1dSRodney W. Grimes struct mbuf *mcopy = (struct mbuf *)0; 127df8bae1dSRodney W. Grimes register struct ether_header *eh; 128df8bae1dSRodney W. Grimes int off, len = m->m_pkthdr.len; 129df8bae1dSRodney W. Grimes struct arpcom *ac = (struct arpcom *)ifp; 130655929bfSJulian Elischer #ifdef NETATALK 131655929bfSJulian Elischer struct at_ifaddr *aa; 132655929bfSJulian Elischer #endif NETATALK 133df8bae1dSRodney W. Grimes 134df8bae1dSRodney W. Grimes if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 135df8bae1dSRodney W. Grimes senderr(ENETDOWN); 1363bda9f9bSPoul-Henning Kamp rt = rt0; 1373bda9f9bSPoul-Henning Kamp if (rt) { 138df8bae1dSRodney W. Grimes if ((rt->rt_flags & RTF_UP) == 0) { 1393bda9f9bSPoul-Henning Kamp rt0 = rt = rtalloc1(dst, 1, 0UL); 1403bda9f9bSPoul-Henning Kamp if (rt0) 141df8bae1dSRodney W. Grimes rt->rt_refcnt--; 142df8bae1dSRodney W. Grimes else 143df8bae1dSRodney W. Grimes senderr(EHOSTUNREACH); 144df8bae1dSRodney W. Grimes } 145df8bae1dSRodney W. Grimes if (rt->rt_flags & RTF_GATEWAY) { 146df8bae1dSRodney W. Grimes if (rt->rt_gwroute == 0) 147df8bae1dSRodney W. Grimes goto lookup; 148df8bae1dSRodney W. Grimes if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { 149df8bae1dSRodney W. Grimes rtfree(rt); rt = rt0; 150995add1aSGarrett Wollman lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 151995add1aSGarrett Wollman 0UL); 152df8bae1dSRodney W. Grimes if ((rt = rt->rt_gwroute) == 0) 153df8bae1dSRodney W. Grimes senderr(EHOSTUNREACH); 154df8bae1dSRodney W. Grimes } 155df8bae1dSRodney W. Grimes } 156df8bae1dSRodney W. Grimes if (rt->rt_flags & RTF_REJECT) 157df8bae1dSRodney W. Grimes if (rt->rt_rmx.rmx_expire == 0 || 158df8bae1dSRodney W. Grimes time.tv_sec < rt->rt_rmx.rmx_expire) 159df8bae1dSRodney W. Grimes senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); 160df8bae1dSRodney W. Grimes } 161df8bae1dSRodney W. Grimes switch (dst->sa_family) { 162df8bae1dSRodney W. Grimes 163df8bae1dSRodney W. Grimes #ifdef INET 164df8bae1dSRodney W. Grimes case AF_INET: 1655df72964SGarrett Wollman if (!arpresolve(ac, rt, m, dst, edst, rt0)) 166df8bae1dSRodney W. Grimes return (0); /* if not yet resolved */ 167df8bae1dSRodney W. Grimes /* If broadcasting on a simplex interface, loopback a copy */ 168df8bae1dSRodney W. Grimes if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) 169df8bae1dSRodney W. Grimes mcopy = m_copy(m, 0, (int)M_COPYALL); 170df8bae1dSRodney W. Grimes off = m->m_pkthdr.len - m->m_len; 17134bed8b0SDavid Greenman type = htons(ETHERTYPE_IP); 172df8bae1dSRodney W. Grimes break; 173df8bae1dSRodney W. Grimes #endif 174cc6a66f2SJulian Elischer #ifdef IPX 175cc6a66f2SJulian Elischer case AF_IPX: 176b1c9d77eSJohn Hay { 177b1c9d77eSJohn Hay struct ifaddr *ia; 178b1c9d77eSJohn Hay 17934bed8b0SDavid Greenman type = htons(ETHERTYPE_IPX); 180cc6a66f2SJulian Elischer bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), 181cc6a66f2SJulian Elischer (caddr_t)edst, sizeof (edst)); 182b1c9d77eSJohn Hay 183b1c9d77eSJohn Hay for(ia = ifp->if_addrhead.tqh_first; ia != 0; 184b1c9d77eSJohn Hay ia = ia->ifa_link.tqe_next) { 185b1c9d77eSJohn Hay if(ia->ifa_addr->sa_family == AF_IPX && 186b1c9d77eSJohn Hay !bcmp((caddr_t)edst, 187b1c9d77eSJohn Hay (caddr_t)&((struct ipx_ifaddr *)ia)->ia_addr.sipx_addr.x_host, 188b1c9d77eSJohn Hay sizeof(edst)) ) 189cc6a66f2SJulian Elischer return (looutput(ifp, m, dst, rt)); 190b1c9d77eSJohn Hay } 191b1c9d77eSJohn Hay 192cc6a66f2SJulian Elischer /* If broadcasting on a simplex interface, loopback a copy */ 193cc6a66f2SJulian Elischer if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) 194cc6a66f2SJulian Elischer mcopy = m_copy(m, 0, (int)M_COPYALL); 195cc6a66f2SJulian Elischer break; 196b1c9d77eSJohn Hay } 197cc6a66f2SJulian Elischer #endif 198655929bfSJulian Elischer #ifdef NETATALK 199655929bfSJulian Elischer case AF_APPLETALK: 2001d0eab59SJulian Elischer { 2011d0eab59SJulian Elischer struct sockaddr_at *sat = (struct sockaddr_at *)dst; 2021d0eab59SJulian Elischer 2031d0eab59SJulian Elischer /* 2041d0eab59SJulian Elischer * super hack.. 2051d0eab59SJulian Elischer * Most of this loopback code should move into the appletalk 2061d0eab59SJulian Elischer * code, but it's here for now.. remember to move it! [JRE] 2071d0eab59SJulian Elischer * This may not get the same interface we started with, 2081d0eab59SJulian Elischer * fix asap. XXX 2091d0eab59SJulian Elischer */ 2101d0eab59SJulian Elischer aa = at_ifawithnet( sat ); 2111d0eab59SJulian Elischer if (aa == NULL) { 2121d0eab59SJulian Elischer goto bad; 2131d0eab59SJulian Elischer } 2141d0eab59SJulian Elischer if( aa->aa_ifa.ifa_ifp != ifp ) { 2151d0eab59SJulian Elischer (*aa->aa_ifa.ifa_ifp->if_output)(aa->aa_ifa.ifa_ifp, 2161d0eab59SJulian Elischer m,dst,rt); 2171d0eab59SJulian Elischer } 2181d0eab59SJulian Elischer if (((sat->sat_addr.s_net == ATADDR_ANYNET) 2191d0eab59SJulian Elischer && (sat->sat_addr.s_node == ATADDR_ANYNODE)) 2201d0eab59SJulian Elischer || ((sat->sat_addr.s_net == aa->aa_addr.sat_addr.s_net ) 2211d0eab59SJulian Elischer && (sat->sat_addr.s_node == aa->aa_addr.sat_addr.s_node))) { 2221d0eab59SJulian Elischer (void) looutput(ifp, m, dst, rt); 2231d0eab59SJulian Elischer return(0); 2241d0eab59SJulian Elischer } 2251d0eab59SJulian Elischer 226655929bfSJulian Elischer if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) { 227655929bfSJulian Elischer #ifdef NETATALKDEBUG 228655929bfSJulian Elischer extern char *prsockaddr(struct sockaddr *); 229655929bfSJulian Elischer printf("aarpresolv: failed for %s\n", prsockaddr(dst)); 230655929bfSJulian Elischer #endif NETATALKDEBUG 231655929bfSJulian Elischer return (0); 232655929bfSJulian Elischer } 233655929bfSJulian Elischer 234655929bfSJulian Elischer /* 2351d0eab59SJulian Elischer * If broadcasting on a simplex interface, loopback a copy 2361d0eab59SJulian Elischer */ 2371d0eab59SJulian Elischer if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)) 2381d0eab59SJulian Elischer mcopy = m_copy(m, 0, (int)M_COPYALL); 2391d0eab59SJulian Elischer } 2401d0eab59SJulian Elischer /* 241655929bfSJulian Elischer * In the phase 2 case, we need to prepend an mbuf for the llc header. 242655929bfSJulian Elischer * Since we must preserve the value of m, which is passed to us by 243655929bfSJulian Elischer * value, we m_copy() the first mbuf, and use it for our llc header. 244655929bfSJulian Elischer */ 245655929bfSJulian Elischer if ( aa->aa_flags & AFA_PHASE2 ) { 246655929bfSJulian Elischer struct llc llc; 247655929bfSJulian Elischer 248655929bfSJulian Elischer M_PREPEND(m, sizeof(struct llc), M_WAIT); 249655929bfSJulian Elischer len += sizeof(struct llc); 250655929bfSJulian Elischer llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; 251655929bfSJulian Elischer llc.llc_control = LLC_UI; 252655929bfSJulian Elischer bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code)); 253655929bfSJulian Elischer llc.llc_snap_ether_type = htons( ETHERTYPE_AT ); 254655929bfSJulian Elischer bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc)); 25534bed8b0SDavid Greenman type = htons(m->m_pkthdr.len); 256655929bfSJulian Elischer } else { 25734bed8b0SDavid Greenman type = htons(ETHERTYPE_AT); 258655929bfSJulian Elischer } 259655929bfSJulian Elischer break; 260655929bfSJulian Elischer #endif NETATALK 261df8bae1dSRodney W. Grimes #ifdef NS 262df8bae1dSRodney W. Grimes case AF_NS: 26388e038feSJordan K. Hubbard switch(ns_nettype){ 26488e038feSJordan K. Hubbard default: 26588e038feSJordan K. Hubbard case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */ 26688e038feSJordan K. Hubbard type = 0x8137; 26788e038feSJordan K. Hubbard break; 26888e038feSJordan K. Hubbard case 0x0: /* Novell 802.3 */ 26988e038feSJordan K. Hubbard type = htons( m->m_pkthdr.len); 27088e038feSJordan K. Hubbard break; 27188e038feSJordan K. Hubbard case 0xe0e0: /* Novell 802.2 and Token-Ring */ 27288e038feSJordan K. Hubbard M_PREPEND(m, 3, M_WAIT); 27388e038feSJordan K. Hubbard type = htons( m->m_pkthdr.len); 27488e038feSJordan K. Hubbard cp = mtod(m, u_char *); 27588e038feSJordan K. Hubbard *cp++ = 0xE0; 27688e038feSJordan K. Hubbard *cp++ = 0xE0; 27788e038feSJordan K. Hubbard *cp++ = 0x03; 27888e038feSJordan K. Hubbard break; 27988e038feSJordan K. Hubbard } 280df8bae1dSRodney W. Grimes bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), 281df8bae1dSRodney W. Grimes (caddr_t)edst, sizeof (edst)); 28288e038feSJordan K. Hubbard if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst))){ 28388e038feSJordan K. Hubbard m->m_pkthdr.rcvif = ifp; 28488e038feSJordan K. Hubbard schednetisr(NETISR_NS); 28588e038feSJordan K. Hubbard inq = &nsintrq; 28688e038feSJordan K. Hubbard s = splimp(); 28788e038feSJordan K. Hubbard if (IF_QFULL(inq)) { 28888e038feSJordan K. Hubbard IF_DROP(inq); 28988e038feSJordan K. Hubbard m_freem(m); 29088e038feSJordan K. Hubbard } else 29188e038feSJordan K. Hubbard IF_ENQUEUE(inq, m); 29288e038feSJordan K. Hubbard splx(s); 29388e038feSJordan K. Hubbard return (error); 29488e038feSJordan K. Hubbard } 29588e038feSJordan K. Hubbard if (!bcmp((caddr_t)edst, (caddr_t)&ns_broadhost, sizeof(edst))){ 29688e038feSJordan K. Hubbard m2 = m_copy(m, 0, (int)M_COPYALL); 29788e038feSJordan K. Hubbard m2->m_pkthdr.rcvif = ifp; 29888e038feSJordan K. Hubbard schednetisr(NETISR_NS); 29988e038feSJordan K. Hubbard inq = &nsintrq; 30088e038feSJordan K. Hubbard s = splimp(); 30188e038feSJordan K. Hubbard if (IF_QFULL(inq)) { 30288e038feSJordan K. Hubbard IF_DROP(inq); 30388e038feSJordan K. Hubbard m_freem(m2); 30488e038feSJordan K. Hubbard } else 30588e038feSJordan K. Hubbard IF_ENQUEUE(inq, m2); 30688e038feSJordan K. Hubbard splx(s); 30788e038feSJordan K. Hubbard } 308df8bae1dSRodney W. Grimes /* If broadcasting on a simplex interface, loopback a copy */ 30988e038feSJordan K. Hubbard if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX)){ 310df8bae1dSRodney W. Grimes mcopy = m_copy(m, 0, (int)M_COPYALL); 31188e038feSJordan K. Hubbard } 312df8bae1dSRodney W. Grimes break; 31388e038feSJordan K. Hubbard #endif /* NS */ 314df8bae1dSRodney W. Grimes #ifdef ISO 315df8bae1dSRodney W. Grimes case AF_ISO: { 316df8bae1dSRodney W. Grimes int snpalen; 317df8bae1dSRodney W. Grimes struct llc *l; 318df8bae1dSRodney W. Grimes register struct sockaddr_dl *sdl; 319df8bae1dSRodney W. Grimes 320df8bae1dSRodney W. Grimes if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) && 321df8bae1dSRodney W. Grimes sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) { 322df8bae1dSRodney W. Grimes bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst)); 323df8bae1dSRodney W. Grimes } else if (error = 324df8bae1dSRodney W. Grimes iso_snparesolve(ifp, (struct sockaddr_iso *)dst, 325df8bae1dSRodney W. Grimes (char *)edst, &snpalen)) 326df8bae1dSRodney W. Grimes goto bad; /* Not Resolved */ 327df8bae1dSRodney W. Grimes /* If broadcasting on a simplex interface, loopback a copy */ 328df8bae1dSRodney W. Grimes if (*edst & 1) 329df8bae1dSRodney W. Grimes m->m_flags |= (M_BCAST|M_MCAST); 330df8bae1dSRodney W. Grimes if ((m->m_flags & M_BCAST) && (ifp->if_flags & IFF_SIMPLEX) && 331df8bae1dSRodney W. Grimes (mcopy = m_copy(m, 0, (int)M_COPYALL))) { 332df8bae1dSRodney W. Grimes M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT); 333df8bae1dSRodney W. Grimes if (mcopy) { 334df8bae1dSRodney W. Grimes eh = mtod(mcopy, struct ether_header *); 335df8bae1dSRodney W. Grimes bcopy((caddr_t)edst, 336df8bae1dSRodney W. Grimes (caddr_t)eh->ether_dhost, sizeof (edst)); 337df8bae1dSRodney W. Grimes bcopy((caddr_t)ac->ac_enaddr, 338df8bae1dSRodney W. Grimes (caddr_t)eh->ether_shost, sizeof (edst)); 339df8bae1dSRodney W. Grimes } 340df8bae1dSRodney W. Grimes } 341df8bae1dSRodney W. Grimes M_PREPEND(m, 3, M_DONTWAIT); 342df8bae1dSRodney W. Grimes if (m == NULL) 343df8bae1dSRodney W. Grimes return (0); 34434bed8b0SDavid Greenman type = htons(m->m_pkthdr.len); 345df8bae1dSRodney W. Grimes l = mtod(m, struct llc *); 346df8bae1dSRodney W. Grimes l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP; 347df8bae1dSRodney W. Grimes l->llc_control = LLC_UI; 348df8bae1dSRodney W. Grimes len += 3; 349df8bae1dSRodney W. Grimes IFDEBUG(D_ETHER) 350df8bae1dSRodney W. Grimes int i; 351df8bae1dSRodney W. Grimes printf("unoutput: sending pkt to: "); 352df8bae1dSRodney W. Grimes for (i=0; i<6; i++) 353df8bae1dSRodney W. Grimes printf("%x ", edst[i] & 0xff); 354df8bae1dSRodney W. Grimes printf("\n"); 355df8bae1dSRodney W. Grimes ENDDEBUG 356df8bae1dSRodney W. Grimes } break; 357df8bae1dSRodney W. Grimes #endif /* ISO */ 358df8bae1dSRodney W. Grimes #ifdef LLC 359df8bae1dSRodney W. Grimes /* case AF_NSAP: */ 360df8bae1dSRodney W. Grimes case AF_CCITT: { 361df8bae1dSRodney W. Grimes register struct sockaddr_dl *sdl = 362df8bae1dSRodney W. Grimes (struct sockaddr_dl *) rt -> rt_gateway; 363df8bae1dSRodney W. Grimes 364df8bae1dSRodney W. Grimes if (sdl && sdl->sdl_family == AF_LINK 365df8bae1dSRodney W. Grimes && sdl->sdl_alen > 0) { 366df8bae1dSRodney W. Grimes bcopy(LLADDR(sdl), (char *)edst, 367df8bae1dSRodney W. Grimes sizeof(edst)); 368df8bae1dSRodney W. Grimes } else goto bad; /* Not a link interface ? Funny ... */ 369df8bae1dSRodney W. Grimes if ((ifp->if_flags & IFF_SIMPLEX) && (*edst & 1) && 370df8bae1dSRodney W. Grimes (mcopy = m_copy(m, 0, (int)M_COPYALL))) { 371df8bae1dSRodney W. Grimes M_PREPEND(mcopy, sizeof (*eh), M_DONTWAIT); 372df8bae1dSRodney W. Grimes if (mcopy) { 373df8bae1dSRodney W. Grimes eh = mtod(mcopy, struct ether_header *); 374df8bae1dSRodney W. Grimes bcopy((caddr_t)edst, 375df8bae1dSRodney W. Grimes (caddr_t)eh->ether_dhost, sizeof (edst)); 376df8bae1dSRodney W. Grimes bcopy((caddr_t)ac->ac_enaddr, 377df8bae1dSRodney W. Grimes (caddr_t)eh->ether_shost, sizeof (edst)); 378df8bae1dSRodney W. Grimes } 379df8bae1dSRodney W. Grimes } 38034bed8b0SDavid Greenman type = htons(m->m_pkthdr.len); 381df8bae1dSRodney W. Grimes #ifdef LLC_DEBUG 382df8bae1dSRodney W. Grimes { 383df8bae1dSRodney W. Grimes int i; 384df8bae1dSRodney W. Grimes register struct llc *l = mtod(m, struct llc *); 385df8bae1dSRodney W. Grimes 386df8bae1dSRodney W. Grimes printf("ether_output: sending LLC2 pkt to: "); 387df8bae1dSRodney W. Grimes for (i=0; i<6; i++) 388df8bae1dSRodney W. Grimes printf("%x ", edst[i] & 0xff); 389df8bae1dSRodney W. Grimes printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n", 390df8bae1dSRodney W. Grimes type & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff, 391df8bae1dSRodney W. Grimes l->llc_control & 0xff); 392df8bae1dSRodney W. Grimes 393df8bae1dSRodney W. Grimes } 394df8bae1dSRodney W. Grimes #endif /* LLC_DEBUG */ 395df8bae1dSRodney W. Grimes } break; 396df8bae1dSRodney W. Grimes #endif /* LLC */ 397df8bae1dSRodney W. Grimes 398df8bae1dSRodney W. Grimes case AF_UNSPEC: 399df8bae1dSRodney W. Grimes eh = (struct ether_header *)dst->sa_data; 40094a5d9b6SDavid Greenman (void)memcpy(edst, eh->ether_dhost, sizeof (edst)); 401df8bae1dSRodney W. Grimes type = eh->ether_type; 402df8bae1dSRodney W. Grimes break; 403df8bae1dSRodney W. Grimes 404df8bae1dSRodney W. Grimes default: 405df8bae1dSRodney W. Grimes printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, 406df8bae1dSRodney W. Grimes dst->sa_family); 407df8bae1dSRodney W. Grimes senderr(EAFNOSUPPORT); 408df8bae1dSRodney W. Grimes } 409df8bae1dSRodney W. Grimes 410df8bae1dSRodney W. Grimes 411df8bae1dSRodney W. Grimes if (mcopy) 412df8bae1dSRodney W. Grimes (void) looutput(ifp, mcopy, dst, rt); 413df8bae1dSRodney W. Grimes /* 414df8bae1dSRodney W. Grimes * Add local net header. If no space in first mbuf, 415df8bae1dSRodney W. Grimes * allocate another. 416df8bae1dSRodney W. Grimes */ 417df8bae1dSRodney W. Grimes M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT); 418df8bae1dSRodney W. Grimes if (m == 0) 419df8bae1dSRodney W. Grimes senderr(ENOBUFS); 420df8bae1dSRodney W. Grimes eh = mtod(m, struct ether_header *); 42194a5d9b6SDavid Greenman (void)memcpy(&eh->ether_type, &type, 422df8bae1dSRodney W. Grimes sizeof(eh->ether_type)); 42394a5d9b6SDavid Greenman (void)memcpy(eh->ether_dhost, edst, sizeof (edst)); 42494a5d9b6SDavid Greenman (void)memcpy(eh->ether_shost, ac->ac_enaddr, 425df8bae1dSRodney W. Grimes sizeof(eh->ether_shost)); 426df8bae1dSRodney W. Grimes s = splimp(); 427df8bae1dSRodney W. Grimes /* 428df8bae1dSRodney W. Grimes * Queue message on interface, and start output if interface 429df8bae1dSRodney W. Grimes * not yet active. 430df8bae1dSRodney W. Grimes */ 431df8bae1dSRodney W. Grimes if (IF_QFULL(&ifp->if_snd)) { 432df8bae1dSRodney W. Grimes IF_DROP(&ifp->if_snd); 433df8bae1dSRodney W. Grimes splx(s); 434df8bae1dSRodney W. Grimes senderr(ENOBUFS); 435df8bae1dSRodney W. Grimes } 436df8bae1dSRodney W. Grimes IF_ENQUEUE(&ifp->if_snd, m); 437df8bae1dSRodney W. Grimes if ((ifp->if_flags & IFF_OACTIVE) == 0) 438df8bae1dSRodney W. Grimes (*ifp->if_start)(ifp); 439df8bae1dSRodney W. Grimes splx(s); 440df8bae1dSRodney W. Grimes ifp->if_obytes += len + sizeof (struct ether_header); 441df8bae1dSRodney W. Grimes if (m->m_flags & M_MCAST) 442df8bae1dSRodney W. Grimes ifp->if_omcasts++; 443df8bae1dSRodney W. Grimes return (error); 444df8bae1dSRodney W. Grimes 445df8bae1dSRodney W. Grimes bad: 446df8bae1dSRodney W. Grimes if (m) 447df8bae1dSRodney W. Grimes m_freem(m); 448df8bae1dSRodney W. Grimes return (error); 449df8bae1dSRodney W. Grimes } 450df8bae1dSRodney W. Grimes 451df8bae1dSRodney W. Grimes /* 452df8bae1dSRodney W. Grimes * Process a received Ethernet packet; 453df8bae1dSRodney W. Grimes * the packet is in the mbuf chain m without 454df8bae1dSRodney W. Grimes * the ether header, which is provided separately. 455df8bae1dSRodney W. Grimes */ 456df8bae1dSRodney W. Grimes void 457df8bae1dSRodney W. Grimes ether_input(ifp, eh, m) 458df8bae1dSRodney W. Grimes struct ifnet *ifp; 459df8bae1dSRodney W. Grimes register struct ether_header *eh; 460df8bae1dSRodney W. Grimes struct mbuf *m; 461df8bae1dSRodney W. Grimes { 462df8bae1dSRodney W. Grimes register struct ifqueue *inq; 4634a11ca4eSPoul-Henning Kamp u_short ether_type; 464df8bae1dSRodney W. Grimes int s; 4658e3bda06SJulian Elischer #if defined (ISO) || defined (LLC) || defined(NETATALK) 466c23670e2SGary Palmer register struct llc *l; 467c23670e2SGary Palmer #endif 468df8bae1dSRodney W. Grimes 469df8bae1dSRodney W. Grimes if ((ifp->if_flags & IFF_UP) == 0) { 470df8bae1dSRodney W. Grimes m_freem(m); 471df8bae1dSRodney W. Grimes return; 472df8bae1dSRodney W. Grimes } 473df8bae1dSRodney W. Grimes ifp->if_ibytes += m->m_pkthdr.len + sizeof (*eh); 474df8bae1dSRodney W. Grimes if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost, 475df8bae1dSRodney W. Grimes sizeof(etherbroadcastaddr)) == 0) 476df8bae1dSRodney W. Grimes m->m_flags |= M_BCAST; 477df8bae1dSRodney W. Grimes else if (eh->ether_dhost[0] & 1) 478df8bae1dSRodney W. Grimes m->m_flags |= M_MCAST; 479df8bae1dSRodney W. Grimes if (m->m_flags & (M_BCAST|M_MCAST)) 480df8bae1dSRodney W. Grimes ifp->if_imcasts++; 481df8bae1dSRodney W. Grimes 482307d80beSDavid Greenman ether_type = ntohs(eh->ether_type); 483307d80beSDavid Greenman 484307d80beSDavid Greenman switch (ether_type) { 485df8bae1dSRodney W. Grimes #ifdef INET 486df8bae1dSRodney W. Grimes case ETHERTYPE_IP: 487df8bae1dSRodney W. Grimes schednetisr(NETISR_IP); 488df8bae1dSRodney W. Grimes inq = &ipintrq; 489df8bae1dSRodney W. Grimes break; 490df8bae1dSRodney W. Grimes 491df8bae1dSRodney W. Grimes case ETHERTYPE_ARP: 492df8bae1dSRodney W. Grimes schednetisr(NETISR_ARP); 493df8bae1dSRodney W. Grimes inq = &arpintrq; 494df8bae1dSRodney W. Grimes break; 495df8bae1dSRodney W. Grimes #endif 496cc6a66f2SJulian Elischer #ifdef IPX 497cc6a66f2SJulian Elischer case ETHERTYPE_IPX: 498cc6a66f2SJulian Elischer schednetisr(NETISR_IPX); 499cc6a66f2SJulian Elischer inq = &ipxintrq; 500cc6a66f2SJulian Elischer break; 501cc6a66f2SJulian Elischer #endif 502df8bae1dSRodney W. Grimes #ifdef NS 50388e038feSJordan K. Hubbard case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */ 504df8bae1dSRodney W. Grimes schednetisr(NETISR_NS); 505df8bae1dSRodney W. Grimes inq = &nsintrq; 506df8bae1dSRodney W. Grimes break; 50788e038feSJordan K. Hubbard 50888e038feSJordan K. Hubbard #endif /* NS */ 509655929bfSJulian Elischer #ifdef NETATALK 510655929bfSJulian Elischer case ETHERTYPE_AT: 511655929bfSJulian Elischer schednetisr(NETISR_ATALK); 512655929bfSJulian Elischer inq = &atintrq1; 513655929bfSJulian Elischer break; 514655929bfSJulian Elischer case ETHERTYPE_AARP: 515655929bfSJulian Elischer /* probably this should be done with a NETISR as well */ 516655929bfSJulian Elischer aarpinput((struct arpcom *)ifp, m); /* XXX */ 517655929bfSJulian Elischer return; 518655929bfSJulian Elischer #endif NETATALK 519df8bae1dSRodney W. Grimes default: 52088e038feSJordan K. Hubbard #ifdef NS 52188e038feSJordan K. Hubbard checksum = mtod(m, ushort *); 52288e038feSJordan K. Hubbard /* Novell 802.3 */ 52388e038feSJordan K. Hubbard if ((ether_type <= ETHERMTU) && 52488e038feSJordan K. Hubbard ((*checksum == 0xffff) || (*checksum == 0xE0E0))){ 52588e038feSJordan K. Hubbard if(*checksum == 0xE0E0) { 52688e038feSJordan K. Hubbard m->m_pkthdr.len -= 3; 52788e038feSJordan K. Hubbard m->m_len -= 3; 52888e038feSJordan K. Hubbard m->m_data += 3; 52988e038feSJordan K. Hubbard } 53088e038feSJordan K. Hubbard schednetisr(NETISR_NS); 53188e038feSJordan K. Hubbard inq = &nsintrq; 53288e038feSJordan K. Hubbard break; 53388e038feSJordan K. Hubbard } 53488e038feSJordan K. Hubbard #endif /* NS */ 535655929bfSJulian Elischer #if defined (ISO) || defined (LLC) || defined(NETATALK) 536307d80beSDavid Greenman if (ether_type > ETHERMTU) 537df8bae1dSRodney W. Grimes goto dropanyway; 538df8bae1dSRodney W. Grimes l = mtod(m, struct llc *); 539df8bae1dSRodney W. Grimes switch (l->llc_dsap) { 540655929bfSJulian Elischer #ifdef NETATALK 541655929bfSJulian Elischer case LLC_SNAP_LSAP: 542655929bfSJulian Elischer switch (l->llc_control) { 543655929bfSJulian Elischer case LLC_UI: 544655929bfSJulian Elischer if (l->llc_ssap != LLC_SNAP_LSAP) 545655929bfSJulian Elischer goto dropanyway; 546655929bfSJulian Elischer 547655929bfSJulian Elischer if (Bcmp(&(l->llc_snap_org_code)[0], at_org_code, 548655929bfSJulian Elischer sizeof(at_org_code)) == 0 && 549655929bfSJulian Elischer ntohs(l->llc_snap_ether_type) == ETHERTYPE_AT) { 550655929bfSJulian Elischer inq = &atintrq2; 551655929bfSJulian Elischer m_adj( m, sizeof( struct llc )); 552655929bfSJulian Elischer schednetisr(NETISR_ATALK); 553655929bfSJulian Elischer break; 554655929bfSJulian Elischer } 555655929bfSJulian Elischer 556655929bfSJulian Elischer if (Bcmp(&(l->llc_snap_org_code)[0], aarp_org_code, 557655929bfSJulian Elischer sizeof(aarp_org_code)) == 0 && 558655929bfSJulian Elischer ntohs(l->llc_snap_ether_type) == ETHERTYPE_AARP) { 559655929bfSJulian Elischer m_adj( m, sizeof( struct llc )); 560655929bfSJulian Elischer aarpinput((struct arpcom *)ifp, m); /* XXX */ 561655929bfSJulian Elischer return; 562655929bfSJulian Elischer } 563655929bfSJulian Elischer 564655929bfSJulian Elischer default: 565655929bfSJulian Elischer goto dropanyway; 566655929bfSJulian Elischer } 567655929bfSJulian Elischer break; 568655929bfSJulian Elischer #endif NETATALK 569df8bae1dSRodney W. Grimes #ifdef ISO 570df8bae1dSRodney W. Grimes case LLC_ISO_LSAP: 571df8bae1dSRodney W. Grimes switch (l->llc_control) { 572df8bae1dSRodney W. Grimes case LLC_UI: 573df8bae1dSRodney W. Grimes /* LLC_UI_P forbidden in class 1 service */ 574df8bae1dSRodney W. Grimes if ((l->llc_dsap == LLC_ISO_LSAP) && 575df8bae1dSRodney W. Grimes (l->llc_ssap == LLC_ISO_LSAP)) { 576df8bae1dSRodney W. Grimes /* LSAP for ISO */ 577307d80beSDavid Greenman if (m->m_pkthdr.len > ether_type) 578307d80beSDavid Greenman m_adj(m, ether_type - m->m_pkthdr.len); 579df8bae1dSRodney W. Grimes m->m_data += 3; /* XXX */ 580df8bae1dSRodney W. Grimes m->m_len -= 3; /* XXX */ 581df8bae1dSRodney W. Grimes m->m_pkthdr.len -= 3; /* XXX */ 582df8bae1dSRodney W. Grimes M_PREPEND(m, sizeof *eh, M_DONTWAIT); 583df8bae1dSRodney W. Grimes if (m == 0) 584df8bae1dSRodney W. Grimes return; 585df8bae1dSRodney W. Grimes *mtod(m, struct ether_header *) = *eh; 586df8bae1dSRodney W. Grimes IFDEBUG(D_ETHER) 587df8bae1dSRodney W. Grimes printf("clnp packet"); 588df8bae1dSRodney W. Grimes ENDDEBUG 589df8bae1dSRodney W. Grimes schednetisr(NETISR_ISO); 590df8bae1dSRodney W. Grimes inq = &clnlintrq; 591df8bae1dSRodney W. Grimes break; 592df8bae1dSRodney W. Grimes } 593df8bae1dSRodney W. Grimes goto dropanyway; 594df8bae1dSRodney W. Grimes 595df8bae1dSRodney W. Grimes case LLC_XID: 596df8bae1dSRodney W. Grimes case LLC_XID_P: 597df8bae1dSRodney W. Grimes if(m->m_len < 6) 598df8bae1dSRodney W. Grimes goto dropanyway; 599df8bae1dSRodney W. Grimes l->llc_window = 0; 600df8bae1dSRodney W. Grimes l->llc_fid = 9; 601df8bae1dSRodney W. Grimes l->llc_class = 1; 602df8bae1dSRodney W. Grimes l->llc_dsap = l->llc_ssap = 0; 603df8bae1dSRodney W. Grimes /* Fall through to */ 604df8bae1dSRodney W. Grimes case LLC_TEST: 605df8bae1dSRodney W. Grimes case LLC_TEST_P: 606df8bae1dSRodney W. Grimes { 607df8bae1dSRodney W. Grimes struct sockaddr sa; 608df8bae1dSRodney W. Grimes register struct ether_header *eh2; 609df8bae1dSRodney W. Grimes int i; 610df8bae1dSRodney W. Grimes u_char c = l->llc_dsap; 611df8bae1dSRodney W. Grimes 612df8bae1dSRodney W. Grimes l->llc_dsap = l->llc_ssap; 613df8bae1dSRodney W. Grimes l->llc_ssap = c; 614df8bae1dSRodney W. Grimes if (m->m_flags & (M_BCAST | M_MCAST)) 615df8bae1dSRodney W. Grimes bcopy((caddr_t)ac->ac_enaddr, 616df8bae1dSRodney W. Grimes (caddr_t)eh->ether_dhost, 6); 617df8bae1dSRodney W. Grimes sa.sa_family = AF_UNSPEC; 618df8bae1dSRodney W. Grimes sa.sa_len = sizeof(sa); 619df8bae1dSRodney W. Grimes eh2 = (struct ether_header *)sa.sa_data; 620df8bae1dSRodney W. Grimes for (i = 0; i < 6; i++) { 621df8bae1dSRodney W. Grimes eh2->ether_shost[i] = c = eh->ether_dhost[i]; 622df8bae1dSRodney W. Grimes eh2->ether_dhost[i] = 623df8bae1dSRodney W. Grimes eh->ether_dhost[i] = eh->ether_shost[i]; 624df8bae1dSRodney W. Grimes eh->ether_shost[i] = c; 625df8bae1dSRodney W. Grimes } 626df8bae1dSRodney W. Grimes ifp->if_output(ifp, m, &sa, NULL); 627df8bae1dSRodney W. Grimes return; 628df8bae1dSRodney W. Grimes } 629df8bae1dSRodney W. Grimes default: 630df8bae1dSRodney W. Grimes m_freem(m); 631df8bae1dSRodney W. Grimes return; 632df8bae1dSRodney W. Grimes } 633df8bae1dSRodney W. Grimes break; 634df8bae1dSRodney W. Grimes #endif /* ISO */ 635df8bae1dSRodney W. Grimes #ifdef LLC 636df8bae1dSRodney W. Grimes case LLC_X25_LSAP: 637df8bae1dSRodney W. Grimes { 638307d80beSDavid Greenman if (m->m_pkthdr.len > ether_type) 639307d80beSDavid Greenman m_adj(m, ether_type - m->m_pkthdr.len); 640df8bae1dSRodney W. Grimes M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT); 641df8bae1dSRodney W. Grimes if (m == 0) 642df8bae1dSRodney W. Grimes return; 643df8bae1dSRodney W. Grimes if ( !sdl_sethdrif(ifp, eh->ether_shost, LLC_X25_LSAP, 644df8bae1dSRodney W. Grimes eh->ether_dhost, LLC_X25_LSAP, 6, 645df8bae1dSRodney W. Grimes mtod(m, struct sdl_hdr *))) 646df8bae1dSRodney W. Grimes panic("ETHER cons addr failure"); 647307d80beSDavid Greenman mtod(m, struct sdl_hdr *)->sdlhdr_len = ether_type; 648df8bae1dSRodney W. Grimes #ifdef LLC_DEBUG 649df8bae1dSRodney W. Grimes printf("llc packet\n"); 650df8bae1dSRodney W. Grimes #endif /* LLC_DEBUG */ 651df8bae1dSRodney W. Grimes schednetisr(NETISR_CCITT); 652df8bae1dSRodney W. Grimes inq = &llcintrq; 653df8bae1dSRodney W. Grimes break; 654df8bae1dSRodney W. Grimes } 655df8bae1dSRodney W. Grimes #endif /* LLC */ 656df8bae1dSRodney W. Grimes dropanyway: 657df8bae1dSRodney W. Grimes default: 658df8bae1dSRodney W. Grimes m_freem(m); 659df8bae1dSRodney W. Grimes return; 660df8bae1dSRodney W. Grimes } 661655929bfSJulian Elischer #else /* ISO || LLC || NETATALK */ 662df8bae1dSRodney W. Grimes m_freem(m); 663df8bae1dSRodney W. Grimes return; 664655929bfSJulian Elischer #endif /* ISO || LLC || NETATALK */ 665df8bae1dSRodney W. Grimes } 666df8bae1dSRodney W. Grimes 667df8bae1dSRodney W. Grimes s = splimp(); 668df8bae1dSRodney W. Grimes if (IF_QFULL(inq)) { 669df8bae1dSRodney W. Grimes IF_DROP(inq); 670df8bae1dSRodney W. Grimes m_freem(m); 671df8bae1dSRodney W. Grimes } else 672df8bae1dSRodney W. Grimes IF_ENQUEUE(inq, m); 673df8bae1dSRodney W. Grimes splx(s); 674df8bae1dSRodney W. Grimes } 675df8bae1dSRodney W. Grimes 676df8bae1dSRodney W. Grimes /* 677df8bae1dSRodney W. Grimes * Perform common duties while attaching to interface list 678df8bae1dSRodney W. Grimes */ 679df8bae1dSRodney W. Grimes void 680df8bae1dSRodney W. Grimes ether_ifattach(ifp) 681df8bae1dSRodney W. Grimes register struct ifnet *ifp; 682df8bae1dSRodney W. Grimes { 683df8bae1dSRodney W. Grimes register struct ifaddr *ifa; 684df8bae1dSRodney W. Grimes register struct sockaddr_dl *sdl; 685df8bae1dSRodney W. Grimes 686df8bae1dSRodney W. Grimes ifp->if_type = IFT_ETHER; 687df8bae1dSRodney W. Grimes ifp->if_addrlen = 6; 688df8bae1dSRodney W. Grimes ifp->if_hdrlen = 14; 689df8bae1dSRodney W. Grimes ifp->if_mtu = ETHERMTU; 6901158dfb7SGarrett Wollman ifp->if_resolvemulti = ether_resolvemulti; 691a330e1f1SGary Palmer if (ifp->if_baudrate == 0) 692a330e1f1SGary Palmer ifp->if_baudrate = 10000000; 69359562606SGarrett Wollman ifa = ifnet_addrs[ifp->if_index - 1]; 69459562606SGarrett Wollman if (ifa == 0) { 69559562606SGarrett Wollman printf("ether_ifattach: no lladdr!\n"); 69659562606SGarrett Wollman return; 69759562606SGarrett Wollman } 69859562606SGarrett Wollman sdl = (struct sockaddr_dl *)ifa->ifa_addr; 699df8bae1dSRodney W. Grimes sdl->sdl_type = IFT_ETHER; 700df8bae1dSRodney W. Grimes sdl->sdl_alen = ifp->if_addrlen; 70159562606SGarrett Wollman bcopy(((struct arpcom *)ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen); 702df8bae1dSRodney W. Grimes } 703df8bae1dSRodney W. Grimes 704602d513cSGarrett Wollman SYSCTL_NODE(_net_link, IFT_ETHER, ether, CTLFLAG_RW, 0, "Ethernet"); 70530106f6aSPoul-Henning Kamp 706fb583156SDavid Greenman int 70730106f6aSPoul-Henning Kamp ether_ioctl(struct ifnet *ifp, int command, caddr_t data) 70830106f6aSPoul-Henning Kamp { 70930106f6aSPoul-Henning Kamp struct ifaddr *ifa = (struct ifaddr *) data; 71030106f6aSPoul-Henning Kamp struct ifreq *ifr = (struct ifreq *) data; 711fb583156SDavid Greenman int error = 0; 71230106f6aSPoul-Henning Kamp 71330106f6aSPoul-Henning Kamp switch (command) { 71430106f6aSPoul-Henning Kamp case SIOCSIFADDR: 71530106f6aSPoul-Henning Kamp ifp->if_flags |= IFF_UP; 71630106f6aSPoul-Henning Kamp 71730106f6aSPoul-Henning Kamp switch (ifa->ifa_addr->sa_family) { 71830106f6aSPoul-Henning Kamp #ifdef INET 71930106f6aSPoul-Henning Kamp case AF_INET: 72030106f6aSPoul-Henning Kamp ifp->if_init(ifp->if_softc); /* before arpwhohas */ 72130106f6aSPoul-Henning Kamp arp_ifinit((struct arpcom *)ifp, ifa); 72230106f6aSPoul-Henning Kamp break; 72330106f6aSPoul-Henning Kamp #endif 72430106f6aSPoul-Henning Kamp #ifdef IPX 72530106f6aSPoul-Henning Kamp /* 72630106f6aSPoul-Henning Kamp * XXX - This code is probably wrong 72730106f6aSPoul-Henning Kamp */ 72830106f6aSPoul-Henning Kamp case AF_IPX: 72930106f6aSPoul-Henning Kamp { 73030106f6aSPoul-Henning Kamp register struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr); 73186101139SPoul-Henning Kamp struct arpcom *ac = (struct arpcom *) (ifp->if_softc); 73230106f6aSPoul-Henning Kamp 73330106f6aSPoul-Henning Kamp if (ipx_nullhost(*ina)) 73430106f6aSPoul-Henning Kamp ina->x_host = 73586101139SPoul-Henning Kamp *(union ipx_host *) 73686101139SPoul-Henning Kamp ac->ac_enaddr; 73730106f6aSPoul-Henning Kamp else { 73830106f6aSPoul-Henning Kamp bcopy((caddr_t) ina->x_host.c_host, 73986101139SPoul-Henning Kamp (caddr_t) ac->ac_enaddr, 74086101139SPoul-Henning Kamp sizeof(ac->ac_enaddr)); 74130106f6aSPoul-Henning Kamp } 74230106f6aSPoul-Henning Kamp 74330106f6aSPoul-Henning Kamp /* 74430106f6aSPoul-Henning Kamp * Set new address 74530106f6aSPoul-Henning Kamp */ 74630106f6aSPoul-Henning Kamp ifp->if_init(ifp->if_softc); 74730106f6aSPoul-Henning Kamp break; 74830106f6aSPoul-Henning Kamp } 74930106f6aSPoul-Henning Kamp #endif 75030106f6aSPoul-Henning Kamp #ifdef NS 75130106f6aSPoul-Henning Kamp /* 75230106f6aSPoul-Henning Kamp * XXX - This code is probably wrong 75330106f6aSPoul-Henning Kamp */ 75430106f6aSPoul-Henning Kamp case AF_NS: 75530106f6aSPoul-Henning Kamp { 75630106f6aSPoul-Henning Kamp register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); 75786101139SPoul-Henning Kamp struct arpcom *ac = (struct arpcom *) (ifp->if_softc); 75830106f6aSPoul-Henning Kamp 75930106f6aSPoul-Henning Kamp if (ns_nullhost(*ina)) 76030106f6aSPoul-Henning Kamp ina->x_host = 76186101139SPoul-Henning Kamp *(union ns_host *) (ac->ac_enaddr); 76230106f6aSPoul-Henning Kamp else { 76330106f6aSPoul-Henning Kamp bcopy((caddr_t) ina->x_host.c_host, 76486101139SPoul-Henning Kamp (caddr_t) ac->ac_enaddr, 76586101139SPoul-Henning Kamp sizeof(ac->ac_enaddr)); 76630106f6aSPoul-Henning Kamp } 76730106f6aSPoul-Henning Kamp 76830106f6aSPoul-Henning Kamp /* 76930106f6aSPoul-Henning Kamp * Set new address 77030106f6aSPoul-Henning Kamp */ 77130106f6aSPoul-Henning Kamp ifp->if_init(ifp->if_softc); 77230106f6aSPoul-Henning Kamp break; 77330106f6aSPoul-Henning Kamp } 77430106f6aSPoul-Henning Kamp #endif 77530106f6aSPoul-Henning Kamp default: 77630106f6aSPoul-Henning Kamp ifp->if_init(ifp->if_softc); 77730106f6aSPoul-Henning Kamp break; 77830106f6aSPoul-Henning Kamp } 77930106f6aSPoul-Henning Kamp break; 78030106f6aSPoul-Henning Kamp 78130106f6aSPoul-Henning Kamp case SIOCGIFADDR: 78230106f6aSPoul-Henning Kamp { 78330106f6aSPoul-Henning Kamp struct sockaddr *sa; 78430106f6aSPoul-Henning Kamp 78530106f6aSPoul-Henning Kamp sa = (struct sockaddr *) & ifr->ifr_data; 7865b73c186SDavid Greenman bcopy(((struct arpcom *)ifp->if_softc)->ac_enaddr, 78730106f6aSPoul-Henning Kamp (caddr_t) sa->sa_data, ETHER_ADDR_LEN); 78830106f6aSPoul-Henning Kamp } 78930106f6aSPoul-Henning Kamp break; 790fb583156SDavid Greenman 791fb583156SDavid Greenman case SIOCSIFMTU: 792fb583156SDavid Greenman /* 793fb583156SDavid Greenman * Set the interface MTU. 794fb583156SDavid Greenman */ 795fb583156SDavid Greenman if (ifr->ifr_mtu > ETHERMTU) { 796fb583156SDavid Greenman error = EINVAL; 797fb583156SDavid Greenman } else { 798fb583156SDavid Greenman ifp->if_mtu = ifr->ifr_mtu; 79930106f6aSPoul-Henning Kamp } 800fb583156SDavid Greenman break; 801fb583156SDavid Greenman } 802fb583156SDavid Greenman return (error); 80330106f6aSPoul-Henning Kamp } 8041158dfb7SGarrett Wollman 8051158dfb7SGarrett Wollman int 8061158dfb7SGarrett Wollman ether_resolvemulti(ifp, llsa, sa) 8071158dfb7SGarrett Wollman struct ifnet *ifp; 8081158dfb7SGarrett Wollman struct sockaddr **llsa; 8091158dfb7SGarrett Wollman struct sockaddr *sa; 8101158dfb7SGarrett Wollman { 8111158dfb7SGarrett Wollman struct sockaddr_dl *sdl; 8121158dfb7SGarrett Wollman struct sockaddr_in *sin; 8131158dfb7SGarrett Wollman u_char *e_addr; 8141158dfb7SGarrett Wollman 8151158dfb7SGarrett Wollman switch(sa->sa_family) { 8161158dfb7SGarrett Wollman case AF_LINK: 8177f33a738SJulian Elischer /* 8187f33a738SJulian Elischer * No mapping needed. Just check that it's a valid MC address. 8197f33a738SJulian Elischer */ 8201158dfb7SGarrett Wollman sdl = (struct sockaddr_dl *)sa; 8211158dfb7SGarrett Wollman e_addr = LLADDR(sdl); 8221158dfb7SGarrett Wollman if ((e_addr[0] & 1) != 1) 8231158dfb7SGarrett Wollman return EADDRNOTAVAIL; 8241158dfb7SGarrett Wollman *llsa = 0; 8251158dfb7SGarrett Wollman return 0; 8261158dfb7SGarrett Wollman 8271158dfb7SGarrett Wollman #ifdef INET 8281158dfb7SGarrett Wollman case AF_INET: 8291158dfb7SGarrett Wollman sin = (struct sockaddr_in *)sa; 8301158dfb7SGarrett Wollman if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) 8311158dfb7SGarrett Wollman return EADDRNOTAVAIL; 8321158dfb7SGarrett Wollman MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR, 8331158dfb7SGarrett Wollman M_WAITOK); 8341158dfb7SGarrett Wollman sdl->sdl_len = sizeof *sdl; 8351158dfb7SGarrett Wollman sdl->sdl_family = AF_LINK; 8361158dfb7SGarrett Wollman sdl->sdl_index = ifp->if_index; 8371158dfb7SGarrett Wollman sdl->sdl_type = IFT_ETHER; 8381158dfb7SGarrett Wollman sdl->sdl_nlen = 0; 8391158dfb7SGarrett Wollman sdl->sdl_alen = ETHER_ADDR_LEN; 8401158dfb7SGarrett Wollman sdl->sdl_slen = 0; 8411158dfb7SGarrett Wollman e_addr = LLADDR(sdl); 8421158dfb7SGarrett Wollman ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr); 8431158dfb7SGarrett Wollman *llsa = (struct sockaddr *)sdl; 8441158dfb7SGarrett Wollman return 0; 8451158dfb7SGarrett Wollman #endif 8461158dfb7SGarrett Wollman 8471158dfb7SGarrett Wollman default: 8481158dfb7SGarrett Wollman /* 8491158dfb7SGarrett Wollman * Well, the text isn't quite right, but it's the name 8501158dfb7SGarrett Wollman * that counts... 8511158dfb7SGarrett Wollman */ 8521158dfb7SGarrett Wollman return EAFNOSUPPORT; 8531158dfb7SGarrett Wollman } 8541158dfb7SGarrett Wollman } 855