if (virStrncpy(ifr->ifr_name,
ifname, strlen(ifname), sizeof(ifr->ifr_name)) == NULL)
- return ENODEV;
+ return -ENODEV;
if (ioctl(fd, SIOCGIFFLAGS, ifr) < 0)
- return errno;
+ return -errno;
return 0;
}
* @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.
+ * Get the flags of the interface. Returns 0 on success, -errno on failure.
*/
int
ifaceGetFlags(const char *ifname, short *flags) {
int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
if (fd < 0)
- return errno;
+ return -errno;
rc = getFlags(fd, ifname, &ifr);
short flags = 0;
int rc = ifaceGetFlags(ifname, &flags);
- if (rc)
+ if (rc < 0)
return rc;
*up = ((flags & IFF_UP) == IFF_UP);
/* 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;
+ return -ENOSYS;
}
int
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
_("ifaceIsUp is not supported on non-linux platforms"));
- return ENOSYS;
+ return -ENOSYS;
}
#endif /* __linux__ */
* flagmask = (~0 ^ flagclear)
* newflags = (curflags & flagmask) | flagset;
*
- * Returns 0 on success, errno on failure.
+ * Returns 0 on success, -errno on failure.
*/
#ifdef __linux__
static int chgIfaceFlags(const char *ifname, short flagclear, short flagset) {
int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
if (fd < 0)
- return errno;
+ return -errno;
rc = getFlags(fd, ifname, &ifr);
- if (rc != 0)
+ if (rc < 0)
goto cleanup;
flags = (ifr.ifr_flags & flagmask) | flagset;
ifr.ifr_flags = flags;
if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0)
- rc = errno;
+ rc = -errno;
}
cleanup:
*
* Function to control if an interface is activated (up, 1) or not (down, 0)
*
- * Returns 0 in case of success or an errno code in case of failure.
+ * Returns 0 on success, -errno on failure.
*/
int
ifaceCtrl(const char *name, bool up)
int
ifaceCtrl(const char *name ATTRIBUTE_UNUSED, bool up ATTRIBUTE_UNUSED)
{
- return ENOSYS;
+ return -ENOSYS;
}
#endif /* __linux__ */
* it must have the given MAC address and if an interface index is
* passed, it must also match the interface index.
*
- * Returns 0 on success, an error code on failure.
- * ENODEV : if interface with given name does not exist or its interface
- * index is different than the one passed
- * EINVAL : if interface name is invalid (too long)
+ * Returns 0 on success, -errno on failure.
+ * -ENODEV : if interface with given name does not exist or its interface
+ * index is different than the one passed
+ * -EINVAL : if interface name is invalid (too long)
*/
#ifdef __linux__
int
if (macaddr != NULL) {
fd = socket(PF_PACKET, SOCK_DGRAM, 0);
if (fd < 0)
- return errno;
+ return -errno;
memset(&ifr, 0, sizeof(ifr));
ifaceError(VIR_ERR_INTERNAL_ERROR,
_("invalid interface name %s"),
ifname);
- rc = EINVAL;
+ rc = -EINVAL;
goto cleanup;
}
ifaceError(VIR_ERR_INTERNAL_ERROR,
_("coud not get MAC address of interface %s"),
ifname);
- rc = errno;
+ rc = -errno;
goto cleanup;
}
if (memcmp(&ifr.ifr_hwaddr.sa_data, macaddr, VIR_MAC_BUFLEN) != 0) {
- rc = ENODEV;
+ rc = -ENODEV;
goto cleanup;
}
}
if (ifindex != -1) {
rc = ifaceGetIndex(reportError, ifname, &idx);
if (rc == 0 && idx != ifindex)
- rc = ENODEV;
+ rc = -ENODEV;
}
cleanup:
const unsigned char *macaddr ATTRIBUTE_UNUSED,
int ifindex ATTRIBUTE_UNUSED)
{
- return ENOSYS;
+ return -ENOSYS;
}
#endif /* __linux__ */
*
* Get the index of an interface given its name.
*
- * Returns 0 on success, an error code on failure.
- * ENODEV : if interface with given name does not exist
- * EINVAL : if interface name is invalid (too long)
+ * Returns 0 on success, -errno on failure.
+ * -ENODEV : if interface with given name does not exist
+ * -EINVAL : if interface name is invalid (too long)
*/
#ifdef __linux__
int
int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
if (fd < 0)
- return errno;
+ return -errno;
memset(&ifreq, 0, sizeof(ifreq));
ifaceError(VIR_ERR_INTERNAL_ERROR,
_("invalid interface name %s"),
ifname);
- rc = EINVAL;
+ rc = -EINVAL;
goto cleanup;
}
ifaceError(VIR_ERR_INTERNAL_ERROR,
_("interface %s does not exist"),
ifname);
- rc = ENODEV;
+ rc = -ENODEV;
}
cleanup:
_("ifaceGetIndex is not supported on non-linux platforms"));
}
- return ENOSYS;
+ return -ENOSYS;
}
#endif /* __linux__ */
int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
if (fd < 0)
- return errno;
+ return -errno;
if (virStrcpyStatic(vlanargs.device1, vlanifname) == NULL) {
- rc = EINVAL;
+ rc = -EINVAL;
goto cleanup;
}
if (ioctl(fd, SIOCGIFVLAN, &vlanargs) != 0) {
- rc = errno;
+ rc = -errno;
goto cleanup;
}
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
_("ifaceGetVlanID is not supported on non-linux platforms"));
- return ENOSYS;
+ return -ENOSYS;
}
#endif /* __linux__ */
*
* This function gets the @macaddr for a given interface @ifname.
*
- * Returns 0 in case of success or an errno code in case of failure.
+ * Returns 0 on success, -errno on failure.
*/
#ifdef __linux__
int
int rc = 0;
if (!ifname)
- return EINVAL;
+ return -EINVAL;
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0)
- return errno;
+ return -errno;
memset(&ifr, 0, sizeof(struct ifreq));
if (virStrcpyStatic(ifr.ifr_name, ifname) == NULL) {
- rc = EINVAL;
+ rc = -EINVAL;
goto cleanup;
}
if (ioctl(fd, SIOCGIFHWADDR, (char *)&ifr) != 0) {
- rc = errno;
+ rc = -errno;
goto cleanup;
}
ifaceGetMacAddress(const char *ifname ATTRIBUTE_UNUSED,
unsigned char *macaddr ATTRIBUTE_UNUSED)
{
- return ENOSYS;
+ return -ENOSYS;
}
#endif /* __linux__ */
* This function sets the @macaddr for a given interface @ifname. This
* gets rid of the kernel's automatically assigned random MAC.
*
- * Returns 0 in case of success or an errno code in case of failure.
+ * Returns 0 on success, -errno on failure.
*/
#ifdef __linux__
int
int rc = 0;
if (!ifname)
- return EINVAL;
+ return -EINVAL;
fd = socket(AF_INET, SOCK_STREAM, 0);
if (fd < 0)
- return errno;
+ return -errno;
memset(&ifr, 0, sizeof(struct ifreq));
if (virStrcpyStatic(ifr.ifr_name, ifname) == NULL) {
- rc = EINVAL;
+ rc = -EINVAL;
goto cleanup;
}
/* To fill ifr.ifr_hdaddr.sa_family field */
if (ioctl(fd, SIOCGIFHWADDR, &ifr) != 0) {
- rc = errno;
+ rc = -errno;
goto cleanup;
}
memcpy(ifr.ifr_hwaddr.sa_data, macaddr, VIR_MAC_BUFLEN);
- rc = ioctl(fd, SIOCSIFHWADDR, &ifr) == 0 ? 0 : errno;
+ rc = ioctl(fd, SIOCSIFHWADDR, &ifr) == 0 ? 0 : -errno;
cleanup:
VIR_FORCE_CLOSE(fd);
ifaceSetMacAddress(const char *ifname ATTRIBUTE_UNUSED,
const unsigned char *macaddr ATTRIBUTE_UNUSED)
{
- return ENOSYS;
+ return -ENOSYS;
}
#endif /* __linux__ */
struct nl_msg *nl_msg;
struct nlattr *linkinfo, *info_data;
- if (ifaceGetIndex(true, srcdev, &ifindex) != 0)
+ if (ifaceGetIndex(true, srcdev, &ifindex) < 0)
return -1;
*retry = 0;
*nth = 0;
- if (ifindex <= 0 && ifaceGetIndex(true, ifname, &ifindex) != 0)
- return 1;
+ if (ifindex <= 0 && ifaceGetIndex(true, ifname, &ifindex) < 0)
+ return -1;
while (!end && i <= nthParent) {
rc = ifaceMacvtapLinkDump(true, ifname, ifindex, tb, &recvbuf, NULL);
ifaceError(VIR_ERR_INTERNAL_ERROR, "%s",
_("buffer for root interface name is too small"));
VIR_FREE(recvbuf);
- return 1;
+ return -1;
}
*parent_ifindex = ifindex;
}
* @linkdev: name of interface
* @stateDir: directory to store old MAC address
*
- * Returns 0 on success, -1 in case of fatal error, error code otherwise.
+ * Returns 0 on success, -errno on failure.
*
*/
int
rc = ifaceGetMacAddress(linkdev, oldmac);
- if (rc) {
+ if (rc < 0) {
virReportSystemError(rc,
_("Getting MAC address from '%s' "
"to '%02x:%02x:%02x:%02x:%02x:%02x' failed."),
stateDir,
linkdev) < 0) {
virReportOOMError();
- return errno;
+ return -errno;
}
virFormatMacAddr(oldmac, macstr);
if (virFileWriteStr(path, macstr, O_CREAT|O_TRUNC|O_WRONLY) < 0) {
virReportSystemError(errno, _("Unable to preserve mac for %s"),
linkdev);
- return errno;
+ return -errno;
}
}
rc = ifaceSetMacAddress(linkdev, macaddress);
- if (rc) {
+ if (rc < 0) {
virReportSystemError(rc,
_("Setting MAC address on '%s' to "
"'%02x:%02x:%02x:%02x:%02x:%02x' failed."),
* @linkdev: name of interface
* @stateDir: directory containing old MAC address
*
- * Returns 0 on success, -1 in case of fatal error, error code otherwise.
+ * Returns 0 on success, -errno on failure.
*
*/
int
stateDir,
linkdev) < 0) {
virReportOOMError();
- return -1;
+ return -errno;
}
if (virFileReadAll(path, VIR_MAC_STRING_BUFLEN, &macstr) < 0) {
- return errno;
+ return -errno;
}
if (virParseMacAddr(macstr, &oldmac[0]) != 0) {
_("Cannot parse MAC address from '%s'"),
oldmacname);
VIR_FREE(macstr);
- return -1;
+ return -EINVAL;
}
/*reset mac and remove file-ignore results*/
rc = ifaceSetMacAddress(linkdev, oldmac);
- if (rc) {
+ if (rc < 0) {
virReportSystemError(rc,
_("Setting MAC address on '%s' to "
"'%02x:%02x:%02x:%02x:%02x:%02x' failed."),