if_arp.h revision 253081
180709Sjake/*-
281180Sjake * Copyright (c) 1986, 1993
381180Sjake *	The Regents of the University of California.  All rights reserved.
481180Sjake *
581180Sjake * Redistribution and use in source and binary forms, with or without
681180Sjake * modification, are permitted provided that the following conditions
781180Sjake * are met:
881180Sjake * 1. Redistributions of source code must retain the above copyright
981180Sjake *    notice, this list of conditions and the following disclaimer.
1081180Sjake * 2. Redistributions in binary form must reproduce the above copyright
1181180Sjake *    notice, this list of conditions and the following disclaimer in the
1281180Sjake *    documentation and/or other materials provided with the distribution.
1381180Sjake * 4. Neither the name of the University nor the names of its contributors
1481180Sjake *    may be used to endorse or promote products derived from this software
1581180Sjake *    without specific prior written permission.
1681180Sjake *
1781180Sjake * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1881180Sjake * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1981180Sjake * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2081180Sjake * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2181180Sjake * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2281180Sjake * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2381180Sjake * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2481180Sjake * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2581180Sjake * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2681180Sjake * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2781180Sjake * SUCH DAMAGE.
28114085Sobrien *
2981180Sjake *	@(#)if_arp.h	8.1 (Berkeley) 6/10/93
3081180Sjake * $FreeBSD: head/sys/net/if_arp.h 253081 2013-07-09 09:32:06Z ae $
3180709Sjake */
3280709Sjake
3380709Sjake#ifndef _NET_IF_ARP_H_
3480709Sjake#define	_NET_IF_ARP_H_
3580709Sjake
3680709Sjake/*
3780709Sjake * Address Resolution Protocol.
3880709Sjake *
3980709Sjake * See RFC 826 for protocol description.  ARP packets are variable
4080709Sjake * in size; the arphdr structure defines the fixed-length portion.
4180709Sjake * Protocol type values are the same as those for 10 Mb/s Ethernet.
4280709Sjake * It is followed by the variable-sized fields ar_sha, arp_spa,
4381337Sobrien * arp_tha and arp_tpa in that order, according to the lengths
4480709Sjake * specified.  Field names used correspond to RFC 826.
4580709Sjake */
4681337Sobrienstruct	arphdr {
4780709Sjake	u_short	ar_hrd;		/* format of hardware address */
4880709Sjake#define ARPHRD_ETHER 	1	/* ethernet hardware format */
4980709Sjake#define ARPHRD_IEEE802	6	/* token-ring hardware format */
5080709Sjake#define ARPHRD_ARCNET	7	/* arcnet hardware format */
5180709Sjake#define ARPHRD_FRELAY 	15	/* frame relay hardware format */
5280709Sjake#define ARPHRD_IEEE1394	24	/* firewire hardware format */
5380709Sjake#define ARPHRD_INFINIBAND 32	/* infiniband hardware format */
5480709Sjake	u_short	ar_pro;		/* format of protocol address */
5580709Sjake	u_char	ar_hln;		/* length of hardware address */
56114188Sjake	u_char	ar_pln;		/* length of protocol address */
57114188Sjake	u_short	ar_op;		/* one of: */
58114188Sjake#define	ARPOP_REQUEST	1	/* request to resolve address */
59106050Sjake#define	ARPOP_REPLY	2	/* response to previous request */
6080709Sjake#define	ARPOP_REVREQUEST 3	/* request protocol address given hardware */
6180709Sjake#define	ARPOP_REVREPLY	4	/* response giving protocol address */
6280709Sjake#define ARPOP_INVREQUEST 8 	/* request to identify peer */
6380709Sjake#define ARPOP_INVREPLY	9	/* response identifying peer */
64166105Smarius/*
65166105Smarius * The remaining fields are variable in size,
66166105Smarius * according to the sizes above.
6782906Sjake */
68166105Smarius#ifdef COMMENT_ONLY
6982906Sjake	u_char	ar_sha[];	/* sender hardware address */
7080709Sjake	u_char	ar_spa[];	/* sender protocol address */
71166105Smarius	u_char	ar_tha[];	/* target hardware address */
7282906Sjake	u_char	ar_tpa[];	/* target protocol address */
73166105Smarius#endif
7482906Sjake};
7580709Sjake
7680709Sjake#define ar_sha(ap)	(((caddr_t)((ap)+1)) +   0)
7780709Sjake#define ar_spa(ap)	(((caddr_t)((ap)+1)) +   (ap)->ar_hln)
78216803Smarius#define ar_tha(ap)	(((caddr_t)((ap)+1)) +   (ap)->ar_hln + (ap)->ar_pln)
79216803Smarius#define ar_tpa(ap)	(((caddr_t)((ap)+1)) + 2*(ap)->ar_hln + (ap)->ar_pln)
80216803Smarius
81216803Smarius#define arphdr_len2(ar_hln, ar_pln)					\
82216803Smarius	(sizeof(struct arphdr) + 2*(ar_hln) + 2*(ar_pln))
83216803Smarius#define arphdr_len(ap)	(arphdr_len2((ap)->ar_hln, (ap)->ar_pln))
84101653Sjake
8588644Sjake/*
8688644Sjake * ARP ioctl request
8788644Sjake */
8888644Sjakestruct arpreq {
8988644Sjake	struct	sockaddr arp_pa;		/* protocol address */
9082005Sjake	struct	sockaddr arp_ha;		/* hardware address */
91216803Smarius	int	arp_flags;			/* flags */
9288644Sjake};
93216803Smarius/*  arp_flags and at_flags field values */
9488644Sjake#define	ATF_INUSE	0x01	/* entry in use */
95216803Smarius#define ATF_COM		0x02	/* completed entry (enaddr valid) */
9688644Sjake#define	ATF_PERM	0x04	/* permanent entry */
97216803Smarius#define	ATF_PUBL	0x08	/* publish entry (respond for other host) */
9888644Sjake#define	ATF_USETRAILERS	0x10	/* has requested trailers */
9988644Sjake
10088644Sjake#ifdef _KERNEL
10188644Sjake/*
102216803Smarius * Structure shared between the ethernet driver modules and
103216803Smarius * the address resolution code.
10488644Sjake */
10588644Sjakestruct	arpcom {
10682906Sjake	struct 	ifnet *ac_ifp;		/* network-visible interface */
10782906Sjake	void	*ac_netgraph;		/* ng_ether(4) netgraph node info */
10882906Sjake};
10982906Sjake#define IFP2AC(ifp) ((struct arpcom *)(ifp->if_l2com))
11082906Sjake#define AC2IFP(ac) ((ac)->ac_ifp)
11182005Sjake
11280709Sjake#endif /* _KERNEL */
11382906Sjake
11482906Sjakestruct arpstat {
11582906Sjake	/* Normal things that happen: */
11682906Sjake	uint64_t txrequests;	/* # of ARP requests sent by this host. */
11782906Sjake	uint64_t txreplies;	/* # of ARP replies sent by this host. */
11882906Sjake	uint64_t rxrequests;	/* # of ARP requests received by this host. */
11982906Sjake	uint64_t rxreplies;	/* # of ARP replies received by this host. */
12082906Sjake	uint64_t received;	/* # of ARP packets received by this host. */
12182906Sjake
12282906Sjake	uint64_t arp_spares[4];	/* For either the upper or lower half. */
12382906Sjake	/* Abnormal event and error  counting: */
12482906Sjake	uint64_t dropped;	/* # of packets dropped waiting for a reply. */
12582906Sjake	uint64_t timeouts;	/* # of times with entries removed */
12682906Sjake				/* due to timeout. */
12782906Sjake	uint64_t dupips;	/* # of duplicate IPs detected. */
12882906Sjake};
12982906Sjake
13080709Sjake/*
13182906Sjake * In-kernel consumers can use these accessor macros directly to update
13282906Sjake * stats.
13382906Sjake */
13482906Sjake#define	ARPSTAT_ADD(name, val)	V_arpstat.name += (val)
13582906Sjake#define	ARPSTAT_SUB(name, val)	V_arpstat.name -= (val)
13682906Sjake#define	ARPSTAT_INC(name)	ARPSTAT_ADD(name, 1)
13782906Sjake#define	ARPSTAT_DEC(name)	ARPSTAT_SUB(name, 1)
13882906Sjake
13982906Sjake#endif /* !_NET_IF_ARP_H_ */
14082906Sjake