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