17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5605445d5Sdg199075 * Common Development and Distribution License (the "License"). 6605445d5Sdg199075 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22ba3594baSGarrett D'Amore * Copyright 2014 Garrett D'Amore <garrett@damore.org> 23ba3594baSGarrett D'Amore * 242a8164dfSZhong Wang * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 257c478bd9Sstevel@tonic-gate * Use is subject to license terms. 267c478bd9Sstevel@tonic-gate */ 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * ethernet.h header for common Ethernet declarations. 307c478bd9Sstevel@tonic-gate */ 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #ifndef _SYS_ETHERNET_H 337c478bd9Sstevel@tonic-gate #define _SYS_ETHERNET_H 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef __cplusplus 367c478bd9Sstevel@tonic-gate extern "C" { 377c478bd9Sstevel@tonic-gate #endif 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #define ETHERADDRL (6) /* ethernet address length in octets */ 407c478bd9Sstevel@tonic-gate #define ETHERFCSL (4) /* ethernet FCS length in octets */ 41*ff3aea39SRobert Mustacchi #define ETHERADDRSTRL (18) /* char size of ETHERADDRL with null */ 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * Ethernet address - 6 octets 457c478bd9Sstevel@tonic-gate */ 467c478bd9Sstevel@tonic-gate typedef uchar_t ether_addr_t[ETHERADDRL]; 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate /* 497c478bd9Sstevel@tonic-gate * Ethernet address - 6 octets 507c478bd9Sstevel@tonic-gate */ 517c478bd9Sstevel@tonic-gate struct ether_addr { 527c478bd9Sstevel@tonic-gate ether_addr_t ether_addr_octet; 537c478bd9Sstevel@tonic-gate }; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * Structure of a 10Mb/s Ethernet header. 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate struct ether_header { 597c478bd9Sstevel@tonic-gate struct ether_addr ether_dhost; 607c478bd9Sstevel@tonic-gate struct ether_addr ether_shost; 617c478bd9Sstevel@tonic-gate ushort_t ether_type; 627c478bd9Sstevel@tonic-gate }; 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate #define ETHER_CFI 0 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate struct ether_vlan_header { 677c478bd9Sstevel@tonic-gate struct ether_addr ether_dhost; 687c478bd9Sstevel@tonic-gate struct ether_addr ether_shost; 697c478bd9Sstevel@tonic-gate ushort_t ether_tpid; 707c478bd9Sstevel@tonic-gate ushort_t ether_tci; 717c478bd9Sstevel@tonic-gate ushort_t ether_type; 727c478bd9Sstevel@tonic-gate }; 737c478bd9Sstevel@tonic-gate 74605445d5Sdg199075 /* 75605445d5Sdg199075 * The VLAN tag. Available for applications that cannot make use of struct 76605445d5Sdg199075 * ether_vlan_header because they assume Ethernet encapsulation. 77605445d5Sdg199075 */ 78605445d5Sdg199075 struct ether_vlan_extinfo { 79605445d5Sdg199075 ushort_t ether_tci; 80605445d5Sdg199075 ushort_t ether_type; 81605445d5Sdg199075 }; 82605445d5Sdg199075 837c478bd9Sstevel@tonic-gate #define ETHERTYPE_PUP (0x0200) /* PUP protocol */ 847c478bd9Sstevel@tonic-gate #define ETHERTYPE_802_MIN (0x0600) /* Min valid ethernet type */ 857c478bd9Sstevel@tonic-gate /* under IEEE 802.3 rules */ 867c478bd9Sstevel@tonic-gate #define ETHERTYPE_IP (0x0800) /* IP protocol */ 877c478bd9Sstevel@tonic-gate #define ETHERTYPE_ARP (0x0806) /* Addr. resolution protocol */ 887c478bd9Sstevel@tonic-gate #define ETHERTYPE_REVARP (0x8035) /* Reverse ARP */ 897c478bd9Sstevel@tonic-gate #define ETHERTYPE_AT (0x809b) /* AppleTalk protocol */ 907c478bd9Sstevel@tonic-gate #define ETHERTYPE_AARP (0x80f3) /* AppleTalk ARP */ 91605445d5Sdg199075 #define ETHERTYPE_VLAN (0x8100) /* 802.1Q VLAN */ 927c478bd9Sstevel@tonic-gate #define ETHERTYPE_IPV6 (0x86dd) /* IPv6 */ 937c478bd9Sstevel@tonic-gate #define ETHERTYPE_SLOW (0x8809) /* Slow Protocol */ 947c478bd9Sstevel@tonic-gate #define ETHERTYPE_PPPOED (0x8863) /* PPPoE Discovery Stage */ 957c478bd9Sstevel@tonic-gate #define ETHERTYPE_PPPOES (0x8864) /* PPPoE Session Stage */ 96a399b765Szf162725 #define ETHERTYPE_EAPOL (0x888e) /* EAPOL protocol */ 97a399b765Szf162725 #define ETHERTYPE_RSN_PREAUTH (0x88c7) /* RSN PRE-Authentication */ 984eaa4710SRishi Srivatsavai #define ETHERTYPE_TRILL (0x88c8) /* TBD. TRILL frame */ 992a8164dfSZhong Wang #define ETHERTYPE_FCOE (0x8906) /* FCoE */ 1007c478bd9Sstevel@tonic-gate #define ETHERTYPE_MAX (0xffff) /* Max valid ethernet type */ 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate /* 1037c478bd9Sstevel@tonic-gate * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have 1047c478bd9Sstevel@tonic-gate * (type-ETHERTYPE_TRAIL)*512 bytes of data followed 1057c478bd9Sstevel@tonic-gate * by an ETHER type (as given above) and then the (variable-length) header. 1067c478bd9Sstevel@tonic-gate */ 1077c478bd9Sstevel@tonic-gate #define ETHERTYPE_TRAIL (0x1000) /* Trailer packet */ 1087c478bd9Sstevel@tonic-gate #define ETHERTYPE_NTRAILER (16) 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate #define ETHERMTU (1500) /* max frame w/o header or fcs */ 1117c478bd9Sstevel@tonic-gate #define ETHERMIN (60) /* min frame w/header w/o fcs */ 1127c478bd9Sstevel@tonic-gate #define ETHERMAX (1514) /* max frame w/header w/o fcs */ 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate /* 1157c478bd9Sstevel@tonic-gate * Compare two Ethernet addresses - assumes that the two given 1167c478bd9Sstevel@tonic-gate * pointers can be referenced as shorts. On architectures 1177c478bd9Sstevel@tonic-gate * where this is not the case, use bcmp instead. Note that like 1187c478bd9Sstevel@tonic-gate * bcmp, we return zero if they are the SAME. 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate #if defined(__sparc) || defined(__i386) || defined(__amd64) 1227c478bd9Sstevel@tonic-gate #define ether_cmp(a, b) (((short *)b)[2] != ((short *)a)[2] || \ 1237c478bd9Sstevel@tonic-gate ((short *)b)[1] != ((short *)a)[1] || \ 1247c478bd9Sstevel@tonic-gate ((short *)b)[0] != ((short *)a)[0]) 1257c478bd9Sstevel@tonic-gate #else 1267c478bd9Sstevel@tonic-gate #define ether_cmp(a, b) (bcmp((caddr_t)a, (caddr_t)b, 6)) 1277c478bd9Sstevel@tonic-gate #endif 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate /* 1307c478bd9Sstevel@tonic-gate * Copy Ethernet addresses from a to b - assumes that the two given 1317c478bd9Sstevel@tonic-gate * pointers can be referenced as shorts. On architectures 1327c478bd9Sstevel@tonic-gate * where this is not the case, use bcopy instead. 1337c478bd9Sstevel@tonic-gate */ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate #if defined(__sparc) || defined(__i386) || defined(__amd64) 1367c478bd9Sstevel@tonic-gate #define ether_copy(a, b) { ((short *)b)[0] = ((short *)a)[0]; \ 1377c478bd9Sstevel@tonic-gate ((short *)b)[1] = ((short *)a)[1]; ((short *)b)[2] = ((short *)a)[2]; } 1387c478bd9Sstevel@tonic-gate #else 1397c478bd9Sstevel@tonic-gate #define ether_copy(a, b) (bcopy((caddr_t)a, (caddr_t)b, 6)) 1407c478bd9Sstevel@tonic-gate #endif 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1437c478bd9Sstevel@tonic-gate extern int localetheraddr(struct ether_addr *, struct ether_addr *); 1447c478bd9Sstevel@tonic-gate extern char *ether_sprintf(struct ether_addr *); 1457c478bd9Sstevel@tonic-gate extern int ether_aton(char *, uchar_t *); 1467c478bd9Sstevel@tonic-gate #else /* _KERNEL */ 1477c478bd9Sstevel@tonic-gate extern char *ether_ntoa(const struct ether_addr *); 148*ff3aea39SRobert Mustacchi extern char *ether_ntoa_r(const struct ether_addr *, char *); 1497c478bd9Sstevel@tonic-gate extern struct ether_addr *ether_aton(const char *); 150*ff3aea39SRobert Mustacchi extern struct ether_addr *ether_aton_r(const char *, struct ether_addr *); 1517c478bd9Sstevel@tonic-gate extern int ether_ntohost(char *, const struct ether_addr *); 1527c478bd9Sstevel@tonic-gate extern int ether_hostton(const char *, struct ether_addr *); 1537c478bd9Sstevel@tonic-gate extern int ether_line(const char *, struct ether_addr *, char *); 1547c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate #endif 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate #endif /* _SYS_ETHERNET_H */ 161