]> Pileus Git - ~andy/linux/blobdiff - net/ipv6/fib6_rules.c
ipv6: fib6_rules should return exact return value
[~andy/linux] / net / ipv6 / fib6_rules.c
index 2e1a432867c0897f4e0d4439f9c6fd5d3f4c66cb..554a4fbabfb3b2dbf9ab4418e3b4c0683c0580d1 100644 (file)
@@ -55,26 +55,33 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
        struct fib6_table *table;
        struct net *net = rule->fr_net;
        pol_lookup_t lookup = arg->lookup_ptr;
+       int err = 0;
 
        switch (rule->action) {
        case FR_ACT_TO_TBL:
                break;
        case FR_ACT_UNREACHABLE:
+               err = -ENETUNREACH;
                rt = net->ipv6.ip6_null_entry;
                goto discard_pkt;
        default:
        case FR_ACT_BLACKHOLE:
+               err = -EINVAL;
                rt = net->ipv6.ip6_blk_hole_entry;
                goto discard_pkt;
        case FR_ACT_PROHIBIT:
+               err = -EACCES;
                rt = net->ipv6.ip6_prohibit_entry;
                goto discard_pkt;
        }
 
        table = fib6_get_table(net, rule->table);
-       if (table)
-               rt = lookup(net, table, flp6, flags);
+       if (!table) {
+               err = -EAGAIN;
+               goto out;
+       }
 
+       rt = lookup(net, table, flp6, flags);
        if (rt != net->ipv6.ip6_null_entry) {
                struct fib6_rule *r = (struct fib6_rule *)rule;
 
@@ -101,6 +108,7 @@ static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp,
        }
 again:
        ip6_rt_put(rt);
+       err = -EAGAIN;
        rt = NULL;
        goto out;
 
@@ -108,9 +116,21 @@ discard_pkt:
        dst_hold(&rt->dst);
 out:
        arg->result = rt;
-       return rt == NULL ? -EAGAIN : 0;
+       return err;
 }
 
+static bool fib6_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg)
+{
+       struct rt6_info *rt = (struct rt6_info *) arg->result;
+       /* do not accept result if the route does
+        * not meet the required prefix length
+        */
+       if (rt->rt6i_dst.plen < rule->table_prefixlen_min) {
+               ip6_rt_put(rt);
+               return true;
+       }
+       return false;
+}
 
 static int fib6_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
 {
@@ -244,6 +264,7 @@ static const struct fib_rules_ops __net_initconst fib6_rules_ops_template = {
        .addr_size              = sizeof(struct in6_addr),
        .action                 = fib6_rule_action,
        .match                  = fib6_rule_match,
+       .suppress               = fib6_rule_suppress,
        .configure              = fib6_rule_configure,
        .compare                = fib6_rule_compare,
        .fill                   = fib6_rule_fill,