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 34ce02431fSDoug Rabson * $Id: if_ethersubr.c,v 1.55 1999/01/31 08:17:16 julian Exp $ 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 377262d3e4SEivind Eklund #include "opt_atalk.h" 381d5e9e22SEivind Eklund #include "opt_inet.h" 39430df5f4SEivind Eklund #include "opt_ipx.h" 40fb5fbe46SLuigi Rizzo #include "opt_bdg.h" 41430df5f4SEivind Eklund 42df8bae1dSRodney W. Grimes #include <sys/param.h> 43df8bae1dSRodney W. Grimes #include <sys/systm.h> 44df8bae1dSRodney W. Grimes #include <sys/kernel.h> 45df8bae1dSRodney W. Grimes #include <sys/malloc.h> 46df8bae1dSRodney W. Grimes #include <sys/mbuf.h> 47df8bae1dSRodney W. Grimes #include <sys/socket.h> 4851a53488SBruce Evans #include <sys/sockio.h> 49602d513cSGarrett Wollman #include <sys/sysctl.h> 50df8bae1dSRodney W. Grimes 51df8bae1dSRodney W. Grimes #include <net/if.h> 52df8bae1dSRodney W. Grimes #include <net/netisr.h> 53df8bae1dSRodney W. Grimes #include <net/route.h> 54df8bae1dSRodney W. Grimes #include <net/if_llc.h> 55df8bae1dSRodney W. Grimes #include <net/if_dl.h> 56df8bae1dSRodney W. Grimes #include <net/if_types.h> 57df8bae1dSRodney W. Grimes 58df8bae1dSRodney W. Grimes #ifdef INET 59df8bae1dSRodney W. Grimes #include <netinet/in.h> 60df8bae1dSRodney W. Grimes #include <netinet/in_var.h> 61df8bae1dSRodney W. Grimes #include <netinet/if_ether.h> 621d5e9e22SEivind Eklund #endif 63df8bae1dSRodney W. Grimes 64cc6a66f2SJulian Elischer #ifdef IPX 65cc6a66f2SJulian Elischer #include <netipx/ipx.h> 66cc6a66f2SJulian Elischer #include <netipx/ipx_if.h> 67cc6a66f2SJulian Elischer #endif 68cc6a66f2SJulian Elischer 69df8bae1dSRodney W. Grimes #ifdef NS 70df8bae1dSRodney W. Grimes #include <netns/ns.h> 71df8bae1dSRodney W. Grimes #include <netns/ns_if.h> 72d0ec898dSJordan K. Hubbard ushort ns_nettype; 7388e038feSJordan K. Hubbard int ether_outputdebug = 0; 7488e038feSJordan K. Hubbard int ether_inputdebug = 0; 75df8bae1dSRodney W. Grimes #endif 76df8bae1dSRodney W. Grimes 77df8bae1dSRodney W. Grimes #ifdef ISO 78df8bae1dSRodney W. Grimes #include <netiso/argo_debug.h> 79df8bae1dSRodney W. Grimes #include <netiso/iso.h> 80df8bae1dSRodney W. Grimes #include <netiso/iso_var.h> 81df8bae1dSRodney W. Grimes #include <netiso/iso_snpac.h> 82df8bae1dSRodney W. Grimes #endif 83df8bae1dSRodney W. Grimes 84655929bfSJulian Elischer /*#ifdef LLC 85df8bae1dSRodney W. Grimes #include <netccitt/dll.h> 86df8bae1dSRodney W. Grimes #include <netccitt/llc_var.h> 87655929bfSJulian Elischer #endif*/ 88df8bae1dSRodney W. Grimes 89df8bae1dSRodney W. Grimes #if defined(LLC) && defined(CCITT) 90df8bae1dSRodney W. Grimes extern struct ifqueue pkintrq; 91df8bae1dSRodney W. Grimes #endif 92df8bae1dSRodney W. Grimes 93655929bfSJulian Elischer #ifdef NETATALK 94655929bfSJulian Elischer #include <netatalk/at.h> 95655929bfSJulian Elischer #include <netatalk/at_var.h> 96655929bfSJulian Elischer #include <netatalk/at_extern.h> 97655929bfSJulian Elischer 98655929bfSJulian Elischer #define llc_snap_org_code llc_un.type_snap.org_code 99655929bfSJulian Elischer #define llc_snap_ether_type llc_un.type_snap.ether_type 100655929bfSJulian Elischer 101655929bfSJulian Elischer extern u_char at_org_code[3]; 102655929bfSJulian Elischer extern u_char aarp_org_code[3]; 1032cc2df49SGarrett Wollman #endif /* NETATALK */ 1042cc2df49SGarrett Wollman 105fb5fbe46SLuigi Rizzo #ifdef BRIDGE 106fb5fbe46SLuigi Rizzo #include <net/bridge.h> 107fb5fbe46SLuigi Rizzo #endif 108fb5fbe46SLuigi Rizzo 1092cc2df49SGarrett Wollman #include "vlan.h" 1102cc2df49SGarrett Wollman #if NVLAN > 0 1112cc2df49SGarrett Wollman #include <net/if_vlan_var.h> 1122cc2df49SGarrett Wollman #endif /* NVLAN > 0 */ 113655929bfSJulian Elischer 1141158dfb7SGarrett Wollman static int ether_resolvemulti __P((struct ifnet *, struct sockaddr **, 1151158dfb7SGarrett Wollman struct sockaddr *)); 116df8bae1dSRodney W. Grimes u_char etherbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 1174c8e8c05SJulian Elischer #define senderr(e) do { error = (e); goto bad;} while (0) 1184c8e8c05SJulian Elischer #define IFP2AC(IFP) ((struct arpcom *)IFP) 119df8bae1dSRodney W. Grimes 120df8bae1dSRodney W. Grimes /* 121df8bae1dSRodney W. Grimes * Ethernet output routine. 122df8bae1dSRodney W. Grimes * Encapsulate a packet of type family for the local net. 123df8bae1dSRodney W. Grimes * Use trailer local net encapsulation if enough data in first 124df8bae1dSRodney W. Grimes * packet leaves a multiple of 512 bytes of data in remainder. 125df8bae1dSRodney W. Grimes * Assumes that ifp is actually pointer to arpcom structure. 126df8bae1dSRodney W. Grimes */ 127df8bae1dSRodney W. Grimes int 128df8bae1dSRodney W. Grimes ether_output(ifp, m0, dst, rt0) 129df8bae1dSRodney W. Grimes register struct ifnet *ifp; 130df8bae1dSRodney W. Grimes struct mbuf *m0; 131df8bae1dSRodney W. Grimes struct sockaddr *dst; 132df8bae1dSRodney W. Grimes struct rtentry *rt0; 133df8bae1dSRodney W. Grimes { 134df8bae1dSRodney W. Grimes short type; 135df8bae1dSRodney W. Grimes int s, error = 0; 1364a11ca4eSPoul-Henning Kamp u_char edst[6]; 1374a11ca4eSPoul-Henning Kamp register struct mbuf *m = m0; 138df8bae1dSRodney W. Grimes register struct rtentry *rt; 139df8bae1dSRodney W. Grimes register struct ether_header *eh; 140ed7509acSJulian Elischer int off, len = m->m_pkthdr.len, loop_copy = 0; 14184dd0fd0SJulian Elischer int hlen; /* link layer header lenght */ 1424c8e8c05SJulian Elischer struct arpcom *ac = IFP2AC(ifp); 143df8bae1dSRodney W. Grimes 144df8bae1dSRodney W. Grimes if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 145df8bae1dSRodney W. Grimes senderr(ENETDOWN); 1463bda9f9bSPoul-Henning Kamp rt = rt0; 1473bda9f9bSPoul-Henning Kamp if (rt) { 148df8bae1dSRodney W. Grimes if ((rt->rt_flags & RTF_UP) == 0) { 1493bda9f9bSPoul-Henning Kamp rt0 = rt = rtalloc1(dst, 1, 0UL); 1503bda9f9bSPoul-Henning Kamp if (rt0) 151df8bae1dSRodney W. Grimes rt->rt_refcnt--; 152df8bae1dSRodney W. Grimes else 153df8bae1dSRodney W. Grimes senderr(EHOSTUNREACH); 154df8bae1dSRodney W. Grimes } 155df8bae1dSRodney W. Grimes if (rt->rt_flags & RTF_GATEWAY) { 156df8bae1dSRodney W. Grimes if (rt->rt_gwroute == 0) 157df8bae1dSRodney W. Grimes goto lookup; 158df8bae1dSRodney W. Grimes if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { 159df8bae1dSRodney W. Grimes rtfree(rt); rt = rt0; 160995add1aSGarrett Wollman lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 161995add1aSGarrett Wollman 0UL); 162df8bae1dSRodney W. Grimes if ((rt = rt->rt_gwroute) == 0) 163df8bae1dSRodney W. Grimes senderr(EHOSTUNREACH); 164df8bae1dSRodney W. Grimes } 165df8bae1dSRodney W. Grimes } 166df8bae1dSRodney W. Grimes if (rt->rt_flags & RTF_REJECT) 167df8bae1dSRodney W. Grimes if (rt->rt_rmx.rmx_expire == 0 || 168227ee8a1SPoul-Henning Kamp time_second < rt->rt_rmx.rmx_expire) 169df8bae1dSRodney W. Grimes senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); 170df8bae1dSRodney W. Grimes } 17184dd0fd0SJulian Elischer hlen = ETHER_HDR_LEN; 172df8bae1dSRodney W. Grimes switch (dst->sa_family) { 173df8bae1dSRodney W. Grimes #ifdef INET 174df8bae1dSRodney W. Grimes case AF_INET: 1755df72964SGarrett Wollman if (!arpresolve(ac, rt, m, dst, edst, rt0)) 176df8bae1dSRodney W. Grimes return (0); /* if not yet resolved */ 177df8bae1dSRodney W. Grimes off = m->m_pkthdr.len - m->m_len; 17834bed8b0SDavid Greenman type = htons(ETHERTYPE_IP); 179df8bae1dSRodney W. Grimes break; 180df8bae1dSRodney W. Grimes #endif 181cc6a66f2SJulian Elischer #ifdef IPX 182cc6a66f2SJulian Elischer case AF_IPX: 18334bed8b0SDavid Greenman type = htons(ETHERTYPE_IPX); 184cc6a66f2SJulian Elischer bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), 185cc6a66f2SJulian Elischer (caddr_t)edst, sizeof (edst)); 186cc6a66f2SJulian Elischer break; 187cc6a66f2SJulian Elischer #endif 188655929bfSJulian Elischer #ifdef NETATALK 189655929bfSJulian Elischer case AF_APPLETALK: 1901d0eab59SJulian Elischer { 191ed7509acSJulian Elischer struct at_ifaddr *aa; 1921d0eab59SJulian Elischer 193ed7509acSJulian Elischer if ((aa = at_ifawithnet((struct sockaddr_at *)dst)) == NULL) { 1941d0eab59SJulian Elischer goto bad; 1951d0eab59SJulian Elischer } 196ed7509acSJulian Elischer if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) 1971d0eab59SJulian Elischer return (0); 198655929bfSJulian Elischer /* 199ed7509acSJulian Elischer * In the phase 2 case, need to prepend an mbuf for the llc header. 200655929bfSJulian Elischer * Since we must preserve the value of m, which is passed to us by 201655929bfSJulian Elischer * value, we m_copy() the first mbuf, and use it for our llc header. 202655929bfSJulian Elischer */ 203655929bfSJulian Elischer if ( aa->aa_flags & AFA_PHASE2 ) { 204655929bfSJulian Elischer struct llc llc; 205655929bfSJulian Elischer 206655929bfSJulian Elischer M_PREPEND(m, sizeof(struct llc), M_WAIT); 207655929bfSJulian Elischer len += sizeof(struct llc); 208655929bfSJulian Elischer llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; 209655929bfSJulian Elischer llc.llc_control = LLC_UI; 210655929bfSJulian Elischer bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code)); 211655929bfSJulian Elischer llc.llc_snap_ether_type = htons( ETHERTYPE_AT ); 212655929bfSJulian Elischer bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc)); 21334bed8b0SDavid Greenman type = htons(m->m_pkthdr.len); 21484dd0fd0SJulian Elischer hlen = sizeof(struct llc) + ETHER_HDR_LEN; 215655929bfSJulian Elischer } else { 21634bed8b0SDavid Greenman type = htons(ETHERTYPE_AT); 217655929bfSJulian Elischer } 218655929bfSJulian Elischer break; 219ed7509acSJulian Elischer } 220655929bfSJulian Elischer #endif NETATALK 221df8bae1dSRodney W. Grimes #ifdef NS 222df8bae1dSRodney W. Grimes case AF_NS: 22388e038feSJordan K. Hubbard switch(ns_nettype){ 22488e038feSJordan K. Hubbard default: 22588e038feSJordan K. Hubbard case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */ 22688e038feSJordan K. Hubbard type = 0x8137; 22788e038feSJordan K. Hubbard break; 22888e038feSJordan K. Hubbard case 0x0: /* Novell 802.3 */ 22988e038feSJordan K. Hubbard type = htons( m->m_pkthdr.len); 23088e038feSJordan K. Hubbard break; 23188e038feSJordan K. Hubbard case 0xe0e0: /* Novell 802.2 and Token-Ring */ 23288e038feSJordan K. Hubbard M_PREPEND(m, 3, M_WAIT); 23388e038feSJordan K. Hubbard type = htons( m->m_pkthdr.len); 23488e038feSJordan K. Hubbard cp = mtod(m, u_char *); 23588e038feSJordan K. Hubbard *cp++ = 0xE0; 23688e038feSJordan K. Hubbard *cp++ = 0xE0; 23788e038feSJordan K. Hubbard *cp++ = 0x03; 23888e038feSJordan K. Hubbard break; 23988e038feSJordan K. Hubbard } 240df8bae1dSRodney W. Grimes bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), 241df8bae1dSRodney W. Grimes (caddr_t)edst, sizeof (edst)); 2424c8e8c05SJulian Elischer /* 2434c8e8c05SJulian Elischer * XXX if ns_thishost is the same as the node's ethernet 2444c8e8c05SJulian Elischer * address then just the default code will catch this anyhow. 2454c8e8c05SJulian Elischer * So I'm not sure if this next clause should be here at all? 2464c8e8c05SJulian Elischer * [JRE] 2474c8e8c05SJulian Elischer */ 24888e038feSJordan K. Hubbard if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst))){ 24988e038feSJordan K. Hubbard m->m_pkthdr.rcvif = ifp; 25088e038feSJordan K. Hubbard schednetisr(NETISR_NS); 25188e038feSJordan K. Hubbard inq = &nsintrq; 25288e038feSJordan K. Hubbard s = splimp(); 25388e038feSJordan K. Hubbard if (IF_QFULL(inq)) { 25488e038feSJordan K. Hubbard IF_DROP(inq); 25588e038feSJordan K. Hubbard m_freem(m); 25688e038feSJordan K. Hubbard } else 25788e038feSJordan K. Hubbard IF_ENQUEUE(inq, m); 25888e038feSJordan K. Hubbard splx(s); 25988e038feSJordan K. Hubbard return (error); 26088e038feSJordan K. Hubbard } 26188e038feSJordan K. Hubbard if (!bcmp((caddr_t)edst, (caddr_t)&ns_broadhost, sizeof(edst))){ 2624c8e8c05SJulian Elischer m->m_flags |= M_BCAST; 26388e038feSJordan K. Hubbard } 264df8bae1dSRodney W. Grimes break; 26588e038feSJordan K. Hubbard #endif /* NS */ 266df8bae1dSRodney W. Grimes #ifdef ISO 267df8bae1dSRodney W. Grimes case AF_ISO: { 268df8bae1dSRodney W. Grimes int snpalen; 269df8bae1dSRodney W. Grimes struct llc *l; 270df8bae1dSRodney W. Grimes register struct sockaddr_dl *sdl; 271df8bae1dSRodney W. Grimes 272df8bae1dSRodney W. Grimes if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) && 273df8bae1dSRodney W. Grimes sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) { 274df8bae1dSRodney W. Grimes bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst)); 275df8bae1dSRodney W. Grimes } else if (error = 276df8bae1dSRodney W. Grimes iso_snparesolve(ifp, (struct sockaddr_iso *)dst, 277df8bae1dSRodney W. Grimes (char *)edst, &snpalen)) 278df8bae1dSRodney W. Grimes goto bad; /* Not Resolved */ 279df8bae1dSRodney W. Grimes /* If broadcasting on a simplex interface, loopback a copy */ 280df8bae1dSRodney W. Grimes if (*edst & 1) 281df8bae1dSRodney W. Grimes m->m_flags |= (M_BCAST|M_MCAST); 282df8bae1dSRodney W. Grimes M_PREPEND(m, 3, M_DONTWAIT); 283df8bae1dSRodney W. Grimes if (m == NULL) 284df8bae1dSRodney W. Grimes return (0); 28534bed8b0SDavid Greenman type = htons(m->m_pkthdr.len); 286df8bae1dSRodney W. Grimes l = mtod(m, struct llc *); 287df8bae1dSRodney W. Grimes l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP; 288df8bae1dSRodney W. Grimes l->llc_control = LLC_UI; 289df8bae1dSRodney W. Grimes len += 3; 290df8bae1dSRodney W. Grimes IFDEBUG(D_ETHER) 291df8bae1dSRodney W. Grimes int i; 292df8bae1dSRodney W. Grimes printf("unoutput: sending pkt to: "); 293df8bae1dSRodney W. Grimes for (i=0; i<6; i++) 294df8bae1dSRodney W. Grimes printf("%x ", edst[i] & 0xff); 295df8bae1dSRodney W. Grimes printf("\n"); 296df8bae1dSRodney W. Grimes ENDDEBUG 297df8bae1dSRodney W. Grimes } break; 298df8bae1dSRodney W. Grimes #endif /* ISO */ 299df8bae1dSRodney W. Grimes #ifdef LLC 300df8bae1dSRodney W. Grimes /* case AF_NSAP: */ 301df8bae1dSRodney W. Grimes case AF_CCITT: { 302df8bae1dSRodney W. Grimes register struct sockaddr_dl *sdl = 303df8bae1dSRodney W. Grimes (struct sockaddr_dl *) rt -> rt_gateway; 304df8bae1dSRodney W. Grimes 305df8bae1dSRodney W. Grimes if (sdl && sdl->sdl_family == AF_LINK 306df8bae1dSRodney W. Grimes && sdl->sdl_alen > 0) { 307ed7509acSJulian Elischer bcopy(LLADDR(sdl), (char *)edst, sizeof(edst)); 308df8bae1dSRodney W. Grimes } else goto bad; /* Not a link interface ? Funny ... */ 309ed7509acSJulian Elischer if (*edst & 1) 310ed7509acSJulian Elischer loop_copy = 1; 31134bed8b0SDavid Greenman type = htons(m->m_pkthdr.len); 312df8bae1dSRodney W. Grimes #ifdef LLC_DEBUG 313df8bae1dSRodney W. Grimes { 314df8bae1dSRodney W. Grimes int i; 315df8bae1dSRodney W. Grimes register struct llc *l = mtod(m, struct llc *); 316df8bae1dSRodney W. Grimes 317df8bae1dSRodney W. Grimes printf("ether_output: sending LLC2 pkt to: "); 318df8bae1dSRodney W. Grimes for (i=0; i<6; i++) 319df8bae1dSRodney W. Grimes printf("%x ", edst[i] & 0xff); 320df8bae1dSRodney W. Grimes printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n", 321df8bae1dSRodney W. Grimes type & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff, 322df8bae1dSRodney W. Grimes l->llc_control & 0xff); 323df8bae1dSRodney W. Grimes 324df8bae1dSRodney W. Grimes } 325df8bae1dSRodney W. Grimes #endif /* LLC_DEBUG */ 326df8bae1dSRodney W. Grimes } break; 327df8bae1dSRodney W. Grimes #endif /* LLC */ 328df8bae1dSRodney W. Grimes 329df8bae1dSRodney W. Grimes case AF_UNSPEC: 3309d3f194dSJulian Elischer loop_copy = -1; /* if this is for us, don't do it */ 331df8bae1dSRodney W. Grimes eh = (struct ether_header *)dst->sa_data; 33294a5d9b6SDavid Greenman (void)memcpy(edst, eh->ether_dhost, sizeof (edst)); 333df8bae1dSRodney W. Grimes type = eh->ether_type; 334df8bae1dSRodney W. Grimes break; 335df8bae1dSRodney W. Grimes 336df8bae1dSRodney W. Grimes default: 337df8bae1dSRodney W. Grimes printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, 338df8bae1dSRodney W. Grimes dst->sa_family); 339df8bae1dSRodney W. Grimes senderr(EAFNOSUPPORT); 340df8bae1dSRodney W. Grimes } 341df8bae1dSRodney W. Grimes 342df8bae1dSRodney W. Grimes /* 343df8bae1dSRodney W. Grimes * Add local net header. If no space in first mbuf, 344df8bae1dSRodney W. Grimes * allocate another. 345df8bae1dSRodney W. Grimes */ 346df8bae1dSRodney W. Grimes M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT); 347df8bae1dSRodney W. Grimes if (m == 0) 348df8bae1dSRodney W. Grimes senderr(ENOBUFS); 349df8bae1dSRodney W. Grimes eh = mtod(m, struct ether_header *); 35094a5d9b6SDavid Greenman (void)memcpy(&eh->ether_type, &type, 351df8bae1dSRodney W. Grimes sizeof(eh->ether_type)); 35294a5d9b6SDavid Greenman (void)memcpy(eh->ether_dhost, edst, sizeof (edst)); 35394a5d9b6SDavid Greenman (void)memcpy(eh->ether_shost, ac->ac_enaddr, 354df8bae1dSRodney W. Grimes sizeof(eh->ether_shost)); 355ed7509acSJulian Elischer 356ed7509acSJulian Elischer /* 357ed7509acSJulian Elischer * If a simplex interface, and the packet is being sent to our 358ed7509acSJulian Elischer * Ethernet address or a broadcast address, loopback a copy. 359ed7509acSJulian Elischer * XXX To make a simplex device behave exactly like a duplex 360ed7509acSJulian Elischer * device, we should copy in the case of sending to our own 361ed7509acSJulian Elischer * ethernet address (thus letting the original actually appear 362ed7509acSJulian Elischer * on the wire). However, we don't do that here for security 363ed7509acSJulian Elischer * reasons and compatibility with the original behavior. 364ed7509acSJulian Elischer */ 3654c8e8c05SJulian Elischer if ((ifp->if_flags & IFF_SIMPLEX) && (loop_copy != -1)) { 3669d3f194dSJulian Elischer if ((m->m_flags & M_BCAST) || (loop_copy > 0)) { 367ed7509acSJulian Elischer struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); 368ed7509acSJulian Elischer 36984dd0fd0SJulian Elischer (void) if_simloop(ifp, n, dst, hlen); 370ed7509acSJulian Elischer } else if (bcmp(eh->ether_dhost, 371ed7509acSJulian Elischer eh->ether_shost, ETHER_ADDR_LEN) == 0) { 37284dd0fd0SJulian Elischer (void) if_simloop(ifp, m, dst, hlen); 373ed7509acSJulian Elischer return (0); /* XXX */ 374ed7509acSJulian Elischer } 375ed7509acSJulian Elischer } 376fb5fbe46SLuigi Rizzo #ifdef BRIDGE 377fb5fbe46SLuigi Rizzo if (do_bridge) { 378fb5fbe46SLuigi Rizzo struct mbuf *m0 = m ; 3791db59ce6SEivind Eklund 380fb5fbe46SLuigi Rizzo if (m->m_pkthdr.rcvif) 381fb5fbe46SLuigi Rizzo m->m_pkthdr.rcvif = NULL ; 382fb5fbe46SLuigi Rizzo ifp = bridge_dst_lookup(m); 383fb5fbe46SLuigi Rizzo bdg_forward(&m0, ifp); 384fb5fbe46SLuigi Rizzo if (m0) 385fb5fbe46SLuigi Rizzo m_freem(m0); 3861db59ce6SEivind Eklund return (0); 387fb5fbe46SLuigi Rizzo } 388fb5fbe46SLuigi Rizzo #endif 389df8bae1dSRodney W. Grimes s = splimp(); 390df8bae1dSRodney W. Grimes /* 391df8bae1dSRodney W. Grimes * Queue message on interface, and start output if interface 392df8bae1dSRodney W. Grimes * not yet active. 393df8bae1dSRodney W. Grimes */ 394df8bae1dSRodney W. Grimes if (IF_QFULL(&ifp->if_snd)) { 395df8bae1dSRodney W. Grimes IF_DROP(&ifp->if_snd); 396df8bae1dSRodney W. Grimes splx(s); 397df8bae1dSRodney W. Grimes senderr(ENOBUFS); 398df8bae1dSRodney W. Grimes } 399df8bae1dSRodney W. Grimes IF_ENQUEUE(&ifp->if_snd, m); 400df8bae1dSRodney W. Grimes if ((ifp->if_flags & IFF_OACTIVE) == 0) 401df8bae1dSRodney W. Grimes (*ifp->if_start)(ifp); 402df8bae1dSRodney W. Grimes splx(s); 403df8bae1dSRodney W. Grimes ifp->if_obytes += len + sizeof (struct ether_header); 404df8bae1dSRodney W. Grimes if (m->m_flags & M_MCAST) 405df8bae1dSRodney W. Grimes ifp->if_omcasts++; 406df8bae1dSRodney W. Grimes return (error); 407df8bae1dSRodney W. Grimes 408df8bae1dSRodney W. Grimes bad: 409df8bae1dSRodney W. Grimes if (m) 410df8bae1dSRodney W. Grimes m_freem(m); 411df8bae1dSRodney W. Grimes return (error); 412df8bae1dSRodney W. Grimes } 413df8bae1dSRodney W. Grimes 414df8bae1dSRodney W. Grimes /* 415df8bae1dSRodney W. Grimes * Process a received Ethernet packet; 416df8bae1dSRodney W. Grimes * the packet is in the mbuf chain m without 417df8bae1dSRodney W. Grimes * the ether header, which is provided separately. 418df8bae1dSRodney W. Grimes */ 419df8bae1dSRodney W. Grimes void 420df8bae1dSRodney W. Grimes ether_input(ifp, eh, m) 421df8bae1dSRodney W. Grimes struct ifnet *ifp; 422df8bae1dSRodney W. Grimes register struct ether_header *eh; 423df8bae1dSRodney W. Grimes struct mbuf *m; 424df8bae1dSRodney W. Grimes { 425df8bae1dSRodney W. Grimes register struct ifqueue *inq; 4264a11ca4eSPoul-Henning Kamp u_short ether_type; 427df8bae1dSRodney W. Grimes int s; 4288e3bda06SJulian Elischer #if defined (ISO) || defined (LLC) || defined(NETATALK) 429c23670e2SGary Palmer register struct llc *l; 430c23670e2SGary Palmer #endif 431df8bae1dSRodney W. Grimes 432df8bae1dSRodney W. Grimes if ((ifp->if_flags & IFF_UP) == 0) { 433df8bae1dSRodney W. Grimes m_freem(m); 434df8bae1dSRodney W. Grimes return; 435df8bae1dSRodney W. Grimes } 436df8bae1dSRodney W. Grimes ifp->if_ibytes += m->m_pkthdr.len + sizeof (*eh); 4372cc2df49SGarrett Wollman if (eh->ether_dhost[0] & 1) { 438df8bae1dSRodney W. Grimes if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost, 439df8bae1dSRodney W. Grimes sizeof(etherbroadcastaddr)) == 0) 440df8bae1dSRodney W. Grimes m->m_flags |= M_BCAST; 4412cc2df49SGarrett Wollman else 442df8bae1dSRodney W. Grimes m->m_flags |= M_MCAST; 4432cc2df49SGarrett Wollman } 444df8bae1dSRodney W. Grimes if (m->m_flags & (M_BCAST|M_MCAST)) 445df8bae1dSRodney W. Grimes ifp->if_imcasts++; 446df8bae1dSRodney W. Grimes 447307d80beSDavid Greenman ether_type = ntohs(eh->ether_type); 448307d80beSDavid Greenman 4492cc2df49SGarrett Wollman #if NVLAN > 0 4502cc2df49SGarrett Wollman if (ether_type == vlan_proto) { 4512cc2df49SGarrett Wollman if (vlan_input(eh, m) < 0) 4522cc2df49SGarrett Wollman ifp->if_data.ifi_noproto++; 4532cc2df49SGarrett Wollman return; 4542cc2df49SGarrett Wollman } 4552cc2df49SGarrett Wollman #endif /* NVLAN > 0 */ 4562cc2df49SGarrett Wollman 457307d80beSDavid Greenman switch (ether_type) { 458df8bae1dSRodney W. Grimes #ifdef INET 459df8bae1dSRodney W. Grimes case ETHERTYPE_IP: 4601f91d8c5SDavid Greenman if (ipflow_fastforward(m)) 4611f91d8c5SDavid Greenman return; 462df8bae1dSRodney W. Grimes schednetisr(NETISR_IP); 463df8bae1dSRodney W. Grimes inq = &ipintrq; 464df8bae1dSRodney W. Grimes break; 465df8bae1dSRodney W. Grimes 466df8bae1dSRodney W. Grimes case ETHERTYPE_ARP: 467df8bae1dSRodney W. Grimes schednetisr(NETISR_ARP); 468df8bae1dSRodney W. Grimes inq = &arpintrq; 469df8bae1dSRodney W. Grimes break; 470df8bae1dSRodney W. Grimes #endif 471cc6a66f2SJulian Elischer #ifdef IPX 472cc6a66f2SJulian Elischer case ETHERTYPE_IPX: 473cc6a66f2SJulian Elischer schednetisr(NETISR_IPX); 474cc6a66f2SJulian Elischer inq = &ipxintrq; 475cc6a66f2SJulian Elischer break; 476cc6a66f2SJulian Elischer #endif 477df8bae1dSRodney W. Grimes #ifdef NS 47888e038feSJordan K. Hubbard case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */ 479df8bae1dSRodney W. Grimes schednetisr(NETISR_NS); 480df8bae1dSRodney W. Grimes inq = &nsintrq; 481df8bae1dSRodney W. Grimes break; 48288e038feSJordan K. Hubbard 48388e038feSJordan K. Hubbard #endif /* NS */ 484655929bfSJulian Elischer #ifdef NETATALK 485655929bfSJulian Elischer case ETHERTYPE_AT: 486655929bfSJulian Elischer schednetisr(NETISR_ATALK); 487655929bfSJulian Elischer inq = &atintrq1; 488655929bfSJulian Elischer break; 489655929bfSJulian Elischer case ETHERTYPE_AARP: 490655929bfSJulian Elischer /* probably this should be done with a NETISR as well */ 4914c8e8c05SJulian Elischer aarpinput(IFP2AC(ifp), m); /* XXX */ 492655929bfSJulian Elischer return; 493655929bfSJulian Elischer #endif NETATALK 494df8bae1dSRodney W. Grimes default: 49588e038feSJordan K. Hubbard #ifdef NS 49688e038feSJordan K. Hubbard checksum = mtod(m, ushort *); 49788e038feSJordan K. Hubbard /* Novell 802.3 */ 49888e038feSJordan K. Hubbard if ((ether_type <= ETHERMTU) && 49988e038feSJordan K. Hubbard ((*checksum == 0xffff) || (*checksum == 0xE0E0))){ 50088e038feSJordan K. Hubbard if(*checksum == 0xE0E0) { 50188e038feSJordan K. Hubbard m->m_pkthdr.len -= 3; 50288e038feSJordan K. Hubbard m->m_len -= 3; 50388e038feSJordan K. Hubbard m->m_data += 3; 50488e038feSJordan K. Hubbard } 50588e038feSJordan K. Hubbard schednetisr(NETISR_NS); 50688e038feSJordan K. Hubbard inq = &nsintrq; 50788e038feSJordan K. Hubbard break; 50888e038feSJordan K. Hubbard } 50988e038feSJordan K. Hubbard #endif /* NS */ 510655929bfSJulian Elischer #if defined (ISO) || defined (LLC) || defined(NETATALK) 511307d80beSDavid Greenman if (ether_type > ETHERMTU) 512df8bae1dSRodney W. Grimes goto dropanyway; 513df8bae1dSRodney W. Grimes l = mtod(m, struct llc *); 514df8bae1dSRodney W. Grimes switch (l->llc_dsap) { 515655929bfSJulian Elischer #ifdef NETATALK 516655929bfSJulian Elischer case LLC_SNAP_LSAP: 517655929bfSJulian Elischer switch (l->llc_control) { 518655929bfSJulian Elischer case LLC_UI: 519655929bfSJulian Elischer if (l->llc_ssap != LLC_SNAP_LSAP) 520655929bfSJulian Elischer goto dropanyway; 521655929bfSJulian Elischer 522655929bfSJulian Elischer if (Bcmp(&(l->llc_snap_org_code)[0], at_org_code, 523655929bfSJulian Elischer sizeof(at_org_code)) == 0 && 524655929bfSJulian Elischer ntohs(l->llc_snap_ether_type) == ETHERTYPE_AT) { 525655929bfSJulian Elischer inq = &atintrq2; 526655929bfSJulian Elischer m_adj( m, sizeof( struct llc )); 527655929bfSJulian Elischer schednetisr(NETISR_ATALK); 528655929bfSJulian Elischer break; 529655929bfSJulian Elischer } 530655929bfSJulian Elischer 531655929bfSJulian Elischer if (Bcmp(&(l->llc_snap_org_code)[0], aarp_org_code, 532655929bfSJulian Elischer sizeof(aarp_org_code)) == 0 && 533655929bfSJulian Elischer ntohs(l->llc_snap_ether_type) == ETHERTYPE_AARP) { 534655929bfSJulian Elischer m_adj( m, sizeof( struct llc )); 5354c8e8c05SJulian Elischer aarpinput(IFP2AC(ifp), m); /* XXX */ 536655929bfSJulian Elischer return; 537655929bfSJulian Elischer } 538655929bfSJulian Elischer 539655929bfSJulian Elischer default: 540655929bfSJulian Elischer goto dropanyway; 541655929bfSJulian Elischer } 542655929bfSJulian Elischer break; 543655929bfSJulian Elischer #endif NETATALK 544df8bae1dSRodney W. Grimes #ifdef ISO 545df8bae1dSRodney W. Grimes case LLC_ISO_LSAP: 546df8bae1dSRodney W. Grimes switch (l->llc_control) { 547df8bae1dSRodney W. Grimes case LLC_UI: 548df8bae1dSRodney W. Grimes /* LLC_UI_P forbidden in class 1 service */ 549df8bae1dSRodney W. Grimes if ((l->llc_dsap == LLC_ISO_LSAP) && 550df8bae1dSRodney W. Grimes (l->llc_ssap == LLC_ISO_LSAP)) { 551df8bae1dSRodney W. Grimes /* LSAP for ISO */ 552307d80beSDavid Greenman if (m->m_pkthdr.len > ether_type) 553307d80beSDavid Greenman m_adj(m, ether_type - m->m_pkthdr.len); 554df8bae1dSRodney W. Grimes m->m_data += 3; /* XXX */ 555df8bae1dSRodney W. Grimes m->m_len -= 3; /* XXX */ 556df8bae1dSRodney W. Grimes m->m_pkthdr.len -= 3; /* XXX */ 557df8bae1dSRodney W. Grimes M_PREPEND(m, sizeof *eh, M_DONTWAIT); 558df8bae1dSRodney W. Grimes if (m == 0) 559df8bae1dSRodney W. Grimes return; 560df8bae1dSRodney W. Grimes *mtod(m, struct ether_header *) = *eh; 561df8bae1dSRodney W. Grimes IFDEBUG(D_ETHER) 562df8bae1dSRodney W. Grimes printf("clnp packet"); 563df8bae1dSRodney W. Grimes ENDDEBUG 564df8bae1dSRodney W. Grimes schednetisr(NETISR_ISO); 565df8bae1dSRodney W. Grimes inq = &clnlintrq; 566df8bae1dSRodney W. Grimes break; 567df8bae1dSRodney W. Grimes } 568df8bae1dSRodney W. Grimes goto dropanyway; 569df8bae1dSRodney W. Grimes 570df8bae1dSRodney W. Grimes case LLC_XID: 571df8bae1dSRodney W. Grimes case LLC_XID_P: 572df8bae1dSRodney W. Grimes if(m->m_len < 6) 573df8bae1dSRodney W. Grimes goto dropanyway; 574df8bae1dSRodney W. Grimes l->llc_window = 0; 575df8bae1dSRodney W. Grimes l->llc_fid = 9; 576df8bae1dSRodney W. Grimes l->llc_class = 1; 577df8bae1dSRodney W. Grimes l->llc_dsap = l->llc_ssap = 0; 578df8bae1dSRodney W. Grimes /* Fall through to */ 579df8bae1dSRodney W. Grimes case LLC_TEST: 580df8bae1dSRodney W. Grimes case LLC_TEST_P: 581df8bae1dSRodney W. Grimes { 582df8bae1dSRodney W. Grimes struct sockaddr sa; 583df8bae1dSRodney W. Grimes register struct ether_header *eh2; 584df8bae1dSRodney W. Grimes int i; 585df8bae1dSRodney W. Grimes u_char c = l->llc_dsap; 586df8bae1dSRodney W. Grimes 587df8bae1dSRodney W. Grimes l->llc_dsap = l->llc_ssap; 588df8bae1dSRodney W. Grimes l->llc_ssap = c; 589df8bae1dSRodney W. Grimes if (m->m_flags & (M_BCAST | M_MCAST)) 590df8bae1dSRodney W. Grimes bcopy((caddr_t)ac->ac_enaddr, 591df8bae1dSRodney W. Grimes (caddr_t)eh->ether_dhost, 6); 592df8bae1dSRodney W. Grimes sa.sa_family = AF_UNSPEC; 593df8bae1dSRodney W. Grimes sa.sa_len = sizeof(sa); 594df8bae1dSRodney W. Grimes eh2 = (struct ether_header *)sa.sa_data; 595df8bae1dSRodney W. Grimes for (i = 0; i < 6; i++) { 596df8bae1dSRodney W. Grimes eh2->ether_shost[i] = c = eh->ether_dhost[i]; 597df8bae1dSRodney W. Grimes eh2->ether_dhost[i] = 598df8bae1dSRodney W. Grimes eh->ether_dhost[i] = eh->ether_shost[i]; 599df8bae1dSRodney W. Grimes eh->ether_shost[i] = c; 600df8bae1dSRodney W. Grimes } 601df8bae1dSRodney W. Grimes ifp->if_output(ifp, m, &sa, NULL); 602df8bae1dSRodney W. Grimes return; 603df8bae1dSRodney W. Grimes } 604df8bae1dSRodney W. Grimes default: 605df8bae1dSRodney W. Grimes m_freem(m); 606df8bae1dSRodney W. Grimes return; 607df8bae1dSRodney W. Grimes } 608df8bae1dSRodney W. Grimes break; 609df8bae1dSRodney W. Grimes #endif /* ISO */ 610df8bae1dSRodney W. Grimes #ifdef LLC 611df8bae1dSRodney W. Grimes case LLC_X25_LSAP: 612df8bae1dSRodney W. Grimes { 613307d80beSDavid Greenman if (m->m_pkthdr.len > ether_type) 614307d80beSDavid Greenman m_adj(m, ether_type - m->m_pkthdr.len); 615df8bae1dSRodney W. Grimes M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT); 616df8bae1dSRodney W. Grimes if (m == 0) 617df8bae1dSRodney W. Grimes return; 618df8bae1dSRodney W. Grimes if ( !sdl_sethdrif(ifp, eh->ether_shost, LLC_X25_LSAP, 619df8bae1dSRodney W. Grimes eh->ether_dhost, LLC_X25_LSAP, 6, 620df8bae1dSRodney W. Grimes mtod(m, struct sdl_hdr *))) 621df8bae1dSRodney W. Grimes panic("ETHER cons addr failure"); 622307d80beSDavid Greenman mtod(m, struct sdl_hdr *)->sdlhdr_len = ether_type; 623df8bae1dSRodney W. Grimes #ifdef LLC_DEBUG 624df8bae1dSRodney W. Grimes printf("llc packet\n"); 625df8bae1dSRodney W. Grimes #endif /* LLC_DEBUG */ 626df8bae1dSRodney W. Grimes schednetisr(NETISR_CCITT); 627df8bae1dSRodney W. Grimes inq = &llcintrq; 628df8bae1dSRodney W. Grimes break; 629df8bae1dSRodney W. Grimes } 630df8bae1dSRodney W. Grimes #endif /* LLC */ 631df8bae1dSRodney W. Grimes dropanyway: 632df8bae1dSRodney W. Grimes default: 633df8bae1dSRodney W. Grimes m_freem(m); 634df8bae1dSRodney W. Grimes return; 635df8bae1dSRodney W. Grimes } 636655929bfSJulian Elischer #else /* ISO || LLC || NETATALK */ 637df8bae1dSRodney W. Grimes m_freem(m); 638df8bae1dSRodney W. Grimes return; 639655929bfSJulian Elischer #endif /* ISO || LLC || NETATALK */ 640df8bae1dSRodney W. Grimes } 641df8bae1dSRodney W. Grimes 642df8bae1dSRodney W. Grimes s = splimp(); 643df8bae1dSRodney W. Grimes if (IF_QFULL(inq)) { 644df8bae1dSRodney W. Grimes IF_DROP(inq); 645df8bae1dSRodney W. Grimes m_freem(m); 646df8bae1dSRodney W. Grimes } else 647df8bae1dSRodney W. Grimes IF_ENQUEUE(inq, m); 648df8bae1dSRodney W. Grimes splx(s); 649df8bae1dSRodney W. Grimes } 650df8bae1dSRodney W. Grimes 651df8bae1dSRodney W. Grimes /* 652df8bae1dSRodney W. Grimes * Perform common duties while attaching to interface list 653df8bae1dSRodney W. Grimes */ 654df8bae1dSRodney W. Grimes void 655df8bae1dSRodney W. Grimes ether_ifattach(ifp) 656df8bae1dSRodney W. Grimes register struct ifnet *ifp; 657df8bae1dSRodney W. Grimes { 658df8bae1dSRodney W. Grimes register struct ifaddr *ifa; 659df8bae1dSRodney W. Grimes register struct sockaddr_dl *sdl; 660df8bae1dSRodney W. Grimes 661df8bae1dSRodney W. Grimes ifp->if_type = IFT_ETHER; 662df8bae1dSRodney W. Grimes ifp->if_addrlen = 6; 663df8bae1dSRodney W. Grimes ifp->if_hdrlen = 14; 664df8bae1dSRodney W. Grimes ifp->if_mtu = ETHERMTU; 6651158dfb7SGarrett Wollman ifp->if_resolvemulti = ether_resolvemulti; 666a330e1f1SGary Palmer if (ifp->if_baudrate == 0) 667a330e1f1SGary Palmer ifp->if_baudrate = 10000000; 66859562606SGarrett Wollman ifa = ifnet_addrs[ifp->if_index - 1]; 66959562606SGarrett Wollman if (ifa == 0) { 67059562606SGarrett Wollman printf("ether_ifattach: no lladdr!\n"); 67159562606SGarrett Wollman return; 67259562606SGarrett Wollman } 67359562606SGarrett Wollman sdl = (struct sockaddr_dl *)ifa->ifa_addr; 674df8bae1dSRodney W. Grimes sdl->sdl_type = IFT_ETHER; 675df8bae1dSRodney W. Grimes sdl->sdl_alen = ifp->if_addrlen; 6764c8e8c05SJulian Elischer bcopy((IFP2AC(ifp))->ac_enaddr, LLADDR(sdl), ifp->if_addrlen); 6774c8e8c05SJulian Elischer #ifdef NETGRAPH 6784c8e8c05SJulian Elischer ngether_init(ifp); 6794c8e8c05SJulian Elischer #endif /* NETGRAPH */ 680df8bae1dSRodney W. Grimes } 681df8bae1dSRodney W. Grimes 682ce02431fSDoug Rabson SYSCTL_DECL(_net_link); 683602d513cSGarrett Wollman SYSCTL_NODE(_net_link, IFT_ETHER, ether, CTLFLAG_RW, 0, "Ethernet"); 68430106f6aSPoul-Henning Kamp 685fb583156SDavid Greenman int 686c5a1016bSBruce Evans ether_ioctl(ifp, command, data) 687c5a1016bSBruce Evans struct ifnet *ifp; 688c5a1016bSBruce Evans int command; 689c5a1016bSBruce Evans caddr_t data; 69030106f6aSPoul-Henning Kamp { 69130106f6aSPoul-Henning Kamp struct ifaddr *ifa = (struct ifaddr *) data; 69230106f6aSPoul-Henning Kamp struct ifreq *ifr = (struct ifreq *) data; 693fb583156SDavid Greenman int error = 0; 69430106f6aSPoul-Henning Kamp 69530106f6aSPoul-Henning Kamp switch (command) { 69630106f6aSPoul-Henning Kamp case SIOCSIFADDR: 69730106f6aSPoul-Henning Kamp ifp->if_flags |= IFF_UP; 69830106f6aSPoul-Henning Kamp 69930106f6aSPoul-Henning Kamp switch (ifa->ifa_addr->sa_family) { 70030106f6aSPoul-Henning Kamp #ifdef INET 70130106f6aSPoul-Henning Kamp case AF_INET: 70230106f6aSPoul-Henning Kamp ifp->if_init(ifp->if_softc); /* before arpwhohas */ 7034c8e8c05SJulian Elischer arp_ifinit(IFP2AC(ifp), ifa); 70430106f6aSPoul-Henning Kamp break; 70530106f6aSPoul-Henning Kamp #endif 70630106f6aSPoul-Henning Kamp #ifdef IPX 70730106f6aSPoul-Henning Kamp /* 70830106f6aSPoul-Henning Kamp * XXX - This code is probably wrong 70930106f6aSPoul-Henning Kamp */ 71030106f6aSPoul-Henning Kamp case AF_IPX: 71130106f6aSPoul-Henning Kamp { 71230106f6aSPoul-Henning Kamp register struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr); 7134c8e8c05SJulian Elischer struct arpcom *ac = IFP2AC(ifp); 71430106f6aSPoul-Henning Kamp 71530106f6aSPoul-Henning Kamp if (ipx_nullhost(*ina)) 71630106f6aSPoul-Henning Kamp ina->x_host = 71786101139SPoul-Henning Kamp *(union ipx_host *) 71886101139SPoul-Henning Kamp ac->ac_enaddr; 71930106f6aSPoul-Henning Kamp else { 72030106f6aSPoul-Henning Kamp bcopy((caddr_t) ina->x_host.c_host, 72186101139SPoul-Henning Kamp (caddr_t) ac->ac_enaddr, 72286101139SPoul-Henning Kamp sizeof(ac->ac_enaddr)); 72330106f6aSPoul-Henning Kamp } 72430106f6aSPoul-Henning Kamp 72530106f6aSPoul-Henning Kamp /* 72630106f6aSPoul-Henning Kamp * Set new address 72730106f6aSPoul-Henning Kamp */ 72830106f6aSPoul-Henning Kamp ifp->if_init(ifp->if_softc); 72930106f6aSPoul-Henning Kamp break; 73030106f6aSPoul-Henning Kamp } 73130106f6aSPoul-Henning Kamp #endif 73230106f6aSPoul-Henning Kamp #ifdef NS 73330106f6aSPoul-Henning Kamp /* 73430106f6aSPoul-Henning Kamp * XXX - This code is probably wrong 73530106f6aSPoul-Henning Kamp */ 73630106f6aSPoul-Henning Kamp case AF_NS: 73730106f6aSPoul-Henning Kamp { 73830106f6aSPoul-Henning Kamp register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); 7394c8e8c05SJulian Elischer struct arpcom *ac = IFP2AC(ifp); 74030106f6aSPoul-Henning Kamp 74130106f6aSPoul-Henning Kamp if (ns_nullhost(*ina)) 74230106f6aSPoul-Henning Kamp ina->x_host = 74386101139SPoul-Henning Kamp *(union ns_host *) (ac->ac_enaddr); 74430106f6aSPoul-Henning Kamp else { 74530106f6aSPoul-Henning Kamp bcopy((caddr_t) ina->x_host.c_host, 74686101139SPoul-Henning Kamp (caddr_t) ac->ac_enaddr, 74786101139SPoul-Henning Kamp sizeof(ac->ac_enaddr)); 74830106f6aSPoul-Henning Kamp } 74930106f6aSPoul-Henning Kamp 75030106f6aSPoul-Henning Kamp /* 75130106f6aSPoul-Henning Kamp * Set new address 75230106f6aSPoul-Henning Kamp */ 75330106f6aSPoul-Henning Kamp ifp->if_init(ifp->if_softc); 75430106f6aSPoul-Henning Kamp break; 75530106f6aSPoul-Henning Kamp } 75630106f6aSPoul-Henning Kamp #endif 75730106f6aSPoul-Henning Kamp default: 75830106f6aSPoul-Henning Kamp ifp->if_init(ifp->if_softc); 75930106f6aSPoul-Henning Kamp break; 76030106f6aSPoul-Henning Kamp } 76130106f6aSPoul-Henning Kamp break; 76230106f6aSPoul-Henning Kamp 76330106f6aSPoul-Henning Kamp case SIOCGIFADDR: 76430106f6aSPoul-Henning Kamp { 76530106f6aSPoul-Henning Kamp struct sockaddr *sa; 76630106f6aSPoul-Henning Kamp 76730106f6aSPoul-Henning Kamp sa = (struct sockaddr *) & ifr->ifr_data; 7684c8e8c05SJulian Elischer bcopy(IFP2AC(ifp)->ac_enaddr, 76930106f6aSPoul-Henning Kamp (caddr_t) sa->sa_data, ETHER_ADDR_LEN); 77030106f6aSPoul-Henning Kamp } 77130106f6aSPoul-Henning Kamp break; 772fb583156SDavid Greenman 773fb583156SDavid Greenman case SIOCSIFMTU: 774fb583156SDavid Greenman /* 775fb583156SDavid Greenman * Set the interface MTU. 776fb583156SDavid Greenman */ 777fb583156SDavid Greenman if (ifr->ifr_mtu > ETHERMTU) { 778fb583156SDavid Greenman error = EINVAL; 779fb583156SDavid Greenman } else { 780fb583156SDavid Greenman ifp->if_mtu = ifr->ifr_mtu; 78130106f6aSPoul-Henning Kamp } 782fb583156SDavid Greenman break; 783fb583156SDavid Greenman } 784fb583156SDavid Greenman return (error); 78530106f6aSPoul-Henning Kamp } 7861158dfb7SGarrett Wollman 7871158dfb7SGarrett Wollman int 7881158dfb7SGarrett Wollman ether_resolvemulti(ifp, llsa, sa) 7891158dfb7SGarrett Wollman struct ifnet *ifp; 7901158dfb7SGarrett Wollman struct sockaddr **llsa; 7911158dfb7SGarrett Wollman struct sockaddr *sa; 7921158dfb7SGarrett Wollman { 7931158dfb7SGarrett Wollman struct sockaddr_dl *sdl; 7941158dfb7SGarrett Wollman struct sockaddr_in *sin; 7951158dfb7SGarrett Wollman u_char *e_addr; 7961158dfb7SGarrett Wollman 7971158dfb7SGarrett Wollman switch(sa->sa_family) { 7981158dfb7SGarrett Wollman case AF_LINK: 7997f33a738SJulian Elischer /* 8007f33a738SJulian Elischer * No mapping needed. Just check that it's a valid MC address. 8017f33a738SJulian Elischer */ 8021158dfb7SGarrett Wollman sdl = (struct sockaddr_dl *)sa; 8031158dfb7SGarrett Wollman e_addr = LLADDR(sdl); 8041158dfb7SGarrett Wollman if ((e_addr[0] & 1) != 1) 8051158dfb7SGarrett Wollman return EADDRNOTAVAIL; 8061158dfb7SGarrett Wollman *llsa = 0; 8071158dfb7SGarrett Wollman return 0; 8081158dfb7SGarrett Wollman 8091158dfb7SGarrett Wollman #ifdef INET 8101158dfb7SGarrett Wollman case AF_INET: 8111158dfb7SGarrett Wollman sin = (struct sockaddr_in *)sa; 8121158dfb7SGarrett Wollman if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) 8131158dfb7SGarrett Wollman return EADDRNOTAVAIL; 8141158dfb7SGarrett Wollman MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR, 8151158dfb7SGarrett Wollman M_WAITOK); 8161158dfb7SGarrett Wollman sdl->sdl_len = sizeof *sdl; 8171158dfb7SGarrett Wollman sdl->sdl_family = AF_LINK; 8181158dfb7SGarrett Wollman sdl->sdl_index = ifp->if_index; 8191158dfb7SGarrett Wollman sdl->sdl_type = IFT_ETHER; 8201158dfb7SGarrett Wollman sdl->sdl_nlen = 0; 8211158dfb7SGarrett Wollman sdl->sdl_alen = ETHER_ADDR_LEN; 8221158dfb7SGarrett Wollman sdl->sdl_slen = 0; 8231158dfb7SGarrett Wollman e_addr = LLADDR(sdl); 8241158dfb7SGarrett Wollman ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr); 8251158dfb7SGarrett Wollman *llsa = (struct sockaddr *)sdl; 8261158dfb7SGarrett Wollman return 0; 8271158dfb7SGarrett Wollman #endif 8281158dfb7SGarrett Wollman 8291158dfb7SGarrett Wollman default: 8301158dfb7SGarrett Wollman /* 8311158dfb7SGarrett Wollman * Well, the text isn't quite right, but it's the name 8321158dfb7SGarrett Wollman * that counts... 8331158dfb7SGarrett Wollman */ 8341158dfb7SGarrett Wollman return EAFNOSUPPORT; 8351158dfb7SGarrett Wollman } 8361158dfb7SGarrett Wollman } 837