mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 03:21:19 +00:00
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.
This commit is contained in:
parent
4d1cf65a8c
commit
3f0d2ee95b
15
configure.ac
15
configure.ac
@ -386,6 +386,10 @@ if test "$prefix" = "/usr" && test "$sysconfdir" = '${prefix}/etc' ; then
|
|||||||
sysconfdir='/etc'
|
sysconfdir='/etc'
|
||||||
fi
|
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 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 drivers require linux headers, and storage_mpath, dtrace, and nwfilter
|
||||||
dnl are also linux specific. The "network" and storage_fs drivers are known
|
dnl are also linux specific. The "network" and storage_fs drivers are known
|
||||||
@ -408,6 +412,8 @@ if test $with_linux = no; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if test $with_freebsd = yes; then
|
if test $with_freebsd = yes; then
|
||||||
|
want_ifconfig=yes
|
||||||
|
|
||||||
with_firewalld=no
|
with_firewalld=no
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -2472,6 +2478,15 @@ AC_CHECK_DECLS([BRDGSFD, BRDGADD, BRDGDEL],
|
|||||||
#include <net/if_bridgevar.h>
|
#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
|
# Detect when running under the clang static analyzer's scan-build driver
|
||||||
# or Coverity-prevent's cov-build. Define STATIC_ANALYSIS accordingly.
|
# or Coverity-prevent's cov-build. Define STATIC_ANALYSIS accordingly.
|
||||||
AC_CACHE_CHECK([whether this build is done by a static analysis tool],
|
AC_CACHE_CHECK([whether this build is done by a static analysis tool],
|
||||||
|
@ -810,12 +810,25 @@ int virNetDevSetIPv4Address(const char *ifname,
|
|||||||
!(bcaststr = virSocketAddrFormat(&broadcast)))) {
|
!(bcaststr = virSocketAddrFormat(&broadcast)))) {
|
||||||
goto cleanup;
|
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);
|
cmd = virCommandNew(IP_PATH);
|
||||||
virCommandAddArgList(cmd, "addr", "add", NULL);
|
virCommandAddArgList(cmd, "addr", "add", NULL);
|
||||||
virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
|
virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
|
||||||
if (bcaststr)
|
if (bcaststr)
|
||||||
virCommandAddArgList(cmd, "broadcast", bcaststr, NULL);
|
virCommandAddArgList(cmd, "broadcast", bcaststr, NULL);
|
||||||
virCommandAddArgList(cmd, "dev", ifname, NULL);
|
virCommandAddArgList(cmd, "dev", ifname, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -895,10 +908,21 @@ int virNetDevClearIPv4Address(const char *ifname,
|
|||||||
|
|
||||||
if (!(addrstr = virSocketAddrFormat(addr)))
|
if (!(addrstr = virSocketAddrFormat(addr)))
|
||||||
goto cleanup;
|
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);
|
cmd = virCommandNew(IP_PATH);
|
||||||
virCommandAddArgList(cmd, "addr", "del", NULL);
|
virCommandAddArgList(cmd, "addr", "del", NULL);
|
||||||
virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
|
virCommandAddArgFormat(cmd, "%s/%u", addrstr, prefix);
|
||||||
virCommandAddArgList(cmd, "dev", ifname, NULL);
|
virCommandAddArgList(cmd, "dev", ifname, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
Loading…
Reference in New Issue
Block a user