diff options
| author | Russ White <russ@riw.us> | 2023-02-21 08:01:03 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-21 08:01:03 -0500 | 
| commit | ba755d35e508c2452e5459bdd7c0dd67a70a88a4 (patch) | |
| tree | adc08f46788b8012240faec23ae7e7271bb0d40d /bgpd/bgp_rpki.c | |
| parent | 39c664c4ea530a9460efa1a78fe669ae56c85f83 (diff) | |
| parent | 616e9f0d9f0458788adf4b30707016c8db383b02 (diff) | |
Merge pull request #12248 from pguibert6WIND/bgpasdot
lib, bgp: add initial support for asdot format
Diffstat (limited to 'bgpd/bgp_rpki.c')
| -rw-r--r-- | bgpd/bgp_rpki.c | 53 | 
1 files changed, 36 insertions, 17 deletions
diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index 61b8b4edce..d7e1a6341b 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -81,6 +81,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); @@ -105,7 +106,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); @@ -270,7 +271,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; @@ -278,8 +279,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); @@ -287,7 +290,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);  	}  } @@ -299,7 +302,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);  	}  } @@ -310,7 +313,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) @@ -728,6 +731,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) @@ -780,6 +784,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) @@ -1337,7 +1342,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" @@ -1345,23 +1350,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" @@ -1372,6 +1382,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) @@ -1392,13 +1404,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; @@ -1415,13 +1433,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);  		}  	}  | 
