xref: /freebsd/sys/netinet/if_ether.h (revision 76429de41a85f7f29554d53bc0a171c0e3913fcf)
1df8bae1dSRodney W. Grimes /*
2df8bae1dSRodney W. Grimes  * Copyright (c) 1982, 1986, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
6df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
7df8bae1dSRodney W. Grimes  * are met:
8df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
9df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
10df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
11df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
12df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
13df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
14df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
15df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
16df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
17df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
18df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
19df8bae1dSRodney W. Grimes  *    without specific prior written permission.
20df8bae1dSRodney W. Grimes  *
21df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
32df8bae1dSRodney W. Grimes  *
33ef91e528SGarrett Wollman  *	@(#)if_ether.h	8.3 (Berkeley) 5/2/95
34c3aac50fSPeter Wemm  * $FreeBSD$
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37707f139eSPaul Richards #ifndef _NETINET_IF_ETHER_H_
38707f139eSPaul Richards #define _NETINET_IF_ETHER_H_
39707f139eSPaul Richards 
4026a8b0bfSPoul-Henning Kamp #include <net/ethernet.h>
414963f4cdSGarrett Wollman #include <net/if_arp.h>
425f6d32c7SBill Paul 
43df8bae1dSRodney W. Grimes /*
44df8bae1dSRodney W. Grimes  * Macro to map an IP multicast address to an Ethernet multicast address.
45df8bae1dSRodney W. Grimes  * The high-order 25 bits of the Ethernet address are statically assigned,
46df8bae1dSRodney W. Grimes  * and the low-order 23 bits are taken from the low end of the IP address.
47df8bae1dSRodney W. Grimes  */
48df8bae1dSRodney W. Grimes #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
49df8bae1dSRodney W. Grimes 	/* struct in_addr *ipaddr; */ \
5026a8b0bfSPoul-Henning Kamp 	/* u_char enaddr[ETHER_ADDR_LEN];	   */ \
51df8bae1dSRodney W. Grimes { \
52df8bae1dSRodney W. Grimes 	(enaddr)[0] = 0x01; \
53df8bae1dSRodney W. Grimes 	(enaddr)[1] = 0x00; \
54df8bae1dSRodney W. Grimes 	(enaddr)[2] = 0x5e; \
55df8bae1dSRodney W. Grimes 	(enaddr)[3] = ((u_char *)ipaddr)[1] & 0x7f; \
56df8bae1dSRodney W. Grimes 	(enaddr)[4] = ((u_char *)ipaddr)[2]; \
57df8bae1dSRodney W. Grimes 	(enaddr)[5] = ((u_char *)ipaddr)[3]; \
58df8bae1dSRodney W. Grimes }
5976429de4SYoshinobu Inoue /*
6076429de4SYoshinobu Inoue  * Macro to map an IP6 multicast address to an Ethernet multicast address.
6176429de4SYoshinobu Inoue  * The high-order 16 bits of the Ethernet address are statically assigned,
6276429de4SYoshinobu Inoue  * and the low-order 32 bits are taken from the low end of the IP6 address.
6376429de4SYoshinobu Inoue  */
6476429de4SYoshinobu Inoue #define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr)			\
6576429de4SYoshinobu Inoue /* struct	in6_addr *ip6addr; */					\
6676429de4SYoshinobu Inoue /* u_char	enaddr[ETHER_ADDR_LEN]; */				\
6776429de4SYoshinobu Inoue {                                                                       \
6876429de4SYoshinobu Inoue 	(enaddr)[0] = 0x33;						\
6976429de4SYoshinobu Inoue 	(enaddr)[1] = 0x33;						\
7076429de4SYoshinobu Inoue 	(enaddr)[2] = ((u_char *)ip6addr)[12];				\
7176429de4SYoshinobu Inoue 	(enaddr)[3] = ((u_char *)ip6addr)[13];				\
7276429de4SYoshinobu Inoue 	(enaddr)[4] = ((u_char *)ip6addr)[14];				\
7376429de4SYoshinobu Inoue 	(enaddr)[5] = ((u_char *)ip6addr)[15];				\
7476429de4SYoshinobu Inoue }
75df8bae1dSRodney W. Grimes 
76df8bae1dSRodney W. Grimes /*
77df8bae1dSRodney W. Grimes  * Ethernet Address Resolution Protocol.
78df8bae1dSRodney W. Grimes  *
79df8bae1dSRodney W. Grimes  * See RFC 826 for protocol description.  Structure below is adapted
80df8bae1dSRodney W. Grimes  * to resolving internet addresses.  Field names used correspond to
81df8bae1dSRodney W. Grimes  * RFC 826.
82df8bae1dSRodney W. Grimes  */
83df8bae1dSRodney W. Grimes struct	ether_arp {
84df8bae1dSRodney W. Grimes 	struct	arphdr ea_hdr;	/* fixed-size header */
8526a8b0bfSPoul-Henning Kamp 	u_char	arp_sha[ETHER_ADDR_LEN];	/* sender hardware address */
86df8bae1dSRodney W. Grimes 	u_char	arp_spa[4];	/* sender protocol address */
8726a8b0bfSPoul-Henning Kamp 	u_char	arp_tha[ETHER_ADDR_LEN];	/* target hardware address */
88df8bae1dSRodney W. Grimes 	u_char	arp_tpa[4];	/* target protocol address */
89df8bae1dSRodney W. Grimes };
90df8bae1dSRodney W. Grimes #define	arp_hrd	ea_hdr.ar_hrd
91df8bae1dSRodney W. Grimes #define	arp_pro	ea_hdr.ar_pro
92df8bae1dSRodney W. Grimes #define	arp_hln	ea_hdr.ar_hln
93df8bae1dSRodney W. Grimes #define	arp_pln	ea_hdr.ar_pln
94df8bae1dSRodney W. Grimes #define	arp_op	ea_hdr.ar_op
95df8bae1dSRodney W. Grimes 
96df8bae1dSRodney W. Grimes struct sockaddr_inarp {
97df8bae1dSRodney W. Grimes 	u_char	sin_len;
98df8bae1dSRodney W. Grimes 	u_char	sin_family;
99df8bae1dSRodney W. Grimes 	u_short sin_port;
100df8bae1dSRodney W. Grimes 	struct	in_addr sin_addr;
101df8bae1dSRodney W. Grimes 	struct	in_addr sin_srcaddr;
102df8bae1dSRodney W. Grimes 	u_short	sin_tos;
103df8bae1dSRodney W. Grimes 	u_short	sin_other;
104df8bae1dSRodney W. Grimes #define SIN_PROXY 1
105df8bae1dSRodney W. Grimes };
106df8bae1dSRodney W. Grimes /*
107df8bae1dSRodney W. Grimes  * IP and ethernet specific routing flags
108df8bae1dSRodney W. Grimes  */
109df8bae1dSRodney W. Grimes #define	RTF_USETRAILERS	RTF_PROTO1	/* use trailers */
110df8bae1dSRodney W. Grimes #define RTF_ANNOUNCE	RTF_PROTO2	/* announce new arp entry */
111df8bae1dSRodney W. Grimes 
112df8bae1dSRodney W. Grimes #ifdef	KERNEL
11326a8b0bfSPoul-Henning Kamp extern u_char	ether_ipmulticast_min[ETHER_ADDR_LEN];
11426a8b0bfSPoul-Henning Kamp extern u_char	ether_ipmulticast_max[ETHER_ADDR_LEN];
115f23b4c91SGarrett Wollman extern struct	ifqueue arpintrq;
116df8bae1dSRodney W. Grimes 
1175df72964SGarrett Wollman int	arpresolve __P((struct arpcom *, struct rtentry *, struct mbuf *,
1185df72964SGarrett Wollman 			struct sockaddr *, u_char *, struct rtentry *));
119dd2e4102SGarrett Wollman void	arp_ifinit __P((struct arpcom *, struct ifaddr *));
120df8bae1dSRodney W. Grimes #endif
121707f139eSPaul Richards 
122707f139eSPaul Richards #endif
123