10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2760Sdg199075 * Common Development and Distribution License (the "License"). 6*2760Sdg199075 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*2760Sdg199075 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* 270Sstevel@tonic-gate * ethernet.h header for common Ethernet declarations. 280Sstevel@tonic-gate */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate #ifndef _SYS_ETHERNET_H 310Sstevel@tonic-gate #define _SYS_ETHERNET_H 320Sstevel@tonic-gate 330Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 340Sstevel@tonic-gate 350Sstevel@tonic-gate #ifdef __cplusplus 360Sstevel@tonic-gate extern "C" { 370Sstevel@tonic-gate #endif 380Sstevel@tonic-gate 390Sstevel@tonic-gate #define ETHERADDRL (6) /* ethernet address length in octets */ 400Sstevel@tonic-gate #define ETHERFCSL (4) /* ethernet FCS length in octets */ 410Sstevel@tonic-gate 420Sstevel@tonic-gate /* 430Sstevel@tonic-gate * Ethernet address - 6 octets 440Sstevel@tonic-gate */ 450Sstevel@tonic-gate typedef uchar_t ether_addr_t[ETHERADDRL]; 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* 480Sstevel@tonic-gate * Ethernet address - 6 octets 490Sstevel@tonic-gate */ 500Sstevel@tonic-gate struct ether_addr { 510Sstevel@tonic-gate ether_addr_t ether_addr_octet; 520Sstevel@tonic-gate }; 530Sstevel@tonic-gate 540Sstevel@tonic-gate /* 550Sstevel@tonic-gate * Structure of a 10Mb/s Ethernet header. 560Sstevel@tonic-gate */ 570Sstevel@tonic-gate struct ether_header { 580Sstevel@tonic-gate struct ether_addr ether_dhost; 590Sstevel@tonic-gate struct ether_addr ether_shost; 600Sstevel@tonic-gate ushort_t ether_type; 610Sstevel@tonic-gate }; 620Sstevel@tonic-gate 630Sstevel@tonic-gate #define ETHER_CFI 0 640Sstevel@tonic-gate 650Sstevel@tonic-gate struct ether_vlan_header { 660Sstevel@tonic-gate struct ether_addr ether_dhost; 670Sstevel@tonic-gate struct ether_addr ether_shost; 680Sstevel@tonic-gate ushort_t ether_tpid; 690Sstevel@tonic-gate ushort_t ether_tci; 700Sstevel@tonic-gate ushort_t ether_type; 710Sstevel@tonic-gate }; 720Sstevel@tonic-gate 73*2760Sdg199075 /* 74*2760Sdg199075 * The VLAN tag. Available for applications that cannot make use of struct 75*2760Sdg199075 * ether_vlan_header because they assume Ethernet encapsulation. 76*2760Sdg199075 */ 77*2760Sdg199075 struct ether_vlan_extinfo { 78*2760Sdg199075 ushort_t ether_tci; 79*2760Sdg199075 ushort_t ether_type; 80*2760Sdg199075 }; 81*2760Sdg199075 820Sstevel@tonic-gate #define ETHERTYPE_PUP (0x0200) /* PUP protocol */ 830Sstevel@tonic-gate #define ETHERTYPE_802_MIN (0x0600) /* Min valid ethernet type */ 840Sstevel@tonic-gate /* under IEEE 802.3 rules */ 850Sstevel@tonic-gate #define ETHERTYPE_IP (0x0800) /* IP protocol */ 860Sstevel@tonic-gate #define ETHERTYPE_ARP (0x0806) /* Addr. resolution protocol */ 870Sstevel@tonic-gate #define ETHERTYPE_REVARP (0x8035) /* Reverse ARP */ 880Sstevel@tonic-gate #define ETHERTYPE_AT (0x809b) /* AppleTalk protocol */ 890Sstevel@tonic-gate #define ETHERTYPE_AARP (0x80f3) /* AppleTalk ARP */ 90*2760Sdg199075 #define ETHERTYPE_VLAN (0x8100) /* 802.1Q VLAN */ 910Sstevel@tonic-gate #define ETHERTYPE_IPV6 (0x86dd) /* IPv6 */ 920Sstevel@tonic-gate #define ETHERTYPE_SLOW (0x8809) /* Slow Protocol */ 930Sstevel@tonic-gate #define ETHERTYPE_PPPOED (0x8863) /* PPPoE Discovery Stage */ 940Sstevel@tonic-gate #define ETHERTYPE_PPPOES (0x8864) /* PPPoE Session Stage */ 950Sstevel@tonic-gate #define ETHERTYPE_MAX (0xffff) /* Max valid ethernet type */ 960Sstevel@tonic-gate 970Sstevel@tonic-gate /* 980Sstevel@tonic-gate * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have 990Sstevel@tonic-gate * (type-ETHERTYPE_TRAIL)*512 bytes of data followed 1000Sstevel@tonic-gate * by an ETHER type (as given above) and then the (variable-length) header. 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate #define ETHERTYPE_TRAIL (0x1000) /* Trailer packet */ 1030Sstevel@tonic-gate #define ETHERTYPE_NTRAILER (16) 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate #define ETHERMTU (1500) /* max frame w/o header or fcs */ 1060Sstevel@tonic-gate #define ETHERMIN (60) /* min frame w/header w/o fcs */ 1070Sstevel@tonic-gate #define ETHERMAX (1514) /* max frame w/header w/o fcs */ 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* 1100Sstevel@tonic-gate * Compare two Ethernet addresses - assumes that the two given 1110Sstevel@tonic-gate * pointers can be referenced as shorts. On architectures 1120Sstevel@tonic-gate * where this is not the case, use bcmp instead. Note that like 1130Sstevel@tonic-gate * bcmp, we return zero if they are the SAME. 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate #if defined(__sparc) || defined(__i386) || defined(__amd64) 1170Sstevel@tonic-gate #define ether_cmp(a, b) (((short *)b)[2] != ((short *)a)[2] || \ 1180Sstevel@tonic-gate ((short *)b)[1] != ((short *)a)[1] || \ 1190Sstevel@tonic-gate ((short *)b)[0] != ((short *)a)[0]) 1200Sstevel@tonic-gate #else 1210Sstevel@tonic-gate #define ether_cmp(a, b) (bcmp((caddr_t)a, (caddr_t)b, 6)) 1220Sstevel@tonic-gate #endif 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate /* 1250Sstevel@tonic-gate * Copy Ethernet addresses from a to b - assumes that the two given 1260Sstevel@tonic-gate * pointers can be referenced as shorts. On architectures 1270Sstevel@tonic-gate * where this is not the case, use bcopy instead. 1280Sstevel@tonic-gate */ 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate #if defined(__sparc) || defined(__i386) || defined(__amd64) 1310Sstevel@tonic-gate #define ether_copy(a, b) { ((short *)b)[0] = ((short *)a)[0]; \ 1320Sstevel@tonic-gate ((short *)b)[1] = ((short *)a)[1]; ((short *)b)[2] = ((short *)a)[2]; } 1330Sstevel@tonic-gate #else 1340Sstevel@tonic-gate #define ether_copy(a, b) (bcopy((caddr_t)a, (caddr_t)b, 6)) 1350Sstevel@tonic-gate #endif 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate #ifdef _KERNEL 1380Sstevel@tonic-gate extern int localetheraddr(struct ether_addr *, struct ether_addr *); 1390Sstevel@tonic-gate extern char *ether_sprintf(struct ether_addr *); 1400Sstevel@tonic-gate extern int ether_aton(char *, uchar_t *); 1410Sstevel@tonic-gate #else /* _KERNEL */ 1420Sstevel@tonic-gate #ifdef __STDC__ 1430Sstevel@tonic-gate extern char *ether_ntoa(const struct ether_addr *); 1440Sstevel@tonic-gate extern struct ether_addr *ether_aton(const char *); 1450Sstevel@tonic-gate extern int ether_ntohost(char *, const struct ether_addr *); 1460Sstevel@tonic-gate extern int ether_hostton(const char *, struct ether_addr *); 1470Sstevel@tonic-gate extern int ether_line(const char *, struct ether_addr *, char *); 1480Sstevel@tonic-gate #else /* __STDC__ */ 1490Sstevel@tonic-gate extern char *ether_ntoa(); 1500Sstevel@tonic-gate extern struct ether_addr *ether_aton(); 1510Sstevel@tonic-gate extern int ether_ntohost(); 1520Sstevel@tonic-gate extern int ether_hostton(); 1530Sstevel@tonic-gate extern int ether_line(); 1540Sstevel@tonic-gate #endif /* __STDC__ */ 1550Sstevel@tonic-gate #endif /* _KERNEL */ 1560Sstevel@tonic-gate 1570Sstevel@tonic-gate #ifdef __cplusplus 1580Sstevel@tonic-gate } 1590Sstevel@tonic-gate #endif 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate #endif /* _SYS_ETHERNET_H */ 162