From: Jan Maria Matejka Date: Tue, 3 Jul 2018 13:31:41 +0000 (+0200) Subject: Nest: Make f_val and eattr binary compatible. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fmq-merge-fval-eattr;p=thirdparty%2Fbird.git Nest: Make f_val and eattr binary compatible. This will help merging them in future commits. --- diff --git a/filter/filter.h b/filter/filter.h index 312a1fd79..9cf388bb9 100644 --- a/filter/filter.h +++ b/filter/filter.h @@ -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; diff --git a/nest/Makefile b/nest/Makefile index 884d39506..e8a779238 100644 --- a/nest/Makefile +++ b/nest/Makefile @@ -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 index 000000000..12c282e1a --- /dev/null +++ b/nest/assert.c @@ -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!"); diff --git a/nest/route.h b/nest/route.h index cad154407..ba05a6a98 100644 --- a/nest/route.h +++ b/nest/route.h @@ -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 */