more debug output
[linux-2.4.git] / include / net / dst.h
1 /*
2  * net/dst.h    Protocol independent destination cache definitions.
3  *
4  * Authors:     Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
5  *
6  */
7
8 #ifndef _NET_DST_H
9 #define _NET_DST_H
10
11 #include <linux/config.h>
12 #include <net/neighbour.h>
13
14 /*
15  * 0 - no debugging messages
16  * 1 - rare events and bugs (default)
17  * 2 - trace mode.
18  */
19 #define RT_CACHE_DEBUG          0
20
21 #define DST_GC_MIN      (HZ/10)
22 #define DST_GC_INC      (HZ/2)
23 #define DST_GC_MAX      (120*HZ)
24
25 struct sk_buff;
26
27 struct dst_entry
28 {
29         struct dst_entry        *next;
30         atomic_t                __refcnt;       /* client references    */
31         int                     __use;
32         struct net_device       *dev;
33         int                     obsolete;
34         int                     flags;
35 #define DST_HOST                1
36         unsigned long           lastuse;
37         unsigned long           expires;
38
39         unsigned                mxlock;
40         unsigned                pmtu;
41         unsigned                window;
42         unsigned                rtt;
43         unsigned                rttvar;
44         unsigned                ssthresh;
45         unsigned                cwnd;
46         unsigned                advmss;
47         unsigned                reordering;
48
49         unsigned long           rate_last;      /* rate limiting for ICMP */
50         unsigned long           rate_tokens;
51
52         int                     error;
53
54         struct neighbour        *neighbour;
55         struct hh_cache         *hh;
56
57         int                     (*input)(struct sk_buff*);
58         int                     (*output)(struct sk_buff*);
59
60 #ifdef CONFIG_NET_CLS_ROUTE
61         __u32                   tclassid;
62 #endif
63
64         struct  dst_ops         *ops;
65                 
66         char                    info[0];
67 };
68
69
70 struct dst_ops
71 {
72         unsigned short          family;
73         unsigned short          protocol;
74         unsigned                gc_thresh;
75
76         int                     (*gc)(void);
77         struct dst_entry *      (*check)(struct dst_entry *, __u32 cookie);
78         struct dst_entry *      (*reroute)(struct dst_entry *,
79                                            struct sk_buff *);
80         void                    (*destroy)(struct dst_entry *);
81         struct dst_entry *      (*negative_advice)(struct dst_entry *);
82         void                    (*link_failure)(struct sk_buff *);
83         int                     entry_size;
84
85         atomic_t                entries;
86         kmem_cache_t            *kmem_cachep;
87 };
88
89 #ifdef __KERNEL__
90
91 static inline void dst_hold(struct dst_entry * dst)
92 {
93         atomic_inc(&dst->__refcnt);
94 }
95
96 static inline
97 struct dst_entry * dst_clone(struct dst_entry * dst)
98 {
99         if (dst)
100                 atomic_inc(&dst->__refcnt);
101         return dst;
102 }
103
104 static inline
105 void dst_release(struct dst_entry * dst)
106 {
107         if (dst) {
108                 smp_mb__before_atomic_dec();
109                 atomic_dec(&dst->__refcnt);
110         }
111 }
112
113 extern void * dst_alloc(struct dst_ops * ops);
114 extern void __dst_free(struct dst_entry * dst);
115 extern void dst_destroy(struct dst_entry * dst);
116
117 static inline
118 void dst_free(struct dst_entry * dst)
119 {
120         if (dst->obsolete > 1)
121                 return;
122         if (!atomic_read(&dst->__refcnt)) {
123                 dst_destroy(dst);
124                 return;
125         }
126         __dst_free(dst);
127 }
128
129 static inline void dst_confirm(struct dst_entry *dst)
130 {
131         if (dst)
132                 neigh_confirm(dst->neighbour);
133 }
134
135 static inline void dst_negative_advice(struct dst_entry **dst_p)
136 {
137         struct dst_entry * dst = *dst_p;
138         if (dst && dst->ops->negative_advice)
139                 *dst_p = dst->ops->negative_advice(dst);
140 }
141
142 static inline void dst_link_failure(struct sk_buff *skb)
143 {
144         struct dst_entry * dst = skb->dst;
145         if (dst && dst->ops && dst->ops->link_failure)
146                 dst->ops->link_failure(skb);
147 }
148
149 static inline void dst_set_expires(struct dst_entry *dst, int timeout)
150 {
151         unsigned long expires = jiffies + timeout;
152
153         if (expires == 0)
154                 expires = 1;
155
156         if (dst->expires == 0 || (long)(dst->expires - expires) > 0)
157                 dst->expires = expires;
158 }
159
160 extern void             dst_init(void);
161
162 #endif
163
164 #endif /* _NET_DST_H */