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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/param.h>
#include <sys/types.h>
#include <sys/systm.h>
#include <sys/cmn_err.h>
#include <sys/stream.h>
#include <sys/sunddi.h>
#include <sys/hook.h>
#include <sys/hook_impl.h>
#include <sys/netstack.h>
#include <net/if.h>
#include <sys/neti.h>
#include <sys/hook_event.h>
#include <inet/arp_impl.h>
/*
* ARP netinfo entry point declarations.
*/
static int arp_getifname(phy_if_t, char *, const size_t, netstack_t *);
static int arp_getmtu(phy_if_t, lif_if_t, netstack_t *);
static int arp_getpmtuenabled(netstack_t *);
static int arp_getlifaddr(phy_if_t, lif_if_t, size_t,
net_ifaddr_t [], void *, netstack_t *);
static phy_if_t arp_phygetnext(phy_if_t, netstack_t *);
static phy_if_t arp_phylookup(const char *, netstack_t *);
static lif_if_t arp_lifgetnext(phy_if_t, lif_if_t, netstack_t *);
static int arp_inject(inject_t, net_inject_t *, netstack_t *);
static phy_if_t arp_routeto(struct sockaddr *, netstack_t *);
static int arp_ispartialchecksum(mblk_t *);
static int arp_isvalidchecksum(mblk_t *);
static net_info_t arp_netinfo = {
NETINFO_VERSION,
NHF_ARP,
arp_getifname,
arp_getmtu,
arp_getpmtuenabled,
arp_getlifaddr,
arp_phygetnext,
arp_phylookup,
arp_lifgetnext,
arp_inject,
arp_routeto,
arp_ispartialchecksum,
arp_isvalidchecksum
};
/*
* Register ARP netinfo functions.
*/
void
arp_net_init(arp_stack_t *as, netstack_t *ns)
{
as->as_net_data = net_register_impl(&arp_netinfo, ns);
ASSERT(as->as_net_data != NULL);
}
/*
* Unregister ARP netinfo functions.
*/
void
arp_net_destroy(arp_stack_t *as)
{
(void) net_unregister(as->as_net_data);
}
/*
* Initialize ARP hook family and events
*/
void
arp_hook_init(arp_stack_t *as)
{
HOOK_FAMILY_INIT(&as->as_arproot, Hn_ARP);
if (net_register_family(as->as_net_data, &as->as_arproot) != 0) {
cmn_err(CE_NOTE, "arp_hook_init: "
"net_register_family failed for arp");
}
HOOK_EVENT_INIT(&as->as_arp_physical_in_event, NH_PHYSICAL_IN);
as->as_arp_physical_in = net_register_event(as->as_net_data,
&as->as_arp_physical_in_event);
if (as->as_arp_physical_in == NULL) {
cmn_err(CE_NOTE, "arp_hook_init: "
"net_register_event failed for arp/physical_in");
}
HOOK_EVENT_INIT(&as->as_arp_physical_out_event, NH_PHYSICAL_OUT);
as->as_arp_physical_out = net_register_event(as->as_net_data,
&as->as_arp_physical_out_event);
if (as->as_arp_physical_out == NULL) {
cmn_err(CE_NOTE, "arp_hook_init: "
"net_register_event failed for arp/physical_out");
}
HOOK_EVENT_INIT(&as->as_arp_nic_events, NH_NIC_EVENTS);
as->as_arpnicevents = net_register_event(as->as_net_data,
&as->as_arp_nic_events);
if (as->as_arpnicevents == NULL) {
cmn_err(CE_NOTE, "arp_hook_init: "
"net_register_event failed for arp/nic_events");
}
}
void
arp_hook_destroy(arp_stack_t *as)
{
if (as->as_arpnicevents != NULL) {
if (net_unregister_event(as->as_net_data,
&as->as_arp_nic_events) == 0)
as->as_arpnicevents = NULL;
}
if (as->as_arp_physical_out != NULL) {
if (net_unregister_event(as->as_net_data,
&as->as_arp_physical_out_event) == 0)
as->as_arp_physical_out = NULL;
}
if (as->as_arp_physical_in != NULL) {
if (net_unregister_event(as->as_net_data,
&as->as_arp_physical_in_event) == 0)
as->as_arp_physical_in = NULL;
}
(void) net_unregister_family(as->as_net_data, &as->as_arproot);
}
/*
* Determine the name of the lower level interface
*/
static int
arp_getifname(phy_if_t phy_ifdata, char *buffer, const size_t buflen,
netstack_t *ns)
{
arl_t *arl;
arp_stack_t *as;
ASSERT(buffer != NULL);
ASSERT(ns != NULL);
as = ns->netstack_arp;
rw_enter(&as->as_arl_lock, RW_READER);
for (arl = as->as_arl_head; arl != NULL; arl = arl->arl_next) {
if (arl->arl_index == phy_ifdata) {
(void) strlcpy(buffer, arl->arl_name, buflen);
rw_exit(&as->as_arl_lock);
return (0);
}
}
rw_exit(&as->as_arl_lock);
return (1);
}
/*
* Unsupported with ARP.
*/
/*ARGSUSED*/
static int
arp_getmtu(phy_if_t phy_ifdata, lif_if_t ifdata, netstack_t *ns)
{
return (-1);
}
/*
* Unsupported with ARP.
*/
/*ARGSUSED*/
static int
arp_getpmtuenabled(netstack_t *ns)
{
return (-1);
}
/*
* Unsupported with ARP.
*/
/*ARGSUSED*/
static int
arp_getlifaddr(phy_if_t phy_ifdata, lif_if_t ifdata, size_t nelem,
net_ifaddr_t type[], void *storage, netstack_t *ns)
{
return (-1);
}
/*
* Determine the instance number of the next lower level interface
*/
static phy_if_t
arp_phygetnext(phy_if_t phy_ifdata, netstack_t *ns)
{
arl_t *arl;
int index;
arp_stack_t *as;
ASSERT(ns != NULL);
as = ns->netstack_arp;
rw_enter(&as->as_arl_lock, RW_READER);
if (phy_ifdata == 0) {
arl = as->as_arl_head;
} else {
for (arl = as->as_arl_head; arl != NULL;
arl = arl->arl_next) {
if (arl->arl_index == phy_ifdata) {
arl = arl->arl_next;
break;
}
}
}
index = (arl != NULL) ? arl->arl_index : 0;
rw_exit(&as->as_arl_lock);
return (index);
}
/*
* Given a network interface name, find its ARP layer instance number.
*/
static phy_if_t
arp_phylookup(const char *name, netstack_t *ns)
{
arl_t *arl;
int index;
arp_stack_t *as;
ASSERT(name != NULL);
ASSERT(ns != NULL);
index = 0;
as = ns->netstack_arp;
rw_enter(&as->as_arl_lock, RW_READER);
for (arl = as->as_arl_head; arl != NULL; arl = arl->arl_next) {
if (strcmp(name, arl->arl_name) == 0) {
index = arl->arl_index;
break;
}
}
rw_exit(&as->as_arl_lock);
return (index);
}
/*
* Unsupported with ARP.
*/
/*ARGSUSED*/
static lif_if_t
arp_lifgetnext(phy_if_t ifp, lif_if_t lif, netstack_t *ns)
{
return ((lif_if_t)-1);
}
/*
* Unsupported with ARP.
*/
/*ARGSUSED*/
static int
arp_inject(inject_t injection, net_inject_t *neti, netstack_t *ns)
{
return (-1);
}
/*
* Unsupported with ARP.
*/
/*ARGSUSED*/
static phy_if_t
arp_routeto(struct sockaddr *addr, netstack_t *ns)
{
return ((phy_if_t)-1);
}
/*
* Unsupported with ARP.
*/
/*ARGSUSED*/
int
arp_ispartialchecksum(mblk_t *mb)
{
return (-1);
}
/*
* Unsupported with ARP.
*/
/*ARGSUSED*/
static int
arp_isvalidchecksum(mblk_t *mb)
{
return (-1);
}
|