Print this page
usr/src/cmd/dlmgmtd/dlmgmt_door.c
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/dlmgmtd/dlmgmt_door.c
+++ new/usr/src/cmd/dlmgmtd/dlmgmt_door.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 *
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.
|
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
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 /*
23 23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 * Copyright 2019 Joyent, Inc.
25 + * Copyright 2023 Oxide Computer Company
25 26 */
26 27
27 28 /*
28 29 * Main door handler functions used by dlmgmtd to process the different door
29 30 * call requests. Door call requests can come from the user-land applications,
30 31 * or from the kernel.
31 32 *
32 33 * Note on zones handling:
33 34 *
34 35 * There are two zoneid's associated with a link. One is the zoneid of the
35 36 * zone in which the link was created (ll_zoneid in the dlmgmt_link_t), and
36 37 * the other is the zoneid of the zone where the link is currently assigned
37 38 * (the "zone" link property). The two can be different if a datalink is
38 39 * created in the global zone and subsequently assigned to a non-global zone
39 40 * via zonecfg or via explicitly setting the "zone" link property.
40 41 *
41 42 * Door clients can see links that were created in their zone, and links that
42 43 * are currently assigned to their zone. Door clients in a zone can only
43 44 * modify links that were created in their zone.
44 45 *
45 46 * The datalink ID space is global, while each zone has its own datalink name
46 47 * space. This allows each zone to have complete freedom over the names that
47 48 * they assign to links created within the zone.
48 49 */
49 50
50 51 #include <assert.h>
51 52 #include <alloca.h>
52 53 #include <errno.h>
53 54 #include <priv_utils.h>
54 55 #include <stdlib.h>
55 56 #include <strings.h>
56 57 #include <syslog.h>
57 58 #include <sys/sysevent/eventdefs.h>
58 59 #include <zone.h>
59 60 #include <libsysevent.h>
60 61 #include <libdlmgmt.h>
61 62 #include <librcm.h>
62 63 #include <unistd.h>
63 64 #include "dlmgmt_impl.h"
64 65
65 66 typedef void dlmgmt_door_handler_t(void *, void *, size_t *, zoneid_t,
66 67 ucred_t *);
67 68
68 69 typedef struct dlmgmt_door_info_s {
69 70 uint_t di_cmd;
70 71 size_t di_reqsz;
71 72 size_t di_acksz;
72 73 dlmgmt_door_handler_t *di_handler;
73 74 } dlmgmt_door_info_t;
74 75
75 76 /*
76 77 * Check if the caller has the required privileges to operate on a link of the
77 78 * given class.
78 79 */
79 80 static int
80 81 dlmgmt_checkprivs(datalink_class_t class, ucred_t *cred)
81 82 {
82 83 const priv_set_t *eset;
83 84
84 85 eset = ucred_getprivset(cred, PRIV_EFFECTIVE);
85 86 if (eset != NULL && ((class == DATALINK_CLASS_IPTUN &&
86 87 priv_ismember(eset, PRIV_SYS_IPTUN_CONFIG)) ||
87 88 priv_ismember(eset, PRIV_SYS_DL_CONFIG) ||
88 89 priv_ismember(eset, PRIV_SYS_NET_CONFIG)))
89 90 return (0);
90 91 return (EACCES);
91 92 }
92 93
93 94 static dlmgmt_link_t *
94 95 dlmgmt_getlink_by_dev(char *devname, zoneid_t zoneid)
95 96 {
96 97 dlmgmt_link_t *linkp = avl_first(&dlmgmt_id_avl);
97 98
98 99 for (; linkp != NULL; linkp = AVL_NEXT(&dlmgmt_id_avl, linkp)) {
99 100 if (link_is_visible(linkp, zoneid) &&
100 101 (linkp->ll_class == DATALINK_CLASS_PHYS) &&
101 102 linkattr_equal(&(linkp->ll_head), FDEVNAME, devname,
102 103 strlen(devname) + 1)) {
103 104 return (linkp);
104 105 }
105 106 }
106 107 return (NULL);
107 108 }
108 109
109 110 /*
110 111 * Post the EC_DATALINK sysevent for the given linkid. This sysevent will
111 112 * be consumed by the datalink sysevent module.
112 113 */
113 114 static void
114 115 dlmgmt_post_sysevent(const char *subclass, datalink_id_t linkid,
115 116 boolean_t reconfigured)
116 117 {
117 118 nvlist_t *nvl = NULL;
118 119 sysevent_id_t eid;
119 120 int err;
120 121
121 122 if (((err = nvlist_alloc(&nvl, NV_UNIQUE_NAME_TYPE, 0)) != 0) ||
122 123 ((err = nvlist_add_uint64(nvl, RCM_NV_LINKID, linkid)) != 0) ||
123 124 ((err = nvlist_add_boolean_value(nvl, RCM_NV_RECONFIGURED,
124 125 reconfigured)) != 0)) {
125 126 goto done;
126 127 }
127 128
128 129 if (sysevent_post_event(EC_DATALINK, (char *)subclass, SUNW_VENDOR,
129 130 (char *)progname, nvl, &eid) == -1) {
130 131 err = errno;
131 132 }
132 133
133 134 done:
134 135 if (err != 0) {
135 136 dlmgmt_log(LOG_WARNING, "dlmgmt_post_sysevent(%d) failed: %s",
136 137 linkid, strerror(err));
137 138 }
138 139 nvlist_free(nvl);
139 140 }
140 141
141 142 /* ARGSUSED */
142 143 static void
143 144 dlmgmt_upcall_create(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
144 145 ucred_t *cred)
145 146 {
146 147 dlmgmt_upcall_arg_create_t *create = argp;
147 148 dlmgmt_create_retval_t *retvalp = retp;
148 149 datalink_class_t class;
149 150 uint32_t media;
150 151 dlmgmt_link_t *linkp;
151 152 char link[MAXLINKNAMELEN];
152 153 uint32_t flags;
153 154 int err = 0;
154 155 boolean_t created = B_FALSE;
155 156 boolean_t reconfigured = B_FALSE;
156 157
157 158 /*
158 159 * Determine whether this link is persistent. Note that this request
159 160 * is coming from kernel so this link must be active.
160 161 */
161 162 flags = DLMGMT_ACTIVE | (create->ld_persist ? DLMGMT_PERSIST : 0);
162 163
163 164 class = create->ld_class;
164 165 media = create->ld_media;
165 166
166 167 /*
167 168 * Hold the writer lock to update the link table.
168 169 */
169 170 dlmgmt_table_lock(B_TRUE);
170 171
171 172 if ((err = dlmgmt_checkprivs(class, cred)) != 0)
172 173 goto done;
173 174
174 175 /*
175 176 * Check to see whether this is the reattachment of an existing
176 177 * physical link. If so, return its linkid.
177 178 */
178 179 if ((class == DATALINK_CLASS_PHYS) && (linkp =
179 180 dlmgmt_getlink_by_dev(create->ld_devname, zoneid)) != NULL) {
180 181 if (linkattr_equal(&(linkp->ll_head), FPHYMAJ,
181 182 &create->ld_phymaj, sizeof (uint64_t)) &&
182 183 linkattr_equal(&(linkp->ll_head), FPHYINST,
183 184 &create->ld_phyinst, sizeof (uint64_t)) &&
184 185 (linkp->ll_flags & flags) == flags) {
185 186 /*
186 187 * If nothing has been changed, directly return.
187 188 */
188 189 goto noupdate;
189 190 }
190 191
191 192 err = linkattr_set(&(linkp->ll_head), FPHYMAJ,
192 193 &create->ld_phymaj, sizeof (uint64_t), DLADM_TYPE_UINT64);
193 194 if (err != 0)
194 195 goto done;
195 196
196 197 err = linkattr_set(&(linkp->ll_head), FPHYINST,
197 198 &create->ld_phyinst, sizeof (uint64_t), DLADM_TYPE_UINT64);
198 199 if (err != 0)
199 200 goto done;
200 201
201 202 /*
202 203 * This is a device that is dynamic reconfigured.
203 204 */
204 205 if ((linkp->ll_flags & DLMGMT_ACTIVE) == 0)
205 206 reconfigured = B_TRUE;
206 207
207 208 if ((err = link_activate(linkp)) != 0)
208 209 goto done;
209 210 linkp->ll_flags |= flags;
210 211 linkp->ll_gen++;
211 212
212 213 goto done;
213 214 }
214 215
215 216 if ((err = dlmgmt_create_common(create->ld_devname, class, media,
216 217 zoneid, flags, &linkp)) == EEXIST) {
217 218 /*
218 219 * The link name already exists. Return error if this is a
219 220 * non-physical link (in that case, the link name must be
220 221 * the same as the given name).
221 222 */
222 223 if (class != DATALINK_CLASS_PHYS)
223 224 goto done;
224 225
225 226 /*
226 227 * The physical link's name already exists, request
227 228 * a suggested link name: net<nextppa>
228 229 */
229 230 err = dlmgmt_generate_name("net", link, MAXLINKNAMELEN, zoneid);
230 231 if (err != 0)
231 232 goto done;
232 233
233 234 err = dlmgmt_create_common(link, class, media, zoneid, flags,
234 235 &linkp);
235 236 }
236 237
237 238 if (err != 0)
238 239 goto done;
239 240
240 241 created = B_TRUE;
241 242
242 243 /*
243 244 * This is a new link. Only need to persist link attributes for
244 245 * physical links.
245 246 */
246 247 if (class == DATALINK_CLASS_PHYS &&
247 248 (((err = linkattr_set(&linkp->ll_head, FDEVNAME, create->ld_devname,
248 249 strlen(create->ld_devname) + 1, DLADM_TYPE_STR)) != 0) ||
249 250 ((err = linkattr_set(&linkp->ll_head, FPHYMAJ, &create->ld_phymaj,
250 251 sizeof (uint64_t), DLADM_TYPE_UINT64)) != 0) ||
251 252 ((err = linkattr_set(&linkp->ll_head, FPHYINST, &create->ld_phyinst,
252 253 sizeof (uint64_t), DLADM_TYPE_UINT64)) != 0))) {
253 254 (void) dlmgmt_destroy_common(linkp, flags);
254 255 }
255 256
256 257 done:
257 258 if ((err == 0) && ((err = dlmgmt_write_db_entry(linkp->ll_link, linkp,
258 259 linkp->ll_flags)) != 0) && created) {
259 260 (void) dlmgmt_destroy_common(linkp, flags);
260 261 }
261 262
262 263 noupdate:
263 264 if (err == 0)
264 265 retvalp->lr_linkid = linkp->ll_linkid;
265 266
266 267 dlmgmt_table_unlock();
267 268
268 269 if ((err == 0) && (class == DATALINK_CLASS_PHYS)) {
269 270 /*
270 271 * Post the ESC_DATALINK_PHYS_ADD sysevent. This sysevent
271 272 * is consumed by the datalink sysevent module which in
272 273 * turn generates the RCM_RESOURCE_LINK_NEW RCM event.
273 274 */
274 275 dlmgmt_post_sysevent(ESC_DATALINK_PHYS_ADD,
275 276 retvalp->lr_linkid, reconfigured);
276 277 }
277 278
278 279 retvalp->lr_err = err;
279 280 }
280 281
281 282 /* ARGSUSED */
282 283 static void
283 284 dlmgmt_upcall_update(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
284 285 ucred_t *cred)
285 286 {
286 287 dlmgmt_upcall_arg_update_t *update = argp;
287 288 dlmgmt_update_retval_t *retvalp = retp;
288 289 uint32_t media = update->ld_media;
289 290 dlmgmt_link_t *linkp;
290 291 int err = 0;
291 292
292 293 /*
293 294 * Hold the writer lock to update the link table.
294 295 */
295 296 dlmgmt_table_lock(B_TRUE);
296 297
297 298 /*
298 299 * Check to see whether this is the reattachment of an existing
299 300 * physical link. If so, return its linkid.
300 301 */
301 302 if ((linkp = dlmgmt_getlink_by_dev(update->ld_devname, zoneid)) ==
302 303 NULL) {
303 304 err = ENOENT;
304 305 goto done;
305 306 }
306 307
307 308 if ((err = dlmgmt_checkprivs(linkp->ll_class, cred)) != 0)
308 309 goto done;
309 310
310 311 retvalp->lr_linkid = linkp->ll_linkid;
311 312 retvalp->lr_media = media;
312 313 if (linkp->ll_media != media && linkp->ll_media != DL_OTHER) {
313 314 /*
314 315 * Assume a DL_ETHER link ce0, a DL_WIFI link ath0
315 316 * 1. # dladm rename-link ce0 net0
316 317 * 2. DR out ce0. net0 is down.
317 318 * 3. use rename-link to have the ath0 device inherit
318 319 * the configuration from net0
319 320 * # dladm rename-link ath0 net0
320 321 * 4. DR in ath0.
321 322 * As ath0 and ce0 do not have the same media type, ath0
322 323 * cannot inherit the configuration of net0.
323 324 */
324 325 err = EEXIST;
325 326
326 327 /*
327 328 * Return the media type of the existing link to indicate the
328 329 * reason for the name conflict.
329 330 */
330 331 retvalp->lr_media = linkp->ll_media;
331 332 goto done;
332 333 }
333 334
334 335 if (update->ld_novanity &&
335 336 (strcmp(update->ld_devname, linkp->ll_link) != 0)) {
336 337 /*
337 338 * Return an error if this is a physical link that does not
338 339 * support vanity naming, but the link name is not the same
339 340 * as the given device name.
340 341 */
341 342 err = EEXIST;
342 343 goto done;
343 344 }
344 345
345 346 if (linkp->ll_media != media) {
346 347 linkp->ll_media = media;
347 348 linkp->ll_gen++;
348 349 (void) dlmgmt_write_db_entry(linkp->ll_link, linkp,
349 350 linkp->ll_flags);
350 351 }
351 352
352 353 done:
353 354 dlmgmt_table_unlock();
354 355 retvalp->lr_err = err;
355 356 }
356 357
357 358 /* ARGSUSED */
358 359 static void
359 360 dlmgmt_upcall_destroy(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
360 361 ucred_t *cred)
361 362 {
362 363 dlmgmt_upcall_arg_destroy_t *destroy = argp;
363 364 dlmgmt_destroy_retval_t *retvalp = retp;
364 365 datalink_id_t linkid = destroy->ld_linkid;
365 366 dlmgmt_link_t *linkp = NULL;
366 367 uint32_t flags, dflags = 0;
367 368 int err = 0;
368 369
369 370 flags = DLMGMT_ACTIVE | (destroy->ld_persist ? DLMGMT_PERSIST : 0);
370 371
371 372 /*
372 373 * Hold the writer lock to update the link table.
373 374 */
374 375 dlmgmt_table_lock(B_TRUE);
375 376
376 377 if ((linkp = link_by_id(linkid, zoneid)) == NULL) {
377 378 err = ENOENT;
378 379 goto done;
379 380 }
380 381
381 382 if ((err = dlmgmt_checkprivs(linkp->ll_class, cred)) != 0)
382 383 goto done;
383 384
384 385 if (((linkp->ll_flags & flags) & DLMGMT_ACTIVE) != 0) {
385 386 if ((err = dlmgmt_delete_db_entry(linkp, DLMGMT_ACTIVE)) != 0)
386 387 goto done;
387 388 dflags |= DLMGMT_ACTIVE;
388 389 }
389 390
390 391 if (((linkp->ll_flags & flags) & DLMGMT_PERSIST) != 0) {
391 392 if ((err = dlmgmt_delete_db_entry(linkp, DLMGMT_PERSIST)) != 0)
392 393 goto done;
393 394 dflags |= DLMGMT_PERSIST;
394 395 }
395 396
396 397 err = dlmgmt_destroy_common(linkp, flags);
397 398 done:
398 399 if (err != 0 && dflags != 0)
399 400 (void) dlmgmt_write_db_entry(linkp->ll_link, linkp, dflags);
400 401
401 402 dlmgmt_table_unlock();
402 403 retvalp->lr_err = err;
403 404 }
404 405
405 406 /* ARGSUSED */
406 407 static void
407 408 dlmgmt_getname(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
408 409 ucred_t *cred)
409 410 {
410 411 dlmgmt_door_getname_t *getname = argp;
411 412 dlmgmt_getname_retval_t *retvalp = retp;
412 413 dlmgmt_link_t *linkp;
413 414 int err = 0;
414 415
415 416 /*
416 417 * Hold the reader lock to access the link
417 418 */
|
↓ open down ↓ |
383 lines elided |
↑ open up ↑ |
418 419 dlmgmt_table_lock(B_FALSE);
419 420 if ((linkp = link_by_id(getname->ld_linkid, zoneid)) == NULL) {
420 421 err = ENOENT;
421 422 } else if (strlcpy(retvalp->lr_link, linkp->ll_link, MAXLINKNAMELEN) >=
422 423 MAXLINKNAMELEN) {
423 424 err = ENOSPC;
424 425 } else {
425 426 retvalp->lr_flags = linkp->ll_flags;
426 427 retvalp->lr_class = linkp->ll_class;
427 428 retvalp->lr_media = linkp->ll_media;
428 - retvalp->lr_flags |= (linkp->ll_trans == B_TRUE) ?
429 - DLMGMT_TRANSIENT : 0;
429 + retvalp->lr_flags |= linkp->ll_transient ? DLMGMT_TRANSIENT : 0;
430 430 }
431 431
432 432
433 433 dlmgmt_table_unlock();
434 434 retvalp->lr_err = err;
435 435 }
436 436
437 437 /* ARGSUSED */
438 438 static void
439 439 dlmgmt_getlinkid(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
440 440 ucred_t *cred)
441 441 {
442 442 dlmgmt_door_getlinkid_t *getlinkid = argp;
443 443 dlmgmt_getlinkid_retval_t *retvalp = retp;
444 444 dlmgmt_link_t *linkp;
445 445 int err = 0;
446 446
447 447 /* Enable the global zone to lookup links it has given away. */
448 448 if (zoneid == GLOBAL_ZONEID && getlinkid->ld_zoneid != -1)
449 449 zoneid = getlinkid->ld_zoneid;
450 450
451 451 /*
452 452 * Hold the reader lock to access the link
453 453 */
454 454 dlmgmt_table_lock(B_FALSE);
455 455
456 456 if ((linkp = link_by_name(getlinkid->ld_link, zoneid)) == NULL) {
457 457 /*
|
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
458 458 * The link does not exist in this zone.
459 459 */
460 460 err = ENOENT;
461 461 goto done;
462 462 }
463 463
464 464 retvalp->lr_linkid = linkp->ll_linkid;
465 465 retvalp->lr_flags = linkp->ll_flags;
466 466 retvalp->lr_class = linkp->ll_class;
467 467 retvalp->lr_media = linkp->ll_media;
468 + retvalp->lr_flags |= linkp->ll_transient ? DLMGMT_TRANSIENT : 0;
468 469
469 470 done:
470 471 dlmgmt_table_unlock();
471 472 retvalp->lr_err = err;
472 473 }
473 474
474 475 /* ARGSUSED */
475 476 static void
476 477 dlmgmt_getnext(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
477 478 ucred_t *cred)
478 479 {
479 480 dlmgmt_door_getnext_t *getnext = argp;
480 481 dlmgmt_getnext_retval_t *retvalp = retp;
481 482 dlmgmt_link_t link, *linkp;
482 483 avl_index_t where;
483 484 int err = 0;
484 485
485 486 /*
486 487 * Hold the reader lock to access the link
487 488 */
488 489 dlmgmt_table_lock(B_FALSE);
489 490
490 491 link.ll_linkid = (getnext->ld_linkid + 1);
491 492 if ((linkp = avl_find(&dlmgmt_id_avl, &link, &where)) == NULL)
492 493 linkp = avl_nearest(&dlmgmt_id_avl, where, AVL_AFTER);
493 494
494 495 for (; linkp != NULL; linkp = AVL_NEXT(&dlmgmt_id_avl, linkp)) {
495 496 if (!link_is_visible(linkp, zoneid))
496 497 continue;
497 498 if ((linkp->ll_class & getnext->ld_class) &&
498 499 (linkp->ll_flags & getnext->ld_flags) &&
499 500 DATALINK_MEDIA_ACCEPTED(getnext->ld_dmedia,
500 501 linkp->ll_media))
|
↓ open down ↓ |
23 lines elided |
↑ open up ↑ |
501 502 break;
502 503 }
503 504
504 505 if (linkp == NULL) {
505 506 err = ENOENT;
506 507 } else {
507 508 retvalp->lr_linkid = linkp->ll_linkid;
508 509 retvalp->lr_class = linkp->ll_class;
509 510 retvalp->lr_media = linkp->ll_media;
510 511 retvalp->lr_flags = linkp->ll_flags;
512 + retvalp->lr_flags |= linkp->ll_transient ? DLMGMT_TRANSIENT : 0;
511 513 }
512 514
513 515 dlmgmt_table_unlock();
514 516 retvalp->lr_err = err;
515 517 }
516 518
517 519 /* ARGSUSED */
518 520 static void
519 521 dlmgmt_upcall_getattr(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
520 522 ucred_t *cred)
521 523 {
522 524 dlmgmt_upcall_arg_getattr_t *getattr = argp;
523 525 dlmgmt_getattr_retval_t *retvalp = retp;
524 526 dlmgmt_link_t *linkp;
525 527
526 528 /*
527 529 * Hold the reader lock to access the link
528 530 */
529 531 dlmgmt_table_lock(B_FALSE);
530 532 if ((linkp = link_by_id(getattr->ld_linkid, zoneid)) == NULL) {
531 533 retvalp->lr_err = ENOENT;
532 534 } else {
533 535 retvalp->lr_err = dlmgmt_getattr_common(&linkp->ll_head,
534 536 getattr->ld_attr, retvalp);
535 537 }
536 538 dlmgmt_table_unlock();
537 539 }
538 540
539 541 /* ARGSUSED */
540 542 static void
541 543 dlmgmt_createid(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
542 544 ucred_t *cred)
543 545 {
544 546 dlmgmt_door_createid_t *createid = argp;
545 547 dlmgmt_createid_retval_t *retvalp = retp;
546 548 dlmgmt_link_t *linkp;
547 549 datalink_id_t linkid = DATALINK_INVALID_LINKID;
548 550 char link[MAXLINKNAMELEN];
549 551 int err;
550 552
551 553 /*
552 554 * Hold the writer lock to update the dlconf table.
553 555 */
554 556 dlmgmt_table_lock(B_TRUE);
555 557
556 558 if ((err = dlmgmt_checkprivs(createid->ld_class, cred)) != 0)
557 559 goto done;
558 560
559 561 if (createid->ld_prefix) {
560 562 err = dlmgmt_generate_name(createid->ld_link, link,
561 563 MAXLINKNAMELEN, zoneid);
562 564 if (err != 0)
563 565 goto done;
564 566
565 567 err = dlmgmt_create_common(link, createid->ld_class,
566 568 createid->ld_media, zoneid, createid->ld_flags, &linkp);
567 569 } else {
568 570 err = dlmgmt_create_common(createid->ld_link,
569 571 createid->ld_class, createid->ld_media, zoneid,
570 572 createid->ld_flags, &linkp);
571 573 }
572 574
573 575 if (err == 0) {
574 576 /*
575 577 * Keep the active mapping.
576 578 */
577 579 linkid = linkp->ll_linkid;
578 580 if (createid->ld_flags & DLMGMT_ACTIVE) {
579 581 (void) dlmgmt_write_db_entry(linkp->ll_link, linkp,
580 582 DLMGMT_ACTIVE);
581 583 }
582 584 }
583 585
584 586 done:
585 587 dlmgmt_table_unlock();
586 588 retvalp->lr_linkid = linkid;
587 589 retvalp->lr_err = err;
588 590 }
589 591
590 592 /* ARGSUSED */
591 593 static void
592 594 dlmgmt_destroyid(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
593 595 ucred_t *cred)
594 596 {
595 597 dlmgmt_door_destroyid_t *destroyid = argp;
596 598 dlmgmt_destroyid_retval_t *retvalp = retp;
597 599 datalink_id_t linkid = destroyid->ld_linkid;
598 600 uint32_t flags = destroyid->ld_flags;
599 601 dlmgmt_link_t *linkp = NULL;
600 602 int err = 0;
601 603
602 604 /*
603 605 * Hold the writer lock to update the link table.
604 606 */
605 607 dlmgmt_table_lock(B_TRUE);
606 608 if ((linkp = link_by_id(linkid, zoneid)) == NULL) {
607 609 err = ENOENT;
608 610 goto done;
609 611 }
610 612
611 613 if ((err = dlmgmt_checkprivs(linkp->ll_class, cred)) != 0)
612 614 goto done;
613 615
614 616 /*
615 617 * Delete the active mapping.
616 618 */
617 619 if (flags & DLMGMT_ACTIVE)
618 620 err = dlmgmt_delete_db_entry(linkp, DLMGMT_ACTIVE);
619 621 if (err == 0)
620 622 err = dlmgmt_destroy_common(linkp, flags);
621 623 done:
622 624 dlmgmt_table_unlock();
623 625 retvalp->lr_err = err;
624 626 }
625 627
626 628 /*
627 629 * Remap a linkid to a given link name, i.e., rename an existing link1
628 630 * (ld_linkid) to a non-existent link2 (ld_link): rename link1's name to
629 631 * the given link name.
630 632 */
631 633 /* ARGSUSED */
632 634 static void
633 635 dlmgmt_remapid(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
634 636 ucred_t *cred)
635 637 {
636 638 dlmgmt_door_remapid_t *remapid = argp;
637 639 dlmgmt_remapid_retval_t *retvalp = retp;
638 640 dlmgmt_link_t *linkp;
639 641 char oldname[MAXLINKNAMELEN];
640 642 boolean_t renamed = B_FALSE;
641 643 int err = 0;
642 644
643 645 if (!dladm_valid_linkname(remapid->ld_link)) {
644 646 retvalp->lr_err = EINVAL;
645 647 return;
646 648 }
647 649
648 650 /*
649 651 * Hold the writer lock to update the link table.
650 652 */
651 653 dlmgmt_table_lock(B_TRUE);
652 654 if ((linkp = link_by_id(remapid->ld_linkid, zoneid)) == NULL) {
653 655 err = ENOENT;
654 656 goto done;
655 657 }
656 658
657 659 if ((err = dlmgmt_checkprivs(linkp->ll_class, cred)) != 0)
658 660 goto done;
659 661
660 662
661 663 if (link_by_name(remapid->ld_link, linkp->ll_zoneid) != NULL) {
662 664 err = EEXIST;
663 665 goto done;
664 666 }
665 667
666 668 (void) strlcpy(oldname, linkp->ll_link, MAXLINKNAMELEN);
667 669 avl_remove(&dlmgmt_name_avl, linkp);
668 670 (void) strlcpy(linkp->ll_link, remapid->ld_link, MAXLINKNAMELEN);
669 671 avl_add(&dlmgmt_name_avl, linkp);
670 672 renamed = B_TRUE;
671 673
672 674 if (linkp->ll_flags & DLMGMT_ACTIVE) {
673 675 err = dlmgmt_write_db_entry(oldname, linkp, DLMGMT_ACTIVE);
674 676 if (err != 0)
675 677 goto done;
676 678 }
677 679 if (linkp->ll_flags & DLMGMT_PERSIST) {
678 680 err = dlmgmt_write_db_entry(oldname, linkp, DLMGMT_PERSIST);
679 681 if (err != 0) {
680 682 if (linkp->ll_flags & DLMGMT_ACTIVE) {
681 683 (void) dlmgmt_write_db_entry(remapid->ld_link,
682 684 linkp, DLMGMT_ACTIVE);
683 685 }
684 686 goto done;
685 687 }
686 688 }
687 689
688 690 dlmgmt_advance(linkp);
689 691 linkp->ll_gen++;
690 692 done:
691 693 if (err != 0 && renamed) {
692 694 avl_remove(&dlmgmt_name_avl, linkp);
693 695 (void) strlcpy(linkp->ll_link, oldname, MAXLINKNAMELEN);
694 696 avl_add(&dlmgmt_name_avl, linkp);
695 697 }
696 698 dlmgmt_table_unlock();
697 699 retvalp->lr_err = err;
698 700 }
699 701
700 702 /* ARGSUSED */
701 703 static void
702 704 dlmgmt_upid(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
703 705 ucred_t *cred)
704 706 {
705 707 dlmgmt_door_upid_t *upid = argp;
706 708 dlmgmt_upid_retval_t *retvalp = retp;
707 709 dlmgmt_link_t *linkp;
708 710 int err = 0;
709 711
710 712 /*
711 713 * Hold the writer lock to update the link table.
712 714 */
713 715 dlmgmt_table_lock(B_TRUE);
714 716 if ((linkp = link_by_id(upid->ld_linkid, zoneid)) == NULL) {
715 717 err = ENOENT;
716 718 goto done;
717 719 }
718 720
719 721 if ((err = dlmgmt_checkprivs(linkp->ll_class, cred)) != 0)
720 722 goto done;
721 723
722 724 if (linkp->ll_flags & DLMGMT_ACTIVE) {
723 725 err = EINVAL;
724 726 goto done;
725 727 }
726 728
727 729 if ((err = link_activate(linkp)) == 0) {
728 730 (void) dlmgmt_write_db_entry(linkp->ll_link, linkp,
729 731 DLMGMT_ACTIVE);
730 732 }
731 733 done:
732 734 dlmgmt_table_unlock();
733 735 retvalp->lr_err = err;
734 736 }
735 737
736 738 /* ARGSUSED */
737 739 static void
738 740 dlmgmt_createconf(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
739 741 ucred_t *cred)
740 742 {
741 743 dlmgmt_door_createconf_t *createconf = argp;
742 744 dlmgmt_createconf_retval_t *retvalp = retp;
743 745 dlmgmt_dlconf_t *dlconfp;
744 746 int err;
745 747
746 748 /*
747 749 * Hold the writer lock to update the dlconf table.
748 750 */
749 751 dlmgmt_dlconf_table_lock(B_TRUE);
750 752
751 753 if ((err = dlmgmt_checkprivs(createconf->ld_class, cred)) != 0)
752 754 goto done;
753 755
754 756 err = dlconf_create(createconf->ld_link, createconf->ld_linkid,
755 757 createconf->ld_class, createconf->ld_media, zoneid, &dlconfp);
756 758 if (err == 0) {
757 759 avl_add(&dlmgmt_dlconf_avl, dlconfp);
758 760 dlmgmt_advance_dlconfid(dlconfp);
759 761 retvalp->lr_confid = dlconfp->ld_id;
760 762 }
761 763 done:
762 764 dlmgmt_dlconf_table_unlock();
763 765 retvalp->lr_err = err;
764 766 }
765 767
766 768 /* ARGSUSED */
767 769 static void
768 770 dlmgmt_setattr(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
769 771 ucred_t *cred)
770 772 {
771 773 dlmgmt_door_setattr_t *setattr = argp;
772 774 dlmgmt_setattr_retval_t *retvalp = retp;
773 775 dlmgmt_dlconf_t dlconf, *dlconfp;
774 776 int err = 0;
775 777
776 778 /*
777 779 * Hold the writer lock to update the dlconf table.
778 780 */
779 781 dlmgmt_dlconf_table_lock(B_TRUE);
780 782
781 783 dlconf.ld_id = setattr->ld_confid;
782 784 dlconfp = avl_find(&dlmgmt_dlconf_avl, &dlconf, NULL);
783 785 if (dlconfp == NULL || zoneid != dlconfp->ld_zoneid) {
784 786 err = ENOENT;
785 787 goto done;
786 788 }
787 789
788 790 if ((err = dlmgmt_checkprivs(dlconfp->ld_class, cred)) != 0)
789 791 goto done;
790 792
791 793 err = linkattr_set(&(dlconfp->ld_head), setattr->ld_attr,
792 794 &setattr->ld_attrval, setattr->ld_attrsz, setattr->ld_type);
793 795
794 796 done:
795 797 dlmgmt_dlconf_table_unlock();
796 798 retvalp->lr_err = err;
797 799 }
798 800
799 801 /* ARGSUSED */
800 802 static void
801 803 dlmgmt_unsetconfattr(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
802 804 ucred_t *cred)
803 805 {
804 806 dlmgmt_door_unsetattr_t *unsetattr = argp;
805 807 dlmgmt_unsetattr_retval_t *retvalp = retp;
806 808 dlmgmt_dlconf_t dlconf, *dlconfp;
807 809 int err = 0;
808 810
809 811 /*
810 812 * Hold the writer lock to update the dlconf table.
811 813 */
812 814 dlmgmt_dlconf_table_lock(B_TRUE);
813 815
814 816 dlconf.ld_id = unsetattr->ld_confid;
815 817 dlconfp = avl_find(&dlmgmt_dlconf_avl, &dlconf, NULL);
816 818 if (dlconfp == NULL || zoneid != dlconfp->ld_zoneid) {
817 819 err = ENOENT;
818 820 goto done;
819 821 }
820 822
821 823 if ((err = dlmgmt_checkprivs(dlconfp->ld_class, cred)) != 0)
822 824 goto done;
823 825
824 826 linkattr_unset(&(dlconfp->ld_head), unsetattr->ld_attr);
825 827
826 828 done:
827 829 dlmgmt_dlconf_table_unlock();
828 830 retvalp->lr_err = err;
829 831 }
830 832
831 833 /*
832 834 * Note that dlmgmt_openconf() returns a conf ID of a conf AVL tree entry,
833 835 * which is managed by dlmgmtd. The ID is used to find the conf entry when
834 836 * dlmgmt_write_conf() is called. The conf entry contains an ld_gen value
835 837 * (which is the generation number - ll_gen) of the dlmgmt_link_t at the time
836 838 * of dlmgmt_openconf(), and ll_gen changes every time the dlmgmt_link_t
837 839 * changes its attributes. Therefore, dlmgmt_write_conf() can compare ld_gen
838 840 * in the conf entry against the latest dlmgmt_link_t ll_gen value to see if
839 841 * anything has changed between the dlmgmt_openconf() and dlmgmt_writeconf()
840 842 * calls. If so, EAGAIN is returned. This mechanism can ensures atomicity
841 843 * across the pair of dladm_read_conf() and dladm_write_conf() calls.
842 844 */
843 845 /* ARGSUSED */
844 846 static void
845 847 dlmgmt_writeconf(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
846 848 ucred_t *cred)
847 849 {
848 850 dlmgmt_door_writeconf_t *writeconf = argp;
849 851 dlmgmt_writeconf_retval_t *retvalp = retp;
850 852 dlmgmt_dlconf_t dlconf, *dlconfp;
851 853 dlmgmt_link_t *linkp;
852 854 dlmgmt_linkattr_t *attrp, *next;
853 855 int err = 0;
854 856
855 857 /*
856 858 * Hold the lock to access the dlconf table.
857 859 */
858 860 dlmgmt_dlconf_table_lock(B_TRUE);
859 861
860 862 dlconf.ld_id = writeconf->ld_confid;
861 863 dlconfp = avl_find(&dlmgmt_dlconf_avl, &dlconf, NULL);
862 864 if (dlconfp == NULL || zoneid != dlconfp->ld_zoneid) {
863 865 err = ENOENT;
864 866 goto done;
865 867 }
866 868
867 869 if ((err = dlmgmt_checkprivs(dlconfp->ld_class, cred)) != 0)
868 870 goto done;
869 871
870 872 /*
871 873 * Hold the writer lock to update the link table.
872 874 */
873 875 dlmgmt_table_lock(B_TRUE);
874 876 linkp = link_by_id(dlconfp->ld_linkid, zoneid);
875 877 if ((linkp == NULL) || (linkp->ll_class != dlconfp->ld_class) ||
876 878 (linkp->ll_media != dlconfp->ld_media) ||
877 879 (strcmp(linkp->ll_link, dlconfp->ld_link) != 0)) {
878 880 /*
879 881 * The link does not exist.
880 882 */
881 883 dlmgmt_table_unlock();
882 884 err = ENOENT;
883 885 goto done;
884 886 }
885 887
886 888 if (linkp->ll_gen != dlconfp->ld_gen) {
887 889 /*
888 890 * Something has changed the link configuration; try again.
889 891 */
890 892 dlmgmt_table_unlock();
891 893 err = EAGAIN;
892 894 goto done;
893 895 }
894 896
895 897 /*
896 898 * Delete the old attribute list.
897 899 */
898 900 for (attrp = linkp->ll_head; attrp != NULL; attrp = next) {
899 901 next = attrp->lp_next;
900 902 free(attrp->lp_val);
901 903 free(attrp);
902 904 }
903 905 linkp->ll_head = NULL;
904 906
905 907 /*
906 908 * Set the new attribute.
907 909 */
908 910 for (attrp = dlconfp->ld_head; attrp != NULL; attrp = attrp->lp_next) {
909 911 if ((err = linkattr_set(&(linkp->ll_head), attrp->lp_name,
910 912 attrp->lp_val, attrp->lp_sz, attrp->lp_type)) != 0) {
911 913 dlmgmt_table_unlock();
912 914 goto done;
913 915 }
914 916 }
915 917
916 918 linkp->ll_gen++;
917 919 err = dlmgmt_write_db_entry(linkp->ll_link, linkp, DLMGMT_PERSIST);
918 920 dlmgmt_table_unlock();
|
↓ open down ↓ |
398 lines elided |
↑ open up ↑ |
919 921 done:
920 922 dlmgmt_dlconf_table_unlock();
921 923 retvalp->lr_err = err;
922 924 }
923 925
924 926 /* ARGSUSED */
925 927 static void
926 928 dlmgmt_removeconf(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
927 929 ucred_t *cred)
928 930 {
929 - dlmgmt_door_removeconf_t *removeconf = argp;
931 + dlmgmt_door_removeconf_t *removeconf = argp;
930 932 dlmgmt_removeconf_retval_t *retvalp = retp;
931 933 dlmgmt_link_t *linkp;
932 934 int err;
933 935
934 936 dlmgmt_table_lock(B_TRUE);
935 937 if ((linkp = link_by_id(removeconf->ld_linkid, zoneid)) == NULL) {
936 938 err = ENOENT;
937 939 goto done;
938 940 }
939 941 if (zoneid != GLOBAL_ZONEID && linkp->ll_onloan) {
940 942 /*
941 943 * A non-global zone cannot remove the persistent
942 944 * configuration of a link that is on loan from the global
943 945 * zone.
944 946 */
945 947 err = EACCES;
946 948 goto done;
947 949 }
948 950 if ((err = dlmgmt_checkprivs(linkp->ll_class, cred)) != 0)
949 951 goto done;
950 952
951 953 err = dlmgmt_delete_db_entry(linkp, DLMGMT_PERSIST);
952 954 done:
953 955 dlmgmt_table_unlock();
954 956 retvalp->lr_err = err;
955 957 }
956 958
957 959 /* ARGSUSED */
958 960 static void
959 961 dlmgmt_destroyconf(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
960 962 ucred_t *cred)
961 963 {
962 964 dlmgmt_door_destroyconf_t *destroyconf = argp;
963 965 dlmgmt_destroyconf_retval_t *retvalp = retp;
964 966 dlmgmt_dlconf_t dlconf, *dlconfp;
965 967 int err = 0;
966 968
967 969 /*
968 970 * Hold the writer lock to update the dlconf table.
969 971 */
970 972 dlmgmt_dlconf_table_lock(B_TRUE);
971 973
972 974 dlconf.ld_id = destroyconf->ld_confid;
973 975 dlconfp = avl_find(&dlmgmt_dlconf_avl, &dlconf, NULL);
974 976 if (dlconfp == NULL || zoneid != dlconfp->ld_zoneid) {
975 977 err = ENOENT;
976 978 goto done;
977 979 }
978 980
979 981 if ((err = dlmgmt_checkprivs(dlconfp->ld_class, cred)) != 0)
980 982 goto done;
981 983
982 984 avl_remove(&dlmgmt_dlconf_avl, dlconfp);
983 985 dlconf_destroy(dlconfp);
984 986
985 987 done:
986 988 dlmgmt_dlconf_table_unlock();
987 989 retvalp->lr_err = err;
988 990 }
989 991
990 992 /*
991 993 * dlmgmt_openconf() returns a handle of the current configuration, which
992 994 * is then used to update the configuration by dlmgmt_writeconf(). Therefore,
993 995 * it requires privileges.
994 996 *
995 997 * Further, please see the comments above dladm_write_conf() to see how
|
↓ open down ↓ |
56 lines elided |
↑ open up ↑ |
996 998 * ld_gen is used to ensure atomicity across the {dlmgmt_openconf(),
997 999 * dlmgmt_writeconf()} pair.
998 1000 */
999 1001 /* ARGSUSED */
1000 1002 static void
1001 1003 dlmgmt_openconf(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
1002 1004 ucred_t *cred)
1003 1005 {
1004 1006 dlmgmt_door_openconf_t *openconf = argp;
1005 1007 dlmgmt_openconf_retval_t *retvalp = retp;
1006 - dlmgmt_link_t *linkp;
1008 + dlmgmt_link_t *linkp;
1007 1009 datalink_id_t linkid = openconf->ld_linkid;
1008 1010 dlmgmt_dlconf_t *dlconfp;
1009 1011 dlmgmt_linkattr_t *attrp;
1010 1012 int err = 0;
1011 1013
1012 1014 /*
1013 1015 * Hold the writer lock to update the dlconf table.
1014 1016 */
1015 1017 dlmgmt_dlconf_table_lock(B_TRUE);
1016 1018
1017 1019 /*
1018 1020 * Hold the reader lock to access the link
1019 1021 */
1020 1022 dlmgmt_table_lock(B_FALSE);
1021 1023 linkp = link_by_id(linkid, zoneid);
1022 1024 if ((linkp == NULL) || !(linkp->ll_flags & DLMGMT_PERSIST)) {
1023 1025 /* The persistent link configuration does not exist. */
1024 1026 err = ENOENT;
1025 1027 goto done;
1026 1028 }
1027 1029 if (linkp->ll_onloan && zoneid != GLOBAL_ZONEID) {
1028 1030 /*
1029 1031 * The caller is in a non-global zone and the persistent
1030 1032 * configuration belongs to the global zone.
1031 1033 */
1032 1034 err = EACCES;
1033 1035 goto done;
1034 1036 }
1035 1037
1036 1038 if ((err = dlmgmt_checkprivs(linkp->ll_class, cred)) != 0)
1037 1039 goto done;
1038 1040
1039 1041 if ((err = dlconf_create(linkp->ll_link, linkp->ll_linkid,
1040 1042 linkp->ll_class, linkp->ll_media, zoneid, &dlconfp)) != 0)
1041 1043 goto done;
1042 1044
1043 1045 for (attrp = linkp->ll_head; attrp != NULL; attrp = attrp->lp_next) {
1044 1046 if ((err = linkattr_set(&(dlconfp->ld_head), attrp->lp_name,
1045 1047 attrp->lp_val, attrp->lp_sz, attrp->lp_type)) != 0) {
1046 1048 dlconf_destroy(dlconfp);
1047 1049 goto done;
1048 1050 }
1049 1051 }
1050 1052 dlconfp->ld_gen = linkp->ll_gen;
1051 1053 avl_add(&dlmgmt_dlconf_avl, dlconfp);
1052 1054 dlmgmt_advance_dlconfid(dlconfp);
1053 1055
1054 1056 retvalp->lr_confid = dlconfp->ld_id;
1055 1057 done:
1056 1058 dlmgmt_table_unlock();
1057 1059 dlmgmt_dlconf_table_unlock();
1058 1060 retvalp->lr_err = err;
1059 1061 }
1060 1062
1061 1063 /*
1062 1064 * dlmgmt_getconfsnapshot() returns a read-only snapshot of all the
1063 1065 * configuration, and requires no privileges.
1064 1066 *
|
↓ open down ↓ |
48 lines elided |
↑ open up ↑ |
1065 1067 * If the given size cannot hold all the configuration, set the size
1066 1068 * that is needed, and return ENOSPC.
1067 1069 */
1068 1070 /* ARGSUSED */
1069 1071 static void
1070 1072 dlmgmt_getconfsnapshot(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
1071 1073 ucred_t *cred)
1072 1074 {
1073 1075 dlmgmt_door_getconfsnapshot_t *snapshot = argp;
1074 1076 dlmgmt_getconfsnapshot_retval_t *retvalp = retp;
1075 - dlmgmt_link_t *linkp;
1077 + dlmgmt_link_t *linkp;
1076 1078 datalink_id_t linkid = snapshot->ld_linkid;
1077 1079 dlmgmt_linkattr_t *attrp;
1078 1080 char *buf;
1079 1081 size_t nvlsz;
1080 1082 nvlist_t *nvl = NULL;
1081 1083 int err = 0;
1082 1084
1083 1085 assert(*sz >= sizeof (dlmgmt_getconfsnapshot_retval_t));
1084 1086
1085 1087 /*
1086 1088 * Hold the reader lock to access the link
1087 1089 */
1088 1090 dlmgmt_table_lock(B_FALSE);
1089 1091 linkp = link_by_id(linkid, zoneid);
1090 1092 if ((linkp == NULL) || !(linkp->ll_flags & DLMGMT_PERSIST)) {
1091 1093 /* The persistent link configuration does not exist. */
1092 1094 err = ENOENT;
1093 1095 goto done;
1094 1096 }
1095 1097 if (linkp->ll_onloan && zoneid != GLOBAL_ZONEID) {
1096 1098 /*
1097 1099 * The caller is in a non-global zone and the persistent
1098 1100 * configuration belongs to the global zone.
1099 1101 */
1100 1102 err = EACCES;
1101 1103 goto done;
1102 1104 }
1103 1105
1104 1106 err = nvlist_alloc(&nvl, NV_UNIQUE_NAME_TYPE, 0);
1105 1107 if (err != 0)
1106 1108 goto done;
1107 1109
1108 1110 for (attrp = linkp->ll_head; attrp != NULL; attrp = attrp->lp_next) {
1109 1111 if ((err = nvlist_add_byte_array(nvl, attrp->lp_name,
1110 1112 attrp->lp_val, attrp->lp_sz)) != 0) {
1111 1113 goto done;
1112 1114 }
1113 1115 }
1114 1116
1115 1117 if ((err = nvlist_size(nvl, &nvlsz, NV_ENCODE_NATIVE)) != 0)
1116 1118 goto done;
1117 1119
1118 1120 if (nvlsz + sizeof (dlmgmt_getconfsnapshot_retval_t) > *sz) {
1119 1121 *sz = nvlsz + sizeof (dlmgmt_getconfsnapshot_retval_t);
1120 1122 err = ENOSPC;
1121 1123 goto done;
1122 1124 }
1123 1125
1124 1126 /*
1125 1127 * pack the the nvlist into the return value.
1126 1128 */
1127 1129 *sz = nvlsz + sizeof (dlmgmt_getconfsnapshot_retval_t);
1128 1130 retvalp->lr_nvlsz = nvlsz;
1129 1131 buf = (char *)retvalp + sizeof (dlmgmt_getconfsnapshot_retval_t);
1130 1132 err = nvlist_pack(nvl, &buf, &nvlsz, NV_ENCODE_NATIVE, 0);
1131 1133
1132 1134 done:
1133 1135 dlmgmt_table_unlock();
1134 1136 nvlist_free(nvl);
1135 1137 retvalp->lr_err = err;
1136 1138 }
1137 1139
1138 1140 /* ARGSUSED */
1139 1141 static void
1140 1142 dlmgmt_getattr(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
1141 1143 ucred_t *cred)
1142 1144 {
1143 1145 dlmgmt_door_getattr_t *getattr = argp;
1144 1146 dlmgmt_getattr_retval_t *retvalp = retp;
1145 1147 dlmgmt_dlconf_t dlconf, *dlconfp;
1146 1148 int err;
1147 1149
1148 1150 /*
1149 1151 * Hold the read lock to access the dlconf table.
1150 1152 */
1151 1153 dlmgmt_dlconf_table_lock(B_FALSE);
1152 1154
1153 1155 dlconf.ld_id = getattr->ld_confid;
1154 1156 if ((dlconfp = avl_find(&dlmgmt_dlconf_avl, &dlconf, NULL)) == NULL ||
1155 1157 zoneid != dlconfp->ld_zoneid) {
1156 1158 retvalp->lr_err = ENOENT;
1157 1159 } else {
1158 1160 if ((err = dlmgmt_checkprivs(dlconfp->ld_class, cred)) != 0) {
1159 1161 retvalp->lr_err = err;
1160 1162 } else {
1161 1163 retvalp->lr_err = dlmgmt_getattr_common(
1162 1164 &dlconfp->ld_head, getattr->ld_attr, retvalp);
1163 1165 }
1164 1166 }
1165 1167
1166 1168 dlmgmt_dlconf_table_unlock();
1167 1169 }
1168 1170
1169 1171 /* ARGSUSED */
1170 1172 static void
1171 1173 dlmgmt_upcall_linkprop_init(void *argp, void *retp, size_t *sz,
1172 1174 zoneid_t zoneid, ucred_t *cred)
1173 1175 {
1174 1176 dlmgmt_door_linkprop_init_t *lip = argp;
1175 1177 dlmgmt_linkprop_init_retval_t *retvalp = retp;
1176 1178 dlmgmt_link_t *linkp;
1177 1179 int err;
1178 1180
1179 1181 dlmgmt_table_lock(B_FALSE);
1180 1182 if ((linkp = link_by_id(lip->ld_linkid, zoneid)) == NULL)
1181 1183 err = ENOENT;
1182 1184 else
1183 1185 err = dlmgmt_checkprivs(linkp->ll_class, cred);
1184 1186 dlmgmt_table_unlock();
1185 1187
1186 1188 if (err == 0) {
1187 1189 dladm_status_t s;
1188 1190 char buf[DLADM_STRSIZE];
1189 1191
1190 1192 s = dladm_init_linkprop(dld_handle, lip->ld_linkid, B_TRUE);
1191 1193 if (s != DLADM_STATUS_OK) {
1192 1194 dlmgmt_log(LOG_WARNING,
1193 1195 "linkprop initialization failed on link %d: %s",
1194 1196 lip->ld_linkid, dladm_status2str(s, buf));
1195 1197 err = EINVAL;
1196 1198 }
1197 1199 }
1198 1200 retvalp->lr_err = err;
1199 1201 }
1200 1202
1201 1203 /* ARGSUSED */
1202 1204 static void
1203 1205 dlmgmt_setzoneid(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
1204 1206 ucred_t *cred)
1205 1207 {
1206 1208 dlmgmt_door_setzoneid_t *setzoneid = argp;
1207 1209 dlmgmt_setzoneid_retval_t *retvalp = retp;
1208 1210 dlmgmt_link_t *linkp;
1209 1211 datalink_id_t linkid = setzoneid->ld_linkid;
1210 1212 zoneid_t oldzoneid, newzoneid;
1211 1213 int err = 0;
1212 1214
1213 1215 dlmgmt_table_lock(B_TRUE);
1214 1216
1215 1217 /* We currently only allow changing zoneid's from the global zone. */
1216 1218 if (zoneid != GLOBAL_ZONEID) {
1217 1219 err = EACCES;
1218 1220 goto done;
1219 1221 }
1220 1222
1221 1223 if ((linkp = link_by_id(linkid, zoneid)) == NULL) {
1222 1224 err = ENOENT;
1223 1225 goto done;
1224 1226 }
1225 1227
1226 1228 if ((err = dlmgmt_checkprivs(linkp->ll_class, cred)) != 0)
1227 1229 goto done;
1228 1230
1229 1231 /* We can only assign an active link to a zone. */
1230 1232 if (!(linkp->ll_flags & DLMGMT_ACTIVE)) {
1231 1233 err = EINVAL;
1232 1234 goto done;
1233 1235 }
1234 1236
1235 1237 oldzoneid = linkp->ll_zoneid;
1236 1238 newzoneid = setzoneid->ld_zoneid;
1237 1239
1238 1240 if (oldzoneid == newzoneid)
1239 1241 goto done;
1240 1242
1241 1243 /*
1242 1244 * Before we remove the link from its current zone, make sure that
1243 1245 * there isn't a link with the same name in the destination zone.
1244 1246 */
1245 1247 if (link_by_name(linkp->ll_link, newzoneid) != NULL) {
1246 1248 err = EEXIST;
|
↓ open down ↓ |
161 lines elided |
↑ open up ↑ |
1247 1249 goto done;
1248 1250 }
1249 1251
1250 1252 if (oldzoneid != GLOBAL_ZONEID) {
1251 1253 if (zone_remove_datalink(oldzoneid, linkid) != 0) {
1252 1254 err = errno;
1253 1255 dlmgmt_log(LOG_WARNING, "unable to remove link %d from "
1254 1256 "zone %d: %s", linkid, oldzoneid, strerror(err));
1255 1257 goto done;
1256 1258 }
1257 -
1258 1259 linkp->ll_onloan = B_FALSE;
1259 1260 }
1260 1261
1261 1262 if (newzoneid != GLOBAL_ZONEID) {
1262 1263 if (zone_add_datalink(newzoneid, linkid) != 0) {
1263 1264 err = errno;
1264 1265 dlmgmt_log(LOG_WARNING, "unable to add link %d to zone "
1265 1266 "%d: %s", linkid, newzoneid, strerror(err));
1266 1267 (void) zone_add_datalink(oldzoneid, linkid);
1267 1268 goto done;
1268 1269 }
1269 1270 linkp->ll_onloan = B_TRUE;
1270 1271 }
1271 1272
1272 1273 avl_remove(&dlmgmt_name_avl, linkp);
1273 1274 linkp->ll_zoneid = newzoneid;
1274 1275 avl_add(&dlmgmt_name_avl, linkp);
1275 1276
1276 1277 done:
1277 1278 dlmgmt_table_unlock();
1278 1279 retvalp->lr_err = err;
1279 1280 }
1280 1281
1281 1282 /* ARGSUSED */
1282 1283 static void
1283 1284 dlmgmt_zoneboot(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
1284 1285 ucred_t *cred)
1285 1286 {
1286 1287 int err;
1287 1288 dlmgmt_door_zoneboot_t *zoneboot = argp;
1288 1289 dlmgmt_zoneboot_retval_t *retvalp = retp;
1289 1290
1290 1291 dlmgmt_table_lock(B_TRUE);
1291 1292
1292 1293 if ((err = dlmgmt_checkprivs(0, cred)) != 0)
1293 1294 goto done;
1294 1295
1295 1296 if (zoneid != GLOBAL_ZONEID) {
1296 1297 err = EACCES;
1297 1298 goto done;
1298 1299 }
1299 1300 if (zoneboot->ld_zoneid == GLOBAL_ZONEID) {
1300 1301 err = EINVAL;
1301 1302 goto done;
1302 1303 }
1303 1304
1304 1305 if ((err = dlmgmt_elevate_privileges()) == 0) {
1305 1306 err = dlmgmt_zone_init(zoneboot->ld_zoneid);
1306 1307 (void) dlmgmt_drop_privileges();
1307 1308 }
1308 1309 done:
1309 1310 dlmgmt_table_unlock();
1310 1311 retvalp->lr_err = err;
1311 1312 }
1312 1313
1313 1314 /* ARGSUSED */
1314 1315 static void
1315 1316 dlmgmt_zonehalt(void *argp, void *retp, size_t *sz, zoneid_t zoneid,
1316 1317 ucred_t *cred)
1317 1318 {
1318 1319 int err = 0;
1319 1320 dlmgmt_door_zonehalt_t *zonehalt = argp;
1320 1321 dlmgmt_zonehalt_retval_t *retvalp = retp;
1321 1322 static char my_pid[10];
1322 1323
1323 1324 if (my_pid[0] == '\0')
1324 1325 (void) snprintf(my_pid, sizeof (my_pid), "%d\n", getpid());
1325 1326
1326 1327 if ((err = dlmgmt_checkprivs(0, cred)) == 0) {
1327 1328 if (zoneid != GLOBAL_ZONEID) {
1328 1329 err = EACCES;
1329 1330 } else if (zonehalt->ld_zoneid == GLOBAL_ZONEID) {
1330 1331 err = EINVAL;
1331 1332 } else {
1332 1333 dlmgmt_table_lock(B_TRUE);
1333 1334 dlmgmt_db_fini(zonehalt->ld_zoneid);
1334 1335 dlmgmt_table_unlock();
1335 1336 }
1336 1337 }
1337 1338 retvalp->lr_err = err;
1338 1339 }
1339 1340
1340 1341 static dlmgmt_door_info_t i_dlmgmt_door_info_tbl[] = {
1341 1342 { DLMGMT_CMD_DLS_CREATE, sizeof (dlmgmt_upcall_arg_create_t),
1342 1343 sizeof (dlmgmt_create_retval_t), dlmgmt_upcall_create },
1343 1344 { DLMGMT_CMD_DLS_GETATTR, sizeof (dlmgmt_upcall_arg_getattr_t),
1344 1345 sizeof (dlmgmt_getattr_retval_t), dlmgmt_upcall_getattr },
1345 1346 { DLMGMT_CMD_DLS_DESTROY, sizeof (dlmgmt_upcall_arg_destroy_t),
1346 1347 sizeof (dlmgmt_destroy_retval_t), dlmgmt_upcall_destroy },
1347 1348 { DLMGMT_CMD_GETNAME, sizeof (dlmgmt_door_getname_t),
1348 1349 sizeof (dlmgmt_getname_retval_t), dlmgmt_getname },
1349 1350 { DLMGMT_CMD_GETLINKID, sizeof (dlmgmt_door_getlinkid_t),
1350 1351 sizeof (dlmgmt_getlinkid_retval_t), dlmgmt_getlinkid },
1351 1352 { DLMGMT_CMD_GETNEXT, sizeof (dlmgmt_door_getnext_t),
1352 1353 sizeof (dlmgmt_getnext_retval_t), dlmgmt_getnext },
1353 1354 { DLMGMT_CMD_DLS_UPDATE, sizeof (dlmgmt_upcall_arg_update_t),
1354 1355 sizeof (dlmgmt_update_retval_t), dlmgmt_upcall_update },
1355 1356 { DLMGMT_CMD_CREATE_LINKID, sizeof (dlmgmt_door_createid_t),
1356 1357 sizeof (dlmgmt_createid_retval_t), dlmgmt_createid },
1357 1358 { DLMGMT_CMD_DESTROY_LINKID, sizeof (dlmgmt_door_destroyid_t),
1358 1359 sizeof (dlmgmt_destroyid_retval_t), dlmgmt_destroyid },
1359 1360 { DLMGMT_CMD_REMAP_LINKID, sizeof (dlmgmt_door_remapid_t),
1360 1361 sizeof (dlmgmt_remapid_retval_t), dlmgmt_remapid },
1361 1362 { DLMGMT_CMD_CREATECONF, sizeof (dlmgmt_door_createconf_t),
1362 1363 sizeof (dlmgmt_createconf_retval_t), dlmgmt_createconf },
1363 1364 { DLMGMT_CMD_OPENCONF, sizeof (dlmgmt_door_openconf_t),
1364 1365 sizeof (dlmgmt_openconf_retval_t), dlmgmt_openconf },
1365 1366 { DLMGMT_CMD_WRITECONF, sizeof (dlmgmt_door_writeconf_t),
1366 1367 sizeof (dlmgmt_writeconf_retval_t), dlmgmt_writeconf },
1367 1368 { DLMGMT_CMD_UP_LINKID, sizeof (dlmgmt_door_upid_t),
1368 1369 sizeof (dlmgmt_upid_retval_t), dlmgmt_upid },
1369 1370 { DLMGMT_CMD_SETATTR, sizeof (dlmgmt_door_setattr_t),
1370 1371 sizeof (dlmgmt_setattr_retval_t), dlmgmt_setattr },
1371 1372 { DLMGMT_CMD_UNSETATTR, sizeof (dlmgmt_door_unsetattr_t),
1372 1373 sizeof (dlmgmt_unsetattr_retval_t), dlmgmt_unsetconfattr },
1373 1374 { DLMGMT_CMD_REMOVECONF, sizeof (dlmgmt_door_removeconf_t),
1374 1375 sizeof (dlmgmt_removeconf_retval_t), dlmgmt_removeconf },
1375 1376 { DLMGMT_CMD_DESTROYCONF, sizeof (dlmgmt_door_destroyconf_t),
1376 1377 sizeof (dlmgmt_destroyconf_retval_t), dlmgmt_destroyconf },
1377 1378 { DLMGMT_CMD_GETATTR, sizeof (dlmgmt_door_getattr_t),
1378 1379 sizeof (dlmgmt_getattr_retval_t), dlmgmt_getattr },
1379 1380 { DLMGMT_CMD_GETCONFSNAPSHOT, sizeof (dlmgmt_door_getconfsnapshot_t),
1380 1381 sizeof (dlmgmt_getconfsnapshot_retval_t), dlmgmt_getconfsnapshot },
1381 1382 { DLMGMT_CMD_LINKPROP_INIT, sizeof (dlmgmt_door_linkprop_init_t),
1382 1383 sizeof (dlmgmt_linkprop_init_retval_t),
1383 1384 dlmgmt_upcall_linkprop_init },
1384 1385 { DLMGMT_CMD_SETZONEID, sizeof (dlmgmt_door_setzoneid_t),
1385 1386 sizeof (dlmgmt_setzoneid_retval_t), dlmgmt_setzoneid },
1386 1387 { DLMGMT_CMD_ZONEBOOT, sizeof (dlmgmt_door_zoneboot_t),
1387 1388 sizeof (dlmgmt_zoneboot_retval_t), dlmgmt_zoneboot },
1388 1389 { DLMGMT_CMD_ZONEHALT, sizeof (dlmgmt_door_zonehalt_t),
1389 1390 sizeof (dlmgmt_zonehalt_retval_t), dlmgmt_zonehalt },
1390 1391 { 0, 0, 0, NULL }
1391 1392 };
1392 1393
1393 1394 static dlmgmt_door_info_t *
1394 1395 dlmgmt_getcmdinfo(int cmd)
1395 1396 {
1396 1397 dlmgmt_door_info_t *infop = i_dlmgmt_door_info_tbl;
1397 1398
1398 1399 while (infop->di_handler != NULL) {
1399 1400 if (infop->di_cmd == cmd)
1400 1401 break;
1401 1402 infop++;
1402 1403 }
1403 1404 return (infop);
1404 1405 }
1405 1406
1406 1407 /* ARGSUSED */
1407 1408 void
1408 1409 dlmgmt_handler(void *cookie, char *argp, size_t argsz, door_desc_t *dp,
1409 1410 uint_t n_desc)
1410 1411 {
1411 1412 dlmgmt_door_arg_t *door_arg = (dlmgmt_door_arg_t *)(void *)argp;
1412 1413 dlmgmt_door_info_t *infop = NULL;
1413 1414 dlmgmt_retval_t retval;
1414 1415 ucred_t *cred = NULL;
1415 1416 zoneid_t zoneid;
1416 1417 void *retvalp = NULL;
1417 1418 size_t sz, acksz;
1418 1419 int err = 0;
1419 1420
1420 1421 infop = dlmgmt_getcmdinfo(door_arg->ld_cmd);
1421 1422 if (infop == NULL || argsz != infop->di_reqsz) {
1422 1423 err = EINVAL;
1423 1424 goto done;
1424 1425 }
1425 1426
1426 1427 if (door_ucred(&cred) != 0 || (zoneid = ucred_getzoneid(cred)) == -1) {
1427 1428 err = errno;
1428 1429 goto done;
1429 1430 }
1430 1431
1431 1432 /*
1432 1433 * Note that malloc() cannot be used here because door_return
1433 1434 * never returns, and memory allocated by malloc() would get leaked.
1434 1435 * Use alloca() instead.
1435 1436 */
1436 1437 acksz = infop->di_acksz;
1437 1438
1438 1439 again:
1439 1440 retvalp = alloca(acksz);
1440 1441 sz = acksz;
1441 1442 infop->di_handler(argp, retvalp, &acksz, zoneid, cred);
1442 1443 if (acksz > sz) {
1443 1444 /*
1444 1445 * If the specified buffer size is not big enough to hold the
1445 1446 * return value, reallocate the buffer and try to get the
1446 1447 * result one more time.
1447 1448 */
1448 1449 assert(((dlmgmt_retval_t *)retvalp)->lr_err == ENOSPC);
1449 1450 goto again;
1450 1451 }
1451 1452
1452 1453 done:
1453 1454 if (cred != NULL)
1454 1455 ucred_free(cred);
1455 1456 if (err == 0) {
1456 1457 (void) door_return(retvalp, acksz, NULL, 0);
1457 1458 } else {
1458 1459 retval.lr_err = err;
1459 1460 (void) door_return((char *)&retval, sizeof (retval), NULL, 0);
1460 1461 }
1461 1462 }
|
↓ open down ↓ |
194 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX