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 /* 22*2a8164dfSZhong Wang * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * ethernet.h header for common Ethernet declarations. 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifndef _SYS_ETHERNET_H 317c478bd9Sstevel@tonic-gate #define _SYS_ETHERNET_H 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #ifdef __cplusplus 347c478bd9Sstevel@tonic-gate extern "C" { 357c478bd9Sstevel@tonic-gate #endif 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #define ETHERADDRL (6) /* ethernet address length in octets */ 387c478bd9Sstevel@tonic-gate #define ETHERFCSL (4) /* ethernet FCS length in octets */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * Ethernet address - 6 octets 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate typedef uchar_t ether_addr_t[ETHERADDRL]; 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate * Ethernet address - 6 octets 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate struct ether_addr { 497c478bd9Sstevel@tonic-gate ether_addr_t ether_addr_octet; 507c478bd9Sstevel@tonic-gate }; 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * Structure of a 10Mb/s Ethernet header. 547c478bd9Sstevel@tonic-gate */ 557c478bd9Sstevel@tonic-gate struct ether_header { 567c478bd9Sstevel@tonic-gate struct ether_addr ether_dhost; 577c478bd9Sstevel@tonic-gate struct ether_addr ether_shost; 587c478bd9Sstevel@tonic-gate ushort_t ether_type; 597c478bd9Sstevel@tonic-gate }; 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate #define ETHER_CFI 0 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate struct ether_vlan_header { 647c478bd9Sstevel@tonic-gate struct ether_addr ether_dhost; 657c478bd9Sstevel@tonic-gate struct ether_addr ether_shost; 667c478bd9Sstevel@tonic-gate ushort_t ether_tpid; 677c478bd9Sstevel@tonic-gate ushort_t ether_tci; 687c478bd9Sstevel@tonic-gate ushort_t ether_type; 697c478bd9Sstevel@tonic-gate }; 707c478bd9Sstevel@tonic-gate 71605445d5Sdg199075 /* 72605445d5Sdg199075 * The VLAN tag. Available for applications that cannot make use of struct 73605445d5Sdg199075 * ether_vlan_header because they assume Ethernet encapsulation. 74605445d5Sdg199075 */ 75605445d5Sdg199075 struct ether_vlan_extinfo { 76605445d5Sdg199075 ushort_t ether_tci; 77605445d5Sdg199075 ushort_t ether_type; 78605445d5Sdg199075 }; 79605445d5Sdg199075 807c478bd9Sstevel@tonic-gate #define ETHERTYPE_PUP (0x0200) /* PUP protocol */ 817c478bd9Sstevel@tonic-gate #define ETHERTYPE_802_MIN (0x0600) /* Min valid ethernet type */ 827c478bd9Sstevel@tonic-gate /* under IEEE 802.3 rules */ 837c478bd9Sstevel@tonic-gate #define ETHERTYPE_IP (0x0800) /* IP protocol */ 847c478bd9Sstevel@tonic-gate #define ETHERTYPE_ARP (0x0806) /* Addr. resolution protocol */ 857c478bd9Sstevel@tonic-gate #define ETHERTYPE_REVARP (0x8035) /* Reverse ARP */ 867c478bd9Sstevel@tonic-gate #define ETHERTYPE_AT (0x809b) /* AppleTalk protocol */ 877c478bd9Sstevel@tonic-gate #define ETHERTYPE_AARP (0x80f3) /* AppleTalk ARP */ 88605445d5Sdg199075 #define ETHERTYPE_VLAN (0x8100) /* 802.1Q VLAN */ 897c478bd9Sstevel@tonic-gate #define ETHERTYPE_IPV6 (0x86dd) /* IPv6 */ 907c478bd9Sstevel@tonic-gate #define ETHERTYPE_SLOW (0x8809) /* Slow Protocol */ 917c478bd9Sstevel@tonic-gate #define ETHERTYPE_PPPOED (0x8863) /* PPPoE Discovery Stage */ 927c478bd9Sstevel@tonic-gate #define ETHERTYPE_PPPOES (0x8864) /* PPPoE Session Stage */ 93a399b765Szf162725 #define ETHERTYPE_EAPOL (0x888e) /* EAPOL protocol */ 94a399b765Szf162725 #define ETHERTYPE_RSN_PREAUTH (0x88c7) /* RSN PRE-Authentication */ 95*2a8164dfSZhong Wang #define ETHERTYPE_FCOE (0x8906) /* FCoE */ 967c478bd9Sstevel@tonic-gate #define ETHERTYPE_MAX (0xffff) /* Max valid ethernet type */ 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate /* 997c478bd9Sstevel@tonic-gate * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have 1007c478bd9Sstevel@tonic-gate * (type-ETHERTYPE_TRAIL)*512 bytes of data followed 1017c478bd9Sstevel@tonic-gate * by an ETHER type (as given above) and then the (variable-length) header. 1027c478bd9Sstevel@tonic-gate */ 1037c478bd9Sstevel@tonic-gate #define ETHERTYPE_TRAIL (0x1000) /* Trailer packet */ 1047c478bd9Sstevel@tonic-gate #define ETHERTYPE_NTRAILER (16) 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate #define ETHERMTU (1500) /* max frame w/o header or fcs */ 1077c478bd9Sstevel@tonic-gate #define ETHERMIN (60) /* min frame w/header w/o fcs */ 1087c478bd9Sstevel@tonic-gate #define ETHERMAX (1514) /* max frame w/header w/o fcs */ 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* 1117c478bd9Sstevel@tonic-gate * Compare two Ethernet addresses - assumes that the two given 1127c478bd9Sstevel@tonic-gate * pointers can be referenced as shorts. On architectures 1137c478bd9Sstevel@tonic-gate * where this is not the case, use bcmp instead. Note that like 1147c478bd9Sstevel@tonic-gate * bcmp, we return zero if they are the SAME. 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate #if defined(__sparc) || defined(__i386) || defined(__amd64) 1187c478bd9Sstevel@tonic-gate #define ether_cmp(a, b) (((short *)b)[2] != ((short *)a)[2] || \ 1197c478bd9Sstevel@tonic-gate ((short *)b)[1] != ((short *)a)[1] || \ 1207c478bd9Sstevel@tonic-gate ((short *)b)[0] != ((short *)a)[0]) 1217c478bd9Sstevel@tonic-gate #else 1227c478bd9Sstevel@tonic-gate #define ether_cmp(a, b) (bcmp((caddr_t)a, (caddr_t)b, 6)) 1237c478bd9Sstevel@tonic-gate #endif 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate /* 1267c478bd9Sstevel@tonic-gate * Copy Ethernet addresses from a to b - assumes that the two given 1277c478bd9Sstevel@tonic-gate * pointers can be referenced as shorts. On architectures 1287c478bd9Sstevel@tonic-gate * where this is not the case, use bcopy instead. 1297c478bd9Sstevel@tonic-gate */ 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate #if defined(__sparc) || defined(__i386) || defined(__amd64) 1327c478bd9Sstevel@tonic-gate #define ether_copy(a, b) { ((short *)b)[0] = ((short *)a)[0]; \ 1337c478bd9Sstevel@tonic-gate ((short *)b)[1] = ((short *)a)[1]; ((short *)b)[2] = ((short *)a)[2]; } 1347c478bd9Sstevel@tonic-gate #else 1357c478bd9Sstevel@tonic-gate #define ether_copy(a, b) (bcopy((caddr_t)a, (caddr_t)b, 6)) 1367c478bd9Sstevel@tonic-gate #endif 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1397c478bd9Sstevel@tonic-gate extern int localetheraddr(struct ether_addr *, struct ether_addr *); 1407c478bd9Sstevel@tonic-gate extern char *ether_sprintf(struct ether_addr *); 1417c478bd9Sstevel@tonic-gate extern int ether_aton(char *, uchar_t *); 1427c478bd9Sstevel@tonic-gate #else /* _KERNEL */ 1437c478bd9Sstevel@tonic-gate #ifdef __STDC__ 1447c478bd9Sstevel@tonic-gate extern char *ether_ntoa(const struct ether_addr *); 1457c478bd9Sstevel@tonic-gate extern struct ether_addr *ether_aton(const char *); 1467c478bd9Sstevel@tonic-gate extern int ether_ntohost(char *, const struct ether_addr *); 1477c478bd9Sstevel@tonic-gate extern int ether_hostton(const char *, struct ether_addr *); 1487c478bd9Sstevel@tonic-gate extern int ether_line(const char *, struct ether_addr *, char *); 1497c478bd9Sstevel@tonic-gate #else /* __STDC__ */ 1507c478bd9Sstevel@tonic-gate extern char *ether_ntoa(); 1517c478bd9Sstevel@tonic-gate extern struct ether_addr *ether_aton(); 1527c478bd9Sstevel@tonic-gate extern int ether_ntohost(); 1537c478bd9Sstevel@tonic-gate extern int ether_hostton(); 1547c478bd9Sstevel@tonic-gate extern int ether_line(); 1557c478bd9Sstevel@tonic-gate #endif /* __STDC__ */ 1567c478bd9Sstevel@tonic-gate #endif /* _KERNEL */ 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1597c478bd9Sstevel@tonic-gate } 1607c478bd9Sstevel@tonic-gate #endif 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate #endif /* _SYS_ETHERNET_H */ 163