summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2020-01-09 11:55:26 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2020-01-09 11:55:26 +0000
commit0b25131f248b04d0ff3ff7ae4c3f2b3a67486d0f (patch)
tree2cd5dd52c3d9569ff27f48234a39293af11a9b93 /usr.sbin/bgpd
parent6cdd3aac731e58d47a474b7343f2a2ed12bf6037 (diff)
Convert the lastchange of a prefix from time(NULL) to getmonotime() which
uses CLOCK_MONOTONIC. Convert the control messages to return the relative age of the prefix instead of the absolute age. Adjust the mrt dump code to stil dump the route age in seconds since epoch as defined in the RFC. With this all times in bgpd are now based on CLOCK_MONOTONIC. OK denis@
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r--usr.sbin/bgpd/bgpd.h4
-rw-r--r--usr.sbin/bgpd/mrt.c11
-rw-r--r--usr.sbin/bgpd/rde.c8
-rw-r--r--usr.sbin/bgpd/rde_rib.c16
4 files changed, 21 insertions, 18 deletions
diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h
index dd22a322af8..6a400d1d312 100644
--- a/usr.sbin/bgpd/bgpd.h
+++ b/usr.sbin/bgpd/bgpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bgpd.h,v 1.396 2020/01/09 11:51:18 claudio Exp $ */
+/* $OpenBSD: bgpd.h,v 1.397 2020/01/09 11:55:25 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -711,7 +711,7 @@ struct ctl_show_rib {
struct bgpd_addr prefix;
struct bgpd_addr remote_addr;
char descr[PEER_DESCR_LEN];
- time_t lastchange;
+ time_t age;
u_int32_t remote_id;
u_int32_t local_pref;
u_int32_t med;
diff --git a/usr.sbin/bgpd/mrt.c b/usr.sbin/bgpd/mrt.c
index d9ab0deff10..c7c39ba7e4f 100644
--- a/usr.sbin/bgpd/mrt.c
+++ b/usr.sbin/bgpd/mrt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mrt.c,v 1.102 2020/01/08 18:01:22 deraadt Exp $ */
+/* $OpenBSD: mrt.c,v 1.103 2020/01/09 11:55:25 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -323,7 +323,8 @@ mrt_dump_entry_mp(struct mrt *mrt, struct prefix *p, u_int16_t snum,
DUMP_SHORT(h2buf, 0); /* view */
DUMP_SHORT(h2buf, 1); /* status */
- DUMP_LONG(h2buf, p->lastchange); /* originated */
+ /* originated timestamp */
+ DUMP_LONG(h2buf, time(NULL) - (getmonotime() - p->lastchange));
pt_getaddr(p->pt, &addr);
@@ -459,7 +460,8 @@ mrt_dump_entry(struct mrt *mrt, struct prefix *p, u_int16_t snum,
DUMP_BYTE(hbuf, p->pt->prefixlen);
DUMP_BYTE(hbuf, 1); /* state */
- DUMP_LONG(hbuf, p->lastchange); /* originated */
+ /* originated timestamp */
+ DUMP_LONG(hbuf, time(NULL) - (getmonotime() - p->lastchange));
switch (p->pt->aid) {
case AID_INET:
DUMP_NLONG(hbuf, peer->remote_addr.v4.s_addr);
@@ -547,7 +549,8 @@ mrt_dump_entry_v2(struct mrt *mrt, struct rib_entry *re, u_int32_t snum)
nh = &nexthop->exit_nexthop;
DUMP_SHORT(buf, prefix_peer(p)->mrt_idx);
- DUMP_LONG(buf, p->lastchange); /* originated */
+ /* originated timestamp */
+ DUMP_LONG(buf, time(NULL) - (getmonotime() - p->lastchange));
if ((tbuf = ibuf_dynamic(0, MAX_PKTSIZE)) == NULL) {
log_warn("%s: ibuf_dynamic", __func__);
diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c
index 83e0d1ed320..08eb50f7986 100644
--- a/usr.sbin/bgpd/rde.c
+++ b/usr.sbin/bgpd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.496 2020/01/08 18:01:22 deraadt Exp $ */
+/* $OpenBSD: rde.c,v 1.497 2020/01/09 11:55:25 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -2204,7 +2204,7 @@ rde_dump_rib_as(struct prefix *p, struct rde_aspath *asp, pid_t pid, int flags)
nexthop = prefix_nexthop(p);
bzero(&rib, sizeof(rib));
- rib.lastchange = p->lastchange;
+ rib.age = getmonotime() - p->lastchange;
rib.local_pref = asp->lpref;
rib.med = asp->med;
rib.weight = asp->weight;
@@ -3883,7 +3883,7 @@ peer_stale(struct rde_peer *peer, u_int8_t aid)
if (peer->staletime[aid])
peer_flush(peer, aid, peer->staletime[aid]);
- peer->staletime[aid] = now = time(NULL);
+ peer->staletime[aid] = now = getmonotime();
peer->state = PEER_DOWN;
/* mark Adj-RIB-Out stale for this peer */
@@ -3892,7 +3892,7 @@ peer_stale(struct rde_peer *peer, u_int8_t aid)
fatal("%s: prefix_dump_new", __func__);
/* make sure new prefixes start on a higher timestamp */
- while (now >= time(NULL))
+ while (now >= getmonotime())
sleep(1);
}
diff --git a/usr.sbin/bgpd/rde_rib.c b/usr.sbin/bgpd/rde_rib.c
index 01a86445ebc..116e55cb531 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.211 2020/01/08 18:01:22 deraadt Exp $ */
+/* $OpenBSD: rde_rib.c,v 1.212 2020/01/09 11:55:25 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Claudio Jeker <claudio@openbsd.org>
@@ -983,7 +983,7 @@ prefix_update(struct rib *rib, struct rde_peer *peer, struct filterstate *state,
communities_equal(ncomm, prefix_communities(p)) &&
path_compare(nasp, prefix_aspath(p)) == 0) {
/* no change, update last change */
- p->lastchange = time(NULL);
+ p->lastchange = getmonotime();
p->validation_state = vstate;
return (0);
}
@@ -1058,7 +1058,7 @@ prefix_move(struct prefix *p, struct rde_peer *peer,
np->nhflags = nhflags;
np->nexthop = nexthop_ref(nexthop);
nexthop_link(np);
- np->lastchange = time(NULL);
+ np->lastchange = getmonotime();
/*
* no need to update the peer prefix count because we are only moving
@@ -1168,7 +1168,7 @@ prefix_adjout_update(struct rde_peer *peer, struct filterstate *state,
0) {
/* nothing changed */
p->validation_state = vstate;
- p->lastchange = time(NULL);
+ p->lastchange = getmonotime();
p->flags &= ~PREFIX_FLAG_STALE;
return 0;
}
@@ -1217,7 +1217,7 @@ prefix_adjout_update(struct rde_peer *peer, struct filterstate *state,
p->nhflags = state->nhflags;
p->validation_state = vstate;
- p->lastchange = time(NULL);
+ p->lastchange = getmonotime();
if (p->flags & PREFIX_FLAG_MASK)
fatalx("%s: bad flags %x", __func__, p->flags);
@@ -1244,7 +1244,7 @@ prefix_adjout_withdraw(struct rde_peer *peer, struct bgpd_addr *prefix,
/* already a withdraw, shortcut */
if (p->flags & PREFIX_FLAG_WITHDRAW) {
- p->lastchange = time(NULL);
+ p->lastchange = getmonotime();
p->flags &= ~PREFIX_FLAG_STALE;
return (0);
}
@@ -1271,7 +1271,7 @@ prefix_adjout_withdraw(struct rde_peer *peer, struct bgpd_addr *prefix,
p->aspath = NULL;
/* re already NULL */
- p->lastchange = time(NULL);
+ p->lastchange = getmonotime();
p->flags |= PREFIX_FLAG_WITHDRAW;
if (RB_INSERT(prefix_tree, &peer->withdraws[prefix->aid], p) != NULL)
@@ -1599,7 +1599,7 @@ prefix_link(struct prefix *p, struct rib_entry *re, struct rde_peer *peer,
p->nhflags = nhflags;
p->nexthop = nexthop_ref(nexthop);
nexthop_link(p);
- p->lastchange = time(NULL);
+ p->lastchange = getmonotime();
/* make route decision */
prefix_evaluate(p, re);