]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - net/ipv6/route.c
[NETLINK]: Do precise netlink message allocations where possible
[net-next-2.6.git] / net / ipv6 / route.c
index c953466b7afdbde3c77e6494c3f24a46908d9097..a6472cb9054cb8193874ca7d4b03420e7e360c82 100644 (file)
@@ -330,6 +330,8 @@ static int inline rt6_check_neigh(struct rt6_info *rt)
                read_lock_bh(&neigh->lock);
                if (neigh->nud_state & NUD_VALID)
                        m = 2;
+               else if (!(neigh->nud_state & NUD_FAILED))
+                       m = 1;
                read_unlock_bh(&neigh->lock);
        }
        return m;
@@ -347,9 +349,7 @@ static int rt6_score_route(struct rt6_info *rt, int oif,
        m |= IPV6_DECODE_PREF(IPV6_EXTRACT_PREF(rt->rt6i_flags)) << 2;
 #endif
        n = rt6_check_neigh(rt);
-       if (n > 1)
-               m |= 16;
-       else if (!n && strict & RT6_LOOKUP_F_REACHABLE)
+       if (!n && (strict & RT6_LOOKUP_F_REACHABLE))
                return -1;
        return m;
 }
@@ -380,10 +380,11 @@ static struct rt6_info *rt6_select(struct rt6_info **head, int oif,
                        continue;
 
                if (m > mpri) {
-                       rt6_probe(match);
+                       if (strict & RT6_LOOKUP_F_REACHABLE)
+                               rt6_probe(match);
                        match = rt;
                        mpri = m;
-               } else {
+               } else if (strict & RT6_LOOKUP_F_REACHABLE) {
                        rt6_probe(rt);
                }
        }
@@ -636,7 +637,7 @@ static struct rt6_info *ip6_pol_route_input(struct fib6_table *table,
        int strict = 0;
        int attempts = 3;
        int err;
-       int reachable = RT6_LOOKUP_F_REACHABLE;
+       int reachable = ipv6_devconf.forwarding ? 0 : RT6_LOOKUP_F_REACHABLE;
 
        strict |= flags & RT6_LOOKUP_F_IFACE;
 
@@ -710,12 +711,10 @@ void ip6_route_input(struct sk_buff *skb)
                        .ip6_u = {
                                .daddr = iph->daddr,
                                .saddr = iph->saddr,
-#ifdef CONFIG_IPV6_ROUTE_FWMARK
-                               .fwmark = skb->nfmark,
-#endif
-                               .flowlabel = (* (u32 *) iph)&IPV6_FLOWINFO_MASK,
+                               .flowlabel = (* (__be32 *) iph)&IPV6_FLOWINFO_MASK,
                        },
                },
+               .mark = skb->mark,
                .proto = iph->nexthdr,
        };
 
@@ -733,7 +732,7 @@ static struct rt6_info *ip6_pol_route_output(struct fib6_table *table,
        int strict = 0;
        int attempts = 3;
        int err;
-       int reachable = RT6_LOOKUP_F_REACHABLE;
+       int reachable = ipv6_devconf.forwarding ? 0 : RT6_LOOKUP_F_REACHABLE;
 
        strict |= flags & RT6_LOOKUP_F_IFACE;
 
@@ -941,7 +940,7 @@ struct dst_entry *ndisc_dst_alloc(struct net_device *dev,
        fib6_force_start_gc();
 
 out:
-       return (struct dst_entry *)rt;
+       return &rt->u.dst;
 }
 
 int ndisc_dst_gc(int *more)
@@ -1224,7 +1223,7 @@ out:
        if (idev)
                in6_dev_put(idev);
        if (rt)
-               dst_free((struct dst_entry *) rt);
+               dst_free(&rt->u.dst);
        return err;
 }
 
@@ -1750,9 +1749,9 @@ static inline int ip6_pkt_drop(struct sk_buff *skb, int code)
 {
        int type = ipv6_addr_type(&skb->nh.ipv6h->daddr);
        if (type == IPV6_ADDR_ANY || type == IPV6_ADDR_RESERVED)
-               IP6_INC_STATS(IPSTATS_MIB_INADDRERRORS);
+               IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_INADDRERRORS);
 
-       IP6_INC_STATS(IPSTATS_MIB_OUTNOROUTES);
+       IP6_INC_STATS(ip6_dst_idev(skb->dst), IPSTATS_MIB_OUTNOROUTES);
        icmpv6_send(skb, ICMPV6_DEST_UNREACH, code, 0, skb->dev);
        kfree_skb(skb);
        return 0;
@@ -1823,7 +1822,7 @@ struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
                rt->rt6i_flags |= RTF_LOCAL;
        rt->rt6i_nexthop = ndisc_get_neigh(rt->rt6i_dev, &rt->rt6i_gateway);
        if (rt->rt6i_nexthop == NULL) {
-               dst_free((struct dst_entry *) rt);
+               dst_free(&rt->u.dst);
                return ERR_PTR(-ENOMEM);
        }
 
@@ -2007,6 +2006,20 @@ int inet6_rtm_newroute(struct sk_buff *skb, struct nlmsghdr* nlh, void *arg)
        return ip6_route_add(&cfg);
 }
 
+static inline size_t rt6_nlmsg_size(void)
+{
+       return NLMSG_ALIGN(sizeof(struct rtmsg))
+              + nla_total_size(16) /* RTA_SRC */
+              + nla_total_size(16) /* RTA_DST */
+              + nla_total_size(16) /* RTA_GATEWAY */
+              + nla_total_size(16) /* RTA_PREFSRC */
+              + nla_total_size(4) /* RTA_TABLE */
+              + nla_total_size(4) /* RTA_IIF */
+              + nla_total_size(4) /* RTA_OIF */
+              + nla_total_size(4) /* RTA_PRIORITY */
+              + nla_total_size(sizeof(struct rta_cacheinfo));
+}
+
 static int rt6_fill_node(struct sk_buff *skb, struct rt6_info *rt,
                         struct in6_addr *dst, struct in6_addr *src,
                         int iif, int type, u32 pid, u32 seq,
@@ -2201,7 +2214,6 @@ void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info)
        struct sk_buff *skb;
        u32 pid = 0, seq = 0;
        struct nlmsghdr *nlh = NULL;
-       int payload = sizeof(struct rtmsg) + 256;
        int err = -ENOBUFS;
 
        if (info) {
@@ -2211,15 +2223,13 @@ void inet6_rt_notify(int event, struct rt6_info *rt, struct nl_info *info)
                        seq = nlh->nlmsg_seq;
        }
 
-       skb = nlmsg_new(nlmsg_total_size(payload), gfp_any());
+       skb = nlmsg_new(rt6_nlmsg_size(), gfp_any());
        if (skb == NULL)
                goto errout;
 
        err = rt6_fill_node(skb, rt, NULL, NULL, 0, event, pid, seq, 0, 0);
-       if (err < 0) {
-               kfree_skb(skb);
-               goto errout;
-       }
+       /* failure implies BUG in rt6_nlmsg_size() */
+       BUG_ON(err < 0);
 
        err = rtnl_notify(skb, pid, RTNLGRP_IPV6_ROUTE, nlh, gfp_any());
 errout:
@@ -2247,7 +2257,6 @@ struct rt6_proc_arg
 static int rt6_info_route(struct rt6_info *rt, void *p_arg)
 {
        struct rt6_proc_arg *arg = (struct rt6_proc_arg *) p_arg;
-       int i;
 
        if (arg->skip < arg->offset / RT6_INFO_LEN) {
                arg->skip++;
@@ -2257,38 +2266,28 @@ static int rt6_info_route(struct rt6_info *rt, void *p_arg)
        if (arg->len >= arg->length)
                return 0;
 
-       for (i=0; i<16; i++) {
-               sprintf(arg->buffer + arg->len, "%02x",
-                       rt->rt6i_dst.addr.s6_addr[i]);
-               arg->len += 2;
-       }
-       arg->len += sprintf(arg->buffer + arg->len, " %02x ",
+       arg->len += sprintf(arg->buffer + arg->len,
+                           NIP6_SEQFMT " %02x ",
+                           NIP6(rt->rt6i_dst.addr),
                            rt->rt6i_dst.plen);
 
 #ifdef CONFIG_IPV6_SUBTREES
-       for (i=0; i<16; i++) {
-               sprintf(arg->buffer + arg->len, "%02x",
-                       rt->rt6i_src.addr.s6_addr[i]);
-               arg->len += 2;
-       }
-       arg->len += sprintf(arg->buffer + arg->len, " %02x ",
+       arg->len += sprintf(arg->buffer + arg->len,
+                           NIP6_SEQFMT " %02x ",
+                           NIP6(rt->rt6i_src.addr),
                            rt->rt6i_src.plen);
 #else
-       sprintf(arg->buffer + arg->len,
-               "00000000000000000000000000000000 00 ");
-       arg->len += 36;
+       arg->len += sprintf(arg->buffer + arg->len,
+                           "00000000000000000000000000000000 00 ");
 #endif
 
        if (rt->rt6i_nexthop) {
-               for (i=0; i<16; i++) {
-                       sprintf(arg->buffer + arg->len, "%02x",
-                               rt->rt6i_nexthop->primary_key[i]);
-                       arg->len += 2;
-               }
+               arg->len += sprintf(arg->buffer + arg->len,
+                                   NIP6_SEQFMT,
+                                   NIP6(*((struct in6_addr *)rt->rt6i_nexthop->primary_key)));
        } else {
-               sprintf(arg->buffer + arg->len,
-                       "00000000000000000000000000000000");
-               arg->len += 32;
+               arg->len += sprintf(arg->buffer + arg->len,
+                                   "00000000000000000000000000000000");
        }
        arg->len += sprintf(arg->buffer + arg->len,
                            " %08x %08x %08x %08x %8s\n",