mirror of
https://github.com/bgp/bgpq4.git
synced 2024-05-11 05:55:05 +00:00
new flag -t: as-sets for OpenBGPD and JSON formats
This commit is contained in:
2
CHANGES
2
CHANGES
@ -12,6 +12,8 @@ untagged yet (2018-10-02)
|
||||
By default checks route[4] presence, to check route6 objects shall be
|
||||
used together with -6.
|
||||
- cleanup OpenBGPd prefix-sets. Submitted by Claudio Jeker.
|
||||
- new flag -s: generate as-sets for OpenBGPd (OpenBSD 6.4+) and JSON
|
||||
formats. Based on submission by Claudio Jeker.
|
||||
|
||||
0.1.35-rc2 (2017-06-14)
|
||||
- OpenBSD need <sys/select.h>. Reported by Denis Fondras.
|
||||
|
@ -7,7 +7,7 @@ SYNOPSIS
|
||||
--------
|
||||
|
||||
```
|
||||
bgpq3 [-h host[:port]] [-S sources] [-EPz] [-f asn | -F fmt | -G asn] [-2346ABbDdJjpsUX] [-a asn] [-r len] [-R len] [-m max] [-W len] OBJECTS [...] EXCEPT OBJECTS
|
||||
bgpq3 [-h host[:port]] [-S sources] [-EPz] [-f asn | -F fmt | -G asn | -t] [-2346ABbDdJjpsUX] [-a asn] [-r len] [-R len] [-m max] [-W len] OBJECTS [...] EXCEPT OBJECTS
|
||||
```
|
||||
|
||||
DESCRIPTION
|
||||
@ -138,6 +138,10 @@ Generate sequence numbers in IOS-style prefix-lists.
|
||||
|
||||
Use specified sources only (recommended: RADB,RIPE,APNIC).
|
||||
|
||||
#### -t
|
||||
|
||||
Generate as-sets for OpenBGPD (OpenBSD 6.4+) and JSON formats.
|
||||
|
||||
#### -T
|
||||
|
||||
Disable pipelining. (not recommended)
|
||||
|
3
bgpq3.8
3
bgpq3.8
@ -37,6 +37,7 @@
|
||||
.Fl f Ar asn |
|
||||
.Fl F Ar fmt |
|
||||
.Fl G Ar asn
|
||||
.Fl t
|
||||
.Oc
|
||||
.Op Fl 2346ABbDdJjNsXU
|
||||
.Op Fl a Ar asn
|
||||
@ -115,6 +116,8 @@ allow more specific routes up to specified masklen too.
|
||||
generate sequence numbers in IOS-style prefix-lists.
|
||||
.It Fl S Ar sources
|
||||
use specified sources only (recommended: RADB,RIPE,APNIC).
|
||||
.It Fl t
|
||||
generate as-sets for OpenBGPD (OpenBSD 6.4+) and JSON formats.
|
||||
.It Fl T
|
||||
disable pipelining.
|
||||
.It Fl W Ar len
|
||||
|
21
bgpq3.c
21
bgpq3.c
@ -26,7 +26,7 @@ extern int expand_special_asn;
|
||||
int
|
||||
usage(int ecode)
|
||||
{
|
||||
printf("\nUsage: bgpq3 [-h host[:port]] [-S sources] [-P|E|G <num>|f <num>]"
|
||||
printf("\nUsage: bgpq3 [-h host[:port]] [-S sources] [-P|E|G <num>|f <num>|t]"
|
||||
" [-2346ABbDdJjwXz] [-R len] <OBJECTS>...\n");
|
||||
printf(" -2 : allow routes belonging to as23456 (transition-as) "
|
||||
"(default: false)\n");
|
||||
@ -66,6 +66,8 @@ usage(int ecode)
|
||||
" RADB,RIPE,APNIC)\n");
|
||||
printf(" -s : generate sequence numbers in prefix-lists (IOS only)\n");
|
||||
printf(" -T : disable pipelining (experimental, faster mode)\n");
|
||||
printf(" -t : generate as-sets for OpenBGPD (OpenBSD 6.4+) and "
|
||||
"JSON formats\n");
|
||||
printf(" -U : generate config for Huawei (Cisco IOS by default)\n");
|
||||
printf(" -W len : specify max-entries on as-path line (use 0 for "
|
||||
"infinity)\n");
|
||||
@ -80,7 +82,7 @@ usage(int ecode)
|
||||
void
|
||||
exclusive()
|
||||
{
|
||||
fprintf(stderr,"-E, -f <asnum>, -G <asnum> and -P are mutually "
|
||||
fprintf(stderr,"-E, -f <asnum>, -G <asnum>, -P and -t are mutually "
|
||||
"exclusive\n");
|
||||
exit(1);
|
||||
};
|
||||
@ -142,7 +144,7 @@ main(int argc, char* argv[])
|
||||
if (getenv("IRRD_SOURCES"))
|
||||
expander.sources=getenv("IRRD_SOURCES");
|
||||
|
||||
while((c=getopt(argc,argv,"2346a:AbBdDEF:S:jJf:l:L:m:M:NW:Ppr:R:G:Th:UwXsz"))
|
||||
while((c=getopt(argc,argv,"2346a:AbBdDEF:S:jJf:l:L:m:M:NW:Ppr:R:G:tTh:UwXsz"))
|
||||
!=EOF) {
|
||||
switch(c) {
|
||||
case '2':
|
||||
@ -297,6 +299,10 @@ main(int argc, char* argv[])
|
||||
case 'N': if(expander.vendor) vendor_exclusive();
|
||||
expander.vendor=V_NOKIA;
|
||||
break;
|
||||
case 't':
|
||||
if(expander.generation) exclusive();
|
||||
expander.generation=T_ASSET;
|
||||
break;
|
||||
case 'T': pipelining=0;
|
||||
break;
|
||||
case 's': expander.sequence=1;
|
||||
@ -371,7 +377,7 @@ main(int argc, char* argv[])
|
||||
"for BIRD output\n");
|
||||
};
|
||||
if(expander.vendor==V_JSON && expander.generation!=T_PREFIXLIST &&
|
||||
expander.generation!=T_ASPATH) {
|
||||
expander.generation!=T_ASPATH && expander.generation!=T_ASSET) {
|
||||
sx_report(SX_FATAL, "Sorry, only prefix-lists and as-paths supported "
|
||||
"for JSON output\n");
|
||||
};
|
||||
@ -392,6 +398,11 @@ main(int argc, char* argv[])
|
||||
sx_report(SX_FATAL, "Route-filter-lists (-z) supported for Juniper (-J)"
|
||||
" output only\n");
|
||||
};
|
||||
if(expander.generation==T_ASSET && expander.vendor!=V_JSON &&
|
||||
expander.vendor!=V_OPENBGPD) {
|
||||
sx_report(SX_FATAL, "As-Sets (-t) supported for JSON (-j) and OpenBGPD"
|
||||
" (-B) output only\n");
|
||||
};
|
||||
|
||||
if(expander.asdot && expander.vendor!=V_CISCO) {
|
||||
sx_report(SX_FATAL,"asdot notation supported only for Cisco, "
|
||||
@ -607,6 +618,8 @@ main(int argc, char* argv[])
|
||||
break;
|
||||
case T_OASPATH: bgpq3_print_oaspath(stdout,&expander);
|
||||
break;
|
||||
case T_ASSET: bgpq3_print_asset(stdout,&expander);
|
||||
break;
|
||||
case T_PREFIXLIST: bgpq3_print_prefixlist(stdout,&expander);
|
||||
break;
|
||||
case T_EACL: bgpq3_print_eacl(stdout,&expander);
|
||||
|
2
bgpq3.h
2
bgpq3.h
@ -26,6 +26,7 @@ typedef enum {
|
||||
T_NONE = 0,
|
||||
T_ASPATH,
|
||||
T_OASPATH,
|
||||
T_ASSET,
|
||||
T_PREFIXLIST,
|
||||
T_EACL,
|
||||
T_ROUTE_FILTER_LIST
|
||||
@ -84,6 +85,7 @@ int bgpq_expand(struct bgpq_expander* b);
|
||||
int bgpq3_print_prefixlist(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq3_print_eacl(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq3_print_aspath(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq3_print_asset(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq3_print_oaspath(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq3_print_route_filter_list(FILE* f, struct bgpq_expander* b);
|
||||
|
||||
|
@ -19,6 +19,7 @@ extern int debug_expander;
|
||||
int bgpq3_print_json_aspath(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq3_print_bird_aspath(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq3_print_openbgpd_aspath(FILE* f, struct bgpq_expander* b);
|
||||
int bgpq3_print_openbgpd_asset(FILE* f, struct bgpq_expander* b);
|
||||
|
||||
int
|
||||
bgpq3_print_cisco_aspath(FILE* f, struct bgpq_expander* b)
|
||||
@ -546,6 +547,27 @@ bgpq3_print_oaspath(FILE* f, struct bgpq_expander* b)
|
||||
return 0;
|
||||
};
|
||||
|
||||
int
|
||||
bgpq3_print_asset(FILE* f, struct bgpq_expander* b)
|
||||
{
|
||||
switch(b->vendor) {
|
||||
case V_JUNIPER:
|
||||
case V_CISCO:
|
||||
case V_CISCO_XR:
|
||||
case V_BIRD:
|
||||
case V_NOKIA:
|
||||
case V_HUAWEI:
|
||||
case V_FORMAT:
|
||||
sx_report(SX_FATAL, "as-sets (-t) supported for json and openbgpd "
|
||||
"only\n");
|
||||
return -1;
|
||||
case V_JSON:
|
||||
return bgpq3_print_json_aspath(f,b);
|
||||
case V_OPENBGPD:
|
||||
return bgpq3_print_openbgpd_asset(f,b);
|
||||
};
|
||||
};
|
||||
|
||||
void
|
||||
bgpq3_print_jprefix(struct sx_radix_node* n, void* ff)
|
||||
{
|
||||
@ -706,6 +728,31 @@ checkSon:
|
||||
bgpq3_print_openbgpd_prefix(n->son, ff);
|
||||
};
|
||||
|
||||
int
|
||||
bgpq3_print_openbgpd_asset(FILE* f, struct bgpq_expander* b)
|
||||
{
|
||||
int i, j, k, nc=0;
|
||||
|
||||
fprintf(f, "as-set %s {", b->name?b->name:"NN");
|
||||
|
||||
for(k=0;k<65536;k++) {
|
||||
if(!b->asn32s[k]) continue;
|
||||
|
||||
for(i=0;i<8192;i++) {
|
||||
for(j=0;j<8;j++) {
|
||||
if(b->asn32s[k][i]&(0x80>>j)) {
|
||||
fprintf(f, "%s%u", nc==0 ? "\n\t" : " ", k*65536+i*8+j);
|
||||
nc++;
|
||||
if(nc==b->aswidth)
|
||||
nc=0;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
fprintf(f, "\n}\n");
|
||||
return 0;
|
||||
};
|
||||
|
||||
int
|
||||
bgpq3_print_openbgpd_aspath(FILE* f, struct bgpq_expander* b)
|
||||
{
|
||||
|
Reference in New Issue
Block a user