[libvirt] [PATCH v3] BSD: implement virNetDev(Set|Clear)IPv4Address

Provide an implementation of virNetDev(Set|Clear)IPv4Address based on BSD ifconfig tool in addition to 'ip' from Linux iproute2 package. --- configure.ac | 15 +++++++++++++++ src/util/virnetdev.c | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/configure.ac b/configure.ac index cc2213d..7667430 100644 --- a/configure.ac +++ b/configure.ac @@ -387,6 +387,10 @@ if test "$prefix" = "/usr" && test "$sysconfdir" = '${prefix}/etc' ; then sysconfdir='/etc' fi +dnl Specify if we rely on ifconfig instead of iproute2 (e.g. in case +dnl we're working on BSD) +want_ifconfig=no + dnl Make some notes about which OS we're compiling for, as the lxc and qemu dnl drivers require linux headers, and storage_mpath, dtrace, and nwfilter dnl are also linux specific. The "network" and storage_fs drivers are known @@ -409,6 +413,8 @@ if test $with_linux = no; then fi if test $with_freebsd = yes; then + want_ifconfig=yes + with_firewalld=no fi @@ -2429,6 +2435,15 @@ AC_CHECK_DECLS([BRDGSFD, BRDGADD, BRDGDEL], #include <net/if_bridgevar.h> ]) +# Check if we need to look for ifconfig +if test "$want_ifconfig" = "yes"; then + AC_PATH_PROG([IFCONFIG_PATH], [ifconfig]) + if test -z "$IFCONFIG_PATH"; then + AC_MSG_ERROR([Failed to find ifconfig.]) + fi + AC_DEFINE_UNQUOTED([IFCONFIG_PATH], "$IFCONFIG_PATH", [path to ifconfig binary]) +fi + # Detect when running under the clang static analyzer's scan-build driver # or Coverity-prevent's cov-build. Define STATIC_ANALYSIS accordingly. AC_CACHE_CHECK([whether this build is done by a static analysis tool], diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 30df7a6..8eb4d4c 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -810,12 +810,25 @@ int virNetDevSetIPv4Address(const char *ifname, !(bcaststr = virSocketAddrFormat(&broadcast)))) { goto cleanup; } +#ifdef IFCONFIG_PATH + cmd = virCommandNew(IFCONFIG_PATH); + virCommandAddArg(cmd, ifname); + if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET6)) + virCommandAddArg(cmd, "inet6"); + else + virCommandAddArg(cmd, "inet"); + virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix); + if (bcaststr) + virCommandAddArgList(cmd, "broadcast", bcaststr, NULL); + virCommandAddArg(cmd, "alias"); +#else cmd = virCommandNew(IP_PATH); virCommandAddArgList(cmd, "addr", "add", NULL); virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix); if (bcaststr) virCommandAddArgList(cmd, "broadcast", bcaststr, NULL); virCommandAddArgList(cmd, "dev", ifname, NULL); +#endif if (virCommandRun(cmd, NULL) < 0) goto cleanup; @@ -895,10 +908,21 @@ int virNetDevClearIPv4Address(const char *ifname, if (!(addrstr = virSocketAddrFormat(addr))) goto cleanup; +#ifdef IFCONFIG_PATH + cmd = virCommandNew(IFCONFIG_PATH); + virCommandAddArg(cmd, ifname); + if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET6)) + virCommandAddArg(cmd, "inet6"); + else + virCommandAddArg(cmd, "inet"); + virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix); + virCommandAddArg(cmd, "-alias"); +#else cmd = virCommandNew(IP_PATH); virCommandAddArgList(cmd, "addr", "del", NULL); virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix); virCommandAddArgList(cmd, "dev", ifname, NULL); +#endif if (virCommandRun(cmd, NULL) < 0) goto cleanup; -- 1.8.2.3

Roman Bogorodskiy wrote:
Provide an implementation of virNetDev(Set|Clear)IPv4Address based on BSD ifconfig tool in addition to 'ip' from Linux iproute2 package. --- configure.ac | 15 +++++++++++++++ src/util/virnetdev.c | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
ping? Roman Bogorodskiy

On 08/11/2013 07:54 AM, Roman Bogorodskiy wrote:
Provide an implementation of virNetDev(Set|Clear)IPv4Address based on BSD ifconfig tool in addition to 'ip' from Linux iproute2 package. --- configure.ac | 15 +++++++++++++++ src/util/virnetdev.c | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
if test $with_freebsd = yes; then + want_ifconfig=yes + with_firewalld=no fi
@@ -2429,6 +2435,15 @@ AC_CHECK_DECLS([BRDGSFD, BRDGADD, BRDGDEL], #include <net/if_bridgevar.h> ])
+# Check if we need to look for ifconfig +if test "$want_ifconfig" = "yes"; then + AC_PATH_PROG([IFCONFIG_PATH], [ifconfig]) + if test -z "$IFCONFIG_PATH"; then + AC_MSG_ERROR([Failed to find ifconfig.])
This means that configure will fail if ifconfig is not installed but want_ifconfig was set. Are you certain enough that FreeBSD is likely to have ifconfig by default, and thus not hit this failure except on extremely unlikely configurations? But I think it looks simple enough, with minimal risk of causing grief on non-BSD systems (the configure check is guarded, so IFCONFIG_PATH is likely to be unset on other platforms). ACK and pushed. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Eric Blake wrote:
On 08/11/2013 07:54 AM, Roman Bogorodskiy wrote:
Provide an implementation of virNetDev(Set|Clear)IPv4Address based on BSD ifconfig tool in addition to 'ip' from Linux iproute2 package. --- configure.ac | 15 +++++++++++++++ src/util/virnetdev.c | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
if test $with_freebsd = yes; then + want_ifconfig=yes + with_firewalld=no fi
@@ -2429,6 +2435,15 @@ AC_CHECK_DECLS([BRDGSFD, BRDGADD, BRDGDEL], #include <net/if_bridgevar.h> ])
+# Check if we need to look for ifconfig +if test "$want_ifconfig" = "yes"; then + AC_PATH_PROG([IFCONFIG_PATH], [ifconfig]) + if test -z "$IFCONFIG_PATH"; then + AC_MSG_ERROR([Failed to find ifconfig.])
This means that configure will fail if ifconfig is not installed but want_ifconfig was set. Are you certain enough that FreeBSD is likely to have ifconfig by default, and thus not hit this failure except on extremely unlikely configurations?
ifconfig is a part of FreeBSD base system. And appears it's not even possible to disable installing it via make.conf [1]. So I doubt there are a lot of systems without ifconfig, and even if they exist I'm not sure we need to support them because, as you said, it's extremely unlikely configuration. 1: http://www.freebsd.org/cgi/man.cgi?query=make.conf&sektion=5
But I think it looks simple enough, with minimal risk of causing grief on non-BSD systems (the configure check is guarded, so IFCONFIG_PATH is likely to be unset on other platforms). ACK and pushed.
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Roman Bogorodskiy

Roman Bogorodskiy wrote:
Eric Blake wrote:
On 08/11/2013 07:54 AM, Roman Bogorodskiy wrote:
Provide an implementation of virNetDev(Set|Clear)IPv4Address based on BSD ifconfig tool in addition to 'ip' from Linux iproute2 package. --- configure.ac | 15 +++++++++++++++ src/util/virnetdev.c | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+)
if test $with_freebsd = yes; then + want_ifconfig=yes + with_firewalld=no fi
@@ -2429,6 +2435,15 @@ AC_CHECK_DECLS([BRDGSFD, BRDGADD, BRDGDEL], #include <net/if_bridgevar.h> ])
+# Check if we need to look for ifconfig +if test "$want_ifconfig" = "yes"; then + AC_PATH_PROG([IFCONFIG_PATH], [ifconfig]) + if test -z "$IFCONFIG_PATH"; then + AC_MSG_ERROR([Failed to find ifconfig.])
This means that configure will fail if ifconfig is not installed but want_ifconfig was set. Are you certain enough that FreeBSD is likely to have ifconfig by default, and thus not hit this failure except on extremely unlikely configurations?
ifconfig is a part of FreeBSD base system. And appears it's not even possible to disable installing it via make.conf [1]. So I doubt there are a lot of systems without ifconfig, and even if they exist I'm not sure we need to support them because, as you said, it's extremely unlikely configuration.
1: http://www.freebsd.org/cgi/man.cgi?query=make.conf&sektion=5
One correction: The proper man would be: http://www.freebsd.org/cgi/man.cgi?query=src.conf It's possible to build using WITHOUT_INET to disable IPv4 networking, but again, I doubt that we should support such systems. Roman Bogorodskiy
participants (2)
-
Eric Blake
-
Roman Bogorodskiy