xref: /titanic_52/usr/src/lib/libdladm/common/libdlvlan.c (revision 0f1702c5201310f0529cd5abb77652e5e9b241b6)
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(datalink_id_t vlanid, dladm_vlan_attr_t *dvap, uint32_t flags)
41 {
42 	dladm_status_t status;
43 	dladm_vnic_attr_t attr, *vnic = &attr;
44 
45 	if ((status = dladm_vnic_info(vlanid, vnic, flags)) !=
46 	    DLADM_STATUS_OK)
47 		return (status);
48 
49 	dvap->dv_vid = vnic->va_vid;
50 	dvap->dv_linkid = vnic->va_link_id;
51 	dvap->dv_force = vnic->va_force;
52 	return (status);
53 }
54 
55 /*
56  * Create a VLAN on given link.
57  */
58 dladm_status_t
59 dladm_vlan_create(const char *vlan, datalink_id_t linkid, uint16_t vid,
60     dladm_arg_list_t *proplist, uint32_t flags, datalink_id_t *vlan_id_out)
61 {
62 	return (dladm_vnic_create(vlan, linkid, VNIC_MAC_ADDR_TYPE_PRIMARY,
63 	    NULL, 0, NULL, 0, vid, vlan_id_out, proplist,
64 	    flags | DLADM_OPT_VLAN));
65 }
66 
67 /*
68  * Delete a given VLAN.
69  */
70 dladm_status_t
71 dladm_vlan_delete(datalink_id_t vlanid, uint32_t flags)
72 {
73 	return (dladm_vnic_delete(vlanid, flags | DLADM_OPT_VLAN));
74 }
75 
76 dladm_status_t
77 dladm_vlan_up(datalink_id_t linkid)
78 {
79 	return (dladm_vnic_up(linkid, DLADM_OPT_VLAN));
80 }
81