summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
Diffstat (limited to 'filter')
-rw-r--r--filter/config.Y153
-rw-r--r--filter/decl.m42
-rw-r--r--filter/f-inst.c31
3 files changed, 16 insertions, 170 deletions
diff --git a/filter/config.Y b/filter/config.Y
index 995f6cd4..49c59efc 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -185,159 +185,6 @@ f_generate_empty(struct f_dynamic_attr dyn)
return f_new_inst(FI_EA_SET, f_new_inst(FI_CONSTANT, empty), dyn);
}
-#if 0
-
-static inline struct f_inst *
-f_generate_dpair(struct f_inst *t1, struct f_inst *t2)
-{
- struct f_inst *rv;
-
- if ((t1->fi_code == FI_CONSTANT) && (t2->fi_code == FI_CONSTANT)) {
- if ((t1->val.type != T_INT) || (t2->val.type != T_INT))
- cf_error( "Can't operate with value of non-integer type in pair constructor");
-
- check_u16(t1->a[1].i);
- check_u16(t2->a[1].i);
-
- rv = f_new_inst(FI_CONSTANT);
- rv->val = (struct f_val) {
- .type = T_PAIR,
- .val.i = pair(t1->a[1].i, t2->a[1].i),
- };
- }
- else {
- rv = f_new_inst(FI_PAIR_CONSTRUCT);
- rv->a[0].p = t1;
- rv->a[1].p = t2;
- }
-
- return rv;
-}
-
-static inline struct f_inst *
-f_generate_ec(u16 kind, struct f_inst *tk, struct f_inst *tv)
-{
- struct f_inst *rv;
- int c1 = 0, c2 = 0, ipv4_used = 0;
- u32 key = 0, val2 = 0;
-
- if (tk->fi_code == FI_CONSTANT) {
- c1 = 1;
- struct f_val *val = &(tk->val);
-
- if (val->type == T_INT) {
- ipv4_used = 0; key = val->val.i;
- }
- else if (tk->val.type == T_QUAD) {
- ipv4_used = 1; key = val->val.i;
- }
- else if ((val->type == T_IP) && ipa_is_ip4(val->val.ip)) {
- ipv4_used = 1; key = ipa_to_u32(val->val.ip);
- }
- else
- cf_error("Can't operate with key of non-integer/IPv4 type in EC constructor");
- }
-
- if (tv->fi_code == FI_CONSTANT) {
- if (tv->val.type != T_INT)
- cf_error("Can't operate with value of non-integer type in EC constructor");
- c2 = 1;
- val2 = tv->val.val.i;
- }
-
- if (c1 && c2) {
- u64 ec;
-
- if (kind == EC_GENERIC) {
- ec = ec_generic(key, val2);
- }
- else if (ipv4_used) {
- check_u16(val2);
- ec = ec_ip4(kind, key, val2);
- }
- else if (key < 0x10000) {
- ec = ec_as2(kind, key, val2);
- }
- else {
- check_u16(val2);
- ec = ec_as4(kind, key, val2);
- }
-
- rv = f_new_inst(FI_CONSTANT);
- rv->val = (struct f_val) {
- .type = T_EC,
- .val.ec = ec,
- };
- }
- else {
- rv = f_new_inst(FI_EC_CONSTRUCT);
- rv->aux = kind;
- rv->a[0].p = tk;
- rv->a[1].p = tv;
- }
-
- return rv;
-}
-
-static inline struct f_inst *
-f_generate_lc(struct f_inst *t1, struct f_inst *t2, struct f_inst *t3)
-{
- struct f_inst *rv;
-
- if ((t1->fi_code == FI_CONSTANT) && (t2->fi_code == FI_CONSTANT) && (t3->fi_code == FI_CONSTANT)) {
- if ((t1->val.type != T_INT) || (t2->val.type != T_INT) || (t3->val.type != T_INT))
- cf_error( "LC - Can't operate with value of non-integer type in tuple constructor");
-
- rv = f_new_inst(FI_CONSTANT);
- rv->val = (struct f_val) {
- .type = T_LC,
- .val.lc = (lcomm) { t1->a[1].i, t2->a[1].i, t3->a[1].i },
- };
- }
- else
- {
- rv = f_new_inst(FI_LC_CONSTRUCT);
- rv->a[0].p = t1;
- rv->a[1].p = t2;
- rv->a[2].p = t3;
- }
-
- return rv;
-}
-
-static inline struct f_inst *
-f_generate_path_mask(struct f_inst *t)
-{
- uint len = 0;
- uint dyn = 0;
- for (const struct f_inst *tt = t; tt; tt = tt->next) {
- if (tt->fi_code != FI_CONSTANT)
- dyn++;
- len++;
- }
-
- if (dyn) {
- struct f_inst *pmc = f_new_inst(FI_PATHMASK_CONSTRUCT);
- pmc->a[0].p = t;
- pmc->a[1].i = len;
- return pmc;
- }
-
- struct f_path_mask *pm = cfg_allocz(sizeof(struct f_path_mask) + len * sizeof(struct f_path_mask_item));
-
- uint i = 0;
- for (const struct f_inst *tt = t; tt; tt = tt->next)
- pm->item[i++] = tt->val.val.pmi;
-
- pm->len = i;
- struct f_inst *pmc = f_new_inst(FI_CONSTANT);
- pmc->val = (struct f_val) { .type = T_PATH_MASK, .val.path_mask = pm, };
-
- return pmc;
-}
-
-#endif
-
/*
* Remove all new lines and doubled whitespaces
* and convert all tabulators to spaces
diff --git a/filter/decl.m4 b/filter/decl.m4
index efecb9a5..14b9329c 100644
--- a/filter/decl.m4
+++ b/filter/decl.m4
@@ -138,7 +138,7 @@ FID_IFCONST([[
}
FID_IFCONST([[
const struct f_inst **items = NULL;
- if (constargs) {
+ if (constargs && whati->varcount) {
items = alloca(whati->varcount * sizeof(struct f_inst *));
const struct f_inst *child = fvar;
for (uint i=0; child; i++)
diff --git a/filter/f-inst.c b/filter/f-inst.c
index 4b3c627b..3d185918 100644
--- a/filter/f-inst.c
+++ b/filter/f-inst.c
@@ -261,7 +261,7 @@
FID_MEMBER(enum ec_subtype, ecs, f1->ecs != f2->ecs, "ec subtype %s", ec_subtype_str(item->ecs));
- int check, ipv4_used;
+ int ipv4_used;
u32 key, val;
if (v1.type == T_INT) {
@@ -279,21 +279,20 @@
val = v2.val.i;
- if (ecs == EC_GENERIC) {
- check = 0; RESULT(T_EC, ec, ec_generic(key, val));
- }
- else if (ipv4_used) {
- check = 1; RESULT(T_EC, ec, ec_ip4(ecs, key, val));
- }
- else if (key < 0x10000) {
- check = 0; RESULT(T_EC, ec, ec_as2(ecs, key, val));
- }
- else {
- check = 1; RESULT(T_EC, ec, ec_as4(ecs, key, val));
- }
-
- if (check && (val > 0xFFFF))
- runtime("Value %u > %u out of bounds in EC constructor", val, 0xFFFF);
+ if (ecs == EC_GENERIC)
+ RESULT(T_EC, ec, ec_generic(key, val));
+ else if (ipv4_used)
+ if (val <= 0xFFFF)
+ RESULT(T_EC, ec, ec_ip4(ecs, key, val));
+ else
+ runtime("4-byte value %u can't be used with IP-address key in extended community", val);
+ else if (key < 0x10000)
+ RESULT(T_EC, ec, ec_as2(ecs, key, val));
+ else
+ if (val <= 0xFFFF)
+ RESULT(T_EC, ec, ec_as4(ecs, key, val));
+ else
+ runtime("4-byte value %u can't be used with 4-byte ASN in extended community", val);
}
INST(FI_LC_CONSTRUCT, 3, 1) {