[ovs-dev] [PATCH 02/18] deal with platforms where backtrace() is in a different library than libc.

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

execinfo for NetBSD and ubacktrace for uClibc.
i don't know if the latter is relevant to Open vSwitch, though.

Signed-off-by: YAMAMOTO Takashi 
---
 m4/openvswitch.m4 | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/m4/openvswitch.m4 b/m4/openvswitch.m4
index 59cc933..189cbf6 100644
--- a/m4/openvswitch.m4
+++ b/m4/openvswitch.m4
@@ -168,10 +168,9 @@ AC_DEFUN([OVS_CHECK_DBDIR],
  [DBDIR='${sysconfdir}/${PACKAGE}'])
AC_SUBST([DBDIR])])
 
-dnl Defines HAVE_BACKTRACE if backtrace() is declared in 
-dnl and exists in libc.
+dnl Defines HAVE_BACKTRACE if backtrace() is found.
 AC_DEFUN([OVS_CHECK_BACKTRACE],
-  [AC_CHECK_HEADER([execinfo.h], [AC_CHECK_FUNCS([backtrace])])])
+  [AC_SEARCH_LIBS([backtrace], [execinfo ubacktrace])])
 
 dnl Checks for __malloc_hook, etc., supported by glibc.
 AC_DEFUN([OVS_CHECK_MALLOC_HOOKS],
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 15/18] implement set_etheraddr for NetBSD

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

Signed-off-by: YAMAMOTO Takashi 
---
 lib/netdev-bsd.c | 76 ++--
 1 file changed, 69 insertions(+), 7 deletions(-)

diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index 76782ec..615a26f 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -1494,13 +1494,7 @@ 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
+#if defined(__FreeBSD__)
 struct ifreq ifr;
 
 memset(&ifr, 0, sizeof ifr);
@@ -1514,6 +1508,74 @@ set_etheraddr(const char *netdev_name, int hwaddr_family,
 return errno;
 }
 return 0;
+#elif defined(__NetBSD__)
+struct if_laddrreq req;
+struct sockaddr_dl *sdl;
+struct sockaddr_storage oldaddr;
+int ret;
+int s;
+
+/*
+ * get the old address, add new one, and then remove old one.
+ */
+
+if (hwaddr_len != ETH_ADDR_LEN) {
+/* just to be safe about sockaddr storage size */
+return ENOTSUP;
+}
+s = socket(AF_LINK, SOCK_DGRAM, 0);
+if (s == -1) {
+return errno;
+}
+memset(&req, 0, sizeof(req));
+strncpy(req.iflr_name, netdev_name, sizeof(req.iflr_name));
+req.addr.ss_len = sizeof(req.addr);
+req.addr.ss_family = hwaddr_family;
+sdl = (struct sockaddr_dl *)&req.addr;
+sdl->sdl_alen = hwaddr_len;
+ret = ioctl(s, SIOCGLIFADDR, &req);
+if (ret == -1) {
+int saved_errno = errno;
+
+close(s);
+return saved_errno;
+}
+if (!memcmp(&sdl->sdl_data[sdl->sdl_nlen], mac, hwaddr_len)) {
+close(s);
+return 0;
+}
+oldaddr = req.addr;
+
+memset(&req, 0, sizeof(req));
+strncpy(req.iflr_name, netdev_name, sizeof(req.iflr_name));
+req.flags = IFLR_ACTIVE;
+sdl = (struct sockaddr_dl *)&req.addr;
+sdl->sdl_len = offsetof(struct sockaddr_dl, sdl_data) + hwaddr_len;
+sdl->sdl_alen = hwaddr_len;
+sdl->sdl_family = hwaddr_family;
+memcpy(sdl->sdl_data, mac, hwaddr_len);
+ret = ioctl(s, SIOCALIFADDR, &req);
+if (ret == -1) {
+int saved_errno = errno;
+
+close(s);
+return saved_errno;
+}
+
+memset(&req, 0, sizeof(req));
+strncpy(req.iflr_name, netdev_name, sizeof(req.iflr_name));
+req.addr = oldaddr;
+ret = ioctl(s, SIOCDLIFADDR, &req);
+if (ret == -1) {
+int saved_errno = errno;
+
+close(s);
+return saved_errno;
+}
+close(s);
+return 0;
+#else
+#error not implemented
 #endif
 }
 
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 09/18] be compilable even when _SC_PHYS_PAGES is not available.

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

Signed-off-by: YAMAMOTO Takashi 
---
 vswitchd/system-stats.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/vswitchd/system-stats.c b/vswitchd/system-stats.c
index f679516..2e18b1b 100644
--- a/vswitchd/system-stats.c
+++ b/vswitchd/system-stats.c
@@ -97,7 +97,11 @@ get_memory_stats(struct smap *stats)
 {
 if (!LINUX_DATAPATH) {
 unsigned int pagesize = get_page_size();
+#ifdef _SC_PHYS_PAGES
 long int phys_pages = sysconf(_SC_PHYS_PAGES);
+#else
+long int phys_pages = 0;
+#endif
 #ifdef _SC_AVPHYS_PAGES
 long int avphys_pages = sysconf(_SC_AVPHYS_PAGES);
 #else
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 01/18] fix an obvious mistake in a test of IFM_ETHER

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

a bug fix in FreeBSD code.

Signed-off-by: YAMAMOTO Takashi 
---
 lib/netdev-bsd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index f46eee8..24facbb 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -1037,7 +1037,7 @@ netdev_bsd_get_features(const struct netdev *netdev,
 media_list = xcalloc(ifmr.ifm_count, sizeof(int));
 ifmr.ifm_ulist = media_list;
 
-if (!IFM_TYPE(ifmr.ifm_current) & IFM_ETHER) {
+if (!(IFM_TYPE(ifmr.ifm_current) & IFM_ETHER)) {
 VLOG_DBG_RL(&rl, "%s: doesn't appear to be ethernet",
 netdev_get_name(netdev));
 error = EINVAL;
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 11/18] include some headers to satisfy header file dependencies on NetBSD-6.

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

while this change don't seem to be necessary on NetBSD-current,
NetBSD-6 is the latest release at this point.

Signed-off-by: YAMAMOTO Takashi 
---
 lib/route-table.h | 1 +
 lib/socket-util.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/lib/route-table.h b/lib/route-table.h
index 804cb3f..6403b6d 100644
--- a/lib/route-table.h
+++ b/lib/route-table.h
@@ -17,6 +17,7 @@
 #ifndef ROUTE_TABLE_H
 #define ROUTE_TABLE_H 1
 
+#include 
 #include 
 #include 
 #include 
diff --git a/lib/socket-util.h b/lib/socket-util.h
index 5bf8529..96aad5d 100644
--- a/lib/socket-util.h
+++ b/lib/socket-util.h
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include "openvswitch/types.h"
+#include 
 #include 
 
 int set_nonblocking(int fd);
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 03/18] add ax_check_openssl.m4

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

this file is obtained from:
http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_check_openssl.m4;hb=5a7260331c7d13263126e35c5743fdc35cbc2894

Signed-off-by: YAMAMOTO Takashi 
---
 m4/ax_check_openssl.m4 | 124 +
 1 file changed, 124 insertions(+)
 create mode 100644 m4/ax_check_openssl.m4

diff --git a/m4/ax_check_openssl.m4 b/m4/ax_check_openssl.m4
new file mode 100644
index 000..a87c5a6
--- /dev/null
+++ b/m4/ax_check_openssl.m4
@@ -0,0 +1,124 @@
+# ===
+# http://www.gnu.org/software/autoconf-archive/ax_check_openssl.html
+# ===
+#
+# SYNOPSIS
+#
+#   AX_CHECK_OPENSSL([action-if-found[, action-if-not-found]])
+#
+# DESCRIPTION
+#
+#   Look for OpenSSL in a number of default spots, or in a user-selected
+#   spot (via --with-openssl).  Sets
+#
+# OPENSSL_INCLUDES to the include directives required
+# OPENSSL_LIBS to the -l directives required
+# OPENSSL_LDFLAGS to the -L or -R flags required
+#
+#   and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
+#
+#   This macro sets OPENSSL_INCLUDES such that source files should use the
+#   openssl/ directory in include directives:
+#
+# #include 
+#
+# LICENSE
+#
+#   Copyright (c) 2009,2010 Zmanda Inc. 
+#   Copyright (c) 2009,2010 Dustin J. Mitchell 
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved. This file is offered as-is, without any
+#   warranty.
+
+#serial 8
+
+AU_ALIAS([CHECK_SSL], [AX_CHECK_OPENSSL])
+AC_DEFUN([AX_CHECK_OPENSSL], [
+found=false
+AC_ARG_WITH([openssl],
+[AS_HELP_STRING([--with-openssl=DIR],
+[root of the OpenSSL directory])],
+[
+case "$withval" in
+"" | y | ye | yes | n | no)
+AC_MSG_ERROR([Invalid --with-openssl value])
+  ;;
+*) ssldirs="$withval"
+  ;;
+esac
+], [
+# if pkg-config is installed and openssl has installed a .pc file,
+# then use that information and don't search ssldirs
+AC_PATH_PROG([PKG_CONFIG], [pkg-config])
+if test x"$PKG_CONFIG" != x""; then
+OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
+if test $? = 0; then
+OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 
2>/dev/null`
+OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 
2>/dev/null`
+found=true
+fi
+fi
+
+# no such luck; use some default ssldirs
+if ! $found; then
+ssldirs="/usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg 
/usr/local /usr"
+fi
+]
+)
+
+
+# note that we #include , so the OpenSSL headers have to be 
in
+# an 'openssl' subdirectory
+
+if ! $found; then
+OPENSSL_INCLUDES=
+for ssldir in $ssldirs; do
+AC_MSG_CHECKING([for openssl/ssl.h in $ssldir])
+if test -f "$ssldir/include/openssl/ssl.h"; then
+OPENSSL_INCLUDES="-I$ssldir/include"
+OPENSSL_LDFLAGS="-L$ssldir/lib"
+OPENSSL_LIBS="-lssl -lcrypto"
+found=true
+AC_MSG_RESULT([yes])
+break
+else
+AC_MSG_RESULT([no])
+fi
+done
+
+# if the file wasn't found, well, go ahead and try the link anyway -- 
maybe
+# it will just work!
+fi
+
+# try the preprocessor and linker with our new flags,
+# being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
+
+AC_MSG_CHECKING([whether compiling and linking against OpenSSL works])
+echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \
+"OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" 
>&AS_MESSAGE_LOG_FD
+
+save_LIBS="$LIBS"
+save_LDFLAGS="$LDFLAGS"
+save_CPPFLAGS="$CPPFLAGS"
+LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
+LIBS="$OPENSSL_LIBS $LIBS"
+CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS"
+AC_LINK_IFELSE(
+[AC_LANG_PROGRAM([#include ], [SSL_new(NULL)])],
+[
+AC_MSG_RESULT([yes])
+$1
+], [
+AC_MSG_RESULT([no])
+$2
+])
+CPPFLAGS="$save_CPPFLAGS"
+LDFLAGS="$save_LDFLAGS"
+LIBS="$save_LIBS"
+
+AC_SUBST([OPENSSL_INCLUDES])
+AC_SUBST([OPENSSL_LIBS])
+AC_SUBST([OPENSSL_LDFLAGS])
+])
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 04/18] use ax_check_openssl.m4 instead of a direct use of pkg-config.

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

on some platforms, including NetBSD-6, openssl is available but
its pkg-config files (*.pc) are not.

Signed-off-by: YAMAMOTO Takashi 
---
 m4/ax_check_openssl.m4 | 38 +++---
 m4/openvswitch.m4  |  3 +--
 2 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/m4/ax_check_openssl.m4 b/m4/ax_check_openssl.m4
index a87c5a6..2d543e6 100644
--- a/m4/ax_check_openssl.m4
+++ b/m4/ax_check_openssl.m4
@@ -11,13 +11,13 @@
 #   Look for OpenSSL in a number of default spots, or in a user-selected
 #   spot (via --with-openssl).  Sets
 #
-# OPENSSL_INCLUDES to the include directives required
-# OPENSSL_LIBS to the -l directives required
-# OPENSSL_LDFLAGS to the -L or -R flags required
+# SSL_INCLUDES to the include directives required
+# SSL_LIBS to the -l directives required
+# SSL_LDFLAGS to the -L or -R flags required
 #
 #   and calls ACTION-IF-FOUND or ACTION-IF-NOT-FOUND appropriately
 #
-#   This macro sets OPENSSL_INCLUDES such that source files should use the
+#   This macro sets SSL_INCLUDES such that source files should use the
 #   openssl/ directory in include directives:
 #
 # #include 
@@ -53,10 +53,10 @@ AC_DEFUN([AX_CHECK_OPENSSL], [
 # then use that information and don't search ssldirs
 AC_PATH_PROG([PKG_CONFIG], [pkg-config])
 if test x"$PKG_CONFIG" != x""; then
-OPENSSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
+SSL_LDFLAGS=`$PKG_CONFIG openssl --libs-only-L 2>/dev/null`
 if test $? = 0; then
-OPENSSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 
2>/dev/null`
-OPENSSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 
2>/dev/null`
+SSL_LIBS=`$PKG_CONFIG openssl --libs-only-l 2>/dev/null`
+SSL_INCLUDES=`$PKG_CONFIG openssl --cflags-only-I 
2>/dev/null`
 found=true
 fi
 fi
@@ -73,13 +73,13 @@ AC_DEFUN([AX_CHECK_OPENSSL], [
 # an 'openssl' subdirectory
 
 if ! $found; then
-OPENSSL_INCLUDES=
+SSL_INCLUDES=
 for ssldir in $ssldirs; do
 AC_MSG_CHECKING([for openssl/ssl.h in $ssldir])
 if test -f "$ssldir/include/openssl/ssl.h"; then
-OPENSSL_INCLUDES="-I$ssldir/include"
-OPENSSL_LDFLAGS="-L$ssldir/lib"
-OPENSSL_LIBS="-lssl -lcrypto"
+SSL_INCLUDES="-I$ssldir/include"
+SSL_LDFLAGS="-L$ssldir/lib"
+SSL_LIBS="-lssl -lcrypto"
 found=true
 AC_MSG_RESULT([yes])
 break
@@ -96,15 +96,15 @@ AC_DEFUN([AX_CHECK_OPENSSL], [
 # being careful not to pollute the global LIBS, LDFLAGS, and CPPFLAGS
 
 AC_MSG_CHECKING([whether compiling and linking against OpenSSL works])
-echo "Trying link with OPENSSL_LDFLAGS=$OPENSSL_LDFLAGS;" \
-"OPENSSL_LIBS=$OPENSSL_LIBS; OPENSSL_INCLUDES=$OPENSSL_INCLUDES" 
>&AS_MESSAGE_LOG_FD
+echo "Trying link with SSL_LDFLAGS=$SSL_LDFLAGS;" \
+"SSL_LIBS=$SSL_LIBS; SSL_INCLUDES=$SSL_INCLUDES" >&AS_MESSAGE_LOG_FD
 
 save_LIBS="$LIBS"
 save_LDFLAGS="$LDFLAGS"
 save_CPPFLAGS="$CPPFLAGS"
-LDFLAGS="$LDFLAGS $OPENSSL_LDFLAGS"
-LIBS="$OPENSSL_LIBS $LIBS"
-CPPFLAGS="$OPENSSL_INCLUDES $CPPFLAGS"
+LDFLAGS="$LDFLAGS $SSL_LDFLAGS"
+LIBS="$SSL_LIBS $LIBS"
+CPPFLAGS="$SSL_INCLUDES $CPPFLAGS"
 AC_LINK_IFELSE(
 [AC_LANG_PROGRAM([#include ], [SSL_new(NULL)])],
 [
@@ -118,7 +118,7 @@ AC_DEFUN([AX_CHECK_OPENSSL], [
 LDFLAGS="$save_LDFLAGS"
 LIBS="$save_LIBS"
 
-AC_SUBST([OPENSSL_INCLUDES])
-AC_SUBST([OPENSSL_LIBS])
-AC_SUBST([OPENSSL_LDFLAGS])
+AC_SUBST([SSL_INCLUDES])
+AC_SUBST([SSL_LIBS])
+AC_SUBST([SSL_LDFLAGS])
 ])
diff --git a/m4/openvswitch.m4 b/m4/openvswitch.m4
index 189cbf6..ac0c7d5 100644
--- a/m4/openvswitch.m4
+++ b/m4/openvswitch.m4
@@ -99,8 +99,7 @@ AC_DEFUN([OVS_CHECK_OPENSSL],
  [ssl=check])
 
if test "$ssl" != false; then
-   m4_ifndef([PKG_CHECK_MODULES], [m4_fatal([Please install pkg-config.])])
-   PKG_CHECK_MODULES([SSL], [openssl],
+   AX_CHECK_OPENSSL(
  [HAVE_OPENSSL=yes],
  [HAVE_OPENSSL=no
   if test "$ssl" = check; then
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 10/18] some ctype related casts to suppress gcc warnings on NetBSD.

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

where it can't be EOF, cast a value to unsigned char before passing it
to ctype functions to avoid unintended sign extension.

Signed-off-by: YAMAMOTO Takashi 
---
 lib/json.c | 14 +++---
 lib/ofp-util.c |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/json.c b/lib/json.c
index 5c96851..29ef246 100644
--- a/lib/json.c
+++ b/lib/json.c
@@ -620,11 +620,11 @@ json_lex_number(struct json_parser *p)
 significand = 0;
 if (*cp == '0') {
 cp++;
-if (isdigit(*cp)) {
+if (isdigit((unsigned char)*cp)) {
 json_error(p, "leading zeros not allowed");
 return;
 }
-} else if (isdigit(*cp)) {
+} else if (isdigit((unsigned char)*cp)) {
 do {
 if (significand <= ULLONG_MAX / 10) {
 significand = significand * 10 + (*cp - '0');
@@ -635,7 +635,7 @@ json_lex_number(struct json_parser *p)
 }
 }
 cp++;
-} while (isdigit(*cp));
+} while (isdigit((unsigned char)*cp));
 } else {
 json_error(p, "'-' must be followed by digit");
 return;
@@ -644,7 +644,7 @@ json_lex_number(struct json_parser *p)
 /* Optional fraction. */
 if (*cp == '.') {
 cp++;
-if (!isdigit(*cp)) {
+if (!isdigit((unsigned char)*cp)) {
 json_error(p, "decimal point must be followed by digit");
 return;
 }
@@ -656,7 +656,7 @@ json_lex_number(struct json_parser *p)
 imprecise = true;
 }
 cp++;
-} while (isdigit(*cp));
+} while (isdigit((unsigned char)*cp));
 }
 
 /* Optional exponent. */
@@ -672,7 +672,7 @@ json_lex_number(struct json_parser *p)
 cp++;
 }
 
-if (!isdigit(*cp)) {
+if (!isdigit((unsigned char)*cp)) {
 json_error(p, "exponent must contain at least one digit");
 return;
 }
@@ -685,7 +685,7 @@ json_lex_number(struct json_parser *p)
 }
 exponent = exponent * 10 + (*cp - '0');
 cp++;
-} while (isdigit(*cp));
+} while (isdigit((unsigned char)*cp));
 
 if (negative_exponent) {
 pow10 -= exponent;
diff --git a/lib/ofp-util.c b/lib/ofp-util.c
index c66cd40..2fd3c00 100644
--- a/lib/ofp-util.c
+++ b/lib/ofp-util.c
@@ -924,7 +924,7 @@ ofputil_version_from_string(const char *s)
 }
 
 static bool
-is_delimiter(char c)
+is_delimiter(unsigned char c)
 {
 return isspace(c) || c == ',';
 }
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 16/18] implement get_stats for NetBSD

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

Signed-off-by: YAMAMOTO Takashi 
---
 lib/netdev-bsd.c | 53 +
 1 file changed, 49 insertions(+), 4 deletions(-)

diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index 615a26f..1cb1d8b 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -890,7 +890,7 @@ 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_, struct netdev_stats *stats)
 {
 #if defined(__FreeBSD__)
 int if_count, i;
@@ -951,10 +951,55 @@ netdev_bsd_get_stats(const struct netdev *netdev_ 
__attribute__((__unused__)), s
 }
 
 return 0;
-#else
-/* XXXnotyet */
-memset(stats, 0, sizeof(*stats));
+#elif defined(__NetBSD__)
+struct netdev_dev_bsd *netdev_dev =
+netdev_dev_bsd_cast(netdev_get_dev(netdev_));
+struct ifdatareq ifdr;
+struct if_data *ifd;
+int saved_errno;
+int s;
+int ret;
+
+s = socket(AF_LINK, SOCK_DGRAM, 0);
+if (s == -1) {
+return errno;
+}
+memset(&ifdr, 0, sizeof(ifdr));
+strncpy(ifdr.ifdr_name, netdev_dev->kernel_name, sizeof(ifdr.ifdr_name));
+ret = ioctl(s, SIOCGIFDATA, &ifdr);
+saved_errno = errno;
+close(s);
+if (ret == -1) {
+return saved_errno;
+}
+ifd = &ifdr.ifdr_data;
+/*
+ * note: UINT64_MAX means unsupported
+ */
+stats->rx_packets = ifd->ifi_ipackets;
+stats->tx_packets = ifd->ifi_opackets;
+stats->rx_bytes = ifd->ifi_obytes;
+stats->tx_bytes = ifd->ifi_ibytes;
+stats->rx_errors = ifd->ifi_ierrors;
+stats->tx_errors = ifd->ifi_oerrors;
+stats->rx_dropped = ifd->ifi_iqdrops;
+stats->tx_dropped = UINT64_MAX;
+stats->multicast = ifd->ifi_imcasts;
+stats->collisions = ifd->ifi_collisions;
+stats->rx_length_errors = UINT64_MAX;
+stats->rx_over_errors = UINT64_MAX;
+stats->rx_crc_errors = UINT64_MAX;
+stats->rx_frame_errors = UINT64_MAX;
+stats->rx_fifo_errors = UINT64_MAX;
+stats->rx_missed_errors = UINT64_MAX;
+stats->tx_aborted_errors = UINT64_MAX;
+stats->tx_carrier_errors = UINT64_MAX;
+stats->tx_fifo_errors = UINT64_MAX;
+stats->tx_heartbeat_errors = UINT64_MAX;
+stats->tx_window_errors = UINT64_MAX;
 return 0;
+#else
+#error not implemented
 #endif
 }
 
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 17/18] some NetBSD related documentation changes

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

Signed-off-by: YAMAMOTO Takashi 
---
 INSTALL.userspace | 20 +---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/INSTALL.userspace b/INSTALL.userspace
index 296f077..65ad499 100644
--- a/INSTALL.userspace
+++ b/INSTALL.userspace
@@ -31,9 +31,9 @@ The tun device must also exist as /dev/net/tun.  If it does 
not exist,
 then create /dev/net (if necessary) with "mkdir /dev/net", then create
 /dev/net/tun with "mknod /dev/net/tun c 10 200".
 
-On FreeBSD, the userspace switch additionally requires the kernel
-tap(4) driver to be available, either built into the kernel or loaded
-as a module.
+On FreeBSD and NetBSD, the userspace switch additionally requires the
+kernel tap(4) driver to be available, either built into the kernel or
+loaded as a module.
 
 Using the Userspace Datapath with ovs-vswitchd
 --
@@ -51,6 +51,12 @@ ovs-vswitchd will create a TAP device as the bridge's local 
interface,
 named the same as the bridge, as well as for each configured internal
 interface.
 
+Currently, on FreeBSD and NetBSD, the functionality required for in-band
+control support is not implemented.  To avoid related errors, you can
+disable the in-band support as the following.
+
+ovs-vsctl set bridge br0 other_config:disable-in-band=true
+
 Firewall Rules
 --
 
@@ -64,6 +70,14 @@ eth0:
 iptables -A INPUT -i eth0 -j DROP
 iptables -A FORWARD -i eth0 -j DROP
 
+Other settings
+--
+
+On NetBSD, depending on your network topology and applications, the
+following configuration might help.  See sysctl(7).
+
+   sysctl net.inet.ip.checkinterface=1
+
 Bug Reporting
 -
 
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 08/18] change the type of popcount unsigned.

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

it's a natural choice and compatible with a version found in NetBSD libc.

Signed-off-by: YAMAMOTO Takashi 
---
 lib/util.c | 2 +-
 lib/util.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/util.c b/lib/util.c
index 83d3ff8..8a0b3ab 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -843,7 +843,7 @@ raw_ctz(uint32_t n)
 #endif
 
 /* Returns the number of 1-bits in 'x', between 0 and 32 inclusive. */
-int
+unsigned int
 popcount(uint32_t x)
 {
 /* In my testing, this implementation is over twice as fast as any other
diff --git a/lib/util.h b/lib/util.h
index b944ec7..4f6a201 100644
--- a/lib/util.h
+++ b/lib/util.h
@@ -265,7 +265,7 @@ ctz(uint32_t n)
 
 int log_2_floor(uint32_t);
 int log_2_ceil(uint32_t);
-int popcount(uint32_t);
+unsigned int popcount(uint32_t);
 
 /* Returns the rightmost 1-bit in 'x' (e.g. 01011000 => 1000), or 0 if 'x'
  * is 0. */
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 06/18] add NetBSD case for test.

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

Signed-off-by: YAMAMOTO Takashi 
---
 utilities/ovs-pki.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/utilities/ovs-pki.in b/utilities/ovs-pki.in
index 1f15410..8da8aa7 100755
--- a/utilities/ovs-pki.in
+++ b/utilities/ovs-pki.in
@@ -27,7 +27,7 @@ bits=2048
 
 # OS-specific compatibility routines
 case $(uname -s) in
-FreeBSD)
+FreeBSD|NetBSD)
 file_mod_epoch()
 {
 stat -r "$1" | awk '{print $10}'
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 13/18] add minimal NetBSD support

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

mostly ride on the existing FreeBSD support.

Signed-off-by: YAMAMOTO Takashi 
---
 lib/command-line.c|  4 ++--
 lib/command-line.h|  2 +-
 lib/netdev-bsd.c  | 37 -
 lib/netdev-dummy.c|  8 
 lib/netdev-provider.h |  2 +-
 lib/netdev.c  |  2 +-
 6 files changed, 45 insertions(+), 10 deletions(-)

diff --git a/lib/command-line.c b/lib/command-line.c
index b881c04..a587d23 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 FreeBSD and NetBSD 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 24facbb..47d6106 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -31,7 +31,9 @@
 #include 
 #include 
 #include 
+#if defined(__FreeBSD__)
 #include 
+#endif /* defined(__FreeBSD__) */
 #include 
 #include 
 #include 
@@ -343,12 +345,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_dev->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_dev->tap_fd);
@@ -359,7 +370,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;
@@ -868,8 +881,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;
@@ -928,6 +942,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
@@ -1202,7 +1221,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;
 }
@@ -1388,7 +1409,11 @@ get_flags(const struct netdev *netdev, int *flags)
 
 error = netdev_bsd_do_ioctl(netdev, &ifr, SIOCGIFFLAGS, "SIOCGIFFLAGS");
 
+#if defined(__FreeBSD__)
 *flags = 0x & (ifr.ifr_flagshigh << 16);
+#else
+*flags = 0;
+#endif
 *flags |= 0x & ifr.ifr_flags;
 
 return error;
@@ -1400,7 +1425,9 @@ set_flags(struct netdev *netdev, int flags)
 struct ifreq ifr;
 
 ifr.ifr_flags = 0x & flags;
+#if defined(__FreeBSD__)
 ifr.ifr_flagshigh = (0x & flags) >> 16;
+#endif
 
 return netdev_bsd_do_ioctl(netdev, &ifr, SIOCSIFFLAGS, "SIOCSIFFLAGS");
 }
@@ -1458,6 +1485,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);
@@ -1471,6 +1505,7 @@ set_etheraddr(const char *netdev_name, int hwaddr_family,
 return errno;
 }
 return 0;
+#endif
 }
 
 static int
diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index f81b68e..04d21f8 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -36,10 +36,10 @@
 
 VLOG_DEFINE_THIS_MODULE(netdev_dummy);
 
-#ifdef __FreeBSD__
-#define FREE_BSD 1
+#if defined(__FreeBSD__) || defined(__NetBSD__)
+#define FREEBSD_

[ovs-dev] [PATCH 00/18] NetBSD support

2013-01-31 Thread YAMAMOTO Takashi
NetBSD support

YAMAMOTO Takashi (18):
  fix an obvious mistake in a test of IFM_ETHER
  deal with platforms where backtrace() is in a different library than
libc.
  add ax_check_openssl.m4
  use ax_check_openssl.m4 instead of a direct use of pkg-config.
  include strings.h for strcasecmp.
  add NetBSD case for test.
  explicitly invoke perl for uuidfilt.pl (rather than via shebang)
  change the type of popcount unsigned.
  be compilable even when _SC_PHYS_PAGES is not available.
  some ctype related casts to suppress gcc warnings on NetBSD.
  include some headers to satisfy header file dependencies on NetBSD-6.
  use RT_ROUNDUP on NetBSD
  add minimal NetBSD support
  keep "kernel name" for each netdev
  implement set_etheraddr for NetBSD
  implement get_stats for NetBSD
  some NetBSD related documentation changes
  implement get_next_hop for NetBSD

 INSTALL.userspace   |  20 ++-
 lib/command-line.c  |   4 +-
 lib/command-line.h  |   2 +-
 lib/json.c  |  14 +--
 lib/netdev-bsd.c| 327 ++--
 lib/netdev-dummy.c  |   8 +-
 lib/netdev-provider.h   |   2 +-
 lib/netdev.c|   2 +-
 lib/ofp-util.c  |   2 +-
 lib/route-table-bsd.c   |   6 +
 lib/route-table.h   |   1 +
 lib/smap.c  |   2 +
 lib/socket-util.h   |   1 +
 lib/util.c  |   2 +-
 lib/util.h  |   2 +-
 m4/ax_check_openssl.m4  | 124 ++
 m4/openvswitch.m4   |   8 +-
 tests/ovs-vsctl.at  |   8 +-
 utilities/ovs-pki.in|   2 +-
 vswitchd/system-stats.c |   4 +
 20 files changed, 496 insertions(+), 45 deletions(-)
 create mode 100644 m4/ax_check_openssl.m4

-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 14/18] keep "kernel name" for each netdev

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

where interface renaming is not supported (NetBSD), remember both of
our netdev name and the correspoinding kernel name separately.
the latter is necessary to talk with kernel using interface names.
eg. ifioctls, bpf

XXX there should be a proper way to query kernel name.

Signed-off-by: YAMAMOTO Takashi 
---
 lib/netdev-bsd.c | 36 
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index 47d6106..76782ec 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -102,6 +102,8 @@ struct netdev_dev_bsd {
 
 bool tap_opened;
 int tap_fd; /* TAP character device, if any */
+
+char *kernel_name;
 };
 
 
@@ -301,6 +303,7 @@ netdev_bsd_create_system(const struct netdev_class *class, 
const char *name,
 netdev_dev = xzalloc(sizeof *netdev_dev);
 netdev_dev->change_seq = 1;
 netdev_dev_init(&netdev_dev->netdev_dev, name, class);
+netdev_dev->kernel_name = xstrdup(name);
 *netdev_devp = &netdev_dev->netdev_dev;
 
 return 0;
@@ -316,6 +319,7 @@ netdev_bsd_create_tap(const struct netdev_class *class, 
const char *name,
 struct netdev_dev_bsd *netdev_dev = NULL;
 int error = 0;
 struct ifreq ifr;
+char *kernel_name = NULL;
 
 error = cache_notifier_ref();
 if (error) {
@@ -352,19 +356,19 @@ netdev_bsd_create_tap(const struct netdev_class *class, 
const char *name,
 destroy_tap(netdev_dev->tap_fd, ifr.ifr_name);
 goto error_undef_notifier;
 }
+kernel_name = xstrdup(name);
 #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 */
+kernel_name = xstrdup(ifr.ifr_name);
 #endif
 
 /* set non-blocking. */
 error = set_nonblocking(netdev_dev->tap_fd);
 if (error) {
-destroy_tap(netdev_dev->tap_fd, name);
+destroy_tap(netdev_dev->tap_fd, kernel_name);
 goto error_undef_notifier;
 }
 
@@ -373,16 +377,17 @@ netdev_bsd_create_tap(const struct netdev_class *class, 
const char *name,
 #if defined(__FreeBSD__)
 ifr.ifr_flagshigh = 0;
 #endif
-strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
+strncpy(ifr.ifr_name, kernel_name, sizeof ifr.ifr_name);
 if (ioctl(af_inet_sock, SIOCSIFFLAGS, &ifr) == -1) {
 error = errno;
-destroy_tap(netdev_dev->tap_fd, name);
+destroy_tap(netdev_dev->tap_fd, kernel_name);
 goto error_undef_notifier;
 }
 
 /* initialize the device structure and
  * link the structure to its netdev */
 netdev_dev_init(&netdev_dev->netdev_dev, name, class);
+netdev_dev->kernel_name = kernel_name;
 *netdev_devp = &netdev_dev->netdev_dev;
 
 return 0;
@@ -391,6 +396,7 @@ error_undef_notifier:
 cache_notifier_unref();
 error:
 free(netdev_dev);
+free(kernel_name);
 return error;
 }
 
@@ -403,8 +409,9 @@ netdev_bsd_destroy(struct netdev_dev *netdev_dev_)
 
 if (netdev_dev->tap_fd >= 0 &&
 !strcmp(netdev_dev_get_type(netdev_dev_), "tap")) {
-destroy_tap(netdev_dev->tap_fd, netdev_dev_get_name(netdev_dev_));
+destroy_tap(netdev_dev->tap_fd, netdev_dev->kernel_name);
 }
+free(netdev_dev->kernel_name);
 free(netdev_dev);
 }
 
@@ -476,7 +483,7 @@ netdev_bsd_listen(struct netdev *netdev_)
 /* open the pcap device. The device is opened in non-promiscuous mode
  * because the interface flags are manually set by the caller. */
 errbuf[0] = '\0';
-netdev->pcap_handle = pcap_open_live(netdev_get_name(netdev_), 
PCAP_SNAPLEN,
+netdev->pcap_handle = pcap_open_live(netdev_dev->kernel_name, PCAP_SNAPLEN,
 0, 1000, errbuf);
 if (netdev->pcap_handle == NULL) {
 VLOG_ERR("%s: pcap_open_live failed: %s",
@@ -686,8 +693,10 @@ netdev_bsd_drain(struct netdev *netdev_)
 {
 struct ifreq ifr;
 struct netdev_bsd *netdev = netdev_bsd_cast(netdev_);
+struct netdev_dev_bsd * netdev_dev =
+netdev_dev_bsd_cast(netdev_get_dev(netdev_));
 
-strcpy(ifr.ifr_name, netdev_get_name(netdev_));
+strcpy(ifr.ifr_name, netdev_dev->kernel_name);
 if (ioctl(netdev->netdev_fd, BIOCFLUSH, &ifr) == -1) {
 VLOG_DBG_RL(&rl, "%s: ioctl(BIOCFLUSH) failed: %s",
 netdev_get_name(netdev_), strerror(errno));
@@ -774,7 +783,7 @@ netdev_bsd_set_etheraddr(struct netdev *netdev_,
 
 if (!(netdev_dev->cache_valid & VALID_ETHERADDR)
 || !eth_addr_equals(netdev_dev->etheraddr, mac)) {
-error = set_etheraddr(netdev_get_name(netdev_), AF_LINK, ETH_ADDR_LEN,
+error = set_etheraddr(netdev_dev->kernel_name, AF_LINK, ETH_ADDR_LEN,
   mac);
 if (!error) {
 netdev_dev->cache_valid |= VALID_ETHERADDR;
@@ -799,7 +808,7 @@ netdev_bsd_get_etheraddr(const struct netdev *netdev_,
 netdev

[ovs-dev] [PATCH 12/18] use RT_ROUNDUP on NetBSD

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

Signed-off-by: YAMAMOTO Takashi 
---
 lib/route-table-bsd.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/lib/route-table-bsd.c b/lib/route-table-bsd.c
index eb4a168..38cd2c9 100644
--- a/lib/route-table-bsd.c
+++ b/lib/route-table-bsd.c
@@ -97,7 +97,13 @@ route_table_get_name(ovs_be32 ip, char name[IFNAMSIZ])
 name[namelen] = '\0';
 return true;
 }
+#if defined(__FreeBSD__)
 sa = (struct sockaddr *)((char *)sa + SA_SIZE(sa));
+#elif defined(__NetBSD__)
+sa = (struct sockaddr *)((char *)sa + RT_ROUNDUP(sa->sa_len));
+#else
+#error unimplemented
+#endif
 }
 }
 return false;
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 18/18] implement get_next_hop for NetBSD

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

Signed-off-by: YAMAMOTO Takashi 
---
 INSTALL.userspace |   6 +--
 lib/netdev-bsd.c  | 151 +-
 2 files changed, 152 insertions(+), 5 deletions(-)

diff --git a/INSTALL.userspace b/INSTALL.userspace
index 65ad499..5f9a9d8 100644
--- a/INSTALL.userspace
+++ b/INSTALL.userspace
@@ -51,9 +51,9 @@ ovs-vswitchd will create a TAP device as the bridge's local 
interface,
 named the same as the bridge, as well as for each configured internal
 interface.
 
-Currently, on FreeBSD and NetBSD, the functionality required for in-band
-control support is not implemented.  To avoid related errors, you can
-disable the in-band support as the following.
+Currently, on FreeBSD, the functionality required for in-band control
+support is not implemented.  To avoid related errors, you can disable
+the in-band support as the following.
 
 ovs-vsctl set bridge br0 other_config:disable-in-band=true
 
diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
index 1cb1d8b..f35ca71 100644
--- a/lib/netdev-bsd.c
+++ b/lib/netdev-bsd.c
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2011 Gaetano Catalli.
+ * Copyright (c) 2013 YAMAMOTO Takashi.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -38,6 +39,9 @@
 #include 
 #include 
 #include 
+#if defined(__NetBSD__)
+#include 
+#endif
 
 #include "rtbsd.h"
 #include "coverage.h"
@@ -1244,6 +1248,149 @@ netdev_bsd_get_in6(const struct netdev *netdev_, struct 
in6_addr *in6)
 return 0;
 }
 
+#if defined(__NetBSD__)
+static struct netdev_dev *
+find_netdev_by_kernel_name(const char *kernel_name)
+{
+struct shash device_shash;
+struct shash_node *node;
+
+shash_init(&device_shash);
+netdev_dev_get_devices(&netdev_tap_class, &device_shash);
+SHASH_FOR_EACH(node, &device_shash) {
+struct netdev_dev_bsd * const dev = node->data;
+
+if (!strcmp(dev->kernel_name, kernel_name)) {
+shash_destroy(&device_shash);
+return &dev->netdev_dev;
+}
+}
+shash_destroy(&device_shash);
+return NULL;
+}
+
+static const char *
+netdev_bsd_convert_kernel_name_to_ovs_name(const char *kernel_name)
+{
+const struct netdev_dev * const netdev_dev =
+  find_netdev_by_kernel_name(kernel_name);
+
+if (netdev_dev == NULL) {
+return NULL;
+}
+return netdev_dev_get_name(netdev_dev);
+}
+#endif
+
+static int
+netdev_bsd_get_next_hop(const struct in_addr *host, struct in_addr *next_hop,
+char **netdev_name)
+{
+#if defined(__NetBSD__)
+static int seq = 0;
+struct sockaddr_in sin;
+struct sockaddr_dl sdl;
+int s;
+int i;
+struct {
+struct rt_msghdr h;
+char space[512];
+} buf;
+struct rt_msghdr *rtm = &buf.h;
+const pid_t pid = getpid();
+char *cp;
+ssize_t ssz;
+bool gateway = false;
+char *ifname = NULL;
+int saved_errno;
+
+memset(next_hop, 0, sizeof(*next_hop));
+*netdev_name = NULL;
+
+memset(&sin, 0, sizeof(sin));
+sin.sin_len = sizeof(sin);
+sin.sin_family = AF_INET;
+sin.sin_port = 0;
+sin.sin_addr = *host;
+
+memset(&sdl, 0, sizeof(sdl));
+sdl.sdl_len = sizeof(sdl);
+sdl.sdl_family = AF_LINK;
+
+s = socket(PF_ROUTE, SOCK_RAW, 0);
+memset(&buf, 0, sizeof(buf));
+rtm->rtm_flags = RTF_HOST|RTF_UP;
+rtm->rtm_version = RTM_VERSION;
+rtm->rtm_addrs = RTA_DST|RTA_IFP;
+cp = (void *)&buf.space;
+memcpy(cp, &sin, sizeof(sin));
+RT_ADVANCE(cp, (struct sockaddr *)(void *)&sin);
+memcpy(cp, &sdl, sizeof(sdl));
+RT_ADVANCE(cp, (struct sockaddr *)(void *)&sdl);
+rtm->rtm_msglen = cp - (char *)(void *)rtm;
+rtm->rtm_seq = ++seq;
+rtm->rtm_type = RTM_GET;
+rtm->rtm_pid = pid;
+write(s, rtm, rtm->rtm_msglen);
+memset(&buf, 0, sizeof(buf));
+do {
+ssz = read(s, &buf, sizeof(buf));
+} while (ssz > 0 && (rtm->rtm_seq != seq || rtm->rtm_pid != pid));
+saved_errno = errno;
+close(s);
+if (ssz <= 0) {
+if (ssz < 0) {
+return saved_errno;
+}
+return EPIPE; /* XXX */
+}
+cp = (void *)&buf.space;
+for (i = 1; i; i <<= 1) {
+if ((rtm->rtm_addrs & i) != 0) {
+const struct sockaddr *sa = (const void *)cp;
+
+if ((i == RTA_GATEWAY) && sa->sa_family == AF_INET) {
+const struct sockaddr_in * const sin =
+  (const struct sockaddr_in *)sa;
+
+*next_hop = sin->sin_addr;
+gateway = true;
+}
+if ((i == RTA_IFP) && sa->sa_family == AF_LINK) {
+const struct sockaddr_dl * const sdl =
+  (const struct sockaddr_dl *)sa;
+const size_t nlen = sdl->sdl_nlen;
+char * const kernel_name = xmalloc(nlen + 1);
+const char *name;
+
+  

[ovs-dev] [PATCH 07/18] explicitly invoke perl for uuidfilt.pl (rather than via shebang)

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

depending on a platform, perl might not be /usr/bin/perl.
eg. on NetBSD it's usually /usr/pkg/bin/perl.

Signed-off-by: YAMAMOTO Takashi 
---
 tests/ovs-vsctl.at | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/tests/ovs-vsctl.at b/tests/ovs-vsctl.at
index 326d5a4..3d00457 100644
--- a/tests/ovs-vsctl.at
+++ b/tests/ovs-vsctl.at
@@ -1019,7 +1019,7 @@ AT_CHECK(
 [list bridge br0])],
   [0], [stdout], [], [OVS_VSCTL_CLEANUP])
 AT_CHECK(
-  [sed -n -e '/uuid/p' -e '/name/p' -e '/mirrors/p' -e '/select/p' -e 
'/output/p' < stdout | $srcdir/uuidfilt.pl], [0], [dnl
+  [sed -n -e '/uuid/p' -e '/name/p' -e '/mirrors/p' -e '/select/p' -e 
'/output/p' < stdout | perl $srcdir/uuidfilt.pl], [0], [dnl
 [_uuid   : <0>
 name: "eth0"
 _uuid   : <1>
@@ -1045,13 +1045,13 @@ AT_KEYWORDS([ovs-vsctl])
 OVS_VSCTL_SETUP
 AT_CHECK(
   [ovs-vsctl -vPATTERN:console:'%c|%p|%m' --timeout=5 --no-wait 
-vreconnect:emer --db=unix:socket \
- -- create Bridge name=br0 | $srcdir/uuidfilt.pl],
+ -- create Bridge name=br0 | perl $srcdir/uuidfilt.pl],
   [0], [<0>
 ], [vsctl|WARN|applying "create" command to table Bridge without --id option 
will have no effect
 ], [OVS_VSCTL_CLEANUP])
 AT_CHECK(
   [ovs-vsctl -vPATTERN:console:'%c|%p|%m' --timeout=5 --no-wait 
-vreconnect:emer --db=unix:socket \
- -- --id=@br0 create Bridge name=br0 | $srcdir/uuidfilt.pl],
+ -- --id=@br0 create Bridge name=br0 | perl $srcdir/uuidfilt.pl],
   [0], [<0>
 ], [vsctl|WARN|row id "@br0" was created but no reference to it was inserted, 
so it will not actually appear in the database
 ], [OVS_VSCTL_CLEANUP])
@@ -1061,7 +1061,7 @@ AT_CHECK(
  -- --id=@eth0 create Port name=eth0 interfaces=@eth0_iface \
  -- --id=@m0 create Mirror name=m0 output_port=@eth0 \
  -- --id=@br0 create Bridge name=br0 mirrors=@m0 \
- -- set Open_vSwitch . bridges=@br0 | $srcdir/uuidfilt.pl],
+ -- set Open_vSwitch . bridges=@br0 | perl $srcdir/uuidfilt.pl],
   [0], [<0>
 <1>
 <2>
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH 05/18] include strings.h for strcasecmp.

2013-01-31 Thread YAMAMOTO Takashi
From: YAMAMOTO Takashi 

Signed-off-by: YAMAMOTO Takashi 
---
 lib/smap.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/smap.c b/lib/smap.c
index 54b339f..d993d84 100644
--- a/lib/smap.c
+++ b/lib/smap.c
@@ -15,6 +15,8 @@
 #include 
 #include "smap.h"
 
+#include/* strcasecmp */
+
 #include "hash.h"
 #include "json.h"
 
-- 
1.7.12

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 01/18] fix an obvious mistake in a test of IFM_ETHER

2013-01-31 Thread Ed Maste
On 31 January 2013 05:49, YAMAMOTO Takashi  wrote:
> From: YAMAMOTO Takashi 
>
> -if (!IFM_TYPE(ifmr.ifm_current) & IFM_ETHER) {
> +if (!(IFM_TYPE(ifmr.ifm_current) & IFM_ETHER)) {
>  VLOG_DBG_RL(&rl, "%s: doesn't appear to be ethernet",
>  netdev_get_name(netdev));

Should probably be IFM_TYPE(ifmr.ifm_current) != IFM_ETHER instead as
IFM_TYPE masks the network type field.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 02/18] deal with platforms where backtrace() is in a different library than libc.

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:36PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> execinfo for NetBSD and ubacktrace for uClibc.
> i don't know if the latter is relevant to Open vSwitch, though.
> 
> Signed-off-by: YAMAMOTO Takashi 

I didn't know that backtrace() was more widely available than glibc.
Does this patch mean that NetBSD makes a backtrace function matching the
following description available via libbacktrace?  (I can see from the
web that this is true for uclibc via libubacktrace.)

 -- Function: int backtrace (void **BUFFER, int SIZE)
 The `backtrace' function obtains a backtrace for the current
 thread, as a list of pointers, and places the information into
 BUFFER.  The argument SIZE should be the number of `void *'
 elements that will fit into BUFFER.  The return value is the
 actual number of entries of BUFFER that are obtained, and is at
 most SIZE.

 The pointers placed in BUFFER are actually return addresses
 obtained by inspecting the stack, one return address per stack
 frame.

 Note that certain compiler optimizations may interfere with
 obtaining a valid backtrace.  Function inlining causes the inlined
 function to not have a stack frame; tail call optimization
 replaces one stack frame with another; frame pointer elimination
 will stop `backtrace' from interpreting the stack contents
 correctly.

Thanks,

Ben.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 05/18] include strings.h for strcasecmp.

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:39PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> Signed-off-by: YAMAMOTO Takashi 

I see many uses of strcasecmp() in the tree:

blp@blp:~/nicira/ovs(0)$ git --no-pager grep -l strcasecmp
lib/bundle.c
lib/cfm.c
lib/meta-flow.c
lib/multipath.c
lib/odp-util.c
lib/ofp-parse.c
lib/ofp-util.c
lib/vlog.c
utilities/ovs-ofctl.c
utilities/ovs-vsctl.c
vswitchd/bridge.c

but only one use of strings.h:

lib/dpif-linux.c

I am surprised that your patch only adds one #include.  Why is that?

> +#include  /* strcasecmp */

The comment isn't necessary here.

Thanks,

Ben.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 07/18] explicitly invoke perl for uuidfilt.pl (rather than via shebang)

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:41PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> depending on a platform, perl might not be /usr/bin/perl.
> eg. on NetBSD it's usually /usr/pkg/bin/perl.
> 
> Signed-off-by: YAMAMOTO Takashi 

That's a good point but we have $PERL (set via "configure") that we
should use instead.  If you resubmit with that change then I'll take it.

By the way, the author and the Signed-off-by need to match, but it
doesn't in your case because the body of your emails begins with
From: YAMAMOTO Takashi 
indicating the biglobe email address but the sign-off is
Signed-off-by: YAMAMOTO Takashi 
with a valinux address.  When you resubmit, please fix this up one way
or another.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 06/18] add NetBSD case for test.

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:40PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> Signed-off-by: YAMAMOTO Takashi 

This looks good to me, thanks.

I'd update the subject to:
ovs-pki: Add NetBSD case for test.
to match our usual style.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 08/18] change the type of popcount unsigned.

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:42PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> it's a natural choice and compatible with a version found in NetBSD libc.
> 
> Signed-off-by: YAMAMOTO Takashi 

This looks good, thank you.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 09/18] be compilable even when _SC_PHYS_PAGES is not available.

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:43PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> Signed-off-by: YAMAMOTO Takashi 

Looks good to me, thanks.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 10/18] some ctype related casts to suppress gcc warnings on NetBSD.

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:44PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> where it can't be EOF, cast a value to unsigned char before passing it
> to ctype functions to avoid unintended sign extension.
> 
> Signed-off-by: YAMAMOTO Takashi 

Thanks, these look good except that we usually put a space following the
")" in a cast, see CodingStyle:

...
Exception 2: Put a space between the () used in a cast and the
expression whose type is cast: (void *) 0.
...

Will you please make that change and resubmit?
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 11/18] include some headers to satisfy header file dependencies on NetBSD-6.

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:45PM +0900, YAMAMOTO Takashi wrote:
> @@ -23,6 +23,7 @@
>  #include 
>  #include 
>  #include "openvswitch/types.h"
> +#include 
>  #include 

This is the first I've ever heard of in_systm.h.  Is it a portable
header file?  It is not in SUSv4, although I do see it on my GNU/Linux
host.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 12/18] use RT_ROUNDUP on NetBSD

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:46PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> Signed-off-by: YAMAMOTO Takashi 

This looks reasonable, thank you.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 13/18] add minimal NetBSD support

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:47PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> mostly ride on the existing FreeBSD support.
> 
> Signed-off-by: YAMAMOTO Takashi 

...

> @@ -1458,6 +1485,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 */

OVS generally uses EOPNOTSUPP (not ENOTSUP, which I hadn't known about)
internally to indicate that an operation isn't supported.  Will you
change this instance to EOPNOTSUPP?  Thanks.

> -#ifdef __FreeBSD__
> -#define FREE_BSD 1
> +#if defined(__FreeBSD__) || defined(__NetBSD__)
> +#define FREEBSD_OR_NETBSD 1
>  #else
> -#define FREE_BSD 0
> +#define FREEBSD_OR_NETBSD 0
>  #endif

It might be more readable to just use "BSD" in place of
FREEBSD_OR_NETBSD, which is a bit long.

Thanks,

Ben.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 03/18] add ax_check_openssl.m4

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:37PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> this file is obtained from:
> http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_check_openssl.m4;hb=5a7260331c7d13263126e35c5743fdc35cbc2894
> 
> Signed-off-by: YAMAMOTO Takashi 

Thanks, this looks good.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 04/18] use ax_check_openssl.m4 instead of a direct use of pkg-config.

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:38PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> on some platforms, including NetBSD-6, openssl is available but
> its pkg-config files (*.pc) are not.
> 
> Signed-off-by: YAMAMOTO Takashi 

Thanks.  I like getting rid of a pkgconfig.m4 dependency.

There are a few remaining references to pkgconfig that I believe we can
now remove also:

INSTALL:- pkg-config.  We test with version 0.22.
debian/control: libssl-dev, pkg-config (>= 0.21), bzip2, openssl,

Thanks,

Ben.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 04/18] use ax_check_openssl.m4 instead of a direct use of pkg-config.

2013-01-31 Thread Ed Maste
On 31 January 2013 05:49, YAMAMOTO Takashi  wrote:
> From: YAMAMOTO Takashi 
>
> on some platforms, including NetBSD-6, openssl is available but
> its pkg-config files (*.pc) are not.

FreeBSD as well (this is a common issue in the FreeBSD ports tree).  Thanks.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 14/18] keep "kernel name" for each netdev

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:48PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> where interface renaming is not supported (NetBSD), remember both of
> our netdev name and the correspoinding kernel name separately.
> the latter is necessary to talk with kernel using interface names.
> eg. ifioctls, bpf
> 
> XXX there should be a proper way to query kernel name.
> 
> Signed-off-by: YAMAMOTO Takashi 

So is the issue here that on NetBSD one cannot specify the name for a
new tap device?  The kernel always assigns its own name?  Then there
might be an extra problem.  Consider this case:

* ovs-vswitchd starts up and creates some tap devices.  It knows
  the mapping between the user-requested name and the kernel
  name.

* Admin restarts ovs-vswitchd.

* New instance of ovs-vswitchd creates new tap devices because
  it does not know the kernel names of the existing ones and
  does not have a way to discover them.  The existing ones are
  effectively leaked.

Furthermore, it seems likely that the tap devices created this way will
not actually be useful to the user, because the user does not have any
way, either, to discover the mapping between his names and the kernel
names.  Thus, the user doesn't know how to use the kernel tap devices.

I am not sure that OVS-created tap devices are that useful anyway.  I've
thought for some time of removing them from OVS entirely.  But it seems
that they are likely to be even less useful on netbsd.  Should we simply
not support them there?

(OVS-created tap devices are distinct from tap devices created other
ways, which at least on Linux can be added to an OVS bridge in the usual
way and don't require any special support.  Thus, removing this feature
would not keep OVS from working with tap devices.)
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 15/18] implement set_etheraddr for NetBSD

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:49PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> Signed-off-by: YAMAMOTO Takashi 

I see a number of repeated blocks here of the form:
> +int saved_errno = errno;
> +
> +close(s);
> +return saved_errno;
We would usually put this at the end of the function following an
"error:" label.  (Usually I would just give "saved_errno" the name
"error".)

Our usual comment style would write:
> +/*
> + * get the old address, add new one, and then remove old one.
> + */
as:
/* Get the old address, add new one, and then remove old one. */

Again we would usually use EOPNOTSUPP instead of ENOTSUP.

Thanks,

Ben.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 16/18] implement get_stats for NetBSD

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:50PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> Signed-off-by: YAMAMOTO Takashi 

Did you consider opening an AF_LINK socket only once instead of once per
call?  The netdev_get_stats() function can sometimes be called often, so
it may be best to avoid unneeded system calls.

Is there a reason not to squash this patch (and the previous one) into
the earlier patch that modified netdev-bsd?  I do not see anything that
keeps it conceptually distinct from that patch.

Thanks,

Ben.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 17/18] some NetBSD related documentation changes

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:51PM +0900, YAMAMOTO Takashi wrote:
> From: YAMAMOTO Takashi 
> 
> Signed-off-by: YAMAMOTO Takashi 

Thanks, this seems reasonable.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 00/18] NetBSD support

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 07:49:34PM +0900, YAMAMOTO Takashi wrote:
> NetBSD support

Thanks a lot!  Ed Maste and I made some comments.  I hope that you will
consider them and then repost a revised series.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 14/18] keep "kernel name" for each netdev

2013-01-31 Thread Jesse Gross
On Thu, Jan 31, 2013 at 9:40 AM, Ben Pfaff  wrote:
> I am not sure that OVS-created tap devices are that useful anyway.  I've
> thought for some time of removing them from OVS entirely.  But it seems
> that they are likely to be even less useful on netbsd.  Should we simply
> not support them there?
>
> (OVS-created tap devices are distinct from tap devices created other
> ways, which at least on Linux can be added to an OVS bridge in the usual
> way and don't require any special support.  Thus, removing this feature
> would not keep OVS from working with tap devices.)

I agree that tap devices as independent entities are useless in OVS.
However, they are pretty useful as an implementation of internal ports
in the userspace datapath.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 14/18] keep "kernel name" for each netdev

2013-01-31 Thread Ben Pfaff
On Thu, Jan 31, 2013 at 09:59:40AM -0800, Jesse Gross wrote:
> On Thu, Jan 31, 2013 at 9:40 AM, Ben Pfaff  wrote:
> > I am not sure that OVS-created tap devices are that useful anyway.  I've
> > thought for some time of removing them from OVS entirely.  But it seems
> > that they are likely to be even less useful on netbsd.  Should we simply
> > not support them there?
> >
> > (OVS-created tap devices are distinct from tap devices created other
> > ways, which at least on Linux can be added to an OVS bridge in the usual
> > way and don't require any special support.  Thus, removing this feature
> > would not keep OVS from working with tap devices.)
> 
> I agree that tap devices as independent entities are useless in OVS.
> However, they are pretty useful as an implementation of internal ports
> in the userspace datapath.

Yes, I'd forgotten about that.  So we need them for BSD (and for
Linux without the kernel module), then.

One possibility is that we could add a way to report back the kernel
name, then store that in the database.  There would still be a race, I
think, where a tap device could get "leaked", but it would be better
than leaking them every time.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [BUG] broad-/multicast & SLB bonding -> FAIL

2013-01-31 Thread Ethan Jackson
Are you absolutely sure the traffic isn't egressing the first switch,
and then ingressing the other switch into the bond?  It's often hard
to tell with tcpdump which direction traffic is travelling.

Could you please send problematic traffic through the switch, and
while that's going either run ovs-bugtool and send us the tarball, or
run the following commands

ovs-dpctl show -s
ovs-dpctl dump-flows 

ovs-appclt bond/list
ovs-appctl bond/show
ovs-acpptl lacp/show
ovs-appctl fdb/show 

Thanks,
Ethan

On Wed, Jan 30, 2013 at 5:26 PM, Jesse Gross  wrote:
> On Mon, Jan 28, 2013 at 12:07 PM, Markus Schuster
>  wrote:
>> On Monday 28 January 2013 20:29:01 Jesse Gross wrote:
>>> Are you configuring bonding directly through the OVS command line or
>>> using Xen tools?
>>
>> I'm using the Xen tools to configure all networking related settings.
>> Currently I'm not deep enough into Open vSwitch - on the ToDo list since a 
>> few
>> years...
>>
>>
>>> Can you also send the output of ovs-vsctl show?
>>
>> Sure:
>> --- cut ---
>> d3a05b53-3615-46e2-8d5a-7e47aa50ad84
>> Bridge "xenbr3"
>> fail_mode: standalone
>> Port "xenbr3"
>> Interface "xenbr3"
>> type: internal
>> Port "eth3"
>> Interface "eth3"
>> Bridge "xapi1"
>> fail_mode: standalone
>> Port "bond0"
>> Interface "eth0"
>> Interface "eth1"
>> Port "xapi1"
>> Interface "xapi1"
>> type: internal
>> Port "vif2.0"
>> Interface "vif2.0"
>> Bridge "xenbr2"
>> fail_mode: standalone
>> Port "xenbr2"
>> Interface "xenbr2"
>> type: internal
>> Port "eth2"
>> Interface "eth2"
>> ovs_version: "1.4.2"
>> --- cut ---
>>
>>
>>> >> Can you also post the logs?
>>> >
>>> > Well, there aren't much log files - at least not much I was able to find.
>>> [..]
>>>
>>> It's also odd that the ovs-vswitchd.log file is empty.  Can you check
>>> the command line to make sure that it is supposed to be logging?
>>
>> Looks like Open vSwitch components are configured to log to syslog:
>> --- cut ---
>> ovsdb-server /etc/openvswitch/conf.db -vANY:CONSOLE:EMER -vANY:SYSLOG:INFO -
>> vANY:FILE:EMER --remote=punix:/var/run/openvswitch/db.sock --
>> remote=db:Open_vSwitch,manager_options --private-key=db:SSL,private_key --
>> certificate=db:SSL,certificate --bootstrap-ca-cert=db:SSL,ca_cert --no-chdir
>> --log-file=/var/log/openvswitch/ovsdb-server.log --
>> pidfile=/var/run/openvswitch/ovsdb-server.pid --detach --monitor
>>
>> ovs-vswitchd unix:/var/run/openvswitch/db.sock -vANY:CONSOLE:EMER -
>> vANY:SYSLOG:INFO -vANY:FILE:EMER --mlockall --no-chdir --log-
>> file=/var/log/openvswitch/ovs-vswitchd.log 
>> --pidfile=/var/run/openvswitch/ovs-
>> vswitchd.pid --detach --monitor
>> --- cut ---
>>
>> So I grepped daemon.log for "ovs" - seems to be a good fit. I'll send you 
>> that
>> file in a direct message as I don't know the list policy regarding larger
>> files - feel free to forward as needed.
>
> At first glance, all of the configuration seems fine to me.
> Realistically, it's been too long since I've looked at the SLB code to
> track this down.  Ethan, I think you've worked on this the most
> recently, can you take a look?
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [BUG] broad-/multicast & SLB bonding -> FAIL

2013-01-31 Thread Jesse Gross
On Thu, Jan 31, 2013 at 11:30 AM, Ethan Jackson  wrote:
> Are you absolutely sure the traffic isn't egressing the first switch,
> and then ingressing the other switch into the bond?  It's often hard
> to tell with tcpdump which direction traffic is travelling.

He did sent the output ovs-dpctl dump-flows before.  At the time I saw
that it was sending the traffic out to two ports but I just noticed
that one of them is the local port.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 18/18] implement get_next_hop for NetBSD

2013-01-31 Thread Reid Price
> +the in-band support as the following.

Perhaps change 'as the following' to 'with the following command'

  -Reid

On Thu, Jan 31, 2013 at 2:49 AM, YAMAMOTO Takashi
 wrote:
> From: YAMAMOTO Takashi 
>
> Signed-off-by: YAMAMOTO Takashi 
> ---
>  INSTALL.userspace |   6 +--
>  lib/netdev-bsd.c  | 151 
> +-
>  2 files changed, 152 insertions(+), 5 deletions(-)
>
> diff --git a/INSTALL.userspace b/INSTALL.userspace
> index 65ad499..5f9a9d8 100644
> --- a/INSTALL.userspace
> +++ b/INSTALL.userspace
> @@ -51,9 +51,9 @@ ovs-vswitchd will create a TAP device as the bridge's local 
> interface,
>  named the same as the bridge, as well as for each configured internal
>  interface.
>
> -Currently, on FreeBSD and NetBSD, the functionality required for in-band
> -control support is not implemented.  To avoid related errors, you can
> -disable the in-band support as the following.
> +Currently, on FreeBSD, the functionality required for in-band control
> +support is not implemented.  To avoid related errors, you can disable
> +the in-band support as the following.
>
>  ovs-vsctl set bridge br0 other_config:disable-in-band=true
>
> diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c
> index 1cb1d8b..f35ca71 100644
> --- a/lib/netdev-bsd.c
> +++ b/lib/netdev-bsd.c
> @@ -1,5 +1,6 @@
>  /*
>   * Copyright (c) 2011 Gaetano Catalli.
> + * Copyright (c) 2013 YAMAMOTO Takashi.
>   *
>   * Licensed under the Apache License, Version 2.0 (the "License");
>   * you may not use this file except in compliance with the License.
> @@ -38,6 +39,9 @@
>  #include 
>  #include 
>  #include 
> +#if defined(__NetBSD__)
> +#include 
> +#endif
>
>  #include "rtbsd.h"
>  #include "coverage.h"
> @@ -1244,6 +1248,149 @@ netdev_bsd_get_in6(const struct netdev *netdev_, 
> struct in6_addr *in6)
>  return 0;
>  }
>
> +#if defined(__NetBSD__)
> +static struct netdev_dev *
> +find_netdev_by_kernel_name(const char *kernel_name)
> +{
> +struct shash device_shash;
> +struct shash_node *node;
> +
> +shash_init(&device_shash);
> +netdev_dev_get_devices(&netdev_tap_class, &device_shash);
> +SHASH_FOR_EACH(node, &device_shash) {
> +struct netdev_dev_bsd * const dev = node->data;
> +
> +if (!strcmp(dev->kernel_name, kernel_name)) {
> +shash_destroy(&device_shash);
> +return &dev->netdev_dev;
> +}
> +}
> +shash_destroy(&device_shash);
> +return NULL;
> +}
> +
> +static const char *
> +netdev_bsd_convert_kernel_name_to_ovs_name(const char *kernel_name)
> +{
> +const struct netdev_dev * const netdev_dev =
> +  find_netdev_by_kernel_name(kernel_name);
> +
> +if (netdev_dev == NULL) {
> +return NULL;
> +}
> +return netdev_dev_get_name(netdev_dev);
> +}
> +#endif
> +
> +static int
> +netdev_bsd_get_next_hop(const struct in_addr *host, struct in_addr *next_hop,
> +char **netdev_name)
> +{
> +#if defined(__NetBSD__)
> +static int seq = 0;
> +struct sockaddr_in sin;
> +struct sockaddr_dl sdl;
> +int s;
> +int i;
> +struct {
> +struct rt_msghdr h;
> +char space[512];
> +} buf;
> +struct rt_msghdr *rtm = &buf.h;
> +const pid_t pid = getpid();
> +char *cp;
> +ssize_t ssz;
> +bool gateway = false;
> +char *ifname = NULL;
> +int saved_errno;
> +
> +memset(next_hop, 0, sizeof(*next_hop));
> +*netdev_name = NULL;
> +
> +memset(&sin, 0, sizeof(sin));
> +sin.sin_len = sizeof(sin);
> +sin.sin_family = AF_INET;
> +sin.sin_port = 0;
> +sin.sin_addr = *host;
> +
> +memset(&sdl, 0, sizeof(sdl));
> +sdl.sdl_len = sizeof(sdl);
> +sdl.sdl_family = AF_LINK;
> +
> +s = socket(PF_ROUTE, SOCK_RAW, 0);
> +memset(&buf, 0, sizeof(buf));
> +rtm->rtm_flags = RTF_HOST|RTF_UP;
> +rtm->rtm_version = RTM_VERSION;
> +rtm->rtm_addrs = RTA_DST|RTA_IFP;
> +cp = (void *)&buf.space;
> +memcpy(cp, &sin, sizeof(sin));
> +RT_ADVANCE(cp, (struct sockaddr *)(void *)&sin);
> +memcpy(cp, &sdl, sizeof(sdl));
> +RT_ADVANCE(cp, (struct sockaddr *)(void *)&sdl);
> +rtm->rtm_msglen = cp - (char *)(void *)rtm;
> +rtm->rtm_seq = ++seq;
> +rtm->rtm_type = RTM_GET;
> +rtm->rtm_pid = pid;
> +write(s, rtm, rtm->rtm_msglen);
> +memset(&buf, 0, sizeof(buf));
> +do {
> +ssz = read(s, &buf, sizeof(buf));
> +} while (ssz > 0 && (rtm->rtm_seq != seq || rtm->rtm_pid != pid));
> +saved_errno = errno;
> +close(s);
> +if (ssz <= 0) {
> +if (ssz < 0) {
> +return saved_errno;
> +}
> +return EPIPE; /* XXX */
> +}
> +cp = (void *)&buf.space;
> +for (i = 1; i; i <<= 1) {
> +if ((rtm->rtm_addrs & i) != 0) {
> +const struct sockaddr *sa = (const void *)cp;
> +
> +if ((i == RTA_GATEWAY) && sa->sa_family == AF_INET) {
> +const struct sockaddr_in * const sin

Re: [ovs-dev] [coverity 04/12] ovsdb-tool: Fix memory leak on error path in "show-log" implementation.

2013-01-31 Thread Ben Pfaff
Thanks.  I pushed these four patches to master and I'm in the process
of doing backports.

On Wed, Jan 30, 2013 at 04:44:06PM -0800, Ethan Jackson wrote:
> Acked-by: Ethan Jackson 
> 
> On Thu, Jan 24, 2013 at 2:44 PM, Ben Pfaff  wrote:
> > Found by Coverity.
> >
> > Signed-off-by: Ben Pfaff 
> > ---
> >  ovsdb/ovsdb-tool.c |6 --
> >  1 files changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/ovsdb/ovsdb-tool.c b/ovsdb/ovsdb-tool.c
> > index 6b75f49..b50b39b 100644
> > --- a/ovsdb/ovsdb-tool.c
> > +++ b/ovsdb/ovsdb-tool.c
> > @@ -1,5 +1,5 @@
> >  /*
> > - * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
> > + * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
> >   *
> >   * Licensed under the Apache License, Version 2.0 (the "License");
> >   * you may not use this file except in compliance with the License.
> > @@ -435,8 +435,8 @@ print_db_changes(struct shash *tables, struct shash 
> > *names,
> >   ? shash_find_data(&table_schema->columns, 
> > column)
> >   : NULL);
> >  if (column_schema) {
> > -const struct ovsdb_error *error;
> >  const struct ovsdb_type *type;
> > +struct ovsdb_error *error;
> >  struct ovsdb_datum datum;
> >
> >  type = &column_schema->type;
> > @@ -448,6 +448,8 @@ print_db_changes(struct shash *tables, struct shash 
> > *names,
> >  ds_init(&s);
> >  ovsdb_datum_to_string(&datum, type, &s);
> >  value_string = ds_steal_cstr(&s);
> > +} else {
> > +ovsdb_error_destroy(error);
> >  }
> >  }
> >  if (!value_string) {
> > --
> > 1.7.2.5
> >
> > ___
> > dev mailing list
> > dev@openvswitch.org
> > http://openvswitch.org/mailman/listinfo/dev
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH] ofproto-dpif: Clear revalidation flags only once, not per-ofproto.

2013-01-31 Thread Ben Pfaff
Thanks, applied to master.

On Mon, Jan 28, 2013 at 12:30:10PM -0800, Ethan Jackson wrote:
> Thanks for fixing this.
> 
> Acked-by: Ethan Jackson 
> 
> On Mon, Jan 28, 2013 at 10:45 AM, Ben Pfaff  wrote:
> > Found by inspection.
> >
> > CC: Ethan Jackson 
> > Signed-off-by: Ben Pfaff 
> > ---
> > I noticed this while reviewing one of your "tunnel" patches.
> >
> > ofproto/ofproto-dpif.c |8 
> >  1 files changed, 4 insertions(+), 4 deletions(-)
> >
> > diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
> > index 1d08baf..d207b52 100644
> > --- a/ofproto/ofproto-dpif.c
> > +++ b/ofproto/ofproto-dpif.c
> > @@ -844,6 +844,10 @@ type_run(const char *type)
> >  case REV_INCONSISTENCY: COVERAGE_INC(rev_inconsistency); break;
> >  }
> >
> > +/* Clear the revalidation flags. */
> > +tag_set_init(&backer->revalidate_set);
> > +backer->need_revalidate = 0;
> > +
> >  HMAP_FOR_EACH (ofproto, all_ofproto_dpifs_node, 
> > &all_ofproto_dpifs) {
> >  struct facet *facet;
> >
> > @@ -851,10 +855,6 @@ type_run(const char *type)
> >  continue;
> >  }
> >
> > -/* Clear the revalidation flags. */
> > -tag_set_init(&backer->revalidate_set);
> > -backer->need_revalidate = 0;
> > -
> >  HMAP_FOR_EACH (facet, hmap_node, &ofproto->facets) {
> >  if (need_revalidate
> >  || tag_set_intersects(&revalidate_set, facet->tags)) {
> > --
> > 1.7.2.5
> >
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH] ovs-ctl: Update comment.

2013-01-31 Thread Ben Pfaff
On Mon, Jan 28, 2013 at 08:20:25PM +, Kyle Mestery (kmestery) wrote:
> On Jan 28, 2013, at 1:00 PM, Ben Pfaff  wrote:
> > Signed-off-by: Ben Pfaff 
> 
> 
> Acked-by: Kyle Mestery 

Thanks, applied to master.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [leaks 1/3] ofproto-dpif: Fix memory leak in port_dump_next().

2013-01-31 Thread Ben Pfaff
Thanks, applied to master.

On Fri, Jan 25, 2013 at 03:11:22PM -0800, Ethan Jackson wrote:
> Acked-by: Ethan Jackson 
> 
> On Thu, Jan 24, 2013 at 3:20 PM, Ben Pfaff  wrote:
> > The caller of port_query_by_name() is responsible for freeing the
> > ofproto_port that it returns on success, but ofproto-dpif did not do this.
> >
> > Signed-off-by: Ben Pfaff 
> > ---
> >  ofproto/ofproto-dpif.c |   20 ++--
> >  1 files changed, 18 insertions(+), 2 deletions(-)
> >
> > diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
> > index d75a63c..411795a 100644
> > --- a/ofproto/ofproto-dpif.c
> > +++ b/ofproto/ofproto-dpif.c
> > @@ -1561,8 +1561,10 @@ port_construct(struct ofport *port_)
> >  if (odp_port_to_ofp_port(ofproto, port->odp_port) != OFPP_NONE) {
> >  VLOG_ERR("port %s already has an OpenFlow port number\n",
> >   dpif_port.name);
> > +dpif_port_destroy(&dpif_port);
> >  return EBUSY;
> >  }
> > +dpif_port_destroy(&dpif_port);
> >
> >  hmap_insert(&ofproto->backer->odp_to_ofport_map, &port->odp_port_node,
> >  hash_int(port->odp_port, 0));
> > @@ -3058,6 +3060,9 @@ struct port_dump_state {
> >  uint32_t bucket;
> >  uint32_t offset;
> >  bool ghost;
> > +
> > +struct ofproto_port port;
> > +bool has_port;
> >  };
> >
> >  static int
> > @@ -3076,12 +3081,20 @@ port_dump_next(const struct ofproto *ofproto_ 
> > OVS_UNUSED, void *state_,
> >  const struct sset *sset;
> >  struct sset_node *node;
> >
> > +if (state->has_port) {
> > +ofproto_port_destroy(&state->port);
> > +state->has_port = false;
> > +}
> >  sset = state->ghost ? &ofproto->ghost_ports : &ofproto->ports;
> >  while ((node = sset_at_position(sset, &state->bucket, 
> > &state->offset))) {
> >  int error;
> >
> > -error = port_query_by_name(ofproto_, node->name, port);
> > -if (error != ENODEV) {
> > +error = port_query_by_name(ofproto_, node->name, &state->port);
> > +if (!error) {
> > +*port = state->port;
> > +state->has_port = true;
> > +return 0;
> > +} else if (error != ENODEV) {
> >  return error;
> >  }
> >  }
> > @@ -3101,6 +3114,9 @@ port_dump_done(const struct ofproto *ofproto_ 
> > OVS_UNUSED, void *state_)
> >  {
> >  struct port_dump_state *state = state_;
> >
> > +if (state->has_port) {
> > +ofproto_port_destroy(&state->port);
> > +}
> >  free(state);
> >  return 0;
> >  }
> > --
> > 1.7.2.5
> >
> > ___
> > dev mailing list
> > dev@openvswitch.org
> > http://openvswitch.org/mailman/listinfo/dev
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [monitor 0/3] "ovs-ofctl monitor" improvements

2013-01-31 Thread Ben Pfaff
This is a repost of a series that I originally sent out on Oct. 24,
2012:
http://openvswitch.org/pipermail/dev/2012-October/022213.html
http://openvswitch.org/pipermail/dev/2012-October/022215.html
http://openvswitch.org/pipermail/dev/2012-October/022214.html

Ben Pfaff (3):
  rconn: Factor code out from copy_to_monitor().
  rconn: Discard messages received on monitor connections.
  ovs-ofctl: Make "ovs-ofctl monitor" respond to echo requests.

 lib/rconn.c   |   31 ++-
 utilities/ovs-ofctl.c |   34 +++---
 2 files changed, 53 insertions(+), 12 deletions(-)

-- 
1.7.2.5

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [monitor 2/3] rconn: Discard messages received on monitor connections.

2013-01-31 Thread Ben Pfaff
Otherwise, if a monitor connection happens to be talking to a (misguided?)
peer that sends it messages, such as replies to what the peer perceives as
echo requests meant for it, then the peer will eventually hang trying to
send data because the monitor connection never sinks it.

Signed-off-by: Ben Pfaff 
---
 lib/rconn.c |   16 +++-
 1 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/lib/rconn.c b/lib/rconn.c
index d7bb0be..4922a5c 100644
--- a/lib/rconn.c
+++ b/lib/rconn.c
@@ -513,8 +513,21 @@ rconn_run(struct rconn *rc)
 if (rc->vconn) {
 vconn_run(rc->vconn);
 }
-for (i = 0; i < rc->n_monitors; i++) {
+for (i = 0; i < rc->n_monitors; ) {
+struct ofpbuf *msg;
+int retval;
+
 vconn_run(rc->monitors[i]);
+
+/* Drain any stray message that came in on the monitor connection. */
+retval = vconn_recv(rc->monitors[i], &msg);
+if (!retval) {
+ofpbuf_delete(msg);
+} else if (retval != EAGAIN) {
+close_monitor(rc, i, retval);
+continue;
+}
+i++;
 }
 
 do {
@@ -545,6 +558,7 @@ rconn_run_wait(struct rconn *rc)
 }
 for (i = 0; i < rc->n_monitors; i++) {
 vconn_run_wait(rc->monitors[i]);
+vconn_recv_wait(rc->monitors[i]);
 }
 
 timeo = timeout(rc);
-- 
1.7.2.5

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [monitor 1/3] rconn: Factor code out from copy_to_monitor().

2013-01-31 Thread Ben Pfaff
This prepares for the introduction of a second user in the following
commit.

Signed-off-by: Ben Pfaff 
---
 lib/rconn.c |   15 +++
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/lib/rconn.c b/lib/rconn.c
index 9b6cd86..d7bb0be 100644
--- a/lib/rconn.c
+++ b/lib/rconn.c
@@ -150,6 +150,7 @@ static void reconnect(struct rconn *);
 static void report_error(struct rconn *, int error);
 static void disconnect(struct rconn *, int error);
 static void flush_queue(struct rconn *);
+static void close_monitor(struct rconn *, size_t idx, int retval);
 static void copy_to_monitor(struct rconn *, const struct ofpbuf *);
 static bool is_connected_state(enum state);
 static bool is_admitted_msg(const struct ofpbuf *);
@@ -1057,6 +1058,15 @@ state_transition(struct rconn *rc, enum state state)
 }
 
 static void
+close_monitor(struct rconn *rc, size_t idx, int retval)
+{
+VLOG_DBG("%s: closing monitor connection to %s: %s",
+ rconn_get_name(rc), vconn_get_name(rc->monitors[idx]),
+ ovs_retval_to_string(retval));
+rc->monitors[idx] = rc->monitors[--rc->n_monitors];
+}
+
+static void
 copy_to_monitor(struct rconn *rc, const struct ofpbuf *b)
 {
 struct ofpbuf *clone = NULL;
@@ -1073,10 +1083,7 @@ copy_to_monitor(struct rconn *rc, const struct ofpbuf *b)
 if (!retval) {
 clone = NULL;
 } else if (retval != EAGAIN) {
-VLOG_DBG("%s: closing monitor connection to %s: %s",
- rconn_get_name(rc), vconn_get_name(vconn),
- strerror(retval));
-rc->monitors[i] = rc->monitors[--rc->n_monitors];
+close_monitor(rc, i, retval);
 continue;
 }
 i++;
-- 
1.7.2.5

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [monitor 3/3] ovs-ofctl: Make "ovs-ofctl monitor" respond to echo requests.

2013-01-31 Thread Ben Pfaff
Otherwise the command will time out after a while when there's no traffic,
which probably isn't what we want.

Reported-by: Henry Mai 
Signed-off-by: Ben Pfaff 
---
 utilities/ovs-ofctl.c |   34 +++---
 1 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/utilities/ovs-ofctl.c b/utilities/ovs-ofctl.c
index 4d8c39f..5591b5f 100644
--- a/utilities/ovs-ofctl.c
+++ b/utilities/ovs-ofctl.c
@@ -1312,8 +1312,12 @@ ofctl_unblock(struct unixctl_conn *conn, int argc 
OVS_UNUSED,
 }
 }
 
+/* Prints to stdout all of the messages received on 'vconn'.
+ *
+ * Iff 'reply_to_echo_requests' is true, sends a reply to any echo request
+ * received on 'vconn'. */
 static void
-monitor_vconn(struct vconn *vconn)
+monitor_vconn(struct vconn *vconn, bool reply_to_echo_requests)
 {
 struct barrier_aux barrier_aux = { vconn, NULL };
 struct unixctl_server *server;
@@ -1366,12 +1370,28 @@ monitor_vconn(struct vconn *vconn)
 
 ofptype_decode(&type, b->data);
 ofp_print(stderr, b->data, b->size, verbosity + 2);
-ofpbuf_delete(b);
 
-if (barrier_aux.conn && type == OFPTYPE_BARRIER_REPLY) {
-unixctl_command_reply(barrier_aux.conn, NULL);
-barrier_aux.conn = NULL;
+switch ((int) type) {
+case OFPTYPE_BARRIER_REPLY:
+if (barrier_aux.conn) {
+unixctl_command_reply(barrier_aux.conn, NULL);
+barrier_aux.conn = NULL;
+}
+break;
+
+case OFPTYPE_ECHO_REQUEST:
+if (reply_to_echo_requests) {
+struct ofpbuf *reply;
+
+reply = make_echo_reply(b->data);
+retval = vconn_send(vconn, reply);
+if (retval && retval != EAGAIN) {
+ovs_fatal(retval, "failed to send echo reply");
+}
+}
+break;
 }
+ofpbuf_delete(b);
 }
 
 if (exiting) {
@@ -1454,7 +1474,7 @@ ofctl_monitor(int argc, char *argv[])
 }
 }
 
-monitor_vconn(vconn);
+monitor_vconn(vconn, true);
 }
 
 static void
@@ -1463,7 +1483,7 @@ ofctl_snoop(int argc OVS_UNUSED, char *argv[])
 struct vconn *vconn;
 
 open_vconn__(argv[1], SNOOP, &vconn);
-monitor_vconn(vconn);
+monitor_vconn(vconn, false);
 }
 
 static void
-- 
1.7.2.5

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 0/16 v2.17] Basic MPLS actions and matches

2013-01-31 Thread Simon Horman
On Fri, Jan 25, 2013 at 04:22:06PM +0900, Simon Horman wrote:
> Hi,
> 
> This series implements basic MPLS actions and matches based on work by
> Ravi K, Leo Alterman and Yamahata-san.
> 
> The main limitation of this implementation is that it only
> supports manipulating the outer-most MPLS label.
> 
> Key differences between the v2.15 and v2.16:
> * Rebase
> * Address review by Ben Pfaff, particularly in th first patch of the
>   series "User-Space MPLS actions and matches"

Hi Ben,

I'm wondering if you might have time to look at some more of the
patches in this series. Or alternatively if there is anything
I can do to aid review.

> 
> Key differences between the v2.15 and v2.16:
> * Rebase
> * Use 62 for OVS_KEY_ATTR_MPLS to reduce the scope for conflict
>   with new values in the future
> 
> Key differences between the v2.14 and v2.15:
> * Addressed review by Ben Pfaff and Jesse Gross
>   In particular:
>   - Use Use OVS_ACTION_SET to set OVS_KEY_ATTR_MPLS instead o
>   Still under discussion
>   - Move OVS_KEY_ATTR_MPLS to after all upstream attributes
>   - Move OVS_ACTION_ATTR_PUSH_MPLS and OVS_ACTION_ATTR_POP_MPLS
> to after all upstream attributes
> 
> Key differences between the v2.13 and v2.14:
> * Reshuffle patches moving kernel datapath patches to the end of the series
>   and allowing the other patches to be applied independently. That is,
>   the first 10 patches of the series may be applied. They do not
>   touch the kernel. And the result will be MPLS support for ovs-vswitchd
>   and the user-space datapath.
> 
> Key differences between the v2.12 and v2.13:
> * Rebase
> * Add Inner and Outer flow support to user-space datapath
> * Allow MPLS matches for OpenFlow 1.3
> * Optimisations suggested by Jarno Rajahalme
> 
> Key differences between the v2.11 and v2.12:
> * Rebase
> * Add eth_type_mpls helper
> * Add flow_innermost_dl_type helper
> * calculate MPLS fitness over entire flow
>   - It is sufficient to just calculate the fitness of an MPLS frame once.
>   - Previously a fitness calculation was made based on expectations calculat
> on L1 and L2 data. However, this may not be correct as it will return
> ODP_FIT_TOO_MUCH in the case where the key contains L3 attributes.
> * Pass MPLS lse to push_mpls
>   - When push_mpls() the LSE of the flow is always already known,
> so pass it to push_mpls and set it directly. This avoids:
> + The need to re-compose an default LSE, allowing
>   the removal of get_lse()
> + The need to follow each call to push_mpls() with
>   a call to set_mpls_lse()
>   - This fixes the previously bogus usage of push_mpls
> in dp_netdev_execute_actions, allowing push_mpls to work
> in conjunction with the user-space datapath.
> * Add dl_type parameter to flow_extract_l3_onwards()
>   and thus allow "flow: Split flow_extract" to be applied
>   independently of the rest of this patch-set.
> 
> Key differences between the v2.10 and v2.11:
> * Rebase
> * The last 13 patches in the series have been added to allow
>   handling of actions on MPLS flows that modify any L3+ data.
>   In particular, to allow modification of the IP TTL.
> 
>   This is achieved by adding the notion of inner and outer flows.
>   This works as follows.
> 
>   - A match is decoded from a packet using the existing implementation
> and this is used to look up the flow.
>   - If the flow includes actions that allow further decoding of
> the packet - e.g. an MPLS pop action which supplies the
> ethernet type of the encapsulated frame - then the packet is
> further decoded and a more fine-grained match is made. This match
> is then used to lookup the flow again.
> 
>   In such cases the flow added to the datapath by ovs-vswtichd
>   includes the richer match and the actions. The datapath inspects
>   the actions and if there are actions that allow further decoding of
>   the packet it inserts the flow twice, once including only an L1 and L2
>   match and once including the richer match. The former is the
>   other flow and the latter is the inner flow.
> 
>   Each inner flow has a single outer flow. Outer flows may
>   have more than one inner flow. Inner flows are not exposed
>   to ovs-vswitchd. Inner flows are deleted when their outer
>   flow is deleted.
> 
> * Check the size of nx_action_mpls_ttl.
>   nx_action_pop_mpls was being checked
>   due to a cut-and-paste error
> 
> Key differences between the previous post, v2.9, and this post, v2.10:
> * Rebase
> * Check the size of nx_action_mpls_ttl.
>   nx_action_pop_mpls was being checked
>   due to a cut-and-paste error
> 
> Key differences between v2.8 and v2.9
> * Rebase
>   and fix tests accordingly
> * Always update MPLS bos pointer when
>   VLAN pop is performed in kernel datapath.
> 
> Key differences between v2.7 and v2.8
> * Rebase
> 
> Key differences between v2.6 and v2.7
> * When encoding TTL actions (the last 4 patches) for
>   an OpenFlow 1.1+ message, encode them as OpenFlow 1

Re: [ovs-dev] [PATCH 0/16 v2.17] Basic MPLS actions and matches

2013-01-31 Thread Ben Pfaff
On Fri, Feb 01, 2013 at 09:23:52AM +0900, Simon Horman wrote:
> On Fri, Jan 25, 2013 at 04:22:06PM +0900, Simon Horman wrote:
> > Hi,
> > 
> > This series implements basic MPLS actions and matches based on work by
> > Ravi K, Leo Alterman and Yamahata-san.
> > 
> > The main limitation of this implementation is that it only
> > supports manipulating the outer-most MPLS label.
> > 
> > Key differences between the v2.15 and v2.16:
> > * Rebase
> > * Address review by Ben Pfaff, particularly in th first patch of the
> >   series "User-Space MPLS actions and matches"
> 
> Hi Ben,
> 
> I'm wondering if you might have time to look at some more of the
> patches in this series. Or alternatively if there is anything
> I can do to aid review.

I'm planning to get back to it soon.  I think we're getting close, at
least on the patches early in the series.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH v2 1/2] netdev-dummy: Correctly maintain port statistics.

2013-01-31 Thread Ben Pfaff
Signed-off-by: Ben Pfaff 
---
 lib/netdev-dummy.c |   18 +-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/lib/netdev-dummy.c b/lib/netdev-dummy.c
index f81b68e..234d7bc 100644
--- a/lib/netdev-dummy.c
+++ b/lib/netdev-dummy.c
@@ -205,6 +205,19 @@ netdev_dummy_drain(struct netdev *netdev_)
 }
 
 static int
+netdev_dummy_send(struct netdev *netdev, const void *buffer OVS_UNUSED,
+  size_t size)
+{
+struct netdev_dev_dummy *dev =
+netdev_dev_dummy_cast(netdev_get_dev(netdev));
+
+dev->stats.tx_packets++;
+dev->stats.tx_bytes += size;
+
+return 0;
+}
+
+static int
 netdev_dummy_set_etheraddr(struct netdev *netdev,
const uint8_t mac[ETH_ADDR_LEN])
 {
@@ -336,7 +349,7 @@ static const struct netdev_class dummy_class = {
 netdev_dummy_recv_wait,
 netdev_dummy_drain,
 
-NULL,   /* send */
+netdev_dummy_send,  /* send */
 NULL,   /* send_wait */
 
 netdev_dummy_set_etheraddr,
@@ -443,6 +456,9 @@ netdev_dummy_receive(struct unixctl_conn *conn,
 return;
 }
 
+dummy_dev->stats.rx_packets++;
+dummy_dev->stats.rx_bytes += packet->size;
+
 n_listeners = 0;
 LIST_FOR_EACH (dev, node, &dummy_dev->devs) {
 if (dev->listening) {
-- 
1.7.2.5

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH v2 0/2] add test for self-modifying learn action

2013-01-31 Thread Ben Pfaff
This is a repost of a series originally posted on Sep. 18, 2012:
http://openvswitch.org/pipermail/dev/2012-September/021272.html
http://openvswitch.org/pipermail/dev/2012-September/021273.html

Ben Pfaff (2):
  netdev-dummy: Correctly maintain port statistics.
  tests: Add test for self-modifying learn action.

 lib/netdev-dummy.c |   18 +-
 tests/learn.at |   35 +++
 2 files changed, 52 insertions(+), 1 deletions(-)

-- 
1.7.2.5

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


[ovs-dev] [PATCH v2 2/2] tests: Add test for self-modifying learn action.

2013-01-31 Thread Ben Pfaff
CC: Paul Ingram 
Signed-off-by: Ben Pfaff 
---
 tests/learn.at |   35 +++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/tests/learn.at b/tests/learn.at
index 800dc14..8f59b63 100644
--- a/tests/learn.at
+++ b/tests/learn.at
@@ -252,6 +252,41 @@ NXST_FLOW reply:
 OVS_VSWITCHD_STOP
 AT_CLEANUP
 
+# In this use of a learn action, the first packet in the flow creates
+# a new flow that changes the behavior of subsequent packets in the
+# flow.
+AT_SETUP([learning action - self-modifying flow])
+OVS_VSWITCHD_START
+ADD_OF_PORTS([br0], 1, 2, 3)
+
+# Set up flow table for TCPv4 port learning.
+AT_CHECK([[ovs-ofctl add-flow br0 
'actions=load:3->NXM_NX_REG0[0..15],learn(table=0,priority=65535,NXM_OF_ETH_SRC[],NXM_OF_VLAN_TCI[0..11],output:NXM_NX_REG0[0..15]),output:2']])
+
+# Trace some packets arriving.  The particular packets don't matter.
+for i in 1 2 3 4 5 6 7 8 9 10; do
+ovs-appctl netdev-dummy/receive p1 
'in_port(1),eth(src=50:54:00:00:00:05,dst=50:54:00:00:00:07),eth_type(0x0800),ipv4(src=192.168.0.1,dst=192.168.0.2,proto=6,tos=0,ttl=64,frag=no),tcp(src=8,dst=9)'
+done
+
+# Check for the learning entry.
+AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0],
+[[ n_packets=1, n_bytes=60, 
actions=load:0x3->NXM_NX_REG0[0..15],learn(table=0,priority=65535,NXM_OF_ETH_SRC[],NXM_OF_VLAN_TCI[0..11],output:NXM_NX_REG0[0..15]),output:2
+ priority=65535,vlan_tci=0x/0x0fff,dl_src=50:54:00:00:00:05 
actions=output:3
+NXST_FLOW reply:
+]])
+
+# Check that the first packet went out port 2 and the rest out port 3.
+AT_CHECK(
+  [(ovs-ofctl dump-ports br0 2; ovs-ofctl dump-ports br0 3) | STRIP_XIDS], [0],
+  [OFPST_PORT reply: 1 ports
+  port  2: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
+   tx pkts=1, bytes=60, drop=0, errs=0, coll=0
+OFPST_PORT reply: 1 ports
+  port  3: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0
+   tx pkts=9, bytes=540, drop=0, errs=0, coll=0
+])
+OVS_VSWITCHD_STOP
+AT_CLEANUP
+
 AT_SETUP([learning action - fin_timeout feature])
 # This is a totally artificial use of the "learn" action.  The only purpose
 # is to check that specifying fin_idle_timeout or fin_hard_timeout causes
-- 
1.7.2.5

___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 0/16 v2.17] Basic MPLS actions and matches

2013-01-31 Thread Simon Horman
On Thu, Jan 31, 2013 at 04:27:01PM -0800, Ben Pfaff wrote:
> On Fri, Feb 01, 2013 at 09:23:52AM +0900, Simon Horman wrote:
> > On Fri, Jan 25, 2013 at 04:22:06PM +0900, Simon Horman wrote:
> > > Hi,
> > > 
> > > This series implements basic MPLS actions and matches based on work by
> > > Ravi K, Leo Alterman and Yamahata-san.
> > > 
> > > The main limitation of this implementation is that it only
> > > supports manipulating the outer-most MPLS label.
> > > 
> > > Key differences between the v2.15 and v2.16:
> > > * Rebase
> > > * Address review by Ben Pfaff, particularly in th first patch of the
> > >   series "User-Space MPLS actions and matches"
> > 
> > Hi Ben,
> > 
> > I'm wondering if you might have time to look at some more of the
> > patches in this series. Or alternatively if there is anything
> > I can do to aid review.
> 
> I'm planning to get back to it soon.  I think we're getting close, at
> least on the patches early in the series.

Great, thanks.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 00/18] NetBSD support

2013-01-31 Thread YAMAMOTO Takashi
hi,

> On Thu, Jan 31, 2013 at 07:49:34PM +0900, YAMAMOTO Takashi wrote:
>> NetBSD support
> 
> Thanks a lot!  Ed Maste and I made some comments.  I hope that you will
> consider them and then repost a revised series.

thanks for reviewing!

YAMAMOTO Takashi
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 14/18] keep "kernel name" for each netdev

2013-01-31 Thread YAMAMOTO Takashi
hi,

> On Thu, Jan 31, 2013 at 07:49:48PM +0900, YAMAMOTO Takashi wrote:
>> From: YAMAMOTO Takashi 
>> 
>> where interface renaming is not supported (NetBSD), remember both of
>> our netdev name and the correspoinding kernel name separately.
>> the latter is necessary to talk with kernel using interface names.
>> eg. ifioctls, bpf
>> 
>> XXX there should be a proper way to query kernel name.
>> 
>> Signed-off-by: YAMAMOTO Takashi 
> 
> So is the issue here that on NetBSD one cannot specify the name for a
> new tap device?  The kernel always assigns its own name?  Then there
> might be an extra problem.  Consider this case:

yes.  kernel picks a name (eg. tap1) and a user can't changed it.

> 
> * ovs-vswitchd starts up and creates some tap devices.  It knows
>   the mapping between the user-requested name and the kernel
>   name.
> 
> * Admin restarts ovs-vswitchd.
> 
> * New instance of ovs-vswitchd creates new tap devices because
>   it does not know the kernel names of the existing ones and
>   does not have a way to discover them.  The existing ones are
>   effectively leaked.

there isn't a leak as ovs-vswitchd destroys the old one when stopping.

> 
> Furthermore, it seems likely that the tap devices created this way will
> not actually be useful to the user, because the user does not have any
> way, either, to discover the mapping between his names and the kernel
> names.  Thus, the user doesn't know how to use the kernel tap devices.

right.  it's what XXX in the commit log says.

it would be useful if the user can query the corresponding kernel name
using one of ovs-xxxctl.  having a way to query netdev implementation
specific data in general might be useful.  any idea?

> 
> I am not sure that OVS-created tap devices are that useful anyway.  I've
> thought for some time of removing them from OVS entirely.  But it seems
> that they are likely to be even less useful on netbsd.  Should we simply
> not support them there?

it would be good to have a way to create a bridge without a local port.
(is there any?)

YAMAMOTO Takashi

> 
> (OVS-created tap devices are distinct from tap devices created other
> ways, which at least on Linux can be added to an OVS bridge in the usual
> way and don't require any special support.  Thus, removing this feature
> would not keep OVS from working with tap devices.)
> ___
> dev mailing list
> dev@openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 11/18] include some headers to satisfy header file dependencies on NetBSD-6.

2013-01-31 Thread YAMAMOTO Takashi
hi,

> On Thu, Jan 31, 2013 at 07:49:45PM +0900, YAMAMOTO Takashi wrote:
>> @@ -23,6 +23,7 @@
>>  #include 
>>  #include 
>>  #include "openvswitch/types.h"
>> +#include 
>>  #include 
> 
> This is the first I've ever heard of in_systm.h.  Is it a portable
> header file?  It is not in SUSv4, although I do see it on my GNU/Linux
> host.

i don't know.

i guess it's available on many of systems because it's ancient.

NetBSD-6's ip.h requires in_systm.h included beforehand.
i can put it in ifdef __NetBSD__ if you worry.

YAMAMOTO Takashi
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 05/18] include strings.h for strcasecmp.

2013-01-31 Thread YAMAMOTO Takashi
hi,

> On Thu, Jan 31, 2013 at 07:49:39PM +0900, YAMAMOTO Takashi wrote:
>> From: YAMAMOTO Takashi 
>> 
>> Signed-off-by: YAMAMOTO Takashi 
> 
> I see many uses of strcasecmp() in the tree:
> 
> blp@blp:~/nicira/ovs(0)$ git --no-pager grep -l strcasecmp
> lib/bundle.c
> lib/cfm.c
> lib/meta-flow.c
> lib/multipath.c
> lib/odp-util.c
> lib/ofp-parse.c
> lib/ofp-util.c
> lib/vlog.c
> utilities/ovs-ofctl.c
> utilities/ovs-vsctl.c
> vswitchd/bridge.c
> 
> but only one use of strings.h:
> 
> lib/dpif-linux.c
> 
> I am surprised that your patch only adds one #include.  Why is that?

because only this one made gcc complain on my environment
and i don't know ovs's header inclusion policy.
for other places some other headers indirectly pulled it, i guess.

> 
>> +#include /* strcasecmp */
> 
> The comment isn't necessary here.

ok.

YAMAMOTO Takashi

> 
> Thanks,
> 
> Ben.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 02/18] deal with platforms where backtrace() is in a different library than libc.

2013-01-31 Thread YAMAMOTO Takashi
hi,

> On Thu, Jan 31, 2013 at 07:49:36PM +0900, YAMAMOTO Takashi wrote:
>> From: YAMAMOTO Takashi 
>> 
>> execinfo for NetBSD and ubacktrace for uClibc.
>> i don't know if the latter is relevant to Open vSwitch, though.
>> 
>> Signed-off-by: YAMAMOTO Takashi 
> 
> I didn't know that backtrace() was more widely available than glibc.
> Does this patch mean that NetBSD makes a backtrace function matching the
> following description available via libbacktrace?  (I can see from the
> web that this is true for uclibc via libubacktrace.)

NetBSD-current has the function in libexecinfo and it seems reasonably
compatible.  (see the end of this mail)

YAMAMOTO Takashi

> 
>  -- Function: int backtrace (void **BUFFER, int SIZE)
>  The `backtrace' function obtains a backtrace for the current
>  thread, as a list of pointers, and places the information into
>  BUFFER.  The argument SIZE should be the number of `void *'
>  elements that will fit into BUFFER.  The return value is the
>  actual number of entries of BUFFER that are obtained, and is at
>  most SIZE.
> 
>  The pointers placed in BUFFER are actually return addresses
>  obtained by inspecting the stack, one return address per stack
>  frame.
> 
>  Note that certain compiler optimizations may interfere with
>  obtaining a valid backtrace.  Function inlining causes the inlined
>  function to not have a stack frame; tail call optimization
>  replaces one stack frame with another; frame pointer elimination
>  will stop `backtrace' from interpreting the stack contents
>  correctly.
> 
> Thanks,
> 
> Ben.

BACKTRACE(3)   Library Functions Manual   BACKTRACE(3)

NAME
 backtrace -- fill in the backtrace of the currently executing thread

LIBRARY
 Backtrace Information Library (libexecinfo, -lexecinfo)

SYNOPSIS
 #include 

 size_t
 backtrace(void **addrlist, size_t len);

 char **
 backtrace_symbols(void * const *addrlist, size_t len);

 int
 backtrace_symbols_fd(void * const *addrlist, size_t len, int fd);

 char **
 backtrace_symbols_fmt(void * const *addrlist, size_t len, const char
 *fmt);

 int
 backtrace_symbols_fmt_fd(void * const *addrlist, size_t len, const char
 *fmt, int fd);

DESCRIPTION
 The backtrace() function places into the array pointed by addrlist the
 array of the values of the program counter for each frame called up to
 len frames.  The number of frames found (which can be fewer than len) is
 returned.

 The backtrace_symbols_fmt() function takes an array of previously filled
 addresses from backtrace() in addrlist of len elements, and uses fmt to
 format them.  The formatting characters available are:

   a  The numeric address of each element as would be printed using
  %p.

   n  The name of the nearest function symbol (smaller than the
  address element) as determined by dladdr(3) if the symbol was
  dynamic, or looked up in the executable if static and the /proc
  filesystem is available to determine the executable path.

   d  The difference of the symbol address and the address element
  printed using 0x%tx.

   D  The difference of the symbol addresss and the address element
  printed using +0x%tx if non-zero, or nothing if zero.

   f  The filename of the symbol as determined by dladdr(3).

 The array of formatted strings is returned as a contiguous memory address
 which can be freed by a single free(3).

 The backtrace_symbols() function is equivalent of calling
 backtrace_symbols_fmt() with a format argument of %a <%n%D> at %f

 The backtrace_symbols_fd() and backtrace_symbols_fmt_fd() are similar to
 the non _fd named functions, only instead of returning an array or
 strings, they print a new-line separated array of strings in fd, and
 return 0 on success and -1 on failure.

RETURN VALUES
 The backtrace() function returns the number of elements tht were filled
 in the backtrace.  The backtrace_symbols() and backtrace_symbols_fmt()
 return a string array on success, and NULL on failure, setting errno.
 Diagnostic output may also be produced by the ELF symbol lookup
 functions.

SEE ALSO
 dladdr(3), elf(3)

HISTORY
 The backtrace() library of functions first appeared in NetBSD 7.0.

BUGS
 1.   Errors should not be printed but communicated to the caller
  differently.

 2.   Because these functions use elf(3) this is a separate library
  instead of being part of libc/libutil so that no library
  dependencies are introduced.

 3.   The Linux versions of the functions (there are no _fmt variants) use
  int instead of size_t arguments.

 4.   Since dladdr(3) only deals with dynamic symbols, we need to find the
  symbols from the main portion of th

Re: [ovs-dev] [PATCH 13/18] add minimal NetBSD support

2013-01-31 Thread YAMAMOTO Takashi
hi,

> On Thu, Jan 31, 2013 at 07:49:47PM +0900, YAMAMOTO Takashi wrote:
>> From: YAMAMOTO Takashi 
>> 
>> mostly ride on the existing FreeBSD support.
>> 
>> Signed-off-by: YAMAMOTO Takashi 
> 
> ...
> 
>> @@ -1458,6 +1485,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 */
> 
> OVS generally uses EOPNOTSUPP (not ENOTSUP, which I hadn't known about)
> internally to indicate that an operation isn't supported.  Will you
> change this instance to EOPNOTSUPP?  Thanks.

ok.

> 
>> -#ifdef __FreeBSD__
>> -#define FREE_BSD 1
>> +#if defined(__FreeBSD__) || defined(__NetBSD__)
>> +#define FREEBSD_OR_NETBSD 1
>>  #else
>> -#define FREE_BSD 0
>> +#define FREEBSD_OR_NETBSD 0
>>  #endif
> 
> It might be more readable to just use "BSD" in place of
> FREEBSD_OR_NETBSD, which is a bit long.

i hesitate to use "BSD" only for FreeBSD and NetBSD given that
there are too many BSD variants in the world.

probably a more meaningful name like REGISTER_TUNNEL is better
in the regard of readability?

YAMAMOTO Takashi

> 
> Thanks,
> 
> Ben.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 16/18] implement get_stats for NetBSD

2013-01-31 Thread YAMAMOTO Takashi
hi,

> On Thu, Jan 31, 2013 at 07:49:50PM +0900, YAMAMOTO Takashi wrote:
>> From: YAMAMOTO Takashi 
>> 
>> Signed-off-by: YAMAMOTO Takashi 
> 
> Did you consider opening an AF_LINK socket only once instead of once per
> call?  The netdev_get_stats() function can sometimes be called often, so
> it may be best to avoid unneeded system calls.

ok.

> 
> Is there a reason not to squash this patch (and the previous one) into
> the earlier patch that modified netdev-bsd?  I do not see anything that
> keeps it conceptually distinct from that patch.

no reason.  it just reflected my development history.
do you prefer to fold them into one?

YAMAMOTO Takashi

> 
> Thanks,
> 
> Ben.
> ___
> dev mailing list
> dev@openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 11/18] include some headers to satisfy header file dependencies on NetBSD-6.

2013-01-31 Thread Ben Pfaff
On Fri, Feb 01, 2013 at 10:56:34AM +0900, YAMAMOTO Takashi wrote:
> hi,
> 
> > On Thu, Jan 31, 2013 at 07:49:45PM +0900, YAMAMOTO Takashi wrote:
> >> @@ -23,6 +23,7 @@
> >>  #include 
> >>  #include 
> >>  #include "openvswitch/types.h"
> >> +#include 
> >>  #include 
> > 
> > This is the first I've ever heard of in_systm.h.  Is it a portable
> > header file?  It is not in SUSv4, although I do see it on my GNU/Linux
> > host.
> 
> i don't know.
> 
> i guess it's available on many of systems because it's ancient.

OK.

> NetBSD-6's ip.h requires in_systm.h included beforehand.
> i can put it in ifdef __NetBSD__ if you worry.

I was more curious than worried.  It's fine as-is, since it is easy to
fix later if it causes a problem.

Thanks,

Ben.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 05/18] include strings.h for strcasecmp.

2013-01-31 Thread Ben Pfaff
On Fri, Feb 01, 2013 at 10:59:51AM +0900, YAMAMOTO Takashi wrote:
> hi,
> 
> > On Thu, Jan 31, 2013 at 07:49:39PM +0900, YAMAMOTO Takashi wrote:
> >> From: YAMAMOTO Takashi 
> >> 
> >> Signed-off-by: YAMAMOTO Takashi 
> > 
> > I see many uses of strcasecmp() in the tree:
> > 
> > blp@blp:~/nicira/ovs(0)$ git --no-pager grep -l strcasecmp
> > lib/bundle.c
> > lib/cfm.c
> > lib/meta-flow.c
> > lib/multipath.c
> > lib/odp-util.c
> > lib/ofp-parse.c
> > lib/ofp-util.c
> > lib/vlog.c
> > utilities/ovs-ofctl.c
> > utilities/ovs-vsctl.c
> > vswitchd/bridge.c
> > 
> > but only one use of strings.h:
> > 
> > lib/dpif-linux.c
> > 
> > I am surprised that your patch only adds one #include.  Why is that?
> 
> because only this one made gcc complain on my environment
> and i don't know ovs's header inclusion policy.
> for other places some other headers indirectly pulled it, i guess.

OK.

Thanks,

Ben.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 02/18] deal with platforms where backtrace() is in a different library than libc.

2013-01-31 Thread Ben Pfaff
On Fri, Feb 01, 2013 at 11:25:35AM +0900, YAMAMOTO Takashi wrote:
> > On Thu, Jan 31, 2013 at 07:49:36PM +0900, YAMAMOTO Takashi wrote:
> >> From: YAMAMOTO Takashi 
> >> 
> >> execinfo for NetBSD and ubacktrace for uClibc.
> >> i don't know if the latter is relevant to Open vSwitch, though.
> >> 
> >> Signed-off-by: YAMAMOTO Takashi 
> > 
> > I didn't know that backtrace() was more widely available than glibc.
> > Does this patch mean that NetBSD makes a backtrace function matching the
> > following description available via libbacktrace?  (I can see from the
> > web that this is true for uclibc via libubacktrace.)
> 
> NetBSD-current has the function in libexecinfo and it seems reasonably
> compatible.  (see the end of this mail)

Thanks for the information, I didn't know that before.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 13/18] add minimal NetBSD support

2013-01-31 Thread Ben Pfaff
On Fri, Feb 01, 2013 at 11:35:26AM +0900, YAMAMOTO Takashi wrote:
> >> -#ifdef __FreeBSD__
> >> -#define FREE_BSD 1
> >> +#if defined(__FreeBSD__) || defined(__NetBSD__)
> >> +#define FREEBSD_OR_NETBSD 1
> >>  #else
> >> -#define FREE_BSD 0
> >> +#define FREEBSD_OR_NETBSD 0
> >>  #endif
> > 
> > It might be more readable to just use "BSD" in place of
> > FREEBSD_OR_NETBSD, which is a bit long.
> 
> i hesitate to use "BSD" only for FreeBSD and NetBSD given that
> there are too many BSD variants in the world.
> 
> probably a more meaningful name like REGISTER_TUNNEL is better
> in the regard of readability?

OK, that seems reasonable, thanks.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 16/18] implement get_stats for NetBSD

2013-01-31 Thread Ben Pfaff
On Fri, Feb 01, 2013 at 11:38:50AM +0900, YAMAMOTO Takashi wrote:
> > On Thu, Jan 31, 2013 at 07:49:50PM +0900, YAMAMOTO Takashi wrote:
> > Is there a reason not to squash this patch (and the previous one) into
> > the earlier patch that modified netdev-bsd?  I do not see anything that
> > keeps it conceptually distinct from that patch.
> 
> no reason.  it just reflected my development history.
> do you prefer to fold them into one?

I slightly prefer them folded.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 00/18] NetBSD support

2013-01-31 Thread Ben Pfaff
On Fri, Feb 01, 2013 at 10:46:52AM +0900, YAMAMOTO Takashi wrote:
> > On Thu, Jan 31, 2013 at 07:49:34PM +0900, YAMAMOTO Takashi wrote:
> >> NetBSD support
> > 
> > Thanks a lot!  Ed Maste and I made some comments.  I hope that you will
> > consider them and then repost a revised series.
> 
> thanks for reviewing!

You're welcome, thanks for the clearly written series.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 14/18] keep "kernel name" for each netdev

2013-01-31 Thread Ben Pfaff
On Fri, Feb 01, 2013 at 10:53:10AM +0900, YAMAMOTO Takashi wrote:
> > On Thu, Jan 31, 2013 at 07:49:48PM +0900, YAMAMOTO Takashi wrote:
> >> From: YAMAMOTO Takashi 
> >> 
> >> where interface renaming is not supported (NetBSD), remember both of
> >> our netdev name and the correspoinding kernel name separately.
> >> the latter is necessary to talk with kernel using interface names.
> >> eg. ifioctls, bpf
> >> 
> >> XXX there should be a proper way to query kernel name.
> >> 
> >> Signed-off-by: YAMAMOTO Takashi 
> > 
> > So is the issue here that on NetBSD one cannot specify the name for a
> > new tap device?  The kernel always assigns its own name?  Then there
> > might be an extra problem.  Consider this case:
> 
> yes.  kernel picks a name (eg. tap1) and a user can't changed it.

OK.

> > 
> > * ovs-vswitchd starts up and creates some tap devices.  It knows
> >   the mapping between the user-requested name and the kernel
> >   name.
> > 
> > * Admin restarts ovs-vswitchd.
> > 
> > * New instance of ovs-vswitchd creates new tap devices because
> >   it does not know the kernel names of the existing ones and
> >   does not have a way to discover them.  The existing ones are
> >   effectively leaked.
> 
> there isn't a leak as ovs-vswitchd destroys the old one when stopping.

OK.  But this may cause a different inconvenience to the user: if the
user configured an IP address on the tap device, then restarting
ovs-vswitchd will drop that IP address and the user will have to add it
back.  This doesn't happen with the Linux kernel datapath, and I don't
think it happens with the Linux userspace datapath (I can't say for the
FreeBSD one).  But if that issue does not bother you, then I will not
worry about it.

> > 
> > Furthermore, it seems likely that the tap devices created this way will
> > not actually be useful to the user, because the user does not have any
> > way, either, to discover the mapping between his names and the kernel
> > names.  Thus, the user doesn't know how to use the kernel tap devices.
> 
> right.  it's what XXX in the commit log says.
> 
> it would be useful if the user can query the corresponding kernel name
> using one of ovs-xxxctl.  having a way to query netdev implementation
> specific data in general might be useful.  any idea?

A command accessible via ovs-appctl would be the easiest way, I guess.
If you look for calls to unixctl_command_register(), then you can see
some examples.

> > I am not sure that OVS-created tap devices are that useful anyway.  I've
> > thought for some time of removing them from OVS entirely.  But it seems
> > that they are likely to be even less useful on netbsd.  Should we simply
> > not support them there?
> 
> it would be good to have a way to create a bridge without a local port.
> (is there any?)

There is currently no way.  There is a significant amount of code that
assumes every bridge has a local port, so it might be difficult to
change this.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 14/18] keep "kernel name" for each netdev

2013-01-31 Thread YAMAMOTO Takashi
hi,

>> > * ovs-vswitchd starts up and creates some tap devices.  It knows
>> >   the mapping between the user-requested name and the kernel
>> >   name.
>> > 
>> > * Admin restarts ovs-vswitchd.
>> > 
>> > * New instance of ovs-vswitchd creates new tap devices because
>> >   it does not know the kernel names of the existing ones and
>> >   does not have a way to discover them.  The existing ones are
>> >   effectively leaked.
>> 
>> there isn't a leak as ovs-vswitchd destroys the old one when stopping.
> 
> OK.  But this may cause a different inconvenience to the user: if the
> user configured an IP address on the tap device, then restarting
> ovs-vswitchd will drop that IP address and the user will have to add it
> back.  This doesn't happen with the Linux kernel datapath, and I don't
> think it happens with the Linux userspace datapath (I can't say for the
> FreeBSD one).  But if that issue does not bother you, then I will not
> worry about it.

are you sure about the linux userspace datapath behaviour?
a casual looking at linux's Documentation/networking/tuntap.txt and
netdev-linux.c made me think otherwise.

YAMAMOTO Takashi
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev


Re: [ovs-dev] [PATCH 14/18] keep "kernel name" for each netdev

2013-01-31 Thread Ben Pfaff
On Fri, Feb 01, 2013 at 12:23:00PM +0900, YAMAMOTO Takashi wrote:
> hi,
> 
> >> > * ovs-vswitchd starts up and creates some tap devices.  It knows
> >> >   the mapping between the user-requested name and the kernel
> >> >   name.
> >> > 
> >> > * Admin restarts ovs-vswitchd.
> >> > 
> >> > * New instance of ovs-vswitchd creates new tap devices because
> >> >   it does not know the kernel names of the existing ones and
> >> >   does not have a way to discover them.  The existing ones are
> >> >   effectively leaked.
> >> 
> >> there isn't a leak as ovs-vswitchd destroys the old one when stopping.
> > 
> > OK.  But this may cause a different inconvenience to the user: if the
> > user configured an IP address on the tap device, then restarting
> > ovs-vswitchd will drop that IP address and the user will have to add it
> > back.  This doesn't happen with the Linux kernel datapath, and I don't
> > think it happens with the Linux userspace datapath (I can't say for the
> > FreeBSD one).  But if that issue does not bother you, then I will not
> > worry about it.
> 
> are you sure about the linux userspace datapath behaviour?
> a casual looking at linux's Documentation/networking/tuntap.txt and
> netdev-linux.c made me think otherwise.

Hmm.  I think you are right.  This is not the way I remember this code
working, but it is pretty old.  Never mind.
___
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev