diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2023-04-20 15:44:46 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2023-04-20 15:44:46 +0000 |
commit | e224e66a7ccb48f1ef1c538d721410bd4a4a79d5 (patch) | |
tree | 3a69941cf24a4c07c07b334c67d5a2b03b125261 /usr.sbin/bgpd/rtr.c | |
parent | aeac220faecea6c85ac000a15af7c81123a150b5 (diff) |
Rework the way transit provider AID masks are built and sent to the RDE.
ASPA provider AS sets can include optional limitations to inet/inet6 these
limits are represented in the TAS_AID bit masks (2bits per AS).
Introduce a TAS_AID_SIZE() makro that returns the size in bytes of this
bit mask (rounded to the next uint32_t).
Without this change aspa objects with AID specific elements trigger a
fatal error condition when the config is loaded.
OK tb@ job@
Diffstat (limited to 'usr.sbin/bgpd/rtr.c')
-rw-r--r-- | usr.sbin/bgpd/rtr.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/usr.sbin/bgpd/rtr.c b/usr.sbin/bgpd/rtr.c index 2c3b18cc9c7..e30d0c4a7b9 100644 --- a/usr.sbin/bgpd/rtr.c +++ b/usr.sbin/bgpd/rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtr.c,v 1.13 2023/03/28 12:15:23 claudio Exp $ */ +/* $OpenBSD: rtr.c,v 1.14 2023/04/20 15:44:45 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker <claudio@openbsd.org> @@ -506,10 +506,15 @@ static size_t rtr_aspa_set_prep(struct aspa_set *aspa) { uint32_t i, mask = 0; + uint8_t *tas_aid; int needafi = 0; size_t s; s = aspa->num * sizeof(uint32_t); + + if ((tas_aid = malloc(TAS_AID_SIZE(aspa->num))) == NULL) + fatal("tas_aid alloc"); + for (i = 0; i < aspa->num; i++) { switch (aspa->tas_aid[i]) { case AID_INET: @@ -525,19 +530,23 @@ rtr_aspa_set_prep(struct aspa_set *aspa) break; } if (i % 16 == 15) { - memcpy(aspa->tas_aid + (i / 16) * sizeof(mask), &mask, + memcpy(tas_aid + (i / 16) * sizeof(mask), &mask, sizeof(mask)); mask = 0; } } + free(aspa->tas_aid); + aspa->tas_aid = NULL; + if (!needafi) { - free(aspa->tas_aid); - aspa->tas_aid = NULL; + free(tas_aid); } else { - memcpy(aspa->tas_aid + (aspa->num / 16) * sizeof(mask), &mask, - sizeof(mask)); - s += (aspa->num + 15) / 16; + if (aspa->num % 16 != 0) + memcpy(tas_aid + (aspa->num / 16) * sizeof(mask), + &mask, sizeof(mask)); + aspa->tas_aid = tas_aid; + s += TAS_AID_SIZE(aspa->num); } return s; @@ -596,8 +605,8 @@ rtr_recalc(void) imsg_compose(ibuf_rde, IMSG_RECONF_ASPA_TAS, 0, 0, -1, aspa->tas, aspa->num * sizeof(*aspa->tas)); if (aspa->tas_aid) - imsg_compose(ibuf_rde, IMSG_RECONF_ASPA_TAS, 0, 0, -1, - aspa->tas_aid, (aspa->num + 15) / 16); + imsg_compose(ibuf_rde, IMSG_RECONF_ASPA_TAS_AID, 0, 0, + -1, aspa->tas_aid, TAS_AID_SIZE(aspa->num)); imsg_compose(ibuf_rde, IMSG_RECONF_ASPA_DONE, 0, 0, -1, NULL, 0); } |