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