summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd/parse.y
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2019-05-27 09:14:34 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2019-05-27 09:14:34 +0000
commite3468b0834bb31e24dcbdf6d3fe61f45f9d1a6ae (patch)
tree531435843aeab483c39915f461f1b06354a6a2b1 /usr.sbin/bgpd/parse.y
parent2de2395c821f9fc4e23012d8dec687e3b8cd945c (diff)
Switch the peer TAILQ to a RB tree indexed by the peer id. This way
getpeerbyid() gets a lot quicker at finding the peer when many peers are configured. In my test case the difference is around 20% runtime. OK denis@
Diffstat (limited to 'usr.sbin/bgpd/parse.y')
-rw-r--r--usr.sbin/bgpd/parse.y13
1 files changed, 7 insertions, 6 deletions
diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y
index 3447519cd0c..c7321d139c4 100644
--- a/usr.sbin/bgpd/parse.y
+++ b/usr.sbin/bgpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.387 2019/05/03 15:08:47 claudio Exp $ */
+/* $OpenBSD: parse.y,v 1.388 2019/05/27 09:14:32 claudio Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -1208,7 +1208,8 @@ neighbor : { curpeer = new_peer(); }
if (neighbor_consistent(curpeer) == -1)
YYERROR;
- TAILQ_INSERT_TAIL(new_peers, curpeer, entry);
+ if (RB_INSERT(peer_head, new_peers, curpeer) != NULL)
+ fatalx("%s: peer tree is corrupt", __func__);
curpeer = curgroup;
}
;
@@ -1816,7 +1817,7 @@ filter_peer : ANY {
fatal(NULL);
$$->p.remote_as = $$->p.groupid = $$->p.peerid = 0;
$$->next = NULL;
- TAILQ_FOREACH(p, new_peers, entry)
+ RB_FOREACH(p, peer_head, new_peers)
if (!memcmp(&p->conf.remote_addr,
&$1, sizeof(p->conf.remote_addr))) {
$$->p.peerid = p->conf.id;
@@ -1843,7 +1844,7 @@ filter_peer : ANY {
fatal(NULL);
$$->p.remote_as = $$->p.peerid = 0;
$$->next = NULL;
- TAILQ_FOREACH(p, new_peers, entry)
+ RB_FOREACH(p, peer_head, new_peers)
if (!strcmp(p->conf.group, $2)) {
$$->p.groupid = p->conf.groupid;
break;
@@ -3965,7 +3966,7 @@ get_id(struct peer *newpeer)
if (newpeer->conf.remote_addr.aid) {
/* neighbor */
if (cur_peers)
- TAILQ_FOREACH(p, cur_peers, entry)
+ RB_FOREACH(p, peer_head, cur_peers)
if (memcmp(&p->conf.remote_addr,
&newpeer->conf.remote_addr,
sizeof(p->conf.remote_addr)) == 0)
@@ -3977,7 +3978,7 @@ get_id(struct peer *newpeer)
} else {
/* group */
if (cur_peers)
- TAILQ_FOREACH(p, cur_peers, entry)
+ RB_FOREACH(p, peer_head, cur_peers)
if (strcmp(p->conf.group,
newpeer->conf.group) == 0)
break;