xref: /xnu-11417.140.69/bsd/netinet/in_arp.h (revision 43a90889846e00bfb5cf1d255cdc0a701a1e05a4)
1*43a90889SApple OSS Distributions /*
2*43a90889SApple OSS Distributions  * Copyright (c) 2009-2013 Apple Inc. All rights reserved.
3*43a90889SApple OSS Distributions  *
4*43a90889SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*43a90889SApple OSS Distributions  *
6*43a90889SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*43a90889SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*43a90889SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*43a90889SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*43a90889SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*43a90889SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*43a90889SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*43a90889SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*43a90889SApple OSS Distributions  *
15*43a90889SApple OSS Distributions  * Please obtain a copy of the License at
16*43a90889SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*43a90889SApple OSS Distributions  *
18*43a90889SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*43a90889SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*43a90889SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*43a90889SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*43a90889SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*43a90889SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*43a90889SApple OSS Distributions  * limitations under the License.
25*43a90889SApple OSS Distributions  *
26*43a90889SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*43a90889SApple OSS Distributions  */
28*43a90889SApple OSS Distributions 
29*43a90889SApple OSS Distributions #ifndef _NETINET_IN_ARP_H_
30*43a90889SApple OSS Distributions #define _NETINET_IN_ARP_H_
31*43a90889SApple OSS Distributions #ifdef KERNEL
32*43a90889SApple OSS Distributions #include <sys/kernel_types.h>
33*43a90889SApple OSS Distributions 
34*43a90889SApple OSS Distributions struct sockaddr;
35*43a90889SApple OSS Distributions struct sockaddr_dl;
36*43a90889SApple OSS Distributions struct sockaddr_in;
37*43a90889SApple OSS Distributions 
38*43a90889SApple OSS Distributions /*!
39*43a90889SApple OSS Distributions  *	@function inet_arp_lookup
40*43a90889SApple OSS Distributions  *	@discussion This function will check the routing table for a cached
41*43a90889SApple OSS Distributions  *		arp entry or trigger an arp query to resolve the ip address to a
42*43a90889SApple OSS Distributions  *		link-layer address.
43*43a90889SApple OSS Distributions  *
44*43a90889SApple OSS Distributions  *		Arp entries are stored in the routing table. This function will
45*43a90889SApple OSS Distributions  *		lookup the ip destination in the routing table. If the
46*43a90889SApple OSS Distributions  *		destination requires forwarding to a gateway, the route of the
47*43a90889SApple OSS Distributions  *		gateway will be looked up. The route entry is inspected to
48*43a90889SApple OSS Distributions  *		determine if the link layer destination address is known. If
49*43a90889SApple OSS Distributions  *		unknown, the arp generation function for IP attached to the
50*43a90889SApple OSS Distributions  *		interface is called to create an arp request packet.
51*43a90889SApple OSS Distributions  *	@param interface The interface the packet is being sent on.
52*43a90889SApple OSS Distributions  *	@param ip_dest The ip destination of the packet.
53*43a90889SApple OSS Distributions  *	@param ll_dest On output, the link-layer destination.
54*43a90889SApple OSS Distributions  *	@param ll_dest_len The length of the buffer for ll_dest.
55*43a90889SApple OSS Distributions  *	@param hint Any routing hint passed down from the protocol.
56*43a90889SApple OSS Distributions  *	@param packet The packet being transmitted.
57*43a90889SApple OSS Distributions  *	@result May return an error such as EHOSTDOWN or ENETUNREACH. If
58*43a90889SApple OSS Distributions  *		this function returns EJUSTRETURN, the packet has been queued
59*43a90889SApple OSS Distributions  *		and will be sent when an arp response is received. If any other
60*43a90889SApple OSS Distributions  *		value is returned, the caller is responsible for disposing of
61*43a90889SApple OSS Distributions  *		the packet.
62*43a90889SApple OSS Distributions  */
63*43a90889SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
64*43a90889SApple OSS Distributions extern boolean_t arp_is_entry_probing(route_t p_route);
65*43a90889SApple OSS Distributions extern errno_t arp_lookup_ip(ifnet_t interface,
66*43a90889SApple OSS Distributions     const struct sockaddr_in *ip_dest,
67*43a90889SApple OSS Distributions     struct sockaddr_dl *__sized_by(ll_dest_len)ll_dest,
68*43a90889SApple OSS Distributions     size_t ll_dest_len, route_t hint, mbuf_t packet);
69*43a90889SApple OSS Distributions #define inet_arp_lookup arp_lookup_ip
70*43a90889SApple OSS Distributions #else
71*43a90889SApple OSS Distributions extern errno_t inet_arp_lookup(ifnet_t interface,
72*43a90889SApple OSS Distributions     const struct sockaddr_in *ip_dest, struct sockaddr_dl *ll_dest,
73*43a90889SApple OSS Distributions     size_t ll_dest_len, route_t hint, mbuf_t packet);
74*43a90889SApple OSS Distributions #endif /* !BSD_KERNEL_PRIVATE */
75*43a90889SApple OSS Distributions 
76*43a90889SApple OSS Distributions /*!
77*43a90889SApple OSS Distributions  *	@function inet_arp_handle_input
78*43a90889SApple OSS Distributions  *	@discussion This function should be called by code that handles
79*43a90889SApple OSS Distributions  *		inbound arp packets. The caller should parse the ARP packet to
80*43a90889SApple OSS Distributions  *		pull out the operation and the relevant addresses. If a response
81*43a90889SApple OSS Distributions  *		is required, the proto_media_send_arp function will be called.
82*43a90889SApple OSS Distributions  *
83*43a90889SApple OSS Distributions  *		This function will lookup the sender in the routing table and
84*43a90889SApple OSS Distributions  *		add an arp entry if necessary. Any queued packets waiting for
85*43a90889SApple OSS Distributions  *		the arp resolution will also be transmitted.
86*43a90889SApple OSS Distributions  *	@param interface The interface the packet was received on.
87*43a90889SApple OSS Distributions  *	@param arp_op The arp operation, ARPOP_REQUEST or ARPOP_REPLY
88*43a90889SApple OSS Distributions  *	@param sender_hw The sender hardware address from the arp payload.
89*43a90889SApple OSS Distributions  *	@param sender_ip The sender IP address from the arp payload.
90*43a90889SApple OSS Distributions  *	@param target_ip The target IP address from the arp payload.
91*43a90889SApple OSS Distributions  *	@result 0 on success or an errno error value on failure.
92*43a90889SApple OSS Distributions  */
93*43a90889SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
94*43a90889SApple OSS Distributions extern errno_t arp_ip_handle_input(ifnet_t ifp, u_int16_t arpop,
95*43a90889SApple OSS Distributions     const struct sockaddr_dl *sender_hw, const struct sockaddr_in *sender_ip,
96*43a90889SApple OSS Distributions     const struct sockaddr_in *target_ip);
97*43a90889SApple OSS Distributions #define inet_arp_handle_input arp_ip_handle_input
98*43a90889SApple OSS Distributions #else
99*43a90889SApple OSS Distributions extern errno_t inet_arp_handle_input(ifnet_t ifp, u_int16_t arpop,
100*43a90889SApple OSS Distributions     const struct sockaddr_dl *sender_hw, const struct sockaddr_in *sender_ip,
101*43a90889SApple OSS Distributions     const struct sockaddr_in *target_ip);
102*43a90889SApple OSS Distributions #endif /* !BSD_KERNEL_PRIVATE */
103*43a90889SApple OSS Distributions 
104*43a90889SApple OSS Distributions /*!
105*43a90889SApple OSS Distributions  *	@function inet_arp_init_ifaddr
106*43a90889SApple OSS Distributions  *	@discussion This function should be called in two places, when an IP
107*43a90889SApple OSS Distributions  *		address is added and when the hardware address changes. This
108*43a90889SApple OSS Distributions  *		function will setup the ifaddr_t for use with the IP ARP
109*43a90889SApple OSS Distributions  *		functions. This function will also trigger the transmission of a
110*43a90889SApple OSS Distributions  *		gratuitous ARP packet.
111*43a90889SApple OSS Distributions  *
112*43a90889SApple OSS Distributions  *		When the SIOCSIFADDR ioctl is handled, the data parameter will
113*43a90889SApple OSS Distributions  *		be an ifaddr_t. If this is an IP address, inet_arp_init_ifaddr
114*43a90889SApple OSS Distributions  *		should be called. This is usually performed in the protocol
115*43a90889SApple OSS Distributions  *		attachment's ioctl handler.
116*43a90889SApple OSS Distributions  *
117*43a90889SApple OSS Distributions  *		When the event handler for the protocol attachment receives a
118*43a90889SApple OSS Distributions  *		KEV_DL_LINK_ADDRESS_CHANGED event, the event handler should call
119*43a90889SApple OSS Distributions  *		inet_arp_init_ifaddr for each interface ip address.
120*43a90889SApple OSS Distributions  *
121*43a90889SApple OSS Distributions  *		For an example, see bsd/net/ether_inet_pr_module.c in xnu.
122*43a90889SApple OSS Distributions  *		Search for inet_arp_init_ifaddr.
123*43a90889SApple OSS Distributions  *	@param interface The interface the packet was received on.
124*43a90889SApple OSS Distributions  *	@param ipaddr The ip interface address.
125*43a90889SApple OSS Distributions  */
126*43a90889SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
127*43a90889SApple OSS Distributions /* inet_arp_init_ifaddr is aliased to arp_ifinit (if_ether.h) */
128*43a90889SApple OSS Distributions #define inet_arp_init_ifaddr    arp_ifinit
129*43a90889SApple OSS Distributions #else
130*43a90889SApple OSS Distributions extern void inet_arp_init_ifaddr(ifnet_t interface, ifaddr_t ipaddr);
131*43a90889SApple OSS Distributions #endif /* !BSD_KERNEL_PRIVATE */
132*43a90889SApple OSS Distributions 
133*43a90889SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
134*43a90889SApple OSS Distributions extern void in_arpdrain(void *);
135*43a90889SApple OSS Distributions extern void arp_llreach_set_reachable(struct ifnet *,
136*43a90889SApple OSS Distributions     void *__sized_by(alen) addr, unsigned int alen);
137*43a90889SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
138*43a90889SApple OSS Distributions #endif /* KERNEL */
139*43a90889SApple OSS Distributions #endif /* _NETINET_IN_ARP_H_ */
140