summaryrefslogtreecommitdiff
path: root/usr.sbin/bgpd
diff options
context:
space:
mode:
authorAlexander Bluhm <bluhm@cvs.openbsd.org>2021-04-15 13:42:34 +0000
committerAlexander Bluhm <bluhm@cvs.openbsd.org>2021-04-15 13:42:34 +0000
commitdfabd83e2d0aadb23719442097a23ccb20b10a9b (patch)
treeb11f0ac7a0a65a12f0ad66cedfd164d39bbab1dc /usr.sbin/bgpd
parentf7aa1e95ae8efc1ffe5bc1ab2b77bf9fb6149b5b (diff)
On powerpc64 regress/usr.sbin/bgpd/config failed. It parses a
config file, writes bgpd's config to stdout and compares it with an expected output. On big endian machines the order of the set of communities is different. The parser used memcmp(3) to sort a struct of integers. This depends of the endianess. The correct way is to compare the integer fields in native byte order. With this change, the resulting order is the same on i386 and powerpc64. OK claudio@
Diffstat (limited to 'usr.sbin/bgpd')
-rw-r--r--usr.sbin/bgpd/parse.y39
1 files changed, 31 insertions, 8 deletions
diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y
index 79f6c97cb71..c5d987a5ec1 100644
--- a/usr.sbin/bgpd/parse.y
+++ b/usr.sbin/bgpd/parse.y
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.y,v 1.414 2021/03/02 09:45:07 claudio Exp $ */
+/* $OpenBSD: parse.y,v 1.415 2021/04/15 13:42:33 bluhm Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -3558,6 +3558,28 @@ symget(const char *nam)
}
static int
+cmpcommunity(struct community *a, struct community *b)
+{
+ if (a->flags > b->flags)
+ return 1;
+ if (a->flags < b->flags)
+ return -1;
+ if (a->data1 > b->data1)
+ return 1;
+ if (a->data1 < b->data1)
+ return -1;
+ if (a->data2 > b->data2)
+ return 1;
+ if (a->data2 < b->data2)
+ return -1;
+ if (a->data3 > b->data3)
+ return 1;
+ if (a->data3 < b->data3)
+ return -1;
+ return 0;
+}
+
+static int
getcommunity(char *s, int large, u_int32_t *val, u_int32_t *flag)
{
long long max = USHRT_MAX;
@@ -4396,16 +4418,17 @@ filterset_add(struct filter_set_head *sh, struct filter_set *s)
switch (s->type) {
case ACTION_SET_COMMUNITY:
case ACTION_DEL_COMMUNITY:
- if (memcmp(&s->action.community,
- &t->action.community,
- sizeof(s->action.community)) < 0) {
+ switch (cmpcommunity(&s->action.community,
+ &t->action.community)) {
+ case -1:
TAILQ_INSERT_BEFORE(t, s, entry);
return;
- } else if (memcmp(&s->action.community,
- &t->action.community,
- sizeof(s->action.community)) == 0)
+ case 0:
break;
- continue;
+ case 1:
+ continue;
+ }
+ break;
case ACTION_SET_NEXTHOP:
/* only last nexthop per AF matters */
if (s->action.nexthop.aid <