1144c6bcdSlogwang /*- 2*d4a07e70Sfengbojiang * SPDX-License-Identifier: BSD-3-Clause 3*d4a07e70Sfengbojiang * 4144c6bcdSlogwang * Copyright (c) 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_arp.h 8.1 (Berkeley) 6/10/93 32144c6bcdSlogwang * $FreeBSD$ 33144c6bcdSlogwang */ 34144c6bcdSlogwang 35144c6bcdSlogwang #ifndef _NET_IF_ARP_H_ 36144c6bcdSlogwang #define _NET_IF_ARP_H_ 37144c6bcdSlogwang 38144c6bcdSlogwang /* 39144c6bcdSlogwang * Address Resolution Protocol. 40144c6bcdSlogwang * 41144c6bcdSlogwang * See RFC 826 for protocol description. ARP packets are variable 42144c6bcdSlogwang * in size; the arphdr structure defines the fixed-length portion. 43144c6bcdSlogwang * Protocol type values are the same as those for 10 Mb/s Ethernet. 44144c6bcdSlogwang * It is followed by the variable-sized fields ar_sha, arp_spa, 45144c6bcdSlogwang * arp_tha and arp_tpa in that order, according to the lengths 46144c6bcdSlogwang * specified. Field names used correspond to RFC 826. 47144c6bcdSlogwang */ 48144c6bcdSlogwang struct arphdr { 49144c6bcdSlogwang u_short ar_hrd; /* format of hardware address */ 50144c6bcdSlogwang #define ARPHRD_ETHER 1 /* ethernet hardware format */ 51144c6bcdSlogwang #define ARPHRD_IEEE802 6 /* token-ring hardware format */ 52144c6bcdSlogwang #define ARPHRD_FRELAY 15 /* frame relay hardware format */ 53144c6bcdSlogwang #define ARPHRD_IEEE1394 24 /* firewire hardware format */ 54144c6bcdSlogwang #define ARPHRD_INFINIBAND 32 /* infiniband hardware format */ 55144c6bcdSlogwang u_short ar_pro; /* format of protocol address */ 56144c6bcdSlogwang u_char ar_hln; /* length of hardware address */ 57144c6bcdSlogwang u_char ar_pln; /* length of protocol address */ 58144c6bcdSlogwang u_short ar_op; /* one of: */ 59144c6bcdSlogwang #define ARPOP_REQUEST 1 /* request to resolve address */ 60144c6bcdSlogwang #define ARPOP_REPLY 2 /* response to previous request */ 61144c6bcdSlogwang #define ARPOP_REVREQUEST 3 /* request protocol address given hardware */ 62144c6bcdSlogwang #define ARPOP_REVREPLY 4 /* response giving protocol address */ 63144c6bcdSlogwang #define ARPOP_INVREQUEST 8 /* request to identify peer */ 64144c6bcdSlogwang #define ARPOP_INVREPLY 9 /* response identifying peer */ 65144c6bcdSlogwang /* 66144c6bcdSlogwang * The remaining fields are variable in size, 67144c6bcdSlogwang * according to the sizes above. 68144c6bcdSlogwang */ 69144c6bcdSlogwang #ifdef COMMENT_ONLY 70144c6bcdSlogwang u_char ar_sha[]; /* sender hardware address */ 71144c6bcdSlogwang u_char ar_spa[]; /* sender protocol address */ 72144c6bcdSlogwang u_char ar_tha[]; /* target hardware address */ 73144c6bcdSlogwang u_char ar_tpa[]; /* target protocol address */ 74144c6bcdSlogwang #endif 75144c6bcdSlogwang }; 76144c6bcdSlogwang 77144c6bcdSlogwang #define ar_sha(ap) (((caddr_t)((ap)+1)) + 0) 78144c6bcdSlogwang #define ar_spa(ap) (((caddr_t)((ap)+1)) + (ap)->ar_hln) 79144c6bcdSlogwang #define ar_tha(ap) (((caddr_t)((ap)+1)) + (ap)->ar_hln + (ap)->ar_pln) 80144c6bcdSlogwang #define ar_tpa(ap) (((caddr_t)((ap)+1)) + 2*(ap)->ar_hln + (ap)->ar_pln) 81144c6bcdSlogwang 82144c6bcdSlogwang #define arphdr_len2(ar_hln, ar_pln) \ 83144c6bcdSlogwang (sizeof(struct arphdr) + 2*(ar_hln) + 2*(ar_pln)) 84144c6bcdSlogwang #define arphdr_len(ap) (arphdr_len2((ap)->ar_hln, (ap)->ar_pln)) 85144c6bcdSlogwang 86144c6bcdSlogwang /* 87144c6bcdSlogwang * ARP ioctl request 88144c6bcdSlogwang */ 89144c6bcdSlogwang struct arpreq { 90144c6bcdSlogwang struct sockaddr arp_pa; /* protocol address */ 91144c6bcdSlogwang struct sockaddr arp_ha; /* hardware address */ 92144c6bcdSlogwang int arp_flags; /* flags */ 93144c6bcdSlogwang }; 94144c6bcdSlogwang /* arp_flags and at_flags field values */ 95144c6bcdSlogwang #define ATF_INUSE 0x01 /* entry in use */ 96144c6bcdSlogwang #define ATF_COM 0x02 /* completed entry (enaddr valid) */ 97144c6bcdSlogwang #define ATF_PERM 0x04 /* permanent entry */ 98144c6bcdSlogwang #define ATF_PUBL 0x08 /* publish entry (respond for other host) */ 99144c6bcdSlogwang #define ATF_USETRAILERS 0x10 /* has requested trailers */ 100144c6bcdSlogwang 101144c6bcdSlogwang struct arpstat { 102144c6bcdSlogwang /* Normal things that happen: */ 103144c6bcdSlogwang uint64_t txrequests; /* # of ARP requests sent by this host. */ 104144c6bcdSlogwang uint64_t txreplies; /* # of ARP replies sent by this host. */ 105144c6bcdSlogwang uint64_t rxrequests; /* # of ARP requests received by this host. */ 106144c6bcdSlogwang uint64_t rxreplies; /* # of ARP replies received by this host. */ 107144c6bcdSlogwang uint64_t received; /* # of ARP packets received by this host. */ 108*d4a07e70Sfengbojiang uint64_t txerrors; /* # of ARP requests failed to send. */ 109144c6bcdSlogwang 110*d4a07e70Sfengbojiang uint64_t arp_spares[3]; /* For either the upper or lower half. */ 111144c6bcdSlogwang /* Abnormal event and error counting: */ 112144c6bcdSlogwang uint64_t dropped; /* # of packets dropped waiting for a reply. */ 113144c6bcdSlogwang uint64_t timeouts; /* # of times with entries removed */ 114144c6bcdSlogwang /* due to timeout. */ 115144c6bcdSlogwang uint64_t dupips; /* # of duplicate IPs detected. */ 116144c6bcdSlogwang }; 117144c6bcdSlogwang 118*d4a07e70Sfengbojiang #ifdef _KERNEL 119*d4a07e70Sfengbojiang #include <sys/counter.h> 120*d4a07e70Sfengbojiang #include <net/vnet.h> 121*d4a07e70Sfengbojiang 122*d4a07e70Sfengbojiang VNET_PCPUSTAT_DECLARE(struct arpstat, arpstat); 123*d4a07e70Sfengbojiang /* 124*d4a07e70Sfengbojiang * In-kernel consumers can use these accessor macros directly to update 125*d4a07e70Sfengbojiang * stats. 126*d4a07e70Sfengbojiang */ 127*d4a07e70Sfengbojiang #define ARPSTAT_ADD(name, val) \ 128*d4a07e70Sfengbojiang VNET_PCPUSTAT_ADD(struct arpstat, arpstat, name, (val)) 129*d4a07e70Sfengbojiang #define ARPSTAT_SUB(name, val) ARPSTAT_ADD(name, -(val)) 130*d4a07e70Sfengbojiang #define ARPSTAT_INC(name) ARPSTAT_ADD(name, 1) 131*d4a07e70Sfengbojiang #define ARPSTAT_DEC(name) ARPSTAT_SUB(name, 1) 132*d4a07e70Sfengbojiang 133*d4a07e70Sfengbojiang #endif /* _KERNEL */ 134*d4a07e70Sfengbojiang 135144c6bcdSlogwang #endif /* !_NET_IF_ARP_H_ */ 136