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