util/virnetdevbandwidth.h util/virnetdevbandwidth.c \
util/virnetdevbridge.h util/virnetdevbridge.c \
util/virnetdevtap.h util/virnetdevtap.c \
+ util/virnetdevveth.h util/virnetdevveth.c \
util/virnetdevvportprofile.h util/virnetdevvportprofile.c \
util/virsocketaddr.h util/virsocketaddr.c
LXC_DRIVER_SOURCES = \
lxc/lxc_conf.c lxc/lxc_conf.h \
lxc/lxc_container.c lxc/lxc_container.h \
- lxc/lxc_driver.c lxc/lxc_driver.h \
- lxc/veth.c lxc/veth.h
+ lxc/lxc_driver.c lxc/lxc_driver.h
LXC_CONTROLLER_SOURCES = \
lxc/lxc_conf.c lxc/lxc_conf.h \
lxc/lxc_container.c lxc/lxc_container.h \
- lxc/lxc_controller.c \
- lxc/veth.c lxc/veth.h
+ lxc/lxc_controller.c
SECURITY_DRIVER_APPARMOR_HELPER_SOURCES = \
security/virt-aa-helper.c
#include "lxc_container.h"
#include "util.h"
#include "memory.h"
-#include "veth.h"
+#include "virnetdevveth.h"
#include "uuid.h"
#include "virfile.h"
#include "command.h"
#include "lxc_conf.h"
#include "lxc_container.h"
-#include "veth.h"
+#include "virnetdev.h"
+#include "virnetdevveth.h"
#include "memory.h"
#include "util.h"
#include "virfile.h"
#include "memory.h"
#include "util.h"
#include "virnetdevbridge.h"
-#include "veth.h"
+#include "virnetdevveth.h"
#include "nodeinfo.h"
#include "uuid.h"
#include "stats_linux.h"
+++ /dev/null
-/*
- * veth.h: Interface to tools for managing veth pairs
- *
- * Copyright (C) 2010 Red Hat, Inc.
- * Copyright IBM Corp. 2008
- *
- * See COPYING.LIB for the License of this software
- *
- * Authors:
- * David L. Leskovec <dlesko at linux.vnet.ibm.com>
- */
-
-#ifndef VETH_H
-# define VETH_H
-
-# include <config.h>
-# include "internal.h"
-
-/* Function declarations */
-int virNetDevVethCreate(char **veth1, char **veth2)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
-int virNetDevVethDelete(const char *veth)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
-int virNetDevSetNamespace(const char *ifname, int pidInNs)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
-int virNetDevSetName(const char *ifname, const char *newifname)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
-
-#endif /* VETH_H */
}
+/**
+ * virNetDevSetNamespace:
+ * @ifname: name of device
+ * @pidInNs: PID of process in target net namespace
+ *
+ * Moves the given device into the target net namespace specified by the given
+ * pid using this command:
+ * ip link set @iface netns @pidInNs
+ *
+ * Returns 0 on success or -1 in case of error
+ */
+int virNetDevSetNamespace(const char *ifname, int pidInNs)
+{
+ int rc;
+ char *pid = NULL;
+ const char *argv[] = {
+ "ip", "link", "set", ifname, "netns", NULL, NULL
+ };
+
+ if (virAsprintf(&pid, "%d", pidInNs) == -1) {
+ virReportOOMError();
+ return -1;
+ }
+
+ argv[5] = pid;
+ rc = virRun(argv, NULL);
+
+ VIR_FREE(pid);
+ return rc;
+}
+
+#ifdef SIOCSIFNAME
+/**
+ * virNetDevSetName:
+ * @ifname: name of device
+ * @newifname: new name of @ifname
+ *
+ * Changes the name of the given device.
+ *
+ * Returns 0 on success, -1 on error
+ */
+int virNetDevSetName(const char* ifname, const char *newifname)
+{
+ int fd = -1;
+ int ret = -1;
+ struct ifreq ifr;
+
+ if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0)
+ return -1;
+
+ if (virStrcpyStatic(ifr.ifr_newname, newifname) == NULL) {
+ virReportSystemError(ERANGE,
+ _("Network interface name '%s' is too long"),
+ newifname);
+ goto cleanup;
+ }
+
+ if (ioctl(fd, SIOCSIFNAME, &ifr)) {
+ virReportSystemError(errno,
+ _("Unable to rename '%s' to '%s'"),
+ ifname, newifname);
+ goto cleanup;
+ }
+
+ ret = 0;
+
+cleanup:
+ VIR_FORCE_CLOSE(fd);
+ return ret;
+}
+#else
+int virNetDevSetName(const char* ifname, const char *newifname)
+{
+ virReportSystemError(ENOSYS,
+ _("Cannot rename interface '%s' to '%s' on this platform"),
+ ifname, newifname);
+ return -1;
+}
+#endif
+
+
#ifdef SIOCSIFFLAGS
/**
* virNetDevSetOnline:
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
int virNetDevGetMTU(const char *ifname)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+int virNetDevSetNamespace(const char *ifname, int pidInNs)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+int virNetDevSetName(const char *ifname, const char *newifname)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
#endif /* __VIR_NETDEV_H__ */
/*
- * veth.c: Tools for managing veth pairs
- *
* Copyright (C) 2010-2011 Red Hat, Inc.
* Copyright IBM Corp. 2008
*
- * See COPYING.LIB for the License of this software
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Authors:
- * David L. Leskovec <dlesko at linux.vnet.ibm.com>
+ * David L. Leskovec <dlesko at linux.vnet.ibm.com>
+ * Daniel P. Berrange <berrange@redhat.com>
*/
#include <config.h>
-#include <linux/sockios.h>
-#include <net/if.h>
-#include <string.h>
-#include <stdio.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
#include <sys/wait.h>
-#include "veth.h"
-#include "internal.h"
-#include "logging.h"
+#include "virnetdevveth.h"
#include "memory.h"
+#include "logging.h"
#include "command.h"
#include "virterror_internal.h"
-#include "virfile.h"
#define VIR_FROM_THIS VIR_FROM_NONE
return rc;
}
-
-
-/**
- * virNetDevSetNamespace:
- * @ifname: name of device
- * @pidInNs: PID of process in target net namespace
- *
- * Moves the given device into the target net namespace specified by the given
- * pid using this command:
- * ip link set @iface netns @pidInNs
- *
- * Returns 0 on success or -1 in case of error
- */
-int virNetDevSetNamespace(const char* ifname, int pidInNs)
-{
- int rc;
- char *pid = NULL;
- const char *argv[] = {
- "ip", "link", "set", ifname, "netns", NULL, NULL
- };
-
- if (virAsprintf(&pid, "%d", pidInNs) == -1) {
- virReportOOMError();
- return -1;
- }
-
- argv[5] = pid;
- rc = virRun(argv, NULL);
-
- VIR_FREE(pid);
- return rc;
-}
-
-/**
- * virNetDevSetName:
- * @ifname: name of device
- * @new: new name of @ifname
- *
- * Changes the name of the given device.
- *
- * Returns 0 on success, -1 on failure with errno set.
- */
-int virNetDevSetName(const char* ifname, const char* new)
-{
- struct ifreq ifr;
- int fd = socket(PF_PACKET, SOCK_DGRAM, 0);
-
- memset(&ifr, 0, sizeof(struct ifreq));
-
- if (virStrcpyStatic(ifr.ifr_name, ifname) == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- if (virStrcpyStatic(ifr.ifr_newname, new) == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- if (ioctl(fd, SIOCSIFNAME, &ifr))
- return -1;
-
- return 0;
-}
--- /dev/null
+/*
+ * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright IBM Corp. 2008
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Authors:
+ * David L. Leskovec <dlesko at linux.vnet.ibm.com>
+ * Daniel P. Berrange <berrange@redhat.com>
+ */
+
+#ifndef __VIR_NETDEV_VETH_H__
+# define __VIR_NETDEV_VETH_H__
+
+# include "internal.h"
+
+/* Function declarations */
+int virNetDevVethCreate(char **veth1, char **veth2)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
+int virNetDevVethDelete(const char *veth)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+
+#endif /* __VIR_NETDEV_VETH_H__ */