inetpeer.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * INETPEER - A storage for permanent information about peers
  3. *
  4. * Authors: Andrey V. Savochkin <saw@msu.ru>
  5. */
  6. #ifndef _NET_INETPEER_H
  7. #define _NET_INETPEER_H
  8. #include <linux/types.h>
  9. #include <linux/init.h>
  10. #include <linux/jiffies.h>
  11. #include <linux/spinlock.h>
  12. #include <asm/atomic.h>
  13. typedef struct {
  14. union {
  15. __be32 a4;
  16. __be32 a6[4];
  17. };
  18. __u16 family;
  19. } inet_peer_address_t;
  20. struct inet_peer {
  21. /* group together avl_left,avl_right,v4daddr to speedup lookups */
  22. struct inet_peer __rcu *avl_left, *avl_right;
  23. inet_peer_address_t daddr;
  24. __u32 avl_height;
  25. struct list_head unused;
  26. __u32 dtime; /* the time of last use of not
  27. * referenced entries */
  28. atomic_t refcnt;
  29. /*
  30. * Once inet_peer is queued for deletion (refcnt == -1), following fields
  31. * are not available: rid, ip_id_count, tcp_ts, tcp_ts_stamp
  32. * We can share memory with rcu_head to keep inet_peer small
  33. * (less then 64 bytes)
  34. */
  35. union {
  36. struct {
  37. atomic_t rid; /* Frag reception counter */
  38. atomic_t ip_id_count; /* IP ID for the next packet */
  39. __u32 tcp_ts;
  40. __u32 tcp_ts_stamp;
  41. };
  42. struct rcu_head rcu;
  43. };
  44. };
  45. void inet_initpeers(void) __init;
  46. /* can be called with or without local BH being disabled */
  47. struct inet_peer *inet_getpeer(__be32 daddr, int create);
  48. /* can be called from BH context or outside */
  49. extern void inet_putpeer(struct inet_peer *p);
  50. /*
  51. * temporary check to make sure we dont access rid, ip_id_count, tcp_ts,
  52. * tcp_ts_stamp if no refcount is taken on inet_peer
  53. */
  54. static inline void inet_peer_refcheck(const struct inet_peer *p)
  55. {
  56. WARN_ON_ONCE(atomic_read(&p->refcnt) <= 0);
  57. }
  58. /* can be called with or without local BH being disabled */
  59. static inline __u16 inet_getid(struct inet_peer *p, int more)
  60. {
  61. more++;
  62. inet_peer_refcheck(p);
  63. return atomic_add_return(more, &p->ip_id_count) - more;
  64. }
  65. #endif /* _NET_INETPEER_H */