* Get the nth parent interface of the given interface. 0 is the interface
* itself.
*
- * Return 0 on success, != 0 otherwise
+ * Return 0 on success, < 0 otherwise
*/
#if defined(__linux__) && WITH_MACVTAP
int
while (!end && i <= nthParent) {
rc = ifaceMacvtapLinkDump(true, ifname, ifindex, tb, &recvbuf, NULL);
- if (rc)
+ if (rc < 0)
break;
if (tb[IFLA_IFNAME]) {
char *if_sysfs_device_link = NULL;
int ret = -1;
- if (ifaceSysfsFile(&if_sysfs_device_link, ifname, "device"))
+ if (ifaceSysfsFile(&if_sysfs_device_link, ifname, "device") < 0)
return ret;
ret = pciDeviceIsVirtualFunction(if_sysfs_device_link);
char *pf_sysfs_device_link = NULL, *vf_sysfs_device_link = NULL;
int ret = -1;
- if (ifaceSysfsFile(&pf_sysfs_device_link, pfname, "device"))
+ if (ifaceSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0)
return ret;
- if (ifaceSysfsFile(&vf_sysfs_device_link, vfname, "device")) {
+ if (ifaceSysfsFile(&vf_sysfs_device_link, vfname, "device") < 0) {
VIR_FREE(pf_sysfs_device_link);
return ret;
}
char *physfn_sysfs_path = NULL;
int ret = -1;
- if (ifaceSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn"))
+ if (ifaceSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") < 0)
return ret;
ret = pciDeviceNetName(physfn_sysfs_path, pfname);
rc_on_fail = -1;
errmsg = _("cannot clean IFF_VNET_HDR flag on macvtap tap");
} else if ((ifreq.ifr_flags & IFF_VNET_HDR) == 0 && vnet_hdr) {
- if (ioctl(tapfd, TUNGETFEATURES, &features) != 0)
- return errno;
+ if (ioctl(tapfd, TUNGETFEATURES, &features) < 0) {
+ virReportSystemError(errno, "%s",
+ _("cannot get feature flags on macvtap tap"));
+ return -1;
+ }
if ((features & IFF_VNET_HDR)) {
new_flags = ifreq.ifr_flags | IFF_VNET_HDR;
errmsg = _("cannot set IFF_VNET_HDR flag on macvtap tap");
* emulate their switch in firmware.
*/
if (mode == VIR_MACVTAP_MODE_PASSTHRU) {
- if (ifaceReplaceMacAddress(macaddress, linkdev, stateDir) != 0) {
+ if (ifaceReplaceMacAddress(macaddress, linkdev, stateDir) < 0) {
return -1;
}
}
macaddress,
linkdev,
virtPortProfile,
- vmuuid, vmOp) != 0) {
+ vmuuid, vmOp) < 0) {
rc = -1;
goto link_del_exit;
}
}
rc = openTap(cr_ifname, 10);
-
if (rc >= 0) {
if (configMacvtapTap(rc, vnet_hdr) < 0) {
VIR_FORCE_CLOSE(rc); /* sets rc to -1 */
* status: pointer to a uint16 where the status will be written into
*
* Get the status from the IFLA_PORT_RESPONSE field; Returns 0 in
- * case of success, != 0 otherwise with error having been reported
+ * case of success, < 0 otherwise with error having been reported
*/
static int
getPortProfileStatus(struct nlattr **tb, int32_t vf,
bool is8021Qbg,
uint16_t *status)
{
- int rc = 1;
+ int rc = -1;
const char *msg = NULL;
struct nlattr *tb_port[IFLA_PORT_MAX + 1] = { NULL, };
int32_t vf,
uint8_t op)
{
- int rc = 0;
+ int rc = -1;
struct nlmsghdr *resp;
struct nlmsgerr *err;
struct ifinfomsg ifinfo = {
nl_msg = nlmsg_alloc_simple(RTM_SETLINK, NLM_F_REQUEST);
if (!nl_msg) {
virReportOOMError();
- return -1;
+ return rc;
}
if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
if (!nltarget_kernel) {
pid = getLldpadPid();
- if (pid == 0) {
- rc = -1;
+ if (pid == 0)
goto err_exit;
- }
}
- if (nlComm(nl_msg, &recvbuf, &recvbuflen, pid) < 0) {
- rc = -1;
+ if (nlComm(nl_msg, &recvbuf, &recvbuflen, pid) < 0)
goto err_exit;
- }
if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
goto malformed_resp;
virReportSystemError(-err->error,
_("error during virtual port configuration of ifindex %d"),
ifindex);
- rc = -1;
+ goto err_exit;
}
break;
goto malformed_resp;
}
+ rc = 0;
+
err_exit:
nlmsg_free(nl_msg);
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
_("malformed netlink response message"));
VIR_FREE(recvbuf);
- return -1;
+ return rc;
buffer_too_small:
nlmsg_free(nl_msg);
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
_("allocated netlink buffer is too small"));
- return -1;
+ return rc;
}
+/* Returns 0 on success, -1 on general failure, and -2 on timeout */
static int
doPortProfileOpCommon(bool nltarget_kernel,
const char *ifname, int ifindex,
hostUUID,
vf,
op);
-
- if (rc) {
+ if (rc < 0) {
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
_("sending of PortProfileRequest failed."));
return rc;
while (--repeats >= 0) {
rc = ifaceMacvtapLinkDump(nltarget_kernel, NULL, ifindex, tb,
&recvbuf, getLldpadPid);
- if (rc)
+ if (rc < 0)
goto err_exit;
+
rc = getPortProfileStatus(tb, vf, instanceId, nltarget_kernel,
is8021Qbg, &status);
- if (rc)
+ if (rc < 0)
goto err_exit;
if (status == PORT_PROFILE_RESPONSE_SUCCESS ||
status == PORT_VDP_RESPONSE_SUCCESS) {
_("error %d during port-profile setlink on "
"interface %s (%d)"),
status, ifname, ifindex);
- rc = 1;
+ rc = -1;
break;
}
if (status == PORT_PROFILE_RESPONSE_INPROGRESS) {
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
_("port-profile setlink timed out"));
- rc = -ETIMEDOUT;
+ rc = -2;
}
err_exit:
*vlanid = -1;
while (1) {
if ((ret = ifaceGetNthParent(ifindex, ifname, 1,
- root_ifindex, root_ifname, &nth)))
+ root_ifindex, root_ifname, &nth)) < 0)
return ret;
if (nth == 0)
break;
# endif
+/* Returns 0 on success, -1 on general failure, and -2 on timeout */
static int
doPortProfileOp8021Qbg(const char *ifname,
const unsigned char *macaddr,
const virVirtualPortProfileParamsPtr virtPort,
enum virVirtualPortOp virtPortOp)
{
- int rc;
+ int rc = 0;
# ifndef IFLA_VF_PORT_MAX
(void)virtPortOp;
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Kernel VF Port support was missing at compile time."));
- rc = 1;
+ rc = -1;
# else /* IFLA_VF_PORT_MAX */
int vf = PORT_SELF_VF;
if (getPhysdevAndVlan(ifname, &physdev_ifindex, physdev_ifname,
- &vlanid) != 0) {
- rc = 1;
+ &vlanid) < 0) {
+ rc = -1;
goto err_exit;
}
default:
macvtapError(VIR_ERR_INTERNAL_ERROR,
_("operation type %d not supported"), virtPortOp);
- rc = 1;
+ rc = -1;
goto err_exit;
}
int32_t *vf,
char **physfndev)
{
- int rc = 0;
-
- if (ifaceIsVirtualFunction(linkdev)) {
+ int rc = -1;
+ if (ifaceIsVirtualFunction(linkdev) == 1) {
/* if linkdev is SR-IOV VF, then set vf = VF index */
/* and set linkdev = PF device */
*physfndev = strdup(linkdev);
if (!*physfndev) {
virReportOOMError();
- rc = -1;
+ goto err_exit;
}
+ rc = 0;
}
+err_exit:
+
return rc;
}
# endif /* IFLA_VF_PORT_MAX */
+/* Returns 0 on success, -1 on general failure, and -2 on timeout */
static int
doPortProfileOp8021Qbh(const char *ifname,
const unsigned char *macaddr,
const unsigned char *vm_uuid,
enum virVirtualPortOp virtPortOp)
{
- int rc;
+ int rc = 0;
# ifndef IFLA_VF_PORT_MAX
(void)virtPortOp;
macvtapError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Kernel VF Port support was missing at compile time."));
- rc = 1;
+ rc = -1;
# else /* IFLA_VF_PORT_MAX */
int vlanid = -1;
rc = getPhysfnDev(ifname, &vf, &physfndev);
- if (rc)
+ if (rc < 0)
goto err_exit;
- if (ifaceGetIndex(true, physfndev, &ifindex) < 0) {
- rc = 1;
+ rc = ifaceGetIndex(true, physfndev, &ifindex);
+ if (rc < 0)
goto err_exit;
- }
switch (virtPortOp) {
case PREASSOCIATE_RR:
case ASSOCIATE:
- rc = virGetHostUUID(hostuuid);
- if (rc)
+ errno = virGetHostUUID(hostuuid);
+ if (errno) {
+ rc = -1;
goto err_exit;
+ }
rc = doPortProfileOpCommon(nltarget_kernel, NULL, ifindex,
macaddr,
(virtPortOp == PREASSOCIATE_RR) ?
PORT_REQUEST_PREASSOCIATE_RR
: PORT_REQUEST_ASSOCIATE);
- if (rc == -ETIMEDOUT)
+ if (rc == -2)
/* Association timed out, disassociate */
doPortProfileOpCommon(nltarget_kernel, NULL, ifindex,
NULL,
default:
macvtapError(VIR_ERR_INTERNAL_ERROR,
_("operation type %d not supported"), virtPortOp);
- rc = 1;
+ rc = -1;
}
err_exit:
* by the user, then this function returns without doing
* anything.
*
- * Returns 0 in case of success, != 0 otherwise with error
+ * Returns 0 in case of success, < 0 otherwise with error
* having been reported.
*/
int