+get_dpif_flow_stats(struct dp_netdev_flow *netdev_flow,
+ struct dpif_flow_stats *stats)
+{
+ struct dp_netdev_flow_stats *bucket;
+ size_t i;
+
+ memset(stats, 0, sizeof *stats);
+ OVSTHREAD_STATS_FOR_EACH_BUCKET (bucket, i, &netdev_flow->stats) {
+ ovs_mutex_lock(&bucket->mutex);
+ stats->n_packets += bucket->packet_count;
+ stats->n_bytes += bucket->byte_count;
+ stats->used = MAX(stats->used, bucket->used);
+ stats->tcp_flags |= bucket->tcp_flags;
+ ovs_mutex_unlock(&bucket->mutex);
+ }
+}
+
+static int
+dpif_netdev_mask_from_nlattrs(const struct nlattr *key, uint32_t key_len,
+ const struct nlattr *mask_key,
+ uint32_t mask_key_len, const struct flow *flow,
+ struct flow *mask)
+{
+ if (mask_key_len) {
+ enum odp_key_fitness fitness;
+
+ fitness = odp_flow_key_to_mask(mask_key, mask_key_len, mask, flow);
+ if (fitness) {
+ /* This should not happen: it indicates that
+ * odp_flow_key_from_mask() and odp_flow_key_to_mask()
+ * disagree on the acceptable form of a mask. Log the problem
+ * as an error, with enough details to enable debugging. */
+ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
+
+ if (!VLOG_DROP_ERR(&rl)) {
+ struct ds s;
+
+ ds_init(&s);
+ odp_flow_format(key, key_len, mask_key, mask_key_len, NULL, &s,
+ true);
+ VLOG_ERR("internal error parsing flow mask %s (%s)",
+ ds_cstr(&s), odp_key_fitness_to_string(fitness));
+ ds_destroy(&s);
+ }
+
+ return EINVAL;
+ }
+ } else {
+ enum mf_field_id id;
+ /* No mask key, unwildcard everything except fields whose
+ * prerequisities are not met. */
+ memset(mask, 0x0, sizeof *mask);
+
+ for (id = 0; id < MFF_N_IDS; ++id) {
+ /* Skip registers and metadata. */
+ if (!(id >= MFF_REG0 && id < MFF_REG0 + FLOW_N_REGS)
+ && id != MFF_METADATA) {
+ const struct mf_field *mf = mf_from_id(id);
+ if (mf_are_prereqs_ok(mf, flow)) {
+ mf_mask_field(mf, mask);
+ }
+ }
+ }
+ }
+
+ /* Force unwildcard the in_port.
+ *
+ * We need to do this even in the case where we unwildcard "everything"
+ * above because "everything" only includes the 16-bit OpenFlow port number
+ * mask->in_port.ofp_port, which only covers half of the 32-bit datapath
+ * port number mask->in_port.odp_port. */
+ mask->in_port.odp_port = u32_to_odp(UINT32_MAX);
+
+ return 0;