@@ -630,12 +630,12 @@ tc_parse_flow_get(struct tc_offload *offload_tc, struct dpif_flow_get *get)
struct dpif_offload_port *port;
struct odputil_keybuf maskbuf;
struct odputil_keybuf keybuf;
- struct odputil_keybuf actbuf;
- struct ofpbuf key, mask, act;
+ size_t key_ofs, mask_ofs, act_ofs;
struct dpif_flow_stats stats;
struct dpif_flow_attrs attrs;
uint64_t act_buf[1024 / 8];
struct nlattr *actions;
+ struct ofpbuf key, mask;
struct match match;
struct ofpbuf buf;
int err = ENOENT;
@@ -659,13 +659,27 @@ tc_parse_flow_get(struct tc_offload *offload_tc, struct dpif_flow_get *get)
VLOG_DBG("found flow from netdev, translating to dpif flow");
ofpbuf_use_stack(&key, &keybuf, sizeof keybuf);
- ofpbuf_use_stack(&act, &actbuf, sizeof actbuf);
ofpbuf_use_stack(&mask, &maskbuf, sizeof maskbuf);
tc_match_to_dpif_flow(&match, &key, &mask, actions, &stats, &attrs,
(ovs_u128 *) get->ufid, dpif_flow, false);
+
+ /* 'key', 'mask' and 'actions' live on this stack frame, so copy them
+ * into the caller's buffer and point the flow at the copies. Resolve
+ * the pointers only after the last put, as any put may reallocate the
+ * buffer. */
+ key_ofs = get->buffer->size;
+ ofpbuf_put(get->buffer, dpif_flow->key, dpif_flow->key_len);
+ mask_ofs = get->buffer->size;
+ ofpbuf_put(get->buffer, dpif_flow->mask, dpif_flow->mask_len);
+ act_ofs = get->buffer->size;
ofpbuf_put(get->buffer, nl_attr_get(actions), nl_attr_get_size(actions));
- dpif_flow->actions = ofpbuf_at(get->buffer, 0, 0);
- dpif_flow->actions_len = nl_attr_get_size(actions);
+
+ dpif_flow->key = ofpbuf_at_assert(get->buffer, key_ofs,
+ dpif_flow->key_len);
+ dpif_flow->mask = ofpbuf_at_assert(get->buffer, mask_ofs,
+ dpif_flow->mask_len);
+ dpif_flow->actions = ofpbuf_at_assert(get->buffer, act_ofs,
+ dpif_flow->actions_len);
ofpbuf_uninit(&buf);
return 0;
@@ -1337,3 +1337,31 @@ AT_CHECK([grep "in_port(ovs-p1)" stdout | grep -q "geneve[[(]][[{]]class=0xffff,
OVS_TRAFFIC_VSWITCHD_STOP
AT_CLEANUP
+
+AT_SETUP([offloads - get flow by ufid])
+OVS_TRAFFIC_VSWITCHD_START([], [],
+ [-- set Open_vSwitch . other_config:hw-offload=true])
+
+ADD_NAMESPACES(at_ns0, at_ns1)
+ADD_VETH(p0, at_ns0, br0, "10.1.1.1/24")
+ADD_VETH(p1, at_ns1, br0, "10.1.1.2/24")
+
+AT_CHECK([ovs-ofctl add-flow br0 "actions=normal"])
+
+NS_CHECK_EXEC([at_ns0], [ping -q -c 3 -i 0.3 -W 2 10.1.1.2 | FORMAT_PING], [0], [dnl
+3 packets transmitted, 3 received, 0% packet loss, time 0ms
+])
+AT_CHECK([ovs-appctl revalidator/wait])
+
+dnl Fetching a tc flow by ufid must give the same key, mask, actions and
+dnl attributes as the dump does. Only the 'used' age may differ.
+AT_CHECK([ovs-appctl dpctl/dump-flows -m type=tc | grep "eth_type(0x0800)" \
+ | sed 's/used:[[0-9.]]*s/used:X/' | sort > dump.txt])
+AT_CHECK([test -s dump.txt])
+AT_CHECK([for ufid in $(sed -n 's/^\(ufid:[[-0-9a-f]]*\).*/\1/p' dump.txt); do
+ ovs-appctl dpctl/get-flow -m $ufid
+ done | sed 's/used:[[0-9.]]*s/used:X/' | sort > get.txt])
+AT_CHECK([diff dump.txt get.txt])
+
+OVS_TRAFFIC_VSWITCHD_STOP
+AT_CLEANUP