]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_open.c
Merge pull request #3502 from donaldsharp/socket_to_me_baby
[mirror_frr.git] / bgpd / bgp_open.c
index da90bbd67dad6591b5747da3c1696948dee160ab..3018124f452053c9a6af3c46743cb654fbec443f 100644 (file)
@@ -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"
@@ -51,8 +52,8 @@
    Next, if we send capability to the peer we want to set my capabilty
    inforation at each peer. */
 
-void bgp_capability_vty_out(struct vty *vty, struct peer *peer,
-                           uint8_t use_json, json_object *json_neigh)
+void bgp_capability_vty_out(struct vty *vty, struct peer *peer, bool use_json,
+                           json_object *json_neigh)
 {
        char *pnt;
        char *end;
@@ -253,7 +254,8 @@ static int bgp_capability_mp(struct peer *peer, struct capability_header *hdr)
 
        /* Verify length is 4 */
        if (hdr->length != 4) {
-               zlog_warn(
+               flog_warn(
+                       EC_BGP_CAPABILITY_INVALID_LENGTH,
                        "MP Cap: Received invalid length %d, non-multiple of 4",
                        hdr->length);
                return -1;
@@ -448,7 +450,8 @@ static int bgp_capability_restart(struct peer *peer,
 
        /* Verify length is a multiple of 4 */
        if ((caphdr->length - 2) % 4) {
-               zlog_warn(
+               flog_warn(
+                       EC_BGP_CAPABILITY_INVALID_LENGTH,
                        "Restart Cap: Received invalid length %d, non-multiple of 4",
                        caphdr->length);
                return -1;
@@ -520,7 +523,8 @@ 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",
+               flog_err(EC_BGP_PKT_OPEN,
+                        "%s AS4 capability has incorrect data length %d",
                         peer->host, hdr->length);
                return 0;
        }
@@ -544,7 +548,8 @@ static int bgp_capability_addpath(struct peer *peer,
 
        /* Verify length is a multiple of 4 */
        if (hdr->length % 4) {
-               zlog_warn(
+               flog_warn(
+                       EC_BGP_CAPABILITY_INVALID_LENGTH,
                        "Add Path: Received invalid length %d, non-multiple of 4",
                        hdr->length);
                return -1;
@@ -602,7 +607,8 @@ static int bgp_capability_enhe(struct peer *peer, struct capability_header *hdr)
 
        /* Verify length is a multiple of 4 */
        if (hdr->length % 6) {
-               zlog_warn(
+               flog_warn(
+                       EC_BGP_CAPABILITY_INVALID_LENGTH,
                        "Extended NH: Received invalid length %d, non-multiple of 6",
                        hdr->length);
                return -1;
@@ -644,7 +650,8 @@ static int bgp_capability_enhe(struct peer *peer, struct capability_header *hdr)
                if (afi != AFI_IP || nh_afi != AFI_IP6
                    || !(safi == SAFI_UNICAST
                         || safi == SAFI_LABELED_UNICAST)) {
-                       zlog_warn(
+                       flog_warn(
+                               EC_BGP_CAPABILITY_INVALID_DATA,
                                "%s Unexpected afi/safi/next-hop afi: %u/%u/%u "
                                "in Extended Next-hop capability, ignoring",
                                peer->host, pkt_afi, pkt_safi, pkt_nh_afi);
@@ -675,7 +682,8 @@ static int bgp_capability_hostname(struct peer *peer,
 
        len = stream_getc(s);
        if (stream_get_getp(s) + len > end) {
-               zlog_warn(
+               flog_warn(
+                       EC_BGP_CAPABILITY_INVALID_DATA,
                        "%s: Received malformed hostname capability from peer %s",
                        __FUNCTION__, peer->host);
                return -1;
@@ -705,7 +713,8 @@ static int bgp_capability_hostname(struct peer *peer,
        }
 
        if (stream_get_getp(s) + 1 > end) {
-               zlog_warn(
+               flog_warn(
+                       EC_BGP_CAPABILITY_INVALID_DATA,
                        "%s: Received invalid domain name len (hostname capability) from peer %s",
                        __FUNCTION__, peer->host);
                return -1;
@@ -713,7 +722,8 @@ static int bgp_capability_hostname(struct peer *peer,
 
        len = stream_getc(s);
        if (stream_get_getp(s) + len > end) {
-               zlog_warn(
+               flog_warn(
+                       EC_BGP_CAPABILITY_INVALID_DATA,
                        "%s: Received runt domain name (hostname capability) from peer %s",
                        __FUNCTION__, peer->host);
                return -1;
@@ -950,10 +960,12 @@ static int bgp_capability_parse(struct peer *peer, size_t length,
                                   specific
                                   capabilities.  It seems reasonable for now...
                                   */
-                               zlog_warn("%s Vendor specific capability %d",
+                               flog_warn(EC_BGP_CAPABILITY_VENDOR,
+                                         "%s Vendor specific capability %d",
                                          peer->host, caphdr.code);
                        } else {
-                               zlog_warn(
+                               flog_warn(
+                                       EC_BGP_CAPABILITY_UNKNOWN,
                                        "%s unrecognized capability code: %d - ignored",
                                        peer->host, caphdr.code);
                                memcpy(*error, sp, caphdr.length + 2);
@@ -968,7 +980,8 @@ static int bgp_capability_parse(struct peer *peer, size_t length,
                }
                if (stream_get_getp(s) != (start + caphdr.length)) {
                        if (stream_get_getp(s) > (start + caphdr.length))
-                               zlog_warn(
+                               flog_warn(
+                                       EC_BGP_CAPABILITY_INVALID_LENGTH,
                                        "%s Cap-parser for %s read past cap-length, %u!",
                                        peer->host,
                                        lookup_msg(capcode_str, caphdr.code,
@@ -1184,10 +1197,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);
+                       flog_err(EC_BGP_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(
@@ -1318,7 +1331,6 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
                         */
                        if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE)
                            && peer->su.sa.sa_family == AF_INET6
-                           && IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)
                            && afi == AFI_IP
                            && (safi == SAFI_UNICAST
                                || safi == SAFI_LABELED_UNICAST)) {
@@ -1375,10 +1387,7 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
                        /* Only advertise addpath TX if a feature that
                         * will use it is
                         * configured */
-                       if (CHECK_FLAG(peer->af_flags[afi][safi],
-                                      PEER_FLAG_ADDPATH_TX_ALL_PATHS)
-                           || CHECK_FLAG(peer->af_flags[afi][safi],
-                                         PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
+                       if (peer->addpath_type[afi][safi] != BGP_ADDPATH_NONE)
                                adv_addpath_tx = 1;
                }
        }