summaryrefslogtreecommitdiff
path: root/lib/asn.c
AgeCommit message (Collapse)Author
2023-02-24lib: some ASNUMs should be forbiddenanlan_cs
In current code, some ASNUMs with redundant zero are legal, e.g. "1.01", "01.1", "1.001", "001.1", and more. They should be forbidden. Signed-off-by: anlan_cs <vic.lan@pica8.com>
2023-02-10bgpd: support for as notation format for route distinguisherPhilippe Guibert
RD may be built based on an AS number. Like for the AS, the RD may use the AS notation. The two below examples can illustrate: RD 1.1:20 stands for an AS4B:NN RD with AS4B=65536 in dot format. RD 0.1:20 stands for an AS2B:NNNN RD with AS2B=0.1 in dot+ format. This commit adds the asnotation mode to prefix_rd2str() API so as to pick up the relevant display. Two new printfrr extensions are available to display the RD with the two above display methods. - The pRDD extension stands for dot asnotation format - The pRDE extension stands for dot+ asnotation format. - The pRD extension has been renamed to pRDP extension The code is changed each time '%pRD' printf extension is called. Possibly, the asnotation may change the output, then a macro defines the asnotation mode to use. A side effect of forging the mode to use is that the string could not be concatenated with other strings in vty_out and snprintfrr. Those functions have been called multiple times. When zlog_debug needs to display the RD with some other string, the prefix_rd2str() old API is used instead of the printf extension. Some code has been kept untouched: - code related to running-config. Actually, wherever an RD is displayed, its configured name should be dumped. - bgp rfapi code - bgp evpn multihoming code (partially done), since the logic is missing to get the asnotation of 'struct bgp_evpn_es'. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-10bgpd: modify bgp as number outputPhilippe Guibert
A json AS number API is created in order to output a given AS number. In order to keep backward compatibility, if the as-notation uses a number, then the json is encoded as an integer, otherwise the encoding will be a string. For what is not relevant to running-configuration, the as-notation mode is the one used for the BGP instance. Also, the vty completion gets the configured 'as_pretty' string value, when an user wants to get the available BGP instances. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-10bgpd: aspath list format binds on as-notation formatPhilippe Guibert
Each BGP prefix may have an as-path list attached. A forged string is stored in the BGP attribute and shows the as-path list output. Before this commit, the as-path list output was expressed as a list of AS values in plain format. Now, if a given BGP instance uses a specific asnotation, then the output is changed: new output: router bgp 1.1 asnotation dot ! address-family ipv4 unicast network 10.200.0.0/24 route-map rmap network 10.201.0.0/24 route-map rmap redistribute connected route-map rmap exit-address-family exit ! route-map rmap permit 1 set as-path prepend 1.1 5433.55 264564564 exit ubuntu2004# do show bgp ipv4 BGP table version is 2, local router ID is 10.0.2.15, vrf id 0 Default local pref 100, local AS 1.1 Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, i internal, r RIB-failure, S Stale, R Removed Nexthop codes: @NNN nexthop's vrf id, < announce-nh-self Origin codes: i - IGP, e - EGP, ? - incomplete RPKI validation codes: V valid, I invalid, N Not found Network Next Hop Metric LocPrf Weight Path *> 4.4.4.4/32 0.0.0.0 0 32768 1.1 5433.55 4036.61268 ? *> 10.0.2.0/24 0.0.0.0 0 32768 1.1 5433.55 4036.61268 ? 10.200.0.0/24 0.0.0.0 0 32768 1.1 5433.55 4036.61268 i 10.201.0.0/24 0.0.0.0 0 32768 1.1 5433.55 4036.61268 i The changes include: - the aspath structure has a new field: asnotation type The ashash list will differentiate 2 aspaths using a different asnotation. - 3 new printf extensions display the as number in the wished format: pASP, pASD, pASE for plain, dot, or dot+ format (extended). Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-10bgpd: add as-notation keyword to 'router bgp' vty commandPhilippe Guibert
A new keyword permits changing the BGP as-notation output: - [no] router bgp <> [vrf BLABLA] [as-notation [<dot|plain|dot+>]] At the BGP instance creation, the output will inherit the way the BGP instance is declared. For instance, the 'router bgp 1.1' command will configure the output in the dot format. However, if the client wants to choose an alternate output, he will have to add the extra command: 'router bgp 1.1 as-notation dot+'. Also, if the user wants to have plain format, even if the BGP instance is declared in dot format, the keyword can also be used for that. The as-notation output is only taken into account at the BGP instance creation. In the case where VPN instances are used, a separate instance may be dynamically created. In that case, the real as-notation format will be taken into acccount at the first configuration. Linking the as-notation format with the BGP instance makes sense, as the operators want to keep consistency of what they configure. One technical reason why to link the as-notation output with the BGP instance creation is that the as-path segment lists stored in the BGP updates use a string representation to handle aspath operations (by using regexp for instance). Changing on the fly the output needs to regenerate this string representation to the correct format. Linking the configuration to the BGP instance creation avoids refreshing the BGP updates. A similar mechanism is put in place in junos too. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
2023-02-10lib, bgp: add initial support for asdot formatPhilippe Guibert
AS number can be defined as an unsigned long number, or two uint16 values separated by a period (.). The possible valus are: - usual 32 bit values : [1;2^32 -1] - <1.65535>.<0.65535> for dot notation - <0.65535>.<0.65535> for dot+ notation. The 0.0 value is forbidden when configuring BGP instances or peer configurations. A new ASN type is added for parsing in the vty. The following commands use that new identifier: - router bgp .. - bgp confederation .. - neighbor <> remote-as <> - neighbor <> local-as <> - clear ip bgp <> - route-map / set as-path <> An asn library is available in lib/ and provides some services: - convert an as string into an as number. - parse an as path list string and extract a number. - convert an as number into a string. Also, the bgp tests forge an as_zero_path, and to do that, an API to relax the possibility to have a 0 as value is specifically called from the tests. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>