444 dlmgmt_link_t *linkp = NULL;
445 avl_index_t name_where, id_where;
446 int err = 0;
447
448 if (!dladm_valid_linkname(name))
449 return (EINVAL);
450 if (dlmgmt_nextlinkid == DATALINK_INVALID_LINKID)
451 return (ENOSPC);
452
453 if ((linkp = calloc(1, sizeof (dlmgmt_link_t))) == NULL) {
454 err = ENOMEM;
455 goto done;
456 }
457
458 (void) strlcpy(linkp->ll_link, name, MAXLINKNAMELEN);
459 linkp->ll_class = class;
460 linkp->ll_media = media;
461 linkp->ll_linkid = dlmgmt_nextlinkid;
462 linkp->ll_zoneid = zoneid;
463 linkp->ll_gen = 0;
464
465 if (avl_find(&dlmgmt_name_avl, linkp, &name_where) != NULL ||
466 avl_find(&dlmgmt_id_avl, linkp, &id_where) != NULL) {
467 err = EEXIST;
468 goto done;
469 }
470
471 avl_insert(&dlmgmt_name_avl, linkp, name_where);
472 avl_insert(&dlmgmt_id_avl, linkp, id_where);
473
474 if ((flags & DLMGMT_ACTIVE) && (err = link_activate(linkp)) != 0) {
475 avl_remove(&dlmgmt_name_avl, linkp);
476 avl_remove(&dlmgmt_id_avl, linkp);
477 goto done;
478 }
479
480 linkp->ll_flags = flags;
481 dlmgmt_advance(linkp);
482 *linkpp = linkp;
483
|
444 dlmgmt_link_t *linkp = NULL;
445 avl_index_t name_where, id_where;
446 int err = 0;
447
448 if (!dladm_valid_linkname(name))
449 return (EINVAL);
450 if (dlmgmt_nextlinkid == DATALINK_INVALID_LINKID)
451 return (ENOSPC);
452
453 if ((linkp = calloc(1, sizeof (dlmgmt_link_t))) == NULL) {
454 err = ENOMEM;
455 goto done;
456 }
457
458 (void) strlcpy(linkp->ll_link, name, MAXLINKNAMELEN);
459 linkp->ll_class = class;
460 linkp->ll_media = media;
461 linkp->ll_linkid = dlmgmt_nextlinkid;
462 linkp->ll_zoneid = zoneid;
463 linkp->ll_gen = 0;
464 linkp->ll_tomb = B_FALSE;
465
466 if (avl_find(&dlmgmt_name_avl, linkp, &name_where) != NULL ||
467 avl_find(&dlmgmt_id_avl, linkp, &id_where) != NULL) {
468 err = EEXIST;
469 goto done;
470 }
471
472 avl_insert(&dlmgmt_name_avl, linkp, name_where);
473 avl_insert(&dlmgmt_id_avl, linkp, id_where);
474
475 if ((flags & DLMGMT_ACTIVE) && (err = link_activate(linkp)) != 0) {
476 avl_remove(&dlmgmt_name_avl, linkp);
477 avl_remove(&dlmgmt_id_avl, linkp);
478 goto done;
479 }
480
481 linkp->ll_flags = flags;
482 dlmgmt_advance(linkp);
483 *linkpp = linkp;
484
|