0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

Filter: Minor cleanups

This commit is contained in:
Ondrej Zajicek (work) 2019-07-10 16:46:31 +02:00
parent b2a4feeb4c
commit bfa15a642f
2 changed files with 33 additions and 23 deletions

View File

@ -91,6 +91,7 @@
else else
RESULT_VAL(v1); RESULT_VAL(v1);
} }
INST(FI_PAIR_CONSTRUCT, 2, 1) { INST(FI_PAIR_CONSTRUCT, 2, 1) {
ARG(1,T_INT); ARG(1,T_INT);
ARG(2,T_INT); ARG(2,T_INT);
@ -100,6 +101,7 @@
runtime( "Can't operate with value out of bounds in pair constructor" ); runtime( "Can't operate with value out of bounds in pair constructor" );
RESULT(T_PAIR, i, (u1 << 16) | u2); RESULT(T_PAIR, i, (u1 << 16) | u2);
} }
INST(FI_EC_CONSTRUCT, 2, 1) { INST(FI_EC_CONSTRUCT, 2, 1) {
ARG_ANY(1); ARG_ANY(1);
ARG(2, T_INT); ARG(2, T_INT);
@ -120,7 +122,7 @@
ipv4_used = 1; key = ipa_to_u32(v1.val.ip); ipv4_used = 1; key = ipa_to_u32(v1.val.ip);
} }
else else
runtime("Argument 1 of instruction FI_EC_CONSTRUCT must be integer or IPv4 address, got 0x%02x"); runtime("Argument 1 of EC constructor must be integer or IPv4 address, got 0x%02x", v1.type);
val = v2.val.i; val = v2.val.i;
@ -173,21 +175,21 @@
if (fstk->vcnt < whati->count) /* TODO: make this check systematic */ if (fstk->vcnt < whati->count) /* TODO: make this check systematic */
runtime("Construction of BGP path mask from %u elements must have at least that number of elements", whati->count); runtime("Construction of BGP path mask from %u elements must have at least that number of elements", whati->count);
#define pv fstk->vstk[fstk->vcnt - whati->count + i] #define pv(i) fstk->vstk[fstk->vcnt - whati->count + (i)]
FID_INTERPRET_NEW FID_INTERPRET_NEW
#define pv items[i]->i_FI_CONSTANT.val #define pv(i) items[i]->i_FI_CONSTANT.val
FID_INTERPRET_BODY FID_INTERPRET_BODY
struct f_path_mask *pm = falloc(sizeof(struct f_path_mask) + whati->count * sizeof(struct f_path_mask_item)); struct f_path_mask *pm = falloc(sizeof(struct f_path_mask) + whati->count * sizeof(struct f_path_mask_item));
for (uint i=0; i<whati->count; i++) { for (uint i=0; i<whati->count; i++) {
switch (pv.type) { switch (pv(i).type) {
case T_PATH_MASK_ITEM: case T_PATH_MASK_ITEM:
pm->item[i] = pv.val.pmi; pm->item[i] = pv(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 = pv.val.i, .asn = pv(i).val.i,
.kind = PM_ASN, .kind = PM_ASN,
}; };
break; break;
@ -195,6 +197,7 @@
runtime( "Error resolving path mask template: value not an integer" ); runtime( "Error resolving path mask template: value not an integer" );
} }
} }
#undef pv
FID_INTERPRET_EXEC FID_INTERPRET_EXEC
fstk->vcnt -= whati->count; fstk->vcnt -= whati->count;
@ -308,8 +311,7 @@
RESULT_VAL(fstk->vstk[curline.vbase + sym->offset]); RESULT_VAL(fstk->vstk[curline.vbase + sym->offset]);
} }
/* some constants have value in a[1], some in *a[0].p, strange. */ INST(FI_CONSTANT, 0, 1) {
INST(FI_CONSTANT, 0, 1) { /* integer (or simple type) constant, string, set, or prefix_set */
FID_MEMBER( FID_MEMBER(
struct f_val, struct f_val,
val, val,
@ -320,6 +322,7 @@
RESULT_VAL(val); RESULT_VAL(val);
} }
INST(FI_CONDITION, 1, 0) { INST(FI_CONDITION, 1, 0) {
ARG(1, T_BOOL); ARG(1, T_BOOL);
if (v1.val.i) if (v1.val.i)
@ -341,10 +344,10 @@
FID_INTERPRET_BODY FID_INTERPRET_BODY
#define pv fstk->vstk[fstk->vcnt - whati->count + i] #define pv(i) fstk->vstk[fstk->vcnt - whati->count + (i)]
if (whati->count) if (whati->count)
for (uint i=0; i<whati->count; i++) for (uint i=0; i<whati->count; i++)
val_format(&(pv), &fs->buf); val_format(&(pv(i)), &fs->buf);
#undef pv #undef pv
fstk->vcnt -= whati->count; fstk->vcnt -= whati->count;
@ -372,7 +375,7 @@
} }
} }
INST(FI_RTA_GET, 0, 1) { /* rta access */ INST(FI_RTA_GET, 0, 1) {
{ {
STATIC_ATTR; STATIC_ATTR;
ACCESS_RTE; ACCESS_RTE;
@ -577,6 +580,7 @@
case EAF_TYPE_OPAQUE: case EAF_TYPE_OPAQUE:
runtime( "Setting opaque attribute is not allowed" ); runtime( "Setting opaque attribute is not allowed" );
break; break;
case EAF_TYPE_IP_ADDRESS: case EAF_TYPE_IP_ADDRESS:
if (v1.type != T_IP) if (v1.type != T_IP)
runtime( "Setting ip attribute to non-ip value" ); runtime( "Setting ip attribute to non-ip value" );
@ -586,11 +590,13 @@
(* (ip_addr *) ad->data) = v1.val.ip; (* (ip_addr *) ad->data) = v1.val.ip;
l->attrs[0].u.ptr = ad; l->attrs[0].u.ptr = ad;
break; break;
case EAF_TYPE_AS_PATH: case EAF_TYPE_AS_PATH:
if (v1.type != T_PATH) if (v1.type != T_PATH)
runtime( "Setting path attribute to non-path value" ); runtime( "Setting path attribute to non-path value" );
l->attrs[0].u.ptr = v1.val.ad; l->attrs[0].u.ptr = v1.val.ad;
break; break;
case EAF_TYPE_BITFIELD: case EAF_TYPE_BITFIELD:
if (v1.type != T_BOOL) if (v1.type != T_BOOL)
runtime( "Setting bit in bitfield attribute to non-bool value" ); runtime( "Setting bit in bitfield attribute to non-bool value" );
@ -605,22 +611,27 @@
l->attrs[0].u.data = data & ~(1u << da.bit); l->attrs[0].u.data = data & ~(1u << da.bit);
} }
break; break;
case EAF_TYPE_INT_SET: case EAF_TYPE_INT_SET:
if (v1.type != T_CLIST) if (v1.type != T_CLIST)
runtime( "Setting clist attribute to non-clist value" ); runtime( "Setting clist attribute to non-clist value" );
l->attrs[0].u.ptr = v1.val.ad; l->attrs[0].u.ptr = v1.val.ad;
break; break;
case EAF_TYPE_EC_SET: case EAF_TYPE_EC_SET:
if (v1.type != T_ECLIST) if (v1.type != T_ECLIST)
runtime( "Setting eclist attribute to non-eclist value" ); runtime( "Setting eclist attribute to non-eclist value" );
l->attrs[0].u.ptr = v1.val.ad; l->attrs[0].u.ptr = v1.val.ad;
break; break;
case EAF_TYPE_LC_SET: case EAF_TYPE_LC_SET:
if (v1.type != T_LCLIST) if (v1.type != T_LCLIST)
runtime( "Setting lclist attribute to non-lclist value" ); runtime( "Setting lclist attribute to non-lclist value" );
l->attrs[0].u.ptr = v1.val.ad; l->attrs[0].u.ptr = v1.val.ad;
break; break;
default: bug("Unknown type in e,S");
default:
bug("Unknown dynamic attribute type");
} }
f_rta_cow(fs); f_rta_cow(fs);
@ -728,7 +739,7 @@
RESULT(T_INT, i, as); RESULT(T_INT, i, as);
} }
INST(FI_AS_PATH_LAST, 1, 1) { /* Get last ASN from AS PATH */ INST(FI_AS_PATH_LAST, 1, 1) { /* Get last ASN from AS PATH */
ARG(1, T_PATH); ARG(1, T_PATH);
int as = 0; int as = 0;
as_path_get_last(v1.val.ad, &as); as_path_get_last(v1.val.ad, &as);
@ -754,7 +765,6 @@
if (!fstk->ecnt) if (!fstk->ecnt)
if (fstk->vstk[retpos].type == T_BOOL) if (fstk->vstk[retpos].type == T_BOOL)
if (fstk->vstk[retpos].val.i) if (fstk->vstk[retpos].val.i)
return F_ACCEPT; return F_ACCEPT;
else else
return F_REJECT; return F_REJECT;

View File

@ -335,7 +335,7 @@ f_run(const struct filter *filter, struct rte **rte, struct linpool *tmp_pool, i
} }
/** /**
* f_eval_rte run a filter line for an uncached route * f_eval_rte - run a filter line for an uncached route
* @expr: filter line to run * @expr: filter line to run
* @rte: route being filtered, may be modified * @rte: route being filtered, may be modified
* @tmp_pool: all filter allocations go from this pool * @tmp_pool: all filter allocations go from this pool
@ -364,7 +364,7 @@ f_eval_rte(const struct f_line *expr, struct rte **rte, struct linpool *tmp_pool
} }
/* /*
* f_eval get a value of a term * f_eval - get a value of a term
* @expr: filter line containing the term * @expr: filter line containing the term
* @tmp_pool: long data may get allocated from this pool * @tmp_pool: long data may get allocated from this pool
* @pres: here the output will be stored * @pres: here the output will be stored
@ -383,7 +383,7 @@ f_eval(const struct f_line *expr, struct linpool *tmp_pool, struct f_val *pres)
} }
/* /*
* f_eval_int get an integer value of a term * f_eval_int - get an integer value of a term
* Called internally from the config parser, uses its internal memory pool * Called internally from the config parser, uses its internal memory pool
* for allocations. Do not call in other cases. * for allocations. Do not call in other cases.
*/ */
@ -409,7 +409,7 @@ f_eval_int(const struct f_line *expr)
} }
/* /*
* f_eval_buf get a value of a term and print it to the supplied buffer * f_eval_buf - get a value of a term and print it to the supplied buffer
*/ */
enum filter_return enum filter_return
f_eval_buf(const struct f_line *expr, struct linpool *tmp_pool, buffer *buf) f_eval_buf(const struct f_line *expr, struct linpool *tmp_pool, buffer *buf)