From: Jan Engelhardt <jengelh@medozas.de>
To: netfilter-devel@vger.kernel.org
Cc: kaber@trash.net
Subject: [PATCH 14/56] netfilter: xtables2: table traversal
Date: Tue, 29 Jun 2010 10:42:54 +0200 [thread overview]
Message-ID: <1277801017-30600-15-git-send-email-jengelh@medozas.de> (raw)
In-Reply-To: <1277801017-30600-1-git-send-email-jengelh@medozas.de>
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
include/linux/netfilter/x_tables.h | 5 ++
net/netfilter/x_tables.c | 115 ++++++++++++++++++++++++++++++++++++
2 files changed, 120 insertions(+), 0 deletions(-)
diff --git a/include/linux/netfilter/x_tables.h b/include/linux/netfilter/x_tables.h
index fcca7a6..a90b758 100644
--- a/include/linux/netfilter/x_tables.h
+++ b/include/linux/netfilter/x_tables.h
@@ -708,6 +708,11 @@ extern int xt2_table_register(struct net *, struct xt2_table *);
extern struct xt2_table *xt2_table_replace(struct net *, struct xt2_table *);
extern void xt2_table_destroy(struct net *, struct xt2_table *);
+extern unsigned int xt2_do_table(struct sk_buff *, unsigned int,
+ const struct net_device *,
+ const struct net_device *,
+ const struct xt2_table *);
+
static inline bool xt2_special_target(const struct xt_target *t)
{
/*
diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index c820bdc..f63587a 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -56,6 +56,17 @@ struct xt_af {
static struct xt_af *xt;
+/***
+ * xt2 internal decisions -
+ *
+ * %XT_START_CHAIN: used to implement jump/goto after chain got switched
+ */
+enum {
+ XT_START_CHAIN = 0xFFFFFFF9,
+ /* XT_RETURN = 0xFFFFFFFB, */ /* reminder (x_tables.h) */
+ /* XT_CONTINUE = 0xFFFFFFFF, */ /* reminder (x_tables.h) */
+};
+
static const char *const xt_prefix[NFPROTO_NUMPROTO] = {
[NFPROTO_UNSPEC] = "x",
[NFPROTO_IPV4] = "ip",
@@ -1649,6 +1660,7 @@ struct xt2_table *xt2_table_replace(struct net *net, struct xt2_table *table)
{
struct xt2_table_link *link;
struct xt2_table *old_table;
+ int ret;
if (*table->name == '\0')
return ERR_PTR(-EINVAL);
@@ -1657,6 +1669,11 @@ struct xt2_table *xt2_table_replace(struct net *net, struct xt2_table *table)
XT2_KEEP_RCULOCK);
if (link == NULL)
return ERR_PTR(-ENOENT);
+ ret = xt2_jumpstack_alloc(table);
+ if (ret < 0) {
+ rcu_read_unlock();
+ return ERR_PTR(ret);
+ }
mutex_lock(&net->xt2.table_lock);
old_table = rcu_dereference(link->table);
@@ -1710,6 +1727,104 @@ void xt2_table_destroy(struct net *net, struct xt2_table *table)
}
EXPORT_SYMBOL_GPL(xt2_table_destroy);
+static unsigned int
+xt2_do_actions(struct sk_buff *skb, struct xt_action_param *acpar,
+ const struct xt2_rule *rule, const struct xt2_chain **chain_ptr,
+ unsigned int *stackptr, unsigned int stacksize,
+ const struct xt2_rule **jumpstack)
+{
+ const struct xt2_entry_target *etarget;
+ const struct xt2_entry_match *ematch;
+ /* For rules without targets: */
+ unsigned int verdict = XT_CONTINUE;
+ bool ret;
+
+ list_for_each_entry(ematch, &rule->match_list, anchor) {
+ acpar->match = ematch->ext;
+ acpar->matchinfo = ematch->data;
+ ret = ematch->ext->match(skb, acpar);
+ if (acpar->hotdrop)
+ return NF_DROP;
+ else if (!ret)
+ return XT_CONTINUE;
+ }
+
+ list_for_each_entry(etarget, &rule->target_list, anchor) {
+ if (etarget->ext == XT2_ACTION_GOTO) {
+ *chain_ptr = etarget->r_goto;
+ return XT_START_CHAIN;
+ } else if (etarget->ext == XT2_ACTION_JUMP) {
+ if (*stackptr >= stacksize)
+ return NF_DROP;
+ jumpstack[(*stackptr)++] = rule;
+ *chain_ptr = etarget->r_jump;
+ return XT_START_CHAIN;
+ } else if (etarget->ext == XT2_FINAL_VERDICT) {
+ verdict = etarget->verdict;
+ } else {
+ acpar->target = etarget->ext;
+ acpar->targinfo = etarget->data;
+ verdict = etarget->ext->target(skb, acpar);
+ }
+ if (verdict != XT_CONTINUE)
+ break;
+ }
+
+ return verdict;
+}
+
+unsigned int
+xt2_do_table(struct sk_buff *skb, unsigned int hook,
+ const struct net_device *in, const struct net_device *out,
+ const struct xt2_table *table)
+{
+ unsigned int cpu = smp_processor_id();
+ const struct xt2_rule **jumpstack = table->jumpstack[cpu];
+ unsigned int *stackptr = per_cpu_ptr(table->stackptr, cpu);
+ unsigned int verdict = NF_DROP;
+ const struct xt2_chain *chain;
+ const struct xt2_rule *rule;
+ struct xt_action_param acpar = {
+ .family = table->nfproto,
+ .in = in,
+ .out = out,
+ .hooknum = hook,
+ };
+
+ chain = table->entrypoint[hook];
+ do_chain:
+ rule = list_first_entry(&chain->rule_list, typeof(*rule), anchor);
+ do_rule:
+ if (&rule->anchor == &chain->rule_list)
+ /* End of chain */
+ verdict = XT_RETURN;
+ else
+ verdict = xt2_do_actions(skb, &acpar, rule, &chain, stackptr,
+ table->stacksize, jumpstack);
+
+ switch (verdict) {
+ case XT_START_CHAIN:
+ goto do_chain;
+ case XT_RETURN:
+ if (*stackptr == 0) {
+ rule = table->underflow[hook];
+ chain = rule->chain;
+ goto do_rule;
+ }
+ /* What was on the stack was where we left... */
+ --*stackptr;
+ rule = jumpstack[*stackptr];
+ chain = rule->chain;
+ /* ...fallthru to advance */
+ case XT_CONTINUE:
+ rule = list_entry(rule->anchor.next, typeof(*rule), anchor);
+ goto do_rule;
+ }
+
+ return verdict;
+}
+EXPORT_SYMBOL_GPL(xt2_do_table);
+
int xt_proto_init(struct net *net, u_int8_t af)
{
#ifdef CONFIG_PROC_FS
--
1.7.1
next prev parent reply other threads:[~2010-06-29 8:43 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-29 8:42 xt2 table core Jan Engelhardt
2010-06-29 8:42 ` [PATCH 01/56] netfilter: ebtables: simplify a device in/out check Jan Engelhardt
2010-06-29 8:42 ` [PATCH 02/56] netfilter: ebtables: change ebt_basic_match to xt convention Jan Engelhardt
2010-06-29 8:42 ` [PATCH 03/56] netfilter: xtables: move functions around Jan Engelhardt
2010-06-29 8:42 ` [PATCH 04/56] netfilter: xtables: convert basic nfproto match functions into xt matches Jan Engelhardt
2010-06-29 8:42 ` [PATCH 05/56] netfilter: xtables2: initial table skeletal functions Jan Engelhardt
2010-06-29 8:42 ` [PATCH 06/56] netfilter: xtables2: initial chain " Jan Engelhardt
2010-06-29 8:42 ` [PATCH 07/56] netfilter: xtables2: initial rule " Jan Engelhardt
2010-06-29 8:42 ` [PATCH 08/56] netfilter: xtables: alternate size checking in xt_check_match Jan Engelhardt
2010-06-29 8:42 ` [PATCH 09/56] netfilter: xtables: alternate size checking in xt_check_target Jan Engelhardt
2010-06-29 8:42 ` [PATCH 10/56] netfilter: xtables2: per-rule match skeletal functions Jan Engelhardt
2010-06-29 8:42 ` [PATCH 11/56] netfilter: xtables2: per-rule target " Jan Engelhardt
2010-06-29 8:42 ` [PATCH 12/56] netfilter: xtables2: xt_check_target in combination with xt2 contexts Jan Engelhardt
2010-06-29 8:42 ` [PATCH 13/56] netfilter: xtables2: jumpstack (de)allocation functions Jan Engelhardt
2010-06-29 8:42 ` Jan Engelhardt [this message]
2010-06-29 8:42 ` [PATCH 15/56] netfilter: xtables: add xt_quota revision 3 Jan Engelhardt
2010-06-29 8:42 ` [PATCH 16/56] netfilter: xtables2: make a copy of the ipv6_filter table Jan Engelhardt
2010-06-29 8:42 ` [PATCH 17/56] netfilter: xtables2: initial xt1->xt2 translation for tables Jan Engelhardt
2010-06-29 8:42 ` [PATCH 18/56] netfilter: xtables2: xt2->xt1 translation - GET_INFO support Jan Engelhardt
2010-06-29 8:42 ` [PATCH 19/56] netfilter: xtables2: xt2->xt1 translation - GET_ENTRIES support Jan Engelhardt
2010-06-29 8:43 ` [PATCH 20/56] netfilter: xtables2: xt1->xt2 translation - SET_REPLACE support Jan Engelhardt
2010-06-29 8:43 ` [PATCH 21/56] netfilter: xtables2: return counters after SET_REPLACE Jan Engelhardt
2010-06-29 8:43 ` [PATCH 22/56] netfilter: xtables2: xt1->xt2 translation - ADD_COUNTERS support Jan Engelhardt
2010-06-29 8:43 ` [PATCH 23/56] netfilter: xtables2: xt2->xt1 translation - compat GET_INFO support Jan Engelhardt
2010-06-29 8:43 ` [PATCH 24/56] netfilter: ip6tables: move mark_chains to xt1_perproto.c Jan Engelhardt
2010-06-29 8:43 ` [PATCH 25/56] netfilter: xtables2: xt2<->xt1 translation - compat GET_ENTRIES/SET_REPLACE support Jan Engelhardt
2010-06-29 8:43 ` [PATCH 26/56] netfilter: xtables2: compat->normal match data translation Jan Engelhardt
2010-06-29 8:43 ` [PATCH 27/56] netfilter: xtables2: compat->normal target " Jan Engelhardt
2010-06-29 8:43 ` [PATCH 28/56] netfilter: xtables2: outsource code into xts_match_to_xt1 function Jan Engelhardt
2010-06-29 8:43 ` [PATCH 29/56] netfilter: xtables2: normal->compat match data translation Jan Engelhardt
2010-06-29 8:43 ` [PATCH 30/56] netfilter: xtables2: normal->compat target " Jan Engelhardt
2010-06-29 8:43 ` [PATCH 31/56] netfilter: xtables2: packet tracing Jan Engelhardt
2010-06-29 8:43 ` [PATCH 32/56] netfilter: xtables: turn procfs entries to walk xt2 table list Jan Engelhardt
2010-06-29 8:43 ` [PATCH 33/56] netfilter: xtables2: switch ip6's tables to the xt2 table format Jan Engelhardt
2010-06-29 8:47 ` xt2 table core [*/33, not */56] Jan Engelhardt
2010-07-02 3:32 ` xt2 table core Simon Lodal
2010-07-04 13:56 ` Jan Engelhardt
2010-07-04 17:22 ` Simon Lodal
2010-07-04 18:00 ` Jan Engelhardt
2010-07-05 8:55 ` Patrick McHardy
2010-07-05 9:13 ` Jan Engelhardt
2010-07-05 9:15 ` Patrick McHardy
2010-07-05 9:36 ` Eric Dumazet
2010-07-05 9:42 ` Jan Engelhardt
2010-07-05 10:22 ` Eric Dumazet
2010-07-05 10:34 ` Jan Engelhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1277801017-30600-15-git-send-email-jengelh@medozas.de \
--to=jengelh@medozas.de \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).