]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
More attribute types: pointers, strings, btime
authorKaterina Kubecova <katerina.kubecova@nic.cz>
Tue, 15 Oct 2024 08:50:29 +0000 (10:50 +0200)
committerMaria Matejka <mq@ucw.cz>
Sat, 9 Nov 2024 08:55:40 +0000 (09:55 +0100)
For the upcoming rework of protocol state information propagation,
we need some more eattr types to be defined.

These types are probably not defined completely and before using
them for route attributes, you should check that they don't lack
some crucial methods.

filter/data.c
lib/route.h
lib/type.h
nest/rt-attr.c

index 4376c10955176620099f642bed50409fa357cd0c..6311ac3045727c7b027696a260d91b0db10c9d93 100644 (file)
@@ -651,6 +651,9 @@ mem_hash_mix_f_val(u64 *h, struct f_val *v)
     case T_NEXTHOP_LIST:
     case T_HOSTENTRY:
     case T_IFACE:
+    case T_PTR:
+    case T_ENUM_STATE:
+    case T_BTIME:
       bug("Invalid type %s in f_val hashing", f_type_name(v->type));
   }
 }
index a0cb75da0dabc8f6048c6c7b0c05442fe2baf06a..de15cfb238d84fa467c81ecaf7a8d76561300eeb 100644 (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)  ({ \
     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); \
     (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)  ({ \
     struct ea_class *cls = ea_class_find((_ident)); \
     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) ({ \
     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); \
     })
 
+#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) ({ \
     btype _type = (_class)->type; \
     ASSERT_DIE(!(_type & EAF_EMBEDDED)); \
@@ -376,6 +389,8 @@ void ea_list_copy(ea_list *dest, ea_list *src, uint size);
 #define EA_LITERAL_GENERIC(_id, _type, _flags, ...) \
   ((eattr) { .id = _id, .type = _type, .flags = _flags, __VA_ARGS__ })
 
+#define EA_LITERAL_STORE_STRING(_class, _flags, string) ({EA_LITERAL_STORE_ADATA(_class, _flags, string, strlen(string)+1);})
+
 static inline eattr *
 ea_set_attr(ea_list **to, eattr a)
 {
@@ -405,6 +420,10 @@ static inline void
 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)); }
 
+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
 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)); }
@@ -414,7 +433,9 @@ ea_copy_attr(ea_list **to, ea_list *from, const struct ea_class *def)
 {
   eattr *e = ea_find_by_class(from, def);
   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);
     else
       ea_set_attr_data(to, def, e->flags, e->u.ptr->data, e->u.ptr->length);
index c59f2d9a8b8a92b71cf514cb906a28b976aab702..ec476a52bfa72007ffec7a865dcf6d99e5e25ebb 100644 (file)
@@ -24,6 +24,7 @@ union bval {
   };                                                                                   \
   const struct adata *ptr;     /* Generic attribute data inherited from eattrs */      \
   const struct adata *ad;      /* Generic attribute data inherited from filters */     \
+  const void * v_ptr;       /* Stored pointer */ \
 
   BVAL_ITEMS;
 };
@@ -73,6 +74,7 @@ enum btype {
   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_STRING = 0x10,
+  T_PTR = 0x11,         /* Void pointer */
 
   T_ENUM_BGP_ORIGIN = 0x13,    /* BGP Origin enum */
   T_ENUM_RA_PREFERENCE = 0x15, /* RA Preference enum */
@@ -114,6 +116,10 @@ enum btype {
 
   T_SET = 0x80,
   T_PREFIX_SET = 0x84,
+
+/* protocol */
+  T_ENUM_STATE = 0xd1,
+  T_BTIME = 0xd4,
 } PACKED;
 
 typedef enum btype btype;
index 978f423e98ab3e7a5190b87d5d9f0c5eb7fa8edf..4ea5f76efe1bd69b08dc607614bf2e6a912754b0 100644 (file)
@@ -1124,6 +1124,8 @@ eattr_same_value(const eattr *a, const eattr *b)
   if (a->undef)
     return 1;
 
+  if (a->type == T_PTR)
+    return a->u.v_ptr == b->u.v_ptr;
   if (a->type & EAF_EMBEDDED)
     return a->u.data == b->u.data;
   else