]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Do not check against aspath `seg` which is already checked before
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Fri, 11 Jun 2021 15:37:50 +0000 (18:37 +0300)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Thu, 17 Jun 2021 07:14:38 +0000 (10:14 +0300)
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
bgpd/bgp_aspath.c

index 5cf3c60fa2cd97d5467ec180698455a62f153f25..25109e030b8d705ecb3cc4ae46c86672ae03a97a 100644 (file)
@@ -910,77 +910,70 @@ size_t aspath_put(struct stream *s, struct aspath *as, int use32bit)
        if (!seg || seg->length == 0)
                return 0;
 
-       if (seg) {
-               /*
-                * Hey, what do we do when we have > STREAM_WRITABLE(s) here?
-                * At the moment, we would write out a partial aspath, and our
-                * peer
-                * will complain and drop the session :-/
-                *
-                * The general assumption here is that many things tested will
-                * never happen.  And, in real live, up to now, they have not.
-                */
-               while (seg && (ASSEGMENT_LEN(seg, use32bit)
-                              <= STREAM_WRITEABLE(s))) {
-                       struct assegment *next = seg->next;
-                       int written = 0;
-                       int asns_packed = 0;
-                       size_t lenp;
-
-                       /* Overlength segments have to be split up */
-                       while ((seg->length - written) > AS_SEGMENT_MAX) {
-                               assegment_header_put(s, seg->type,
-                                                    AS_SEGMENT_MAX);
-                               assegment_data_put(s, (seg->as + written), AS_SEGMENT_MAX,
-                                                  use32bit);
-                               written += AS_SEGMENT_MAX;
-                               bytes += ASSEGMENT_SIZE(AS_SEGMENT_MAX,
-                                                       use32bit);
-                       }
-
-                       /* write the final segment, probably is also the first
-                        */
-                       lenp = assegment_header_put(s, seg->type,
-                                                   seg->length - written);
+       /*
+        * Hey, what do we do when we have > STREAM_WRITABLE(s) here?
+        * At the moment, we would write out a partial aspath, and our
+        * peer
+        * will complain and drop the session :-/
+        *
+        * The general assumption here is that many things tested will
+        * never happen.  And, in real live, up to now, they have not.
+        */
+       while (seg && (ASSEGMENT_LEN(seg, use32bit) <= STREAM_WRITEABLE(s))) {
+               struct assegment *next = seg->next;
+               int written = 0;
+               int asns_packed = 0;
+               size_t lenp;
+
+               /* Overlength segments have to be split up */
+               while ((seg->length - written) > AS_SEGMENT_MAX) {
+                       assegment_header_put(s, seg->type, AS_SEGMENT_MAX);
                        assegment_data_put(s, (seg->as + written),
-                                          seg->length - written, use32bit);
+                                          AS_SEGMENT_MAX, use32bit);
+                       written += AS_SEGMENT_MAX;
+                       bytes += ASSEGMENT_SIZE(AS_SEGMENT_MAX, use32bit);
+               }
 
-                       /* Sequence-type segments can be 'packed' together
-                        * Case of a segment which was overlength and split up
-                        * will be missed here, but that doesn't matter.
+               /* write the final segment, probably is also the first
+                */
+               lenp = assegment_header_put(s, seg->type,
+                                           seg->length - written);
+               assegment_data_put(s, (seg->as + written),
+                                  seg->length - written, use32bit);
+
+               /* Sequence-type segments can be 'packed' together
+                * Case of a segment which was overlength and split up
+                * will be missed here, but that doesn't matter.
+                */
+               while (next && ASSEGMENTS_PACKABLE(seg, next)) {
+                       /* NB: We should never normally get here given
+                        * we
+                        * normalise aspath data when parse them.
+                        * However, better
+                        * safe than sorry. We potentially could call
+                        * assegment_normalise here instead, but it's
+                        * cheaper and
+                        * easier to do it on the fly here rather than
+                        * go through
+                        * the segment list twice every time we write
+                        * out
+                        * aspath's.
                         */
-                       while (next && ASSEGMENTS_PACKABLE(seg, next)) {
-                               /* NB: We should never normally get here given
-                                * we
-                                * normalise aspath data when parse them.
-                                * However, better
-                                * safe than sorry. We potentially could call
-                                * assegment_normalise here instead, but it's
-                                * cheaper and
-                                * easier to do it on the fly here rather than
-                                * go through
-                                * the segment list twice every time we write
-                                * out
-                                * aspath's.
-                                */
-
-                               /* Next segment's data can fit in this one */
-                               assegment_data_put(s, next->as, next->length,
-                                                  use32bit);
-
-                               /* update the length of the segment header */
-                               stream_putc_at(s, lenp,
-                                              seg->length - written
-                                                      + next->length);
-                               asns_packed += next->length;
-
-                               next = next->next;
-                       }
 
-                       bytes += ASSEGMENT_SIZE(
-                               seg->length - written + asns_packed, use32bit);
-                       seg = next;
+                       /* Next segment's data can fit in this one */
+                       assegment_data_put(s, next->as, next->length, use32bit);
+
+                       /* update the length of the segment header */
+                       stream_putc_at(s, lenp,
+                                      seg->length - written + next->length);
+                       asns_packed += next->length;
+
+                       next = next->next;
                }
+
+               bytes += ASSEGMENT_SIZE(seg->length - written + asns_packed,
+                                       use32bit);
+               seg = next;
        }
        return bytes;
 }