summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2008-07-29 19:04:34 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2008-07-29 19:04:34 +0200
commitce5e35f466c4e1168b7f4b11bf7d9f8e6516e920 (patch)
tree96c4e563f38b1b36f10f684304fdb175c485921b
parent72ed4ffedd4ea97faf1e405e90f512f881c59386 (diff)
parent675e30f258952292972a562b71161b6d3cd77313 (diff)
Merge branch 'master' of vishnu.netfilter.org:/data/git/iptables
-rw-r--r--COMMIT_NOTES24
-rw-r--r--configure.ac13
-rw-r--r--extensions/libxt_string.c70
-rw-r--r--extensions/tos_values.c3
-rw-r--r--include/linux/netfilter/xt_string.h15
-rw-r--r--ip6tables.8.in323
-rw-r--r--ip6tables.c30
-rw-r--r--iptables.8.in296
-rw-r--r--libiptc/libiptc.c126
-rw-r--r--release.sh29
10 files changed, 471 insertions, 458 deletions
diff --git a/COMMIT_NOTES b/COMMIT_NOTES
deleted file mode 100644
index 5b6e6f7f..00000000
--- a/COMMIT_NOTES
+++ /dev/null
@@ -1,24 +0,0 @@
-A quick list of rules for committing stuff into netfilter svn:
-
-- Always include the Name of the Author/Contributor in the SVN comment
- like 'fix for foo (Au Thor)'
-
-- make sure that you have set the executable bits on an 'extensions/.*-test'
- script before adding/committing it to SVN
-
-- If the commit fixes a bugzilla bug, please include '(Closes: #bugnr)' in
- the commit message
-
-- Make sure you don't commit to svn while a feature freeze is announced
-
-- For new extensions, there are two possible cases:
- 1) header files are just in patch-o-matic patch, you need an
- 'extensions/.*-test' script to have a conditional build
- 2) header files are in patch-o-matic patch, and copied to
- 'netfilter/include/linux/netfilter_xxx'. This way the extension
- can be built _unconditionally_, and thus be included in
- 'extensions/Makefile'. Make sure to keep the headers in sync!
-
- Usually '1)' is used, but in case something is expected to show up in the
- kernel soon, we should already make userspace support unconditionally.
-
diff --git a/configure.ac b/configure.ac
index ce26e28c..2ffe6c02 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,7 @@
define([_XTABLES_VERSION_MAJOR], 1)
define([_XTABLES_VERSION_MINOR], 4)
-define([_XTABLES_VERSION_PATCH], 1)
-define([_XTABLES_VERSION_EXTRA], .1)
+define([_XTABLES_VERSION_PATCH], 2)
+define([_XTABLES_VERSION_EXTRA], -rc1)
define([_XTABLES_VERSION],_XTABLES_VERSION_MAJOR._XTABLES_VERSION_MINOR._XTABLES_VERSION_PATCH[]_XTABLES_VERSION_EXTRA)
@@ -38,7 +38,6 @@ AC_ARG_ENABLE([devel],
AC_ARG_ENABLE([libipq],
AS_HELP_STRING([--enable-libipq], [Build and install libipq]))
-AC_CHECK_HEADER([netinet/ip6.h], [], [AC_MSG_ERROR(but we need that for IPv6)])
AC_CHECK_HEADER([linux/dccp.h])
blacklist_modules="";
@@ -47,10 +46,10 @@ if test "$ac_cv_header_linux_dccp_h" != "yes"; then
fi;
AC_SUBST([blacklist_modules])
-AM_CONDITIONAL([ENABLE_STATIC], [test "$enable_static" == "yes"])
-AM_CONDITIONAL([ENABLE_SHARED], [test "$enable_shared" == "yes"])
-AM_CONDITIONAL([ENABLE_DEVEL], [test "$enable_devel" == "yes"])
-AM_CONDITIONAL([ENABLE_LIBIPQ], [test "$enable_libipq" == "yes"])
+AM_CONDITIONAL([ENABLE_STATIC], [test "$enable_static" = "yes"])
+AM_CONDITIONAL([ENABLE_SHARED], [test "$enable_shared" = "yes"])
+AM_CONDITIONAL([ENABLE_DEVEL], [test "$enable_devel" = "yes"])
+AM_CONDITIONAL([ENABLE_LIBIPQ], [test "$enable_libipq" = "yes"])
regular_CFLAGS="-D_LARGEFILE_SOURCE=1 -D_LARGE_FILES -D_FILE_OFFSET_BITS=64 \
-D_REENTRANT -Wall -Waggregate-return -Wmissing-declarations \
diff --git a/extensions/libxt_string.c b/extensions/libxt_string.c
index 5eec44ba..61b5bb56 100644
--- a/extensions/libxt_string.c
+++ b/extensions/libxt_string.c
@@ -37,7 +37,8 @@ static void string_help(void)
"string match options:\n"
"--from Offset to start searching from\n"
"--to Offset to stop searching\n"
-"--algo Algorithm\n"
+"--algo Algorithm\n"
+"--icase Ignore case (default: 0)\n"
"[!] --string string Match a string in a packet\n"
"[!] --hex-string string Match a hex string in a packet\n");
}
@@ -48,6 +49,7 @@ static const struct option string_opts[] = {
{ "algo", 1, NULL, '3' },
{ "string", 1, NULL, '4' },
{ "hex-string", 1, NULL, '5' },
+ { "icase", 0, NULL, '6' },
{ .name = NULL }
};
@@ -162,6 +164,7 @@ parse_hex_string(const char *s, struct xt_string_info *info)
#define ALGO 0x2
#define FROM 0x4
#define TO 0x8
+#define ICASE 0x10
/* Function which parses command options; returns true if it
ate an option */
@@ -169,7 +172,9 @@ static int
string_parse(int c, char **argv, int invert, unsigned int *flags,
const void *entry, struct xt_entry_match **match)
{
- struct xt_string_info *stringinfo = (struct xt_string_info *)(*match)->data;
+ struct xt_string_info *stringinfo =
+ (struct xt_string_info *)(*match)->data;
+ const int revision = (*match)->u.user.revision;
switch (c) {
case '1':
@@ -199,8 +204,12 @@ string_parse(int c, char **argv, int invert, unsigned int *flags,
"Can't specify multiple --string");
check_inverse(optarg, &invert, &optind, 0);
parse_string(argv[optind-1], stringinfo);
- if (invert)
- stringinfo->invert = 1;
+ if (invert) {
+ if (revision == 0)
+ stringinfo->u.v0.invert = 1;
+ else
+ stringinfo->u.v1.flags |= XT_STRING_FLAG_INVERT;
+ }
stringinfo->patlen=strlen((char *)&stringinfo->pattern);
*flags |= STRING;
break;
@@ -212,11 +221,24 @@ string_parse(int c, char **argv, int invert, unsigned int *flags,
check_inverse(optarg, &invert, &optind, 0);
parse_hex_string(argv[optind-1], stringinfo); /* sets length */
- if (invert)
- stringinfo->invert = 1;
+ if (invert) {
+ if (revision == 0)
+ stringinfo->u.v0.invert = 1;
+ else
+ stringinfo->u.v1.flags |= XT_STRING_FLAG_INVERT;
+ }
*flags |= STRING;
break;
+ case '6':
+ if (revision == 0)
+ exit_error(VERSION_PROBLEM,
+ "Kernel doesn't support --icase");
+
+ stringinfo->u.v1.flags |= XT_STRING_FLAG_IGNORECASE;
+ *flags |= ICASE;
+ break;
+
default:
return 0;
}
@@ -287,12 +309,15 @@ string_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
const struct xt_string_info *info =
(const struct xt_string_info*) match->data;
+ const int revision = match->u.user.revision;
+ int invert = (revision == 0 ? info->u.v0.invert :
+ info->u.v1.flags & XT_STRING_FLAG_INVERT);
if (is_hex_string(info->pattern, info->patlen)) {
- printf("STRING match %s", (info->invert) ? "!" : "");
+ printf("STRING match %s", invert ? "!" : "");
print_hex_string(info->pattern, info->patlen);
} else {
- printf("STRING match %s", (info->invert) ? "!" : "");
+ printf("STRING match %s", invert ? "!" : "");
print_string(info->pattern, info->patlen);
}
printf("ALGO name %s ", info->algo);
@@ -300,6 +325,8 @@ string_print(const void *ip, const struct xt_entry_match *match, int numeric)
printf("FROM %u ", info->from_offset);
if (info->to_offset != 0)
printf("TO %u ", info->to_offset);
+ if (revision > 0 && info->u.v1.flags & XT_STRING_FLAG_IGNORECASE)
+ printf("ICASE ");
}
@@ -308,12 +335,15 @@ static void string_save(const void *ip, const struct xt_entry_match *match)
{
const struct xt_string_info *info =
(const struct xt_string_info*) match->data;
+ const int revision = match->u.user.revision;
+ int invert = (revision == 0 ? info->u.v0.invert :
+ info->u.v1.flags & XT_STRING_FLAG_INVERT);
if (is_hex_string(info->pattern, info->patlen)) {
- printf("--hex-string %s", (info->invert) ? "! ": "");
+ printf("--hex-string %s", (invert) ? "! ": "");
print_hex_string(info->pattern, info->patlen);
} else {
- printf("--string %s", (info->invert) ? "! ": "");
+ printf("--string %s", (invert) ? "! ": "");
print_string(info->pattern, info->patlen);
}
printf("--algo %s ", info->algo);
@@ -321,11 +351,30 @@ static void string_save(const void *ip, const struct xt_entry_match *match)
printf("--from %u ", info->from_offset);
if (info->to_offset != 0)
printf("--to %u ", info->to_offset);
+ if (revision > 0 && info->u.v1.flags & XT_STRING_FLAG_IGNORECASE)
+ printf("--icase ");
}
static struct xtables_match string_match = {
.name = "string",
+ .revision = 0,
+ .family = AF_UNSPEC,
+ .version = XTABLES_VERSION,
+ .size = XT_ALIGN(sizeof(struct xt_string_info)),
+ .userspacesize = offsetof(struct xt_string_info, config),
+ .help = string_help,
+ .init = string_init,
+ .parse = string_parse,
+ .final_check = string_check,
+ .print = string_print,
+ .save = string_save,
+ .extra_opts = string_opts,
+};
+
+static struct xtables_match string_match_v1 = {
+ .name = "string",
+ .revision = 1,
.family = AF_UNSPEC,
.version = XTABLES_VERSION,
.size = XT_ALIGN(sizeof(struct xt_string_info)),
@@ -342,4 +391,5 @@ static struct xtables_match string_match = {
void _init(void)
{
xtables_register_match(&string_match);
+ xtables_register_match(&string_match_v1);
}
diff --git a/extensions/tos_values.c b/extensions/tos_values.c
index 1630834e..4c0b0bcb 100644
--- a/extensions/tos_values.c
+++ b/extensions/tos_values.c
@@ -56,8 +56,9 @@ static bool tos_parse_symbolic(const char *str, struct tos_value_mask *tvm,
{
const unsigned int max = 255;
const struct tos_symbol_info *symbol;
+ char *tmp;
- if (strtonum(str, NULL, NULL, 0, max))
+ if (strtonum(str, &tmp, NULL, 0, max))
return tos_parse_numeric(str, tvm, max);
/* Do not consider ECN bits */
diff --git a/include/linux/netfilter/xt_string.h b/include/linux/netfilter/xt_string.h
index bb21dd1a..f1c182fd 100644
--- a/include/linux/netfilter/xt_string.h
+++ b/include/linux/netfilter/xt_string.h
@@ -4,6 +4,11 @@
#define XT_STRING_MAX_PATTERN_SIZE 128
#define XT_STRING_MAX_ALGO_NAME_SIZE 16
+enum {
+ XT_STRING_FLAG_INVERT = 0x01,
+ XT_STRING_FLAG_IGNORECASE = 0x02
+};
+
struct xt_string_info
{
u_int16_t from_offset;
@@ -11,7 +16,15 @@ struct xt_string_info
char algo[XT_STRING_MAX_ALGO_NAME_SIZE];
char pattern[XT_STRING_MAX_PATTERN_SIZE];
u_int8_t patlen;
- u_int8_t invert;
+ union {
+ struct {
+ u_int8_t invert;
+ } v0;
+
+ struct {
+ u_int8_t flags;
+ } v1;
+ } u;
/* Used internally by the kernel */
struct ts_config __attribute__((aligned(8))) *config;
diff --git a/ip6tables.8.in b/ip6tables.8.in
index 45b14dca..666616dc 100644
--- a/ip6tables.8.in
+++ b/ip6tables.8.in
@@ -1,4 +1,4 @@
-.TH IP6TABLES 8 "Jan 22, 2006" "" ""
+.TH IP6TABLES 8 "Jul 03, 2008" "" ""
.\"
.\" Man page written by Andras Kis-Szabo <kisza@sch.bme.hu>
.\" It is based on iptables man page.
@@ -27,26 +27,28 @@
.SH NAME
ip6tables \- IPv6 packet filter administration
.SH SYNOPSIS
-.BR "ip6tables [-t table] -[AD] " "chain rule-specification [options]"
+\fBip6tables\fP [\fB-t\fP \fItable\fP\fB]\fP {\fB-A\fP|\fB-D\fP} \fIchain rule-specification\fP [\fIoptions...\fP]
.br
-.BR "ip6tables [-t table] -I " "chain [rulenum] rule-specification [options]"
+\fBip6tables\fP [\fB-t\fP \fItable\fP\fB] -I\fP [\fIrulenum\fP] \fIrule-specification\fP [\fIoptions...\fP]
.br
-.BR "ip6tables [-t table] -R " "chain rulenum rule-specification [options]"
+\fBip6tables\fP [\fB-t\fP \fItable\fP\fB] -R\fP \fIrulenum rule-specification\fP [\fIoptions...\fP]
.br
-.BR "ip6tables [-t table] -D " "chain rulenum [options]"
+\fBip6tables\fP [\fB-t\fP \fItable\fP\fB] -D\fP \fIchain rulenum\fP [\fIoptions...\fP]
.br
-.BR "ip6tables [-t table] -[LFZ] " "[chain] [options]"
+\fBip6tables\fP [\fB-t\fP \fItable\fP\fB] -S\fP [\fIchain\fP]
.br
-.BR "ip6tables [-t table] -N " "chain"
+\fBip6tables\fP [\fB-t\fP \fItable\fP\fB]\fP {\fB-F\fP|\fB-L\fP|\fB-Z\fP} [\fIchain\fP] [\fIoptions...\fP]
.br
-.BR "ip6tables [-t table] -X " "[chain]"
+\fBip6tables\fP [\fB-t\fP \fItable\fP\fB] -N\fP \fIchain\fP
.br
-.BR "ip6tables [-t table] -P " "chain target [options]"
+\fBip6tables\fP [\fB-t\fP \fItable\fP\fB] -X\fP [\fIchain\fP]
.br
-.BR "ip6tables [-t table] -E " "old-chain-name new-chain-name"
+\fBip6tables\fP [\fB-t\fP \fItable\fP\fB] -P\fP \fIchain target\fP [\fIoptions...\fP]
+.br
+\fBip6tables\fP [\fB-t\fP \fItable\fP\fB] -E\fP \fIold-chain-name new-chain-name\fP
.SH DESCRIPTION
-.B Ip6tables
-is used to set up, maintain, and inspect the tables of IPv6 packet
+\fBIp6tables\fP is used to set up, maintain, and inspect the
+tables of IPv6 packet
filter rules in the Linux kernel. Several different tables
may be defined. Each table contains a number of built-in
chains and may also contain user-defined chains.
@@ -57,48 +59,34 @@ a `target', which may be a jump to a user-defined chain in the same
table.
.SH TARGETS
-A firewall rule specifies criteria for a packet, and a target. If the
+A firewall rule specifies criteria for a packet and a target. If the
packet does not match, the next rule in the chain is the examined; if
it does match, then the next rule is specified by the value of the
target, which can be the name of a user-defined chain or one of the
-special values
-.IR ACCEPT ,
-.IR DROP ,
-.IR QUEUE ,
-or
-.IR RETURN .
+special values \fBACCEPT\fP, \fBDROP\fP, \fBQUEUE\fP or \fBRETURN\fP.
.PP
-.I ACCEPT
-means to let the packet through.
-.I DROP
-means to drop the packet on the floor.
-.I QUEUE
-means to pass the packet to userspace. (How the packet can be received
+\fBACCEPT\fP means to let the packet through.
+\fBDROP\fP means to drop the packet on the floor.
+\fBQUEUE\fP means to pass the packet to userspace.
+(How the packet can be received
by a userspace process differs by the particular queue handler. 2.4.x
-and 2.6.x kernels up to 2.6.13 include the
-.B
-ip_queue
-queue handler. Kernels 2.6.14 and later additionally include the
-.B
-nfnetlink_queue
-queue handler. Packets with a target of QUEUE will be sent to queue number '0'
-in this case. Please also see the
-.B
-NFQUEUE
+and 2.6.x kernels up to 2.6.13 include the \fBip_queue\fP
+queue handler. Kernels 2.6.14 and later additionally include the
+\fBnfnetlink_queue\fP queue handler. Packets with a target of QUEUE will be
+sent to queue number '0' in this case. Please also see the \fBNFQUEUE\fP
target as described later in this man page.)
-.I RETURN
-means stop traversing this chain and resume at the next rule in the
+\fBRETURN\fP means stop traversing this chain and resume at the next
+rule in the
previous (calling) chain. If the end of a built-in chain is reached
-or a rule in a built-in chain with target
-.I RETURN
+or a rule in a built-in chain with target \fBRETURN\fP
is matched, the target specified by the chain policy determines the
fate of the packet.
.SH TABLES
-There are currently two independent tables (which tables are present
+There are currently three independent tables (which tables are present
at any time depends on the kernel configuration options and which
-modules are present), as nat table has not been implemented yet.
+modules are present).
.TP
-.BI "-t, --table " "table"
+\fB-t\fP, \fB--table\fP \fItable\fP
This option specifies the packet matching table which the command
should operate on. If the kernel is configured with automatic module
loading, an attempt will be made to load the appropriate module for
@@ -107,132 +95,121 @@ that table if it is not already there.
The tables are as follows:
.RS
.TP .4i
-.BR "filter" :
+\fBfilter\fP:
This is the default table (if no -t option is passed). It contains
-the built-in chains
-.B INPUT
-(for packets coming into the box itself),
-.B FORWARD
-(for packets being routed through the box), and
-.B OUTPUT
-(for locally-generated packets).
+the built-in chains \fBINPUT\fP (for packets destined to local sockets),
+\fBFORWARD\fP (for packets being routed through the box), and
+\fBOUTPUT\fP (for locally-generated packets).
.TP
-.BR "mangle" :
+\fBmangle\fP:
This table is used for specialized packet alteration. Until kernel
-2.4.17 it had two built-in chains:
-.B PREROUTING
-(for altering incoming packets before routing) and
-.B OUTPUT
+2.4.17 it had two built-in chains: \fBPREROUTING\fP
+(for altering incoming packets before routing) and \fBOUTPUT\fP
(for altering locally-generated packets before routing).
Since kernel 2.4.18, three other built-in chains are also supported:
-.B INPUT
-(for packets coming into the box itself),
-.B FORWARD
-(for altering packets being routed through the box), and
-.B POSTROUTING
+\fBINPUT\fP (for packets coming into the box itself), \fBFORWARD\fP
+(for altering packets being routed through the box), and \fBPOSTROUTING\fP
(for altering packets as they are about to go out).
.TP
-.BR "raw" :
+\fBraw\fP:
This table is used mainly for configuring exemptions from connection
tracking in combination with the NOTRACK target. It registers at the netfilter
-hooks with higher priority and is thus called before nf_conntrack, or any other
-IP6 tables. It provides the following built-in chains:
-.B PREROUTING
-(for packets arriving via any network interface)
-.B OUTPUT
+hooks with higher priority and is thus called before ip_conntrack, or any other
+IP tables. It provides the following built-in chains: \fBPREROUTING\fP
+(for packets arriving via any network interface) \fBOUTPUT\fP
(for packets generated by local processes)
.RE
.SH OPTIONS
The options that are recognized by
-.B ip6tables
-can be divided into several different groups.
+\fBip6tables\fP can be divided into several different groups.
.SS COMMANDS
These options specify the specific action to perform. Only one of them
can be specified on the command line unless otherwise specified
below. For all the long versions of the command and option names, you
need to use only enough letters to ensure that
-.B ip6tables
-can differentiate it from all other options.
+\fBip6tables\fP can differentiate it from all other options.
.TP
-.BI "-A, --append " "chain rule-specification"
+\fB-A\fP, \fB--append\fP \fIchain rule-specification\fP
Append one or more rules to the end of the selected chain.
When the source and/or destination names resolve to more than one
address, a rule will be added for each possible address combination.
.TP
-.BI "-D, --delete " "chain rule-specification"
+\fB-D\fP, \fB--delete\fP \fIchain rule-specification\fP
.ns
.TP
-.BI "-D, --delete " "chain rulenum"
+\fB-D\fP, \fB--delete\fP \fIchain rulenum\fP
Delete one or more rules from the selected chain. There are two
versions of this command: the rule can be specified as a number in the
chain (starting at 1 for the first rule) or a rule to match.
.TP
-.B "-I, --insert"
+\fB-I\fP, \fB--insert\fP \fIchain\fP [\fIrulenum\fP] \fIrule-specification\fP
Insert one or more rules in the selected chain as the given rule
number. So, if the rule number is 1, the rule or rules are inserted
at the head of the chain. This is also the default if no rule number
is specified.
.TP
-.BI "-R, --replace " "chain rulenum rule-specification"
+\fB-R\fP, \fB--replace\fP \fIchain rulenum rule-specification\fP
Replace a rule in the selected chain. If the source and/or
destination names resolve to multiple addresses, the command will
fail. Rules are numbered starting at 1.
.TP
-.BR "-L, --list " "[\fIchain\fP]"
+\fB-L\fP, \fB--list\fP [\fIchain\fP]
List all rules in the selected chain. If no chain is selected, all
-chains are listed. As every other iptables command, it applies to the
-specified table (filter is the default), so mangle rules get listed by
+chains are listed. Like every other iptables command, it applies to the
+specified table (filter is the default), so NAT rules get listed by
.nf
- ip6tables -t mangle -n -L
+ iptables -t nat -n -L
.fi
-Please note that it is often used with the
-.B -n
+Please note that it is often used with the \fB-n\fP
option, in order to avoid long reverse DNS lookups.
-It is legal to specify the
-.B -Z
+It is legal to specify the \fB-Z\fP
(zero) option as well, in which case the chain(s) will be atomically
listed and zeroed. The exact output is affected by the other
arguments given. The exact rules are suppressed until you use
.nf
- ip6tables -L -v
+ iptables -L -v
.fi
.TP
-.BR "-S, --list-rules " "[\fIchain\fP]"
+\fB-S\fP, \fB--list-rules\fP [\fIchain\fP]
Print all rules in the selected chain. If no chain is selected, all
chains are printed like iptables-save. Like every other iptables command,
it applies to the specified table (filter is the default).
.TP
-.BR "-F, --flush " "[\fIchain\fP]"
+\fB-F\fP, \fB--flush\fP [\fIchain\fP]
Flush the selected chain (all the chains in the table if none is given).
This is equivalent to deleting all the rules one by one.
.TP
-.BR "-Z, --zero " "[\fIchain\fP]"
+\fB-Z\fP, \fB--zero\fP [\fIchain\fP]
Zero the packet and byte counters in all chains. It is legal to
specify the
-.B "-L, --list"
+\fB-L\fP, \fB--list\fP
(list) option as well, to see the counters immediately before they are
cleared. (See above.)
.TP
-.BI "-N, --new-chain " "chain"
+\fB-N\fP, \fB--new-chain\fP \fIchain\fP
Create a new user-defined chain by the given name. There must be no
target of that name already.
.TP
-.BR "-X, --delete-chain " "[\fIchain\fP]"
+\fB-X\fP, \fB--delete-chain\fP [\fIchain\fP]
Delete the optional user-defined chain specified. There must be no references
-to the chain. If there are, you must delete or replace the referring
-rules before the chain can be deleted. If no argument is given, it
-will attempt to delete every non-builtin chain in the table.
+to the chain. If there are, you must delete or replace the referring rules
+before the chain can be deleted. The chain must be empty, i.e. not contain
+any rules. If no argument is given, it will attempt to delete every
+non-builtin chain in the table.
.TP
-.BI "-P, --policy " "chain target"
-Set the policy for the chain to the given target. See the section
-.B TARGETS
+\fB-P\fP, \fB--policy\fP \fIchain target\fP
+Set the policy for the chain to the given target. See the section \fBTARGETS\fP
for the legal targets. Only built-in (non-user-defined) chains can have
policies, and neither built-in nor user-defined chains can be policy
targets.
.TP
-.BI "-E, --rename-chain " "old-chain new-chain"
+\fB-E\fP, \fB--rename-chain\fP \fIold-chain new-chain\fP
Rename the user specified chain to the user supplied name. This is
cosmetic, and has no effect on the structure of the table.
+.BI "-A, --append " "chain rule-specification"
+Append one or more rules to the end of the selected chain.
+When the source and/or destination names resolve to more than one
+address, a rule will be added for each possible address combination.
.TP
.B -h
Help.
@@ -241,171 +218,130 @@ Give a (currently very brief) description of the command syntax.
The following parameters make up a rule specification (as used in the
add, delete, insert, replace and append commands).
.TP
-.BR "-p, --protocol " "[!] \fIprotocol\fP"
+[\fB!\fP] \fB-p\fP, \fB--protocol\fP \fIprotocol\fP
The protocol of the rule or of the packet to check.
-The specified protocol can be one of
-.IR tcp ,
-.IR udp ,
-.IR icmpv6 ,
-.IR esp ,
-.IR all ,
+The specified protocol can be one of \fBtcp\fP, \fBudp\fP, \fBudplite\fP,
+\fBicmpv6\fP, \fBesp\fP, \fBmh\fP or \fBall\fP,
or it can be a numeric value, representing one of these protocols or a
different one. A protocol name from /etc/protocols is also allowed.
-But IPv6 extension headers except
-.IR esp
-are not allowed.
-.IR esp ,
-and
-.IR ipv6-nonext
+But IPv6 extension headers except \fBesp\fP are not allowed.
+\fBesp\fP and \fBipv6-nonext\fP
can be used with Kernel version 2.6.11 or later.
A "!" argument before the protocol inverts the
-test. The number zero is equivalent to
-.IR all .
-Protocol
-.I all
+test. The number zero is equivalent to \fBall\fP.
+Protocol \fBall\fP
will match with all protocols and is taken as default when this
option is omitted.
.TP
-.BR "-s, --source " "[!] \fIaddress\fP[/\fImask\fP]"
+[\fB!\fP] \fB-s\fP, \fB--source\fP \fIaddress\fP[\fB/\fP\fImask\fP]
Source specification.
-.I Address
-can be either a hostname (please note that specifying
+\fIAddress\fP can be either a hostname (please note that specifying
any name to be resolved with a remote query such as DNS is a really bad idea),
-a network IPv6 address (with /mask), or a plain IPv6 address.
+a network IPv6 address (with \fB/\fP\fImask\fP), or a plain IPv6 address.
(the network name isn't supported now).
-The
-.I mask
-can be either a network mask or a plain number,
+The \fImask\fP is a plain number,
specifying the number of 1's at the left side of the network mask.
-Thus, a mask of
-.I 64
-is equivalent to
-.IR ffff:ffff:ffff:ffff:0000:0000:0000:0000 .
A "!" argument before the address specification inverts the sense of
-the address. The flag
-.B --src
+the address. The flag \fB--src\fP
is an alias for this option.
.TP
-.BR "-d, --destination " "[!] \fIaddress\fP[/\fImask\fP]"
+[\fB!\fP] \fB-d\fP, \fB--destination\fP \fIaddress\fP[\fB/\fP\fImask\fP]
Destination specification.
-See the description of the
-.B -s
+See the description of the \fB-s\fP
(source) flag for a detailed description of the syntax. The flag
-.B --dst
-is an alias for this option.
+\fB--dst\fP is an alias for this option.
.TP
-.BI "-j, --jump " "target"
+\fB-j\fP, \fB--jump\fP \fItarget\fP
This specifies the target of the rule; i.e., what to do if the packet
matches it. The target can be a user-defined chain (other than the
one this rule is in), one of the special builtin targets which decide
-the fate of the packet immediately, or an extension (see
-.B EXTENSIONS
+the fate of the packet immediately, or an extension (see \fBEXTENSIONS\fP
below). If this
-option is omitted in a rule, then matching the rule will have no
+option is omitted in a rule (and \fB-g\fP
+is not used), then matching the rule will have no
effect on the packet's fate, but the counters on the rule will be
incremented.
.TP
-.BR "-i, --in-interface " "[!] \fIname\fP"
-Name of an interface via which a packet is going to be received (only for
-packets entering the
-.BR INPUT ,
-.B FORWARD
-and
-.B PREROUTING
+\fB-g\fP, \fB--goto\fP \fIchain\fP
+This specifies that the processing should continue in a user
+specified chain. Unlike the --jump option return will not continue
+processing in this chain but instead in the chain that called us via
+--jump.
+.TP
+[\fB!\fP] \fB-i\fP, \fB--in-interface\fP \fIname\fP
+Name of an interface via which a packet was received (only for
+packets entering the \fBINPUT\fP, \fBFORWARD\fP and \fBPREROUTING\fP
chains). When the "!" argument is used before the interface name, the
sense is inverted. If the interface name ends in a "+", then any
interface which begins with this name will match. If this option is
omitted, any interface name will match.
.TP
-.BR "-o, --out-interface " "[!] \fIname\fP"
+[\fB!\fP] \fB-o\fP, \fB--out-interface\fP \fIname\fP
Name of an interface via which a packet is going to be sent (for packets
-entering the
-.BR FORWARD
-and
-.B OUTPUT
+entering the \fBFORWARD\fP, \fBOUTPUT\fP and \fBPOSTROUTING\fP
chains). When the "!" argument is used before the interface name, the
sense is inverted. If the interface name ends in a "+", then any
interface which begins with this name will match. If this option is
omitted, any interface name will match.
-.TP
.\" Currently not supported (header-based)
-.\"
-.\" .B "[!] " "-f, --fragment"
+.\" .TP
+.\" [\fB!\fP] \fB-f\fP, \fB--fragment\fP
.\" This means that the rule only refers to second and further fragments
.\" of fragmented packets. Since there is no way to tell the source or
.\" destination ports of such a packet (or ICMP type), such a packet will
.\" not match any rules which specify them. When the "!" argument
.\" precedes the "-f" flag, the rule will only match head fragments, or
.\" unfragmented packets.
-.\" .TP
-.B "-c, --set-counters " "PKTS BYTES"
+.TP
+\fB-c\fP, \fB--set-counters\fP \fIpackets bytes\fP
This enables the administrator to initialize the packet and byte
-counters of a rule (during
-.B INSERT,
-.B APPEND,
-.B REPLACE
+counters of a rule (during \fBINSERT\fP, \fBAPPEND\fP, \fBREPLACE\fP
operations).
.SS "OTHER OPTIONS"
The following additional options can be specified:
.TP
-.B "-v, --verbose"
+\fB-v\fP, \fB--verbose\fP
Verbose output. This option makes the list command show the interface
name, the rule options (if any), and the TOS masks. The packet and
byte counters are also listed, with the suffix 'K', 'M' or 'G' for
1000, 1,000,000 and 1,000,000,000 multipliers respectively (but see
-the
-.B -x
-flag to change this).
+the \fB-x\fP flag to change this).
For appending, insertion, deletion and replacement, this causes
detailed information on the rule or rules to be printed.
.TP
-.B "-n, --numeric"
+\fB-n\fP, \fB--numeric\fP
Numeric output.
IP addresses and port numbers will be printed in numeric format.
By default, the program will try to display them as host names,
network names, or services (whenever applicable).
.TP
-.B "-x, --exact"
+\fB-x\fP, \fB--exact\fP
Expand numbers.
Display the exact value of the packet and byte counters,
instead of only the rounded number in K's (multiples of 1000)
M's (multiples of 1000K) or G's (multiples of 1000M). This option is
-only relevant for the
-.B -L
-command.
+only relevant for the \fB-L\fP command.
.TP
.B "--line-numbers"
When listing rules, add line numbers to the beginning of each rule,
corresponding to that rule's position in the chain.
.TP
-.B "--modprobe=command"
-When adding or inserting rules into a chain, use
-.B command
+\fB--modprobe=\fP\fIcommand\fP
+When adding or inserting rules into a chain, use \fIcommand\fP
to load any necessary modules (targets, match extensions, etc).
.SH MATCH EXTENSIONS
ip6tables can use extended packet matching modules. These are loaded
-in two ways: implicitly, when
-.B -p
-or
-.B --protocol
-is specified, or with the
-.B -m
-or
-.B --match
+in two ways: implicitly, when \fB-p\fP or \fB--protocol\fP
+is specified, or with the \fB-m\fP or \fB--match\fP
options, followed by the matching module name; after these, various
extra command line options become available, depending on the specific
module. You can specify multiple extended match modules in one line,
-and you can use the
-.B -h
-or
-.B --help
+and you can use the \fB-h\fP or \fB--help\fP
options after the module has been specified to receive help specific
to that module.
The following are included in the base package, and most of these can
-be preceded by a
-.B !
-to invert the sense of the match.
+be preceded by a "\fB!\fP" to invert the sense of the match.
.\" @MATCH@
.SH TARGET EXTENSIONS
ip6tables can use extended target modules: the following are included
@@ -420,27 +356,18 @@ other errors cause an exit code of 1.
Bugs? What's this? ;-)
Well... the counters are not reliable on sparc64.
.SH COMPATIBILITY WITH IPCHAINS
-This
-.B ip6tables
+This \fBip6tables\fP
is very similar to ipchains by Rusty Russell. The main difference is
-that the chains
-.B INPUT
-and
-.B OUTPUT
+that the chains \fBINPUT\fP and \fBOUTPUT\fP
are only traversed for packets coming into the local host and
originating from the local host respectively. Hence every packet only
passes through one of the three chains (except loopback traffic, which
involves both INPUT and OUTPUT chains); previously a forwarded packet
would pass through all three.
.PP
-The other main difference is that
-.B -i
-refers to the input interface;
-.B -o
-refers to the output interface, and both are available for packets
-entering the
-.B FORWARD
-chain.
+The other main difference is that \fB-i\fP refers to the input interface;
+\fB-o\fP refers to the output interface, and both are available for packets
+entering the \fBFORWARD\fP chain.
.\" .PP The various forms of NAT have been separated out;
.\" .B iptables
.\" is a pure packet filter when using the default `filter' table, with
diff --git a/ip6tables.c b/ip6tables.c
index e1461146..2b053924 100644
--- a/ip6tables.c
+++ b/ip6tables.c
@@ -132,6 +132,7 @@ static struct option original_opts[] = {
{.name = "line-numbers", .has_arg = 0, .val = '0'},
{.name = "modprobe", .has_arg = 1, .val = 'M'},
{.name = "set-counters", .has_arg = 1, .val = 'c'},
+ {.name = "goto", .has_arg = 1, .val = 'g'},
{NULL},
};
@@ -328,6 +329,10 @@ exit_printhelp(struct ip6tables_rule_match *matches)
" network interface name ([+] for wildcard)\n"
" --jump -j target\n"
" target for rule (may load target extension)\n"
+#ifdef IP6T_F_GOTO
+" --goto -g chain\n"
+" jump to chain with no return\n"
+#endif
" --match -m match\n"
" extended match (may load extension)\n"
" --numeric -n numeric output of addresses and ports\n"
@@ -823,6 +828,11 @@ print_firewall(const struct ip6t_entry *fw,
if (format & FMT_NOTABLE)
fputs(" ", stdout);
+#ifdef IP6T_F_GOTO
+ if(fw->ipv6.flags & IP6T_F_GOTO)
+ printf("[goto] ");
+#endif
+
IP6T_MATCH_ITERATE(fw, print_match, &fw->ipv6, format & FMT_NUMERIC);
if (target) {
@@ -1259,7 +1269,11 @@ void print_rule(const struct ip6t_entry *e,
/* Print target name */
target_name = ip6tc_get_target(e, h);
if (target_name && (*target_name != '\0'))
+#ifdef IP6T_F_GOTO
+ printf("-%c %s ", e->ipv6.flags & IP6T_F_GOTO ? 'g' : 'j', target_name);
+#else
printf("-j %s ", target_name);
+#endif
/* Print targinfo part */
t = ip6t_get_target((struct ip6t_entry *)e);
@@ -1447,7 +1461,7 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle)
opterr = 0;
while ((c = getopt_long(argc, argv,
- "-A:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:bvnt:m:xc:",
+ "-A:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:bvnt:m:xc:g:",
opts, NULL)) != -1) {
switch (c) {
/*
@@ -1638,6 +1652,15 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle)
dhostnetworkmask = argv[optind-1];
break;
+#ifdef IP6T_F_GOTO
+ case 'g':
+ set_option(&options, OPT_JUMP, &fw.ipv6.invflags,
+ invert);
+ fw.ipv6.flags |= IP6T_F_GOTO;
+ jumpto = parse_target(optarg);
+ break;
+#endif
+
case 'j':
set_option(&options, OPT_JUMP, &fw.ipv6.invflags,
invert);
@@ -1995,6 +2018,11 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle)
* We cannot know if the plugin is corrupt, non
* existant OR if the user just misspelled a
* chain. */
+#ifdef IP6T_F_GOTO
+ if (fw.ipv6.flags & IP6T_F_GOTO)
+ exit_error(PARAMETER_PROBLEM,
+ "goto '%s' is not a chain\n", jumpto);
+#endif
find_target(jumpto, LOAD_MUST_SUCCEED);
} else {
e = generate_entry(&fw, matches, target->t);
diff --git a/iptables.8.in b/iptables.8.in
index 0b945cb7..c08d27db 100644
--- a/iptables.8.in
+++ b/iptables.8.in
@@ -1,4 +1,4 @@
-.TH IPTABLES 8 "Mar 09, 2002" "" ""
+.TH IPTABLES 8 "Jul 03, 2008" "" ""
.\"
.\" Man page written by Herve Eychenne <rv@wallfire.org> (May 1999)
.\" It is based on ipchains page.
@@ -25,26 +25,28 @@
.SH NAME
iptables \- administration tool for IPv4 packet filtering and NAT
.SH SYNOPSIS
-.BR "iptables [-t table] -[AD] " "chain rule-specification [options]"
+\fBiptables\fP [\fB-t\fP \fItable\fP\fB]\fP {\fB-A\fP|\fB-D\fP} \fIchain rule-specification\fP [\fIoptions...\fP]
.br
-.BR "iptables [-t table] -I " "chain [rulenum] rule-specification [options]"
+\fBiptables\fP [\fB-t\fP \fItable\fP\fB] -I\fP [\fIrulenum\fP] \fIrule-specification\fP [\fIoptions...\fP]
.br
-.BR "iptables [-t table] -R " "chain rulenum rule-specification [options]"
+\fBiptables\fP [\fB-t\fP \fItable\fP\fB] -R\fP \fIrulenum rule-specification\fP [\fIoptions...\fP]
.br
-.BR "iptables [-t table] -D " "chain rulenum [options]"
+\fBiptables\fP [\fB-t\fP \fItable\fP\fB] -D\fP \fIchain rulenum\fP [\fIoptions...\fP]
.br
-.BR "iptables [-t table] -[LFZ] " "[chain] [options]"
+\fBiptables\fP [\fB-t\fP \fItable\fP\fB] -S\fP [\fIchain\fP]
.br
-.BR "iptables [-t table] -N " "chain"
+\fBiptables\fP [\fB-t\fP \fItable\fP\fB]\fP {\fB-F\fP|\fB-L\fP|\fB-Z\fP} [\fIchain\fP] [\fIoptions...\fP]
.br
-.BR "iptables [-t table] -X " "[chain]"
+\fBiptables\fP [\fB-t\fP \fItable\fP\fB] -N\fP \fIchain\fP
.br
-.BR "iptables [-t table] -P " "chain target [options]"
+\fBiptables\fP [\fB-t\fP \fItable\fP\fB] -X\fP [\fIchain\fP]
.br
-.BR "iptables [-t table] -E " "old-chain-name new-chain-name"
+\fBiptables\fP [\fB-t\fP \fItable\fP\fB] -P\fP \fIchain target\fP [\fIoptions...\fP]
+.br
+\fBiptables\fP [\fB-t\fP \fItable\fP\fB] -E\fP \fIold-chain-name new-chain-name\fP
.SH DESCRIPTION
-.B Iptables
-is used to set up, maintain, and inspect the tables of IP packet
+\fBIptables\fP is used to set up, maintain, and inspect the
+tables of IPv4 packet
filter rules in the Linux kernel. Several different tables
may be defined. Each table contains a number of built-in
chains and may also contain user-defined chains.
@@ -59,36 +61,22 @@ A firewall rule specifies criteria for a packet and a target. If the
packet does not match, the next rule in the chain is the examined; if
it does match, then the next rule is specified by the value of the
target, which can be the name of a user-defined chain or one of the
-special values
-.IR ACCEPT ,
-.IR DROP ,
-.IR QUEUE ,
-or
-.IR RETURN .
+special values \fBACCEPT\fP, \fBDROP\fP, \fBQUEUE\fP or \fBRETURN\fP.
.PP
-.I ACCEPT
-means to let the packet through.
-.I DROP
-means to drop the packet on the floor.
-.I QUEUE
-means to pass the packet to userspace. (How the packet can be received
+\fBACCEPT\fP means to let the packet through.
+\fBDROP\fP means to drop the packet on the floor.
+\fBQUEUE\fP means to pass the packet to userspace.
+(How the packet can be received
by a userspace process differs by the particular queue handler. 2.4.x
-and 2.6.x kernels up to 2.6.13 include the
-.B
-ip_queue
-queue handler. Kernels 2.6.14 and later additionally include the
-.B
-nfnetlink_queue
-queue handler. Packets with a target of QUEUE will be sent to queue number '0'
-in this case. Please also see the
-.B
-NFQUEUE
+and 2.6.x kernels up to 2.6.13 include the \fBip_queue\fP
+queue handler. Kernels 2.6.14 and later additionally include the
+\fBnfnetlink_queue\fP queue handler. Packets with a target of QUEUE will be
+sent to queue number '0' in this case. Please also see the \fBNFQUEUE\fP
target as described later in this man page.)
-.I RETURN
-means stop traversing this chain and resume at the next rule in the
+\fBRETURN\fP means stop traversing this chain and resume at the next
+rule in the
previous (calling) chain. If the end of a built-in chain is reached
-or a rule in a built-in chain with target
-.I RETURN
+or a rule in a built-in chain with target \fBRETURN\fP
is matched, the target specified by the chain policy determines the
fate of the packet.
.SH TABLES
@@ -96,7 +84,7 @@ There are currently three independent tables (which tables are present
at any time depends on the kernel configuration options and which
modules are present).
.TP
-.BI "-t, --table " "table"
+\fB-t\fP, \fB--table\fP \fItable\fP
This option specifies the packet matching table which the command
should operate on. If the kernel is configured with automatic module
loading, an attempt will be made to load the appropriate module for
@@ -105,99 +93,81 @@ that table if it is not already there.
The tables are as follows:
.RS
.TP .4i
-.BR "filter" :
+\fBfilter\fP:
This is the default table (if no -t option is passed). It contains
-the built-in chains
-.B INPUT
-(for packets destined to local sockets),
-.B FORWARD
-(for packets being routed through the box), and
-.B OUTPUT
-(for locally-generated packets).
-.TP
-.BR "nat" :
+the built-in chains \fBINPUT\fP (for packets destined to local sockets),
+\fBFORWARD\fP (for packets being routed through the box), and
+\fBOUTPUT\fP (for locally-generated packets).
+.TP
+\fBnat\fP:
This table is consulted when a packet that creates a new
-connection is encountered. It consists of three built-ins:
-.B PREROUTING
-(for altering packets as soon as they come in),
-.B OUTPUT
-(for altering locally-generated packets before routing), and
-.B POSTROUTING
+connection is encountered. It consists of three built-ins: \fBPREROUTING\fP
+(for altering packets as soon as they come in), \fBOUTPUT\fP
+(for altering locally-generated packets before routing), and \fBPOSTROUTING\fP
(for altering packets as they are about to go out).
.TP
-.BR "mangle" :
+\fBmangle\fP:
This table is used for specialized packet alteration. Until kernel
-2.4.17 it had two built-in chains:
-.B PREROUTING
-(for altering incoming packets before routing) and
-.B OUTPUT
+2.4.17 it had two built-in chains: \fBPREROUTING\fP
+(for altering incoming packets before routing) and \fBOUTPUT\fP
(for altering locally-generated packets before routing).
Since kernel 2.4.18, three other built-in chains are also supported:
-.B INPUT
-(for packets coming into the box itself),
-.B FORWARD
-(for altering packets being routed through the box), and
-.B POSTROUTING
+\fBINPUT\fP (for packets coming into the box itself), \fBFORWARD\fP
+(for altering packets being routed through the box), and \fBPOSTROUTING\fP
(for altering packets as they are about to go out).
.TP
-.BR "raw" :
+\fBraw\fP:
This table is used mainly for configuring exemptions from connection
tracking in combination with the NOTRACK target. It registers at the netfilter
hooks with higher priority and is thus called before ip_conntrack, or any other
-IP tables. It provides the following built-in chains:
-.B PREROUTING
-(for packets arriving via any network interface)
-.B OUTPUT
+IP tables. It provides the following built-in chains: \fBPREROUTING\fP
+(for packets arriving via any network interface) \fBOUTPUT\fP
(for packets generated by local processes)
.RE
.SH OPTIONS
The options that are recognized by
-.B iptables
-can be divided into several different groups.
+\fBiptables\fP can be divided into several different groups.
.SS COMMANDS
These options specify the desired action to perform. Only one of them
can be specified on the command line unless otherwise stated
below. For long versions of the command and option names, you
need to use only enough letters to ensure that
-.B iptables
-can differentiate it from all other options.
+\fBiptables\fP can differentiate it from all other options.
.TP
-.BI "-A, --append " "chain rule-specification"
+\fB-A\fP, \fB--append\fP \fIchain rule-specification\fP
Append one or more rules to the end of the selected chain.
When the source and/or destination names resolve to more than one
address, a rule will be added for each possible address combination.
.TP
-.BI "-D, --delete " "chain rule-specification"
+\fB-D\fP, \fB--delete\fP \fIchain rule-specification\fP
.ns
.TP
-.BI "-D, --delete " "chain rulenum"
+\fB-D\fP, \fB--delete\fP \fIchain rulenum\fP
Delete one or more rules from the selected chain. There are two
versions of this command: the rule can be specified as a number in the
chain (starting at 1 for the first rule) or a rule to match.
.TP
-.BR "-I, --insert " "\fIchain\fP [\fIrulenum\fP] \fIrule-specification\fP"
+\fB-I\fP, \fB--insert\fP \fIchain\fP [\fIrulenum\fP] \fIrule-specification\fP
Insert one or more rules in the selected chain as the given rule
number. So, if the rule number is 1, the rule or rules are inserted
at the head of the chain. This is also the default if no rule number
is specified.
.TP
-.BI "-R, --replace " "chain rulenum rule-specification"
+\fB-R\fP, \fB--replace\fP \fIchain rulenum rule-specification\fP
Replace a rule in the selected chain. If the source and/or
destination names resolve to multiple addresses, the command will
fail. Rules are numbered starting at 1.
.TP
-.BR "-L, --list " "[\fIchain\fP]"
+\fB-L\fP, \fB--list\fP [\fIchain\fP]
List all rules in the selected chain. If no chain is selected, all
chains are listed. Like every other iptables command, it applies to the
specified table (filter is the default), so NAT rules get listed by
.nf
iptables -t nat -n -L
.fi
-Please note that it is often used with the
-.B -n
+Please note that it is often used with the \fB-n\fP
option, in order to avoid long reverse DNS lookups.
-It is legal to specify the
-.B -Z
+It is legal to specify the \fB-Z\fP
(zero) option as well, in which case the chain(s) will be atomically
listed and zeroed. The exact output is affected by the other
arguments given. The exact rules are suppressed until you use
@@ -205,41 +175,40 @@ arguments given. The exact rules are suppressed until you use
iptables -L -v
.fi
.TP
-.BR "-S, --list-rules " "[\fIchain\fP]"
+\fB-S\fP, \fB--list-rules\fP [\fIchain\fP]
Print all rules in the selected chain. If no chain is selected, all
chains are printed like iptables-save. Like every other iptables command,
it applies to the specified table (filter is the default).
.TP
-.BR "-F, --flush " "[\fIchain\fP]"
+\fB-F\fP, \fB--flush\fP [\fIchain\fP]
Flush the selected chain (all the chains in the table if none is given).
This is equivalent to deleting all the rules one by one.
.TP
-.BR "-Z, --zero " "[\fIchain\fP]"
+\fB-Z\fP, \fB--zero\fP [\fIchain\fP]
Zero the packet and byte counters in all chains. It is legal to
specify the
-.B "-L, --list"
+\fB-L\fP, \fB--list\fP
(list) option as well, to see the counters immediately before they are
cleared. (See above.)
.TP
-.BI "-N, --new-chain " "chain"
+\fB-N\fP, \fB--new-chain\fP \fIchain\fP
Create a new user-defined chain by the given name. There must be no
target of that name already.
.TP
-.BR "-X, --delete-chain " "[\fIchain\fP]"
+\fB-X\fP, \fB--delete-chain\fP [\fIchain\fP]
Delete the optional user-defined chain specified. There must be no references
to the chain. If there are, you must delete or replace the referring rules
before the chain can be deleted. The chain must be empty, i.e. not contain
any rules. If no argument is given, it will attempt to delete every
non-builtin chain in the table.
.TP
-.BI "-P, --policy " "chain target"
-Set the policy for the chain to the given target. See the section
-.B TARGETS
+\fB-P\fP, \fB--policy\fP \fIchain target\fP
+Set the policy for the chain to the given target. See the section \fBTARGETS\fP
for the legal targets. Only built-in (non-user-defined) chains can have
policies, and neither built-in nor user-defined chains can be policy
targets.
.TP
-.BI "-E, --rename-chain " "old-chain new-chain"
+\fB-E\fP, \fB--rename-chain\fP \fIold-chain new-chain\fP
Rename the user specified chain to the user supplied name. This is
cosmetic, and has no effect on the structure of the table.
.TP
@@ -250,95 +219,70 @@ Give a (currently very brief) description of the command syntax.
The following parameters make up a rule specification (as used in the
add, delete, insert, replace and append commands).
.TP
-.BR "-p, --protocol " "[!] \fIprotocol\fP"
+[\fB!\fP] \fB-p\fP, \fB--protocol\fP \fIprotocol\fP
The protocol of the rule or of the packet to check.
-The specified protocol can be one of
-.IR tcp ,
-.IR udp ,
-.IR icmp ,
-or
-.IR all ,
+The specified protocol can be one of \fBtcp\fP, \fBudp\fP, \fBudplite\fP,
+\fBicmp\fP, \fBesp\fP, \fBah\fP, \fBsctp\fP or \fBall\fP,
or it can be a numeric value, representing one of these protocols or a
different one. A protocol name from /etc/protocols is also allowed.
A "!" argument before the protocol inverts the
-test. The number zero is equivalent to
-.IR all .
-Protocol
-.I all
+test. The number zero is equivalent to \fBall\fP.
+Protocol \fBall\fP
will match with all protocols and is taken as default when this
option is omitted.
.TP
-.BR "-s, --source " "[!] \fIaddress\fP[/\fImask\fP]"
-Source specification.
-.I Address
+[\fB!\fP] \fB-s\fP, \fB--source\fP \fIaddress\fP[\fB/\fP\fImask\fP]
+Source specification. \fIAddress\fP
can be either a network name, a hostname (please note that specifying
any name to be resolved with a remote query such as DNS is a really bad idea),
-a network IP address (with /mask), or a plain IP address.
-The
-.I mask
+a network IP address (with \fB/\fP\fImask\fP), or a plain IP address.
+The \fImask\fP
can be either a network mask or a plain number,
specifying the number of 1's at the left side of the network mask.
-Thus, a mask of
-.I 24
-is equivalent to
-.IR 255.255.255.0 .
+Thus, a mask of \fI24\fP is equivalent to \fI255.255.255.0\fP.
A "!" argument before the address specification inverts the sense of
-the address. The flag
-.B --src
-is an alias for this option.
+the address. The flag \fB--src\fP is an alias for this option.
.TP
-.BR "-d, --destination " "[!] \fIaddress\fP[/\fImask\fP]"
+[\fB!\fP] \fB-d\fP, \fB--destination\fP \fIaddress\fP[\fB/\fP\fImask\fP]
Destination specification.
-See the description of the
-.B -s
+See the description of the \fB-s\fP
(source) flag for a detailed description of the syntax. The flag
-.B --dst
-is an alias for this option.
+\fB--dst\fP is an alias for this option.
.TP
-.BI "-j, --jump " "target"
+\fB-j\fP, \fB--jump\fP \fItarget\fP
This specifies the target of the rule; i.e., what to do if the packet
matches it. The target can be a user-defined chain (other than the
one this rule is in), one of the special builtin targets which decide
-the fate of the packet immediately, or an extension (see
-.B EXTENSIONS
+the fate of the packet immediately, or an extension (see \fBEXTENSIONS\fP
below). If this
-option is omitted in a rule (and
-.B -g
+option is omitted in a rule (and \fB-g\fP
is not used), then matching the rule will have no
effect on the packet's fate, but the counters on the rule will be
incremented.
.TP
-.BI "-g, --goto " "chain"
+\fB-g\fP, \fB--goto\fP \fIchain\fP
This specifies that the processing should continue in a user
specified chain. Unlike the --jump option return will not continue
processing in this chain but instead in the chain that called us via
--jump.
.TP
-.BR "-i, --in-interface " "[!] \fIname\fP"
+[\fB!\fP] \fB-i\fP, \fB--in-interface\fP \fIname\fP
Name of an interface via which a packet was received (only for
-packets entering the
-.BR INPUT ,
-.B FORWARD
-and
-.B PREROUTING
+packets entering the \fBINPUT\fP, \fBFORWARD\fP and \fBPREROUTING\fP
chains). When the "!" argument is used before the interface name, the
sense is inverted. If the interface name ends in a "+", then any
interface which begins with this name will match. If this option is
omitted, any interface name will match.
.TP
-.BR "-o, --out-interface " "[!] \fIname\fP"
+[\fB!\fP] \fB-o\fP, \fB--out-interface\fP \fIname\fP
Name of an interface via which a packet is going to be sent (for packets
-entering the
-.BR FORWARD ,
-.B OUTPUT
-and
-.B POSTROUTING
+entering the \fBFORWARD\fP, \fBOUTPUT\fP and \fBPOSTROUTING\fP
chains). When the "!" argument is used before the interface name, the
sense is inverted. If the interface name ends in a "+", then any
interface which begins with this name will match. If this option is
omitted, any interface name will match.
.TP
-.B "[!] " "-f, --fragment"
+[\fB!\fP] \fB-f\fP, \fB--fragment\fP
This means that the rule only refers to second and further fragments
of fragmented packets. Since there is no way to tell the source or
destination ports of such a packet (or ICMP type), such a packet will
@@ -346,74 +290,55 @@ not match any rules which specify them. When the "!" argument
precedes the "-f" flag, the rule will only match head fragments, or
unfragmented packets.
.TP
-.BI "-c, --set-counters " "PKTS BYTES"
+\fB-c\fP, \fB--set-counters\fP \fIpackets bytes\fP
This enables the administrator to initialize the packet and byte
-counters of a rule (during
-.B INSERT,
-.B APPEND,
-.B REPLACE
+counters of a rule (during \fBINSERT\fP, \fBAPPEND\fP, \fBREPLACE\fP
operations).
.SS "OTHER OPTIONS"
The following additional options can be specified:
.TP
-.B "-v, --verbose"
+\fB-v\fP, \fB--verbose\fP
Verbose output. This option makes the list command show the interface
name, the rule options (if any), and the TOS masks. The packet and
byte counters are also listed, with the suffix 'K', 'M' or 'G' for
1000, 1,000,000 and 1,000,000,000 multipliers respectively (but see
-the
-.B -x
-flag to change this).
+the \fB-x\fP flag to change this).
For appending, insertion, deletion and replacement, this causes
detailed information on the rule or rules to be printed.
.TP
-.B "-n, --numeric"
+\fB-n\fP, \fB--numeric\fP
Numeric output.
IP addresses and port numbers will be printed in numeric format.
By default, the program will try to display them as host names,
network names, or services (whenever applicable).
.TP
-.B "-x, --exact"
+\fB-x\fP, \fB--exact\fP
Expand numbers.
Display the exact value of the packet and byte counters,
instead of only the rounded number in K's (multiples of 1000)
M's (multiples of 1000K) or G's (multiples of 1000M). This option is
-only relevant for the
-.B -L
-command.
+only relevant for the \fB-L\fP command.
.TP
.B "--line-numbers"
When listing rules, add line numbers to the beginning of each rule,
corresponding to that rule's position in the chain.
.TP
-.B "--modprobe=command"
-When adding or inserting rules into a chain, use
-.B command
+\fB--modprobe=\fP\fIcommand\fP
+When adding or inserting rules into a chain, use \fIcommand\fP
to load any necessary modules (targets, match extensions, etc).
.SH MATCH EXTENSIONS
iptables can use extended packet matching modules. These are loaded
-in two ways: implicitly, when
-.B -p
-or
-.B --protocol
-is specified, or with the
-.B -m
-or
-.B --match
+in two ways: implicitly, when \fB-p\fP or \fB--protocol\fP
+is specified, or with the \fB-m\fP or \fB--match\fP
options, followed by the matching module name; after these, various
extra command line options become available, depending on the specific
module. You can specify multiple extended match modules in one line,
-and you can use the
-.B -h
-or
-.B --help
+and you can use the \fB-h\fP or \fB--help\fP
options after the module has been specified to receive help specific
to that module.
The following are included in the base package, and most of these can
-be preceded by a
-.B !
-to invert the sense of the match.
+be preceded by a "\fB!\fP" to invert the sense of the match.
.\" @MATCH@
.SH TARGET EXTENSIONS
iptables can use extended target modules: the following are included
@@ -428,29 +353,20 @@ other errors cause an exit code of 1.
Bugs? What's this? ;-)
Well, you might want to have a look at http://bugzilla.netfilter.org/
.SH COMPATIBILITY WITH IPCHAINS
-This
-.B iptables
+This \fBiptables\fP
is very similar to ipchains by Rusty Russell. The main difference is
-that the chains
-.B INPUT
-and
-.B OUTPUT
+that the chains \fBINPUT\fP and \fBOUTPUT\fP
are only traversed for packets coming into the local host and
originating from the local host respectively. Hence every packet only
passes through one of the three chains (except loopback traffic, which
involves both INPUT and OUTPUT chains); previously a forwarded packet
would pass through all three.
.PP
-The other main difference is that
-.B -i
-refers to the input interface;
-.B -o
-refers to the output interface, and both are available for packets
-entering the
-.B FORWARD
-chain.
-.PP The various forms of NAT have been separated out;
-.B iptables
+The other main difference is that \fB-i\fP refers to the input interface;
+\fB-o\fP refers to the output interface, and both are available for packets
+entering the \fBFORWARD\fP chain.
+.PP
+The various forms of NAT have been separated out; \fBiptables\fP
is a pure packet filter when using the default `filter' table, with
optional extension modules. This should simplify much of the previous
confusion over the combination of IP masquerading and packet filtering
diff --git a/libiptc/libiptc.c b/libiptc/libiptc.c
index d0f51b4a..b68e48c3 100644
--- a/libiptc/libiptc.c
+++ b/libiptc/libiptc.c
@@ -140,10 +140,20 @@ STRUCT_TC_HANDLE
struct chain_head **chain_index; /* array for fast chain list access*/
unsigned int chain_index_sz;/* size of chain index array */
+ int sorted_offsets; /* if chains are received sorted from kernel,
+ * then the offsets are also sorted. Says if its
+ * possible to bsearch offsets using chain_index.
+ */
+
STRUCT_GETINFO info;
STRUCT_GET_ENTRIES *entries;
};
+enum bsearch_type {
+ BSEARCH_NAME, /* Binary search after chain name */
+ BSEARCH_OFFSET, /* Binary search based on offset */
+};
+
/* allocate a new chain head for the cache */
static struct chain_head *iptcc_alloc_chain_head(const char *name, int hooknum)
{
@@ -306,15 +316,21 @@ iptcb_ent_is_hook_entry(STRUCT_ENTRY *e, TC_HANDLE_T h)
static inline unsigned int iptcc_is_builtin(struct chain_head *c);
-
/* Use binary search in the chain index array, to find a chain_head
* pointer closest to the place of the searched name element.
*
* Notes that, binary search (obviously) requires that the chain list
* is sorted by name.
+ *
+ * The not so obvious: The chain index array, is actually both sorted
+ * by name and offset, at the same time!. This is only true because,
+ * chain are stored sorted in the kernel (as we pushed it in sorted).
+ *
*/
static struct list_head *
-iptcc_bsearch_chain_index(const char *name, unsigned int *idx, TC_HANDLE_T handle)
+__iptcc_bsearch_chain_index(const char *name, unsigned int offset,
+ unsigned int *idx, TC_HANDLE_T handle,
+ enum bsearch_type type)
{
unsigned int pos, end;
int res;
@@ -332,7 +348,8 @@ iptcc_bsearch_chain_index(const char *name, unsigned int *idx, TC_HANDLE_T handl
end = handle->chain_index_sz;
pos = end / 2;
- debug("bsearch Find chain:%s (pos:%d end:%d)\n", name, pos, end);
+ debug("bsearch Find chain:%s (pos:%d end:%d) (offset:%d)\n",
+ name, pos, end, offset);
/* Loop */
loop:
@@ -341,13 +358,32 @@ iptcc_bsearch_chain_index(const char *name, unsigned int *idx, TC_HANDLE_T handl
return &handle->chains; /* Be safe, return orig start pos */
}
- res = strcmp(name, handle->chain_index[pos]->name);
+ debug("bsearch Index[%d] name:%s ",
+ pos, handle->chain_index[pos]->name);
+
+ /* Support for different compare functions */
+ switch (type) {
+ case BSEARCH_NAME:
+ res = strcmp(name, handle->chain_index[pos]->name);
+ break;
+ case BSEARCH_OFFSET:
+ debug("head_offset:[%d] foot_offset:[%d] ",
+ handle->chain_index[pos]->head_offset,
+ handle->chain_index[pos]->foot_offset);
+ res = offset - handle->chain_index[pos]->head_offset;
+ break;
+ default:
+ fprintf(stderr, "ERROR: %d not a valid bsearch type\n",
+ type);
+ abort();
+ break;
+ }
+ debug("res:%d ", res);
+
+
list_pos = &handle->chain_index[pos]->list;
*idx = pos;
- debug("bsearch Index[%d] name:%s res:%d ",
- pos, handle->chain_index[pos]->name, res);
-
if (res == 0) { /* Found element, by direct hit */
debug("[found] Direct hit pos:%d end:%d\n", pos, end);
return list_pos;
@@ -371,7 +407,15 @@ iptcc_bsearch_chain_index(const char *name, unsigned int *idx, TC_HANDLE_T handl
}
/* Exit case: Next index less, thus elem in this list section */
- res = strcmp(name, handle->chain_index[pos+1]->name);
+ switch (type) {
+ case BSEARCH_NAME:
+ res = strcmp(name, handle->chain_index[pos+1]->name);
+ break;
+ case BSEARCH_OFFSET:
+ res = offset - handle->chain_index[pos+1]->head_offset;
+ break;
+ }
+
if (res < 0) {
debug("[found] closest list (end:%d)\n", end);
return list_pos;
@@ -385,6 +429,34 @@ iptcc_bsearch_chain_index(const char *name, unsigned int *idx, TC_HANDLE_T handl
return list_pos;
}
+/* Wrapper for string chain name based bsearch */
+static struct list_head *
+iptcc_bsearch_chain_index(const char *name, unsigned int *idx,
+ TC_HANDLE_T handle)
+{
+ return __iptcc_bsearch_chain_index(name, 0, idx, handle, BSEARCH_NAME);
+}
+
+
+/* Wrapper for offset chain based bsearch */
+static struct list_head *
+iptcc_bsearch_chain_offset(unsigned int offset, unsigned int *idx,
+ TC_HANDLE_T handle)
+{
+ struct list_head *pos;
+
+ /* If chains were not received sorted from kernel, then the
+ * offset bsearch is not possible.
+ */
+ if (!handle->sorted_offsets)
+ pos = handle->chains.next;
+ else
+ pos = __iptcc_bsearch_chain_index(NULL, offset, idx, handle,
+ BSEARCH_OFFSET);
+ return pos;
+}
+
+
#ifdef DEBUG
/* Trivial linear search of chain index. Function used for verifying
the output of bsearch function */
@@ -612,14 +684,28 @@ static struct chain_head *
iptcc_find_chain_by_offset(TC_HANDLE_T handle, unsigned int offset)
{
struct list_head *pos;
+ struct list_head *list_start_pos;
+ unsigned int i;
if (list_empty(&handle->chains))
return NULL;
- list_for_each(pos, &handle->chains) {
+ /* Find a smart place to start the search */
+ list_start_pos = iptcc_bsearch_chain_offset(offset, &i, handle);
+
+ /* Note that iptcc_bsearch_chain_offset() skips builtin
+ * chains, but this function is only used for finding jump
+ * targets, and a buildin chain is not a valid jump target */
+
+ debug("Offset:[%u] starting search at index:[%u]\n", offset, i);
+// list_for_each(pos, &handle->chains) {
+ list_for_each(pos, list_start_pos->prev) {
struct chain_head *c = list_entry(pos, struct chain_head, list);
- if (offset >= c->head_offset && offset <= c->foot_offset)
+ debug(".");
+ if (offset >= c->head_offset && offset <= c->foot_offset) {
+ debug("Offset search found chain:[%s]\n", c->name);
return c;
+ }
}
return NULL;
@@ -819,10 +905,22 @@ static void __iptcc_p_add_chain(TC_HANDLE_T h, struct chain_head *c,
list_add_tail(&c->list, &h->chains);
else {
ctail = list_entry(tail, struct chain_head, list);
- if (strcmp(c->name, ctail->name) > 0)
+
+ if (strcmp(c->name, ctail->name) > 0 ||
+ iptcc_is_builtin(ctail))
list_add_tail(&c->list, &h->chains);/* Already sorted*/
- else
+ else {
iptc_insert_chain(h, c);/* Was not sorted */
+
+ /* Notice, if chains were not received sorted
+ * from kernel, then an offset bsearch is no
+ * longer valid.
+ */
+ h->sorted_offsets = 0;
+
+ debug("NOTICE: chain:[%s] was NOT sorted(ctail:%s)\n",
+ c->name, ctail->name);
+ }
}
h->chain_iterator_cur = c;
@@ -946,6 +1044,10 @@ static int parse_table(TC_HANDLE_T h)
unsigned int num = 0;
struct chain_head *c;
+ /* Assume that chains offsets are sorted, this verified during
+ parsing of ruleset (in __iptcc_p_add_chain())*/
+ h->sorted_offsets = 1;
+
/* First pass: over ruleset blob */
ENTRY_ITERATE(h->entries->entrytable, h->entries->size,
cache_add_entry, h, &prev, &num);
diff --git a/release.sh b/release.sh
index e27c1217..30f3931e 100644
--- a/release.sh
+++ b/release.sh
@@ -2,29 +2,30 @@
#
set -e
-VERSION=1.4.1.1
-PREV_VERSION=1.4.1
+VERSION=1.4.2-rc1
+PREV_VERSION=1.4.1.1
TMPDIR=/tmp/ipt-release
IPTDIR="$TMPDIR/iptables-$VERSION"
-PATCH=patch-iptables-$PREV_VERSION-$VERSION.bz2
-TARBALL=iptables-$VERSION.tar.bz2
-CHANGELOG=changes-iptables-$PREV_VERSION-$VERSION
+PATCH="patch-iptables-$PREV_VERSION-$VERSION.bz2";
+TARBALL="iptables-$VERSION.tar.bz2";
+CHANGELOG="changes-iptables-$PREV_VERSION-$VERSION.txt";
mkdir -p "$TMPDIR"
-git shortlog v$PREV_VERSION..v$VERSION > "$TMPDIR/$CHANGELOG"
-git diff v$PREV_VERSION..v$VERSION | bzip2 > "$TMPDIR/$PATCH"
-git archive --prefix=iptables-$VERSION/ v$VERSION | tar -xC "$TMPDIR/"
+git shortlog "v$PREV_VERSION..v$VERSION" > "$TMPDIR/$CHANGELOG"
+git diff "v$PREV_VERSION..v$VERSION" | bzip2 > "$TMPDIR/$PATCH"
+git archive --prefix="iptables-$VERSION/" "v$VERSION" | tar -xC "$TMPDIR/"
cd "$IPTDIR" && {
sh autogen.sh
- rm autogen.sh COMMIT_NOTES
cd ..
}
-tar -cjf $TARBALL iptables-$VERSION
-gpg -u "Netfilter Core Team" -sb $TARBALL
-md5sum $TARBALL > $TARBALL.md5sum
+tar -cjf "$TARBALL" "iptables-$VERSION";
+gpg -u "Netfilter Core Team" -sb "$TARBALL";
+md5sum "$TARBALL" >"$TARBALL.md5sum";
+sha1sum "$TARBALL" >"$TARBALL.sha1sum";
-gpg -u "Netfilter Core Team" -sb $PATCH
-md5sum $PATCH > $PATCH.md5sum
+gpg -u "Netfilter Core Team" -sb "$PATCH";
+md5sum "$PATCH" >"$PATCH.md5sum";
+sha1sum "$PATCH" >"$PATCH.sha1sum";