ovs_mutex_unlock(&dp_netdev_mutex);
}
+static void
+dp_netdev_output_port(struct dp_netdev *dp, struct ofpbuf *packet,
+ odp_port_t out_port)
+{
+ struct dp_netdev_port *p = dp->ports[odp_to_u32(out_port)];
+ if (p) {
+ netdev_send(p->netdev, packet);
+ }
+}
+
static int
dp_netdev_output_userspace(struct dp_netdev *dp, struct ofpbuf *packet,
int queue_no, const struct flow *flow,
};
static void
-dp_netdev_action_output(void *aux_, struct ofpbuf *packet,
- const struct flow *flow OVS_UNUSED,
- odp_port_t out_port)
+dp_execute_cb(void *aux_, struct ofpbuf *packet, struct flow *flow OVS_UNUSED,
+ const struct nlattr *a, bool may_steal)
{
struct dp_netdev_execute_aux *aux = aux_;
- struct dp_netdev_port *p = aux->dp->ports[odp_to_u32(out_port)];
- if (p) {
- netdev_send(p->netdev, packet);
- }
-}
+ int type = nl_attr_type(a);
-static void
-dp_netdev_action_userspace(void *aux_, struct ofpbuf *packet,
- const struct flow *flow OVS_UNUSED,
- const struct nlattr *a, bool may_steal)
-{
- struct dp_netdev_execute_aux *aux = aux_;
- const struct nlattr *userdata;
+ switch ((enum ovs_action_attr)type) {
+ case OVS_ACTION_ATTR_OUTPUT:
+ dp_netdev_output_port(aux->dp, packet, u32_to_odp(nl_attr_get_u32(a)));
+ break;
+
+ case OVS_ACTION_ATTR_USERSPACE: {
+ const struct nlattr *userdata;
- userdata = nl_attr_find_nested(a, OVS_USERSPACE_ATTR_USERDATA);
+ userdata = nl_attr_find_nested(a, OVS_USERSPACE_ATTR_USERDATA);
- /* Make a copy if we are not allowed to steal the packet's data. */
- if (!may_steal) {
- packet = ofpbuf_clone_with_headroom(packet, DP_NETDEV_HEADROOM);
+ /* Make a copy if we are not allowed to steal the packet's data. */
+ if (!may_steal) {
+ packet = ofpbuf_clone_with_headroom(packet, DP_NETDEV_HEADROOM);
+ }
+ dp_netdev_output_userspace(aux->dp, packet, DPIF_UC_ACTION, aux->key,
+ userdata);
+ if (!may_steal) {
+ ofpbuf_uninit(packet);
+ }
+ break;
}
- dp_netdev_output_userspace(aux->dp, packet, DPIF_UC_ACTION, aux->key,
- userdata);
- if (!may_steal) {
- ofpbuf_uninit(packet);
+ case OVS_ACTION_ATTR_PUSH_VLAN:
+ case OVS_ACTION_ATTR_POP_VLAN:
+ case OVS_ACTION_ATTR_PUSH_MPLS:
+ case OVS_ACTION_ATTR_POP_MPLS:
+ case OVS_ACTION_ATTR_SET:
+ case OVS_ACTION_ATTR_SAMPLE:
+ case OVS_ACTION_ATTR_UNSPEC:
+ case __OVS_ACTION_ATTR_MAX:
+ OVS_NOT_REACHED();
}
}
struct flow md = *key; /* Packet metadata, may be modified by actions. */
odp_execute_actions(&aux, packet, &md, actions, actions_len,
- dp_netdev_action_output, dp_netdev_action_userspace);
+ dp_execute_cb);
}
const struct dpif_class dpif_netdev_class = {
}
}
+/* This is called for actions that need the context of the datapath to be
+ * meaningful. */
static void
-dpif_execute_helper_output_cb(void *aux, struct ofpbuf *packet,
- const struct flow *flow, odp_port_t out_port)
-{
- uint64_t actions_stub[DIV_ROUND_UP(NL_A_U32_SIZE, 8)];
- struct ofpbuf actions;
-
- ofpbuf_use_stack(&actions, actions_stub, sizeof actions_stub);
- nl_msg_put_u32(&actions, OVS_ACTION_ATTR_OUTPUT, odp_to_u32(out_port));
-
- dpif_execute_helper_execute__(aux, packet, flow,
- actions.data, actions.size);
-}
-
-static void
-dpif_execute_helper_userspace_cb(void *aux, struct ofpbuf *packet,
- const struct flow *flow,
- const struct nlattr *action,
- bool may_steal OVS_UNUSED)
-{
- dpif_execute_helper_execute__(aux, packet, flow,
- action, NLA_ALIGN(action->nla_len));
+dpif_execute_helper_cb(void *aux, struct ofpbuf *packet, struct flow *flow,
+ const struct nlattr *action, bool may_steal OVS_UNUSED)
+{
+ int type = nl_attr_type(action);
+ switch ((enum ovs_action_attr)type) {
+ case OVS_ACTION_ATTR_OUTPUT:
+ case OVS_ACTION_ATTR_USERSPACE:
+ dpif_execute_helper_execute__(aux, packet, flow,
+ action, NLA_ALIGN(action->nla_len));
+ break;
+ case OVS_ACTION_ATTR_PUSH_VLAN:
+ case OVS_ACTION_ATTR_POP_VLAN:
+ case OVS_ACTION_ATTR_PUSH_MPLS:
+ case OVS_ACTION_ATTR_POP_MPLS:
+ case OVS_ACTION_ATTR_SET:
+ case OVS_ACTION_ATTR_SAMPLE:
+ case OVS_ACTION_ATTR_UNSPEC:
+ case __OVS_ACTION_ATTR_MAX:
+ OVS_NOT_REACHED();
+ }
}
/* Executes 'execute' by performing most of the actions in userspace and
odp_execute_actions(&aux, execute->packet, &flow,
execute->actions, execute->actions_len,
- dpif_execute_helper_output_cb,
- dpif_execute_helper_userspace_cb);
+ dpif_execute_helper_cb);
return aux.error;
}
#include "util.h"
static void
-odp_eth_set_addrs(struct ofpbuf *packet, const struct ovs_key_ethernet *eth_key)
+odp_eth_set_addrs(struct ofpbuf *packet,
+ const struct ovs_key_ethernet *eth_key)
{
struct eth_header *eh = packet->l2;
static void
odp_execute_set_action(struct ofpbuf *packet, const struct nlattr *a,
- struct flow *flow)
+ struct flow *md)
{
enum ovs_key_attr type = nl_attr_type(a);
const struct ovs_key_ipv4 *ipv4_key;
switch (type) {
case OVS_KEY_ATTR_PRIORITY:
- flow->skb_priority = nl_attr_get_u32(a);
+ md->skb_priority = nl_attr_get_u32(a);
break;
case OVS_KEY_ATTR_TUNNEL:
- odp_set_tunnel_action(a, &flow->tunnel);
+ odp_set_tunnel_action(a, &md->tunnel);
break;
case OVS_KEY_ATTR_SKB_MARK:
- flow->pkt_mark = nl_attr_get_u32(a);
+ md->pkt_mark = nl_attr_get_u32(a);
break;
case OVS_KEY_ATTR_ETHERNET:
static void
odp_execute_actions__(void *dp, struct ofpbuf *packet, struct flow *key,
const struct nlattr *actions, size_t actions_len,
- odp_output_cb output, odp_userspace_cb userspace,
- bool more_actions);
+ odp_execute_cb dp_execute_action, bool more_actions);
static void
-odp_execute_sample(void *dp, struct ofpbuf *packet, struct flow *key,
- const struct nlattr *action, odp_output_cb output,
- odp_userspace_cb userspace, bool more_actions)
+odp_execute_sample(void *dp, struct ofpbuf *packet, struct flow *md,
+ const struct nlattr *action,
+ odp_execute_cb dp_execute_action, bool more_actions)
{
const struct nlattr *subactions = NULL;
const struct nlattr *a;
}
}
- odp_execute_actions__(dp, packet, key, nl_attr_get(subactions),
- nl_attr_get_size(subactions), output, userspace,
+ odp_execute_actions__(dp, packet, md, nl_attr_get(subactions),
+ nl_attr_get_size(subactions), dp_execute_action,
more_actions);
}
static void
-odp_execute_actions__(void *dp, struct ofpbuf *packet, struct flow *key,
+odp_execute_actions__(void *dp, struct ofpbuf *packet, struct flow *md,
const struct nlattr *actions, size_t actions_len,
- odp_output_cb output, odp_userspace_cb userspace,
- bool more_actions)
+ odp_execute_cb dp_execute_action, bool more_actions)
{
const struct nlattr *a;
unsigned int left;
int type = nl_attr_type(a);
switch ((enum ovs_action_attr) type) {
+ /* These only make sense in the context of a datapath. */
case OVS_ACTION_ATTR_OUTPUT:
- if (output) {
- output(dp, packet, key, u32_to_odp(nl_attr_get_u32(a)));
- }
- break;
-
- case OVS_ACTION_ATTR_USERSPACE: {
- if (userspace) {
- /* Allow 'userspace' to steal the packet data if we do not
- * need it any more. */
+ case OVS_ACTION_ATTR_USERSPACE:
+ if (dp_execute_action) {
+ /* Allow 'dp_execute_action' to steal the packet data if we do
+ * not need it any more. */
bool steal = !more_actions && left <= NLA_ALIGN(a->nla_len);
- userspace(dp, packet, key, a, steal);
+ dp_execute_action(dp, packet, md, a, steal);
}
break;
- }
case OVS_ACTION_ATTR_PUSH_VLAN: {
const struct ovs_action_push_vlan *vlan = nl_attr_get(a);
break;
case OVS_ACTION_ATTR_SET:
- odp_execute_set_action(packet, nl_attr_get(a), key);
+ odp_execute_set_action(packet, nl_attr_get(a), md);
break;
case OVS_ACTION_ATTR_SAMPLE:
- odp_execute_sample(dp, packet, key, a, output, userspace,
+ odp_execute_sample(dp, packet, md, a, dp_execute_action,
more_actions || left > NLA_ALIGN(a->nla_len));
break;
}
void
-odp_execute_actions(void *dp, struct ofpbuf *packet, struct flow *key,
+odp_execute_actions(void *dp, struct ofpbuf *packet, struct flow *md,
const struct nlattr *actions, size_t actions_len,
- odp_output_cb output, odp_userspace_cb userspace)
+ odp_execute_cb dp_execute_action)
{
- odp_execute_actions__(dp, packet, key, actions, actions_len, output,
- userspace, false);
+ odp_execute_actions__(dp, packet, md, actions, actions_len,
+ dp_execute_action, false);
}
struct nlattr;
struct ofpbuf;
-typedef void (*odp_output_cb)(void *dp, struct ofpbuf *packet,
- const struct flow *key, odp_port_t out_port);
-typedef void (*odp_userspace_cb)(void *dp, struct ofpbuf *packet,
- const struct flow *key,
- const struct nlattr *action, bool may_steal);
+typedef void (*odp_execute_cb)(void *dp, struct ofpbuf *packet,
+ struct flow *metadata,
+ const struct nlattr *action, bool may_steal);
+/* Actions that need to be executed in the context of a datapath are handed
+ * to 'dp_execute_action', if non-NULL. Currently this is called only for
+ * actions OVS_ACTION_ATTR_OUTPUT and OVS_ACTION_ATTR_USERSPACE so
+ * 'dp_execute_action' needs to handle only these. */
void
-odp_execute_actions(void *dp, struct ofpbuf *packet, struct flow *key,
+odp_execute_actions(void *dp, struct ofpbuf *packet, struct flow *metadata,
const struct nlattr *actions, size_t actions_len,
- odp_output_cb output, odp_userspace_cb userspace);
+ odp_execute_cb dp_execute_action);
#endif
&ctx->mpls_depth_delta);
odp_execute_actions(NULL, packet, &key, ctx->xout->odp_actions.data,
- ctx->xout->odp_actions.size, NULL, NULL);
+ ctx->xout->odp_actions.size, NULL);
pin = xmalloc(sizeof *pin);
pin->up.packet_len = packet->size;