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