Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Aug 2014 16:22:14 +0000 (UTC)
From:      Alexander V. Chernikov <melifaro@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r269478 - projects/ipfw/sbin/ipfw
Message-ID:  <53de61b7.5073.29626422@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: melifaro
Date: Sun Aug  3 16:22:14 2014
New Revision: 269478
URL: http://svnweb.freebsd.org/changeset/base/269478

Log:
  * 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".

Modified:
  projects/ipfw/sbin/ipfw/ipfw2.c
  projects/ipfw/sbin/ipfw/ipfw2.h
  projects/ipfw/sbin/ipfw/main.c
  projects/ipfw/sbin/ipfw/tables.c

Modified: projects/ipfw/sbin/ipfw/ipfw2.c
==============================================================================
--- projects/ipfw/sbin/ipfw/ipfw2.c	Sun Aug  3 15:49:03 2014	(r269477)
+++ projects/ipfw/sbin/ipfw/ipfw2.c	Sun Aug  3 16:22:14 2014	(r269478)
@@ -383,6 +383,7 @@ static int ipfw_get_config(struct cmdlin
     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;

Modified: projects/ipfw/sbin/ipfw/ipfw2.h
==============================================================================
--- projects/ipfw/sbin/ipfw/ipfw2.h	Sun Aug  3 15:49:03 2014	(r269477)
+++ projects/ipfw/sbin/ipfw/ipfw2.h	Sun Aug  3 16:22:14 2014	(r269478)
@@ -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[]);
 

Modified: projects/ipfw/sbin/ipfw/main.c
==============================================================================
--- projects/ipfw/sbin/ipfw/main.c	Sun Aug  3 15:49:03 2014	(r269477)
+++ projects/ipfw/sbin/ipfw/main.c	Sun Aug  3 16:22:14 2014	(r269478)
@@ -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);
 	}

Modified: projects/ipfw/sbin/ipfw/tables.c
==============================================================================
--- projects/ipfw/sbin/ipfw/tables.c	Sun Aug  3 15:49:03 2014	(r269477)
+++ projects/ipfw/sbin/ipfw/tables.c	Sun Aug  3 16:22:14 2014	(r269478)
@@ -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, voi
 	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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?53de61b7.5073.29626422>