aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazuki Yamaguchi <k@rhe.jp>2020-08-03 03:06:48 +0900
committerKazuki Yamaguchi <k@rhe.jp>2023-10-11 17:40:55 +0900
commitff1b12139941870aea274276d597a79f26c2ab50 (patch)
tree957009f3f2907cce87d42017b563d442eca9e926
parent0e1fbaa5b21db8e5c64a732dbaf0b8afe707a147 (diff)
downloadbird-ff1b12139941870aea274276d597a79f26c2ab50.tar.gz
Nest: Statically allocate space for MPLS labels
-rw-r--r--nest/route.h12
-rw-r--r--nest/rt-attr.c31
2 files changed, 12 insertions, 31 deletions
diff --git a/nest/route.h b/nest/route.h
index f83a5b33..e6f5f95a 100644
--- a/nest/route.h
+++ b/nest/route.h
@@ -431,7 +431,7 @@ struct nexthop {
byte weight;
byte labels_orig; /* Number of labels before hostentry was applied */
byte labels; /* Number of all labels */
- u32 label[0];
+ u32 label[MPLS_MAX_LABEL_STACK];
};
#define RNF_ONLINK 0x1 /* Gateway is onlink regardless of IP ranges */
@@ -683,10 +683,10 @@ ea_set_attr_data(ea_list **to, struct linpool *pool, uint id, uint flags, uint t
}
-#define NEXTHOP_MAX_SIZE (sizeof(struct nexthop) + sizeof(u32)*MPLS_MAX_LABEL_STACK)
+#define NEXTHOP_MAX_SIZE sizeof(struct nexthop)
-static inline size_t nexthop_size(const struct nexthop *nh)
-{ return sizeof(struct nexthop) + sizeof(u32)*nh->labels; }
+static inline size_t nexthop_size(const struct nexthop *nh UNUSED)
+{ return sizeof(struct nexthop); }
int nexthop__same(struct nexthop *x, struct nexthop *y); /* Compare multipath nexthops */
static inline int nexthop_same(struct nexthop *x, struct nexthop *y)
{ return (x == y) || nexthop__same(x, y); }
@@ -698,8 +698,8 @@ void nexthop_insert(struct nexthop **n, struct nexthop *y);
int nexthop_is_sorted(struct nexthop *x);
void rta_init(void);
-static inline size_t rta_size(const rta *a) { return sizeof(rta) + sizeof(u32)*a->nh.labels; }
-#define RTA_MAX_SIZE (sizeof(rta) + sizeof(u32)*MPLS_MAX_LABEL_STACK)
+static inline size_t rta_size(const rta *a UNUSED) { return sizeof(rta); }
+#define RTA_MAX_SIZE sizeof(rta)
rta *rta_lookup(rta *); /* Get rta equivalent to this one, uc++ */
static inline int rta_is_cached(rta *r) { return r->cached; }
static inline rta *rta_clone(rta *r) { r->uc++; return r; }
diff --git a/nest/rt-attr.c b/nest/rt-attr.c
index 7beb119b..6149fe39 100644
--- a/nest/rt-attr.c
+++ b/nest/rt-attr.c
@@ -90,8 +90,8 @@ const char * rta_dest_names[RTD_MAX] = {
pool *rta_pool;
-static slab *rta_slab_[4];
-static slab *nexthop_slab_[4];
+static slab *rta_slab;
+static slab *nexthop_slab;
static slab *rte_src_slab;
static struct idm src_ids;
@@ -354,12 +354,6 @@ nexthop_is_sorted(struct nexthop *x)
return 1;
}
-static inline slab *
-nexthop_slab(struct nexthop *nh)
-{
- return nexthop_slab_[MIN(nh->labels, 3)];
-}
-
static struct nexthop *
nexthop_copy(struct nexthop *o)
{
@@ -368,7 +362,7 @@ nexthop_copy(struct nexthop *o)
for (; o; o = o->next)
{
- struct nexthop *n = sl_allocz(nexthop_slab(o));
+ struct nexthop *n = sl_allocz(nexthop_slab);
n->gw = o->gw;
n->iface = o->iface;
n->next = NULL;
@@ -1156,16 +1150,10 @@ rta_same(rta *x, rta *y)
ea_same(x->eattrs, y->eattrs));
}
-static inline slab *
-rta_slab(rta *a)
-{
- return rta_slab_[a->nh.labels > 2 ? 3 : a->nh.labels];
-}
-
static rta *
rta_copy(rta *o)
{
- rta *r = sl_alloc(rta_slab(o));
+ rta *r = sl_alloc(rta_slab);
memcpy(r, o, rta_size(o));
r->uc = 1;
@@ -1359,15 +1347,8 @@ rta_init(void)
{
rta_pool = rp_new(&root_pool, "Attributes");
- rta_slab_[0] = sl_new(rta_pool, sizeof(rta));
- rta_slab_[1] = sl_new(rta_pool, sizeof(rta) + sizeof(u32));
- rta_slab_[2] = sl_new(rta_pool, sizeof(rta) + sizeof(u32)*2);
- rta_slab_[3] = sl_new(rta_pool, sizeof(rta) + sizeof(u32)*MPLS_MAX_LABEL_STACK);
-
- nexthop_slab_[0] = sl_new(rta_pool, sizeof(struct nexthop));
- nexthop_slab_[1] = sl_new(rta_pool, sizeof(struct nexthop) + sizeof(u32));
- nexthop_slab_[2] = sl_new(rta_pool, sizeof(struct nexthop) + sizeof(u32)*2);
- nexthop_slab_[3] = sl_new(rta_pool, sizeof(struct nexthop) + sizeof(u32)*MPLS_MAX_LABEL_STACK);
+ rta_slab = sl_new(rta_pool, sizeof(rta));
+ nexthop_slab = sl_new(rta_pool, sizeof(struct nexthop));
rta_alloc_hash();
rte_src_init();