302
343
if (nl == clist->length)
305
struct adata *res = lp_alloc(pool, sizeof(struct adata) + nl);
346
struct adata *res = adata_empty(pool, nl);
347
memcpy(res->data, tmp, nl);
351
static struct adata *
352
eclist_filter(struct linpool *pool, struct adata *list, struct f_tree *set, int pos)
359
int len = int_set_get_size(list);
360
u32 *l = int_set_get_data(list);
366
for (i = 0; i < len; i += 2) {
367
v.val.ec = ec_get(l, i);
368
if (pos == !!find_tree(set, v)) { /* pos && find_tree || !pos && !find_tree */
374
int nl = (k - tmp) * 4;
375
if (nl == list->length)
378
struct adata *res = adata_empty(pool, nl);
307
379
memcpy(res->data, tmp, nl);
397
473
case T_PREFIX: logn("%I/%d", v.val.px.ip, v.val.px.len); return;
398
474
case T_PAIR: logn("(%d,%d)", v.val.i >> 16, v.val.i & 0xffff); return;
399
475
case T_QUAD: logn("%R", v.val.i); return;
476
case T_EC: ec_format(buf2, v.val.ec); logn("%s", buf2); return;
400
477
case T_PREFIX_SET: trie_print(v.val.ti); return;
401
478
case T_SET: tree_print(v.val.t); return;
402
479
case T_ENUM: logn("(enum %x)%d", v.type, v.val.i); return;
403
480
case T_PATH: as_path_format(v.val.ad, buf2, 1000); logn("(path %s)", buf2); return;
404
481
case T_CLIST: int_set_format(v.val.ad, 1, -1, buf2, 1000); logn("(clist %s)", buf2); return;
482
case T_ECLIST: ec_set_format(v.val.ad, -1, buf2, 1000); logn("(eclist %s)", buf2); return;
405
483
case T_PATH_MASK: pm_format(v.val.path_mask, buf2, 1000); logn("(pathmask%s)", buf2); return;
406
484
default: logn( "[unknown type %x]", v.type ); return;
552
630
res.type = T_PAIR;
637
int check, ipv4_used;
640
if (v1.type == T_INT) {
641
ipv4_used = 0; key = v1.val.i;
643
else if (v1.type == T_QUAD) {
644
ipv4_used = 1; key = v1.val.i;
647
/* IP->Quad implicit conversion */
648
else if (v1.type == T_IP) {
649
ipv4_used = 1; key = ipa_to_u32(v1.val.px.ip);
653
runtime("Can't operate with key of non-integer/IPv4 type in EC constructor");
655
if (v2.type != T_INT)
656
runtime("Can't operate with value of non-integer type in EC constructor");
661
if (what->aux == EC_GENERIC) {
662
check = 0; res.val.ec = ec_generic(key, val);
664
else if (ipv4_used) {
665
check = 1; res.val.ec = ec_ip4(what->aux, key, val);
667
else if (key < 0x10000) {
668
check = 0; res.val.ec = ec_as2(what->aux, key, val);
671
check = 1; res.val.ec = ec_as4(what->aux, key, val);
674
if (check && (val > 0xFFFF))
675
runtime("Can't operate with value out of bounds in EC constructor");
555
680
/* Relational operators */
557
682
#define COMPARE(x) \
939
1080
res.val.ad = as_path_prepend(f_pool, v1.val.ad, v2.val.i);
942
case P('C','a'): /* Community list add or delete */
1083
case P('C','a'): /* (Extended) Community list add or delete */
944
if (v1.type != T_CLIST)
945
runtime("Can't add/delete to non-clist");
951
if ((v2.type == T_PAIR) || (v2.type == T_QUAD))
1085
if (v1.type == T_CLIST)
1087
/* Community (or cluster) list */
1092
if ((v2.type == T_PAIR) || (v2.type == T_QUAD))
954
/* IP->Quad implicit conversion */
955
else if (v2.type == T_IP)
956
i = ipa_to_u32(v2.val.px.ip);
1095
/* IP->Quad implicit conversion */
1096
else if (v2.type == T_IP)
1097
i = ipa_to_u32(v2.val.px.ip);
958
else if ((v2.type == T_SET) && clist_set_type(v2.val.t, &dummy))
1099
else if ((v2.type == T_SET) && clist_set_type(v2.val.t, &dummy))
1102
runtime("Can't add/delete non-pair");
1109
runtime("Can't add set");
1110
res.val.ad = int_set_add(f_pool, v1.val.ad, i);
1115
res.val.ad = int_set_del(f_pool, v1.val.ad, i);
1117
res.val.ad = clist_filter(f_pool, v1.val.ad, v2.val.t, 0);
1122
runtime("Can't filter pair");
1123
res.val.ad = clist_filter(f_pool, v1.val.ad, v2.val.t, 1);
1127
bug("unknown Ca operation");
1130
else if (v1.type == T_ECLIST)
1132
/* Extended community list */
1135
/* v2.val is either EC or EC-set */
1136
if ((v2.type == T_SET) && eclist_set_type(v2.val.t))
1138
else if (v2.type != T_EC)
1139
runtime("Can't add/delete non-pair");
1141
res.type = T_ECLIST;
1146
runtime("Can't add set");
1147
res.val.ad = ec_set_add(f_pool, v1.val.ad, v2.val.ec);
1152
res.val.ad = ec_set_del(f_pool, v1.val.ad, v2.val.ec);
1154
res.val.ad = eclist_filter(f_pool, v1.val.ad, v2.val.t, 0);
1159
runtime("Can't filter ec");
1160
res.val.ad = eclist_filter(f_pool, v1.val.ad, v2.val.t, 1);
1164
bug("unknown Ca operation");
961
runtime("Can't add/delete non-pair");
968
runtime("Can't add set");
969
res.val.ad = int_set_add(f_pool, v1.val.ad, i);
974
res.val.ad = int_set_del(f_pool, v1.val.ad, i);
976
res.val.ad = clist_filter(f_pool, v1.val.ad, v2.val.t, 0);
981
runtime("Can't filter pair");
982
res.val.ad = clist_filter(f_pool, v1.val.ad, v2.val.t, 1);
986
bug("unknown Ca operation");
1168
runtime("Can't add/delete to non-(e)clist");