root/include/net/route.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. ip_rt_fast_lock
  2. ip_rt_fast_unlock
  3. ip_rt_unlock
  4. ip_rt_hash_code
  5. ip_rt_put
  6. ip_rt_route
  7. 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  *              Make atomic ops more generic and hide them in asm/...
  19  *
  20  *              This program is free software; you can redistribute it and/or
  21  *              modify it under the terms of the GNU General Public License
  22  *              as published by the Free Software Foundation; either version
  23  *              2 of the License, or (at your option) any later version.
  24  */
  25 #ifndef _ROUTE_H
  26 #define _ROUTE_H
  27 
  28 #include <linux/config.h>
  29 
  30 /*
  31  * 0 - no debugging messages
  32  * 1 - rare events and bugs situations (default)
  33  * 2 - trace mode.
  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  * Maximal time to live for unused entry.
  50  */
  51 #define RT_CACHE_TIMEOUT                (HZ*300)
  52 
  53 /*
  54  * Prevents LRU trashing, entries considered equivalent,
  55  * if the difference between last use times is less then this number.
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
 101 {
 102         atomic_inc(&ip_rt_lock);
 103 }
 104 
 105 extern __inline__ void ip_rt_fast_unlock(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 106 {
 107         atomic_dec(&ip_rt_lock);
 108 }
 109 
 110 extern __inline__ void ip_rt_unlock(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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)
     /* [previous][next][first][last][top][bottom][index][help] */
 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,
     /* [previous][next][first][last][top][bottom][index][help] */
 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  /* _ROUTE_H */

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