summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2017-01-24 23:38:13 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2017-01-24 23:38:13 +0000
commite080f3b49a8f2c7098c1cc17d85a2976c8829c78 (patch)
treec5270a60d748162e763d9f00fda5c0e1e283a7a2
parent96a69d3b71c71985b01a8ca718b96cb2bad1d6f8 (diff)
Save some space in struct rib_entry so it is back to 64bytes (on 64bit archs).
Doing this by folding the lock flag into a pointer and providing an accessor function for the rib pointer. This is an acceptable middle path for this important structure. OK benno@ on an earlier version
-rw-r--r--usr.sbin/bgpd/rde.c4
-rw-r--r--usr.sbin/bgpd/rde.h15
-rw-r--r--usr.sbin/bgpd/rde_decide.c10
-rw-r--r--usr.sbin/bgpd/rde_rib.c43
4 files changed, 48 insertions, 24 deletions
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index 02762aa8b0c..1c42fe2f557 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.358 2017/01/24 04:22:42 benno Exp $ */
+/* $OpenBSD: rde.c,v 1.359 2017/01/24 23:38:12 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -2870,7 +2870,7 @@ rde_up_dump_upcall(struct rib_entry *re, void *ptr)
{
struct rde_peer *peer = ptr;
- if (re->rib != &peer->rib->rib)
+ if (re_rib(re) != &peer->rib->rib)
fatalx("King Bula: monstrous evil horror.");
if (re->active == NULL)
return;
diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h
index 867f6b28370..d2228b6808a 100644
--- a/usr.sbin/bgpd/rde.h
+++ b/usr.sbin/bgpd/rde.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.h,v 1.157 2017/01/23 22:53:52 claudio Exp $ */
+/* $OpenBSD: rde.h,v 1.158 2017/01/24 23:38:12 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org> and
@@ -22,6 +22,7 @@
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/tree.h>
+#include <stdint.h>
#include "bgpd.h"
@@ -280,10 +281,9 @@ struct rib_context {
struct rib_entry {
RB_ENTRY(rib_entry) rib_e;
struct prefix_head prefix_h;
- struct prefix *active; /* for fast access */
+ struct prefix *active; /* for fast access */
struct pt_entry *prefix;
- struct rib *rib;
- u_int16_t flags;
+ struct rib *__rib; /* mangled pointer with flags */
};
struct rib {
@@ -438,6 +438,13 @@ void rib_dump_r(struct rib_context *);
void rib_dump_runner(void);
int rib_dump_pending(void);
+static inline struct rib *
+re_rib(struct rib_entry *re)
+{
+ return (struct rib *)((intptr_t)re->__rib & ~1);
+}
+
+void path_init(u_int32_t);
void path_init(u_int32_t);
void path_shutdown(void);
int path_update(struct rib *, struct rde_peer *,
diff --git a/usr.sbin/bgpd/rde_decide.c b/usr.sbin/bgpd/rde_decide.c
index 5e23b62a560..84d11c55c92 100644
--- a/usr.sbin/bgpd/rde_decide.c
+++ b/usr.sbin/bgpd/rde_decide.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_decide.c,v 1.64 2017/01/24 04:22:42 benno Exp $ */
+/* $OpenBSD: rde_decide.c,v 1.65 2017/01/24 23:38:12 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -244,7 +244,7 @@ prefix_evaluate(struct prefix *p, struct rib_entry *re)
{
struct prefix *xp;
- if (re->flags & F_RIB_NOEVALUATE || rde_noevaluate()) {
+ if (re_rib(re)->flags & F_RIB_NOEVALUATE || rde_noevaluate()) {
/* decision process is turned off */
if (p != NULL)
LIST_INSERT_HEAD(&re->prefix_h, p, rib_l);
@@ -288,9 +288,9 @@ prefix_evaluate(struct prefix *p, struct rib_entry *re)
* but remember that xp may be NULL aka ineligible.
* Additional decision may be made by the called functions.
*/
- rde_generate_updates(re->rib->id, xp, re->active);
- if ((re->flags & F_RIB_NOFIB) == 0)
- rde_send_kroute(xp, re->active, re->rib->id);
+ rde_generate_updates(re_rib(re)->id, xp, re->active);
+ if ((re_rib(re)->flags & F_RIB_NOFIB) == 0)
+ rde_send_kroute(xp, re->active, re_rib(re)->id);
re->active = xp;
if (xp != NULL)
diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c
index 7f716a1a2e4..54d3dfde91d 100644
--- a/usr.sbin/bgpd/rde_rib.c
+++ b/usr.sbin/bgpd/rde_rib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_rib.c,v 1.150 2017/01/24 04:22:42 benno Exp $ */
+/* $OpenBSD: rde_rib.c,v 1.151 2017/01/24 23:38:12 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -49,6 +49,24 @@ struct rib_entry *rib_restart(struct rib_context *);
RB_PROTOTYPE(rib_tree, rib_entry, rib_e, rib_compare);
RB_GENERATE(rib_tree, rib_entry, rib_e, rib_compare);
+static inline void
+re_lock(struct rib_entry *re)
+{
+ re->__rib = (struct rib *)((intptr_t)re->__rib | 1);
+}
+
+static inline void
+re_unlock(struct rib_entry *re)
+{
+ re->__rib = (struct rib *)((intptr_t)re->__rib & ~1);
+}
+
+static inline int
+re_is_locked(struct rib_entry *re)
+{
+ return ((intptr_t)re->__rib & 1);
+}
+
static inline struct rib_tree *
rib_tree(struct rib *rib)
{
@@ -121,7 +139,7 @@ rib_free(struct rib_desc *rib)
next = LIST_NEXT(ctx, entry);
if (ctx->ctx_rib == &rib->rib) {
re = ctx->ctx_re;
- re->flags &= ~F_RIB_ENTRYLOCK;
+ re_unlock(re);
LIST_REMOVE(ctx, entry);
if (ctx->ctx_done)
ctx->ctx_done(ctx->ctx_arg);
@@ -222,8 +240,7 @@ rib_add(struct rib *rib, struct bgpd_addr *prefix, int prefixlen)
LIST_INIT(&re->prefix_h);
re->prefix = pte;
- re->rib = rib;
- re->flags = rib->flags;
+ re->__rib = rib;
if (RB_INSERT(rib_tree, rib_tree(rib), re) != NULL) {
log_warnx("rib_add: insert failed");
@@ -244,7 +261,7 @@ rib_remove(struct rib_entry *re)
if (!rib_empty(re))
fatalx("rib_remove: entry not empty");
- if (re->flags & F_RIB_ENTRYLOCK)
+ if (re_is_locked(re))
/* entry is locked, don't free it. */
return;
@@ -252,7 +269,7 @@ rib_remove(struct rib_entry *re)
if (pt_empty(re->prefix))
pt_remove(re->prefix);
- if (RB_REMOVE(rib_tree, rib_tree(re->rib), re) == NULL)
+ if (RB_REMOVE(rib_tree, rib_tree(re_rib(re)), re) == NULL)
log_warnx("rib_remove: remove failed.");
free(re);
@@ -297,10 +314,10 @@ rib_dump_r(struct rib_context *ctx)
ctx->ctx_aid != re->prefix->aid)
continue;
if (ctx->ctx_count && i++ >= ctx->ctx_count &&
- (re->flags & F_RIB_ENTRYLOCK) == 0) {
+ re_is_locked(re)) {
/* store and lock last element */
ctx->ctx_re = re;
- re->flags |= F_RIB_ENTRYLOCK;
+ re_lock(re);
return;
}
ctx->ctx_upcall(re, ctx->ctx_arg);
@@ -319,7 +336,7 @@ rib_restart(struct rib_context *ctx)
struct rib_entry *re;
re = ctx->ctx_re;
- re->flags &= ~F_RIB_ENTRYLOCK;
+ re_unlock(re);
/* find first non empty element */
while (re && rib_empty(re))
@@ -548,7 +565,7 @@ path_remove_stale(struct rde_aspath *asp, u_int8_t aid)
}
/* only count Adj-RIB-In */
- if (p->re->rib == &ribs[0].rib)
+ if (re_rib(p->re) == &ribs[0].rib)
rprefixes++;
prefix_destroy(p);
@@ -905,7 +922,7 @@ prefix_updateall(struct rde_aspath *asp, enum nexthop_state state,
/*
* skip non local-RIBs or RIBs that are flagged as noeval.
*/
- if (p->re->rib->flags & F_RIB_NOEVALUATE)
+ if (re_rib(p->re)->flags & F_RIB_NOEVALUATE)
continue;
if (oldstate == state && state == NEXTHOP_REACH) {
@@ -915,9 +932,9 @@ prefix_updateall(struct rde_aspath *asp, enum nexthop_state state,
* or other internal infos. This will not change
* the routing decision so shortcut here.
*/
- if ((p->re->rib->flags & F_RIB_NOFIB) == 0 &&
+ if ((re_rib(p->re)->flags & F_RIB_NOFIB) == 0 &&
p == p->re->active)
- rde_send_kroute(p, NULL, p->re->rib->id);
+ rde_send_kroute(p, NULL, re_rib(p->re)->id);
continue;
}