/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stropts.h>
#include <stdlib.h>
#include <errno.h>
#include <strings.h>
#include <libintl.h>
#include <net/if_types.h>
#include <sys/dls_mgmt.h>
#include <libdladm_impl.h>
#include <libvrrpadm.h>
#include <libdllink.h>
#include <libdlbridge.h>
#include <libdlvnic.h>
/*
* VNIC administration library.
*/
/*
* Default random MAC address prefix.
*/
const char *name, dladm_vnic_attr_t *,
static const char *dladm_vnic_macaddr2str(const uchar_t *, char *);
/*
* Convert a diagnostic returned by the kernel into a dladm_status_t.
*/
static dladm_status_t
{
switch (ioc_diag) {
case VNIC_IOC_DIAG_NONE:
return (DLADM_STATUS_OK);
return (DLADM_STATUS_INVALIDMACADDRLEN);
return (DLADM_STATUS_INVALIDMACADDRNIC);
return (DLADM_STATUS_INVALIDMACADDRINUSE);
return (DLADM_STATUS_MACFACTORYSLOTINVALID);
return (DLADM_STATUS_MACFACTORYSLOTUSED);
return (DLADM_STATUS_MACFACTORYSLOTALLUSED);
return (DLADM_STATUS_MACFACTORYNOTSUP);
return (DLADM_STATUS_INVALIDMACPREFIX);
return (DLADM_STATUS_INVALIDMACPREFIXLEN);
return (DLADM_STATUS_INVALID_MACMARGIN);
case VNIC_IOC_DIAG_NO_HWRINGS:
return (DLADM_STATUS_NO_HWRINGS);
return (DLADM_STATUS_INVALIDMACADDR);
return (DLADM_STATUS_VID_IS_PVID);
case VNIC_IOC_DIAG_EXCLUSIVE:
return (DLADM_STATUS_EXCLUSIVE);
default:
return (DLADM_STATUS_FAILED);
}
}
/*
* Send a create command to the VNIC driver.
*/
{
if (create) {
VNIC_IOC_OPT_ANCHOR : 0;
} else {
}
sizeof (mac_resource_props_t));
if (rc < 0)
if (status != DLADM_STATUS_OK) {
}
if (status != DLADM_STATUS_OK)
return (status);
switch (ioc.vc_mac_addr_type) {
break;
break;
}
return (status);
}
{
}
{
}
/*
* Get the configuration information of the given VNIC.
*/
static dladm_status_t
{
int rc;
if (rc != 0) {
goto bail;
}
bail:
return (status);
}
static dladm_status_t
{
return (status);
sizeof (linkover));
if (status != DLADM_STATUS_OK) {
/*
* This isn't an error, etherstubs don't have a FLINKOVER
* property.
*/
} else {
goto done;
}
goto done;
if (class == DATALINK_CLASS_VLAN) {
goto done;
}
attrp->va_mac_len = 0;
} else {
sizeof (u64));
if (status != DLADM_STATUS_OK)
goto done;
} else {
}
} else {
}
sizeof (u64));
sizeof (u64));
(int)u64 : -1);
if (status != DLADM_STATUS_OK)
goto done;
if ((attrp->va_mac_len != 0) ||
attrp->va_mac_prefix_len != 0) {
attrp->va_mac_addr);
if (status != DLADM_STATUS_OK)
goto done;
}
} else {
}
}
sizeof (u64));
done:
return (status);
}
{
if (flags == DLADM_OPT_ACTIVE)
else if (flags == DLADM_OPT_PERSIST)
else
return (DLADM_STATUS_BADARG);
}
/*
* Remove a VNIC from the kernel.
*/
{
int rc;
if (rc < 0)
return (dladm_errno2status(errno));
return (DLADM_STATUS_OK);
}
/*
* Convert between MAC address types and their string representations.
*/
typedef struct dladm_vnic_addr_type_s {
const char *va_str;
{"fixed", VNIC_MAC_ADDR_TYPE_FIXED},
{"random", VNIC_MAC_ADDR_TYPE_RANDOM},
{"factory", VNIC_MAC_ADDR_TYPE_FACTORY},
{"auto", VNIC_MAC_ADDR_TYPE_AUTO},
{"fixed", VNIC_MAC_ADDR_TYPE_PRIMARY},
{"vrrp", VNIC_MAC_ADDR_TYPE_VRID}
};
static const char *
{
int i;
for (i = 0; i < NADDR_TYPES; i++) {
return (addr_types[i].va_str);
}
return (NULL);
}
{
int i;
for (i = 0; i < NADDR_TYPES; i++) {
type = &addr_types[i];
return (DLADM_STATUS_OK);
}
}
return (DLADM_STATUS_BADARG);
}
/*
* Based on the VRRP specification, the virtual router MAC address associated
* with a virtual router is an IEEE 802 MAC address in the following format:
*
* IPv4 case: 00-00-5E-00-01-{VRID} (in hex in internet standard bit-order)
*
* IPv6 case: 00-00-5E-00-02-{VRID} (in hex in internet standard bit-order)
*/
static dladm_status_t
{
return (DLADM_STATUS_BADARG);
}
return (DLADM_STATUS_OK);
}
static dladm_status_t
{
return (DLADM_STATUS_INVALIDMACADDRTYPE);
/*
* Only VRRP VNIC need VRID and address family specified.
*/
if (mac_addr_type != VNIC_MAC_ADDR_TYPE_VRID &&
return (DLADM_STATUS_BADARG);
}
/*
* If a random address might be generated, but no prefix
* was specified by the caller, use the default MAC address
* prefix.
* If mac_addr_type == VNIC_MAC_ADDR_TYPE_RANDOM and
* mac_addr != NULL then we are trying to create a
* autovnic and reuse the previously generated mac address.
*/
if ((mac_addr_type == VNIC_MAC_ADDR_TYPE_RANDOM ||
*mac_prefix_len = sizeof (dladm_vnic_def_prefix);
if (is_etherstub && *mac_len == 0)
*mac_len = ETHERADDRL;
}
/*
* If this is a VRRP VNIC, generate its MAC address using the given
* VRID and address family.
*/
if (mac_addr_type == VNIC_MAC_ADDR_TYPE_VRID) {
/*
* VRRP VNICs must be created over ethernet data-links.
*/
*mac_len != 0 || *mac_prefix_len != 0 ||
return (DLADM_STATUS_BADARG);
}
*mac_len = ETHERADDRL;
if (status != DLADM_STATUS_OK)
return (status);
}
if (*mac_len > MAXMACADDRLEN)
return (DLADM_STATUS_INVALIDMACADDRLEN);
return (DLADM_STATUS_OK);
}
/*
* Create a new VNIC / VLAN. Update the configuration file and bring it up.
* The "vrid" and "af" arguments are only required if the mac_addr_type is
* VNIC_MAC_ADDR_TYPE_VRID. In that case, the MAC address will be calculated
* based on the above algorithm.
*
* If mac_addr_type is random then the randomly-generated mac address
* will be returned to the caller through auto_mac_addr.
*/
{
int i;
/*
* Sanity test arguments.
*/
if ((flags & DLADM_OPT_ACTIVE) == 0)
return (DLADM_STATUS_NOTSUP);
return (DLADM_STATUS_VIDINVAL);
if (!is_etherstub) {
return (status);
if (class == DATALINK_CLASS_VNIC ||
return (DLADM_STATUS_BADARG);
return (DLADM_STATUS_NOTSUP);
} else {
/* it's an anchor VNIC */
return (DLADM_STATUS_BADARG);
}
if (status != DLADM_STATUS_OK)
return (status);
} else {
}
return (status);
if ((flags & DLADM_OPT_PREFIX) != 0) {
"%llu", vnic_id);
flags &= ~DLADM_OPT_PREFIX;
}
/* Extract resource_ctl and cpu_list from proplist */
&attr.va_resource_props, 0);
if (status != DLADM_STATUS_OK)
goto done;
}
if (mac_len > 0)
else if (mac_prefix_len > 0)
if (status != DLADM_STATUS_OK)
goto done;
/* Save vnic configuration and its properties */
if (!(flags & DLADM_OPT_PERSIST))
goto done;
if (status != DLADM_STATUS_OK)
goto done;
if (status != DLADM_STATUS_OK)
break;
}
}
done:
if (status != DLADM_STATUS_OK) {
if (conf_set)
if (vnic_created)
} else {
if (vnic_id_out != NULL)
*vnic_id_out = vnic_id;
if (auto_mac_addr != NULL &&
}
if (is_vlan) {
}
return (status);
}
/* ARGSUSED */
{
return (DLADM_STATUS_NOTSUP);
return (status);
if (vnic_class != DATALINK_CLASS_VNIC &&
return (DLADM_STATUS_NOTSUP);
return (DLADM_STATUS_BADARG);
if ((flags & DLADM_OPT_PERSIST) != 0) {
return (status);
}
if (status != DLADM_STATUS_OK)
return (status);
if (mac_addr_type != VNIC_MAC_ADDR_TYPE_UNKNOWN) {
if (is_vlan)
return (DLADM_STATUS_NOTSUP);
flags);
if (status != DLADM_STATUS_OK)
return (status);
else
if (mac_len > 0)
else if (mac_prefix_len > 0)
if (mac_addr_type == VNIC_MAC_ADDR_TYPE_VRID) {
}
} else {
return (DLADM_STATUS_BADARG);
}
if (lower_linkid != DATALINK_INVALID_LINKID) {
return (status);
if (class == DATALINK_CLASS_VNIC ||
return (DLADM_STATUS_BADARG);
return (DLADM_STATUS_NOTSUP);
return (DLADM_STATUS_BADARG);
}
return (DLADM_STATUS_VIDINVAL);
} else {
return (DLADM_STATUS_BADARG);
}
if (status != DLADM_STATUS_OK)
goto done;
if ((flags & DLADM_OPT_PERSIST) == 0)
goto done;
if (attr.va_mac_len > 0) {
}
}
}
B_FALSE);
done:
if (status == DLADM_STATUS_OK) {
if (auto_mac_addr != NULL &&
}
}
return (status);
}
/*
* Delete a VNIC / VLAN.
*/
{
if (flags == 0)
return (DLADM_STATUS_BADARG);
/*
* Validate that flags are right since this code handles VNIC, VLAN
* and etherstubs.
*/
== DLADM_STATUS_OK) {
if ((flags & DLADM_OPT_VLAN) != 0) {
if (class != DATALINK_CLASS_VLAN)
return (DLADM_STATUS_BADARG);
} else {
if (class != DATALINK_CLASS_VNIC &&
return (DLADM_STATUS_BADARG);
}
}
/*
* Validate class in-kernel for active configuration to avoid the
* case where we cannot remove active VNICs where the (linkid, linkname)
* mapping has been removed.
*/
if ((flags & DLADM_OPT_ACTIVE) != 0) {
/* Validate if VNIC is a VLAN using in-kernel VNIC attrs. */
if ((flags & DLADM_OPT_VLAN) != 0 &&
return (DLADM_STATUS_BADARG);
if (status == DLADM_STATUS_OK ||
status == DLADM_STATUS_NOTFOUND) {
} else {
return (status);
}
}
if ((flags & DLADM_OPT_PERSIST) != 0) {
}
}
static const char *
{
static char unknown_mac[] = {0, 0, 0, 0, 0, 0};
return (NULL);
else
return (buf);
}
static dladm_status_t
{
int len = 0;
return (DLADM_STATUS_BADARG);
free(b);
return (DLADM_STATUS_OK);
}
static dladm_status_t
{
if (create) {
return (status);
} else {
&conf)) != DLADM_STATUS_OK)
return (status);
}
if (status != DLADM_STATUS_OK)
goto done;
if (status != DLADM_STATUS_OK)
goto done;
}
if (class != DATALINK_CLASS_VLAN) {
if (!create) {
}
DLADM_TYPE_UINT64, &u64);
if (status != DLADM_STATUS_OK)
goto done;
DLADM_TYPE_UINT64, &u64);
if (status != DLADM_STATUS_OK)
goto done;
}
DLADM_TYPE_UINT64, &u64);
if (status != DLADM_STATUS_OK)
goto done;
}
DLADM_TYPE_UINT64, &u64);
if (status != DLADM_STATUS_OK)
goto done;
}
if (status != DLADM_STATUS_OK)
goto done;
}
sizeof (dladm_vnic_def_prefix)) {
if (status != DLADM_STATUS_OK)
goto done;
}
macstr);
if (status != DLADM_STATUS_OK)
goto done;
}
}
if (!create)
DLADM_TYPE_UINT64, &u64);
if (status != DLADM_STATUS_OK)
goto done;
}
/*
* Commit the link configuration.
*/
done:
return (status);
}
typedef struct dladm_vnic_up_arg_s {
static int
{
if (status != DLADM_STATUS_OK)
goto done;
/* Get all properties for this vnic */
if (status != DLADM_STATUS_OK)
goto done;
}
if (status == DLADM_STATUS_OK) {
if (status != DLADM_STATUS_OK)
}
done:
return (DLADM_WALK_CONTINUE);
}
{
if (linkid == DATALINK_ALL_LINKID) {
return (DLADM_STATUS_OK);
} else {
}
}
/*
* Bring down a VNIC. Persistent configuration is not changed.
*/
static int
{
if (status == DLADM_STATUS_OK) {
}
return (DLADM_WALK_CONTINUE);
}
/*
* Bring down one VNIC (or VLAN) or all active VNICs (or VLANs). Persistent
* configuration and linkid mapping in dlmgmtd is not removed. Down VNIC(s)
* (and VLAN(s)) can be brought up with dladm_vnic_up().
*/
{
/* Handle VLANs, etherstubs and VNICs separately */
if (linkid == DATALINK_ALL_LINKID) {
} else {
}
return (status);
}