summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorOndrej Zajicek (work) <santiago@crfreenet.org>2022-03-04 02:01:34 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2022-06-27 21:13:31 +0200
commit8f3c6151b4ff11d98a20f6f9919723f0fb719161 (patch)
tree215ecd33d34beaeb685d982ac0de13181c39a3ef /filter
parent9b302c133f02f96edc5caa769dfd21dc9ef038b5 (diff)
Nest: Cleanups in as_path_filter()
Use struct f_val as a common argument for as_path_filter(), as suggested by Alexander Zubkov. That allows to use NULL sets as valid arguments.
Diffstat (limited to 'filter')
-rw-r--r--filter/data.h2
-rw-r--r--filter/f-inst.c21
2 files changed, 8 insertions, 15 deletions
diff --git a/filter/data.h b/filter/data.h
index 4cb6b7a8..8cba8c0e 100644
--- a/filter/data.h
+++ b/filter/data.h
@@ -282,6 +282,8 @@ static inline int eclist_set_type(const struct f_tree *set)
{ return set->from.type == T_EC; }
static inline int lclist_set_type(const struct f_tree *set)
{ return set->from.type == T_LC; }
+static inline int path_set_type(const struct f_tree *set)
+{ return set->from.type == T_INT; }
const struct adata *clist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos);
const struct adata *eclist_filter(struct linpool *pool, const struct adata *list, const struct f_val *set, int pos);
diff --git a/filter/f-inst.c b/filter/f-inst.c
index 2a02c8e5..5d42c40a 100644
--- a/filter/f-inst.c
+++ b/filter/f-inst.c
@@ -1035,7 +1035,7 @@
RESULT(T_INT, i, v1.val.lc.ldp2);
}
- INST(FI_MIN, 1, 1) { /* Get minimum element from set */
+ INST(FI_MIN, 1, 1) { /* Get minimum element from list */
ARG_ANY(1);
RESULT_TYPE(f_type_element_type(v1.type));
switch(v1.type)
@@ -1069,7 +1069,7 @@
}
}
- INST(FI_MAX, 1, 1) { /* Get maximum element from set */
+ INST(FI_MAX, 1, 1) { /* Get maximum element from list */
ARG_ANY(1);
RESULT_TYPE(f_type_element_type(v1.type));
switch(v1.type)
@@ -1291,17 +1291,10 @@
if (v1.type == T_PATH)
{
- const struct f_tree *set = NULL;
- u32 key = 0;
-
- if (v2.type == T_INT)
- key = v2.val.i;
- else if ((v2.type == T_SET) && (v2.val.t->from.type == T_INT))
- set = v2.val.t;
+ if ((v2.type == T_SET) && path_set_type(v2.val.t) || (v2.type == T_INT))
+ RESULT_(T_PATH, ad, [[ as_path_filter(fpool, v1.val.ad, &v2, 0) ]]);
else
runtime("Can't delete non-integer (set)");
-
- RESULT_(T_PATH, ad, [[ as_path_filter(fpool, v1.val.ad, set, key, 0) ]]);
}
else if (v1.type == T_CLIST)
@@ -1353,10 +1346,8 @@
if (v1.type == T_PATH)
{
- u32 key = 0;
-
- if ((v2.type == T_SET) && (v2.val.t->from.type == T_INT))
- RESULT_(T_PATH, ad, [[ as_path_filter(fpool, v1.val.ad, v2.val.t, key, 1) ]]);
+ if ((v2.type == T_SET) && path_set_type(v2.val.t))
+ RESULT_(T_PATH, ad, [[ as_path_filter(fpool, v1.val.ad, &v2, 1) ]]);
else
runtime("Can't filter integer");
}