[libvirt] [PATCH 1/4] FreeBSD: implement virNetDevExists() and virNetDevSetName()
John Ferlan
jferlan at redhat.com
Mon Jan 7 15:03:32 UTC 2013
Not a "regular reviewer" (yet), but I figured I'd give this series a
look and provide some feedback...
On 01/04/2013 10:00 AM, Roman Bogorodskiy wrote:
> ---
> src/util/virnetdev.c | 37 ++++++++++++++++++++++++++++++++++---
> 1 file changed, 34 insertions(+), 3 deletions(-)
>
> diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
> index 7ffd3c2..c7eeb50 100644
> --- a/src/util/virnetdev.c
> +++ b/src/util/virnetdev.c
> @@ -83,10 +83,32 @@ static int virNetDevSetupControl(const char *ifname,
> {
> return virNetDevSetupControlFull(ifname, ifr, AF_PACKET, SOCK_DGRAM);
> }
> -#endif
> +#elif defined(__FreeBSD__)
> +static int virNetDevSetupControl(const char *ifname,
> + struct ifreq *ifr)
> +{
Why not use virNetDevSetupControlFull() passing AF_LOCAL, SOCK_DGRAM?
Does the virSetInherit() not apply for FreeBSD?
> + int s;
>
> + memset(ifr, 0, sizeof(*ifr));
>
> -#if defined(SIOCGIFFLAGS) && defined(HAVE_STRUCT_IFREQ)
> + if (virStrcpyStatic(ifr->ifr_name, ifname) == NULL) {
> + virReportSystemError(ERANGE,
> + _("Network interface name '%s' is too long"),
> + ifname);
> + return -1;
> + }
> +
> + if ((s = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
> + virReportSystemError(errno, "%s",
> + _("Cannot open network interface control socket"));
> + return -1;
> + }
> +
> + return s;
> +}
> +#endif
> +
> +#if defined(SIOCGIFFLAGS) && (defined(HAVE_STRUCT_IFREQ) || defined(__FreeBSD__))
> /**
> * virNetDevExists:
> * @ifname
> @@ -105,7 +127,12 @@ int virNetDevExists(const char *ifname)
> return -1;
>
> if (ioctl(fd, SIOCGIFFLAGS, &ifr)) {
> + /* FreeBSD throws ENXIO when interface doesn't exist */
> +#if defined(__FreeBSD__)
> + if (errno == ENXIO)
> +#else
> if (errno == ENODEV)
> +#endif
> ret = 0;
> else
> virReportSystemError(errno,
> @@ -459,7 +486,7 @@ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs)
> return rc;
> }
>
> -#if defined(SIOCSIFNAME) && defined(HAVE_STRUCT_IFREQ)
> +#if defined(SIOCSIFNAME) && (defined(HAVE_STRUCT_IFREQ) || defined(__FreeBSD__))
> /**
> * virNetDevSetName:
> * @ifname: name of device
> @@ -478,12 +505,16 @@ int virNetDevSetName(const char* ifname, const char *newifname)
> if ((fd = virNetDevSetupControl(ifname, &ifr)) < 0)
> return -1;
>
> +#if defined(__FreeBSD__)
> + ifr.ifr_data = newifname;
> +#else
> if (virStrcpyStatic(ifr.ifr_newname, newifname) == NULL) {
> virReportSystemError(ERANGE,
> _("Network interface name '%s' is too long"),
> newifname);
> goto cleanup;
> }
> +#endif
>
> if (ioctl(fd, SIOCSIFNAME, &ifr)) {
> virReportSystemError(errno,
>
More information about the libvir-list
mailing list