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