mirror of
https://github.com/bgp/bgpq4.git
synced 2024-05-11 05:55:05 +00:00
Remove the option to disable 32-bit ASN support
This removes the '-3' command line option and fixes #3.
This commit is contained in:
@@ -7,7 +7,7 @@ SYNOPSIS
|
|||||||
--------
|
--------
|
||||||
|
|
||||||
```
|
```
|
||||||
bgpq4 [-h host[:port]] [-S sources] [-Ez] [-f asn | -F fmt | -G asn | -t] [-346ABbDdJjNnpsUX] [-a asn] [-r len] [-R len] [-m max] [-W len] OBJECTS [...] EXCEPT OBJECTS
|
bgpq4 [-h host[:port]] [-S sources] [-Ez] [-f asn | -F fmt | -G asn | -t] [-46ABbDdJjNnpsUX] [-a asn] [-r len] [-R len] [-m max] [-W len] OBJECTS [...] EXCEPT OBJECTS
|
||||||
```
|
```
|
||||||
|
|
||||||
DESCRIPTION
|
DESCRIPTION
|
||||||
@@ -19,10 +19,6 @@ based on RADB data.
|
|||||||
|
|
||||||
The options are as follows:
|
The options are as follows:
|
||||||
|
|
||||||
#### -3
|
|
||||||
|
|
||||||
Assume that your device is asn32-capable.
|
|
||||||
|
|
||||||
#### -4
|
#### -4
|
||||||
|
|
||||||
Generate IPv4 prefix/access-lists (default).
|
Generate IPv4 prefix/access-lists (default).
|
||||||
|
4
bgpq4.8
4
bgpq4.8
@@ -39,7 +39,7 @@
|
|||||||
.Fl G Ar asn
|
.Fl G Ar asn
|
||||||
.Fl t
|
.Fl t
|
||||||
.Oc
|
.Oc
|
||||||
.Op Fl 2346ABbDdJjNnsXU
|
.Op Fl 46ABbDdJjNnsXU
|
||||||
.Op Fl a Ar asn
|
.Op Fl a Ar asn
|
||||||
.Op Fl r Ar len
|
.Op Fl r Ar len
|
||||||
.Op Fl R Ar len
|
.Op Fl R Ar len
|
||||||
@@ -56,8 +56,6 @@ access-lists, policy-statement terms and as-path lists) based on RADB data.
|
|||||||
.Pp
|
.Pp
|
||||||
The options are as follows:
|
The options are as follows:
|
||||||
.Bl -tag -width Ds
|
.Bl -tag -width Ds
|
||||||
.It Fl 3
|
|
||||||
assume that your device is asn32-safe.
|
|
||||||
.It Fl 4
|
.It Fl 4
|
||||||
generate IPv4 prefix/access-lists (default).
|
generate IPv4 prefix/access-lists (default).
|
||||||
.It Fl 6
|
.It Fl 6
|
||||||
|
14
bgpq4.c
14
bgpq4.c
@@ -27,8 +27,7 @@ int
|
|||||||
usage(int ecode)
|
usage(int ecode)
|
||||||
{
|
{
|
||||||
printf("\nUsage: bgpq4 [-h host[:port]] [-S sources] [-E|G <num>"
|
printf("\nUsage: bgpq4 [-h host[:port]] [-S sources] [-E|G <num>"
|
||||||
"|f <num>|t] [-346ABbdJjKNnwXz] [-R len] <OBJECTS>...\n");
|
"|f <num>|t] [-46ABbdJjKNnwXz] [-R len] <OBJECTS>...\n");
|
||||||
printf(" -3 : assume that your device is asn32-safe\n");
|
|
||||||
printf(" -4 : generate IPv4 prefix-lists (default)\n");
|
printf(" -4 : generate IPv4 prefix-lists (default)\n");
|
||||||
printf(" -6 : generate IPv6 prefix-lists\n");
|
printf(" -6 : generate IPv6 prefix-lists\n");
|
||||||
printf(" -A : try to aggregate prefix-lists/route-filters\n");
|
printf(" -A : try to aggregate prefix-lists/route-filters\n");
|
||||||
@@ -36,7 +35,7 @@ usage(int ecode)
|
|||||||
printf(" -b : generate BIRD output\n");
|
printf(" -b : generate BIRD output\n");
|
||||||
printf(" -d : generate some debugging output\n");
|
printf(" -d : generate some debugging output\n");
|
||||||
printf(" -E : generate extended access-list(Cisco), "
|
printf(" -E : generate extended access-list(Cisco), "
|
||||||
"route-filter(Juniper)\n"
|
"route-filter (Juniper)\n"
|
||||||
" [ip|ipv6]-prefix-list (Nokia) or prefix-set "
|
" [ip|ipv6]-prefix-list (Nokia) or prefix-set "
|
||||||
"(OpenBGPD)\n");
|
"(OpenBGPD)\n");
|
||||||
printf(" -F fmt : generate output in user-defined format\n");
|
printf(" -F fmt : generate output in user-defined format\n");
|
||||||
@@ -147,12 +146,9 @@ main(int argc, char* argv[])
|
|||||||
if (getenv("IRRD_SOURCES"))
|
if (getenv("IRRD_SOURCES"))
|
||||||
expander.sources=getenv("IRRD_SOURCES");
|
expander.sources=getenv("IRRD_SOURCES");
|
||||||
|
|
||||||
while ((c = getopt(argc,argv,"346a:AbBdDEF:S:jJKf:l:L:m:M:NnW:pr:R:G:tTh:UwXsz"))
|
while ((c = getopt(argc,argv,"46a:AbBdDEF:S:jJKf:l:L:m:M:NnW:pr:R:G:tTh:UwXsz"))
|
||||||
!=EOF) {
|
!=EOF) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '3':
|
|
||||||
expander.asn32 = 1;
|
|
||||||
break;
|
|
||||||
case '4':
|
case '4':
|
||||||
/* do nothing, expander already configured for IPv4 */
|
/* do nothing, expander already configured for IPv4 */
|
||||||
if (expander.family == AF_INET6) {
|
if (expander.family == AF_INET6) {
|
||||||
@@ -189,7 +185,6 @@ main(int argc, char* argv[])
|
|||||||
if (expander.vendor)
|
if (expander.vendor)
|
||||||
vendor_exclusive();
|
vendor_exclusive();
|
||||||
expander.vendor = V_OPENBGPD;
|
expander.vendor = V_OPENBGPD;
|
||||||
expander.asn32 = 1;
|
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
debug_expander++;
|
debug_expander++;
|
||||||
@@ -455,9 +450,6 @@ main(int argc, char* argv[])
|
|||||||
sx_report(SX_FATAL, "As-Sets (-t) supported for JSON (-j), OpenBGPD "
|
sx_report(SX_FATAL, "As-Sets (-t) supported for JSON (-j), OpenBGPD "
|
||||||
"(-B) and BIRD (-b) output only\n");
|
"(-B) and BIRD (-b) output only\n");
|
||||||
|
|
||||||
if (!expander.asn32 && expander.asnumber > 65535)
|
|
||||||
expander.asnumber = 23456;
|
|
||||||
|
|
||||||
if (aggregate && expander.vendor == V_JUNIPER && expander.generation == T_PREFIXLIST) {
|
if (aggregate && expander.vendor == V_JUNIPER && expander.generation == T_PREFIXLIST) {
|
||||||
sx_report(SX_FATAL, "Sorry, aggregation (-A) does not work in"
|
sx_report(SX_FATAL, "Sorry, aggregation (-A) does not work in"
|
||||||
" Juniper prefix-lists\nYou can try route-filters (-E) "
|
" Juniper prefix-lists\nYou can try route-filters (-E) "
|
||||||
|
1
bgpq4.h
1
bgpq4.h
@@ -60,7 +60,6 @@ struct bgpq_expander {
|
|||||||
int sequence;
|
int sequence;
|
||||||
int maxdepth;
|
int maxdepth;
|
||||||
int validate_asns;
|
int validate_asns;
|
||||||
unsigned char asn32;
|
|
||||||
unsigned char* asn32s[65536];
|
unsigned char* asn32s[65536];
|
||||||
struct bgpq_prequest* firstpipe, *lastpipe;
|
struct bgpq_prequest* firstpipe, *lastpipe;
|
||||||
int piped;
|
int piped;
|
||||||
|
108
bgpq4_printer.c
108
bgpq4_printer.c
@@ -24,61 +24,61 @@ int bgpq4_print_openbgpd_asset(FILE* f, struct bgpq_expander* b);
|
|||||||
int
|
int
|
||||||
bgpq4_print_cisco_aspath(FILE* f, struct bgpq_expander* b)
|
bgpq4_print_cisco_aspath(FILE* f, struct bgpq_expander* b)
|
||||||
{
|
{
|
||||||
|
|
||||||
int nc = 0, i, j, k, empty = 1;
|
int nc = 0, i, j, k, empty = 1;
|
||||||
|
|
||||||
fprintf(f, "no ip as-path access-list %s\n",
|
fprintf(f, "no ip as-path access-list %s\n", b->name ? b->name : "NN");
|
||||||
b->name ? b->name : "NN");
|
|
||||||
|
|
||||||
if (b->asn32s[b->asnumber / 65536] &&
|
if (b->asn32s[b->asnumber / 65536] &&
|
||||||
b->asn32s[b->asnumber / 65536][(b->asnumber % 65536)/8] &
|
b->asn32s[b->asnumber / 65536][(b->asnumber % 65536) / 8] &
|
||||||
(0x80 >> (b->asnumber % 8))) {
|
(0x80 >> (b->asnumber % 8))) {
|
||||||
fprintf(f,"ip as-path access-list %s permit "
|
fprintf(f,"ip as-path access-list %s permit ^%u(_%u)*$\n",
|
||||||
"^%u(_%u)*$\n", b->name ? b->name : "NN",
|
b->name?b->name:"NN",b->asnumber,b->asnumber);
|
||||||
b->asnumber, b->asnumber);
|
empty = 0;
|
||||||
empty = 0;
|
}
|
||||||
};
|
|
||||||
|
for(k = 0; k < 65536; k++) {
|
||||||
|
|
||||||
for (k = 0; k < 65536; k++) {
|
|
||||||
if (!b->asn32s[k])
|
if (!b->asn32s[k])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (i = 0; i < 8192; i++) {
|
for(i = 0; i < 8192; i++) {
|
||||||
for (j = 0; j <8 ; j++) {
|
for(j = 0; j <8;j++) {
|
||||||
if (b->asn32s[k][i] & (0x80 >> j)) {
|
if (b->asn32s[k][i] & (0x80>>j)) {
|
||||||
|
|
||||||
if (k * 65536 + i * 8 + j == b->asnumber)
|
if (k * 65536 + i * 8 + j == b->asnumber)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!nc) {
|
if (!nc) {
|
||||||
fprintf(f,"ip as-path access-list %s permit"
|
fprintf(f,"ip as-path access-list %s permit"
|
||||||
" ^%u(_[0-9]+)*_(%u",
|
" ^%u(_[0-9]+)*_(%u", b->name?b->name:"NN",
|
||||||
b->name ? b->name : "NN",
|
b->asnumber,k*65536+i*8+j);
|
||||||
b->asnumber,
|
empty=0;
|
||||||
k * 65536 + i * 8 + j);
|
} else {
|
||||||
empty = 0;
|
fprintf(f,"|%u",k*65536+i*8+j);
|
||||||
};
|
empty=0;
|
||||||
} else {
|
}
|
||||||
fprintf(f, "|%u", k * 65536 + i * 8 + j);
|
|
||||||
empty = 0;
|
nc++;
|
||||||
};
|
|
||||||
|
if (nc == b->aswidth) {
|
||||||
|
fprintf(f, ")$\n");
|
||||||
|
nc = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
nc++;
|
}
|
||||||
|
|
||||||
if (nc == b->aswidth) {
|
|
||||||
fprintf(f, ")$\n");
|
|
||||||
nc = 0;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
if (nc)
|
if (nc)
|
||||||
fprintf(f, ")$\n");
|
fprintf(f,")$\n");
|
||||||
|
|
||||||
if (empty)
|
if (empty)
|
||||||
fprintf(f, "ip as-path access-list %s deny .*\n",
|
fprintf(f, "ip as-path access-list %s deny .*\n",
|
||||||
b->name ? b->name : "NN");
|
b->name ? b->name : "NN");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
bgpq4_print_cisco_xr_aspath(FILE* f, struct bgpq_expander* b)
|
bgpq4_print_cisco_xr_aspath(FILE* f, struct bgpq_expander* b)
|
||||||
@@ -754,27 +754,28 @@ bgpq4_print_nokia_md_oaspath(FILE* f, struct bgpq_expander* b)
|
|||||||
int
|
int
|
||||||
bgpq4_print_aspath(FILE* f, struct bgpq_expander* b)
|
bgpq4_print_aspath(FILE* f, struct bgpq_expander* b)
|
||||||
{
|
{
|
||||||
if (b->vendor == V_JUNIPER) {
|
switch (b->vendor) {
|
||||||
|
case V_JUNIPER:
|
||||||
return bgpq4_print_juniper_aspath(f, b);
|
return bgpq4_print_juniper_aspath(f, b);
|
||||||
} else if (b->vendor == V_CISCO) {
|
case V_CISCO:
|
||||||
return bgpq4_print_cisco_aspath(f, b);
|
return bgpq4_print_cisco_aspath(f, b);
|
||||||
} else if (b->vendor == V_CISCO_XR) {
|
case V_CISCO_XR:
|
||||||
return bgpq4_print_cisco_xr_aspath(f, b);
|
return bgpq4_print_cisco_xr_aspath(f, b);
|
||||||
} else if (b->vendor == V_JSON) {
|
case V_JSON:
|
||||||
return bgpq4_print_json_aspath(f, b);
|
return bgpq4_print_json_aspath(f, b);
|
||||||
} else if (b->vendor == V_BIRD) {
|
case V_BIRD:
|
||||||
return bgpq4_print_bird_aspath(f, b);
|
return bgpq4_print_bird_aspath(f, b);
|
||||||
} else if (b->vendor == V_OPENBGPD) {
|
case V_OPENBGPD:
|
||||||
return bgpq4_print_openbgpd_aspath(f, b);
|
return bgpq4_print_openbgpd_aspath(f, b);
|
||||||
} else if (b->vendor == V_NOKIA) {
|
case V_NOKIA:
|
||||||
return bgpq4_print_nokia_aspath(f, b);
|
return bgpq4_print_nokia_aspath(f, b);
|
||||||
} else if (b->vendor == V_NOKIA_MD) {
|
case V_NOKIA_MD:
|
||||||
return bgpq4_print_nokia_md_aspath(f, b);
|
return bgpq4_print_nokia_md_aspath(f, b);
|
||||||
} else if (b->vendor == V_HUAWEI) {
|
case V_HUAWEI:
|
||||||
return bgpq4_print_huawei_aspath(f, b);
|
return bgpq4_print_huawei_aspath(f, b);
|
||||||
} else {
|
default:
|
||||||
sx_report(SX_FATAL,"Unknown vendor %i\n", b->vendor);
|
sx_report(SX_FATAL,"Unknown vendor %i\n", b->vendor);
|
||||||
};
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
@@ -782,23 +783,24 @@ bgpq4_print_aspath(FILE* f, struct bgpq_expander* b)
|
|||||||
int
|
int
|
||||||
bgpq4_print_oaspath(FILE* f, struct bgpq_expander* b)
|
bgpq4_print_oaspath(FILE* f, struct bgpq_expander* b)
|
||||||
{
|
{
|
||||||
if (b->vendor == V_JUNIPER) {
|
switch (b->vendor) {
|
||||||
|
case V_JUNIPER:
|
||||||
return bgpq4_print_juniper_oaspath(f, b);
|
return bgpq4_print_juniper_oaspath(f, b);
|
||||||
} else if (b->vendor == V_CISCO) {
|
case V_CISCO:
|
||||||
return bgpq4_print_cisco_oaspath(f, b);
|
return bgpq4_print_cisco_oaspath(f, b);
|
||||||
} else if (b->vendor == V_CISCO_XR) {
|
case V_CISCO_XR:
|
||||||
return bgpq4_print_cisco_xr_oaspath(f, b);
|
return bgpq4_print_cisco_xr_oaspath(f, b);
|
||||||
} else if (b->vendor == V_OPENBGPD) {
|
case V_OPENBGPD:
|
||||||
return bgpq4_print_openbgpd_oaspath(f, b);
|
return bgpq4_print_openbgpd_oaspath(f, b);
|
||||||
} else if (b->vendor == V_NOKIA) {
|
case V_NOKIA:
|
||||||
return bgpq4_print_nokia_oaspath(f, b);
|
return bgpq4_print_nokia_oaspath(f, b);
|
||||||
} else if (b->vendor == V_NOKIA_MD) {
|
case V_NOKIA_MD:
|
||||||
return bgpq4_print_nokia_md_oaspath(f, b);
|
return bgpq4_print_nokia_md_oaspath(f, b);
|
||||||
} else if (b->vendor == V_HUAWEI) {
|
case V_HUAWEI:
|
||||||
return bgpq4_print_huawei_oaspath(f, b);
|
return bgpq4_print_huawei_oaspath(f, b);
|
||||||
} else {
|
default:
|
||||||
sx_report(SX_FATAL,"Unknown vendor %i\n", b->vendor);
|
sx_report(SX_FATAL,"Unknown vendor %i\n", b->vendor);
|
||||||
};
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
@@ -161,77 +161,49 @@ int
|
|||||||
bgpq_expander_add_as(struct bgpq_expander* b, char* as)
|
bgpq_expander_add_as(struct bgpq_expander* b, char* as)
|
||||||
{
|
{
|
||||||
char* eoa;
|
char* eoa;
|
||||||
uint32_t asno;
|
uint32_t asn1 = 0, asn2 = 0;
|
||||||
|
uint32_t asno = 0;
|
||||||
|
|
||||||
if (!b || !as)
|
if (!b || !as)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
asno = strtoul(as+2,&eoa,10);
|
asno = strtoul(as + 2, &eoa, 10);
|
||||||
if (eoa && (*eoa!='.' && *eoa!=0)) {
|
|
||||||
|
if (eoa && *eoa != 0) {
|
||||||
sx_report(SX_ERROR,"Invalid symbol in AS number: '%c' in %s\n",
|
sx_report(SX_ERROR,"Invalid symbol in AS number: '%c' in %s\n",
|
||||||
*eoa, as);
|
*eoa, as);
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (*eoa == '.' || asno > 65535) {
|
|
||||||
if (b->asn32 || b->generation >= T_PREFIXLIST) {
|
|
||||||
uint32_t asn1;
|
|
||||||
if (asno > 65535) {
|
|
||||||
asn1 = asno % 65536;
|
|
||||||
asno /= 65536;
|
|
||||||
} else if (eoa && *(eoa+1)) {
|
|
||||||
asn1 = strtoul(eoa+1, &eoa, 10);
|
|
||||||
} else {
|
|
||||||
sx_report(SX_ERROR, "Invalid AS number: '%s'\n", as);
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (eoa && *eoa!=0)
|
if (asno > 65535) {
|
||||||
sx_report(SX_ERROR,"Invalid symbol in AS number: '%c' in %s\n",
|
asn1 = asno / 65536;
|
||||||
*eoa, as);
|
asn2 = asno % 65536;
|
||||||
return 0;
|
} else
|
||||||
|
asn1 = asno;
|
||||||
|
|
||||||
if (asn1 > 65535) {
|
if (!expand_special_asn &&
|
||||||
sx_report(SX_ERROR, "Invalid AS number in %s\n", as);
|
((asno >= 4200000000ul) || (asno >= 64496 && asno <= 65551)))
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!expand_special_asn && (((asno * 65536 + asn1) >= 4200000000ul) ||
|
|
||||||
((asno * 65536 + asn1) >= 64496 && (asno * 65536 + asn1) <= 65551)))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (!b->asn32s[asno]) {
|
|
||||||
b->asn32s[asno] = malloc(8192);
|
|
||||||
if (!b->asn32s[asno]) {
|
|
||||||
sx_report(SX_FATAL, "Unable to allocate 8192 bytes: %s."
|
|
||||||
" Unable to add asn32 %s to future expansion\n",
|
|
||||||
strerror(errno), as);
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
memset(b->asn32s[asno], 0, 8192);
|
|
||||||
};
|
|
||||||
|
|
||||||
b->asn32s[asno][asn1/8] |= (0x80 >> (asn1 % 8));
|
|
||||||
|
|
||||||
} else if (!b->asn32) {
|
|
||||||
b->asn32s[0][23456/8] |= (0x80 >> (23456 % 8));
|
|
||||||
};
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (asno < 1 || asno > 65535) {
|
|
||||||
sx_report(SX_ERROR,"Invalid AS number in %s\n", as);
|
|
||||||
return 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!expand_special_asn && (asno >= 64496 && asno <= 65536))
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
b->asn32s[0][asno / 8] |= (0x80 >> (asno % 8));
|
if (!b->asn32s[asn1]) {
|
||||||
|
b->asn32s[asn1] = malloc(8192);
|
||||||
|
if (!b->asn32s[asn1]) {
|
||||||
|
sx_report(SX_FATAL, "Unable to allocate 8192 "
|
||||||
|
"bytes: %s. Unable to add asn32 %s to "
|
||||||
|
" future expansion\n", strerror(errno), as);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
memset(b->asn32s[asn1], 0, 8192);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (asno > 65535)
|
||||||
|
b->asn32s[asn1][asn2 / 8] |= (0x80 >> (asn2 % 8));
|
||||||
|
else
|
||||||
|
b->asn32s[0][asn1 / 8] |= (0x80 >> (asn1 % 8));
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
};
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
bgpq_expander_add_prefix(struct bgpq_expander* b, char* prefix)
|
bgpq_expander_add_prefix(struct bgpq_expander* b, char* prefix)
|
||||||
|
Reference in New Issue
Block a user