Skip to contentSkip to conversation

segtree: release single element already contained in an interval

PATCH New Pablo Neira Ayuso 1 participant 1 message Mar 16, 2021 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/1 segtree: release single element already contained in an interval

Before this patch:

 table ip x {
        chain y {
                ip saddr { 1.1.1.1-1.1.1.2, 1.1.1.1 }
        }

}

results in:

 table ip x {
        chain y {
                ip saddr { 1.1.1.1 }
        }

}

due to incorrect interval merge logic.

If the element 1.1.1.1 is already contained in an existing interval 1.1.1.1-1.1.1.2, release it.

---
 src/segtree.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
src/segtree.c +7 -1
index 9aa39e52d8a0..ad199355532e 100644
@@ -210,6 +210,12 @@ static int ei_insert(struct list_head *msgs, struct seg_tree *tree,
 			ei = lei;
 			goto err;
 		}
+		/* single element contained in an existing interval */
+		if (mpz_cmp(new->left, new->right) == 0) {
+			ei_destroy(new);
+			goto out;
+		}
+
 		/*
 		 * The new interval is entirely contained in the same interval,
 		 * split it into two parts:
@@ -277,7 +283,7 @@ static int ei_insert(struct list_head *msgs, struct seg_tree *tree,
 	}
 
 	__ei_insert(tree, new);
-
+out:
 	mpz_clear(p);
 
 	return 0;
Signature · 1 line
2.20.1