mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 11:01:19 +00:00
add 802.1Qbh and 802.1Qbg handling
This patch that adds support for configuring 802.1Qbg and 802.1Qbh switches. The 802.1Qbh part has been successfully tested with real hardware. The 802.1Qbg part has only been tested with a (dummy) server that 'behaves' similarly to how we expect lldpad to 'behave'. The following changes were made during the development of this patch: - Merging Scott's v13-pre1 patch - Fixing endptr related bug while using virStrToLong_ui() pointed out by Jim Meyering - Addressing Jim Meyering's comments to v11 - requiring mac address to the vpDisassociateProfileId() function to pass it further to the 802.1Qbg disassociate part (802.1Qbh untouched) - determining pid of lldpad daemon by reading it from /var/run/libvirt.pid (hardcode as is hardcode alson in lldpad sources) - merging netlink send code for kernel target and user space target (lldpad) using one function nlComm() to send the messages - adding a select() after the sending and before the reading of the netlink response in case lldpad doesn't respond and so we don't hang - when reading the port status, in case of 802.1Qbg, no status may be received while things are 'in progress' and only at the end a status will be there. - when reading the port status, use the given instanceId and vf to pick the right IFLA_VF_PORT among those nested under IFLA_VF_PORTS. - never sending nor parsing IFLA_PORT_SELF type of messages in the 802.1Qbg case - iterating over the elements in a IFLA_VF_PORTS to pick the right IFLA_VF_PORT by either IFLA_PORT_PROFILE and given profileId (802.1Qbh) or IFLA_PORT_INSTANCE_UUID and given instanceId (802.1Qbg) and reading the current status in IFLA_PORT_RESPONSE. - recycling a previous patch that adds functionality to interface.c to - get the vlan identifier on an interface - get the flags of an interface and some convenience function to check whether an interface is 'up' or not (not currently used here) - adding function to determine the root physical interface of an interface. For example if a macvtap is linked to eth0.100, it will find eth0. Also adding a function that finds the vlan on the 'way to the root physical interface' - conveying the root physical interface name and index in case of 802.1Qbg - conveying mac address of macvlan device and vlan identifier in IFLA_VFINFO_LIST[ IFLA_VF_INFO[ IFLA_VF_MAC(mac), IFLA_VF_VLAN(vlan) ] ] to (future) lldpad via netlink - To enable build with --without-macvtap rename the [dis|]associatePortProfileId functions, prepend 'vp' before their name and make them non-static functions. - Renaming variable multicast to nltarget_kernel and inverting the logic - Addressing Jim Meyering's comments; this also touches existing code for example for correcting indentation of break statements or simplification of switch statements. - Renamed occurrencvirVirtualPortProfileDef to virVirtualPortProfileParamses - 802.1Qbg part prepared for sending a RTM_SETLINK and getting processing status back plus a subsequent RTM_GETLINK to get IFLA_PORT_RESPONSE. Note: This interface for 802.1Qbg may still change - [David Allan] move getPhysfn inside IFLA_VF_PORT_MAX to avoid compiler warning when latest if_link.h isn't available - move from Stefan's 802.1Qb{g|h} XML v8 to v9 - move hostuuid and vf index calcs to inside doPortProfileOp8021Qbh - remove debug fprintfs - use virGetHostUUID (thanks Stefan!) - fix compile issue when latest if_link.h isn't available - change poll timeout to 10s, at 1/8 intervals - if polling times out, log msg and return -ETIMEDOUT - Add Stefan's code for getPortProfileStatus - Poll for up to 2 secs for port-profile status, at 1/8 sec intervals: - if status indicates error, abort openMacvtapTap - if status indicates success, exit polling - if status is "in-progress" after 2 secs of polling, exit polling loop silently, without error My patch finishes out the 802.1Qbh parts, which Stefan had mostly complete. I've tested using the recent kernel updates for VF_PORT netlink msgs and enic for Cisco's 10G Ethernet NIC. I tested many VMs, each with several direct interfaces, each configured with a port-profile per the XML. VM-to-VM, and VM-to-external work as expected. VM-to-VM on same host (using same NIC) works same as VM-to-VM where VMs are on diff hosts. I'm able to change settings on the port-profile while the VM is running to change the virtual port behaviour. For example, adjusting a QoS setting like rate limit. All VMs with interfaces using that port-profile immediatly see the effect of the change to the port-profile. I don't have a SR-IOV device to test so source dev is a non-SR-IOV device, but most of the code paths include support for specifing the source dev and VF index. We'll need to complete this by discovering the PF given the VF linkdev. Once we have the PF, we'll also have the VF index. All this info- mation is available from sysfs.
This commit is contained in:
parent
ce49cfb48a
commit
ca3b22bb5c
17
configure.ac
17
configure.ac
@ -2005,13 +2005,27 @@ if test "$with_macvtap" != "no" ; then
|
||||
fi
|
||||
AM_CONDITIONAL([WITH_MACVTAP], [test "$with_macvtap" = "yes"])
|
||||
|
||||
AC_TRY_COMPILE([ #include <sys/socket.h>
|
||||
#include <linux/rtnetlink.h> ],
|
||||
[ int x = IFLA_PORT_MAX; ],
|
||||
[ with_virtualport=yes ],
|
||||
[ with_virtualport=no ])
|
||||
if test "$with_virtualport" = "yes"; then
|
||||
val=1
|
||||
else
|
||||
val=0
|
||||
fi
|
||||
AC_DEFINE_UNQUOTED([WITH_VIRTUALPORT], $val,
|
||||
[whether vsi vepa support is enabled])
|
||||
AM_CONDITIONAL([WITH_VIRTUALPORT], [test "$with_virtualport" = "yes"])
|
||||
|
||||
|
||||
dnl netlink library
|
||||
|
||||
LIBNL_CFLAGS=""
|
||||
LIBNL_LIBS=""
|
||||
|
||||
if test "$with_macvtap" = "yes"; then
|
||||
if test "$with_macvtap" = "yes" || test "$with_virtualport" = "yes"; then
|
||||
PKG_CHECK_MODULES([LIBNL], [libnl-1 >= $LIBNL_REQUIRED], [
|
||||
], [
|
||||
AC_MSG_ERROR([libnl >= $LIBNL_REQUIRED is required for macvtap support])
|
||||
@ -2084,6 +2098,7 @@ AC_MSG_NOTICE([ Network: $with_network])
|
||||
AC_MSG_NOTICE([Libvirtd: $with_libvirtd])
|
||||
AC_MSG_NOTICE([ netcf: $with_netcf])
|
||||
AC_MSG_NOTICE([ macvtap: $with_macvtap])
|
||||
AC_MSG_NOTICE([virtport: $with_virtualport])
|
||||
AC_MSG_NOTICE([])
|
||||
AC_MSG_NOTICE([Storage Drivers])
|
||||
AC_MSG_NOTICE([])
|
||||
|
@ -695,6 +695,9 @@ virArgvToString;
|
||||
ifaceCtrl;
|
||||
ifaceCheck;
|
||||
ifaceGetIndex;
|
||||
ifaceGetFlags;
|
||||
ifaceIsUp;
|
||||
ifaceGetVlanID;
|
||||
|
||||
# usb.h
|
||||
usbGetDevice;
|
||||
|
@ -1559,7 +1559,7 @@ qemudPhysIfaceConnect(virConnectPtr conn,
|
||||
if (err) {
|
||||
close(rc);
|
||||
rc = -1;
|
||||
delMacvtap(net->ifname,
|
||||
delMacvtap(net->ifname, net->mac, net->data.direct.linkdev,
|
||||
&net->data.direct.virtPortProfile);
|
||||
VIR_FREE(net->ifname);
|
||||
}
|
||||
|
@ -3716,7 +3716,7 @@ static void qemudShutdownVMDaemon(struct qemud_driver *driver,
|
||||
for (i = 0; i < def->nnets; i++) {
|
||||
virDomainNetDefPtr net = def->nets[i];
|
||||
if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
delMacvtap(net->ifname,
|
||||
delMacvtap(net->ifname, net->mac, net->data.direct.linkdev,
|
||||
&net->data.direct.virtPortProfile);
|
||||
VIR_FREE(net->ifname);
|
||||
}
|
||||
@ -8555,7 +8555,7 @@ qemudDomainDetachNetDevice(struct qemud_driver *driver,
|
||||
|
||||
#if WITH_MACVTAP
|
||||
if (detach->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
delMacvtap(detach->ifname,
|
||||
delMacvtap(detach->ifname, detach->mac, detach->data.direct.linkdev,
|
||||
&detach->data.direct.virtPortProfile);
|
||||
VIR_FREE(detach->ifname);
|
||||
}
|
||||
|
@ -30,6 +30,8 @@
|
||||
|
||||
#ifdef __linux__
|
||||
# include <linux/if.h>
|
||||
# include <linux/sockios.h>
|
||||
# include <linux/if_vlan.h>
|
||||
#endif
|
||||
|
||||
#include "internal.h"
|
||||
@ -42,6 +44,85 @@
|
||||
virReportErrorHelper(NULL, VIR_FROM_NET, code, __FILE__, \
|
||||
__FUNCTION__, __LINE__, __VA_ARGS__)
|
||||
|
||||
#if __linux__
|
||||
static int
|
||||
getFlags(int fd, const char *ifname, struct ifreq *ifr) {
|
||||
|
||||
memset(ifr, 0, sizeof(*ifr));
|
||||
|
||||
if (virStrncpy(ifr->ifr_name,
|
||||
ifname, strlen(ifname), sizeof(ifr->ifr_name)) == NULL)
|
||||
return ENODEV;
|
||||
|
||||
if (ioctl(fd, SIOCGIFFLAGS, ifr) < 0)
|
||||
return errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* ifaceGetFlags
|
||||
*
|
||||
* @ifname : name of the interface
|
||||
* @flags : pointer to short holding the flags on success
|
||||
*
|
||||
* Get the flags of the interface. Returns 0 on success, error code on failure.
|
||||
*/
|
||||
int
|
||||
ifaceGetFlags(const char *ifname, short *flags) {
|
||||
struct ifreq ifr;
|
||||
int rc;
|
||||
int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
|
||||
|
||||
if (fd < 0)
|
||||
return errno;
|
||||
|
||||
rc = getFlags(fd, ifname, &ifr);
|
||||
|
||||
*flags = ifr.ifr_flags;
|
||||
|
||||
close(fd);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
ifaceIsUp(const char *ifname, bool *up) {
|
||||
short flags;
|
||||
int rc = ifaceGetFlags(ifname, &flags);
|
||||
|
||||
if (rc)
|
||||
return rc;
|
||||
|
||||
*up = ((flags & IFF_UP) == IFF_UP);
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
||||
/* Note: Showstopper on cygwin is only missing PF_PACKET */
|
||||
|
||||
int
|
||||
ifaceGetFlags(const char *ifname ATTRIBUTE_UNUSED,
|
||||
short *flags ATTRIBUTE_UNUSED) {
|
||||
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("ifaceGetFlags is not supported on non-linux platforms"));
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
int
|
||||
ifaceIsUp(const char *ifname ATTRIBUTE_UNUSED,
|
||||
bool *up ATTRIBUTE_UNUSED) {
|
||||
|
||||
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("ifaceIsUp is not supported on non-linux platforms"));
|
||||
return ENOSYS;
|
||||
}
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
||||
/*
|
||||
* chgIfaceFlags: Change flags on an interface
|
||||
*
|
||||
@ -59,23 +140,16 @@
|
||||
static int chgIfaceFlags(const char *ifname, short flagclear, short flagset) {
|
||||
struct ifreq ifr;
|
||||
int rc = 0;
|
||||
int flags;
|
||||
short flags;
|
||||
short flagmask = (~0 ^ flagclear);
|
||||
int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
|
||||
|
||||
if (fd < 0)
|
||||
return errno;
|
||||
|
||||
if (virStrncpy(ifr.ifr_name,
|
||||
ifname, strlen(ifname), sizeof(ifr.ifr_name)) == NULL) {
|
||||
rc = ENODEV;
|
||||
rc = getFlags(fd, ifname, &ifr);
|
||||
if (rc != 0)
|
||||
goto err_exit;
|
||||
}
|
||||
|
||||
if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) {
|
||||
rc = errno;
|
||||
goto err_exit;
|
||||
}
|
||||
|
||||
flags = (ifr.ifr_flags & flagmask) | flagset;
|
||||
|
||||
@ -151,6 +225,8 @@ ifaceCheck(bool reportError, const char *ifname,
|
||||
if (fd < 0)
|
||||
return errno;
|
||||
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
|
||||
if (virStrncpy(ifr.ifr_name,
|
||||
ifname, strlen(ifname), sizeof(ifr.ifr_name)) == NULL) {
|
||||
if (reportError)
|
||||
@ -227,6 +303,8 @@ ifaceGetIndex(bool reportError, const char *ifname, int *ifindex)
|
||||
if (fd < 0)
|
||||
return errno;
|
||||
|
||||
memset(&ifreq, 0, sizeof(ifreq));
|
||||
|
||||
if (virStrncpy(ifreq.ifr_name, ifname, strlen(ifname),
|
||||
sizeof(ifreq.ifr_name)) == NULL) {
|
||||
if (reportError)
|
||||
@ -269,3 +347,46 @@ ifaceGetIndex(bool reportError,
|
||||
}
|
||||
|
||||
#endif /* __linux__ */
|
||||
|
||||
#ifdef __linux__
|
||||
int
|
||||
ifaceGetVlanID(const char *vlanifname, int *vlanid) {
|
||||
struct vlan_ioctl_args vlanargs = {
|
||||
.cmd = GET_VLAN_VID_CMD,
|
||||
};
|
||||
int rc = 0;
|
||||
int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
|
||||
|
||||
if (fd < 0)
|
||||
return errno;
|
||||
|
||||
if (virStrcpyStatic(vlanargs.device1, vlanifname) == NULL) {
|
||||
rc = EINVAL;
|
||||
goto err_exit;
|
||||
}
|
||||
|
||||
if (ioctl(fd, SIOCGIFVLAN, &vlanargs) != 0) {
|
||||
rc = errno;
|
||||
goto err_exit;
|
||||
}
|
||||
|
||||
*vlanid = vlanargs.u.VID;
|
||||
|
||||
err_exit:
|
||||
close(fd);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
ifaceGetVlanID(const char *vlanifname ATTRIBUTE_UNUSED,
|
||||
int *vlanid ATTRIBUTE_UNUSED) {
|
||||
|
||||
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("ifaceGetVlanID is not supported on non-linux platforms"));
|
||||
|
||||
return ENOSYS;
|
||||
}
|
||||
#endif /* __linux__ */
|
||||
|
@ -12,6 +12,9 @@
|
||||
|
||||
# include "datatypes.h"
|
||||
|
||||
int ifaceGetFlags(const char *name, short *flags);
|
||||
int ifaceIsUp(const char *name, bool *up);
|
||||
|
||||
int ifaceCtrl(const char *name, bool up);
|
||||
|
||||
static inline int ifaceUp(const char *name) {
|
||||
@ -27,4 +30,6 @@ int ifaceCheck(bool reportError, const char *ifname,
|
||||
|
||||
int ifaceGetIndex(bool reportError, const char *ifname, int *ifindex);
|
||||
|
||||
int ifaceGetVlanID(const char *vlanifname, int *vlanid);
|
||||
|
||||
#endif /* __VIR_INTERFACE_H__ */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -72,6 +72,8 @@ int openMacvtapTap(const char *ifname,
|
||||
char **res_ifname);
|
||||
|
||||
void delMacvtap(const char *ifname,
|
||||
const unsigned char *macaddress,
|
||||
const char *linkdev,
|
||||
virVirtualPortProfileParamsPtr virtPortProfile);
|
||||
|
||||
# endif /* WITH_MACVTAP */
|
||||
@ -80,6 +82,16 @@ void delMacvtap(const char *ifname,
|
||||
# define MACVTAP_MODE_VEPA_STR "vepa"
|
||||
# define MACVTAP_MODE_BRIDGE_STR "bridge"
|
||||
|
||||
int vpAssociatePortProfileId(const char *macvtap_ifname,
|
||||
const unsigned char *macvtap_macaddr,
|
||||
const char *linkdev,
|
||||
const virVirtualPortProfileParamsPtr virtPort,
|
||||
const unsigned char *vmuuid);
|
||||
|
||||
int vpDisassociatePortProfileId(const char *macvtap_ifname,
|
||||
const unsigned char *macvtap_macaddr,
|
||||
const char *linkdev,
|
||||
const virVirtualPortProfileParamsPtr virtPort);
|
||||
|
||||
VIR_ENUM_DECL(virVirtualPort)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user