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