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