From 52e030e14666ff00a4bb0c700d2c027fbeb87d04 Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Sun, 24 Nov 2013 00:17:02 +0100 Subject: [PATCH] Converts filters to unsigned integers. --- doc/bird.sgml | 7 ++++--- filter/filter.c | 29 +++++++++++------------------ filter/filter.h | 4 ++-- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/doc/bird.sgml b/doc/bird.sgml index e208f1e2..421be713 100644 --- a/doc/bird.sgml +++ b/doc/bird.sgml @@ -925,9 +925,10 @@ incompatible with each other (that is to prevent you from shooting in the foot). i2) - (i1 < i2); -} - static inline int uint_cmp(uint i1, uint i2) { @@ -146,7 +140,6 @@ val_compare(struct f_val v1, struct f_val v2) case T_ENUM: case T_INT: case T_BOOL: - return int_cmp(v1.val.i, v2.val.i); case T_PAIR: case T_QUAD: return uint_cmp(v1.val.i, v2.val.i); @@ -157,7 +150,7 @@ val_compare(struct f_val v1, struct f_val v2) case T_PREFIX: if (rc = ipa_compare(v1.val.px.ip, v2.val.px.ip)) return rc; - return int_cmp(v1.val.px.len, v2.val.px.len); + return uint_cmp(v1.val.px.len, v2.val.px.len); case T_STRING: return strcmp(v1.val.s, v2.val.s); default: @@ -442,16 +435,16 @@ val_format(struct f_val v, buffer *buf) { case T_VOID: buffer_puts(buf, "(void)"); return; case T_BOOL: buffer_puts(buf, v.val.i ? "TRUE" : "FALSE"); return; - case T_INT: buffer_print(buf, "%d", v.val.i); return; + case T_INT: buffer_print(buf, "%u", v.val.i); return; case T_STRING: buffer_print(buf, "%s", v.val.s); return; case T_IP: buffer_print(buf, "%I", v.val.px.ip); return; case T_PREFIX: buffer_print(buf, "%I/%d", v.val.px.ip, v.val.px.len); return; - case T_PAIR: buffer_print(buf, "(%d,%d)", v.val.i >> 16, v.val.i & 0xffff); return; + case T_PAIR: buffer_print(buf, "(%u,%u)", v.val.i >> 16, v.val.i & 0xffff); return; case T_QUAD: buffer_print(buf, "%R", v.val.i); return; case T_EC: ec_format(buf2, v.val.ec); buffer_print(buf, "%s", buf2); return; case T_PREFIX_SET: trie_format(v.val.ti, buf); return; case T_SET: tree_format(v.val.t, buf); return; - case T_ENUM: buffer_print(buf, "(enum %x)%d", v.type, v.val.i); return; + case T_ENUM: buffer_print(buf, "(enum %x)%u", v.type, v.val.i); return; case T_PATH: as_path_format(v.val.ad, buf2, 1000); buffer_print(buf, "(path %s)", buf2); return; case T_CLIST: int_set_format(v.val.ad, 1, -1, buf2, 1000); buffer_print(buf, "(clist %s)", buf2); return; case T_ECLIST: ec_set_format(v.val.ad, -1, buf2, 1000); buffer_print(buf, "(eclist %s)", buf2); return; @@ -1167,14 +1160,14 @@ interpret(struct f_inst *what) /* Community (or cluster) list */ struct f_val dummy; int arg_set = 0; - i = 0; + uint n = 0; if ((v2.type == T_PAIR) || (v2.type == T_QUAD)) - i = v2.val.i; + n = v2.val.i; #ifndef IPV6 /* IP->Quad implicit conversion */ else if (v2.type == T_IP) - i = ipa_to_u32(v2.val.px.ip); + n = ipa_to_u32(v2.val.px.ip); #endif else if ((v2.type == T_SET) && clist_set_type(v2.val.t, &dummy)) arg_set = 1; @@ -1190,14 +1183,14 @@ interpret(struct f_inst *what) if (arg_set == 1) runtime("Can't add set"); else if (!arg_set) - res.val.ad = int_set_add(f_pool, v1.val.ad, i); + res.val.ad = int_set_add(f_pool, v1.val.ad, n); else res.val.ad = int_set_union(f_pool, v1.val.ad, v2.val.ad); break; case 'd': if (!arg_set) - res.val.ad = int_set_del(f_pool, v1.val.ad, i); + res.val.ad = int_set_del(f_pool, v1.val.ad, n); else res.val.ad = clist_filter(f_pool, v1.val.ad, v2, 0); break; @@ -1502,7 +1495,7 @@ f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struc log( L_ERR "Filter %s did not return accept nor reject. Make up your mind", filter->name); return F_ERROR; } - DBG( "done (%d)\n", res.val.i ); + DBG( "done (%u)\n", res.val.i ); return res.val.i; } @@ -1519,7 +1512,7 @@ f_eval(struct f_inst *expr, struct linpool *tmp_pool) return interpret(expr); } -int +uint f_eval_int(struct f_inst *expr) { /* Called independently in parse-time to eval expressions */ diff --git a/filter/filter.h b/filter/filter.h index 07a4c9e4..3a6b66d9 100644 --- a/filter/filter.h +++ b/filter/filter.h @@ -51,7 +51,7 @@ struct f_prefix { struct f_val { int type; union { - int i; + uint i; u64 ec; /* ip_addr ip; Folded into prefix */ struct f_prefix px; @@ -108,7 +108,7 @@ struct rte; int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags); struct f_val f_eval(struct f_inst *expr, struct linpool *tmp_pool); -int f_eval_int(struct f_inst *expr); +uint f_eval_int(struct f_inst *expr); u32 f_eval_asn(struct f_inst *expr); char *filter_name(struct filter *filter);