xref: /386bsd/usr/src/kernel/include/domain/if_ether.h (revision dc8b130e)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *	This product includes software developed by the University of
16  *	California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * $Id: $
34  *
35  * Ethernet Link Layer.
36  */
37 
38 /*
39  * Structure of a 10Mb/s Ethernet header.
40  */
41 struct	ether_header {
42 	u_char	ether_dhost[6];
43 	u_char	ether_shost[6];
44 	u_short	ether_type;
45 };
46 
47 #define	ETHERTYPE_PUP	0x0200		/* PUP protocol */
48 #define	ETHERTYPE_IP	0x0800		/* IP protocol */
49 #define ETHERTYPE_ARP	0x0806		/* Addr. resolution protocol */
50 
51 /*
52  * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have
53  * (type-ETHERTYPE_TRAIL)*512 bytes of data followed
54  * by an ETHER type (as given above) and then the (variable-length) header.
55  */
56 #define	ETHERTYPE_TRAIL		0x1000		/* Trailer packet */
57 #define	ETHERTYPE_NTRAILER	16
58 
59 #define	ETHERMTU	1500
60 #define	ETHERMIN	(60-14)
61 
62 /*
63  * Ethernet Address Resolution Protocol.
64  *
65  * See RFC 826 for protocol description.  Structure below is adapted
66  * to resolving internet addresses.  Field names used correspond to
67  * RFC 826.
68  */
69 struct	ether_arp {
70 	struct	arphdr ea_hdr;	/* fixed-size header */
71 	u_char	arp_sha[6];	/* sender hardware address */
72 	u_char	arp_spa[4];	/* sender protocol address */
73 	u_char	arp_tha[6];	/* target hardware address */
74 	u_char	arp_tpa[4];	/* target protocol address */
75 };
76 #define	arp_hrd	ea_hdr.ar_hrd
77 #define	arp_pro	ea_hdr.ar_pro
78 #define	arp_hln	ea_hdr.ar_hln
79 #define	arp_pln	ea_hdr.ar_pln
80 #define	arp_op	ea_hdr.ar_op
81 
82 
83 /*
84  * Structure shared between the ethernet driver modules and
85  * the address resolution code.  For example, each ec_softc or il_softc
86  * begins with this structure.
87  */
88 struct	arpcom {
89 	struct 	ifnet ac_if;		/* network-visible interface */
90 	u_char	ac_enaddr[6];		/* ethernet hardware address */
91 	struct in_addr ac_ipaddr;	/* copy of ip address- XXX */
92 };
93 
94 /*
95  * Internet to ethernet address resolution table.
96  */
97 struct	arptab {
98 	struct	in_addr at_iaddr;	/* internet address */
99 	u_char	at_enaddr[6];		/* ethernet address */
100 	u_char	at_timer;		/* minutes since last reference */
101 	u_char	at_flags;		/* flags */
102 	struct	mbuf *at_hold;		/* last packet until resolved/timeout */
103 };
104 
105 #ifdef	KERNEL
106 /*u_char	etherbroadcastaddr[6];
107 struct	arptab *arptnew();*/
108 struct	arptab *arptnew(struct in_addr *);
109 
110 /* interface symbols */
111 #define	__ISYM_VERSION__ "1"	/* XXX RCS major revision number of hdr file */
112 #include "isym.h"		/* this header has interface symbols */
113 
114 /* global variables used in core kernel and other modules */
115 __ISYM__(u_char, etherbroadcastaddr, [6])
116 
117 /* functions used in modules */
118 __ISYM__(void, ether_input, (struct ifnet *, struct ether_header *, struct mbuf *))
119 __ISYM__(int, ether_output, (struct ifnet *, struct mbuf *, struct sockaddr *, struct rtentry *))
120 __ISYM__(char *, ether_sprintf, (u_char *))
121 
122 #undef __ISYM__
123 #undef __ISYM_ALIAS__
124 #undef __ISYM_VERSION__
125 
126 #ifndef _ARP_PROTOTYPES
127 /* private arp functions, accessed via external symbol stub when loaded */
128 static void arpwhohas(struct arpcom *, struct in_addr *);
129 static void arpinput(struct arpcom *ac, struct mbuf *m);
130 static int arpresolve(struct arpcom *ac, struct mbuf *m, struct in_addr *destip,
131 	u_char *desten, int *usetrailers);
132 
133 /* inline external symbol table function stubs */
134 extern inline void
arpwhohas(struct arpcom * a,struct in_addr * i)135 arpwhohas(struct arpcom *a, struct in_addr *i) {
136 	void (*f)(struct arpcom *, struct in_addr *);
137 
138 	(const void *) f = esym_fetch(arpwhohas);
139 	if (f == 0)
140 		return;
141 	(*f)(a, i);
142 }
143 extern inline void
arpinput(struct arpcom * a,struct mbuf * m)144 arpinput(struct arpcom *a, struct mbuf *m) {
145 	void (*f)(struct arpcom *, struct mbuf *);
146 
147 	(const void *) f = esym_fetch(arpinput);
148 	if (f == 0)
149 		return;
150 	(*f)(a, m);
151 }
152 extern inline int
arpresolve(struct arpcom * a,struct mbuf * m,struct in_addr * d,u_char * c,int * u)153 arpresolve(struct arpcom *a, struct mbuf *m, struct in_addr *d, u_char *c, int *u) {
154 	int (*f)(struct arpcom *, struct mbuf *, struct in_addr *, u_char *, int *);
155 
156 	(const void *) f = esym_fetch(arpresolve);
157 	if (f == 0)
158 		return (0);
159 	return ((*f)(a, m, d, c, u));
160 }
161 #else
162 extern void arpwhohas(struct arpcom *, struct in_addr *);
163 extern void arpinput(struct arpcom *ac, struct mbuf *m);
164 extern int arpresolve(struct arpcom *ac, struct mbuf *m, struct in_addr *destip,
165 	u_char *desten, int *usetrailers);
166 #endif /* _ARP_PROTOTYPES */
167 #endif
168