inetpeer.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. atomic_t rid; /* Frag reception counter */
  26. __u32 tcp_ts;
  27. unsigned long tcp_ts_stamp;
  28. };
  29. void inet_initpeers(void) __init;
  30. /* can be called with or without local BH being disabled */
  31. struct inet_peer *inet_getpeer(__u32 daddr, int create);
  32. extern spinlock_t inet_peer_unused_lock;
  33. extern struct inet_peer **inet_peer_unused_tailp;
  34. /* can be called from BH context or outside */
  35. static inline void inet_putpeer(struct inet_peer *p)
  36. {
  37. spin_lock_bh(&inet_peer_unused_lock);
  38. if (atomic_dec_and_test(&p->refcnt)) {
  39. p->unused_prevp = inet_peer_unused_tailp;
  40. p->unused_next = NULL;
  41. *inet_peer_unused_tailp = p;
  42. inet_peer_unused_tailp = &p->unused_next;
  43. p->dtime = jiffies;
  44. }
  45. spin_unlock_bh(&inet_peer_unused_lock);
  46. }
  47. extern spinlock_t inet_peer_idlock;
  48. /* can be called with or without local BH being disabled */
  49. static inline __u16 inet_getid(struct inet_peer *p, int more)
  50. {
  51. __u16 id;
  52. spin_lock_bh(&inet_peer_idlock);
  53. id = p->ip_id_count;
  54. p->ip_id_count += 1 + more;
  55. spin_unlock_bh(&inet_peer_idlock);
  56. return id;
  57. }
  58. #endif /* _NET_INETPEER_H */