1139823Simp/*-
21541Srgrimes * Copyright (c) 1986, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 4. Neither the name of the University nor the names of its contributors
141541Srgrimes *    may be used to endorse or promote products derived from this software
151541Srgrimes *    without specific prior written permission.
161541Srgrimes *
171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271541Srgrimes * SUCH DAMAGE.
281541Srgrimes *
291541Srgrimes *	@(#)if_arp.h	8.1 (Berkeley) 6/10/93
3050477Speter * $FreeBSD$
311541Srgrimes */
321541Srgrimes
332168Spaul#ifndef _NET_IF_ARP_H_
344507Sbde#define	_NET_IF_ARP_H_
352168Spaul
361541Srgrimes/*
371541Srgrimes * Address Resolution Protocol.
381541Srgrimes *
391541Srgrimes * See RFC 826 for protocol description.  ARP packets are variable
401541Srgrimes * in size; the arphdr structure defines the fixed-length portion.
411541Srgrimes * Protocol type values are the same as those for 10 Mb/s Ethernet.
421541Srgrimes * It is followed by the variable-sized fields ar_sha, arp_spa,
431541Srgrimes * arp_tha and arp_tpa in that order, according to the lengths
441541Srgrimes * specified.  Field names used correspond to RFC 826.
451541Srgrimes */
461541Srgrimesstruct	arphdr {
471541Srgrimes	u_short	ar_hrd;		/* format of hardware address */
481541Srgrimes#define ARPHRD_ETHER 	1	/* ethernet hardware format */
4944165Sjulian#define ARPHRD_IEEE802	6	/* token-ring hardware format */
5084931Sfjoe#define ARPHRD_ARCNET	7	/* arcnet hardware format */
511541Srgrimes#define ARPHRD_FRELAY 	15	/* frame relay hardware format */
52130407Sdfr#define ARPHRD_IEEE1394	24	/* firewire hardware format */
53219819Sjeff#define ARPHRD_INFINIBAND 32	/* infiniband hardware format */
541541Srgrimes	u_short	ar_pro;		/* format of protocol address */
551541Srgrimes	u_char	ar_hln;		/* length of hardware address */
561541Srgrimes	u_char	ar_pln;		/* length of protocol address */
571541Srgrimes	u_short	ar_op;		/* one of: */
581541Srgrimes#define	ARPOP_REQUEST	1	/* request to resolve address */
591541Srgrimes#define	ARPOP_REPLY	2	/* response to previous request */
601541Srgrimes#define	ARPOP_REVREQUEST 3	/* request protocol address given hardware */
611541Srgrimes#define	ARPOP_REVREPLY	4	/* response giving protocol address */
621541Srgrimes#define ARPOP_INVREQUEST 8 	/* request to identify peer */
631541Srgrimes#define ARPOP_INVREPLY	9	/* response identifying peer */
641541Srgrimes/*
651541Srgrimes * The remaining fields are variable in size,
661541Srgrimes * according to the sizes above.
671541Srgrimes */
681541Srgrimes#ifdef COMMENT_ONLY
691541Srgrimes	u_char	ar_sha[];	/* sender hardware address */
701541Srgrimes	u_char	ar_spa[];	/* sender protocol address */
711541Srgrimes	u_char	ar_tha[];	/* target hardware address */
721541Srgrimes	u_char	ar_tpa[];	/* target protocol address */
731541Srgrimes#endif
741541Srgrimes};
751541Srgrimes
7684931Sfjoe#define ar_sha(ap)	(((caddr_t)((ap)+1)) +   0)
7784931Sfjoe#define ar_spa(ap)	(((caddr_t)((ap)+1)) +   (ap)->ar_hln)
7884931Sfjoe#define ar_tha(ap)	(((caddr_t)((ap)+1)) +   (ap)->ar_hln + (ap)->ar_pln)
7984931Sfjoe#define ar_tpa(ap)	(((caddr_t)((ap)+1)) + 2*(ap)->ar_hln + (ap)->ar_pln)
8084931Sfjoe
8184931Sfjoe#define arphdr_len2(ar_hln, ar_pln)					\
8284931Sfjoe	(sizeof(struct arphdr) + 2*(ar_hln) + 2*(ar_pln))
8384931Sfjoe#define arphdr_len(ap)	(arphdr_len2((ap)->ar_hln, (ap)->ar_pln))
8484931Sfjoe
851541Srgrimes/*
861541Srgrimes * ARP ioctl request
871541Srgrimes */
881541Srgrimesstruct arpreq {
891541Srgrimes	struct	sockaddr arp_pa;		/* protocol address */
901541Srgrimes	struct	sockaddr arp_ha;		/* hardware address */
911541Srgrimes	int	arp_flags;			/* flags */
921541Srgrimes};
931541Srgrimes/*  arp_flags and at_flags field values */
941541Srgrimes#define	ATF_INUSE	0x01	/* entry in use */
951541Srgrimes#define ATF_COM		0x02	/* completed entry (enaddr valid) */
961541Srgrimes#define	ATF_PERM	0x04	/* permanent entry */
971541Srgrimes#define	ATF_PUBL	0x08	/* publish entry (respond for other host) */
981541Srgrimes#define	ATF_USETRAILERS	0x10	/* has requested trailers */
992168Spaul
10055205Speter#ifdef _KERNEL
10132350Seivind/*
10232350Seivind * Structure shared between the ethernet driver modules and
103147256Sbrooks * the address resolution code.
10432350Seivind */
10532350Seivindstruct	arpcom {
106147256Sbrooks	struct 	ifnet *ac_ifp;		/* network-visible interface */
10762143Sarchie	void	*ac_netgraph;		/* ng_ether(4) netgraph node info */
10832350Seivind};
109147256Sbrooks#define IFP2AC(ifp) ((struct arpcom *)(ifp->if_l2com))
110147256Sbrooks#define AC2IFP(ac) ((ac)->ac_ifp)
111128376Sluigi
112196797Sgnn#endif /* _KERNEL */
11332350Seivind
114196797Sgnnstruct arpstat {
115196797Sgnn	/* Normal things that happen: */
116253081Sae	uint64_t txrequests;	/* # of ARP requests sent by this host. */
117253081Sae	uint64_t txreplies;	/* # of ARP replies sent by this host. */
118253081Sae	uint64_t rxrequests;	/* # of ARP requests received by this host. */
119253081Sae	uint64_t rxreplies;	/* # of ARP replies received by this host. */
120253081Sae	uint64_t received;	/* # of ARP packets received by this host. */
121196797Sgnn
122253081Sae	uint64_t arp_spares[4];	/* For either the upper or lower half. */
123196797Sgnn	/* Abnormal event and error  counting: */
124253081Sae	uint64_t dropped;	/* # of packets dropped waiting for a reply. */
125253081Sae	uint64_t timeouts;	/* # of times with entries removed */
126196797Sgnn				/* due to timeout. */
127253081Sae	uint64_t dupips;	/* # of duplicate IPs detected. */
128196797Sgnn};
129196797Sgnn
130253084Sae#ifdef _KERNEL
131253084Sae#include <sys/counter.h>
132253084Sae#include <net/vnet.h>
133253084Sae
134253084SaeVNET_PCPUSTAT_DECLARE(struct arpstat, arpstat);
135196797Sgnn/*
136196797Sgnn * In-kernel consumers can use these accessor macros directly to update
137196797Sgnn * stats.
138196797Sgnn */
139253084Sae#define	ARPSTAT_ADD(name, val)	\
140253084Sae    VNET_PCPUSTAT_ADD(struct arpstat, arpstat, name, (val))
141253084Sae#define	ARPSTAT_SUB(name, val)	ARPSTAT_ADD(name, -(val))
142196797Sgnn#define	ARPSTAT_INC(name)	ARPSTAT_ADD(name, 1)
143196797Sgnn#define	ARPSTAT_DEC(name)	ARPSTAT_SUB(name, 1)
144196797Sgnn
145253084Sae#endif /* _KERNEL */
146253084Sae
1474507Sbde#endif /* !_NET_IF_ARP_H_ */
148