inetpeer.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * INETPEER - A storage for permanent information about peers
  3. *
  4. * Version: $Id: inetpeer.h,v 1.2 2002/01/12 07:54:56 davem Exp $
  5. *
  6. * Authors: Andrey V. Savochkin <saw@msu.ru>
  7. */
  8. #ifndef _NET_INETPEER_H
  9. #define _NET_INETPEER_H
  10. #include <linux/types.h>
  11. #include <linux/init.h>
  12. #include <linux/jiffies.h>
  13. #include <linux/spinlock.h>
  14. #include <asm/atomic.h>
  15. struct inet_peer
  16. {
  17. struct inet_peer *avl_left, *avl_right;
  18. struct inet_peer *unused_next, **unused_prevp;
  19. unsigned long dtime; /* the time of last use of not
  20. * referenced entries */
  21. atomic_t refcnt;
  22. __u32 v4daddr; /* peer's address */
  23. __u16 avl_height;
  24. __u16 ip_id_count; /* IP ID for the next packet */
  25. __u32 tcp_ts;
  26. unsigned long tcp_ts_stamp;
  27. };
  28. void inet_initpeers(void) __init;
  29. /* can be called with or without local BH being disabled */
  30. struct inet_peer *inet_getpeer(__u32 daddr, int create);
  31. extern spinlock_t inet_peer_unused_lock;
  32. extern struct inet_peer **inet_peer_unused_tailp;
  33. /* can be called from BH context or outside */
  34. static inline void inet_putpeer(struct inet_peer *p)
  35. {
  36. spin_lock_bh(&inet_peer_unused_lock);
  37. if (atomic_dec_and_test(&p->refcnt)) {
  38. p->unused_prevp = inet_peer_unused_tailp;
  39. p->unused_next = NULL;
  40. *inet_peer_unused_tailp = p;
  41. inet_peer_unused_tailp = &p->unused_next;
  42. p->dtime = jiffies;
  43. }
  44. spin_unlock_bh(&inet_peer_unused_lock);
  45. }
  46. extern spinlock_t inet_peer_idlock;
  47. /* can be called with or without local BH being disabled */
  48. static inline __u16 inet_getid(struct inet_peer *p, int more)
  49. {
  50. __u16 id;
  51. spin_lock_bh(&inet_peer_idlock);
  52. id = p->ip_id_count;
  53. p->ip_id_count += 1 + more;
  54. spin_unlock_bh(&inet_peer_idlock);
  55. return id;
  56. }
  57. #endif /* _NET_INETPEER_H */