diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c index 4280513b0f..f58b9d0074 100644 --- a/src/conf/device_conf.c +++ b/src/conf/device_conf.c @@ -32,29 +32,6 @@ #define VIR_FROM_THIS VIR_FROM_DEVICE -VIR_ENUM_IMPL(virInterfaceState, - VIR_INTERFACE_STATE_LAST, - "" /* value of zero means no state */, - "unknown", "notpresent", - "down", "lowerlayerdown", - "testing", "dormant", "up") - -VIR_ENUM_IMPL(virNetDevFeature, - VIR_NET_DEV_FEAT_LAST, - "rx", - "tx", - "sg", - "tso", - "gso", - "gro", - "lro", - "rxvlan", - "txvlan", - "ntuple", - "rxhash", - "rdma", - "txudptnl") - int virPCIDeviceAddressIsValid(virPCIDeviceAddressPtr addr, bool report) { @@ -196,7 +173,7 @@ virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1, int virInterfaceLinkParseXML(xmlNodePtr node, - virInterfaceLinkPtr lnk) + virNetDevIfLinkPtr lnk) { int ret = -1; char *stateStr, *speedStr; @@ -206,7 +183,7 @@ virInterfaceLinkParseXML(xmlNodePtr node, speedStr = virXMLPropString(node, "speed"); if (stateStr) { - if ((state = virInterfaceStateTypeFromString(stateStr)) < 0) { + if ((state = virNetDevIfStateTypeFromString(stateStr)) < 0) { virReportError(VIR_ERR_XML_ERROR, _("unknown link state: %s"), stateStr); @@ -232,7 +209,7 @@ virInterfaceLinkParseXML(xmlNodePtr node, int virInterfaceLinkFormat(virBufferPtr buf, - const virInterfaceLink *lnk) + const virNetDevIfLink *lnk) { if (!lnk->speed && !lnk->state) { /* If there's nothing to format, return early. */ @@ -244,7 +221,7 @@ virInterfaceLinkFormat(virBufferPtr buf, virBufferAsprintf(buf, " speed='%u'", lnk->speed); if (lnk->state) virBufferAsprintf(buf, " state='%s'", - virInterfaceStateTypeToString(lnk->state)); + virNetDevIfStateTypeToString(lnk->state)); virBufferAddLit(buf, "/>\n"); return 0; } diff --git a/src/conf/device_conf.h b/src/conf/device_conf.h index 934afd4445..9b7916092d 100644 --- a/src/conf/device_conf.h +++ b/src/conf/device_conf.h @@ -32,45 +32,7 @@ # include "virthread.h" # include "virbuffer.h" # include "virpci.h" - -typedef enum { - VIR_INTERFACE_STATE_UNKNOWN = 1, - VIR_INTERFACE_STATE_NOT_PRESENT, - VIR_INTERFACE_STATE_DOWN, - VIR_INTERFACE_STATE_LOWER_LAYER_DOWN, - VIR_INTERFACE_STATE_TESTING, - VIR_INTERFACE_STATE_DORMANT, - VIR_INTERFACE_STATE_UP, - VIR_INTERFACE_STATE_LAST -} virInterfaceState; - -VIR_ENUM_DECL(virInterfaceState) - -typedef struct _virInterfaceLink virInterfaceLink; -typedef virInterfaceLink *virInterfaceLinkPtr; -struct _virInterfaceLink { - virInterfaceState state; /* link state */ - unsigned int speed; /* link speed in Mbits per second */ -}; - -typedef enum { - VIR_NET_DEV_FEAT_GRXCSUM, - VIR_NET_DEV_FEAT_GTXCSUM, - VIR_NET_DEV_FEAT_GSG, - VIR_NET_DEV_FEAT_GTSO, - VIR_NET_DEV_FEAT_GGSO, - VIR_NET_DEV_FEAT_GGRO, - VIR_NET_DEV_FEAT_LRO, - VIR_NET_DEV_FEAT_RXVLAN, - VIR_NET_DEV_FEAT_TXVLAN, - VIR_NET_DEV_FEAT_NTUPLE, - VIR_NET_DEV_FEAT_RXHASH, - VIR_NET_DEV_FEAT_RDMA, - VIR_NET_DEV_FEAT_TXUDPTNL, - VIR_NET_DEV_FEAT_LAST -} virNetDevFeature; - -VIR_ENUM_DECL(virNetDevFeature) +# include "virnetdev.h" typedef enum { VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE, @@ -218,9 +180,9 @@ bool virPCIDeviceAddressEqual(virPCIDeviceAddress *addr1, virPCIDeviceAddress *addr2); int virInterfaceLinkParseXML(xmlNodePtr node, - virInterfaceLinkPtr lnk); + virNetDevIfLinkPtr lnk); int virInterfaceLinkFormat(virBufferPtr buf, - const virInterfaceLink *lnk); + const virNetDevIfLink *lnk); #endif /* __DEVICE_CONF_H__ */ diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 79d15c8ed2..8aea766932 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -53,6 +53,7 @@ #include "network_conf.h" #include "virtpm.h" #include "virstring.h" +#include "virnetdev.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h index ac212fb530..5cabec7f43 100644 --- a/src/conf/interface_conf.h +++ b/src/conf/interface_conf.h @@ -147,7 +147,7 @@ struct _virInterfaceDef { char *name; /* interface name */ unsigned int mtu; /* maximum transmit size in byte */ char *mac; /* MAC address */ - virInterfaceLink lnk; /* interface link info */ + virNetDevIfLink lnk; /* interface link info */ virInterfaceStartMode startmode; /* how it is started */ diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index be6dd5eb4e..9e3e6fe5a9 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -140,7 +140,7 @@ typedef struct _virNodeDevCapData { char *address; unsigned int address_len; char *ifname; - virInterfaceLink lnk; + virNetDevIfLink lnk; virNodeDevNetCapType subtype; /* LAST -> no subtype */ virBitmapPtr features; /* enum virNetDevFeature */ } net; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 11f049994f..e5174495c6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -78,8 +78,6 @@ virCPUModeTypeToString; # conf/device_conf.h virInterfaceLinkFormat; virInterfaceLinkParseXML; -virInterfaceStateTypeFromString; -virInterfaceStateTypeToString; virPCIDeviceAddressEqual; virPCIDeviceAddressFormat; virPCIDeviceAddressIsValid; @@ -1861,6 +1859,8 @@ virNetDevAddRoute; virNetDevClearIPAddress; virNetDevDelMulti; virNetDevExists; +virNetDevFeatureTypeFromString; +virNetDevFeatureTypeToString; virNetDevGetFeatures; virNetDevGetIndex; virNetDevGetIPAddress; @@ -1877,6 +1877,8 @@ virNetDevGetVirtualFunctionIndex; virNetDevGetVirtualFunctionInfo; virNetDevGetVirtualFunctions; virNetDevGetVLanID; +virNetDevIfStateTypeFromString; +virNetDevIfStateTypeToString; virNetDevIsVirtualFunction; virNetDevReplaceMacAddress; virNetDevReplaceNetConfig; diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 0308256a75..8f4e949874 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -2547,10 +2547,33 @@ virNetDevRestoreNetConfig(const char *linkdev ATTRIBUTE_UNUSED, #endif /* defined(__linux__) && defined(HAVE_LIBNL) */ +VIR_ENUM_IMPL(virNetDevIfState, + VIR_NETDEV_IF_STATE_LAST, + "" /* value of zero means no state */, + "unknown", "notpresent", + "down", "lowerlayerdown", + "testing", "dormant", "up") + +VIR_ENUM_IMPL(virNetDevFeature, + VIR_NET_DEV_FEAT_LAST, + "rx", + "tx", + "sg", + "tso", + "gso", + "gro", + "lro", + "rxvlan", + "txvlan", + "ntuple", + "rxhash", + "rdma", + "txudptnl") + #ifdef __linux__ int virNetDevGetLinkInfo(const char *ifname, - virInterfaceLinkPtr lnk) + virNetDevIfLinkPtr lnk) { int ret = -1; char *path = NULL; @@ -2580,7 +2603,7 @@ virNetDevGetLinkInfo(const char *ifname, /* We shouldn't allow 0 here, because * virInterfaceState enum starts from 1. */ - if ((tmp_state = virInterfaceStateTypeFromString(buf)) <= 0) { + if ((tmp_state = virNetDevIfStateTypeFromString(buf)) <= 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); @@ -2593,7 +2616,7 @@ virNetDevGetLinkInfo(const char *ifname, * report several misleading values. While igb reports 65535, realtek goes * with 10. To avoid muddying XML with insane values, don't report link * speed if that's the case. */ - if (lnk->state != VIR_INTERFACE_STATE_UP) { + if (lnk->state != VIR_NETDEV_IF_STATE_UP) { lnk->speed = 0; ret = 0; goto cleanup; @@ -2638,7 +2661,7 @@ virNetDevGetLinkInfo(const char *ifname, int virNetDevGetLinkInfo(const char *ifname, - virInterfaceLinkPtr lnk) + virNetDevIfLinkPtr lnk) { /* Port me */ VIR_DEBUG("Getting link info on %s is not implemented on this platform", diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 522536f5d5..849f8e74d5 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -30,7 +30,6 @@ # include "virmacaddr.h" # include "virpci.h" # include "virnetdevvlan.h" -# include "device_conf.h" # ifdef HAVE_STRUCT_IFREQ typedef struct ifreq virIfreq; @@ -74,6 +73,43 @@ struct _virNetDevRxFilter { } vlan; }; +typedef enum { + VIR_NETDEV_IF_STATE_UNKNOWN = 1, + VIR_NETDEV_IF_STATE_NOT_PRESENT, + VIR_NETDEV_IF_STATE_DOWN, + VIR_NETDEV_IF_STATE_LOWER_LAYER_DOWN, + VIR_NETDEV_IF_STATE_TESTING, + VIR_NETDEV_IF_STATE_DORMANT, + VIR_NETDEV_IF_STATE_UP, + VIR_NETDEV_IF_STATE_LAST +} virNetDevIfState; + +VIR_ENUM_DECL(virNetDevIfState) + +typedef struct { + virNetDevIfState state; /* link state */ + unsigned int speed; /* link speed in Mbits per second */ +} virNetDevIfLink, *virNetDevIfLinkPtr; + +typedef enum { + VIR_NET_DEV_FEAT_GRXCSUM, + VIR_NET_DEV_FEAT_GTXCSUM, + VIR_NET_DEV_FEAT_GSG, + VIR_NET_DEV_FEAT_GTSO, + VIR_NET_DEV_FEAT_GGSO, + VIR_NET_DEV_FEAT_GGRO, + VIR_NET_DEV_FEAT_LRO, + VIR_NET_DEV_FEAT_RXVLAN, + VIR_NET_DEV_FEAT_TXVLAN, + VIR_NET_DEV_FEAT_NTUPLE, + VIR_NET_DEV_FEAT_RXHASH, + VIR_NET_DEV_FEAT_RDMA, + VIR_NET_DEV_FEAT_TXUDPTNL, + VIR_NET_DEV_FEAT_LAST +} virNetDevFeature; + +VIR_ENUM_DECL(virNetDevFeature) + int virNetDevSetupControl(const char *ifname, virIfreq *ifr) ATTRIBUTE_RETURN_CHECK; @@ -187,7 +223,7 @@ int virNetDevGetFeatures(const char *ifname, ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; int virNetDevGetLinkInfo(const char *ifname, - virInterfaceLinkPtr lnk) + virNetDevIfLinkPtr lnk) ATTRIBUTE_NONNULL(1); virNetDevRxFilterPtr virNetDevRxFilterNew(void) diff --git a/tests/virnetdevtest.c b/tests/virnetdevtest.c index 3987a8ac21..7c8a03f9b7 100644 --- a/tests/virnetdevtest.c +++ b/tests/virnetdevtest.c @@ -30,7 +30,7 @@ struct testVirNetDevGetLinkInfoData { const char *ifname; /* ifname to get info on */ - virInterfaceState state; /* expected state */ + virNetDevIfState state; /* expected state */ unsigned int speed; /* expected speed */ }; @@ -39,7 +39,7 @@ testVirNetDevGetLinkInfo(const void *opaque) { int ret = -1; const struct testVirNetDevGetLinkInfoData *data = opaque; - virInterfaceLink lnk; + virNetDevIfLink lnk; if (virNetDevGetLinkInfo(data->ifname, &lnk) < 0) goto cleanup; @@ -47,8 +47,8 @@ testVirNetDevGetLinkInfo(const void *opaque) if (lnk.state != data->state) { fprintf(stderr, "Fetched link state (%s) doesn't match the expected one (%s)", - virInterfaceStateTypeToString(lnk.state), - virInterfaceStateTypeToString(data->state)); + virNetDevIfStateTypeToString(lnk.state), + virNetDevIfStateTypeToString(data->state)); goto cleanup; } @@ -77,9 +77,9 @@ mymain(void) ret = -1; \ } while (0) - DO_TEST_LINK("eth0", VIR_INTERFACE_STATE_UP, 1000); - DO_TEST_LINK("lo", VIR_INTERFACE_STATE_UNKNOWN, 0); - DO_TEST_LINK("eth0-broken", VIR_INTERFACE_STATE_DOWN, 0); + DO_TEST_LINK("eth0", VIR_NETDEV_IF_STATE_UP, 1000); + DO_TEST_LINK("lo", VIR_NETDEV_IF_STATE_UNKNOWN, 0); + DO_TEST_LINK("eth0-broken", VIR_NETDEV_IF_STATE_DOWN, 0); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; }