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