Browse Source

bgpd: Make aspath_highest 4-byte compatible for private AS

* bgp_aspath.h: Add BGP_AS_IS_PRIVATE macro.
* bgp_aspath.c: (aspath_highest) use said macro to also ensure 4-byte private
  AS range is ignored in calculating highest public ASN.
  (aspath_private_as_check) consolidate to use said macro.

Note: Extracted from 'bgpd: Add replace-as option to remove-private-as'
by paul@jakma.org.
Daniel Walton 3 years ago
parent
commit
d0aa6e8b22
2 changed files with 7 additions and 7 deletions
  1. 3 7
      bgpd/bgp_aspath.c
  2. 4 0
      bgpd/bgp_aspath.h

+ 3 - 7
bgpd/bgp_aspath.c

@@ -475,9 +475,8 @@ aspath_highest (struct aspath *aspath)
   while (seg)
     {
       for (i = 0; i < seg->length; i++)
-        if (seg->as[i] > highest
-            && (seg->as[i] < BGP_PRIVATE_AS_MIN
-                || seg->as[i] > BGP_PRIVATE_AS_MAX))
+        if (seg->as[i] > highest 
+            && !BGP_AS_IS_PRIVATE(seg->as[i]))
 	  highest = seg->as[i];
       seg = seg->next;
     }
@@ -1280,10 +1279,7 @@ aspath_private_as_check (struct aspath *aspath)
       
       for (i = 0; i < seg->length; i++)
 	{
-	  if ( (seg->as[i] < BGP_PRIVATE_AS_MIN)
-	      || (seg->as[i] > BGP_PRIVATE_AS_MAX &&
-                  seg->as[i] < BGP_PRIVATE_AS4_MIN)
-               || (seg->as[i] > BGP_PRIVATE_AS4_MAX))
+	  if (!BGP_AS_IS_PRIVATE(seg->as[i]))
 	    return 0;
 	}
       seg = seg->next;

+ 4 - 0
bgpd/bgp_aspath.h

@@ -41,6 +41,10 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 /* Transition 16Bit AS as defined by IANA */
 #define BGP_AS_TRANS		 23456U
 
+#define BGP_AS_IS_PRIVATE(ASN) \
+    (((ASN) >= BGP_PRIVATE_AS_MIN && (ASN) <= BGP_PRIVATE_AS_MAX) || \
+     ((ASN) >= BGP_PRIVATE_AS4_MIN && (ASN) <= BGP_PRIVATE_AS4_MAX))
+
 /* AS_PATH segment data in abstracted form, no limit is placed on length */
 struct assegment
 {