root/include/net/route.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. ATOMIC_INCR
  2. ATOMIC_DECR
  3. ATOMIC_DECR_AND_CHECK
  4. ATOMIC_INCR
  5. ATOMIC_DECR
  6. ATOMIC_DECR_AND_CHECK
  7. ATOMIC_INCR
  8. ATOMIC_DECR
  9. ATOMIC_DECR_AND_CHECK
  10. ip_rt_fast_lock
  11. ip_rt_fast_unlock
  12. ip_rt_unlock
  13. ip_rt_hash_code
  14. ip_rt_put
  15. ip_rt_route
  16. ip_check_route

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

/* [previous][next][first][last][top][bottom][index][help] */