2
* From FreeBSD 2.2.7: Fundamental constants relating to ethernet.
4
* Copyright 2008, Broadcom Corporation
7
* Unless you and Broadcom execute a separate written software license
8
* agreement governing use of this software, this software is licensed to you
9
* under the terms of the GNU General Public License version 2, available at
10
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL"), with the
11
* following added to such license:
12
* As a special exception, the copyright holders of this software give you
13
* permission to link this software with independent modules, regardless of the
14
* license terms of these independent modules, and to copy and distribute the
15
* resulting executable under terms of your choice, provided that you also meet,
16
* for each linked independent module, the terms and conditions of the license
17
* of that module. An independent module is a module which is not derived from
20
* THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
21
* KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
22
* SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
23
* FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
25
* $Id: ethernet.h,v 9.45.12.1 2008/08/13 02:24:19 Exp $
28
#ifndef _NET_ETHERNET_H_
29
#define _NET_ETHERNET_H_
36
#define PACKED __attribute__((packed))
42
#define ETHER_ADDR_LEN 6
44
#define ETHER_TYPE_LEN 2
46
#define ETHER_CRC_LEN 4
48
#define ETHER_HDR_LEN (ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN)
50
#define ETHER_MIN_LEN 64
52
#define ETHER_MIN_DATA 46
54
#define ETHER_MAX_LEN 1518
56
#define ETHER_MAX_DATA 1500
58
#define ETHER_TYPE_MIN 0x0600
59
#define ETHER_TYPE_IP 0x0800
60
#define ETHER_TYPE_ARP 0x0806
61
#define ETHER_TYPE_8021Q 0x8100
62
#define ETHER_TYPE_BRCM 0x886c
63
#define ETHER_TYPE_802_1X 0x888e
64
#define ETHER_TYPE_802_1X_PREAUTH 0x88c7
66
#define ETHER_BRCM_SUBTYPE_LEN 4
67
#define ETHER_BRCM_CRAM 1
69
#define ETHER_DEST_OFFSET (0 * ETHER_ADDR_LEN)
70
#define ETHER_SRC_OFFSET (1 * ETHER_ADDR_LEN)
71
#define ETHER_TYPE_OFFSET (2 * ETHER_ADDR_LEN)
73
#define ETHER_IS_VALID_LEN(foo) \
74
((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
76
#define ETHER_FILL_MCAST_ADDR_FROM_IP(eaddr, mgrp_ip) \
80
eaddr[5] = mgrp_ip & 0xff; mgrp_ip >>= 8; \
81
eaddr[4] = mgrp_ip & 0xff; mgrp_ip >>= 8; \
82
eaddr[3] = mgrp_ip & 0x7f
84
#ifndef __INCif_etherh
87
uint8 ether_dhost[ETHER_ADDR_LEN];
88
uint8 ether_shost[ETHER_ADDR_LEN];
93
uint8 octet[ETHER_ADDR_LEN];
97
#define ETHER_SET_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] | 2))
98
#define ETHER_IS_LOCALADDR(ea) (((uint8 *)(ea))[0] & 2)
99
#define ETHER_CLR_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] & 0xd))
100
#define ETHER_TOGGLE_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] ^ 2))
102
#define ETHER_SET_UNICAST(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] & ~1))
104
#define ETHER_ISMULTI(ea) (((const uint8 *)(ea))[0] & 1)
106
#define ether_cmp(a, b) (!(((short*)a)[0] == ((short*)b)[0]) | \
107
!(((short*)a)[1] == ((short*)b)[1]) | \
108
!(((short*)a)[2] == ((short*)b)[2]))
110
#define ether_copy(s, d) { \
111
((short*)d)[0] = ((short*)s)[0]; \
112
((short*)d)[1] = ((short*)s)[1]; \
113
((short*)d)[2] = ((short*)s)[2]; }
115
#define ETHER_ISBCAST(ea) ((((uint8 *)(ea))[0] & \
116
((uint8 *)(ea))[1] & \
117
((uint8 *)(ea))[2] & \
118
((uint8 *)(ea))[3] & \
119
((uint8 *)(ea))[4] & \
120
((uint8 *)(ea))[5]) == 0xff)
122
static const struct ether_addr ether_bcast = {{255, 255, 255, 255, 255, 255}};
123
static const struct ether_addr ether_null = {{0, 0, 0, 0, 0, 0}};
125
#define ETHER_ISNULLADDR(ea) ((((uint8 *)(ea))[0] | \
126
((uint8 *)(ea))[1] | \
127
((uint8 *)(ea))[2] | \
128
((uint8 *)(ea))[3] | \
129
((uint8 *)(ea))[4] | \
130
((uint8 *)(ea))[5]) == 0)
133
#if !defined(__GNUC__)