Merge commit '10a89ef04df5669c5cdd02f786150a7ab8454e01'
authorGiuseppe Lettieri <g.lettieri@iet.unipi.it>
Sat, 6 Jul 2013 16:57:17 +0000 (18:57 +0200)
committerGiuseppe Lettieri <g.lettieri@iet.unipi.it>
Sat, 6 Jul 2013 16:57:17 +0000 (18:57 +0200)
1  2 
Makefile.am
lib/automake.mk
lib/dpif-netdev.c
lib/dpif-provider.h
lib/dpif.c
lib/netdev-provider.h
lib/netdev.c

diff --combined Makefile.am
@@@ -55,6 -55,7 +55,7 @@@ EXTRA_DIST = 
        NOTICE \
        OPENFLOW-1.1+ \
        PORTING \
+       README-OFTest \
        README-gcov \
        README-lisp \
        REPORTING-BUGS \
@@@ -107,7 -108,6 +108,7 @@@ ro_shell = printf '\043 Generated autom
  
  SUFFIXES += .in
  .in:
 +      @mkdir -p $$(dirname $@)
        $(PERL) $(srcdir)/build-aux/soexpand.pl -I$(srcdir) < $< | \
            sed \
                -e 's,[@]PKIDIR[@],$(PKIDIR),g' \
@@@ -149,7 -149,7 +150,7 @@@ dist-hook-git: distfile
          (cd datapath && $(MAKE) distfiles);                               \
          (cat distfiles; sed 's|^|datapath/|' datapath/distfiles) |        \
            sort -u > all-distfiles;                                        \
 -        (cd $(srcdir) && git ls-files) | grep -v '\.gitignore$$' |        \
 +        (cd $(srcdir) && git ls-files) | grep -vFf $(srcdir)/.non-distfiles |     \
            sort -u > all-gitfiles;                                         \
          comm -1 -3 all-distfiles all-gitfiles > missing-distfiles;        \
          if test -s missing-distfiles; then                                \
@@@ -185,17 -185,17 +186,17 @@@ config-h-check
        fi
  .PHONY: config-h-check
  
- # Check that "struct vlog_ratelimit" is always declared "static".
- ALL_LOCAL += rate-limit-check
rate-limit-check:
+ # Check that certain data structures are always declared "static".
+ ALL_LOCAL += static-check
static-check:
        @if test -e $(srcdir)/.git && (git --version) >/dev/null 2>&1 && \
-           git --no-pager grep -n -E '^[       ]+struct vlog_rate_limit.*=' $(srcdir); \
+           git --no-pager grep -n -E '^[       ]+(struct vlog_rate_limit|pthread_once_t|struct ovsthread_once).*=' $(srcdir); \
           then \
            echo "See above for list of violations of the rule that "; \
-           echo "'struct vlog_rate_limit' must always be 'static'"; \
+           echo "certain data structures must always be 'static'"; \
            exit 1; \
         fi
- .PHONY: rate-limit-check
+ .PHONY: static-check
  
  # Check that assert.h is not used outside a whitelist of files.
  ALL_LOCAL += check-assert-h-usage
@@@ -259,5 -259,4 +260,5 @@@ include rhel/automake.m
  include xenserver/automake.mk
  include python/automake.mk
  include python/compat/automake.mk
 +include planetlab/automake.mk
  include tutorial/automake.mk
diff --combined lib/automake.mk
@@@ -1,4 -1,4 +1,4 @@@
- # Copyright (C) 2009, 2010, 2011, 2012 Nicira, Inc.
+ # Copyright (C) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
  #
  # Copying and distribution of this file, with or without modification,
  # are permitted in any medium without royalty provided the copyright
@@@ -57,6 -57,8 +57,8 @@@ lib_libopenvswitch_a_SOURCES = 
        lib/flow.h \
        lib/hash.c \
        lib/hash.h \
+       lib/hindex.c \
+       lib/hindex.h \
        lib/hmap.c \
        lib/hmap.h \
        lib/hmapx.c \
@@@ -69,8 -71,6 +71,6 @@@
        lib/jsonrpc.h \
        lib/lacp.c \
        lib/lacp.h \
-       lib/leak-checker.c \
-       lib/leak-checker.h \
        lib/learn.c \
        lib/learn.h \
        lib/learning-switch.c \
@@@ -90,8 -90,6 +90,8 @@@
        lib/multipath.c \
        lib/multipath.h \
        lib/netdev-dummy.c \
 +      lib/netdev-tunnel.c \
 +      lib/netdev-pltap.c \
        lib/netdev-provider.h \
        lib/netdev-vport.c \
        lib/netdev-vport.h \
        lib/netlink.h \
        lib/nx-match.c \
        lib/nx-match.h \
+       lib/odp-execute.c \
+       lib/odp-execute.h \
        lib/odp-util.c \
        lib/odp-util.h \
        lib/ofp-actions.c \
        lib/ofp-version-opt.c \
        lib/ofpbuf.c \
        lib/ofpbuf.h \
+       lib/ovs-atomic-c11.h \
+       lib/ovs-atomic-gcc4+.c \
+       lib/ovs-atomic-gcc4+.h \
+       lib/ovs-atomic-gcc4.7+.h \
+       lib/ovs-atomic-pthreads.c \
+       lib/ovs-atomic-pthreads.h \
+       lib/ovs-atomic.h \
+       lib/ovs-thread.c \
+       lib/ovs-thread.h \
        lib/ovsdb-data.c \
        lib/ovsdb-data.h \
        lib/ovsdb-error.c \
        lib/timeval.h \
        lib/token-bucket.c \
        lib/token-bucket.h \
 +      lib/tunalloc.c \
 +      lib/tunalloc.h \
        lib/type-props.h \
        lib/unaligned.h \
        lib/unicode.c \
@@@ -293,7 -300,6 +304,6 @@@ MAN_FRAGMENTS += 
        lib/coverage-unixctl.man \
        lib/daemon.man \
        lib/daemon-syn.man \
-       lib/leak-checker.man \
        lib/memory-unixctl.man \
        lib/ofp-version.man \
        lib/ovs.tmac \
@@@ -339,9 -345,12 +349,12 @@@ lib/dirs.c: lib/dirs.c.in Makefil
        mv lib/dirs.c.tmp lib/dirs.c
  
  $(srcdir)/lib/ofp-errors.inc: \
-       lib/ofp-errors.h $(srcdir)/build-aux/extract-ofp-errors
+       lib/ofp-errors.h include/openflow/openflow-common.h \
+       $(srcdir)/build-aux/extract-ofp-errors
        $(run_python) $(srcdir)/build-aux/extract-ofp-errors \
-               $(srcdir)/lib/ofp-errors.h > $@.tmp && mv $@.tmp $@
+               $(srcdir)/lib/ofp-errors.h \
+               $(srcdir)/include/openflow/openflow-common.h > $@.tmp
+       mv $@.tmp $@
  $(srcdir)/lib/ofp-errors.c: $(srcdir)/lib/ofp-errors.inc
  EXTRA_DIST += build-aux/extract-ofp-errors lib/ofp-errors.inc
  
diff --combined lib/dpif-netdev.c
@@@ -42,6 -42,7 +42,7 @@@
  #include "netdev.h"
  #include "netdev-vport.h"
  #include "netlink.h"
+ #include "odp-execute.h"
  #include "odp-util.h"
  #include "ofp-print.h"
  #include "ofpbuf.h"
@@@ -103,7 -104,7 +104,7 @@@ struct dp_netdev 
  
  /* A port in a netdev-based datapath. */
  struct dp_netdev_port {
-     int port_no;                /* Index into dp_netdev's 'ports'. */
+     odp_port_t port_no;         /* Index into dp_netdev's 'ports'. */
      struct list node;           /* Element in dp_netdev's 'port_list'. */
      struct netdev *netdev;
      struct netdev_saved_flags *sf;
@@@ -140,15 -141,15 +141,15 @@@ static struct shash dp_netdevs = SHASH_
  /* Maximum port MTU seen so far. */
  static int max_mtu = ETH_PAYLOAD_MAX;
  
- static int get_port_by_number(struct dp_netdev *, uint32_t port_no,
+ static int get_port_by_number(struct dp_netdev *, odp_port_t port_no,
                                struct dp_netdev_port **portp);
  static int get_port_by_name(struct dp_netdev *, const char *devname,
                              struct dp_netdev_port **portp);
  static void dp_netdev_free(struct dp_netdev *);
  static void dp_netdev_flow_flush(struct dp_netdev *);
  static int do_add_port(struct dp_netdev *, const char *devname,
-                        const char *type, uint32_t port_no);
- static int do_del_port(struct dp_netdev *, uint32_t port_no);
+                        const char *type, odp_port_t port_no);
+ static int do_del_port(struct dp_netdev *, odp_port_t port_no);
  static int dpif_netdev_open(const struct dpif_class *, const char *name,
                              bool create, struct dpif **);
  static int dp_netdev_output_userspace(struct dp_netdev *, const struct ofpbuf *,
@@@ -158,6 -159,10 +159,10 @@@ static void dp_netdev_execute_actions(s
                                        struct ofpbuf *, struct flow *,
                                        const struct nlattr *actions,
                                        size_t actions_len);
+ static void dp_netdev_port_input(struct dp_netdev *dp,
+                                  struct dp_netdev_port *port,
+                                  struct ofpbuf *packet, uint32_t skb_priority,
+                                  uint32_t skb_mark, const struct flow_tnl *tnl);
  
  static struct dpif_netdev *
  dpif_netdev_cast(const struct dpif *dpif)
@@@ -189,17 -194,10 +194,17 @@@ dpif_netdev_class_is_dummy(const struc
      return class != &dpif_netdev_class;
  }
  
 +static bool
 +dpif_netdev_class_is_planetlab(const struct dpif_class *class)
 +{
 +    return class == &dpif_planetlab_class;
 +}
 +
  static const char *
  dpif_netdev_port_open_type(const struct dpif_class *class, const char *type)
  {
      return strcmp(type, "internal") ? type
 +                  : dpif_netdev_class_is_planetlab(class) ? "pltap"
                    : dpif_netdev_class_is_dummy(class) ? "dummy"
                    : "tap";
  }
@@@ -220,13 -218,14 +225,15 @@@ create_dpif_netdev(struct dp_netdev *dp
      return &dpif->dpif;
  }
  
- static int
+ /* Choose an unused, non-zero port number and return it on success.
+  * Return ODPP_NONE on failure. */
+ static odp_port_t
  choose_port(struct dp_netdev *dp, const char *name)
  {
-     int port_no;
+     uint32_t port_no;
  
 -    if (dp->class != &dpif_netdev_class) {
 +    if (dp->class != &dpif_netdev_class && 
 +        dp->class != &dpif_planetlab_class) {
          const char *p;
          int start_no = 0;
  
                  port_no = start_no + strtol(p, NULL, 10);
                  if (port_no > 0 && port_no < MAX_PORTS
                      && !dp->ports[port_no]) {
-                     return port_no;
+                     return u32_to_odp(port_no);
                  }
                  break;
              }
  
      for (port_no = 1; port_no < MAX_PORTS; port_no++) {
          if (!dp->ports[port_no]) {
-             return port_no;
+             return u32_to_odp(port_no);
          }
      }
  
-     return -1;
+     return ODPP_NONE;
  }
  
  static int
@@@ -278,7 -277,7 +285,7 @@@ create_dp_netdev(const char *name, cons
      hmap_init(&dp->flow_table);
      list_init(&dp->port_list);
  
-     error = do_add_port(dp, name, "internal", OVSP_LOCAL);
+     error = do_add_port(dp, name, "internal", ODPP_LOCAL);
      if (error) {
          dp_netdev_free(dp);
          return error;
@@@ -382,7 -381,7 +389,7 @@@ dpif_netdev_get_stats(const struct dpi
  
  static int
  do_add_port(struct dp_netdev *dp, const char *devname, const char *type,
-             uint32_t port_no)
+             odp_port_t port_no)
  {
      struct netdev_saved_flags *sf;
      struct dp_netdev_port *port;
      if (error
          && !(error == EOPNOTSUPP && dpif_netdev_class_is_dummy(dp->class))) {
          VLOG_ERR("%s: cannot receive packets on this network device (%s)",
-                  devname, strerror(errno));
+                  devname, ovs_strerror(errno));
          netdev_close(netdev);
          return error;
      }
      }
  
      list_push_back(&dp->port_list, &port->node);
-     dp->ports[port_no] = port;
+     dp->ports[odp_to_u32(port_no)] = port;
      dp->serial++;
  
      return 0;
  
  static int
  dpif_netdev_port_add(struct dpif *dpif, struct netdev *netdev,
-                      uint32_t *port_nop)
+                      odp_port_t *port_nop)
  {
      struct dp_netdev *dp = get_dp_netdev(dpif);
-     int port_no;
-     if (*port_nop != UINT32_MAX) {
-         if (*port_nop >= MAX_PORTS) {
+     char namebuf[NETDEV_VPORT_NAME_BUFSIZE];
+     const char *dpif_port;
+     odp_port_t port_no;
+     dpif_port = netdev_vport_get_dpif_port(netdev, namebuf, sizeof namebuf);
+     if (*port_nop != ODPP_NONE) {
+         uint32_t port_idx = odp_to_u32(*port_nop);
+         if (port_idx >= MAX_PORTS) {
              return EFBIG;
-         } else if (dp->ports[*port_nop]) {
+         } else if (dp->ports[port_idx]) {
              return EBUSY;
          }
          port_no = *port_nop;
      } else {
-         port_no = choose_port(dp, netdev_vport_get_dpif_port(netdev));
+         port_no = choose_port(dp, dpif_port);
      }
-     if (port_no >= 0) {
+     if (port_no != ODPP_NONE) {
          *port_nop = port_no;
-         return do_add_port(dp, netdev_vport_get_dpif_port(netdev),
-                            netdev_get_type(netdev), port_no);
+         return do_add_port(dp, dpif_port, netdev_get_type(netdev), port_no);
      }
      return EFBIG;
  }
  
  static int
- dpif_netdev_port_del(struct dpif *dpif, uint32_t port_no)
+ dpif_netdev_port_del(struct dpif *dpif, odp_port_t port_no)
  {
      struct dp_netdev *dp = get_dp_netdev(dpif);
-     return port_no == OVSP_LOCAL ? EINVAL : do_del_port(dp, port_no);
+     return (port_no == ODPP_LOCAL ?
+                            EINVAL : do_del_port(dp, port_no));
  }
  
  static bool
- is_valid_port_number(uint32_t port_no)
+ is_valid_port_number(odp_port_t port_no)
  {
-     return port_no < MAX_PORTS;
+     return odp_to_u32(port_no) < MAX_PORTS;
  }
  
  static int
  get_port_by_number(struct dp_netdev *dp,
-                    uint32_t port_no, struct dp_netdev_port **portp)
+                    odp_port_t port_no, struct dp_netdev_port **portp)
  {
      if (!is_valid_port_number(port_no)) {
          *portp = NULL;
          return EINVAL;
      } else {
-         *portp = dp->ports[port_no];
+         *portp = dp->ports[odp_to_u32(port_no)];
          return *portp ? 0 : ENOENT;
      }
  }
@@@ -496,7 -499,7 +507,7 @@@ get_port_by_name(struct dp_netdev *dp
      struct dp_netdev_port *port;
  
      LIST_FOR_EACH (port, node, &dp->port_list) {
-         if (!strcmp(netdev_vport_get_dpif_port(port->netdev), devname)) {
+         if (!strcmp(netdev_get_name(port->netdev), devname)) {
              *portp = port;
              return 0;
          }
  }
  
  static int
- do_del_port(struct dp_netdev *dp, uint32_t port_no)
+ do_del_port(struct dp_netdev *dp, odp_port_t port_no)
  {
      struct dp_netdev_port *port;
      int error;
      }
  
      list_remove(&port->node);
-     dp->ports[port->port_no] = NULL;
+     dp->ports[odp_to_u32(port_no)] = NULL;
      dp->serial++;
  
      netdev_close(port->netdev);
@@@ -532,13 -535,13 +543,13 @@@ static voi
  answer_port_query(const struct dp_netdev_port *port,
                    struct dpif_port *dpif_port)
  {
-     dpif_port->name = xstrdup(netdev_vport_get_dpif_port(port->netdev));
+     dpif_port->name = xstrdup(netdev_get_name(port->netdev));
      dpif_port->type = xstrdup(port->type);
      dpif_port->port_no = port->port_no;
  }
  
  static int
- dpif_netdev_port_query_by_number(const struct dpif *dpif, uint32_t port_no,
+ dpif_netdev_port_query_by_number(const struct dpif *dpif, odp_port_t port_no,
                                   struct dpif_port *dpif_port)
  {
      struct dp_netdev *dp = get_dp_netdev(dpif);
@@@ -567,10 -570,10 +578,10 @@@ dpif_netdev_port_query_by_name(const st
      return error;
  }
  
- static int
+ static odp_port_t
  dpif_netdev_get_max_ports(const struct dpif *dpif OVS_UNUSED)
  {
-     return MAX_PORTS;
+     return u32_to_odp(MAX_PORTS);
  }
  
  static void
@@@ -600,7 -603,7 +611,7 @@@ dpif_netdev_flow_flush(struct dpif *dpi
  }
  
  struct dp_netdev_port_state {
-     uint32_t port_no;
+     odp_port_t port_no;
      char *name;
  };
  
@@@ -617,17 -620,18 +628,18 @@@ dpif_netdev_port_dump_next(const struc
  {
      struct dp_netdev_port_state *state = state_;
      struct dp_netdev *dp = get_dp_netdev(dpif);
-     uint32_t port_no;
+     uint32_t port_idx;
  
-     for (port_no = state->port_no; port_no < MAX_PORTS; port_no++) {
-         struct dp_netdev_port *port = dp->ports[port_no];
+     for (port_idx = odp_to_u32(state->port_no);
+          port_idx < MAX_PORTS; port_idx++) {
+         struct dp_netdev_port *port = dp->ports[port_idx];
          if (port) {
              free(state->name);
-             state->name = xstrdup(netdev_vport_get_dpif_port(port->netdev));
+             state->name = xstrdup(netdev_get_name(port->netdev));
              dpif_port->name = state->name;
              dpif_port->type = port->type;
              dpif_port->port_no = port->port_no;
-             state->port_no = port_no + 1;
+             state->port_no = u32_to_odp(port_idx + 1);
              return 0;
          }
      }
@@@ -709,9 -713,7 +721,7 @@@ dpif_netdev_flow_from_nlattrs(const str
          return EINVAL;
      }
  
-     if (flow->in_port < OFPP_MAX
-         ? flow->in_port >= MAX_PORTS
-         : flow->in_port != OFPP_LOCAL && flow->in_port != OFPP_NONE) {
+     if (!is_valid_port_number(flow->in_port.odp_port)) {
          return EINVAL;
      }
  
@@@ -880,6 -882,7 +890,7 @@@ dpif_netdev_flow_dump_start(const struc
  static int
  dpif_netdev_flow_dump_next(const struct dpif *dpif, void *state_,
                             const struct nlattr **key, size_t *key_len,
+                            const struct nlattr **mask, size_t *mask_len,
                             const struct nlattr **actions, size_t *actions_len,
                             const struct dpif_flow_stats **stats)
  {
          struct ofpbuf buf;
  
          ofpbuf_use_stack(&buf, &state->keybuf, sizeof state->keybuf);
-         odp_flow_key_from_flow(&buf, &flow->key, flow->key.in_port);
+         odp_flow_key_from_flow(&buf, &flow->key, flow->key.in_port.odp_port);
  
          *key = buf.data;
          *key_len = buf.size;
      }
  
+     if (mask) {
+         *mask = NULL;
+         *mask_len = 0;
+     }
      if (actions) {
          free(state->actions);
          state->actions = xmemdup(flow->actions, flow->actions_len);
@@@ -949,7 -957,7 +965,7 @@@ dpif_netdev_execute(struct dpif *dpif, 
      ofpbuf_reserve(&copy, DP_NETDEV_HEADROOM);
      ofpbuf_put(&copy, execute->packet->data, execute->packet->size);
  
-     flow_extract(&copy, 0, 0, NULL, -1, &key);
+     flow_extract(&copy, 0, 0, NULL, NULL, &key);
      error = dpif_netdev_flow_from_nlattrs(execute->key, execute->key_len,
                                            &key);
      if (!error) {
@@@ -1039,15 -1047,18 +1055,18 @@@ dp_netdev_flow_used(struct dp_netdev_fl
  
  static void
  dp_netdev_port_input(struct dp_netdev *dp, struct dp_netdev_port *port,
-                      struct ofpbuf *packet)
+                      struct ofpbuf *packet, uint32_t skb_priority,
+                      uint32_t skb_mark, const struct flow_tnl *tnl)
  {
      struct dp_netdev_flow *flow;
      struct flow key;
+     union flow_in_port in_port_;
  
      if (packet->size < ETH_HEADER_LEN) {
          return;
      }
-     flow_extract(packet, 0, 0, NULL, port->port_no, &key);
+     in_port_.odp_port = port->port_no;
+     flow_extract(packet, skb_priority, skb_mark, tnl, &in_port_, &key);
      flow = dp_netdev_lookup_flow(dp, &key);
      if (flow) {
          dp_netdev_flow_used(flow, packet);
@@@ -1078,12 -1089,12 +1097,12 @@@ dpif_netdev_run(struct dpif *dpif
  
          error = port->rx ? netdev_rx_recv(port->rx, &packet) : EOPNOTSUPP;
          if (!error) {
-             dp_netdev_port_input(dp, port, &packet);
+             dp_netdev_port_input(dp, port, &packet, 0, 0, NULL);
          } else if (error != EAGAIN && error != EOPNOTSUPP) {
              static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
              VLOG_ERR_RL(&rl, "error receiving data from %s: %s",
-                         netdev_vport_get_dpif_port(port->netdev),
-                         strerror(error));
+                         netdev_get_name(port->netdev), ovs_strerror(error));
          }
      }
      ofpbuf_uninit(&packet);
@@@ -1103,18 -1114,9 +1122,9 @@@ dpif_netdev_wait(struct dpif *dpif
  }
  
  static void
- dp_netdev_set_dl(struct ofpbuf *packet, const struct ovs_key_ethernet *eth_key)
- {
-     struct eth_header *eh = packet->l2;
-     memcpy(eh->eth_src, eth_key->eth_src, sizeof eh->eth_src);
-     memcpy(eh->eth_dst, eth_key->eth_dst, sizeof eh->eth_dst);
- }
- static void
- dp_netdev_output_port(struct dp_netdev *dp, struct ofpbuf *packet,
-                       uint32_t out_port)
+ dp_netdev_output_port(void *dp_, struct ofpbuf *packet, uint32_t out_port)
  {
+     struct dp_netdev *dp = dp_;
      struct dp_netdev_port *p = dp->ports[out_port];
      if (p) {
          netdev_send(p->netdev, packet);
@@@ -1143,7 -1145,7 +1153,7 @@@ dp_netdev_output_userspace(struct dp_ne
          ofpbuf_init(buf, buf_size);
  
          /* Put ODP flow. */
-         odp_flow_key_from_flow(buf, flow, flow->in_port);
+         odp_flow_key_from_flow(buf, flow, flow->in_port.odp_port);
          upcall->key = buf->data;
          upcall->key_len = buf->size;
  
  }
  
  static void
- dp_netdev_sample(struct dp_netdev *dp,
-                  struct ofpbuf *packet, struct flow *key,
-                  const struct nlattr *action)
- {
-     const struct nlattr *subactions = NULL;
-     const struct nlattr *a;
-     size_t left;
-     NL_NESTED_FOR_EACH_UNSAFE (a, left, action) {
-         int type = nl_attr_type(a);
-         switch ((enum ovs_sample_attr) type) {
-         case OVS_SAMPLE_ATTR_PROBABILITY:
-             if (random_uint32() >= nl_attr_get_u32(a)) {
-                 return;
-             }
-             break;
-         case OVS_SAMPLE_ATTR_ACTIONS:
-             subactions = a;
-             break;
-         case OVS_SAMPLE_ATTR_UNSPEC:
-         case __OVS_SAMPLE_ATTR_MAX:
-         default:
-             NOT_REACHED();
-         }
-     }
-     dp_netdev_execute_actions(dp, packet, key, nl_attr_get(subactions),
-                               nl_attr_get_size(subactions));
- }
- static void
- dp_netdev_action_userspace(struct dp_netdev *dp,
-                           struct ofpbuf *packet, struct flow *key,
-                           const struct nlattr *a)
+ dp_netdev_action_userspace(void *dp, struct ofpbuf *packet,
+                            const struct flow *key,
+                            const struct nlattr *userdata)
  {
-     const struct nlattr *userdata;
-     userdata = nl_attr_find_nested(a, OVS_USERSPACE_ATTR_USERDATA);
      dp_netdev_output_userspace(dp, packet, DPIF_UC_ACTION, key, userdata);
  }
  
- static void
- execute_set_action(struct ofpbuf *packet, const struct nlattr *a)
- {
-     enum ovs_key_attr type = nl_attr_type(a);
-     const struct ovs_key_ipv4 *ipv4_key;
-     const struct ovs_key_ipv6 *ipv6_key;
-     const struct ovs_key_tcp *tcp_key;
-     const struct ovs_key_udp *udp_key;
-     switch (type) {
-     case OVS_KEY_ATTR_PRIORITY:
-     case OVS_KEY_ATTR_SKB_MARK:
-     case OVS_KEY_ATTR_TUNNEL:
-         /* not implemented */
-         break;
-     case OVS_KEY_ATTR_ETHERNET:
-         dp_netdev_set_dl(packet,
-                    nl_attr_get_unspec(a, sizeof(struct ovs_key_ethernet)));
-         break;
-     case OVS_KEY_ATTR_IPV4:
-         ipv4_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_ipv4));
-         packet_set_ipv4(packet, ipv4_key->ipv4_src, ipv4_key->ipv4_dst,
-                         ipv4_key->ipv4_tos, ipv4_key->ipv4_ttl);
-         break;
-     case OVS_KEY_ATTR_IPV6:
-         ipv6_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_ipv6));
-         packet_set_ipv6(packet, ipv6_key->ipv6_proto, ipv6_key->ipv6_src,
-                         ipv6_key->ipv6_dst, ipv6_key->ipv6_tclass,
-                         ipv6_key->ipv6_label, ipv6_key->ipv6_hlimit);
-         break;
-     case OVS_KEY_ATTR_TCP:
-         tcp_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_tcp));
-         packet_set_tcp_port(packet, tcp_key->tcp_src, tcp_key->tcp_dst);
-         break;
-      case OVS_KEY_ATTR_UDP:
-         udp_key = nl_attr_get_unspec(a, sizeof(struct ovs_key_udp));
-         packet_set_udp_port(packet, udp_key->udp_src, udp_key->udp_dst);
-         break;
-      case OVS_KEY_ATTR_MPLS:
-          set_mpls_lse(packet, nl_attr_get_be32(a));
-          break;
-      case OVS_KEY_ATTR_UNSPEC:
-      case OVS_KEY_ATTR_ENCAP:
-      case OVS_KEY_ATTR_ETHERTYPE:
-      case OVS_KEY_ATTR_IN_PORT:
-      case OVS_KEY_ATTR_VLAN:
-      case OVS_KEY_ATTR_ICMP:
-      case OVS_KEY_ATTR_ICMPV6:
-      case OVS_KEY_ATTR_ARP:
-      case OVS_KEY_ATTR_ND:
-      case __OVS_KEY_ATTR_MAX:
-      default:
-         NOT_REACHED();
-     }
- }
  static void
  dp_netdev_execute_actions(struct dp_netdev *dp,
                            struct ofpbuf *packet, struct flow *key,
                            const struct nlattr *actions,
                            size_t actions_len)
  {
-     const struct nlattr *a;
-     unsigned int left;
-     NL_ATTR_FOR_EACH_UNSAFE (a, left, actions, actions_len) {
-         int type = nl_attr_type(a);
-         switch ((enum ovs_action_attr) type) {
-         case OVS_ACTION_ATTR_OUTPUT:
-             dp_netdev_output_port(dp, packet, nl_attr_get_u32(a));
-             break;
-         case OVS_ACTION_ATTR_USERSPACE:
-             dp_netdev_action_userspace(dp, packet, key, a);
-             break;
-         case OVS_ACTION_ATTR_PUSH_VLAN: {
-             const struct ovs_action_push_vlan *vlan = nl_attr_get(a);
-             eth_push_vlan(packet, vlan->vlan_tci);
-             break;
-         }
-         case OVS_ACTION_ATTR_POP_VLAN:
-             eth_pop_vlan(packet);
-             break;
-         case OVS_ACTION_ATTR_PUSH_MPLS: {
-             const struct ovs_action_push_mpls *mpls = nl_attr_get(a);
-             push_mpls(packet, mpls->mpls_ethertype, mpls->mpls_lse);
-             break;
-          }
-         case OVS_ACTION_ATTR_POP_MPLS:
-             pop_mpls(packet, nl_attr_get_be16(a));
-             break;
-         case OVS_ACTION_ATTR_SET:
-             execute_set_action(packet, nl_attr_get(a));
-             break;
-         case OVS_ACTION_ATTR_SAMPLE:
-             dp_netdev_sample(dp, packet, key, a);
-             break;
-         case OVS_ACTION_ATTR_UNSPEC:
-         case __OVS_ACTION_ATTR_MAX:
-             NOT_REACHED();
-         }
-     }
+     odp_execute_actions(dp, packet, key, actions, actions_len,
+                         dp_netdev_output_port, dp_netdev_action_userspace);
  }
  
 +#define DPIF_NETDEV_CLASS_FUNCTIONS                   \
 +    dpif_netdev_enumerate,                            \
 +    dpif_netdev_port_open_type,                               \
 +    dpif_netdev_open,                                 \
 +    dpif_netdev_close,                                        \
 +    dpif_netdev_destroy,                              \
 +    dpif_netdev_run,                                  \
 +    dpif_netdev_wait,                                 \
 +    dpif_netdev_get_stats,                            \
 +    dpif_netdev_port_add,                             \
 +    dpif_netdev_port_del,                             \
 +    dpif_netdev_port_query_by_number,                 \
 +    dpif_netdev_port_query_by_name,                   \
 +    dpif_netdev_get_max_ports,                                \
 +    NULL,                       /* port_get_pid */    \
 +    dpif_netdev_port_dump_start,                      \
 +    dpif_netdev_port_dump_next,                               \
 +    dpif_netdev_port_dump_done,                               \
 +    dpif_netdev_port_poll,                            \
 +    dpif_netdev_port_poll_wait,                               \
 +    dpif_netdev_flow_get,                             \
 +    dpif_netdev_flow_put,                             \
 +    dpif_netdev_flow_del,                             \
 +    dpif_netdev_flow_flush,                           \
 +    dpif_netdev_flow_dump_start,                      \
 +    dpif_netdev_flow_dump_next,                               \
 +    dpif_netdev_flow_dump_done,                               \
 +    dpif_netdev_execute,                              \
 +    NULL,                       /* operate */         \
 +    dpif_netdev_recv_set,                             \
 +    dpif_netdev_queue_to_priority,                    \
 +    dpif_netdev_recv,                                 \
 +    dpif_netdev_recv_wait,                            \
 +    dpif_netdev_recv_purge,                           \
 +
  const struct dpif_class dpif_netdev_class = {
      "netdev",
 -    dpif_netdev_enumerate,
 -    dpif_netdev_port_open_type,
 -    dpif_netdev_open,
 -    dpif_netdev_close,
 -    dpif_netdev_destroy,
 -    dpif_netdev_run,
 -    dpif_netdev_wait,
 -    dpif_netdev_get_stats,
 -    dpif_netdev_port_add,
 -    dpif_netdev_port_del,
 -    dpif_netdev_port_query_by_number,
 -    dpif_netdev_port_query_by_name,
 -    dpif_netdev_get_max_ports,
 -    NULL,                       /* port_get_pid */
 -    dpif_netdev_port_dump_start,
 -    dpif_netdev_port_dump_next,
 -    dpif_netdev_port_dump_done,
 -    dpif_netdev_port_poll,
 -    dpif_netdev_port_poll_wait,
 -    dpif_netdev_flow_get,
 -    dpif_netdev_flow_put,
 -    dpif_netdev_flow_del,
 -    dpif_netdev_flow_flush,
 -    dpif_netdev_flow_dump_start,
 -    dpif_netdev_flow_dump_next,
 -    dpif_netdev_flow_dump_done,
 -    dpif_netdev_execute,
 -    NULL,                       /* operate */
 -    dpif_netdev_recv_set,
 -    dpif_netdev_queue_to_priority,
 -    dpif_netdev_recv,
 -    dpif_netdev_recv_wait,
 -    dpif_netdev_recv_purge,
 +    DPIF_NETDEV_CLASS_FUNCTIONS
 +};
 +
 +const struct dpif_class dpif_planetlab_class = {
 +    "planetlab",
 +    DPIF_NETDEV_CLASS_FUNCTIONS
  };
  
  static void
@@@ -1409,4 -1257,3 +1273,4 @@@ dpif_dummy_register(bool override
  
      dpif_dummy_register__("dummy");
  }
 +
diff --combined lib/dpif-provider.h
@@@ -1,5 -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.
@@@ -127,10 -127,10 +127,10 @@@ struct dpif_class 
       * port number.  Returns EBUSY if caller attempted to choose a port
       * number, and it was in use. */
      int (*port_add)(struct dpif *dpif, struct netdev *netdev,
-                     uint32_t *port_no);
+                     odp_port_t *port_no);
  
      /* Removes port numbered 'port_no' from 'dpif'. */
-     int (*port_del)(struct dpif *dpif, uint32_t port_no);
+     int (*port_del)(struct dpif *dpif, odp_port_t port_no);
  
      /* Queries 'dpif' for a port with the given 'port_no' or 'devname'.
       * If 'port' is not null, stores information about the port into
       * If 'port' is not null, the caller takes ownership of data in
       * 'port' and must free it with dpif_port_destroy() when it is no
       * longer needed. */
-     int (*port_query_by_number)(const struct dpif *dpif, uint32_t port_no,
+     int (*port_query_by_number)(const struct dpif *dpif, odp_port_t port_no,
                                  struct dpif_port *port);
      int (*port_query_by_name)(const struct dpif *dpif, const char *devname,
                                struct dpif_port *port);
  
      /* Returns one greater than the largest port number accepted in flow
       * actions. */
-     int (*get_max_ports)(const struct dpif *dpif);
+     odp_port_t (*get_max_ports)(const struct dpif *dpif);
  
      /* Returns the Netlink PID value to supply in OVS_ACTION_ATTR_USERSPACE
       * actions as the OVS_USERSPACE_ATTR_PID attribute's value, for use in
       *
       * A dpif provider that doesn't have meaningful Netlink PIDs can use NULL
       * for this function.  This is equivalent to always returning 0. */
-     uint32_t (*port_get_pid)(const struct dpif *dpif, uint32_t port_no);
+     uint32_t (*port_get_pid)(const struct dpif *dpif, odp_port_t port_no);
  
      /* Attempts to begin dumping the ports in a dpif.  On success, returns 0
       * and initializes '*statep' with any data needed for iteration.  On
       * called again once it returns nonzero within a given iteration (but the
       * 'flow_dump_done' function will be called afterward).
       *
-      * On success, if 'key' and 'key_len' are nonnull then '*key' and
-      * '*key_len' must be set to Netlink attributes with types OVS_KEY_ATTR_*
-      * representing the dumped flow's key.  If 'actions' and 'actions_len' are
-      * nonnull then they should be set to Netlink attributes with types
-      * OVS_ACTION_ATTR_* representing the dumped flow's actions.  If 'stats'
-      * is nonnull then it should be set to the dumped flow's statistics.
+      * On success:
+      *
+      *     - If 'key' and 'key_len' are nonnull, then '*key' and '*key_len'
+      *       must be set to Netlink attributes with types OVS_KEY_ATTR_*
+      *       representing the dumped flow's key.
+      *
+      *     - If 'mask' and 'mask_len' are nonnull then '*mask' and '*mask_len'
+      *       must be set to Netlink attributes with types of OVS_KEY_ATTR_*
+      *       representing the dumped flow's mask.
+      *
+      *     - If 'actions' and 'actions_len' are nonnull then they should be set
+      *       to Netlink attributes with types OVS_ACTION_ATTR_* representing
+      *       the dumped flow's actions.
+      *
+      *     - If 'stats' is nonnull then it should be set to the dumped flow's
+      *       statistics.
       *
       * All of the returned data is owned by 'dpif', not by the caller, and the
       * caller must not modify or free it.  'dpif' must guarantee that it
       * 'flow_dump_next' or 'flow_dump_done' for 'state'. */
      int (*flow_dump_next)(const struct dpif *dpif, void *state,
                            const struct nlattr **key, size_t *key_len,
+                           const struct nlattr **mask, size_t *mask_len,
                            const struct nlattr **actions, size_t *actions_len,
                            const struct dpif_flow_stats **stats);
  
  
  extern const struct dpif_class dpif_linux_class;
  extern const struct dpif_class dpif_netdev_class;
 +extern const struct dpif_class dpif_planetlab_class;
  
  #ifdef  __cplusplus
  }
diff --combined lib/dpif.c
@@@ -1,5 -1,5 +1,5 @@@
  /*
-  * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
+  * Copyright (c) 2008, 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.
@@@ -61,7 -61,6 +61,7 @@@ static const struct dpif_class *base_dp
      &dpif_linux_class,
  #endif
      &dpif_netdev_class,
 +    &dpif_planetlab_class,
  };
  
  struct registered_dpif_class {
@@@ -82,6 -81,7 +82,7 @@@ static struct vlog_rate_limit error_rl 
  static void log_flow_message(const struct dpif *dpif, int error,
                               const char *operation,
                               const struct nlattr *key, size_t key_len,
+                              const struct nlattr *mask, size_t mask_len,
                               const struct dpif_flow_stats *stats,
                               const struct nlattr *actions, size_t actions_len);
  static void log_operation(const struct dpif *, const char *operation,
@@@ -216,7 -216,7 +217,7 @@@ dp_enumerate_names(const char *type, st
  
      if (error) {
          VLOG_WARN("failed to enumerate %s datapaths: %s", dpif_class->type,
-                    strerror(error));
+                    ovs_strerror(error));
      }
  
      return error;
@@@ -311,10 -311,11 +312,11 @@@ dpif_create_and_open(const char *name, 
          error = dpif_open(name, type, dpifp);
          if (error) {
              VLOG_WARN("datapath %s already exists but cannot be opened: %s",
-                       name, strerror(error));
+                       name, ovs_strerror(error));
          }
      } else if (error) {
-         VLOG_WARN("failed to create datapath %s: %s", name, strerror(error));
+         VLOG_WARN("failed to create datapath %s: %s",
+                   name, ovs_strerror(error));
      }
      return error;
  }
@@@ -435,18 -436,18 +437,18 @@@ dpif_port_open_type(const char *datapat
  }
  
  /* Attempts to add 'netdev' as a port on 'dpif'.  If 'port_nop' is
-  * non-null and its value is not UINT32_MAX, then attempts to use the
+  * non-null and its value is not ODPP_NONE, then attempts to use the
   * value as the port number.
   *
   * If successful, returns 0 and sets '*port_nop' to the new port's port
   * number (if 'port_nop' is non-null).  On failure, returns a positive
-  * errno value and sets '*port_nop' to UINT32_MAX (if 'port_nop' is
+  * errno value and sets '*port_nop' to ODPP_NONE (if 'port_nop' is
   * non-null). */
  int
- dpif_port_add(struct dpif *dpif, struct netdev *netdev, uint32_t *port_nop)
+ dpif_port_add(struct dpif *dpif, struct netdev *netdev, odp_port_t *port_nop)
  {
      const char *netdev_name = netdev_get_name(netdev);
-     uint32_t port_no = UINT32_MAX;
+     odp_port_t port_no = ODPP_NONE;
      int error;
  
      COVERAGE_INC(dpif_port_add);
                      dpif_name(dpif), netdev_name, port_no);
      } else {
          VLOG_WARN_RL(&error_rl, "%s: failed to add %s as port: %s",
-                      dpif_name(dpif), netdev_name, strerror(error));
-         port_no = UINT32_MAX;
+                      dpif_name(dpif), netdev_name, ovs_strerror(error));
+         port_no = ODPP_NONE;
      }
      if (port_nop) {
          *port_nop = port_no;
  /* Attempts to remove 'dpif''s port number 'port_no'.  Returns 0 if successful,
   * otherwise a positive errno value. */
  int
- dpif_port_del(struct dpif *dpif, uint32_t port_no)
+ dpif_port_del(struct dpif *dpif, odp_port_t port_no)
  {
      int error;
  
@@@ -518,7 -519,7 +520,7 @@@ dpif_port_exists(const struct dpif *dpi
      int error = dpif->dpif_class->port_query_by_name(dpif, devname, NULL);
      if (error != 0 && error != ENOENT && error != ENODEV) {
          VLOG_WARN_RL(&error_rl, "%s: failed to query port %s: %s",
-                      dpif_name(dpif), devname, strerror(error));
+                      dpif_name(dpif), devname, ovs_strerror(error));
      }
  
      return !error;
   * The caller owns the data in 'port' and must free it with
   * dpif_port_destroy() when it is no longer needed. */
  int
- dpif_port_query_by_number(const struct dpif *dpif, uint32_t port_no,
+ dpif_port_query_by_number(const struct dpif *dpif, odp_port_t port_no,
                            struct dpif_port *port)
  {
      int error = dpif->dpif_class->port_query_by_number(dpif, port_no, port);
      } else {
          memset(port, 0, sizeof *port);
          VLOG_WARN_RL(&error_rl, "%s: failed to query port %"PRIu32": %s",
-                      dpif_name(dpif), port_no, strerror(error));
+                      dpif_name(dpif), port_no, ovs_strerror(error));
      }
      return error;
  }
@@@ -570,14 -571,14 +572,14 @@@ dpif_port_query_by_name(const struct dp
          VLOG_RL(&error_rl,
                  error == ENOENT || error == ENODEV ? VLL_DBG : VLL_WARN,
                  "%s: failed to query port %s: %s",
-                 dpif_name(dpif), devname, strerror(error));
+                 dpif_name(dpif), devname, ovs_strerror(error));
      }
      return error;
  }
  
  /* Returns one greater than the maximum port number accepted in flow
   * actions. */
int
odp_port_t
  dpif_get_max_ports(const struct dpif *dpif)
  {
      return dpif->dpif_class->get_max_ports(dpif);
   * as the OVS_USERSPACE_ATTR_PID attribute's value, for use in flows whose
   * packets arrived on port 'port_no'.
   *
-  * A 'port_no' of UINT32_MAX is a special case: it returns a reserved PID, not
+  * A 'port_no' of ODPP_NONE is a special case: it returns a reserved PID, not
   * allocated to any port, that the client may use for special purposes.
   *
   * The return value is only meaningful when DPIF_UC_ACTION has been enabled in
   * update all of the flows that it installed that contain
   * OVS_ACTION_ATTR_USERSPACE actions. */
  uint32_t
- dpif_port_get_pid(const struct dpif *dpif, uint32_t port_no)
+ dpif_port_get_pid(const struct dpif *dpif, odp_port_t port_no)
  {
      return (dpif->dpif_class->port_get_pid
              ? (dpif->dpif_class->port_get_pid)(dpif, port_no)
   * result is null-terminated.  On failure, returns a positive errno value and
   * makes 'name' the empty string. */
  int
- dpif_port_get_name(struct dpif *dpif, uint32_t port_no,
+ dpif_port_get_name(struct dpif *dpif, odp_port_t port_no,
                     char *name, size_t name_size)
  {
      struct dpif_port port;
@@@ -809,8 -810,8 +811,8 @@@ dpif_flow_get(const struct dpif *dpif
              actions = NULL;
              actions_len = 0;
          }
-         log_flow_message(dpif, error, "flow_get", key, key_len, stats,
-                          actions, actions_len);
+         log_flow_message(dpif, error, "flow_get", key, key_len,
+                          NULL, 0, stats, actions, actions_len);
      }
      return error;
  }
@@@ -833,9 -834,11 +835,11 @@@ dpif_flow_put__(struct dpif *dpif, cons
  }
  
  /* Adds or modifies a flow in 'dpif'.  The flow is specified by the Netlink
-  * attributes with types OVS_KEY_ATTR_* in the 'key_len' bytes starting at
-  * 'key'.  The associated actions are specified by the Netlink attributes with
-  * types OVS_ACTION_ATTR_* in the 'actions_len' bytes starting at 'actions'.
+  * attribute OVS_FLOW_ATTR_KEY with types OVS_KEY_ATTR_* in the 'key_len' bytes
+  * starting at 'key', and OVS_FLOW_ATTR_MASK with types of OVS_KEY_ATTR_* in the
+  * 'mask_len' bytes starting at 'mask'. The associated actions are specified by
+  * the Netlink attributes with types OVS_ACTION_ATTR_* in the 'actions_len'
+  * bytes starting at 'actions'.
   *
   * - If the flow's key does not exist in 'dpif', then the flow will be added if
   *   'flags' includes DPIF_FP_CREATE.  Otherwise the operation will fail with
  int
  dpif_flow_put(struct dpif *dpif, enum dpif_flow_put_flags flags,
                const struct nlattr *key, size_t key_len,
+               const struct nlattr *mask, size_t mask_len,
                const struct nlattr *actions, size_t actions_len,
                struct dpif_flow_stats *stats)
  {
      put.flags = flags;
      put.key = key;
      put.key_len = key_len;
+     put.mask = mask;
+     put.mask_len = mask_len;
      put.actions = actions;
      put.actions_len = actions_len;
      put.stats = stats;
@@@ -938,6 -944,7 +945,7 @@@ dpif_flow_dump_start(struct dpif_flow_d
  bool
  dpif_flow_dump_next(struct dpif_flow_dump *dump,
                      const struct nlattr **key, size_t *key_len,
+                     const struct nlattr **mask, size_t *mask_len,
                      const struct nlattr **actions, size_t *actions_len,
                      const struct dpif_flow_stats **stats)
  {
      if (!error) {
          error = dpif->dpif_class->flow_dump_next(dpif, dump->state,
                                                   key, key_len,
+                                                  mask, mask_len,
                                                   actions, actions_len,
                                                   stats);
          if (error) {
              *key = NULL;
              *key_len = 0;
          }
+         if (mask) {
+             *mask = NULL;
+             *mask_len = 0;
+         }
          if (actions) {
              *actions = NULL;
              *actions_len = 0;
          } else if (should_log_flow_message(error)) {
              log_flow_message(dpif, error, "flow_dump",
                               key ? *key : NULL, key ? *key_len : 0,
+                              mask ? *mask : NULL, mask ? *mask_len : 0,
                               stats ? *stats : NULL, actions ? *actions : NULL,
                               actions ? *actions_len : 0);
          }
@@@ -1244,14 -1257,19 +1258,19 @@@ log_operation(const struct dpif *dpif, 
                       dpif_name(dpif), operation, ofperr_get_name(error));
      } else {
          VLOG_WARN_RL(&error_rl, "%s: %s failed (%s)",
-                      dpif_name(dpif), operation, strerror(error));
+                      dpif_name(dpif), operation, ovs_strerror(error));
      }
  }
  
  static enum vlog_level
  flow_message_log_level(int error)
  {
-     return error ? VLL_WARN : VLL_DBG;
+     /* If flows arrive in a batch, userspace may push down multiple
+      * unique flow definitions that overlap when wildcards are applied.
+      * Kernels that support flow wildcarding will reject these flows as
+      * duplicates (EEXIST), so lower the log level to debug for these
+      * types of messages. */
+     return (error && error != EEXIST) ? VLL_WARN : VLL_DBG;
  }
  
  static bool
@@@ -1264,6 -1282,7 +1283,7 @@@ should_log_flow_message(int error
  static void
  log_flow_message(const struct dpif *dpif, int error, const char *operation,
                   const struct nlattr *key, size_t key_len,
+                  const struct nlattr *mask, size_t mask_len,
                   const struct dpif_flow_stats *stats,
                   const struct nlattr *actions, size_t actions_len)
  {
      }
      ds_put_format(&ds, "%s ", operation);
      if (error) {
-         ds_put_format(&ds, "(%s) ", strerror(error));
+         ds_put_format(&ds, "(%s) ", ovs_strerror(error));
      }
-     odp_flow_key_format(key, key_len, &ds);
+     odp_flow_format(key, key_len, mask, mask_len, &ds);
      if (stats) {
          ds_put_cstr(&ds, ", ");
          dpif_flow_stats_format(stats, &ds);
@@@ -1308,8 -1327,8 +1328,8 @@@ log_flow_put_message(struct dpif *dpif
              ds_put_cstr(&s, "[zero]");
          }
          log_flow_message(dpif, error, ds_cstr(&s),
-                          put->key, put->key_len, put->stats,
-                          put->actions, put->actions_len);
+                          put->key, put->key_len, put->mask, put->mask_len,
+                          put->stats, put->actions, put->actions_len);
          ds_destroy(&s);
      }
  }
@@@ -1320,7 -1339,7 +1340,7 @@@ log_flow_del_message(struct dpif *dpif
  {
      if (should_log_flow_message(error)) {
          log_flow_message(dpif, error, "flow_del", del->key, del->key_len,
-                          !error ? del->stats : NULL, NULL, 0);
+                          NULL, 0, !error ? del->stats : NULL, NULL, 0);
      }
  }
  
@@@ -1337,7 -1356,7 +1357,7 @@@ log_execute_message(struct dpif *dpif, 
          ds_put_format(&ds, "%s: execute ", dpif_name(dpif));
          format_odp_actions(&ds, execute->actions, execute->actions_len);
          if (error) {
-             ds_put_format(&ds, " failed (%s)", strerror(error));
+             ds_put_format(&ds, " failed (%s)", ovs_strerror(error));
          }
          ds_put_format(&ds, " on packet %s", packet);
          vlog(THIS_MODULE, error ? VLL_WARN : VLL_DBG, "%s", ds_cstr(&ds));
diff --combined lib/netdev-provider.h
@@@ -470,7 -470,7 +470,7 @@@ struct netdev_class 
       * anyhow. */
      int (*add_router)(struct netdev *netdev, struct in_addr router);
  
-     /* Looks up the next hop for 'host'.  If succesful, stores the next hop
+     /* Looks up the next hop for 'host'.  If successful, stores the next hop
       * gateway's address (0 if 'host' is on a directly connected network) in
       * '*next_hop' and a copy of the name of the device to reach 'host' in
       * '*netdev_name', and returns 0.  The caller is responsible for freeing
@@@ -575,13 -575,10 +575,13 @@@ const struct netdev_class *netdev_looku
  extern const struct netdev_class netdev_linux_class;
  extern const struct netdev_class netdev_internal_class;
  extern const struct netdev_class netdev_tap_class;
- #ifdef __FreeBSD__
+ #if defined(__FreeBSD__) || defined(__NetBSD__)
  extern const struct netdev_class netdev_bsd_class;
  #endif
  
 +extern const struct netdev_class netdev_tunnel_class;
 +extern const struct netdev_class netdev_pltap_class;
 +
  #ifdef  __cplusplus
  }
  #endif
diff --combined lib/netdev.c
@@@ -25,6 -25,7 +25,7 @@@
  #include <unistd.h>
  
  #include "coverage.h"
+ #include "dpif.h"
  #include "dynamic-string.h"
  #include "fatal-signal.h"
  #include "hash.h"
@@@ -84,12 -85,10 +85,12 @@@ netdev_initialize(void
          netdev_register_provider(&netdev_tap_class);
          netdev_vport_tunnel_register();
  #endif
- #ifdef __FreeBSD__
+ #if defined(__FreeBSD__) || defined(__NetBSD__)
          netdev_register_provider(&netdev_tap_class);
          netdev_register_provider(&netdev_bsd_class);
  #endif
 +      netdev_register_provider(&netdev_tunnel_class);
 +      netdev_register_provider(&netdev_pltap_class);
      }
  }
  
@@@ -140,7 -139,7 +141,7 @@@ netdev_register_provider(const struct n
          int error = new_class->init();
          if (error) {
              VLOG_ERR("failed to initialize %s network device class: %s",
-                      new_class->type, strerror(error));
+                      new_class->type, ovs_strerror(error));
              return error;
          }
      }
@@@ -202,6 -201,43 +203,43 @@@ netdev_enumerate_types(struct sset *typ
      }
  }
  
+ /* Check that the network device name is not the same as any of the registered
+  * vport providers' dpif_port name (dpif_port is NULL if the vport provider
+  * does not define it) or the datapath internal port name (e.g. ovs-system).
+  *
+  * Returns true if there is a name conflict, false otherwise. */
+ bool
+ netdev_is_reserved_name(const char *name)
+ {
+     struct shash_node *node;
+     netdev_initialize();
+     SHASH_FOR_EACH (node, &netdev_classes) {
+         const char *dpif_port;
+         dpif_port = netdev_vport_class_get_dpif_port(node->data);
+         if (dpif_port && !strcmp(dpif_port, name)) {
+             return true;
+         }
+     }
+     if (!strncmp(name, "ovs-", 4)) {
+         struct sset types;
+         const char *type;
+         sset_init(&types);
+         dp_enumerate_types(&types);
+         SSET_FOR_EACH (type, &types) {
+             if (!strcmp(name+4, type)) {
+                 sset_destroy(&types);
+                 return true;
+             }
+         }
+         sset_destroy(&types);
+     }
+     return false;
+ }
  /* Opens the network device named 'name' (e.g. "eth0") of the specified 'type'
   * (e.g. "system") and returns zero if successful, otherwise a positive errno
   * value.  On success, sets '*netdevp' to the new network device, otherwise to
@@@ -241,6 -277,20 +279,20 @@@ netdev_open(const char *name, const cha
      return 0;
  }
  
+ /* Returns a reference to 'netdev_' for the caller to own. Returns null if
+  * 'netdev_' is null. */
+ struct netdev *
+ netdev_ref(const struct netdev *netdev_)
+ {
+     struct netdev *netdev = CONST_CAST(struct netdev *, netdev_);
+     if (netdev) {
+         ovs_assert(netdev->ref_cnt > 0);
+         netdev->ref_cnt++;
+     }
+     return netdev;
+ }
  /* Reconfigures the device 'netdev' with 'args'.  'args' may be empty
   * or NULL if none are needed. */
  int
@@@ -476,7 -526,7 +528,7 @@@ netdev_get_mtu(const struct netdev *net
          *mtup = 0;
          if (error != EOPNOTSUPP) {
              VLOG_DBG_RL(&rl, "failed to retrieve MTU for network device %s: "
-                          "%s", netdev_get_name(netdev), strerror(error));
+                          "%s", netdev_get_name(netdev), ovs_strerror(error));
          }
      }
      return error;
@@@ -497,7 -547,7 +549,7 @@@ netdev_set_mtu(const struct netdev *net
      error = class->set_mtu ? class->set_mtu(netdev, mtu) : EOPNOTSUPP;
      if (error && error != EOPNOTSUPP) {
          VLOG_DBG_RL(&rl, "failed to set MTU for network device %s: %s",
-                      netdev_get_name(netdev), strerror(error));
+                      netdev_get_name(netdev), ovs_strerror(error));
      }
  
      return error;
@@@ -775,7 -825,7 +827,7 @@@ do_update_flags(struct netdev *netdev, 
      if (error) {
          VLOG_WARN_RL(&rl, "failed to %s flags for network device %s: %s",
                       off || on ? "set" : "get", netdev_get_name(netdev),
-                      strerror(error));
+                      ovs_strerror(error));
          old_flags = 0;
      } else if ((off || on) && sfp) {
          enum netdev_flags new_flags = (old_flags & ~off) | on;
@@@ -906,7 -956,7 +958,7 @@@ netdev_get_carrier(const struct netdev 
                                                                &carrier);
      if (error) {
          VLOG_DBG("%s: failed to get network device carrier status, assuming "
-                  "down: %s", netdev_get_name(netdev), strerror(error));
+                  "down: %s", netdev_get_name(netdev), ovs_strerror(error));
          carrier = false;
      }