[PATCH 1/3] [NET] fib_rules: goto rule action

2007-03-26 Thread Thomas Graf
This patch adds a new rule action FR_ACT_GOTO which allows
to skip a set of rules by jumping to another rule. The rule
to jump to is specified via the FRA_GOTO attribute which
carries a rule preference.

Referring to a rule which doesn't exists is explicitely allowed.
Such goto rules are marked with the flag FIB_RULE_UNRESOLVED
and will act like a rule with a non-matching selector. The rule
will become functional as soon as its target is present.

The goto action enables performance optimizations by reducing
the average number of rules that have to be passed per lookup.

Example:
0:  from all lookup local 
40: not from all to 192.168.23.128 goto 32766
41: from all fwmark 0xa blackhole
42: from all fwmark 0xff blackhole
32766:  from all lookup main 

Signed-off-by: Thomas Graf [EMAIL PROTECTED]

Index: net-2.6.22/include/linux/fib_rules.h
===
--- net-2.6.22.orig/include/linux/fib_rules.h   2007-03-26 13:07:41.0 
+0200
+++ net-2.6.22/include/linux/fib_rules.h2007-03-27 01:43:14.0 
+0200
@@ -7,6 +7,7 @@
 /* rule is permanent, and cannot be deleted */
 #define FIB_RULE_PERMANENT 1
 #define FIB_RULE_INVERT2
+#define FIB_RULE_UNRESOLVED4
 
 struct fib_rule_hdr
 {
@@ -29,7 +30,7 @@ enum
FRA_DST,/* destination address */
FRA_SRC,/* source address */
FRA_IFNAME, /* interface name */
-   FRA_UNUSED1,
+   FRA_GOTO,   /* target to jump to (FR_ACT_GOTO) */
FRA_UNUSED2,
FRA_PRIORITY,   /* priority/preference */
FRA_UNUSED3,
@@ -51,7 +52,7 @@ enum
 {
FR_ACT_UNSPEC,
FR_ACT_TO_TBL,  /* Pass to fixed table */
-   FR_ACT_RES1,
+   FR_ACT_GOTO,/* Jump to another rule */
FR_ACT_RES2,
FR_ACT_RES3,
FR_ACT_RES4,
Index: net-2.6.22/include/net/fib_rules.h
===
--- net-2.6.22.orig/include/net/fib_rules.h 2007-03-26 13:07:41.0 
+0200
+++ net-2.6.22/include/net/fib_rules.h  2007-03-26 13:40:32.0 +0200
@@ -19,6 +19,8 @@ struct fib_rule
u32 flags;
u32 table;
u8  action;
+   u32 target;
+   struct fib_rule *   ctarget;
struct rcu_head rcu;
 };
 
@@ -35,6 +37,8 @@ struct fib_rules_ops
struct list_headlist;
int rule_size;
int addr_size;
+   int unresolved_rules;
+   int nr_goto_rules;
 
int (*action)(struct fib_rule *,
  struct flowi *, int,
@@ -66,7 +70,8 @@ struct fib_rules_ops
[FRA_PRIORITY]  = { .type = NLA_U32 }, \
[FRA_FWMARK]= { .type = NLA_U32 }, \
[FRA_FWMASK]= { .type = NLA_U32 }, \
-   [FRA_TABLE] = { .type = NLA_U32 }
+   [FRA_TABLE] = { .type = NLA_U32 }, \
+   [FRA_GOTO]  = { .type = NLA_U32 }
 
 static inline void fib_rule_get(struct fib_rule *rule)
 {
Index: net-2.6.22/net/core/fib_rules.c
===
--- net-2.6.22.orig/net/core/fib_rules.c2007-03-26 13:07:41.0 
+0200
+++ net-2.6.22/net/core/fib_rules.c 2007-03-27 01:43:39.0 +0200
@@ -132,10 +132,23 @@ int fib_rules_lookup(struct fib_rules_op
rcu_read_lock();
 
list_for_each_entry_rcu(rule, ops-rules_list, list) {
+jumped:
if (!fib_rule_match(rule, ops, fl, flags))
continue;
 
-   err = ops-action(rule, fl, flags, arg);
+   if (rule-action == FR_ACT_GOTO) {
+   struct fib_rule *target;
+
+   target = rcu_dereference(rule-ctarget);
+   if (target == NULL) {
+   continue;
+   } else {
+   rule = target;
+   goto jumped;
+   }
+   } else
+   err = ops-action(rule, fl, flags, arg);
+
if (err != -EAGAIN) {
fib_rule_get(rule);
arg-rule = rule;
@@ -180,7 +193,7 @@ static int fib_nl_newrule(struct sk_buff
struct fib_rules_ops *ops = NULL;
struct fib_rule *rule, *r, *last = NULL;
struct nlattr *tb[FRA_MAX+1];
-   int err = -EINVAL;
+   int err = -EINVAL, unresolved = 0;
 
if (nlh-nlmsg_len  nlmsg_msg_size(sizeof(*frh)))
goto errout;
@@ -237,6 +250,28 @@ static int fib_nl_newrule(struct sk_buff
if (!rule-pref  ops-default_pref)
rule-pref = ops-default_pref();
 
+   err = -EINVAL;
+   if (tb[FRA_GOTO]) {
+   if (rule-action != 

Re: [PATCH 1/3] [NET] fib_rules: goto rule action

2007-03-26 Thread David Miller
From: Thomas Graf [EMAIL PROTECTED]
Date: Tue, 27 Mar 2007 01:54:51 +0200

 This patch adds a new rule action FR_ACT_GOTO which allows
 to skip a set of rules by jumping to another rule. The rule
 to jump to is specified via the FRA_GOTO attribute which
 carries a rule preference.
 
 Referring to a rule which doesn't exists is explicitely allowed.
 Such goto rules are marked with the flag FIB_RULE_UNRESOLVED
 and will act like a rule with a non-matching selector. The rule
 will become functional as soon as its target is present.
 
 The goto action enables performance optimizations by reducing
 the average number of rules that have to be passed per lookup.
 
 Example:
 0:  from all lookup local 
 40: not from all to 192.168.23.128 goto 32766
 41: from all fwmark 0xa blackhole
 42: from all fwmark 0xff blackhole
 32766:  from all lookup main 
 
 Signed-off-by: Thomas Graf [EMAIL PROTECTED]

This looks excellent, applied to net-2.6.22, thanks Thomas.
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3] [NET] fib_rules: goto rule action

2007-03-26 Thread Stephen Hemminger

David Miller wrote:

From: Thomas Graf [EMAIL PROTECTED]
Date: Tue, 27 Mar 2007 01:54:51 +0200

  

This patch adds a new rule action FR_ACT_GOTO which allows
to skip a set of rules by jumping to another rule. The rule
to jump to is specified via the FRA_GOTO attribute which
carries a rule preference.

Referring to a rule which doesn't exists is explicitely allowed.
Such goto rules are marked with the flag FIB_RULE_UNRESOLVED
and will act like a rule with a non-matching selector. The rule
will become functional as soon as its target is present.

The goto action enables performance optimizations by reducing
the average number of rules that have to be passed per lookup.

Example:
0:  from all lookup local 
40: not from all to 192.168.23.128 goto 32766

41: from all fwmark 0xa blackhole
42: from all fwmark 0xff blackhole
32766:  from all lookup main 


Signed-off-by: Thomas Graf [EMAIL PROTECTED]



This looks excellent, applied to net-2.6.22, thanks Thomas.
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
  


Do we have to worry about self inflicted infinite loops?
Shouldn't there be some way to some basic validation?

-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3] [NET] fib_rules: goto rule action

2007-03-26 Thread David Miller
From: Stephen Hemminger [EMAIL PROTECTED]
Date: Mon, 26 Mar 2007 21:13:07 -0700

 Do we have to worry about self inflicted infinite loops?
 Shouldn't there be some way to some basic validation?

We do, and there is.  You obviously didn't read Thomas's patch.

He prevents loops by only allowing forward gotos.
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html