xref: /freebsd/sys/net/if_arp.h (revision fbbd9655e5107c68e4e0146ff22b73d7350475bc)
1c398230bSWarner Losh /*-
2df8bae1dSRodney W. Grimes  * Copyright (c) 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.
13*fbbd9655SWarner Losh  * 3. 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  *
29df8bae1dSRodney W. Grimes  *	@(#)if_arp.h	8.1 (Berkeley) 6/10/93
30c3aac50fSPeter Wemm  * $FreeBSD$
31df8bae1dSRodney W. Grimes  */
32df8bae1dSRodney W. Grimes 
33cea1da3bSPaul Richards #ifndef _NET_IF_ARP_H_
34cea1da3bSPaul Richards #define	_NET_IF_ARP_H_
35cea1da3bSPaul Richards 
36df8bae1dSRodney W. Grimes /*
37df8bae1dSRodney W. Grimes  * Address Resolution Protocol.
38df8bae1dSRodney W. Grimes  *
39df8bae1dSRodney W. Grimes  * See RFC 826 for protocol description.  ARP packets are variable
40df8bae1dSRodney W. Grimes  * in size; the arphdr structure defines the fixed-length portion.
41df8bae1dSRodney W. Grimes  * Protocol type values are the same as those for 10 Mb/s Ethernet.
42df8bae1dSRodney W. Grimes  * It is followed by the variable-sized fields ar_sha, arp_spa,
43df8bae1dSRodney W. Grimes  * arp_tha and arp_tpa in that order, according to the lengths
44df8bae1dSRodney W. Grimes  * specified.  Field names used correspond to RFC 826.
45df8bae1dSRodney W. Grimes  */
46df8bae1dSRodney W. Grimes struct	arphdr {
47df8bae1dSRodney W. Grimes 	u_short	ar_hrd;		/* format of hardware address */
48df8bae1dSRodney W. Grimes #define ARPHRD_ETHER 	1	/* ethernet hardware format */
49722012ccSJulian Elischer #define ARPHRD_IEEE802	6	/* token-ring hardware format */
50322dcb8dSMax Khon #define ARPHRD_ARCNET	7	/* arcnet hardware format */
51df8bae1dSRodney W. Grimes #define ARPHRD_FRELAY 	15	/* frame relay hardware format */
52b8b33234SDoug Rabson #define ARPHRD_IEEE1394	24	/* firewire hardware format */
53e4cd31ddSJeff Roberson #define ARPHRD_INFINIBAND 32	/* infiniband hardware format */
54df8bae1dSRodney W. Grimes 	u_short	ar_pro;		/* format of protocol address */
55df8bae1dSRodney W. Grimes 	u_char	ar_hln;		/* length of hardware address */
56df8bae1dSRodney W. Grimes 	u_char	ar_pln;		/* length of protocol address */
57df8bae1dSRodney W. Grimes 	u_short	ar_op;		/* one of: */
58df8bae1dSRodney W. Grimes #define	ARPOP_REQUEST	1	/* request to resolve address */
59df8bae1dSRodney W. Grimes #define	ARPOP_REPLY	2	/* response to previous request */
60df8bae1dSRodney W. Grimes #define	ARPOP_REVREQUEST 3	/* request protocol address given hardware */
61df8bae1dSRodney W. Grimes #define	ARPOP_REVREPLY	4	/* response giving protocol address */
62df8bae1dSRodney W. Grimes #define ARPOP_INVREQUEST 8 	/* request to identify peer */
63df8bae1dSRodney W. Grimes #define ARPOP_INVREPLY	9	/* response identifying peer */
64df8bae1dSRodney W. Grimes /*
65df8bae1dSRodney W. Grimes  * The remaining fields are variable in size,
66df8bae1dSRodney W. Grimes  * according to the sizes above.
67df8bae1dSRodney W. Grimes  */
68df8bae1dSRodney W. Grimes #ifdef COMMENT_ONLY
69df8bae1dSRodney W. Grimes 	u_char	ar_sha[];	/* sender hardware address */
70df8bae1dSRodney W. Grimes 	u_char	ar_spa[];	/* sender protocol address */
71df8bae1dSRodney W. Grimes 	u_char	ar_tha[];	/* target hardware address */
72df8bae1dSRodney W. Grimes 	u_char	ar_tpa[];	/* target protocol address */
73df8bae1dSRodney W. Grimes #endif
74df8bae1dSRodney W. Grimes };
75df8bae1dSRodney W. Grimes 
76322dcb8dSMax Khon #define ar_sha(ap)	(((caddr_t)((ap)+1)) +   0)
77322dcb8dSMax Khon #define ar_spa(ap)	(((caddr_t)((ap)+1)) +   (ap)->ar_hln)
78322dcb8dSMax Khon #define ar_tha(ap)	(((caddr_t)((ap)+1)) +   (ap)->ar_hln + (ap)->ar_pln)
79322dcb8dSMax Khon #define ar_tpa(ap)	(((caddr_t)((ap)+1)) + 2*(ap)->ar_hln + (ap)->ar_pln)
80322dcb8dSMax Khon 
81322dcb8dSMax Khon #define arphdr_len2(ar_hln, ar_pln)					\
82322dcb8dSMax Khon 	(sizeof(struct arphdr) + 2*(ar_hln) + 2*(ar_pln))
83322dcb8dSMax Khon #define arphdr_len(ap)	(arphdr_len2((ap)->ar_hln, (ap)->ar_pln))
84322dcb8dSMax Khon 
85df8bae1dSRodney W. Grimes /*
86df8bae1dSRodney W. Grimes  * ARP ioctl request
87df8bae1dSRodney W. Grimes  */
88df8bae1dSRodney W. Grimes struct arpreq {
89df8bae1dSRodney W. Grimes 	struct	sockaddr arp_pa;		/* protocol address */
90df8bae1dSRodney W. Grimes 	struct	sockaddr arp_ha;		/* hardware address */
91df8bae1dSRodney W. Grimes 	int	arp_flags;			/* flags */
92df8bae1dSRodney W. Grimes };
93df8bae1dSRodney W. Grimes /*  arp_flags and at_flags field values */
94df8bae1dSRodney W. Grimes #define	ATF_INUSE	0x01	/* entry in use */
95df8bae1dSRodney W. Grimes #define ATF_COM		0x02	/* completed entry (enaddr valid) */
96df8bae1dSRodney W. Grimes #define	ATF_PERM	0x04	/* permanent entry */
97df8bae1dSRodney W. Grimes #define	ATF_PUBL	0x08	/* publish entry (respond for other host) */
98df8bae1dSRodney W. Grimes #define	ATF_USETRAILERS	0x10	/* has requested trailers */
99cea1da3bSPaul Richards 
10054fc657dSGeorge V. Neville-Neil struct arpstat {
10154fc657dSGeorge V. Neville-Neil 	/* Normal things that happen: */
102c80211e3SAndrey V. Elsukov 	uint64_t txrequests;	/* # of ARP requests sent by this host. */
103c80211e3SAndrey V. Elsukov 	uint64_t txreplies;	/* # of ARP replies sent by this host. */
104c80211e3SAndrey V. Elsukov 	uint64_t rxrequests;	/* # of ARP requests received by this host. */
105c80211e3SAndrey V. Elsukov 	uint64_t rxreplies;	/* # of ARP replies received by this host. */
106c80211e3SAndrey V. Elsukov 	uint64_t received;	/* # of ARP packets received by this host. */
10754fc657dSGeorge V. Neville-Neil 
108c80211e3SAndrey V. Elsukov 	uint64_t arp_spares[4];	/* For either the upper or lower half. */
10954fc657dSGeorge V. Neville-Neil 	/* Abnormal event and error  counting: */
110c80211e3SAndrey V. Elsukov 	uint64_t dropped;	/* # of packets dropped waiting for a reply. */
111c80211e3SAndrey V. Elsukov 	uint64_t timeouts;	/* # of times with entries removed */
11254fc657dSGeorge V. Neville-Neil 				/* due to timeout. */
113c80211e3SAndrey V. Elsukov 	uint64_t dupips;	/* # of duplicate IPs detected. */
11454fc657dSGeorge V. Neville-Neil };
11554fc657dSGeorge V. Neville-Neil 
1165b7cb97cSAndrey V. Elsukov #ifdef _KERNEL
1175b7cb97cSAndrey V. Elsukov #include <sys/counter.h>
1185b7cb97cSAndrey V. Elsukov #include <net/vnet.h>
1195b7cb97cSAndrey V. Elsukov 
1205b7cb97cSAndrey V. Elsukov VNET_PCPUSTAT_DECLARE(struct arpstat, arpstat);
12154fc657dSGeorge V. Neville-Neil /*
12254fc657dSGeorge V. Neville-Neil  * In-kernel consumers can use these accessor macros directly to update
12354fc657dSGeorge V. Neville-Neil  * stats.
12454fc657dSGeorge V. Neville-Neil  */
1255b7cb97cSAndrey V. Elsukov #define	ARPSTAT_ADD(name, val)	\
1265b7cb97cSAndrey V. Elsukov     VNET_PCPUSTAT_ADD(struct arpstat, arpstat, name, (val))
1275b7cb97cSAndrey V. Elsukov #define	ARPSTAT_SUB(name, val)	ARPSTAT_ADD(name, -(val))
12854fc657dSGeorge V. Neville-Neil #define	ARPSTAT_INC(name)	ARPSTAT_ADD(name, 1)
12954fc657dSGeorge V. Neville-Neil #define	ARPSTAT_DEC(name)	ARPSTAT_SUB(name, 1)
1301d5e9e22SEivind Eklund 
1315b7cb97cSAndrey V. Elsukov #endif /* _KERNEL */
1325b7cb97cSAndrey V. Elsukov 
133df708ff1SBruce Evans #endif /* !_NET_IF_ARP_H_ */
134