xref: /freebsd/sys/net/if_arp.h (revision fcdf9a19893b9b5beb7a21407de507f0ae4c500b)
1c398230bSWarner Losh /*-
251369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni  *
4df8bae1dSRodney W. Grimes  * Copyright (c) 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 
32cea1da3bSPaul Richards #ifndef _NET_IF_ARP_H_
33cea1da3bSPaul Richards #define	_NET_IF_ARP_H_
34cea1da3bSPaul Richards 
35df8bae1dSRodney W. Grimes /*
36df8bae1dSRodney W. Grimes  * Address Resolution Protocol.
37df8bae1dSRodney W. Grimes  *
38df8bae1dSRodney W. Grimes  * See RFC 826 for protocol description.  ARP packets are variable
39df8bae1dSRodney W. Grimes  * in size; the arphdr structure defines the fixed-length portion.
40df8bae1dSRodney W. Grimes  * Protocol type values are the same as those for 10 Mb/s Ethernet.
41df8bae1dSRodney W. Grimes  * It is followed by the variable-sized fields ar_sha, arp_spa,
42df8bae1dSRodney W. Grimes  * arp_tha and arp_tpa in that order, according to the lengths
43df8bae1dSRodney W. Grimes  * specified.  Field names used correspond to RFC 826.
44df8bae1dSRodney W. Grimes  */
45df8bae1dSRodney W. Grimes struct	arphdr {
46df8bae1dSRodney W. Grimes 	u_short	ar_hrd;		/* format of hardware address */
47df8bae1dSRodney W. Grimes #define ARPHRD_ETHER 	1	/* ethernet hardware format */
48*fcdf9a19SDenny Page #define ARPHRD_IEEE802	6	/* 802.2 networks (ethernet/tb/tr) */
49df8bae1dSRodney W. Grimes #define ARPHRD_FRELAY 	15	/* frame relay hardware format */
50b8b33234SDoug Rabson #define ARPHRD_IEEE1394	24	/* firewire hardware format */
51e4cd31ddSJeff Roberson #define ARPHRD_INFINIBAND 32	/* infiniband hardware format */
52df8bae1dSRodney W. Grimes 	u_short	ar_pro;		/* format of protocol address */
53df8bae1dSRodney W. Grimes 	u_char	ar_hln;		/* length of hardware address */
54df8bae1dSRodney W. Grimes 	u_char	ar_pln;		/* length of protocol address */
55df8bae1dSRodney W. Grimes 	u_short	ar_op;		/* one of: */
56df8bae1dSRodney W. Grimes #define	ARPOP_REQUEST	1	/* request to resolve address */
57df8bae1dSRodney W. Grimes #define	ARPOP_REPLY	2	/* response to previous request */
58df8bae1dSRodney W. Grimes #define	ARPOP_REVREQUEST 3	/* request protocol address given hardware */
59df8bae1dSRodney W. Grimes #define	ARPOP_REVREPLY	4	/* response giving protocol address */
60df8bae1dSRodney W. Grimes #define ARPOP_INVREQUEST 8 	/* request to identify peer */
61df8bae1dSRodney W. Grimes #define ARPOP_INVREPLY	9	/* response identifying peer */
62df8bae1dSRodney W. Grimes /*
63df8bae1dSRodney W. Grimes  * The remaining fields are variable in size,
64df8bae1dSRodney W. Grimes  * according to the sizes above.
65df8bae1dSRodney W. Grimes  */
66df8bae1dSRodney W. Grimes #ifdef COMMENT_ONLY
67df8bae1dSRodney W. Grimes 	u_char	ar_sha[];	/* sender hardware address */
68df8bae1dSRodney W. Grimes 	u_char	ar_spa[];	/* sender protocol address */
69df8bae1dSRodney W. Grimes 	u_char	ar_tha[];	/* target hardware address */
70df8bae1dSRodney W. Grimes 	u_char	ar_tpa[];	/* target protocol address */
71df8bae1dSRodney W. Grimes #endif
72df8bae1dSRodney W. Grimes };
73df8bae1dSRodney W. Grimes 
74322dcb8dSMax Khon #define ar_sha(ap)	(((caddr_t)((ap)+1)) +   0)
75322dcb8dSMax Khon #define ar_spa(ap)	(((caddr_t)((ap)+1)) +   (ap)->ar_hln)
76322dcb8dSMax Khon #define ar_tha(ap)	(((caddr_t)((ap)+1)) +   (ap)->ar_hln + (ap)->ar_pln)
77322dcb8dSMax Khon #define ar_tpa(ap)	(((caddr_t)((ap)+1)) + 2*(ap)->ar_hln + (ap)->ar_pln)
78322dcb8dSMax Khon 
79322dcb8dSMax Khon #define arphdr_len2(ar_hln, ar_pln)					\
80322dcb8dSMax Khon 	(sizeof(struct arphdr) + 2*(ar_hln) + 2*(ar_pln))
81322dcb8dSMax Khon #define arphdr_len(ap)	(arphdr_len2((ap)->ar_hln, (ap)->ar_pln))
82322dcb8dSMax Khon 
83df8bae1dSRodney W. Grimes /*
84df8bae1dSRodney W. Grimes  * ARP ioctl request
85df8bae1dSRodney W. Grimes  */
86df8bae1dSRodney W. Grimes struct arpreq {
87df8bae1dSRodney W. Grimes 	struct	sockaddr arp_pa;		/* protocol address */
88df8bae1dSRodney W. Grimes 	struct	sockaddr arp_ha;		/* hardware address */
89df8bae1dSRodney W. Grimes 	int	arp_flags;			/* flags */
90df8bae1dSRodney W. Grimes };
91df8bae1dSRodney W. Grimes /*  arp_flags and at_flags field values */
92df8bae1dSRodney W. Grimes #define	ATF_INUSE	0x01	/* entry in use */
93df8bae1dSRodney W. Grimes #define ATF_COM		0x02	/* completed entry (enaddr valid) */
94df8bae1dSRodney W. Grimes #define	ATF_PERM	0x04	/* permanent entry */
95df8bae1dSRodney W. Grimes #define	ATF_PUBL	0x08	/* publish entry (respond for other host) */
96df8bae1dSRodney W. Grimes #define	ATF_USETRAILERS	0x10	/* has requested trailers */
97cea1da3bSPaul Richards 
9854fc657dSGeorge V. Neville-Neil struct arpstat {
9954fc657dSGeorge V. Neville-Neil 	/* Normal things that happen: */
100c80211e3SAndrey V. Elsukov 	uint64_t txrequests;	/* # of ARP requests sent by this host. */
101c80211e3SAndrey V. Elsukov 	uint64_t txreplies;	/* # of ARP replies sent by this host. */
102c80211e3SAndrey V. Elsukov 	uint64_t rxrequests;	/* # of ARP requests received by this host. */
103c80211e3SAndrey V. Elsukov 	uint64_t rxreplies;	/* # of ARP replies received by this host. */
104c80211e3SAndrey V. Elsukov 	uint64_t received;	/* # of ARP packets received by this host. */
105b25d74e0SBjoern A. Zeeb 	uint64_t txerrors;	/* # of ARP requests failed to send. */
10654fc657dSGeorge V. Neville-Neil 
107b25d74e0SBjoern A. Zeeb 	uint64_t arp_spares[3];	/* For either the upper or lower half. */
10854fc657dSGeorge V. Neville-Neil 	/* Abnormal event and error  counting: */
109c80211e3SAndrey V. Elsukov 	uint64_t dropped;	/* # of packets dropped waiting for a reply. */
110c80211e3SAndrey V. Elsukov 	uint64_t timeouts;	/* # of times with entries removed */
11154fc657dSGeorge V. Neville-Neil 				/* due to timeout. */
112c80211e3SAndrey V. Elsukov 	uint64_t dupips;	/* # of duplicate IPs detected. */
11354fc657dSGeorge V. Neville-Neil };
11454fc657dSGeorge V. Neville-Neil 
1155b7cb97cSAndrey V. Elsukov #ifdef _KERNEL
1165b7cb97cSAndrey V. Elsukov #include <sys/counter.h>
1175b7cb97cSAndrey V. Elsukov #include <net/vnet.h>
1185b7cb97cSAndrey V. Elsukov 
1195b7cb97cSAndrey V. Elsukov VNET_PCPUSTAT_DECLARE(struct arpstat, arpstat);
12054fc657dSGeorge V. Neville-Neil /*
12154fc657dSGeorge V. Neville-Neil  * In-kernel consumers can use these accessor macros directly to update
12254fc657dSGeorge V. Neville-Neil  * stats.
12354fc657dSGeorge V. Neville-Neil  */
1245b7cb97cSAndrey V. Elsukov #define	ARPSTAT_ADD(name, val)	\
1255b7cb97cSAndrey V. Elsukov     VNET_PCPUSTAT_ADD(struct arpstat, arpstat, name, (val))
1265b7cb97cSAndrey V. Elsukov #define	ARPSTAT_SUB(name, val)	ARPSTAT_ADD(name, -(val))
12754fc657dSGeorge V. Neville-Neil #define	ARPSTAT_INC(name)	ARPSTAT_ADD(name, 1)
12854fc657dSGeorge V. Neville-Neil #define	ARPSTAT_DEC(name)	ARPSTAT_SUB(name, 1)
1291d5e9e22SEivind Eklund 
1305b7cb97cSAndrey V. Elsukov #endif /* _KERNEL */
1315b7cb97cSAndrey V. Elsukov 
132df708ff1SBruce Evans #endif /* !_NET_IF_ARP_H_ */
133