2 * Filters: utility functions
4 * Copyright 1998 Pavel Machek <pavel@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
13 * You can find sources of the filter language in |filter/|
14 * directory. File |filter/config.Y| contains filter grammar and basically translates
15 * the source from user into a tree of &f_inst structures. These trees are
16 * later interpreted using code in |filter/filter.c|.
18 * A filter is represented by a tree of &f_inst structures, one structure per
19 * "instruction". Each &f_inst contains @code, @aux value which is
20 * usually the data type this instruction operates on and two generic
21 * arguments (@a1, @a2). Some instructions contain pointer(s) to other
22 * instructions in their (@a1, @a2) fields.
24 * Filters use a &f_val structure for their data. Each &f_val
25 * contains type and value (types are constants prefixed with %T_). Few
26 * of the types are special; %T_RETURN can be or-ed with a type to indicate
27 * that return from a function or from the whole filter should be
28 * forced. Important thing about &f_val's is that they may be copied
29 * with a simple |=|. That's fine for all currently defined types: strings
30 * are read-only (and therefore okay), paths are copied for each
31 * operation (okay too).
36 #include "nest/bird.h"
37 #include "lib/lists.h"
38 #include "lib/resource.h"
39 #include "lib/socket.h"
40 #include "lib/string.h"
41 #include "lib/unaligned.h"
42 #include "nest/route.h"
43 #include "nest/protocol.h"
44 #include "nest/iface.h"
45 #include "nest/attrs.h"
46 #include "conf/conf.h"
47 #include "filter/filter.h"
49 #define P(a,b) ((a<<8) | b)
54 adata_empty(struct linpool
*pool
)
56 struct adata
*res
= lp_alloc(pool
, sizeof(struct adata
));
62 pm_path_compare(struct f_path_mask
*m1
, struct f_path_mask
*m2
)
66 return !((!m1
) && (!m2
));
68 if ((m1
->kind
!= m2
->kind
) || (m1
->val
!= m2
->val
)) return 1;
74 u32
f_eval_asn(struct f_inst
*expr
);
77 pm_format(struct f_path_mask
*p
, byte
*buf
, unsigned int size
)
79 byte
*end
= buf
+ size
- 16;
92 buf
+= bsprintf(buf
, " %u", p
->val
);
96 buf
+= bsprintf(buf
, " ?");
100 buf
+= bsprintf(buf
, " *");
104 buf
+= bsprintf(buf
, " %u", f_eval_asn((struct f_inst
*) p
->val
));
115 * val_compare - compare two values
119 * Compares two values and returns -1, 0, 1 on <, =, > or 999 on error.
120 * Tree module relies on this giving consistent results so that it can
121 * build balanced trees.
124 val_compare(struct f_val v1
, struct f_val v2
)
128 if ((v1
.type
== T_VOID
) && (v2
.type
== T_VOID
))
130 if (v1
.type
== T_VOID
) /* Hack for else */
132 if (v2
.type
== T_VOID
)
135 if (v1
.type
!= v2
.type
) {
136 debug( "Types do not match in val_compare\n" );
144 if (v1
.val
.i
== v2
.val
.i
) return 0;
145 if (v1
.val
.i
< v2
.val
.i
) return -1;
148 return ipa_compare(v1
.val
.px
.ip
, v2
.val
.px
.ip
);
150 if (rc
= ipa_compare(v1
.val
.px
.ip
, v2
.val
.px
.ip
))
152 if (v1
.val
.px
.len
< v2
.val
.px
.len
)
154 if (v1
.val
.px
.len
> v2
.val
.px
.len
)
158 return pm_path_compare(v1
.val
.path_mask
, v2
.val
.path_mask
);
160 return strcmp(v1
.val
.s
, v2
.val
.s
);
162 debug( "Compare of unknown entities: %x\n", v1
.type
);
169 f_prefix_get_bounds(struct f_prefix
*px
, int *l
, int *h
)
171 *l
= *h
= px
->len
& LEN_MASK
;
173 if (px
->len
& LEN_MINUS
)
176 else if (px
->len
& LEN_PLUS
)
177 *h
= MAX_PREFIX_LENGTH
;
179 else if (px
->len
& LEN_RANGE
)
181 *l
= 0xff & (px
->len
>> 16);
182 *h
= 0xff & (px
->len
>> 8);
187 * val_simple_in_range - check if @v1 ~ @v2 for everything except sets
190 val_simple_in_range(struct f_val v1
, struct f_val v2
)
192 if ((v1
.type
== T_PATH
) && (v2
.type
== T_PATH_MASK
))
193 return as_path_match(v1
.val
.ad
, v2
.val
.path_mask
);
194 if ((v1
.type
== T_PAIR
) && (v2
.type
== T_CLIST
))
195 return int_set_contains(v2
.val
.ad
, v1
.val
.i
);
196 if ((v1
.type
== T_STRING
) && (v2
.type
== T_STRING
))
197 return patmatch(v2
.val
.s
, v1
.val
.s
);
199 if ((v1
.type
== T_IP
) && (v2
.type
== T_PREFIX
))
200 return ipa_in_net(v1
.val
.px
.ip
, v2
.val
.px
.ip
, v2
.val
.px
.len
);
202 if ((v1
.type
== T_PREFIX
) && (v2
.type
== T_PREFIX
))
203 return ipa_in_net(v1
.val
.px
.ip
, v2
.val
.px
.ip
, v2
.val
.px
.len
) && (v1
.val
.px
.len
>= v2
.val
.px
.len
);
209 * val_in_range - implement |~| operator
213 * Checks if @v1 is element (|~| operator) of @v2. Sets are internally represented as balanced trees, see
214 * |tree.c| module (this is not limited to sets, but for non-set cases, val_simple_in_range() is called early).
217 val_in_range(struct f_val v1
, struct f_val v2
)
221 res
= val_simple_in_range(v1
, v2
);
223 if (res
!= CMP_ERROR
)
226 if ((v1
.type
== T_PREFIX
) && (v2
.type
== T_PREFIX_SET
))
227 return trie_match_prefix(v2
.val
.ti
, &v1
.val
.px
);
229 if (v2
.type
== T_SET
)
237 n
= find_tree(v2
.val
.t
, v1
);
240 return !! (val_simple_in_range(v1
, n
->from
)); /* We turn CMP_ERROR into compared ok, and that's fine */
247 tree_print(struct f_tree
*t
)
254 tree_print( t
->left
);
255 debug( ", " ); val_print( t
->from
); debug( ".." ); val_print( t
->to
); debug( ", " );
256 tree_print( t
->right
);
261 * val_print - format filter value
264 val_print(struct f_val v
)
268 #define PRINTF(a...) bsnprintf( buf, 2040, a )
271 case T_VOID
: PRINTF( "(void)" ); break;
272 case T_BOOL
: PRINTF( v
.val
.i
? "TRUE" : "FALSE" ); break;
273 case T_INT
: PRINTF( "%d ", v
.val
.i
); break;
274 case T_STRING
: PRINTF( "%s", v
.val
.s
); break;
275 case T_IP
: PRINTF( "%I", v
.val
.px
.ip
); break;
276 case T_PREFIX
: PRINTF( "%I/%d", v
.val
.px
.ip
, v
.val
.px
.len
); break;
277 case T_PAIR
: PRINTF( "(%d,%d)", v
.val
.i
>> 16, v
.val
.i
& 0xffff ); break;
278 case T_PREFIX_SET
: trie_print(v
.val
.ti
, buf
, 2040); break;
279 case T_SET
: tree_print( v
.val
.t
); PRINTF( "\n" ); break;
280 case T_ENUM
: PRINTF( "(enum %x)%d", v
.type
, v
.val
.i
); break;
281 case T_PATH
: as_path_format(v
.val
.ad
, buf2
, 1020); PRINTF( "(path %s)", buf2
); break;
282 case T_CLIST
: int_set_format(v
.val
.ad
, 1, buf2
, 1020); PRINTF( "(clist %s)", buf2
); break;
283 case T_PATH_MASK
: pm_format(v
.val
.path_mask
, buf2
, 1020); PRINTF( "(pathmask%s)", buf2
); break;
284 default: PRINTF( "[unknown type %x]", v
.type
);
290 static struct rte
**f_rte
, *f_rte_old
;
291 static struct linpool
*f_pool
;
292 static struct ea_list
**f_tmp_attrs
;
294 static rta
*f_rta_copy
;
297 * rta_cow - prepare rta for modification by filter
303 f_rta_copy
= lp_alloc(f_pool
, sizeof(rta
));
304 memcpy(f_rta_copy
, (*f_rte
)->attrs
, sizeof(rta
));
305 f_rta_copy
->aflags
= 0;
306 *f_rte
= rte_cow(*f_rte
);
307 rta_free((*f_rte
)->attrs
);
308 (*f_rte
)->attrs
= f_rta_copy
;
312 static struct rate_limit rl_runtime_err
;
314 #define runtime(x) do { \
315 log_rl(&rl_runtime_err, L_ERR "filters, line %d: %s", what->lineno, x); \
316 res.type = T_RETURN; \
317 res.val.i = F_ERROR; \
322 x = interpret(what->y); \
323 if (x.type & T_RETURN) \
326 #define ONEARG ARG(v1, a1.p)
327 #define TWOARGS ARG(v1, a1.p) \
329 #define TWOARGS_C TWOARGS \
330 if (v1.type != v2.type) \
331 runtime( "Can't operate with values of incompatible types" );
335 * @what: filter to interpret
337 * Interpret given tree of filter instructions. This is core function
338 * of filter system and does all the hard work.
340 * Each instruction has 4 fields: code (which is instruction code),
341 * aux (which is extension to instruction code, typically type),
342 * arg1 and arg2 - arguments. Depending on instruction, arguments
343 * are either integers, or pointers to instruction trees. Common
344 * instructions like +, that have two expressions as arguments use
345 * TWOARGS macro to get both of them evaluated.
347 * &f_val structures are copied around, so there are no problems with
351 interpret(struct f_inst
*what
)
354 struct f_val v1
, v2
, res
;
367 /* Binary operators */
370 switch (res
.type
= v1
.type
) {
371 case T_VOID
: runtime( "Can't operate with values of type void" );
372 case T_INT
: res
.val
.i
= v1
.val
.i
+ v2
.val
.i
; break;
373 default: runtime( "Usage of unknown type" );
378 switch (res
.type
= v1
.type
) {
379 case T_VOID
: runtime( "Can't operate with values of type void" );
380 case T_INT
: res
.val
.i
= v1
.val
.i
- v2
.val
.i
; break;
381 default: runtime( "Usage of unknown type" );
386 switch (res
.type
= v1
.type
) {
387 case T_VOID
: runtime( "Can't operate with values of type void" );
388 case T_INT
: res
.val
.i
= v1
.val
.i
* v2
.val
.i
; break;
389 default: runtime( "Usage of unknown type" );
394 switch (res
.type
= v1
.type
) {
395 case T_VOID
: runtime( "Can't operate with values of type void" );
396 case T_INT
: if (v2
.val
.i
== 0) runtime( "Mother told me not to divide by 0" );
397 res
.val
.i
= v1
.val
.i
/ v2
.val
.i
; break;
398 case T_IP
: if (v2
.type
!= T_INT
)
399 runtime( "Incompatible types in / operator" );
401 default: runtime( "Usage of unknown type" );
408 if (res
.type
!= T_BOOL
) runtime( "Can't do boolean operation on non-booleans" );
409 res
.val
.i
= v1
.val
.i
&& v2
.val
.i
;
414 if (res
.type
!= T_BOOL
) runtime( "Can't do boolean operation on non-booleans" );
415 res
.val
.i
= v1
.val
.i
|| v2
.val
.i
;
420 if ((v1
.type
!= T_INT
) || (v2
.type
!= T_INT
))
421 runtime( "Can't operate with value of non-integer type in pair constructor" );
424 if ((u1
> 0xFFFF) || (u2
> 0xFFFF))
425 runtime( "Can't operate with value out of bounds in pair constructor" );
426 res
.val
.i
= (u1
<< 16) | u2
;
430 /* Relational operators */
435 i = val_compare(v1, v2); \
437 runtime( "Error in comparison" ); \
441 case P('!','='): COMPARE(i
!=0);
442 case P('=','='): COMPARE(i
==0);
443 case '<': COMPARE(i
==-1);
444 case P('<','='): COMPARE(i
!=1);
448 if (v1
.type
!= T_BOOL
)
449 runtime( "Not applied to non-boolean" );
451 res
.val
.i
= !res
.val
.i
;
457 res
.val
.i
= val_in_range(v1
, v2
);
458 if (res
.val
.i
== CMP_ERROR
)
459 runtime( "~ applied on unknown type pair" );
464 res
.val
.i
= (v1
.type
!= T_VOID
);
467 /* Set to indirect value, a1 = variable, a2 = value */
471 switch (res
.type
= v2
.type
) {
472 case T_VOID
: runtime( "Can't assign void values" );
485 if (sym
->class != (SYM_VARIABLE
| v2
.type
))
486 runtime( "Assigning to variable of incompatible type" );
487 * (struct f_val
*) sym
->def
= v2
;
490 bug( "Set to invalid type" );
494 /* some constants have value in a2, some in *a1.p, strange. */
495 case 'c': /* integer (or simple type) constant, string, set, or prefix_set */
496 res
.type
= what
->aux
;
498 if (res
.type
== T_PREFIX_SET
)
499 res
.val
.ti
= what
->a2
.p
;
500 else if (res
.type
== T_SET
)
501 res
.val
.t
= what
->a2
.p
;
502 else if (res
.type
== T_STRING
)
503 res
.val
.s
= what
->a2
.p
;
505 res
.val
.i
= what
->a2
.i
;
509 res
= * ((struct f_val
*) what
->a1
.p
);
515 case '?': /* ? has really strange error value, so we can implement if ... else nicely :-) */
517 if (v1
.type
!= T_BOOL
)
518 runtime( "If requires boolean expression" );
522 } else res
.val
.i
= 1;
526 debug( "No operation\n" );
530 if (what
->a2
.i
== F_NOP
|| (what
->a2
.i
!= F_NONL
&& what
->a1
.p
))
533 switch (what
->a2
.i
) {
535 die( "Filter asked me to die" );
537 /* Should take care about turning ACCEPT into MODIFY */
539 case F_REJECT
: /* FIXME (noncritical) Should print complete route along with reason to reject route */
541 res
.val
.i
= what
->a2
.i
;
542 return res
; /* We have to return now, no more processing. */
547 bug( "unknown return type: Can't happen");
550 case 'a': /* rta access */
552 struct rta
*rta
= (*f_rte
)->attrs
;
553 res
.type
= what
->aux
;
556 res
.val
.px
.ip
= * (ip_addr
*) ((char *) rta
+ what
->a2
.i
);
559 res
.val
.i
= * ((char *) rta
+ what
->a2
.i
);
561 case T_STRING
: /* Warning: this is a special case for proto attribute */
562 res
.val
.s
= rta
->proto
->name
;
564 case T_PREFIX
: /* Warning: this works only for prefix of network */
566 res
.val
.px
.ip
= (*f_rte
)->net
->n
.prefix
;
567 res
.val
.px
.len
= (*f_rte
)->net
->n
.pxlen
;
571 bug( "Invalid type for rta access (%x)", res
.type
);
577 if (what
->aux
!= v1
.type
)
578 runtime( "Attempt to set static attribute to incompatible type" );
581 struct rta
*rta
= (*f_rte
)->attrs
;
584 * ((char *) rta
+ what
->a2
.i
) = v1
.val
.i
;
587 * (ip_addr
*) ((char *) rta
+ what
->a2
.i
) = v1
.val
.px
.ip
;
590 bug( "Unknown type in set of static attribute" );
594 case P('e','a'): /* Access to extended attributes */
597 if (!(f_flags
& FF_FORCE_TMPATTR
))
598 e
= ea_find( (*f_rte
)->attrs
->eattrs
, what
->a2
.i
);
600 e
= ea_find( (*f_tmp_attrs
), what
->a2
.i
);
601 if ((!e
) && (f_flags
& FF_FORCE_TMPATTR
))
602 e
= ea_find( (*f_rte
)->attrs
->eattrs
, what
->a2
.i
);
604 switch (what
->aux
& EAF_TYPE_MASK
) {
611 res
.val
.i
= e
->u
.data
;
613 case EAF_TYPE_IP_ADDRESS
:
619 struct adata
* ad
= e
->u
.ptr
;
620 res
.val
.px
.ip
= * (ip_addr
*) ad
->data
;
622 case EAF_TYPE_AS_PATH
:
628 res
.val
.ad
= e
->u
.ptr
;
630 case EAF_TYPE_INT_SET
:
633 res
.val
.ad
= adata_empty(f_pool
);
637 res
.val
.ad
= e
->u
.ptr
;
640 bug("Unknown type in e,a");
647 struct ea_list
*l
= lp_alloc(f_pool
, sizeof(struct ea_list
) + sizeof(eattr
));
650 l
->flags
= EALF_SORTED
;
652 l
->attrs
[0].id
= what
->a2
.i
;
653 l
->attrs
[0].flags
= 0;
654 l
->attrs
[0].type
= what
->aux
| EAF_ORIGINATED
;
655 switch (what
->aux
& EAF_TYPE_MASK
) {
657 if (v1
.type
!= T_INT
)
658 runtime( "Setting int attribute to non-int value" );
659 l
->attrs
[0].u
.data
= v1
.val
.i
;
661 case EAF_TYPE_IP_ADDRESS
:
663 runtime( "Setting ip attribute to non-ip value" );
664 int len
= sizeof(ip_addr
);
665 struct adata
*ad
= lp_alloc(f_pool
, sizeof(struct adata
) + len
);
667 (* (ip_addr
*) ad
->data
) = v1
.val
.px
.ip
;
669 case EAF_TYPE_AS_PATH
:
670 if (v1
.type
!= T_PATH
)
671 runtime( "Setting path attribute to non-path value" );
672 l
->attrs
[0].u
.ptr
= v1
.val
.ad
;
674 case EAF_TYPE_INT_SET
:
675 if (v1
.type
!= T_CLIST
)
676 runtime( "Setting int set attribute to non-clist value" );
677 l
->attrs
[0].u
.ptr
= v1
.val
.ad
;
680 if (v1
.type
!= T_VOID
)
681 runtime( "Setting void attribute to non-void value" );
682 l
->attrs
[0].u
.data
= 0;
684 default: bug("Unknown type in e,S");
687 if (!(what
->aux
& EAF_TEMP
) && (!(f_flags
& FF_FORCE_TMPATTR
))) {
689 l
->next
= f_rta_copy
->eattrs
;
690 f_rta_copy
->eattrs
= l
;
692 l
->next
= (*f_tmp_attrs
);
699 res
.val
.i
= (*f_rte
)->pref
;
703 if (v1
.type
!= T_INT
)
704 runtime( "Can't set preference to non-integer" );
705 *f_rte
= rte_cow(*f_rte
);
706 (*f_rte
)->pref
= v1
.val
.i
;
708 case 'L': /* Get length of */
712 case T_PREFIX
: res
.val
.i
= v1
.val
.px
.len
; break;
713 case T_PATH
: res
.val
.i
= as_path_getlen(v1
.val
.ad
); break;
714 default: runtime( "Prefix or path expected" );
717 case P('c','p'): /* Convert prefix to ... */
719 if (v1
.type
!= T_PREFIX
)
720 runtime( "Prefix expected" );
721 res
.type
= what
->aux
;
723 /* case T_INT: res.val.i = v1.val.px.len; break; Not needed any more */
724 case T_IP
: res
.val
.px
.ip
= v1
.val
.px
.ip
; break;
725 default: bug( "Unknown prefix to conversion" );
731 res
.type
|= T_RETURN
;
733 case P('c','a'): /* CALL: this is special: if T_RETURN and returning some value, mask it out */
735 res
= interpret(what
->a2
.p
);
736 if (res
.type
== T_RETURN
)
738 res
.type
&= ~T_RETURN
;
743 struct f_tree
*t
= find_tree(what
->a2
.p
, v1
);
746 t
= find_tree(what
->a2
.p
, v1
);
748 debug( "No else statement?\n");
752 /* It is actually possible to have t->data NULL */
754 res
= interpret(t
->data
);
755 if (res
.type
& T_RETURN
)
759 case P('i','M'): /* IP.MASK(val) */
761 if (v2
.type
!= T_INT
)
762 runtime( "Integer expected");
764 runtime( "You can mask only IP addresses" );
766 ip_addr mask
= ipa_mkmask(v2
.val
.i
);
768 res
.val
.px
.ip
= ipa_and(mask
, v1
.val
.px
.ip
);
772 case 'E': /* Create empty attribute */
773 res
.type
= what
->aux
;
774 res
.val
.ad
= adata_empty(f_pool
);
776 case P('A','p'): /* Path prepend */
778 if (v1
.type
!= T_PATH
)
779 runtime("Can't prepend to non-path");
780 if (v2
.type
!= T_INT
)
781 runtime("Can't prepend non-integer");
784 res
.val
.ad
= as_path_prepend(f_pool
, v1
.val
.ad
, v2
.val
.i
);
787 case P('C','a'): /* Community list add or delete */
789 if (v1
.type
!= T_CLIST
)
790 runtime("Can't add/delete to non-clist");
791 if (v2
.type
!= T_PAIR
)
792 runtime("Can't add/delete non-pair");
796 case 'a': res
.val
.ad
= int_set_add(f_pool
, v1
.val
.ad
, v2
.val
.i
); break;
797 case 'd': res
.val
.ad
= int_set_del(f_pool
, v1
.val
.ad
, v2
.val
.i
); break;
798 default: bug("unknown Ca operation");
803 bug( "Unknown instruction %d (%c)", what
->code
, what
->code
& 0xff);
806 return interpret(what
->next
);
812 if (!i_same(f1->y, f2->y)) \
815 #define ONEARG ARG(v1, a1.p)
816 #define TWOARGS ARG(v1, a1.p) \
819 #define A2_SAME if (f1->a2.i != f2->a2.i) return 0;
822 * i_same - function that does real comparing of instruction trees, you should call filter_same from outside
825 i_same(struct f_inst
*f1
, struct f_inst
*f2
)
827 if ((!!f1
) != (!!f2
))
831 if (f1
->aux
!= f2
->aux
)
833 if (f1
->code
!= f2
->code
)
835 if (f1
== f2
) /* It looks strange, but it is possible with call rewriting trickery */
839 case ',': /* fall through */
850 case P('<','='): TWOARGS
; break;
852 case '!': ONEARG
; break;
853 case '~': TWOARGS
; break;
854 case P('d','e'): ONEARG
; break;
859 struct symbol
*s1
, *s2
;
862 if (strcmp(s1
->name
, s2
->name
))
864 if (s1
->class != s2
->class)
873 if (!trie_same(f1
->a2
.p
, f2
->a2
.p
))
878 if (!same_tree(f1
->a2
.p
, f2
->a2
.p
))
883 if (strcmp(f1
->a2
.p
, f2
->a2
.p
))
892 if (val_compare(* (struct f_val
*) f1
->a1
.p
, * (struct f_val
*) f2
->a1
.p
))
896 if (strcmp((char *) f1
->a2
.p
, (char *) f2
->a2
.p
))
899 case 'p': case 'L': ONEARG
; break;
900 case '?': TWOARGS
; break;
901 case '0': case 'E': break;
902 case P('p',','): ONEARG
; A2_SAME
; break;
904 case 'a': A2_SAME
; break;
905 case P('e','a'): A2_SAME
; break;
908 case P('e','S'): ONEARG
; A2_SAME
; break;
910 case 'r': ONEARG
; break;
911 case P('c','p'): ONEARG
; break;
912 case P('c','a'): /* Call rewriting trickery to avoid exponential behaviour */
914 if (!i_same(f1
->a2
.p
, f2
->a2
.p
))
918 case P('S','W'): ONEARG
; if (!same_tree(f1
->a2
.p
, f2
->a2
.p
)) return 0; break;
919 case P('i','M'): TWOARGS
; break;
920 case P('A','p'): TWOARGS
; break;
921 case P('C','a'): TWOARGS
; break;
923 bug( "Unknown instruction %d in same (%c)", f1
->code
, f1
->code
& 0xff);
925 return i_same(f1
->next
, f2
->next
);
929 * f_run - external entry point to filters
930 * @filter: pointer to filter to run
931 * @tmp_attrs: where to store newly generated temporary attributes
932 * @rte: pointer to pointer to &rte being filtered. When route is modified, this is changed with rte_cow().
933 * @tmp_pool: all filter allocations go from this pool
937 f_run(struct filter
*filter
, struct rte
**rte
, struct ea_list
**tmp_attrs
, struct linpool
*tmp_pool
, int flags
)
941 DBG( "Running filter `%s'...", filter
->name
);
944 f_tmp_attrs
= tmp_attrs
;
950 res
= interpret(inst
);
951 if (res
.type
!= T_RETURN
) {
952 log( L_ERR
"Filter %s did not return accept nor reject. Make up your mind", filter
->name
);
955 DBG( "done (%d)\n", res
.val
.i
);
960 f_eval_int(struct f_inst
*expr
)
970 res
= interpret(expr
);
971 if (res
.type
!= T_INT
)
972 cf_error("Integer expression expected");
977 f_eval_asn(struct f_inst
*expr
)
979 struct f_val res
= interpret(expr
);
980 if (res
.type
!= T_INT
)
981 cf_error("Can't operate with value of non-integer type in AS path mask constructor");
987 * filter_same - compare two filters
988 * @new: first filter to be compared
989 * @old: second filter to be compared, notice that this filter is
990 * damaged while comparing.
992 * Returns 1 in case filters are same, otherwise 0. If there are
993 * underlying bugs, it will rather say 0 on same filters than say
997 filter_same(struct filter
*new, struct filter
*old
)
999 if (old
== new) /* Handle FILTER_ACCEPT and FILTER_REJECT */
1001 if (old
== FILTER_ACCEPT
|| old
== FILTER_REJECT
||
1002 new == FILTER_ACCEPT
|| new == FILTER_REJECT
)
1004 return i_same(new->root
, old
->root
);