Print this page
OS-478 -- lint
OS-249
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/lib/libdladm/common/libdlmgmt.c
+++ new/usr/src/lib/libdladm/common/libdlmgmt.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 + * Copyright (c) 2011, Joyent Inc. All rights reserved.
23 24 */
24 25
25 26 #include <door.h>
26 27 #include <errno.h>
27 28 #include <assert.h>
28 29 #include <stdio.h>
29 30 #include <stdlib.h>
30 31 #include <unistd.h>
31 32 #include <string.h>
32 33 #include <strings.h>
33 34 #include <zone.h>
34 35 #include <sys/types.h>
35 36 #include <sys/stat.h>
36 37 #include <sys/aggr.h>
37 38 #include <sys/mman.h>
38 39 #include <fcntl.h>
39 40 #include <libdladm.h>
40 41 #include <libdladm_impl.h>
41 42 #include <libdllink.h>
42 43 #include <libdlmgmt.h>
43 44
44 45 /*
45 46 * Table of data type sizes indexed by dladm_datatype_t.
46 47 */
47 48 static size_t dladm_datatype_size[] = {
48 49 0, /* DLADM_TYPE_STR, use strnlen() */
49 50 sizeof (boolean_t), /* DLADM_TYPE_BOOLEAN */
50 51 sizeof (uint64_t) /* DLADM_TYPE_UINT64 */
51 52 };
52 53
53 54 static dladm_status_t
54 55 dladm_door_call(dladm_handle_t handle, void *arg, size_t asize, void *rbuf,
55 56 size_t *rsizep)
56 57 {
57 58 door_arg_t darg;
58 59 int door_fd;
59 60 dladm_status_t status;
60 61 boolean_t reopen = B_FALSE;
61 62
62 63 darg.data_ptr = arg;
63 64 darg.data_size = asize;
64 65 darg.desc_ptr = NULL;
65 66 darg.desc_num = 0;
66 67 darg.rbuf = rbuf;
67 68 darg.rsize = *rsizep;
68 69
69 70 reopen:
70 71 /* The door descriptor is opened if it isn't already */
71 72 if ((status = dladm_door_fd(handle, &door_fd)) != DLADM_STATUS_OK)
72 73 return (status);
73 74 if (door_call(door_fd, &darg) == -1) {
74 75 /*
75 76 * Stale door descriptor is possible if dlmgmtd was re-started
76 77 * since last door_fd open so try re-opening door file.
77 78 */
78 79 if (!reopen && errno == EBADF) {
79 80 (void) close(handle->door_fd);
80 81 handle->door_fd = -1;
81 82 reopen = B_TRUE;
82 83 goto reopen;
83 84 }
84 85 status = dladm_errno2status(errno);
85 86 }
86 87 if (status != DLADM_STATUS_OK)
87 88 return (status);
88 89
89 90 if (darg.rbuf != rbuf) {
90 91 /*
91 92 * The size of the input rbuf is not big enough so that
92 93 * the door allocate the rbuf itself. In this case, return
93 94 * the required size to the caller.
94 95 */
95 96 (void) munmap(darg.rbuf, darg.rsize);
96 97 *rsizep = darg.rsize;
97 98 return (DLADM_STATUS_TOOSMALL);
98 99 } else if (darg.rsize != *rsizep) {
99 100 return (DLADM_STATUS_FAILED);
100 101 }
101 102
102 103 return (dladm_errno2status(((dlmgmt_retval_t *)rbuf)->lr_err));
103 104 }
104 105
105 106 /*
106 107 * Allocate a new linkid with the given name. Return the new linkid.
107 108 */
108 109 dladm_status_t
109 110 dladm_create_datalink_id(dladm_handle_t handle, const char *link,
110 111 datalink_class_t class, uint32_t media, uint32_t flags,
111 112 datalink_id_t *linkidp)
112 113 {
113 114 dlmgmt_door_createid_t createid;
114 115 dlmgmt_createid_retval_t retval;
115 116 uint32_t dlmgmt_flags;
116 117 dladm_status_t status;
117 118 size_t sz = sizeof (retval);
118 119
119 120 if (link == NULL || class == DATALINK_CLASS_ALL ||
120 121 !(flags & (DLADM_OPT_ACTIVE | DLADM_OPT_PERSIST)) ||
121 122 linkidp == NULL) {
122 123 return (DLADM_STATUS_BADARG);
123 124 }
124 125
125 126 dlmgmt_flags = (flags & DLADM_OPT_ACTIVE) ? DLMGMT_ACTIVE : 0;
126 127 dlmgmt_flags |= (flags & DLADM_OPT_PERSIST) ? DLMGMT_PERSIST : 0;
127 128
128 129 (void) strlcpy(createid.ld_link, link, MAXLINKNAMELEN);
129 130 createid.ld_class = class;
130 131 createid.ld_media = media;
131 132 createid.ld_flags = dlmgmt_flags;
132 133 createid.ld_cmd = DLMGMT_CMD_CREATE_LINKID;
133 134 createid.ld_prefix = (flags & DLADM_OPT_PREFIX);
134 135
135 136 if ((status = dladm_door_call(handle, &createid, sizeof (createid),
136 137 &retval, &sz)) == DLADM_STATUS_OK) {
137 138 *linkidp = retval.lr_linkid;
138 139 }
139 140 return (status);
140 141 }
141 142
142 143 /*
143 144 * Destroy the given link ID.
144 145 */
145 146 dladm_status_t
146 147 dladm_destroy_datalink_id(dladm_handle_t handle, datalink_id_t linkid,
147 148 uint32_t flags)
148 149 {
149 150 dlmgmt_door_destroyid_t destroyid;
150 151 dlmgmt_destroyid_retval_t retval;
151 152 uint32_t dlmgmt_flags;
152 153 size_t sz = sizeof (retval);
153 154
154 155 dlmgmt_flags = (flags & DLADM_OPT_ACTIVE) ? DLMGMT_ACTIVE : 0;
155 156 dlmgmt_flags |= ((flags & DLADM_OPT_PERSIST) ? DLMGMT_PERSIST : 0);
156 157
157 158 destroyid.ld_cmd = DLMGMT_CMD_DESTROY_LINKID;
158 159 destroyid.ld_linkid = linkid;
159 160 destroyid.ld_flags = dlmgmt_flags;
160 161
161 162 return (dladm_door_call(handle, &destroyid, sizeof (destroyid),
162 163 &retval, &sz));
163 164 }
164 165
165 166 /*
166 167 * Remap a given link ID to a new name.
167 168 */
168 169 dladm_status_t
169 170 dladm_remap_datalink_id(dladm_handle_t handle, datalink_id_t linkid,
170 171 const char *link)
171 172 {
172 173 dlmgmt_door_remapid_t remapid;
173 174 dlmgmt_remapid_retval_t retval;
174 175 size_t sz = sizeof (retval);
175 176
176 177 remapid.ld_cmd = DLMGMT_CMD_REMAP_LINKID;
177 178 remapid.ld_linkid = linkid;
178 179 (void) strlcpy(remapid.ld_link, link, MAXLINKNAMELEN);
179 180
180 181 return (dladm_door_call(handle, &remapid, sizeof (remapid),
181 182 &retval, &sz));
182 183 }
183 184
184 185 /*
185 186 * Make a given link ID active.
186 187 */
187 188 dladm_status_t
188 189 dladm_up_datalink_id(dladm_handle_t handle, datalink_id_t linkid)
189 190 {
190 191 dlmgmt_door_upid_t upid;
191 192 dlmgmt_upid_retval_t retval;
192 193 size_t sz = sizeof (retval);
193 194
194 195 upid.ld_cmd = DLMGMT_CMD_UP_LINKID;
195 196 upid.ld_linkid = linkid;
196 197
197 198 return (dladm_door_call(handle, &upid, sizeof (upid), &retval, &sz));
198 199 }
199 200
200 201 /*
201 202 * Create a new link with the given name. Return the new link's handle
202 203 */
203 204 dladm_status_t
204 205 dladm_create_conf(dladm_handle_t handle, const char *link, datalink_id_t linkid,
205 206 datalink_class_t class, uint32_t media, dladm_conf_t *confp)
206 207 {
207 208 dlmgmt_door_createconf_t createconf;
208 209 dlmgmt_createconf_retval_t retval;
209 210 dladm_status_t status;
210 211 size_t sz = sizeof (retval);
211 212
212 213 if (link == NULL || confp == NULL)
213 214 return (DLADM_STATUS_BADARG);
214 215
215 216 (void) strlcpy(createconf.ld_link, link, MAXLINKNAMELEN);
216 217 createconf.ld_class = class;
217 218 createconf.ld_media = media;
218 219 createconf.ld_linkid = linkid;
219 220 createconf.ld_cmd = DLMGMT_CMD_CREATECONF;
220 221 confp->ds_confid = DLADM_INVALID_CONF;
221 222
222 223 if ((status = dladm_door_call(handle, &createconf, sizeof (createconf),
223 224 &retval, &sz)) == DLADM_STATUS_OK) {
224 225 confp->ds_readonly = B_FALSE;
225 226 confp->ds_confid = retval.lr_confid;
226 227 }
227 228 return (status);
228 229 }
229 230
230 231 /*
231 232 * An active physical link reported by the dlmgmtd daemon might not be active
232 233 * anymore as this link might be removed during system shutdown. Check its
233 234 * real status by calling dladm_phys_info().
234 235 */
235 236 dladm_status_t
236 237 i_dladm_phys_status(dladm_handle_t handle, datalink_id_t linkid,
237 238 uint32_t *flagsp)
238 239 {
239 240 dladm_phys_attr_t dpa;
240 241 dladm_status_t status;
241 242
242 243 assert((*flagsp) & DLMGMT_ACTIVE);
243 244
244 245 status = dladm_phys_info(handle, linkid, &dpa, DLADM_OPT_ACTIVE);
245 246 if (status == DLADM_STATUS_NOTFOUND) {
246 247 /*
247 248 * No active status, this link was removed. Update its status
248 249 * in the daemon and delete all active linkprops.
249 250 *
250 251 * Note that the operation could fail. If it does, return
251 252 * failure now since otherwise dladm_set_linkprop() might
252 253 * call back to i_dladm_phys_status() recursively.
253 254 */
254 255 if ((status = dladm_destroy_datalink_id(handle, linkid,
255 256 DLADM_OPT_ACTIVE)) != DLADM_STATUS_OK)
256 257 return (status);
257 258
258 259 (void) dladm_set_linkprop(handle, linkid, NULL, NULL, 0,
259 260 DLADM_OPT_ACTIVE);
260 261
261 262 (*flagsp) &= ~DLMGMT_ACTIVE;
262 263 status = DLADM_STATUS_OK;
263 264 }
264 265 return (status);
265 266 }
266 267
267 268 /*
268 269 * Walk each entry in the data link configuration repository and
269 270 * call fn on the linkid and arg.
270 271 */
271 272 dladm_status_t
272 273 dladm_walk_datalink_id(int (*fn)(dladm_handle_t, datalink_id_t, void *),
273 274 dladm_handle_t handle, void *argp, datalink_class_t class,
274 275 datalink_media_t dmedia, uint32_t flags)
275 276 {
276 277 dlmgmt_door_getnext_t getnext;
277 278 dlmgmt_getnext_retval_t retval;
278 279 uint32_t dlmgmt_flags;
279 280 datalink_id_t linkid = DATALINK_INVALID_LINKID;
280 281 dladm_status_t status = DLADM_STATUS_OK;
281 282 size_t sz = sizeof (retval);
282 283
283 284 if (fn == NULL)
284 285 return (DLADM_STATUS_BADARG);
285 286
286 287 dlmgmt_flags = (flags & DLADM_OPT_ACTIVE) ? DLMGMT_ACTIVE : 0;
287 288 dlmgmt_flags |= ((flags & DLADM_OPT_PERSIST) ? DLMGMT_PERSIST : 0);
288 289
289 290 getnext.ld_cmd = DLMGMT_CMD_GETNEXT;
290 291 getnext.ld_class = class;
291 292 getnext.ld_dmedia = dmedia;
292 293 getnext.ld_flags = dlmgmt_flags;
293 294
294 295 do {
295 296 getnext.ld_linkid = linkid;
296 297 if ((status = dladm_door_call(handle, &getnext,
297 298 sizeof (getnext), &retval, &sz)) != DLADM_STATUS_OK) {
298 299 /*
299 300 * Done with walking. If no next datalink is found,
300 301 * return success.
301 302 */
302 303 if (status == DLADM_STATUS_NOTFOUND)
303 304 status = DLADM_STATUS_OK;
304 305 break;
305 306 }
306 307
307 308 linkid = retval.lr_linkid;
308 309 if ((retval.lr_class == DATALINK_CLASS_PHYS) &&
309 310 (retval.lr_flags & DLMGMT_ACTIVE)) {
310 311 /*
311 312 * An active physical link reported by the dlmgmtd
312 313 * daemon might not be active anymore. Check its
313 314 * real status.
314 315 */
315 316 if (i_dladm_phys_status(handle, linkid,
316 317 &retval.lr_flags) != DLADM_STATUS_OK) {
317 318 continue;
318 319 }
319 320
320 321 if (!(dlmgmt_flags & retval.lr_flags))
321 322 continue;
322 323 }
323 324
324 325 if (fn(handle, linkid, argp) == DLADM_WALK_TERMINATE)
325 326 break;
326 327 } while (linkid != DATALINK_INVALID_LINKID);
327 328
328 329 return (status);
329 330 }
330 331
331 332 /*
332 333 * Get a handle of a copy of the link configuration (kept in the daemon)
333 334 * for the given link so it can be updated later by dladm_write_conf().
334 335 */
335 336 dladm_status_t
336 337 dladm_open_conf(dladm_handle_t handle, datalink_id_t linkid,
337 338 dladm_conf_t *confp)
338 339 {
339 340 dlmgmt_door_openconf_t openconf;
340 341 dlmgmt_openconf_retval_t retval;
341 342 dladm_status_t status;
342 343 size_t sz;
343 344
344 345 if (linkid == DATALINK_INVALID_LINKID || confp == NULL)
345 346 return (DLADM_STATUS_BADARG);
346 347
347 348 sz = sizeof (retval);
348 349 openconf.ld_linkid = linkid;
349 350 openconf.ld_cmd = DLMGMT_CMD_OPENCONF;
350 351 confp->ds_confid = DLADM_INVALID_CONF;
351 352 if ((status = dladm_door_call(handle, &openconf,
352 353 sizeof (openconf), &retval, &sz)) == DLADM_STATUS_OK) {
353 354 confp->ds_readonly = B_FALSE;
354 355 confp->ds_confid = retval.lr_confid;
355 356 }
356 357
357 358 return (status);
358 359 }
359 360
360 361 /*
361 362 * Get the handle of a local snapshot of the link configuration. Note that
362 363 * any operations with this handle are read-only, i.e., one can not update
363 364 * the configuration with this handle.
364 365 */
365 366 dladm_status_t
366 367 dladm_getsnap_conf(dladm_handle_t handle, datalink_id_t linkid,
367 368 dladm_conf_t *confp)
368 369 {
369 370 dlmgmt_door_getconfsnapshot_t snapshot;
370 371 dlmgmt_getconfsnapshot_retval_t *retvalp;
371 372 char *nvlbuf;
372 373 dladm_status_t status;
373 374 int err;
374 375 size_t sz;
375 376
376 377 if (linkid == DATALINK_INVALID_LINKID || confp == NULL)
377 378 return (DLADM_STATUS_BADARG);
378 379
379 380 sz = sizeof (dlmgmt_getconfsnapshot_retval_t);
380 381 snapshot.ld_linkid = linkid;
381 382 snapshot.ld_cmd = DLMGMT_CMD_GETCONFSNAPSHOT;
382 383 again:
383 384 if ((retvalp = malloc(sz)) == NULL)
384 385 return (DLADM_STATUS_NOMEM);
385 386
386 387 if ((status = dladm_door_call(handle, &snapshot, sizeof (snapshot),
387 388 retvalp, &sz)) == DLADM_STATUS_TOOSMALL) {
388 389 free(retvalp);
389 390 goto again;
390 391 }
391 392
392 393 if (status != DLADM_STATUS_OK) {
393 394 free(retvalp);
394 395 return (status);
395 396 }
396 397
397 398 confp->ds_readonly = B_TRUE;
398 399 nvlbuf = (char *)retvalp + sizeof (dlmgmt_getconfsnapshot_retval_t);
399 400 if ((err = nvlist_unpack(nvlbuf, retvalp->lr_nvlsz,
400 401 &(confp->ds_nvl), NV_ENCODE_NATIVE)) != 0) {
401 402 status = dladm_errno2status(err);
402 403 }
403 404 free(retvalp);
404 405 return (status);
405 406 }
406 407
407 408 /*
408 409 * Commit the given link to the data link configuration repository so
409 410 * that it will persist across reboots.
410 411 */
411 412 dladm_status_t
412 413 dladm_write_conf(dladm_handle_t handle, dladm_conf_t conf)
413 414 {
414 415 dlmgmt_door_writeconf_t writeconf;
415 416 dlmgmt_writeconf_retval_t retval;
416 417 size_t sz = sizeof (retval);
417 418
418 419 if (conf.ds_confid == DLADM_INVALID_CONF)
419 420 return (DLADM_STATUS_BADARG);
420 421
421 422 if (conf.ds_readonly)
422 423 return (DLADM_STATUS_DENIED);
423 424
424 425 writeconf.ld_cmd = DLMGMT_CMD_WRITECONF;
425 426 writeconf.ld_confid = conf.ds_confid;
426 427
427 428 return (dladm_door_call(handle, &writeconf, sizeof (writeconf),
428 429 &retval, &sz));
429 430 }
430 431
431 432 /*
432 433 * Given a dladm_conf_t, get the specific configuration field
433 434 *
434 435 * If the specified dladm_conf_t is a read-only snapshot of the configuration,
435 436 * get a specific link propertie from that snapshot (nvl), otherwise, get
436 437 * the link protperty from the dlmgmtd daemon using the given confid.
437 438 */
438 439 dladm_status_t
439 440 dladm_get_conf_field(dladm_handle_t handle, dladm_conf_t conf, const char *attr,
440 441 void *attrval, size_t attrsz)
441 442 {
442 443 dladm_status_t status = DLADM_STATUS_OK;
443 444
444 445 if (attrval == NULL || attrsz == 0 || attr == NULL)
445 446 return (DLADM_STATUS_BADARG);
446 447
447 448 if (conf.ds_readonly) {
448 449 uchar_t *oattrval;
449 450 uint32_t oattrsz;
450 451 int err;
451 452
452 453 if ((err = nvlist_lookup_byte_array(conf.ds_nvl, (char *)attr,
453 454 &oattrval, &oattrsz)) != 0) {
454 455 return (dladm_errno2status(err));
455 456 }
456 457 if (oattrsz > attrsz)
457 458 return (DLADM_STATUS_TOOSMALL);
458 459
459 460 bcopy(oattrval, attrval, oattrsz);
460 461 } else {
461 462 dlmgmt_door_getattr_t getattr;
462 463 dlmgmt_getattr_retval_t retval;
463 464 size_t sz = sizeof (retval);
464 465
465 466 if (conf.ds_confid == DLADM_INVALID_CONF)
466 467 return (DLADM_STATUS_BADARG);
467 468
468 469 getattr.ld_cmd = DLMGMT_CMD_GETATTR;
469 470 getattr.ld_confid = conf.ds_confid;
470 471 (void) strlcpy(getattr.ld_attr, attr, MAXLINKATTRLEN);
471 472
472 473 if ((status = dladm_door_call(handle, &getattr,
473 474 sizeof (getattr), &retval, &sz)) != DLADM_STATUS_OK) {
474 475 return (status);
475 476 }
476 477
477 478 if (retval.lr_attrsz > attrsz)
478 479 return (DLADM_STATUS_TOOSMALL);
479 480
480 481 bcopy(retval.lr_attrval, attrval, retval.lr_attrsz);
481 482 }
482 483 return (status);
483 484 }
484 485
485 486 /*
486 487 * Get next property attribute from data link configuration repository.
487 488 * If last_attr is "", return the first property.
488 489 */
489 490 /* ARGSUSED */
490 491 dladm_status_t
491 492 dladm_getnext_conf_linkprop(dladm_handle_t handle, dladm_conf_t conf,
492 493 const char *last_attr, char *attr, void *attrval, size_t attrsz,
493 494 size_t *attrszp)
494 495 {
495 496 nvlist_t *nvl = conf.ds_nvl;
496 497 nvpair_t *last = NULL, *nvp;
497 498 uchar_t *oattrval;
498 499 uint32_t oattrsz;
499 500 int err;
500 501
501 502 if (nvl == NULL || attrval == NULL || attrsz == 0 || attr == NULL ||
502 503 !conf.ds_readonly)
503 504 return (DLADM_STATUS_BADARG);
504 505
505 506 while ((nvp = nvlist_next_nvpair(nvl, last)) != NULL) {
506 507 if (last_attr[0] == '\0')
507 508 break;
508 509 if (last != NULL && strcmp(last_attr, nvpair_name(last)) == 0)
509 510 break;
510 511 last = nvp;
511 512 }
512 513
513 514 if (nvp == NULL)
514 515 return (DLADM_STATUS_NOTFOUND);
515 516
516 517 if ((err = nvpair_value_byte_array(nvp, (uchar_t **)&oattrval,
517 518 &oattrsz)) != NULL) {
518 519 return (dladm_errno2status(err));
519 520 }
520 521
|
↓ open down ↓ |
488 lines elided |
↑ open up ↑ |
521 522 *attrszp = oattrsz;
522 523 if (oattrsz > attrsz)
523 524 return (DLADM_STATUS_TOOSMALL);
524 525
525 526 (void) strlcpy(attr, nvpair_name(nvp), MAXLINKATTRLEN);
526 527 bcopy(oattrval, attrval, oattrsz);
527 528 return (DLADM_STATUS_OK);
528 529 }
529 530
530 531 /*
531 - * Get the link ID that is associated with the given name.
532 + * Get the link ID that is associated with the given name in the current zone.
532 533 */
533 534 dladm_status_t
534 535 dladm_name2info(dladm_handle_t handle, const char *link, datalink_id_t *linkidp,
535 536 uint32_t *flagp, datalink_class_t *classp, uint32_t *mediap)
536 537 {
538 + return (dladm_zname2info(handle, NULL, link, linkidp, flagp, classp,
539 + mediap));
540 +}
541 +
542 +/*
543 + * Get the link ID that is associated with the given zone/name pair.
544 + */
545 +dladm_status_t
546 +dladm_zname2info(dladm_handle_t handle, const char *zonename, const char *link,
547 + datalink_id_t *linkidp, uint32_t *flagp, datalink_class_t *classp,
548 + uint32_t *mediap)
549 +{
537 550 dlmgmt_door_getlinkid_t getlinkid;
538 551 dlmgmt_getlinkid_retval_t retval;
539 552 datalink_id_t linkid;
540 553 dladm_status_t status;
541 554 size_t sz = sizeof (retval);
542 555
543 556 getlinkid.ld_cmd = DLMGMT_CMD_GETLINKID;
544 557 (void) strlcpy(getlinkid.ld_link, link, MAXLINKNAMELEN);
558 + if (zonename != NULL)
559 + getlinkid.ld_zoneid = getzoneidbyname(zonename);
560 + else
561 + getlinkid.ld_zoneid = -1;
545 562
546 563 if ((status = dladm_door_call(handle, &getlinkid, sizeof (getlinkid),
547 564 &retval, &sz)) != DLADM_STATUS_OK) {
548 565 return (status);
549 566 }
550 567
551 568 linkid = retval.lr_linkid;
552 569 if (retval.lr_class == DATALINK_CLASS_PHYS &&
553 570 retval.lr_flags & DLMGMT_ACTIVE) {
554 571 /*
555 572 * An active physical link reported by the dlmgmtd daemon
556 573 * might not be active anymore. Check and set its real status.
557 574 */
558 575 status = i_dladm_phys_status(handle, linkid, &retval.lr_flags);
559 576 if (status != DLADM_STATUS_OK)
560 577 return (status);
561 578 }
562 579
563 580 if (linkidp != NULL)
564 581 *linkidp = linkid;
565 582 if (flagp != NULL) {
566 583 *flagp = retval.lr_flags & DLMGMT_ACTIVE ? DLADM_OPT_ACTIVE : 0;
567 584 *flagp |= (retval.lr_flags & DLMGMT_PERSIST) ?
568 585 DLADM_OPT_PERSIST : 0;
569 586 }
570 587 if (classp != NULL)
571 588 *classp = retval.lr_class;
572 589 if (mediap != NULL)
573 590 *mediap = retval.lr_media;
574 591
575 592 return (DLADM_STATUS_OK);
576 593 }
577 594
578 595 /*
579 596 * Get the link name that is associated with the given id.
580 597 */
581 598 dladm_status_t
582 599 dladm_datalink_id2info(dladm_handle_t handle, datalink_id_t linkid,
583 600 uint32_t *flagp, datalink_class_t *classp, uint32_t *mediap, char *link,
584 601 size_t len)
585 602 {
586 603 dlmgmt_door_getname_t getname;
587 604 dlmgmt_getname_retval_t retval;
588 605 dladm_status_t status;
589 606 size_t sz = sizeof (retval);
590 607
591 608 if ((linkid == DATALINK_INVALID_LINKID) || (link != NULL && len == 0) ||
592 609 (link == NULL && len != 0)) {
593 610 return (DLADM_STATUS_BADARG);
594 611 }
595 612
596 613 getname.ld_cmd = DLMGMT_CMD_GETNAME;
597 614 getname.ld_linkid = linkid;
598 615 if ((status = dladm_door_call(handle, &getname, sizeof (getname),
599 616 &retval, &sz)) != DLADM_STATUS_OK) {
600 617 return (status);
601 618 }
602 619
603 620 if (len != 0 && (strlen(retval.lr_link) + 1 > len))
604 621 return (DLADM_STATUS_TOOSMALL);
605 622
606 623 if (retval.lr_class == DATALINK_CLASS_PHYS &&
607 624 retval.lr_flags & DLMGMT_ACTIVE) {
608 625 /*
609 626 * An active physical link reported by the dlmgmtd daemon
610 627 * might not be active anymore. Check and set its real status.
611 628 */
612 629 status = i_dladm_phys_status(handle, linkid, &retval.lr_flags);
613 630 if (status != DLADM_STATUS_OK)
614 631 return (status);
615 632 }
616 633
617 634 if (link != NULL)
618 635 (void) strlcpy(link, retval.lr_link, len);
619 636 if (classp != NULL)
620 637 *classp = retval.lr_class;
621 638 if (mediap != NULL)
622 639 *mediap = retval.lr_media;
623 640 if (flagp != NULL) {
624 641 *flagp = retval.lr_flags & DLMGMT_ACTIVE ?
625 642 DLADM_OPT_ACTIVE : 0;
626 643 *flagp |= (retval.lr_flags & DLMGMT_PERSIST) ?
627 644 DLADM_OPT_PERSIST : 0;
628 645 }
629 646 return (DLADM_STATUS_OK);
630 647 }
631 648
632 649 /*
633 650 * Set the given attr with the given attrval for the given link.
634 651 */
635 652 dladm_status_t
636 653 dladm_set_conf_field(dladm_handle_t handle, dladm_conf_t conf, const char *attr,
637 654 dladm_datatype_t type, const void *attrval)
638 655 {
639 656 dlmgmt_door_setattr_t setattr;
640 657 dlmgmt_setattr_retval_t retval;
641 658 size_t attrsz;
642 659 size_t sz = sizeof (retval);
643 660
644 661 if (attr == NULL || attrval == NULL)
645 662 return (DLADM_STATUS_BADARG);
646 663
647 664 if (conf.ds_readonly)
648 665 return (DLADM_STATUS_DENIED);
649 666
650 667 if (type == DLADM_TYPE_STR)
651 668 attrsz = strlen(attrval) + 1;
652 669 else
653 670 attrsz = dladm_datatype_size[type];
654 671
655 672 if (attrsz > MAXLINKATTRVALLEN)
656 673 return (DLADM_STATUS_TOOSMALL);
657 674
658 675 setattr.ld_cmd = DLMGMT_CMD_SETATTR;
659 676 setattr.ld_confid = conf.ds_confid;
660 677 (void) strlcpy(setattr.ld_attr, attr, MAXLINKATTRLEN);
661 678 setattr.ld_attrsz = attrsz;
662 679 setattr.ld_type = type;
663 680 bcopy(attrval, &setattr.ld_attrval, attrsz);
664 681
665 682 return (dladm_door_call(handle, &setattr, sizeof (setattr),
666 683 &retval, &sz));
667 684 }
668 685
669 686 /*
670 687 * Unset the given attr the given link.
671 688 */
672 689 dladm_status_t
673 690 dladm_unset_conf_field(dladm_handle_t handle, dladm_conf_t conf,
674 691 const char *attr)
675 692 {
676 693 dlmgmt_door_unsetattr_t unsetattr;
677 694 dlmgmt_unsetattr_retval_t retval;
678 695 size_t sz = sizeof (retval);
679 696
680 697 if (attr == NULL)
681 698 return (DLADM_STATUS_BADARG);
682 699
683 700 if (conf.ds_readonly)
684 701 return (DLADM_STATUS_DENIED);
685 702
686 703 unsetattr.ld_cmd = DLMGMT_CMD_UNSETATTR;
687 704 unsetattr.ld_confid = conf.ds_confid;
688 705 (void) strlcpy(unsetattr.ld_attr, attr, MAXLINKATTRLEN);
689 706
690 707 return (dladm_door_call(handle, &unsetattr, sizeof (unsetattr),
691 708 &retval, &sz));
692 709 }
693 710
694 711 /*
695 712 * Remove the given link ID and its entry from the data link configuration
696 713 * repository.
697 714 */
698 715 dladm_status_t
699 716 dladm_remove_conf(dladm_handle_t handle, datalink_id_t linkid)
700 717 {
701 718 dlmgmt_door_removeconf_t removeconf;
702 719 dlmgmt_removeconf_retval_t retval;
703 720 size_t sz = sizeof (retval);
704 721
705 722 removeconf.ld_cmd = DLMGMT_CMD_REMOVECONF;
706 723 removeconf.ld_linkid = linkid;
707 724
708 725 return (dladm_door_call(handle, &removeconf, sizeof (removeconf),
709 726 &retval, &sz));
710 727 }
711 728
712 729 /*
713 730 * Free the contents of the link structure.
714 731 */
715 732 void
716 733 dladm_destroy_conf(dladm_handle_t handle, dladm_conf_t conf)
717 734 {
718 735 dlmgmt_door_destroyconf_t dconf;
719 736 dlmgmt_destroyconf_retval_t retval;
720 737 size_t sz = sizeof (retval);
721 738
722 739 if (conf.ds_readonly) {
723 740 nvlist_free(conf.ds_nvl);
724 741 } else {
725 742 if (conf.ds_confid == DLADM_INVALID_CONF)
726 743 return;
727 744
728 745 dconf.ld_cmd = DLMGMT_CMD_DESTROYCONF;
729 746 dconf.ld_confid = conf.ds_confid;
730 747
731 748 (void) dladm_door_call(handle, &dconf, sizeof (dconf),
732 749 &retval, &sz);
733 750 }
734 751 }
735 752
736 753 dladm_status_t
737 754 dladm_zone_boot(dladm_handle_t handle, zoneid_t zoneid)
738 755 {
739 756 dlmgmt_door_zoneboot_t zoneboot;
740 757 dlmgmt_zoneboot_retval_t retval;
741 758 size_t sz = sizeof (retval);
742 759
743 760 zoneboot.ld_cmd = DLMGMT_CMD_ZONEBOOT;
744 761 zoneboot.ld_zoneid = zoneid;
745 762 return (dladm_door_call(handle, &zoneboot, sizeof (zoneboot),
746 763 &retval, &sz));
747 764 }
748 765
749 766 dladm_status_t
750 767 dladm_zone_halt(dladm_handle_t handle, zoneid_t zoneid)
751 768 {
752 769 dlmgmt_door_zonehalt_t zonehalt;
753 770 dlmgmt_zonehalt_retval_t retval;
754 771 size_t sz = sizeof (retval);
755 772
756 773 zonehalt.ld_cmd = DLMGMT_CMD_ZONEHALT;
757 774 zonehalt.ld_zoneid = zoneid;
758 775 return (dladm_door_call(handle, &zonehalt, sizeof (zonehalt),
759 776 &retval, &sz));
760 777 }
|
↓ open down ↓ |
206 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX