1144c6bcdSlogwang /*- 2*d4a07e70Sfengbojiang * SPDX-License-Identifier: BSD-3-Clause 3*d4a07e70Sfengbojiang * 4144c6bcdSlogwang * Copyright (c) 1982, 1986, 1993 5144c6bcdSlogwang * The Regents of the University of California. All rights reserved. 6144c6bcdSlogwang * 7144c6bcdSlogwang * Redistribution and use in source and binary forms, with or without 8144c6bcdSlogwang * modification, are permitted provided that the following conditions 9144c6bcdSlogwang * are met: 10144c6bcdSlogwang * 1. Redistributions of source code must retain the above copyright 11144c6bcdSlogwang * notice, this list of conditions and the following disclaimer. 12144c6bcdSlogwang * 2. Redistributions in binary form must reproduce the above copyright 13144c6bcdSlogwang * notice, this list of conditions and the following disclaimer in the 14144c6bcdSlogwang * documentation and/or other materials provided with the distribution. 15*d4a07e70Sfengbojiang * 3. Neither the name of the University nor the names of its contributors 16144c6bcdSlogwang * may be used to endorse or promote products derived from this software 17144c6bcdSlogwang * without specific prior written permission. 18144c6bcdSlogwang * 19144c6bcdSlogwang * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20144c6bcdSlogwang * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21144c6bcdSlogwang * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22144c6bcdSlogwang * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23144c6bcdSlogwang * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24144c6bcdSlogwang * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25144c6bcdSlogwang * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26144c6bcdSlogwang * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27144c6bcdSlogwang * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28144c6bcdSlogwang * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29144c6bcdSlogwang * SUCH DAMAGE. 30144c6bcdSlogwang * 31144c6bcdSlogwang * @(#)if_ether.h 8.3 (Berkeley) 5/2/95 32144c6bcdSlogwang * $FreeBSD$ 33144c6bcdSlogwang */ 34144c6bcdSlogwang 35144c6bcdSlogwang #ifndef _NETINET_IF_ETHER_H_ 36144c6bcdSlogwang #define _NETINET_IF_ETHER_H_ 37144c6bcdSlogwang 38144c6bcdSlogwang #include <net/ethernet.h> 39144c6bcdSlogwang #include <net/if_arp.h> 40144c6bcdSlogwang 41144c6bcdSlogwang /* 42144c6bcdSlogwang * Macro to map an IP multicast address to an Ethernet multicast address. 43144c6bcdSlogwang * The high-order 25 bits of the Ethernet address are statically assigned, 44144c6bcdSlogwang * and the low-order 23 bits are taken from the low end of the IP address. 45144c6bcdSlogwang */ 46144c6bcdSlogwang #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \ 47144c6bcdSlogwang /* struct in_addr *ipaddr; */ \ 48144c6bcdSlogwang /* u_char enaddr[ETHER_ADDR_LEN]; */ \ 49144c6bcdSlogwang { \ 50144c6bcdSlogwang (enaddr)[0] = 0x01; \ 51144c6bcdSlogwang (enaddr)[1] = 0x00; \ 52144c6bcdSlogwang (enaddr)[2] = 0x5e; \ 53144c6bcdSlogwang (enaddr)[3] = ((const u_char *)ipaddr)[1] & 0x7f; \ 54144c6bcdSlogwang (enaddr)[4] = ((const u_char *)ipaddr)[2]; \ 55144c6bcdSlogwang (enaddr)[5] = ((const u_char *)ipaddr)[3]; \ 56144c6bcdSlogwang } 57144c6bcdSlogwang /* 58144c6bcdSlogwang * Macro to map an IP6 multicast address to an Ethernet multicast address. 59144c6bcdSlogwang * The high-order 16 bits of the Ethernet address are statically assigned, 60144c6bcdSlogwang * and the low-order 32 bits are taken from the low end of the IP6 address. 61144c6bcdSlogwang */ 62144c6bcdSlogwang #define ETHER_MAP_IPV6_MULTICAST(ip6addr, enaddr) \ 63144c6bcdSlogwang /* struct in6_addr *ip6addr; */ \ 64144c6bcdSlogwang /* u_char enaddr[ETHER_ADDR_LEN]; */ \ 65144c6bcdSlogwang { \ 66144c6bcdSlogwang (enaddr)[0] = 0x33; \ 67144c6bcdSlogwang (enaddr)[1] = 0x33; \ 68144c6bcdSlogwang (enaddr)[2] = ((const u_char *)ip6addr)[12]; \ 69144c6bcdSlogwang (enaddr)[3] = ((const u_char *)ip6addr)[13]; \ 70144c6bcdSlogwang (enaddr)[4] = ((const u_char *)ip6addr)[14]; \ 71144c6bcdSlogwang (enaddr)[5] = ((const u_char *)ip6addr)[15]; \ 72144c6bcdSlogwang } 73144c6bcdSlogwang 74144c6bcdSlogwang /* 75144c6bcdSlogwang * Ethernet Address Resolution Protocol. 76144c6bcdSlogwang * 77144c6bcdSlogwang * See RFC 826 for protocol description. Structure below is adapted 78144c6bcdSlogwang * to resolving internet addresses. Field names used correspond to 79144c6bcdSlogwang * RFC 826. 80144c6bcdSlogwang */ 81144c6bcdSlogwang struct ether_arp { 82144c6bcdSlogwang struct arphdr ea_hdr; /* fixed-size header */ 83144c6bcdSlogwang u_char arp_sha[ETHER_ADDR_LEN]; /* sender hardware address */ 84144c6bcdSlogwang u_char arp_spa[4]; /* sender protocol address */ 85144c6bcdSlogwang u_char arp_tha[ETHER_ADDR_LEN]; /* target hardware address */ 86144c6bcdSlogwang u_char arp_tpa[4]; /* target protocol address */ 87144c6bcdSlogwang }; 88144c6bcdSlogwang #define arp_hrd ea_hdr.ar_hrd 89144c6bcdSlogwang #define arp_pro ea_hdr.ar_pro 90144c6bcdSlogwang #define arp_hln ea_hdr.ar_hln 91144c6bcdSlogwang #define arp_pln ea_hdr.ar_pln 92144c6bcdSlogwang #define arp_op ea_hdr.ar_op 93144c6bcdSlogwang 94144c6bcdSlogwang #ifndef BURN_BRIDGES /* Can be used by third party software. */ 95144c6bcdSlogwang struct sockaddr_inarp { 96144c6bcdSlogwang u_char sin_len; 97144c6bcdSlogwang u_char sin_family; 98144c6bcdSlogwang u_short sin_port; 99144c6bcdSlogwang struct in_addr sin_addr; 100144c6bcdSlogwang struct in_addr sin_srcaddr; 101144c6bcdSlogwang u_short sin_tos; 102144c6bcdSlogwang u_short sin_other; 103144c6bcdSlogwang #define SIN_PROXY 1 104144c6bcdSlogwang }; 105144c6bcdSlogwang #endif /* !BURN_BRIDGES */ 106144c6bcdSlogwang 107144c6bcdSlogwang /* 108144c6bcdSlogwang * IP and ethernet specific routing flags 109144c6bcdSlogwang */ 110144c6bcdSlogwang #define RTF_USETRAILERS RTF_PROTO1 /* use trailers */ 111144c6bcdSlogwang #define RTF_ANNOUNCE RTF_PROTO2 /* announce new arp entry */ 112144c6bcdSlogwang 113*d4a07e70Sfengbojiang #ifdef _KERNEL 114*d4a07e70Sfengbojiang extern u_char ether_ipmulticast_min[ETHER_ADDR_LEN]; 115*d4a07e70Sfengbojiang extern u_char ether_ipmulticast_max[ETHER_ADDR_LEN]; 116*d4a07e70Sfengbojiang 117*d4a07e70Sfengbojiang struct ifaddr; 118*d4a07e70Sfengbojiang struct llentry; 119*d4a07e70Sfengbojiang 120*d4a07e70Sfengbojiang int arpresolve(struct ifnet *ifp, int is_gw, struct mbuf *m, 121*d4a07e70Sfengbojiang const struct sockaddr *dst, u_char *desten, uint32_t *pflags, 122*d4a07e70Sfengbojiang struct llentry **plle); 123*d4a07e70Sfengbojiang void arprequest(struct ifnet *, const struct in_addr *, 124*d4a07e70Sfengbojiang const struct in_addr *, u_char *); 125*d4a07e70Sfengbojiang void arp_ifinit(struct ifnet *, struct ifaddr *); 126*d4a07e70Sfengbojiang void arp_announce_ifaddr(struct ifnet *, struct in_addr addr, u_char *); 127*d4a07e70Sfengbojiang #endif 128*d4a07e70Sfengbojiang 129144c6bcdSlogwang #endif 130