Skip to content

Commit

Permalink
initial support for as-transparent route-servers
Browse files Browse the repository at this point in the history
  • Loading branch information
snar committed Feb 21, 2021
1 parent 2c6e84a commit 3a8fe87
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 20 deletions.
6 changes: 5 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
0.1.36-pre (2020-12-21):
0.1.36-pre (2021-02-21):
- initial support for as-transparent route-servers in import as-path
generation: now you can use -f 0 to not enforce first asn in path.
No actual changes for Bird and JSON, not yet supported for Nokia
(including MD) and OpenBGPD. Use case reported by Mikhail Grishin.
- correct sequencing in empty prefix-lists. Reported by Brooks Swinnerton.
- fix empty route-filter-lists generation. Reported by Antti Ristimäki.
- minor documentation cleanup: bgpq3 supports much more vendors
Expand Down
19 changes: 14 additions & 5 deletions bgpq3.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ vendor_exclusive()
};

int
parseasnumber(struct bgpq_expander* expander, char* optarg)
parseasnumber(struct bgpq_expander* expander, char* optarg, int zero)
{
char* eon=NULL;
expander->asnumber=strtoul(optarg,&eon,10);
if(expander->asnumber<1 || expander->asnumber>(65535ul*65535)) {
if((!zero && expander->asnumber<1) ||
expander->asnumber>(65535ul*65535)) {
sx_report(SX_FATAL,"Invalid AS number: %s\n", optarg);
exit(1);
};
Expand Down Expand Up @@ -173,7 +174,7 @@ main(int argc, char* argv[])
expander.tree->family=AF_INET6;
break;
case 'a':
parseasnumber(&expander,optarg);
parseasnumber(&expander,optarg,0);
break;
case 'A':
if(aggregate) debug_aggregation++;
Expand Down Expand Up @@ -202,12 +203,12 @@ main(int argc, char* argv[])
case 'f':
if(expander.generation) exclusive();
expander.generation=T_ASPATH;
parseasnumber(&expander,optarg);
parseasnumber(&expander,optarg,1);
break;
case 'G':
if(expander.generation) exclusive();
expander.generation=T_OASPATH;
parseasnumber(&expander,optarg);
parseasnumber(&expander,optarg,0);
break;
case 'h': {
char* d=strchr(optarg, ':');
Expand Down Expand Up @@ -566,6 +567,14 @@ main(int argc, char* argv[])
sx_report(SX_FATAL, "Sorry, -w makes sense only for as-path (-f/-G) "
"generation\n");
};
if(expander.generation==T_ASPATH && expander.asnumber==0 &&
(expander.vendor==V_OPENBGPD)) {
sx_report(SX_FATAL, "Sorry, -f 0 makes no sense with OpenBGPD\n");
};
if(expander.generation==T_ASPATH && expander.asnumber==0 &&
(expander.vendor==V_NOKIA || expander.vendor==V_NOKIA_MD)) {
sx_report(SX_FATAL, "Sorry, -f 0 is not yet implemented for Nokia\n");
};

if(!argv[0])
usage(1);
Expand Down
49 changes: 35 additions & 14 deletions bgpq3_printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ bgpq3_print_cisco_aspath(FILE* f, struct bgpq_expander* b)
if(b->asn32s[b->asnumber/65536] &&
b->asn32s[b->asnumber/65536][(b->asnumber%65536)/8]&
(0x80>>(b->asnumber%8))) {
if(b->asdot && b->asnumber>65535) {
if(b->asdot && b->asnumber>65535) { /* b->asnumber > 0 is implied */
fprintf(f,"ip as-path access-list %s permit ^%u.%u(_%u.%u)*$\n",
b->name?b->name:"NN",b->asnumber/65536,b->asnumber%65536,
b->asnumber/65536,b->asnumber%65536);
empty=0;
} else {
} else if (b->asnumber>0) {
fprintf(f,"ip as-path access-list %s permit ^%u(_%u)*$\n",
b->name?b->name:"NN",b->asnumber,b->asnumber);
empty=0;
Expand All @@ -46,18 +46,26 @@ bgpq3_print_cisco_aspath(FILE* f, struct bgpq_expander* b)
for(i=0;i<8192;i++) {
for(j=0;j<8;j++) {
if(b->asn32s[k][i]&(0x80>>j)) {
if(k*65536+i*8+j==b->asnumber) continue;
if(b->asnumber>0 && k*65536+i*8+j==b->asnumber)
continue;
if(!nc) {
if(b->asdot && k>0) {
if(b->asdot && k>0 && b->asnumber>0) {
fprintf(f,"ip as-path access-list %s permit"
" ^%u(_[0-9]+)*_(%u.%u", b->name?b->name:"NN",
b->asnumber,k,i*8+j);
empty=0;
} else {
} else if(b->asnumber>0) {
fprintf(f,"ip as-path access-list %s permit"
" ^%u(_[0-9]+)*_(%u", b->name?b->name:"NN",
b->asnumber,k*65536+i*8+j);
empty=0;
} else if(b->asdot && k>0) {
/* b->asnumber==0 is implied */
fprintf(f,"ip as-path access-list %s permit"
" ^.*(%u.%u", b->name?b->name:"NN",k,i*8+j);
} else {
fprintf(f,"ip as-path access-list %s permit"
" ^.*(%u",b->name?b->name:"NN",k*65536+i*8+j);
};
} else {
if(b->asdot && k>0) {
Expand Down Expand Up @@ -88,7 +96,7 @@ bgpq3_print_cisco_xr_aspath(FILE* f, struct bgpq_expander* b)
{
int nc=0, i, j, k, comma=0;
fprintf(f, "as-path-set %s", b->name?b->name:"NN");
if(b->asn32s[b->asnumber/65536] &&
if(b->asnumber!=0 && b->asn32s[b->asnumber/65536] &&
b->asn32s[b->asnumber/65536][(b->asnumber%65536)/8]&
(0x80>>(b->asnumber%8))) {
fprintf(f,"\n ios-regex '^%u(_%u)*$'", b->asnumber,b->asnumber);
Expand All @@ -100,11 +108,16 @@ bgpq3_print_cisco_xr_aspath(FILE* f, struct bgpq_expander* b)
for(i=0;i<8192;i++) {
for(j=0;j<8;j++) {
if(b->asn32s[k][i]&(0x80>>j)) {
if(k*65536+i*8+j==b->asnumber) continue;
if(!nc) {
if(b->asnumber!=0 && k*65536+i*8+j==b->asnumber)
continue;
if(!nc && b->asnumber!=0) {
fprintf(f,"%s\n ios-regex '^%u(_[0-9]+)*_(%u",
comma?",":"", b->asnumber,k*65536+i*8+j);
comma=1;
} else if(!nc) {
fprintf(f,"%s\n ios-regex '^([0-9]+_)*(%u",
comma?",":"",k*65536+i*8+j);
comma=1;
} else {
fprintf(f,"|%u",k*65536+i*8+j);
}
Expand Down Expand Up @@ -225,7 +238,7 @@ bgpq3_print_juniper_aspath(FILE* f, struct bgpq_expander* b)
fprintf(f,"policy-options {\nreplace:\n as-path-group %s {\n",
b->name?b->name:"NN");

if(b->asn32s[b->asnumber/65536] &&
if(b->asnumber!=0 && b->asn32s[b->asnumber/65536] &&
b->asn32s[b->asnumber/65535][(b->asnumber%65536)/8]&
(0x80>>(b->asnumber%8))) {
fprintf(f," as-path a%u \"^%u(%u)*$\";\n", lineNo, b->asnumber,
Expand All @@ -237,10 +250,14 @@ bgpq3_print_juniper_aspath(FILE* f, struct bgpq_expander* b)
for(i=0;i<8192;i++) {
for(j=0;j<8;j++) {
if(b->asn32s[k][i]&(0x80>>j)) {
if(k*65536+i*8+j==b->asnumber) continue;
if(!nc) {
if(b->asnumber!=0 && k*65536+i*8+j==b->asnumber)
continue;
if(!nc && b->asnumber!=0) {
fprintf(f," as-path a%u \"^%u(.)*(%u",
lineNo,b->asnumber,k*65536+i*8+j);
} else if (!nc) {
fprintf(f," as-path a%u \"^.*(%u", lineNo,
k*65536+i*8+j);
} else {
fprintf(f,"|%u",k*65536+i*8+j);
};
Expand Down Expand Up @@ -422,7 +439,7 @@ bgpq3_print_huawei_aspath(FILE* f, struct bgpq_expander* b)
fprintf(f,"undo ip as-path-filter %s\n",
b->name ? b->name : "NN");

if(b->asn32s[b->asnumber/65536] &&
if(b->asnumber!=0 && b->asn32s[b->asnumber/65536] &&
b->asn32s[b->asnumber/65535][(b->asnumber%65536)/8]&
(0x80>>(b->asnumber%8))) {
fprintf(f,"ip as-path-filter %s permit ^%u(%u)*$\n",
Expand All @@ -434,12 +451,16 @@ bgpq3_print_huawei_aspath(FILE* f, struct bgpq_expander* b)
for(i=0;i<8192;i++) {
for(j=0;j<8;j++) {
if(b->asn32s[k][i]&(0x80>>j)) {
if(k*65536+i*8+j==b->asnumber) continue;
if(!nc) {
if(b->asnumber!=0 && k*65536+i*8+j==b->asnumber)
continue;
if(!nc && b->asnumber!=0) {
fprintf(f,"ip as-path-filter %s permit ^%u([0-9]+)*"
"_(%u",
b->name?b->name:"NN",b->asnumber,k*65536+i*8+j);
empty=0;
} else if (!nc) {
fprintf(f,"ip as-path-filter %s permit ^.*_(%u",
b->name?b->name:"NN",k*65536+i*8+j);
} else {
fprintf(f,"|%u",k*65536+i*8+j);
};
Expand Down

0 comments on commit 3a8fe87

Please sign in to comment.