X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=lib%2Fdpif-netdev.c;h=911cb5dc1f7e4c6a66453b288c0be3ba32f46007;hb=bc0d88eece4d6f0a5703d59102a7cf8f1f8c7372;hp=3007d9ffdcac9018170fd7f758254e742bab3e44;hpb=2c0ea78f0ac532e4e48739235f43c9b7432b9270;p=sliver-openvswitch.git diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 3007d9ffd..911cb5dc1 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -168,8 +168,8 @@ static int dpif_netdev_open(const struct dpif_class *, const char *name, static int dp_netdev_output_userspace(struct dp_netdev *, const struct ofpbuf *, int queue_no, const struct flow *, const struct nlattr *userdata); -static void dp_netdev_execute_actions(struct dp_netdev *, - struct ofpbuf *, struct flow *, +static void dp_netdev_execute_actions(struct dp_netdev *, const struct flow *, + struct ofpbuf *, const struct nlattr *actions, size_t actions_len); static void dp_netdev_port_input(struct dp_netdev *dp, @@ -292,7 +292,7 @@ create_dp_netdev(const char *name, const struct dpif_class *class, dp->queues[i].head = dp->queues[i].tail = 0; } dp->queue_seq = seq_create(); - classifier_init(&dp->cls); + classifier_init(&dp->cls, NULL); hmap_init(&dp->flow_table); list_init(&dp->port_list); dp->port_seq = seq_create(); @@ -1107,8 +1107,7 @@ static int dpif_netdev_execute(struct dpif *dpif, const struct dpif_execute *execute) { struct dp_netdev *dp = get_dp_netdev(dpif); - struct ofpbuf copy; - struct flow key; + struct flow md; int error; if (execute->packet->size < ETH_HEADER_LEN || @@ -1116,22 +1115,24 @@ dpif_netdev_execute(struct dpif *dpif, const struct dpif_execute *execute) return EINVAL; } - /* Make a deep copy of 'packet', because we might modify its data. */ - ofpbuf_init(©, DP_NETDEV_HEADROOM + execute->packet->size); - ofpbuf_reserve(©, DP_NETDEV_HEADROOM); - ofpbuf_put(©, execute->packet->data, execute->packet->size); - - flow_extract(©, 0, 0, NULL, NULL, &key); - error = dpif_netdev_flow_from_nlattrs(execute->key, execute->key_len, - &key); + /* Get packet metadata. */ + error = dpif_netdev_flow_from_nlattrs(execute->key, execute->key_len, &md); if (!error) { + struct ofpbuf *copy; + struct flow key; + + /* Make a deep copy of 'packet', because we might modify its data. */ + copy = ofpbuf_clone_with_headroom(execute->packet, DP_NETDEV_HEADROOM); + + /* Extract flow key. */ + flow_extract(copy, md.skb_priority, md.pkt_mark, &md.tunnel, + &md.in_port, &key); ovs_mutex_lock(&dp_netdev_mutex); - dp_netdev_execute_actions(dp, ©, &key, + dp_netdev_execute_actions(dp, &key, copy, execute->actions, execute->actions_len); ovs_mutex_unlock(&dp_netdev_mutex); + ofpbuf_delete(copy); } - - ofpbuf_uninit(©); return error; } @@ -1243,7 +1244,7 @@ dp_netdev_port_input(struct dp_netdev *dp, struct dp_netdev_port *port, netdev_flow = dp_netdev_lookup_flow(dp, &key); if (netdev_flow) { dp_netdev_flow_used(netdev_flow, packet); - dp_netdev_execute_actions(dp, packet, &key, + dp_netdev_execute_actions(dp, &key, packet, netdev_flow->actions, netdev_flow->actions_len); dp->n_hit++; @@ -1313,17 +1314,6 @@ dpif_netdev_wait(struct dpif *dpif) ovs_mutex_unlock(&dp_netdev_mutex); } -static void -dp_netdev_output_port(void *dp_, struct ofpbuf *packet, - const struct flow *flow OVS_UNUSED, odp_port_t out_port) -{ - struct dp_netdev *dp = dp_; - 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, @@ -1375,25 +1365,46 @@ dp_netdev_output_userspace(struct dp_netdev *dp, const struct ofpbuf *packet, } } +struct dp_netdev_execute_aux { + struct dp_netdev *dp; + const struct flow *key; +}; + static void -dp_netdev_action_userspace(void *dp, struct ofpbuf *packet, - const struct flow *key, +dp_netdev_action_output(void *aux_, struct ofpbuf *packet, + const struct flow *flow OVS_UNUSED, + odp_port_t out_port) +{ + 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); + } +} + +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; userdata = nl_attr_find_nested(a, OVS_USERSPACE_ATTR_USERDATA); - dp_netdev_output_userspace(dp, packet, DPIF_UC_ACTION, key, userdata); + dp_netdev_output_userspace(aux->dp, packet, DPIF_UC_ACTION, aux->key, + userdata); } static void -dp_netdev_execute_actions(struct dp_netdev *dp, - struct ofpbuf *packet, struct flow *key, - const struct nlattr *actions, - size_t actions_len) +dp_netdev_execute_actions(struct dp_netdev *dp, const struct flow *key, + struct ofpbuf *packet, + const struct nlattr *actions, size_t actions_len) { - odp_execute_actions(dp, packet, key, actions, actions_len, - dp_netdev_output_port, dp_netdev_action_userspace); + struct dp_netdev_execute_aux aux = {dp, 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); } const struct dpif_class dpif_netdev_class = {