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