]>
Commit | Line | Data |
---|---|---|
91447636 | 1 | /* |
5d5c5d0d A |
2 | * Copyright (c) 2004 Apple Computer, Inc. All rights reserved. |
3 | * | |
6601e61a | 4 | * @APPLE_LICENSE_HEADER_START@ |
91447636 | 5 | * |
6601e61a A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
8f6c56a5 | 11 | * |
6601e61a A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
6601e61a A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
8f6c56a5 | 19 | * |
6601e61a | 20 | * @APPLE_LICENSE_HEADER_END@ |
91447636 A |
21 | */ |
22 | ||
23 | #ifndef _NETINET_IN_ARP_H_ | |
24 | #define _NETINET_IN_ARP_H_ | |
25 | #include <sys/kernel_types.h> | |
26 | ||
27 | struct sockaddr_dl; | |
28 | struct sockaddr_in; | |
29 | ||
30 | /*! | |
31 | @function inet_arp_lookup | |
32 | @discussion This function will check the routing table for a cached | |
33 | arp entry or trigger an arp query to resolve the ip address to a | |
34 | link-layer address. | |
35 | ||
36 | Arp entries are stored in the routing table. This function will | |
37 | lookup the ip destination in the routing table. If the | |
38 | destination requires forwarding to a gateway, the route of the | |
39 | gateway will be looked up. The route entry is inspected to | |
40 | determine if the link layer destination address is known. If | |
41 | unknown, the arp generation function for IP attached to the | |
42 | interface is called to create an arp request packet. | |
43 | @param interface The interface the packet is being sent on. | |
44 | @param ip_dest The ip destination of the packet. | |
45 | @param ll_dest On output, the link-layer destination. | |
46 | @param ll_dest_len The length of the buffer for ll_dest. | |
47 | @param hint Any routing hint passed down from the protocol. | |
48 | @param packet The packet being transmitted. | |
49 | @result May return an error such as EHOSTDOWN or ENETUNREACH. If | |
50 | this function returns EJUSTRETURN, the packet has been queued | |
51 | and will be sent when an arp response is received. If any other | |
52 | value is returned, the caller is responsible for disposing of | |
53 | the packet. | |
54 | */ | |
55 | #ifdef BSD_KERNEL_PRIVATE | |
56 | #define inet_arp_lookup arp_lookup_ip | |
57 | #else | |
58 | errno_t inet_arp_lookup(ifnet_t interface, const struct sockaddr_in *ip_dest, | |
59 | struct sockaddr_dl *ll_dest, size_t ll_dest_len, route_t hint, | |
60 | mbuf_t packet); | |
61 | #endif /* BSD_KERNEL_PRIVATE */ | |
62 | #ifdef KERNEL_PRIVATE | |
63 | /* arp_lookup_ip is obsolete, use inet_arp_lookup */ | |
64 | errno_t arp_lookup_ip(ifnet_t interface, const struct sockaddr_in *ip_dest, | |
65 | struct sockaddr_dl *ll_dest, size_t ll_dest_len, route_t hint, | |
66 | mbuf_t packet); | |
67 | #endif /* KERNEL_PRIVATE */ | |
68 | ||
69 | /*! | |
70 | @function inet_arp_handle_input | |
71 | @discussion This function should be called by code that handles | |
72 | inbound arp packets. The caller should parse the ARP packet to | |
73 | pull out the operation and the relevant addresses. If a response | |
74 | is required, the proto_media_send_arp function will be called. | |
75 | ||
76 | This function will lookup the sender in the routing table and | |
77 | add an arp entry if necessary. Any queued packets waiting for | |
78 | the arp resolution will also be transmitted. | |
79 | @param interface The interface the packet was received on. | |
80 | @param arp_op The arp operation, ARPOP_REQUEST or ARPOP_REPLY | |
81 | @param sender_hw The sender hardware address from the arp payload. | |
82 | @param sender_ip The sender IP address from the arp payload. | |
83 | @param target_ip The target IP address from the arp payload. | |
84 | @result 0 on success or an errno error value on failure. | |
85 | */ | |
86 | #ifdef BSD_KERNEL_PRIVATE | |
87 | #define inet_arp_handle_input arp_ip_handle_input | |
88 | #else | |
89 | errno_t inet_arp_handle_input(ifnet_t ifp, u_int16_t arpop, | |
90 | const struct sockaddr_dl *sender_hw, | |
91 | const struct sockaddr_in *sender_ip, | |
92 | const struct sockaddr_in *target_ip); | |
93 | #endif /* KERNEL_PRIVATE */ | |
94 | #ifdef KERNEL_PRIVATE | |
95 | /* arp_ip_handle_input is obsolete, use inet_arp_handle_input */ | |
96 | errno_t arp_ip_handle_input(ifnet_t ifp, u_int16_t arpop, | |
97 | const struct sockaddr_dl *sender_hw, | |
98 | const struct sockaddr_in *sender_ip, | |
99 | const struct sockaddr_in *target_ip); | |
100 | #endif /* BSD_KERNEL_PRIVATE */ | |
101 | ||
102 | /*! | |
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. | |
123 | */ | |
124 | #ifdef BSD_KERNEL_PRIVATE | |
125 | /* inet_arp_init_ifaddr is aliased to arp_ifinit */ | |
126 | #define inet_arp_init_ifaddr arp_ifinit | |
127 | #else | |
128 | void inet_arp_init_ifaddr(ifnet_t interface, ifaddr_t ipaddr); | |
129 | #endif | |
130 | ||
131 | #endif _NETINET_IN_ARP_H_ |