This source file includes following definitions.
- ip_rt_fast_lock
- ip_rt_fast_unlock
- ip_rt_unlock
- ip_rt_hash_code
- ip_rt_put
- ip_rt_route
- ip_check_route
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #ifndef _ROUTE_H
26 #define _ROUTE_H
27
28 #include <linux/config.h>
29
30
31
32
33
34
35 #define RT_CACHE_DEBUG 0
36
37 #define RT_HASH_DIVISOR 256
38 #define RT_CACHE_SIZE_MAX 256
39
40 #define RTZ_HASH_DIVISOR 256
41
42 #if RT_CACHE_DEBUG >= 2
43 #define RTZ_HASHING_LIMIT 0
44 #else
45 #define RTZ_HASHING_LIMIT 16
46 #endif
47
48
49
50
51 #define RT_CACHE_TIMEOUT (HZ*300)
52
53
54
55
56
57 #define RT_CACHE_BUBBLE_THRESHOLD (HZ*5)
58
59 #include <linux/route.h>
60
61 #ifdef __KERNEL__
62 #define RTF_LOCAL 0x8000
63 #endif
64
65 struct rtable
66 {
67 struct rtable *rt_next;
68 __u32 rt_dst;
69 __u32 rt_src;
70 __u32 rt_gateway;
71 atomic_t rt_refcnt;
72 atomic_t rt_use;
73 unsigned long rt_window;
74 atomic_t rt_lastuse;
75 struct hh_cache *rt_hh;
76 struct device *rt_dev;
77 unsigned short rt_flags;
78 unsigned short rt_mtu;
79 unsigned short rt_irtt;
80 unsigned char rt_tos;
81 };
82
83 extern void ip_rt_flush(struct device *dev);
84 extern void ip_rt_update(int event, struct device *dev);
85 extern void ip_rt_redirect(__u32 src, __u32 dst, __u32 gw, struct device *dev);
86 extern struct rtable *ip_rt_slow_route(__u32 daddr, int local);
87 extern int rt_get_info(char * buffer, char **start, off_t offset, int length, int dummy);
88 extern int rt_cache_get_info(char *buffer, char **start, off_t offset, int length, int dummy);
89 extern int ip_rt_ioctl(unsigned int cmd, void *arg);
90 extern int ip_rt_new(struct rtentry *rt);
91 extern int ip_rt_kill(struct rtentry *rt);
92 extern void ip_rt_check_expire(void);
93 extern void ip_rt_advice(struct rtable **rp, int advice);
94
95 extern void ip_rt_run_bh(void);
96 extern atomic_t ip_rt_lock;
97 extern unsigned ip_rt_bh_mask;
98 extern struct rtable *ip_rt_hash_table[RT_HASH_DIVISOR];
99
100 extern __inline__ void ip_rt_fast_lock(void)
101 {
102 atomic_inc(&ip_rt_lock);
103 }
104
105 extern __inline__ void ip_rt_fast_unlock(void)
106 {
107 atomic_dec(&ip_rt_lock);
108 }
109
110 extern __inline__ void ip_rt_unlock(void)
111 {
112 if (atomic_dec_and_test(&ip_rt_lock) && ip_rt_bh_mask)
113 ip_rt_run_bh();
114 }
115
116 extern __inline__ unsigned ip_rt_hash_code(__u32 addr)
117 {
118 unsigned tmp = addr + (addr>>16);
119 return (tmp + (tmp>>8)) & 0xFF;
120 }
121
122
123 extern __inline__ void ip_rt_put(struct rtable * rt)
124 #ifndef MODULE
125 {
126 if (rt)
127 atomic_dec(&rt->rt_refcnt);
128 }
129 #else
130 ;
131 #endif
132
133 #ifdef CONFIG_KERNELD
134 extern struct rtable * ip_rt_route(__u32 daddr, int local);
135 #else
136 extern __inline__ struct rtable * ip_rt_route(__u32 daddr, int local)
137 #ifndef MODULE
138 {
139 struct rtable * rth;
140
141 ip_rt_fast_lock();
142
143 for (rth=ip_rt_hash_table[ip_rt_hash_code(daddr)^local]; rth; rth=rth->rt_next)
144 {
145 if (rth->rt_dst == daddr)
146 {
147 rth->rt_lastuse = jiffies;
148 atomic_inc(&rth->rt_use);
149 atomic_inc(&rth->rt_refcnt);
150 ip_rt_unlock();
151 return rth;
152 }
153 }
154 return ip_rt_slow_route (daddr, local);
155 }
156 #else
157 ;
158 #endif
159 #endif
160
161 extern __inline__ struct rtable * ip_check_route(struct rtable ** rp,
162 __u32 daddr, int local)
163 {
164 struct rtable * rt = *rp;
165
166 if (!rt || rt->rt_dst != daddr || !(rt->rt_flags&RTF_UP)
167 || ((local==1)^((rt->rt_flags&RTF_LOCAL) != 0)))
168 {
169 ip_rt_put(rt);
170 rt = ip_rt_route(daddr, local);
171 *rp = rt;
172 }
173 return rt;
174 }
175
176
177 #endif