diff options
author | Cedric Berger <cedric@cvs.openbsd.org> | 2003-01-22 01:15:33 +0000 |
---|---|---|
committer | Cedric Berger <cedric@cvs.openbsd.org> | 2003-01-22 01:15:33 +0000 |
commit | 7fbb287018457945cd8c2a4a14964139d97aa330 (patch) | |
tree | f6c5c374e6d8f8179c7ec53ba5709451ef13de29 /sbin | |
parent | ef798641430813065dc78f71f7829e5bfc3d256a (diff) |
Automatically create tables for the "add" and "replace" table commands.
Requested by deraadt@, pass all regress tests.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/pfctl/pfctl.8 | 4 | ||||
-rw-r--r-- | sbin/pfctl/pfctl_table.c | 15 |
2 files changed, 17 insertions, 2 deletions
diff --git a/sbin/pfctl/pfctl.8 b/sbin/pfctl/pfctl.8 index 94e453eddfd..0bc7f30a32f 100644 --- a/sbin/pfctl/pfctl.8 +++ b/sbin/pfctl/pfctl.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pfctl.8,v 1.66 2003/01/19 13:48:06 dhartmei Exp $ +.\" $OpenBSD: pfctl.8,v 1.67 2003/01/22 01:15:32 cedric Exp $ .\" .\" Copyright (c) 2001 Kjell Wooding. All rights reserved. .\" @@ -222,10 +222,12 @@ Kill a table. Flush all addresses of a table. .It Fl T Ar add Add one or more addresses in a table. +Automatically create a nonexisting table. .It Fl T Ar delete Delete one or more addresses from a table. .It Fl T Ar replace Replace the addresses of the table. +Automatically create a nonexisting table. .It Fl T Ar show Show the content (addresses) of a table. .It Fl T Ar test diff --git a/sbin/pfctl/pfctl_table.c b/sbin/pfctl/pfctl_table.c index 847a872e99b..888ba0213a2 100644 --- a/sbin/pfctl/pfctl_table.c +++ b/sbin/pfctl/pfctl_table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl_table.c,v 1.24 2003/01/18 22:18:09 cedric Exp $ */ +/* $OpenBSD: pfctl_table.c,v 1.25 2003/01/22 01:15:32 cedric Exp $ */ /* * Copyright (c) 2002 Cedric Berger @@ -97,6 +97,17 @@ static char *stats_text[PFR_DIR_MAX][PFR_OP_TABLE_MAX] = { } \ } while (0) +#define CREATE_TABLE do { \ + table.pfrt_flags |= PFR_TFLAG_PERSIST; \ + RVTEST(pfr_add_tables(&table, 1, &nadd, flags)); \ + if (nadd) { \ + xprintf(opts, "%d table created", nadd); \ + if (opts & PF_OPT_NOACTION) \ + return (0); \ + } \ + table.pfrt_flags &= ~PFR_TFLAG_PERSIST; \ + } while(0) + int pfctl_clear_tables(int opts) { @@ -186,6 +197,7 @@ pfctl_table(int argc, char *argv[], char *tname, char *command, xprintf(opts, "%d addresses deleted", ndel); } else if (!strcmp(command, "add")) { load_addr(argc, argv, file, 0); + CREATE_TABLE; if (opts & PF_OPT_VERBOSE) flags |= PFR_FLAG_FEEDBACK; RVTEST(pfr_add_addrs(&table, buffer.addrs, size, &nadd, @@ -212,6 +224,7 @@ pfctl_table(int argc, char *argv[], char *tname, char *command, opts & PF_OPT_USEDNS); } else if (!strcmp(command, "replace")) { load_addr(argc, argv, file, 0); + CREATE_TABLE; if (opts & PF_OPT_VERBOSE) flags |= PFR_FLAG_FEEDBACK; for (;;) { |