Use one callback instead of many, helps in adding new functionality later on.
Signed-off-by: Jarno Rajahalme <jrajaha...@nicira.com> --- lib/dpif-netdev.c | 55 +++++++++++++++++++++++++++--------------- lib/dpif.c | 43 ++++++++++++++++----------------- lib/odp-execute.c | 50 +++++++++++++------------------------- lib/odp-execute.h | 13 +++++----- ofproto/ofproto-dpif-xlate.c | 2 +- 5 files changed, 81 insertions(+), 82 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 9e1ade5..9c79ad1 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -1232,6 +1232,16 @@ dpif_netdev_wait(struct dpif *dpif) 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, const struct ofpbuf *packet, int queue_no, const struct flow *flow, @@ -1289,28 +1299,35 @@ struct dp_netdev_execute_aux { }; 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) { 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) -{ - 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, 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); - dp_netdev_output_userspace(aux->dp, packet, DPIF_UC_ACTION, aux->key, - userdata); + userdata = nl_attr_find_nested(a, OVS_USERSPACE_ATTR_USERDATA); + dp_netdev_output_userspace(aux->dp, packet, DPIF_UC_ACTION, aux->key, + userdata); + 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: + NOT_REACHED(); + } } static void @@ -1322,7 +1339,7 @@ dp_netdev_execute_actions(struct dp_netdev *dp, const struct flow *key, 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 = { diff --git a/lib/dpif.c b/lib/dpif.c index dd77ebf..6cfa4e6 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -1088,26 +1088,26 @@ dpif_execute_helper_execute__(void *aux_, struct ofpbuf *packet, } 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) -{ - 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) +{ + 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: + NOT_REACHED(); + } } /* Executes 'execute' by performing most of the actions in userspace and @@ -1136,8 +1136,7 @@ dpif_execute_with_help(struct dpif *dpif, struct dpif_execute *execute) packet = ofpbuf_clone_with_headroom(execute->packet, VLAN_HEADER_LEN); odp_execute_actions(&aux, packet, &flow, execute->actions, execute->actions_len, - dpif_execute_helper_output_cb, - dpif_execute_helper_userspace_cb); + dpif_execute_helper_cb); ofpbuf_delete(packet); return aux.error; diff --git a/lib/odp-execute.c b/lib/odp-execute.c index af3370d..8b29ddc 100644 --- a/lib/odp-execute.c +++ b/lib/odp-execute.c @@ -29,7 +29,8 @@ #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; @@ -60,7 +61,7 @@ set_arp(struct ofpbuf *packet, const struct ovs_key_arp *arp_key) 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; @@ -71,15 +72,15 @@ odp_execute_set_action(struct ofpbuf *packet, const struct nlattr *a, 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: @@ -139,14 +140,8 @@ odp_execute_set_action(struct ofpbuf *packet, const struct nlattr *a, } static void -odp_execute_sample(void *dp, struct ofpbuf *packet, struct flow *key, - const struct nlattr *action, - void (*output)(void *dp, struct ofpbuf *packet, - const struct flow *key, - odp_port_t out_port), - void (*userspace)(void *dp, struct ofpbuf *packet, - const struct flow *key, - const struct nlattr *action)) +odp_execute_sample(void *dp, struct ofpbuf *packet, struct flow *md, + const struct nlattr *action, odp_execute_callback callback) { const struct nlattr *subactions = NULL; const struct nlattr *a; @@ -173,19 +168,14 @@ odp_execute_sample(void *dp, struct ofpbuf *packet, struct flow *key, } } - 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), callback); } 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, - void (*output)(void *dp, struct ofpbuf *packet, - const struct flow *key, - odp_port_t out_port), - void (*userspace)(void *dp, struct ofpbuf *packet, - const struct flow *key, - const struct nlattr *action)) + odp_execute_callback callback) { const struct nlattr *a; unsigned int left; @@ -195,18 +185,12 @@ odp_execute_actions(void *dp, struct ofpbuf *packet, struct flow *key, switch ((enum ovs_action_attr) type) { case OVS_ACTION_ATTR_OUTPUT: - if (output) { - output(dp, packet, key, u32_to_odp(nl_attr_get_u32(a))); + case OVS_ACTION_ATTR_USERSPACE: + if (callback) { + callback(dp, packet, md, a); } break; - case OVS_ACTION_ATTR_USERSPACE: { - if (userspace) { - userspace(dp, packet, key, a); - } - break; - } - case OVS_ACTION_ATTR_PUSH_VLAN: { const struct ovs_action_push_vlan *vlan = nl_attr_get(a); eth_push_vlan(packet, vlan->vlan_tci); @@ -228,11 +212,11 @@ odp_execute_actions(void *dp, struct ofpbuf *packet, struct flow *key, 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, callback); break; case OVS_ACTION_ATTR_UNSPEC: diff --git a/lib/odp-execute.h b/lib/odp-execute.h index 5d9fa90..6f2376b 100644 --- a/lib/odp-execute.h +++ b/lib/odp-execute.h @@ -26,13 +26,12 @@ struct flow; struct nlattr; struct ofpbuf; +typedef void (*odp_execute_callback)(void *dp, struct ofpbuf *packet, + struct flow *metadata, + const struct nlattr *action); + 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, - void (*output)(void *dp, struct ofpbuf *packet, - const struct flow *key, - odp_port_t out_port), - void (*userspace)(void *dp, struct ofpbuf *packet, - const struct flow *key, - const struct nlattr *action)); + odp_execute_callback callback); #endif diff --git a/ofproto/ofproto-dpif-xlate.c b/ofproto/ofproto-dpif-xlate.c index 367dd88..fa1dc30 100644 --- a/ofproto/ofproto-dpif-xlate.c +++ b/ofproto/ofproto-dpif-xlate.c @@ -2058,7 +2058,7 @@ execute_controller_action(struct xlate_ctx *ctx, int len, &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; -- 1.7.10.4 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev