5088N/A/*
5088N/A * CDDL HEADER START
5088N/A *
5088N/A * The contents of this file are subject to the terms of the
5088N/A * Common Development and Distribution License (the "License").
5088N/A * You may not use this file except in compliance with the License.
5088N/A *
5088N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
5088N/A * or http://www.opensolaris.org/os/licensing.
5088N/A * See the License for the specific language governing permissions
5088N/A * and limitations under the License.
5088N/A *
5088N/A * When distributing Covered Code, include this CDDL HEADER in each
5088N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
5088N/A * If applicable, add the following below this CDDL HEADER, with the
5088N/A * fields enclosed by brackets "[]" replaced with your own identifying
5088N/A * information: Portions Copyright [yyyy] [name of copyright owner]
5088N/A *
5088N/A * CDDL HEADER END
5088N/A */
5088N/A
5088N/A/*
5503N/A * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
5088N/A */
5088N/A
5088N/A#include <config.h>
5088N/A
5088N/A#include <stdio.h>
5088N/A#include <stdlib.h>
5088N/A#include <ctype.h>
5088N/A#include <alloca.h>
5088N/A#include <errno.h>
5088N/A#include <limits.h>
5088N/A#include <string.h>
5088N/A#include <strings.h>
5088N/A#include <stropts.h>
5088N/A#include <sys/types.h>
5088N/A#include <sys/stat.h>
5088N/A#include <fcntl.h>
5088N/A#include <unistd.h>
5088N/A#include <inet/ip.h>
5088N/A#include <inet/ip6.h>
5088N/A#include <arpa/inet.h>
5088N/A#include <sys/sockio.h>
5088N/A#include <libdlpi.h>
5088N/A#include <libdladm.h>
5088N/A#include <libdllink.h>
5088N/A#include <zone.h>
5088N/A#include <net/if_types.h>
5088N/A#include <inet/arp.h>
5088N/A#include <sys/socket.h>
5088N/A#include <netdb.h>
5088N/A#include <rad/radclient.h>
5088N/A#include <rad/client/1/dlmgr.h>
5088N/A
5088N/A#undef IP_VERSION
5088N/A#include "netlink-protocol.h"
5088N/A#include "netlink.h"
5088N/A#include "flow.h"
5088N/A#include "packets.h"
5088N/A#include "util-solaris.h"
5088N/A#include "util.h"
5088N/A#include "dpif-solaris.h"
5088N/A
6554N/A#ifndef MAX_OF_ACTIONS_SIZE
6554N/A#define MAX_OF_ACTIONS_SIZE 4096
6554N/A#endif
6554N/A
5088N/Astatic rc_conn_t *rad_conn = NULL;
5088N/Astatic boolean_t b_true = B_TRUE;
5088N/A
5088N/Atypedef struct {
5088N/A uint_t ifsp_ppa; /* Physical Point of Attachment */
5088N/A uint_t ifsp_lun; /* Logical Unit number */
5088N/A boolean_t ifsp_lunvalid; /* TRUE if lun is valid */
5088N/A char ifsp_devnm[LIFNAMSIZ]; /* only the device name */
5088N/A} ifspec_t;
5088N/A
6554N/Atypedef struct {
6554N/A uint32_t ofp_min;
6554N/A uint32_t ofp_max;
6554N/A} ofport_range_t;
6554N/A
5088N/Astatic int
5088N/Aextract_uint(const char *valstr, uint_t *val)
5088N/A{
5088N/A char *ep;
5088N/A unsigned long ul;
5088N/A
5088N/A errno = 0;
5088N/A ul = strtoul(valstr, &ep, 10);
5088N/A if (errno != 0 || *ep != '\0' || ul > UINT_MAX)
5088N/A return (-1);
5088N/A *val = (uint_t)ul;
5088N/A return (0);
5088N/A}
5088N/A
5088N/A/*
5088N/A * Given a token with a logical unit spec, return the logical unit converted
5088N/A * to a uint_t.
5088N/A *
5088N/A * Returns: 0 for success, nonzero if an error occurred. errno is set if
5088N/A * necessary.
5088N/A */
5088N/Astatic int
5088N/Agetlun(const char *bp, size_t bpsize, uint_t *lun)
5088N/A{
5088N/A const char *ep = &bp[bpsize - 1];
5088N/A const char *tp;
5088N/A
5088N/A /* Lun must be all digits */
5088N/A for (tp = ep; tp > bp && isdigit(*tp); tp--)
5088N/A /* Null body */;
5088N/A
5088N/A if (tp == ep || tp != bp || extract_uint(bp + 1, lun) != 0) {
5088N/A errno = EINVAL;
5088N/A return (-1);
5088N/A }
5088N/A return (0);
5088N/A}
5088N/A
5088N/A/*
5088N/A * Given a single token ending with a ppa spec, return the ppa spec converted
5088N/A * to a uint_t.
5088N/A *
5088N/A * Returns: 0 for success, nonzero if an error occurred. errno is set if
5088N/A * necessary.
5088N/A */
5088N/Astatic int
5088N/Agetppa(const char *bp, size_t bpsize, uint_t *ppa)
5088N/A{
5088N/A const char *ep = &bp[bpsize - 1];
5088N/A const char *tp;
5088N/A
5088N/A for (tp = ep; tp >= bp && isdigit(*tp); tp--)
5088N/A /* Null body */;
5088N/A
5088N/A /*
5088N/A * If the device name does not end with a digit or the device
5088N/A * name is a sequence of numbers or a PPA contains a leading
5088N/A * zero, return error.
5088N/A */
5088N/A if (tp == ep || tp < bp || ((ep - tp) > 1 && *(tp + 1) == '0'))
5088N/A goto fail;
5088N/A
5088N/A if (extract_uint(tp + 1, ppa) != 0)
5088N/A goto fail;
5088N/A
5088N/A /* max value of PPA is 4294967294, which is (UINT_MAX - 1) */
5088N/A if (*ppa > UINT_MAX - 1)
5088N/A goto fail;
5088N/A return (0);
5088N/Afail:
5088N/A errno = EINVAL;
5088N/A return (-1);
5088N/A}
5088N/A
5088N/A/*
5088N/A * Given a `linkname' of the form drv(ppa), parse it into `driver' and `ppa'.
5088N/A * If the `dsize' for the `driver' is not atleast MAXLINKNAMELEN then part of
5088N/A * the driver name will be copied to `driver'.
5088N/A *
5088N/A * This function also validates driver name and PPA and therefore callers can
5088N/A * call this function with `driver' and `ppa' set to NULL, to just verify the
5088N/A * linkname.
5088N/A */
5088N/Aboolean_t
5088N/Adlparse_drvppa(const char *linknamep, char *driver, uint_t dsize, uint_t *ppa)
5088N/A{
5088N/A char *tp;
5088N/A char linkname[MAXLINKNAMELEN];
5088N/A size_t len;
5088N/A uint_t lppa;
5088N/A
5088N/A if (linknamep == NULL || linknamep[0] == '\0')
5088N/A goto fail;
5088N/A
5088N/A len = strlcpy(linkname, linknamep, MAXLINKNAMELEN);
5088N/A if (len >= MAXLINKNAMELEN)
5088N/A goto fail;
5088N/A
5088N/A /* Get PPA */
5088N/A if (getppa(linkname, len, &lppa) != 0)
5088N/A return (_B_FALSE);
5088N/A
5088N/A /* strip the ppa off of the linkname, if present */
5088N/A for (tp = &linkname[len - 1]; tp >= linkname && isdigit(*tp); tp--)
5088N/A *tp = '\0';
5088N/A
5088N/A /*
5088N/A * Now check for the validity of the device name. The legal characters
5088N/A * in a device name are: alphanumeric (a-z, A-Z, 0-9), underscore
5088N/A * ('_'), hyphen ('-'), and period ('.'). The first character
5088N/A * of the device name cannot be a digit and should be an alphabetic
5088N/A * character.
5088N/A */
5088N/A if (!isalpha(linkname[0]))
5088N/A goto fail;
5088N/A for (tp = linkname + 1; *tp != '\0'; tp++) {
5088N/A if (!isalnum(*tp) && *tp != '_' && *tp != '-' && *tp != '.')
5088N/A goto fail;
5088N/A }
5088N/A
5088N/A if (driver != NULL)
5088N/A (void) strlcpy(driver, linkname, dsize);
5088N/A
5088N/A if (ppa != NULL)
5088N/A *ppa = lppa;
5088N/A
5088N/A return (_B_TRUE);
5088N/Afail:
5088N/A errno = EINVAL;
5088N/A return (_B_FALSE);
5088N/A}
5088N/A
5088N/A/*
5088N/A * Given an IP interface name, which is either a
5088N/A * - datalink name (which is driver name plus PPA), for e.g. bge0 or
5088N/A * - datalink name plus a logical interface identifier (delimited by ':'),
5088N/A * for e.g. bge0:34
5088N/A * the following function validates its form and decomposes the contents into
5088N/A * ifspec_t.
5088N/A *
5088N/A * Returns _B_TRUE for success, otherwise _B_FALSE is returned.
5088N/A */
5088N/Astatic boolean_t
5088N/Aifparse_ifspec(const char *ifname, ifspec_t *ifsp)
5088N/A{
5088N/A char *lp;
5088N/A char ifnamecp[LIFNAMSIZ];
5088N/A
5088N/A if (ifname == NULL || ifname[0] == '\0' ||
5088N/A strlcpy(ifnamecp, ifname, LIFNAMSIZ) >= LIFNAMSIZ) {
5088N/A errno = EINVAL;
5088N/A return (_B_FALSE);
5088N/A }
5088N/A
5088N/A ifsp->ifsp_lunvalid = _B_FALSE;
5088N/A
5088N/A /* Any logical units? */
5088N/A lp = strchr(ifnamecp, ':');
5088N/A if (lp != NULL) {
5088N/A if (getlun(lp, strlen(lp), &ifsp->ifsp_lun) != 0)
5088N/A return (_B_FALSE);
5088N/A *lp = '\0';
5088N/A ifsp->ifsp_lunvalid = _B_TRUE;
5088N/A }
5088N/A
5088N/A return (dlparse_drvppa(ifnamecp, ifsp->ifsp_devnm,
5088N/A sizeof (ifsp->ifsp_devnm), &ifsp->ifsp_ppa));
5088N/A}
5088N/A
5088N/A/*
5088N/A * Issues the ioctl SIOCSLIFNAME to kernel.
5088N/A */
5088N/Astatic int
5088N/Aslifname(const char *ifname, uint64_t flags, int fd)
5088N/A{
5088N/A struct lifreq lifr;
5088N/A int status = 0;
5088N/A ifspec_t ifsp;
5088N/A boolean_t valid_if;
5088N/A
5088N/A bzero(&lifr, sizeof (lifr));
5088N/A
5088N/A /* We should have already validated the interface name. */
5088N/A valid_if = ifparse_ifspec(ifname, &ifsp);
5088N/A ovs_assert(valid_if);
5088N/A
5088N/A lifr.lifr_ppa = ifsp.ifsp_ppa;
5088N/A lifr.lifr_flags = flags;
5088N/A (void) strlcpy(lifr.lifr_name, ifname, sizeof (lifr.lifr_name));
5088N/A if (ioctl(fd, SIOCSLIFNAME, &lifr) == -1) {
5088N/A status = errno;
5088N/A }
5088N/A
5088N/A return (status);
5088N/A}
5088N/A
5088N/A/*
5088N/A * Wrapper for sending a non-transparent I_STR ioctl().
5088N/A * Returns: Result from ioctl().
5088N/A */
5088N/Astatic int
5088N/Astrioctl(int s, int cmd, char *buf, uint_t buflen)
5088N/A{
5088N/A struct strioctl ioc;
5088N/A
5088N/A (void) memset(&ioc, 0, sizeof (ioc));
5088N/A ioc.ic_cmd = cmd;
5088N/A ioc.ic_timout = 0;
5088N/A ioc.ic_len = buflen;
5088N/A ioc.ic_dp = buf;
5088N/A
5088N/A return (ioctl(s, I_STR, (char *)&ioc));
5088N/A}
5088N/A
5088N/A/*
5088N/A * Issues the ioctl SIOCSLIFNAME to kernel on the given ARP stream fd.
5088N/A */
5088N/Astatic int
5088N/Aslifname_arp(const char *ifname, uint64_t flags, int fd)
5088N/A{
5088N/A struct lifreq lifr;
5088N/A ifspec_t ifsp;
5088N/A
5088N/A bzero(&lifr, sizeof (lifr));
5088N/A (void) ifparse_ifspec(ifname, &ifsp);
5088N/A lifr.lifr_ppa = ifsp.ifsp_ppa;
5088N/A lifr.lifr_flags = flags;
5088N/A (void) strlcpy(lifr.lifr_name, ifname, sizeof (lifr.lifr_name));
5088N/A /*
5088N/A * Tell ARP the name and unit number for this interface.
5088N/A * Note that arp has no support for transparent ioctls.
5088N/A */
5088N/A if (strioctl(fd, SIOCSLIFNAME, (char *)&lifr,
5088N/A sizeof (lifr)) == -1) {
5088N/A return (errno);
5088N/A }
5088N/A return (0);
5088N/A}
5088N/A
5088N/A/*
5088N/A * Open "/dev/udp{,6}" for use as a multiplexor to PLINK the interface stream
5088N/A * under. We use "/dev/udp" instead of "/dev/ip" since STREAMS will not let
5088N/A * you PLINK a driver under itself, and "/dev/ip" is typically the driver at
5088N/A * the bottom of the stream for tunneling interfaces.
5088N/A */
5088N/Astatic int
5088N/Aopen_arp_on_udp(const char *udp_dev_name, int *fd)
5088N/A{
5088N/A int err;
5088N/A
5088N/A if ((*fd = open(udp_dev_name, O_RDWR)) == -1)
5088N/A return (errno);
5088N/A /*
5088N/A * Pop off all undesired modules (note that the user may have
5088N/A * configured autopush to add modules above udp), and push the
5088N/A * arp module onto the resulting stream. This is used to make
5088N/A * IP+ARP be able to atomically track the muxid for the I_PLINKed
5088N/A * STREAMS, thus it isn't related to ARP running the ARP protocol.
5088N/A */
5088N/A while (ioctl(*fd, I_POP, 0) != -1)
5088N/A ;
5088N/A if (errno == EINVAL && ioctl(*fd, I_PUSH, ARP_MOD_NAME) != -1)
5088N/A return (0);
5088N/A
5088N/A err = errno;
5088N/A (void) close(*fd);
5088N/A return (err);
5088N/A}
5088N/A
5088N/Astatic char *
5088N/Asolaris_proto2str(uint8_t protocol)
5088N/A{
5088N/A if (protocol == IPPROTO_TCP)
5088N/A return ("tcp");
5088N/A if (protocol == IPPROTO_UDP)
5088N/A return ("udp");
5088N/A if (protocol == IPPROTO_SCTP)
5088N/A return ("sctp");
5088N/A if (protocol == IPPROTO_ICMPV6)
5088N/A return ("icmpv6");
5088N/A if (protocol == IPPROTO_ICMP)
5088N/A return ("icmp");
5088N/A else
5088N/A return ("");
5088N/A}
5088N/A
5088N/Astatic uint8_t
5088N/Asolaris_str2proto(const char *protostr)
5088N/A{
5088N/A if (strcasecmp(protostr, "tcp") == 0)
5088N/A return (IPPROTO_TCP);
5088N/A else if (strcasecmp(protostr, "udp") == 0)
5088N/A return (IPPROTO_UDP);
5088N/A else if (strcasecmp(protostr, "sctp") == 0)
5088N/A return (IPPROTO_SCTP);
5088N/A else if (strcasecmp(protostr, "icmpv6") == 0)
5088N/A return (IPPROTO_ICMPV6);
5088N/A else if (strcasecmp(protostr, "icmp") == 0)
5088N/A return (IPPROTO_ICMP);
5088N/A return (0);
5088N/A}
5088N/A
5088N/A/*
5088N/A * Returns the flags value for the logical interface in `lifname'
5088N/A * in the buffer pointed to by `flags'.
5088N/A */
5088N/Astatic int
5088N/Asolaris_get_flags(int sock, const char *lifname, uint64_t *flags)
5088N/A{
5088N/A struct lifreq lifr;
5088N/A
5088N/A bzero(&lifr, sizeof (lifr));
5088N/A (void) strlcpy(lifr.lifr_name, lifname, sizeof (lifr.lifr_name));
5088N/A
5088N/A if (ioctl(sock, SIOCGLIFFLAGS, (caddr_t)&lifr) < 0)
5088N/A return (errno);
5088N/A *flags = lifr.lifr_flags;
5088N/A
5088N/A return (0);
5088N/A}
5088N/A
5088N/A/*
5088N/A * For a given interface name, checks if IP interface exists.
5088N/A */
5088N/Aint
5088N/Asolaris_if_enabled(int sock, const char *ifname, uint64_t *flags)
5088N/A{
5088N/A struct lifreq lifr;
5088N/A int error = 0;
5088N/A
5088N/A bzero(&lifr, sizeof (lifr));
5088N/A (void) strlcpy(lifr.lifr_name, ifname, sizeof (lifr.lifr_name));
5088N/A if (ioctl(sock, SIOCGLIFFLAGS, (caddr_t)&lifr) != 0)
5088N/A error = errno;
5088N/A
5088N/A if (error == 0 && flags != NULL)
5088N/A *flags = lifr.lifr_flags;
5088N/A
5088N/A return (error);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_unplumb_if(int sock, const char *ifname, sa_family_t af)
5088N/A{
5088N/A int ip_muxid;
5088N/A int arp_muxid;
5088N/A int mux_fd = -1;
5088N/A int muxid_fd = -1;
5088N/A char *udp_dev_name;
5088N/A uint64_t ifflags = 0;
5088N/A boolean_t changed_arp_muxid = B_FALSE;
5088N/A struct lifreq lifr;
5088N/A int ret = 0;
5088N/A boolean_t v6 = (af == AF_INET6);
5088N/A
5088N/A /*
5088N/A * We used /dev/udp or udp6 to set up the mux. So we have to use
5088N/A * the same now for PUNLINK also.
5088N/A */
5088N/A udp_dev_name = (v6 ? UDP6_DEV_NAME : UDP_DEV_NAME);
5088N/A if ((muxid_fd = open(udp_dev_name, O_RDWR)) == -1) {
5088N/A ret = errno;
5088N/A goto done;
5088N/A }
5088N/A ret = open_arp_on_udp(udp_dev_name, &mux_fd);
5088N/A if (ret != 0)
5088N/A goto done;
5088N/A
5088N/A bzero(&lifr, sizeof (lifr));
5088N/A (void) strlcpy(lifr.lifr_name, ifname, sizeof (lifr.lifr_name));
5088N/A if (ioctl(muxid_fd, SIOCGLIFMUXID, (caddr_t)&lifr) < 0) {
5088N/A ret = errno;
5088N/A goto done;
5088N/A }
5088N/A arp_muxid = lifr.lifr_arp_muxid;
5088N/A ip_muxid = lifr.lifr_ip_muxid;
5088N/A
5088N/A ret = solaris_get_flags(sock, ifname, &ifflags);
5088N/A if (ret != 0)
5088N/A goto done;
5088N/A /*
5088N/A * We don't have a good way of knowing whether the arp stream is
5088N/A * plumbed. We can't rely on IFF_NOARP because someone could
5088N/A * have turned it off later using "ifconfig xxx -arp".
5088N/A */
5088N/A if (arp_muxid != 0) {
5088N/A if (ioctl(mux_fd, I_PUNLINK, arp_muxid) < 0) {
5088N/A if ((errno == EINVAL) &&
5088N/A (ifflags & (IFF_NOARP | IFF_IPV6))) {
5088N/A /*
5088N/A * Some plumbing utilities set the muxid to
5088N/A * -1 or some invalid value to signify that
5088N/A * there is no arp stream. Set the muxid to 0
5088N/A * before trying to unplumb the IP stream.
5088N/A * IP does not allow the IP stream to be
5088N/A * unplumbed if it sees a non-null arp muxid,
5088N/A * for consistency of IP-ARP streams.
5088N/A */
5088N/A lifr.lifr_arp_muxid = 0;
5088N/A (void) ioctl(muxid_fd, SIOCSLIFMUXID,
5088N/A (caddr_t)&lifr);
5088N/A changed_arp_muxid = B_TRUE;
5088N/A }
5088N/A }
5088N/A }
5088N/A
5088N/A if (ioctl(mux_fd, I_PUNLINK, ip_muxid) < 0) {
5088N/A if (changed_arp_muxid) {
5088N/A /*
5088N/A * Some error occurred, and we need to restore
5088N/A * everything back to what it was.
5088N/A */
5088N/A ret = errno;
5088N/A lifr.lifr_arp_muxid = arp_muxid;
5088N/A lifr.lifr_ip_muxid = ip_muxid;
5088N/A (void) ioctl(muxid_fd, SIOCSLIFMUXID, (caddr_t)&lifr);
5088N/A }
5088N/A }
5088N/Adone:
5088N/A if (muxid_fd != -1)
5088N/A (void) close(muxid_fd);
5088N/A if (mux_fd != -1)
5088N/A (void) close(mux_fd);
5088N/A
5088N/A return (ret);
5088N/A}
5088N/A
5088N/A/*
5088N/A * Plumbs the interface `ifname'.
5088N/A */
5088N/Aint
5088N/Asolaris_plumb_if(int sock, const char *ifname, sa_family_t af)
5088N/A{
5088N/A int ip_muxid;
5088N/A int mux_fd = -1, ip_fd, arp_fd;
5088N/A char *udp_dev_name;
5088N/A dlpi_handle_t dh_arp = NULL, dh_ip = NULL;
5088N/A uint64_t ifflags;
5088N/A uint_t dlpi_flags;
5088N/A int status = 0;
5088N/A const char *linkname;
5088N/A int ret;
5088N/A
5088N/A if (solaris_if_enabled(sock, ifname, NULL) == 0) {
5088N/A status = EEXIST;
5088N/A goto done;
5088N/A }
5088N/A
5088N/A dlpi_flags = DLPI_NOATTACH;
5088N/A linkname = ifname;
5088N/A
5088N/A /*
5088N/A * We use DLPI_NOATTACH because the ip module will do the attach
5088N/A * itself for DLPI style-2 devices.
5088N/A */
5088N/A ret = dlpi_open(linkname, &dh_ip, dlpi_flags);
5088N/A if (ret != DLPI_SUCCESS) {
5088N/A ret = (ret == DL_SYSERR) ? errno : EOPNOTSUPP;
5088N/A goto done;
5088N/A }
5088N/A
5088N/A ip_fd = dlpi_fd(dh_ip);
5088N/A if (ioctl(ip_fd, I_PUSH, IP_MOD_NAME) == -1) {
5088N/A status = errno;
5088N/A goto done;
5088N/A }
5088N/A
5088N/A if (af == AF_INET) {
5088N/A ifflags = IFF_IPV4;
5088N/A } else {
5088N/A ifflags = IFF_IPV6;
5088N/A ifflags |= IFF_NOLINKLOCAL;
5088N/A }
5088N/A
5088N/A status = slifname(ifname, ifflags, ip_fd);
5088N/A if (status != 0)
5088N/A goto done;
5088N/A
5088N/A /* Get the full set of existing flags for this stream */
5088N/A status = solaris_get_flags(sock, ifname, &ifflags);
5088N/A if (status != 0)
5088N/A goto done;
5088N/A
5088N/A udp_dev_name = (af == AF_INET6 ? UDP6_DEV_NAME : UDP_DEV_NAME);
5088N/A status = open_arp_on_udp(udp_dev_name, &mux_fd);
5088N/A if (status != 0)
5088N/A goto done;
5088N/A
5088N/A /* Check if arp is not needed */
5088N/A if (ifflags & (IFF_NOARP|IFF_IPV6)) {
5088N/A /*
5088N/A * PLINK the interface stream so that the application can exit
5088N/A * without tearing down the stream.
5088N/A */
5088N/A if ((ip_muxid = ioctl(mux_fd, I_PLINK, ip_fd)) == -1)
5088N/A status = errno;
5088N/A goto done;
5088N/A }
5088N/A
5088N/A /*
5088N/A * This interface does use ARP, so set up a separate stream
5088N/A * from the interface to ARP.
5088N/A *
5088N/A * We use DLPI_NOATTACH because the arp module will do the attach
5088N/A * itself for DLPI style-2 devices.
5088N/A */
5088N/A ret = dlpi_open(linkname, &dh_arp, dlpi_flags);
5088N/A if (ret != DLPI_SUCCESS) {
5088N/A ret = (ret == DL_SYSERR) ? errno : EOPNOTSUPP;
5088N/A goto done;
5088N/A }
5088N/A
5088N/A arp_fd = dlpi_fd(dh_arp);
5088N/A if (ioctl(arp_fd, I_PUSH, ARP_MOD_NAME) == -1) {
5088N/A status = errno;
5088N/A goto done;
5088N/A }
5088N/A status = slifname_arp(ifname, ifflags, arp_fd);
5088N/A if (status != 0)
5088N/A goto done;
5088N/A /*
5088N/A * PLINK the IP and ARP streams so that we can exit
5088N/A * without tearing down the stream.
5088N/A */
5088N/A if ((ip_muxid = ioctl(mux_fd, I_PLINK, ip_fd)) == -1) {
5088N/A status = errno;
5088N/A goto done;
5088N/A }
5088N/A
5088N/A if (ioctl(mux_fd, I_PLINK, arp_fd) < 0) {
5088N/A status = errno;
5088N/A (void) ioctl(mux_fd, I_PUNLINK, ip_muxid);
5088N/A }
5088N/A
5088N/Adone:
5088N/A dlpi_close(dh_ip);
5088N/A if (dh_arp != NULL)
5088N/A dlpi_close(dh_arp);
5088N/A if (mux_fd != -1)
5088N/A (void) close(mux_fd);
5088N/A
5088N/A return (status);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_init_rad()
5088N/A{
5507N/A rc_uri_t *rc_uri;
5507N/A
5088N/A if (rad_conn == NULL) {
5507N/A if ((rc_uri = rc_alloc_uri("unix://", RCS_UNIX)) == NULL)
5088N/A return (ENODEV); /* Not sure what to return */
5507N/A
5507N/A rad_conn = rc_connect_uri(rc_uri, NULL);
5507N/A rc_free_uri(rc_uri);
5507N/A if (rad_conn == NULL)
5507N/A return (ENODEV); /* Not sure what to return */
5728N/A }
5728N/A return (0);
5088N/A}
5088N/A
5088N/Astatic rc_err_t
5088N/Atest_dlclass(const char *key, dlmgr_DLValue_t *dlval, void *arg)
5088N/A{
5088N/A if (strcmp(key, "class") == 0)
5088N/A (void) strlcpy((char *)arg, dlval->ddlv_sval, DLADM_STRSIZE);
5088N/A dlmgr_DLValue_free(dlval);
5088N/A return (RCE_OK);
5088N/A}
5088N/A
5088N/Astatic rc_err_t
5088N/Atest_dllower(const char *key, dlmgr_DLValue_t *dlval, void *arg)
5088N/A{
5088N/A /* TODO(gmoodalb): seems like we need physname/devname here */
5088N/A if (strcmp(key, "over") == 0) {
5088N/A (void) strlcpy((char *)arg, dlval->ddlv_slist[0],
5088N/A DLADM_STRSIZE);
5088N/A }
5088N/A dlmgr_DLValue_free(dlval);
5088N/A return (RCE_OK);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Asolaris_get_dlinfo(const char *netdev_name, char *info_val, size_t info_len,
5088N/A rc_err_t (*test_cb)(const char *, dlmgr_DLValue_t *, void *))
5088N/A{
5088N/A dlmgr__rad_dict_string_DLValue_t *linkinfo = NULL;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A rc_instance_t *link = NULL;
5088N/A rc_err_t status;
5088N/A char propstr[DLADM_STRSIZE];
5088N/A int error = 0;
5088N/A
5088N/A status = dlmgr_Datalink__rad_lookup(rad_conn, B_TRUE, &link, 1,
5088N/A "name", netdev_name);
5088N/A if (status != RCE_OK) {
5088N/A error = ENODEV;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A status = dlmgr_Datalink_getInfo(link, NULL, 0, &linkinfo, &derrp);
5088N/A if (status != RCE_OK) {
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A dpif_log(derrp->dde_err,
5088N/A "failed Datalink_getInfo(%s): %s",
5088N/A netdev_name, derrp->dde_errmsg);
5088N/A }
5088N/A error = ENOTSUP;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A propstr[0] = '\0';
5088N/A status = dlmgr__rad_dict_string_DLValue_map(linkinfo, test_cb,
5088N/A propstr);
5088N/A if (status != RCE_OK) {
5088N/A error = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A memcpy(info_val, propstr, info_len);
5088N/Aout:
5088N/A dlmgr__rad_dict_string_DLValue_free(linkinfo);
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A rc_instance_rele(link);
5088N/A return (error);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_get_devname(const char *netdev_name, char *name_val, size_t name_len)
5088N/A{
5088N/A dlmgr__rad_dict_string_DLValue_t *linkinfo = NULL;
5088N/A dlmgr_DLValue_t *dlval = NULL;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A rc_instance_t *link = NULL;
5088N/A rc_err_t status;
5088N/A int error = 0;
5088N/A
5088N/A status = dlmgr_Physical__rad_lookup(rad_conn, B_TRUE, &link, 1,
5088N/A "name", netdev_name);
5088N/A if (status != RCE_OK) {
5088N/A error = ENODEV;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A status = dlmgr_Physical_getInfo(link, NULL, 0, &linkinfo, &derrp);
5088N/A if (status != RCE_OK) {
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A dpif_log(derrp->dde_err,
5088N/A "failed Physical_getInfo(%s): %s",
5088N/A netdev_name, derrp->dde_errmsg);
5088N/A }
5088N/A error = ENODEV;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A status = dlmgr__rad_dict_string_DLValue_get(linkinfo, "device",
5088N/A &dlval);
5088N/A if (status != RCE_OK) {
5088N/A error = ENODEV;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A memcpy(name_val, dlval->ddlv_sval, name_len);
5088N/Aout:
5088N/A dlmgr_DLValue_free(dlval);
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A dlmgr__rad_dict_string_DLValue_free(linkinfo);
5088N/A rc_instance_rele(link);
5088N/A return (error);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_get_dlclass(const char *netdev_name, char *class_val, size_t class_len)
5088N/A{
5088N/A return (solaris_get_dlinfo(netdev_name, class_val, class_len,
5088N/A test_dlclass));
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_get_dllower(const char *netdev_name, char *lower_val, size_t lower_len)
5088N/A{
5088N/A return (solaris_get_dlinfo(netdev_name, lower_val, lower_len,
5088N/A test_dllower));
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_get_dlprop(const char *netdev_name, const char *prop_name,
5088N/A const char *field_name, char *prop_value, size_t prop_len)
5088N/A{
5088N/A dlmgr_DLDict_t **dlist = NULL;
5088N/A dlmgr_DLValue_t *dlval = NULL;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A rc_instance_t *link = NULL;
5088N/A rc_err_t status;
5088N/A const char *props[1];
5088N/A const char *fields[1];
5088N/A int ndlist = 0;
5088N/A int error = 0, i = 0;
5088N/A char buf[DLADM_STRSIZE];
5088N/A
5088N/A status = dlmgr_Datalink__rad_lookup(rad_conn, B_TRUE, &link, 1,
5088N/A "name", netdev_name);
5088N/A if (status != RCE_OK) {
5088N/A error = ENODEV;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A props[0] = prop_name;
5088N/A fields[0] = field_name;
5088N/A status = dlmgr_Datalink_getProperties(link, props, 1, fields, 1,
5088N/A &dlist, &ndlist, &derrp);
5088N/A if (status != RCE_OK) {
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A dpif_log(derrp->dde_err,
5088N/A "failed Datalink_getProperties(%s, %s): %s",
5088N/A netdev_name, prop_name, derrp->dde_errmsg);
5088N/A }
5088N/A error = ENOTSUP;
5088N/A goto out;
5088N/A }
5088N/A status = dlmgr__rad_dict_string_DLValue_get((*dlist)->ddld_map,
5088N/A field_name, &dlval);
5088N/A if (status != RCE_OK) {
5088N/A error = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A switch (dlval->ddlv_type) {
5088N/A case DDLVT_STRING:
5088N/A if (dlval->ddlv_sval == NULL) {
5088N/A error = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A memcpy(prop_value, dlval->ddlv_sval, prop_len);
5088N/A break;
5088N/A case DDLVT_STRINGS:
5088N/A if (dlval->ddlv_slist_count == 0) {
5088N/A error = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A for (i = 0; i < dlval->ddlv_slist_count; i++) {
5088N/A (void) snprintf(buf, sizeof (buf), "%s%s",
5088N/A (i != 0 ? "," : ""), dlval->ddlv_slist[i]);
5088N/A }
5088N/A memcpy(prop_value, buf, prop_len);
5088N/A break;
5088N/A case DDLVT_ULONG:
5088N/A if (dlval->ddlv_ulval == NULL) {
5088N/A error = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A (void) snprintf(buf, sizeof (buf), "%llu", *dlval->ddlv_ulval);
5088N/A memcpy(prop_value, buf, prop_len);
5088N/A break;
5088N/A case DDLVT_BOOLEAN:
6016N/A if (dlval->ddlv_bval == NULL) {
6016N/A error = EINVAL;
6016N/A goto out;
6016N/A }
6016N/A (void) snprintf(buf, sizeof (buf), "%d", *dlval->ddlv_bval);
6016N/A memcpy(prop_value, buf, prop_len);
6016N/A break;
5088N/A case DDLVT_BOOLEANS:
5088N/A case DDLVT_LONG:
5088N/A case DDLVT_LONGS:
5088N/A case DDLVT_ULONGS:
5088N/A case DDLVT_DICTIONARY:
5088N/A case DDLVT_DICTIONARYS:
5088N/A default:
5088N/A ovs_assert(0);
5088N/A break;
5088N/A }
5088N/Aout:
5088N/A dlmgr_DLValue_free(dlval);
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A dlmgr_DLDict_array_free(dlist, ndlist);
5088N/A rc_instance_rele(link);
5088N/A return (error);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Asolaris_set_dlprop(const char *netdev_name, const char *propname, void *arg,
6016N/A dlmgr_DLValueType_t vtype, boolean_t temp)
5088N/A{
5088N/A dlmgr__rad_dict_string_DLValue_t *sprop_dict = NULL;
5088N/A dlmgr_DLValue_t *old_val = NULL;
5088N/A dlmgr_DLValue_t new_val;
5088N/A rc_instance_t *link = NULL;
5088N/A rc_err_t status;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A int error = 0;
5088N/A
5088N/A status = dlmgr_Datalink__rad_lookup(rad_conn, B_TRUE, &link, 1,
5088N/A "name", netdev_name);
5088N/A if (status != RCE_OK) {
5088N/A error = ENODEV;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A sprop_dict = dlmgr__rad_dict_string_DLValue_create(link);
5088N/A if (sprop_dict == NULL) {
5088N/A status = ENOMEM;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A bzero(&new_val, sizeof (new_val));
5088N/A new_val.ddlv_type = vtype;
5088N/A switch (vtype) {
5088N/A case DDLVT_BOOLEAN:
5088N/A new_val.ddlv_bval = arg;
5088N/A status = dlmgr__rad_dict_string_DLValue_put(
5088N/A sprop_dict, propname, &new_val, &old_val);
5088N/A if (status != RCE_OK) {
5088N/A error = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A dlmgr_DLValue_free(old_val);
5088N/A break;
5088N/A case DDLVT_ULONG:
5088N/A new_val.ddlv_ulval = arg;
5088N/A status = dlmgr__rad_dict_string_DLValue_put(
5088N/A sprop_dict, propname, &new_val, &old_val);
5088N/A if (status != RCE_OK) {
5088N/A error = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A dlmgr_DLValue_free(old_val);
5088N/A break;
5088N/A case DDLVT_STRING:
5088N/A new_val.ddlv_sval = arg;
5088N/A status = dlmgr__rad_dict_string_DLValue_put(
5088N/A sprop_dict, propname, &new_val, &old_val);
5088N/A if (status != RCE_OK) {
5088N/A error = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A dlmgr_DLValue_free(old_val);
5088N/A break;
5088N/A case DDLVT_LONG:
5088N/A case DDLVT_LONGS:
5088N/A case DDLVT_ULONGS:
5088N/A case DDLVT_STRINGS:
5088N/A case DDLVT_BOOLEANS:
5088N/A case DDLVT_DICTIONARY:
5088N/A case DDLVT_DICTIONARYS:
5088N/A default:
5088N/A ovs_assert(0);
5088N/A break;
5088N/A }
5088N/A
6016N/A if (temp) {
6016N/A bzero(&new_val, sizeof (new_val));
6016N/A old_val = NULL;
6016N/A new_val.ddlv_type = DDLVT_BOOLEAN;
6016N/A new_val.ddlv_bval = &b_true;
6016N/A status = dlmgr__rad_dict_string_DLValue_put(
6016N/A sprop_dict, "temporary", &new_val, &old_val);
6016N/A if (status != RCE_OK) {
6016N/A error = EINVAL;
6016N/A goto out;
6016N/A }
6016N/A dlmgr_DLValue_free(old_val);
5088N/A }
5088N/A
5088N/A status = dlmgr_Datalink_setProperties(link, sprop_dict, &derrp);
5088N/A if (status != RCE_OK) {
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A dpif_log(derrp->dde_err,
5088N/A "failed Datalink_setPropertiess(%s, %s): %s",
5088N/A netdev_name, propname, derrp->dde_errmsg);
5088N/A }
5088N/A error = ENOTSUP;
5088N/A }
5088N/Aout:
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A dlmgr__rad_dict_string_DLValue_free(sprop_dict);
5088N/A rc_instance_rele(link);
5088N/A return (error);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_set_dlprop_boolean(const char *netdev_name, const char *propname,
6016N/A void *arg, boolean_t temp)
5088N/A{
6016N/A return (solaris_set_dlprop(netdev_name, propname, arg, DDLVT_BOOLEAN,
6016N/A temp));
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_set_dlprop_ulong(const char *netdev_name, const char *propname,
6016N/A void *arg, boolean_t temp)
5088N/A{
6016N/A return (solaris_set_dlprop(netdev_name, propname, arg, DDLVT_ULONG,
6016N/A temp));
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_set_dlprop_string(const char *netdev_name, const char *propname,
6016N/A void *arg, boolean_t temp)
5088N/A{
6016N/A return (solaris_set_dlprop(netdev_name, propname, arg, DDLVT_STRING,
6016N/A temp));
5088N/A}
5088N/A
6998N/Astatic int
6998N/Adlmgr_DLValue_putstring(dlmgr__rad_dict_string_DLValue_t *ddvp,
6998N/A const char *key, char *buf, char *dstr, size_t dstrlen)
6998N/A{
6998N/A dlmgr_DLValue_t *old_val = NULL;
6998N/A dlmgr_DLValue_t new_val;
6998N/A rc_err_t status;
6998N/A
6998N/A if (strlen(key) != 0) {
6998N/A bzero(&new_val, sizeof (new_val));
6998N/A new_val.ddlv_type = DDLVT_STRING;
6998N/A new_val.ddlv_sval = buf;
6998N/A if ((status = dlmgr__rad_dict_string_DLValue_put(ddvp, key,
6998N/A &new_val, &old_val)) != RCE_OK) {
6998N/A return (EINVAL);
6998N/A }
6998N/A if (dstr)
6998N/A snprintf(dstr, dstrlen, "%s,%s=%s", dstr, key, buf);
6998N/A dlmgr_DLValue_free(old_val);
6998N/A }
6998N/A return (0);
6998N/A}
6998N/A
6998N/Astatic int
6998N/Adlmgr_DLValue_putdict(dlmgr__rad_dict_string_DLValue_t *ddvp,
6998N/A const char *key, dlmgr__rad_dict_string_DLValue_t *dict)
6998N/A{
6998N/A dlmgr_DLValue_t *old_val = NULL;
6998N/A dlmgr_DLValue_t new_val;
6998N/A rc_err_t status;
6998N/A
6998N/A if (strlen(key) != 0) {
6998N/A bzero(&new_val, sizeof (new_val));
6998N/A new_val.ddlv_type = DDLVT_DICTIONARY;
6998N/A new_val.ddlv_dval = dict;
6998N/A if ((status = dlmgr__rad_dict_string_DLValue_put(ddvp, key,
6998N/A &new_val, &old_val)) != RCE_OK) {
6998N/A return (EINVAL);
6998N/A }
6998N/A dlmgr_DLValue_free(old_val);
6998N/A }
6998N/A return (0);
6998N/A}
6998N/A
5088N/Aint
5088N/Asolaris_create_vnic(const char *linkname, const char *vnicname)
5088N/A{
5088N/A dlmgr__rad_dict_string_DLValue_t *prop = NULL;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A dlmgr_DLValue_t *old_val = NULL;
5088N/A dlmgr_DLValue_t name_val;
5088N/A rc_instance_t *linkmgr = NULL;
5088N/A rc_instance_t *vnic = NULL;
5088N/A rc_err_t status;
5088N/A
5088N/A status = dlmgr_DatalinkManager__rad_lookup(rad_conn, B_TRUE,
5088N/A &linkmgr, 0);
5088N/A if (status != RCE_OK)
5088N/A goto out;
5088N/A
5088N/A prop = dlmgr__rad_dict_string_DLValue_create(linkmgr);
5088N/A if (prop == NULL)
5088N/A goto out;
5088N/A
5088N/A bzero(&name_val, sizeof (name_val));
5088N/A name_val.ddlv_type = DDLVT_STRING;
5088N/A /* linkname is 'const char *' and ddlv_sval is 'char *' */
5088N/A name_val.ddlv_sval = strdupa(linkname);
5088N/A status = dlmgr__rad_dict_string_DLValue_put(prop, "lower-link",
5088N/A &name_val, &old_val);
5088N/A if (status != RCE_OK)
5088N/A goto out;
5088N/A dlmgr_DLValue_free(old_val);
5088N/A old_val = NULL;
5088N/A
5088N/A status = dlmgr_DatalinkManager_createVNIC(linkmgr, vnicname, prop,
5088N/A &vnic, &derrp);
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A dpif_log(derrp->dde_err,
5088N/A "failed DatalinkManager_createVNIC(%s): %s",
5088N/A vnicname, derrp->dde_errmsg);
5088N/A }
5088N/A rc_instance_rele(vnic);
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/Aout:
5088N/A dlmgr__rad_dict_string_DLValue_free(prop);
5088N/A rc_instance_rele(linkmgr);
5088N/A return ((status != RCE_OK) ? ENOTSUP : 0);
5088N/A}
5088N/A
6998N/A/*
6998N/A * Try setting implicit VNIC's mac-addr-type as "fixed", if it fails then try
6998N/A * with "auto" else bail out. This procedure is to ensure vnic migration
6998N/A * succeeds specifically on LDOM's vnet (ensuring it works on other uplinks too)
6998N/A * with any of its config (custom=enable/disable).
6998N/A */
5088N/Aint
5088N/Asolaris_modify_vnic(const char *linkname, const char *vnicname)
5088N/A{
5088N/A dlmgr__rad_dict_string_DLValue_t *sprop_dict = NULL;
6998N/A dlmgr__rad_dict_string_DLValue_t *mac_info_dict = NULL;
5088N/A dlmgr_DLValue_t *old_val = NULL;
5088N/A rc_instance_t *link = NULL;
5088N/A rc_err_t status;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
6998N/A char mac_address[DLADM_PROP_VAL_MAX];
5088N/A int error = 0;
5088N/A
5088N/A status = dlmgr_Datalink__rad_lookup(rad_conn, B_TRUE, &link, 1,
5088N/A "name", vnicname);
5088N/A if (status != RCE_OK) {
5088N/A error = ENODEV;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A sprop_dict = dlmgr__rad_dict_string_DLValue_create(link);
5088N/A if (sprop_dict == NULL) {
6998N/A error = ENOMEM;
6998N/A goto out;
6998N/A }
6998N/A mac_info_dict = dlmgr__rad_dict_string_DLValue_create(link);
6998N/A if (mac_info_dict == NULL) {
6998N/A error = ENOMEM;
6998N/A goto out;
6998N/A }
6998N/A
6998N/A if ((error = dlmgr_DLValue_putstring(sprop_dict, "lower-link",
6998N/A strdupa(linkname), NULL, 0)) != 0) {
5088N/A goto out;
5088N/A }
5088N/A
6998N/A if ((error = solaris_get_dlprop(vnicname, "mac-address", "current",
6998N/A mac_address, sizeof (mac_address))) != 0) {
6998N/A goto out;
6998N/A }
6998N/A
6998N/A if ((error = dlmgr_DLValue_putstring(mac_info_dict, "mac-address-type",
6998N/A "fixed", NULL, 0)) != 0) {
5088N/A goto out;
5088N/A }
6998N/A if ((error = dlmgr_DLValue_putstring(mac_info_dict, "mac-address",
6998N/A mac_address, NULL, 0)) != 0) {
6998N/A goto out;
6998N/A }
6998N/A if ((error = dlmgr_DLValue_putdict(sprop_dict, "mac-address-info",
6998N/A mac_info_dict)) != 0) {
6998N/A goto out;
6998N/A }
5088N/A
5088N/A status = dlmgr_Datalink_setProperties(link, sprop_dict, &derrp);
5088N/A if (status != RCE_OK) {
6998N/A /* If it fails with "fixed" as mac-addr-type, try with "auto" */
6998N/A if ((status = dlmgr__rad_dict_string_DLValue_remove(
6998N/A mac_info_dict, "mac-address", &old_val)) != RCE_OK) {
6998N/A error = ENOTSUP;
6998N/A goto out;
6998N/A }
6998N/A dlmgr_DLValue_free(old_val);
6998N/A
6998N/A if ((error = dlmgr_DLValue_putstring(mac_info_dict,
6998N/A "mac-address-type", "auto", NULL, 0))
6998N/A != 0) {
6998N/A goto out;
5088N/A }
6998N/A
6998N/A status = dlmgr_Datalink_setProperties(link, sprop_dict,
6998N/A &derrp);
6998N/A if (status != RCE_OK) {
6998N/A if (status == RCE_SERVER_OBJECT) {
6998N/A dpif_log(derrp->dde_err,
6998N/A "failed Datalink_setProperties"
6998N/A "(%s, lower-link): %s",
6998N/A vnicname, derrp->dde_errmsg);
6998N/A }
6998N/A error = ENOTSUP;
6998N/A }
5088N/A }
5088N/Aout:
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A dlmgr__rad_dict_string_DLValue_free(sprop_dict);
6998N/A dlmgr__rad_dict_string_DLValue_free(mac_info_dict);
5088N/A rc_instance_rele(link);
5088N/A return (error);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_delete_vnic(const char *vnicname)
5088N/A{
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A rc_instance_t *linkmgr = NULL;
5088N/A rc_err_t status;
5088N/A int err = 0;
5088N/A
5088N/A status = dlmgr_DatalinkManager__rad_lookup(rad_conn, B_TRUE,
5088N/A &linkmgr, 0);
5728N/A if (status != RCE_OK)
5728N/A return (EINVAL);
5728N/A
5728N/A status = dlmgr_DatalinkManager_deleteVNIC(linkmgr, vnicname, NULL,
5088N/A &derrp);
5088N/A if (status != RCE_OK) {
5088N/A err = -1;
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A err = derrp->dde_err;
5088N/A dpif_log(err,
5088N/A "failed DatalinkManager_deleteVNIC(%s): %s",
5088N/A vnicname, derrp->dde_errmsg);
5088N/A }
5088N/A }
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A
5088N/A rc_instance_rele(linkmgr);
5088N/A return (err);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_create_etherstub(const char *name)
5088N/A{
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A rc_instance_t *linkmgr = NULL;
5088N/A rc_instance_t *etherstub = NULL;
5088N/A rc_err_t status;
5088N/A
5088N/A status = dlmgr_DatalinkManager__rad_lookup(rad_conn, B_TRUE,
5088N/A &linkmgr, 0);
5088N/A if (status != RCE_OK)
5728N/A return (ENOTSUP);
5728N/A
5728N/A status = dlmgr_DatalinkManager_createEtherstub(linkmgr, name, NULL,
5088N/A &etherstub, &derrp);
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A dpif_log(derrp->dde_err,
5088N/A "failed DatalinkManager_createEtherstub(%s): %s",
5088N/A name, derrp->dde_errmsg);
5088N/A }
5088N/A rc_instance_rele(etherstub);
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A rc_instance_rele(linkmgr);
5088N/A
5088N/A return ((status != RCE_OK) ? ENOTSUP : 0);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_delete_etherstub(const char *name)
5088N/A{
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A rc_instance_t *linkmgr = NULL;
5088N/A rc_err_t status;
5088N/A
5088N/A status = dlmgr_DatalinkManager__rad_lookup(rad_conn, B_TRUE,
5088N/A &linkmgr, 0);
5088N/A if (status != RCE_OK)
5728N/A return (ENOTSUP);
5728N/A
5728N/A status = dlmgr_DatalinkManager_deleteEtherstub(linkmgr, name, NULL,
5088N/A &derrp);
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A dpif_log(derrp->dde_err,
5088N/A "failed DatalinkManager_deleteEtherstub(%s): %s",
5088N/A name, derrp->dde_errmsg);
5088N/A }
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A rc_instance_rele(linkmgr);
5728N/A
5088N/A return ((status != RCE_OK) ? ENOTSUP : 0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_str2mac(const char *str, uchar_t *f, size_t maclen)
5088N/A{
5088N/A uchar_t *addr = NULL;
5088N/A int len, err = 0;
5088N/A
5088N/A if ((addr = _link_aton(str, &len)) == NULL)
5088N/A return ((len == -1) ? EINVAL : ENOMEM);
5088N/A
5088N/A if (len != maclen) {
5088N/A err = EINVAL;
5088N/A goto done;
5088N/A }
5088N/A
5088N/A bcopy(addr, f, maclen);
5088N/Adone:
5088N/A free(addr);
5088N/A return (err);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_str2addr(const char *str, in6_addr_t *f, int *afp)
5088N/A{
5088N/A struct in_addr v4addr;
5088N/A struct in6_addr v6addr;
5088N/A int af;
5088N/A
5088N/A if (inet_pton(AF_INET, str, &v4addr.s_addr) == 1) {
5088N/A af = AF_INET;
5088N/A } else if (inet_pton(AF_INET6, str, v6addr.s6_addr) == 1) {
5088N/A af = AF_INET6;
5088N/A } else {
5088N/A return (EINVAL);
5088N/A }
5088N/A
5088N/A if (af == AF_INET) {
5088N/A IN6_INADDR_TO_V4MAPPED(&v4addr, f);
5088N/A } else {
5088N/A *f = v6addr;
5088N/A }
5088N/A *afp = af;
5088N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Asolaris_flowinfo2linkname(dlmgr__rad_dict_string_DLValue_t *flowinfo,
5088N/A char *linkname, size_t size)
5088N/A{
5088N/A dlmgr__rad_dict_string_DLValue_t *fdict;
5088N/A dlmgr_DLValue_t *flist = NULL, *dlval = NULL;
5088N/A rc_err_t status;
5088N/A int err = 0;
5088N/A
5088N/A status = dlmgr__rad_dict_string_DLValue_get(flowinfo, "filters",
5088N/A &flist);
5088N/A if (status != RCE_OK)
5088N/A return (EINVAL);
5088N/A
5088N/A fdict = flist->ddlv_dlist[0]->ddld_map;
5088N/A
5088N/A status = dlmgr__rad_dict_string_DLValue_get(fdict,
5088N/A "linkname", &dlval);
5088N/A if (status != RCE_OK) {
5088N/A err = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A (void) strlcpy(linkname, dlval->ddlv_sval, size);
5088N/A dlmgr_DLValue_free(dlval);
5088N/Aout:
5088N/A dlmgr_DLValue_free(flist);
5088N/A return (err);
5088N/A}
5088N/A
5088N/Astatic void
5088N/Aflow_mac2str(uint8_t *f, uint8_t *m, char *buf, char *rbuf, size_t buf_len,
5088N/A size_t rbuf_len)
5088N/A{
5088N/A char *str = NULL;
5088N/A char *pstr = NULL;
5088N/A
5088N/A buf[0] = '\0';
5088N/A rbuf[0] = '\0';
5088N/A
5088N/A if (!eth_addr_is_zero(f) || !eth_addr_is_zero(m)) {
5088N/A str = _link_ntoa(f, NULL, ETHERADDRL, IFT_ETHER);
5088N/A if (str != NULL) {
5088N/A pstr = _link_ntoa(m, NULL, ETHERADDRL, IFT_ETHER);
5088N/A if (pstr != NULL) {
5088N/A (void) snprintf(buf, buf_len, "%s", str);
5088N/A (void) snprintf(rbuf, rbuf_len, "%s", pstr);
5088N/A free(pstr);
5088N/A }
5088N/A free(str);
5088N/A }
5088N/A }
5088N/A}
5088N/A
5088N/Astatic void
5088N/Aflow_addr2str(struct in6_addr *f6, struct in6_addr *m6, uint32_t f4,
5088N/A uint32_t m4, char *buf, char *rbuf, size_t buf_len, size_t rbuf_len)
5088N/A{
5088N/A struct in_addr ipaddr;
5088N/A char abuf[INET6_ADDRSTRLEN], mbuf[INET6_ADDRSTRLEN];
5088N/A
5088N/A buf[0] = '\0';
5088N/A rbuf[0] = '\0';
5088N/A if ((f6 != NULL) && (m6 != NULL) &&
5088N/A (!ipv6_addr_equals(f6, &in6addr_any) ||
5088N/A !ipv6_addr_equals(m6, &in6addr_any))) {
5088N/A (void) inet_ntop(AF_INET6, f6, abuf, INET6_ADDRSTRLEN);
5088N/A (void) inet_ntop(AF_INET6, m6, mbuf, INET6_ADDRSTRLEN);
5088N/A (void) snprintf(buf, buf_len, "%s", abuf);
5088N/A (void) snprintf(rbuf, rbuf_len, "%s", mbuf);
5088N/A } else if (f4 != 0 || m4 != 0) {
5088N/A ipaddr.s_addr = f4;
5088N/A (void) strlcpy(abuf, inet_ntoa(ipaddr), sizeof (abuf));
5088N/A ipaddr.s_addr = m4;
5088N/A (void) strlcpy(mbuf, inet_ntoa(ipaddr), sizeof (mbuf));
5088N/A (void) snprintf(buf, buf_len, "%s", abuf);
5088N/A (void) snprintf(rbuf, rbuf_len, "%s", mbuf);
5088N/A }
5088N/A}
5088N/A
5728N/A#define FP_NAME_VAL_DELIM '@'
5728N/A#define FP_MULTI_ACTION_DELIM '#'
5728N/A#define FP_ACTION_NAME_VALUE_DELIM '-'
6554N/A#define FP_ACTION_PORT_RANGE_DELIM ':'
5728N/A#define FP_ACTION_MULTI_VAL_DELIM '^'
5728N/A#define FP_MULTI_ACTION_DELIM_STR "#"
5728N/A
5088N/Astatic int
6554N/Auint32cmp(const void *a, const void *b)
6554N/A{
6554N/A return (*(uint32_t *)a - *(uint32_t *)b);
6554N/A}
6554N/A
6554N/Astatic int
6554N/Aofport_list2range(uint32_t *ofports, int nofports, ofport_range_t **range,
6554N/A int *range_cnt)
6554N/A{
6554N/A int i, nr = 1;
6554N/A uint32_t *sort32;
6554N/A ofport_range_t *ur;
6554N/A
6554N/A sort32 = malloc(nofports * sizeof (uint32_t));
6554N/A if (sort32 == NULL)
6554N/A return (ENOMEM);
6554N/A
6554N/A for (i = 0; i < nofports; i++)
6554N/A sort32[i] = ofports[i];
6554N/A
6554N/A if (nofports > 1)
6554N/A qsort(sort32, nofports, sizeof (uint32_t), uint32cmp);
6554N/A
6554N/A ur = *range;
6554N/A ur->ofp_min = ur->ofp_max = sort32[0];
6554N/A
6554N/A for (i = 1; i < nofports; i++) {
6554N/A if (sort32[i] - sort32[i-1] == 1) {
6554N/A ur->ofp_max = sort32[i];
6554N/A } else {
6554N/A ur++; nr++;
6554N/A ur->ofp_min = ur->ofp_max = sort32[i];
6554N/A }
6554N/A }
6554N/A free(sort32);
6554N/A *range_cnt = nr;
6554N/A return (0);
6554N/A}
6554N/A
6554N/Astatic int
5728N/Aflow_ofports2propstr(char *str, size_t strsize, uint32_t *ofports,
5728N/A int nofports)
5088N/A{
5728N/A char buf[DLADM_STRSIZE];
6554N/A int i, err, range_cnt;
6554N/A ofport_range_t *ofports_range;
5728N/A
6922N/A
6922N/A if (nofports == 0)
5728N/A return (0);
5728N/A
6554N/A ofports_range = malloc(nofports * sizeof (ofport_range_t));
6554N/A if (ofports_range == NULL)
6554N/A return (ENOMEM);
6554N/A
6554N/A err = ofport_list2range(ofports, nofports, &ofports_range, &range_cnt);
6554N/A if (err != 0) {
6554N/A free(ofports_range);
6554N/A return (err);
6554N/A }
6554N/A
6554N/A if (snprintf(buf, sizeof (buf), "%soutports", strlen(str) == 0 ? "" :
6554N/A FP_MULTI_ACTION_DELIM_STR) >= sizeof (buf)) {
6554N/A goto no_buffer;
6554N/A }
6554N/A
6554N/A if (strlcat(str, buf, strsize) >= strsize)
6554N/A goto no_buffer;
6554N/A
6554N/A for (i = 0; i < range_cnt; i++) {
6554N/A if (ofports_range[i].ofp_min == ofports_range[i].ofp_max) {
6554N/A if (snprintf(buf, sizeof (buf), "%c%u", (i == 0) ?
6554N/A FP_NAME_VAL_DELIM : FP_ACTION_MULTI_VAL_DELIM,
6554N/A ofports_range[i].ofp_min) >= sizeof (buf)) {
6554N/A goto no_buffer;
6554N/A }
6554N/A } else {
6554N/A if (snprintf(buf, sizeof (buf), "%c%u%c%u",
6554N/A (i == 0) ? FP_NAME_VAL_DELIM :
6554N/A FP_ACTION_MULTI_VAL_DELIM, ofports_range[i].ofp_min,
6554N/A FP_ACTION_PORT_RANGE_DELIM,
6554N/A ofports_range[i].ofp_max) >= sizeof (buf)) {
6554N/A goto no_buffer;
6554N/A }
6554N/A }
5728N/A
5728N/A if (strlcat(str, buf, strsize) >= strsize)
6554N/A goto no_buffer;
5728N/A }
6554N/A free(ofports_range);
5728N/A return (0);
6554N/A
6554N/Ano_buffer:
6554N/A free(ofports_range);
6554N/A return (ENOBUFS);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Adlmgr_DLValue_fm_putstring(dlmgr__rad_dict_string_DLValue_t *ddvp,
5088N/A dlmgr__rad_dict_string_DLValue_t *ddmp, const char *key,
5088N/A char *buf, char *rbuf, char *dstr, size_t dstrlen)
5088N/A{
5088N/A dlmgr_DLValue_t *old_val = NULL;
5088N/A dlmgr_DLValue_t new_val;
5088N/A rc_err_t status;
5088N/A
5088N/A if (strlen(buf) != 0) {
5088N/A bzero(&new_val, sizeof (new_val));
5088N/A new_val.ddlv_type = DDLVT_STRING;
5088N/A new_val.ddlv_sval = buf;
5088N/A if ((status = dlmgr__rad_dict_string_DLValue_put(ddvp, key,
5088N/A &new_val, &old_val)) != RCE_OK) {
5088N/A return (EINVAL);
5088N/A }
5088N/A dlmgr_DLValue_free(old_val);
5088N/A old_val = NULL;
5088N/A new_val.ddlv_sval = rbuf;
5088N/A if ((status = dlmgr__rad_dict_string_DLValue_put(ddmp, key,
5088N/A &new_val, &old_val)) != RCE_OK) {
5088N/A return (EINVAL);
5088N/A }
5088N/A dlmgr_DLValue_free(old_val);
5088N/A
5088N/A snprintf(dstr, dstrlen, "%s,%s=%s/%s", dstr, key, buf, rbuf);
5088N/A }
5088N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Adlmgr_DLValue_putboolean(dlmgr__rad_dict_string_DLValue_t *ddvp,
5088N/A const char *key, boolean_t val, char *dstr, size_t dstrlen)
5088N/A{
5088N/A dlmgr_DLValue_t *old_val = NULL;
5088N/A dlmgr_DLValue_t new_val;
5088N/A rc_err_t status;
5088N/A
5088N/A bzero(&new_val, sizeof (new_val));
5088N/A new_val.ddlv_type = DDLVT_BOOLEAN;
5088N/A new_val.ddlv_bval = &val;
5088N/A if ((status = dlmgr__rad_dict_string_DLValue_put(ddvp, key, &new_val,
5088N/A &old_val)) != RCE_OK) {
5088N/A return (EINVAL);
5088N/A }
5088N/A snprintf(dstr, dstrlen, "%s,%s=%s", dstr, key,
5088N/A val ? "true" : "false");
5088N/A dlmgr_DLValue_free(old_val);
5088N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Adlmgr_DLValue_putulong(dlmgr__rad_dict_string_DLValue_t *ddvp, const char *key,
5088N/A uint64_t val, char *dstr, size_t dstrlen)
5088N/A{
5088N/A dlmgr_DLValue_t *old_val = NULL;
5088N/A dlmgr_DLValue_t new_val;
5088N/A unsigned long long ulval = val;
5088N/A rc_err_t status;
5088N/A
5088N/A bzero(&new_val, sizeof (new_val));
5088N/A new_val.ddlv_type = DDLVT_ULONG;
5088N/A new_val.ddlv_ulval = &ulval;
5088N/A if ((status = dlmgr__rad_dict_string_DLValue_put(ddvp, key, &new_val,
5088N/A &old_val)) != RCE_OK) {
5088N/A return (EINVAL);
5088N/A }
5088N/A snprintf(dstr, dstrlen, "%s,%s=%"PRIu64, dstr, key, val);
5088N/A dlmgr_DLValue_free(old_val);
5088N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Adlmgr_DLValue_fm_putulong(dlmgr__rad_dict_string_DLValue_t *ddvp,
5088N/A dlmgr__rad_dict_string_DLValue_t *ddmp, const char *key,
5088N/A uint64_t f, uint64_t m, char *dstr, size_t dstrlen)
5088N/A{
5088N/A dlmgr_DLValue_t *old_val = NULL;
5088N/A dlmgr_DLValue_t new_val;
5088N/A unsigned long long f_ulval = f;
5088N/A unsigned long long m_ulval = m;
5088N/A rc_err_t status;
5088N/A
5088N/A bzero(&new_val, sizeof (new_val));
5088N/A new_val.ddlv_type = DDLVT_ULONG;
5088N/A new_val.ddlv_ulval = &f_ulval;
5088N/A if ((status = dlmgr__rad_dict_string_DLValue_put(ddvp, key, &new_val,
5088N/A &old_val)) != RCE_OK) {
5088N/A return (EINVAL);
5088N/A }
5088N/A dlmgr_DLValue_free(old_val);
5088N/A old_val = NULL;
5088N/A new_val.ddlv_ulval = &m_ulval;
5088N/A if ((status = dlmgr__rad_dict_string_DLValue_put(ddmp, key, &new_val,
5088N/A &old_val)) != RCE_OK) {
5088N/A return (EINVAL);
5088N/A }
5088N/A dlmgr_DLValue_free(old_val);
5088N/A snprintf(dstr, dstrlen, "%s,%s=%"PRIu64"/%"PRIu64, dstr, key, f, m);
5088N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Asolaris_flow_to_DLVal(struct flow *f, struct flow *m,
5088N/A dlmgr__rad_dict_string_DLValue_t *ddvp,
5088N/A dlmgr__rad_dict_string_DLValue_t *ddmp)
5088N/A{
5088N/A char buf[DLADM_STRSIZE], rbuf[DLADM_STRSIZE];
5088N/A char dstr[DLADM_STRSIZE];
5088N/A int err = 0;
5088N/A boolean_t is_arp = (ntohs(f->dl_type) == 0x806);
5088N/A
5088N/A dstr[0] = '\0';
5088N/A if (f->dl_type != htons(FLOW_DL_TYPE_NONE)) {
5088N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp, "sap",
5088N/A ntohs(f->dl_type), ntohs(m->dl_type), dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A if (is_arp) {
5088N/A if (f->nw_proto != 0 || m->nw_proto != 0) {
5088N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp, "arp-op",
5088N/A f->nw_proto, m->nw_proto, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A flow_mac2str(f->arp_sha, m->arp_sha, buf, rbuf, sizeof (buf),
5088N/A sizeof (rbuf));
5088N/A if (strlen(buf) != 0) {
5088N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp,
5088N/A "arp-sender", buf, rbuf, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A flow_mac2str(f->arp_tha, m->arp_tha, buf, rbuf, sizeof (buf),
5088N/A sizeof (rbuf));
5088N/A if (strlen(buf) != 0) {
5088N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp,
5088N/A "arp-target", buf, rbuf, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A flow_addr2str(NULL, NULL, f->nw_src, m->nw_src, buf, rbuf,
5088N/A sizeof (buf), sizeof (rbuf));
5088N/A if (strlen(buf) != 0) {
5088N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp, "arp-sip",
5088N/A buf, rbuf, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A flow_addr2str(NULL, NULL, f->nw_dst, m->nw_dst, buf, rbuf,
5088N/A sizeof (buf), sizeof (rbuf));
5088N/A if (strlen(buf) != 0) {
5088N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp, "arp-tip",
5088N/A buf, rbuf, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A } else {
5088N/A if (f->nw_proto != 0 || m->nw_proto != 0) {
5088N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp, "transport",
5088N/A f->nw_proto, m->nw_proto, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A flow_addr2str(&f->ipv6_src, &m->ipv6_src, f->nw_src, m->nw_src,
5088N/A buf, rbuf, sizeof (buf), sizeof (rbuf));
5088N/A if (strlen(buf) != 0) {
5088N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp, "local-ip",
5088N/A buf, rbuf, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A flow_addr2str(&f->ipv6_dst, &m->ipv6_dst, f->nw_dst, m->nw_dst,
5088N/A buf, rbuf, sizeof (buf), sizeof (rbuf));
5088N/A if (strlen(buf) != 0) {
5088N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp,
5088N/A "remote-ip", buf, rbuf, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A if (f->tcp_flags != 0 || m->tcp_flags != 0) {
5088N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp,
5088N/A "tcp-flags", (uint8_t)(ntohs(f->tcp_flags)),
5088N/A (uint8_t)(ntohs(m->tcp_flags)), dstr,
5088N/A sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A if (f->nw_proto != IPPROTO_ICMP &&
5088N/A f->nw_proto != IPPROTO_ICMPV6) {
5088N/A if (f->tp_src != 0 || m->tp_src != 0) {
5088N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp,
5088N/A "local-port", ntohs(f->tp_src),
5088N/A ntohs(m->tp_src), dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A if (f->tp_dst != 0 || m->tp_dst != 0) {
5088N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp,
5088N/A "remote-port", ntohs(f->tp_dst),
5088N/A ntohs(m->tp_dst), dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A } else {
5088N/A if (f->tp_src != 0 || m->tp_src != 0) {
5088N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp,
5088N/A "icmp-type", ntohs(f->tp_src),
5088N/A ntohs(m->tp_src), dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A if (f->tp_dst != 0 || m->tp_dst != 0) {
5088N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp,
5088N/A "icmp-code", ntohs(f->tp_dst),
5088N/A ntohs(m->tp_dst), dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
6158N/A
6158N/A flow_mac2str(f->arp_sha, m->arp_sha, buf, rbuf,
6158N/A sizeof (buf), sizeof (rbuf));
6158N/A if (strlen(buf) != 0) {
6158N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp,
6158N/A "nd-sll", buf, rbuf,
6158N/A dstr, sizeof (dstr));
6158N/A if (err != 0)
6158N/A goto out;
6158N/A }
6158N/A
6158N/A flow_mac2str(f->arp_tha, m->arp_tha, buf, rbuf,
6158N/A sizeof (buf), sizeof (rbuf));
6158N/A if (strlen(buf) != 0) {
6158N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp,
6158N/A "nd-tll", buf, rbuf,
6158N/A dstr, sizeof (dstr));
6158N/A if (err != 0)
6158N/A goto out;
6158N/A }
6158N/A
6158N/A flow_addr2str(&f->nd_target, &m->nd_target, 0, 0,
6158N/A buf, rbuf, sizeof (buf), sizeof (rbuf));
6158N/A if (strlen(buf) != 0) {
6158N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp,
6158N/A "nd-target", buf, rbuf,
6158N/A dstr, sizeof (dstr));
6158N/A if (err != 0)
6158N/A goto out;
6158N/A }
5088N/A }
5088N/A }
5088N/A
5088N/A
5088N/A flow_mac2str(f->dl_src, m->dl_src, buf, rbuf, sizeof (buf),
5088N/A sizeof (rbuf));
5088N/A if (strlen(buf) != 0) {
5088N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp, "src-mac", buf,
5088N/A rbuf, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A flow_mac2str(f->dl_dst, m->dl_dst, buf, rbuf, sizeof (buf),
5088N/A sizeof (rbuf));
5088N/A if (strlen(buf) != 0) {
5088N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp, "dst-mac", buf,
5088N/A rbuf, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A if (f->in_port.odp_port != ODPP_NONE) {
5088N/A err = dlmgr_DLValue_putulong(ddvp, "srcport",
5088N/A f->in_port.odp_port, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
6536N/A /*
6536N/A * when "f" is filled in by the parse_vlan() function, VLAN_CFI bit is
6536N/A * set blindly. Unset this bit now since we don't set this bit in
6536N/A * Solaris for VLAN packets.
6536N/A */
6536N/A f->vlan_tci &= htons(~VLAN_CFI);
5728N/A if ((f->vlan_tci != 0) || (m->vlan_tci != htons(0xffff))) {
5088N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp,
5088N/A "vlan-tci", ntohs(f->vlan_tci),
5088N/A ntohs(m->vlan_tci), dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A if (f->nw_tos != 0 || m->nw_tos != 0) {
5088N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp,
5088N/A "dsfield", f->nw_tos, m->nw_tos, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
5088N/A if (f->nw_ttl != 0 || m->nw_ttl != 0) {
5088N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp,
5088N/A "ttl", f->nw_ttl, m->nw_ttl, dstr, sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A
6554N/A if (f->tunnel.ip_dst) {
6554N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp,
6554N/A "tun-id", ntohll(f->tunnel.tun_id),
6554N/A ntohll(m->tunnel.tun_id), dstr, sizeof (dstr));
6554N/A if (err != 0)
6554N/A goto out;
6554N/A
6554N/A flow_addr2str(NULL, NULL, f->tunnel.ip_src, m->tunnel.ip_src,
6554N/A buf, rbuf, sizeof (buf), sizeof (rbuf));
6554N/A if (strlen(buf) != 0) {
6554N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp,
6554N/A "tun-local-ip", buf, rbuf, dstr, sizeof (dstr));
6554N/A if (err != 0)
6554N/A goto out;
6554N/A }
6554N/A
6554N/A flow_addr2str(NULL, NULL, f->tunnel.ip_dst, m->tunnel.ip_dst,
6554N/A buf, rbuf, sizeof (buf), sizeof (rbuf));
6554N/A if (strlen(buf) != 0) {
6554N/A err = dlmgr_DLValue_fm_putstring(ddvp, ddmp,
6554N/A "tun-remote-ip", buf, rbuf, dstr, sizeof (dstr));
6554N/A if (err != 0)
6554N/A goto out;
6554N/A }
6554N/A
6554N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp, "tun-dsfield",
6554N/A f->tunnel.ip_tos, m->tunnel.ip_tos, dstr, sizeof (dstr));
6554N/A if (err != 0)
6554N/A goto out;
6554N/A
6554N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp, "tun-ttl",
6554N/A f->tunnel.ip_ttl, m->tunnel.ip_ttl, dstr, sizeof (dstr));
6554N/A if (err != 0)
6554N/A goto out;
6554N/A
6554N/A err = dlmgr_DLValue_fm_putulong(ddvp, ddmp, "tun-flags",
6554N/A f->tunnel.flags, m->tunnel.flags, dstr, sizeof (dstr));
6554N/A if (err != 0)
6554N/A goto out;
6554N/A }
6554N/A
5088N/Aout:
5088N/A dpif_log(err, "solaris_flow_to_DLVal FLOWATTR: %s", dstr);
5088N/A return (err);
5088N/A}
5088N/A
5088N/Astatic int
5728N/Asolaris_maxbw_action_to_DLVal(dlmgr__rad_dict_string_DLValue_t *prop,
5088N/A void *cookie, uint32_t ofports[], int nofports, uint32_t queueid,
5088N/A char *dstr, size_t dstrlen)
5088N/A{
5088N/A struct smap details;
5088N/A const char *max_rate = NULL;
5088N/A uint64_t maxbw;
5088N/A char *endp = NULL;
6016N/A int err = EINVAL;
5088N/A
5088N/A smap_init(&details);
5088N/A if (queueid == UINT32_MAX || nofports != 1)
5728N/A goto done;
5088N/A
5088N/A if ((err = dpif_solaris_get_priority_details(cookie, ofports[0],
5088N/A queueid, &details)) != 0) {
5728N/A goto done;
5088N/A }
5088N/A /* min-rate and priority not currently used */
5088N/A max_rate = smap_get(&details, "max-rate");
5088N/A if (max_rate == NULL)
5728N/A goto done;
5088N/A
5088N/A errno = 0;
5088N/A maxbw = strtoull(max_rate, &endp, 10);
5088N/A if (errno != 0 || *endp != '\0')
5728N/A goto done;
5088N/A
5088N/A err = dlmgr_DLValue_putulong(prop, "max-bw", maxbw, dstr, dstrlen);
5088N/A
5728N/Adone:
5088N/A smap_destroy(&details);
5088N/A return (err);
5088N/A}
5088N/A
5088N/Astatic int
5728N/Asolaris_setether_action_to_str(char *str, size_t strsize,
5728N/A const struct ovs_key_ethernet *ek)
5088N/A{
5088N/A char *sstr = NULL, *dstr = NULL;
5088N/A char buf[DLADM_STRSIZE];
6554N/A int err = ENOBUFS;
5088N/A
5088N/A sstr = _link_ntoa(ek->eth_src, NULL, ETHERADDRL, IFT_ETHER);
5088N/A dstr = _link_ntoa(ek->eth_dst, NULL, ETHERADDRL, IFT_ETHER);
5088N/A if (sstr != NULL && dstr != NULL) {
6554N/A if (snprintf(buf, sizeof (buf),
6554N/A "%sset-ether%cether_src%c%s%cether_dst%c%s",
5728N/A (strlen(str) == 0) ? "" : FP_MULTI_ACTION_DELIM_STR,
5728N/A FP_NAME_VAL_DELIM, FP_ACTION_NAME_VALUE_DELIM, sstr,
5728N/A FP_ACTION_MULTI_VAL_DELIM, FP_ACTION_NAME_VALUE_DELIM,
6554N/A dstr) < sizeof (buf) &&
6554N/A strlcat(str, buf, strsize) < strsize)
6554N/A err = 0;
5088N/A }
5088N/A free(sstr);
5088N/A free(dstr);
5728N/A if (sstr == NULL || dstr == NULL)
5088N/A err = ENOMEM;
5088N/A return (err);
5088N/A}
5088N/A
5088N/Astatic int
5728N/Asolaris_setipv4_action_to_str(char *str, size_t strsize,
5728N/A const struct ovs_key_ipv4 *ipv4)
5088N/A{
5088N/A struct in_addr ipaddr;
5088N/A char *cp;
5088N/A char buf[DLADM_STRSIZE];
5088N/A
5088N/A ipaddr.s_addr = ipv4->ipv4_src;
5088N/A cp = inet_ntoa(ipaddr);
6554N/A if (snprintf(buf, sizeof (buf), "%sset-ipv4%csrc%c%s%c",
5728N/A (strlen(str) == 0) ? "" : FP_MULTI_ACTION_DELIM_STR,
5728N/A FP_NAME_VAL_DELIM, FP_ACTION_NAME_VALUE_DELIM, cp,
6554N/A FP_ACTION_MULTI_VAL_DELIM) >= sizeof (buf))
6554N/A return (ENOBUFS);
5728N/A
5088N/A ipaddr.s_addr = ipv4->ipv4_dst;
5088N/A cp = inet_ntoa(ipaddr);
6554N/A if (snprintf(buf, sizeof (buf),
5728N/A "%sdst%c%s%cprotocol%c%s%ctos%c0x%x%choplimit%c%d",
5728N/A buf, FP_ACTION_NAME_VALUE_DELIM, cp, FP_ACTION_MULTI_VAL_DELIM,
5728N/A FP_ACTION_NAME_VALUE_DELIM, solaris_proto2str(ipv4->ipv4_proto),
5728N/A FP_ACTION_MULTI_VAL_DELIM, FP_ACTION_NAME_VALUE_DELIM,
5728N/A ipv4->ipv4_tos, FP_ACTION_MULTI_VAL_DELIM,
6554N/A FP_ACTION_NAME_VALUE_DELIM, ipv4->ipv4_ttl) >= sizeof (buf))
6554N/A return (ENOBUFS);
6554N/A
5728N/A if (strlcat(str, buf, strsize) >= strsize)
6554N/A return (ENOBUFS);
6554N/A
6554N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5728N/Asolaris_setipv6_action_to_str(char *str, size_t strsize,
5728N/A const struct ovs_key_ipv6 *ipv6)
5088N/A{
5088N/A char abuf[INET6_ADDRSTRLEN];
5088N/A char buf[DLADM_STRSIZE];
5088N/A
5088N/A (void) inet_ntop(AF_INET6, ipv6->ipv6_src, abuf, INET6_ADDRSTRLEN);
6554N/A if (snprintf(buf, sizeof (buf),
5728N/A "%sset-ipv6%csrc%c%s%c", (strlen(str) == 0) ? "" :
5728N/A FP_MULTI_ACTION_DELIM_STR, FP_NAME_VAL_DELIM,
6554N/A FP_ACTION_NAME_VALUE_DELIM, abuf, FP_ACTION_MULTI_VAL_DELIM) >=
6554N/A sizeof (buf))
6554N/A return (ENOBUFS);
5728N/A
5088N/A (void) inet_ntop(AF_INET6, ipv6->ipv6_dst, abuf, INET6_ADDRSTRLEN);
6554N/A if (snprintf(buf, sizeof (buf),
5728N/A "%sdst%c%s%clabel%c0x%x%cprotocol%c%s%ctos%c0x%x%choplimit%c%d",
5728N/A buf, FP_ACTION_NAME_VALUE_DELIM, abuf, FP_ACTION_MULTI_VAL_DELIM,
5728N/A FP_ACTION_NAME_VALUE_DELIM, ipv6->ipv6_label,
5728N/A FP_ACTION_MULTI_VAL_DELIM, FP_ACTION_NAME_VALUE_DELIM,
5728N/A solaris_proto2str(ipv6->ipv6_proto), FP_ACTION_MULTI_VAL_DELIM,
5728N/A FP_ACTION_NAME_VALUE_DELIM, ipv6->ipv6_tclass,
5728N/A FP_ACTION_MULTI_VAL_DELIM, FP_ACTION_NAME_VALUE_DELIM,
6554N/A ipv6->ipv6_hlimit) >= sizeof (buf))
6554N/A return (ENOBUFS);
6554N/A
5728N/A if (strlcat(str, buf, strsize) >= strsize)
6554N/A return (ENOBUFS);
6554N/A
6554N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5728N/Asolaris_settransport_action_to_str(char *str, size_t strsize, const char *key,
5728N/A uint16_t src, uint16_t dst)
5088N/A{
5088N/A char buf[DLADM_STRSIZE];
6554N/A
6554N/A if (snprintf(buf, sizeof (buf),
5728N/A "%s%s%csport%c%d%cdport%c%d", (strlen(str) == 0) ? "" :
5728N/A FP_MULTI_ACTION_DELIM_STR, key, FP_NAME_VAL_DELIM,
5728N/A FP_ACTION_NAME_VALUE_DELIM, src, FP_ACTION_MULTI_VAL_DELIM,
6554N/A FP_ACTION_NAME_VALUE_DELIM, dst) >= sizeof (buf))
6554N/A return (ENOBUFS);
6554N/A
5728N/A if (strlcat(str, buf, strsize) >= strsize)
6554N/A return (ENOBUFS);
6554N/A
6554N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5728N/Asolaris_settnl_action_to_str(char *str, size_t strsize,
5728N/A const struct flow_tnl *tnl)
5088N/A{
5088N/A struct in_addr ipaddr;
5088N/A char *cp;
5088N/A char buf[DLADM_STRSIZE];
5088N/A
5088N/A ipaddr.s_addr = tnl->ip_src;
5088N/A cp = inet_ntoa(ipaddr);
6554N/A if (snprintf(buf, sizeof (buf), "%sset-tunnel%csrc%c%s%c",
5728N/A (strlen(str) == 0) ? "" : FP_MULTI_ACTION_DELIM_STR,
5728N/A FP_NAME_VAL_DELIM, FP_ACTION_NAME_VALUE_DELIM, cp,
6554N/A FP_ACTION_MULTI_VAL_DELIM) >= sizeof (buf))
6554N/A return (ENOBUFS);
5728N/A
5088N/A ipaddr.s_addr = tnl->ip_dst;
5088N/A cp = inet_ntoa(ipaddr);
6554N/A if (snprintf(buf, sizeof (buf),
5728N/A "%sdst%c%s%ctun_id%c0x%"PRIx64"%ctos%c0x%x%choplimit%c%d",
5728N/A buf, FP_ACTION_NAME_VALUE_DELIM, cp, FP_ACTION_MULTI_VAL_DELIM,
5728N/A FP_ACTION_NAME_VALUE_DELIM, ntohll(tnl->tun_id),
5728N/A FP_ACTION_MULTI_VAL_DELIM, FP_ACTION_NAME_VALUE_DELIM,
5728N/A tnl->ip_tos, FP_ACTION_MULTI_VAL_DELIM, FP_ACTION_NAME_VALUE_DELIM,
6554N/A tnl->ip_ttl) >= sizeof (buf))
6554N/A return (ENOBUFS);
6554N/A
5728N/A if (strlcat(str, buf, strsize) >= strsize)
6554N/A return (ENOBUFS);
6554N/A
6554N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Asolaris_nlattr_to_DLVal(void *cookie,
5088N/A const struct nlattr *actions_nlattr, size_t actions_len,
5728N/A dlmgr__rad_dict_string_DLValue_t *prop)
5088N/A{
5088N/A const struct nlattr *a;
5088N/A unsigned int left;
6554N/A char buf[MAX_OF_ACTIONS_SIZE];
6554N/A char str[MAX_OF_ACTIONS_SIZE];
6554N/A char dstr[MAX_OF_ACTIONS_SIZE];
5088N/A int err = 0, nofports = 0;
5088N/A uint32_t ofports[MAC_OF_MAXPORT];
5088N/A enum ovs_action_attr type = -1, lasttype;
5088N/A uint_t queueid = UINT32_MAX;
5088N/A
5088N/A dstr[0] = '\0';
5728N/A str[0] = '\0';
5088N/A err = dlmgr_DLValue_putboolean(prop, "temporary", B_TRUE, dstr,
5088N/A sizeof (dstr));
5088N/A if (err != 0)
5088N/A goto out;
5088N/A
5088N/A /* if actions_len == 0, then the action is drop */
6922N/A if (actions_len == 0)
5088N/A goto out;
5088N/A
5088N/A NL_ATTR_FOR_EACH_UNSAFE(a, left, actions_nlattr, actions_len) {
5088N/A lasttype = type;
5088N/A type = nl_attr_type(a);
5088N/A if ((type != OVS_ACTION_ATTR_OUTPUT) ||
5088N/A (lasttype != OVS_ACTION_ATTR_OUTPUT)) {
5088N/A if (lasttype == OVS_ACTION_ATTR_OUTPUT) {
5728N/A err = flow_ofports2propstr(str, sizeof (str),
5728N/A ofports, nofports);
5088N/A if (err != 0)
5088N/A goto out;
5728N/A (void) solaris_maxbw_action_to_DLVal(prop,
5728N/A cookie, ofports, nofports, queueid, dstr,
5728N/A sizeof (dstr));
5088N/A }
5088N/A nofports = 0;
5088N/A }
5088N/A
5088N/A switch ((enum ovs_action_attr) type) {
5088N/A /* These only make sense in the context of a datapath. */
5088N/A case OVS_ACTION_ATTR_OUTPUT:
5088N/A if (nofports + 1 > MAC_OF_MAXPORT) {
5088N/A err = ENOBUFS;
5088N/A break;
5088N/A }
5088N/A ofports[nofports++] = u32_to_odp(nl_attr_get_u32(a));
5088N/A break;
5088N/A case OVS_ACTION_ATTR_USERSPACE: {
5088N/A const struct nlattr *userdata;
5088N/A size_t userdata_len;
5088N/A union user_action_cookie cookie;
5088N/A
5088N/A userdata = nl_attr_find_nested(a,
5088N/A OVS_USERSPACE_ATTR_USERDATA);
5088N/A userdata_len = nl_attr_get_size(userdata);
5088N/A memcpy(&cookie, nl_attr_get(userdata), userdata_len);
5088N/A if (userdata_len < sizeof (cookie.type) ||
5088N/A userdata_len > sizeof (cookie)) {
5088N/A err = EINVAL;
5088N/A dpif_log(err,
5088N/A "unexpected action size %"PRIuSIZE,
5088N/A userdata_len);
5088N/A break;
5088N/A }
5088N/A if (userdata_len != MAX(8, sizeof (cookie.slow_path)) ||
5088N/A cookie.type != USER_ACTION_COOKIE_SLOW_PATH) {
5088N/A err = EOPNOTSUPP;
5088N/A dpif_log(err,
5088N/A "userspace action size %"PRIuSIZE" "
5088N/A "type unsupported %d", userdata_len,
5088N/A cookie.type);
5088N/A break;
5088N/A }
5088N/A if (cookie.slow_path.reason != SLOW_CONTROLLER)
5088N/A break;
5088N/A
6554N/A if (snprintf(buf, sizeof (buf), "%scontroller%c%u",
5728N/A (strlen(str) == 0) ? "" : FP_MULTI_ACTION_DELIM_STR,
6554N/A FP_NAME_VAL_DELIM, PORT_PF_PACKET_UPLINK) >=
6554N/A sizeof (buf)) {
6554N/A err = ENOBUFS;
6554N/A break;
6554N/A }
5728N/A
5728N/A if (strlcat(str, buf, sizeof (str)) >= sizeof (str)) {
6554N/A err = ENOBUFS;
5088N/A break;
5088N/A }
5088N/A break;
5088N/A }
5088N/A case OVS_ACTION_ATTR_SET: {
5088N/A const struct nlattr *aset = nl_attr_get(a);
5088N/A
5088N/A switch (nl_attr_type(aset)) {
5088N/A case OVS_KEY_ATTR_PRIORITY:
5088N/A queueid = nl_attr_get_u32(aset);
5088N/A break;
5088N/A
5088N/A case OVS_KEY_ATTR_ETHERNET: {
5088N/A const struct ovs_key_ethernet *ek;
5088N/A
5088N/A ek = nl_attr_get_unspec(aset,
5088N/A sizeof (struct ovs_key_ethernet));
5728N/A err = solaris_setether_action_to_str(str,
5728N/A sizeof (str), ek);
5088N/A break;
5088N/A }
5088N/A case OVS_KEY_ATTR_IPV4: {
5088N/A const struct ovs_key_ipv4 *eip4;
5088N/A
5088N/A eip4 = nl_attr_get_unspec(aset,
5088N/A sizeof (struct ovs_key_ipv4));
5728N/A err = solaris_setipv4_action_to_str(str,
5728N/A sizeof (str), eip4);
5088N/A break;
5088N/A }
5088N/A case OVS_KEY_ATTR_IPV6: {
5088N/A const struct ovs_key_ipv6 *eip6;
5088N/A
5088N/A eip6 = nl_attr_get_unspec(aset,
5088N/A sizeof (struct ovs_key_ipv6));
5728N/A err = solaris_setipv6_action_to_str(str,
5728N/A sizeof (str), eip6);
5088N/A break;
5088N/A }
5088N/A case OVS_KEY_ATTR_TCP: {
5088N/A const struct ovs_key_tcp *etcp;
5088N/A etcp = nl_attr_get_unspec(aset,
5088N/A sizeof (struct ovs_key_tcp));
5728N/A err = solaris_settransport_action_to_str(
5728N/A str, sizeof (str), "set-tcp", etcp->tcp_src,
5728N/A etcp->tcp_dst);
5088N/A break;
5088N/A }
5088N/A case OVS_KEY_ATTR_UDP: {
5088N/A const struct ovs_key_udp *eudp;
5088N/A eudp = nl_attr_get_unspec(aset,
5088N/A sizeof (struct ovs_key_udp));
5728N/A err = solaris_settransport_action_to_str(
5728N/A str, sizeof (str), "set-udp", eudp->udp_src,
5728N/A eudp->udp_dst);
5088N/A break;
5088N/A }
5088N/A case OVS_KEY_ATTR_SCTP: {
5088N/A const struct ovs_key_sctp *esctp;
5088N/A esctp = nl_attr_get_unspec(aset,
5088N/A sizeof (struct ovs_key_sctp));
5728N/A err = solaris_settransport_action_to_str(str,
5728N/A sizeof (str), "set-sctp", esctp->sctp_src,
5728N/A esctp->sctp_dst);
5088N/A break;
5088N/A }
5088N/A case OVS_KEY_ATTR_TUNNEL: {
5088N/A struct flow_tnl tnl;
5088N/A enum odp_key_fitness fitness;
5088N/A
5088N/A memset(&tnl, 0, sizeof (tnl));
5088N/A fitness = odp_tun_key_from_attr(aset, &tnl);
5088N/A ovs_assert(fitness != ODP_FIT_ERROR);
5728N/A err = solaris_settnl_action_to_str(
5728N/A str, sizeof (str), &tnl);
5088N/A break;
5088N/A }
5088N/A default:
5088N/A err = EOPNOTSUPP;
5088N/A dpif_log(err, "solaris_nlattr_to_DLVal set "
5088N/A "%d not supported",
5088N/A nl_attr_type(nl_attr_get(a)));
5088N/A }
5088N/A break;
5088N/A }
5088N/A case OVS_ACTION_ATTR_PUSH_VLAN: {
5088N/A const struct ovs_action_push_vlan *vlan;
5088N/A
5088N/A vlan = nl_attr_get_unspec(a,
5088N/A sizeof (struct ovs_action_push_vlan));
5088N/A
6554N/A if (snprintf(buf, sizeof (buf), "%svlan-tag%c%u",
5728N/A (strlen(str) == 0) ? "" : FP_MULTI_ACTION_DELIM_STR,
6554N/A FP_NAME_VAL_DELIM, ntohs(vlan->vlan_tci)) >=
6554N/A sizeof (buf)) {
6554N/A err = ENOBUFS;
6554N/A break;
6554N/A }
5728N/A
5728N/A if (strlcat(str, buf, sizeof (str)) >= sizeof (str)) {
6554N/A err = ENOBUFS;
5728N/A break;
5728N/A }
5088N/A break;
5088N/A }
5088N/A case OVS_ACTION_ATTR_POP_VLAN:
6554N/A if (snprintf(buf, sizeof (buf), "%svlan-strip%c%s",
5728N/A (strlen(str) == 0) ? "" : FP_MULTI_ACTION_DELIM_STR,
6554N/A FP_NAME_VAL_DELIM, "on") >= sizeof (buf)) {
6554N/A err = ENOBUFS;
6554N/A break;
6554N/A }
5728N/A
5728N/A if (strlcat(str, buf, sizeof (str)) >= sizeof (str)) {
6554N/A err = ENOBUFS;
5728N/A break;
5728N/A }
5088N/A break;
5088N/A case OVS_ACTION_ATTR_RECIRC:
5088N/A case OVS_ACTION_ATTR_HASH:
5088N/A case OVS_ACTION_ATTR_PUSH_MPLS:
5088N/A case OVS_ACTION_ATTR_POP_MPLS:
5088N/A case OVS_ACTION_ATTR_SAMPLE:
5088N/A /* TBD */
5088N/A err = EOPNOTSUPP;
5088N/A dpif_log(err, "solaris_nlattr_to_DLVal type %d "
5088N/A "not supported", type);
5088N/A case OVS_ACTION_ATTR_UNSPEC:
5088N/A case __OVS_ACTION_ATTR_MAX:
5088N/A OVS_NOT_REACHED();
5088N/A }
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A if (type == OVS_ACTION_ATTR_OUTPUT) {
5088N/A dpif_log(0, "solaris_nlattr_to_DLVal outports total %d ports",
5088N/A nofports);
5728N/A err = flow_ofports2propstr(str, sizeof (str),
5728N/A ofports, nofports);
5728N/A if (err != 0)
5728N/A goto out;
5728N/A (void) solaris_maxbw_action_to_DLVal(prop, cookie, ofports,
5088N/A nofports, queueid, dstr, sizeof (dstr));
5088N/A }
5728N/A
5728N/A err = dlmgr_DLValue_putstring(prop, "ofaction", str, dstr,
5728N/A sizeof (dstr));
5088N/Aout:
5728N/A
6554N/A dpif_log(err, "solaris_nlattr_to_DLVal %s %d", dstr, err);
5728N/A
5088N/A return (err);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_add_flow(void *cookie, const char *linkname,
5088N/A const char *flowname, struct flow *f, struct flow *m,
5088N/A const struct nlattr *actions_nlattr, size_t actions_len)
5088N/A{
5088N/A dlmgr_DLDict_t dff, dfm, *dffp, *dfmp;
5088N/A dlmgr__rad_dict_string_DLValue_t *prop = NULL;
5088N/A rc_instance_t *link = NULL, *flow = NULL;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A int err = 0;
5088N/A rc_err_t status;
5088N/A
5088N/A bzero(&dff, sizeof (dff));
5088N/A bzero(&dfm, sizeof (dfm));
5088N/A dffp = &dff;
5088N/A dfmp = &dfm;
5088N/A status = dlmgr_Datalink__rad_lookup(rad_conn, B_TRUE, &link, 1,
5088N/A "name", linkname);
5088N/A if (status != RCE_OK) {
5088N/A err = ENODEV;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A dff.ddld_map = dlmgr__rad_dict_string_DLValue_create(link);
5088N/A if (dff.ddld_map == NULL) {
5088N/A err = ENOMEM;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A dfm.ddld_map = dlmgr__rad_dict_string_DLValue_create(link);
5088N/A if (dfm.ddld_map == NULL) {
5088N/A err = ENOMEM;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A prop = dlmgr__rad_dict_string_DLValue_create(link);
5088N/A if (prop == NULL) {
5088N/A err = ENOMEM;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A err = solaris_flow_to_DLVal(f, m, dff.ddld_map, dfm.ddld_map);
5088N/A if (err != 0)
5088N/A goto out;
5088N/A
5088N/A err = solaris_nlattr_to_DLVal(cookie, actions_nlattr,
5728N/A actions_len, prop);
5088N/A if (err != 0)
5088N/A goto out;
5088N/A
5088N/A status = dlmgr_Datalink_addFlow(link, flowname, &dffp, 1, &dfmp, 1,
5088N/A prop, &flow, &derrp);
5088N/A if (status != RCE_OK) {
5088N/A err = -1;
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A err = derrp->dde_err;
5088N/A dpif_log(err,
5088N/A "failed Datalink_addFlow(%s, %s): %s",
5088N/A flowname, linkname, derrp->dde_errmsg);
5088N/A }
5088N/A }
5088N/A rc_instance_rele(flow);
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A
5088N/Aout:
5088N/A dlmgr__rad_dict_string_DLValue_free(dfm.ddld_map);
5088N/A dlmgr__rad_dict_string_DLValue_free(dff.ddld_map);
5088N/A dlmgr__rad_dict_string_DLValue_free(prop);
5088N/A rc_instance_rele(link);
5088N/A return (err);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_modify_flow(void *cookie, const char *flowname,
5088N/A const struct nlattr *actions_nlattr, size_t actions_len)
5088N/A{
5088N/A rc_instance_t *flow = NULL;
5088N/A dlmgr__rad_dict_string_DLValue_t *prop = NULL;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A rc_err_t status;
5088N/A int err;
5088N/A
5728N/A dpif_log(0, "solaris_modify_flow(%s)", flowname);
5088N/A status = dlmgr_Flow__rad_lookup(rad_conn, B_TRUE, &flow, 1,
5088N/A "name", flowname);
5088N/A if (status != RCE_OK) {
5088N/A err = ENODEV;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A prop = dlmgr__rad_dict_string_DLValue_create(flow);
5088N/A if (prop == NULL) {
5088N/A err = ENOMEM;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A err = solaris_nlattr_to_DLVal(cookie, actions_nlattr,
5728N/A actions_len, prop);
5088N/A if (err != 0)
5088N/A goto out;
5088N/A
5088N/A status = dlmgr_Flow_setProperties(flow, prop, &derrp);
5088N/A if (status != RCE_OK) {
5088N/A err = -1;
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A err = derrp->dde_err;
5088N/A dpif_log(err,
5088N/A "failed Flow_setProperties(%s): %s",
5088N/A flowname, derrp->dde_errmsg);
5088N/A }
5088N/A }
5088N/A
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A
5088N/Aout:
5088N/A dlmgr__rad_dict_string_DLValue_free(prop);
5088N/A rc_instance_rele(flow);
5088N/A return (err);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_remove_flow(const char *linkname, const char *flowname)
5088N/A{
5088N/A dlmgr__rad_dict_string_DLValue_t *prop = NULL;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A dlmgr_DLValue_t *old_val = NULL;
5088N/A dlmgr_DLValue_t val;
5088N/A rc_instance_t *link = NULL;
5088N/A rc_err_t status;
5088N/A int error = 0;
5088N/A
5088N/A status = dlmgr_Datalink__rad_lookup(rad_conn, B_TRUE, &link, 1,
5088N/A "name", linkname);
5088N/A if (status != RCE_OK) {
5088N/A error = ENODEV;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A prop = dlmgr__rad_dict_string_DLValue_create(link);
5088N/A if (prop == NULL) {
5088N/A error = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A bzero(&val, sizeof (val));
5088N/A val.ddlv_type = DDLVT_BOOLEAN;
5088N/A val.ddlv_bval = &b_true;
5088N/A status = dlmgr__rad_dict_string_DLValue_put(prop, "temporary",
5088N/A &val, &old_val);
5088N/A if (status != RCE_OK) {
5088N/A error = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A dlmgr_DLValue_free(old_val);
5088N/A
5088N/A status = dlmgr_Datalink_removeFlow(link, flowname, prop, &derrp);
5088N/A if (status != RCE_OK) {
5088N/A error = -1;
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A error = derrp->dde_err;
5088N/A dpif_log(error, "failed Datalink_removeFlow(%s): %s",
5088N/A flowname, derrp->dde_errmsg);
5088N/A }
5088N/A }
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/Aout:
5088N/A dlmgr__rad_dict_string_DLValue_free(prop);
5088N/A rc_instance_rele(link);
5088N/A return (error);
5088N/A}
5088N/A
5088N/Astatic rc_err_t
5088N/Asolaris_flowinfo2flowmap(const char *key, dlmgr_DLValue_t *val, void *arg)
5088N/A{
5088N/A struct flow *f = arg;
5088N/A in6_addr_t fa;
5088N/A struct in_addr v4;
5088N/A int af, err = 0;
5088N/A
5088N/A if (strcmp(key, "dst-mac") == 0) {
5088N/A err = flow_str2mac(val->ddlv_sval, f->dl_dst, 6);
5088N/A } else if (strcmp(key, "src-mac") == 0) {
5088N/A err = flow_str2mac(val->ddlv_sval, f->dl_src, 6);
5088N/A } else if (strcmp(key, "local-ip") == 0 ||
5088N/A strcmp(key, "remote-ip") == 0 || strcmp(key, "arp-sip") == 0 ||
5088N/A strcmp(key, "arp-tip") == 0) {
5088N/A err = flow_str2addr(val->ddlv_sval, &fa, &af);
5088N/A if (err != 0)
5088N/A goto out;
5088N/A if (af == AF_INET) {
5088N/A IN6_V4MAPPED_TO_INADDR(&fa, &v4);
5088N/A if (strcmp(key, "local-ip") == 0 ||
5088N/A strcmp(key, "arp-sip") == 0) {
5088N/A f->nw_src = v4.s_addr;
5088N/A } else {
5088N/A f->nw_dst = v4.s_addr;
5088N/A }
5088N/A } else {
5088N/A if (strcmp(key, "local-ip") == 0) {
5088N/A bcopy(&fa, &f->ipv6_src, sizeof (f->ipv6_src));
5088N/A } else if (strcmp(key, "remote-ip") == 0) {
5088N/A bcopy(&fa, &f->ipv6_dst, sizeof (f->ipv6_dst));
5088N/A } else {
5088N/A err = EINVAL;
5088N/A }
5088N/A }
5088N/A } else if (strcmp(key, "transport") == 0) {
5088N/A f->nw_proto = (uint8_t)*val->ddlv_ulval;
5088N/A } else if (strcmp(key, "local-port") == 0) {
5088N/A f->tp_src = htons((uint16_t)*val->ddlv_ulval);
5088N/A } else if (strcmp(key, "remote-port") == 0) {
5088N/A f->tp_dst = htons((uint16_t)*val->ddlv_ulval);
5088N/A } else if (strcmp(key, "dsfield") == 0) {
5088N/A f->nw_tos = (uint8_t)*val->ddlv_ulval;
5088N/A } else if (strcmp(key, "srcport") == 0) {
5088N/A f->in_port.odp_port = (odp_port_t)*val->ddlv_ulval;
6158N/A } else if (strcmp(key, "arp-target") == 0 ||
6158N/A strcmp(key, "nd-tll") == 0) {
5088N/A err = flow_str2mac(val->ddlv_sval, f->arp_tha, 6);
6158N/A } else if (strcmp(key, "arp-sender") == 0 ||
6158N/A strcmp(key, "nd-sll") == 0) {
5088N/A err = flow_str2mac(val->ddlv_sval, f->arp_sha, 6);
5088N/A } else if (strcmp(key, "arp-op") == 0) {
5088N/A f->nw_proto = (uint8_t)*val->ddlv_ulval;
5088N/A } else if (strcmp(key, "sap") == 0) {
5088N/A f->dl_type = htons((uint16_t)*val->ddlv_ulval);
5088N/A } else if (strcmp(key, "ttl") == 0) {
5088N/A f->nw_ttl = (uint8_t)*val->ddlv_ulval;
5088N/A } else if (strcmp(key, "vlan-tci") == 0) {
5088N/A f->vlan_tci = htons((uint16_t)*val->ddlv_ulval);
5088N/A } else if (strcmp(key, "icmp-type") == 0) {
5088N/A f->tp_src = htons((uint16_t)*val->ddlv_ulval);
5088N/A } else if (strcmp(key, "icmp-code") == 0) {
5088N/A f->tp_dst = htons((uint16_t)*val->ddlv_ulval);
6158N/A } else if (strcmp(key, "nd-target") == 0) {
6158N/A err = flow_str2addr(val->ddlv_sval, &fa, &af);
6158N/A if (err != 0)
6158N/A goto out;
6158N/A bcopy(&fa, &f->nd_target, sizeof (f->nd_target));
5088N/A } else if (strcmp(key, "tcp-flags") == 0) {
5088N/A f->tcp_flags = htons((uint16_t)*val->ddlv_ulval);
6554N/A } else if (strcmp(key, "tun-id") == 0) {
6554N/A f->tunnel.tun_id = htonll((uint64_t)*val->ddlv_ulval);
6554N/A } else if (strcmp(key, "tun-local-ip") == 0 ||
6554N/A strcmp(key, "tun-remote-ip") == 0) {
6554N/A err = flow_str2addr(val->ddlv_sval, &fa, &af);
6554N/A if (err != 0 || af != AF_INET)
6554N/A goto out;
6554N/A IN6_V4MAPPED_TO_INADDR(&fa, &v4);
6554N/A if (strcmp(key, "tun-local-ip") == 0)
6554N/A f->tunnel.ip_src = v4.s_addr;
6554N/A else
6554N/A f->tunnel.ip_dst = v4.s_addr;
6554N/A } else if (strcmp(key, "tun-dsfield") == 0) {
6554N/A f->tunnel.ip_tos = (uint8_t)*val->ddlv_ulval;
6554N/A } else if (strcmp(key, "tun-ttl") == 0) {
6554N/A f->tunnel.ip_ttl = (uint8_t)*val->ddlv_ulval;
6554N/A } else if (strcmp(key, "tun-flags") == 0) {
6554N/A f->tunnel.flags = (uint16_t)*val->ddlv_ulval;
5088N/A }
5088N/Aout:
5728N/A if (err != 0)
5728N/A dpif_log(err, "solaris_flowinfo2flowmap %s failed", key);
5088N/A dlmgr_DLValue_free(val);
5088N/A return (err == 0 ? RCE_OK : -1);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Asolaris_flowinfo2flow(dlmgr__rad_dict_string_DLValue_t *flowinfo,
5088N/A struct flow *f, struct flow *m)
5088N/A{
5088N/A dlmgr__rad_dict_string_DLValue_t *fdict, *mdict;
5088N/A dlmgr_DLValue_t *flist = NULL, *mlist = NULL;
5088N/A rc_err_t status;
5088N/A
5088N/A bzero(f, sizeof (*f));
5088N/A bzero(m, sizeof (*m));
5088N/A
5088N/A status = dlmgr__rad_dict_string_DLValue_get(flowinfo, "filters",
5088N/A &flist);
5088N/A if (status != RCE_OK)
5088N/A return (EINVAL);
5088N/A
5088N/A fdict = flist->ddlv_dlist[0]->ddld_map;
5088N/A
5088N/A status = dlmgr__rad_dict_string_DLValue_map(fdict,
5088N/A solaris_flowinfo2flowmap, f);
5088N/A dlmgr_DLValue_free(flist);
5088N/A if (status != RCE_OK)
5088N/A return (EINVAL);
5088N/A
5088N/A status = dlmgr__rad_dict_string_DLValue_get(flowinfo, "masks", &mlist);
5088N/A if (status != RCE_OK)
5088N/A return (EINVAL);
5088N/A
5088N/A mdict = mlist->ddlv_dlist[0]->ddld_map;
5088N/A
5088N/A status = dlmgr__rad_dict_string_DLValue_map(mdict,
5088N/A solaris_flowinfo2flowmap, m);
5088N/A dlmgr_DLValue_free(mlist);
5088N/A if (status != RCE_OK)
5088N/A return (EINVAL);
5088N/A return (0);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_get_flowattr(const char *flowname, struct flow *f, struct flow *m)
5088N/A{
5088N/A dlmgr__rad_dict_string_DLValue_t *flowinfo = NULL;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A rc_instance_t *flow = NULL;
5088N/A rc_err_t status;
5088N/A int err = 0;
5088N/A
5088N/A status = dlmgr_Flow__rad_lookup(rad_conn, B_TRUE, &flow, 1,
5088N/A "name", flowname);
5088N/A if (status != RCE_OK) {
5088N/A return (ENODEV);
5088N/A }
5088N/A
5088N/A status = dlmgr_Flow_getInfo(flow, NULL, 0, &flowinfo, &derrp);
5088N/A if (status != RCE_OK) {
5088N/A err = -1;
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A err = derrp->dde_err;
5088N/A /*
5088N/A * XXX For now, log DDLSTATUS_NOT_FOUND as debug until
5088N/A * we can determine how to handle the RAD caching
5088N/A * issue.
5088N/A */
5088N/A dpif_log(err == DDLSTATUS_NOT_FOUND ? 0 : err,
5088N/A "failed Flow_getInfo(%s): %s",
5088N/A flowname, derrp->dde_errmsg);
5088N/A }
5088N/A }
5088N/A
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A rc_instance_rele(flow);
5088N/A
5088N/A if (err == 0) {
5088N/A err = solaris_flowinfo2flow(flowinfo, f, m);
5088N/A dlmgr__rad_dict_string_DLValue_free(flowinfo);
5088N/A }
5088N/A
5088N/A return (err);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_propval2action_setpri(char **propvals OVS_UNUSED, int nval OVS_UNUSED,
5088N/A struct ofpbuf *action OVS_UNUSED)
5088N/A{
5088N/A /* TBD */
5088N/A return (0);
5088N/A}
5088N/A
5088N/Avoid
5088N/Aslowpath_to_actions(enum slow_path_reason reason, struct ofpbuf *buf)
5088N/A{
5088N/A union user_action_cookie cookie;
5088N/A
5088N/A cookie.type = USER_ACTION_COOKIE_SLOW_PATH;
5088N/A cookie.slow_path.unused = 0;
5088N/A cookie.slow_path.reason = reason;
5088N/A
5088N/A odp_put_userspace_action(0, &cookie, sizeof (cookie.slow_path), buf);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_propval2action_controller(char **propvals OVS_UNUSED, int nval OVS_UNUSED,
5088N/A struct ofpbuf *action)
5088N/A{
5088N/A slowpath_to_actions(SLOW_CONTROLLER, action);
5088N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_propval2action_pushvlan(char **propvals, int nval OVS_UNUSED,
5088N/A struct ofpbuf *action)
5088N/A{
5088N/A char *endp = NULL;
5088N/A int64_t n;
5088N/A struct ovs_action_push_vlan push;
5088N/A int tpid = ETH_TYPE_VLAN;
5088N/A
5088N/A errno = 0;
5088N/A n = strtoull(propvals[0], &endp, 10);
5088N/A if ((errno != 0) || *endp != '\0' || n > 0xffff)
5088N/A return (EINVAL);
5088N/A
5088N/A push.vlan_tpid = htons(tpid);
5088N/A push.vlan_tci = htons((uint16_t)n);
5088N/A nl_msg_put_unspec(action, OVS_ACTION_ATTR_PUSH_VLAN,
5088N/A &push, sizeof (push));
5088N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_propval2action_popvlan(char **propvals OVS_UNUSED, int nval OVS_UNUSED,
5088N/A struct ofpbuf *action)
5088N/A{
5088N/A nl_msg_put_flag(action, OVS_ACTION_ATTR_POP_VLAN);
5088N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_propval2action_setether(char **propvals, int nval, struct ofpbuf *action)
5088N/A{
5088N/A char pval[DLADM_PROP_VAL_MAX];
5088N/A struct ovs_key_ethernet eth_key;
5088N/A uchar_t *etheraddr;
5088N/A int etheraddrlen;
5088N/A boolean_t src_set, dst_set;
5088N/A char *sep;
5088N/A size_t start_ofs;
5088N/A uint_t i;
5088N/A int err = 0;
5088N/A
5088N/A /*
5728N/A * The property value is in the format of "ether_src-xxx"
5728N/A * "ether_dst-xxx"
5088N/A */
5088N/A bzero(&eth_key, sizeof (eth_key));
5088N/A src_set = dst_set = B_FALSE;
5728N/A
5088N/A for (i = 0; i < nval; i++) {
5728N/A (void) strlcpy(pval, propvals[i], sizeof (pval));
5728N/A if ((sep = strchr(pval, FP_ACTION_NAME_VALUE_DELIM)) == NULL) {
5088N/A err = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A *sep = '\0';
5088N/A sep++;
5088N/A if ((etheraddr = _link_aton(sep, &etheraddrlen)) == NULL) {
5088N/A err = (etheraddrlen == -1) ? EINVAL : ENOMEM;
5088N/A goto out;
5088N/A }
5088N/A /* Only ethernet address is supported */
5088N/A if (etheraddrlen != ETHERADDRL) {
5088N/A err = EINVAL;
5088N/A free(etheraddr);
5088N/A goto out;
5088N/A }
5088N/A if (strcmp(pval, "ether_src") == 0) {
5088N/A if (src_set) {
5088N/A err = EINVAL;
5088N/A } else {
5088N/A bcopy(etheraddr, &eth_key.eth_src, ETHERADDRL);
5088N/A src_set = _B_TRUE;
5088N/A }
5088N/A } else if (strcmp(pval, "ether_dst") == 0) {
5088N/A if (dst_set) {
5088N/A err = EINVAL;
5088N/A } else {
5088N/A bcopy(etheraddr, &eth_key.eth_dst, ETHERADDRL);
5088N/A dst_set = _B_TRUE;
5088N/A }
5088N/A } else {
5088N/A err = EINVAL;
5088N/A }
5088N/A free(etheraddr);
5088N/A if (err != 0)
5088N/A goto out;
5088N/A }
5088N/A if (!src_set || !dst_set) {
5088N/A err = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A start_ofs = nl_msg_start_nested(action, OVS_ACTION_ATTR_SET);
5088N/A nl_msg_put_unspec(action, OVS_KEY_ATTR_ETHERNET, &eth_key,
5088N/A sizeof (eth_key));
5088N/A nl_msg_end_nested(action, start_ofs);
5088N/Aout:
5088N/A return (err);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_propval2action_setipv4(char **propvals, int nval, struct ofpbuf *action)
5088N/A{
5088N/A struct ovs_key_ipv4 ipv4;
5088N/A char pval[DLADM_PROP_VAL_MAX];
5088N/A char *sep, *endp;
5088N/A uint_t i, value;
5088N/A uint8_t protocol;
5088N/A size_t start_ofs;
5088N/A int err = EINVAL;
5088N/A boolean_t tos_set = B_FALSE;
5088N/A
5088N/A /*
5088N/A * The property value is in the format of "src:xxx" "dst:xxx"
5088N/A * "protocol:xxx" "tos:xxx" "hoplimit:xxx"
5088N/A */
5088N/A bzero(&ipv4, sizeof (ipv4));
5088N/A for (i = 0; i < nval; i++) {
5728N/A (void) strlcpy(pval, propvals[i], sizeof (pval));
5728N/A if ((sep = strchr(pval, FP_ACTION_NAME_VALUE_DELIM)) == NULL) {
5088N/A err = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A *sep = '\0';
5088N/A sep++;
5088N/A if (strcmp(pval, "src") == 0) {
5088N/A if (ipv4.ipv4_src != 0)
5088N/A goto out;
5088N/A if (inet_pton(AF_INET, sep, &ipv4.ipv4_src) != 1)
5088N/A goto out;
5088N/A } else if (strcmp(pval, "dst") == 0) {
5088N/A if (ipv4.ipv4_dst != 0)
5088N/A goto out;
5088N/A if (inet_pton(AF_INET, sep, &ipv4.ipv4_dst) != 1)
5088N/A goto out;
5088N/A } else if (strcmp(pval, "protocol") == 0) {
5088N/A if (ipv4.ipv4_proto != 0)
5088N/A goto out;
5088N/A protocol = solaris_str2proto(sep);
5088N/A if (protocol == 0)
5088N/A goto out;
5088N/A ipv4.ipv4_proto = protocol;
5088N/A } else if (strcmp(pval, "tos") == 0) {
5088N/A if (tos_set)
5088N/A goto out;
5088N/A errno = 0;
5088N/A endp = NULL;
5088N/A value = strtoul(sep, &endp, 16);
5088N/A if (errno != 0 || value > 0xff || *endp != '\0')
5088N/A goto out;
5088N/A tos_set = B_TRUE;
5088N/A ipv4.ipv4_tos = value;
5088N/A } else if (strcmp(pval, "hoplimit") == 0) {
5088N/A if (ipv4.ipv4_ttl != 0)
5088N/A goto out;
5088N/A errno = 0;
5088N/A endp = NULL;
5088N/A value = strtoul(sep, &endp, 10);
5088N/A if (errno != 0 || value == 0 || value > 0xff ||
5088N/A *endp != '\0')
5088N/A goto out;
5088N/A ipv4.ipv4_ttl = value;
5088N/A }
5088N/A }
5088N/A start_ofs = nl_msg_start_nested(action, OVS_ACTION_ATTR_SET);
5088N/A nl_msg_put_unspec(action, OVS_KEY_ATTR_IPV4, &ipv4, sizeof (ipv4));
5088N/A nl_msg_end_nested(action, start_ofs);
5088N/A err = 0;
5088N/Aout:
5088N/A return (err);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_propval2action_setipv6(char **propvals, int nval, struct ofpbuf *action)
5088N/A{
5088N/A struct ovs_key_ipv6 ipv6;
5088N/A char pval[DLADM_PROP_VAL_MAX];
5088N/A char *sep, *endp;
5088N/A uint_t i, value;
5088N/A uint8_t protocol;
5088N/A struct in6_addr in6;
5088N/A size_t start_ofs;
5088N/A int err = EINVAL;
5088N/A boolean_t tos_set = B_FALSE;
5088N/A
5088N/A /*
5088N/A * The property value is in the format of "src:xxx" "dst:xxx"
5088N/A * "label:0xxxxx" "protocol:xxx" "tos:xxx" "hoplimit:xxx"
5088N/A */
5088N/A bzero(&ipv6, sizeof (ipv6));
5088N/A for (i = 0; i < nval; i++) {
5728N/A (void) strlcpy(pval, propvals[i], sizeof (pval));
5728N/A if ((sep = strchr(pval, FP_ACTION_NAME_VALUE_DELIM)) == NULL)
5088N/A goto out;
5088N/A *sep = '\0';
5088N/A sep++;
5088N/A if (strcmp(pval, "src") == 0) {
5088N/A bcopy(&ipv6.ipv6_src, &in6.s6_addr,
5088N/A sizeof (struct in6_addr));
5088N/A if (!IN6_IS_ADDR_UNSPECIFIED(&in6))
5088N/A goto out;
5088N/A if (inet_pton(AF_INET6, sep, ipv6.ipv6_src) != 1)
5088N/A goto out;
5088N/A } else if (strcmp(pval, "dst") == 0) {
5088N/A bcopy(&ipv6.ipv6_dst, &in6.s6_addr,
5088N/A sizeof (struct in6_addr));
5088N/A if (!IN6_IS_ADDR_UNSPECIFIED(&in6))
5088N/A goto out;
5088N/A if (inet_pton(AF_INET6, sep, ipv6.ipv6_dst) != 1)
5088N/A goto out;
5088N/A } else if (strcmp(pval, "protocol") == 0) {
5088N/A if (ipv6.ipv6_proto != 0)
5088N/A goto out;
5088N/A protocol = solaris_str2proto(sep);
5088N/A if (protocol == 0)
5088N/A goto out;
5088N/A ipv6.ipv6_proto = protocol;
5088N/A } else if (strcmp(pval, "tos") == 0) {
5088N/A if (tos_set)
5088N/A goto out;
5088N/A errno = 0;
5088N/A endp = NULL;
5088N/A value = strtoul(sep, &endp, 16);
5088N/A if (errno != 0 || value > 0xff || *endp != '\0')
5088N/A goto out;
5088N/A tos_set = B_TRUE;
5088N/A ipv6.ipv6_tclass = value;
6554N/A } else if (strcmp(pval, "hoplimit") == 0) {
5088N/A if (ipv6.ipv6_hlimit != 0)
5088N/A goto out;
5088N/A errno = 0;
5088N/A endp = NULL;
5088N/A value = strtoul(sep, &endp, 10);
5088N/A if (errno != 0 || value == 0 || value > 0xff ||
5088N/A *endp != '\0') {
5088N/A goto out;
5088N/A }
5088N/A ipv6.ipv6_hlimit = value;
5088N/A } else if (strcmp(pval, "label") == 0) {
5088N/A if (ipv6.ipv6_label != 0)
5088N/A goto out;
5088N/A errno = 0;
5088N/A endp = NULL;
5088N/A value = strtoul(sep, &endp, 16);
6922N/A if (errno != 0 || value > 0xff || *endp != '\0') {
5088N/A goto out;
5088N/A }
5088N/A ipv6.ipv6_label = value;
5088N/A }
5088N/A }
5088N/A start_ofs = nl_msg_start_nested(action, OVS_ACTION_ATTR_SET);
5088N/A nl_msg_put_unspec(action, OVS_KEY_ATTR_IPV6, &ipv6, sizeof (ipv6));
5088N/A nl_msg_end_nested(action, start_ofs);
5088N/A err = 0;
5088N/Aout:
5088N/A return (err);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_propval2action_settransport(char **propvals, int nval,
5088N/A uint16_t *sportp, uint16_t *dportp)
5088N/A{
5088N/A char pval[DLADM_PROP_VAL_MAX];
5088N/A char *sep, *endp;
5088N/A uint_t i, value;
5088N/A int err = EINVAL;
5088N/A uint16_t sport = 0, dport = 0;
5088N/A
5728N/A /* The property value is in the format of "sport-xxx" "dport-xxx" */
5088N/A for (i = 0; i < nval; i++) {
5728N/A (void) strlcpy(pval, propvals[i], sizeof (pval));
5728N/A if ((sep = strchr(pval, FP_ACTION_NAME_VALUE_DELIM)) == NULL)
5088N/A goto out;
5088N/A *sep = '\0';
5088N/A sep++;
5088N/A if (strcmp(pval, "sport") == 0) {
5088N/A if (sport != 0)
5088N/A goto out;
5088N/A errno = 0;
5088N/A endp = NULL;
5088N/A value = strtoul(sep, &endp, 10);
5088N/A if (errno != 0 || value == 0 || value > 0xffff ||
5088N/A *endp != '\0') {
5088N/A goto out;
5088N/A }
5088N/A sport = value;
5088N/A } else if (strcmp(pval, "dport") == 0) {
5088N/A if (dport != 0)
5088N/A return (DLADM_STATUS_DUPLICATE_ARG);
5088N/A errno = 0;
5088N/A endp = NULL;
5088N/A value = strtoul(sep, &endp, 10);
5088N/A if (errno != 0 || value == 0 || value > 0xffff ||
5088N/A *endp != '\0') {
5088N/A goto out;
5088N/A }
5088N/A dport = value;
5088N/A }
5088N/A }
5088N/A err = 0;
5088N/Aout:
5088N/A *sportp = sport;
5088N/A *dportp = dport;
5088N/A return (err);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_propval2action_settcp(char **propvals, int nval, struct ofpbuf *action)
5088N/A{
5088N/A struct ovs_key_tcp tcp;
5088N/A size_t start_ofs;
5088N/A int err;
5088N/A
5088N/A err = flow_propval2action_settransport(propvals, nval, &tcp.tcp_src,
5088N/A &tcp.tcp_dst);
5088N/A if (err != 0)
5088N/A return (err);
5088N/A
5088N/A start_ofs = nl_msg_start_nested(action, OVS_ACTION_ATTR_SET);
5088N/A nl_msg_put_unspec(action, OVS_KEY_ATTR_TCP, &tcp, sizeof (tcp));
5088N/A nl_msg_end_nested(action, start_ofs);
5088N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_propval2action_setudp(char **propvals, int nval, struct ofpbuf *action)
5088N/A{
5088N/A struct ovs_key_udp udp;
5088N/A size_t start_ofs;
5088N/A int err;
5088N/A
5088N/A err = flow_propval2action_settransport(propvals, nval, &udp.udp_src,
5088N/A &udp.udp_dst);
5088N/A if (err != 0)
5088N/A return (err);
5088N/A
5088N/A start_ofs = nl_msg_start_nested(action, OVS_ACTION_ATTR_SET);
5088N/A nl_msg_put_unspec(action, OVS_KEY_ATTR_UDP, &udp, sizeof (udp));
5088N/A nl_msg_end_nested(action, start_ofs);
5088N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_propval2action_setsctp(char **propvals, int nval, struct ofpbuf *action)
5088N/A{
5088N/A struct ovs_key_sctp sctp;
5088N/A size_t start_ofs;
5088N/A int err;
5088N/A
5088N/A err = flow_propval2action_settransport(propvals, nval, &sctp.sctp_src,
5088N/A &sctp.sctp_dst);
5088N/A if (err != 0)
5088N/A return (err);
5088N/A
5088N/A start_ofs = nl_msg_start_nested(action, OVS_ACTION_ATTR_SET);
5088N/A nl_msg_put_unspec(action, OVS_KEY_ATTR_SCTP, &sctp, sizeof (sctp));
5088N/A nl_msg_end_nested(action, start_ofs);
5088N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aset_addr(char *pval, uint32_t *addrp)
5088N/A{
5088N/A struct addrinfo hints;
5088N/A struct addrinfo *ai;
5088N/A struct addrinfo *next_ai;
5088N/A void *ptr;
5088N/A
5088N/A (void) memset(&hints, 0, sizeof (hints));
5088N/A hints.ai_family = AF_UNSPEC;
5088N/A if (getaddrinfo(pval, NULL, &hints, &ai) != 0)
5088N/A return (EINVAL);
5088N/A
5088N/A /* Check if hostname resolves to multiple addresses */
5088N/A for (next_ai = ai->ai_next; next_ai != NULL;
5088N/A next_ai = next_ai->ai_next) {
5088N/A if (next_ai->ai_addrlen != ai->ai_addrlen ||
5088N/A bcmp(next_ai->ai_addr, ai->ai_addr,
5088N/A ai->ai_addrlen) != 0) {
5088N/A /* maps to more than one address */
5088N/A freeaddrinfo(ai);
5088N/A return (EINVAL);
5088N/A }
5088N/A }
5088N/A if (ai->ai_family != AF_INET) {
5088N/A freeaddrinfo(ai);
5088N/A return (EINVAL);
5088N/A }
5088N/A
5088N/A ptr = ((uint8_t *)ai->ai_addr) +
5088N/A offsetof(struct sockaddr_in, sin_addr);
5088N/A memcpy(addrp, ptr, sizeof (struct in_addr));
5088N/A freeaddrinfo(ai);
5088N/A return (0);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Aflow_propval2action_settnl(char **propvals, int nval, struct ofpbuf *action)
5088N/A{
5088N/A char pval[DLADM_PROP_VAL_MAX];
5088N/A char *sep, *endp;
5088N/A uint_t i, value;
5088N/A struct flow_tnl tnl;
5728N/A size_t start_ofs, tun_key_ofs;
5088N/A boolean_t id_set, src_set, dst_set, tos_set, ttl_set;
5088N/A int err = 0;
5088N/A
5088N/A id_set = src_set = dst_set = tos_set = ttl_set = B_FALSE;
5088N/A
5088N/A /*
5088N/A * The property value is in the format of "src:xxx" "dst:xxx"
5088N/A * "tun_id:0x%x" "tos:0x%x" "hoplimit:xxx"
5088N/A */
6016N/A bzero(&tnl, sizeof (struct flow_tnl));
5088N/A tnl.ip_tos = 0xff;
5088N/A for (i = 0; i < nval; i++) {
5728N/A (void) strlcpy(pval, propvals[i], sizeof (pval));
5728N/A if ((sep = strchr(pval, FP_ACTION_NAME_VALUE_DELIM)) == NULL)
5088N/A return (EINVAL);
5088N/A *sep = '\0';
5088N/A sep++;
5088N/A if (strcmp(pval, "tun_id") == 0) {
5088N/A if (id_set)
5088N/A return (EINVAL);
5088N/A errno = 0;
5088N/A endp = NULL;
5088N/A value = strtoull(sep, &endp, 16);
5088N/A if (errno != 0 || *endp != '\0')
5088N/A return (EINVAL);
5088N/A tnl.tun_id = value;
5088N/A id_set = B_TRUE;
5088N/A } else if (strcmp(pval, "src") == 0) {
5088N/A if (src_set)
5088N/A return (EINVAL);
5088N/A err = set_addr(sep, &tnl.ip_src);
5088N/A if (err != 0)
5088N/A return (err);
5088N/A src_set = B_TRUE;
5088N/A } else if (strcmp(pval, "dst") == 0) {
5088N/A if (dst_set)
5088N/A return (EINVAL);
5088N/A err = set_addr(sep, &tnl.ip_dst);
5088N/A if (err != 0)
5088N/A return (err);
5088N/A dst_set = B_TRUE;
5088N/A } else if (strcmp(pval, "tos") == 0) {
5088N/A if (tos_set)
5088N/A return (EINVAL);
5088N/A errno = 0;
5088N/A endp = NULL;
5088N/A value = strtoul(sep, &endp, 16);
5088N/A if (errno != 0 || value > 0xff || *endp != '\0')
5088N/A return (EINVAL);
5088N/A tnl.ip_tos = value;
5088N/A tos_set = B_TRUE;
5088N/A } else if (strcmp(pval, "hoplimit") == 0) {
5088N/A if (ttl_set)
5088N/A return (EINVAL);
5088N/A errno = 0;
5088N/A endp = NULL;
5088N/A value = strtoul(sep, &endp, 10);
5088N/A if (errno != 0 || value == 0 || value > 0xff ||
5088N/A *endp != '\0') {
5088N/A return (EINVAL);
5088N/A }
5088N/A tnl.ip_ttl = value;
5088N/A ttl_set = B_TRUE;
5088N/A }
5088N/A }
5088N/A
5088N/A start_ofs = nl_msg_start_nested(action, OVS_ACTION_ATTR_SET);
5728N/A tun_key_ofs = nl_msg_start_nested(action, OVS_KEY_ATTR_TUNNEL);
5728N/A nl_msg_put_be64(action, OVS_TUNNEL_KEY_ATTR_ID,
5728N/A ntohll((uint64_t)tnl.tun_id));
5088N/A nl_msg_put_be32(action, OVS_TUNNEL_KEY_ATTR_IPV4_SRC, tnl.ip_src);
5088N/A nl_msg_put_be32(action, OVS_TUNNEL_KEY_ATTR_IPV4_DST, tnl.ip_dst);
5088N/A nl_msg_put_u8(action, OVS_TUNNEL_KEY_ATTR_TOS, tnl.ip_tos);
5088N/A nl_msg_put_u8(action, OVS_TUNNEL_KEY_ATTR_TTL, tnl.ip_ttl);
5088N/A nl_msg_put_flag(action, OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT);
5728N/A nl_msg_end_nested(action, tun_key_ofs);
5088N/A nl_msg_end_nested(action, start_ofs);
5088N/A return (0);
5088N/A}
5088N/A
5728N/Astatic int
6922N/Aflow_propstr2outports(char *key, char *val, uint32_t outports[], int *valcntp)
5728N/A{
6922N/A char *curr;
6922N/A int maxcnt = *valcntp, i, j, len;
6922N/A char *ofp_min, *ofp_max, *tmp = NULL, *endp = NULL;
6922N/A uint32_t of_min, of_max, i_of;
6922N/A boolean_t match, is_range;
5728N/A char c;
5728N/A
5728N/A dpif_log(0, "flow_propstr2vals key %s val %s", key, val);
5728N/A len = strlen(val);
6554N/A
6922N/A ovs_assert(strcmp(key, "outports") == 0);
6922N/A
6922N/A match = is_range = B_FALSE;
6922N/A ofp_min = ofp_max = val;
6922N/A
6922N/A for (i = 0, j = 0, curr = val; i < len && j < maxcnt; i++) {
6922N/A ofp_min = ofp_max = curr;
6922N/A c = val[i];
6922N/A match = (c == FP_ACTION_MULTI_VAL_DELIM ||
6922N/A c == FP_ACTION_PORT_RANGE_DELIM);
6922N/A if (!match && i != len -1)
6922N/A continue;
6922N/A if (match)
6922N/A val[i] = '\0';
6922N/A
6922N/A if (c == FP_ACTION_PORT_RANGE_DELIM) {
6922N/A tmp = curr;
6554N/A curr = val + i + 1;
6922N/A is_range = B_TRUE;
6922N/A continue;
5728N/A }
6922N/A
6922N/A if (is_range == B_TRUE) {
6922N/A ofp_min = tmp;
6922N/A is_range = B_FALSE;
6554N/A }
6922N/A of_min = (uint32_t)strtoul(ofp_min, &endp, 10);
6922N/A of_max = (uint32_t)strtoul(ofp_max, &endp, 10);
6922N/A
6922N/A for (i_of = of_min; i_of <= of_max; i_of++)
6922N/A outports[j++] = i_of;
6922N/A curr = val + i + 1;
5728N/A }
6922N/A if (j >= maxcnt)
6922N/A dpif_log(ENOBUFS, "flow_propstr2outports action truncated");
6922N/A *valcntp = j;
6922N/A for (i = 0; i < j; i++)
6922N/A dpif_log(0, "flow_propstr2outports key %s %dth: %d", key, i+1,
6922N/A outports[i]);
6922N/A return (0);
6922N/A}
6922N/A
6922N/Astatic int
6922N/Aflow_propstr2vals(char *key, char *val, char ***propvalsp, int *valcntp)
6922N/A{
6922N/A char **propvals = *propvalsp, *curr;
6922N/A int maxcnt = *valcntp, i, j, len;
6922N/A char c;
6922N/A
6922N/A dpif_log(0, "flow_propstr2vals key %s val %s", key, val);
6922N/A len = strlen(val);
6922N/A
6922N/A ovs_assert(strcmp(key, "outports") != 0);
6922N/A for (i = 0, j = 0, curr = val; i < len && j < maxcnt; i++) {
6922N/A if ((c = val[i]) != FP_ACTION_MULTI_VAL_DELIM &&
6922N/A i != len -1)
6922N/A continue;
6922N/A
6922N/A if (c == FP_ACTION_MULTI_VAL_DELIM)
6922N/A val[i] = '\0';
6922N/A
6922N/A if (strlcpy(propvals[j++], curr, DLADM_PROP_VAL_MAX) >=
6922N/A DLADM_PROP_VAL_MAX) {
6922N/A dpif_log(EINVAL, "flow_propstr2vals key %s %dth"
6922N/A " string too long %s", key, j - 1, curr);
6922N/A return (EINVAL);
6922N/A }
6922N/A curr = val + i + 1;
6922N/A }
6922N/A if (j >= maxcnt)
6922N/A dpif_log(ENOBUFS, "flow_propstr2vals action truncated");
5728N/A *valcntp = j;
5728N/A for (i = 0; i < j; i++)
5728N/A dpif_log(0, "flow_propstr2vals key %s %dth: %s", key, i+1,
5728N/A propvals[i]);
5728N/A return (0);
5728N/A}
5728N/A
5728N/Astatic int
5728N/Aflow_propval2action_ofaction(char *propval, struct ofpbuf *action)
5728N/A{
6554N/A char ofaction_str[4096];
5728N/A char **pvals, *buf = NULL;
6922N/A uint32_t outports[MAC_OF_MAXPORT];
5728N/A size_t len;
5728N/A char *curr, *key, c;
5728N/A boolean_t match;
6922N/A int nval, err = 0, i, j;
6922N/A
6922N/A buf = malloc((sizeof (char *) + DLADM_PROP_VAL_MAX) *
6922N/A DLADM_PROP_VAL_MAX);
5728N/A
5728N/A pvals = (char **)(void *)buf;
6922N/A for (i = 0; i < DLADM_PROP_VAL_MAX; i++) {
6922N/A pvals[i] = buf + sizeof (char *) * DLADM_PROP_VAL_MAX +
5728N/A i * DLADM_PROP_VAL_MAX;
5728N/A }
5728N/A
5728N/A if (strlcpy(ofaction_str, propval, sizeof (ofaction_str)) >=
5728N/A sizeof (ofaction_str)) {
5728N/A err = EINVAL;
5728N/A goto done;
5728N/A }
5728N/A
5728N/A len = strlen(ofaction_str);
5728N/A curr = ofaction_str;
5728N/A key = NULL;
5728N/A for (i = 0; i < len; i++) {
5728N/A c = ofaction_str[i];
5728N/A
5728N/A match = (c == FP_NAME_VAL_DELIM || c == FP_MULTI_ACTION_DELIM);
5728N/A if (!match && i != len - 1)
5728N/A continue;
5728N/A if (match) {
5728N/A ofaction_str[i] = '\0';
5728N/A if (*curr == '\0') {
5728N/A err = EINVAL;
5728N/A goto done;
5728N/A }
5728N/A }
5728N/A if (c == FP_NAME_VAL_DELIM) {
5728N/A key = curr;
5728N/A curr = ofaction_str + i + 1;
5728N/A continue;
5728N/A }
5728N/A
5728N/A if (key == NULL) {
5728N/A err = EINVAL;
5728N/A goto done;
5728N/A }
5728N/A
6922N/A if (strcmp(key, "outports") == 0) {
6922N/A nval = MAC_OF_MAXPORT;
6922N/A err = flow_propstr2outports(key, curr, outports, &nval);
6922N/A } else {
6922N/A nval = DLADM_PROP_VAL_MAX;
6922N/A err = flow_propstr2vals(key, curr, &pvals, &nval);
6922N/A }
5728N/A if (err != 0)
5728N/A goto done;
5728N/A
6922N/A if (strcmp(key, "outports") == 0) {
6922N/A for (j = 0; j < nval; j++)
6922N/A nl_msg_put_u32(action, OVS_ACTION_ATTR_OUTPUT,
6922N/A outports[j]);
6922N/A } else if (strcmp(key, "max-bw") == 0)
5728N/A err = flow_propval2action_setpri(pvals, nval, action);
5728N/A else if (strcmp(key, "controller") == 0)
5728N/A err = flow_propval2action_controller(pvals, nval,
5728N/A action);
5728N/A else if (strcmp(key, "vlan-tag") == 0)
5728N/A err = flow_propval2action_pushvlan(pvals, nval, action);
5728N/A else if (strcmp(key, "vlan-strip") == 0)
5728N/A err = flow_propval2action_popvlan(pvals, nval, action);
5728N/A else if (strcmp(key, "set-ether") == 0)
5728N/A err = flow_propval2action_setether(pvals, nval, action);
5728N/A else if (strcmp(key, "set-ipv4") == 0)
5728N/A err = flow_propval2action_setipv4(pvals, nval, action);
5728N/A else if (strcmp(key, "set-ipv6") == 0)
5728N/A err = flow_propval2action_setipv6(pvals, nval, action);
5728N/A else if (strcmp(key, "set-tcp") == 0)
5728N/A err = flow_propval2action_settcp(pvals, nval, action);
5728N/A else if (strcmp(key, "set-udp") == 0)
5728N/A err = flow_propval2action_setudp(pvals, nval, action);
5728N/A else if (strcmp(key, "set-sctp") == 0)
5728N/A err = flow_propval2action_setsctp(pvals, nval, action);
5728N/A else if (strcmp(key, "set-tunnel") == 0)
5728N/A err = flow_propval2action_settnl(pvals, nval, action);
5728N/A else
5728N/A err = EINVAL;
5728N/A
5728N/A if (err != 0)
5728N/A goto done;
5728N/A
5728N/A key = NULL;
5728N/A curr = ofaction_str + i + 1;
5728N/A }
5728N/Adone:
5728N/A free(buf);
5728N/A return (err);
5728N/A}
5728N/A
5728N/A/* valcnt must be 1 */
5088N/Astatic rc_err_t
5088N/Asolaris_flowinfo2actionmap(const char *key, dlmgr_DLValue_t *val,
5088N/A void *arg)
5088N/A{
5088N/A struct ofpbuf *action = arg;
6554N/A char propval[4096];
5728N/A int valcnt, err = 0;
5088N/A
5088N/A switch (val->ddlv_type) {
5088N/A case DDLVT_STRING:
5088N/A if (val->ddlv_sval == NULL)
5088N/A goto out;
5088N/A if (strlen(val->ddlv_sval) == 0)
5088N/A goto out;
5088N/A valcnt = 1;
6554N/A if (strlcpy(propval, val->ddlv_sval, sizeof (propval)) >=
6922N/A sizeof (propval))
5728N/A goto out;
5088N/A break;
5088N/A case DDLVT_STRINGS:
5088N/A if (val->ddlv_slist_count == 0)
5088N/A goto out;
5088N/A valcnt = val->ddlv_slist_count;
5728N/A if (valcnt != 1 || strlen(val->ddlv_slist[0]) == 0)
5088N/A goto out;
6554N/A if (strlcpy(propval, val->ddlv_slist[0], sizeof (propval)) >=
6922N/A sizeof (propval))
5728N/A goto out;
5088N/A break;
5088N/A case DDLVT_ULONG:
5088N/A if (val->ddlv_ulval == NULL || *val->ddlv_ulval == 0)
5088N/A goto out;
5088N/A valcnt = 1;
6554N/A (void) snprintf(propval, sizeof (propval), "%llu",
5088N/A *val->ddlv_ulval);
5088N/A break;
5088N/A case DDLVT_BOOLEAN:
5088N/A case DDLVT_BOOLEANS:
5088N/A case DDLVT_LONG:
5088N/A case DDLVT_LONGS:
5088N/A case DDLVT_ULONGS:
5088N/A case DDLVT_DICTIONARY:
5088N/A case DDLVT_DICTIONARYS:
5088N/A default:
5088N/A goto out;
5088N/A }
5088N/A dpif_log(0, "solaris_flowinfo2actionmap %s:%d %s", key, valcnt,
5728N/A propval);
5728N/A
5728N/A if (strcmp(key, "ofaction") == 0)
5728N/A err = flow_propval2action_ofaction(propval, action);
5728N/A
5088N/Aout:
5088N/A dlmgr_DLValue_free(val);
5088N/A return (err == 0 ? RCE_OK : -1);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Asolaris_flowinfo2action(dlmgr__rad_dict_string_DLValue_t *flowinfo,
5088N/A struct ofpbuf *action)
5088N/A{
5088N/A dlmgr__rad_dict_string_DLValue_t *fdict;
5088N/A dlmgr_DLValue_t *flist = NULL;
5088N/A rc_err_t status;
5088N/A int err = 0;
5088N/A
5088N/A status = dlmgr__rad_dict_string_DLValue_get(flowinfo, "properties",
5088N/A &flist);
5728N/A if (status != RCE_OK) {
5728N/A dpif_log(EINVAL, "solaris_flowinfo2action get properties failed"
5728N/A " %d", status);
5088N/A return (EINVAL);
5728N/A }
5088N/A
5088N/A fdict = flist->ddlv_dval;
5088N/A status = dlmgr__rad_dict_string_DLValue_map(fdict,
5088N/A solaris_flowinfo2actionmap, action);
5728N/A if (status != RCE_OK) {
5088N/A err = EINVAL;
5728N/A dpif_log(EINVAL, "solaris_flowinfo2action get walk actionmap "
5728N/A "failed %d", status);
5728N/A }
5088N/A
5088N/A dlmgr_DLValue_free(flist);
5088N/A return (err);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_get_flowaction(const char *flowname, struct ofpbuf *action)
5088N/A{
5088N/A dlmgr__rad_dict_string_DLValue_t *flowinfo = NULL;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A rc_instance_t *flow = NULL;
5088N/A rc_err_t status;
5088N/A int err = 0;
5088N/A
5088N/A status = dlmgr_Flow__rad_lookup(rad_conn, B_TRUE, &flow, 1,
5088N/A "name", flowname);
5088N/A if (status != RCE_OK) {
5088N/A return (ENODEV);
5088N/A }
5088N/A
5088N/A status = dlmgr_Flow_getInfo(flow, NULL, 0, &flowinfo, &derrp);
5088N/A if (status != RCE_OK) {
5088N/A err = -1;
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A err = derrp->dde_err;
5088N/A /*
5088N/A * XXX For now, log DDLSTATUS_NOT_FOUND as debug until
5088N/A * we can determine how to handle the RAD caching
5088N/A * issue.
5088N/A */
5088N/A dpif_log(err == DDLSTATUS_NOT_FOUND ? 0 : err,
5088N/A "failed Flow_getInfo(%s): %s",
5088N/A flowname, derrp->dde_errmsg);
5088N/A }
5088N/A }
5088N/A
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A rc_instance_rele(flow);
5088N/A
5088N/A if (err == 0) {
5088N/A err = solaris_flowinfo2action(flowinfo, action);
5088N/A dlmgr__rad_dict_string_DLValue_free(flowinfo);
5088N/A }
5088N/A
5088N/A return (err);
5088N/A}
5088N/A
5088N/Astatic int
5088N/Ai_solaris_get_flowstats(rc_instance_t *flow, uint64_t *npackets,
5088N/A uint64_t *nbytes, uint64_t *lastused)
5088N/A{
5088N/A dlmgr__rad_dict_string_DLValue_t *flowstat = NULL;
5088N/A dlmgr_DLValue_t *dlval = NULL;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A rc_err_t status;
5088N/A int err = 0;
5088N/A
5088N/A status = dlmgr_Flow_getStatistics(flow, NULL, 0, &flowstat, &derrp);
5088N/A if (status != RCE_OK) {
5088N/A err = -1;
5088N/A if (status == RCE_SERVER_OBJECT) {
5088N/A err = derrp->dde_err;
5088N/A dpif_log(err, "failed Flow_getStatistics(): %s",
5088N/A derrp->dde_errmsg);
5088N/A }
5088N/A goto out;
5088N/A }
5088N/A
5088N/A#if _TBD_
5088N/A uint16_t tcp_flags; /* bitmaps of tcp_flags */
5088N/A#endif
5088N/A status = dlmgr__rad_dict_string_DLValue_get(flowstat, "ipackets",
5088N/A &dlval);
5088N/A if (status != RCE_OK) {
5088N/A err = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A *npackets = *dlval->ddlv_ulval;
5088N/A dlmgr_DLValue_free(dlval);
5088N/A
5088N/A status = dlmgr__rad_dict_string_DLValue_get(flowstat, "opackets",
5088N/A &dlval);
5088N/A if (status != RCE_OK) {
5088N/A err = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A *npackets += *dlval->ddlv_ulval;
5088N/A dlmgr_DLValue_free(dlval);
5088N/A
5088N/A status = dlmgr__rad_dict_string_DLValue_get(flowstat, "ibytes",
5088N/A &dlval);
5088N/A if (status != RCE_OK) {
5088N/A err = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A *nbytes = *dlval->ddlv_ulval;
5088N/A dlmgr_DLValue_free(dlval);
5088N/A
5088N/A status = dlmgr__rad_dict_string_DLValue_get(flowstat, "obytes",
5088N/A &dlval);
5088N/A if (status != RCE_OK) {
5088N/A err = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A *nbytes += *dlval->ddlv_ulval;
5088N/A dlmgr_DLValue_free(dlval);
5088N/A
5088N/A status = dlmgr__rad_dict_string_DLValue_get(flowstat, "lastused",
5088N/A &dlval);
5088N/A if (status != RCE_OK) {
5088N/A err = EINVAL;
5088N/A goto out;
5088N/A }
5088N/A *lastused = *dlval->ddlv_ulval;
5088N/A dlmgr_DLValue_free(dlval);
5088N/Aout:
5088N/A dlmgr__rad_dict_string_DLValue_free(flowstat);
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A return (err);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_get_flowstats(const char *flowname, uint64_t *npackets,
5088N/A uint64_t *nbytes, uint64_t *lastused)
5088N/A{
5088N/A rc_err_t status;
5088N/A rc_instance_t *flow = NULL;
5088N/A int err;
5088N/A
5088N/A status = dlmgr_Flow__rad_lookup(rad_conn, B_TRUE, &flow, 1,
5088N/A "name", flowname);
5088N/A if (status != RCE_OK) {
5088N/A err = ENODEV;
5088N/A goto out;
5088N/A }
5088N/A
5088N/A err = i_solaris_get_flowstats(flow, npackets, nbytes, lastused);
5088N/Aout:
5088N/A rc_instance_rele(flow);
5088N/A return (err);
5088N/A}
5088N/A
5088N/Aboolean_t
5088N/Akstat_handle_init(kstat2_handle_t *khandlep)
5088N/A{
5088N/A kstat2_status_t stat;
5088N/A
5916N/A stat = kstat2_open(khandlep, NULL);
5088N/A return (stat != KSTAT2_S_OK ? B_FALSE: B_TRUE);
5088N/A}
5088N/A
5088N/Aboolean_t
5088N/Akstat_handle_update(kstat2_handle_t khandle)
5088N/A{
5088N/A kstat2_status_t stat;
5088N/A
5088N/A stat = kstat2_update(khandle);
5088N/A return (stat != KSTAT2_S_OK ? B_FALSE: B_TRUE);
5088N/A}
5088N/A
5088N/Avoid
5088N/Akstat_handle_close(kstat2_handle_t *khandlep)
5088N/A{
5088N/A kstat2_close(khandlep);
5088N/A}
5088N/A
5088N/Auint64_t
5088N/Aget_nvvt_int(kstat2_map_t map, char *name)
5088N/A{
5088N/A kstat2_status_t stat;
5088N/A kstat2_nv_t val;
5088N/A
5088N/A stat = kstat2_map_get(map, name, &val);
5088N/A if (stat != KSTAT2_S_OK) {
5088N/A (void) printf("can't get value: %s\n",
5088N/A kstat2_status_string(stat));
5088N/A return (0);
5088N/A }
5088N/A
5088N/A if (val->type != KSTAT2_NVVT_INT) {
5088N/A (void) printf("%s is not KSTAT2_NVVT_INT type\n", name);
5088N/A return (0);
5088N/A }
5088N/A
5088N/A return (val->kstat2_integer);
5088N/A}
5088N/A
5088N/Avoid
5088N/Asolaris_port_walk(void *arg, void (*fn)(void *, const char *, char *,
5088N/A odp_port_t))
5088N/A{
5088N/A adr_name_t **anamearr = NULL;
5088N/A int anamecnt = 0, i;
5088N/A rc_err_t rerr;
5088N/A
5088N/A rerr = dlmgr_Datalink__rad_list(rad_conn, B_FALSE, NS_GLOB, &anamearr,
5088N/A &anamecnt, 0);
5088N/A if (rerr != RCE_OK)
5088N/A return;
5088N/A
5088N/A if (anamecnt == 0) {
5088N/A free(anamearr);
5088N/A return;
5088N/A }
5088N/A
5088N/A for (i = 0; i < anamecnt; i++) {
5088N/A dlmgr_DLDict_t **dlist = NULL;
5088N/A dlmgr_DLValue_t *dlval = NULL;
5088N/A const char *props[1];
5088N/A const char *fields[1];
5088N/A int ndlist = 0;
5088N/A rc_instance_t *rip = NULL;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A rc_err_t rerr;
5088N/A
5088N/A rerr = rc_lookup(rad_conn, anamearr[i], NULL, B_FALSE, &rip);
5088N/A if (rerr != RCE_OK)
5088N/A continue;
5088N/A
5088N/A props[0] = "ofport";
5088N/A fields[0] = "current";
5088N/A rerr = dlmgr_Datalink_getProperties(rip, props, 1, fields, 1,
5088N/A &dlist, &ndlist, &derrp);
5088N/A rc_instance_rele(rip);
5088N/A if (rerr != RCE_OK) {
5088N/A if (rerr == RCE_SERVER_OBJECT) {
5088N/A dpif_log(derrp->dde_err,
5088N/A "failed Datalink_getProperties(%s, %s): %s",
5088N/A adr_name_key(anamearr[i], "name"),
5088N/A props[0], derrp->dde_errmsg);
5088N/A }
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A continue;
5088N/A }
5088N/A rerr = dlmgr__rad_dict_string_DLValue_get((*dlist)->ddld_map,
5088N/A "current", &dlval);
5088N/A if (rerr != RCE_OK || dlval->ddlv_sval == NULL) {
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A dlmgr_DLValue_free(dlval);
5088N/A dlmgr_DLDict_array_free(dlist, ndlist);
5088N/A continue;
5088N/A }
5088N/A
5088N/A if (dlval->ddlv_sval != NULL && dlval->ddlv_sval[0] != '\0') {
5088N/A fn(arg, adr_name_key(anamearr[i], "name"),
5088N/A "system", atoi(dlval->ddlv_sval));
5088N/A }
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A dlmgr_DLValue_free(dlval);
5088N/A dlmgr_DLDict_array_free(dlist, ndlist);
5088N/A }
5728N/A
5088N/A for (i = 0; i < anamecnt; i++)
5088N/A adr_name_rele(anamearr[i]);
5088N/A free(anamearr);
5088N/A}
5088N/A
7235N/Avoid
7235N/Asolaris_flow_walk(void *arg, struct ofpbuf *action,
7235N/A void (*fn)(void *, const char *, struct flow *, struct flow *,
5088N/A struct ofpbuf *, uint64_t, uint64_t, uint64_t))
5088N/A{
5088N/A adr_name_t **anamearr = NULL;
5088N/A int anamecnt = 0, i;
5088N/A rc_err_t rerr;
5088N/A int err = 0;
5088N/A
5088N/A rerr = dlmgr_Flow__rad_list(rad_conn, B_FALSE, NS_GLOB, &anamearr,
5088N/A &anamecnt, 0);
5088N/A if (rerr != RCE_OK)
7235N/A return;
5088N/A
5088N/A if (anamecnt == 0) {
5088N/A free(anamearr);
7235N/A return;
5088N/A }
5088N/A
5088N/A for (i = 0; i < anamecnt; i++) {
5088N/A dlmgr__rad_dict_string_DLValue_t *flowinfo;
5088N/A char linkname[MAXLINKNAMELEN];
5088N/A rc_instance_t *rip = NULL;
5088N/A dlmgr_DLDict_t **dlist;
5088N/A dlmgr_DLValue_t *dlval;
5088N/A const char *props[1];
5088N/A const char *fields[1];
5088N/A struct flow f, m;
5088N/A int ndlist = 0;
5088N/A uint64_t npackets, nbytes, lastused;
5088N/A dlmgr_DatalinkError_t *derrp = NULL;
5088N/A
5088N/A flowinfo = NULL;
5088N/A dlist = NULL;
5088N/A dlval = NULL;
5088N/A if (strstr(adr_name_key(anamearr[i], "name"), "defflow") !=
5088N/A NULL) {
7235N/A continue;
5728N/A } else if (strstr(adr_name_key(anamearr[i], "name"),
5728N/A "sys.of") == NULL) {
5728N/A continue;
5088N/A }
5728N/A
5088N/A rerr = rc_lookup(rad_conn, anamearr[i], NULL, B_FALSE, &rip);
5088N/A if (rerr != RCE_OK)
5088N/A continue;
5088N/A
5088N/A if ((err = i_solaris_get_flowstats(rip, &npackets, &nbytes,
5088N/A &lastused)) != 0) {
5088N/A dpif_log(err, "solaris_flow_walk get_flowstats "
5088N/A "failed for %s: %d", adr_name_key(anamearr[i],
5088N/A "name"), err);
5088N/A rc_instance_rele(rip);
5088N/A goto done;
5088N/A }
5088N/A
5088N/A rerr = dlmgr_Flow_getInfo(rip, NULL, 0, &flowinfo, &derrp);
5088N/A rc_instance_rele(rip);
5088N/A if (rerr != RCE_OK) {
5088N/A err = -1;
5088N/A if (rerr == RCE_SERVER_OBJECT) {
5088N/A err = derrp->dde_err;
5088N/A /*
5088N/A * XXX For now, log DDLSTATUS_NOT_FOUND as
5088N/A * debug until we can determine how to handle
5088N/A * the RAD caching issue.
5088N/A */
5088N/A dpif_log(err == DDLSTATUS_NOT_FOUND ? 0 : err,
5088N/A "failed Flow_getInfo(%s): %s",
5088N/A adr_name_key(anamearr[i], "name"),
5088N/A derrp->dde_errmsg);
5088N/A }
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A goto done;
5088N/A }
5088N/A
5088N/A /* See whether this flow is created over of enabled link */
5088N/A err = solaris_flowinfo2linkname(flowinfo, linkname,
5088N/A MAXLINKNAMELEN);
5088N/A if (err != 0) {
5088N/A goto done;
5088N/A }
5088N/A
5088N/A rerr = dlmgr_Datalink__rad_lookup(rad_conn, B_TRUE, &rip,
5088N/A 1, "name", linkname);
5088N/A if (rerr != RCE_OK) {
5088N/A goto done;
5088N/A }
5088N/A
5088N/A props[0] = "openvswitch";
5088N/A fields[0] = "current";
5088N/A rerr = dlmgr_Datalink_getProperties(rip, props, 1, fields, 1,
5088N/A &dlist, &ndlist, &derrp);
5088N/A rc_instance_rele(rip);
5088N/A if (rerr != RCE_OK) {
5088N/A err = -1;
5088N/A if (rerr == RCE_SERVER_OBJECT) {
5088N/A err = derrp->dde_err;
5088N/A dpif_log(err,
5088N/A "failed Datalink_getProperties(%s, %s): %s",
5088N/A linkname, props[0], derrp->dde_errmsg);
5088N/A }
5088N/A dlmgr_DatalinkError_free(derrp);
5088N/A goto done;
5088N/A }
5088N/A rerr = dlmgr__rad_dict_string_DLValue_get((*dlist)->ddld_map,
5088N/A "current", &dlval);
5088N/A if (rerr != RCE_OK)
5088N/A goto done;
5088N/A
5088N/A if (!dlval->ddlv_bval)
5088N/A goto done;
5088N/A
5088N/A err = solaris_flowinfo2flow(flowinfo, &f, &m);
5088N/A if (err != 0) {
5088N/A dpif_log(err, "solaris_flow_walk flowinfo2flow "
5088N/A "failed for %s: %d", adr_name_key(anamearr[i],
5088N/A "name"), err);
5088N/A goto done;
5088N/A }
5088N/A
7235N/A err = solaris_flowinfo2action(flowinfo, action);
7235N/A if (err != 0) {
7235N/A dpif_log(err, "solaris_flow_walk "
7235N/A "flowinfo2action failed for %s: %d",
7235N/A adr_name_key(anamearr[i], "name"), err);
7235N/A goto done;
5088N/A }
5088N/A
7235N/A fn(arg, adr_name_key(anamearr[i], "name"), &f, &m, action,
7235N/A npackets, nbytes, lastused);
5088N/Adone:
5088N/A dlmgr__rad_dict_string_DLValue_free(flowinfo);
5088N/A dlmgr_DLValue_free(dlval);
5088N/A dlmgr_DLDict_array_free(dlist, ndlist);
5088N/A }
5088N/A
5088N/A for (i = 0; i < anamecnt; i++)
5088N/A adr_name_rele(anamearr[i]);
5088N/A free(anamearr);
5088N/A}
5088N/A
5088N/Aint
5088N/Asolaris_dladm_status2error(dladm_status_t status)
5088N/A{
5088N/A int error;
5088N/A
5088N/A if (status == DLADM_STATUS_NOMEM) {
5088N/A error = ENOMEM;
5088N/A } else if (status == DLADM_STATUS_DENIED) {
5088N/A error = EPERM;
5088N/A } else if (status == DLADM_STATUS_OK) {
5088N/A error = 0;
5088N/A } else if (status == DLADM_STATUS_IOERR) {
5088N/A error = EIO;
5088N/A } else {
5088N/A error = EINVAL;
5088N/A }
5088N/A return (error);
5088N/A}
5088N/A
5088N/Aboolean_t
5088N/Asolaris_is_uplink_class(const char *class)
5088N/A{
5088N/A return (strcmp("phys", class) == 0 ||
5088N/A strcmp("aggr", class) == 0 ||
5088N/A strcmp("etherstub", class) == 0 ||
5088N/A strcmp("vxlan", class) == 0 ||
5637N/A strcmp("veth", class) == 0 ||
5088N/A strcmp("simnet", class) == 0);
5088N/A}
5088N/A
5088N/A/*
5088N/A * This is a copy of dlparse_zonelinkname() function in libinetutil. libinetutil
5088N/A * is not a public interface, therefore we make a copy here.
5088N/A *
5088N/A * Given a linkname that can be specified using a zonename prefix retrieve
5088N/A * the optional linkname and/or zone ID value. If no zonename prefix was
5088N/A * specified we set the optional linkname and set optional zone ID return
5088N/A * value to ALL_ZONES.
5088N/A */
5088N/Aboolean_t
5088N/Asolaris_dlparse_zonelinkname(const char *name, char *link_name,
5088N/A zoneid_t *zoneidp)
5088N/A{
5088N/A char buffer[MAXLINKNAMESPECIFIER];
5088N/A char *search = "/";
5088N/A char *zonetoken;
5088N/A char *linktoken;
5088N/A char *last;
5088N/A size_t namelen;
5088N/A
5088N/A if (link_name != NULL)
5088N/A link_name[0] = '\0';
5088N/A if (zoneidp != NULL)
5088N/A *zoneidp = ALL_ZONES;
5088N/A
5088N/A if ((namelen = strlcpy(buffer, name, sizeof (buffer))) >=
5088N/A sizeof (buffer))
5088N/A return (_B_FALSE);
5088N/A
5088N/A if ((zonetoken = strtok_r(buffer, search, &last)) == NULL)
5088N/A return (_B_FALSE);
5088N/A
5088N/A /* If there are no other strings, return given name as linkname */
5088N/A if ((linktoken = strtok_r(NULL, search, &last)) == NULL) {
5088N/A if (namelen >= MAXLINKNAMELEN)
5088N/A return (_B_FALSE);
5088N/A if (link_name != NULL)
5088N/A (void) strlcpy(link_name, name, MAXLINKNAMELEN);
5088N/A return (_B_TRUE);
5088N/A }
5088N/A
5088N/A /* First token is the zonename. Check zone and link lengths */
5088N/A if (strlen(zonetoken) >= ZONENAME_MAX || strlen(linktoken) >=
5088N/A MAXLINKNAMELEN)
5088N/A return (_B_FALSE);
5088N/A /*
5088N/A * If there are more '/' separated strings in the input
5088N/A * name then we return failure. We only support a single
5088N/A * zone prefix or a devnet directory (f.e. net/bge0).
5088N/A */
5088N/A if (strtok_r(NULL, search, &last) != NULL)
5088N/A return (_B_FALSE);
5088N/A
5088N/A if (link_name != NULL)
5088N/A (void) strlcpy(link_name, linktoken, MAXLINKNAMELEN);
5088N/A if (zoneidp != NULL) {
5088N/A if ((*zoneidp = getzoneidbyname(zonetoken)) < MIN_ZONEID)
5088N/A return (_B_FALSE);
5088N/A }
5088N/A
5088N/A return (_B_TRUE);
5088N/A}
6016N/A
6016N/A/*
6016N/A * Sets *n_cores to the total number of cores on this system, or 0 if the
6016N/A * number cannot be determined.
6016N/A */
6016N/Avoid
6016N/Asolaris_parse_cpuinfo(long int *n_cores)
6016N/A{
6016N/A kstat2_handle_t handle;
6016N/A kstat2_status_t stat;
6016N/A kstat2_map_t map;
6016N/A kstat2_nv_t val;
6016N/A char kuri[1024];
6016N/A int coreid;
6016N/A int lcoreid = -1;
6016N/A int i;
6016N/A
6016N/A *n_cores = 0;
6016N/A
6016N/A stat = kstat2_open(&handle, NULL);
6016N/A if (stat != KSTAT2_S_OK) {
6016N/A dpif_log(1, "solaris_parse_cpuinfo kstat2_open failed (%s). "
6016N/A "Core count may be inaccurate.",
6016N/A kstat2_status_string(stat));
6016N/A return;
6016N/A }
6016N/A
6016N/A for (i = 0; ; i++) {
6016N/A (void) snprintf(kuri, sizeof (kuri),
6016N/A "kstat:/system/cpu/%d/info", i);
6016N/A stat = kstat2_lookup_map(handle, kuri, &map);
6016N/A if (stat == KSTAT2_S_OK) {
6016N/A stat = kstat2_map_get(map, "core_id", &val);
6016N/A if (stat != KSTAT2_S_OK) {
6016N/A dpif_log(1, "solaris_parse_cpuinfo"
6016N/A "kstat2_map_get failed (%s). "
6016N/A "Core count may be inaccurate.",
6016N/A kstat2_status_string(stat));
6016N/A *n_cores = 0;
6016N/A break;
6016N/A }
6016N/A
6016N/A if (val->type != KSTAT2_NVVT_INT) {
6016N/A dpif_log(1, "solaris_parse_cpuinfo "
6016N/A "kstat2 value error. "
6016N/A "Core count may be inaccurate.");
6016N/A *n_cores = 0;
6016N/A break;
6016N/A }
6016N/A
6016N/A coreid = val->kstat2_integer;
6016N/A if (coreid != lcoreid) {
6016N/A (*n_cores)++;
6016N/A lcoreid = coreid;
6016N/A }
6016N/A } else if (stat == KSTAT2_S_NOT_FOUND) {
6016N/A /* no more cores */
6016N/A break;
6016N/A } else {
6016N/A dpif_log(1, "solaris_parse_cpuinfo kstat2_lookup_map "
6016N/A "failed (%s). Core count may be inaccurate.",
6016N/A kstat2_status_string(stat));
6016N/A *n_cores = 0;
6016N/A break;
6016N/A }
6016N/A }
6016N/A
6016N/A kstat2_close(&handle);
6016N/A}