From 14454c9fdd59340bbd71766b925f3ebb8fba13ba Mon Sep 17 00:00:00 2001 From: Don Slice Date: Fri, 15 Jun 2018 21:08:53 +0000 Subject: [PATCH] bgpd: implement zlog_ferr facility for enhance error messages in bgp Signed-off-by: Don Slice total); } @@ -1127,7 +1132,8 @@ static bgp_attr_parse_ret_t bgp_attr_origin(struct bgp_attr_parser_args *args) contains the unrecognized attribute (type, length and value). */ if ((attr->origin != BGP_ORIGIN_IGP) && (attr->origin != BGP_ORIGIN_EGP) && (attr->origin != BGP_ORIGIN_INCOMPLETE)) { - zlog_err("Origin attribute value is invalid %d", attr->origin); + zlog_ferr(BGP_ERR_ATTR_ORIGIN, + "Origin attribute value is invalid %d", attr->origin); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_INVAL_ORIGIN, args->total); } @@ -1155,8 +1161,9 @@ static int bgp_attr_aspath(struct bgp_attr_parser_args *args) /* In case of IBGP, length will be zero. */ if (!attr->aspath) { - zlog_err("Malformed AS path from %s, length is %d", peer->host, - length); + zlog_ferr(BGP_ERR_ATTR_MAL_AS_PATH, + "Malformed AS path from %s, length is %d", peer->host, + length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_AS_PATH, 0); } @@ -1184,7 +1191,8 @@ static bgp_attr_parse_ret_t bgp_attr_aspath_check(struct peer *const peer, && !aspath_left_confed_check(attr->aspath)) || (peer->sort == BGP_PEER_EBGP && aspath_confed_check(attr->aspath))) { - zlog_err("Malformed AS path from %s", peer->host); + zlog_ferr(BGP_ERR_ATTR_MAL_AS_PATH, "Malformed AS path from %s", + peer->host); bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_MAL_AS_PATH); return BGP_ATTR_PARSE_ERROR; @@ -1194,8 +1202,9 @@ static bgp_attr_parse_ret_t bgp_attr_aspath_check(struct peer *const peer, if (CHECK_FLAG(peer->flags, PEER_FLAG_ENFORCE_FIRST_AS)) { if (peer->sort == BGP_PEER_EBGP && !aspath_firstas_check(attr->aspath, peer->as)) { - zlog_err("%s incorrect first AS (must be %u)", - peer->host, peer->as); + zlog_ferr(BGP_ERR_ATTR_FIRST_AS, + "%s incorrect first AS (must be %u)", + peer->host, peer->as); bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_MAL_AS_PATH); return BGP_ATTR_PARSE_ERROR; @@ -1227,8 +1236,9 @@ static int bgp_attr_as4_path(struct bgp_attr_parser_args *args, /* In case of IBGP, length will be zero. */ if (!*as4_path) { - zlog_err("Malformed AS4 path from %s, length is %d", peer->host, - length); + zlog_ferr(BGP_ERR_ATTR_MAL_AS_PATH, + "Malformed AS4 path from %s, length is %d", + peer->host, length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_AS_PATH, 0); } @@ -1250,7 +1260,8 @@ static bgp_attr_parse_ret_t bgp_attr_nexthop(struct bgp_attr_parser_args *args) /* Check nexthop attribute length. */ if (length != 4) { - zlog_err("Nexthop attribute length isn't four [%d]", length); + zlog_ferr(BGP_ERR_ATTR_LEN, + "Nexthop attribute length isn't four [%d]", length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, args->total); @@ -1274,7 +1285,7 @@ static bgp_attr_parse_ret_t bgp_attr_nexthop(struct bgp_attr_parser_args *args) { char buf[INET_ADDRSTRLEN]; inet_ntop(AF_INET, &nexthop_n, buf, INET_ADDRSTRLEN); - zlog_err("Martian nexthop %s", buf); + zlog_ferr(BGP_ERR_ATTR_MARTIAN_NH, "Martian nexthop %s", buf); return bgp_attr_malformed( args, BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, args->total); } @@ -1294,7 +1305,8 @@ static bgp_attr_parse_ret_t bgp_attr_med(struct bgp_attr_parser_args *args) /* Length check. */ if (length != 4) { - zlog_err("MED attribute length isn't four [%d]", length); + zlog_ferr(BGP_ERR_ATTR_LEN, + "MED attribute length isn't four [%d]", length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, args->total); @@ -1317,7 +1329,8 @@ bgp_attr_local_pref(struct bgp_attr_parser_args *args) /* Length check. */ if (length != 4) { - zlog_err("LOCAL_PREF attribute length isn't 4 [%u]", length); + zlog_ferr(BGP_ERR_ATTR_LEN, + "LOCAL_PREF attribute length isn't 4 [%u]", length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, args->total); } @@ -1346,8 +1359,9 @@ static int bgp_attr_atomic(struct bgp_attr_parser_args *args) /* Length check. */ if (length != 0) { - zlog_err("ATOMIC_AGGREGATE attribute length isn't 0 [%u]", - length); + zlog_ferr(BGP_ERR_ATTR_LEN, + "ATOMIC_AGGREGATE attribute length isn't 0 [%u]", + length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, args->total); } @@ -1372,8 +1386,9 @@ static int bgp_attr_aggregator(struct bgp_attr_parser_args *args) wantedlen = 8; if (length != wantedlen) { - zlog_err("AGGREGATOR attribute length isn't %u [%u]", wantedlen, - length); + zlog_ferr(BGP_ERR_ATTR_LEN, + "AGGREGATOR attribute length isn't %u [%u]", + wantedlen, length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, args->total); } @@ -1401,7 +1416,8 @@ bgp_attr_as4_aggregator(struct bgp_attr_parser_args *args, const bgp_size_t length = args->length; if (length != 8) { - zlog_err("New Aggregator length is not 8 [%d]", length); + zlog_ferr(BGP_ERR_ATTR_LEN, + "New Aggregator length is not 8 [%d]", length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, 0); } @@ -1560,7 +1576,8 @@ bgp_attr_originator_id(struct bgp_attr_parser_args *args) /* Length check. */ if (length != 4) { - zlog_err("Bad originator ID length %d", length); + zlog_ferr(BGP_ERR_ATTR_LEN, "Bad originator ID length %d", + length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, args->total); @@ -1583,7 +1600,8 @@ bgp_attr_cluster_list(struct bgp_attr_parser_args *args) /* Check length. */ if (length % 4) { - zlog_err("Bad cluster list length %d", length); + zlog_ferr(BGP_ERR_ATTR_LEN, "Bad cluster list length %d", + length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, args->total); @@ -2052,10 +2070,10 @@ static bgp_attr_parse_ret_t bgp_attr_psid_sub(int32_t type, if (type == BGP_PREFIX_SID_LABEL_INDEX) { if (length != BGP_PREFIX_SID_LABEL_INDEX_LENGTH) { - zlog_err( - "Prefix SID label index length is %d instead of %d", - length, - BGP_PREFIX_SID_LABEL_INDEX_LENGTH); + zlog_ferr( + BGP_ERR_ATTR_LEN, + "Prefix SID label index length is %d instead of %d", + length, BGP_PREFIX_SID_LABEL_INDEX_LENGTH); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, args->total); @@ -2088,8 +2106,9 @@ static bgp_attr_parse_ret_t bgp_attr_psid_sub(int32_t type, /* Placeholder code for the IPv6 SID type */ else if (type == BGP_PREFIX_SID_IPV6) { if (length != BGP_PREFIX_SID_IPV6_LENGTH) { - zlog_err("Prefix SID IPv6 length is %d instead of %d", - length, BGP_PREFIX_SID_IPV6_LENGTH); + zlog_ferr(BGP_ERR_ATTR_LEN, + "Prefix SID IPv6 length is %d instead of %d", + length, BGP_PREFIX_SID_IPV6_LENGTH); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, args->total); @@ -2110,7 +2129,8 @@ static bgp_attr_parse_ret_t bgp_attr_psid_sub(int32_t type, length -= 2; if (length % BGP_PREFIX_SID_ORIGINATOR_SRGB_LENGTH) { - zlog_err( + zlog_ferr( + BGP_ERR_ATTR_LEN, "Prefix SID Originator SRGB length is %d, it must be a multiple of %d ", length, BGP_PREFIX_SID_ORIGINATOR_SRGB_LENGTH); return bgp_attr_malformed( @@ -2159,8 +2179,10 @@ bgp_attr_prefix_sid(int32_t tlength, struct bgp_attr_parser_args *args, tlength -= length + 3; if (tlength < 0) { - zlog_err("Prefix SID internal length %d causes us to read beyond the total Prefix SID length", - length); + zlog_ferr( + BGP_ERR_ATTR_LEN, + "Prefix SID internal length %d causes us to read beyond the total Prefix SID length", + length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, args->total); @@ -2185,21 +2207,24 @@ bgp_attr_pmsi_tunnel(struct bgp_attr_parser_args *args) * can only support that. */ if (length < 2) { - zlog_err("Bad PMSI tunnel attribute length %d", length); + zlog_ferr(BGP_ERR_ATTR_LEN, + "Bad PMSI tunnel attribute length %d", length); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, args->total); } stream_getc(peer->curr); /* Flags */ tnl_type = stream_getc(peer->curr); if (tnl_type > PMSI_TNLTYPE_MAX) { - zlog_err("Invalid PMSI tunnel attribute type %d", tnl_type); + zlog_ferr(BGP_ERR_ATTR_PMSI_TYPE, + "Invalid PMSI tunnel attribute type %d", tnl_type); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, args->total); } if (tnl_type == PMSI_TNLTYPE_INGR_REPL) { if (length != 9) { - zlog_err("Bad PMSI tunnel attribute length %d for IR", - length); + zlog_ferr(BGP_ERR_ATTR_PMSI_LEN, + "Bad PMSI tunnel attribute length %d for IR", + length); return bgp_attr_malformed( args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, args->total); @@ -2799,9 +2824,10 @@ size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi, break; default: if (safi != SAFI_FLOWSPEC) - zlog_err( - "Bad nexthop when sending to %s, AFI %u SAFI %u nhlen %d", - peer->host, afi, safi, attr->mp_nexthop_len); + zlog_ferr( + BGP_ERR_ATTR_NH_SEND_LEN, + "Bad nexthop when sending to %s, AFI %u SAFI %u nhlen %d", + peer->host, afi, safi, attr->mp_nexthop_len); break; } diff --git a/bgpd/bgp_errors.c b/bgpd/bgp_errors.c new file mode 100644 index 0000000000..c69035cac9 --- /dev/null +++ b/bgpd/bgp_errors.c @@ -0,0 +1,311 @@ +/* + * bgp_errors - code for error messages that may occur in the + * bgp process + * Copyright (C) 2018 Cumulus Networks, Inc. + * Don Slice + * + * FRR is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * FRR is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include +#include + +static struct ferr_ref ferr_lib_err[] = { + { + .code = BGP_ERR_ATTR_FLAG, + .title = "BGP attribute flag is incorrect", + .description = "BGP attribute flag is set to the wrong value (Optional/Transitive/Partial)", + .suggestion = "Determine the soure of the attribute and determine why the attribute\n flag has been set incorrectly" + }, + { + .code = BGP_ERR_ATTR_LEN, + .title = "BGP attribute length is incorrect", + .description = "BGP attribute length is incorrect)", + .suggestion = "Determine the soure of the attribute and determine why the attribute\nlength has been set incorrectly" + }, + { + .code = BGP_ERR_ATTR_ORIGIN, + .title = "BGP attribute origin value invalid", + .description = "BGP attribute origin value is invalid", + .suggestion = "Determine the soure of the attribute and determine why the origin\nattribute has been set incorrectly" + }, + { + .code = BGP_ERR_ATTR_MAL_AS_PATH, + .title = "BGP as path is invalid", + .description = "BGP as path has been malformed", + .suggestion = "Determine the soure of the update and determine why the as path has\nbeen set incorrectly" + }, + { + .code = BGP_ERR_ATTR_FIRST_AS, + .title = "BGP as path first as is invalid", + .description = "BGP update has invalid first as in as path", + .suggestion = "Determine the soure of the update and determine why the as path first\nas value has been set incorrectly" + }, + { + .code = BGP_ERR_ATTR_PMSI_TYPE, + .title = "BGP PMSI tunnel attribute type is invalid", + .description = "BGP update has invalid type for PMSI tunnel", + .suggestion = "Determine the soure of the update and determine why the PMSI tunnel\nattribute type has been set incorrectly" + }, + { + .code = BGP_ERR_ATTR_PMSI_LEN, + .title = "BGP PMSI tunnel attribute length is invalid", + .description = "BGP update has invalid length for PMSI tunnel", + .suggestion = "Determine the soure of the update and determine why the PMSI tunnel\nattribute length has been set incorrectly" + }, + { + .code = BGP_ERR_NH_SEND_LEN, + .title = "BGP nethop length is invalid sending to peer", + .description = "BGP update has invalid length for nexthop sending to peer", + .suggestion = "Determine why the nexthop length has been set incorrectly" + }, + { + .code = BGP_ERR_PEER_GROUP, + .title = "BGP peergroup operated on in error", + .description = "BGP operating on peer-group instead of peers included", + .suggestion = "Ensure the config doesn't contain peergroups contained within peergroups" + }, + { + .code = BGP_ERR_PEER_DELETE, + .title = "BGP failed to delete peer structure", + .description = "BGP was unable to delete peer structure when address-family removed", + .suggestion = "Determine if all expected peers are removed and restart FRR if not.\nMost likely a bug" + }, + { + .code = BGP_ERR_TABLE_CHUNK, + .title = "BGP failed to get table chunk memory", + .description = "BGP unable to get chunk memory for table manager", + .suggestion = "Ensure there is adequate memory on the device to support the table\nrequirements" + }, + { + .code = BGP_ERR_MACIP_LEN, + .title = "BGP received MACIP with invalid IP addr len", + .description = "BGP received MACIP with invalid IP addr len from Zebra", + .suggestion = "Verify MACIP entries inserted in Zebra are correct. Most likely a bug" + }, + { + .code = BGP_ERR_LM_ERROR, + .title = "BGP received invalid label manager message", + .description = "BGP received nvalid label manager message from label manager", + .suggestion = "Label manager sent invalid essage to BGP for wrong protocol, instance, etc.\nMost likely a bug" + }, + { + .code = BGP_ERR_JSON_MEM_ERROR, + .title = "BGP unable to allocate memory for JSON output", + .description = "BGP attempted to generate JSON output and was unable to allocate\nthe memory required", + .suggestion = "Ensure that the device has adequate memory to suport the required functions" + }, + { + .code = BGP_ERR_UPDGRP_ATTR_LEN, + .title = "BGP update had attributes too long to send", + .description = "BGP attempted to send an update but the attributes were too long to fit", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_UPDGRP_CREATE, + .title = "BGP update group creation failed", + .description = "BGP attempted to create an update group but was unable to", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_UPDATE_SND, + .title = "BGP error creating update packet", + .description = "BGP attempted to create an update packet but was unable to", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_PKT_OPEN, + .title = "BGP error receiving open packet", + .description = "BGP received an open from a peer that was invalid", + .suggestion = "Determine the sending peer and correct his invalid open packet" + }, + { + .code = BGP_ERR_SOCKET, + .title = "Socket Error", + .description = "When attempting to access a socket a system error has occurred\nand we were unable to properly complete the request", + .suggestion = "Ensure that there are sufficient system resources available and\nensure that the frr user has sufficient permissions to work" + }, + { + .code = BGP_ERR_SND_FAIL, + .title = "BGP error sending to peer", + .description = "BGP attempted to respond to open from a peer and failed", + .suggestion = "BGP attempted to respond to an open and could not sene the packet.\nCheck local IP address for source" + }, + { + .code = BGP_ERR_INVALID_STATUS, + .title = "BGP error receiving from peer", + .description = "BGP received an update from a peer but status was incorrect", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_UPDATE_RCV, + .title = "BGP error receiving update packet", + .description = "BGP received an invalid update packet", + .suggestion = "Determine the source of the update and resolve the invalid update being sent" + }, + { + .code = BGP_ERR_NO_CAP, + .title = "BGP error due to capability not enabled", + .description = "BGP attempted a function that did not have the capability enabled", + .suggestion = "Enable the capability if this functionality is desired" + }, + { + .code = BGP_ERR_NOTIFY_RCV, + .title = "BGP error receiving notify message", + .description = "BGP unable to process notification message", + .suggestion = "BGP notify received while in stopped state. If the problem persists,\nreport for troubleshooting" + }, + { + .code = BGP_ERR_KEEP_RCV, + .title = "BGP error receiving keepalive packet", + .description = "BGP unable to process keepalive packet", + .suggestion = "BGP keepalive received while in stopped state. If the problem persists,\nreport for troubleshooting" + }, + { + .code = BGP_ERR_RFSH_RCV, + .title = "BGP error receiving route refresh message", + .description = "BGP unable to process route refresh message", + .suggestion = "BGP route refresh received while in stopped state. If the problem persists,\nreport for troubleshooting"}, + { + .code = BGP_ERR_CAP_RCV, + .title = "BGP error capability message", + .description = "BGP unable to process received capability", + .suggestion = "BGP capability message received while in stopped state. If the problem\npersists, report for troubleshooting" + }, + { + .code = BGP_ERR_NH_UPD, + .title = "BGP error with nexthopo update", + .description = "BGP unable to process nexthop update", + .suggestion = "BGP received nexthop update but nexthop is not reachable in this bgp\ninstance. Report for troubleshooting" + }, + { + .code = BGP_ERR_PRIVILEGES, + .title = "Failure to raise or lower privileges", + .description = "FRR attempted to raise or lower its privileges and was unable to do so", + .suggestion = "Ensure that you are running FRR as the frr user and that the user has\nSufficient privileges to properly access root privileges" + }, + { + .code = BGP_ERR_LABEL, + .title = "Failure to apply label", + .description = "BGP attempted to attempted to apply a label but could not", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_MULTIPATH, + .title = "Multipath specified is invalid", + .description = "BGP was started with an invalid ecmp/multipath value", + .suggestion = "Correct the ecmp/multipath value supplied when starting the BGP daemon" + }, + { + .code = BGP_ERR_PKT_PROCESS, + .title = "Failure to process a packet", + .description = "BGP attempted to process a received packet but could not", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_CONNECT, + .title = "Failure to connect to peer", + .description = "BGP attempted to send open to peer but couldn't connect", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_FSM, + .title = "BGP FSM issue", + .description = "BGP neighbor transition problem", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_VNI, + title = "BGP VNI creation issue", + .description = "BGP could not create a new VNI", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_NO_DFLT, + .title = "BGP default instance missing", + .description = "BGP could not find default instance", + .suggestion = "Define a default instance of BGP since some feature requires it's existence" + }, + { + .code = BGP_ERR_VTEP_INVALID, + .title = "BGP remote VTEP invalid", + .description = "BGP remote VTEP is invalid and cannot be used", + .suggestion = "Correct remote VTEP configuration or resolve the source of the problem" + }, + { + .code = BGP_ERR_ES_INVALID, + .title = "BGP ES route error", + .description = "BGP ES route incorrect, learned both local and remote", + .suggestion = "Correct configuration or addressing so that same not learned both local and remote" + }, + { + .code = BGP_ERR_EVPN_ROUTE_DELETE, + .title = "BGP EVPN route delete error", + .description = "BGP attempted to delete an EVPN route and failed", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_EVPN_FAIL, + .title = "BGP EVPN install/uninstall error", + .description = "BGP attempted to install or uninstall an EVPN prefix and failed", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_EVPN_ROUTE_INVALID, + .title = "BGP EVPN route received with invalid contents", + .description = "BGP received an EVPN route with invalid contents", + .suggestion = "Determine the source of the EVPN route and resolve whatever is causing\ninvalid contents" + }, + { + .code = BGP_ERR_EVPN_ROUTE_CREATE, + .title = "BGP EVPN route create error", + .description = "BGP attempted to create an EVPN route and failed", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_ES_CREATE, + .title = "BGP EVPN ES entry create error", + .description = "BGP attempted to create an EVPN ES entry and failed", + .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting" + }, + { + .code = BGP_ERR_MULTI_INSTANCE, + .title = "BGP config multi-instance issue", + .description = "BGP configuration attempting multiple instances without enabling the feature", + .suggestion = "Correct the configuration so that bgp multiple-instance is enabled if desired" + }, + { + .code = BGP_ERR_EVPN_AS_MISMATCH, + .title = "BGP AS configuration issue", + .description = "BGP configuration attempted for a different AS than currently configured", + .suggestion = "Correct the configuration so that the correct BGP AS number is used" + }, + { + .code = BGP_ERR_EVPN_INSTANCE_MISMATCH, + .title = "BGP EVPN AS and process name mismatch", + .description = "BGP configuration has AS and process name mismatch", + .suggestion = "Correct the configuration so that the BGP AS number and instance\nname are consistent" + }, +{ + .code = END_FERR, +} +} +; + +void BGP_error_init(void) +{ + ferr_ref_init(); + + ferr_ref_add(ferr_bgp_err); +} diff --git a/bgpd/bgp_errors.h b/bgpd/bgp_errors.h new file mode 100644 index 0000000000..0a829a6fb7 --- /dev/null +++ b/bgpd/bgp_errors.h @@ -0,0 +1,79 @@ +/* + * bgp_errors - header for error messages that may occur in the bgp process + * Copyright (C) 2018 Cumulus Networks, Inc. + * Don Slice + * + * FRR is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * FRR is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#ifndef __BGP_ERRORS_H__ +#define __BGP_ERRORS_H__ + +#include "ferr.h" +#include "bgp_errors.h" + +enum bgp_ferr_refs { + + BGP_ERR_ATTR_FLAG = BGP_FERR_START, + BGP_ERR_ATTR_LEN, + BGP_ERR_ATTR_ORIGIN, + BGP_ERR_ATTR_MAL_AS_PATH, + BGP_ERR_ATTR_FIRST_AS, + BGP_ERR_ATTR_MARTIAN_NH, + BGP_ERR_ATTR_PMSI_TYPE, + BGP_ERR_ATTR_PMSI_LEN, + BGP_ERR_ATTR_NH_SEND_LEN, + BGP_ERR_PEER_GROUP, + BGP_ERR_PEER_DELETE, + BGP_ERR_TABLE_CHUNK, + BGP_ERR_MACIP_LEN, + BGP_ERR_LM_ERROR, + BGP_ERR_JSON_MEM_ERROR, + BGP_ERR_UPDGRP_ATTR_LEN, + BGP_ERR_UPDGRP_CREATE, + BGP_ERR_UPDATE_SND, + BGP_ERR_PKT_OPEN, + BGP_ERR_SOCKET, + BGP_ERR_SND_FAIL, + BGP_ERR_INVALID_STATUS, + BGP_ERR_UPDATE_RCV, + BGP_ERR_NO_CAP, + BGP_ERR_NOTIFY_RCV, + BGP_ERR_KEEP_RCV, + BGP_ERR_RFSH_RCV, + BGP_ERR_CAP_RCV, + BGP_ERR_NH_UPD, + BGP_ERR_PRIVILEGES, + BGP_ERR_LABEL, + BGP_ERR_MULTIPATH, + BGP_ERR_PKT_PROCESS, + BGP_ERR_CONNECT, + BGP_ERR_FSM, + BGP_ERR_VNI, + BGP_ERR_NO_DFLT, + BGP_ERR_VTEP_INVALID, + BGP_ERR_ES_INVALID, + BGP_ERR_EVPN_ROUTE_DELETE, + BGP_ERR_EVPN_FAIL, + BGP_ERR_EVPN_ROUTE_INVALID, + BGP_ERR_EVPN_ROUTE_CREATE, + BGP_ERR_ES_CREATE, + BGP_ERR_MULTI_INSTANCE, + BGP_ERR_EVPN_AS_MISMATCH, + BGP_ERR_EVPN_INSTANCE_MISMATCH, +}; + +extern void bgp_error_init(void); + +#endif diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 73f225784c..6ebfb7d780 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -43,6 +43,7 @@ #include "bgpd/bgp_ecommunity.h" #include "bgpd/bgp_encap_types.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_aspath.h" #include "bgpd/bgp_zebra.h" #include "bgpd/bgp_nexthop.h" @@ -172,7 +173,8 @@ static struct vrf_irt_node *vrf_import_rt_new(struct ecommunity_val *rt) bgp_def = bgp_get_default(); if (!bgp_def) { - zlog_err("vrf import rt new - def instance not created yet"); + zlog_ferr(BGP_ERR_NO_DFLT, + "vrf import rt new - def instance not created yet"); return NULL; } @@ -202,7 +204,8 @@ static void vrf_import_rt_free(struct vrf_irt_node *irt) bgp_def = bgp_get_default(); if (!bgp_def) { - zlog_err("vrf import rt free - def instance not created yet"); + zlog_ferr(BGP_ERR_NO_DFLT, + "vrf import rt free - def instance not created yet"); return; } @@ -223,7 +226,9 @@ static struct vrf_irt_node *lookup_vrf_import_rt(struct ecommunity_val *rt) bgp_def = bgp_get_default(); if (!bgp_def) { - zlog_err("vrf import rt lookup - def instance not created yet"); + zlog_ferr( + BGP_ERR_NO_DFLT, + "vrf import rt lookup - def instance not created yet"); return NULL; } @@ -619,7 +624,8 @@ static int bgp_zebra_send_remote_vtep(struct bgp *bgp, struct bgpevpn *vpn, if (is_evpn_prefix_ipaddr_v4(p)) stream_put_in_addr(s, &p->prefix.imet_addr.ip.ipaddr_v4); else if (is_evpn_prefix_ipaddr_v6(p)) { - zlog_err( + zlog_ferr( + BGP_ERR_VTEP_INVALID, "Bad remote IP when trying to %s remote VTEP for VNI %u", add ? "ADD" : "DEL", vpn->vni); return -1; @@ -1289,11 +1295,12 @@ static int update_evpn_type4_route_entry(struct bgp *bgp, * We shouldn't see the same route from any other vtep. */ if (remote_ri) { - zlog_err( - "%u ERROR: local es route for ESI: %s Vtep %s also learnt from remote", - bgp->vrf_id, - esi_to_str(&evp->prefix.es_addr.esi, buf, sizeof(buf)), - ipaddr2str(&es->originator_ip, buf1, sizeof(buf1))); + zlog_ferr( + BGP_ERR_ES_INVALID, + "%u ERROR: local es route for ESI: %s Vtep %s also learnt from remote", + bgp->vrf_id, + esi_to_str(&evp->prefix.es_addr.esi, buf, sizeof(buf)), + ipaddr2str(&es->originator_ip, buf1, sizeof(buf1))); return -1; } @@ -1376,10 +1383,12 @@ static int update_evpn_type4_route(struct bgp *bgp, &attr, 1, &ri, &route_changed); if (ret != 0) { - zlog_err("%u ERROR: Failed to updated ES route ESI: %s VTEP %s", - bgp->vrf_id, - esi_to_str(&p->prefix.es_addr.esi, buf, sizeof(buf)), - ipaddr2str(&es->originator_ip, buf1, sizeof(buf1))); + zlog_ferr( + BGP_ERR_ES_INVALID, + "%u ERROR: Failed to updated ES route ESI: %s VTEP %s", + bgp->vrf_id, + esi_to_str(&p->prefix.es_addr.esi, buf, sizeof(buf)), + ipaddr2str(&es->originator_ip, buf1, sizeof(buf1))); } assert(ri); @@ -2216,10 +2225,9 @@ static int delete_routes_for_es(struct bgp *bgp, struct evpnes *es) build_evpn_type4_prefix(&p, &es->esi, es->originator_ip.ipaddr_v4); ret = delete_evpn_type4_route(bgp, es, &p); if (ret) { - zlog_err( - "%u failed to delete type-4 route for ESI %s", - bgp->vrf_id, - esi_to_str(&es->esi, buf, sizeof(buf))); + zlog_ferr(BGP_ERR_EVPN_ROUTE_DELETE, + "%u failed to delete type-4 route for ESI %s", + bgp->vrf_id, esi_to_str(&es->esi, buf, sizeof(buf))); } /* Delete all routes from per ES table */ @@ -2876,7 +2884,8 @@ static int install_uninstall_routes_for_es(struct bgp *bgp, bgp, es, evp, ri); if (ret) { - zlog_err( + zlog_ferr( + BGP_ERR_EVPN_FAIL, "Failed to %s EVPN %s route in ESI %s", install ? "install" : "uninstall", @@ -2955,7 +2964,8 @@ static int install_uninstall_routes_for_vrf(struct bgp *bgp_vrf, int install) bgp_vrf, evp, ri); if (ret) { - zlog_err( + zlog_ferr( + BGP_ERR_EVPN_FAIL, "Failed to %s EVPN %s route in VRF %s", install ? "install" : "uninstall", @@ -3028,7 +3038,8 @@ static int install_uninstall_routes_for_vni(struct bgp *bgp, bgp, vpn, evp, ri); if (ret) { - zlog_err( + zlog_ferr( + BGP_ERR_EVPN_FAIL, "%u: Failed to %s EVPN %s route in VNI %u", bgp->vrf_id, install ? "install" @@ -3130,11 +3141,11 @@ static int install_uninstall_route_in_es(struct bgp *bgp, struct evpnes *es, ret = uninstall_evpn_route_entry_in_es(bgp, es, evp, ri); if (ret) { - zlog_err("%u: Failed to %s EVPN %s route in ESI %s", - bgp->vrf_id, install ? "install" : "uninstall", - "ES", - esi_to_str(&evp->prefix.es_addr.esi, buf, - sizeof(buf))); + zlog_ferr( + BGP_ERR_EVPN_FAIL, + "%u: Failed to %s EVPN %s route in ESI %s", bgp->vrf_id, + install ? "install" : "uninstall", "ES", + esi_to_str(&evp->prefix.es_addr.esi, buf, sizeof(buf))); return ret; } return 0; @@ -3173,11 +3184,12 @@ static int install_uninstall_route_in_vrfs(struct bgp *bgp_def, afi_t afi, ri); if (ret) { - zlog_err("%u: Failed to %s prefix %s in VRF %s", - bgp_def->vrf_id, - install ? "install" : "uninstall", - prefix2str(evp, buf, sizeof(buf)), - vrf_id_to_name(bgp_vrf->vrf_id)); + zlog_ferr(BGP_ERR_EVPN_FAIL, + "%u: Failed to %s prefix %s in VRF %s", + bgp_def->vrf_id, + install ? "install" : "uninstall", + prefix2str(evp, buf, sizeof(buf)), + vrf_id_to_name(bgp_vrf->vrf_id)); return ret; } } @@ -3208,12 +3220,14 @@ static int install_uninstall_route_in_vnis(struct bgp *bgp, afi_t afi, ret = uninstall_evpn_route_entry(bgp, vpn, evp, ri); if (ret) { - zlog_err("%u: Failed to %s EVPN %s route in VNI %u", - bgp->vrf_id, install ? "install" : "uninstall", - evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE - ? "MACIP" - : "IMET", - vpn->vni); + zlog_ferr( + BGP_ERR_EVPN_FAIL, + "%u: Failed to %s EVPN %s route in VNI %u", + bgp->vrf_id, install ? "install" : "uninstall", + evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE + ? "MACIP" + : "IMET", + vpn->vni); return ret; } } @@ -3592,8 +3606,9 @@ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi, */ if (psize != 33 && psize != 37 && psize != 49 && psize != 36 && psize != 40 && psize != 52) { - zlog_err("%u:%s - Rx EVPN Type-2 NLRI with invalid length %d", - peer->bgp->vrf_id, peer->host, psize); + zlog_ferr(BGP_ERR_EVPN_ROUTE_INVALID, + "%u:%s - Rx EVPN Type-2 NLRI with invalid length %d", + peer->bgp->vrf_id, peer->host, psize); return -1; } @@ -3628,7 +3643,8 @@ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi, memcpy(&p.prefix.macip_addr.mac.octet, pfx, ETH_ALEN); pfx += ETH_ALEN; } else { - zlog_err( + zlog_ferr( + BGP_ERR_EVPN_ROUTE_INVALID, "%u:%s - Rx EVPN Type-2 NLRI with unsupported MAC address length %d", peer->bgp->vrf_id, peer->host, macaddr_len); return -1; @@ -3639,7 +3655,8 @@ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi, ipaddr_len = *pfx++; if (ipaddr_len != 0 && ipaddr_len != IPV4_MAX_BITLEN && ipaddr_len != IPV6_MAX_BITLEN) { - zlog_err( + zlog_ferr( + BGP_ERR_EVPN_ROUTE_INVALID, "%u:%s - Rx EVPN Type-2 NLRI with unsupported IP address length %d", peer->bgp->vrf_id, peer->host, ipaddr_len); return -1; @@ -3700,8 +3717,9 @@ static int process_type3_route(struct peer *peer, afi_t afi, safi_t safi, * IP len (1) and IP (4 or 16). */ if (psize != 17 && psize != 29) { - zlog_err("%u:%s - Rx EVPN Type-3 NLRI with invalid length %d", - peer->bgp->vrf_id, peer->host, psize); + zlog_ferr(BGP_ERR_EVPN_ROUTE_INVALID, + "%u:%s - Rx EVPN Type-3 NLRI with invalid length %d", + peer->bgp->vrf_id, peer->host, psize); return -1; } @@ -3741,7 +3759,8 @@ static int process_type3_route(struct peer *peer, afi_t afi, safi_t safi, p.prefix.imet_addr.ip.ipa_type = IPADDR_V4; memcpy(&p.prefix.imet_addr.ip.ip.addr, pfx, IPV4_MAX_BYTELEN); } else { - zlog_err( + zlog_ferr( + BGP_ERR_EVPN_ROUTE_INVALID, "%u:%s - Rx EVPN Type-3 NLRI with unsupported IP address length %d", peer->bgp->vrf_id, peer->host, ipaddr_len); return -1; @@ -3777,8 +3796,9 @@ static int process_type4_route(struct peer *peer, afi_t afi, safi_t safi, * RD (8), ESI (10), ip-len (1), ip (4 or 16) */ if (psize != 23 && psize != 35) { - zlog_err("%u:%s - Rx EVPN Type-4 NLRI with invalid length %d", - peer->bgp->vrf_id, peer->host, psize); + zlog_ferr(BGP_ERR_EVPN_ROUTE_INVALID, + "%u:%s - Rx EVPN Type-4 NLRI with invalid length %d", + peer->bgp->vrf_id, peer->host, psize); return -1; } @@ -3798,7 +3818,8 @@ static int process_type4_route(struct peer *peer, afi_t afi, safi_t safi, if (ipaddr_len == IPV4_MAX_BITLEN) { memcpy(&vtep_ip, pfx, IPV4_MAX_BYTELEN); } else { - zlog_err( + zlog_ferr( + BGP_ERR_EVPN_ROUTE_INVALID, "%u:%s - Rx EVPN Type-4 NLRI with unsupported IP address length %d", peer->bgp->vrf_id, peer->host, ipaddr_len); return -1; @@ -3840,8 +3861,9 @@ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi, * Note that the IP and GW should both be IPv4 or both IPv6. */ if (psize != 34 && psize != 58) { - zlog_err("%u:%s - Rx EVPN Type-5 NLRI with invalid length %d", - peer->bgp->vrf_id, peer->host, psize); + zlog_ferr(BGP_ERR_EVPN_ROUTE_INVALID, + "%u:%s - Rx EVPN Type-5 NLRI with invalid length %d", + peer->bgp->vrf_id, peer->host, psize); return -1; } @@ -3872,7 +3894,8 @@ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi, /* Fetch IP prefix length. */ ippfx_len = *pfx++; if (ippfx_len > IPV6_MAX_BITLEN) { - zlog_err( + zlog_ferr( + BGP_ERR_EVPN_ROUTE_INVALID, "%u:%s - Rx EVPN Type-5 NLRI with invalid IP Prefix length %d", peer->bgp->vrf_id, peer->host, ippfx_len); return -1; @@ -4104,7 +4127,8 @@ void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf, struct prefix *p, build_type5_prefix_from_ip_prefix(&evp, p); ret = delete_evpn_type5_route(bgp_vrf, &evp); if (ret) { - zlog_err( + zlog_ferr( + BGP_ERR_EVPN_ROUTE_DELETE, "%u failed to delete type-5 route for prefix %s in vrf %s", bgp_vrf->vrf_id, prefix2str(p, buf, sizeof(buf)), vrf_id_to_name(bgp_vrf->vrf_id)); @@ -4150,8 +4174,9 @@ void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf, struct prefix *p, build_type5_prefix_from_ip_prefix(&evp, p); ret = update_evpn_type5_route(bgp_vrf, &evp, src_attr); if (ret) - zlog_err("%u: Failed to create type-5 route for prefix %s", - bgp_vrf->vrf_id, prefix2str(p, buf, sizeof(buf))); + zlog_ferr(BGP_ERR_EVPN_ROUTE_CREATE, + "%u: Failed to create type-5 route for prefix %s", + bgp_vrf->vrf_id, prefix2str(p, buf, sizeof(buf))); } /* Inject all prefixes of a particular address-family (currently, IPv4 or @@ -4709,7 +4734,8 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr, if (process_type2_route(peer, afi, safi, withdraw ? NULL : attr, pnt, psize, addpath_id)) { - zlog_err( + zlog_ferr( + BGP_ERR_EVPN_FAIL, "%u:%s - Error in processing EVPN type-2 NLRI size %d", peer->bgp->vrf_id, peer->host, psize); return -1; @@ -4720,7 +4746,8 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr, if (process_type3_route(peer, afi, safi, withdraw ? NULL : attr, pnt, psize, addpath_id)) { - zlog_err( + zlog_ferr( + BGP_ERR_PKT_PROCESS, "%u:%s - Error in processing EVPN type-3 NLRI size %d", peer->bgp->vrf_id, peer->host, psize); return -1; @@ -4731,7 +4758,8 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr, if (process_type4_route(peer, afi, safi, withdraw ? NULL : attr, pnt, psize, addpath_id)) { - zlog_err( + zlog_ferr( + BGP_ERR_PKT_PROCESS, "%u:%s - Error in processing EVPN type-4 NLRI size %d", peer->bgp->vrf_id, peer->host, psize); return -1; @@ -4741,7 +4769,8 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr, case BGP_EVPN_IP_PREFIX_ROUTE: if (process_type5_route(peer, afi, safi, attr, pnt, psize, addpath_id, withdraw)) { - zlog_err( + zlog_ferr( + BGP_ERR_PKT_PROCESS, "%u:%s - Error in processing EVPN type-5 NLRI size %d", peer->bgp->vrf_id, peer->host, psize); return -1; @@ -5204,7 +5233,8 @@ int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni, struct ethaddr *mac, char buf[ETHER_ADDR_STRLEN]; char buf2[INET6_ADDRSTRLEN]; - zlog_err( + zlog_ferr( + BGP_ERR_EVPN_ROUTE_CREATE, "%u:Failed to create Type-2 route, VNI %u %s MAC %s IP %s (flags: 0x%x)", bgp->vrf_id, vpn->vni, CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY) @@ -5246,7 +5276,8 @@ int bgp_evpn_local_l3vni_add(vni_t l3vni, vrf_id_t vrf_id, struct ethaddr *rmac, */ bgp_def = bgp_get_default(); if (!bgp_def) { - zlog_err( + zlog_ferr( + BGP_ERR_NO_DFLT, "Cannot process L3VNI %u ADD - default BGP instance not yet created", l3vni); return -1; @@ -5263,13 +5294,16 @@ int bgp_evpn_local_l3vni_add(vni_t l3vni, vrf_id_t vrf_id, struct ethaddr *rmac, BGP_INSTANCE_TYPE_VRF); switch (ret) { case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET: - zlog_err("'bgp multiple-instance' not present\n"); + zlog_ferr(BGP_ERR_MULTI_INSTANCE, + "'bgp multiple-instance' not present\n"); return -1; case BGP_ERR_AS_MISMATCH: - zlog_err("BGP is already running; AS is %u\n", as); + zlog_ferr(BGP_ERR_EVPN_AS_MISMATCH, + "BGP is already running; AS is %u\n", as); return -1; case BGP_ERR_INSTANCE_MISMATCH: - zlog_err("BGP instance name and AS number mismatch\n"); + zlog_ferr(BGP_ERR_EVPN_INSTANCE_MISMATCH, + "BGP instance name and AS number mismatch\n"); return -1; } @@ -5330,7 +5364,8 @@ int bgp_evpn_local_l3vni_del(vni_t l3vni, vrf_id_t vrf_id) bgp_vrf = bgp_lookup_by_vrf_id(vrf_id); if (!bgp_vrf) { - zlog_err( + zlog_ferr( + BGP_ERR_NO_DFLT, "Cannot process L3VNI %u Del - Could not find BGP instance", l3vni); return -1; @@ -5338,7 +5373,8 @@ int bgp_evpn_local_l3vni_del(vni_t l3vni, vrf_id_t vrf_id) bgp_def = bgp_get_default(); if (!bgp_def) { - zlog_err( + zlog_ferr( + BGP_ERR_NO_DFLT, "Cannot process L3VNI %u Del - Could not find default BGP instance", l3vni); return -1; @@ -5468,7 +5504,8 @@ int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni, if (!vpn) { vpn = bgp_evpn_new(bgp, vni, originator_ip, tenant_vrf_id); if (!vpn) { - zlog_err( + zlog_ferr( + BGP_ERR_VNI, "%u: Failed to allocate VNI entry for VNI %u - at Add", bgp->vrf_id, vni); return -1; @@ -5491,8 +5528,9 @@ int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni, /* Create EVPN type-3 route and schedule for processing. */ build_evpn_type3_prefix(&p, vpn->originator_ip); if (update_evpn_route(bgp, vpn, &p, 0)) { - zlog_err("%u: Type3 route creation failure for VNI %u", - bgp->vrf_id, vni); + zlog_ferr(BGP_ERR_EVPN_ROUTE_CREATE, + "%u: Type3 route creation failure for VNI %u", + bgp->vrf_id, vni); return -1; } @@ -5520,7 +5558,8 @@ int bgp_evpn_local_es_del(struct bgp *bgp, struct evpnes *es = NULL; if (!bgp->esihash) { - zlog_err("%u: ESI hash not yet created", bgp->vrf_id); + zlog_ferr(BGP_ERR_ES_CREATE, "%u: ESI hash not yet created", + bgp->vrf_id); return -1; } @@ -5556,7 +5595,8 @@ int bgp_evpn_local_es_add(struct bgp *bgp, struct prefix_evpn p; if (!bgp->esihash) { - zlog_err("%u: ESI hash not yet created", bgp->vrf_id); + zlog_ferr(BGP_ERR_ES_CREATE, "%u: ESI hash not yet created", + bgp->vrf_id); return -1; } @@ -5565,7 +5605,8 @@ int bgp_evpn_local_es_add(struct bgp *bgp, if (!es) { es = bgp_evpn_es_new(bgp, esi, originator_ip); if (!es) { - zlog_err( + zlog_ferr( + BGP_ERR_ES_CREATE, "%u: Failed to allocate ES entry for ESI %s - at Local ES Add", bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf))); return -1; @@ -5576,8 +5617,9 @@ int bgp_evpn_local_es_add(struct bgp *bgp, build_evpn_type4_prefix(&p, esi, originator_ip->ipaddr_v4); if (update_evpn_type4_route(bgp, es, &p)) { - zlog_err("%u: Type4 route creation failure for ESI %s", - bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf))); + zlog_ferr(BGP_ERR_EVPN_ROUTE_CREATE, + "%u: Type4 route creation failure for ESI %s", + bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf))); return -1; } diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index b45c1a99db..d883598493 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -35,6 +35,7 @@ #include "bgpd/bgp_evpn_private.h" #include "bgpd/bgp_zebra.h" #include "bgpd/bgp_vty.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_ecommunity.h" #define SHOW_DISPLAY_STANDARD 0 @@ -1892,7 +1893,8 @@ static struct bgpevpn *evpn_create_update_vni(struct bgp *bgp, vni_t vni) */ vpn = bgp_evpn_new(bgp, vni, bgp->router_id, 0); if (!vpn) { - zlog_err( + zlog_ferr( + BGP_ERR_VNI, "%u: Failed to allocate VNI entry for VNI %u - at Config", bgp->vrf_id, vni); return NULL; diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index 2fd63531db..dc51aa981d 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -39,6 +39,7 @@ #include "bgpd/bgpd.h" #include "bgpd/bgp_attr.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_fsm.h" #include "bgpd/bgp_packet.h" #include "bgpd/bgp_network.h" @@ -164,7 +165,8 @@ static struct peer *peer_xfer_conn(struct peer *from_peer) * runs in our pthread. */ if (peer->curr) { - zlog_err( + zlog_ferr( + BGP_ERR_PKT_PROCESS, "[%s] Dropping pending packet on connection transfer:", peer->host); uint16_t type = stream_getc_from(peer->curr, @@ -242,7 +244,8 @@ static struct peer *peer_xfer_conn(struct peer *from_peer) } if (bgp_getsockname(peer) < 0) { - zlog_err( + zlog_ferr( + BGP_ERR_SOCKET, "%%bgp_getsockname() failed for %s peer %s fd %d (from_peer fd %d)", (CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER) ? "accept" @@ -254,8 +257,10 @@ static struct peer *peer_xfer_conn(struct peer *from_peer) } if (from_peer->status > Active) { if (bgp_getsockname(from_peer) < 0) { - zlog_err( + zlog_ferr( + BGP_ERR_SOCKET, "%%bgp_getsockname() failed for %s from_peer %s fd %d (peer fd %d)", + (CHECK_FLAG(from_peer->sflags, PEER_STATUS_ACCEPT_PEER) ? "accept" @@ -1280,15 +1285,17 @@ static int bgp_connect_check(struct thread *thread) static int bgp_connect_success(struct peer *peer) { if (peer->fd < 0) { - zlog_err("bgp_connect_success peer's fd is negative value %d", - peer->fd); + zlog_ferr(BGP_ERR_CONNECT, + "bgp_connect_success peer's fd is negative value %d", + peer->fd); bgp_stop(peer); return -1; } if (bgp_getsockname(peer) < 0) { - zlog_err("%s: bgp_getsockname(): failed for peer %s, fd %d", - __FUNCTION__, peer->host, peer->fd); + zlog_ferr(BGP_ERR_SOCKET, + "%s: bgp_getsockname(): failed for peer %s, fd %d", + __FUNCTION__, peer->host, peer->fd); bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, 0); /* internal error */ bgp_writes_on(peer); @@ -1346,10 +1353,10 @@ int bgp_start(struct peer *peer) if (BGP_PEER_START_SUPPRESSED(peer)) { if (bgp_debug_neighbor_events(peer)) - zlog_err( - "%s [FSM] Trying to start suppressed peer" - " - this is never supposed to happen!", - peer->host); + zlog_ferr(BGP_ERR_FSM, + "%s [FSM] Trying to start suppressed peer" + " - this is never supposed to happen!", + peer->host); return -1; } @@ -1381,7 +1388,8 @@ int bgp_start(struct peer *peer) if (peer->bgp->vrf_id == VRF_UNKNOWN) { if (bgp_debug_neighbor_events(peer)) - zlog_err( + zlog_ferr( + BGP_ERR_FSM, "%s [FSM] In a VRF that is not initialised yet", peer->host); return -1; @@ -1435,8 +1443,9 @@ int bgp_start(struct peer *peer) "%s [FSM] Non blocking connect waiting result, fd %d", peer->host, peer->fd); if (peer->fd < 0) { - zlog_err("bgp_start peer's fd is negative value %d", - peer->fd); + zlog_ferr(BGP_ERR_FSM, + "bgp_start peer's fd is negative value %d", + peer->fd); return -1; } /* @@ -1482,8 +1491,9 @@ static int bgp_fsm_open(struct peer *peer) peer and change to Idle status. */ static int bgp_fsm_event_error(struct peer *peer) { - zlog_err("%s [FSM] unexpected packet received in state %s", peer->host, - lookup_msg(bgp_status_msg, peer->status, NULL)); + zlog_ferr(BGP_ERR_FSM, + "%s [FSM] unexpected packet received in state %s", peer->host, + lookup_msg(bgp_status_msg, peer->status, NULL)); return bgp_stop_with_notify(peer, BGP_NOTIFY_FSM_ERR, 0); } @@ -1515,7 +1525,7 @@ static int bgp_establish(struct peer *peer) other = peer->doppelganger; peer = peer_xfer_conn(peer); if (!peer) { - zlog_err("%%Neighbor failed in xfer_conn"); + zlog_ferr(BGP_ERR_CONNECT, "%%Neighbor failed in xfer_conn"); return -1; } @@ -1674,7 +1684,8 @@ static int bgp_fsm_update(struct peer *peer) /* This is empty event. */ static int bgp_ignore(struct peer *peer) { - zlog_err( + zlog_ferr( + BGP_ERR_FSM, "%s [FSM] Ignoring event %s in state %s, prior events %s, %s, fd %d", peer->host, bgp_event_str[peer->cur_event], lookup_msg(bgp_status_msg, peer->status, NULL), @@ -1686,7 +1697,8 @@ static int bgp_ignore(struct peer *peer) /* This is to handle unexpected events.. */ static int bgp_fsm_exeption(struct peer *peer) { - zlog_err( + zlog_ferr( + BGP_ERR_FSM, "%s [FSM] Unexpected event %s in state %s, prior events %s, %s, fd %d", peer->host, bgp_event_str[peer->cur_event], lookup_msg(bgp_status_msg, peer->status, NULL), @@ -1960,7 +1972,8 @@ int bgp_event_update(struct peer *peer, int event) * code. */ if (!dyn_nbr && !passive_conn && peer->bgp) { - zlog_err( + zlog_ferr( + BGP_ERR_FSM, "%s [FSM] Failure handling event %s in state %s, " "prior events %s, %s, fd %d", peer->host, bgp_event_str[peer->cur_event], diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c index c8d5b1daa1..87ba4af018 100644 --- a/bgpd/bgp_io.c +++ b/bgpd/bgp_io.c @@ -35,6 +35,7 @@ #include "bgpd/bgp_io.h" #include "bgpd/bgp_debug.h" // for bgp_debug_neighbor_events, bgp_type_str +#include "bgpd/bgp_errors.h" // for expanded error reference information #include "bgpd/bgp_fsm.h" // for BGP_EVENT_ADD, bgp_event #include "bgpd/bgp_packet.h" // for bgp_notify_send_with_data, bgp_notify... #include "bgpd/bgpd.h" // for peer, BGP_MARKER_SIZE, bgp_master, bm @@ -401,8 +402,9 @@ static uint16_t bgp_read(struct peer *peer) SET_FLAG(status, BGP_IO_TRANS_ERR); /* Fatal error; tear down session */ } else if (nbytes < 0) { - zlog_err("%s [Error] bgp_read_packet error: %s", peer->host, - safe_strerror(errno)); + zlog_ferr(BGP_ERR_UPDATE_RCV, + "%s [Error] bgp_read_packet error: %s", peer->host, + safe_strerror(errno)); if (peer->status == Established) { if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_MODE)) { diff --git a/bgpd/bgp_label.c b/bgpd/bgp_label.c index 8a051b7ff0..6969c262af 100644 --- a/bgpd/bgp_label.c +++ b/bgpd/bgp_label.c @@ -38,6 +38,7 @@ #include "bgpd/bgp_label.h" #include "bgpd/bgp_packet.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" extern struct zclient *zclient; @@ -244,7 +245,8 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr, /* sanity check against packet data */ if ((pnt + psize) > lim) { - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s [Error] Update packet error / L-U (prefix length %d exceeds packet size %u)", peer->host, prefixlen, (uint)(lim - pnt)); return -1; @@ -256,10 +258,10 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr, /* There needs to be at least one label */ if (prefixlen < 24) { - zlog_err( - "%s [Error] Update packet error" - " (wrong label length %d)", - peer->host, prefixlen); + zlog_ferr(BGP_ERR_UPDATE_RCV, + "%s [Error] Update packet error" + " (wrong label length %d)", + peer->host, prefixlen); bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_INVAL_NETWORK); return -1; @@ -284,7 +286,8 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr, * be logged locally, and the prefix SHOULD be * ignored. */ - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s: IPv4 labeled-unicast NLRI is multicast address %s, ignoring", peer->host, inet_ntoa(p.u.prefix4)); continue; @@ -296,7 +299,8 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr, if (IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)) { char buf[BUFSIZ]; - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s: IPv6 labeled-unicast NLRI is link-local address %s, ignoring", peer->host, inet_ntop(AF_INET6, &p.u.prefix6, buf, @@ -308,7 +312,8 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr, if (IN6_IS_ADDR_MULTICAST(&p.u.prefix6)) { char buf[BUFSIZ]; - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s: IPv6 unicast NLRI is multicast address %s, ignoring", peer->host, inet_ntop(AF_INET6, &p.u.prefix6, buf, @@ -331,7 +336,8 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr, /* Packet length consistency check. */ if (pnt != lim) { - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s [Error] Update packet error / L-U (%zu data remaining after parsing)", peer->host, lim - pnt); return -1; diff --git a/bgpd/bgp_labelpool.c b/bgpd/bgp_labelpool.c index e052d6061e..dd3b8d5b8e 100644 --- a/bgpd/bgp_labelpool.c +++ b/bgpd/bgp_labelpool.c @@ -34,6 +34,7 @@ #include "bgpd/bgpd.h" #include "bgpd/bgp_labelpool.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" /* * Definitions and external declarations. @@ -126,7 +127,8 @@ static wq_item_status lp_cbq_docallback(struct work_queue *wq, void *data) if (lcbq->label == MPLS_LABEL_NONE) { /* shouldn't happen */ - zlog_err("%s: error: label==MPLS_LABEL_NONE", __func__); + zlog_ferr(BGP_ERR_LABEL, "%s: error: label==MPLS_LABEL_NONE", + __func__); return WQ_SUCCESS; } @@ -336,8 +338,9 @@ void bgp_lp_get( if (rc) { /* shouldn't happen */ - zlog_err("%s: can't insert new LCB into ledger list", - __func__); + zlog_ferr(BGP_ERR_LABEL, + "%s: can't insert new LCB into ledger list", + __func__); XFREE(MTYPE_BGP_LABEL_CB, lcb); return; } @@ -424,8 +427,9 @@ void bgp_lp_event_chunk(uint8_t keep, uint32_t first, uint32_t last) struct lp_fifo *lf; if (last < first) { - zlog_err("%s: zebra label chunk invalid: first=%u, last=%u", - __func__, first, last); + zlog_ferr(BGP_ERR_LABEL, + "%s: zebra label chunk invalid: first=%u, last=%u", + __func__, first, last); return; } diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index 2327e262a1..7cc46e020d 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -54,6 +54,7 @@ #include "bgpd/bgp_regex.h" #include "bgpd/bgp_clist.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_filter.h" #include "bgpd/bgp_zebra.h" #include "bgpd/bgp_packet.h" @@ -384,7 +385,8 @@ int main(int argc, char **argv) multipath_num = atoi(optarg); if (multipath_num > MULTIPATH_NUM || multipath_num <= 0) { - zlog_err( + zlog_ferr( + BGP_ERR_MULTIPATH, "Multipath Number specified must be less than %d and greater than 0", MULTIPATH_NUM); return 1; diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index f72104dd33..6c26ba782a 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -33,6 +33,7 @@ #include "bgpd/bgpd.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_table.h" #include "bgpd/bgp_route.h" #include "bgpd/bgp_attr.h" @@ -150,7 +151,8 @@ int bgp_nlri_parse_vpn(struct peer *peer, struct attr *attr, psize = PSIZE(prefixlen); if (prefixlen < VPN_PREFIXLEN_MIN_BYTES * 8) { - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s [Error] Update packet error / VPN (prefix length %d less than VPN min length)", peer->host, prefixlen); return -1; @@ -158,7 +160,8 @@ int bgp_nlri_parse_vpn(struct peer *peer, struct attr *attr, /* sanity check against packet data */ if ((pnt + psize) > lim) { - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s [Error] Update packet error / VPN (prefix length %d exceeds packet size %u)", peer->host, prefixlen, (uint)(lim - pnt)); return -1; @@ -166,7 +169,8 @@ int bgp_nlri_parse_vpn(struct peer *peer, struct attr *attr, /* sanity check against storage for the IP address portion */ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t)sizeof(p.u)) { - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s [Error] Update packet error / VPN (psize %d exceeds storage size %zu)", peer->host, prefixlen - VPN_PREFIXLEN_MIN_BYTES * 8, @@ -176,7 +180,8 @@ int bgp_nlri_parse_vpn(struct peer *peer, struct attr *attr, /* Sanity check against max bitlen of the address family */ if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen(&p)) { - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s [Error] Update packet error / VPN (psize %d exceeds family (%u) max byte len %u)", peer->host, prefixlen - VPN_PREFIXLEN_MIN_BYTES * 8, @@ -213,7 +218,8 @@ int bgp_nlri_parse_vpn(struct peer *peer, struct attr *attr, #endif default: - zlog_err("Unknown RD type %d", type); + zlog_ferr(BGP_ERR_UPDATE_RCV, "Unknown RD type %d", + type); break; /* just report */ } @@ -235,7 +241,8 @@ int bgp_nlri_parse_vpn(struct peer *peer, struct attr *attr, } /* Packet length consistency check. */ if (pnt != lim) { - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s [Error] Update packet error / VPN (%zu data remaining after parsing)", peer->host, lim - pnt); return -1; @@ -359,8 +366,10 @@ int vpn_leak_label_callback( return 0; } /* Shouldn't happen: different label allocation */ - zlog_err("%s: %s had label %u but got new assignment %u", - __func__, vp->bgp->name_pretty, vp->tovpn_label, label); + zlog_ferr(BGP_ERR_LABEL, + "%s: %s had label %u but got new assignment %u", + __func__, vp->bgp->name_pretty, vp->tovpn_label, + label); /* use new one */ } diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index 20853c8af0..168e2c9b81 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -42,6 +42,7 @@ #include "bgpd/bgp_fsm.h" #include "bgpd/bgp_attr.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_network.h" extern struct zebra_privs_t bgpd_privs; @@ -97,14 +98,16 @@ static int bgp_md5_set_connect(int socket, union sockunion *su, #if HAVE_DECL_TCP_MD5SIG if (bgpd_privs.change(ZPRIVS_RAISE)) { - zlog_err("%s: could not raise privs", __func__); + zlog_ferr(BGP_ERR_PRIVILEGES, "%s: could not raise privs", + __func__); return ret; } ret = bgp_md5_set_socket(socket, su, password); if (bgpd_privs.change(ZPRIVS_LOWER)) - zlog_err("%s: could not lower privs", __func__); + zlog_ferr(BGP_ERR_PRIVILEGES, "%s: could not lower privs", + __func__); #endif /* HAVE_TCP_MD5SIG */ return ret; @@ -117,7 +120,8 @@ static int bgp_md5_set_password(struct peer *peer, const char *password) struct bgp_listener *listener; if (bgpd_privs.change(ZPRIVS_RAISE)) { - zlog_err("%s: could not raise privs", __func__); + zlog_ferr(BGP_ERR_PRIVILEGES, "%s: could not raise privs", + __func__); return -1; } @@ -133,7 +137,8 @@ static int bgp_md5_set_password(struct peer *peer, const char *password) } if (bgpd_privs.change(ZPRIVS_LOWER)) - zlog_err("%s: could not lower privs", __func__); + zlog_ferr(BGP_ERR_PRIVILEGES, "%s: could not lower privs", + __func__); return ret; } @@ -159,10 +164,12 @@ int bgp_set_socket_ttl(struct peer *peer, int bgp_sock) if (!peer->gtsm_hops && (peer_sort(peer) == BGP_PEER_EBGP)) { ret = sockopt_ttl(peer->su.sa.sa_family, bgp_sock, peer->ttl); if (ret) { - zlog_err( + zlog_ferr( + BGP_ERR_SOCKET, "%s: Can't set TxTTL on peer (rtrid %s) socket, err = %d", - __func__, inet_ntop(AF_INET, &peer->remote_id, - buf, sizeof(buf)), + __func__, + inet_ntop(AF_INET, &peer->remote_id, buf, + sizeof(buf)), errno); return ret; } @@ -173,20 +180,24 @@ int bgp_set_socket_ttl(struct peer *peer, int bgp_sock) */ ret = sockopt_ttl(peer->su.sa.sa_family, bgp_sock, MAXTTL); if (ret) { - zlog_err( + zlog_ferr( + BGP_ERR_SOCKET, "%s: Can't set TxTTL on peer (rtrid %s) socket, err = %d", - __func__, inet_ntop(AF_INET, &peer->remote_id, - buf, sizeof(buf)), + __func__, + inet_ntop(AF_INET, &peer->remote_id, buf, + sizeof(buf)), errno); return ret; } ret = sockopt_minttl(peer->su.sa.sa_family, bgp_sock, MAXTTL + 1 - peer->gtsm_hops); if (ret) { - zlog_err( + zlog_ferr( + BGP_ERR_SOCKET, "%s: Can't set MinTTL on peer (rtrid %s) socket, err = %d", - __func__, inet_ntop(AF_INET, &peer->remote_id, - buf, sizeof(buf)), + __func__, + inet_ntop(AF_INET, &peer->remote_id, buf, + sizeof(buf)), errno); return ret; } @@ -227,8 +238,10 @@ static int bgp_get_instance_for_inc_conn(int sock, struct bgp **bgp_inst) rc = getsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, name, &name_len); if (rc != 0) { #if defined(HAVE_CUMULUS) - zlog_err("[Error] BGP SO_BINDTODEVICE get failed (%s), sock %d", - safe_strerror(errno), sock); + zlog_ferr( + BGP_ERR_SOCKET, + "[Error] BGP SO_BINDTODEVICE get failed (%s), sock %d", + safe_strerror(errno), sock); return -1; #endif } @@ -283,7 +296,8 @@ static int bgp_accept(struct thread *thread) /* Register accept thread. */ accept_sock = THREAD_FD(thread); if (accept_sock < 0) { - zlog_err("accept_sock is nevative value %d", accept_sock); + zlog_ferr(BGP_ERR_SOCKET, "accept_sock is nevative value %d", + accept_sock); return -1; } listener->thread = NULL; @@ -294,8 +308,9 @@ static int bgp_accept(struct thread *thread) /* Accept client connection. */ bgp_sock = sockunion_accept(accept_sock, &su); if (bgp_sock < 0) { - zlog_err("[Error] BGP socket accept failed (%s)", - safe_strerror(errno)); + zlog_ferr(BGP_ERR_SOCKET, + "[Error] BGP socket accept failed (%s)", + safe_strerror(errno)); return -1; } set_nonblocking(bgp_sock); @@ -570,13 +585,15 @@ int bgp_connect(struct peer *peer) #ifdef IPTOS_PREC_INTERNETCONTROL if (bgpd_privs.change(ZPRIVS_RAISE)) - zlog_err("%s: could not raise privs", __func__); + zlog_ferr(BGP_ERR_PRIVILEGES, "%s: could not raise privs", + __func__); if (sockunion_family(&peer->su) == AF_INET) setsockopt_ipv4_tos(peer->fd, IPTOS_PREC_INTERNETCONTROL); else if (sockunion_family(&peer->su) == AF_INET6) setsockopt_ipv6_tclass(peer->fd, IPTOS_PREC_INTERNETCONTROL); if (bgpd_privs.change(ZPRIVS_LOWER)) - zlog_err("%s: could not lower privs", __func__); + zlog_ferr(BGP_ERR_PRIVILEGES, "%s: could not lower privs", + __func__); #endif if (peer->password) @@ -624,7 +641,8 @@ int bgp_getsockname(struct peer *peer) if (bgp_nexthop_set(peer->su_local, peer->su_remote, &peer->nexthop, peer)) { #if defined(HAVE_CUMULUS) - zlog_err( + zlog_ferr( + BGP_ERR_NH_UPD, "%s: nexthop_set failed, resetting connection - intf %p", peer->host, peer->nexthop.ifp); return -1; @@ -644,7 +662,8 @@ static int bgp_listener(int sock, struct sockaddr *sa, socklen_t salen, sockopt_reuseport(sock); if (bgpd_privs.change(ZPRIVS_RAISE)) - zlog_err("%s: could not raise privs", __func__); + zlog_ferr(BGP_ERR_PRIVILEGES, "%s: could not raise privs", + __func__); #ifdef IPTOS_PREC_INTERNETCONTROL if (sa->sa_family == AF_INET) @@ -658,16 +677,17 @@ static int bgp_listener(int sock, struct sockaddr *sa, socklen_t salen, ret = bind(sock, sa, salen); en = errno; if (bgpd_privs.change(ZPRIVS_LOWER)) - zlog_err("%s: could not lower privs", __func__); + zlog_ferr(BGP_ERR_PRIVILEGES, "%s: could not lower privs", + __func__); if (ret < 0) { - zlog_err("bind: %s", safe_strerror(en)); + zlog_ferr(BGP_ERR_SOCKET, "bind: %s", safe_strerror(en)); return ret; } ret = listen(sock, SOMAXCONN); if (ret < 0) { - zlog_err("listen: %s", safe_strerror(errno)); + zlog_ferr(BGP_ERR_SOCKET, "listen: %s", safe_strerror(errno)); return ret; } @@ -710,7 +730,7 @@ int bgp_socket(struct bgp *bgp, unsigned short port, const char *address) if (bgpd_privs.change(ZPRIVS_LOWER)) zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (ret != 0) { - zlog_err("getaddrinfo: %s", gai_strerror(ret)); + zlog_ferr(BGP_ERR_SOCKET, "getaddrinfo: %s", gai_strerror(ret)); return -1; } @@ -730,7 +750,8 @@ int bgp_socket(struct bgp *bgp, unsigned short port, const char *address) if (bgpd_privs.change(ZPRIVS_LOWER)) zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (sock < 0) { - zlog_err("socket: %s", safe_strerror(errno)); + zlog_ferr(BGP_ERR_SOCKET, "socket: %s", + safe_strerror(errno)); continue; } @@ -747,10 +768,12 @@ int bgp_socket(struct bgp *bgp, unsigned short port, const char *address) } freeaddrinfo(ainfo_save); if (count == 0 && bgp->inst_type != BGP_INSTANCE_TYPE_VRF) { - zlog_err( + zlog_ferr( + BGP_ERR_SOCKET, "%s: no usable addresses please check other programs usage of specified port %d", __func__, port); - zlog_err("%s: Program cannot continue", __func__); + zlog_ferr(BGP_ERR_SOCKET, "%s: Program cannot continue", + __func__); exit(-1); } diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index 8b6ff3fa22..d8d337930b 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -38,6 +38,7 @@ #include "bgpd/bgp_attr.h" #include "bgpd/bgp_nexthop.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_nht.h" #include "bgpd/bgp_fsm.h" #include "bgpd/bgp_zebra.h" @@ -343,7 +344,8 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id) bgp = bgp_lookup_by_vrf_id(vrf_id); if (!bgp) { - zlog_err( + zlog_ferr( + BGP_ERR_NH_UPD, "parse nexthop update: instance not found for vrf_id %u", vrf_id); return; diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c index da90bbd67d..af3275d3e6 100644 --- a/bgpd/bgp_open.c +++ b/bgpd/bgp_open.c @@ -34,6 +34,7 @@ #include "bgpd/bgpd.h" #include "bgpd/bgp_attr.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_fsm.h" #include "bgpd/bgp_packet.h" #include "bgpd/bgp_open.h" @@ -520,8 +521,9 @@ static as_t bgp_capability_as4(struct peer *peer, struct capability_header *hdr) SET_FLAG(peer->cap, PEER_CAP_AS4_RCV); if (hdr->length != CAPABILITY_CODE_AS4_LEN) { - zlog_err("%s AS4 capability has incorrect data length %d", - peer->host, hdr->length); + zlog_ferr(BGP_ERR_PKT_OPEN, + "%s AS4 capability has incorrect data length %d", + peer->host, hdr->length); return 0; } @@ -1184,10 +1186,10 @@ int bgp_open_option_parse(struct peer *peer, uint8_t length, int *mp_capability) && !peer->afc_nego[AFI_IP6][SAFI_ENCAP] && !peer->afc_nego[AFI_IP6][SAFI_FLOWSPEC] && !peer->afc_nego[AFI_L2VPN][SAFI_EVPN]) { - zlog_err( - "%s [Error] Configured AFI/SAFIs do not " - "overlap with received MP capabilities", - peer->host); + zlog_ferr(BGP_ERR_PKT_OPEN, + "%s [Error] Configured AFI/SAFIs do not " + "overlap with received MP capabilities", + peer->host); if (error != error_data) bgp_notify_send_with_data( diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index 446dc5ac12..f5964b9abd 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -42,6 +42,7 @@ #include "bgpd/bgp_dump.h" #include "bgpd/bgp_attr.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_fsm.h" #include "bgpd/bgp_route.h" #include "bgpd/bgp_packet.h" @@ -1089,8 +1090,9 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) /* Just in case we have a silly peer who sends AS4 capability set to 0 */ if (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV) && !as4) { - zlog_err("%s bad OPEN, got AS4 capability, but AS4 set to 0", - peer->host); + zlog_ferr(BGP_ERR_PKT_OPEN, + "%s bad OPEN, got AS4 capability, but AS4 set to 0", + peer->host); bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, BGP_NOTIFY_OPEN_BAD_PEER_AS, notify_data_remote_as4, 4); @@ -1103,7 +1105,8 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) * BGP_AS_TRANS, for some unknown reason. */ if (as4 == BGP_AS_TRANS) { - zlog_err( + zlog_ferr( + BGP_ERR_PKT_OPEN, "%s [AS4] NEW speaker using AS_TRANS for AS4, not allowed", peer->host); bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR, @@ -1132,7 +1135,8 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) if (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV) && as4 != remote_as) { /* raise error, log this, close session */ - zlog_err( + zlog_ferr( + BGP_ERR_PKT_OPEN, "%s bad OPEN, got AS4 capability, but remote_as %u" " mismatch with 16bit 'myasn' %u in open", peer->host, as4, remote_as); @@ -1299,8 +1303,9 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) /* Get sockname. */ if ((ret = bgp_getsockname(peer)) < 0) { - zlog_err("%s: bgp_getsockname() failed for peer: %s", - __FUNCTION__, peer->host); + zlog_ferr(BGP_ERR_SOCKET, + "%s: bgp_getsockname() failed for peer: %s", + __FUNCTION__, peer->host); return BGP_Stop; } @@ -1313,7 +1318,8 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) || peer->afc_nego[AFI_IP][SAFI_ENCAP]) { if (!peer->nexthop.v4.s_addr) { #if defined(HAVE_CUMULUS) - zlog_err( + zlog_ferr( + BGP_ERR_SND_FAIL, "%s: No local IPv4 addr resetting connection, fd %d", peer->host, peer->fd); bgp_notify_send(peer, BGP_NOTIFY_CEASE, @@ -1329,7 +1335,8 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size) || peer->afc_nego[AFI_IP6][SAFI_ENCAP]) { if (IN6_IS_ADDR_UNSPECIFIED(&peer->nexthop.v6_global)) { #if defined(HAVE_CUMULUS) - zlog_err( + zlog_ferr( + BGP_ERR_SND_FAIL, "%s: No local IPv6 addr resetting connection, fd %d", peer->host, peer->fd); bgp_notify_send(peer, BGP_NOTIFY_CEASE, @@ -1391,9 +1398,10 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) /* Status must be Established. */ if (peer->status != Established) { - zlog_err("%s [FSM] Update packet received under status %s", - peer->host, - lookup_msg(bgp_status_msg, peer->status, NULL)); + zlog_ferr(BGP_ERR_INVALID_STATUS, + "%s [FSM] Update packet received under status %s", + peer->host, + lookup_msg(bgp_status_msg, peer->status, NULL)); bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, 0); return BGP_Stop; } @@ -1414,10 +1422,10 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) Attribute Length + 23 exceeds the message Length), then the Error Subcode is set to Malformed Attribute List. */ if (stream_pnt(s) + 2 > end) { - zlog_err( - "%s [Error] Update packet error" - " (packet length is short for unfeasible length)", - peer->host); + zlog_ferr(BGP_ERR_UPDATE_RCV, + "%s [Error] Update packet error" + " (packet length is short for unfeasible length)", + peer->host); bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_MAL_ATTR); return BGP_Stop; @@ -1428,10 +1436,10 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) /* Unfeasible Route Length check. */ if (stream_pnt(s) + withdraw_len > end) { - zlog_err( - "%s [Error] Update packet error" - " (packet unfeasible length overflow %d)", - peer->host, withdraw_len); + zlog_ferr(BGP_ERR_UPDATE_RCV, + "%s [Error] Update packet error" + " (packet unfeasible length overflow %d)", + peer->host, withdraw_len); bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR, BGP_NOTIFY_UPDATE_MAL_ATTR); return BGP_Stop; @@ -1502,7 +1510,8 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) ret = bgp_dump_attr(&attr, peer->rcvd_attr_str, BUFSIZ); if (attr_parse_ret == BGP_ATTR_PARSE_WITHDRAW) - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s rcvd UPDATE with errors in attr(s)!! Withdrawing route.", peer->host); @@ -1562,7 +1571,8 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size) } if (nlri_ret < 0) { - zlog_err("%s [Error] Error parsing NLRI", peer->host); + zlog_ferr(BGP_ERR_UPDATE_RCV, + "%s [Error] Error parsing NLRI", peer->host); if (peer->status == Established) bgp_notify_send( peer, BGP_NOTIFY_UPDATE_ERR, @@ -1733,8 +1743,9 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) /* If peer does not have the capability, send notification. */ if (!CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_ADV)) { - zlog_err("%s [Error] BGP route refresh is not enabled", - peer->host); + zlog_ferr(BGP_ERR_NO_CAP, + "%s [Error] BGP route refresh is not enabled", + peer->host); bgp_notify_send(peer, BGP_NOTIFY_HEADER_ERR, BGP_NOTIFY_HEADER_BAD_MESTYPE); return BGP_Stop; @@ -1742,7 +1753,8 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) /* Status must be Established. */ if (peer->status != Established) { - zlog_err( + zlog_ferr( + BGP_ERR_INVALID_STATUS, "%s [Error] Route refresh packet received under status %s", peer->host, lookup_msg(bgp_status_msg, peer->status, NULL)); @@ -2122,8 +2134,9 @@ int bgp_capability_receive(struct peer *peer, bgp_size_t size) /* If peer does not have the capability, send notification. */ if (!CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV)) { - zlog_err("%s [Error] BGP dynamic capability is not enabled", - peer->host); + zlog_ferr(BGP_ERR_NO_CAP, + "%s [Error] BGP dynamic capability is not enabled", + peer->host); bgp_notify_send(peer, BGP_NOTIFY_HEADER_ERR, BGP_NOTIFY_HEADER_BAD_MESTYPE); return BGP_Stop; @@ -2131,7 +2144,8 @@ int bgp_capability_receive(struct peer *peer, bgp_size_t size) /* Status must be Established. */ if (peer->status != Established) { - zlog_err( + zlog_ferr( + BGP_ERR_NO_CAP, "%s [Error] Dynamic capability packet received under status %s", peer->host, lookup_msg(bgp_status_msg, peer->status, NULL)); @@ -2212,7 +2226,8 @@ int bgp_process_packet(struct thread *thread) memory_order_relaxed); mprc = bgp_open_receive(peer, size); if (mprc == BGP_Stop) - zlog_err( + zlog_ferr( + BGP_ERR_PKT_OPEN, "%s: BGP OPEN receipt failed for peer: %s", __FUNCTION__, peer->host); break; @@ -2222,7 +2237,8 @@ int bgp_process_packet(struct thread *thread) peer->readtime = monotime(NULL); mprc = bgp_update_receive(peer, size); if (mprc == BGP_Stop) - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s: BGP UPDATE receipt failed for peer: %s", __FUNCTION__, peer->host); break; @@ -2231,7 +2247,8 @@ int bgp_process_packet(struct thread *thread) memory_order_relaxed); mprc = bgp_notify_receive(peer, size); if (mprc == BGP_Stop) - zlog_err( + zlog_ferr( + BGP_ERR_NOTIFY_RCV, "%s: BGP NOTIFY receipt failed for peer: %s", __FUNCTION__, peer->host); break; @@ -2241,7 +2258,8 @@ int bgp_process_packet(struct thread *thread) memory_order_relaxed); mprc = bgp_keepalive_receive(peer, size); if (mprc == BGP_Stop) - zlog_err( + zlog_ferr( + BGP_ERR_KEEP_RCV, "%s: BGP KEEPALIVE receipt failed for peer: %s", __FUNCTION__, peer->host); break; @@ -2251,7 +2269,8 @@ int bgp_process_packet(struct thread *thread) memory_order_relaxed); mprc = bgp_route_refresh_receive(peer, size); if (mprc == BGP_Stop) - zlog_err( + zlog_ferr( + BGP_ERR_RFSH_RCV, "%s: BGP ROUTEREFRESH receipt failed for peer: %s", __FUNCTION__, peer->host); break; @@ -2260,7 +2279,8 @@ int bgp_process_packet(struct thread *thread) memory_order_relaxed); mprc = bgp_capability_receive(peer, size); if (mprc == BGP_Stop) - zlog_err( + zlog_ferr( + BGP_ERR_CAP_RCV, "%s: BGP CAPABILITY receipt failed for peer: %s", __FUNCTION__, peer->host); break; diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index d0dbb4221d..1cf166607a 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -44,6 +44,7 @@ #include "bgpd/bgp_route.h" #include "bgpd/bgp_attr.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_aspath.h" #include "bgpd/bgp_regex.h" #include "bgpd/bgp_community.h" @@ -4202,8 +4203,9 @@ int bgp_nlri_parse_ip(struct peer *peer, struct attr *attr, /* Prefix length check. */ if (p.prefixlen > prefix_blen(&p) * 8) { - zlog_err( - "%s [Error] Update packet error (wrong perfix length %d for afi %u)", + zlog_ferr( + BGP_ERR_UPDATE_RCV, + "%s [Error] Update packet error (wrong prefix length %d for afi %u)", peer->host, p.prefixlen, packet->afi); return -1; } @@ -4213,7 +4215,8 @@ int bgp_nlri_parse_ip(struct peer *peer, struct attr *attr, /* When packet overflow occur return immediately. */ if (pnt + psize > lim) { - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s [Error] Update packet error (prefix length %d overflows packet)", peer->host, p.prefixlen); return -1; @@ -4222,7 +4225,8 @@ int bgp_nlri_parse_ip(struct peer *peer, struct attr *attr, /* Defensive coding, double-check the psize fits in a struct * prefix */ if (psize > (ssize_t)sizeof(p.u)) { - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s [Error] Update packet error (prefix length %d too large for prefix storage %zu)", peer->host, p.prefixlen, sizeof(p.u)); return -1; @@ -4243,7 +4247,8 @@ int bgp_nlri_parse_ip(struct peer *peer, struct attr *attr, * be logged locally, and the prefix SHOULD be * ignored. */ - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s: IPv4 unicast NLRI is multicast address %s, ignoring", peer->host, inet_ntoa(p.u.prefix4)); continue; @@ -4255,7 +4260,8 @@ int bgp_nlri_parse_ip(struct peer *peer, struct attr *attr, if (IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)) { char buf[BUFSIZ]; - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s: IPv6 unicast NLRI is link-local address %s, ignoring", peer->host, inet_ntop(AF_INET6, &p.u.prefix6, buf, @@ -4266,7 +4272,8 @@ int bgp_nlri_parse_ip(struct peer *peer, struct attr *attr, if (IN6_IS_ADDR_MULTICAST(&p.u.prefix6)) { char buf[BUFSIZ]; - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s: IPv6 unicast NLRI is multicast address %s, ignoring", peer->host, inet_ntop(AF_INET6, &p.u.prefix6, buf, @@ -4295,7 +4302,8 @@ int bgp_nlri_parse_ip(struct peer *peer, struct attr *attr, /* Packet length consistency check. */ if (pnt != lim) { - zlog_err( + zlog_ferr( + BGP_ERR_UPDATE_RCV, "%s [Error] Update packet error (prefix length mismatch with total length)", peer->host); return -1; diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index 6a65f982e0..2e4648a600 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -47,6 +47,7 @@ #include "bgpd/bgpd.h" #include "bgpd/bgp_table.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_fsm.h" #include "bgpd/bgp_advertise.h" #include "bgpd/bgp_packet.h" @@ -1630,8 +1631,9 @@ void update_group_adjust_peer(struct peer_af *paf) if (!updgrp) { updgrp = update_group_create(paf); if (!updgrp) { - zlog_err("couldn't create update group for peer %s", - paf->peer->host); + zlog_ferr(BGP_ERR_UPDGRP_CREATE, + "couldn't create update group for peer %s", + paf->peer->host); return; } } diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index 34ddbfcd14..55253d695b 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -46,6 +46,7 @@ #include "bgpd/bgpd.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_fsm.h" #include "bgpd/bgp_route.h" #include "bgpd/bgp_packet.h" @@ -786,7 +787,8 @@ struct bpacket *subgroup_update_packet(struct update_subgroup *subgrp) * NLRI then * return */ if (space_remaining < space_needed) { - zlog_err( + zlog_ferr( + BGP_ERR_UPDGRP_ATTR_LEN, "u%" PRIu64 ":s%" PRIu64 " attributes too long, cannot send UPDATE", subgrp->update_group->id, subgrp->id); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index e3efbbf252..ddd9aa2301 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -45,6 +45,7 @@ #include "bgpd/bgp_lcommunity.h" #include "bgpd/bgp_damp.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_fsm.h" #include "bgpd/bgp_nexthop.h" #include "bgpd/bgp_open.h" @@ -10754,7 +10755,8 @@ static void bgp_show_all_instances_neighbors_vty(struct vty *vty, for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) { if (use_json) { if (!(json = json_object_new_object())) { - zlog_err( + zlog_ferr( + BGP_ERR_JSON_MEM_ERROR, "Unable to allocate memory for JSON object"); vty_out(vty, "{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n"); diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 9591fe673f..a70af867f9 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -44,6 +44,7 @@ #include "bgpd/bgp_zebra.h" #include "bgpd/bgp_fsm.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_mpath.h" #include "bgpd/bgp_nexthop.h" #include "bgpd/bgp_nht.h" @@ -1077,7 +1078,8 @@ int bgp_zebra_get_table_range(uint32_t chunk_size, return -1; ret = tm_get_table_chunk(zclient, chunk_size, start, end); if (ret < 0) { - zlog_err("BGP: Error getting table chunk %u", chunk_size); + zlog_ferr(BGP_ERR_TABLE_CHUNK, + "BGP: Error getting table chunk %u", chunk_size); return -1; } zlog_info("BGP: Table Manager returns range from chunk %u is [%u %u]", @@ -2381,9 +2383,10 @@ static int bgp_zebra_process_local_macip(int command, struct zclient *zclient, ipa_len = stream_getl(s); if (ipa_len != 0 && ipa_len != IPV4_MAX_BYTELEN && ipa_len != IPV6_MAX_BYTELEN) { - zlog_err("%u:Recv MACIP %s with invalid IP addr length %d", - vrf_id, (command == ZEBRA_MACIP_ADD) ? "Add" : "Del", - ipa_len); + zlog_ferr(BGP_ERR_MACIP_LEN, + "%u:Recv MACIP %s with invalid IP addr length %d", + vrf_id, (command == ZEBRA_MACIP_ADD) ? "Add" : "Del", + ipa_len); return -1; } @@ -2473,11 +2476,13 @@ static void bgp_zebra_process_label_chunk( STREAM_GETL(s, last); if (zclient->redist_default != proto) { - zlog_err("Got LM msg with wrong proto %u", proto); + zlog_ferr(BGP_ERR_LM_ERROR, "Got LM msg with wrong proto %u", + proto); return; } if (zclient->instance != instance) { - zlog_err("Got LM msg with wrong instance %u", proto); + zlog_ferr(BGP_ERR_LM_ERROR, "Got LM msg with wrong instance %u", + proto); return; } @@ -2485,8 +2490,8 @@ static void bgp_zebra_process_label_chunk( first < MPLS_LABEL_UNRESERVED_MIN || last > MPLS_LABEL_UNRESERVED_MAX) { - zlog_err("%s: Invalid Label chunk: %u - %u", - __func__, first, last); + zlog_ferr(BGP_ERR_LM_ERROR, "%s: Invalid Label chunk: %u - %u", + __func__, first, last); return; } if (BGP_DEBUG(zebra, ZEBRA)) { diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 82da0245b5..9d44b148cf 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -52,6 +52,7 @@ #include "bgpd/bgp_route.h" #include "bgpd/bgp_dump.h" #include "bgpd/bgp_debug.h" +#include "bgpd/bgp_errors.h" #include "bgpd/bgp_community.h" #include "bgpd/bgp_attr.h" #include "bgpd/bgp_regex.h" @@ -683,12 +684,6 @@ struct peer_af *peer_af_create(struct peer *peer, afi_t afi, safi_t safi) /* Allocate new peer af */ af = XCALLOC(MTYPE_BGP_PEER_AF, sizeof(struct peer_af)); - if (af == NULL) { - zlog_err("Could not create af structure for peer %s", - peer->host); - return NULL; - } - peer->peer_af_array[afid] = af; af->afi = afi; af->safi = safi; @@ -1809,8 +1804,8 @@ static int peer_activate_af(struct peer *peer, afi_t afi, safi_t safi) int active; if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { - zlog_err("%s was called for peer-group %s", __func__, - peer->host); + zlog_ferr(BGP_ERR_PEER_GROUP, "%s was called for peer-group %s", + __func__, peer->host); return 1; } @@ -1923,8 +1918,8 @@ static int non_peergroup_deactivate_af(struct peer *peer, afi_t afi, safi_t safi) { if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { - zlog_err("%s was called for peer-group %s", __func__, - peer->host); + zlog_ferr(BGP_ERR_PEER_GROUP, "%s was called for peer-group %s", + __func__, peer->host); return 1; } @@ -1936,8 +1931,9 @@ static int non_peergroup_deactivate_af(struct peer *peer, afi_t afi, peer->afc[afi][safi] = 0; if (peer_af_delete(peer, afi, safi) != 0) { - zlog_err("couldn't delete af structure for peer %s", - peer->host); + zlog_ferr(BGP_ERR_PEER_DELETE, + "couldn't delete af structure for peer %s", + peer->host); return 1; } @@ -1986,8 +1982,9 @@ int peer_deactivate(struct peer *peer, afi_t afi, safi_t safi) group = peer->group; if (peer_af_delete(peer, afi, safi) != 0) { - zlog_err("couldn't delete af structure for peer %s", - peer->host); + zlog_ferr(BGP_ERR_PEER_DELETE, + "couldn't delete af structure for peer %s", + peer->host); } for (ALL_LIST_ELEMENTS(group->peer, node, nnode, tmp_peer)) { -- 2.39.5