| 1 |
1254 |
phoenix |
//==========================================================================
|
| 2 |
|
|
//
|
| 3 |
|
|
// include/netinet/if_ether.h
|
| 4 |
|
|
//
|
| 5 |
|
|
//
|
| 6 |
|
|
//
|
| 7 |
|
|
//==========================================================================
|
| 8 |
|
|
//####BSDCOPYRIGHTBEGIN####
|
| 9 |
|
|
//
|
| 10 |
|
|
// -------------------------------------------
|
| 11 |
|
|
//
|
| 12 |
|
|
// Portions of this software may have been derived from OpenBSD or other sources,
|
| 13 |
|
|
// and are covered by the appropriate copyright disclaimers included herein.
|
| 14 |
|
|
//
|
| 15 |
|
|
// -------------------------------------------
|
| 16 |
|
|
//
|
| 17 |
|
|
//####BSDCOPYRIGHTEND####
|
| 18 |
|
|
//==========================================================================
|
| 19 |
|
|
//#####DESCRIPTIONBEGIN####
|
| 20 |
|
|
//
|
| 21 |
|
|
// Author(s): gthomas
|
| 22 |
|
|
// Contributors: gthomas
|
| 23 |
|
|
// Date: 2000-01-10
|
| 24 |
|
|
// Purpose:
|
| 25 |
|
|
// Description:
|
| 26 |
|
|
//
|
| 27 |
|
|
//
|
| 28 |
|
|
//####DESCRIPTIONEND####
|
| 29 |
|
|
//
|
| 30 |
|
|
//==========================================================================
|
| 31 |
|
|
|
| 32 |
|
|
|
| 33 |
|
|
/* $OpenBSD: if_ether.h,v 1.10 1999/12/08 06:50:19 itojun Exp $ */
|
| 34 |
|
|
/* $NetBSD: if_ether.h,v 1.22 1996/05/11 13:00:00 mycroft Exp $ */
|
| 35 |
|
|
|
| 36 |
|
|
/*
|
| 37 |
|
|
* Copyright (c) 1982, 1986, 1993
|
| 38 |
|
|
* The Regents of the University of California. All rights reserved.
|
| 39 |
|
|
*
|
| 40 |
|
|
* Redistribution and use in source and binary forms, with or without
|
| 41 |
|
|
* modification, are permitted provided that the following conditions
|
| 42 |
|
|
* are met:
|
| 43 |
|
|
* 1. Redistributions of source code must retain the above copyright
|
| 44 |
|
|
* notice, this list of conditions and the following disclaimer.
|
| 45 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
| 46 |
|
|
* notice, this list of conditions and the following disclaimer in the
|
| 47 |
|
|
* documentation and/or other materials provided with the distribution.
|
| 48 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
| 49 |
|
|
* must display the following acknowledgement:
|
| 50 |
|
|
* This product includes software developed by the University of
|
| 51 |
|
|
* California, Berkeley and its contributors.
|
| 52 |
|
|
* 4. Neither the name of the University nor the names of its contributors
|
| 53 |
|
|
* may be used to endorse or promote products derived from this software
|
| 54 |
|
|
* without specific prior written permission.
|
| 55 |
|
|
*
|
| 56 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
| 57 |
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 58 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
| 59 |
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
| 60 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 61 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
| 62 |
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
| 63 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
| 64 |
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
| 65 |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
| 66 |
|
|
* SUCH DAMAGE.
|
| 67 |
|
|
*
|
| 68 |
|
|
* @(#)if_ether.h 8.1 (Berkeley) 6/10/93
|
| 69 |
|
|
*/
|
| 70 |
|
|
|
| 71 |
|
|
#ifndef _NETINET_IF_ETHER_H_
|
| 72 |
|
|
#define _NETINET_IF_ETHER_H_
|
| 73 |
|
|
|
| 74 |
|
|
/*
|
| 75 |
|
|
* Ethernet address - 6 octets
|
| 76 |
|
|
* this is only used by the ethers(3) functions.
|
| 77 |
|
|
*/
|
| 78 |
|
|
struct ether_addr {
|
| 79 |
|
|
u_int8_t ether_addr_octet[6];
|
| 80 |
|
|
} __attribute__ ((aligned(1), packed));
|
| 81 |
|
|
|
| 82 |
|
|
/*
|
| 83 |
|
|
* Structure of a Ethernet header.
|
| 84 |
|
|
*/
|
| 85 |
|
|
#define ETHER_ADDR_LEN 6
|
| 86 |
|
|
|
| 87 |
|
|
struct ether_header {
|
| 88 |
|
|
u_int8_t ether_dhost[ETHER_ADDR_LEN];
|
| 89 |
|
|
u_int8_t ether_shost[ETHER_ADDR_LEN];
|
| 90 |
|
|
u_int16_t ether_type;
|
| 91 |
|
|
} __attribute__ ((aligned(1), packed));
|
| 92 |
|
|
|
| 93 |
|
|
#define ETHERTYPE_PUP 0x0200 /* PUP protocol */
|
| 94 |
|
|
#define ETHERTYPE_IP 0x0800 /* IP protocol */
|
| 95 |
|
|
#define ETHERTYPE_ARP 0x0806 /* address resolution protocol */
|
| 96 |
|
|
#define ETHERTYPE_REVARP 0x8035 /* reverse addr resolution protocol */
|
| 97 |
|
|
#define ETHERTYPE_IPV6 0x86DD /* IPv6 protocol */
|
| 98 |
|
|
|
| 99 |
|
|
/*
|
| 100 |
|
|
* The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
|
| 101 |
|
|
* (type-ETHERTYPE_TRAIL)*512 bytes of data followed
|
| 102 |
|
|
* by an ETHER type (as given above) and then the (variable-length) header.
|
| 103 |
|
|
*/
|
| 104 |
|
|
#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
|
| 105 |
|
|
#define ETHERTYPE_NTRAILER 16
|
| 106 |
|
|
|
| 107 |
|
|
#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */
|
| 108 |
|
|
|
| 109 |
|
|
#define ETHERMTU 1500
|
| 110 |
|
|
#define ETHERMIN (60-14)
|
| 111 |
|
|
|
| 112 |
|
|
#ifdef _KERNEL
|
| 113 |
|
|
/*
|
| 114 |
|
|
* Macro to map an IP multicast address to an Ethernet multicast address.
|
| 115 |
|
|
* The high-order 25 bits of the Ethernet address are statically assigned,
|
| 116 |
|
|
* and the low-order 23 bits are taken from the low end of the IP address.
|
| 117 |
|
|
*/
|
| 118 |
|
|
#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
|
| 119 |
|
|
/* struct in_addr *ipaddr; */ \
|
| 120 |
|
|
/* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \
|
| 121 |
|
|
{ \
|
| 122 |
|
|
(enaddr)[0] = 0x01; \
|
| 123 |
|
|
(enaddr)[1] = 0x00; \
|
| 124 |
|
|
(enaddr)[2] = 0x5e; \
|
| 125 |
|
|
(enaddr)[3] = ((u_int8_t *)ipaddr)[1] & 0x7f; \
|
| 126 |
|
|
(enaddr)[4] = ((u_int8_t *)ipaddr)[2]; \
|
| 127 |
|
|
(enaddr)[5] = ((u_int8_t *)ipaddr)[3]; \
|
| 128 |
|
|
}
|
| 129 |
|
|
|
| 130 |
|
|
/*
|
| 131 |
|
|
* Macro to map an IPv6 multicast address to an Ethernet multicast address.
|
| 132 |
|
|
* The high-order 16 bits of the Ethernet address are statically assigned,
|
| 133 |
|
|
* and the low-order 32 bits are taken from the low end of the IPv6 address.
|
| 134 |
|
|
*/
|
| 135 |
|
|
#define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr) \
|
| 136 |
|
|
/* struct in6_addr *ip6addr; */ \
|
| 137 |
|
|
/* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \
|
| 138 |
|
|
{ \
|
| 139 |
|
|
(enaddr)[0] = 0x33; \
|
| 140 |
|
|
(enaddr)[1] = 0x33; \
|
| 141 |
|
|
(enaddr)[2] = ((u_int8_t *)ip6addr)[12]; \
|
| 142 |
|
|
(enaddr)[3] = ((u_int8_t *)ip6addr)[13]; \
|
| 143 |
|
|
(enaddr)[4] = ((u_int8_t *)ip6addr)[14]; \
|
| 144 |
|
|
(enaddr)[5] = ((u_int8_t *)ip6addr)[15]; \
|
| 145 |
|
|
}
|
| 146 |
|
|
#endif
|
| 147 |
|
|
|
| 148 |
|
|
/*
|
| 149 |
|
|
* Ethernet Address Resolution Protocol.
|
| 150 |
|
|
*
|
| 151 |
|
|
* See RFC 826 for protocol description. Structure below is adapted
|
| 152 |
|
|
* to resolving internet addresses. Field names used correspond to
|
| 153 |
|
|
* RFC 826.
|
| 154 |
|
|
*/
|
| 155 |
|
|
struct ether_arp {
|
| 156 |
|
|
struct arphdr ea_hdr; /* fixed-size header */
|
| 157 |
|
|
u_int8_t arp_sha[ETHER_ADDR_LEN]; /* sender hardware address */
|
| 158 |
|
|
u_int8_t arp_spa[4]; /* sender protocol address */
|
| 159 |
|
|
u_int8_t arp_tha[ETHER_ADDR_LEN]; /* target hardware address */
|
| 160 |
|
|
u_int8_t arp_tpa[4]; /* target protocol address */
|
| 161 |
|
|
};
|
| 162 |
|
|
#define arp_hrd ea_hdr.ar_hrd
|
| 163 |
|
|
#define arp_pro ea_hdr.ar_pro
|
| 164 |
|
|
#define arp_hln ea_hdr.ar_hln
|
| 165 |
|
|
#define arp_pln ea_hdr.ar_pln
|
| 166 |
|
|
#define arp_op ea_hdr.ar_op
|
| 167 |
|
|
|
| 168 |
|
|
/*
|
| 169 |
|
|
* Structure shared between the ethernet driver modules and
|
| 170 |
|
|
* the address resolution code. For example, each ec_softc or il_softc
|
| 171 |
|
|
* begins with this structure.
|
| 172 |
|
|
*/
|
| 173 |
|
|
struct arpcom {
|
| 174 |
|
|
struct ifnet ac_if; /* network-visible interface */
|
| 175 |
|
|
u_int8_t ac_enaddr[ETHER_ADDR_LEN]; /* ethernet hardware address */
|
| 176 |
|
|
char ac__pad[2]; /* pad for some machines */
|
| 177 |
|
|
LIST_HEAD(, ether_multi) ac_multiaddrs; /* list of ether multicast addrs */
|
| 178 |
|
|
int ac_multicnt; /* length of ac_multiaddrs list */
|
| 179 |
|
|
};
|
| 180 |
|
|
|
| 181 |
|
|
struct llinfo_arp {
|
| 182 |
|
|
LIST_ENTRY(llinfo_arp) la_list;
|
| 183 |
|
|
struct rtentry *la_rt;
|
| 184 |
|
|
struct mbuf *la_hold; /* last packet until resolved/timeout */
|
| 185 |
|
|
long la_asked; /* last time we QUERIED for this addr */
|
| 186 |
|
|
#define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */
|
| 187 |
|
|
};
|
| 188 |
|
|
|
| 189 |
|
|
struct sockaddr_inarp {
|
| 190 |
|
|
u_int8_t sin_len;
|
| 191 |
|
|
u_int8_t sin_family;
|
| 192 |
|
|
u_int16_t sin_port;
|
| 193 |
|
|
struct in_addr sin_addr;
|
| 194 |
|
|
struct in_addr sin_srcaddr;
|
| 195 |
|
|
u_int16_t sin_tos;
|
| 196 |
|
|
u_int16_t sin_other;
|
| 197 |
|
|
#define SIN_PROXY 1
|
| 198 |
|
|
};
|
| 199 |
|
|
|
| 200 |
|
|
/*
|
| 201 |
|
|
* IP and ethernet specific routing flags
|
| 202 |
|
|
*/
|
| 203 |
|
|
#define RTF_USETRAILERS RTF_PROTO1 /* use trailers */
|
| 204 |
|
|
#define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */
|
| 205 |
|
|
#define RTF_PERMANENT_ARP RTF_PROTO3 /* only manual overwrite of entry */
|
| 206 |
|
|
|
| 207 |
|
|
#ifdef _KERNEL
|
| 208 |
|
|
extern u_int8_t etherbroadcastaddr[ETHER_ADDR_LEN];
|
| 209 |
|
|
extern u_int8_t ether_ipmulticast_min[ETHER_ADDR_LEN];
|
| 210 |
|
|
extern u_int8_t ether_ipmulticast_max[ETHER_ADDR_LEN];
|
| 211 |
|
|
extern struct ifqueue arpintrq;
|
| 212 |
|
|
|
| 213 |
|
|
void arpwhohas __P((struct arpcom *, struct in_addr *));
|
| 214 |
|
|
void arpintr __P((void));
|
| 215 |
|
|
int arpresolve __P((struct arpcom *,
|
| 216 |
|
|
struct rtentry *, struct mbuf *, struct sockaddr *, u_char *));
|
| 217 |
|
|
void arp_ifinit __P((struct arpcom *, struct ifaddr *));
|
| 218 |
|
|
void arp_rtrequest __P((int, struct rtentry *, struct sockaddr *));
|
| 219 |
|
|
|
| 220 |
|
|
int ether_addmulti __P((struct ifreq *, struct arpcom *));
|
| 221 |
|
|
int ether_delmulti __P((struct ifreq *, struct arpcom *));
|
| 222 |
|
|
#endif /* _KERNEL */
|
| 223 |
|
|
|
| 224 |
|
|
/*
|
| 225 |
|
|
* Ethernet multicast address structure. There is one of these for each
|
| 226 |
|
|
* multicast address or range of multicast addresses that we are supposed
|
| 227 |
|
|
* to listen to on a particular interface. They are kept in a linked list,
|
| 228 |
|
|
* rooted in the interface's arpcom structure. (This really has nothing to
|
| 229 |
|
|
* do with ARP, or with the Internet address family, but this appears to be
|
| 230 |
|
|
* the minimally-disrupting place to put it.)
|
| 231 |
|
|
*/
|
| 232 |
|
|
struct ether_multi {
|
| 233 |
|
|
u_int8_t enm_addrlo[ETHER_ADDR_LEN]; /* low or only address of range */
|
| 234 |
|
|
u_int8_t enm_addrhi[ETHER_ADDR_LEN]; /* high or only address of range */
|
| 235 |
|
|
struct arpcom *enm_ac; /* back pointer to arpcom */
|
| 236 |
|
|
u_int enm_refcount; /* no. claims to this addr/range */
|
| 237 |
|
|
LIST_ENTRY(ether_multi) enm_list;
|
| 238 |
|
|
};
|
| 239 |
|
|
|
| 240 |
|
|
/*
|
| 241 |
|
|
* Structure used by macros below to remember position when stepping through
|
| 242 |
|
|
* all of the ether_multi records.
|
| 243 |
|
|
*/
|
| 244 |
|
|
struct ether_multistep {
|
| 245 |
|
|
struct ether_multi *e_enm;
|
| 246 |
|
|
};
|
| 247 |
|
|
|
| 248 |
|
|
/*
|
| 249 |
|
|
* Macro for looking up the ether_multi record for a given range of Ethernet
|
| 250 |
|
|
* multicast addresses connected to a given arpcom structure. If no matching
|
| 251 |
|
|
* record is found, "enm" returns NULL.
|
| 252 |
|
|
*/
|
| 253 |
|
|
#define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
|
| 254 |
|
|
/* u_int8_t addrlo[ETHER_ADDR_LEN]; */ \
|
| 255 |
|
|
/* u_int8_t addrhi[ETHER_ADDR_LEN]; */ \
|
| 256 |
|
|
/* struct arpcom *ac; */ \
|
| 257 |
|
|
/* struct ether_multi *enm; */ \
|
| 258 |
|
|
{ \
|
| 259 |
|
|
for ((enm) = (ac)->ac_multiaddrs.lh_first; \
|
| 260 |
|
|
(enm) != NULL && \
|
| 261 |
|
|
(bcmp((enm)->enm_addrlo, (addrlo), ETHER_ADDR_LEN) != 0 || \
|
| 262 |
|
|
bcmp((enm)->enm_addrhi, (addrhi), ETHER_ADDR_LEN) != 0); \
|
| 263 |
|
|
(enm) = (enm)->enm_list.le_next); \
|
| 264 |
|
|
}
|
| 265 |
|
|
|
| 266 |
|
|
/*
|
| 267 |
|
|
* Macro to step through all of the ether_multi records, one at a time.
|
| 268 |
|
|
* The current position is remembered in "step", which the caller must
|
| 269 |
|
|
* provide. ETHER_FIRST_MULTI(), below, must be called to initialize "step"
|
| 270 |
|
|
* and get the first record. Both macros return a NULL "enm" when there
|
| 271 |
|
|
* are no remaining records.
|
| 272 |
|
|
*/
|
| 273 |
|
|
#define ETHER_NEXT_MULTI(step, enm) \
|
| 274 |
|
|
/* struct ether_multistep step; */ \
|
| 275 |
|
|
/* struct ether_multi *enm; */ \
|
| 276 |
|
|
{ \
|
| 277 |
|
|
if (((enm) = (step).e_enm) != NULL) \
|
| 278 |
|
|
(step).e_enm = (enm)->enm_list.le_next; \
|
| 279 |
|
|
}
|
| 280 |
|
|
|
| 281 |
|
|
#define ETHER_FIRST_MULTI(step, ac, enm) \
|
| 282 |
|
|
/* struct ether_multistep step; */ \
|
| 283 |
|
|
/* struct arpcom *ac; */ \
|
| 284 |
|
|
/* struct ether_multi *enm; */ \
|
| 285 |
|
|
{ \
|
| 286 |
|
|
(step).e_enm = (ac)->ac_multiaddrs.lh_first; \
|
| 287 |
|
|
ETHER_NEXT_MULTI((step), (enm)); \
|
| 288 |
|
|
}
|
| 289 |
|
|
|
| 290 |
|
|
#ifdef _KERNEL
|
| 291 |
|
|
|
| 292 |
|
|
extern struct ifnet *myip_ifp;
|
| 293 |
|
|
|
| 294 |
|
|
void arp_rtrequest __P((int, struct rtentry *, struct sockaddr *));
|
| 295 |
|
|
int arpresolve __P((struct arpcom *, struct rtentry *, struct mbuf *,
|
| 296 |
|
|
struct sockaddr *, u_char *));
|
| 297 |
|
|
void arpintr __P((void));
|
| 298 |
|
|
int arpioctl __P((u_long, caddr_t));
|
| 299 |
|
|
void arp_ifinit __P((struct arpcom *, struct ifaddr *));
|
| 300 |
|
|
void revarpinput __P((struct mbuf *));
|
| 301 |
|
|
void in_revarpinput __P((struct mbuf *));
|
| 302 |
|
|
void revarprequest __P((struct ifnet *));
|
| 303 |
|
|
int revarpwhoarewe __P((struct ifnet *, struct in_addr *, struct in_addr *));
|
| 304 |
|
|
int revarpwhoami __P((struct in_addr *, struct ifnet *));
|
| 305 |
|
|
int db_show_arptab __P((void));
|
| 306 |
|
|
|
| 307 |
|
|
#else
|
| 308 |
|
|
|
| 309 |
|
|
char *ether_ntoa __P((struct ether_addr *));
|
| 310 |
|
|
struct ether_addr *ether_aton __P((char *));
|
| 311 |
|
|
int ether_ntohost __P((char *, struct ether_addr *));
|
| 312 |
|
|
int ether_hostton __P((char *, struct ether_addr *));
|
| 313 |
|
|
int ether_line __P((char *, struct ether_addr *, char *));
|
| 314 |
|
|
|
| 315 |
|
|
#endif // _KERNEL
|
| 316 |
|
|
|
| 317 |
|
|
#endif // _NETINET_IF_ETHER_H_
|