mirror of
https://github.com/bgp/bgpq4.git
synced 2024-05-11 05:55:05 +00:00
ok, asn32 now fully supported (for Juniper only).
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -1,3 +1,6 @@
|
||||
0.1.2 (2008-05-19):
|
||||
- final support for asn32, now with correct syntax for Juniper.
|
||||
|
||||
0.1.1 (2008-05-16):
|
||||
- initial support for asn32 added (flag -3). By default it's off,
|
||||
and when bgpq sees 32-bit asn in resolver queue, it either replaces
|
||||
|
||||
55
bgpq3.c
55
bgpq3.c
@@ -47,6 +47,41 @@ exclusive()
|
||||
exit(1);
|
||||
};
|
||||
|
||||
int
|
||||
parseasnumber(struct bgpq_expander* expander, char* optarg)
|
||||
{
|
||||
char* eon=NULL;
|
||||
expander->asnumber=strtoul(optarg,&eon,10);
|
||||
if(expander->asnumber<0 || expander->asnumber>(65535ul*65535)) {
|
||||
sx_report(SX_FATAL,"Invalid AS number: %s\n", optarg);
|
||||
exit(1);
|
||||
};
|
||||
if(eon && *eon=='.') {
|
||||
/* -f 3.3, for example */
|
||||
uint32_t loas=strtoul(eon+1,&eon,10);
|
||||
if(expander->asnumber>65535) {
|
||||
/* should prevent incorrect numbers like 65537.1 */
|
||||
sx_report(SX_FATAL,"Invalid AS number: %s\n", optarg);
|
||||
exit(1);
|
||||
};
|
||||
if(loas<0 || loas>65536) {
|
||||
sx_report(SX_FATAL,"Invalid AS number: %s\n", optarg);
|
||||
exit(1);
|
||||
};
|
||||
if(eon && *eon) {
|
||||
sx_report(SX_FATAL,"Invalid symbol in AS number: %c (%s)\n",
|
||||
*eon, optarg);
|
||||
exit(1);
|
||||
};
|
||||
expander->asnumber=(expander->asnumber<<16)+loas;
|
||||
} else if(eon && *eon) {
|
||||
sx_report(SX_FATAL,"Invalid symbol in AS number: %c (%s)\n",
|
||||
*eon, optarg);
|
||||
exit(1);
|
||||
};
|
||||
return 0;
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
@@ -71,21 +106,15 @@ main(int argc, char* argv[])
|
||||
break;
|
||||
case 'J': expander.vendor=V_JUNIPER;
|
||||
break;
|
||||
case 'f': expander.asnumber=atoi(optarg);
|
||||
if(expander.asnumber<0 || expander.asnumber>65535) {
|
||||
sx_report(SX_FATAL,"Invalid AS number: %s\n", optarg);
|
||||
exit(1);
|
||||
};
|
||||
case 'f':
|
||||
if(expander.generation) exclusive();
|
||||
expander.generation=T_ASPATH;
|
||||
parseasnumber(&expander,optarg);
|
||||
break;
|
||||
case 'G': expander.asnumber=atoi(optarg);
|
||||
if(expander.asnumber<0 || expander.asnumber>65535) {
|
||||
sx_report(SX_FATAL,"Invalid AS number: %s\n", optarg);
|
||||
exit(1);
|
||||
};
|
||||
case 'G':
|
||||
if(expander.generation) exclusive();
|
||||
expander.generation=T_OASPATH;
|
||||
parseasnumber(&expander,optarg);
|
||||
break;
|
||||
case 'P':
|
||||
if(expander.generation) exclusive();
|
||||
@@ -134,8 +163,10 @@ main(int argc, char* argv[])
|
||||
expander.generation<T_PREFIXLIST) {
|
||||
sx_report(SX_FATAL,"Sorry, AS32-safety is not yet ready for Cisco\n");
|
||||
};
|
||||
|
||||
|
||||
|
||||
if(!expander.asn32 && expander.asnumber>=65536) {
|
||||
expander.asnumber=23456;
|
||||
};
|
||||
|
||||
if(!argv[0]) usage(1);
|
||||
|
||||
|
||||
@@ -82,8 +82,10 @@ 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[0][b->asnumber/8]&(0x80>>(b->asnumber%8))) {
|
||||
fprintf(f," as-path a%i \"^%i(%i)*$\";\n", lineNo, b->asnumber,
|
||||
if(b->asn32s[b->asnumber/65536] &&
|
||||
b->asn32s[b->asnumber/65535][(b->asnumber/65536)/8]&
|
||||
(0x80>>(b->asnumber%8))) {
|
||||
fprintf(f," as-path a%i \"^%u(%u)*$\";\n", lineNo, b->asnumber,
|
||||
b->asnumber);
|
||||
lineNo++;
|
||||
};
|
||||
@@ -92,21 +94,12 @@ 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(i*8+j==b->asnumber) continue;
|
||||
if(k*65536+i*8+j==b->asnumber) continue;
|
||||
if(!nc) {
|
||||
if(k) {
|
||||
fprintf(f," as-path a%i \"^%i(.)*(%u.%u",
|
||||
lineNo,b->asnumber,k,i*8+j);
|
||||
} else {
|
||||
fprintf(f," as-path a%i \"^%i(.)*(%u",
|
||||
lineNo,b->asnumber,i*8+j);
|
||||
};
|
||||
fprintf(f," as-path a%i \"^%u(.)*(%u",
|
||||
lineNo,b->asnumber,k*65536+i*8+j);
|
||||
} else {
|
||||
if(k) {
|
||||
fprintf(f,"|%u.%u",k,i*8+j);
|
||||
} else {
|
||||
fprintf(f,"|%u",i*8+j);
|
||||
};
|
||||
fprintf(f,"|%u",k*65536+i*8+j);
|
||||
};
|
||||
nc++;
|
||||
if(nc==b->aswidth) {
|
||||
@@ -130,8 +123,10 @@ bgpq3_print_juniper_oaspath(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[0][b->asnumber/8]&(0x80>>(b->asnumber%8))) {
|
||||
fprintf(f," as-path a%i \"^%i(%i)*$\";\n", lineNo, b->asnumber,
|
||||
if(b->asn32s[b->asnumber/65536] &&
|
||||
b->asn32s[b->asnumber/65536][(b->asnumber/65536)/8]&
|
||||
(0x80>>(b->asnumber%8))) {
|
||||
fprintf(f," as-path a%i \"^%u(%u)*$\";\n", lineNo, b->asnumber,
|
||||
b->asnumber);
|
||||
lineNo++;
|
||||
};
|
||||
@@ -141,21 +136,12 @@ bgpq3_print_juniper_oaspath(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(i*8+j==b->asnumber) continue;
|
||||
if(k*65536+i*8+j==b->asnumber) continue;
|
||||
if(!nc) {
|
||||
if(!k) {
|
||||
fprintf(f," as-path a%i \"^(.)*(%u",
|
||||
lineNo,i*8+j);
|
||||
} else {
|
||||
fprintf(f," as-path a%i \"^(.)*(%u.%u",
|
||||
lineNo,k,i*8+j);
|
||||
};
|
||||
fprintf(f," as-path a%i \"^(.)*(%u",
|
||||
lineNo,k*65536+i*8+j);
|
||||
} else {
|
||||
if(!k) {
|
||||
fprintf(f,"|%u",i*8+j);
|
||||
} else {
|
||||
fprintf(f,"|%u.%u",k,i*8+j);
|
||||
};
|
||||
fprintf(f,"|%u",k*65536+i*8+j);
|
||||
}
|
||||
nc++;
|
||||
if(nc==b->aswidth) {
|
||||
|
||||
Reference in New Issue
Block a user