]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - net/ipv6/fib6_rules.c
[IPV6] ADDRCONF: Mobile IPv6 Home Address support.
[linux-2.6-omap-h63xx.git] / net / ipv6 / fib6_rules.c
index 94a46ec967a41a9bac8c428f4ff3b466263183c6..34f5bfaddfc293f20e890be4c9acc4db193a4fe9 100644 (file)
@@ -26,6 +26,10 @@ struct fib6_rule
        struct fib_rule         common;
        struct rt6key           src;
        struct rt6key           dst;
+#ifdef CONFIG_IPV6_ROUTE_FWMARK
+       u32                     fwmark;
+       u32                     fwmask;
+#endif
        u8                      tclass;
 };
 
@@ -63,11 +67,15 @@ struct dst_entry *fib6_rule_lookup(struct flowi *fl, int flags,
        if (arg.rule)
                fib_rule_put(arg.rule);
 
-       return (struct dst_entry *) arg.result;
+       if (arg.result)
+               return (struct dst_entry *) arg.result;
+
+       dst_hold(&ip6_null_entry.u.dst);
+       return &ip6_null_entry.u.dst;
 }
 
-int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
-                    int flags, struct fib_lookup_arg *arg)
+static 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;
@@ -113,18 +121,29 @@ static int fib6_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
        if (!ipv6_prefix_equal(&fl->fl6_dst, &r->dst.addr, r->dst.plen))
                return 0;
 
-       if ((flags & RT6_F_HAS_SADDR) &&
+       if ((flags & RT6_LOOKUP_F_HAS_SADDR) &&
            !ipv6_prefix_equal(&fl->fl6_src, &r->src.addr, r->src.plen))
                return 0;
 
+       if (r->tclass && r->tclass != ((ntohl(fl->fl6_flowlabel) >> 20) & 0xff))
+               return 0;
+
+#ifdef CONFIG_IPV6_ROUTE_FWMARK
+       if ((r->fwmark ^ fl->fl6_fwmark) & r->fwmask)
+               return 0;
+#endif
+
        return 1;
 }
 
-static struct nla_policy fib6_rule_policy[RTA_MAX+1] __read_mostly = {
-       [FRA_IFNAME]    = { .type = NLA_STRING },
+static struct nla_policy fib6_rule_policy[FRA_MAX+1] __read_mostly = {
+       [FRA_IFNAME]    = { .type = NLA_STRING, .len = IFNAMSIZ - 1 },
        [FRA_PRIORITY]  = { .type = NLA_U32 },
-       [FRA_SRC]       = { .minlen = sizeof(struct in6_addr) },
-       [FRA_DST]       = { .minlen = sizeof(struct in6_addr) },
+       [FRA_SRC]       = { .len = sizeof(struct in6_addr) },
+       [FRA_DST]       = { .len = sizeof(struct in6_addr) },
+       [FRA_FWMARK]    = { .type = NLA_U32 },
+       [FRA_FWMASK]    = { .type = NLA_U32 },
+       [FRA_TABLE]     = { .type = NLA_U32 },
 };
 
 static int fib6_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
@@ -156,6 +175,23 @@ static int fib6_rule_configure(struct fib_rule *rule, struct sk_buff *skb,
                nla_memcpy(&rule6->dst.addr, tb[FRA_DST],
                           sizeof(struct in6_addr));
 
+#ifdef CONFIG_IPV6_ROUTE_FWMARK
+       if (tb[FRA_FWMARK]) {
+               rule6->fwmark = nla_get_u32(tb[FRA_FWMARK]);
+               if (rule6->fwmark) {
+                       /*
+                        * if the mark value is non-zero,
+                        * all bits are compared by default
+                        * unless a mask is explicitly specified.
+                        */
+                       rule6->fwmask = 0xFFFFFFFF;
+               }
+       }
+
+       if (tb[FRA_FWMASK])
+               rule6->fwmask = nla_get_u32(tb[FRA_FWMASK]);
+#endif
+
        rule6->src.plen = frh->src_len;
        rule6->dst.plen = frh->dst_len;
        rule6->tclass = frh->tos;
@@ -187,6 +223,14 @@ static int fib6_rule_compare(struct fib_rule *rule, struct fib_rule_hdr *frh,
            nla_memcmp(tb[FRA_DST], &rule6->dst.addr, sizeof(struct in6_addr)))
                return 0;
 
+#ifdef CONFIG_IPV6_ROUTE_FWMARK
+       if (tb[FRA_FWMARK] && (rule6->fwmark != nla_get_u32(tb[FRA_FWMARK])))
+               return 0;
+
+       if (tb[FRA_FWMASK] && (rule6->fwmask != nla_get_u32(tb[FRA_FWMASK])))
+               return 0;
+#endif
+
        return 1;
 }
 
@@ -208,6 +252,14 @@ static int fib6_rule_fill(struct fib_rule *rule, struct sk_buff *skb,
                NLA_PUT(skb, FRA_SRC, sizeof(struct in6_addr),
                        &rule6->src.addr);
 
+#ifdef CONFIG_IPV6_ROUTE_FWMARK
+       if (rule6->fwmark)
+               NLA_PUT_U32(skb, FRA_FWMARK, rule6->fwmark);
+
+       if (rule6->fwmask || rule6->fwmark)
+               NLA_PUT_U32(skb, FRA_FWMASK, rule6->fwmask);
+#endif
+
        return 0;
 
 nla_put_failure: