From: YAMAMOTO Takashi <y...@mwd.biglobe.ne.jp> mostly ride on the existing FreeBSD support.
Signed-off-by: YAMAMOTO Takashi <y...@mwd.biglobe.ne.jp> --- lib/command-line.c | 4 ++-- lib/command-line.h | 2 +- lib/netdev-bsd.c | 37 ++++++++++++++++++++++++++++++++++++- lib/netdev-provider.h | 2 +- lib/netdev.c | 2 +- 5 files changed, 41 insertions(+), 6 deletions(-) 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 ca43d07..f33ed59 100644 --- a/lib/netdev-bsd.c +++ b/lib/netdev-bsd.c @@ -32,7 +32,9 @@ #include <net/if_media.h> #include <net/if_tap.h> #include <netinet/in.h> +#if defined(__FreeBSD__) #include <net/if_mib.h> +#endif /* defined(__FreeBSD__) */ #include <poll.h> #include <string.h> #include <unistd.h> @@ -339,12 +341,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); @@ -355,7 +366,9 @@ 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 strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); if (ioctl(af_inet_sock, SIOCSIFFLAGS, &ifr) == -1) { error = errno; @@ -818,8 +831,9 @@ 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_ __attribute__((__unused__)), struct netdev_stats *stats) { +#if defined(__FreeBSD__) int if_count, i; int mib[6]; size_t len; @@ -878,6 +892,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 +1168,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,7 +1353,11 @@ 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; return error; @@ -1344,7 +1369,9 @@ 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 return netdev_bsd_do_ioctl(name, &ifr, SIOCSIFFLAGS, "SIOCSIFFLAGS"); } @@ -1401,6 +1428,13 @@ static int set_etheraddr(const char *netdev_name, int hwaddr_family, int hwaddr_len, const uint8_t mac[ETH_ADDR_LEN]) { +#if defined(__NetBSD__) + (void)netdev_name; + (void)hwaddr_family; + (void)hwaddr_len; + (void)mac; + return ENOTSUP; /* XXX */ +#else struct ifreq ifr; memset(&ifr, 0, sizeof ifr); @@ -1414,6 +1448,7 @@ set_etheraddr(const char *netdev_name, int hwaddr_family, return errno; } return 0; +#endif } static int 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.8.0.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev