[ovs-dev] [PATCH 02/13] add minimal NetBSD support
Ben Pfaff
blp at nicira.com
Tue May 21 14:59:58 UTC 2013
On Tue, May 21, 2013 at 05:49:54PM +0900, yamt at mwd.biglobe.ne.jp wrote:
> From: YAMAMOTO Takashi <yamt at mwd.biglobe.ne.jp>
>
> mostly ride on the existing FreeBSD support.
>
> Signed-off-by: YAMAMOTO Takashi <yamt at mwd.biglobe.ne.jp>
I'd like to refine this patch a little in the following way (which is
followed by a full revised version). Ed and Yamamoto-san, are you happy
with this version?
diff --git a/configure.ac b/configure.ac
index fe3f9c7..1e23289 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,8 +61,10 @@ OVS_CHECK_IF_DL
OVS_CHECK_STRTOK_R
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec, struct stat.st_mtimensec],
[], [], [[#include <sys/stat.h>]])
+AC_CHECK_MEMBERS([struct ifreq.ifr_flagshigh], [], [], [[#include <net/if.h>]])
AC_CHECK_FUNCS([mlockall strnlen strsignal getloadavg statvfs getmntent_r])
-AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h])
+AC_CHECK_HEADERS(
+ [mntent.h sys/statvfs.h linux/types.h linux/if_ether.h net/if_mib.h])
OVS_CHECK_PKIDIR
OVS_CHECK_RUNDIR
diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index f33ed59..753a8e5 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 Gaetano Catalli.
+ * Copyright (c) 2011, 2013 Gaetano Catalli.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,9 +32,9 @@
#include <net/if_media.h>
#include <net/if_tap.h>
#include <netinet/in.h>
-#if defined(__FreeBSD__)
+#ifdef HAVE_NET_IF_MIB_H
#include <net/if_mib.h>
-#endif /* defined(__FreeBSD__) */
+#endif
#include <poll.h>
#include <string.h>
#include <unistd.h>
@@ -134,6 +134,9 @@ static int set_etheraddr(const char *netdev_name, int hwaddr_family,
int hwaddr_len, const uint8_t[ETH_ADDR_LEN]);
static int get_ifindex(const struct netdev *, int *ifindexp);
+static int ifr_get_flags(const struct ifreq *);
+static void ifr_set_flags(struct ifreq *, int flags);
+
static int netdev_bsd_init(void);
static bool
@@ -365,10 +368,7 @@ netdev_bsd_create_tap(const struct netdev_class *class, const char *name,
}
/* Turn device UP */
- ifr.ifr_flags = (uint16_t)IFF_UP;
-#if defined(__FreeBSD__)
- ifr.ifr_flagshigh = 0;
-#endif
+ ifr_set_flags(&ifr, IFF_UP);
strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
if (ioctl(af_inet_sock, SIOCSIFFLAGS, &ifr) == -1) {
error = errno;
@@ -831,7 +831,8 @@ netdev_bsd_get_carrier(const struct netdev *netdev_, bool *carrier)
/* Retrieves current device stats for 'netdev'. */
static int
-netdev_bsd_get_stats(const struct netdev *netdev_ __attribute__((__unused__)), struct netdev_stats *stats)
+netdev_bsd_get_stats(const struct netdev *netdev_ OVS_UNUSED,
+ struct netdev_stats *stats)
{
#if defined(__FreeBSD__)
int if_count, i;
@@ -1353,12 +1354,7 @@ get_flags(const struct netdev *netdev, int *flags)
error = netdev_bsd_do_ioctl(netdev->name, &ifr,
SIOCGIFFLAGS, "SIOCGIFFLAGS");
-#if defined(__FreeBSD__)
- *flags = 0xFFFF0000 & (ifr.ifr_flagshigh << 16);
-#else
- *flags = 0;
-#endif
- *flags |= 0x0000FFFF & ifr.ifr_flags;
+ *flags = ifr_get_flags(&ifr);
return error;
}
@@ -1368,10 +1364,7 @@ set_flags(const char *name, int flags)
{
struct ifreq ifr;
- ifr.ifr_flags = 0x0000FFFF & flags;
-#if defined(__FreeBSD__)
- ifr.ifr_flagshigh = (0xFFFF0000 & flags) >> 16;
-#endif
+ ifr_set_flags(&ifr, flags);
return netdev_bsd_do_ioctl(name, &ifr, SIOCSIFFLAGS, "SIOCSIFFLAGS");
}
@@ -1425,14 +1418,11 @@ get_etheraddr(const char *netdev_name, uint8_t ea[ETH_ADDR_LEN])
}
static int
-set_etheraddr(const char *netdev_name, int hwaddr_family,
- int hwaddr_len, const uint8_t mac[ETH_ADDR_LEN])
+set_etheraddr(const char *netdev_name OVS_UNUSED, int hwaddr_family OVS_UNUSED,
+ int hwaddr_len OVS_UNUSED,
+ const uint8_t mac[ETH_ADDR_LEN] OVS_UNUSED)
{
#if defined(__NetBSD__)
- (void)netdev_name;
- (void)hwaddr_family;
- (void)hwaddr_len;
- (void)mac;
return ENOTSUP; /* XXX */
#else
struct ifreq ifr;
@@ -1463,3 +1453,22 @@ netdev_bsd_do_ioctl(const char *name, struct ifreq *ifr, unsigned long cmd,
}
return 0;
}
+
+static int
+ifr_get_flags(const struct ifreq *ifr)
+{
+#ifdef HAVE_STRUCT_IFREQ_IFR_FLAGSHIGH
+ return (ifr.ifr_flagshigh << 16) | ifr.ifr_flags;
+#else
+ return ifr.ifr_flags;
+#endif
+}
+
+static void
+ifr_set_flags(struct ifreq *ifr, int flags)
+{
+ ifr->ifr_flags = flags;
+#ifdef HAVE_STRUCT_IFREQ_IFR_FLAGSHIGH
+ ifr->ifr_flagshigh = flags >> 16;
+#endif
+}
--8<--------------------------cut here-------------------------->8--
From: YAMAMOTO Takashi <yamt at mwd.biglobe.ne.jp>
Date: Tue, 21 May 2013 17:49:54 +0900
Subject: [PATCH] add minimal NetBSD support
mostly ride on the existing FreeBSD support.
Signed-off-by: YAMAMOTO Takashi <yamt at mwd.biglobe.ne.jp>
Signed-off-by: Ben Pfaff <blp at nicira.com>
---
configure.ac | 4 +++-
lib/command-line.c | 4 ++--
lib/command-line.h | 2 +-
lib/netdev-bsd.c | 64 +++++++++++++++++++++++++++++++++++++++++--------
lib/netdev-provider.h | 2 +-
lib/netdev.c | 2 +-
6 files changed, 62 insertions(+), 16 deletions(-)
diff --git a/configure.ac b/configure.ac
index fe3f9c7..1e23289 100644
--- a/configure.ac
+++ b/configure.ac
@@ -61,8 +61,10 @@ OVS_CHECK_IF_DL
OVS_CHECK_STRTOK_R
AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec, struct stat.st_mtimensec],
[], [], [[#include <sys/stat.h>]])
+AC_CHECK_MEMBERS([struct ifreq.ifr_flagshigh], [], [], [[#include <net/if.h>]])
AC_CHECK_FUNCS([mlockall strnlen strsignal getloadavg statvfs getmntent_r])
-AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h])
+AC_CHECK_HEADERS(
+ [mntent.h sys/statvfs.h linux/types.h linux/if_ether.h net/if_mib.h])
OVS_CHECK_PKIDIR
OVS_CHECK_RUNDIR
diff --git a/lib/command-line.c b/lib/command-line.c
index b881c04..70b1f4d 100644
--- a/lib/command-line.c
+++ b/lib/command-line.c
@@ -190,8 +190,8 @@ proctitle_init(int argc OVS_UNUSED, char **argv OVS_UNUSED)
{
}
-#ifndef __FreeBSD__
-/* On FreeBSD we #define this to setproctitle. */
+#if !(defined(__FreeBSD__) || defined(__NetBSD__))
+/* On these platforms we #define this to setproctitle. */
void
proctitle_set(const char *format OVS_UNUSED, ...)
{
diff --git a/lib/command-line.h b/lib/command-line.h
index 2592b79..bb12f72 100644
--- a/lib/command-line.h
+++ b/lib/command-line.h
@@ -34,7 +34,7 @@ char *long_options_to_short_options(const struct option *options);
void run_command(int argc, char *argv[], const struct command[]);
void proctitle_init(int argc, char **argv);
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__NetBSD__)
#define proctitle_set setproctitle
#else
void proctitle_set(const char *, ...)
diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index ca43d07e..753a8e5 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 Gaetano Catalli.
+ * Copyright (c) 2011, 2013 Gaetano Catalli.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,9 @@
#include <net/if_media.h>
#include <net/if_tap.h>
#include <netinet/in.h>
+#ifdef HAVE_NET_IF_MIB_H
#include <net/if_mib.h>
+#endif
#include <poll.h>
#include <string.h>
#include <unistd.h>
@@ -132,6 +134,9 @@ static int set_etheraddr(const char *netdev_name, int hwaddr_family,
int hwaddr_len, const uint8_t[ETH_ADDR_LEN]);
static int get_ifindex(const struct netdev *, int *ifindexp);
+static int ifr_get_flags(const struct ifreq *);
+static void ifr_set_flags(struct ifreq *, int flags);
+
static int netdev_bsd_init(void);
static bool
@@ -339,12 +344,21 @@ netdev_bsd_create_tap(const struct netdev_class *class, const char *name,
}
/* Change the name of the tap device */
+#if defined(SIOCSIFNAME)
ifr.ifr_data = (void *)name;
if (ioctl(af_inet_sock, SIOCSIFNAME, &ifr) == -1) {
error = errno;
destroy_tap(netdev->tap_fd, ifr.ifr_name);
goto error_undef_notifier;
}
+#else
+ /*
+ * XXX
+ * NetBSD doesn't support inteface renaming.
+ */
+ VLOG_INFO("tap %s is created for bridge %s", ifr.ifr_name, name);
+ name = ifr.ifr_name; /* XXX */
+#endif
/* set non-blocking. */
error = set_nonblocking(netdev->tap_fd);
@@ -354,8 +368,7 @@ netdev_bsd_create_tap(const struct netdev_class *class, const char *name,
}
/* Turn device UP */
- ifr.ifr_flags = (uint16_t)IFF_UP;
- ifr.ifr_flagshigh = 0;
+ ifr_set_flags(&ifr, IFF_UP);
strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
if (ioctl(af_inet_sock, SIOCSIFFLAGS, &ifr) == -1) {
error = errno;
@@ -818,8 +831,10 @@ netdev_bsd_get_carrier(const struct netdev *netdev_, bool *carrier)
/* Retrieves current device stats for 'netdev'. */
static int
-netdev_bsd_get_stats(const struct netdev *netdev_, struct netdev_stats *stats)
+netdev_bsd_get_stats(const struct netdev *netdev_ OVS_UNUSED,
+ struct netdev_stats *stats)
{
+#if defined(__FreeBSD__)
int if_count, i;
int mib[6];
size_t len;
@@ -878,6 +893,11 @@ netdev_bsd_get_stats(const struct netdev *netdev_, struct netdev_stats *stats)
}
return 0;
+#else
+ /* XXXnotyet */
+ memset(stats, 0, sizeof(*stats));
+ return 0;
+#endif
}
static uint32_t
@@ -1149,7 +1169,9 @@ nd_to_iff_flags(enum netdev_flags nd)
}
if (nd & NETDEV_PROMISC) {
iff |= IFF_PROMISC;
+#if defined(IFF_PPROMISC)
iff |= IFF_PPROMISC;
+#endif
}
return iff;
}
@@ -1332,8 +1354,7 @@ get_flags(const struct netdev *netdev, int *flags)
error = netdev_bsd_do_ioctl(netdev->name, &ifr,
SIOCGIFFLAGS, "SIOCGIFFLAGS");
- *flags = 0xFFFF0000 & (ifr.ifr_flagshigh << 16);
- *flags |= 0x0000FFFF & ifr.ifr_flags;
+ *flags = ifr_get_flags(&ifr);
return error;
}
@@ -1343,8 +1364,7 @@ set_flags(const char *name, int flags)
{
struct ifreq ifr;
- ifr.ifr_flags = 0x0000FFFF & flags;
- ifr.ifr_flagshigh = (0xFFFF0000 & flags) >> 16;
+ ifr_set_flags(&ifr, flags);
return netdev_bsd_do_ioctl(name, &ifr, SIOCSIFFLAGS, "SIOCSIFFLAGS");
}
@@ -1398,9 +1418,13 @@ get_etheraddr(const char *netdev_name, uint8_t ea[ETH_ADDR_LEN])
}
static int
-set_etheraddr(const char *netdev_name, int hwaddr_family,
- int hwaddr_len, const uint8_t mac[ETH_ADDR_LEN])
+set_etheraddr(const char *netdev_name OVS_UNUSED, int hwaddr_family OVS_UNUSED,
+ int hwaddr_len OVS_UNUSED,
+ const uint8_t mac[ETH_ADDR_LEN] OVS_UNUSED)
{
+#if defined(__NetBSD__)
+ return ENOTSUP; /* XXX */
+#else
struct ifreq ifr;
memset(&ifr, 0, sizeof ifr);
@@ -1414,6 +1438,7 @@ set_etheraddr(const char *netdev_name, int hwaddr_family,
return errno;
}
return 0;
+#endif
}
static int
@@ -1428,3 +1453,22 @@ netdev_bsd_do_ioctl(const char *name, struct ifreq *ifr, unsigned long cmd,
}
return 0;
}
+
+static int
+ifr_get_flags(const struct ifreq *ifr)
+{
+#ifdef HAVE_STRUCT_IFREQ_IFR_FLAGSHIGH
+ return (ifr.ifr_flagshigh << 16) | ifr.ifr_flags;
+#else
+ return ifr.ifr_flags;
+#endif
+}
+
+static void
+ifr_set_flags(struct ifreq *ifr, int flags)
+{
+ ifr->ifr_flags = flags;
+#ifdef HAVE_STRUCT_IFREQ_IFR_FLAGSHIGH
+ ifr->ifr_flagshigh = flags >> 16;
+#endif
+}
diff --git a/lib/netdev-provider.h b/lib/netdev-provider.h
index a9de2ad..2d43431 100644
--- a/lib/netdev-provider.h
+++ b/lib/netdev-provider.h
@@ -575,7 +575,7 @@ const struct netdev_class *netdev_lookup_provider(const char *type);
extern const struct netdev_class netdev_linux_class;
extern const struct netdev_class netdev_internal_class;
extern const struct netdev_class netdev_tap_class;
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__NetBSD__)
extern const struct netdev_class netdev_bsd_class;
#endif
diff --git a/lib/netdev.c b/lib/netdev.c
index 5c2e9f5..3340ab5 100644
--- a/lib/netdev.c
+++ b/lib/netdev.c
@@ -85,7 +85,7 @@ netdev_initialize(void)
netdev_register_provider(&netdev_tap_class);
netdev_vport_tunnel_register();
#endif
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__NetBSD__)
netdev_register_provider(&netdev_tap_class);
netdev_register_provider(&netdev_bsd_class);
#endif
--
1.7.10.4
More information about the dev
mailing list