-/* $OpenBSD: bgpd.h,v 1.474 2023/04/20 12:53:27 claudio Exp $ */
+/* $OpenBSD: bgpd.h,v 1.475 2023/04/20 15:44:45 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
uint8_t *tas_aid;
RB_ENTRY(aspa_set) entry;
};
+#define TAS_AID_SIZE(n) (((n) + 15) / 16 * sizeof(uint32_t))
struct aspa_prep {
size_t datasize;
-/* $OpenBSD: rde.c,v 1.604 2023/04/20 12:53:27 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.605 2023/04/20 15:44:45 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
if (aspa == NULL)
fatalx("unexpected IMSG_RECONF_ASPA_TAS");
if (imsg.hdr.len - IMSG_HEADER_SIZE !=
- aspa->num * sizeof(uint32_t))
+ aspa->num * sizeof(uint32_t))
fatalx("IMSG_RECONF_ASPA_TAS bad len");
aspa->tas = reallocarray(NULL, aspa->num,
sizeof(uint32_t));
if (aspa == NULL)
fatalx("unexpected IMSG_RECONF_ASPA_TAS_AID");
if (imsg.hdr.len - IMSG_HEADER_SIZE !=
- (aspa->num + 15) / 16)
+ TAS_AID_SIZE(aspa->num))
fatalx("IMSG_RECONF_ASPA_TAS_AID bad len");
- aspa->tas_aid = malloc((aspa->num + 15) / 16);
+ aspa->tas_aid = malloc(TAS_AID_SIZE(aspa->num));
if (aspa->tas_aid == NULL)
fatal("IMSG_RECONF_ASPA_TAS_AID");
- memcpy(aspa->tas_aid, imsg.data, (aspa->num + 15) / 16);
+ memcpy(aspa->tas_aid, imsg.data,
+ TAS_AID_SIZE(aspa->num));
break;
case IMSG_RECONF_ASPA_DONE:
if (aspa_new == NULL)
-/* $OpenBSD: rde_aspa.c,v 1.3 2023/01/24 11:28:41 claudio Exp $ */
+/* $OpenBSD: rde_aspa.c,v 1.4 2023/04/20 15:44:45 claudio Exp $ */
/*
* Copyright (c) 2022 Claudio Jeker <claudio@openbsd.org>
/* nobody in their right mind has per afi specific data */
if (pas_aid != NULL) {
/* 2 bits per entry rounded to next uint32_t */
- if (ra->maxdata - ra->curdata < (pascnt * 2 + 31) / 32)
+ if (ra->maxdata - ra->curdata <
+ TAS_AID_SIZE(pascnt) / sizeof(ra->data[0]))
fatalx("aspa set data overflow");
aspa->pas_aid = ra->data + ra->curdata;
- for (i = 0; i < (pascnt * 2 + 31) / 32; i++)
- ra->data[ra->curdata++] = pas_aid[i];
+ memcpy(aspa->pas_aid, pas_aid, TAS_AID_SIZE(pascnt));
+ ra->curdata += TAS_AID_SIZE(pascnt) / sizeof(ra->data[0]);
}
}
-/* $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>
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:
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;
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);
}