1/* 2 * Copyright (c) 1982, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. All advertising materials mentioning features or use of this software 14 * must display the following acknowledgement: 15 * This product includes software developed by the University of 16 * California, Berkeley and its contributors. 17 * 4. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)if_ether.h 8.1 (Berkeley) 6/10/93 34 */ 35 36#ifndef NETINET_IF_ETHER_H 37#define NETINET_IF_ETHER_H 38 39#include "net/if_arp.h" 40 41/* 42 * Ethernet address - 6 octets 43 * this is only used by the ethers(3) functions. 44 */ 45struct ether_addr { 46 uint8 ether_addr_octet[6]; 47}; 48 49/* 50 * Some Ethernet constants. 51 */ 52#define ETHER_ADDR_LEN 6 /* Ethernet address length */ 53#define ETHER_TYPE_LEN 2 /* Ethernet type field length */ 54#define ETHER_CRC_LEN 4 /* Ethernet CRC lenght */ 55#define ETHER_HDR_LEN ((ETHER_ADDR_LEN * 2) + ETHER_TYPE_LEN) 56#define ETHER_MIN_LEN 64 /* Minimum frame length, CRC included */ 57#define ETHER_MAX_LEN 1518 /* Maximum frame length, CRC included */ 58 59struct ether_header { 60 uint8 ether_dhost[ETHER_ADDR_LEN]; 61 uint8 ether_shost[ETHER_ADDR_LEN]; 62 uint16 ether_type; 63}; 64 65#define ETHERTYPE_PUP 0x0200 /* PUP protocol */ 66#define ETHERTYPE_IP 0x0800 /* IP protocol */ 67#define ETHERTYPE_ARP 0x0806 /* address resolution protocol */ 68#define ETHERTYPE_REVARP 0x8035 /* reverse addr resolution protocol */ 69#define ETHERTYPE_8021Q 0x8100 /* IEEE 802.1Q VLAN tagging */ 70#define ETHERTYPE_IPV6 0x86DD /* IPv6 protocol */ 71#define ETHERTYPE_PPPOEDISC 0x8863 /* PPP Over Ethernet Discovery Stage */ 72#define ETHERTYPE_PPPOE 0x8864 /* PPP Over Ethernet Session Stage */ 73#define ETHERTYPE_LOOPBACK 0x9000 /* used to test interfaces */ 74 75#define ETHER_IS_MULTICAST(addr) (*(addr) & 0x01) /* is address mcast/bcast? */ 76 77#define ETHERMTU (ETHER_MAX_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) 78#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) 79 80 81//#ifdef _NETWORK_STACK 82 83/* 84 * Macro to map an IP multicast address to an Ethernet multicast address. 85 * The high-order 25 bits of the Ethernet address are statically assigned, 86 * and the low-order 23 bits are taken from the low end of the IP address. 87 */ 88#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \ 89 /* struct in_addr *ipaddr; */ \ 90 /* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \ 91{ \ 92 (enaddr)[0] = 0x01; \ 93 (enaddr)[1] = 0x00; \ 94 (enaddr)[2] = 0x5e; \ 95 (enaddr)[3] = ((uint8 *)ipaddr)[1] & 0x7f; \ 96 (enaddr)[4] = ((uint8 *)ipaddr)[2]; \ 97 (enaddr)[5] = ((uint8 *)ipaddr)[3]; \ 98} 99 100/* 101 * Macro to map an IPv6 multicast address to an Ethernet multicast address. 102 * The high-order 16 bits of the Ethernet address are statically assigned, 103 * and the low-order 32 bits are taken from the low end of the IPv6 address. 104 */ 105#define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr) \ 106 /* struct in6_addr *ip6addr; */ \ 107 /* u_int8_t enaddr[ETHER_ADDR_LEN]; */ \ 108{ \ 109 (enaddr)[0] = 0x33; \ 110 (enaddr)[1] = 0x33; \ 111 (enaddr)[2] = ((u_int8_t *)ip6addr)[12]; \ 112 (enaddr)[3] = ((u_int8_t *)ip6addr)[13]; \ 113 (enaddr)[4] = ((u_int8_t *)ip6addr)[14]; \ 114 (enaddr)[5] = ((u_int8_t *)ip6addr)[15]; \ 115} 116//#endif 117 118/* 119 * Structure shared between the ethernet driver modules and 120 * the address resolution code. For example, each ec_softc or il_softc 121 * begins with this structure. 122 */ 123struct arpcom { 124 struct ifnet ac_if; /* network-visible interface */ 125 uint8 ac_enaddr[ETHER_ADDR_LEN]; /* ethernet hardware address */ 126 struct in_addr ac_ipaddr; 127 char ac__pad[2]; /* pad for some machines */ 128// struct ether_multi *ac_multiaddrs; /* list of ether multicast addrs */ 129 int ac_multicnt; /* length of ac_multiaddrs list */ 130}; 131 132struct ether_device { 133 struct arpcom sc_ac; 134 struct ether_device *next; /* next ether_device */ 135}; 136#define sc_if sc_ac.ac_if 137#define sc_addr sc_ac.ac_enaddr 138 139struct ether_arp { 140 struct arphdr ea_hdr; 141 u_char arp_sha[6]; 142 u_char arp_spa[4]; 143 u_char arp_tha[6]; 144 u_char arp_tpa[4]; 145}; 146#define arp_hrd ea_hdr.ar_hrd 147#define arp_pro ea_hdr.ar_pro 148#define arp_hln ea_hdr.ar_hln 149#define arp_pln ea_hdr.ar_pln 150#define arp_op ea_hdr.ar_op 151 152struct llinfo_arp { 153 struct llinfo_arp *la_next; 154 struct llinfo_arp *la_prev; 155 struct rtentry *la_rt; 156 struct mbuf *la_hold; 157 int32 la_asked; 158}; 159 160#define la_timer la_rt->rt_rmx.rmx_expire 161 162struct sockaddr_inarp { 163 uint8 sin_len; 164 uint8 sin_family; 165 uint16 sin_port; 166 struct in_addr sin_addr; 167 struct in_addr sin_srcaddr; 168 uint16 sin_tos; 169 uint16 sin_other; 170}; 171#define SIN_PROXY 1 172 173/* 174 * IP and ethernet specific routing flags 175 */ 176#define RTF_USETRAILERS RTF_PROTO1 /* use trailers */ 177#define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */ 178#define RTF_PERMANENT_ARP RTF_PROTO3 /* only manual overwrite of entry */ 179 180//#ifdef _NETWORK_STACK 181 182int arpresolve(struct arpcom *ac, struct rtentry *rt, struct mbuf *m, 183 struct sockaddr *dst, uint8 *desten); 184//void arpwhohas(struct arpcom *ac, struct in_addr *ia); 185 186 187//#else 188 189char *ether_ntoa (struct ether_addr *); 190struct ether_addr *ether_aton (char *); 191int ether_ntohost (char *, struct ether_addr *); 192int ether_hostton (char *, struct ether_addr *); 193int ether_line(char *line, struct ether_addr *e, char *hostname); 194 195//#endif 196 197#endif /* NETINET_IF_ETHER_H */ 198 199