+ for (;;) {
+ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
+ uint64_t buf_stub[4096 / 8];
+ struct ofpbuf buf;
+ int error;
+
+ ofpbuf_use_stub(&buf, buf_stub, sizeof buf_stub);
+ error = nl_sock_recv(dpif->port_notifier, &buf, false);
+ if (!error) {
+ struct dpif_linux_vport vport;
+
+ error = dpif_linux_vport_from_ofpbuf(&vport, &buf);
+ if (!error) {
+ if (vport.dp_ifindex == dpif->dp_ifindex
+ && (vport.cmd == OVS_VPORT_CMD_NEW
+ || vport.cmd == OVS_VPORT_CMD_DEL
+ || vport.cmd == OVS_VPORT_CMD_SET)) {
+ VLOG_DBG("port_changed: dpif:%s vport:%s cmd:%"PRIu8,
+ dpif->dpif.full_name, vport.name, vport.cmd);
+ *devnamep = xstrdup(vport.name);
+ ofpbuf_uninit(&buf);
+ return 0;
+ }
+ }
+ } else if (error != EAGAIN) {
+ VLOG_WARN_RL(&rl, "error reading or parsing netlink (%s)",
+ ovs_strerror(error));
+ nl_sock_drain(dpif->port_notifier);
+ error = ENOBUFS;
+ }
+
+ ofpbuf_uninit(&buf);
+ if (error) {
+ return error;
+ }
+ }
+}
+
+static void
+dpif_linux_port_poll_wait(const struct dpif *dpif_)
+{
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+
+ if (dpif->port_notifier) {
+ nl_sock_wait(dpif->port_notifier, POLLIN);
+ } else {
+ poll_immediate_wake();
+ }
+}
+
+static int
+dpif_linux_flow_get__(const struct dpif *dpif_,
+ const struct nlattr *key, size_t key_len,
+ struct dpif_linux_flow *reply, struct ofpbuf **bufp)
+{
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ struct dpif_linux_flow request;
+
+ dpif_linux_flow_init(&request);
+ request.cmd = OVS_FLOW_CMD_GET;
+ request.dp_ifindex = dpif->dp_ifindex;
+ request.key = key;
+ request.key_len = key_len;
+ return dpif_linux_flow_transact(&request, reply, bufp);
+}
+
+static int
+dpif_linux_flow_get(const struct dpif *dpif_,
+ const struct nlattr *key, size_t key_len,
+ struct ofpbuf **actionsp, struct dpif_flow_stats *stats)
+{
+ struct dpif_linux_flow reply;
+ struct ofpbuf *buf;
+ int error;
+
+ error = dpif_linux_flow_get__(dpif_, key, key_len, &reply, &buf);
+ if (!error) {
+ if (stats) {
+ dpif_linux_flow_get_stats(&reply, stats);
+ }
+ if (actionsp) {
+ buf->data = CONST_CAST(struct nlattr *, reply.actions);
+ buf->size = reply.actions_len;
+ *actionsp = buf;
+ } else {
+ ofpbuf_delete(buf);
+ }
+ }
+ return error;
+}
+
+static void
+dpif_linux_init_flow_put(struct dpif *dpif_, const struct dpif_flow_put *put,
+ struct dpif_linux_flow *request)
+{
+ static const struct nlattr dummy_action;
+
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+
+ dpif_linux_flow_init(request);
+ request->cmd = (put->flags & DPIF_FP_CREATE
+ ? OVS_FLOW_CMD_NEW : OVS_FLOW_CMD_SET);
+ request->dp_ifindex = dpif->dp_ifindex;
+ request->key = put->key;
+ request->key_len = put->key_len;
+ request->mask = put->mask;
+ request->mask_len = put->mask_len;
+ /* Ensure that OVS_FLOW_ATTR_ACTIONS will always be included. */
+ request->actions = (put->actions
+ ? put->actions
+ : CONST_CAST(struct nlattr *, &dummy_action));
+ request->actions_len = put->actions_len;
+ if (put->flags & DPIF_FP_ZERO_STATS) {
+ request->clear = true;
+ }
+ request->nlmsg_flags = put->flags & DPIF_FP_MODIFY ? 0 : NLM_F_CREATE;
+}
+
+static int
+dpif_linux_flow_put(struct dpif *dpif_, const struct dpif_flow_put *put)
+{
+ struct dpif_linux_flow request, reply;
+ struct ofpbuf *buf;
+ int error;
+
+ dpif_linux_init_flow_put(dpif_, put, &request);
+ error = dpif_linux_flow_transact(&request,
+ put->stats ? &reply : NULL,
+ put->stats ? &buf : NULL);
+ if (!error && put->stats) {
+ dpif_linux_flow_get_stats(&reply, put->stats);
+ ofpbuf_delete(buf);
+ }
+ return error;
+}
+
+static void
+dpif_linux_init_flow_del(struct dpif *dpif_, const struct dpif_flow_del *del,
+ struct dpif_linux_flow *request)
+{
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+
+ dpif_linux_flow_init(request);
+ request->cmd = OVS_FLOW_CMD_DEL;
+ request->dp_ifindex = dpif->dp_ifindex;
+ request->key = del->key;
+ request->key_len = del->key_len;
+}
+
+static int
+dpif_linux_flow_del(struct dpif *dpif_, const struct dpif_flow_del *del)
+{
+ struct dpif_linux_flow request, reply;
+ struct ofpbuf *buf;
+ int error;
+
+ dpif_linux_init_flow_del(dpif_, del, &request);
+ error = dpif_linux_flow_transact(&request,
+ del->stats ? &reply : NULL,
+ del->stats ? &buf : NULL);
+ if (!error && del->stats) {
+ dpif_linux_flow_get_stats(&reply, del->stats);
+ ofpbuf_delete(buf);