* Move "talist" and "iflist" cmds into newly-create "internal" ipfw(8) cmd.

* Add "table X detail" cmd and show detailed algo info there instead
  of "info".
This commit is contained in:
melifaro 2014-08-03 16:22:14 +00:00
parent c7e5ac0567
commit becbec7be8
4 changed files with 49 additions and 12 deletions

View File

@ -383,6 +383,7 @@ static int ipfw_get_config(struct cmdline_opts *co, struct format_opts *fo,
ipfw_cfg_lheader **pcfg, size_t *psize); ipfw_cfg_lheader **pcfg, size_t *psize);
static int ipfw_show_config(struct cmdline_opts *co, struct format_opts *fo, static int ipfw_show_config(struct cmdline_opts *co, struct format_opts *fo,
ipfw_cfg_lheader *cfg, size_t sz, int ac, char **av); ipfw_cfg_lheader *cfg, size_t sz, int ac, char **av);
static void ipfw_list_tifaces(void);
/* /*
* Simple string buffer API. * Simple string buffer API.
@ -4768,7 +4769,34 @@ ipfw_flush(int force)
printf("Flushed all %s.\n", co.do_pipe ? "pipes" : "rules"); printf("Flushed all %s.\n", co.do_pipe ? "pipes" : "rules");
} }
int static struct _s_x intcmds[] = {
{ "talist", TOK_TALIST },
{ "iflist", TOK_IFLIST },
{ NULL, 0 }
};
void
ipfw_internal_handler(int ac, char *av[])
{
int tcmd;
ac--; av++;
NEED1("internal cmd required");
if ((tcmd = match_token(intcmds, *av)) == -1)
errx(EX_USAGE, "invalid internal sub-cmd: %s", *av);
switch (tcmd) {
case TOK_IFLIST:
ipfw_list_tifaces();
break;
case TOK_TALIST:
ipfw_list_ta(ac, av);
break;
}
}
static int
ipfw_get_tracked_ifaces(ipfw_obj_lheader **polh) ipfw_get_tracked_ifaces(ipfw_obj_lheader **polh)
{ {
ipfw_obj_lheader req, *olh; ipfw_obj_lheader req, *olh;
@ -4812,7 +4840,7 @@ ifinfo_cmp(const void *a, const void *b)
* optionally sorts it and calls requested function for each table. * optionally sorts it and calls requested function for each table.
* Returns 0 on success. * Returns 0 on success.
*/ */
void static void
ipfw_list_tifaces() ipfw_list_tifaces()
{ {
ipfw_obj_lheader *olh; ipfw_obj_lheader *olh;

View File

@ -207,17 +207,20 @@ enum tokens {
TOK_LOOKUP, TOK_LOOKUP,
TOK_SOCKARG, TOK_SOCKARG,
TOK_SETDSCP, TOK_SETDSCP,
TOK_FLOW,
TOK_IFLIST,
/* Table tokens */ /* Table tokens */
TOK_CREATE, TOK_CREATE,
TOK_DESTROY, TOK_DESTROY,
TOK_LIST, TOK_LIST,
TOK_INFO, TOK_INFO,
TOK_DETAIL,
TOK_FLUSH, TOK_FLUSH,
TOK_ADD, TOK_ADD,
TOK_DEL, TOK_DEL,
TOK_VALTYPE, TOK_VALTYPE,
TOK_ALGO, TOK_ALGO,
TOK_FLOW, TOK_TALIST,
}; };
/* /*
* the following macro returns an error message if we run out of * the following macro returns an error message if we run out of
@ -299,8 +302,7 @@ void ipfw_delete(char *av[]);
void ipfw_flush(int force); void ipfw_flush(int force);
void ipfw_zero(int ac, char *av[], int optname); void ipfw_zero(int ac, char *av[], int optname);
void ipfw_list(int ac, char *av[], int show_counters); void ipfw_list(int ac, char *av[], int show_counters);
void ipfw_list_tifaces(void); void ipfw_internal_handler(int ac, char *av[]);
void ipfw_list_ta(int ac, char *av[]);
#ifdef PF #ifdef PF
/* altq.c */ /* altq.c */
@ -336,4 +338,5 @@ struct _ipfw_obj_ctlv;
char *table_search_ctlv(struct _ipfw_obj_ctlv *ctlv, uint16_t idx); char *table_search_ctlv(struct _ipfw_obj_ctlv *ctlv, uint16_t idx);
void table_sort_ctlv(struct _ipfw_obj_ctlv *ctlv); void table_sort_ctlv(struct _ipfw_obj_ctlv *ctlv);
int table_check_name(char *tablename); int table_check_name(char *tablename);
void ipfw_list_ta(int ac, char *av[]);

View File

@ -438,10 +438,8 @@ ipfw_main(int oldac, char **oldav)
ipfw_list(ac, av, 1 /* show counters */); ipfw_list(ac, av, 1 /* show counters */);
else if (_substrcmp(*av, "table") == 0) else if (_substrcmp(*av, "table") == 0)
ipfw_table_handler(ac, av); ipfw_table_handler(ac, av);
else if (_substrcmp(*av, "iflist") == 0) else if (_substrcmp(*av, "internal") == 0)
ipfw_list_tifaces(); ipfw_internal_handler(ac, av);
else if (_substrcmp(*av, "talist") == 0)
ipfw_list_ta(ac, av);
else else
errx(EX_USAGE, "bad command `%s'", *av); errx(EX_USAGE, "bad command `%s'", *av);
} }

View File

@ -101,6 +101,7 @@ static struct _s_x tablecmds[] = {
{ "destroy", TOK_DESTROY }, { "destroy", TOK_DESTROY },
{ "flush", TOK_FLUSH }, { "flush", TOK_FLUSH },
{ "info", TOK_INFO }, { "info", TOK_INFO },
{ "detail", TOK_DETAIL },
{ "list", TOK_LIST }, { "list", TOK_LIST },
{ "lookup", TOK_LOOKUP }, { "lookup", TOK_LOOKUP },
{ NULL, 0 } { NULL, 0 }
@ -138,6 +139,7 @@ ipfw_table_handler(int ac, char *av[])
ipfw_obj_header oh; ipfw_obj_header oh;
char *tablename; char *tablename;
uint32_t set; uint32_t set;
void *arg;
memset(&oh, 0, sizeof(oh)); memset(&oh, 0, sizeof(oh));
is_all = 0; is_all = 0;
@ -168,6 +170,7 @@ ipfw_table_handler(int ac, char *av[])
switch (tcmd) { switch (tcmd) {
case TOK_LIST: case TOK_LIST:
case TOK_INFO: case TOK_INFO:
case TOK_DETAIL:
case TOK_FLUSH: case TOK_FLUSH:
break; break;
default: default:
@ -201,13 +204,15 @@ ipfw_table_handler(int ac, char *av[])
err(EX_OSERR, "failed to flush tables list"); err(EX_OSERR, "failed to flush tables list");
} }
break; break;
case TOK_DETAIL:
case TOK_INFO: case TOK_INFO:
arg = (tcmd == TOK_DETAIL) ? (void *)1 : NULL;
if (is_all == 0) { if (is_all == 0) {
if ((error = table_get_info(&oh, &i)) != 0) if ((error = table_get_info(&oh, &i)) != 0)
err(EX_OSERR, "failed to request table info"); err(EX_OSERR, "failed to request table info");
table_show_info(&i, NULL); table_show_info(&i, arg);
} else { } else {
error = tables_foreach(table_show_info, NULL, 1); error = tables_foreach(table_show_info, arg, 1);
if (error != 0) if (error != 0)
err(EX_OSERR, "failed to request tables list"); err(EX_OSERR, "failed to request tables list");
} }
@ -549,7 +554,10 @@ table_show_info(ipfw_xtable_info *i, void *arg)
if (i->limit > 0) if (i->limit > 0)
printf(" limit: %u\n", i->limit); printf(" limit: %u\n", i->limit);
/* Print algo-specific info if any */ /* Print algo-specific info if requested & set */
if (arg == NULL)
return (0);
if ((i->ta_info.flags & IPFW_TATFLAGS_DATA) == 0) if ((i->ta_info.flags & IPFW_TATFLAGS_DATA) == 0)
return (0); return (0);
tainfo = &i->ta_info; tainfo = &i->ta_info;