summaryrefslogtreecommitdiff
path: root/filter/data.c
diff options
context:
space:
mode:
authorAlexander Zubkov <green@qrator.net>2022-03-04 14:07:58 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2022-06-27 21:13:31 +0200
commitb2d6d2948af268812a8f55f260d340194eb3f7ac (patch)
tree4d1d4d3b91776e4aafcee83b5c4a3144425fe2aa /filter/data.c
parent8f3c6151b4ff11d98a20f6f9919723f0fb719161 (diff)
Filter: Add literal for empty set
Add literal for empty set [], which works both for tree-based sets and prefix sets by using existing constant promotion mechanism. Minor changes by committer.
Diffstat (limited to 'filter/data.c')
-rw-r--r--filter/data.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/filter/data.c b/filter/data.c
index 56c1fb17..276738a9 100644
--- a/filter/data.c
+++ b/filter/data.c
@@ -79,6 +79,8 @@ f_type_element_type(enum f_type t)
};
}
+const struct f_trie f_const_empty_trie = { .ipv4 = -1, };
+
const struct f_val f_const_empty_path = {
.type = T_PATH,
.val.ad = &null_adata,
@@ -91,6 +93,9 @@ const struct f_val f_const_empty_path = {
}, f_const_empty_lclist = {
.type = T_LCLIST,
.val.ad = &null_adata,
+}, f_const_empty_prefix_set = {
+ .type = T_PREFIX_SET,
+ .val.ti = &f_const_empty_trie,
};
static struct adata *
@@ -301,6 +306,12 @@ val_same(const struct f_val *v1, const struct f_val *v2)
int
clist_set_type(const struct f_tree *set, struct f_val *v)
{
+ if (!set)
+ {
+ v->type = T_VOID;
+ return 1;
+ }
+
switch (set->from.type)
{
case T_PAIR:
@@ -537,6 +548,9 @@ val_in_range(const struct f_val *v1, const struct f_val *v2)
if (v2->type != T_SET)
return F_CMP_ERROR;
+ if (!v2->val.t)
+ return 0;
+
/* With integrated Quad<->IP implicit conversion */
if ((v1->type == v2->val.t->from.type) ||
((v1->type == T_QUAD) && val_is_ip4(&(v2->val.t->from)) && val_is_ip4(&(v2->val.t->to))))