1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2014 Garrett D'Amore <garrett@damore.org> 23 * Copyright 2021 Oxide Computer Company 24 * 25 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29 /* 30 * ethernet.h header for common Ethernet declarations. 31 */ 32 33 #ifndef _SYS_ETHERNET_H 34 #define _SYS_ETHERNET_H 35 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 #define ETHERADDRL (6) /* ethernet address length in octets */ 41 #define ETHERFCSL (4) /* ethernet FCS length in octets */ 42 #define ETHERADDRSTRL (18) /* char size of ETHERADDRL with null */ 43 44 /* 45 * Ethernet address - 6 octets 46 */ 47 typedef uchar_t ether_addr_t[ETHERADDRL]; 48 49 /* 50 * Ethernet address - 6 octets 51 */ 52 struct ether_addr { 53 ether_addr_t ether_addr_octet; 54 }; 55 56 /* 57 * Structure of a 10Mb/s Ethernet header. 58 */ 59 struct ether_header { 60 struct ether_addr ether_dhost; 61 struct ether_addr ether_shost; 62 ushort_t ether_type; 63 }; 64 65 #define ETHER_CFI 0 66 67 struct ether_vlan_header { 68 struct ether_addr ether_dhost; 69 struct ether_addr ether_shost; 70 ushort_t ether_tpid; 71 ushort_t ether_tci; 72 ushort_t ether_type; 73 }; 74 75 /* 76 * The VLAN tag. Available for applications that cannot make use of struct 77 * ether_vlan_header because they assume Ethernet encapsulation. 78 */ 79 struct ether_vlan_extinfo { 80 ushort_t ether_tci; 81 ushort_t ether_type; 82 }; 83 84 #define ETHERTYPE_PUP (0x0200) /* PUP protocol */ 85 #define ETHERTYPE_802_MIN (0x0600) /* Min valid ethernet type */ 86 /* under IEEE 802.3 rules */ 87 #define ETHERTYPE_IP (0x0800) /* IP protocol */ 88 #define ETHERTYPE_ARP (0x0806) /* Addr. resolution protocol */ 89 #define ETHERTYPE_REVARP (0x8035) /* Reverse ARP */ 90 #define ETHERTYPE_AT (0x809b) /* AppleTalk protocol */ 91 #define ETHERTYPE_AARP (0x80f3) /* AppleTalk ARP */ 92 #define ETHERTYPE_VLAN (0x8100) /* 802.1Q VLAN */ 93 #define ETHERTYPE_IPV6 (0x86dd) /* IPv6 */ 94 #define ETHERTYPE_SLOW (0x8809) /* Slow Protocol */ 95 #define ETHERTYPE_PPPOED (0x8863) /* PPPoE Discovery Stage */ 96 #define ETHERTYPE_PPPOES (0x8864) /* PPPoE Session Stage */ 97 #define ETHERTYPE_EAPOL (0x888e) /* EAPOL protocol */ 98 #define ETHERTYPE_RSN_PREAUTH (0x88c7) /* RSN PRE-Authentication */ 99 #define ETHERTYPE_TRILL (0x88c8) /* TBD. TRILL frame */ 100 #define ETHERTYPE_FCOE (0x8906) /* FCoE */ 101 #define ETHERTYPE_MAX (0xffff) /* Max valid ethernet type */ 102 103 /* 104 * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have 105 * (type-ETHERTYPE_TRAIL)*512 bytes of data followed 106 * by an ETHER type (as given above) and then the (variable-length) header. 107 */ 108 #define ETHERTYPE_TRAIL (0x1000) /* Trailer packet */ 109 #define ETHERTYPE_NTRAILER (16) 110 111 #define ETHERMTU (1500) /* max frame w/o header or fcs */ 112 #define ETHERMIN (60) /* min frame w/header w/o fcs */ 113 #define ETHERMAX (1514) /* max frame w/header w/o fcs */ 114 115 /* 116 * Compare two Ethernet addresses - assumes that the two given 117 * pointers can be referenced as shorts. On architectures 118 * where this is not the case, use bcmp instead. Note that like 119 * bcmp, we return zero if they are the SAME. 120 */ 121 122 #if defined(__sparc) || defined(__i386) || defined(__amd64) 123 #define ether_cmp(a, b) (((short *)b)[2] != ((short *)a)[2] || \ 124 ((short *)b)[1] != ((short *)a)[1] || \ 125 ((short *)b)[0] != ((short *)a)[0]) 126 #else 127 #define ether_cmp(a, b) (bcmp((caddr_t)a, (caddr_t)b, 6)) 128 #endif 129 130 /* 131 * Copy Ethernet addresses from a to b - assumes that the two given 132 * pointers can be referenced as shorts. On architectures 133 * where this is not the case, use bcopy instead. 134 */ 135 136 #if defined(__sparc) || defined(__i386) || defined(__amd64) 137 #define ether_copy(a, b) { ((short *)b)[0] = ((short *)a)[0]; \ 138 ((short *)b)[1] = ((short *)a)[1]; ((short *)b)[2] = ((short *)a)[2]; } 139 #else 140 #define ether_copy(a, b) (bcopy((caddr_t)a, (caddr_t)b, 6)) 141 #endif 142 143 #ifdef _KERNEL 144 #define ETHER_IS_MULTICAST(addr) (((addr)[0] & 0x01) != 0) 145 146 extern int localetheraddr(struct ether_addr *, struct ether_addr *); 147 extern char *ether_sprintf(struct ether_addr *); 148 extern int ether_aton(char *, uchar_t *); 149 #else /* _KERNEL */ 150 extern char *ether_ntoa(const struct ether_addr *); 151 extern char *ether_ntoa_r(const struct ether_addr *, char *); 152 extern struct ether_addr *ether_aton(const char *); 153 extern struct ether_addr *ether_aton_r(const char *, struct ether_addr *); 154 extern int ether_ntohost(char *, const struct ether_addr *); 155 extern int ether_hostton(const char *, struct ether_addr *); 156 extern int ether_line(const char *, struct ether_addr *, char *); 157 #endif /* _KERNEL */ 158 159 #ifdef __cplusplus 160 } 161 #endif 162 163 #endif /* _SYS_ETHERNET_H */ 164