/*
* 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 <libdladm_impl.h>
#include <libvrrpadm.h>
#include <libdllink.h>
#include <libdlbridge.h>
#include <libdlvnic.h>
/*
* VNIC administration library.
*/
/*
* Default random MAC address prefix (locally administered).
*/
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_INVALID_MTU);
default:
return (DLADM_STATUS_FAILED);
}
}
/*
* Send a create command to the VNIC driver.
*/
{
int rc;
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);
sizeof (macstr));
if (status != DLADM_STATUS_OK)
goto done;
if (status != DLADM_STATUS_OK)
goto done;
}
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 (status);
}
/*
* 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);
}
/*
* 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 caculated
* based on the above algorithm.
*/
{
int i;
/*
* Sanity test arguments.
*/
if ((flags & DLADM_OPT_ACTIVE) == 0)
return (DLADM_STATUS_NOTSUP);
return (DLADM_STATUS_VIDINVAL);
return (DLADM_STATUS_INVALIDMACADDRTYPE);
if ((flags & DLADM_OPT_ANCHOR) == 0) {
return (status);
if (class == DATALINK_CLASS_VNIC ||
return (DLADM_STATUS_BADARG);
} else {
/* it's an anchor VNIC */
return (DLADM_STATUS_BADARG);
}
/*
* 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 ||
mac_prefix_len == 0) {
mac_prefix_len = sizeof (dladm_vnic_def_prefix);
}
/*
* 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);
}
if (status != DLADM_STATUS_OK)
return (status);
}
if (mac_len > MAXMACADDRLEN)
return (DLADM_STATUS_INVALIDMACADDRLEN);
} else {
}
return (status);
if ((flags & DLADM_OPT_PREFIX) != 0) {
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 (is_vlan) {
}
return (status);
}
/*
* Delete a VNIC / VLAN.
*/
{
if (flags == 0)
return (DLADM_STATUS_BADARG);
!= DLADM_STATUS_OK))
return (DLADM_STATUS_BADARG);
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);
}
if ((flags & DLADM_OPT_ACTIVE) != 0) {
if (status == DLADM_STATUS_OK) {
} else if (status != DLADM_STATUS_NOTFOUND ||
!(flags & DLADM_OPT_PERSIST)) {
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
{
return (status);
if (status != DLADM_STATUS_OK)
goto done;
if (status != DLADM_STATUS_OK)
goto done;
}
if (class != DATALINK_CLASS_VLAN) {
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;
}
if (attrp->va_mac_prefix_len !=
sizeof (dladm_vnic_def_prefix)) {
if (status != DLADM_STATUS_OK)
goto done;
}
if (status != DLADM_STATUS_OK)
goto done;
}
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 {
}
}