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