Some minor changes to CLI.

This commit is contained in:
Ondrej Zajicek 2012-03-22 11:46:38 +01:00
parent df27911880
commit c47d037ecb
6 changed files with 45 additions and 10 deletions

View file

@ -29,6 +29,7 @@ struct cmd_node {
struct cmd_node *sibling, *son, **plastson; struct cmd_node *sibling, *son, **plastson;
struct cmd_info *cmd, *help; struct cmd_info *cmd, *help;
int len; int len;
signed char prio;
char token[1]; char token[1];
}; };
@ -66,6 +67,7 @@ cmd_build_tree(void)
new->plastson = &new->son; new->plastson = &new->son;
new->len = c-d; new->len = c-d;
memcpy(new->token, d, c-d); memcpy(new->token, d, c-d);
new->prio = (new->len == 3 && !memcmp(new->token, "roa", 3)) ? 0 : 1; /* Hack */
} }
old = new; old = new;
while (isspace(*c)) while (isspace(*c))
@ -108,6 +110,9 @@ cmd_find_abbrev(struct cmd_node *root, char *cmd, int len, int *pambiguous)
return m; return m;
if (m->len > len && !memcmp(m->token, cmd, len)) if (m->len > len && !memcmp(m->token, cmd, len))
{ {
if (best && best->prio > m->prio)
continue;
if (best && best->prio == m->prio)
best2 = best; best2 = best;
best = m; best = m;
} }
@ -168,19 +173,31 @@ static int
cmd_find_common_match(struct cmd_node *root, char *cmd, int len, int *pcount, char *buf) cmd_find_common_match(struct cmd_node *root, char *cmd, int len, int *pcount, char *buf)
{ {
struct cmd_node *m; struct cmd_node *m;
int best, i; int best, best_prio, i;
*pcount = 0; *pcount = 0;
best = -1; best = -1;
best_prio = -1;
for(m=root->son; m; m=m->sibling) for(m=root->son; m; m=m->sibling)
{ {
if (m->len < len || memcmp(m->token, cmd, len)) if (m->len < len || memcmp(m->token, cmd, len))
continue; continue;
if (best_prio > m->prio)
continue;
if (best_prio < m->prio)
{
*pcount = 0;
best = -1;
}
(*pcount)++; (*pcount)++;
if (best < 0) if (best < 0)
{ {
strcpy(buf, m->token + len); strcpy(buf, m->token + len);
best = m->len - len; best = m->len - len;
best_prio = m->prio;
} }
else else
{ {

View file

@ -615,7 +615,7 @@ This argument can be omitted if there exists only a single instance.
number of networks, number of routes before and after filtering). If number of networks, number of routes before and after filtering). If
you use <cf/count/ instead, only the statistics will be printed. you use <cf/count/ instead, only the statistics will be printed.
<tag>show xroa [<m/prefix/ | in <m/prefix/ | for <m/prefix/] [as <m/num/] [table <m/t/>]</tag> <tag>show roa [<m/prefix/ | in <m/prefix/ | for <m/prefix/] [as <m/num/] [table <m/t/>]</tag>
Show contents of a ROA table (by default of the first one). Show contents of a ROA table (by default of the first one).
You can specify a <m/prefix/ to print ROA entries for a You can specify a <m/prefix/ to print ROA entries for a
specific network. If you use <cf>for <m/prefix/</cf>, you'll specific network. If you use <cf>for <m/prefix/</cf>, you'll

View file

@ -45,6 +45,7 @@ Reply codes of BIRD command-line interface
1016 Show ospf state/topology 1016 Show ospf state/topology
1017 Show ospf lsadb 1017 Show ospf lsadb
1018 Show memory 1018 Show memory
1019 Show ROA list
8000 Reply too long 8000 Reply too long
8001 Route not found 8001 Route not found

View file

@ -45,7 +45,7 @@ CF_DECLS
CF_KEYWORDS(ROUTER, ID, PROTOCOL, TEMPLATE, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT) CF_KEYWORDS(ROUTER, ID, PROTOCOL, TEMPLATE, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS) CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES) CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREEXPORT, GENERATE, ROA, XROA, MAX, FLUSH) CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, COMMANDS, PREEXPORT, GENERATE, ROA, MAX, FLUSH)
CF_KEYWORDS(LISTEN, BGP, V6ONLY, DUAL, ADDRESS, PORT, PASSWORDS, DESCRIPTION) CF_KEYWORDS(LISTEN, BGP, V6ONLY, DUAL, ADDRESS, PORT, PASSWORDS, DESCRIPTION)
CF_KEYWORDS(RELOAD, IN, OUT, MRTDUMP, MESSAGES, RESTRICT, MEMORY, IGP_METRIC) CF_KEYWORDS(RELOAD, IN, OUT, MRTDUMP, MESSAGES, RESTRICT, MEMORY, IGP_METRIC)
@ -376,6 +376,7 @@ CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]]) CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
{ if_show_summary(); } ; { if_show_summary(); } ;
CF_CLI_HELP(SHOW ROUTE, ..., [[Show routing table]])
CF_CLI(SHOW ROUTE, r_args, [[[<prefix>|for <prefix>|for <ip>] [table <t>] [filter <f>|where <cond>] [all] [primary] [(export|preexport) <p>] [protocol <p>] [stats|count]]], [[Show routing table]]) CF_CLI(SHOW ROUTE, r_args, [[[<prefix>|for <prefix>|for <ip>] [table <t>] [filter <f>|where <cond>] [all] [primary] [(export|preexport) <p>] [protocol <p>] [stats|count]]], [[Show routing table]])
{ rt_show($3); } ; { rt_show($3); } ;
@ -456,7 +457,8 @@ export_or_preexport:
; ;
CF_CLI(SHOW XROA, roa_args, [<prefix> | in <prefix> | for <prefix>] [as <num>] [table <t>], [[Show ROA table]]) CF_CLI_HELP(SHOW ROA, ..., [[Show ROA table]])
CF_CLI(SHOW ROA, roa_args, [<prefix> | in <prefix> | for <prefix>] [as <num>] [table <t>], [[Show ROA table]])
{ roa_show($3); } ; { roa_show($3); } ;
roa_args: roa_args:
@ -492,6 +494,7 @@ roa_mode:
; ;
CF_CLI_HELP(SHOW SYMBOLS, ..., [[Show all known symbolic names]])
CF_CLI(SHOW SYMBOLS, sym_args, [table|filter|function|protocol|template|roa|<symbol>], [[Show all known symbolic names]]) CF_CLI(SHOW SYMBOLS, sym_args, [table|filter|function|protocol|template|roa|<symbol>], [[Show all known symbolic names]])
{ cmd_show_symbols($3); } ; { cmd_show_symbols($3); } ;
@ -522,14 +525,26 @@ roa_table_arg:
} }
; ;
CF_CLI_HELP(ADD, roa ..., [[Add ROA record]])
CF_CLI(ADD ROA, prefix MAX NUM AS NUM roa_table_arg, <prefix> max <num> as <num> [table <name>], [[Add ROA record]]) CF_CLI(ADD ROA, prefix MAX NUM AS NUM roa_table_arg, <prefix> max <num> as <num> [table <name>], [[Add ROA record]])
{ roa_add_item($8, $3.addr, $3.len, $5, $7, ROA_SRC_DYNAMIC); cli_msg(0, ""); } ; {
if (! cli_access_restricted())
{ roa_add_item($8, $3.addr, $3.len, $5, $7, ROA_SRC_DYNAMIC); cli_msg(0, ""); }
};
CF_CLI_HELP(DELETE, roa ..., [[Delete ROA record]])
CF_CLI(DELETE ROA, prefix MAX NUM AS NUM roa_table_arg, <prefix> max <num> as <num> [table <name>], [[Delete ROA record]]) CF_CLI(DELETE ROA, prefix MAX NUM AS NUM roa_table_arg, <prefix> max <num> as <num> [table <name>], [[Delete ROA record]])
{ roa_delete_item($8, $3.addr, $3.len, $5, $7, ROA_SRC_DYNAMIC); cli_msg(0, ""); } ; {
if (! cli_access_restricted())
{ roa_delete_item($8, $3.addr, $3.len, $5, $7, ROA_SRC_DYNAMIC); cli_msg(0, ""); }
};
CF_CLI_HELP(FLUSH, roa [table <name>], [[Removes all dynamic ROA records]])
CF_CLI(FLUSH ROA, roa_table_arg, [table <name>], [[Removes all dynamic ROA records]]) CF_CLI(FLUSH ROA, roa_table_arg, [table <name>], [[Removes all dynamic ROA records]])
{ roa_flush($3, ROA_SRC_DYNAMIC); cli_msg(0, ""); } ; {
if (! cli_access_restricted())
{ roa_flush($3, ROA_SRC_DYNAMIC); cli_msg(0, ""); }
};
CF_CLI_HELP(DUMP, ..., [[Dump debugging information]]) CF_CLI_HELP(DUMP, ..., [[Dump debugging information]])

View file

@ -354,7 +354,7 @@ roa_show_node(struct cli *c, struct roa_node *rn, int len, u32 asn)
for (ri = rn->items; ri; ri = ri->next) for (ri = rn->items; ri; ri = ri->next)
if ((ri->maxlen >= len) && (!asn || (ri->asn == asn))) if ((ri->maxlen >= len) && (!asn || (ri->asn == asn)))
cli_printf(c, -1111, "%I/%d max %d as %u", rn->n.prefix, rn->n.pxlen, ri->maxlen, ri->asn); cli_printf(c, -1019, "%I/%d max %d as %u", rn->n.prefix, rn->n.pxlen, ri->maxlen, ri->asn);
} }
static void static void

View file

@ -388,7 +388,8 @@ CF_ADDTO(dynamic_attr, OSPF_METRIC2 { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF
CF_ADDTO(dynamic_attr, OSPF_TAG { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_OSPF_TAG); }) CF_ADDTO(dynamic_attr, OSPF_TAG { $$ = f_new_dynamic_attr(EAF_TYPE_INT | EAF_TEMP, T_INT, EA_OSPF_TAG); })
CF_ADDTO(dynamic_attr, OSPF_ROUTER_ID { $$ = f_new_dynamic_attr(EAF_TYPE_ROUTER_ID | EAF_TEMP, T_QUAD, EA_OSPF_ROUTER_ID); }) CF_ADDTO(dynamic_attr, OSPF_ROUTER_ID { $$ = f_new_dynamic_attr(EAF_TYPE_ROUTER_ID | EAF_TEMP, T_QUAD, EA_OSPF_ROUTER_ID); })
CF_CLI(SHOW OSPF, optsym, [<name>], [[Show information about OSPF protocol]]) CF_CLI_HELP(SHOW OSPF, ..., [[Show information about OSPF protocol]]);
CF_CLI(SHOW OSPF, optsym, [<name>], [[Show information about OSPF protocol XXX]])
{ ospf_sh(proto_get_named($3, &proto_ospf)); }; { ospf_sh(proto_get_named($3, &proto_ospf)); };
CF_CLI(SHOW OSPF NEIGHBORS, optsym opttext, [<name>] [\"<interface>\"], [[Show information about OSPF neighbors]]) CF_CLI(SHOW OSPF NEIGHBORS, optsym opttext, [<name>] [\"<interface>\"], [[Show information about OSPF neighbors]])
@ -413,6 +414,7 @@ CF_CLI(SHOW OSPF STATE, optsym opttext, [<name>], [[Show information about reach
CF_CLI(SHOW OSPF STATE ALL, optsym opttext, [<name>], [[Show information about all OSPF network state]]) CF_CLI(SHOW OSPF STATE ALL, optsym opttext, [<name>], [[Show information about all OSPF network state]])
{ ospf_sh_state(proto_get_named($5, &proto_ospf), 1, 0); }; { ospf_sh_state(proto_get_named($5, &proto_ospf), 1, 0); };
CF_CLI_HELP(SHOW OSPF LSADB, ..., [[Show content of OSPF LSA database]]);
CF_CLI(SHOW OSPF LSADB, lsadb_args, [global | area <id> | link] [type <num>] [lsid <id>] [self | router <id>] [<proto>], [[Show content of OSPF LSA database]]) CF_CLI(SHOW OSPF LSADB, lsadb_args, [global | area <id> | link] [type <num>] [lsid <id>] [self | router <id>] [<proto>], [[Show content of OSPF LSA database]])
{ ospf_sh_lsadb($4); }; { ospf_sh_lsadb($4); };