xref: /freebsd/sys/netinet/if_ether.h (revision 47e8d432d5db395e2812c03093b70227e48a1c6d)
1c398230bSWarner Losh /*-
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  * 4. Neither the name of the University nor the names of its contributors
14df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
15df8bae1dSRodney W. Grimes  *    without specific prior written permission.
16df8bae1dSRodney W. Grimes  *
17df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
28df8bae1dSRodney W. Grimes  *
29ef91e528SGarrett Wollman  *	@(#)if_ether.h	8.3 (Berkeley) 5/2/95
30c3aac50fSPeter Wemm  * $FreeBSD$
31df8bae1dSRodney W. Grimes  */
32df8bae1dSRodney W. Grimes 
33707f139eSPaul Richards #ifndef _NETINET_IF_ETHER_H_
34707f139eSPaul Richards #define _NETINET_IF_ETHER_H_
35707f139eSPaul Richards 
3626a8b0bfSPoul-Henning Kamp #include <net/ethernet.h>
374963f4cdSGarrett Wollman #include <net/if_arp.h>
385f6d32c7SBill Paul 
39df8bae1dSRodney W. Grimes /*
40df8bae1dSRodney W. Grimes  * Macro to map an IP multicast address to an Ethernet multicast address.
41df8bae1dSRodney W. Grimes  * The high-order 25 bits of the Ethernet address are statically assigned,
42df8bae1dSRodney W. Grimes  * and the low-order 23 bits are taken from the low end of the IP address.
43df8bae1dSRodney W. Grimes  */
44df8bae1dSRodney W. Grimes #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \
45df8bae1dSRodney W. Grimes 	/* struct in_addr *ipaddr; */ \
4626a8b0bfSPoul-Henning Kamp 	/* u_char enaddr[ETHER_ADDR_LEN];	   */ \
47df8bae1dSRodney W. Grimes { \
48df8bae1dSRodney W. Grimes 	(enaddr)[0] = 0x01; \
49df8bae1dSRodney W. Grimes 	(enaddr)[1] = 0x00; \
50df8bae1dSRodney W. Grimes 	(enaddr)[2] = 0x5e; \
51*47e8d432SGleb Smirnoff 	(enaddr)[3] = ((const u_char *)ipaddr)[1] & 0x7f; \
52*47e8d432SGleb Smirnoff 	(enaddr)[4] = ((const u_char *)ipaddr)[2]; \
53*47e8d432SGleb Smirnoff 	(enaddr)[5] = ((const u_char *)ipaddr)[3]; \
54df8bae1dSRodney W. Grimes }
5576429de4SYoshinobu Inoue /*
5676429de4SYoshinobu Inoue  * Macro to map an IP6 multicast address to an Ethernet multicast address.
5776429de4SYoshinobu Inoue  * The high-order 16 bits of the Ethernet address are statically assigned,
5876429de4SYoshinobu Inoue  * and the low-order 32 bits are taken from the low end of the IP6 address.
5976429de4SYoshinobu Inoue  */
6076429de4SYoshinobu Inoue #define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr)			\
6176429de4SYoshinobu Inoue /* struct	in6_addr *ip6addr; */					\
6276429de4SYoshinobu Inoue /* u_char	enaddr[ETHER_ADDR_LEN]; */				\
6376429de4SYoshinobu Inoue {                                                                       \
6476429de4SYoshinobu Inoue 	(enaddr)[0] = 0x33;						\
6576429de4SYoshinobu Inoue 	(enaddr)[1] = 0x33;						\
66*47e8d432SGleb Smirnoff 	(enaddr)[2] = ((const u_char *)ip6addr)[12];			\
67*47e8d432SGleb Smirnoff 	(enaddr)[3] = ((const u_char *)ip6addr)[13];			\
68*47e8d432SGleb Smirnoff 	(enaddr)[4] = ((const u_char *)ip6addr)[14];			\
69*47e8d432SGleb Smirnoff 	(enaddr)[5] = ((const u_char *)ip6addr)[15];			\
7076429de4SYoshinobu Inoue }
71df8bae1dSRodney W. Grimes 
72df8bae1dSRodney W. Grimes /*
73df8bae1dSRodney W. Grimes  * Ethernet Address Resolution Protocol.
74df8bae1dSRodney W. Grimes  *
75df8bae1dSRodney W. Grimes  * See RFC 826 for protocol description.  Structure below is adapted
76df8bae1dSRodney W. Grimes  * to resolving internet addresses.  Field names used correspond to
77df8bae1dSRodney W. Grimes  * RFC 826.
78df8bae1dSRodney W. Grimes  */
79df8bae1dSRodney W. Grimes struct	ether_arp {
80df8bae1dSRodney W. Grimes 	struct	arphdr ea_hdr;	/* fixed-size header */
8126a8b0bfSPoul-Henning Kamp 	u_char	arp_sha[ETHER_ADDR_LEN];	/* sender hardware address */
82df8bae1dSRodney W. Grimes 	u_char	arp_spa[4];	/* sender protocol address */
8326a8b0bfSPoul-Henning Kamp 	u_char	arp_tha[ETHER_ADDR_LEN];	/* target hardware address */
84df8bae1dSRodney W. Grimes 	u_char	arp_tpa[4];	/* target protocol address */
85df8bae1dSRodney W. Grimes };
86df8bae1dSRodney W. Grimes #define	arp_hrd	ea_hdr.ar_hrd
87df8bae1dSRodney W. Grimes #define	arp_pro	ea_hdr.ar_pro
88df8bae1dSRodney W. Grimes #define	arp_hln	ea_hdr.ar_hln
89df8bae1dSRodney W. Grimes #define	arp_pln	ea_hdr.ar_pln
90df8bae1dSRodney W. Grimes #define	arp_op	ea_hdr.ar_op
91df8bae1dSRodney W. Grimes 
929711a168SGleb Smirnoff #ifndef BURN_BRIDGES	/* Can be used by third party software. */
93df8bae1dSRodney W. Grimes struct sockaddr_inarp {
94df8bae1dSRodney W. Grimes 	u_char	sin_len;
95df8bae1dSRodney W. Grimes 	u_char	sin_family;
96df8bae1dSRodney W. Grimes 	u_short sin_port;
97df8bae1dSRodney W. Grimes 	struct	in_addr sin_addr;
98df8bae1dSRodney W. Grimes 	struct	in_addr sin_srcaddr;
99df8bae1dSRodney W. Grimes 	u_short	sin_tos;
100df8bae1dSRodney W. Grimes 	u_short	sin_other;
101df8bae1dSRodney W. Grimes #define SIN_PROXY 1
102df8bae1dSRodney W. Grimes };
1039711a168SGleb Smirnoff #endif /* !BURN_BRIDGES  */
1049711a168SGleb Smirnoff 
105df8bae1dSRodney W. Grimes /*
106df8bae1dSRodney W. Grimes  * IP and ethernet specific routing flags
107df8bae1dSRodney W. Grimes  */
108df8bae1dSRodney W. Grimes #define	RTF_USETRAILERS	RTF_PROTO1	/* use trailers */
109df8bae1dSRodney W. Grimes #define RTF_ANNOUNCE	RTF_PROTO2	/* announce new arp entry */
110df8bae1dSRodney W. Grimes 
111664a31e4SPeter Wemm #ifdef	_KERNEL
11226a8b0bfSPoul-Henning Kamp extern u_char	ether_ipmulticast_min[ETHER_ADDR_LEN];
11326a8b0bfSPoul-Henning Kamp extern u_char	ether_ipmulticast_max[ETHER_ADDR_LEN];
114df8bae1dSRodney W. Grimes 
1156e6b3f7cSQing Li struct llentry;
116281c8daeSLuigi Rizzo struct ifaddr;
1176e6b3f7cSQing Li 
118*47e8d432SGleb Smirnoff int	arpresolve(struct ifnet *ifp, struct rtentry *rt, struct mbuf *m,
119*47e8d432SGleb Smirnoff 	    const struct sockaddr *dst, u_char *desten, struct llentry **lle);
120*47e8d432SGleb Smirnoff void	arprequest(struct ifnet *, const struct in_addr *,
121*47e8d432SGleb Smirnoff 	    const struct in_addr *, u_char *);
1224d77a549SAlfred Perlstein void	arp_ifinit(struct ifnet *, struct ifaddr *);
123a9771948SGleb Smirnoff void	arp_ifinit2(struct ifnet *, struct ifaddr *, u_char *);
12408b68b0eSGleb Smirnoff void	arp_ifscrub(struct ifnet *, uint32_t);
125df8bae1dSRodney W. Grimes #endif
126707f139eSPaul Richards 
127707f139eSPaul Richards #endif
128