- uint8_t be32ofs = ctx->be32ofs;
- uint8_t be64ofs = be32ofs / 2;
-
- /* Is the trie field within the current range of fields? */
- if (MINIFLOW_IN_MAP(range_map, be64ofs)) {
- /* On-demand trie lookup. */
- if (!ctx->lookup_done) {
- memset(&ctx->match_plens, 0, sizeof ctx->match_plens);
- ctx->maskbits = trie_lookup(ctx->trie, flow,
- &ctx->match_plens);
- ctx->lookup_done = true;
+
+ /* On-demand trie lookup. */
+ if (!ctx->lookup_done) {
+ memset(&ctx->match_plens, 0, sizeof ctx->match_plens);
+ ctx->maskbits = trie_lookup(ctx->trie, flow, &ctx->match_plens);
+ ctx->lookup_done = true;
+ }
+ /* Possible to skip the rest of the subtable if subtable's
+ * prefix on the field is not included in the lookup result. */
+ if (!be_get_bit_at(&ctx->match_plens.be32, field_plen[j] - 1)) {
+ /* We want the trie lookup to never result in unwildcarding
+ * any bits that would not be unwildcarded otherwise.
+ * Since the trie is shared by the whole classifier, it is
+ * possible that the 'maskbits' contain bits that are
+ * irrelevant for the partition relevant for the current
+ * packet. Hence the checks below. */
+
+ /* Check that the trie result will not unwildcard more bits
+ * than this subtable would otherwise. */
+ if (ctx->maskbits <= field_plen[j]) {
+ /* Unwildcard the bits and skip the rest. */
+ mask_set_prefix_bits(wc, ctx->be32ofs, ctx->maskbits);
+ /* Note: Prerequisite already unwildcarded, as the only
+ * prerequisite of the supported trie lookup fields is
+ * the ethertype, which is always unwildcarded. */
+ return true;