]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/ipv6/fib6_rules.c
[NET] rules: Share common attribute validation policy
[net-next-2.6.git] / net / ipv6 / fib6_rules.c
index d8c1057e8b008520f2f9c3a8e21e6de1bd90f757..8377477b2c1931a1433c53b8a5917b04dd479219 100644 (file)
@@ -25,10 +25,6 @@ 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;
 };
 
@@ -117,32 +113,26 @@ 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))
+       if (r->dst.plen &&
+           !ipv6_prefix_equal(&fl->fl6_dst, &r->dst.addr, r->dst.plen))
                return 0;
 
-       if ((flags & RT6_LOOKUP_F_HAS_SADDR) &&
-           !ipv6_prefix_equal(&fl->fl6_src, &r->src.addr, r->src.plen))
-               return 0;
+       if (r->src.plen) {
+               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[FRA_MAX+1] __read_mostly = {
-       [FRA_IFNAME]    = { .type = NLA_STRING, .len = IFNAMSIZ - 1 },
-       [FRA_PRIORITY]  = { .type = NLA_U32 },
+       FRA_GENERIC_POLICY,
        [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,
@@ -174,23 +164,6 @@ 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;
@@ -222,14 +195,6 @@ 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;
 }
 
@@ -251,14 +216,6 @@ 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: