]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_aspath.c
Merge pull request #3394 from karamalla0406/frr3360
[mirror_frr.git] / bgpd / bgp_aspath.c
index e02617691fa783a402fca224740a6ec51100e5c5..4f756519cafc3fbff1117e72cb8eef171910c5bf 100644 (file)
 #include "bgpd/bgp_aspath.h"
 #include "bgpd/bgp_debug.h"
 #include "bgpd/bgp_attr.h"
+#include "bgpd/bgp_errors.h"
 
 /* Attr. Flags and Attr. Type Code. */
-#define AS_HEADER_SIZE        2         
+#define AS_HEADER_SIZE 2
 
 /* Now FOUR octets are used for AS value. */
 #define AS_VALUE_SIZE         sizeof (as_t)
@@ -214,16 +215,11 @@ static struct assegment *assegment_append_asns(struct assegment *seg,
        newas = XREALLOC(MTYPE_AS_SEG_DATA, seg->as,
                         ASSEGMENT_DATA_SIZE(seg->length + num, 1));
 
-       if (newas) {
-               seg->as = newas;
-               memcpy(seg->as + seg->length, asnos,
-                      ASSEGMENT_DATA_SIZE(num, 1));
-               seg->length += num;
-               return seg;
-       }
-
-       assegment_free_all(seg);
-       return NULL;
+       seg->as = newas;
+       memcpy(seg->as + seg->length, asnos,
+              ASSEGMENT_DATA_SIZE(num, 1));
+       seg->length += num;
+       return seg;
 }
 
 static int int_cmp(const void *p1, const void *p2)
@@ -904,7 +900,7 @@ size_t aspath_put(struct stream *s, struct aspath *as, int use32bit)
                        while ((seg->length - written) > AS_SEGMENT_MAX) {
                                assegment_header_put(s, seg->type,
                                                     AS_SEGMENT_MAX);
-                               assegment_data_put(s, seg->as, AS_SEGMENT_MAX,
+                               assegment_data_put(s, (seg->as + written), AS_SEGMENT_MAX,
                                                   use32bit);
                                written += AS_SEGMENT_MAX;
                                bytes += ASSEGMENT_SIZE(AS_SEGMENT_MAX,
@@ -1632,7 +1628,7 @@ struct aspath *aspath_reconcile_as4(struct aspath *aspath,
        struct aspath *newpath = NULL, *mergedpath;
        int hops, cpasns = 0;
 
-       if (!aspath)
+       if (!aspath || !as4path)
                return NULL;
 
        seg = aspath->segments;
@@ -1643,7 +1639,8 @@ struct aspath *aspath_reconcile_as4(struct aspath *aspath,
 
        if (hops < 0) {
                if (BGP_DEBUG(as4, AS4))
-                       zlog_warn(
+                       flog_warn(
+                               EC_BGP_ASPATH_FEWER_HOPS,
                                "[AS4] Fewer hops in AS_PATH than NEW_AS_PATH");
                /* Something's gone wrong. The RFC says we should now ignore
                 * AS4_PATH,
@@ -1729,23 +1726,23 @@ struct aspath *aspath_reconcile_as4(struct aspath *aspath,
 /* Compare leftmost AS value for MED check.  If as1's leftmost AS and
    as2's leftmost AS is same return 1. (confederation as-path
    only).  */
-int aspath_cmp_left_confed(const struct aspath *aspath1,
-                          const struct aspath *aspath2)
+bool aspath_cmp_left_confed(const struct aspath *aspath1,
+                           const struct aspath *aspath2)
 {
        if (!(aspath1 && aspath2))
-               return 0;
+               return false;
 
        if (!(aspath1->segments && aspath2->segments))
-               return 0;
+               return false;
 
        if ((aspath1->segments->type != AS_CONFED_SEQUENCE)
            || (aspath2->segments->type != AS_CONFED_SEQUENCE))
-               return 0;
+               return false;
 
        if (aspath1->segments->as[0] == aspath2->segments->as[0])
-               return 1;
+               return true;
 
-       return 0;
+       return false;
 }
 
 /* Delete all AS_CONFED_SEQUENCE/SET segments from aspath.
@@ -2011,7 +2008,7 @@ unsigned int aspath_key_make(void *p)
 }
 
 /* If two aspath have same value then return 1 else return 0 */
-int aspath_cmp(const void *arg1, const void *arg2)
+bool aspath_cmp(const void *arg1, const void *arg2)
 {
        const struct assegment *seg1 = ((const struct aspath *)arg1)->segments;
        const struct assegment *seg2 = ((const struct aspath *)arg2)->segments;
@@ -2019,18 +2016,18 @@ int aspath_cmp(const void *arg1, const void *arg2)
        while (seg1 || seg2) {
                int i;
                if ((!seg1 && seg2) || (seg1 && !seg2))
-                       return 0;
+                       return false;
                if (seg1->type != seg2->type)
-                       return 0;
+                       return false;
                if (seg1->length != seg2->length)
-                       return 0;
+                       return false;
                for (i = 0; i < seg1->length; i++)
                        if (seg1->as[i] != seg2->as[i])
-                               return 0;
+                               return false;
                seg1 = seg1->next;
                seg2 = seg2->next;
        }
-       return 1;
+       return true;
 }
 
 /* AS path hash initialize. */