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