1
0
mirror of https://github.com/bgp/bgpq4.git synced 2024-05-11 05:55:05 +00:00

Enable aggregate support with '-F' (user-defined).

This commit is contained in:
Chris Caputo
2020-03-09 02:08:36 +00:00
parent e4d72f0505
commit 1d5b375cc3
6 changed files with 36 additions and 18 deletions

View File

@ -290,6 +290,7 @@ example below:
ipfw add pass all from 193.193.192.0/19 to any
Recognized format characters: '%n' - network, '%l' - mask length,
'%a' - aggregate low mask length, '%A' - aggregate high mask length,
'%N' - object name, '%m' - object mask and '%i' - inversed mask.
Recognized escape characters: '\n' - new line, '\t' - tabulation.
Please note that no new lines inserted automatically after each sentence,

View File

@ -251,6 +251,7 @@ ipfw add pass all from 193.193.192.0/19 to any
.fi
.Pp
Recognized format characters: %n - network, %l - mask length,
%a - aggregate low mask length, %A - aggregate high mask length,
%N - object name, %m - object mask and %i - inversed mask.
Recognized escape characters: \\n - new line, \\t - tabulation.
Please note that no new lines inserted automatically after each sentence,

12
bgpq4.c
View File

@ -459,12 +459,6 @@ main(int argc, char* argv[])
sx_report(SX_FATAL, "Sorry, only prefix-lists supported in formatted "
"output\n");
if (expander.vendor == V_FORMAT && (refine || refineLow)) {
sx_report(SX_FATAL, "Sorry, formatted output (-F <fmt>) in not "
"compatible with -R/-r options\n");
exit(1);
}
if (expander.vendor == V_HUAWEI && expander.generation != T_ASPATH &&
expander.generation != T_OASPATH && expander.generation != T_PREFIXLIST)
sx_report(SX_FATAL, "Sorry, only as-paths and prefix-lists supported "
@ -486,12 +480,6 @@ main(int argc, char* argv[])
exit(1);
}
if(aggregate && expander.vendor == V_FORMAT) {
sx_report(SX_FATAL, "Sorry, aggregation (-A) is not compatible with "
"formatted output (-F <fmt>)\n");
exit(1);
}
if (aggregate && (expander.vendor == V_NOKIA_MD || expander.vendor == V_NOKIA)
&& expander.generation != T_PREFIXLIST) {
sx_report(SX_FATAL, "Sorry, aggregation (-A) is not supported with "

View File

@ -1638,14 +1638,34 @@ bgpq4_print_format_prefix(struct sx_radix_node* n, void* ff)
struct bgpq_expander* b = fpc->b;
if (n->isGlue)
return;
goto checkSon;
if (!f)
f = stdout;
sx_prefix_snprintf_fmt(n->prefix, f,
b->name ? b->name : "NN",
b->format);
if (!n->isAggregate) {
sx_prefix_snprintf_fmt(n->prefix, f,
b->name ? b->name : "NN",
b->format,
n->prefix->masklen,
n->prefix->masklen);
} else if (n->aggregateLow > n->prefix->masklen) {
sx_prefix_snprintf_fmt(n->prefix, f,
b->name ? b->name : "NN",
b->format,
n->aggregateLow,
n->aggregateHi);
} else {
sx_prefix_snprintf_fmt(n->prefix, f,
b->name ? b->name : "NN",
b->format,
n->prefix->masklen,
n->aggregateHi);
}
checkSon:
if (n->son)
bgpq4_print_format_prefix(n->son, ff);
}

View File

@ -401,7 +401,8 @@ sx_prefix_snprintf(struct sx_prefix* p, char* rbuffer, int srb)
void
sx_prefix_snprintf_fmt(struct sx_prefix* p, FILE* f,
const char* name, const char* format)
const char* name, const char* format,
unsigned int aggregateLow, unsigned int aggregateHi)
{
unsigned off = 0;
const char* c = format;
@ -423,6 +424,12 @@ sx_prefix_snprintf_fmt(struct sx_prefix* p, FILE* f,
case 'l':
fprintf(f, "%i", p->masklen);
break;
case 'a':
fprintf(f, "%u", aggregateLow);
break;
case 'A':
fprintf(f, "%u", aggregateHi);
break;
case '%':
fprintf(f, "%%");
break;

View File

@ -52,7 +52,8 @@ int sx_prefix_fprint(FILE* f, struct sx_prefix* p);
int sx_prefix_snprintf(struct sx_prefix* p, char* rbuffer, int srb);
int sx_prefix_snprintf_sep(struct sx_prefix* p, char* rbuffer, int srb, char*);
void sx_prefix_snprintf_fmt(struct sx_prefix* p, FILE* f,
const char* name, const char* fmt);
const char* name, const char* fmt,
unsigned int aggregateLow, unsigned int aggregateHi);
int sx_prefix_jsnprintf(struct sx_prefix* p, char* rbuffer, int srb);
struct sx_radix_tree* sx_radix_tree_new(int af);
struct sx_radix_node* sx_radix_node_new(struct sx_prefix* prefix);