summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdladm/common/libdliptun.c
blob: cf1ab20ba3bff527ca31af0622354b16ac6de19e (plain)
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
/*
 * 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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
 */

#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <stropts.h>
#include <string.h>
#include <netdb.h>
#include <sys/conf.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <inet/iptun.h>
#include <sys/dls.h>
#include <libdlpi.h>
#include <libdladm_impl.h>
#include <libdllink.h>
#include <libdliptun.h>

/*
 * IP Tunneling Administration Library.
 * This library is used by dladm(8) and to configure IP tunnel links.
 */

#define	IPTUN_CONF_TYPE		"type"
#define	IPTUN_CONF_LADDR	"laddr"
#define	IPTUN_CONF_RADDR	"raddr"

/*
 * If IPTUN_CREATE and IPTUN_MODIFY include IPsec policy and IPsec hasn't
 * loaded yet, the ioctls may return EAGAIN.  We try the ioctl
 * IPTUN_IOCTL_ATTEMPT_LIMIT times and wait IPTUN_IOCTL_ATTEMPT_INTERVAL
 * microseconds between attempts.
 */
#define	IPTUN_IOCTL_ATTEMPT_LIMIT	3
#define	IPTUN_IOCTL_ATTEMPT_INTERVAL	10000

dladm_status_t
i_iptun_ioctl(dladm_handle_t handle, int cmd, void *dp)
{
	dladm_status_t	status = DLADM_STATUS_OK;
	uint_t		attempt;

	for (attempt = 0; attempt < IPTUN_IOCTL_ATTEMPT_LIMIT; attempt++) {
		if (attempt != 0)
			(void) usleep(IPTUN_IOCTL_ATTEMPT_INTERVAL);
		status = (ioctl(dladm_dld_fd(handle), cmd, dp) == 0) ?
		    DLADM_STATUS_OK : dladm_errno2status(errno);
		if (status != DLADM_STATUS_TRYAGAIN)
			break;
	}
	return (status);
}

/*
 * Given tunnel paramaters as supplied by a library consumer, fill in kernel
 * parameters to be passed down to the iptun control device.
 */
static dladm_status_t
i_iptun_kparams(dladm_handle_t handle, const iptun_params_t *params,
    iptun_kparams_t *ik)
{
	dladm_status_t	status;
	struct addrinfo	*ai, hints;
	iptun_kparams_t	tmpik;
	iptun_type_t	iptuntype = IPTUN_TYPE_UNKNOWN;

	(void) memset(ik, 0, sizeof (*ik));

	ik->iptun_kparam_linkid = params->iptun_param_linkid;

	if (params->iptun_param_flags & IPTUN_PARAM_TYPE) {
		ik->iptun_kparam_type = iptuntype = params->iptun_param_type;
		ik->iptun_kparam_flags |= IPTUN_KPARAM_TYPE;
	}

	if (params->iptun_param_flags & (IPTUN_PARAM_LADDR|IPTUN_PARAM_RADDR)) {
		if (iptuntype == IPTUN_TYPE_UNKNOWN) {
			/*
			 * We need to get the type of this existing tunnel in
			 * order to validate and/or look up the right kind of
			 * IP address.
			 */
			tmpik.iptun_kparam_linkid = params->iptun_param_linkid;
			status = i_iptun_ioctl(handle, IPTUN_INFO, &tmpik);
			if (status != DLADM_STATUS_OK)
				return (status);
			iptuntype = tmpik.iptun_kparam_type;
		}

		(void) memset(&hints, 0, sizeof (hints));
		switch (iptuntype) {
		case IPTUN_TYPE_IPV4:
		case IPTUN_TYPE_6TO4:
			hints.ai_family = AF_INET;
			break;
		case IPTUN_TYPE_IPV6:
			hints.ai_family = AF_INET6;
			break;
		case IPTUN_TYPE_UNKNOWN:
			return (DLADM_STATUS_BADIPTUNLADDR);
		}
	}

	if (params->iptun_param_flags & IPTUN_PARAM_LADDR) {
		if (getaddrinfo(params->iptun_param_laddr, NULL, &hints, &ai) !=
		    0)
			return (DLADM_STATUS_BADIPTUNLADDR);
		if (ai->ai_next != NULL) {
			freeaddrinfo(ai);
			return (DLADM_STATUS_BADIPTUNLADDR);
		}
		(void) memcpy(&ik->iptun_kparam_laddr, ai->ai_addr,
		    ai->ai_addrlen);
		ik->iptun_kparam_flags |= IPTUN_KPARAM_LADDR;
		freeaddrinfo(ai);
	}

	if (params->iptun_param_flags & IPTUN_PARAM_RADDR) {
		if (getaddrinfo(params->iptun_param_raddr, NULL, &hints, &ai) !=
		    0)
			return (DLADM_STATUS_BADIPTUNRADDR);
		if (ai->ai_next != NULL) {
			freeaddrinfo(ai);
			return (DLADM_STATUS_BADIPTUNRADDR);
		}
		(void) memcpy(&ik->iptun_kparam_raddr, ai->ai_addr,
		    ai->ai_addrlen);
		ik->iptun_kparam_flags |= IPTUN_KPARAM_RADDR;
		freeaddrinfo(ai);
	}

	if (params->iptun_param_flags & IPTUN_PARAM_SECINFO) {
		ik->iptun_kparam_secinfo = params->iptun_param_secinfo;
		ik->iptun_kparam_flags |= IPTUN_KPARAM_SECINFO;
	}

	return (DLADM_STATUS_OK);
}

/*
 * The inverse of i_iptun_kparams().  Given kernel tunnel paramaters as
 * returned from an IPTUN_INFO ioctl, fill in tunnel parameters.
 */
static dladm_status_t
i_iptun_params(const iptun_kparams_t *ik, iptun_params_t *params)
{
	socklen_t salen;

	(void) memset(params, 0, sizeof (*params));

	params->iptun_param_linkid = ik->iptun_kparam_linkid;

	if (ik->iptun_kparam_flags & IPTUN_KPARAM_TYPE) {
		params->iptun_param_type = ik->iptun_kparam_type;
		params->iptun_param_flags |= IPTUN_PARAM_TYPE;
	}

	if (ik->iptun_kparam_flags & IPTUN_KPARAM_LADDR) {
		salen = ik->iptun_kparam_laddr.ss_family == AF_INET ?
		    sizeof (struct sockaddr_in) : sizeof (struct sockaddr_in6);
		if (getnameinfo((const struct sockaddr *)
		    &ik->iptun_kparam_laddr, salen, params->iptun_param_laddr,
		    sizeof (params->iptun_param_laddr), NULL, 0,
		    NI_NUMERICHOST) != 0) {
			return (DLADM_STATUS_BADIPTUNLADDR);
		}
		params->iptun_param_flags |= IPTUN_PARAM_LADDR;
	}

	if (ik->iptun_kparam_flags & IPTUN_KPARAM_RADDR) {
		salen = ik->iptun_kparam_raddr.ss_family == AF_INET ?
		    sizeof (struct sockaddr_in) : sizeof (struct sockaddr_in6);
		if (getnameinfo((const struct sockaddr *)
		    &ik->iptun_kparam_raddr, salen, params->iptun_param_raddr,
		    sizeof (params->iptun_param_raddr), NULL, 0,
		    NI_NUMERICHOST) != 0) {
			return (DLADM_STATUS_BADIPTUNRADDR);
		}
		params->iptun_param_flags |= IPTUN_PARAM_RADDR;
	}

	if (ik->iptun_kparam_flags & IPTUN_KPARAM_SECINFO) {
		params->iptun_param_secinfo = ik->iptun_kparam_secinfo;
		params->iptun_param_flags |= IPTUN_PARAM_SECINFO;
	}

	if (ik->iptun_kparam_flags & IPTUN_KPARAM_IMPLICIT)
		params->iptun_param_flags |= IPTUN_PARAM_IMPLICIT;

	if (ik->iptun_kparam_flags & IPTUN_KPARAM_IPSECPOL)
		params->iptun_param_flags |= IPTUN_PARAM_IPSECPOL;

	return (DLADM_STATUS_OK);
}

dladm_status_t
i_iptun_get_sysparams(dladm_handle_t handle, iptun_params_t *params)
{
	dladm_status_t	status = DLADM_STATUS_OK;
	iptun_kparams_t	ik;

	ik.iptun_kparam_linkid = params->iptun_param_linkid;
	status = i_iptun_ioctl(handle, IPTUN_INFO, &ik);
	if (status == DLADM_STATUS_OK)
		status = i_iptun_params(&ik, params);
	return (status);
}

/*
 * Read tunnel parameters from persistent storage.  Note that the tunnel type
 * is the only thing which must always be in the configuratioh.  All other
 * parameters (currently the source and destination addresses) may or may not
 * have been configured, and therefore may not have been set.
 */
static dladm_status_t
i_iptun_get_dbparams(dladm_handle_t handle, iptun_params_t *params)
{
	dladm_status_t		status;
	dladm_conf_t		conf;
	datalink_class_t	class;
	uint64_t		temp;

	/* First, make sure that this is an IP tunnel. */
	if ((status = dladm_datalink_id2info(handle, params->iptun_param_linkid,
	    NULL, &class, NULL, NULL, 0)) != DLADM_STATUS_OK)
		return (status);
	if (class != DATALINK_CLASS_IPTUN)
		return (DLADM_STATUS_LINKINVAL);

	if ((status = dladm_getsnap_conf(handle, params->iptun_param_linkid,
	    &conf)) != DLADM_STATUS_OK) {
		return (status);
	}

	params->iptun_param_flags = 0;

	if ((status = dladm_get_conf_field(handle, conf, IPTUN_CONF_TYPE, &temp,
	    sizeof (temp))) != DLADM_STATUS_OK)
		goto done;
	params->iptun_param_type = (iptun_type_t)temp;
	params->iptun_param_flags |= IPTUN_PARAM_TYPE;

	if (dladm_get_conf_field(handle, conf, IPTUN_CONF_LADDR,
	    params->iptun_param_laddr, sizeof (params->iptun_param_laddr)) ==
	    DLADM_STATUS_OK)
		params->iptun_param_flags |= IPTUN_PARAM_LADDR;

	if (dladm_get_conf_field(handle, conf, IPTUN_CONF_RADDR,
	    params->iptun_param_raddr, sizeof (params->iptun_param_raddr)) ==
	    DLADM_STATUS_OK)
		params->iptun_param_flags |= IPTUN_PARAM_RADDR;

done:
	dladm_destroy_conf(handle, conf);
	return (status);
}

static dladm_status_t
i_iptun_create_sys(dladm_handle_t handle, iptun_params_t *params)
{
	iptun_kparams_t	ik;
	dladm_status_t	status = DLADM_STATUS_OK;

	/* The tunnel type is required for creation. */
	if (!(params->iptun_param_flags & IPTUN_PARAM_TYPE))
		return (DLADM_STATUS_IPTUNTYPEREQD);

	if ((status = i_iptun_kparams(handle, params, &ik)) == DLADM_STATUS_OK)
		status = i_iptun_ioctl(handle, IPTUN_CREATE, &ik);
	return (status);
}

static dladm_status_t
i_iptun_create_db(dladm_handle_t handle, const char *name,
    iptun_params_t *params, uint32_t media)
{
	dladm_conf_t	conf;
	dladm_status_t	status;
	uint64_t	storage;

	status = dladm_create_conf(handle, name, params->iptun_param_linkid,
	    DATALINK_CLASS_IPTUN, media, &conf);
	if (status != DLADM_STATUS_OK)
		return (status);

	assert(params->iptun_param_flags & IPTUN_PARAM_TYPE);
	storage = params->iptun_param_type;
	status = dladm_set_conf_field(handle, conf, IPTUN_CONF_TYPE,
	    DLADM_TYPE_UINT64, &storage);
	if (status != DLADM_STATUS_OK)
		goto done;

	if (params->iptun_param_flags & IPTUN_PARAM_LADDR) {
		status = dladm_set_conf_field(handle, conf, IPTUN_CONF_LADDR,
		    DLADM_TYPE_STR, params->iptun_param_laddr);
		if (status != DLADM_STATUS_OK)
			goto done;
	}

	if (params->iptun_param_flags & IPTUN_PARAM_RADDR) {
		status = dladm_set_conf_field(handle, conf, IPTUN_CONF_RADDR,
		    DLADM_TYPE_STR, params->iptun_param_raddr);
		if (status != DLADM_STATUS_OK)
			goto done;
	}

	status = dladm_write_conf(handle, conf);

done:
	dladm_destroy_conf(handle, conf);
	return (status);
}

static dladm_status_t
i_iptun_delete_sys(dladm_handle_t handle, datalink_id_t linkid)
{
	dladm_status_t status;

	status = i_iptun_ioctl(handle, IPTUN_DELETE, &linkid);
	if (status != DLADM_STATUS_OK)
		return (status);
	(void) dladm_destroy_datalink_id(handle, linkid, DLADM_OPT_ACTIVE);
	return (DLADM_STATUS_OK);
}

static dladm_status_t
i_iptun_modify_sys(dladm_handle_t handle, const iptun_params_t *params)
{
	iptun_kparams_t	ik;
	dladm_status_t	status;

	if ((status = i_iptun_kparams(handle, params, &ik)) == DLADM_STATUS_OK)
		status = i_iptun_ioctl(handle, IPTUN_MODIFY, &ik);
	return (status);
}

static dladm_status_t
i_iptun_modify_db(dladm_handle_t handle, const iptun_params_t *params)
{
	dladm_conf_t	conf;
	dladm_status_t	status;

	assert(params->iptun_param_flags &
	    (IPTUN_PARAM_LADDR|IPTUN_PARAM_RADDR));

	/*
	 * The only parameters that can be modified persistently are the local
	 * and remote addresses.
	 */
	if (params->iptun_param_flags & ~(IPTUN_PARAM_LADDR|IPTUN_PARAM_RADDR))
		return (DLADM_STATUS_BADARG);

	status = dladm_open_conf(handle, params->iptun_param_linkid, &conf);
	if (status != DLADM_STATUS_OK)
		return (status);

	if (params->iptun_param_flags & IPTUN_PARAM_LADDR) {
		status = dladm_set_conf_field(handle, conf, IPTUN_CONF_LADDR,
		    DLADM_TYPE_STR, (void *)params->iptun_param_laddr);
		if (status != DLADM_STATUS_OK)
			goto done;
	}

	if (params->iptun_param_flags & IPTUN_PARAM_RADDR) {
		status = dladm_set_conf_field(handle, conf, IPTUN_CONF_RADDR,
		    DLADM_TYPE_STR, (void *)params->iptun_param_raddr);
		if (status != DLADM_STATUS_OK)
			goto done;
	}

	status = dladm_write_conf(handle, conf);

done:
	dladm_destroy_conf(handle, conf);
	return (status);
}

dladm_status_t
dladm_iptun_create(dladm_handle_t handle, const char *name,
    iptun_params_t *params, uint32_t flags)
{
	dladm_status_t	status;
	uint32_t	linkmgmt_flags = flags;
	uint32_t	media;

	if (!(params->iptun_param_flags & IPTUN_PARAM_TYPE))
		return (DLADM_STATUS_IPTUNTYPEREQD);

	switch (params->iptun_param_type) {
	case IPTUN_TYPE_IPV4:
		media = DL_IPV4;
		break;
	case IPTUN_TYPE_IPV6:
		media = DL_IPV6;
		break;
	case IPTUN_TYPE_6TO4:
		media = DL_6TO4;
		break;
	default:
		return (DLADM_STATUS_IPTUNTYPE);
	}

	status = dladm_create_datalink_id(handle, name, DATALINK_CLASS_IPTUN,
	    media, linkmgmt_flags, &params->iptun_param_linkid);
	if (status != DLADM_STATUS_OK)
		return (status);

	if (flags & DLADM_OPT_PERSIST) {
		status = i_iptun_create_db(handle, name, params, media);
		if (status != DLADM_STATUS_OK)
			goto done;
	}

	if (flags & DLADM_OPT_ACTIVE) {
		status = i_iptun_create_sys(handle, params);
		if (status != DLADM_STATUS_OK && (flags & DLADM_OPT_PERSIST)) {
			(void) dladm_remove_conf(handle,
			    params->iptun_param_linkid);
		}
	}

done:
	if (status != DLADM_STATUS_OK) {
		(void) dladm_destroy_datalink_id(handle,
		    params->iptun_param_linkid, flags);
	}
	return (status);
}

dladm_status_t
dladm_iptun_delete(dladm_handle_t handle, datalink_id_t linkid, uint32_t flags)
{
	dladm_status_t		status;
	datalink_class_t	class;

	/* First, make sure that this is an IP tunnel. */
	if ((status = dladm_datalink_id2info(handle, linkid, NULL, &class, NULL,
	    NULL, 0)) != DLADM_STATUS_OK)
		return (status);
	if (class != DATALINK_CLASS_IPTUN)
		return (DLADM_STATUS_LINKINVAL);

	if (flags & DLADM_OPT_ACTIVE) {
		/*
		 * Note that if i_iptun_delete_sys() fails with
		 * DLADM_STATUS_NOTFOUND and the caller also wishes to delete
		 * the persistent configuration, we still fall through to the
		 * DLADM_OPT_PERSIST case in case the tunnel only exists
		 * persistently.
		 */
		status = i_iptun_delete_sys(handle, linkid);
		if (status != DLADM_STATUS_OK &&
		    (status != DLADM_STATUS_NOTFOUND ||
		    !(flags & DLADM_OPT_PERSIST)))
			return (status);
	}

	if (flags & DLADM_OPT_PERSIST) {
		(void) dladm_remove_conf(handle, linkid);
		(void) dladm_destroy_datalink_id(handle, linkid,
		    DLADM_OPT_PERSIST);
	}
	return (DLADM_STATUS_OK);
}

dladm_status_t
dladm_iptun_modify(dladm_handle_t handle, const iptun_params_t *params,
    uint32_t flags)
{
	dladm_status_t	status = DLADM_STATUS_OK;
	iptun_params_t	old_params;

	/*
	 * We can only modify the tunnel source, tunnel destination, or IPsec
	 * policy.
	 */
	if (!(params->iptun_param_flags &
	    (IPTUN_PARAM_LADDR|IPTUN_PARAM_RADDR|IPTUN_PARAM_SECINFO)))
		return (DLADM_STATUS_BADARG);

	if (flags & DLADM_OPT_PERSIST) {
		/*
		 * Before we change the database, save the old configuration
		 * so that we can revert back if an error occurs.
		 */
		old_params.iptun_param_linkid = params->iptun_param_linkid;
		status = i_iptun_get_dbparams(handle, &old_params);
		if (status != DLADM_STATUS_OK)
			return (status);
		/* we'll only need to revert the parameters being modified */
		old_params.iptun_param_flags = params->iptun_param_flags;

		status = i_iptun_modify_db(handle, params);
		if (status != DLADM_STATUS_OK)
			return (status);
	}

	if (flags & DLADM_OPT_ACTIVE) {
		status = i_iptun_modify_sys(handle, params);
		if (status != DLADM_STATUS_OK && (flags & DLADM_OPT_PERSIST)) {
			(void) i_iptun_modify_db(handle, &old_params);
		}
	}

	return (status);
}

dladm_status_t
dladm_iptun_getparams(dladm_handle_t handle, iptun_params_t *params,
    uint32_t flags)
{
	if (flags == DLADM_OPT_ACTIVE)
		return (i_iptun_get_sysparams(handle, params));
	else if (flags == DLADM_OPT_PERSIST)
		return (i_iptun_get_dbparams(handle, params));
	else
		return (DLADM_STATUS_BADARG);
}

static int
i_iptun_up(dladm_handle_t handle, datalink_id_t linkid, void *arg)
{
	dladm_status_t	*statusp = arg;
	dladm_status_t	status;
	iptun_params_t	params;
	boolean_t	id_up = B_FALSE;

	status = dladm_up_datalink_id(handle, linkid);
	if (status != DLADM_STATUS_OK)
		goto done;
	id_up = B_TRUE;

	(void) memset(&params, 0, sizeof (params));

	params.iptun_param_linkid = linkid;
	if ((status = i_iptun_get_dbparams(handle, &params)) == DLADM_STATUS_OK)
		status = i_iptun_create_sys(handle, &params);
done:
	if (statusp != NULL)
		*statusp = status;
	if (status != DLADM_STATUS_OK && id_up) {
		(void) dladm_destroy_datalink_id(handle, linkid,
		    DLADM_OPT_ACTIVE);
	}
	return (DLADM_WALK_CONTINUE);
}

static int
i_iptun_down(dladm_handle_t handle, datalink_id_t linkid, void *arg)
{
	dladm_status_t	*statusp = arg;
	dladm_status_t	status;

	status = i_iptun_delete_sys(handle, linkid);
	if (statusp != NULL)
		*statusp = status;
	return (DLADM_WALK_CONTINUE);
}

/* ARGSUSED */
dladm_status_t
dladm_iptun_up(dladm_handle_t handle, datalink_id_t linkid)
{
	dladm_status_t status = DLADM_STATUS_OK;

	if (linkid == DATALINK_ALL_LINKID) {
		(void) dladm_walk_datalink_id(i_iptun_up, handle, NULL,
		    DATALINK_CLASS_IPTUN, DATALINK_ANY_MEDIATYPE,
		    DLADM_OPT_PERSIST);
	} else {
		(void) i_iptun_up(handle, linkid, &status);
	}
	return (status);
}

dladm_status_t
dladm_iptun_down(dladm_handle_t handle, datalink_id_t linkid)
{
	dladm_status_t status = DLADM_STATUS_OK;

	if (linkid == DATALINK_ALL_LINKID) {
		(void) dladm_walk_datalink_id(i_iptun_down, handle, NULL,
		    DATALINK_CLASS_IPTUN, DATALINK_ANY_MEDIATYPE,
		    DLADM_OPT_ACTIVE);
	} else {
		(void) i_iptun_down(handle, linkid, &status);
	}
	return (status);
}

dladm_status_t
dladm_iptun_set6to4relay(dladm_handle_t handle, struct in_addr *relay)
{
	return (i_iptun_ioctl(handle, IPTUN_SET_6TO4RELAY, relay));
}

dladm_status_t
dladm_iptun_get6to4relay(dladm_handle_t handle, struct in_addr *relay)
{
	return (i_iptun_ioctl(handle, IPTUN_GET_6TO4RELAY, relay));
}