vconn: Implement Unix domain socket vconn.
[sliver-openvswitch.git] / lib / dpif.c
index 08c83c7..202a182 100644 (file)
@@ -31,6 +31,7 @@
  * derivatives without specific, written prior permission.
  */
 
+#include <config.h>
 #include "dpif.h"
 
 #include <ctype.h>
@@ -42,6 +43,7 @@
 
 #include "buffer.h"
 #include "netlink.h"
+#include "netlink-protocol.h"
 #include "ofp-print.h"
 #include "openflow-netlink.h"
 #include "openflow.h"
@@ -127,13 +129,17 @@ dpif_recv_openflow(struct dpif *dp, struct buffer **bufferp,
     struct nlattr *attrs[ARRAY_SIZE(openflow_policy)];
     struct buffer *buffer;
     struct ofp_header *oh;
-    size_t ofp_len;
+    uint16_t ofp_len;
     int retval;
 
-    *bufferp = NULL;
+    buffer = *bufferp = NULL;
     do {
+        buffer_delete(buffer);
         retval = nl_sock_recv(dp->sock, &buffer, wait);
-    } while (retval == ENOBUFS || (!retval && nl_msg_nlmsgerr(buffer, NULL)));
+    } while (retval == ENOBUFS
+             || (!retval
+                 && (nl_msg_nlmsgerr(buffer, NULL)
+                     || nl_msg_nlmsghdr(buffer)->nlmsg_type == NLMSG_DONE)));
     if (retval) {
         if (retval != EAGAIN) {
             VLOG_WARN("dpif_recv_openflow: %s", strerror(retval)); 
@@ -191,6 +197,8 @@ error:
 int
 dpif_send_openflow(struct dpif *dp, struct buffer *buffer, bool wait) 
 {
+    struct ofp_header *oh;
+    unsigned int dump_flag;
     struct buffer hdr;
     struct nlattr *nla;
     uint32_t fixed_buffer[64 / 4];
@@ -199,9 +207,14 @@ dpif_send_openflow(struct dpif *dp, struct buffer *buffer, bool wait)
     int n_iov;
     int retval;
 
+    /* The reply to OFPT_STATS_REQUEST may be multiple segments long, so we
+     * need to specify NLM_F_DUMP in the request. */
+    oh = buffer_at_assert(buffer, 0, sizeof *oh);
+    dump_flag = oh->type == OFPT_STATS_REQUEST ? NLM_F_DUMP : 0;
+
     buffer_use(&hdr, fixed_buffer, sizeof fixed_buffer);
     nl_msg_put_genlmsghdr(&hdr, dp->sock, 32, openflow_family,
-                          NLM_F_REQUEST, DP_GENL_C_OPENFLOW, 1);
+                          NLM_F_REQUEST | dump_flag, DP_GENL_C_OPENFLOW, 1);
     nl_msg_put_u32(&hdr, DP_GENL_A_DP_IDX, dp->dp_idx);
     nla = buffer_put_uninit(&hdr, sizeof *nla);
     nla->nla_len = sizeof *nla + buffer->size;
@@ -257,25 +270,6 @@ dpif_del_port(struct dpif *dp, const char *netdev)
 {
     return send_mgmt_command(dp, DP_GENL_C_DEL_PORT, netdev);
 }
-
-/* Tells dp to send num_packets up through netlink for benchmarking*/
-int
-dpif_benchmark_nl(struct dpif *dp, uint32_t num_packets, uint32_t packet_size)
-{
-    struct buffer request;
-    int retval;
-
-    buffer_init(&request, 0);
-    nl_msg_put_genlmsghdr(&request, dp->sock, 0, openflow_family,
-                          NLM_F_REQUEST, DP_GENL_C_BENCHMARK_NL, 1);
-    nl_msg_put_u32(&request, DP_GENL_A_DP_IDX, dp->dp_idx);
-    nl_msg_put_u32(&request, DP_GENL_A_NPACKETS, num_packets);
-    nl_msg_put_u32(&request, DP_GENL_A_PSIZE, packet_size);
-    retval = nl_sock_send(dp->sock, &request, true);
-    buffer_uninit(&request);
-
-    return retval;
-}
 \f
 static const struct nl_policy openflow_multicast_policy[] = {
     [DP_GENL_A_DP_IDX] = { .type = NL_A_U32 },