summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authormelifaro <melifaro@FreeBSD.org>2014-08-03 16:22:14 +0000
committermelifaro <melifaro@FreeBSD.org>2014-08-03 16:22:14 +0000
commitbecbec7be8fc96c65142c29024e62335a3e0a95c (patch)
tree11519bd7dcec0b308a29c9150130bf01f75bec17 /sbin
parentc7e5ac056769fc29e9dcdd64d0ae77cc056c3e8f (diff)
downloadFreeBSD-src-becbec7be8fc96c65142c29024e62335a3e0a95c.zip
FreeBSD-src-becbec7be8fc96c65142c29024e62335a3e0a95c.tar.gz
* 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".
Diffstat (limited to 'sbin')
-rw-r--r--sbin/ipfw/ipfw2.c32
-rw-r--r--sbin/ipfw/ipfw2.h9
-rw-r--r--sbin/ipfw/main.c6
-rw-r--r--sbin/ipfw/tables.c14
4 files changed, 49 insertions, 12 deletions
diff --git a/sbin/ipfw/ipfw2.c b/sbin/ipfw/ipfw2.c
index 4595b04..119d7b4 100644
--- a/sbin/ipfw/ipfw2.c
+++ b/sbin/ipfw/ipfw2.c
@@ -383,6 +383,7 @@ static int ipfw_get_config(struct cmdline_opts *co, struct format_opts *fo,
ipfw_cfg_lheader **pcfg, size_t *psize);
static int ipfw_show_config(struct cmdline_opts *co, struct format_opts *fo,
ipfw_cfg_lheader *cfg, size_t sz, int ac, char **av);
+static void ipfw_list_tifaces(void);
/*
* Simple string buffer API.
@@ -4768,7 +4769,34 @@ ipfw_flush(int force)
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_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.
* Returns 0 on success.
*/
-void
+static void
ipfw_list_tifaces()
{
ipfw_obj_lheader *olh;
diff --git a/sbin/ipfw/ipfw2.h b/sbin/ipfw/ipfw2.h
index ff9bc5b..93634ea 100644
--- a/sbin/ipfw/ipfw2.h
+++ b/sbin/ipfw/ipfw2.h
@@ -207,17 +207,20 @@ enum tokens {
TOK_LOOKUP,
TOK_SOCKARG,
TOK_SETDSCP,
+ TOK_FLOW,
+ TOK_IFLIST,
/* Table tokens */
TOK_CREATE,
TOK_DESTROY,
TOK_LIST,
TOK_INFO,
+ TOK_DETAIL,
TOK_FLUSH,
TOK_ADD,
TOK_DEL,
TOK_VALTYPE,
TOK_ALGO,
- TOK_FLOW,
+ TOK_TALIST,
};
/*
* 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_zero(int ac, char *av[], int optname);
void ipfw_list(int ac, char *av[], int show_counters);
-void ipfw_list_tifaces(void);
-void ipfw_list_ta(int ac, char *av[]);
+void ipfw_internal_handler(int ac, char *av[]);
#ifdef PF
/* altq.c */
@@ -336,4 +338,5 @@ struct _ipfw_obj_ctlv;
char *table_search_ctlv(struct _ipfw_obj_ctlv *ctlv, uint16_t idx);
void table_sort_ctlv(struct _ipfw_obj_ctlv *ctlv);
int table_check_name(char *tablename);
+void ipfw_list_ta(int ac, char *av[]);
diff --git a/sbin/ipfw/main.c b/sbin/ipfw/main.c
index 4760360..f25578f 100644
--- a/sbin/ipfw/main.c
+++ b/sbin/ipfw/main.c
@@ -438,10 +438,8 @@ ipfw_main(int oldac, char **oldav)
ipfw_list(ac, av, 1 /* show counters */);
else if (_substrcmp(*av, "table") == 0)
ipfw_table_handler(ac, av);
- else if (_substrcmp(*av, "iflist") == 0)
- ipfw_list_tifaces();
- else if (_substrcmp(*av, "talist") == 0)
- ipfw_list_ta(ac, av);
+ else if (_substrcmp(*av, "internal") == 0)
+ ipfw_internal_handler(ac, av);
else
errx(EX_USAGE, "bad command `%s'", *av);
}
diff --git a/sbin/ipfw/tables.c b/sbin/ipfw/tables.c
index 37e782a..06aab5e 100644
--- a/sbin/ipfw/tables.c
+++ b/sbin/ipfw/tables.c
@@ -101,6 +101,7 @@ static struct _s_x tablecmds[] = {
{ "destroy", TOK_DESTROY },
{ "flush", TOK_FLUSH },
{ "info", TOK_INFO },
+ { "detail", TOK_DETAIL },
{ "list", TOK_LIST },
{ "lookup", TOK_LOOKUP },
{ NULL, 0 }
@@ -138,6 +139,7 @@ ipfw_table_handler(int ac, char *av[])
ipfw_obj_header oh;
char *tablename;
uint32_t set;
+ void *arg;
memset(&oh, 0, sizeof(oh));
is_all = 0;
@@ -168,6 +170,7 @@ ipfw_table_handler(int ac, char *av[])
switch (tcmd) {
case TOK_LIST:
case TOK_INFO:
+ case TOK_DETAIL:
case TOK_FLUSH:
break;
default:
@@ -201,13 +204,15 @@ ipfw_table_handler(int ac, char *av[])
err(EX_OSERR, "failed to flush tables list");
}
break;
+ case TOK_DETAIL:
case TOK_INFO:
+ arg = (tcmd == TOK_DETAIL) ? (void *)1 : NULL;
if (is_all == 0) {
if ((error = table_get_info(&oh, &i)) != 0)
err(EX_OSERR, "failed to request table info");
- table_show_info(&i, NULL);
+ table_show_info(&i, arg);
} else {
- error = tables_foreach(table_show_info, NULL, 1);
+ error = tables_foreach(table_show_info, arg, 1);
if (error != 0)
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)
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)
return (0);
tainfo = &i->ta_info;
OpenPOWER on IntegriCloud