}
 EXPORT_SYMBOL_GPL(vcap_lookup_rule_by_cookie);
 
+/* Get number of rules in a vcap instance lookup chain id range */
+int vcap_admin_rule_count(struct vcap_admin *admin, int cid)
+{
+       int max_cid = roundup(cid + 1, VCAP_CID_LOOKUP_SIZE);
+       int min_cid = rounddown(cid, VCAP_CID_LOOKUP_SIZE);
+       struct vcap_rule_internal *elem;
+       int count = 0;
+
+       list_for_each_entry(elem, &admin->rules, list) {
+               mutex_lock(&admin->lock);
+               if (elem->data.vcap_chain_id >= min_cid &&
+                   elem->data.vcap_chain_id < max_cid)
+                       ++count;
+               mutex_unlock(&admin->lock);
+       }
+       return count;
+}
+EXPORT_SYMBOL_GPL(vcap_admin_rule_count);
+
 /* Make a copy of the rule, shallow or full */
 static struct vcap_rule_internal *vcap_dup_rule(struct vcap_rule_internal *ri,
                                                bool full)
 }
 EXPORT_SYMBOL_GPL(vcap_rule_mod_key_u32);
 
+/* Remove a key field with value and mask in the rule */
+int vcap_rule_rem_key(struct vcap_rule *rule, enum vcap_key_field key)
+{
+       struct vcap_rule_internal *ri = to_intrule(rule);
+       struct vcap_client_keyfield *field;
+
+       field = vcap_find_keyfield(rule, key);
+       if (!field) {
+               pr_err("%s:%d: key %s is not in the rule\n",
+                      __func__, __LINE__, vcap_keyfield_name(ri->vctrl, key));
+               return -EINVAL;
+       }
+       /* Deallocate the key field */
+       list_del(&field->ctrl.list);
+       kfree(field);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(vcap_rule_rem_key);
+
 static int vcap_rule_mod_action(struct vcap_rule *rule,
                                enum vcap_action_field action,
                                enum vcap_field_type ftype,
 }
 EXPORT_SYMBOL_GPL(vcap_filter_rule_keys);
 
+/* Select the keyset from the list that results in the smallest rule size */
+enum vcap_keyfield_set
+vcap_select_min_rule_keyset(struct vcap_control *vctrl,
+                           enum vcap_type vtype,
+                           struct vcap_keyset_list *kslist)
+{
+       enum vcap_keyfield_set ret = VCAP_KFS_NO_VALUE;
+       const struct vcap_set *kset;
+       int max = 100, idx;
+
+       for (idx = 0; idx < kslist->cnt; ++idx) {
+               kset = vcap_keyfieldset(vctrl, vtype, kslist->keysets[idx]);
+               if (!kset)
+                       continue;
+               if (kset->sw_per_item >= max)
+                       continue;
+               max = kset->sw_per_item;
+               ret = kslist->keysets[idx];
+       }
+       return ret;
+}
+EXPORT_SYMBOL_GPL(vcap_select_min_rule_keyset);
+
 /* Make a full copy of an existing rule with a new rule id */
 struct vcap_rule *vcap_copy_rule(struct vcap_rule *erule)
 {
 
 int vcap_rule_add_action_u32(struct vcap_rule *rule,
                             enum vcap_action_field action, u32 value);
 
+/* Get number of rules in a vcap instance lookup chain id range */
+int vcap_admin_rule_count(struct vcap_admin *admin, int cid);
+
 /* VCAP rule counter operations */
 int vcap_get_rule_count_by_cookie(struct vcap_control *vctrl,
                                  struct vcap_counter *ctr, u64 cookie);
 int vcap_rule_get_key_u32(struct vcap_rule *rule, enum vcap_key_field key,
                          u32 *value, u32 *mask);
 
+/* Remove a key field with value and mask in the rule */
+int vcap_rule_rem_key(struct vcap_rule *rule, enum vcap_key_field key);
+
+/* Select the keyset from the list that results in the smallest rule size */
+enum vcap_keyfield_set
+vcap_select_min_rule_keyset(struct vcap_control *vctrl, enum vcap_type vtype,
+                           struct vcap_keyset_list *kslist);
+
 struct vcap_client_actionfield *
 vcap_find_actionfield(struct vcap_rule *rule, enum vcap_action_field act);
 #endif /* __VCAP_API_CLIENT__ */