Annotation of Gnu-Mach/linux/src/include/net/route.h, revision 1.1

1.1     ! root        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, <[email protected]>
        !            11:  *             Fred N. van Kempen, <[email protected]>
        !            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:  *              Elliot Poger    :       Added support for SO_BINDTODEVICE.
        !            17:  *             Wolfgang Walter,
        !            18:  *             Daniel Ryde,
        !            19:  *             Ingo Molinar    :       fixed bug in ip_rt_put introduced
        !            20:  *                                     by SO_BINDTODEVICE support causing
        !            21:  *                                     a memory leak
        !            22:  *
        !            23:  *     FIXME:
        !            24:  *             Make atomic ops more generic and hide them in asm/...
        !            25:  *
        !            26:  *             This program is free software; you can redistribute it and/or
        !            27:  *             modify it under the terms of the GNU General Public License
        !            28:  *             as published by the Free Software Foundation; either version
        !            29:  *             2 of the License, or (at your option) any later version.
        !            30:  */
        !            31: #ifndef _ROUTE_H
        !            32: #define _ROUTE_H
        !            33: 
        !            34: #include <linux/config.h>
        !            35: 
        !            36: /*
        !            37:  * 0 - no debugging messages
        !            38:  * 1 - rare events and bugs situations (default)
        !            39:  * 2 - trace mode.
        !            40:  */
        !            41: #define RT_CACHE_DEBUG         0
        !            42: 
        !            43: #define RT_HASH_DIVISOR                256
        !            44: #define RT_CACHE_SIZE_MAX      256
        !            45: 
        !            46: #define RTZ_HASH_DIVISOR       256
        !            47: 
        !            48: #if RT_CACHE_DEBUG >= 2
        !            49: #define RTZ_HASHING_LIMIT 0
        !            50: #else
        !            51: #define RTZ_HASHING_LIMIT 16
        !            52: #endif
        !            53: 
        !            54: /*
        !            55:  * Maximal time to live for unused entry.
        !            56:  */
        !            57: #define RT_CACHE_TIMEOUT               (HZ*300)
        !            58: 
        !            59: /*
        !            60:  * Prevents LRU trashing, entries considered equivalent,
        !            61:  * if the difference between last use times is less then this number.
        !            62:  */
        !            63: #define RT_CACHE_BUBBLE_THRESHOLD      (HZ*5)
        !            64: 
        !            65: #include <linux/route.h>
        !            66: 
        !            67: #ifdef __KERNEL__
        !            68: #define RTF_LOCAL 0x8000
        !            69: #endif
        !            70: 
        !            71: struct rtable 
        !            72: {
        !            73:        struct rtable           *rt_next;
        !            74:        __u32                   rt_dst;
        !            75:        __u32                   rt_src;
        !            76:        __u32                   rt_gateway;
        !            77:        atomic_t                rt_refcnt;
        !            78:        atomic_t                rt_use;
        !            79:        unsigned long           rt_window;
        !            80:        atomic_t                rt_lastuse;
        !            81:        struct hh_cache         *rt_hh;
        !            82:        struct device           *rt_dev;
        !            83:        unsigned short          rt_flags;
        !            84:        unsigned short          rt_mtu;
        !            85:        unsigned short          rt_irtt;
        !            86:        unsigned char           rt_tos;
        !            87: };
        !            88: 
        !            89: extern void            ip_rt_flush(struct device *dev);
        !            90: extern void            ip_rt_update(int event, struct device *dev);
        !            91: extern void            ip_rt_redirect(__u32 src, __u32 dst, __u32 gw, struct device *dev);
        !            92: extern struct rtable   *ip_rt_slow_route(__u32 daddr, int local, struct device *dev);
        !            93: extern struct device   *ip_rt_dev(__u32 addr);
        !            94: extern int             rt_get_info(char * buffer, char **start, off_t offset, int length, int dummy);
        !            95: extern int             rt_cache_get_info(char *buffer, char **start, off_t offset, int length, int dummy);
        !            96: extern int             ip_rt_ioctl(unsigned int cmd, void *arg);
        !            97: extern int             ip_rt_new(struct rtentry *rt);
        !            98: extern int             ip_rt_kill(struct rtentry *rt);
        !            99: extern void            ip_rt_check_expire(void);
        !           100: extern void            ip_rt_advice(struct rtable **rp, int advice);
        !           101: 
        !           102: extern void            ip_rt_run_bh(void);
        !           103: extern atomic_t                ip_rt_lock;
        !           104: extern unsigned                ip_rt_bh_mask;
        !           105: extern struct rtable   *ip_rt_hash_table[RT_HASH_DIVISOR];
        !           106: extern void            rt_free(struct rtable * rt);
        !           107: 
        !           108: extern __inline__ void ip_rt_fast_lock(void)
        !           109: {
        !           110:        atomic_inc(&ip_rt_lock);
        !           111: }
        !           112: 
        !           113: extern __inline__ void ip_rt_fast_unlock(void)
        !           114: {
        !           115:        atomic_dec(&ip_rt_lock);
        !           116: }
        !           117: 
        !           118: extern __inline__ void ip_rt_unlock(void)
        !           119: {
        !           120:        if (atomic_dec_and_test(&ip_rt_lock) && ip_rt_bh_mask)
        !           121:                ip_rt_run_bh();
        !           122: }
        !           123: 
        !           124: extern __inline__ unsigned ip_rt_hash_code(__u32 addr)
        !           125: {
        !           126:        unsigned tmp = addr + (addr>>16);
        !           127:        return (tmp + (tmp>>8)) & 0xFF;
        !           128: }
        !           129: 
        !           130: 
        !           131: extern __inline__ void ip_rt_put(struct rtable * rt)
        !           132: #ifndef MODULE
        !           133: {
        !           134:        /* If this rtable entry is not in the cache, we'd better free
        !           135:         * it once the refcnt goes to zero, because nobody else will.
        !           136:         */
        !           137:        if (rt&&atomic_dec_and_test(&rt->rt_refcnt)&&(rt->rt_flags&RTF_NOTCACHED))
        !           138:                rt_free(rt);
        !           139: }
        !           140: #else
        !           141: ;
        !           142: #endif
        !           143: 
        !           144: #ifdef CONFIG_KERNELD
        !           145: extern struct rtable * ip_rt_route(__u32 daddr, int local, struct device *dev);
        !           146: #else
        !           147: extern __inline__ struct rtable * ip_rt_route(__u32 daddr, int local, struct device *dev)
        !           148: #ifndef MODULE
        !           149: {
        !           150:        struct rtable * rth;
        !           151: 
        !           152:        ip_rt_fast_lock();
        !           153: 
        !           154:        for (rth=ip_rt_hash_table[ip_rt_hash_code(daddr)^local]; rth; rth=rth->rt_next)
        !           155:        {
        !           156:                /* If an interface is specified, make sure this route points to it. */
        !           157:                if ( (rth->rt_dst == daddr) && ((dev==NULL) || (dev==rth->rt_dev)) )
        !           158:                {
        !           159:                        rth->rt_lastuse = jiffies;
        !           160:                        atomic_inc(&rth->rt_use);
        !           161:                        atomic_inc(&rth->rt_refcnt);
        !           162:                        ip_rt_unlock();
        !           163:                        return rth;
        !           164:                }
        !           165:        }
        !           166:        return ip_rt_slow_route (daddr, local, dev);
        !           167: }
        !           168: #else
        !           169: ;
        !           170: #endif
        !           171: #endif
        !           172: 
        !           173: extern __inline__ struct rtable * ip_check_route(struct rtable ** rp, __u32 daddr, 
        !           174:                                                 int local, struct device *dev)
        !           175: {
        !           176:        struct rtable * rt = *rp;
        !           177: 
        !           178:        if (!rt || rt->rt_dst != daddr || !(rt->rt_flags&RTF_UP) || (dev!=NULL)
        !           179:            || ((local==1)^((rt->rt_flags&RTF_LOCAL) != 0)))
        !           180:        {
        !           181:                ip_rt_put(rt);
        !           182:                rt = ip_rt_route(daddr, local, dev);
        !           183:                *rp = rt;
        !           184:        }
        !           185:        return rt;
        !           186: }      
        !           187: 
        !           188: 
        !           189: #endif /* _ROUTE_H */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.