Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement RFC 8050/7911 MRT Additional Path extension #203

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/bgpstream_bgpdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ char *bgpstream_record_elem_bgpdump_snprintf(char *buf, size_t len,
/* Record type */
switch (elem->type) {
case BGPSTREAM_ELEM_TYPE_RIB:
c = snprintf(buf_p, B_REMAIN, "TABLE_DUMP2|%" PRIu32, record->time_sec);
c = snprintf(buf_p, B_REMAIN, "TABLE_DUMP2%s|%" PRIu32,
elem->has_addl_path_id ? "_AP" : "", record->time_sec);
break;
case BGPSTREAM_ELEM_TYPE_ANNOUNCEMENT:
case BGPSTREAM_ELEM_TYPE_WITHDRAWAL:
case BGPSTREAM_ELEM_TYPE_PEERSTATE:
c = snprintf(buf_p, B_REMAIN, "BGP4MP|%" PRIu32, record->time_sec);
c = snprintf(buf_p, B_REMAIN, "BGP4MP%s|%" PRIu32,
elem->has_addl_path_id ? "_AP" : "", record->time_sec);
break;
default:
c = 0;
Expand Down Expand Up @@ -132,6 +134,13 @@ char *bgpstream_record_elem_bgpdump_snprintf(char *buf, size_t len,
SEEK_STR_END;
ADD_PIPE;

if (elem->has_addl_path_id) {
c = snprintf(buf_p, B_REMAIN, "%" PRIu32, elem->addl_path_id);
written += c;
buf_p += c;
ADD_PIPE;
}

/* AS PATH */
c = bgpstream_as_path_snprintf(buf_p, B_REMAIN, elem->as_path);
written += c;
Expand Down
5 changes: 5 additions & 0 deletions lib/bgpstream_elem.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ char *bgpstream_elem_custom_snprintf(char *buf, size_t len,
return NULL;
}
SEEK_STR_END;
if (elem->has_addl_path_id) {
c = snprintf(buf_p, B_REMAIN, "#%" PRIu32, elem->addl_path_id);
written += c;
buf_p += c;
}
ADD_PIPE;

/* NEXT HOP */
Expand Down
9 changes: 9 additions & 0 deletions lib/bgpstream_elem.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ typedef struct bgpstream_elem {
*/
bgpstream_pfx_t prefix;

/** Additional Path Identifier (RFC 7911)
*
* Available only for RIB, Announcement and Withdrawal elem types
*/
uint32_t addl_path_id;

/** Set if the addl_path_id field is valid */
uint8_t has_addl_path_id;

/** Next hop
*
* Available only for RIB and Announcement elem types
Expand Down
6 changes: 6 additions & 0 deletions lib/formats/bs_format_mrt.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ static int handle_table_dump(rec_data_t *rd, parsebgp_mrt_msg_t *mrt)
el->type = BGPSTREAM_ELEM_TYPE_RIB;
el->orig_time_sec = td->originated_time;
el->orig_time_usec = 0;
el->has_addl_path_id = 0;
el->addl_path_id = 0;

COPY_IP(&el->peer_ip, mrt->subtype, &td->peer_ip, return -1);

Expand Down Expand Up @@ -122,6 +124,8 @@ static int handle_td2_rib_entry(rec_data_t *rd, khash_t(td2_peer) * peer_table,

rd->elem->orig_time_sec = re->originated_time;
rd->elem->orig_time_usec = 0;
rd->elem->has_addl_path_id = re->has_addl_path_id;
rd->elem->addl_path_id = re->addl_path_id;

// look the peer up in the peer index table
if ((k = kh_get(td2_peer, peer_table, re->peer_index)) ==
Expand Down Expand Up @@ -202,9 +206,11 @@ static int handle_table_dump_v2(rec_data_t *rd, khash_t(td2_peer) * peer_table,
break;

case PARSEBGP_MRT_TABLE_DUMP_V2_RIB_IPV4_UNICAST:
case PARSEBGP_MRT_TABLE_DUMP_V2_RIB_IPV4_UNICAST_ADDPATH:
return handle_td2_afi_safi_rib(rd, peer_table, mrt, PARSEBGP_BGP_AFI_IPV4,
&td2->afi_safi_rib);
case PARSEBGP_MRT_TABLE_DUMP_V2_RIB_IPV6_UNICAST:
case PARSEBGP_MRT_TABLE_DUMP_V2_RIB_IPV6_UNICAST_ADDPATH:
return handle_td2_afi_safi_rib(rd, peer_table, mrt, PARSEBGP_BGP_AFI_IPV6,
&td2->afi_safi_rib);

Expand Down
2 changes: 1 addition & 1 deletion lib/formats/libparsebgp
4 changes: 2 additions & 2 deletions tools/bgpreader.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
"# Elem format:\n" \
"# " \
"<rec-type>|<elem-type>|<rec-ts-sec>.<rec-ts-usec>|<project>|<collector>|<" \
"router>|<router-ip>|<peer-ASN>|<peer-IP>|<prefix>|<next-hop-IP>|<AS-path>|" \
"<origin-AS>|<communities>|<old-state>|<new-state>\n" \
"router>|<router-ip>|<peer-ASN>|<peer-IP>|<prefix>[#<path_id>]|<next-hop-IP>"\
"|<AS-path>|<origin-AS>|<communities>|<old-state>|<new-state>\n" \
"#\n" \
"# <rec-type>: R RIB, U Update\n" \
"# <elem-type>: R RIB, A announcement, W withdrawal, S state message\n" \
Expand Down