ipv6: fix problem with expired dst cache
[linux-flexiantxendom0-3.2.10.git] / include / net / dst.h
index 15d67c8..ff4da42 100644 (file)
 #include <linux/netdevice.h>
 #include <linux/rtnetlink.h>
 #include <linux/rcupdate.h>
+#include <linux/bug.h>
 #include <linux/jiffies.h>
 #include <net/neighbour.h>
 #include <asm/processor.h>
 
-/*
- * 0 - no debugging messages
- * 1 - rare events and bugs (default)
- * 2 - trace mode.
- */
-#define RT_CACHE_DEBUG         0
-
 #define DST_GC_MIN     (HZ/10)
 #define DST_GC_INC     (HZ/2)
 #define DST_GC_MAX     (120*HZ)
@@ -42,10 +36,13 @@ struct dst_entry {
        struct net_device       *dev;
        struct  dst_ops         *ops;
        unsigned long           _metrics;
-       unsigned long           expires;
+       union {
+               unsigned long           expires;
+               /* point to where the dst_entry copied from */
+               struct dst_entry        *from;
+       };
        struct dst_entry        *path;
-       struct neighbour        *neighbour;
-       struct hh_cache         *hh;
+       struct neighbour __rcu  *_neighbour;
 #ifdef CONFIG_XFRM
        struct xfrm_state       *xfrm;
 #else
@@ -54,6 +51,15 @@ struct dst_entry {
        int                     (*input)(struct sk_buff*);
        int                     (*output)(struct sk_buff*);
 
+       int                     flags;
+#define DST_HOST               0x0001
+#define DST_NOXFRM             0x0002
+#define DST_NOPOLICY           0x0004
+#define DST_NOHASH             0x0008
+#define DST_NOCACHE            0x0010
+#define DST_NOCOUNT            0x0020
+#define DST_NOPEER             0x0040
+
        short                   error;
        short                   obsolete;
        unsigned short          header_len;     /* more space at head required */
@@ -69,7 +75,7 @@ struct dst_entry {
         * (L1_CACHE_SIZE would be too much)
         */
 #ifdef CONFIG_64BIT
-       long                    __pad_to_align_refcnt[1];
+       long                    __pad_to_align_refcnt[2];
 #endif
        /*
         * __refcnt wants to be on a different cache line from
@@ -78,12 +84,6 @@ struct dst_entry {
        atomic_t                __refcnt;       /* client references    */
        int                     __use;
        unsigned long           lastuse;
-       int                     flags;
-#define DST_HOST               0x0001
-#define DST_NOXFRM             0x0002
-#define DST_NOPOLICY           0x0004
-#define DST_NOHASH             0x0008
-#define DST_NOCACHE            0x0010
        union {
                struct dst_entry        *next;
                struct rtable __rcu     *rt_next;
@@ -92,7 +92,20 @@ struct dst_entry {
        };
 };
 
-#ifdef __KERNEL__
+static inline struct neighbour *dst_get_neighbour_noref(struct dst_entry *dst)
+{
+       return rcu_dereference(dst->_neighbour);
+}
+
+static inline struct neighbour *dst_get_neighbour_noref_raw(struct dst_entry *dst)
+{
+       return rcu_dereference_raw(dst->_neighbour);
+}
+
+static inline void dst_set_neighbour(struct dst_entry *dst, struct neighbour *neigh)
+{
+       rcu_assign_pointer(dst->_neighbour, neigh);
+}
 
 extern u32 *dst_cow_metrics_generic(struct dst_entry *dst, unsigned long old);
 extern const u32 dst_default_metrics[RTAX_MAX];
@@ -120,6 +133,8 @@ static inline u32 *dst_metrics_write_ptr(struct dst_entry *dst)
 {
        unsigned long p = dst->_metrics;
 
+       BUG_ON(!p);
+
        if (p & DST_METRICS_READ_ONLY)
                return dst->ops->cow_metrics(dst, p);
        return __DST_METRICS_PTR(p);
@@ -196,12 +211,7 @@ dst_feature(const struct dst_entry *dst, u32 feature)
 
 static inline u32 dst_mtu(const struct dst_entry *dst)
 {
-       u32 mtu = dst_metric_raw(dst, RTAX_MTU);
-
-       if (!mtu)
-               mtu = dst->ops->default_mtu(dst);
-
-       return mtu;
+       return dst->ops->mtu(dst);
 }
 
 /* RTT metrics are stored in milliseconds for user ABI, but used as jiffies */
@@ -316,7 +326,14 @@ static inline void skb_dst_force(struct sk_buff *skb)
 static inline void __skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev)
 {
        skb->dev = dev;
-       skb->rxhash = 0;
+
+       /*
+        * Clear rxhash so that we can recalulate the hash for the
+        * encapsulated packet, unless we have already determine the hash
+        * over the L4 4-tuple.
+        */
+       if (!skb->l4_rxhash)
+               skb->rxhash = 0;
        skb_set_queue_mapping(skb, 0);
        skb_dst_drop(skb);
        nf_reset(skb);
@@ -345,14 +362,15 @@ static inline void skb_tunnel_rx(struct sk_buff *skb, struct net_device *dev)
 
 static inline struct dst_entry *skb_dst_pop(struct sk_buff *skb)
 {
-       struct dst_entry *child = skb_dst(skb)->child;
+       struct dst_entry *child = dst_clone(skb_dst(skb)->child);
 
        skb_dst_drop(skb);
        return child;
 }
 
 extern int dst_discard(struct sk_buff *skb);
-extern void *dst_alloc(struct dst_ops * ops, int initial_ref);
+extern void *dst_alloc(struct dst_ops * ops, struct net_device *dev,
+                      int initial_ref, int initial_obsolete, int flags);
 extern void __dst_free(struct dst_entry * dst);
 extern struct dst_entry *dst_destroy(struct dst_entry * dst);
 
@@ -376,8 +394,19 @@ static inline void dst_rcu_free(struct rcu_head *head)
 
 static inline void dst_confirm(struct dst_entry *dst)
 {
-       if (dst)
-               neigh_confirm(dst->neighbour);
+       if (dst) {
+               struct neighbour *n;
+
+               rcu_read_lock();
+               n = dst_get_neighbour_noref(dst);
+               neigh_confirm(n);
+               rcu_read_unlock();
+       }
+}
+
+static inline struct neighbour *dst_neigh_lookup(const struct dst_entry *dst, const void *daddr)
+{
+       return dst->ops->neigh_lookup(dst, daddr);
 }
 
 static inline void dst_link_failure(struct sk_buff *skb)
@@ -426,24 +455,17 @@ enum {
 
 struct flowi;
 #ifndef CONFIG_XFRM
-static inline int xfrm_lookup(struct net *net, struct dst_entry **dst_p,
-                             const struct flowi *fl, struct sock *sk,
-                             int flags)
+static inline struct dst_entry *xfrm_lookup(struct net *net,
+                                           struct dst_entry *dst_orig,
+                                           const struct flowi *fl, struct sock *sk,
+                                           int flags)
 {
-       return 0;
+       return dst_orig;
 } 
-static inline int __xfrm_lookup(struct net *net, struct dst_entry **dst_p,
-                               const struct flowi *fl, struct sock *sk,
-                               int flags)
-{
-       return 0;
-}
 #else
-extern int xfrm_lookup(struct net *net, struct dst_entry **dst_p,
-                      const struct flowi *fl, struct sock *sk, int flags);
-extern int __xfrm_lookup(struct net *net, struct dst_entry **dst_p,
-                        const struct flowi *fl, struct sock *sk, int flags);
-#endif
+extern struct dst_entry *xfrm_lookup(struct net *net, struct dst_entry *dst_orig,
+                                    const struct flowi *fl, struct sock *sk,
+                                    int flags);
 #endif
 
 #endif /* _NET_DST_H */