ovsdb-server: Fix a reference count leak bug
[cascardo/ovs.git] / lib / netdev-dummy.c
index fcb0b77..ccd4a0a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2010, 2011, 2012, 2013, 2015, 2016 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
 
 #include <errno.h>
 
+#include "dp-packet.h"
 #include "dpif-netdev.h"
 #include "dynamic-string.h"
 #include "flow.h"
@@ -29,7 +30,7 @@
 #include "odp-util.h"
 #include "ofp-print.h"
 #include "ofpbuf.h"
-#include "packet-dpif.h"
+#include "ovs-atomic.h"
 #include "packets.h"
 #include "pcap-file.h"
 #include "poll-loop.h"
@@ -48,7 +49,7 @@ struct reconnect;
 
 struct dummy_packet_stream {
     struct stream *stream;
-    struct ofpbuf rxbuf;
+    struct dp_packet rxbuf;
     struct ovs_list txq;
 };
 
@@ -83,6 +84,11 @@ struct dummy_packet_conn {
     } u;
 };
 
+struct pkt_list_node {
+    struct dp_packet *pkt;
+    struct ovs_list list_node;
+};
+
 /* Protects 'dummy_list'. */
 static struct ovs_mutex dummy_list_mutex = OVS_MUTEX_INITIALIZER;
 
@@ -99,7 +105,7 @@ struct netdev_dummy {
     /* Protects all members below. */
     struct ovs_mutex mutex OVS_ACQ_AFTER(dummy_list_mutex);
 
-    uint8_t hwaddr[ETH_ADDR_LEN] OVS_GUARDED;
+    struct eth_addr hwaddr OVS_GUARDED;
     int mtu OVS_GUARDED;
     struct netdev_stats stats OVS_GUARDED;
     enum netdev_flags flags OVS_GUARDED;
@@ -110,6 +116,7 @@ struct netdev_dummy {
     FILE *tx_pcap, *rxq_pcap OVS_GUARDED;
 
     struct in_addr address, netmask;
+    struct in6_addr ipv6;
     struct ovs_list rxes OVS_GUARDED; /* List of child "netdev_rxq_dummy"s. */
 };
 
@@ -126,10 +133,12 @@ struct netdev_rxq_dummy {
 
 static unixctl_cb_func netdev_dummy_set_admin_state;
 static int netdev_dummy_construct(struct netdev *);
-static void netdev_dummy_queue_packet(struct netdev_dummy *, struct ofpbuf *);
+static void netdev_dummy_queue_packet(struct netdev_dummy *, struct dp_packet *);
 
 static void dummy_packet_stream_close(struct dummy_packet_stream *);
 
+static void pkt_list_delete(struct ovs_list *);
+
 static bool
 is_dummy_class(const struct netdev_class *class)
 {
@@ -155,7 +164,7 @@ dummy_packet_stream_init(struct dummy_packet_stream *s, struct stream *stream)
 {
     int rxbuf_size = stream ? 2048 : 0;
     s->stream = stream;
-    ofpbuf_init(&s->rxbuf, rxbuf_size);
+    dp_packet_init(&s->rxbuf, rxbuf_size);
     list_init(&s->txq);
 }
 
@@ -184,11 +193,15 @@ static void
 dummy_packet_stream_send(struct dummy_packet_stream *s, const void *buffer, size_t size)
 {
     if (list_size(&s->txq) < NETDEV_DUMMY_MAX_QUEUE) {
-        struct ofpbuf *b;
+        struct dp_packet *b;
+        struct pkt_list_node *node;
+
+        b = dp_packet_clone_data_with_headroom(buffer, size, 2);
+        put_unaligned_be16(dp_packet_push_uninit(b, 2), htons(size));
 
-        b = ofpbuf_clone_data_with_headroom(buffer, size, 2);
-        put_unaligned_be16(ofpbuf_push_uninit(b, 2), htons(size));
-        list_push_back(&s->txq, &b->list_node);
+        node = xmalloc(sizeof *node);
+        node->pkt = b;
+        list_push_back(&s->txq, &node->list_node);
     }
 }
 
@@ -201,17 +214,20 @@ dummy_packet_stream_run(struct netdev_dummy *dev, struct dummy_packet_stream *s)
     stream_run(s->stream);
 
     if (!list_is_empty(&s->txq)) {
-        struct ofpbuf *txbuf;
+        struct pkt_list_node *txbuf_node;
+        struct dp_packet *txbuf;
         int retval;
 
-        txbuf = ofpbuf_from_list(list_front(&s->txq));
-        retval = stream_send(s->stream, ofpbuf_data(txbuf), ofpbuf_size(txbuf));
+        ASSIGN_CONTAINER(txbuf_node, list_front(&s->txq), list_node);
+        txbuf = txbuf_node->pkt;
+        retval = stream_send(s->stream, dp_packet_data(txbuf), dp_packet_size(txbuf));
 
         if (retval > 0) {
-            ofpbuf_pull(txbuf, retval);
-            if (!ofpbuf_size(txbuf)) {
-                list_remove(&txbuf->list_node);
-                ofpbuf_delete(txbuf);
+            dp_packet_pull(txbuf, retval);
+            if (!dp_packet_size(txbuf)) {
+                list_remove(&txbuf_node->list_node);
+                free(txbuf_node);
+                dp_packet_delete(txbuf);
             }
         } else if (retval != -EAGAIN) {
             error = -retval;
@@ -219,37 +235,37 @@ dummy_packet_stream_run(struct netdev_dummy *dev, struct dummy_packet_stream *s)
     }
 
     if (!error) {
-        if (ofpbuf_size(&s->rxbuf) < 2) {
-            n = 2 - ofpbuf_size(&s->rxbuf);
+        if (dp_packet_size(&s->rxbuf) < 2) {
+            n = 2 - dp_packet_size(&s->rxbuf);
         } else {
             uint16_t frame_len;
 
-            frame_len = ntohs(get_unaligned_be16(ofpbuf_data(&s->rxbuf)));
+            frame_len = ntohs(get_unaligned_be16(dp_packet_data(&s->rxbuf)));
             if (frame_len < ETH_HEADER_LEN) {
                 error = EPROTO;
                 n = 0;
             } else {
-                n = (2 + frame_len) - ofpbuf_size(&s->rxbuf);
+                n = (2 + frame_len) - dp_packet_size(&s->rxbuf);
             }
         }
     }
     if (!error) {
         int retval;
 
-        ofpbuf_prealloc_tailroom(&s->rxbuf, n);
-        retval = stream_recv(s->stream, ofpbuf_tail(&s->rxbuf), n);
+        dp_packet_prealloc_tailroom(&s->rxbuf, n);
+        retval = stream_recv(s->stream, dp_packet_tail(&s->rxbuf), n);
 
         if (retval > 0) {
-            ofpbuf_set_size(&s->rxbuf, ofpbuf_size(&s->rxbuf) + retval);
-            if (retval == n && ofpbuf_size(&s->rxbuf) > 2) {
-                ofpbuf_pull(&s->rxbuf, 2);
+            dp_packet_set_size(&s->rxbuf, dp_packet_size(&s->rxbuf) + retval);
+            if (retval == n && dp_packet_size(&s->rxbuf) > 2) {
+                dp_packet_pull(&s->rxbuf, 2);
                 netdev_dummy_queue_packet(dev,
-                                          ofpbuf_clone(&s->rxbuf));
-                ofpbuf_clear(&s->rxbuf);
+                                          dp_packet_clone(&s->rxbuf));
+                dp_packet_clear(&s->rxbuf);
             }
         } else if (retval != -EAGAIN) {
             error = (retval < 0 ? -retval
-                     : ofpbuf_size(&s->rxbuf) ? EPROTO
+                     : dp_packet_size(&s->rxbuf) ? EPROTO
                      : EOF);
         }
     }
@@ -261,8 +277,8 @@ static void
 dummy_packet_stream_close(struct dummy_packet_stream *s)
 {
     stream_close(s->stream);
-    ofpbuf_uninit(&s->rxbuf);
-    ofpbuf_list_delete(&s->txq);
+    dp_packet_uninit(&s->rxbuf);
+    pkt_list_delete(&s->txq);
 }
 
 static void
@@ -341,13 +357,15 @@ dummy_packet_conn_set_config(struct dummy_packet_conn *conn,
 
     switch (conn->type) {
     case PASSIVE:
-        if (!strcmp(pstream_get_name(conn->u.pconn.pstream), pstream)) {
+        if (pstream &&
+            !strcmp(pstream_get_name(conn->u.pconn.pstream), pstream)) {
             return;
         }
         dummy_packet_conn_close(conn);
         break;
     case ACTIVE:
-        if (!strcmp(stream_get_name(conn->u.rconn.rstream->stream), stream)) {
+        if (stream &&
+            !strcmp(stream_get_name(conn->u.rconn.rstream->stream), stream)) {
             return;
         }
         dummy_packet_conn_close(conn);
@@ -371,7 +389,7 @@ dummy_packet_conn_set_config(struct dummy_packet_conn *conn,
     if (stream) {
         int error;
         struct stream *active_stream;
-        struct reconnect *reconnect;;
+        struct reconnect *reconnect;
 
         reconnect = reconnect_create(time_msec());
         reconnect_set_name(reconnect, stream);
@@ -634,12 +652,12 @@ netdev_dummy_construct(struct netdev *netdev_)
 
     ovs_mutex_init(&netdev->mutex);
     ovs_mutex_lock(&netdev->mutex);
-    netdev->hwaddr[0] = 0xaa;
-    netdev->hwaddr[1] = 0x55;
-    netdev->hwaddr[2] = n >> 24;
-    netdev->hwaddr[3] = n >> 16;
-    netdev->hwaddr[4] = n >> 8;
-    netdev->hwaddr[5] = n;
+    netdev->hwaddr.ea[0] = 0xaa;
+    netdev->hwaddr.ea[1] = 0x55;
+    netdev->hwaddr.ea[2] = n >> 24;
+    netdev->hwaddr.ea[3] = n >> 16;
+    netdev->hwaddr.ea[4] = n >> 8;
+    netdev->hwaddr.ea[5] = n;
     netdev->mtu = 1500;
     netdev->flags = 0;
     netdev->ifindex = -EOPNOTSUPP;
@@ -708,7 +726,20 @@ netdev_dummy_get_in4(const struct netdev *netdev_,
     *address = netdev->address;
     *netmask = netdev->netmask;
     ovs_mutex_unlock(&netdev->mutex);
-    return 0;
+
+    return address->s_addr ? 0 : EADDRNOTAVAIL;
+}
+
+static int
+netdev_dummy_get_in6(const struct netdev *netdev_, struct in6_addr *in6)
+{
+    struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
+
+    ovs_mutex_lock(&netdev->mutex);
+    *in6 = netdev->ipv6;
+    ovs_mutex_unlock(&netdev->mutex);
+
+    return ipv6_addr_is_set(in6) ? 0 : EADDRNOTAVAIL;
 }
 
 static int
@@ -725,6 +756,18 @@ netdev_dummy_set_in4(struct netdev *netdev_, struct in_addr address,
     return 0;
 }
 
+static int
+netdev_dummy_set_in6(struct netdev *netdev_, struct in6_addr *in6)
+{
+    struct netdev_dummy *netdev = netdev_dummy_cast(netdev_);
+
+    ovs_mutex_lock(&netdev->mutex);
+    netdev->ipv6 = *in6;
+    ovs_mutex_unlock(&netdev->mutex);
+
+    return 0;
+}
+
 static int
 netdev_dummy_set_config(struct netdev *netdev_, const struct smap *args)
 {
@@ -794,7 +837,7 @@ netdev_dummy_rxq_destruct(struct netdev_rxq *rxq_)
 
     ovs_mutex_lock(&netdev->mutex);
     list_remove(&rx->node);
-    ofpbuf_list_delete(&rx->recv_queue);
+    pkt_list_delete(&rx->recv_queue);
     ovs_mutex_unlock(&netdev->mutex);
     seq_destroy(rx->seq);
 }
@@ -808,16 +851,20 @@ netdev_dummy_rxq_dealloc(struct netdev_rxq *rxq_)
 }
 
 static int
-netdev_dummy_rxq_recv(struct netdev_rxq *rxq_, struct dpif_packet **arr,
+netdev_dummy_rxq_recv(struct netdev_rxq *rxq_, struct dp_packet **arr,
                       int *c)
 {
     struct netdev_rxq_dummy *rx = netdev_rxq_dummy_cast(rxq_);
     struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
-    struct ofpbuf *packet;
+    struct dp_packet *packet;
 
     ovs_mutex_lock(&netdev->mutex);
     if (!list_is_empty(&rx->recv_queue)) {
-        packet = ofpbuf_from_list(list_pop_front(&rx->recv_queue));
+        struct pkt_list_node *pkt_node;
+
+        ASSIGN_CONTAINER(pkt_node, list_pop_front(&rx->recv_queue), list_node);
+        packet = pkt_node->pkt;
+        free(pkt_node);
         rx->recv_queue_len--;
     } else {
         packet = NULL;
@@ -829,15 +876,13 @@ netdev_dummy_rxq_recv(struct netdev_rxq *rxq_, struct dpif_packet **arr,
     }
     ovs_mutex_lock(&netdev->mutex);
     netdev->stats.rx_packets++;
-    netdev->stats.rx_bytes += ofpbuf_size(packet);
+    netdev->stats.rx_bytes += dp_packet_size(packet);
     ovs_mutex_unlock(&netdev->mutex);
 
     dp_packet_pad(packet);
+    dp_packet_rss_invalidate(packet);
 
-    /* This performs a (sometimes unnecessary) copy */
-    arr[0] = dpif_packet_clone_from_ofpbuf(packet);
-    dpif_packet_set_dp_hash(arr[0], 0);
-    ofpbuf_delete(packet);
+    arr[0] = packet;
     *c = 1;
     return 0;
 }
@@ -865,7 +910,7 @@ netdev_dummy_rxq_drain(struct netdev_rxq *rxq_)
     struct netdev_dummy *netdev = netdev_dummy_cast(rx->up.netdev);
 
     ovs_mutex_lock(&netdev->mutex);
-    ofpbuf_list_delete(&rx->recv_queue);
+    pkt_list_delete(&rx->recv_queue);
     rx->recv_queue_len = 0;
     ovs_mutex_unlock(&netdev->mutex);
 
@@ -876,15 +921,15 @@ netdev_dummy_rxq_drain(struct netdev_rxq *rxq_)
 
 static int
 netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
-                  struct dpif_packet **pkts, int cnt, bool may_steal)
+                  struct dp_packet **pkts, int cnt, bool may_steal)
 {
     struct netdev_dummy *dev = netdev_dummy_cast(netdev);
     int error = 0;
     int i;
 
     for (i = 0; i < cnt; i++) {
-        const void *buffer = ofpbuf_data(&pkts[i]->ofpbuf);
-        size_t size = ofpbuf_size(&pkts[i]->ofpbuf);
+        const void *buffer = dp_packet_data(pkts[i]);
+        size_t size = dp_packet_size(pkts[i]);
 
         if (size < ETH_HEADER_LEN) {
             error = EMSGSIZE;
@@ -912,10 +957,27 @@ netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
 
         dummy_packet_conn_send(&dev->conn, buffer, size);
 
+        /* Reply to ARP requests for 'dev''s assigned IP address. */
+        if (dev->address.s_addr) {
+            struct dp_packet packet;
+            struct flow flow;
+
+            dp_packet_use_const(&packet, buffer, size);
+            flow_extract(&packet, &flow);
+            if (flow.dl_type == htons(ETH_TYPE_ARP)
+                && flow.nw_proto == ARP_OP_REQUEST
+                && flow.nw_dst == dev->address.s_addr) {
+                struct dp_packet *reply = dp_packet_new(0);
+                compose_arp(reply, ARP_OP_REPLY, dev->hwaddr, flow.dl_src,
+                            false, flow.nw_dst, flow.nw_src);
+                netdev_dummy_queue_packet(dev, reply);
+            }
+        }
+
         if (dev->tx_pcap) {
-            struct ofpbuf packet;
+            struct dp_packet packet;
 
-            ofpbuf_use_const(&packet, buffer, size);
+            dp_packet_use_const(&packet, buffer, size);
             ovs_pcap_write(dev->tx_pcap, &packet);
             fflush(dev->tx_pcap);
         }
@@ -925,7 +987,7 @@ netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
 
     if (may_steal) {
         for (i = 0; i < cnt; i++) {
-            dpif_packet_delete(pkts[i]);
+            dp_packet_delete(pkts[i]);
         }
     }
 
@@ -933,14 +995,13 @@ netdev_dummy_send(struct netdev *netdev, int qid OVS_UNUSED,
 }
 
 static int
-netdev_dummy_set_etheraddr(struct netdev *netdev,
-                           const uint8_t mac[ETH_ADDR_LEN])
+netdev_dummy_set_etheraddr(struct netdev *netdev, const struct eth_addr mac)
 {
     struct netdev_dummy *dev = netdev_dummy_cast(netdev);
 
     ovs_mutex_lock(&dev->mutex);
     if (!eth_addr_equals(dev->hwaddr, mac)) {
-        memcpy(dev->hwaddr, mac, ETH_ADDR_LEN);
+        dev->hwaddr = mac;
         netdev_change_seq_changed(netdev);
     }
     ovs_mutex_unlock(&dev->mutex);
@@ -949,13 +1010,12 @@ netdev_dummy_set_etheraddr(struct netdev *netdev,
 }
 
 static int
-netdev_dummy_get_etheraddr(const struct netdev *netdev,
-                           uint8_t mac[ETH_ADDR_LEN])
+netdev_dummy_get_etheraddr(const struct netdev *netdev, struct eth_addr *mac)
 {
     struct netdev_dummy *dev = netdev_dummy_cast(netdev);
 
     ovs_mutex_lock(&dev->mutex);
-    memcpy(mac, dev->hwaddr, ETH_ADDR_LEN);
+    *mac = dev->hwaddr;
     ovs_mutex_unlock(&dev->mutex);
 
     return 0;
@@ -997,6 +1057,92 @@ netdev_dummy_get_stats(const struct netdev *netdev, struct netdev_stats *stats)
     return 0;
 }
 
+static int
+netdev_dummy_get_queue(const struct netdev *netdev OVS_UNUSED,
+                       unsigned int queue_id, struct smap *details OVS_UNUSED)
+{
+    if (queue_id == 0) {
+        return 0;
+    } else {
+        return EINVAL;
+    }
+}
+
+static void
+netdev_dummy_init_queue_stats(struct netdev_queue_stats *stats)
+{
+    *stats = (struct netdev_queue_stats) {
+        .tx_bytes = UINT64_MAX,
+        .tx_packets = UINT64_MAX,
+        .tx_errors = UINT64_MAX,
+        .created = LLONG_MIN,
+    };
+}
+
+static int
+netdev_dummy_get_queue_stats(const struct netdev *netdev OVS_UNUSED,
+                             unsigned int queue_id,
+                             struct netdev_queue_stats *stats)
+{
+    if (queue_id == 0) {
+        netdev_dummy_init_queue_stats(stats);
+        return 0;
+    } else {
+        return EINVAL;
+    }
+}
+
+struct netdev_dummy_queue_state {
+    unsigned int next_queue;
+};
+
+static int
+netdev_dummy_queue_dump_start(const struct netdev *netdev OVS_UNUSED,
+                              void **statep)
+{
+    struct netdev_dummy_queue_state *state = xmalloc(sizeof *state);
+    state->next_queue = 0;
+    *statep = state;
+    return 0;
+}
+
+static int
+netdev_dummy_queue_dump_next(const struct netdev *netdev OVS_UNUSED,
+                             void *state_,
+                             unsigned int *queue_id,
+                             struct smap *details OVS_UNUSED)
+{
+    struct netdev_dummy_queue_state *state = state_;
+    if (state->next_queue == 0) {
+        *queue_id = 0;
+        state->next_queue++;
+        return 0;
+    } else {
+        return EOF;
+    }
+}
+
+static int
+netdev_dummy_queue_dump_done(const struct netdev *netdev OVS_UNUSED,
+                             void *state)
+{
+    free(state);
+    return 0;
+}
+
+static int
+netdev_dummy_dump_queue_stats(const struct netdev *netdev OVS_UNUSED,
+                              void (*cb)(unsigned int queue_id,
+                                         struct netdev_queue_stats *,
+                                         void *aux),
+                              void *aux)
+{
+    struct netdev_queue_stats stats;
+    netdev_dummy_init_queue_stats(&stats);
+    cb(0, &stats, aux);
+    return 0;
+}
+
 static int
 netdev_dummy_get_ifindex(const struct netdev *netdev)
 {
@@ -1087,18 +1233,18 @@ static const struct netdev_class dummy_class = {
     NULL,                       /* get_qos_capabilities */
     NULL,                       /* get_qos */
     NULL,                       /* set_qos */
-    NULL,                       /* get_queue */
+    netdev_dummy_get_queue,
     NULL,                       /* set_queue */
     NULL,                       /* delete_queue */
-    NULL,                       /* get_queue_stats */
-    NULL,                       /* queue_dump_start */
-    NULL,                       /* queue_dump_next */
-    NULL,                       /* queue_dump_done */
-    NULL,                       /* dump_queue_stats */
+    netdev_dummy_get_queue_stats,
+    netdev_dummy_queue_dump_start,
+    netdev_dummy_queue_dump_next,
+    netdev_dummy_queue_dump_done,
+    netdev_dummy_dump_queue_stats,
 
     netdev_dummy_get_in4,       /* get_in4 */
     NULL,                       /* set_in4 */
-    NULL,                       /* get_in6 */
+    netdev_dummy_get_in6,       /* get_in6 */
     NULL,                       /* add_router */
     NULL,                       /* get_next_hop */
     NULL,                       /* get_status */
@@ -1115,11 +1261,22 @@ static const struct netdev_class dummy_class = {
     netdev_dummy_rxq_drain,
 };
 
-static struct ofpbuf *
+static void
+pkt_list_delete(struct ovs_list *l)
+{
+    struct pkt_list_node *pkt;
+
+    LIST_FOR_EACH_POP(pkt, list_node, l) {
+        dp_packet_delete(pkt->pkt);
+        free(pkt);
+    }
+}
+
+static struct dp_packet *
 eth_from_packet_or_flow(const char *s)
 {
     enum odp_key_fitness fitness;
-    struct ofpbuf *packet;
+    struct dp_packet *packet;
     struct ofpbuf odp_key;
     struct flow flow;
     int error;
@@ -1142,13 +1299,13 @@ eth_from_packet_or_flow(const char *s)
     }
 
     /* Convert odp_key to flow. */
-    fitness = odp_flow_key_to_flow(ofpbuf_data(&odp_key), ofpbuf_size(&odp_key), &flow);
+    fitness = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
     if (fitness == ODP_FIT_ERROR) {
         ofpbuf_uninit(&odp_key);
         return NULL;
     }
 
-    packet = ofpbuf_new(0);
+    packet = dp_packet_new(0);
     flow_compose(packet, &flow);
 
     ofpbuf_uninit(&odp_key);
@@ -1156,15 +1313,18 @@ eth_from_packet_or_flow(const char *s)
 }
 
 static void
-netdev_dummy_queue_packet__(struct netdev_rxq_dummy *rx, struct ofpbuf *packet)
+netdev_dummy_queue_packet__(struct netdev_rxq_dummy *rx, struct dp_packet *packet)
 {
-    list_push_back(&rx->recv_queue, &packet->list_node);
+    struct pkt_list_node *pkt_node = xmalloc(sizeof *pkt_node);
+
+    pkt_node->pkt = packet;
+    list_push_back(&rx->recv_queue, &pkt_node->list_node);
     rx->recv_queue_len++;
     seq_change(rx->seq);
 }
 
 static void
-netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct ofpbuf *packet)
+netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct dp_packet *packet)
     OVS_REQUIRES(dummy->mutex)
 {
     struct netdev_rxq_dummy *rx, *prev;
@@ -1177,7 +1337,7 @@ netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct ofpbuf *packet)
     LIST_FOR_EACH (rx, node, &dummy->rxes) {
         if (rx->recv_queue_len < NETDEV_DUMMY_MAX_QUEUE) {
             if (prev) {
-                netdev_dummy_queue_packet__(prev, ofpbuf_clone(packet));
+                netdev_dummy_queue_packet__(prev, dp_packet_clone(packet));
             }
             prev = rx;
         }
@@ -1185,7 +1345,7 @@ netdev_dummy_queue_packet(struct netdev_dummy *dummy, struct ofpbuf *packet)
     if (prev) {
         netdev_dummy_queue_packet__(prev, packet);
     } else {
-        ofpbuf_delete(packet);
+        dp_packet_delete(packet);
     }
 }
 
@@ -1205,7 +1365,7 @@ netdev_dummy_receive(struct unixctl_conn *conn,
     dummy_dev = netdev_dummy_cast(netdev);
 
     for (i = 2; i < argc; i++) {
-        struct ofpbuf *packet;
+        struct dp_packet *packet;
 
         packet = eth_from_packet_or_flow(argv[i]);
         if (!packet) {
@@ -1352,31 +1512,71 @@ netdev_dummy_ip4addr(struct unixctl_conn *conn, int argc OVS_UNUSED,
     struct netdev *netdev = netdev_from_name(argv[1]);
 
     if (netdev && is_dummy_class(netdev->netdev_class)) {
-        struct in_addr ip;
-        uint16_t plen;
+        struct in_addr ip, mask;
+        char *error;
 
-        if (ovs_scan(argv[2], IP_SCAN_FMT"/%"SCNi16,
-                     IP_SCAN_ARGS(&ip.s_addr), &plen)) {
-            struct in_addr mask;
-
-            mask.s_addr = be32_prefix_mask(plen);
+        error = ip_parse_masked(argv[2], &ip.s_addr, &mask.s_addr);
+        if (!error) {
             netdev_dummy_set_in4(netdev, ip, mask);
             unixctl_command_reply(conn, "OK");
         } else {
-            unixctl_command_reply(conn, "Invalid parameters");
+            unixctl_command_reply_error(conn, error);
+            free(error);
         }
+    } else {
+        unixctl_command_reply_error(conn, "Unknown Dummy Interface");
+    }
 
+    netdev_close(netdev);
+}
+
+static void
+netdev_dummy_ip6addr(struct unixctl_conn *conn, int argc OVS_UNUSED,
+                     const char *argv[], void *aux OVS_UNUSED)
+{
+    struct netdev *netdev = netdev_from_name(argv[1]);
+
+    if (netdev && is_dummy_class(netdev->netdev_class)) {
+        char ip6_s[IPV6_SCAN_LEN + 1];
+        struct in6_addr ip6;
+
+        if (ovs_scan(argv[2], IPV6_SCAN_FMT, ip6_s) &&
+            inet_pton(AF_INET6, ip6_s, &ip6) == 1) {
+            netdev_dummy_set_in6(netdev, &ip6);
+            unixctl_command_reply(conn, "OK");
+        } else {
+            unixctl_command_reply_error(conn, "Invalid parameters");
+        }
         netdev_close(netdev);
     } else {
         unixctl_command_reply_error(conn, "Unknown Dummy Interface");
-        netdev_close(netdev);
-        return;
     }
 
+    netdev_close(netdev);
+}
+
+
+static void
+netdev_dummy_override(const char *type)
+{
+    if (!netdev_unregister_provider(type)) {
+        struct netdev_class *class;
+        int error;
+
+        class = xmemdup(&dummy_class, sizeof dummy_class);
+        class->type = xstrdup(type);
+        error = netdev_register_provider(class);
+        if (error) {
+            VLOG_ERR("%s: failed to register netdev provider (%s)",
+                     type, ovs_strerror(error));
+            free(CONST_CAST(char *, class->type));
+            free(class);
+        }
+    }
 }
 
 void
-netdev_dummy_register(bool override)
+netdev_dummy_register(enum dummy_level level)
 {
     unixctl_command_register("netdev-dummy/receive", "name packet|flow...",
                              2, INT_MAX, netdev_dummy_receive, NULL);
@@ -1389,34 +1589,24 @@ netdev_dummy_register(bool override)
     unixctl_command_register("netdev-dummy/ip4addr",
                              "[netdev] ipaddr/mask-prefix-len", 2, 2,
                              netdev_dummy_ip4addr, NULL);
+    unixctl_command_register("netdev-dummy/ip6addr",
+                             "[netdev] ip6addr", 2, 2,
+                             netdev_dummy_ip6addr, NULL);
 
-
-    if (override) {
+    if (level == DUMMY_OVERRIDE_ALL) {
         struct sset types;
         const char *type;
 
         sset_init(&types);
         netdev_enumerate_types(&types);
         SSET_FOR_EACH (type, &types) {
-            if (!strcmp(type, "patch")) {
-                continue;
-            }
-            if (!netdev_unregister_provider(type)) {
-                struct netdev_class *class;
-                int error;
-
-                class = xmemdup(&dummy_class, sizeof dummy_class);
-                class->type = xstrdup(type);
-                error = netdev_register_provider(class);
-                if (error) {
-                    VLOG_ERR("%s: failed to register netdev provider (%s)",
-                             type, ovs_strerror(error));
-                    free(CONST_CAST(char *, class->type));
-                    free(class);
-                }
+            if (strcmp(type, "patch")) {
+                netdev_dummy_override(type);
             }
         }
         sset_destroy(&types);
+    } else if (level == DUMMY_OVERRIDE_SYSTEM) {
+        netdev_dummy_override("system");
     }
     netdev_register_provider(&dummy_class);