const struct expr *init, bool add)
{
if (add) {
- /* Add the first segment in three situations:
+ /* Add the first segment in four situations:
*
* 1) This is an anonymous set.
* 2) This set exists and it is empty.
- * 3) This set is created with a number of initial elements.
+ * 3) New empty set and, separately, new elements are added.
+ * 4) This set is created with a number of initial elements.
*/
if ((set->flags & NFT_SET_ANONYMOUS) ||
(set->init && set->init->size == 0) ||
- (set->init == init))
+ (set->init == NULL && init) ||
+ (set->init == init)) {
return true;
+ }
} else {
/* If the set is empty after the removal, we have to
* remove the first non-matching segment too.
--- /dev/null
+#!/bin/bash
+
+RULESET="add table ip x
+add set x y {type ipv4_addr; flags interval;}
+add element x y { 10.0.24.0/24 }
+"
+
+set -e
+$NFT -f - <<< "$RULESET"
+$NFT delete element x y { 10.0.24.0/24 }