Browse Source

route eattrs

master
eta 4 months ago
parent
commit
72d9698fc0
  1. 60
      sysdep/unix/main.c

60
sysdep/unix/main.c

@ -1083,6 +1083,65 @@ clbird_make_val(cl_object from)
}
return ecl_make_pointer(res);
}
cl_object
ea_to_object(eattr *e)
{
struct f_val *res = cfg_alloc(sizeof(struct f_val));
switch (e->type & EAF_TYPE_MASK) {
case EAF_TYPE_INT:
return ecl_make_integer(e->u.data);
case EAF_TYPE_ROUTER_ID:
res->type = T_QUAD;
res->val.i = e->u.data;
break;
case EAF_TYPE_OPAQUE:
return eclk("OPAQUE");
case EAF_TYPE_IP_ADDRESS:
res->type = T_IP;
res->val.ip = *((ip_addr *) e->u.ptr->data);
break;
case EAF_TYPE_AS_PATH:
res->type = T_PATH;
res->val.ad = e->u.ptr;
break;
case EAF_TYPE_BITFIELD:
return ecl_make_integer(e->u.data);
break;
case EAF_TYPE_INT_SET:
res->type = T_CLIST;
res->val.ad = e->u.ptr;
break;
case EAF_TYPE_EC_SET:
res->type = T_ECLIST;
res->val.ad = e->u.ptr;
break;
case EAF_TYPE_LC_SET:
res->type = T_LCLIST;
res->val.ad = e->u.ptr;
break;
case EAF_TYPE_UNDEF:
return ECL_NIL;
break;
default:
FEerror("failed to translate BIRD dynamic attribute of type ~A", 1, ecl_make_integer(e->type));
}
return ecl_make_pointer(res);
}
cl_object
clbird_get_eattrs(cl_object rte_obj)
{
struct rte *rte = ecl_foreign_data_pointer_safe(rte_obj);
cl_object ret = ECL_NIL;
for (ea_list *eal = rte->attrs->eattrs; eal; eal=eal->next) {
for (int i = 0; i < eal->count; i++) {
eattr *e = &eal->attrs[i];
cl_object id = ecl_make_integer(e->id);
cl_object attr = ecl_cons(id, ea_to_object(e));
ret = ecl_cons(attr, ret);
}
}
return ret;
}
void
init_ecl_functions()
@ -1101,6 +1160,7 @@ init_ecl_functions()
ecl_def_c_function(_ecl_intern("DOTQUAD", package), clbird_dotquad, 4);
ecl_def_c_function(_ecl_intern("CIDR4", package), clbird_cidr4, 5);
ecl_def_c_function(_ecl_intern("MAKE-VAL", package), clbird_make_val, 1);
ecl_def_c_function(_ecl_intern("ROUTE-EATTRS", package), clbird_get_eattrs, 1);
ecl_def_c_function(_ecl_intern("VAL-TYPE-NAME", package), clbird_val_type_name, 1);
ecl_def_c_function(_ecl_intern("VAL-COMPARE", package), clbird_val_compare, 2);
ecl_def_c_function(_ecl_intern("VAL-SAME", package), clbird_val_same, 2);

Loading…
Cancel
Save