]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Nest: Make f_val and eattr binary compatible. mq-merge-fval-eattr
authorJan Maria Matejka <mq@ucw.cz>
Tue, 3 Jul 2018 13:31:41 +0000 (15:31 +0200)
committerJan Maria Matejka <mq@ucw.cz>
Tue, 3 Jul 2018 15:24:17 +0000 (17:24 +0200)
This will help merging them in future commits.

filter/filter.h
nest/Makefile
nest/assert.c [new file with mode: 0644]
nest/route.h

index 312a1fd7959f048d4c3ad8804b5050d3155cdc72..9cf388bb910272b0a42a7ef0dcda05f2a7e52616 100644 (file)
@@ -170,7 +170,7 @@ struct f_prefix {
 struct f_val {
   enum f_type type;            /* T_*  */
   union {
-    uint i;
+    u32 i;
     u64 ec;
     lcomm lc;
     ip_addr ip;
@@ -183,6 +183,13 @@ struct f_val {
   } val;
 };
 
+/* To allow direct copying between eattrs and f_val. */
+
+union f_val_eattr {
+  struct f_val f;
+  struct eattr e;
+};
+
 struct f_dynamic_attr {
   int type;
   enum f_type f_type;
index 884d39506a37136e65042c4249c42f89d028c656..e8a779238c4a95d28ef122826af082d34837f401 100644 (file)
@@ -1,4 +1,4 @@
-src := a-path.c a-set.c cli.c cmds.c iface.c locks.c neighbor.c password.c proto.c rt-attr.c rt-dev.c rt-fib.c rt-show.c rt-table.c
+src := assert.c a-path.c a-set.c cli.c cmds.c iface.c locks.c neighbor.c password.c proto.c rt-attr.c rt-dev.c rt-fib.c rt-show.c rt-table.c
 obj := $(src-o-files)
 $(all-daemon)
 $(cf-local)
diff --git a/nest/assert.c b/nest/assert.c
new file mode 100644 (file)
index 0000000..12c282e
--- /dev/null
@@ -0,0 +1,8 @@
+#include "nest/bird.h"
+
+#include "filter/filter.h"
+#include "nest/route.h"
+
+_Static_assert(sizeof(struct f_val) >= sizeof(struct eattr), "Structures f_val and eattr not binary compatible!");
+_Static_assert(OFFSETOF(struct f_val, val) == OFFSETOF(struct eattr, u), "Structures f_val and eattr not binary compatible!");
+_Static_assert(sizeof(enum ea_type) == sizeof(enum f_type), "Structures f_val and eattr not binary compatible!");
index cad154407949779d9ee037e23cd773543ea75203..ba05a6a981b4f4307094ef4300c5fc5ebb6b81d9 100644 (file)
@@ -456,16 +456,6 @@ static inline int rte_is_reachable(rte *r)
  *     Extended Route Attributes
  */
 
-typedef struct eattr {
-  word id;                             /* EA_CODE(PROTOCOL_..., protocol-dependent ID) */
-  byte flags;                          /* Protocol-dependent flags */
-  byte type;                           /* Attribute type and several flags (EAF_...) */
-  union {
-    u32 data;
-    struct adata *ptr;                 /* Attribute data elsewhere */
-  } u;
-} eattr;
-
 #define EA_CODE(proto,id) (((proto) << 8) | (id))
 #define EA_PROTO(ea) ((ea) >> 8)
 #define EA_ID(ea) ((ea) & 0xff)
@@ -476,22 +466,34 @@ typedef struct eattr {
 #define EA_ALLOW_UNDEF 0x10000         /* ea_find: allow EAF_TYPE_UNDEF */
 #define EA_BIT(n) ((n) << 24)          /* Used in bitfield accessors */
 
-#define EAF_TYPE_MASK 0x1f             /* Mask with this to get type */
-#define EAF_TYPE_INT 0x01              /* 32-bit unsigned integer number */
-#define EAF_TYPE_OPAQUE 0x02           /* Opaque byte string (not filterable) */
-#define EAF_TYPE_IP_ADDRESS 0x04       /* IP address */
-#define EAF_TYPE_ROUTER_ID 0x05                /* Router ID (IPv4 address) */
-#define EAF_TYPE_AS_PATH 0x06          /* BGP AS path (encoding per RFC 1771:4.3) */
-#define EAF_TYPE_BITFIELD 0x09         /* 32-bit embedded bitfield */
-#define EAF_TYPE_INT_SET 0x0a          /* Set of u32's (e.g., a community list) */
-#define EAF_TYPE_EC_SET 0x0e           /* Set of pairs of u32's - ext. community list */
-#define EAF_TYPE_LC_SET 0x12           /* Set of triplets of u32's - large community list */
-#define EAF_TYPE_UNDEF 0x1f            /* `force undefined' entry */
-#define EAF_EMBEDDED 0x01              /* Data stored in eattr.u.data (part of type spec) */
-#define EAF_VAR_LENGTH 0x02            /* Attribute length is variable (part of type spec) */
-#define EAF_ORIGINATED 0x20            /* The attribute has originated locally */
-#define EAF_FRESH 0x40                 /* An uncached attribute (e.g. modified in export filter) */
-#define EAF_TEMP 0x80                  /* A temporary attribute (the one stored in the tmp attr list) */
+enum ea_type {
+  EAF_TYPE_MASK = 0x1f,                /* Mask with this to get type */
+  EAF_TYPE_INT = 0x01,         /* 32-bit unsigned integer number */
+  EAF_TYPE_OPAQUE = 0x02,      /* Opaque byte string (not filterable) */
+  EAF_TYPE_IP_ADDRESS = 0x04,  /* IP address */
+  EAF_TYPE_ROUTER_ID = 0x05,   /* Router ID (IPv4 address) */
+  EAF_TYPE_AS_PATH = 0x06,     /* BGP AS path (encoding per RFC 1771:4.3) */
+  EAF_TYPE_BITFIELD = 0x09,    /* 32-bit embedded bitfield */
+  EAF_TYPE_INT_SET = 0x0a,     /* Set of u32's (e.g., a community list) */
+  EAF_TYPE_EC_SET = 0x0e,      /* Set of pairs of u32's - ext. community list */
+  EAF_TYPE_LC_SET = 0x12,      /* Set of triplets of u32's - large community list */
+  EAF_TYPE_UNDEF = 0x1f,       /* `force undefined' entry */
+  EAF_EMBEDDED = 0x01,         /* Data stored in eattr.u.data (part of type spec) */
+  EAF_VAR_LENGTH = 0x02,       /* Attribute length is variable (part of type spec) */
+  EAF_ORIGINATED = 0x20,       /* The attribute has originated locally */
+  EAF_FRESH = 0x40,            /* An uncached attribute (e.g. modified in export filter) */
+  EAF_TEMP = 0x80,             /* A temporary attribute (the one stored in the tmp attr list) */
+};
+
+typedef struct eattr {
+  enum ea_type type;                   /* Attribute type and several flags (EAF_...) */
+  word id;                             /* EA_CODE(PROTOCOL_..., protocol-dependent ID) */
+  byte flags;                          /* Protocol-dependent flags */
+  union {
+    u32 data;
+    struct adata *ptr;                 /* Attribute data elsewhere */
+  } u;
+} eattr;
 
 typedef struct adata {
   uint length;                         /* Length of data */