]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_packet.c
isisd: implement the 'if-state-change' notification
[mirror_frr.git] / bgpd / bgp_packet.c
index 446dc5ac1254dece034006922c2d0afac5e6d719..73a07c8232290e6b8545d11e12408c4f869dd810 100644 (file)
 #include "plist.h"
 #include "queue.h"
 #include "filter.h"
+#include "lib_errors.h"
 
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_table.h"
 #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"
@@ -270,7 +272,7 @@ static void bgp_update_explicit_eors(struct peer *peer)
                                           PEER_STATUS_EOR_RECEIVED)) {
                                if (bgp_debug_neighbor_events(peer))
                                        zlog_debug(
-                                               "   afi %d safi %d didnt receive EOR",
+                                               "   afi %d safi %d didn't receive EOR",
                                                afi, safi);
                                return;
                        }
@@ -1089,7 +1091,8 @@ 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",
+               flog_err(EC_BGP_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,
@@ -1103,7 +1106,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(
+                       flog_err(
+                               EC_BGP_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 +1136,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(
+                       flog_err(
+                               EC_BGP_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 +1304,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);
+               flog_err_sys(EC_LIB_SOCKET,
+                            "%s: bgp_getsockname() failed for peer: %s",
+                            __FUNCTION__, peer->host);
                return BGP_Stop;
        }
 
@@ -1313,7 +1319,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(
+                       flog_err(
+                               EC_BGP_SND_FAIL,
                                "%s: No local IPv4 addr resetting connection, fd %d",
                                peer->host, peer->fd);
                        bgp_notify_send(peer, BGP_NOTIFY_CEASE,
@@ -1329,7 +1336,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(
+                       flog_err(
+                               EC_BGP_SND_FAIL,
                                "%s: No local IPv6 addr resetting connection, fd %d",
                                peer->host, peer->fd);
                        bgp_notify_send(peer, BGP_NOTIFY_CEASE,
@@ -1391,7 +1399,8 @@ 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",
+               flog_err(EC_BGP_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);
@@ -1414,10 +1423,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);
+               flog_err(EC_BGP_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 +1437,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);
+               flog_err(EC_BGP_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;
@@ -1448,9 +1457,9 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size)
 
        /* Attribute total length check. */
        if (stream_pnt(s) + 2 > end) {
-               zlog_warn(
-                       "%s [Error] Packet Error"
-                       " (update packet is short for attribute length)",
+               flog_warn(
+                       EC_BGP_UPDATE_PACKET_SHORT,
+                       "%s [Error] Packet Error (update packet is short for attribute length)",
                        peer->host);
                bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
                                BGP_NOTIFY_UPDATE_MAL_ATTR);
@@ -1462,9 +1471,9 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size)
 
        /* Attribute length check. */
        if (stream_pnt(s) + attribute_len > end) {
-               zlog_warn(
-                       "%s [Error] Packet Error"
-                       " (update packet attribute length overflow %d)",
+               flog_warn(
+                       EC_BGP_UPDATE_PACKET_LONG,
+                       "%s [Error] Packet Error (update packet attribute length overflow %d)",
                        peer->host, attribute_len);
                bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
                                BGP_NOTIFY_UPDATE_MAL_ATTR);
@@ -1502,7 +1511,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(
+                       flog_err(
+                               EC_BGP_UPDATE_RCV,
                                "%s rcvd UPDATE with errors in attr(s)!! Withdrawing route.",
                                peer->host);
 
@@ -1562,7 +1572,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);
+                       flog_err(EC_BGP_UPDATE_RCV,
+                                "%s [Error] Error parsing NLRI", peer->host);
                        if (peer->status == Established)
                                bgp_notify_send(
                                        peer, BGP_NOTIFY_UPDATE_ERR,
@@ -1733,7 +1744,8 @@ 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",
+               flog_err(EC_BGP_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);
@@ -1742,7 +1754,8 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
 
        /* Status must be Established. */
        if (peer->status != Established) {
-               zlog_err(
+               flog_err(
+                       EC_BGP_INVALID_STATUS,
                        "%s [Error] Route refresh packet received under status %s",
                        peer->host,
                        lookup_msg(bgp_status_msg, peer->status, NULL));
@@ -2091,7 +2104,8 @@ static int bgp_capability_msg_parse(struct peer *peer, uint8_t *pnt,
                                        return BGP_Stop;
                        }
                } else {
-                       zlog_warn(
+                       flog_warn(
+                               EC_BGP_UNRECOGNIZED_CAPABILITY,
                                "%s unrecognized capability code: %d - ignored",
                                peer->host, hdr->code);
                }
@@ -2122,7 +2136,8 @@ 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",
+               flog_err(EC_BGP_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);
@@ -2131,7 +2146,8 @@ int bgp_capability_receive(struct peer *peer, bgp_size_t size)
 
        /* Status must be Established. */
        if (peer->status != Established) {
-               zlog_err(
+               flog_err(
+                       EC_BGP_NO_CAP,
                        "%s [Error] Dynamic capability packet received under status %s",
                        peer->host,
                        lookup_msg(bgp_status_msg, peer->status, NULL));
@@ -2212,7 +2228,8 @@ int bgp_process_packet(struct thread *thread)
                                                  memory_order_relaxed);
                        mprc = bgp_open_receive(peer, size);
                        if (mprc == BGP_Stop)
-                               zlog_err(
+                               flog_err(
+                                       EC_BGP_PKT_OPEN,
                                        "%s: BGP OPEN receipt failed for peer: %s",
                                        __FUNCTION__, peer->host);
                        break;
@@ -2222,7 +2239,8 @@ int bgp_process_packet(struct thread *thread)
                        peer->readtime = monotime(NULL);
                        mprc = bgp_update_receive(peer, size);
                        if (mprc == BGP_Stop)
-                               zlog_err(
+                               flog_err(
+                                       EC_BGP_UPDATE_RCV,
                                        "%s: BGP UPDATE receipt failed for peer: %s",
                                        __FUNCTION__, peer->host);
                        break;
@@ -2231,7 +2249,8 @@ int bgp_process_packet(struct thread *thread)
                                                  memory_order_relaxed);
                        mprc = bgp_notify_receive(peer, size);
                        if (mprc == BGP_Stop)
-                               zlog_err(
+                               flog_err(
+                                       EC_BGP_NOTIFY_RCV,
                                        "%s: BGP NOTIFY receipt failed for peer: %s",
                                        __FUNCTION__, peer->host);
                        break;
@@ -2241,7 +2260,8 @@ int bgp_process_packet(struct thread *thread)
                                                  memory_order_relaxed);
                        mprc = bgp_keepalive_receive(peer, size);
                        if (mprc == BGP_Stop)
-                               zlog_err(
+                               flog_err(
+                                       EC_BGP_KEEP_RCV,
                                        "%s: BGP KEEPALIVE receipt failed for peer: %s",
                                        __FUNCTION__, peer->host);
                        break;
@@ -2251,7 +2271,8 @@ int bgp_process_packet(struct thread *thread)
                                                  memory_order_relaxed);
                        mprc = bgp_route_refresh_receive(peer, size);
                        if (mprc == BGP_Stop)
-                               zlog_err(
+                               flog_err(
+                                       EC_BGP_RFSH_RCV,
                                        "%s: BGP ROUTEREFRESH receipt failed for peer: %s",
                                        __FUNCTION__, peer->host);
                        break;
@@ -2260,7 +2281,8 @@ int bgp_process_packet(struct thread *thread)
                                                  memory_order_relaxed);
                        mprc = bgp_capability_receive(peer, size);
                        if (mprc == BGP_Stop)
-                               zlog_err(
+                               flog_err(
+                                       EC_BGP_CAP_RCV,
                                        "%s: BGP CAPABILITY receipt failed for peer: %s",
                                        __FUNCTION__, peer->host);
                        break;