xref: /onnv-gate/usr/src/uts/common/sys/ethernet.h (revision 10491:8893b747ecdf)
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
52760Sdg199075  * Common Development and Distribution License (the "License").
62760Sdg199075  * 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 /*
229087SZhong.Wang@Sun.COM  * Copyright 2009 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 #ifdef	__cplusplus
340Sstevel@tonic-gate extern "C" {
350Sstevel@tonic-gate #endif
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #define	ETHERADDRL	(6)		/* ethernet address length in octets */
380Sstevel@tonic-gate #define	ETHERFCSL	(4)		/* ethernet FCS length in octets */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate /*
410Sstevel@tonic-gate  * Ethernet address - 6 octets
420Sstevel@tonic-gate  */
430Sstevel@tonic-gate typedef uchar_t ether_addr_t[ETHERADDRL];
440Sstevel@tonic-gate 
450Sstevel@tonic-gate /*
460Sstevel@tonic-gate  * Ethernet address - 6 octets
470Sstevel@tonic-gate  */
480Sstevel@tonic-gate struct	ether_addr {
490Sstevel@tonic-gate 	ether_addr_t	ether_addr_octet;
500Sstevel@tonic-gate };
510Sstevel@tonic-gate 
520Sstevel@tonic-gate /*
530Sstevel@tonic-gate  * Structure of a 10Mb/s Ethernet header.
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate struct	ether_header {
560Sstevel@tonic-gate 	struct	ether_addr	ether_dhost;
570Sstevel@tonic-gate 	struct	ether_addr	ether_shost;
580Sstevel@tonic-gate 	ushort_t		ether_type;
590Sstevel@tonic-gate };
600Sstevel@tonic-gate 
610Sstevel@tonic-gate #define	ETHER_CFI	0
620Sstevel@tonic-gate 
630Sstevel@tonic-gate struct	ether_vlan_header {
640Sstevel@tonic-gate 	struct	ether_addr	ether_dhost;
650Sstevel@tonic-gate 	struct	ether_addr	ether_shost;
660Sstevel@tonic-gate 	ushort_t		ether_tpid;
670Sstevel@tonic-gate 	ushort_t		ether_tci;
680Sstevel@tonic-gate 	ushort_t		ether_type;
690Sstevel@tonic-gate };
700Sstevel@tonic-gate 
712760Sdg199075 /*
722760Sdg199075  * The VLAN tag.  Available for applications that cannot make use of struct
732760Sdg199075  * ether_vlan_header because they assume Ethernet encapsulation.
742760Sdg199075  */
752760Sdg199075 struct ether_vlan_extinfo {
762760Sdg199075 	ushort_t		ether_tci;
772760Sdg199075 	ushort_t		ether_type;
782760Sdg199075 };
792760Sdg199075 
800Sstevel@tonic-gate #define	ETHERTYPE_PUP		(0x0200)	/* PUP protocol */
810Sstevel@tonic-gate #define	ETHERTYPE_802_MIN	(0x0600)	/* Min valid ethernet type */
820Sstevel@tonic-gate 						/* under IEEE 802.3 rules */
830Sstevel@tonic-gate #define	ETHERTYPE_IP		(0x0800)	/* IP protocol */
840Sstevel@tonic-gate #define	ETHERTYPE_ARP		(0x0806)	/* Addr. resolution protocol */
850Sstevel@tonic-gate #define	ETHERTYPE_REVARP	(0x8035)	/* Reverse ARP */
860Sstevel@tonic-gate #define	ETHERTYPE_AT		(0x809b)	/* AppleTalk protocol */
870Sstevel@tonic-gate #define	ETHERTYPE_AARP		(0x80f3)	/* AppleTalk ARP */
882760Sdg199075 #define	ETHERTYPE_VLAN		(0x8100)	/* 802.1Q VLAN */
890Sstevel@tonic-gate #define	ETHERTYPE_IPV6		(0x86dd)	/* IPv6 */
900Sstevel@tonic-gate #define	ETHERTYPE_SLOW		(0x8809)	/* Slow Protocol */
910Sstevel@tonic-gate #define	ETHERTYPE_PPPOED	(0x8863)	/* PPPoE Discovery Stage */
920Sstevel@tonic-gate #define	ETHERTYPE_PPPOES	(0x8864)	/* PPPoE Session Stage */
934126Szf162725 #define	ETHERTYPE_EAPOL		(0x888e)	/* EAPOL protocol */
944126Szf162725 #define	ETHERTYPE_RSN_PREAUTH	(0x88c7)	/* RSN PRE-Authentication */
95*10491SRishi.Srivatsavai@Sun.COM #define	ETHERTYPE_TRILL		(0x88c8)	/* TBD. TRILL frame */
969087SZhong.Wang@Sun.COM #define	ETHERTYPE_FCOE		(0x8906)	/* FCoE */
970Sstevel@tonic-gate #define	ETHERTYPE_MAX		(0xffff)	/* Max valid ethernet type */
980Sstevel@tonic-gate 
990Sstevel@tonic-gate /*
1000Sstevel@tonic-gate  * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
1010Sstevel@tonic-gate  * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
1020Sstevel@tonic-gate  * by an ETHER type (as given above) and then the (variable-length) header.
1030Sstevel@tonic-gate  */
1040Sstevel@tonic-gate #define	ETHERTYPE_TRAIL		(0x1000)	/* Trailer packet */
1050Sstevel@tonic-gate #define	ETHERTYPE_NTRAILER	(16)
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate #define	ETHERMTU		(1500)	/* max frame w/o header or fcs */
1080Sstevel@tonic-gate #define	ETHERMIN		(60)	/* min frame w/header w/o fcs */
1090Sstevel@tonic-gate #define	ETHERMAX		(1514)	/* max frame w/header w/o fcs */
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate /*
1120Sstevel@tonic-gate  * Compare two Ethernet addresses - assumes that the two given
1130Sstevel@tonic-gate  * pointers can be referenced as shorts.  On architectures
1140Sstevel@tonic-gate  * where this is not the case, use bcmp instead.  Note that like
1150Sstevel@tonic-gate  * bcmp, we return zero if they are the SAME.
1160Sstevel@tonic-gate  */
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate #if defined(__sparc) || defined(__i386) || defined(__amd64)
1190Sstevel@tonic-gate #define	ether_cmp(a, b) (((short *)b)[2] != ((short *)a)[2] || \
1200Sstevel@tonic-gate 	((short *)b)[1] != ((short *)a)[1] || \
1210Sstevel@tonic-gate 	((short *)b)[0] != ((short *)a)[0])
1220Sstevel@tonic-gate #else
1230Sstevel@tonic-gate #define	ether_cmp(a, b) (bcmp((caddr_t)a, (caddr_t)b, 6))
1240Sstevel@tonic-gate #endif
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate /*
1270Sstevel@tonic-gate  * Copy Ethernet addresses from a to b - assumes that the two given
1280Sstevel@tonic-gate  * pointers can be referenced as shorts.  On architectures
1290Sstevel@tonic-gate  * where this is not the case, use bcopy instead.
1300Sstevel@tonic-gate  */
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate #if defined(__sparc) || defined(__i386) || defined(__amd64)
1330Sstevel@tonic-gate #define	ether_copy(a, b) { ((short *)b)[0] = ((short *)a)[0]; \
1340Sstevel@tonic-gate 	((short *)b)[1] = ((short *)a)[1]; ((short *)b)[2] = ((short *)a)[2]; }
1350Sstevel@tonic-gate #else
1360Sstevel@tonic-gate #define	ether_copy(a, b) (bcopy((caddr_t)a, (caddr_t)b, 6))
1370Sstevel@tonic-gate #endif
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate #ifdef	_KERNEL
1400Sstevel@tonic-gate extern int localetheraddr(struct ether_addr *, struct ether_addr *);
1410Sstevel@tonic-gate extern char *ether_sprintf(struct ether_addr *);
1420Sstevel@tonic-gate extern int ether_aton(char *, uchar_t *);
1430Sstevel@tonic-gate #else	/* _KERNEL */
1440Sstevel@tonic-gate #ifdef  __STDC__
1450Sstevel@tonic-gate extern char *ether_ntoa(const struct ether_addr *);
1460Sstevel@tonic-gate extern struct ether_addr *ether_aton(const char *);
1470Sstevel@tonic-gate extern int ether_ntohost(char *, const struct ether_addr *);
1480Sstevel@tonic-gate extern int ether_hostton(const char *, struct ether_addr *);
1490Sstevel@tonic-gate extern int ether_line(const char *, struct ether_addr *, char *);
1500Sstevel@tonic-gate #else	/* __STDC__ */
1510Sstevel@tonic-gate extern char *ether_ntoa();
1520Sstevel@tonic-gate extern struct ether_addr *ether_aton();
1530Sstevel@tonic-gate extern int ether_ntohost();
1540Sstevel@tonic-gate extern int ether_hostton();
1550Sstevel@tonic-gate extern int ether_line();
1560Sstevel@tonic-gate #endif	/* __STDC__ */
1570Sstevel@tonic-gate #endif	/* _KERNEL */
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate #ifdef	__cplusplus
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate #endif
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate #endif	/* _SYS_ETHERNET_H */
164