summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/attrs.h30
-rw-r--r--lib/birdlib.h1
-rw-r--r--lib/route.h39
-rw-r--r--lib/type.h19
4 files changed, 55 insertions, 34 deletions
diff --git a/lib/attrs.h b/lib/attrs.h
index e0595846..fcb70230 100644
--- a/lib/attrs.h
+++ b/lib/attrs.h
@@ -11,7 +11,35 @@
#include <stdint.h>
#include "lib/unaligned.h"
-#include "lib/route.h"
+
+typedef struct adata {
+ uint length; /* Length of data */
+ byte data[0];
+} adata;
+
+#define ADATA_SIZE(s) BIRD_CPU_ALIGN(sizeof(struct adata) + s)
+
+extern const adata null_adata; /* adata of length 0 */
+
+static inline struct adata *
+lp_alloc_adata(struct linpool *pool, uint len)
+{
+ struct adata *ad = lp_alloc(pool, sizeof(struct adata) + len);
+ ad->length = len;
+ return ad;
+}
+
+static inline struct adata *
+lp_store_adata(struct linpool *pool, const void *buf, uint len)
+{
+ struct adata *ad = lp_alloc_adata(pool, len);
+ memcpy(ad->data, buf, len);
+ return ad;
+}
+
+static inline int adata_same(const struct adata *a, const struct adata *b)
+{ return (a->length == b->length && !memcmp(a->data, b->data, a->length)); }
+
/* a-path.c */
diff --git a/lib/birdlib.h b/lib/birdlib.h
index 81d4908a..6f0bab96 100644
--- a/lib/birdlib.h
+++ b/lib/birdlib.h
@@ -19,6 +19,7 @@ struct align_probe { char x; long int y; };
#define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i)))
#define BIRD_ALIGN(s, a) (((s)+a-1)&~(a-1))
#define CPU_STRUCT_ALIGN (sizeof(struct align_probe))
+#define BIRD_CPU_ALIGN(s) BIRD_ALIGN((s), CPU_STRUCT_ALIGN)
/* Utility macros */
diff --git a/lib/route.h b/lib/route.h
index 20b6fd39..62c16fa9 100644
--- a/lib/route.h
+++ b/lib/route.h
@@ -10,6 +10,8 @@
#ifndef _BIRD_LIB_ROUTE_H_
#define _BIRD_LIB_ROUTE_H_
+#include "lib/type.h"
+
struct network;
struct proto;
struct cli;
@@ -165,25 +167,6 @@ const char *ea_custom_name(uint ea);
#define EA_BIT(n) ((n) << 24) /* Used in bitfield accessors */
#define EA_BIT_GET(ea) ((ea) >> 24)
-typedef struct adata {
- uint length; /* Length of data */
- byte data[0];
-} adata;
-
-extern const adata null_adata; /* adata of length 0 */
-
-static inline struct adata *
-lp_alloc_adata(struct linpool *pool, uint len)
-{
- struct adata *ad = lp_alloc(pool, sizeof(struct adata) + len);
- ad->length = len;
- return ad;
-}
-
-static inline int adata_same(const struct adata *a, const struct adata *b)
-{ return (a->length == b->length && !memcmp(a->data, b->data, a->length)); }
-
-
typedef struct ea_list {
struct ea_list *next; /* In case we have an override list */
byte flags; /* Flags: EALF_... */
@@ -223,24 +206,16 @@ ea_get_int(ea_list *e, unsigned id, u32 def)
}
void ea_dump(ea_list *);
-void ea_sort(ea_list *); /* Sort entries in all sub-lists */
-unsigned ea_scan(ea_list *); /* How many bytes do we need for merged ea_list */
-void ea_merge(ea_list *from, ea_list *to); /* Merge sub-lists to allocated buffer */
int ea_same(ea_list *x, ea_list *y); /* Test whether two ea_lists are identical */
uint ea_hash(ea_list *e); /* Calculate 16-bit hash value */
ea_list *ea_append(ea_list *to, ea_list *what);
void ea_format_bitfield(const struct eattr *a, byte *buf, int bufsize, const char **names, int min, int max);
-#define ea_normalize(ea) do { \
- if (ea->next) { \
- ea_list *t = alloca(ea_scan(ea)); \
- ea_merge(ea, t); \
- ea = t; \
- } \
- ea_sort(ea); \
- if (ea->count == 0) \
- ea = NULL; \
-} while(0) \
+/* Normalize ea_list; allocates the result from tmp_linpool */
+ea_list *ea_normalize(const ea_list *e);
+
+uint ea_list_size(ea_list *);
+void ea_list_copy(ea_list *dest, ea_list *src, uint size);
struct ea_one_attr_list {
ea_list l;
diff --git a/lib/type.h b/lib/type.h
index d0a887d8..6d19a250 100644
--- a/lib/type.h
+++ b/lib/type.h
@@ -10,6 +10,7 @@
#define _BIRD_TYPE_H_
#include "lib/birdlib.h"
+#include "lib/attrs.h"
union bval {
#define BVAL_ITEMS \
@@ -18,9 +19,25 @@ union bval {
const struct adata *ptr; /* Generic attribute data inherited from eattrs */ \
const struct adata *ad; /* Generic attribute data inherited from filters */ \
- BVAL_ITEMS
+ BVAL_ITEMS;
};
+union bval_long {
+ union bval bval; /* For direct assignments */
+ BVAL_ITEMS; /* For item-wise access */
+
+ u64 ec;
+ lcomm lc;
+ ip_addr ip;
+ const net_addr *net;
+ const char *s;
+ const struct f_tree *t;
+ const struct f_trie *ti;
+ const struct f_path_mask *path_mask;
+ struct f_path_mask_item pmi;
+};
+
+
/* Internal types */
enum btype {
/* Nothing. Simply nothing. */