Loading...
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | /*
* INET An implementation of the TCP/IP protocol suite for the LINUX
* operating system. INET is implemented using the BSD Socket
* interface as the means of communication with the user level.
*
* Definitions for the IP router.
*
* Version: @(#)route.h 1.0.4 05/27/93
*
* Authors: Ross Biro, <bir7@leland.Stanford.Edu>
* Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
* Fixes:
* Alan Cox : Reformatted. Added ip_rt_local()
* Alan Cox : Support for TCP parameters.
* Alexey Kuznetsov: Major changes for new routing code.
*
* FIXME:
* Modules stuff is broken at the moment.
* Make atomic ops more generic and hide them in asm/...
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#ifndef _ROUTE_H
#define _ROUTE_H
#include <linux/config.h>
/*
* 0 - no debugging messages
* 1 - rare events and bugs situations (default)
* 2 - trace mode.
*/
#define RT_CACHE_DEBUG 1
#define RT_HASH_DIVISOR 256
#define RT_CACHE_SIZE_MAX 256
#define RTZ_HASH_DIVISOR 256
#if RT_CACHE_DEBUG >= 2
#define RTZ_HASHING_LIMIT 0
#else
#define RTZ_HASHING_LIMIT 16
#endif
/*
* Maximal time to live for unused entry.
*/
#define RT_CACHE_TIMEOUT (HZ*300)
/*
* Prevents LRU trashing, entries considered equivalent,
* if the difference between last use times is less then this number.
*/
#define RT_CACHE_BUBBLE_THRESHOULD (HZ*5)
#include <linux/route.h>
#ifdef __KERNEL__
#define RTF_LOCAL 0x8000
#endif
/*
* Semaphores.
*/
#if defined(__alpha__)
static __inline__ void ATOMIC_INCR(unsigned int * addr)
{
unsigned tmp;
__asm__ __volatile__(
"1:\n\
ldl_l %1,%2\n\
addl %1,1,%1\n\
stl_c %1,%0\n\
beq %1,1b\n"
: "m=" (*addr), "r=&" (tmp)
: "m"(*addr));
}
static __inline__ void ATOMIC_DECR(unsigned int * addr)
{
unsigned tmp;
__asm__ __volatile__(
"1:\n\
ldl_l %1,%2\n\
subl %1,1,%1\n\
stl_c %1,%0\n\
beq %1,1b\n"
: "m=" (*addr), "r=&" (tmp)
: "m"(*addr));
}
static __inline__ int ATOMIC_DECR_AND_CHECK (unsigned int * addr)
{
unsigned tmp;
int result;
__asm__ __volatile__(
"1:\n\
ldl_l %1,%3\n\
subl %1,1,%1\n\
mov %1,%2\n\
stl_c %1,%0\n\
beq %1,1b\n"
: "m=" (*addr), "r=&" (tmp), "r=&"(result)
: "m"(*addr));
return result;
}
#elif defined(__i386__)
#include <asm/bitops.h>
extern __inline__ void ATOMIC_INCR(void * addr)
{
__asm__ __volatile__(
"incl %0"
:"=m" (ADDR));
}
extern __inline__ void ATOMIC_DECR(void * addr)
{
__asm__ __volatile__(
"decl %0"
:"=m" (ADDR));
}
/*
* It is DECR that is ATOMIC, not CHECK!
* If you want to do atomic checks, use cli()/sti(). --ANK
*/
extern __inline__ unsigned long ATOMIC_DECR_AND_CHECK(void * addr)
{
unsigned long retval;
__asm__ __volatile__(
"decl %0\nmovl %0,%1"
: "=m" (ADDR), "=r"(retval));
return retval;
}
#else
static __inline__ void ATOMIC_INCR(unsigned int * addr)
{
(*(__volatile__ unsigned int*)addr)++;
}
static __inline__ void ATOMIC_DECR(unsigned int * addr)
{
(*(__volatile__ unsigned int*)addr)--;
}
static __inline__ int ATOMIC_DECR_AND_CHECK (unsigned int * addr)
{
ATOMIC_DECR(addr);
return *(volatile unsigned int*)addr;
}
#endif
struct rtable
{
struct rtable *rt_next;
__u32 rt_dst;
__u32 rt_src;
__u32 rt_gateway;
unsigned rt_refcnt;
unsigned rt_use;
unsigned long rt_window;
unsigned long rt_lastuse;
struct hh_cache *rt_hh;
struct device *rt_dev;
unsigned short rt_flags;
unsigned short rt_mtu;
unsigned short rt_irtt;
unsigned char rt_tos;
};
extern void ip_rt_flush(struct device *dev);
extern void ip_rt_redirect(__u32 src, __u32 dst, __u32 gw, struct device *dev);
extern struct rtable *ip_rt_slow_route(__u32 daddr, int local);
extern int rt_get_info(char * buffer, char **start, off_t offset, int length, int dummy);
extern int rt_cache_get_info(char *buffer, char **start, off_t offset, int length, int dummy);
extern int ip_rt_ioctl(unsigned int cmd, void *arg);
extern int ip_rt_new(struct rtentry *rt);
extern int ip_rt_kill(struct rtentry *rt);
extern void ip_rt_check_expire(void);
extern void ip_rt_advice(struct rtable **rp, int advice);
extern void ip_rt_run_bh(void);
extern int ip_rt_lock;
extern unsigned ip_rt_bh_mask;
extern struct rtable *ip_rt_hash_table[RT_HASH_DIVISOR];
extern __inline__ void ip_rt_fast_lock(void)
{
ATOMIC_INCR(&ip_rt_lock);
}
extern __inline__ void ip_rt_fast_unlock(void)
{
ATOMIC_DECR(&ip_rt_lock);
}
extern __inline__ void ip_rt_unlock(void)
{
if (!ATOMIC_DECR_AND_CHECK(&ip_rt_lock) && ip_rt_bh_mask)
ip_rt_run_bh();
}
extern __inline__ unsigned ip_rt_hash_code(__u32 addr)
{
unsigned tmp = addr + (addr>>16);
return (tmp + (tmp>>8)) & 0xFF;
}
extern __inline__ void ip_rt_put(struct rtable * rt)
#ifndef MODULE
{
if (rt)
ATOMIC_DECR(&rt->rt_refcnt);
}
#else
;
#endif
#ifdef CONFIG_KERNELD
extern struct rtable * ip_rt_route(__u32 daddr, int local);
#else
extern __inline__ struct rtable * ip_rt_route(__u32 daddr, int local)
#ifndef MODULE
{
struct rtable * rth;
ip_rt_fast_lock();
for (rth=ip_rt_hash_table[ip_rt_hash_code(daddr)^local]; rth; rth=rth->rt_next)
{
if (rth->rt_dst == daddr)
{
rth->rt_lastuse = jiffies;
ATOMIC_INCR(&rth->rt_use);
ATOMIC_INCR(&rth->rt_refcnt);
ip_rt_unlock();
return rth;
}
}
return ip_rt_slow_route (daddr, local);
}
#else
;
#endif
#endif
extern __inline__ struct rtable * ip_check_route(struct rtable ** rp,
__u32 daddr, int local)
{
struct rtable * rt = *rp;
if (!rt || rt->rt_dst != daddr || !(rt->rt_flags&RTF_UP)
|| ((local==1)^((rt->rt_flags&RTF_LOCAL) != 0)))
{
ip_rt_put(rt);
rt = ip_rt_route(daddr, local);
*rp = rt;
}
return rt;
}
#endif /* _ROUTE_H */
|