1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 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_ether.h 8.1 (Berkeley) 6/10/93 345f6d32c7SBill Paul * $Id: if_ether.h,v 1.7 1994/12/22 22:00:30 wollman Exp $ 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 37707f139eSPaul Richards #ifndef _NETINET_IF_ETHER_H_ 38707f139eSPaul Richards #define _NETINET_IF_ETHER_H_ 39707f139eSPaul Richards 40df8bae1dSRodney W. Grimes /* 41df8bae1dSRodney W. Grimes * Structure of a 10Mb/s Ethernet header. 42df8bae1dSRodney W. Grimes */ 43df8bae1dSRodney W. Grimes struct ether_header { 44df8bae1dSRodney W. Grimes u_char ether_dhost[6]; 45df8bae1dSRodney W. Grimes u_char ether_shost[6]; 46df8bae1dSRodney W. Grimes u_short ether_type; 47df8bae1dSRodney W. Grimes }; 48df8bae1dSRodney W. Grimes 495f6d32c7SBill Paul /* 505f6d32c7SBill Paul * Structure of a 48-bit Ethernet address. 515f6d32c7SBill Paul */ 525f6d32c7SBill Paul struct ether_addr { 535f6d32c7SBill Paul u_char octet[6]; 545f6d32c7SBill Paul }; 555f6d32c7SBill Paul 56df8bae1dSRodney W. Grimes #define ETHERTYPE_PUP 0x0200 /* PUP protocol */ 57df8bae1dSRodney W. Grimes #define ETHERTYPE_IP 0x0800 /* IP protocol */ 58df8bae1dSRodney W. Grimes #define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */ 59df8bae1dSRodney W. Grimes #define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */ 60df8bae1dSRodney W. Grimes 61df8bae1dSRodney W. Grimes /* 62df8bae1dSRodney W. Grimes * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have 63df8bae1dSRodney W. Grimes * (type-ETHERTYPE_TRAIL)*512 bytes of data followed 64df8bae1dSRodney W. Grimes * by an ETHER type (as given above) and then the (variable-length) header. 65df8bae1dSRodney W. Grimes */ 66df8bae1dSRodney W. Grimes #define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */ 67df8bae1dSRodney W. Grimes #define ETHERTYPE_NTRAILER 16 68df8bae1dSRodney W. Grimes 69df8bae1dSRodney W. Grimes #define ETHERMTU 1500 70df8bae1dSRodney W. Grimes #define ETHERMIN (60-14) 71df8bae1dSRodney W. Grimes 72df8bae1dSRodney W. Grimes #ifdef KERNEL 73df8bae1dSRodney W. Grimes /* 74df8bae1dSRodney W. Grimes * Macro to map an IP multicast address to an Ethernet multicast address. 75df8bae1dSRodney W. Grimes * The high-order 25 bits of the Ethernet address are statically assigned, 76df8bae1dSRodney W. Grimes * and the low-order 23 bits are taken from the low end of the IP address. 77df8bae1dSRodney W. Grimes */ 78df8bae1dSRodney W. Grimes #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \ 79df8bae1dSRodney W. Grimes /* struct in_addr *ipaddr; */ \ 80df8bae1dSRodney W. Grimes /* u_char enaddr[6]; */ \ 81df8bae1dSRodney W. Grimes { \ 82df8bae1dSRodney W. Grimes (enaddr)[0] = 0x01; \ 83df8bae1dSRodney W. Grimes (enaddr)[1] = 0x00; \ 84df8bae1dSRodney W. Grimes (enaddr)[2] = 0x5e; \ 85df8bae1dSRodney W. Grimes (enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; \ 86df8bae1dSRodney W. Grimes (enaddr)[4] = ((u_char *)ipaddr)[2]; \ 87df8bae1dSRodney W. Grimes (enaddr)[5] = ((u_char *)ipaddr)[3]; \ 88df8bae1dSRodney W. Grimes } 89df8bae1dSRodney W. Grimes #endif 90df8bae1dSRodney W. Grimes 91df8bae1dSRodney W. Grimes /* 92df8bae1dSRodney W. Grimes * Ethernet Address Resolution Protocol. 93df8bae1dSRodney W. Grimes * 94df8bae1dSRodney W. Grimes * See RFC 826 for protocol description. Structure below is adapted 95df8bae1dSRodney W. Grimes * to resolving internet addresses. Field names used correspond to 96df8bae1dSRodney W. Grimes * RFC 826. 97df8bae1dSRodney W. Grimes */ 98df8bae1dSRodney W. Grimes struct ether_arp { 99df8bae1dSRodney W. Grimes struct arphdr ea_hdr; /* fixed-size header */ 100df8bae1dSRodney W. Grimes u_char arp_sha[6]; /* sender hardware address */ 101df8bae1dSRodney W. Grimes u_char arp_spa[4]; /* sender protocol address */ 102df8bae1dSRodney W. Grimes u_char arp_tha[6]; /* target hardware address */ 103df8bae1dSRodney W. Grimes u_char arp_tpa[4]; /* target protocol address */ 104df8bae1dSRodney W. Grimes }; 105df8bae1dSRodney W. Grimes #define arp_hrd ea_hdr.ar_hrd 106df8bae1dSRodney W. Grimes #define arp_pro ea_hdr.ar_pro 107df8bae1dSRodney W. Grimes #define arp_hln ea_hdr.ar_hln 108df8bae1dSRodney W. Grimes #define arp_pln ea_hdr.ar_pln 109df8bae1dSRodney W. Grimes #define arp_op ea_hdr.ar_op 110df8bae1dSRodney W. Grimes 111df8bae1dSRodney W. Grimes 112df8bae1dSRodney W. Grimes /* 113df8bae1dSRodney W. Grimes * Structure shared between the ethernet driver modules and 114df8bae1dSRodney W. Grimes * the address resolution code. For example, each ec_softc or il_softc 115df8bae1dSRodney W. Grimes * begins with this structure. 116df8bae1dSRodney W. Grimes */ 117df8bae1dSRodney W. Grimes struct arpcom { 118df8bae1dSRodney W. Grimes struct ifnet ac_if; /* network-visible interface */ 119df8bae1dSRodney W. Grimes u_char ac_enaddr[6]; /* ethernet hardware address */ 120df8bae1dSRodney W. Grimes struct in_addr ac_ipaddr; /* copy of ip address- XXX */ 121df8bae1dSRodney W. Grimes struct ether_multi *ac_multiaddrs; /* list of ether multicast addrs */ 122df8bae1dSRodney W. Grimes int ac_multicnt; /* length of ac_multiaddrs list */ 123df8bae1dSRodney W. Grimes }; 124df8bae1dSRodney W. Grimes 125df8bae1dSRodney W. Grimes struct llinfo_arp { 126df8bae1dSRodney W. Grimes struct llinfo_arp *la_next; 127df8bae1dSRodney W. Grimes struct llinfo_arp *la_prev; 128df8bae1dSRodney W. Grimes struct rtentry *la_rt; 129df8bae1dSRodney W. Grimes struct mbuf *la_hold; /* last packet until resolved/timeout */ 130df8bae1dSRodney W. Grimes long la_asked; /* last time we QUERIED for this addr */ 131df8bae1dSRodney W. Grimes #define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */ 132df8bae1dSRodney W. Grimes }; 133df8bae1dSRodney W. Grimes 134df8bae1dSRodney W. Grimes struct sockaddr_inarp { 135df8bae1dSRodney W. Grimes u_char sin_len; 136df8bae1dSRodney W. Grimes u_char sin_family; 137df8bae1dSRodney W. Grimes u_short sin_port; 138df8bae1dSRodney W. Grimes struct in_addr sin_addr; 139df8bae1dSRodney W. Grimes struct in_addr sin_srcaddr; 140df8bae1dSRodney W. Grimes u_short sin_tos; 141df8bae1dSRodney W. Grimes u_short sin_other; 142df8bae1dSRodney W. Grimes #define SIN_PROXY 1 143df8bae1dSRodney W. Grimes }; 144df8bae1dSRodney W. Grimes /* 145df8bae1dSRodney W. Grimes * IP and ethernet specific routing flags 146df8bae1dSRodney W. Grimes */ 147df8bae1dSRodney W. Grimes #define RTF_USETRAILERS RTF_PROTO1 /* use trailers */ 148df8bae1dSRodney W. Grimes #define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */ 149df8bae1dSRodney W. Grimes 150df8bae1dSRodney W. Grimes #ifdef KERNEL 151f23b4c91SGarrett Wollman extern u_char etherbroadcastaddr[6]; 152f23b4c91SGarrett Wollman extern u_char ether_ipmulticast_min[6]; 153f23b4c91SGarrett Wollman extern u_char ether_ipmulticast_max[6]; 154f23b4c91SGarrett Wollman extern struct ifqueue arpintrq; 155df8bae1dSRodney W. Grimes 156df8bae1dSRodney W. Grimes struct llinfo_arp *arptnew __P((struct in_addr *)); 157f23b4c91SGarrett Wollman extern struct llinfo_arp llinfo_arp; /* head of the llinfo queue */ 158df8bae1dSRodney W. Grimes 159df8bae1dSRodney W. Grimes void arpwhohas __P((struct arpcom *, struct in_addr *)); 160df8bae1dSRodney W. Grimes void arpintr __P((void)); 1615df72964SGarrett Wollman int arpresolve __P((struct arpcom *, struct rtentry *, struct mbuf *, 1625df72964SGarrett Wollman struct sockaddr *, u_char *, struct rtentry *)); 163dd2e4102SGarrett Wollman void arp_ifinit __P((struct arpcom *, struct ifaddr *)); 164df8bae1dSRodney W. Grimes 165df8bae1dSRodney W. Grimes int ether_addmulti __P((struct ifreq *, struct arpcom *)); 166df8bae1dSRodney W. Grimes int ether_delmulti __P((struct ifreq *, struct arpcom *)); 167df8bae1dSRodney W. Grimes 168df8bae1dSRodney W. Grimes /* 169df8bae1dSRodney W. Grimes * Ethernet multicast address structure. There is one of these for each 170df8bae1dSRodney W. Grimes * multicast address or range of multicast addresses that we are supposed 171df8bae1dSRodney W. Grimes * to listen to on a particular interface. They are kept in a linked list, 172df8bae1dSRodney W. Grimes * rooted in the interface's arpcom structure. (This really has nothing to 173df8bae1dSRodney W. Grimes * do with ARP, or with the Internet address family, but this appears to be 174df8bae1dSRodney W. Grimes * the minimally-disrupting place to put it.) 175df8bae1dSRodney W. Grimes */ 176df8bae1dSRodney W. Grimes struct ether_multi { 177df8bae1dSRodney W. Grimes u_char enm_addrlo[6]; /* low or only address of range */ 178df8bae1dSRodney W. Grimes u_char enm_addrhi[6]; /* high or only address of range */ 179df8bae1dSRodney W. Grimes struct arpcom *enm_ac; /* back pointer to arpcom */ 180df8bae1dSRodney W. Grimes u_int enm_refcount; /* no. claims to this addr/range */ 181df8bae1dSRodney W. Grimes struct ether_multi *enm_next; /* ptr to next ether_multi */ 182df8bae1dSRodney W. Grimes }; 183df8bae1dSRodney W. Grimes 184df8bae1dSRodney W. Grimes /* 185df8bae1dSRodney W. Grimes * Structure used by macros below to remember position when stepping through 186df8bae1dSRodney W. Grimes * all of the ether_multi records. 187df8bae1dSRodney W. Grimes */ 188df8bae1dSRodney W. Grimes struct ether_multistep { 189df8bae1dSRodney W. Grimes struct ether_multi *e_enm; 190df8bae1dSRodney W. Grimes }; 191df8bae1dSRodney W. Grimes 192df8bae1dSRodney W. Grimes /* 193df8bae1dSRodney W. Grimes * Macro for looking up the ether_multi record for a given range of Ethernet 194df8bae1dSRodney W. Grimes * multicast addresses connected to a given arpcom structure. If no matching 195df8bae1dSRodney W. Grimes * record is found, "enm" returns NULL. 196df8bae1dSRodney W. Grimes */ 197df8bae1dSRodney W. Grimes #define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \ 198df8bae1dSRodney W. Grimes /* u_char addrlo[6]; */ \ 199df8bae1dSRodney W. Grimes /* u_char addrhi[6]; */ \ 200df8bae1dSRodney W. Grimes /* struct arpcom *ac; */ \ 201df8bae1dSRodney W. Grimes /* struct ether_multi *enm; */ \ 202df8bae1dSRodney W. Grimes { \ 203df8bae1dSRodney W. Grimes for ((enm) = (ac)->ac_multiaddrs; \ 204df8bae1dSRodney W. Grimes (enm) != NULL && \ 205df8bae1dSRodney W. Grimes (bcmp((enm)->enm_addrlo, (addrlo), 6) != 0 || \ 206df8bae1dSRodney W. Grimes bcmp((enm)->enm_addrhi, (addrhi), 6) != 0); \ 207df8bae1dSRodney W. Grimes (enm) = (enm)->enm_next); \ 208df8bae1dSRodney W. Grimes } 209df8bae1dSRodney W. Grimes 210df8bae1dSRodney W. Grimes /* 211df8bae1dSRodney W. Grimes * Macro to step through all of the ether_multi records, one at a time. 212df8bae1dSRodney W. Grimes * The current position is remembered in "step", which the caller must 213df8bae1dSRodney W. Grimes * provide. ETHER_FIRST_MULTI(), below, must be called to initialize "step" 214df8bae1dSRodney W. Grimes * and get the first record. Both macros return a NULL "enm" when there 215df8bae1dSRodney W. Grimes * are no remaining records. 216df8bae1dSRodney W. Grimes */ 217df8bae1dSRodney W. Grimes #define ETHER_NEXT_MULTI(step, enm) \ 218df8bae1dSRodney W. Grimes /* struct ether_multistep step; */ \ 219df8bae1dSRodney W. Grimes /* struct ether_multi *enm; */ \ 220df8bae1dSRodney W. Grimes { \ 221df8bae1dSRodney W. Grimes if (((enm) = (step).e_enm) != NULL) \ 222df8bae1dSRodney W. Grimes (step).e_enm = (enm)->enm_next; \ 223df8bae1dSRodney W. Grimes } 224df8bae1dSRodney W. Grimes 225df8bae1dSRodney W. Grimes #define ETHER_FIRST_MULTI(step, ac, enm) \ 226df8bae1dSRodney W. Grimes /* struct ether_multistep step; */ \ 227df8bae1dSRodney W. Grimes /* struct arpcom *ac; */ \ 228df8bae1dSRodney W. Grimes /* struct ether_multi *enm; */ \ 229df8bae1dSRodney W. Grimes { \ 230df8bae1dSRodney W. Grimes (step).e_enm = (ac)->ac_multiaddrs; \ 231df8bae1dSRodney W. Grimes ETHER_NEXT_MULTI((step), (enm)); \ 232df8bae1dSRodney W. Grimes } 233df8bae1dSRodney W. Grimes 234df8bae1dSRodney W. Grimes #endif 235707f139eSPaul Richards 236707f139eSPaul Richards #endif 237