Adds support for policy routing rules including a new
local table for routes with a local destination.
Signed-off-by: Thomas Graf [EMAIL PROTECTED]
Index: net-2.6.git/net/ipv6/fib6_rules.c
===
--- /dev/null
+++ net-2.6.git/net/ipv6/fib6_rules.c
@@ -0,0 +1,255 @@
+/*
+ * net/ipv6/fib6_rules.c IPv6 Routing Policy Rules
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ * Authors
+ * Ville Nuorvala [EMAIL PROTECTED]
+ * Thomas Graf [EMAIL PROTECTED]
+ */
+
+#include linux/config.h
+#include linux/netdevice.h
+
+#include net/fib_rules.h
+#include net/ipv6.h
+#include net/ip6_route.h
+#include net/netlink.h
+
+struct fib6_rule
+{
+ struct fib_rule common;
+ struct rt6key src;
+ struct rt6key dst;
+ u8 tclass;
+};
+
+static struct fib_rules_ops fib6_rules_ops;
+
+static struct fib6_rule main_rule = {
+ .common = {
+ .refcnt = ATOMIC_INIT(2),
+ .pref = 0x7FFE,
+ .action = FR_ACT_TO_TBL,
+ .table =RT6_TABLE_MAIN,
+ },
+};
+
+static struct fib6_rule local_rule = {
+ .common = {
+ .refcnt = ATOMIC_INIT(2),
+ .pref = 0,
+ .action = FR_ACT_TO_TBL,
+ .table =RT6_TABLE_LOCAL,
+ .flags =FIB_RULE_PERMANENT,
+ },
+};
+
+static LIST_HEAD(fib6_rules);
+
+struct dst_entry *fib6_rule_lookup(struct flowi *fl, int flags,
+ pol_lookup_t lookup)
+{
+ struct fib_lookup_arg arg = {
+ .lookup_ptr = lookup,
+ };
+
+ fib_rules_lookup(fib6_rules_ops, fl, flags, arg);
+ if (arg.rule)
+ fib_rule_put(arg.rule);
+
+ return (struct dst_entry *) arg.result;
+}
+
+int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
+int flags, struct fib_lookup_arg *arg)
+{
+ struct rt6_info *rt = NULL;
+ struct fib6_table *table;
+ pol_lookup_t lookup = arg-lookup_ptr;
+
+ switch (rule-action) {
+ case FR_ACT_TO_TBL:
+ break;
+ case FR_ACT_UNREACHABLE:
+ rt = ip6_null_entry;
+ goto discard_pkt;
+ default:
+ case FR_ACT_BLACKHOLE:
+ rt = ip6_blk_hole_entry;
+ goto discard_pkt;
+ case FR_ACT_PROHIBIT:
+ rt = ip6_prohibit_entry;
+ goto discard_pkt;
+ }
+
+ table = fib6_get_table(rule-table);
+ if (table)
+ rt = lookup(table, flp, flags);
+
+ if (rt != ip6_null_entry)
+ goto out;
+
+ dst_release(rt-u.dst);
+discard_pkt:
+ dst_hold(rt-u.dst);
+out:
+ arg-result = rt;
+ return rt == NULL ? -EAGAIN : 0;
+}
+
+
+static int fib6_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
+{
+ struct fib6_rule *r = (struct fib6_rule *) rule;
+
+ if (!ipv6_prefix_equal(fl-fl6_dst, r-dst.addr, r-dst.plen))
+ return 0;
+
+#ifdef CONFIG_IPV6_SUBTREES
+ if ((flags RT6_F_HAS_SADDR)
+ !ipv6_prefix_equal(fl-fl6_src, r-r_src.addr, r-r_src.plen))
+ return 0;
+#endif
+
+ return 1;
+}
+
+static struct nla_policy fib6_rule_policy[RTA_MAX+1] __read_mostly = {
+ [FRA_IFNAME]= { .type = NLA_STRING },
+ [FRA_PRIORITY] = { .type = NLA_U32 },
+ [FRA_SRC] = { .minlen = sizeof(struct in6_addr) },
+ [FRA_DST] = { .minlen = sizeof(struct in6_addr) },
+};
+
+static int fib6_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
+ struct nlmsghdr *nlh, struct fib_rule_hdr *frh,
+ struct nlattr **tb)
+{
+ int err = -EINVAL;
+ struct fib6_rule *rule6 = (struct fib6_rule *) rule;
+
+ if (frh-src_len 128 || frh-dst_len 128 ||
+ (frh-tos ~IPV6_FLOWINFO_MASK))
+ goto errout;
+
+#ifndef CONFIG_IPV6_SUBTREES
+ if (frh-src_len 0)
+ goto errout;
+#endif
+
+ if (rule-action == FR_ACT_TO_TBL) {
+ if (rule-table == RT6_TABLE_UNSPEC)
+ goto errout;
+
+ if (fib6_new_table(rule-table) == NULL) {
+ err = -ENOBUFS;
+ goto errout;
+ }
+ }
+
+ if (tb[FRA_SRC])
+ nla_memcpy(rule6-src.addr, tb[FRA_SRC],
+ sizeof(struct in6_addr));
+
+ if (tb[FRA_DST])
+ nla_memcpy(rule6-dst.addr, tb[FRA_DST],
+ sizeof(struct in6_addr));
+
+ rule6-src.plen = frh-src_len;
+ rule6-dst.plen =