NetIf-solaris.cpp revision 71d819c352c9a8d9df9857363a15b4bc17778f6e
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Main - NetIfList, Solaris implementation.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Copyright (C) 2008-2012 Oracle Corporation
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * available from http://www.virtualbox.org. This file is free software;
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * General Public License (GPL) as published by the Free Software
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync/*******************************************************************************
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync* Header Files *
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync*******************************************************************************/
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsyncstatic uint32_t getInstance(const char *pszIfaceName, char *pszDevName)
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Get the instance number from the interface name, then clip it off.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync strncpy(pszDevName, pszIfaceName, cbIface - cbInstance);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync kstat_t *ksAdapter = kstat_lookup(kc, "link", -1, (char *)name);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync ksAdapter = kstat_lookup(kc, szModule, uInstance, "phys");
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync ksAdapter = kstat_lookup(kc, szModule, uInstance, (char*)name);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync LogRel(("Failed to get network statistics for %s\n", name));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync if ((kn = (kstat_named_t *)kstat_data_lookup(ksAdapter, (char *)"ifspeed")) == 0)
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync LogRel(("kstat_data_lookup(ifspeed) -> %d, name=%s\n", errno, name));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync uSpeed = kn->value.ul / 1000000; /* bits -> Mbits */
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync LogFlow(("kstatGet(%s) -> %u Mbit/s\n", name, uSpeed));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync /* Don't query interface speed for inactive interfaces (see @bugref{6345}). */
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync LogFlow(("queryIfaceSpeed(%s) -> %u\n", pInfo->szShortName, pInfo->uSpeedMbits));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsyncstatic void vboxSolarisAddHostIface(char *pszIface, int Instance, void *pvHostNetworkInterfaceList)
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync std::list<ComObjPtr<HostNetworkInterface> > *pList = (std::list<ComObjPtr<HostNetworkInterface> > *)pvHostNetworkInterfaceList;
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync typedef std::map <std::string, std::string> NICMap;
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync typedef std::pair <std::string, std::string> NICPair;
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("afe", "ADMtek Centaur/Comet Fast Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("atge", "Atheros/Attansic Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("aggr", "Link Aggregation Interface"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("bfe", "Broadcom BCM4401 Fast Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("bge", "Broadcom BCM57xx Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("bnx", "Broadcom NetXtreme Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("bnxe", "Broadcom NetXtreme II 10 Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("ce", "Cassini Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("chxge", "Chelsio Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("dmfe", "Davicom 9102 Fast Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("dnet", "DEC 21040/41 21140 Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("e1000", "Intel PRO/1000 Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("e1000g", "Intel PRO/1000 Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("elx", "3COM Etherlink III Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("elxl", "3COM Etherlink XL Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("eri", "eri Fast Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("ge", "GEM Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("hme", "SUNW,hme Fast-Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("hxge", "Sun Blade 10 Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("igb", "Intel 82575 PCI-E Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("ipge", "PCI-E Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("iprb", "Intel 82557/58/59 Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("ixgb", "Intel 82597ex 10 Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("ixgbe", "Intel 10 Gigabit PCI-E Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("mcxe", "Mellanox ConnectX-2 10 Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("mxfe", "Macronix 98715 Fast Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("nfo", "Nvidia Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("nge", "Nvidia Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("ntxn", "NetXen 10/1 Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("nxge", "Sun 10/1 Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("pcelx", "3COM EtherLink III PCMCIA Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("pcn", "AMD PCnet Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("qfe", "SUNW,qfe Quad Fast-Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("rge", "Realtek Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("rtls", "Realtek 8139 Fast Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("sfe", "SiS900 Fast Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("skge", "SksKonnect Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("spwr", "SMC EtherPower II 10/100 (9432) Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("vboxnet", "VirtualBox Host Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("vboxvnic_template", "VirtualBox Virtual Network Interface Template"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("vlan", "Virtual LAN Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("vr", "VIA Rhine Fast Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("vnic", "Virtual Network Interface Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("xge", "Neterior Xframe 10Gigabit Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync SolarisNICMap.insert(NICPair("yge", "Marvell Yukon 2 Fast Ethernet"));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Try picking up description from our NIC map.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync RTStrPrintf(szNICInstance, sizeof(szNICInstance), "%s%d", pszIface, Instance);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync RTStrPrintf(szNICDesc, sizeof(szNICDesc), "%s - %s", szNICInstance, Description.c_str());
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync RTStrPrintf(szNICDesc, sizeof(szNICDesc), "%s - Ethernet", szNICInstance);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync RTStrPrintf(szNICDesc, sizeof(szNICDesc), "%s", szNICInstance);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Try to get IP V4 address and netmask as well as Ethernet address.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync int Sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync memcpy(Info.IPAddress.au8, &((struct sockaddr_in *)&IfReq.lifr_addr)->sin_addr.s_addr,
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync memcpy(&ArpReq.arp_pa, &IfReq.lifr_addr, sizeof(struct sockaddr_in));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * We might fail if the interface has not been assigned an IP address.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * That doesn't matter; as long as it's plumbed we can pick it up.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * But, if it has not acquired an IP address we cannot obtain it's MAC
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * address this way, so we just use all zeros there.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync memcpy(&Info.MACAddress, ArpReq.arp_ha.sa_data, sizeof(Info.MACAddress));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync memcpy(Info.IPNetMask.au8, &((struct sockaddr_in *)&IfReq.lifr_addr)->sin_addr.s_addr,
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync Info.enmStatus = IfReq.lifr_flags & IFF_UP ? NETIF_S_UP : NETIF_S_DOWN;
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Try to get IP V6 address and netmask.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync memcpy(Info.IPv6Address.au8, ((struct sockaddr_in6 *)&IfReq.lifr_addr)->sin6_addr.s6_addr,
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync memcpy(Info.IPv6NetMask.au8, ((struct sockaddr_in6 *)&IfReq.lifr_addr)->sin6_addr.s6_addr,
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Construct UUID with interface name and the MAC address if available.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync memcpy(&Uuid, szNICInstance, RT_MIN(strlen(szNICInstance), sizeof(Uuid)));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync Uuid.Gen.u8ClockSeqHiAndReserved = (Uuid.Gen.u8ClockSeqHiAndReserved & 0x3f) | 0x80;
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync Uuid.Gen.u16TimeHiAndVersion = (Uuid.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000;
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync strncpy(Info.szShortName, szNICInstance, sizeof(Info.szShortName) - 1);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync if (SUCCEEDED(IfObj->init(Bstr(szNICDesc), enmType, &Info)))
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsyncstatic boolean_t vboxSolarisAddLinkHostIface(const char *pszIface, void *pvHostNetworkInterfaceList)
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Skip IPSEC interfaces. It's at IP level.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Skip our own dynamic VNICs but don't skip VNIC templates.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * These names originate from VBoxNetFltBow-solaris.c, hardcoded here for now.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Clip off the zone instance number from the interface name (if any).
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync char *pszColon = (char *)memchr(szIfaceName, ':', sizeof(szIfaceName));
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Get the instance number from the interface name, then clip it off.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync strncpy(szIfaceName, pszIface, cbIface - cbInstance);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Add the interface.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync vboxSolarisAddHostIface(szIfaceName, Instance, pvHostNetworkInterfaceList);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Continue walking...
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsyncstatic bool vboxSolarisSortNICList(const ComObjPtr<HostNetworkInterface> Iface1, const ComObjPtr<HostNetworkInterface> Iface2)
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync (*Iface1).COMGETTER(Name) (Iface1Str.asOutParam());
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync (*Iface2).COMGETTER(Name) (Iface2Str.asOutParam());
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsyncstatic bool vboxSolarisSameNIC(const ComObjPtr<HostNetworkInterface> Iface1, const ComObjPtr<HostNetworkInterface> Iface2)
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync (*Iface1).COMGETTER(Name) (Iface1Str.asOutParam());
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync (*Iface2).COMGETTER(Name) (Iface2Str.asOutParam());
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsyncstatic int vboxSolarisAddPhysHostIface(di_node_t Node, di_minor_t Minor, void *pvHostNetworkInterfaceList)
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Skip aggregations.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Skip softmacs.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync vboxSolarisAddHostIface(di_driver_name(Node), di_instance(Node), pvHostNetworkInterfaceList);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsyncint NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list)
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Use libdevinfo for determining all physical interfaces.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync di_walk_minor(Root, DDI_NT_NET, 0, &list, vboxSolarisAddPhysHostIface);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * Use libdlpi for determining all DLPI interfaces.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync g_pfnLibDlpiWalk(vboxSolarisAddLinkHostIface, &list, 0);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * This gets only the list of all plumbed logical interfaces.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * This is needed for zones which cannot access the device tree
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * and in this case we just let them use the list of plumbed interfaces
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync * on the zone.
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync int Sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync int cIfaces = RT_MIN(1024, IfNum.lifn_count); /* sane limit */
a9a79301a7d78abffc51521473bbb5a1e08028c5vboxsync struct lifreq *Ifaces = (struct lifreq *)RTMemTmpAlloc(cbIfaces);
for (int i = 0; i < cIfaces; i++)
if (rc >= 0)
if (rc >= 0)
return VINF_SUCCESS;
return VERR_NOT_IMPLEMENTED;
return VERR_NOT_IMPLEMENTED;
return VINF_SUCCESS;