0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-08 12:18:42 +00:00

void pointer can be stored in eattr

This commit is contained in:
Katerina Kubecova 2024-07-08 13:50:40 +02:00
parent dda37842dc
commit 83f2b114c8
4 changed files with 27 additions and 3 deletions

View File

@ -651,6 +651,7 @@ mem_hash_mix_f_val(u64 *h, struct f_val *v)
case T_NEXTHOP_LIST: case T_NEXTHOP_LIST:
case T_HOSTENTRY: case T_HOSTENTRY:
case T_IFACE: case T_IFACE:
case T_PTR:
bug("Invalid type %s in f_val hashing", f_type_name(v->type)); bug("Invalid type %s in f_val hashing", f_type_name(v->type));
} }
} }

View File

@ -321,11 +321,18 @@ static inline eattr *ea_find_by_name(ea_list *l, const char *name)
#define ea_get_int(_l, _ident, _def) ({ \ #define ea_get_int(_l, _ident, _def) ({ \
struct ea_class *cls = ea_class_find((_ident)); \ struct ea_class *cls = ea_class_find((_ident)); \
ASSERT_DIE(cls->type & EAF_EMBEDDED); \ ASSERT_DIE(cls->type & EAF_EMBEDDED && cls->type != T_PTR); \
const eattr *ea = ea_find((_l), cls->id); \ const eattr *ea = ea_find((_l), cls->id); \
(ea ? ea->u.data : (_def)); \ (ea ? ea->u.data : (_def)); \
}) })
#define ea_get_ptr(_l, _ident, _def) ({ \
struct ea_class *cls = ea_class_find((_ident)); \
ASSERT_DIE(cls->type == T_PTR); \
const eattr *ea = ea_find((_l), cls->id); \
(ea ? ea->u.v_ptr : (_def)); \
})
#define ea_get_ip(_l, _ident, _def) ({ \ #define ea_get_ip(_l, _ident, _def) ({ \
struct ea_class *cls = ea_class_find((_ident)); \ struct ea_class *cls = ea_class_find((_ident)); \
ASSERT_DIE(cls->type == T_IP); \ ASSERT_DIE(cls->type == T_IP); \
@ -357,10 +364,16 @@ void ea_list_copy(ea_list *dest, ea_list *src, uint size);
#define EA_LITERAL_EMBEDDED(_class, _flags, _val) ({ \ #define EA_LITERAL_EMBEDDED(_class, _flags, _val) ({ \
btype _type = (_class)->type; \ btype _type = (_class)->type; \
ASSERT_DIE(_type & EAF_EMBEDDED); \ ASSERT_DIE(_type & EAF_EMBEDDED && _type != T_PTR); \
EA_LITERAL_GENERIC((_class)->id, _type, _flags, .u.i = _val); \ EA_LITERAL_GENERIC((_class)->id, _type, _flags, .u.i = _val); \
}) })
#define EA_LITERAL_STORE_PTR(_class, _flags, _ptr) ({ \
btype _type = (_class)->type; \
ASSERT_DIE(!(_type == T_PTR)); \
EA_LITERAL_GENERIC((_class)->id, _type, _flags, .u.v_ptr = _ptr); \
})
#define EA_LITERAL_STORE_ADATA(_class, _flags, _buf, _len) ({ \ #define EA_LITERAL_STORE_ADATA(_class, _flags, _buf, _len) ({ \
btype _type = (_class)->type; \ btype _type = (_class)->type; \
ASSERT_DIE(!(_type & EAF_EMBEDDED)); \ ASSERT_DIE(!(_type & EAF_EMBEDDED)); \
@ -405,6 +418,10 @@ static inline void
ea_set_attr_u32(ea_list **to, const struct ea_class *def, uint flags, u64 data) ea_set_attr_u32(ea_list **to, const struct ea_class *def, uint flags, u64 data)
{ ea_set_attr(to, EA_LITERAL_EMBEDDED(def, flags, data)); } { ea_set_attr(to, EA_LITERAL_EMBEDDED(def, flags, data)); }
static inline void
ea_set_attr_ptr(ea_list **to, const struct ea_class *def, uint flags, const void *data)
{ ea_set_attr(to, EA_LITERAL_STORE_PTR(def, flags, data)); }
static inline void static inline void
ea_set_attr_data(ea_list **to, const struct ea_class *def, uint flags, const void *data, uint len) ea_set_attr_data(ea_list **to, const struct ea_class *def, uint flags, const void *data, uint len)
{ ea_set_attr(to, EA_LITERAL_STORE_ADATA(def, flags, data, len)); } { ea_set_attr(to, EA_LITERAL_STORE_ADATA(def, flags, data, len)); }
@ -414,7 +431,9 @@ ea_copy_attr(ea_list **to, ea_list *from, const struct ea_class *def)
{ {
eattr *e = ea_find_by_class(from, def); eattr *e = ea_find_by_class(from, def);
if (e) if (e)
if (e->type & EAF_EMBEDDED) if (e->type == T_PTR)
ea_set_attr_ptr(to, def, e->flags, (void *)e->u.v_ptr);
else if (e->type & EAF_EMBEDDED)
ea_set_attr_u32(to, def, e->flags, e->u.data); ea_set_attr_u32(to, def, e->flags, e->u.data);
else else
ea_set_attr_data(to, def, e->flags, e->u.ptr->data, e->u.ptr->length); ea_set_attr_data(to, def, e->flags, e->u.ptr->data, e->u.ptr->length);

View File

@ -24,6 +24,7 @@ union bval {
}; \ }; \
const struct adata *ptr; /* Generic attribute data inherited from eattrs */ \ const struct adata *ptr; /* Generic attribute data inherited from eattrs */ \
const struct adata *ad; /* Generic attribute data inherited from filters */ \ const struct adata *ad; /* Generic attribute data inherited from filters */ \
const void * v_ptr; /* Stored pointer */ \
BVAL_ITEMS; BVAL_ITEMS;
}; };
@ -73,6 +74,7 @@ enum btype {
T_ECLIST = 0x0e, /* Set of pairs of u32's - ext. community list */ T_ECLIST = 0x0e, /* Set of pairs of u32's - ext. community list */
T_LCLIST = 0x08, /* Set of triplets of u32's - large community list */ T_LCLIST = 0x08, /* Set of triplets of u32's - large community list */
T_STRING = 0x10, T_STRING = 0x10,
T_PTR = 0x11, /* Void pointer */
T_ENUM_BGP_ORIGIN = 0x13, /* BGP Origin enum */ T_ENUM_BGP_ORIGIN = 0x13, /* BGP Origin enum */
T_ENUM_RA_PREFERENCE = 0x15, /* RA Preference enum */ T_ENUM_RA_PREFERENCE = 0x15, /* RA Preference enum */

View File

@ -1120,6 +1120,8 @@ eattr_same_value(const eattr *a, const eattr *b)
if (a->undef) if (a->undef)
return 1; return 1;
if (a->type == T_PTR)
return a->u.v_ptr == b->u.v_ptr;
if (a->type & EAF_EMBEDDED) if (a->type & EAF_EMBEDDED)
return a->u.data == b->u.data; return a->u.data == b->u.data;
else else