From: claudio Date: Wed, 16 Aug 2023 08:26:35 +0000 (+0000) Subject: Remove per-AFI ASPA handling in bgpd internals X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c0c9c1699ab597a4cc652cacfa4e92e3c4aa6e20;p=openbsd Remove per-AFI ASPA handling in bgpd internals With draft-ietf-sidrops-aspa-profile-16 and draft-ietf-sidrops-aspa-verification-15 the AFI dependence of ASPA records was dropped. So remove this complication form the code. This only removes the AFI handling internally in bgpd but still allows the old syntax in aspa-set tables. The optional address family is just ignored and records are merged together. For RTR sessions draft-ietf-sidrops-8210bis has not yet been updated so right now we still handle RTR sessions as specified there. The IPv4 and IPv6 ASPA entries are handled in two trees and merged together into one AFI independent tree. This is the best we can do for now until IETF updates draft-ietf-sidrops-8210bis. OK tb@ job@ --- diff --git a/usr.sbin/bgpd/bgpd.c b/usr.sbin/bgpd/bgpd.c index 1d72bd8a235..1131e152bb5 100644 --- a/usr.sbin/bgpd/bgpd.c +++ b/usr.sbin/bgpd/bgpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.c,v 1.258 2023/04/19 07:12:22 claudio Exp $ */ +/* $OpenBSD: bgpd.c,v 1.259 2023/08/16 08:26:35 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -722,9 +722,6 @@ send_config(struct bgpd_config *conf) if (imsg_compose(ibuf_rtr, IMSG_RECONF_ASPA_TAS, 0, 0, -1, aspa->tas, sizeof(*aspa->tas) * aspa->num) == -1) return (-1); - if (imsg_compose(ibuf_rtr, IMSG_RECONF_ASPA_TAS_AID, - 0, 0, -1, aspa->tas_aid, aspa->num) == -1) - return (-1); if (imsg_compose(ibuf_rtr, IMSG_RECONF_ASPA_DONE, 0, 0, -1, NULL, 0) == -1) return -1; diff --git a/usr.sbin/bgpd/bgpd.h b/usr.sbin/bgpd/bgpd.h index 181746b7ac1..985ab7915c5 100644 --- a/usr.sbin/bgpd/bgpd.h +++ b/usr.sbin/bgpd/bgpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpd.h,v 1.475 2023/04/20 15:44:45 claudio Exp $ */ +/* $OpenBSD: bgpd.h,v 1.476 2023/08/16 08:26:35 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -642,7 +642,6 @@ enum imsg_type { IMSG_RECONF_ROA_ITEM, IMSG_RECONF_ASPA, IMSG_RECONF_ASPA_TAS, - IMSG_RECONF_ASPA_TAS_AID, IMSG_RECONF_ASPA_DONE, IMSG_RECONF_ASPA_PREP, IMSG_RECONF_RTR_CONFIG, @@ -1270,10 +1269,8 @@ struct aspa_set { uint32_t as; uint32_t num; uint32_t *tas; - 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; diff --git a/usr.sbin/bgpd/config.c b/usr.sbin/bgpd/config.c index 00f2379df73..057dc863457 100644 --- a/usr.sbin/bgpd/config.c +++ b/usr.sbin/bgpd/config.c @@ -1,4 +1,4 @@ -/* $OpenBSD: config.c,v 1.107 2023/04/18 12:11:27 claudio Exp $ */ +/* $OpenBSD: config.c,v 1.108 2023/08/16 08:26:35 claudio Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer @@ -224,7 +224,6 @@ free_aspa(struct aspa_set *aspa) if (aspa == NULL) return; free(aspa->tas); - free(aspa->tas_aid); free(aspa); } diff --git a/usr.sbin/bgpd/parse.y b/usr.sbin/bgpd/parse.y index b6a182040c1..235eedf3089 100644 --- a/usr.sbin/bgpd/parse.y +++ b/usr.sbin/bgpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.454 2023/04/28 13:23:52 claudio Exp $ */ +/* $OpenBSD: parse.y,v 1.455 2023/08/16 08:26:35 claudio Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer @@ -134,7 +134,6 @@ struct aspa_tas_l { struct aspa_tas_l *next; uint32_t as; uint32_t num; - uint8_t aid; }; struct flowspec_context { @@ -667,14 +666,12 @@ aspa_tas : as4number_any { if (($$ = calloc(1, sizeof(*$$))) == NULL) fatal(NULL); $$->as = $1; - $$->aid = AID_UNSPEC; $$->num = 1; } | as4number_any af { if (($$ = calloc(1, sizeof(*$$))) == NULL) fatal(NULL); $$->as = $1; - $$->aid = $2; $$->num = 1; } ; @@ -5448,7 +5445,6 @@ merge_aspa_set(uint32_t as, struct aspa_tas_l *tas, time_t expires) { struct aspa_set *aspa, needle = { .as = as }; uint32_t i, num, *newtas; - uint8_t *newtasaid = NULL; aspa = RB_FIND(aspa_tree, &conf->aspa, &needle); if (aspa == NULL) { @@ -5471,25 +5467,14 @@ merge_aspa_set(uint32_t as, struct aspa_tas_l *tas, time_t expires) yyerror("out of memory"); return -1; } - newtasaid = recallocarray(aspa->tas_aid, aspa->num, num, 1); - if (newtasaid == NULL) { - free(newtas); - yyerror("out of memory"); - return -1; - } - /* fill starting at the end since the tas list is reversed */ if (num > 0) { - for (i = num - 1; tas; tas = tas->next, i--) { + for (i = num - 1; tas; tas = tas->next, i--) newtas[i] = tas->as; - if (tas->aid != AID_UNSPEC) - newtasaid[i] = tas->aid; - } } aspa->num = num; aspa->tas = newtas; - aspa->tas_aid = newtasaid; /* take the longest expiry time, same logic as for ROA entries */ if (aspa->expires != 0 && expires != 0 && expires > aspa->expires) aspa->expires = expires; diff --git a/usr.sbin/bgpd/printconf.c b/usr.sbin/bgpd/printconf.c index 32be9d82042..57dc8aeb02f 100644 --- a/usr.sbin/bgpd/printconf.c +++ b/usr.sbin/bgpd/printconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: printconf.c,v 1.167 2023/04/28 13:23:52 claudio Exp $ */ +/* $OpenBSD: printconf.c,v 1.168 2023/08/16 08:26:35 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -723,11 +723,8 @@ print_aspa(struct aspa_tree *a) if (aspa->expires != 0) printf(" expires %lld", (long long)aspa->expires); printf(" provider-as { "); - for (i = 0; i < aspa->num; i++) { + for (i = 0; i < aspa->num; i++) printf("%s ", log_as(aspa->tas[i])); - if (aspa->tas_aid[i] != AID_UNSPEC) - printf("%s ", print_af(aspa->tas_aid[i])); - } printf("}"); } printf("\n}\n\n"); diff --git a/usr.sbin/bgpd/rde.c b/usr.sbin/bgpd/rde.c index b575e9398e4..dc6a318f747 100644 --- a/usr.sbin/bgpd/rde.c +++ b/usr.sbin/bgpd/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.609 2023/08/04 09:20:12 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.610 2023/08/16 08:26:35 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -1319,23 +1319,11 @@ rde_dispatch_imsg_rtr(struct imsgbuf *ibuf) memcpy(aspa->tas, imsg.data, aspa->num * sizeof(uint32_t)); break; - case IMSG_RECONF_ASPA_TAS_AID: - if (aspa == NULL) - fatalx("unexpected IMSG_RECONF_ASPA_TAS_AID"); - if (imsg.hdr.len - IMSG_HEADER_SIZE != - TAS_AID_SIZE(aspa->num)) - fatalx("IMSG_RECONF_ASPA_TAS_AID bad len"); - 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, - TAS_AID_SIZE(aspa->num)); - break; case IMSG_RECONF_ASPA_DONE: if (aspa_new == NULL) fatalx("unexpected IMSG_RECONF_ASPA"); aspa_add_set(aspa_new, aspa->as, aspa->tas, - aspa->num, (void *)aspa->tas_aid); + aspa->num); free_aspa(aspa); aspa = NULL; break; @@ -2729,20 +2717,10 @@ rde_aspa_validity(struct rde_peer *peer, struct rde_aspath *asp, uint8_t aid) if (peer->role == ROLE_NONE) return ASPA_UNKNOWN; - switch (aid) { - case AID_INET: - if (peer->role == ROLE_CUSTOMER) - return asp->aspa_state.downup_v4; - else - return asp->aspa_state.onlyup_v4; - case AID_INET6: - if (peer->role == ROLE_CUSTOMER) - return asp->aspa_state.downup_v6; - else - return asp->aspa_state.onlyup_v6; - default: - return ASPA_NEVER_KNOWN; /* not reachable */ - } + if (peer->role == ROLE_CUSTOMER) + return asp->aspa_state.downup; + else + return asp->aspa_state.onlyup; } /* diff --git a/usr.sbin/bgpd/rde.h b/usr.sbin/bgpd/rde.h index d2e8850776d..c700aca75a3 100644 --- a/usr.sbin/bgpd/rde.h +++ b/usr.sbin/bgpd/rde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.h,v 1.295 2023/07/12 14:45:43 claudio Exp $ */ +/* $OpenBSD: rde.h,v 1.296 2023/08/16 08:26:35 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Claudio Jeker and @@ -108,10 +108,8 @@ struct rde_peer { struct rde_aspa; struct rde_aspa_state { - uint8_t onlyup_v4; - uint8_t downup_v4; - uint8_t onlyup_v6; - uint8_t downup_v6; + uint8_t onlyup; + uint8_t downup; }; #define AS_SET 1 @@ -714,7 +712,7 @@ void aspa_validation(struct rde_aspa *, struct aspath *, struct rde_aspa_state *); struct rde_aspa *aspa_table_prep(uint32_t, size_t); void aspa_add_set(struct rde_aspa *, uint32_t, const uint32_t *, - uint32_t, const uint32_t *); + uint32_t); void aspa_table_free(struct rde_aspa *); void aspa_table_stats(const struct rde_aspa *, struct ctl_show_set *); diff --git a/usr.sbin/bgpd/rde_aspa.c b/usr.sbin/bgpd/rde_aspa.c index da1746adfe4..233b97d9481 100644 --- a/usr.sbin/bgpd/rde_aspa.c +++ b/usr.sbin/bgpd/rde_aspa.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_aspa.c,v 1.4 2023/04/20 15:44:45 claudio Exp $ */ +/* $OpenBSD: rde_aspa.c,v 1.5 2023/08/16 08:26:35 claudio Exp $ */ /* * Copyright (c) 2022 Claudio Jeker @@ -23,18 +23,16 @@ #include "bgpd.h" #include "rde.h" -#define UNKNOWN 0x0 -#define NOT_PROVIDER 0x1 -#define PROVIDER 0x2 - -#define CP(x, y) (x | (y << 4)) -#define CP_GET(x, i) ((x >> (i * 4)) & 0xf) +enum cp_state { + UNKNOWN, + NOT_PROVIDER, + PROVIDER, +}; struct rde_aspa_set { uint32_t as; uint32_t num; uint32_t *pas; - uint32_t *pas_aid; int next; }; @@ -110,11 +108,9 @@ aspa_lookup(struct rde_aspa *ra, uint32_t asnum) * Returns UNKNOWN if cas is not in the ra table or the aid is out of range. * Returns PROVIDER if pas is registered for cas for the specified aid. * Retruns NOT_PROVIDER otherwise. - * The returned value includes the result for both IPv4 and IPv6 and needs - * to be looked at with CP_GET. * This function is called very frequently and needs to be fast. */ -static uint8_t +static enum cp_state aspa_cp_lookup(struct rde_aspa *ra, uint32_t cas, uint32_t pas) { struct rde_aspa_set *aspa; @@ -122,17 +118,17 @@ aspa_cp_lookup(struct rde_aspa *ra, uint32_t cas, uint32_t pas) aspa = aspa_lookup(ra, cas); if (aspa == NULL) - return CP(UNKNOWN, UNKNOWN); + return UNKNOWN; if (aspa->num < 16) { for (i = 0; i < aspa->num; i++) { if (aspa->pas[i] == pas) break; if (aspa->pas[i] > pas) - return CP(NOT_PROVIDER, NOT_PROVIDER); + return NOT_PROVIDER; } if (i == aspa->num) - return CP(NOT_PROVIDER, NOT_PROVIDER); + return NOT_PROVIDER; } else { uint32_t lim, x; for (i = 0, lim = aspa->num; lim != 0; lim /= 2) { @@ -150,21 +146,10 @@ aspa_cp_lookup(struct rde_aspa *ra, uint32_t cas, uint32_t pas) } } if (lim == 0) - return CP(NOT_PROVIDER, NOT_PROVIDER); + return NOT_PROVIDER; } - if (aspa->pas_aid == NULL) - return CP(PROVIDER, PROVIDER); - switch (aspa->pas_aid[i / 16] >> ((i % 16) * 2) & 0x3) { - case 0x1: - return CP(PROVIDER, NOT_PROVIDER); - case 0x2: - return CP(NOT_PROVIDER, PROVIDER); - case 0x3: - return CP(PROVIDER, PROVIDER); - default: - fatalx("impossible state in aspa_cp_lookup"); - } + return PROVIDER; } /* @@ -184,14 +169,12 @@ static int aspa_check_aspath(struct rde_aspa *ra, struct aspath *a, struct aspa_state *s) { uint8_t *seg; - int afi; uint32_t as, prevas = 0; uint16_t len, seg_size; - uint8_t i, r, seg_type, seg_len; + uint8_t i, seg_type, seg_len; /* the neighbor-as itself is by definition valid */ - s[0].ndown_p = 1; - s[1].ndown_p = 1; + s->ndown_p = 1; /* * Walk aspath and validate if necessary both up- and down-ramp. @@ -213,8 +196,7 @@ aspa_check_aspath(struct rde_aspa *ra, struct aspath *a, struct aspa_state *s) if (as == prevas) continue; /* skip prepends */ - s[0].nhops++; - s[1].nhops++; + s->nhops++; if (prevas == 0) { prevas = as; /* skip left-most AS */ continue; @@ -226,22 +208,19 @@ aspa_check_aspath(struct rde_aspa *ra, struct aspath *a, struct aspa_state *s) * node and the right-most provider node * for which all nodes before are valid. */ - r = aspa_cp_lookup(ra, prevas, as); - for (afi = 0; afi < 2; afi++) { - switch (CP_GET(r, afi)) { - case UNKNOWN: - if (s[afi].ndown_u == 0) - s[afi].ndown_u = s[afi].nhops; - break; - case PROVIDER: - if (s[afi].ndown_p + 1 == s[afi].nhops) - s[afi].ndown_p = s[afi].nhops; - break; - case NOT_PROVIDER: - if (s[afi].ndown_np == 0) - s[afi].ndown_np = s[afi].nhops; - break; - } + switch (aspa_cp_lookup(ra, prevas, as)) { + case UNKNOWN: + if (s->ndown_u == 0) + s->ndown_u = s->nhops; + break; + case PROVIDER: + if (s->ndown_p + 1 == s->nhops) + s->ndown_p = s->nhops; + break; + case NOT_PROVIDER: + if (s->ndown_np == 0) + s->ndown_np = s->nhops; + break; } /* @@ -252,32 +231,27 @@ aspa_check_aspath(struct rde_aspa *ra, struct aspath *a, struct aspa_state *s) * We recorde the nhops value of prevas, * that's why the use of nhops - 1. */ - r = aspa_cp_lookup(ra, as, prevas); - for (afi = 0; afi < 2; afi++) { - switch (CP_GET(r, afi)) { - case UNKNOWN: - s[afi].nup_p = 0; - s[afi].nup_u = s[afi].nhops - 1; - break; - case PROVIDER: - if (s[afi].nup_p == 0) - s[afi].nup_p = s[afi].nhops - 1; - break; - case NOT_PROVIDER: - s[afi].nup_p = 0; - s[afi].nup_np = s[afi].nhops - 1; - break; - } + switch (aspa_cp_lookup(ra, as, prevas)) { + case UNKNOWN: + s->nup_p = 0; + s->nup_u = s->nhops - 1; + break; + case PROVIDER: + if (s->nup_p == 0) + s->nup_p = s->nhops - 1; + break; + case NOT_PROVIDER: + s->nup_p = 0; + s->nup_np = s->nhops - 1; + break; } prevas = as; } } /* the source-as itself is by definition valid */ - if (s[0].nup_p == 0) - s[0].nup_p = s[0].nhops; - if (s[1].nup_p == 0) - s[1].nup_p = s[1].nhops; + if (s->nup_p == 0) + s->nup_p = s->nhops; return 0; } @@ -324,34 +298,33 @@ aspa_check_finalize(struct aspa_state *state, uint8_t *onlyup, uint8_t *downup) /* * Validate an aspath against the aspa_set *ra. * Returns ASPA_VALID if the aspath is valid, ASPA_UNKNOWN if the - * aspath contains hops with unknown relation and invalid for + * aspath contains hops with unknown relation and ASPA_INVALID for * empty aspaths, aspath with AS_SET and aspaths that fail validation. */ void aspa_validation(struct rde_aspa *ra, struct aspath *a, struct rde_aspa_state *vstate) { - struct aspa_state state[2] = { 0 }; + struct aspa_state state = { 0 }; /* no aspa table, evrything is unknown */ if (ra == NULL) { - memset(vstate, ASPA_UNKNOWN, 4); + memset(vstate, ASPA_UNKNOWN, sizeof(*vstate)); return; } /* empty ASPATHs are always invalid */ if (aspath_length(a) == 0) { - memset(vstate, ASPA_INVALID, 4); + memset(vstate, ASPA_INVALID, sizeof(*vstate)); return; } - if (aspa_check_aspath(ra, a, state) == -1) { - memset(vstate, ASPA_INVALID, 4); + if (aspa_check_aspath(ra, a, &state) == -1) { + memset(vstate, ASPA_INVALID, sizeof(*vstate)); return; } - aspa_check_finalize(state, &vstate->onlyup_v4, &vstate->downup_v4); - aspa_check_finalize(state + 1, &vstate->onlyup_v6, &vstate->downup_v6); + aspa_check_finalize(&state, &vstate->onlyup, &vstate->downup); } /* @@ -402,7 +375,7 @@ aspa_table_prep(uint32_t entries, size_t datasize) */ void aspa_add_set(struct rde_aspa *ra, uint32_t cas, const uint32_t *pas, - uint32_t pascnt, const uint32_t *pas_aid) + uint32_t pascnt) { struct rde_aspa_set *aspa; uint32_t h, i; @@ -441,18 +414,6 @@ aspa_add_set(struct rde_aspa *ra, uint32_t cas, const uint32_t *pas, aspa->pas = ra->data + ra->curdata; for (i = 0; i < pascnt; i++) ra->data[ra->curdata++] = pas[i]; - - /* 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 < - TAS_AID_SIZE(pascnt) / sizeof(ra->data[0])) - fatalx("aspa set data overflow"); - - aspa->pas_aid = ra->data + ra->curdata; - memcpy(aspa->pas_aid, pas_aid, TAS_AID_SIZE(pascnt)); - ra->curdata += TAS_AID_SIZE(pascnt) / sizeof(ra->data[0]); - } } void @@ -476,7 +437,7 @@ aspa_table_stats(const struct rde_aspa *ra, struct ctl_show_set *cset) } /* - * Return true if the two rde_aspa tables are contain the same data. + * Return true if the two rde_aspa tables contain the same data. */ int aspa_table_equal(const struct rde_aspa *ra, const struct rde_aspa *rb) diff --git a/usr.sbin/bgpd/rtr.c b/usr.sbin/bgpd/rtr.c index e02b09bd822..407bac6f4f7 100644 --- a/usr.sbin/bgpd/rtr.c +++ b/usr.sbin/bgpd/rtr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtr.c,v 1.15 2023/05/05 10:48:16 claudio Exp $ */ +/* $OpenBSD: rtr.c,v 1.16 2023/08/16 08:26:35 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker @@ -129,45 +129,32 @@ rtr_roa_insert(struct roa_tree *rt, struct roa *in) /* * Add an asnum to the aspa_set. The aspa_set is sorted by asnum. - * The aid is altered to AID_UNSPEC (match for both v4 and v6) if - * the current aid and the one passed do not match. */ static void -aspa_set_entry(struct aspa_set *aspa, uint32_t asnum, uint8_t aid) +aspa_set_entry(struct aspa_set *aspa, uint32_t asnum) { uint32_t i, num, *newtas; - uint8_t *newtasaid; - - if (aid != AID_UNSPEC && aid != AID_INET && aid != AID_INET6) - fatalx("aspa set with invalid AFI %s", aid2str(aid)); for (i = 0; i < aspa->num; i++) { if (asnum < aspa->tas[i]) break; - if (asnum == aspa->tas[i]) { - if (aspa->tas_aid[i] != aid) - aspa->tas_aid[i] = AID_UNSPEC; + if (asnum == aspa->tas[i]) return; - } } num = aspa->num + 1; newtas = recallocarray(aspa->tas, aspa->num, num, sizeof(uint32_t)); - newtasaid = recallocarray(aspa->tas_aid, aspa->num, num, 1); - if (newtas == NULL || newtasaid == NULL) + if (newtas == NULL) fatal("aspa_set merge"); if (i < aspa->num) { memmove(newtas + i + 1, newtas + i, (aspa->num - i) * sizeof(uint32_t)); - memmove(newtasaid + i + 1, newtasaid + i, (aspa->num - i)); } newtas[i] = asnum; - newtasaid[i] = aid; aspa->num = num; aspa->tas = newtas; - aspa->tas_aid = newtasaid; } /* @@ -188,7 +175,7 @@ rtr_aspa_insert(struct aspa_tree *at, struct aspa_set *mergeset) } for (i = 0; i < mergeset->num; i++) - aspa_set_entry(aspa, mergeset->tas[i], mergeset->tas_aid[i]); + aspa_set_entry(aspa, mergeset->tas[i]); } void @@ -398,16 +385,6 @@ rtr_dispatch_imsg_parent(struct imsgbuf *ibuf) memcpy(aspa->tas, imsg.data, aspa->num * sizeof(*aspa->tas)); break; - case IMSG_RECONF_ASPA_TAS_AID: - if (aspa == NULL) - fatalx("unexpected IMSG_RECONF_ASPA_TAS_ID"); - if (imsg.hdr.len - IMSG_HEADER_SIZE != aspa->num) - fatalx("IMSG_RECONF_ASPA_TAS_AID bad len"); - aspa->tas_aid = malloc(aspa->num); - if (aspa->tas_aid == NULL) - fatal("aspa tas aid alloc"); - memcpy(aspa->tas_aid, imsg.data, aspa->num); - break; case IMSG_RECONF_ASPA_DONE: if (aspa == NULL) fatalx("unexpected IMSG_RECONF_ASPA_DONE"); @@ -503,53 +480,9 @@ rtr_imsg_compose(int type, uint32_t id, pid_t pid, void *data, size_t datalen) * if no extra aid masks are needed. */ static size_t -rtr_aspa_set_prep(struct aspa_set *aspa) +rtr_aspa_set_size(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: - needafi = 1; - mask |= 0x1 << ((i % 16) * 2); - break; - case AID_INET6: - needafi = 1; - mask |= 0x2 << ((i % 16) * 2); - break; - default: - mask |= 0x3 << ((i % 16) * 2); - break; - } - if (i % 16 == 15) { - memcpy(tas_aid + (i / 16) * sizeof(mask), &mask, - sizeof(mask)); - mask = 0; - } - } - - free(aspa->tas_aid); - aspa->tas_aid = NULL; - - if (!needafi) { - free(tas_aid); - } else { - 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; + return aspa->num * sizeof(uint32_t); } /* @@ -588,7 +521,7 @@ rtr_recalc(void) rtr_aspa_merge(&at); RB_FOREACH(aspa, aspa_tree, &at) { - ap.datasize += rtr_aspa_set_prep(aspa); + ap.datasize += rtr_aspa_set_size(aspa); ap.entries++; } @@ -605,9 +538,6 @@ rtr_recalc(void) &as, sizeof(as)); 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_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); } diff --git a/usr.sbin/bgpd/rtr_proto.c b/usr.sbin/bgpd/rtr_proto.c index bfa74c47b30..2b7b1b78fa7 100644 --- a/usr.sbin/bgpd/rtr_proto.c +++ b/usr.sbin/bgpd/rtr_proto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtr_proto.c,v 1.16 2023/03/28 12:15:23 claudio Exp $ */ +/* $OpenBSD: rtr_proto.c,v 1.17 2023/08/16 08:26:35 claudio Exp $ */ /* * Copyright (c) 2020 Claudio Jeker @@ -150,8 +150,8 @@ struct rtr_session { TAILQ_ENTRY(rtr_session) entry; char descr[PEER_DESCR_LEN]; struct roa_tree roa_set; - struct aspa_tree aspa_v4; - struct aspa_tree aspa_v6; + struct aspa_tree aspa; + struct aspa_tree aspa_oldv6; struct ibuf_read r; struct msgbuf w; struct timer_head timers; @@ -224,8 +224,8 @@ rtr_reset_cache(struct rtr_session *rs) rs->session_id = -1; timer_stop(&rs->timers, Timer_Rtr_Expire); free_roatree(&rs->roa_set); - free_aspatree(&rs->aspa_v4); - free_aspatree(&rs->aspa_v6); + free_aspatree(&rs->aspa); + free_aspatree(&rs->aspa_oldv6); } static struct ibuf * @@ -627,7 +627,6 @@ rtr_parse_aspa(struct rtr_session *rs, uint8_t *buf, size_t len) struct aspa_set *aspa, *a; size_t offset; uint16_t cnt, i; - uint8_t aid; memcpy(&rtr_aspa, buf + sizeof(struct rtr_header), sizeof(rtr_aspa)); offset = sizeof(struct rtr_header) + sizeof(rtr_aspa); @@ -647,11 +646,9 @@ rtr_parse_aspa(struct rtr_session *rs, uint8_t *buf, size_t len) } if (rtr_aspa.afi_flags & FLAG_AFI_V6) { - aid = AID_INET6; - aspatree = &rs->aspa_v6; + aspatree = &rs->aspa_oldv6; } else { - aid = AID_INET; - aspatree = &rs->aspa_v4; + aspatree = &rs->aspa; } /* create aspa_set entry from the rtr aspa pdu */ @@ -664,8 +661,7 @@ rtr_parse_aspa(struct rtr_session *rs, uint8_t *buf, size_t len) aspa->as = ntohl(rtr_aspa.cas); aspa->num = cnt; if (cnt > 0) { - if ((aspa->tas = calloc(cnt, sizeof(uint32_t))) == NULL || - (aspa->tas_aid = calloc(cnt, 1)) == NULL) { + if ((aspa->tas = calloc(cnt, sizeof(uint32_t))) == NULL) { free_aspa(aspa); log_warn("rtr %s: received %s", log_rtr(rs), log_rtr_type(ASPA)); @@ -678,7 +674,6 @@ rtr_parse_aspa(struct rtr_session *rs, uint8_t *buf, size_t len) memcpy(&tas, buf + offset + i * sizeof(tas), sizeof(tas)); aspa->tas[i] = ntohl(tas); - aspa->tas_aid[i] = aid; } } @@ -1245,8 +1240,8 @@ rtr_new(uint32_t id, char *descr) fatal("RTR session %s", descr); RB_INIT(&rs->roa_set); - RB_INIT(&rs->aspa_v4); - RB_INIT(&rs->aspa_v6); + RB_INIT(&rs->aspa); + RB_INIT(&rs->aspa_oldv6); TAILQ_INIT(&rs->timers); msgbuf_init(&rs->w); @@ -1359,9 +1354,9 @@ rtr_aspa_merge(struct aspa_tree *at) struct aspa_set *aspa; TAILQ_FOREACH(rs, &rtrs, entry) { - RB_FOREACH(aspa, aspa_tree, &rs->aspa_v4) + RB_FOREACH(aspa, aspa_tree, &rs->aspa) rtr_aspa_insert(at, aspa); - RB_FOREACH(aspa, aspa_tree, &rs->aspa_v6) + RB_FOREACH(aspa, aspa_tree, &rs->aspa_oldv6) rtr_aspa_insert(at, aspa); } }