@@ -287,9 +287,13 @@ static struct assegment *assegment_normalise(struct assegment *head)
287
287
return head ;
288
288
}
289
289
290
- static struct aspath * aspath_new (void )
290
+ static struct aspath * aspath_new (enum asnotation_mode asnotation )
291
291
{
292
- return XCALLOC (MTYPE_AS_PATH , sizeof (struct aspath ));
292
+ struct aspath * as ;
293
+
294
+ as = XCALLOC (MTYPE_AS_PATH , sizeof (struct aspath ));
295
+ as -> asnotation = asnotation ;
296
+ return as ;
293
297
}
294
298
295
299
/* Free AS path structure. */
@@ -537,8 +541,10 @@ static void aspath_make_str_count(struct aspath *as, bool make_json)
537
541
*
538
542
* This was changed to 10 after the well-known BGP assertion, which
539
543
* had hit some parts of the Internet in May of 2009.
544
+ * plain format : '4294967295 ' : 10 + 1
545
+ * astod format : '65535.65535 ': 11 + 1
540
546
*/
541
- #define ASN_STR_LEN (10 + 1)
547
+ #define ASN_STR_LEN (11 + 1)
542
548
str_size = MAX (assegment_count_asns (seg , 0 ) * ASN_STR_LEN + 2 + 1 ,
543
549
ASPATH_STR_DEFAULT_LEN );
544
550
str_buf = XMALLOC (MTYPE_AS_STR , str_size );
@@ -569,7 +575,7 @@ static void aspath_make_str_count(struct aspath *as, bool make_json)
569
575
570
576
/* We might need to increase str_buf, particularly if path has
571
577
* differing segments types, our initial guesstimate above will
572
- * have been wrong. Need 10 chars for ASN, a separator each and
578
+ * have been wrong. Need 11 chars for ASN, a separator each and
573
579
* potentially two segment delimiters, plus a space between each
574
580
* segment and trailing zero.
575
581
*
@@ -595,12 +601,11 @@ static void aspath_make_str_count(struct aspath *as, bool make_json)
595
601
/* write out the ASNs, with their separators, bar the last one*/
596
602
for (i = 0 ; i < seg -> length ; i ++ ) {
597
603
if (make_json )
598
- json_object_array_add (
599
- jseg_list ,
600
- json_object_new_int64 (seg -> as [i ]));
601
-
602
- len += snprintf (str_buf + len , str_size - len , "%u" ,
603
- seg -> as [i ]);
604
+ asn_asn2json_array (jseg_list , seg -> as [i ],
605
+ as -> asnotation );
606
+ len += snprintfrr (str_buf + len , str_size - len ,
607
+ ASN_FORMAT (as -> asnotation ),
608
+ & seg -> as [i ]);
604
609
605
610
if (i < (seg -> length - 1 ))
606
611
len += snprintf (str_buf + len , str_size - len ,
@@ -691,6 +696,7 @@ struct aspath *aspath_dup(struct aspath *aspath)
691
696
692
697
new -> str = XMALLOC (MTYPE_AS_STR , buflen );
693
698
new -> str_len = aspath -> str_len ;
699
+ new -> asnotation = aspath -> asnotation ;
694
700
695
701
/* copy the string data */
696
702
if (aspath -> str_len > 0 )
@@ -718,6 +724,7 @@ static void *aspath_hash_alloc(void *arg)
718
724
new -> str = aspath -> str ;
719
725
new -> str_len = aspath -> str_len ;
720
726
new -> json = aspath -> json ;
727
+ new -> asnotation = aspath -> asnotation ;
721
728
722
729
return new ;
723
730
}
@@ -825,7 +832,8 @@ static int assegments_parse(struct stream *s, size_t length,
825
832
826
833
On error NULL is returned.
827
834
*/
828
- struct aspath * aspath_parse (struct stream * s , size_t length , int use32bit )
835
+ struct aspath * aspath_parse (struct stream * s , size_t length , int use32bit ,
836
+ enum asnotation_mode asnotation )
829
837
{
830
838
struct aspath as ;
831
839
struct aspath * find ;
@@ -840,6 +848,7 @@ struct aspath *aspath_parse(struct stream *s, size_t length, int use32bit)
840
848
return NULL ;
841
849
842
850
memset (& as , 0 , sizeof (as ));
851
+ as .asnotation = asnotation ;
843
852
if (assegments_parse (s , length , & as .segments , use32bit ) < 0 )
844
853
return NULL ;
845
854
@@ -1057,7 +1066,7 @@ struct aspath *aspath_aggregate(struct aspath *as1, struct aspath *as2)
1057
1066
seg = assegment_append_asns (seg , seg1 -> as , match );
1058
1067
1059
1068
if (!aspath ) {
1060
- aspath = aspath_new ();
1069
+ aspath = aspath_new (as1 -> asnotation );
1061
1070
aspath -> segments = seg ;
1062
1071
} else
1063
1072
prevseg -> next = seg ;
@@ -1077,7 +1086,7 @@ struct aspath *aspath_aggregate(struct aspath *as1, struct aspath *as2)
1077
1086
}
1078
1087
1079
1088
if (!aspath )
1080
- aspath = aspath_new ();
1089
+ aspath = aspath_new (as1 -> asnotation );
1081
1090
1082
1091
/* Make as-set using rest of all information. */
1083
1092
from = match ;
@@ -1521,7 +1530,7 @@ struct aspath *aspath_filter_exclude(struct aspath *source,
1521
1530
struct assegment * srcseg , * exclseg , * lastseg ;
1522
1531
struct aspath * newpath ;
1523
1532
1524
- newpath = aspath_new ();
1533
+ newpath = aspath_new (source -> asnotation );
1525
1534
lastseg = NULL ;
1526
1535
1527
1536
for (srcseg = source -> segments ; srcseg ; srcseg = srcseg -> next ) {
@@ -1751,7 +1760,7 @@ struct aspath *aspath_reconcile_as4(struct aspath *aspath,
1751
1760
newseg = assegment_append_asns (newseg , seg -> as , cpasns );
1752
1761
1753
1762
if (!newpath ) {
1754
- newpath = aspath_new ();
1763
+ newpath = aspath_new (aspath -> asnotation );
1755
1764
newpath -> segments = newseg ;
1756
1765
} else
1757
1766
prevseg -> next = newseg ;
@@ -1880,16 +1889,16 @@ static void aspath_segment_add(struct aspath *as, int type)
1880
1889
as -> segments = new ;
1881
1890
}
1882
1891
1883
- struct aspath * aspath_empty (void )
1892
+ struct aspath * aspath_empty (enum asnotation_mode asnotation )
1884
1893
{
1885
- return aspath_parse (NULL , 0 , 1 ); /* 32Bit ;-) */
1894
+ return aspath_parse (NULL , 0 , 1 , asnotation ); /* 32Bit ;-) */
1886
1895
}
1887
1896
1888
1897
struct aspath * aspath_empty_get (void )
1889
1898
{
1890
1899
struct aspath * aspath ;
1891
1900
1892
- aspath = aspath_new ();
1901
+ aspath = aspath_new (bgp_get_asnotation ( NULL ) );
1893
1902
aspath_make_str_count (aspath , false);
1894
1903
return aspath ;
1895
1904
}
@@ -1925,6 +1934,8 @@ static const char *aspath_gettoken(const char *buf, enum as_token *token,
1925
1934
unsigned long * asno )
1926
1935
{
1927
1936
const char * p = buf ;
1937
+ as_t asval ;
1938
+ bool found = false;
1928
1939
1929
1940
/* Skip separators (space for sequences, ',' for sets). */
1930
1941
while (isspace ((unsigned char )* p ) || * p == ',' )
@@ -1961,38 +1972,26 @@ static const char *aspath_gettoken(const char *buf, enum as_token *token,
1961
1972
return p ;
1962
1973
}
1963
1974
1964
- /* Check actual AS value. */
1965
- if (isdigit ((unsigned char )* p )) {
1966
- as_t asval ;
1967
-
1968
- * token = as_token_asval ;
1969
- asval = (* p - '0' );
1970
- p ++ ;
1971
-
1972
- while (isdigit ((unsigned char )* p )) {
1973
- asval *= 10 ;
1974
- asval += (* p - '0' );
1975
- p ++ ;
1976
- }
1975
+ asval = 0 ;
1976
+ p = asn_str2asn_parse (p , & asval , & found );
1977
+ if (found ) {
1977
1978
* asno = asval ;
1978
- return p ;
1979
- }
1980
-
1981
- /* There is no match then return unknown token. */
1982
- * token = as_token_unknown ;
1983
- p ++ ;
1979
+ * token = as_token_asval ;
1980
+ } else
1981
+ * token = as_token_unknown ;
1984
1982
return p ;
1985
1983
}
1986
1984
1987
- struct aspath * aspath_str2aspath (const char * str )
1985
+ struct aspath * aspath_str2aspath (const char * str ,
1986
+ enum asnotation_mode asnotation )
1988
1987
{
1989
1988
enum as_token token = as_token_unknown ;
1990
1989
unsigned short as_type ;
1991
1990
unsigned long asno = 0 ;
1992
1991
struct aspath * aspath ;
1993
1992
int needtype ;
1994
1993
1995
- aspath = aspath_new ();
1994
+ aspath = aspath_new (asnotation );
1996
1995
1997
1996
/* We start default type as AS_SEQUENCE. */
1998
1997
as_type = AS_SEQUENCE ;
@@ -2066,6 +2065,10 @@ bool aspath_cmp(const void *arg1, const void *arg2)
2066
2065
const struct assegment * seg1 = ((const struct aspath * )arg1 )-> segments ;
2067
2066
const struct assegment * seg2 = ((const struct aspath * )arg2 )-> segments ;
2068
2067
2068
+ if (((const struct aspath * )arg1 )-> asnotation !=
2069
+ ((const struct aspath * )arg2 )-> asnotation )
2070
+ return false;
2071
+
2069
2072
while (seg1 || seg2 ) {
2070
2073
int i ;
2071
2074
if ((!seg1 && seg2 ) || (seg1 && !seg2 ))
0 commit comments