Filter: Allow to use set constants / expressions in path masks

Allow to not only use set literals in path masks, but also existing
set constants or set expressions.
This commit is contained in:
Ondrej Zajicek (work) 2019-08-06 18:54:19 +02:00
parent ef113c6f72
commit 9f3e098320
4 changed files with 20 additions and 3 deletions

View file

@ -308,12 +308,24 @@
case T_PATH_MASK_ITEM: case T_PATH_MASK_ITEM:
pm->item[i] = vv(i).val.pmi; pm->item[i] = vv(i).val.pmi;
break; break;
case T_INT: case T_INT:
pm->item[i] = (struct f_path_mask_item) { pm->item[i] = (struct f_path_mask_item) {
.asn = vv(i).val.i, .asn = vv(i).val.i,
.kind = PM_ASN, .kind = PM_ASN,
}; };
break; break;
case T_SET:
if (vv(i).val.t->from.type != T_INT)
runtime("Only integer sets allowed in path mask");
pm->item[i] = (struct f_path_mask_item) {
.set = vv(i).val.t,
.kind = PM_ASN_SET,
};
break;
default: default:
runtime( "Error resolving path mask template: value not an integer" ); runtime( "Error resolving path mask template: value not an integer" );
} }

View file

@ -597,11 +597,15 @@ function mkpath(int a; int b)
return [= a b 3 2 1 =]; return [= a b 3 2 1 =];
} }
define set35 = [3 .. 5];
function t_path() function t_path()
bgpmask pm1; bgpmask pm1;
bgppath p2; bgppath p2;
int set set12;
{ {
pm1 = [= 4 3 2 1 =]; pm1 = [= 4 3 2 1 =];
set12 = [1, 2];
bt_assert(format(pm1) = "[= 4 3 2 1 =]"); bt_assert(format(pm1) = "[= 4 3 2 1 =]");
@ -627,6 +631,7 @@ bgppath p2;
bt_assert(p2 ~ [= * 4 3 * 1 =]); bt_assert(p2 ~ [= * 4 3 * 1 =]);
bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]); bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]);
bt_assert(p2 ~ [= 5 [2, 4, 6] 3 [1..2] 1 =]); bt_assert(p2 ~ [= 5 [2, 4, 6] 3 [1..2] 1 =]);
bt_assert(p2 ~ [= 5 set35 3 set12 set12 =]);
bt_assert(p2 ~ mkpath(5, 4)); bt_assert(p2 ~ mkpath(5, 4));
bt_assert(p2.len = 5); bt_assert(p2.len = 5);

View file

@ -741,7 +741,7 @@ pm_match(struct pm_pos *pos, u32 asn, u32 asn2)
} }
static int static int
pm_match_set(struct pm_pos *pos, struct f_tree *set) pm_match_set(struct pm_pos *pos, const struct f_tree *set)
{ {
struct f_val asn = { .type = T_INT }; struct f_val asn = { .type = T_INT };

View file

@ -65,8 +65,8 @@ static inline struct adata *as_path_prepend(struct linpool *pool, const struct a
struct f_path_mask_item { struct f_path_mask_item {
union { union {
u32 asn; /* PM_ASN */ u32 asn; /* PM_ASN */
struct f_line *expr; /* PM_ASN_EXPR */ const struct f_line *expr; /* PM_ASN_EXPR */
struct f_tree *set; /* PM_ASN_SET */ const struct f_tree *set; /* PM_ASN_SET */
struct { /* PM_ASN_RANGE */ struct { /* PM_ASN_RANGE */
u32 from; u32 from;
u32 to; u32 to;