summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_rpki.c
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2022-11-25 17:51:33 +0100
committerPhilippe Guibert <philippe.guibert@6wind.com>2023-02-10 10:27:23 +0100
commit6ccfd1030b42771cfb182e9e6ad53c5368d4b10e (patch)
tree38ecdb33c7a7b8ce1407dc1d8eb7be8d46426098 /bgpd/bgp_rpki.c
parentbgpd: handle network rd parameter in network configuration (diff)
downloadfrr-6ccfd1030b42771cfb182e9e6ad53c5368d4b10e.tar.xz
frr-6ccfd1030b42771cfb182e9e6ad53c5368d4b10e.zip
bgpd: add as notation support for bgp rpki service
Rpki service uses AS number: - some show commands use the as number as paramter. use asnotation support. - the as number of entries is displayed based on the asnotation mode of the chose bgp instance. Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'bgpd/bgp_rpki.c')
-rw-r--r--bgpd/bgp_rpki.c53
1 files changed, 36 insertions, 17 deletions
diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c
index 73c6fe0c4..50bbfc146 100644
--- a/bgpd/bgp_rpki.c
+++ b/bgpd/bgp_rpki.c
@@ -96,6 +96,7 @@ struct rpki_for_each_record_arg {
unsigned int *prefix_amount;
as_t as;
json_object *json;
+ enum asnotation_mode asnotation;
};
static int start(void);
@@ -120,7 +121,7 @@ static void rpki_delete_all_cache_nodes(void);
static int add_tcp_cache(const char *host, const char *port,
const uint8_t preference, const char *bindaddr);
static void print_record(const struct pfx_record *record, struct vty *vty,
- json_object *json);
+ json_object *json, enum asnotation_mode asnotation);
static bool is_synchronized(void);
static bool is_running(void);
static bool is_stopping(void);
@@ -285,7 +286,7 @@ static void rpki_delete_all_cache_nodes(void)
}
static void print_record(const struct pfx_record *record, struct vty *vty,
- json_object *json)
+ json_object *json, enum asnotation_mode asnotation)
{
char ip[INET6_ADDRSTRLEN];
json_object *json_record = NULL;
@@ -293,8 +294,10 @@ static void print_record(const struct pfx_record *record, struct vty *vty,
lrtr_ip_addr_to_str(&record->prefix, ip, sizeof(ip));
if (!json) {
- vty_out(vty, "%-40s %3u - %3u %10u\n", ip, record->min_len,
- record->max_len, record->asn);
+ vty_out(vty, "%-40s %3u - %3u ", ip, record->min_len,
+ record->max_len);
+ vty_out(vty, ASN_FORMAT(asnotation), &record->asn);
+ vty_out(vty, "\n");
} else {
json_record = json_object_new_object();
json_object_string_add(json_record, "prefix", ip);
@@ -302,7 +305,7 @@ static void print_record(const struct pfx_record *record, struct vty *vty,
record->min_len);
json_object_int_add(json_record, "prefixLenMax",
record->max_len);
- json_object_int_add(json_record, "asn", record->asn);
+ asn_asn2json(json_record, "asn", record->asn, asnotation);
json_object_array_add(json, json_record);
}
}
@@ -314,7 +317,7 @@ static void print_record_by_asn(const struct pfx_record *record, void *data)
if (record->asn == arg->as) {
(*arg->prefix_amount)++;
- print_record(record, vty, arg->json);
+ print_record(record, vty, arg->json, arg->asnotation);
}
}
@@ -325,7 +328,7 @@ static void print_record_cb(const struct pfx_record *record, void *data)
(*arg->prefix_amount)++;
- print_record(record, vty, arg->json);
+ print_record(record, vty, arg->json, arg->asnotation);
}
static struct rtr_mgr_group *get_groups(void)
@@ -743,6 +746,7 @@ static void print_prefix_table_by_asn(struct vty *vty, as_t as,
arg.vty = vty;
arg.as = as;
arg.json = NULL;
+ arg.asnotation = bgp_get_asnotation(bgp_lookup_by_vrf_id(VRF_DEFAULT));
if (!group) {
if (!json)
@@ -795,6 +799,7 @@ static void print_prefix_table(struct vty *vty, json_object *json)
arg.vty = vty;
arg.json = NULL;
+ arg.asnotation = bgp_get_asnotation(bgp_lookup_by_vrf_id(VRF_DEFAULT));
if (!group) {
if (!json)
@@ -1352,7 +1357,7 @@ DEFPY (show_rpki_prefix_table,
DEFPY (show_rpki_as_number,
show_rpki_as_number_cmd,
- "show rpki as-number (1-4294967295)$by_asn [json$uj]",
+ "show rpki as-number ASNUM$by_asn [json$uj]",
SHOW_STR
RPKI_OUTPUT_STRING
"Lookup by ASN in prefix table\n"
@@ -1360,23 +1365,28 @@ DEFPY (show_rpki_as_number,
JSON_STR)
{
struct json_object *json = NULL;
+ as_t as;
if (!is_synchronized()) {
if (!uj)
vty_out(vty, "No Connection to RPKI cache server.\n");
return CMD_WARNING;
}
-
+ if (!asn_str2asn(by_asn, &as)) {
+ if (!uj)
+ vty_out(vty, "Invalid AS value: %s.\n", by_asn);
+ return CMD_WARNING;
+ }
if (uj)
json = json_object_new_object();
- print_prefix_table_by_asn(vty, by_asn, json);
+ print_prefix_table_by_asn(vty, as, json);
return CMD_SUCCESS;
}
DEFPY (show_rpki_prefix,
show_rpki_prefix_cmd,
- "show rpki prefix <A.B.C.D/M|X:X::X:X/M> [(1-4294967295)$asn] [json$uj]",
+ "show rpki prefix <A.B.C.D/M|X:X::X:X/M> [ASNUM$asn] [json$uj]",
SHOW_STR
RPKI_OUTPUT_STRING
"Lookup IP prefix and optionally ASN in prefix table\n"
@@ -1387,6 +1397,8 @@ DEFPY (show_rpki_prefix,
{
json_object *json = NULL;
json_object *json_records = NULL;
+ as_t as;
+ enum asnotation_mode asnotation;
if (!is_synchronized()) {
if (!uj)
@@ -1407,13 +1419,19 @@ DEFPY (show_rpki_prefix,
return CMD_WARNING;
}
+ if (asn && !asn_str2asn(asn, &as)) {
+ if (!uj)
+ vty_out(vty, "Invalid AS value: %s.\n", asn);
+ return CMD_WARNING;
+ }
+
struct pfx_record *matches = NULL;
unsigned int match_count = 0;
enum pfxv_state result;
if (pfx_table_validate_r(rtr_config->pfx_table, &matches, &match_count,
- asn, &addr, prefix->prefixlen, &result)
- != PFX_SUCCESS) {
+ as, &addr, prefix->prefixlen,
+ &result) != PFX_SUCCESS) {
if (!json)
vty_out(vty, "Prefix lookup failed\n");
return CMD_WARNING;
@@ -1430,13 +1448,14 @@ DEFPY (show_rpki_prefix,
json_object_object_add(json, "prefixes", json_records);
}
+ asnotation = bgp_get_asnotation(bgp_lookup_by_vrf_id(VRF_DEFAULT));
for (size_t i = 0; i < match_count; ++i) {
const struct pfx_record *record = &matches[i];
- if (record->max_len >= prefix->prefixlen
- && ((asn != 0 && (uint32_t)asn == record->asn)
- || asn == 0)) {
- print_record(&matches[i], vty, json_records);
+ if (record->max_len >= prefix->prefixlen &&
+ ((as != 0 && (uint32_t)as == record->asn) || as == 0)) {
+ print_record(&matches[i], vty, json_records,
+ asnotation);
}
}