xref: /titanic_41/usr/src/lib/libdladm/common/libdlvlan.c (revision c93c462eec9d46f84d567abf52eb29a27c2e134b)
1 /*
2  * CDDL HEADER START
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #include <libdlvlan.h>
27 #include <libdlvnic.h>
28 
29 /*
30  * VLAN Administration Library.
31  *
32  * This library is used by administration tools such as dladm(1M) to
33  * configure VLANs.
34  */
35 
36 /*
37  * Returns the current attributes of the specified VLAN.
38  */
39 dladm_status_t
40 dladm_vlan_info(dladm_handle_t handle, datalink_id_t vlanid,
41     dladm_vlan_attr_t *dvap, uint32_t flags)
42 {
43 	dladm_status_t status;
44 	dladm_vnic_attr_t attr, *vnic = &attr;
45 
46 	if ((status = dladm_vnic_info(handle, vlanid, vnic, flags)) !=
47 	    DLADM_STATUS_OK)
48 		return (status);
49 
50 	dvap->dv_vid = vnic->va_vid;
51 	dvap->dv_linkid = vnic->va_link_id;
52 	dvap->dv_force = vnic->va_force;
53 	return (status);
54 }
55 
56 /*
57  * Create a VLAN on given link.
58  */
59 dladm_status_t
60 dladm_vlan_create(dladm_handle_t handle, const char *vlan, datalink_id_t linkid,
61     uint16_t vid, dladm_arg_list_t *proplist, uint32_t flags,
62     datalink_id_t *vlan_id_out)
63 {
64 	return (dladm_vnic_create(handle, vlan, linkid,
65 	    VNIC_MAC_ADDR_TYPE_PRIMARY, NULL, 0, NULL, 0, vid, vlan_id_out,
66 	    proplist, flags | DLADM_OPT_VLAN));
67 }
68 
69 /*
70  * Delete a given VLAN.
71  */
72 dladm_status_t
73 dladm_vlan_delete(dladm_handle_t handle, datalink_id_t vlanid, uint32_t flags)
74 {
75 	return (dladm_vnic_delete(handle, vlanid, flags | DLADM_OPT_VLAN));
76 }
77 
78 dladm_status_t
79 dladm_vlan_up(dladm_handle_t handle, datalink_id_t linkid)
80 {
81 	return (dladm_vnic_up(handle, linkid, DLADM_OPT_VLAN));
82 }
83