Skip to content

Add large BGP communities support #3

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions zebra-dump-parser.pl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
BGP_ATTR_MP_REACH_NLRI => 14,
BGP_ATTR_MP_UNREACH_NLRI => 15,
BGP_ATTR_EXT_COMMUNITIES => 16,
BGP_ATTR_LARGE_COMMUNITIES => 32,
};

my @BGP_ORIGIN = qw(IGP EGP Incomplete);
Expand Down Expand Up @@ -377,6 +378,12 @@ sub parse_attributes {
my $community = substr($attrib, 0, 4, '');
push(@{$attr[BGP_ATTR_COMMUNITIES]}, $community);
}
} elsif ($type == BGP_ATTR_LARGE_COMMUNITIES) {
$attr[BGP_ATTR_LARGE_COMMUNITIES] = [ ];
while (length $attrib > 0) {
my $community = substr($attrib, 0, 12, '');
push(@{$attr[BGP_ATTR_LARGE_COMMUNITIES]}, $community);
}
} elsif ($type == BGP_ATTR_MP_REACH_NLRI) {
# FIXME v2 uses a different format
my ($afi, $safi, $next_hop, $rest) = unpack('n C C/a a*', $attrib);
Expand Down Expand Up @@ -517,6 +524,9 @@ sub print_verbose_attributes {
print "COMMUNITIES: "
. print_communities(@{$attr->[BGP_ATTR_COMMUNITIES]}) . "\n"
if $attr->[BGP_ATTR_COMMUNITIES];
print "LARGE_COMMUNITIES: "
. print_large_communities(@{$attr->[BGP_ATTR_LARGE_COMMUNITIES]}) . "\n"
if $attr->[BGP_ATTR_LARGE_COMMUNITIES];
}

sub print_communities {
Expand All @@ -529,6 +539,16 @@ sub print_communities {
return join(' ', @communities);
}

sub print_large_communities {
my @communities;
foreach my $community (@_) {
my ($ga, $ldp1, $ldp2) = unpack('N N N', $community);
push(@communities, "${ga}:${ldp1}:${ldp2}");
}

return join(' ', @communities);
}

sub pretty_as {
my ($as_hi, $as_lo) = unpack('nn', $_[0]);
return defined $as_lo ? ($as_hi ? unpack('N', $_[0]) : $as_lo) : $as_hi;
Expand Down