2022-11-02 18:17:21 +01:00
|
|
|
/*
|
|
|
|
* ASN functions
|
|
|
|
*
|
|
|
|
* Copyright 2022 6WIND
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; see the file COPYING; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
#include <zebra.h>
|
|
|
|
#include "log.h"
|
|
|
|
#include "asn.h"
|
|
|
|
|
|
|
|
static bool relax_as_zero;
|
|
|
|
|
bgpd: add as-notation keyword to 'router bgp' vty command
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>
2022-11-03 21:17:57 +01:00
|
|
|
static const struct message asnotation_mode_msg[] = {
|
|
|
|
{ASNOTATION_PLAIN, "plain"},
|
|
|
|
{ASNOTATION_DOT, "dot"},
|
|
|
|
{ASNOTATION_DOTPLUS, "dot+"},
|
|
|
|
{ASNOTATION_UNDEFINED, "undefined"},
|
|
|
|
{0}
|
|
|
|
};
|
|
|
|
|
2022-11-02 18:17:21 +01:00
|
|
|
/* converts a string into an Autonomous system number
|
|
|
|
* "1.1" => 65536
|
|
|
|
* "65500" => 65500
|
|
|
|
*/
|
|
|
|
static bool asn_str2asn_internal(const char *asstring, as_t *asn,
|
bgpd: add as-notation keyword to 'router bgp' vty command
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>
2022-11-03 21:17:57 +01:00
|
|
|
const char **next, bool *partial,
|
|
|
|
enum asnotation_mode *mode)
|
2022-11-02 18:17:21 +01:00
|
|
|
{
|
|
|
|
uint32_t high = 0, low = 0;
|
|
|
|
uint64_t temp_val;
|
|
|
|
const char *p = asstring;
|
|
|
|
bool ret = false;
|
|
|
|
uint32_t digit;
|
bgpd: add as-notation keyword to 'router bgp' vty command
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>
2022-11-03 21:17:57 +01:00
|
|
|
enum asnotation_mode val = ASNOTATION_PLAIN;
|
2022-11-02 18:17:21 +01:00
|
|
|
|
|
|
|
if (!asstring)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (!isdigit((unsigned char)*p))
|
|
|
|
goto end;
|
|
|
|
|
2023-02-22 13:57:07 +01:00
|
|
|
/* leading zero is forbidden */
|
|
|
|
if (*p == '0' && isdigit((unsigned char)*(p + 1)))
|
|
|
|
goto end;
|
|
|
|
|
2022-11-02 18:17:21 +01:00
|
|
|
temp_val = 0;
|
|
|
|
while (isdigit((unsigned char)*p)) {
|
|
|
|
digit = (*p) - '0';
|
|
|
|
temp_val *= 10;
|
|
|
|
temp_val += digit;
|
|
|
|
if (temp_val > UINT32_MAX)
|
|
|
|
/* overflow */
|
|
|
|
goto end;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
high = (uint32_t)temp_val;
|
|
|
|
if (*p == '.') { /* dot format */
|
|
|
|
p++;
|
2023-02-22 13:57:07 +01:00
|
|
|
|
2022-11-02 18:17:21 +01:00
|
|
|
if (*p == '\0' && partial) {
|
|
|
|
*partial = true;
|
|
|
|
goto end;
|
|
|
|
}
|
2023-02-22 13:57:07 +01:00
|
|
|
|
|
|
|
/* leading zero is forbidden */
|
|
|
|
if (*p == '0' && isdigit((unsigned char)*(p + 1)))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
temp_val = 0;
|
2022-11-02 18:17:21 +01:00
|
|
|
while (isdigit((unsigned char)*p)) {
|
|
|
|
digit = (*p) - '0';
|
|
|
|
temp_val *= 10;
|
|
|
|
temp_val += digit;
|
|
|
|
if (temp_val > UINT16_MAX)
|
|
|
|
/* overflow */
|
|
|
|
goto end;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
low = (uint32_t)temp_val;
|
|
|
|
|
|
|
|
if (!next && *p != '\0' && !isdigit((unsigned char)*p))
|
|
|
|
goto end;
|
|
|
|
/* AS <AS4B>.<AS4B> is forbidden */
|
|
|
|
if (high > UINT16_MAX)
|
|
|
|
goto end;
|
|
|
|
/* AS 0.0 is authorised for some case only */
|
|
|
|
if (!relax_as_zero && high == 0 && low == 0) {
|
|
|
|
if (partial)
|
|
|
|
*partial = true;
|
|
|
|
goto end;
|
|
|
|
}
|
bgpd: add as-notation keyword to 'router bgp' vty command
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>
2022-11-03 21:17:57 +01:00
|
|
|
if (asn)
|
|
|
|
*asn = (high << 16) + low;
|
2022-11-02 18:17:21 +01:00
|
|
|
ret = true;
|
bgpd: add as-notation keyword to 'router bgp' vty command
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>
2022-11-03 21:17:57 +01:00
|
|
|
if (high == 0)
|
|
|
|
val = ASNOTATION_DOTPLUS;
|
|
|
|
else
|
|
|
|
val = ASNOTATION_DOT;
|
2022-11-02 18:17:21 +01:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
/* AS 0 is forbidden */
|
|
|
|
if (!relax_as_zero && high == 0)
|
|
|
|
goto end;
|
|
|
|
if (!asn) {
|
|
|
|
ret = true;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
*asn = high;
|
|
|
|
ret = true;
|
|
|
|
end:
|
|
|
|
if (next)
|
|
|
|
*next = p;
|
bgpd: add as-notation keyword to 'router bgp' vty command
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>
2022-11-03 21:17:57 +01:00
|
|
|
if (mode)
|
|
|
|
*mode = val;
|
2022-11-02 18:17:21 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
bgpd: aspath list format binds on as-notation format
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>
2022-11-14 15:56:40 +01:00
|
|
|
static void asn_asn2asdot(as_t asn, char *asstring, size_t len)
|
|
|
|
{
|
|
|
|
uint16_t low, high;
|
|
|
|
|
|
|
|
high = (asn >> 16) & 0xffff;
|
|
|
|
low = asn & 0xffff;
|
|
|
|
snprintf(asstring, len, "%hu.%hu", high, low);
|
|
|
|
}
|
|
|
|
|
2022-11-02 18:17:21 +01:00
|
|
|
bool asn_str2asn(const char *asstring, as_t *asn)
|
|
|
|
{
|
bgpd: add as-notation keyword to 'router bgp' vty command
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>
2022-11-03 21:17:57 +01:00
|
|
|
return asn_str2asn_internal(asstring, asn, NULL, NULL, NULL);
|
2022-11-02 18:17:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *asn_asn2asplain(as_t asn)
|
|
|
|
{
|
|
|
|
static char buf[ASN_STRING_MAX_SIZE];
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%u", asn);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *asn_str2asn_parse(const char *asstring, as_t *asn, bool *found_ptr)
|
|
|
|
{
|
|
|
|
const char *p = NULL;
|
|
|
|
const char **next = &p;
|
|
|
|
bool found;
|
|
|
|
|
bgpd: add as-notation keyword to 'router bgp' vty command
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>
2022-11-03 21:17:57 +01:00
|
|
|
found = asn_str2asn_internal(asstring, asn, next, NULL, NULL);
|
2022-11-02 18:17:21 +01:00
|
|
|
if (found_ptr)
|
|
|
|
*found_ptr = found;
|
|
|
|
return *next;
|
|
|
|
}
|
|
|
|
|
|
|
|
void asn_relax_as_zero(bool relax)
|
|
|
|
{
|
|
|
|
relax_as_zero = relax;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum match_type asn_str2asn_match(const char *str)
|
|
|
|
{
|
|
|
|
bool found, partial = false;
|
|
|
|
|
bgpd: add as-notation keyword to 'router bgp' vty command
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>
2022-11-03 21:17:57 +01:00
|
|
|
found = asn_str2asn_internal(str, NULL, NULL, &partial, NULL);
|
2022-11-02 18:17:21 +01:00
|
|
|
if (found && !partial)
|
|
|
|
return exact_match;
|
|
|
|
|
|
|
|
if (partial)
|
|
|
|
return partly_match;
|
|
|
|
|
|
|
|
return no_match;
|
|
|
|
}
|
bgpd: add as-notation keyword to 'router bgp' vty command
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>
2022-11-03 21:17:57 +01:00
|
|
|
|
|
|
|
bool asn_str2asn_notation(const char *asstring, as_t *asn,
|
|
|
|
enum asnotation_mode *asnotation)
|
|
|
|
{
|
|
|
|
return asn_str2asn_internal(asstring, asn, NULL, NULL, asnotation);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *asn_mode2str(enum asnotation_mode asnotation)
|
|
|
|
{
|
|
|
|
return lookup_msg(asnotation_mode_msg, asnotation,
|
|
|
|
"Unrecognized AS notation mode");
|
|
|
|
}
|
bgpd: aspath list format binds on as-notation format
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>
2022-11-14 15:56:40 +01:00
|
|
|
|
2022-11-18 13:49:53 +01:00
|
|
|
void asn_asn2json(json_object *json, const char *attr,
|
|
|
|
as_t asn, enum asnotation_mode asnotation)
|
|
|
|
{
|
|
|
|
static char as_str[ASN_STRING_MAX_SIZE];
|
|
|
|
|
|
|
|
if ((asnotation == ASNOTATION_PLAIN) ||
|
|
|
|
((asnotation == ASNOTATION_DOT) && asn < UINT16_MAX))
|
|
|
|
json_object_int_add(json, attr, asn);
|
|
|
|
else {
|
|
|
|
asn_asn2asdot(asn, as_str, sizeof(as_str));
|
|
|
|
json_object_string_add(json, attr, as_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
bgpd: aspath list format binds on as-notation format
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>
2022-11-14 15:56:40 +01:00
|
|
|
void asn_asn2json_array(json_object *jseg_list, as_t asn,
|
|
|
|
enum asnotation_mode asnotation)
|
|
|
|
{
|
|
|
|
static char as_str[ASN_STRING_MAX_SIZE];
|
|
|
|
|
|
|
|
if ((asnotation == ASNOTATION_PLAIN) ||
|
|
|
|
((asnotation == ASNOTATION_DOT) && asn < UINT16_MAX))
|
|
|
|
json_object_array_add(jseg_list,
|
|
|
|
json_object_new_int64(asn));
|
|
|
|
else {
|
|
|
|
asn_asn2asdot(asn, as_str, sizeof(as_str));
|
|
|
|
json_array_string_add(jseg_list, as_str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-22 09:57:10 +01:00
|
|
|
char *asn_asn2string(const as_t *asn, char *buf, size_t len,
|
|
|
|
enum asnotation_mode asnotation)
|
|
|
|
{
|
|
|
|
if ((asnotation == ASNOTATION_PLAIN) ||
|
|
|
|
((asnotation == ASNOTATION_DOT) && *asn < UINT16_MAX))
|
|
|
|
snprintf(buf, len, "%u", *asn);
|
|
|
|
else
|
|
|
|
asn_asn2asdot(*asn, buf, len);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
bgpd: aspath list format binds on as-notation format
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>
2022-11-14 15:56:40 +01:00
|
|
|
static ssize_t printfrr_asnotation(struct fbuf *buf, struct printfrr_eargs *ea,
|
|
|
|
const void *ptr,
|
|
|
|
enum asnotation_mode asnotation)
|
|
|
|
{
|
|
|
|
/* for alignemnt up to 33 chars - %33pASD for instance - */
|
|
|
|
char as_str[ASN_STRING_MAX_SIZE*3];
|
|
|
|
const as_t *asn;
|
|
|
|
|
|
|
|
if (!ptr)
|
|
|
|
return bputs(buf, "(null)");
|
|
|
|
asn = ptr;
|
2022-11-22 09:57:10 +01:00
|
|
|
asn_asn2string(asn, as_str, sizeof(as_str), asnotation);
|
bgpd: aspath list format binds on as-notation format
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>
2022-11-14 15:56:40 +01:00
|
|
|
return bputs(buf, as_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
printfrr_ext_autoreg_p("ASP", printfrr_asplain);
|
|
|
|
static ssize_t printfrr_asplain(struct fbuf *buf, struct printfrr_eargs *ea,
|
|
|
|
const void *ptr)
|
|
|
|
{
|
|
|
|
return printfrr_asnotation(buf, ea, ptr, ASNOTATION_PLAIN);
|
|
|
|
}
|
|
|
|
|
|
|
|
printfrr_ext_autoreg_p("ASD", printfrr_asdot);
|
|
|
|
static ssize_t printfrr_asdot(struct fbuf *buf, struct printfrr_eargs *ea,
|
|
|
|
const void *ptr)
|
|
|
|
{
|
|
|
|
return printfrr_asnotation(buf, ea, ptr, ASNOTATION_DOT);
|
|
|
|
}
|
|
|
|
|
|
|
|
printfrr_ext_autoreg_p("ASE", printfrr_asdotplus);
|
|
|
|
static ssize_t printfrr_asdotplus(struct fbuf *buf, struct printfrr_eargs *ea,
|
|
|
|
const void *ptr)
|
|
|
|
{
|
|
|
|
return printfrr_asnotation(buf, ea, ptr, ASNOTATION_DOTPLUS);
|
|
|
|
}
|