1c398230bSWarner Losh /*- 2*51369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 3*51369649SPedro F. Giffuni * 4df8bae1dSRodney W. Grimes * Copyright (c) 1982, 1986, 1993 5df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 6df8bae1dSRodney W. Grimes * 7df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 8df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 9df8bae1dSRodney W. Grimes * are met: 10df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 12df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 13df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 14df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 15fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 16df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 17df8bae1dSRodney W. Grimes * without specific prior written permission. 18df8bae1dSRodney W. Grimes * 19df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29df8bae1dSRodney W. Grimes * SUCH DAMAGE. 30df8bae1dSRodney W. Grimes */ 31df8bae1dSRodney W. Grimes 32707f139eSPaul Richards #ifndef _NETINET_IF_ETHER_H_ 33707f139eSPaul Richards #define _NETINET_IF_ETHER_H_ 34707f139eSPaul Richards 3526a8b0bfSPoul-Henning Kamp #include <net/ethernet.h> 364963f4cdSGarrett Wollman #include <net/if_arp.h> 375f6d32c7SBill Paul 38df8bae1dSRodney W. Grimes /* 39df8bae1dSRodney W. Grimes * Macro to map an IP multicast address to an Ethernet multicast address. 40df8bae1dSRodney W. Grimes * The high-order 25 bits of the Ethernet address are statically assigned, 41df8bae1dSRodney W. Grimes * and the low-order 23 bits are taken from the low end of the IP address. 42df8bae1dSRodney W. Grimes */ 43df8bae1dSRodney W. Grimes #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \ 44df8bae1dSRodney W. Grimes /* struct in_addr *ipaddr; */ \ 4526a8b0bfSPoul-Henning Kamp /* u_char enaddr[ETHER_ADDR_LEN]; */ \ 46df8bae1dSRodney W. Grimes { \ 47df8bae1dSRodney W. Grimes (enaddr)[0] = 0x01; \ 48df8bae1dSRodney W. Grimes (enaddr)[1] = 0x00; \ 49df8bae1dSRodney W. Grimes (enaddr)[2] = 0x5e; \ 5047e8d432SGleb Smirnoff (enaddr)[3] = ((const u_char *)ipaddr)[1] & 0x7f; \ 5147e8d432SGleb Smirnoff (enaddr)[4] = ((const u_char *)ipaddr)[2]; \ 5247e8d432SGleb Smirnoff (enaddr)[5] = ((const u_char *)ipaddr)[3]; \ 53df8bae1dSRodney W. Grimes } 5476429de4SYoshinobu Inoue /* 5576429de4SYoshinobu Inoue * Macro to map an IP6 multicast address to an Ethernet multicast address. 5676429de4SYoshinobu Inoue * The high-order 16 bits of the Ethernet address are statically assigned, 5776429de4SYoshinobu Inoue * and the low-order 32 bits are taken from the low end of the IP6 address. 5876429de4SYoshinobu Inoue */ 5976429de4SYoshinobu Inoue #define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr) \ 6076429de4SYoshinobu Inoue /* struct in6_addr *ip6addr; */ \ 6176429de4SYoshinobu Inoue /* u_char enaddr[ETHER_ADDR_LEN]; */ \ 6276429de4SYoshinobu Inoue { \ 6376429de4SYoshinobu Inoue (enaddr)[0] = 0x33; \ 6476429de4SYoshinobu Inoue (enaddr)[1] = 0x33; \ 6547e8d432SGleb Smirnoff (enaddr)[2] = ((const u_char *)ip6addr)[12]; \ 6647e8d432SGleb Smirnoff (enaddr)[3] = ((const u_char *)ip6addr)[13]; \ 6747e8d432SGleb Smirnoff (enaddr)[4] = ((const u_char *)ip6addr)[14]; \ 6847e8d432SGleb Smirnoff (enaddr)[5] = ((const u_char *)ip6addr)[15]; \ 6976429de4SYoshinobu Inoue } 70df8bae1dSRodney W. Grimes 71df8bae1dSRodney W. Grimes /* 72df8bae1dSRodney W. Grimes * Ethernet Address Resolution Protocol. 73df8bae1dSRodney W. Grimes * 74df8bae1dSRodney W. Grimes * See RFC 826 for protocol description. Structure below is adapted 75df8bae1dSRodney W. Grimes * to resolving internet addresses. Field names used correspond to 76df8bae1dSRodney W. Grimes * RFC 826. 77df8bae1dSRodney W. Grimes */ 78df8bae1dSRodney W. Grimes struct ether_arp { 79df8bae1dSRodney W. Grimes struct arphdr ea_hdr; /* fixed-size header */ 8026a8b0bfSPoul-Henning Kamp u_char arp_sha[ETHER_ADDR_LEN]; /* sender hardware address */ 81df8bae1dSRodney W. Grimes u_char arp_spa[4]; /* sender protocol address */ 8226a8b0bfSPoul-Henning Kamp u_char arp_tha[ETHER_ADDR_LEN]; /* target hardware address */ 83df8bae1dSRodney W. Grimes u_char arp_tpa[4]; /* target protocol address */ 84df8bae1dSRodney W. Grimes }; 85df8bae1dSRodney W. Grimes #define arp_hrd ea_hdr.ar_hrd 86df8bae1dSRodney W. Grimes #define arp_pro ea_hdr.ar_pro 87df8bae1dSRodney W. Grimes #define arp_hln ea_hdr.ar_hln 88df8bae1dSRodney W. Grimes #define arp_pln ea_hdr.ar_pln 89df8bae1dSRodney W. Grimes #define arp_op ea_hdr.ar_op 90df8bae1dSRodney W. Grimes 919711a168SGleb Smirnoff #ifndef BURN_BRIDGES /* Can be used by third party software. */ 92df8bae1dSRodney W. Grimes struct sockaddr_inarp { 93df8bae1dSRodney W. Grimes u_char sin_len; 94df8bae1dSRodney W. Grimes u_char sin_family; 95df8bae1dSRodney W. Grimes u_short sin_port; 96df8bae1dSRodney W. Grimes struct in_addr sin_addr; 97df8bae1dSRodney W. Grimes struct in_addr sin_srcaddr; 98df8bae1dSRodney W. Grimes u_short sin_tos; 99df8bae1dSRodney W. Grimes u_short sin_other; 100df8bae1dSRodney W. Grimes #define SIN_PROXY 1 101df8bae1dSRodney W. Grimes }; 1029711a168SGleb Smirnoff #endif /* !BURN_BRIDGES */ 1039711a168SGleb Smirnoff 104df8bae1dSRodney W. Grimes /* 105df8bae1dSRodney W. Grimes * IP and ethernet specific routing flags 106df8bae1dSRodney W. Grimes */ 107df8bae1dSRodney W. Grimes #define RTF_USETRAILERS RTF_PROTO1 /* use trailers */ 108df8bae1dSRodney W. Grimes #define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */ 109df8bae1dSRodney W. Grimes 110664a31e4SPeter Wemm #ifdef _KERNEL 11126a8b0bfSPoul-Henning Kamp extern u_char ether_ipmulticast_min[ETHER_ADDR_LEN]; 11226a8b0bfSPoul-Henning Kamp extern u_char ether_ipmulticast_max[ETHER_ADDR_LEN]; 113df8bae1dSRodney W. Grimes 114281c8daeSLuigi Rizzo struct ifaddr; 1156d768226SGeorge V. Neville-Neil struct llentry; 1166e6b3f7cSQing Li 11774860d4fSAlexander V. Chernikov int arpresolve(struct ifnet *ifp, int is_gw, struct mbuf *m, 1186d768226SGeorge V. Neville-Neil const struct sockaddr *dst, u_char *desten, uint32_t *pflags, 1196d768226SGeorge V. Neville-Neil struct llentry **plle); 12047e8d432SGleb Smirnoff void arprequest(struct ifnet *, const struct in_addr *, 12147e8d432SGleb Smirnoff const struct in_addr *, u_char *); 1224d77a549SAlfred Perlstein void arp_ifinit(struct ifnet *, struct ifaddr *); 123d6e82913SSteven Hartland void arp_announce_ifaddr(struct ifnet *, struct in_addr addr, u_char *); 124df8bae1dSRodney W. Grimes #endif 125707f139eSPaul Richards 126707f139eSPaul Richards #endif 127