00001 /* 00002 * INETPEER - A storage for permanent information about peers 00003 * 00004 * Version: $Id: inetpeer.h,v 1.1.2.1 2002/01/12 07:53:15 davem Exp $ 00005 * 00006 * Authors: Andrey V. Savochkin <saw@msu.ru> 00007 */ 00008 00009 #ifndef _NET_INETPEER_H 00010 #define _NET_INETPEER_H 00011 00012 #include <linux/types.h> 00013 #include <linux/init.h> 00014 #include <linux/sched.h> 00015 #include <linux/spinlock.h> 00016 #include <asm/atomic.h> 00017 00018 struct inet_peer 00019 { 00020 struct inet_peer *avl_left, *avl_right; 00021 struct inet_peer *unused_next, **unused_prevp; 00022 atomic_t refcnt; 00023 unsigned long dtime; /* the time of last use of not 00024 * referenced entries */ 00025 __u32 v4daddr; /* peer's address */ 00026 __u16 avl_height; 00027 __u16 ip_id_count; /* IP ID for the next packet */ 00028 __u32 tcp_ts; 00029 unsigned long tcp_ts_stamp; 00030 }; 00031 00032 void inet_initpeers(void) __init; 00033 00034 /* can be called with or without local BH being disabled */ 00035 struct inet_peer *inet_getpeer(__u32 daddr, int create); 00036 00037 extern spinlock_t inet_peer_unused_lock; 00038 extern struct inet_peer *inet_peer_unused_head; 00039 extern struct inet_peer **inet_peer_unused_tailp; 00040 /* can be called from BH context or outside */ 00041 static inline void inet_putpeer(struct inet_peer *p) 00042 { 00043 spin_lock_bh(&inet_peer_unused_lock); 00044 if (atomic_dec_and_test(&p->refcnt)) { 00045 p->unused_prevp = inet_peer_unused_tailp; 00046 p->unused_next = NULL; 00047 *inet_peer_unused_tailp = p; 00048 inet_peer_unused_tailp = &p->unused_next; 00049 p->dtime = jiffies; 00050 } 00051 spin_unlock_bh(&inet_peer_unused_lock); 00052 } 00053 00054 extern spinlock_t inet_peer_idlock; 00055 /* can be called with or without local BH being disabled */ 00056 static inline __u16 inet_getid(struct inet_peer *p) 00057 { 00058 __u16 id; 00059 00060 spin_lock_bh(&inet_peer_idlock); 00061 id = p->ip_id_count++; 00062 spin_unlock_bh(&inet_peer_idlock); 00063 return id; 00064 } 00065 00066 #endif /* _NET_INETPEER_H */
1.3.8