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 349d3f194dSJulian Elischer * $Id: if_ethersubr.c,v 1.49 1998/06/12 03:48:07 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" 40430df5f4SEivind Eklund 41df8bae1dSRodney W. Grimes #include <sys/param.h> 42df8bae1dSRodney W. Grimes #include <sys/systm.h> 43df8bae1dSRodney W. Grimes #include <sys/kernel.h> 44df8bae1dSRodney W. Grimes #include <sys/malloc.h> 45df8bae1dSRodney W. Grimes #include <sys/mbuf.h> 46df8bae1dSRodney W. Grimes #include <sys/socket.h> 4751a53488SBruce Evans #include <sys/sockio.h> 48602d513cSGarrett Wollman #include <sys/sysctl.h> 49df8bae1dSRodney W. Grimes 50df8bae1dSRodney W. Grimes #include <net/if.h> 51df8bae1dSRodney W. Grimes #include <net/netisr.h> 52df8bae1dSRodney W. Grimes #include <net/route.h> 53df8bae1dSRodney W. Grimes #include <net/if_llc.h> 54df8bae1dSRodney W. Grimes #include <net/if_dl.h> 55df8bae1dSRodney W. Grimes #include <net/if_types.h> 56df8bae1dSRodney W. Grimes 57df8bae1dSRodney W. Grimes #ifdef INET 58df8bae1dSRodney W. Grimes #include <netinet/in.h> 59df8bae1dSRodney W. Grimes #include <netinet/in_var.h> 60df8bae1dSRodney W. Grimes #include <netinet/if_ether.h> 611d5e9e22SEivind Eklund #endif 62df8bae1dSRodney W. Grimes 63cc6a66f2SJulian Elischer #ifdef IPX 64cc6a66f2SJulian Elischer #include <netipx/ipx.h> 65cc6a66f2SJulian Elischer #include <netipx/ipx_if.h> 66cc6a66f2SJulian Elischer #endif 67cc6a66f2SJulian Elischer 68df8bae1dSRodney W. Grimes #ifdef NS 69df8bae1dSRodney W. Grimes #include <netns/ns.h> 70df8bae1dSRodney W. Grimes #include <netns/ns_if.h> 71d0ec898dSJordan K. Hubbard ushort ns_nettype; 7288e038feSJordan K. Hubbard int ether_outputdebug = 0; 7388e038feSJordan K. Hubbard int ether_inputdebug = 0; 74df8bae1dSRodney W. Grimes #endif 75df8bae1dSRodney W. Grimes 76df8bae1dSRodney W. Grimes #ifdef ISO 77df8bae1dSRodney W. Grimes #include <netiso/argo_debug.h> 78df8bae1dSRodney W. Grimes #include <netiso/iso.h> 79df8bae1dSRodney W. Grimes #include <netiso/iso_var.h> 80df8bae1dSRodney W. Grimes #include <netiso/iso_snpac.h> 81df8bae1dSRodney W. Grimes #endif 82df8bae1dSRodney W. Grimes 83655929bfSJulian Elischer /*#ifdef LLC 84df8bae1dSRodney W. Grimes #include <netccitt/dll.h> 85df8bae1dSRodney W. Grimes #include <netccitt/llc_var.h> 86655929bfSJulian Elischer #endif*/ 87df8bae1dSRodney W. Grimes 88df8bae1dSRodney W. Grimes #if defined(LLC) && defined(CCITT) 89df8bae1dSRodney W. Grimes extern struct ifqueue pkintrq; 90df8bae1dSRodney W. Grimes #endif 91df8bae1dSRodney W. Grimes 92655929bfSJulian Elischer #ifdef NETATALK 93655929bfSJulian Elischer #include <netatalk/at.h> 94655929bfSJulian Elischer #include <netatalk/at_var.h> 95655929bfSJulian Elischer #include <netatalk/at_extern.h> 96655929bfSJulian Elischer 97655929bfSJulian Elischer #define llc_snap_org_code llc_un.type_snap.org_code 98655929bfSJulian Elischer #define llc_snap_ether_type llc_un.type_snap.ether_type 99655929bfSJulian Elischer 100655929bfSJulian Elischer extern u_char at_org_code[3]; 101655929bfSJulian Elischer extern u_char aarp_org_code[3]; 1022cc2df49SGarrett Wollman #endif /* NETATALK */ 1032cc2df49SGarrett Wollman 1042cc2df49SGarrett Wollman #include "vlan.h" 1052cc2df49SGarrett Wollman #if NVLAN > 0 1062cc2df49SGarrett Wollman #include <net/if_vlan_var.h> 1072cc2df49SGarrett Wollman #endif /* NVLAN > 0 */ 108655929bfSJulian Elischer 1091158dfb7SGarrett Wollman static int ether_resolvemulti __P((struct ifnet *, struct sockaddr **, 1101158dfb7SGarrett Wollman struct sockaddr *)); 111df8bae1dSRodney W. Grimes u_char etherbroadcastaddr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 112df8bae1dSRodney W. Grimes #define senderr(e) { error = (e); goto bad;} 113df8bae1dSRodney W. Grimes 114df8bae1dSRodney W. Grimes /* 115df8bae1dSRodney W. Grimes * Ethernet output routine. 116df8bae1dSRodney W. Grimes * Encapsulate a packet of type family for the local net. 117df8bae1dSRodney W. Grimes * Use trailer local net encapsulation if enough data in first 118df8bae1dSRodney W. Grimes * packet leaves a multiple of 512 bytes of data in remainder. 119df8bae1dSRodney W. Grimes * Assumes that ifp is actually pointer to arpcom structure. 120df8bae1dSRodney W. Grimes */ 121df8bae1dSRodney W. Grimes int 122df8bae1dSRodney W. Grimes ether_output(ifp, m0, dst, rt0) 123df8bae1dSRodney W. Grimes register struct ifnet *ifp; 124df8bae1dSRodney W. Grimes struct mbuf *m0; 125df8bae1dSRodney W. Grimes struct sockaddr *dst; 126df8bae1dSRodney W. Grimes struct rtentry *rt0; 127df8bae1dSRodney W. Grimes { 128df8bae1dSRodney W. Grimes short type; 129df8bae1dSRodney W. Grimes int s, error = 0; 1304a11ca4eSPoul-Henning Kamp u_char edst[6]; 1314a11ca4eSPoul-Henning Kamp register struct mbuf *m = m0; 132df8bae1dSRodney W. Grimes register struct rtentry *rt; 133df8bae1dSRodney W. Grimes register struct ether_header *eh; 134ed7509acSJulian Elischer int off, len = m->m_pkthdr.len, loop_copy = 0; 135df8bae1dSRodney W. Grimes struct arpcom *ac = (struct arpcom *)ifp; 136df8bae1dSRodney W. Grimes 137df8bae1dSRodney W. Grimes if ((ifp->if_flags & (IFF_UP|IFF_RUNNING)) != (IFF_UP|IFF_RUNNING)) 138df8bae1dSRodney W. Grimes senderr(ENETDOWN); 1393bda9f9bSPoul-Henning Kamp rt = rt0; 1403bda9f9bSPoul-Henning Kamp if (rt) { 141df8bae1dSRodney W. Grimes if ((rt->rt_flags & RTF_UP) == 0) { 1423bda9f9bSPoul-Henning Kamp rt0 = rt = rtalloc1(dst, 1, 0UL); 1433bda9f9bSPoul-Henning Kamp if (rt0) 144df8bae1dSRodney W. Grimes rt->rt_refcnt--; 145df8bae1dSRodney W. Grimes else 146df8bae1dSRodney W. Grimes senderr(EHOSTUNREACH); 147df8bae1dSRodney W. Grimes } 148df8bae1dSRodney W. Grimes if (rt->rt_flags & RTF_GATEWAY) { 149df8bae1dSRodney W. Grimes if (rt->rt_gwroute == 0) 150df8bae1dSRodney W. Grimes goto lookup; 151df8bae1dSRodney W. Grimes if (((rt = rt->rt_gwroute)->rt_flags & RTF_UP) == 0) { 152df8bae1dSRodney W. Grimes rtfree(rt); rt = rt0; 153995add1aSGarrett Wollman lookup: rt->rt_gwroute = rtalloc1(rt->rt_gateway, 1, 154995add1aSGarrett Wollman 0UL); 155df8bae1dSRodney W. Grimes if ((rt = rt->rt_gwroute) == 0) 156df8bae1dSRodney W. Grimes senderr(EHOSTUNREACH); 157df8bae1dSRodney W. Grimes } 158df8bae1dSRodney W. Grimes } 159df8bae1dSRodney W. Grimes if (rt->rt_flags & RTF_REJECT) 160df8bae1dSRodney W. Grimes if (rt->rt_rmx.rmx_expire == 0 || 161227ee8a1SPoul-Henning Kamp time_second < rt->rt_rmx.rmx_expire) 162df8bae1dSRodney W. Grimes senderr(rt == rt0 ? EHOSTDOWN : EHOSTUNREACH); 163df8bae1dSRodney W. Grimes } 164df8bae1dSRodney W. Grimes switch (dst->sa_family) { 165df8bae1dSRodney W. Grimes #ifdef INET 166df8bae1dSRodney W. Grimes case AF_INET: 1675df72964SGarrett Wollman if (!arpresolve(ac, rt, m, dst, edst, rt0)) 168df8bae1dSRodney W. Grimes return (0); /* if not yet resolved */ 169df8bae1dSRodney W. Grimes off = m->m_pkthdr.len - m->m_len; 17034bed8b0SDavid Greenman type = htons(ETHERTYPE_IP); 171df8bae1dSRodney W. Grimes break; 172df8bae1dSRodney W. Grimes #endif 173cc6a66f2SJulian Elischer #ifdef IPX 174cc6a66f2SJulian Elischer case AF_IPX: 17534bed8b0SDavid Greenman type = htons(ETHERTYPE_IPX); 176cc6a66f2SJulian Elischer bcopy((caddr_t)&(((struct sockaddr_ipx *)dst)->sipx_addr.x_host), 177cc6a66f2SJulian Elischer (caddr_t)edst, sizeof (edst)); 178cc6a66f2SJulian Elischer break; 179cc6a66f2SJulian Elischer #endif 180655929bfSJulian Elischer #ifdef NETATALK 181655929bfSJulian Elischer case AF_APPLETALK: 1821d0eab59SJulian Elischer { 183ed7509acSJulian Elischer struct at_ifaddr *aa; 1841d0eab59SJulian Elischer 185ed7509acSJulian Elischer if ((aa = at_ifawithnet((struct sockaddr_at *)dst)) == NULL) { 1861d0eab59SJulian Elischer goto bad; 1871d0eab59SJulian Elischer } 188ed7509acSJulian Elischer if (!aarpresolve(ac, m, (struct sockaddr_at *)dst, edst)) 1891d0eab59SJulian Elischer return (0); 190655929bfSJulian Elischer /* 191ed7509acSJulian Elischer * In the phase 2 case, need to prepend an mbuf for the llc header. 192655929bfSJulian Elischer * Since we must preserve the value of m, which is passed to us by 193655929bfSJulian Elischer * value, we m_copy() the first mbuf, and use it for our llc header. 194655929bfSJulian Elischer */ 195655929bfSJulian Elischer if ( aa->aa_flags & AFA_PHASE2 ) { 196655929bfSJulian Elischer struct llc llc; 197655929bfSJulian Elischer 198655929bfSJulian Elischer M_PREPEND(m, sizeof(struct llc), M_WAIT); 199655929bfSJulian Elischer len += sizeof(struct llc); 200655929bfSJulian Elischer llc.llc_dsap = llc.llc_ssap = LLC_SNAP_LSAP; 201655929bfSJulian Elischer llc.llc_control = LLC_UI; 202655929bfSJulian Elischer bcopy(at_org_code, llc.llc_snap_org_code, sizeof(at_org_code)); 203655929bfSJulian Elischer llc.llc_snap_ether_type = htons( ETHERTYPE_AT ); 204655929bfSJulian Elischer bcopy(&llc, mtod(m, caddr_t), sizeof(struct llc)); 20534bed8b0SDavid Greenman type = htons(m->m_pkthdr.len); 206655929bfSJulian Elischer } else { 20734bed8b0SDavid Greenman type = htons(ETHERTYPE_AT); 208655929bfSJulian Elischer } 209655929bfSJulian Elischer break; 210ed7509acSJulian Elischer } 211655929bfSJulian Elischer #endif NETATALK 212df8bae1dSRodney W. Grimes #ifdef NS 213df8bae1dSRodney W. Grimes case AF_NS: 21488e038feSJordan K. Hubbard switch(ns_nettype){ 21588e038feSJordan K. Hubbard default: 21688e038feSJordan K. Hubbard case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */ 21788e038feSJordan K. Hubbard type = 0x8137; 21888e038feSJordan K. Hubbard break; 21988e038feSJordan K. Hubbard case 0x0: /* Novell 802.3 */ 22088e038feSJordan K. Hubbard type = htons( m->m_pkthdr.len); 22188e038feSJordan K. Hubbard break; 22288e038feSJordan K. Hubbard case 0xe0e0: /* Novell 802.2 and Token-Ring */ 22388e038feSJordan K. Hubbard M_PREPEND(m, 3, M_WAIT); 22488e038feSJordan K. Hubbard type = htons( m->m_pkthdr.len); 22588e038feSJordan K. Hubbard cp = mtod(m, u_char *); 22688e038feSJordan K. Hubbard *cp++ = 0xE0; 22788e038feSJordan K. Hubbard *cp++ = 0xE0; 22888e038feSJordan K. Hubbard *cp++ = 0x03; 22988e038feSJordan K. Hubbard break; 23088e038feSJordan K. Hubbard } 231df8bae1dSRodney W. Grimes bcopy((caddr_t)&(((struct sockaddr_ns *)dst)->sns_addr.x_host), 232df8bae1dSRodney W. Grimes (caddr_t)edst, sizeof (edst)); 23388e038feSJordan K. Hubbard if (!bcmp((caddr_t)edst, (caddr_t)&ns_thishost, sizeof(edst))){ 23488e038feSJordan K. Hubbard m->m_pkthdr.rcvif = ifp; 23588e038feSJordan K. Hubbard schednetisr(NETISR_NS); 23688e038feSJordan K. Hubbard inq = &nsintrq; 23788e038feSJordan K. Hubbard s = splimp(); 23888e038feSJordan K. Hubbard if (IF_QFULL(inq)) { 23988e038feSJordan K. Hubbard IF_DROP(inq); 24088e038feSJordan K. Hubbard m_freem(m); 24188e038feSJordan K. Hubbard } else 24288e038feSJordan K. Hubbard IF_ENQUEUE(inq, m); 24388e038feSJordan K. Hubbard splx(s); 24488e038feSJordan K. Hubbard return (error); 24588e038feSJordan K. Hubbard } 24688e038feSJordan K. Hubbard if (!bcmp((caddr_t)edst, (caddr_t)&ns_broadhost, sizeof(edst))){ 24788e038feSJordan K. Hubbard m2 = m_copy(m, 0, (int)M_COPYALL); 24888e038feSJordan K. Hubbard m2->m_pkthdr.rcvif = ifp; 24988e038feSJordan K. Hubbard schednetisr(NETISR_NS); 25088e038feSJordan K. Hubbard inq = &nsintrq; 25188e038feSJordan K. Hubbard s = splimp(); 25288e038feSJordan K. Hubbard if (IF_QFULL(inq)) { 25388e038feSJordan K. Hubbard IF_DROP(inq); 25488e038feSJordan K. Hubbard m_freem(m2); 25588e038feSJordan K. Hubbard } else 25688e038feSJordan K. Hubbard IF_ENQUEUE(inq, m2); 25788e038feSJordan K. Hubbard splx(s); 25888e038feSJordan K. Hubbard } 259df8bae1dSRodney W. Grimes break; 26088e038feSJordan K. Hubbard #endif /* NS */ 261df8bae1dSRodney W. Grimes #ifdef ISO 262df8bae1dSRodney W. Grimes case AF_ISO: { 263df8bae1dSRodney W. Grimes int snpalen; 264df8bae1dSRodney W. Grimes struct llc *l; 265df8bae1dSRodney W. Grimes register struct sockaddr_dl *sdl; 266df8bae1dSRodney W. Grimes 267df8bae1dSRodney W. Grimes if (rt && (sdl = (struct sockaddr_dl *)rt->rt_gateway) && 268df8bae1dSRodney W. Grimes sdl->sdl_family == AF_LINK && sdl->sdl_alen > 0) { 269df8bae1dSRodney W. Grimes bcopy(LLADDR(sdl), (caddr_t)edst, sizeof(edst)); 270df8bae1dSRodney W. Grimes } else if (error = 271df8bae1dSRodney W. Grimes iso_snparesolve(ifp, (struct sockaddr_iso *)dst, 272df8bae1dSRodney W. Grimes (char *)edst, &snpalen)) 273df8bae1dSRodney W. Grimes goto bad; /* Not Resolved */ 274df8bae1dSRodney W. Grimes /* If broadcasting on a simplex interface, loopback a copy */ 275df8bae1dSRodney W. Grimes if (*edst & 1) 276df8bae1dSRodney W. Grimes m->m_flags |= (M_BCAST|M_MCAST); 277df8bae1dSRodney W. Grimes M_PREPEND(m, 3, M_DONTWAIT); 278df8bae1dSRodney W. Grimes if (m == NULL) 279df8bae1dSRodney W. Grimes return (0); 28034bed8b0SDavid Greenman type = htons(m->m_pkthdr.len); 281df8bae1dSRodney W. Grimes l = mtod(m, struct llc *); 282df8bae1dSRodney W. Grimes l->llc_dsap = l->llc_ssap = LLC_ISO_LSAP; 283df8bae1dSRodney W. Grimes l->llc_control = LLC_UI; 284df8bae1dSRodney W. Grimes len += 3; 285df8bae1dSRodney W. Grimes IFDEBUG(D_ETHER) 286df8bae1dSRodney W. Grimes int i; 287df8bae1dSRodney W. Grimes printf("unoutput: sending pkt to: "); 288df8bae1dSRodney W. Grimes for (i=0; i<6; i++) 289df8bae1dSRodney W. Grimes printf("%x ", edst[i] & 0xff); 290df8bae1dSRodney W. Grimes printf("\n"); 291df8bae1dSRodney W. Grimes ENDDEBUG 292df8bae1dSRodney W. Grimes } break; 293df8bae1dSRodney W. Grimes #endif /* ISO */ 294df8bae1dSRodney W. Grimes #ifdef LLC 295df8bae1dSRodney W. Grimes /* case AF_NSAP: */ 296df8bae1dSRodney W. Grimes case AF_CCITT: { 297df8bae1dSRodney W. Grimes register struct sockaddr_dl *sdl = 298df8bae1dSRodney W. Grimes (struct sockaddr_dl *) rt -> rt_gateway; 299df8bae1dSRodney W. Grimes 300df8bae1dSRodney W. Grimes if (sdl && sdl->sdl_family == AF_LINK 301df8bae1dSRodney W. Grimes && sdl->sdl_alen > 0) { 302ed7509acSJulian Elischer bcopy(LLADDR(sdl), (char *)edst, sizeof(edst)); 303df8bae1dSRodney W. Grimes } else goto bad; /* Not a link interface ? Funny ... */ 304ed7509acSJulian Elischer if (*edst & 1) 305ed7509acSJulian Elischer loop_copy = 1; 30634bed8b0SDavid Greenman type = htons(m->m_pkthdr.len); 307df8bae1dSRodney W. Grimes #ifdef LLC_DEBUG 308df8bae1dSRodney W. Grimes { 309df8bae1dSRodney W. Grimes int i; 310df8bae1dSRodney W. Grimes register struct llc *l = mtod(m, struct llc *); 311df8bae1dSRodney W. Grimes 312df8bae1dSRodney W. Grimes printf("ether_output: sending LLC2 pkt to: "); 313df8bae1dSRodney W. Grimes for (i=0; i<6; i++) 314df8bae1dSRodney W. Grimes printf("%x ", edst[i] & 0xff); 315df8bae1dSRodney W. Grimes printf(" len 0x%x dsap 0x%x ssap 0x%x control 0x%x\n", 316df8bae1dSRodney W. Grimes type & 0xff, l->llc_dsap & 0xff, l->llc_ssap &0xff, 317df8bae1dSRodney W. Grimes l->llc_control & 0xff); 318df8bae1dSRodney W. Grimes 319df8bae1dSRodney W. Grimes } 320df8bae1dSRodney W. Grimes #endif /* LLC_DEBUG */ 321df8bae1dSRodney W. Grimes } break; 322df8bae1dSRodney W. Grimes #endif /* LLC */ 323df8bae1dSRodney W. Grimes 324df8bae1dSRodney W. Grimes case AF_UNSPEC: 3259d3f194dSJulian Elischer loop_copy = -1; /* if this is for us, don't do it */ 326df8bae1dSRodney W. Grimes eh = (struct ether_header *)dst->sa_data; 32794a5d9b6SDavid Greenman (void)memcpy(edst, eh->ether_dhost, sizeof (edst)); 328df8bae1dSRodney W. Grimes type = eh->ether_type; 329df8bae1dSRodney W. Grimes break; 330df8bae1dSRodney W. Grimes 331df8bae1dSRodney W. Grimes default: 332df8bae1dSRodney W. Grimes printf("%s%d: can't handle af%d\n", ifp->if_name, ifp->if_unit, 333df8bae1dSRodney W. Grimes dst->sa_family); 334df8bae1dSRodney W. Grimes senderr(EAFNOSUPPORT); 335df8bae1dSRodney W. Grimes } 336df8bae1dSRodney W. Grimes 337df8bae1dSRodney W. Grimes /* 338df8bae1dSRodney W. Grimes * Add local net header. If no space in first mbuf, 339df8bae1dSRodney W. Grimes * allocate another. 340df8bae1dSRodney W. Grimes */ 341df8bae1dSRodney W. Grimes M_PREPEND(m, sizeof (struct ether_header), M_DONTWAIT); 342df8bae1dSRodney W. Grimes if (m == 0) 343df8bae1dSRodney W. Grimes senderr(ENOBUFS); 344df8bae1dSRodney W. Grimes eh = mtod(m, struct ether_header *); 34594a5d9b6SDavid Greenman (void)memcpy(&eh->ether_type, &type, 346df8bae1dSRodney W. Grimes sizeof(eh->ether_type)); 34794a5d9b6SDavid Greenman (void)memcpy(eh->ether_dhost, edst, sizeof (edst)); 34894a5d9b6SDavid Greenman (void)memcpy(eh->ether_shost, ac->ac_enaddr, 349df8bae1dSRodney W. Grimes sizeof(eh->ether_shost)); 350ed7509acSJulian Elischer 351ed7509acSJulian Elischer /* 352ed7509acSJulian Elischer * If a simplex interface, and the packet is being sent to our 353ed7509acSJulian Elischer * Ethernet address or a broadcast address, loopback a copy. 354ed7509acSJulian Elischer * XXX To make a simplex device behave exactly like a duplex 355ed7509acSJulian Elischer * device, we should copy in the case of sending to our own 356ed7509acSJulian Elischer * ethernet address (thus letting the original actually appear 357ed7509acSJulian Elischer * on the wire). However, we don't do that here for security 358ed7509acSJulian Elischer * reasons and compatibility with the original behavior. 359ed7509acSJulian Elischer */ 360ed7509acSJulian Elischer if (ifp->if_flags & IFF_SIMPLEX) { 3619d3f194dSJulian Elischer if ((m->m_flags & M_BCAST) || (loop_copy > 0)) { 362ed7509acSJulian Elischer struct mbuf *n = m_copy(m, 0, (int)M_COPYALL); 363ed7509acSJulian Elischer 364ed7509acSJulian Elischer (void) if_simloop(ifp, n, dst, ETHER_HDR_LEN); 365ed7509acSJulian Elischer } else if (bcmp(eh->ether_dhost, 366ed7509acSJulian Elischer eh->ether_shost, ETHER_ADDR_LEN) == 0) { 3679d3f194dSJulian Elischer if (loop_copy != -1) 3689d3f194dSJulian Elischer (void) if_simloop(ifp, m, dst, 3699d3f194dSJulian Elischer ETHER_HDR_LEN); 370ed7509acSJulian Elischer return(0); /* XXX */ 371ed7509acSJulian Elischer } 372ed7509acSJulian Elischer } 373ed7509acSJulian Elischer 374df8bae1dSRodney W. Grimes s = splimp(); 375df8bae1dSRodney W. Grimes /* 376df8bae1dSRodney W. Grimes * Queue message on interface, and start output if interface 377df8bae1dSRodney W. Grimes * not yet active. 378df8bae1dSRodney W. Grimes */ 379df8bae1dSRodney W. Grimes if (IF_QFULL(&ifp->if_snd)) { 380df8bae1dSRodney W. Grimes IF_DROP(&ifp->if_snd); 381df8bae1dSRodney W. Grimes splx(s); 382df8bae1dSRodney W. Grimes senderr(ENOBUFS); 383df8bae1dSRodney W. Grimes } 384df8bae1dSRodney W. Grimes IF_ENQUEUE(&ifp->if_snd, m); 385df8bae1dSRodney W. Grimes if ((ifp->if_flags & IFF_OACTIVE) == 0) 386df8bae1dSRodney W. Grimes (*ifp->if_start)(ifp); 387df8bae1dSRodney W. Grimes splx(s); 388df8bae1dSRodney W. Grimes ifp->if_obytes += len + sizeof (struct ether_header); 389df8bae1dSRodney W. Grimes if (m->m_flags & M_MCAST) 390df8bae1dSRodney W. Grimes ifp->if_omcasts++; 391df8bae1dSRodney W. Grimes return (error); 392df8bae1dSRodney W. Grimes 393df8bae1dSRodney W. Grimes bad: 394df8bae1dSRodney W. Grimes if (m) 395df8bae1dSRodney W. Grimes m_freem(m); 396df8bae1dSRodney W. Grimes return (error); 397df8bae1dSRodney W. Grimes } 398df8bae1dSRodney W. Grimes 399df8bae1dSRodney W. Grimes /* 400df8bae1dSRodney W. Grimes * Process a received Ethernet packet; 401df8bae1dSRodney W. Grimes * the packet is in the mbuf chain m without 402df8bae1dSRodney W. Grimes * the ether header, which is provided separately. 403df8bae1dSRodney W. Grimes */ 404df8bae1dSRodney W. Grimes void 405df8bae1dSRodney W. Grimes ether_input(ifp, eh, m) 406df8bae1dSRodney W. Grimes struct ifnet *ifp; 407df8bae1dSRodney W. Grimes register struct ether_header *eh; 408df8bae1dSRodney W. Grimes struct mbuf *m; 409df8bae1dSRodney W. Grimes { 410df8bae1dSRodney W. Grimes register struct ifqueue *inq; 4114a11ca4eSPoul-Henning Kamp u_short ether_type; 412df8bae1dSRodney W. Grimes int s; 4138e3bda06SJulian Elischer #if defined (ISO) || defined (LLC) || defined(NETATALK) 414c23670e2SGary Palmer register struct llc *l; 415c23670e2SGary Palmer #endif 416df8bae1dSRodney W. Grimes 417df8bae1dSRodney W. Grimes if ((ifp->if_flags & IFF_UP) == 0) { 418df8bae1dSRodney W. Grimes m_freem(m); 419df8bae1dSRodney W. Grimes return; 420df8bae1dSRodney W. Grimes } 421df8bae1dSRodney W. Grimes ifp->if_ibytes += m->m_pkthdr.len + sizeof (*eh); 4222cc2df49SGarrett Wollman if (eh->ether_dhost[0] & 1) { 423df8bae1dSRodney W. Grimes if (bcmp((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost, 424df8bae1dSRodney W. Grimes sizeof(etherbroadcastaddr)) == 0) 425df8bae1dSRodney W. Grimes m->m_flags |= M_BCAST; 4262cc2df49SGarrett Wollman else 427df8bae1dSRodney W. Grimes m->m_flags |= M_MCAST; 4282cc2df49SGarrett Wollman } 429df8bae1dSRodney W. Grimes if (m->m_flags & (M_BCAST|M_MCAST)) 430df8bae1dSRodney W. Grimes ifp->if_imcasts++; 431df8bae1dSRodney W. Grimes 432307d80beSDavid Greenman ether_type = ntohs(eh->ether_type); 433307d80beSDavid Greenman 4342cc2df49SGarrett Wollman #if NVLAN > 0 4352cc2df49SGarrett Wollman if (ether_type == vlan_proto) { 4362cc2df49SGarrett Wollman if (vlan_input(eh, m) < 0) 4372cc2df49SGarrett Wollman ifp->if_data.ifi_noproto++; 4382cc2df49SGarrett Wollman return; 4392cc2df49SGarrett Wollman } 4402cc2df49SGarrett Wollman #endif /* NVLAN > 0 */ 4412cc2df49SGarrett Wollman 442307d80beSDavid Greenman switch (ether_type) { 443df8bae1dSRodney W. Grimes #ifdef INET 444df8bae1dSRodney W. Grimes case ETHERTYPE_IP: 4451f91d8c5SDavid Greenman if (ipflow_fastforward(m)) 4461f91d8c5SDavid Greenman return; 447df8bae1dSRodney W. Grimes schednetisr(NETISR_IP); 448df8bae1dSRodney W. Grimes inq = &ipintrq; 449df8bae1dSRodney W. Grimes break; 450df8bae1dSRodney W. Grimes 451df8bae1dSRodney W. Grimes case ETHERTYPE_ARP: 452df8bae1dSRodney W. Grimes schednetisr(NETISR_ARP); 453df8bae1dSRodney W. Grimes inq = &arpintrq; 454df8bae1dSRodney W. Grimes break; 455df8bae1dSRodney W. Grimes #endif 456cc6a66f2SJulian Elischer #ifdef IPX 457cc6a66f2SJulian Elischer case ETHERTYPE_IPX: 458cc6a66f2SJulian Elischer schednetisr(NETISR_IPX); 459cc6a66f2SJulian Elischer inq = &ipxintrq; 460cc6a66f2SJulian Elischer break; 461cc6a66f2SJulian Elischer #endif 462df8bae1dSRodney W. Grimes #ifdef NS 46388e038feSJordan K. Hubbard case 0x8137: /* Novell Ethernet_II Ethernet TYPE II */ 464df8bae1dSRodney W. Grimes schednetisr(NETISR_NS); 465df8bae1dSRodney W. Grimes inq = &nsintrq; 466df8bae1dSRodney W. Grimes break; 46788e038feSJordan K. Hubbard 46888e038feSJordan K. Hubbard #endif /* NS */ 469655929bfSJulian Elischer #ifdef NETATALK 470655929bfSJulian Elischer case ETHERTYPE_AT: 471655929bfSJulian Elischer schednetisr(NETISR_ATALK); 472655929bfSJulian Elischer inq = &atintrq1; 473655929bfSJulian Elischer break; 474655929bfSJulian Elischer case ETHERTYPE_AARP: 475655929bfSJulian Elischer /* probably this should be done with a NETISR as well */ 476655929bfSJulian Elischer aarpinput((struct arpcom *)ifp, m); /* XXX */ 477655929bfSJulian Elischer return; 478655929bfSJulian Elischer #endif NETATALK 479df8bae1dSRodney W. Grimes default: 48088e038feSJordan K. Hubbard #ifdef NS 48188e038feSJordan K. Hubbard checksum = mtod(m, ushort *); 48288e038feSJordan K. Hubbard /* Novell 802.3 */ 48388e038feSJordan K. Hubbard if ((ether_type <= ETHERMTU) && 48488e038feSJordan K. Hubbard ((*checksum == 0xffff) || (*checksum == 0xE0E0))){ 48588e038feSJordan K. Hubbard if(*checksum == 0xE0E0) { 48688e038feSJordan K. Hubbard m->m_pkthdr.len -= 3; 48788e038feSJordan K. Hubbard m->m_len -= 3; 48888e038feSJordan K. Hubbard m->m_data += 3; 48988e038feSJordan K. Hubbard } 49088e038feSJordan K. Hubbard schednetisr(NETISR_NS); 49188e038feSJordan K. Hubbard inq = &nsintrq; 49288e038feSJordan K. Hubbard break; 49388e038feSJordan K. Hubbard } 49488e038feSJordan K. Hubbard #endif /* NS */ 495655929bfSJulian Elischer #if defined (ISO) || defined (LLC) || defined(NETATALK) 496307d80beSDavid Greenman if (ether_type > ETHERMTU) 497df8bae1dSRodney W. Grimes goto dropanyway; 498df8bae1dSRodney W. Grimes l = mtod(m, struct llc *); 499df8bae1dSRodney W. Grimes switch (l->llc_dsap) { 500655929bfSJulian Elischer #ifdef NETATALK 501655929bfSJulian Elischer case LLC_SNAP_LSAP: 502655929bfSJulian Elischer switch (l->llc_control) { 503655929bfSJulian Elischer case LLC_UI: 504655929bfSJulian Elischer if (l->llc_ssap != LLC_SNAP_LSAP) 505655929bfSJulian Elischer goto dropanyway; 506655929bfSJulian Elischer 507655929bfSJulian Elischer if (Bcmp(&(l->llc_snap_org_code)[0], at_org_code, 508655929bfSJulian Elischer sizeof(at_org_code)) == 0 && 509655929bfSJulian Elischer ntohs(l->llc_snap_ether_type) == ETHERTYPE_AT) { 510655929bfSJulian Elischer inq = &atintrq2; 511655929bfSJulian Elischer m_adj( m, sizeof( struct llc )); 512655929bfSJulian Elischer schednetisr(NETISR_ATALK); 513655929bfSJulian Elischer break; 514655929bfSJulian Elischer } 515655929bfSJulian Elischer 516655929bfSJulian Elischer if (Bcmp(&(l->llc_snap_org_code)[0], aarp_org_code, 517655929bfSJulian Elischer sizeof(aarp_org_code)) == 0 && 518655929bfSJulian Elischer ntohs(l->llc_snap_ether_type) == ETHERTYPE_AARP) { 519655929bfSJulian Elischer m_adj( m, sizeof( struct llc )); 520655929bfSJulian Elischer aarpinput((struct arpcom *)ifp, m); /* XXX */ 521655929bfSJulian Elischer return; 522655929bfSJulian Elischer } 523655929bfSJulian Elischer 524655929bfSJulian Elischer default: 525655929bfSJulian Elischer goto dropanyway; 526655929bfSJulian Elischer } 527655929bfSJulian Elischer break; 528655929bfSJulian Elischer #endif NETATALK 529df8bae1dSRodney W. Grimes #ifdef ISO 530df8bae1dSRodney W. Grimes case LLC_ISO_LSAP: 531df8bae1dSRodney W. Grimes switch (l->llc_control) { 532df8bae1dSRodney W. Grimes case LLC_UI: 533df8bae1dSRodney W. Grimes /* LLC_UI_P forbidden in class 1 service */ 534df8bae1dSRodney W. Grimes if ((l->llc_dsap == LLC_ISO_LSAP) && 535df8bae1dSRodney W. Grimes (l->llc_ssap == LLC_ISO_LSAP)) { 536df8bae1dSRodney W. Grimes /* LSAP for ISO */ 537307d80beSDavid Greenman if (m->m_pkthdr.len > ether_type) 538307d80beSDavid Greenman m_adj(m, ether_type - m->m_pkthdr.len); 539df8bae1dSRodney W. Grimes m->m_data += 3; /* XXX */ 540df8bae1dSRodney W. Grimes m->m_len -= 3; /* XXX */ 541df8bae1dSRodney W. Grimes m->m_pkthdr.len -= 3; /* XXX */ 542df8bae1dSRodney W. Grimes M_PREPEND(m, sizeof *eh, M_DONTWAIT); 543df8bae1dSRodney W. Grimes if (m == 0) 544df8bae1dSRodney W. Grimes return; 545df8bae1dSRodney W. Grimes *mtod(m, struct ether_header *) = *eh; 546df8bae1dSRodney W. Grimes IFDEBUG(D_ETHER) 547df8bae1dSRodney W. Grimes printf("clnp packet"); 548df8bae1dSRodney W. Grimes ENDDEBUG 549df8bae1dSRodney W. Grimes schednetisr(NETISR_ISO); 550df8bae1dSRodney W. Grimes inq = &clnlintrq; 551df8bae1dSRodney W. Grimes break; 552df8bae1dSRodney W. Grimes } 553df8bae1dSRodney W. Grimes goto dropanyway; 554df8bae1dSRodney W. Grimes 555df8bae1dSRodney W. Grimes case LLC_XID: 556df8bae1dSRodney W. Grimes case LLC_XID_P: 557df8bae1dSRodney W. Grimes if(m->m_len < 6) 558df8bae1dSRodney W. Grimes goto dropanyway; 559df8bae1dSRodney W. Grimes l->llc_window = 0; 560df8bae1dSRodney W. Grimes l->llc_fid = 9; 561df8bae1dSRodney W. Grimes l->llc_class = 1; 562df8bae1dSRodney W. Grimes l->llc_dsap = l->llc_ssap = 0; 563df8bae1dSRodney W. Grimes /* Fall through to */ 564df8bae1dSRodney W. Grimes case LLC_TEST: 565df8bae1dSRodney W. Grimes case LLC_TEST_P: 566df8bae1dSRodney W. Grimes { 567df8bae1dSRodney W. Grimes struct sockaddr sa; 568df8bae1dSRodney W. Grimes register struct ether_header *eh2; 569df8bae1dSRodney W. Grimes int i; 570df8bae1dSRodney W. Grimes u_char c = l->llc_dsap; 571df8bae1dSRodney W. Grimes 572df8bae1dSRodney W. Grimes l->llc_dsap = l->llc_ssap; 573df8bae1dSRodney W. Grimes l->llc_ssap = c; 574df8bae1dSRodney W. Grimes if (m->m_flags & (M_BCAST | M_MCAST)) 575df8bae1dSRodney W. Grimes bcopy((caddr_t)ac->ac_enaddr, 576df8bae1dSRodney W. Grimes (caddr_t)eh->ether_dhost, 6); 577df8bae1dSRodney W. Grimes sa.sa_family = AF_UNSPEC; 578df8bae1dSRodney W. Grimes sa.sa_len = sizeof(sa); 579df8bae1dSRodney W. Grimes eh2 = (struct ether_header *)sa.sa_data; 580df8bae1dSRodney W. Grimes for (i = 0; i < 6; i++) { 581df8bae1dSRodney W. Grimes eh2->ether_shost[i] = c = eh->ether_dhost[i]; 582df8bae1dSRodney W. Grimes eh2->ether_dhost[i] = 583df8bae1dSRodney W. Grimes eh->ether_dhost[i] = eh->ether_shost[i]; 584df8bae1dSRodney W. Grimes eh->ether_shost[i] = c; 585df8bae1dSRodney W. Grimes } 586df8bae1dSRodney W. Grimes ifp->if_output(ifp, m, &sa, NULL); 587df8bae1dSRodney W. Grimes return; 588df8bae1dSRodney W. Grimes } 589df8bae1dSRodney W. Grimes default: 590df8bae1dSRodney W. Grimes m_freem(m); 591df8bae1dSRodney W. Grimes return; 592df8bae1dSRodney W. Grimes } 593df8bae1dSRodney W. Grimes break; 594df8bae1dSRodney W. Grimes #endif /* ISO */ 595df8bae1dSRodney W. Grimes #ifdef LLC 596df8bae1dSRodney W. Grimes case LLC_X25_LSAP: 597df8bae1dSRodney W. Grimes { 598307d80beSDavid Greenman if (m->m_pkthdr.len > ether_type) 599307d80beSDavid Greenman m_adj(m, ether_type - m->m_pkthdr.len); 600df8bae1dSRodney W. Grimes M_PREPEND(m, sizeof(struct sdl_hdr) , M_DONTWAIT); 601df8bae1dSRodney W. Grimes if (m == 0) 602df8bae1dSRodney W. Grimes return; 603df8bae1dSRodney W. Grimes if ( !sdl_sethdrif(ifp, eh->ether_shost, LLC_X25_LSAP, 604df8bae1dSRodney W. Grimes eh->ether_dhost, LLC_X25_LSAP, 6, 605df8bae1dSRodney W. Grimes mtod(m, struct sdl_hdr *))) 606df8bae1dSRodney W. Grimes panic("ETHER cons addr failure"); 607307d80beSDavid Greenman mtod(m, struct sdl_hdr *)->sdlhdr_len = ether_type; 608df8bae1dSRodney W. Grimes #ifdef LLC_DEBUG 609df8bae1dSRodney W. Grimes printf("llc packet\n"); 610df8bae1dSRodney W. Grimes #endif /* LLC_DEBUG */ 611df8bae1dSRodney W. Grimes schednetisr(NETISR_CCITT); 612df8bae1dSRodney W. Grimes inq = &llcintrq; 613df8bae1dSRodney W. Grimes break; 614df8bae1dSRodney W. Grimes } 615df8bae1dSRodney W. Grimes #endif /* LLC */ 616df8bae1dSRodney W. Grimes dropanyway: 617df8bae1dSRodney W. Grimes default: 618df8bae1dSRodney W. Grimes m_freem(m); 619df8bae1dSRodney W. Grimes return; 620df8bae1dSRodney W. Grimes } 621655929bfSJulian Elischer #else /* ISO || LLC || NETATALK */ 622df8bae1dSRodney W. Grimes m_freem(m); 623df8bae1dSRodney W. Grimes return; 624655929bfSJulian Elischer #endif /* ISO || LLC || NETATALK */ 625df8bae1dSRodney W. Grimes } 626df8bae1dSRodney W. Grimes 627df8bae1dSRodney W. Grimes s = splimp(); 628df8bae1dSRodney W. Grimes if (IF_QFULL(inq)) { 629df8bae1dSRodney W. Grimes IF_DROP(inq); 630df8bae1dSRodney W. Grimes m_freem(m); 631df8bae1dSRodney W. Grimes } else 632df8bae1dSRodney W. Grimes IF_ENQUEUE(inq, m); 633df8bae1dSRodney W. Grimes splx(s); 634df8bae1dSRodney W. Grimes } 635df8bae1dSRodney W. Grimes 636df8bae1dSRodney W. Grimes /* 637df8bae1dSRodney W. Grimes * Perform common duties while attaching to interface list 638df8bae1dSRodney W. Grimes */ 639df8bae1dSRodney W. Grimes void 640df8bae1dSRodney W. Grimes ether_ifattach(ifp) 641df8bae1dSRodney W. Grimes register struct ifnet *ifp; 642df8bae1dSRodney W. Grimes { 643df8bae1dSRodney W. Grimes register struct ifaddr *ifa; 644df8bae1dSRodney W. Grimes register struct sockaddr_dl *sdl; 645df8bae1dSRodney W. Grimes 646df8bae1dSRodney W. Grimes ifp->if_type = IFT_ETHER; 647df8bae1dSRodney W. Grimes ifp->if_addrlen = 6; 648df8bae1dSRodney W. Grimes ifp->if_hdrlen = 14; 649df8bae1dSRodney W. Grimes ifp->if_mtu = ETHERMTU; 6501158dfb7SGarrett Wollman ifp->if_resolvemulti = ether_resolvemulti; 651a330e1f1SGary Palmer if (ifp->if_baudrate == 0) 652a330e1f1SGary Palmer ifp->if_baudrate = 10000000; 65359562606SGarrett Wollman ifa = ifnet_addrs[ifp->if_index - 1]; 65459562606SGarrett Wollman if (ifa == 0) { 65559562606SGarrett Wollman printf("ether_ifattach: no lladdr!\n"); 65659562606SGarrett Wollman return; 65759562606SGarrett Wollman } 65859562606SGarrett Wollman sdl = (struct sockaddr_dl *)ifa->ifa_addr; 659df8bae1dSRodney W. Grimes sdl->sdl_type = IFT_ETHER; 660df8bae1dSRodney W. Grimes sdl->sdl_alen = ifp->if_addrlen; 66159562606SGarrett Wollman bcopy(((struct arpcom *)ifp)->ac_enaddr, LLADDR(sdl), ifp->if_addrlen); 662df8bae1dSRodney W. Grimes } 663df8bae1dSRodney W. Grimes 664602d513cSGarrett Wollman SYSCTL_NODE(_net_link, IFT_ETHER, ether, CTLFLAG_RW, 0, "Ethernet"); 66530106f6aSPoul-Henning Kamp 666fb583156SDavid Greenman int 667c5a1016bSBruce Evans ether_ioctl(ifp, command, data) 668c5a1016bSBruce Evans struct ifnet *ifp; 669c5a1016bSBruce Evans int command; 670c5a1016bSBruce Evans caddr_t data; 67130106f6aSPoul-Henning Kamp { 67230106f6aSPoul-Henning Kamp struct ifaddr *ifa = (struct ifaddr *) data; 67330106f6aSPoul-Henning Kamp struct ifreq *ifr = (struct ifreq *) data; 674fb583156SDavid Greenman int error = 0; 67530106f6aSPoul-Henning Kamp 67630106f6aSPoul-Henning Kamp switch (command) { 67730106f6aSPoul-Henning Kamp case SIOCSIFADDR: 67830106f6aSPoul-Henning Kamp ifp->if_flags |= IFF_UP; 67930106f6aSPoul-Henning Kamp 68030106f6aSPoul-Henning Kamp switch (ifa->ifa_addr->sa_family) { 68130106f6aSPoul-Henning Kamp #ifdef INET 68230106f6aSPoul-Henning Kamp case AF_INET: 68330106f6aSPoul-Henning Kamp ifp->if_init(ifp->if_softc); /* before arpwhohas */ 68430106f6aSPoul-Henning Kamp arp_ifinit((struct arpcom *)ifp, ifa); 68530106f6aSPoul-Henning Kamp break; 68630106f6aSPoul-Henning Kamp #endif 68730106f6aSPoul-Henning Kamp #ifdef IPX 68830106f6aSPoul-Henning Kamp /* 68930106f6aSPoul-Henning Kamp * XXX - This code is probably wrong 69030106f6aSPoul-Henning Kamp */ 69130106f6aSPoul-Henning Kamp case AF_IPX: 69230106f6aSPoul-Henning Kamp { 69330106f6aSPoul-Henning Kamp register struct ipx_addr *ina = &(IA_SIPX(ifa)->sipx_addr); 69486101139SPoul-Henning Kamp struct arpcom *ac = (struct arpcom *) (ifp->if_softc); 69530106f6aSPoul-Henning Kamp 69630106f6aSPoul-Henning Kamp if (ipx_nullhost(*ina)) 69730106f6aSPoul-Henning Kamp ina->x_host = 69886101139SPoul-Henning Kamp *(union ipx_host *) 69986101139SPoul-Henning Kamp ac->ac_enaddr; 70030106f6aSPoul-Henning Kamp else { 70130106f6aSPoul-Henning Kamp bcopy((caddr_t) ina->x_host.c_host, 70286101139SPoul-Henning Kamp (caddr_t) ac->ac_enaddr, 70386101139SPoul-Henning Kamp sizeof(ac->ac_enaddr)); 70430106f6aSPoul-Henning Kamp } 70530106f6aSPoul-Henning Kamp 70630106f6aSPoul-Henning Kamp /* 70730106f6aSPoul-Henning Kamp * Set new address 70830106f6aSPoul-Henning Kamp */ 70930106f6aSPoul-Henning Kamp ifp->if_init(ifp->if_softc); 71030106f6aSPoul-Henning Kamp break; 71130106f6aSPoul-Henning Kamp } 71230106f6aSPoul-Henning Kamp #endif 71330106f6aSPoul-Henning Kamp #ifdef NS 71430106f6aSPoul-Henning Kamp /* 71530106f6aSPoul-Henning Kamp * XXX - This code is probably wrong 71630106f6aSPoul-Henning Kamp */ 71730106f6aSPoul-Henning Kamp case AF_NS: 71830106f6aSPoul-Henning Kamp { 71930106f6aSPoul-Henning Kamp register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr); 72086101139SPoul-Henning Kamp struct arpcom *ac = (struct arpcom *) (ifp->if_softc); 72130106f6aSPoul-Henning Kamp 72230106f6aSPoul-Henning Kamp if (ns_nullhost(*ina)) 72330106f6aSPoul-Henning Kamp ina->x_host = 72486101139SPoul-Henning Kamp *(union ns_host *) (ac->ac_enaddr); 72530106f6aSPoul-Henning Kamp else { 72630106f6aSPoul-Henning Kamp bcopy((caddr_t) ina->x_host.c_host, 72786101139SPoul-Henning Kamp (caddr_t) ac->ac_enaddr, 72886101139SPoul-Henning Kamp sizeof(ac->ac_enaddr)); 72930106f6aSPoul-Henning Kamp } 73030106f6aSPoul-Henning Kamp 73130106f6aSPoul-Henning Kamp /* 73230106f6aSPoul-Henning Kamp * Set new address 73330106f6aSPoul-Henning Kamp */ 73430106f6aSPoul-Henning Kamp ifp->if_init(ifp->if_softc); 73530106f6aSPoul-Henning Kamp break; 73630106f6aSPoul-Henning Kamp } 73730106f6aSPoul-Henning Kamp #endif 73830106f6aSPoul-Henning Kamp default: 73930106f6aSPoul-Henning Kamp ifp->if_init(ifp->if_softc); 74030106f6aSPoul-Henning Kamp break; 74130106f6aSPoul-Henning Kamp } 74230106f6aSPoul-Henning Kamp break; 74330106f6aSPoul-Henning Kamp 74430106f6aSPoul-Henning Kamp case SIOCGIFADDR: 74530106f6aSPoul-Henning Kamp { 74630106f6aSPoul-Henning Kamp struct sockaddr *sa; 74730106f6aSPoul-Henning Kamp 74830106f6aSPoul-Henning Kamp sa = (struct sockaddr *) & ifr->ifr_data; 7495b73c186SDavid Greenman bcopy(((struct arpcom *)ifp->if_softc)->ac_enaddr, 75030106f6aSPoul-Henning Kamp (caddr_t) sa->sa_data, ETHER_ADDR_LEN); 75130106f6aSPoul-Henning Kamp } 75230106f6aSPoul-Henning Kamp break; 753fb583156SDavid Greenman 754fb583156SDavid Greenman case SIOCSIFMTU: 755fb583156SDavid Greenman /* 756fb583156SDavid Greenman * Set the interface MTU. 757fb583156SDavid Greenman */ 758fb583156SDavid Greenman if (ifr->ifr_mtu > ETHERMTU) { 759fb583156SDavid Greenman error = EINVAL; 760fb583156SDavid Greenman } else { 761fb583156SDavid Greenman ifp->if_mtu = ifr->ifr_mtu; 76230106f6aSPoul-Henning Kamp } 763fb583156SDavid Greenman break; 764fb583156SDavid Greenman } 765fb583156SDavid Greenman return (error); 76630106f6aSPoul-Henning Kamp } 7671158dfb7SGarrett Wollman 7681158dfb7SGarrett Wollman int 7691158dfb7SGarrett Wollman ether_resolvemulti(ifp, llsa, sa) 7701158dfb7SGarrett Wollman struct ifnet *ifp; 7711158dfb7SGarrett Wollman struct sockaddr **llsa; 7721158dfb7SGarrett Wollman struct sockaddr *sa; 7731158dfb7SGarrett Wollman { 7741158dfb7SGarrett Wollman struct sockaddr_dl *sdl; 7751158dfb7SGarrett Wollman struct sockaddr_in *sin; 7761158dfb7SGarrett Wollman u_char *e_addr; 7771158dfb7SGarrett Wollman 7781158dfb7SGarrett Wollman switch(sa->sa_family) { 7791158dfb7SGarrett Wollman case AF_LINK: 7807f33a738SJulian Elischer /* 7817f33a738SJulian Elischer * No mapping needed. Just check that it's a valid MC address. 7827f33a738SJulian Elischer */ 7831158dfb7SGarrett Wollman sdl = (struct sockaddr_dl *)sa; 7841158dfb7SGarrett Wollman e_addr = LLADDR(sdl); 7851158dfb7SGarrett Wollman if ((e_addr[0] & 1) != 1) 7861158dfb7SGarrett Wollman return EADDRNOTAVAIL; 7871158dfb7SGarrett Wollman *llsa = 0; 7881158dfb7SGarrett Wollman return 0; 7891158dfb7SGarrett Wollman 7901158dfb7SGarrett Wollman #ifdef INET 7911158dfb7SGarrett Wollman case AF_INET: 7921158dfb7SGarrett Wollman sin = (struct sockaddr_in *)sa; 7931158dfb7SGarrett Wollman if (!IN_MULTICAST(ntohl(sin->sin_addr.s_addr))) 7941158dfb7SGarrett Wollman return EADDRNOTAVAIL; 7951158dfb7SGarrett Wollman MALLOC(sdl, struct sockaddr_dl *, sizeof *sdl, M_IFMADDR, 7961158dfb7SGarrett Wollman M_WAITOK); 7971158dfb7SGarrett Wollman sdl->sdl_len = sizeof *sdl; 7981158dfb7SGarrett Wollman sdl->sdl_family = AF_LINK; 7991158dfb7SGarrett Wollman sdl->sdl_index = ifp->if_index; 8001158dfb7SGarrett Wollman sdl->sdl_type = IFT_ETHER; 8011158dfb7SGarrett Wollman sdl->sdl_nlen = 0; 8021158dfb7SGarrett Wollman sdl->sdl_alen = ETHER_ADDR_LEN; 8031158dfb7SGarrett Wollman sdl->sdl_slen = 0; 8041158dfb7SGarrett Wollman e_addr = LLADDR(sdl); 8051158dfb7SGarrett Wollman ETHER_MAP_IP_MULTICAST(&sin->sin_addr, e_addr); 8061158dfb7SGarrett Wollman *llsa = (struct sockaddr *)sdl; 8071158dfb7SGarrett Wollman return 0; 8081158dfb7SGarrett Wollman #endif 8091158dfb7SGarrett Wollman 8101158dfb7SGarrett Wollman default: 8111158dfb7SGarrett Wollman /* 8121158dfb7SGarrett Wollman * Well, the text isn't quite right, but it's the name 8131158dfb7SGarrett Wollman * that counts... 8141158dfb7SGarrett Wollman */ 8151158dfb7SGarrett Wollman return EAFNOSUPPORT; 8161158dfb7SGarrett Wollman } 8171158dfb7SGarrett Wollman } 818