1/*
2 * Copyright (c) 2000-2011 Apple 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/*
25 * arp_session.h
26 */
27
28/*
29 * Modification History
30 *
31 * May 11, 2000		Dieter Siegmund (dieter@apple.com)
32 * - created
33 */
34
35
36#ifndef _S_ARP_SESSION_H
37#define _S_ARP_SESSION_H
38
39#include "FDSet.h"
40#include "interfaces.h"
41
42#define ARP_PROBE_COUNT				3
43#define ARP_GRATUITOUS_COUNT			2
44#define ARP_RETRY_SECS				0
45#define ARP_RETRY_USECS				320000
46#define ARP_DETECT_COUNT			3
47#define ARP_DETECT_RETRY_SECS			0
48#define ARP_DETECT_RETRY_USECS			15000
49#define ARP_CONFLICT_RETRY_COUNT		2
50#define ARP_CONFLICT_RETRY_DELAY_SECS		0
51#define ARP_CONFLICT_RETRY_DELAY_USECS		750000
52#define ARP_RESOLVE_RETRY_SECS			0
53#define ARP_RESOLVE_RETRY_USECS			320000
54
55typedef struct arp_session_values {
56    int * 		probe_count;
57    int * 		probe_gratuitous_count;
58    struct timeval * 	probe_interval;
59    int * 		detect_count;
60    struct timeval * 	detect_interval;
61    int *		conflict_retry_count;
62    struct timeval *	conflict_delay_interval;
63    struct timeval * 	resolve_interval;
64} arp_session_values_t;
65
66typedef struct arp_client arp_client_t;
67
68typedef struct {
69    struct in_addr		sender_ip;
70    struct in_addr		target_ip;
71    uint8_t			target_hardware[MAX_LINK_ADDR_LEN];
72} arp_address_info_t;
73
74typedef struct {
75    arp_client_t *		client;
76    boolean_t			error;
77    boolean_t			in_use;
78    arp_address_info_t		addr;
79} arp_result_t;
80
81/*
82 * Type: arp_result_func_t
83 * Purpose:
84 *   Called to send results back to the caller.  The first two args are
85 *   supplied by the client.
86 */
87typedef void (arp_result_func_t)(void * arg1, void * arg2,
88				 const arp_result_t * result);
89
90/*
91 * Type: arp_our_address_func_t
92 * Purpose:
93 *   Called to check whether a given hardware address matches any
94 *   of this system's hardware addresses.  A return value of TRUE
95 *   implies the hardware address corresponds to a physical interface on
96 *   this system, and should not be reported as a conflict.  A return of
97 *   FALSE implies the converse, and a conflict should be reported.
98 */
99typedef boolean_t (arp_our_address_func_t)(interface_t * if_p,
100					   int hwtype, void * hwaddr,
101					   int hwlen);
102
103typedef struct arp_session arp_session_t;
104
105arp_session_t *
106arp_session_init(arp_our_address_func_t * func,
107		 arp_session_values_t * values);
108void
109arp_session_free(arp_session_t * * session_p);
110
111void
112arp_session_set_debug(arp_session_t * session, int debug);
113
114
115/**
116 ** arp client functions
117 **/
118void
119arp_client_set_probes_are_collisions(arp_client_t * client,
120				     boolean_t probes_are_collisions);
121
122arp_client_t *
123arp_client_init(arp_session_t * session, interface_t * if_p);
124
125void
126arp_client_free(arp_client_t * * client_p);
127
128const char *
129arp_client_errmsg(arp_client_t * client);
130
131void
132arp_client_set_probe_info(arp_client_t * client,
133			  const struct timeval * retry_interval,
134			  const int * probe_count,
135			  const int * gratuitous_count);
136void
137arp_client_restore_default_probe_info(arp_client_t * client);
138
139void
140arp_client_probe(arp_client_t * client,
141		 arp_result_func_t * func, void * arg1, void * arg2,
142		 struct in_addr sender_ip, struct in_addr target_ip);
143
144void
145arp_client_resolve(arp_client_t * client,
146		   arp_result_func_t * func, void * arg1, void * arg2,
147		   struct in_addr sender_ip, struct in_addr target_ip,
148		   uint32_t resolve_secs);
149
150void
151arp_client_detect(arp_client_t * client,
152		  arp_result_func_t * func, void * arg1, void * arg2,
153		  const arp_address_info_t * list, int list_count,
154		  boolean_t resolve);
155void
156arp_client_cancel(arp_client_t * client);
157
158boolean_t
159arp_client_defend(arp_client_t * client, struct in_addr our_ip);
160
161boolean_t
162arp_client_is_active(arp_client_t * client);
163
164void
165arp_client_announce(arp_client_t * client,
166                    arp_result_func_t * func, void * arg1, void * arg2,
167                    struct in_addr sender_ip, struct in_addr target_ip,
168                    boolean_t skip);
169
170#endif /* _S_ARP_SESSION_H */
171