From: Igor Putovny Date: Mon, 19 May 2025 13:42:25 +0000 (+0200) Subject: Add more descriptive error messages for AFI/SAFI mismatch X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a2a84b1bcd27d61226319cd4f05f09f4a70222de;p=thirdparty%2Fbird.git Add more descriptive error messages for AFI/SAFI mismatch --- diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index 2eabe6ec1..c2c955426 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -944,7 +944,48 @@ bgp_rx_open(struct bgp_conn *conn, byte *pkt, uint len) /* RFC 5492 5 - check for required capabilities */ if (p->cf->capabilities && !bgp_check_capabilities(conn)) - { bgp_error(conn, 2, 7, NULL, 0); return; } + { + char buf[256] = { 0 }; + char *t = buf; + + const struct bgp_caps *local = conn->local_caps; + const struct bgp_caps *remote = conn->remote_caps; + + const struct bgp_af_caps *local_ac = NULL, *remote_ac = NULL; + + t += bsprintf(t, "AFI/SAFI mismatch: local has: "); + int i = 0; + + WALK_AF_CAPS(local, local_ac) + { + const struct bgp_af_desc *desc = bgp_get_af_desc(local_ac->afi); + t += bsprintf(t, "%s", desc->name); + + if (i < local->af_count - 1) + t += bsprintf(t, ", "); + + i++; + } + + t += bsprintf(t, "; remote has: "); + i = 0; + + WALK_AF_CAPS(remote, remote_ac) + { + const struct bgp_af_desc *desc = bgp_get_af_desc(remote_ac->afi); + t += bsprintf(t, "%s", desc->name); + + if (i < remote->af_count - 1) + t += bsprintf(t, ", "); + + i++; + } + + *t = 0; + const char *dsc = bgp_error_dsc(2, 7); + log(L_REMOTE "%s: %s: %s: %s", p->p.name, "Error", dsc, buf); + return; + } struct bgp_caps *caps = conn->remote_caps;