4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / sys / netinet / if_ether.h
CommitLineData
8ae0e4b4 1/*
e7a3707f
KB
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
8ae0e4b4 4 *
dbf0c423 5 * %sccs.include.redist.c%
2b6b6284 6 *
e7a3707f 7 * @(#)if_ether.h 8.1 (Berkeley) %G%
8ae0e4b4 8 */
66b2ba82
SL
9
10/*
11 * Structure of a 10Mb/s Ethernet header.
12 */
3fa8d9bb 13struct ether_header {
12026cce
MK
14 u_char ether_dhost[6];
15 u_char ether_shost[6];
3fa8d9bb 16 u_short ether_type;
66b2ba82
SL
17};
18
d6fa15c2
KS
19#define ETHERTYPE_PUP 0x0200 /* PUP protocol */
20#define ETHERTYPE_IP 0x0800 /* IP protocol */
21#define ETHERTYPE_ARP 0x0806 /* Addr. resolution protocol */
22#define ETHERTYPE_REVARP 0x8035 /* reverse Addr. resolution protocol */
66b2ba82
SL
23
24/*
12026cce 25 * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
8a0ea807
MK
26 * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
27 * by an ETHER type (as given above) and then the (variable-length) header.
66b2ba82 28 */
12026cce
MK
29#define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */
30#define ETHERTYPE_NTRAILER 16
3fa8d9bb
SL
31
32#define ETHERMTU 1500
33#define ETHERMIN (60-14)
8ae4cebd 34
d6fa15c2
KS
35#ifdef KERNEL
36/*
37 * Macro to map an IP multicast address to an Ethernet multicast address.
38 * The high-order 25 bits of the Ethernet address are statically assigned,
39 * and the low-order 23 bits are taken from the low end of the IP address.
40 */
41#define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
42 /* struct in_addr *ipaddr; */ \
43 /* u_char enaddr[6]; */ \
44{ \
45 (enaddr)[0] = 0x01; \
46 (enaddr)[1] = 0x00; \
47 (enaddr)[2] = 0x5e; \
48 (enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; \
49 (enaddr)[4] = ((u_char *)ipaddr)[2]; \
50 (enaddr)[5] = ((u_char *)ipaddr)[3]; \
51}
52#endif
53
8ae4cebd
SL
54/*
55 * Ethernet Address Resolution Protocol.
56 *
57 * See RFC 826 for protocol description. Structure below is adapted
58 * to resolving internet addresses. Field names used correspond to
59 * RFC 826.
60 */
61struct ether_arp {
8a0ea807 62 struct arphdr ea_hdr; /* fixed-size header */
12026cce
MK
63 u_char arp_sha[6]; /* sender hardware address */
64 u_char arp_spa[4]; /* sender protocol address */
65 u_char arp_tha[6]; /* target hardware address */
66 u_char arp_tpa[4]; /* target protocol address */
8ae4cebd 67};
8a0ea807
MK
68#define arp_hrd ea_hdr.ar_hrd
69#define arp_pro ea_hdr.ar_pro
70#define arp_hln ea_hdr.ar_hln
71#define arp_pln ea_hdr.ar_pln
72#define arp_op ea_hdr.ar_op
73
8ae4cebd 74
8ae4cebd
SL
75/*
76 * Structure shared between the ethernet driver modules and
77 * the address resolution code. For example, each ec_softc or il_softc
78 * begins with this structure.
79 */
80struct arpcom {
12026cce
MK
81 struct ifnet ac_if; /* network-visible interface */
82 u_char ac_enaddr[6]; /* ethernet hardware address */
d6fa15c2
KS
83 struct in_addr ac_ipaddr; /* copy of ip address- XXX */
84 struct ether_multi *ac_multiaddrs; /* list of ether multicast addrs */
85 int ac_multicnt; /* length of ac_multiaddrs list */
187456a2
MK
86};
87
bedad5e8
KS
88struct llinfo_arp {
89 struct llinfo_arp *la_next;
90 struct llinfo_arp *la_prev;
91 struct rtentry *la_rt;
92 struct mbuf *la_hold; /* last packet until resolved/timeout */
93 long la_asked; /* last time we QUERIED for this addr */
94#define la_timer la_rt->rt_rmx.rmx_expire /* deletion time in seconds */
95};
96
97struct sockaddr_inarp {
98 u_char sin_len;
99 u_char sin_family;
100 u_short sin_port;
101 struct in_addr sin_addr;
102 struct in_addr sin_srcaddr;
103 u_short sin_tos;
104 u_short sin_other;
105#define SIN_PROXY 1
106};
d6fa15c2
KS
107/*
108 * IP and ethernet specific routing flags
109 */
110#define RTF_USETRAILERS RTF_PROTO1 /* use trailers */
111#define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */
bedad5e8 112
5ebce7c6 113#ifdef KERNEL
0d246a40 114u_char etherbroadcastaddr[6];
d6fa15c2
KS
115u_char ether_ipmulticast_min[6];
116u_char ether_ipmulticast_max[6];
1acdf733 117struct ifqueue arpintrq;
d6fa15c2 118
0cf7ef94 119struct llinfo_arp *arptnew __P((struct in_addr *));
bedad5e8 120struct llinfo_arp llinfo_arp; /* head of the llinfo queue */
0cf7ef94 121
0cf7ef94 122void arpwhohas __P((struct arpcom *, struct in_addr *));
1acdf733
KB
123void arpintr __P((void));
124int arpresolve __P((struct arpcom *,
125 struct rtentry *, struct mbuf *, struct sockaddr *, u_char *));
126void arp_rtrequest __P((int, struct rtentry *, struct sockaddr *));
127void arpwhohas __P((struct arpcom *, struct in_addr *));
128
129int ether_addmulti __P((struct ifreq *, struct arpcom *));
130int ether_delmulti __P((struct ifreq *, struct arpcom *));
d6fa15c2 131
d6fa15c2
KS
132/*
133 * Ethernet multicast address structure. There is one of these for each
134 * multicast address or range of multicast addresses that we are supposed
135 * to listen to on a particular interface. They are kept in a linked list,
136 * rooted in the interface's arpcom structure. (This really has nothing to
137 * do with ARP, or with the Internet address family, but this appears to be
138 * the minimally-disrupting place to put it.)
139 */
140struct ether_multi {
141 u_char enm_addrlo[6]; /* low or only address of range */
142 u_char enm_addrhi[6]; /* high or only address of range */
143 struct arpcom *enm_ac; /* back pointer to arpcom */
144 u_int enm_refcount; /* no. claims to this addr/range */
145 struct ether_multi *enm_next; /* ptr to next ether_multi */
146};
147
d6fa15c2
KS
148/*
149 * Structure used by macros below to remember position when stepping through
150 * all of the ether_multi records.
151 */
152struct ether_multistep {
153 struct ether_multi *e_enm;
154};
155
156/*
157 * Macro for looking up the ether_multi record for a given range of Ethernet
158 * multicast addresses connected to a given arpcom structure. If no matching
159 * record is found, "enm" returns NULL.
160 */
161#define ETHER_LOOKUP_MULTI(addrlo, addrhi, ac, enm) \
162 /* u_char addrlo[6]; */ \
163 /* u_char addrhi[6]; */ \
164 /* struct arpcom *ac; */ \
165 /* struct ether_multi *enm; */ \
166{ \
167 for ((enm) = (ac)->ac_multiaddrs; \
168 (enm) != NULL && \
169 (bcmp((enm)->enm_addrlo, (addrlo), 6) != 0 || \
170 bcmp((enm)->enm_addrhi, (addrhi), 6) != 0); \
171 (enm) = (enm)->enm_next); \
172}
173
174/*
175 * Macro to step through all of the ether_multi records, one at a time.
176 * The current position is remembered in "step", which the caller must
177 * provide. ETHER_FIRST_MULTI(), below, must be called to initialize "step"
178 * and get the first record. Both macros return a NULL "enm" when there
179 * are no remaining records.
180 */
181#define ETHER_NEXT_MULTI(step, enm) \
182 /* struct ether_multistep step; */ \
183 /* struct ether_multi *enm; */ \
184{ \
185 if (((enm) = (step).e_enm) != NULL) \
186 (step).e_enm = (enm)->enm_next; \
187}
188
189#define ETHER_FIRST_MULTI(step, ac, enm) \
190 /* struct ether_multistep step; */ \
191 /* struct arpcom *ac; */ \
192 /* struct ether_multi *enm; */ \
193{ \
194 (step).e_enm = (ac)->ac_multiaddrs; \
195 ETHER_NEXT_MULTI((step), (enm)); \
196}
1acdf733 197
d6fa15c2 198#endif