3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25 #include <stdio.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <string.h>
29 #include <fcntl.h>
30 #include <unistd.h>
31 #include <stropts.h>
32 #include <stdlib.h>
33 #include <errno.h>
34 #include <strings.h>
35 #include <libintl.h>
36 #include <net/if_types.h>
37 #include <net/if_dl.h>
38 #include <sys/dld.h>
39 #include <libdladm_impl.h>
40 #include <libvrrpadm.h>
41 #include <libdllink.h>
42 #include <libdlbridge.h>
522 attr.va_mac_addr_type = mac_addr_type;
523 attr.va_mac_len = mac_len;
524 if (mac_slot != NULL)
525 attr.va_mac_slot = *mac_slot;
526 if (mac_len > 0)
527 bcopy(mac_addr, attr.va_mac_addr, mac_len);
528 else if (mac_prefix_len > 0)
529 bcopy(mac_addr, attr.va_mac_addr, mac_prefix_len);
530 attr.va_mac_prefix_len = mac_prefix_len;
531 attr.va_vid = vid;
532 attr.va_vrid = vrid;
533 attr.va_af = af;
534 attr.va_force = (flags & DLADM_OPT_FORCE) != 0;
535
536 status = i_dladm_vnic_create_sys(handle, &attr);
537 if (status != DLADM_STATUS_OK)
538 goto done;
539 vnic_created = B_TRUE;
540
541 /* Save vnic configuration and its properties */
542 if (!(flags & DLADM_OPT_PERSIST))
543 goto done;
544
545 status = dladm_vnic_persist_conf(handle, name, &attr, class);
546 if (status != DLADM_STATUS_OK)
547 goto done;
548 conf_set = B_TRUE;
549
550 if (proplist != NULL) {
551 for (i = 0; i < proplist->al_count; i++) {
552 dladm_arg_info_t *aip = &proplist->al_info[i];
553
554 status = dladm_set_linkprop(handle, vnic_id,
555 aip->ai_name, aip->ai_val, aip->ai_count,
556 DLADM_OPT_PERSIST);
557 if (status != DLADM_STATUS_OK)
558 break;
559 }
560 }
561
562 done:
563 if (status != DLADM_STATUS_OK) {
564 if (conf_set)
565 (void) dladm_remove_conf(handle, vnic_id);
566 if (vnic_created)
567 (void) i_dladm_vnic_delete_sys(handle, vnic_id);
568 (void) dladm_destroy_datalink_id(handle, vnic_id, flags);
569 } else {
570 if (vnic_id_out != NULL)
571 *vnic_id_out = vnic_id;
572 if (mac_slot != NULL)
573 *mac_slot = attr.va_mac_slot;
574 }
575
576 if (is_vlan) {
577 dladm_status_t stat2;
578
579 stat2 = dladm_bridge_refresh(handle, linkid);
580 if (status == DLADM_STATUS_OK && stat2 != DLADM_STATUS_OK)
581 status = stat2;
582 }
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2011, Joyent Inc. All rights reserved.
24 */
25
26 #include <stdio.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <string.h>
30 #include <fcntl.h>
31 #include <unistd.h>
32 #include <stropts.h>
33 #include <stdlib.h>
34 #include <errno.h>
35 #include <strings.h>
36 #include <libintl.h>
37 #include <net/if_types.h>
38 #include <net/if_dl.h>
39 #include <sys/dld.h>
40 #include <libdladm_impl.h>
41 #include <libvrrpadm.h>
42 #include <libdllink.h>
43 #include <libdlbridge.h>
523 attr.va_mac_addr_type = mac_addr_type;
524 attr.va_mac_len = mac_len;
525 if (mac_slot != NULL)
526 attr.va_mac_slot = *mac_slot;
527 if (mac_len > 0)
528 bcopy(mac_addr, attr.va_mac_addr, mac_len);
529 else if (mac_prefix_len > 0)
530 bcopy(mac_addr, attr.va_mac_addr, mac_prefix_len);
531 attr.va_mac_prefix_len = mac_prefix_len;
532 attr.va_vid = vid;
533 attr.va_vrid = vrid;
534 attr.va_af = af;
535 attr.va_force = (flags & DLADM_OPT_FORCE) != 0;
536
537 status = i_dladm_vnic_create_sys(handle, &attr);
538 if (status != DLADM_STATUS_OK)
539 goto done;
540 vnic_created = B_TRUE;
541
542 /* Save vnic configuration and its properties */
543 if (flags & DLADM_OPT_PERSIST) {
544 status = dladm_vnic_persist_conf(handle, name, &attr, class);
545 if (status == DLADM_STATUS_OK)
546 conf_set = B_TRUE;
547 }
548
549 done:
550 if (status == DLADM_STATUS_OK && proplist != NULL) {
551 uint32_t flg;
552
553 flg = (flags & DLADM_OPT_PERSIST) ?
554 DLADM_OPT_PERSIST : DLADM_OPT_ACTIVE;
555
556 for (i = 0; i < proplist->al_count; i++) {
557 dladm_arg_info_t *aip = &proplist->al_info[i];
558
559 if (strcmp(aip->ai_name, "zone") == 0 &&
560 flags & DLADM_OPT_TRANSIENT)
561 flg |= DLADM_OPT_TRANSIENT;
562 else
563 flg &= ~DLADM_OPT_TRANSIENT;
564
565 status = dladm_set_linkprop(handle, vnic_id,
566 aip->ai_name, aip->ai_val, aip->ai_count, flg);
567 if (status != DLADM_STATUS_OK)
568 break;
569 }
570 }
571
572 if (status != DLADM_STATUS_OK) {
573 if (conf_set)
574 (void) dladm_remove_conf(handle, vnic_id);
575 if (vnic_created)
576 (void) i_dladm_vnic_delete_sys(handle, vnic_id);
577 (void) dladm_destroy_datalink_id(handle, vnic_id, flags);
578 } else {
579 if (vnic_id_out != NULL)
580 *vnic_id_out = vnic_id;
581 if (mac_slot != NULL)
582 *mac_slot = attr.va_mac_slot;
583 }
584
585 if (is_vlan) {
586 dladm_status_t stat2;
587
588 stat2 = dladm_bridge_refresh(handle, linkid);
589 if (status == DLADM_STATUS_OK && stat2 != DLADM_STATUS_OK)
590 status = stat2;
591 }
|