+ 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);
+ }
+ return error;
+}
+
+struct dpif_linux_flow_state {
+ struct nl_dump dump;
+ struct dpif_linux_flow flow;
+ struct dpif_flow_stats stats;
+ struct ofpbuf *buf;
+};
+
+static int
+dpif_linux_flow_dump_start(const struct dpif *dpif_, void **statep)
+{
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+ struct dpif_linux_flow_state *state;
+ struct dpif_linux_flow request;
+ struct ofpbuf *buf;
+
+ *statep = state = xmalloc(sizeof *state);
+
+ dpif_linux_flow_init(&request);
+ request.cmd = OVS_FLOW_CMD_GET;
+ request.dp_ifindex = dpif->dp_ifindex;
+
+ buf = ofpbuf_new(1024);
+ dpif_linux_flow_to_ofpbuf(&request, buf);
+ nl_dump_start(&state->dump, NETLINK_GENERIC, buf);
+ ofpbuf_delete(buf);
+
+ state->buf = NULL;
+
+ return 0;
+}
+
+static int
+dpif_linux_flow_dump_next(const struct dpif *dpif_ OVS_UNUSED, 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 dpif_linux_flow_state *state = state_;
+ struct ofpbuf buf;
+ int error;
+
+ do {
+ ofpbuf_delete(state->buf);
+ state->buf = NULL;
+
+ if (!nl_dump_next(&state->dump, &buf)) {
+ return EOF;
+ }
+
+ error = dpif_linux_flow_from_ofpbuf(&state->flow, &buf);
+ if (error) {
+ return error;
+ }
+
+ if (actions && !state->flow.actions) {
+ error = dpif_linux_flow_get__(dpif_, state->flow.key,
+ state->flow.key_len,
+ &state->flow, &state->buf);
+ if (error == ENOENT) {
+ VLOG_DBG("dumped flow disappeared on get");
+ } else if (error) {
+ VLOG_WARN("error fetching dumped flow: %s",
+ ovs_strerror(error));
+ }
+ }
+ } while (error);
+
+ if (actions) {
+ *actions = state->flow.actions;
+ *actions_len = state->flow.actions_len;
+ }
+ if (key) {
+ *key = state->flow.key;
+ *key_len = state->flow.key_len;
+ }
+ if (mask) {
+ *mask = state->flow.mask;
+ *mask_len = state->flow.mask ? state->flow.mask_len : 0;
+ }
+ if (stats) {
+ dpif_linux_flow_get_stats(&state->flow, &state->stats);
+ *stats = &state->stats;
+ }
+ return error;
+}
+
+static int
+dpif_linux_flow_dump_done(const struct dpif *dpif OVS_UNUSED, void *state_)
+{
+ struct dpif_linux_flow_state *state = state_;
+ int error = nl_dump_done(&state->dump);
+ ofpbuf_delete(state->buf);
+ free(state);
+ return error;
+}
+
+static void
+dpif_linux_encode_execute(int dp_ifindex, const struct dpif_execute *d_exec,
+ struct ofpbuf *buf)
+{
+ struct ovs_header *k_exec;
+
+ ofpbuf_prealloc_tailroom(buf, (64
+ + d_exec->packet->size
+ + d_exec->key_len
+ + d_exec->actions_len));
+
+ nl_msg_put_genlmsghdr(buf, 0, ovs_packet_family, NLM_F_REQUEST,
+ OVS_PACKET_CMD_EXECUTE, OVS_PACKET_VERSION);
+
+ k_exec = ofpbuf_put_uninit(buf, sizeof *k_exec);
+ k_exec->dp_ifindex = dp_ifindex;
+
+ nl_msg_put_unspec(buf, OVS_PACKET_ATTR_PACKET,
+ d_exec->packet->data, d_exec->packet->size);
+ nl_msg_put_unspec(buf, OVS_PACKET_ATTR_KEY, d_exec->key, d_exec->key_len);
+ nl_msg_put_unspec(buf, OVS_PACKET_ATTR_ACTIONS,
+ d_exec->actions, d_exec->actions_len);
+}
+
+static int
+dpif_linux_execute__(int dp_ifindex, const struct dpif_execute *execute)
+{
+ uint64_t request_stub[1024 / 8];
+ struct ofpbuf request;
+ int error;
+
+ ofpbuf_use_stub(&request, request_stub, sizeof request_stub);
+ dpif_linux_encode_execute(dp_ifindex, execute, &request);
+ error = nl_transact(NETLINK_GENERIC, &request, NULL);
+ ofpbuf_uninit(&request);
+
+ return error;
+}
+
+static int
+dpif_linux_execute(struct dpif *dpif_, const struct dpif_execute *execute)
+{
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+
+ return dpif_linux_execute__(dpif->dp_ifindex, execute);
+}
+
+#define MAX_OPS 50
+
+static void
+dpif_linux_operate__(struct dpif *dpif_, struct dpif_op **ops, size_t n_ops)
+{
+ const struct dpif_linux *dpif = dpif_linux_cast(dpif_);
+
+ struct op_auxdata {
+ struct nl_transaction txn;
+
+ struct ofpbuf request;
+ uint64_t request_stub[1024 / 8];
+
+ struct ofpbuf reply;
+ uint64_t reply_stub[1024 / 8];
+ } auxes[MAX_OPS];
+
+ struct nl_transaction *txnsp[MAX_OPS];
+ size_t i;
+
+ ovs_assert(n_ops <= MAX_OPS);
+ for (i = 0; i < n_ops; i++) {
+ struct op_auxdata *aux = &auxes[i];
+ struct dpif_op *op = ops[i];
+ struct dpif_flow_put *put;
+ struct dpif_flow_del *del;
+ struct dpif_execute *execute;
+ struct dpif_linux_flow flow;
+
+ ofpbuf_use_stub(&aux->request,
+ aux->request_stub, sizeof aux->request_stub);
+ aux->txn.request = &aux->request;
+
+ ofpbuf_use_stub(&aux->reply, aux->reply_stub, sizeof aux->reply_stub);
+ aux->txn.reply = NULL;
+
+ switch (op->type) {
+ case DPIF_OP_FLOW_PUT:
+ put = &op->u.flow_put;
+ dpif_linux_init_flow_put(dpif_, put, &flow);
+ if (put->stats) {
+ flow.nlmsg_flags |= NLM_F_ECHO;
+ aux->txn.reply = &aux->reply;
+ }
+ dpif_linux_flow_to_ofpbuf(&flow, &aux->request);
+ break;
+
+ case DPIF_OP_FLOW_DEL:
+ del = &op->u.flow_del;
+ dpif_linux_init_flow_del(dpif_, del, &flow);
+ if (del->stats) {
+ flow.nlmsg_flags |= NLM_F_ECHO;
+ aux->txn.reply = &aux->reply;
+ }
+ dpif_linux_flow_to_ofpbuf(&flow, &aux->request);
+ break;
+
+ case DPIF_OP_EXECUTE:
+ execute = &op->u.execute;
+ dpif_linux_encode_execute(dpif->dp_ifindex, execute,
+ &aux->request);
+ break;
+
+ default:
+ NOT_REACHED();
+ }
+ }
+
+ for (i = 0; i < n_ops; i++) {
+ txnsp[i] = &auxes[i].txn;
+ }
+ nl_transact_multiple(NETLINK_GENERIC, txnsp, n_ops);
+
+ for (i = 0; i < n_ops; i++) {
+ struct op_auxdata *aux = &auxes[i];
+ struct nl_transaction *txn = &auxes[i].txn;
+ struct dpif_op *op = ops[i];
+ struct dpif_flow_put *put;
+ struct dpif_flow_del *del;
+
+ op->error = txn->error;
+
+ switch (op->type) {
+ case DPIF_OP_FLOW_PUT:
+ put = &op->u.flow_put;
+ if (put->stats) {
+ if (!op->error) {
+ struct dpif_linux_flow reply;
+
+ op->error = dpif_linux_flow_from_ofpbuf(&reply,
+ txn->reply);
+ if (!op->error) {
+ dpif_linux_flow_get_stats(&reply, put->stats);
+ }
+ }
+
+ if (op->error) {
+ memset(put->stats, 0, sizeof *put->stats);
+ }
+ }
+ break;
+
+ case DPIF_OP_FLOW_DEL:
+ del = &op->u.flow_del;
+ if (del->stats) {
+ if (!op->error) {
+ struct dpif_linux_flow reply;
+
+ op->error = dpif_linux_flow_from_ofpbuf(&reply,
+ txn->reply);
+ if (!op->error) {
+ dpif_linux_flow_get_stats(&reply, del->stats);
+ }
+ }
+
+ if (op->error) {
+ memset(del->stats, 0, sizeof *del->stats);
+ }
+ }
+ break;
+
+ case DPIF_OP_EXECUTE:
+ break;
+
+ default:
+ NOT_REACHED();
+ }
+
+ ofpbuf_uninit(&aux->request);
+ ofpbuf_uninit(&aux->reply);
+ }
+}
+
+static void
+dpif_linux_operate(struct dpif *dpif, struct dpif_op **ops, size_t n_ops)