Blame view

include/net/inetpeer.h 3.03 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
  /*
   *		INETPEER - A storage for permanent information about peers
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
7
8
9
10
11
12
13
   *  Authors:	Andrey V. Savochkin <saw@msu.ru>
   */
  
  #ifndef _NET_INETPEER_H
  #define _NET_INETPEER_H
  
  #include <linux/types.h>
  #include <linux/init.h>
  #include <linux/jiffies.h>
  #include <linux/spinlock.h>
606598237   David S. Miller   inetpeer: Add met...
14
  #include <linux/rtnetlink.h>
672f007d6   David S. Miller   inetpeer: Add ine...
15
  #include <net/ipv6.h>
60063497a   Arun Sharma   atomic: use <linu...
16
  #include <linux/atomic.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17

7a71ed899   David S. Miller   inetpeer: Abstrac...
18
  struct inetpeer_addr_base {
582a72da9   David S. Miller   inetpeer: Introdu...
19
  	union {
7a71ed899   David S. Miller   inetpeer: Abstrac...
20
21
  		__be32			a4;
  		__be32			a6[4];
582a72da9   David S. Miller   inetpeer: Introdu...
22
  	};
7a71ed899   David S. Miller   inetpeer: Abstrac...
23
24
25
26
27
  };
  
  struct inetpeer_addr {
  	struct inetpeer_addr_base	addr;
  	__u16				family;
8790ca172   David S. Miller   inetpeer: Kill us...
28
  };
582a72da9   David S. Miller   inetpeer: Introdu...
29

fd2c3ef76   Eric Dumazet   net: cleanup incl...
30
  struct inet_peer {
78d794231   Eric Dumazet   [IPV4] inet_peer:...
31
  	/* group together avl_left,avl_right,v4daddr to speedup lookups */
b914c4ea9   Eric Dumazet   inetpeer: __rcu a...
32
  	struct inet_peer __rcu	*avl_left, *avl_right;
8790ca172   David S. Miller   inetpeer: Kill us...
33
  	struct inetpeer_addr	daddr;
2c1409a0a   Eric Dumazet   inetpeer: Optimiz...
34
  	__u32			avl_height;
2b77bdde9   Eric Dumazet   inetpeer: lower f...
35
36
37
  
  	u32			metrics[RTAX_MAX];
  	u32			rate_tokens;	/* rate limiting for ICMP */
de68dca18   Eric Dumazet   inet: add a redir...
38
  	int			redirect_genid;
2b77bdde9   Eric Dumazet   inetpeer: lower f...
39
40
41
42
43
  	unsigned long		rate_last;
  	unsigned long		pmtu_expires;
  	u32			pmtu_orig;
  	u32			pmtu_learned;
  	struct inetpeer_addr_base redirect_learned;
317fe0e6c   Eric Dumazet   inetpeer: restore...
44
45
  	/*
  	 * Once inet_peer is queued for deletion (refcnt == -1), following fields
2b77bdde9   Eric Dumazet   inetpeer: lower f...
46
  	 * are not available: rid, ip_id_count, tcp_ts, tcp_ts_stamp
606598237   David S. Miller   inetpeer: Add met...
47
  	 * We can share memory with rcu_head to help keep inet_peer small.
317fe0e6c   Eric Dumazet   inetpeer: restore...
48
49
50
  	 */
  	union {
  		struct {
ddd4aa424   David S. Miller   inetpeer: Add red...
51
52
53
54
  			atomic_t			rid;		/* Frag reception counter */
  			atomic_t			ip_id_count;	/* IP ID for the next packet */
  			__u32				tcp_ts;
  			__u32				tcp_ts_stamp;
317fe0e6c   Eric Dumazet   inetpeer: restore...
55
56
  		};
  		struct rcu_head         rcu;
4b9d9be83   Eric Dumazet   inetpeer: remove ...
57
  		struct inet_peer	*gc_next;
317fe0e6c   Eric Dumazet   inetpeer: restore...
58
  	};
2b77bdde9   Eric Dumazet   inetpeer: lower f...
59
60
61
62
  
  	/* following fields might be frequently dirtied */
  	__u32			dtime;	/* the time of last use of not referenced entries */
  	atomic_t		refcnt;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
64
65
  };
  
  void			inet_initpeers(void) __init;
144001bdd   David S. Miller   inetpeer: Mark me...
66
67
68
69
70
71
  #define INETPEER_METRICS_NEW	(~(u32) 0)
  
  static inline bool inet_metrics_new(const struct inet_peer *p)
  {
  	return p->metrics[RTAX_LOCK-1] == INETPEER_METRICS_NEW;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
  /* can be called with or without local BH being disabled */
87c48fa3b   Eric Dumazet   ipv6: make fragme...
73
  struct inet_peer	*inet_getpeer(const struct inetpeer_addr *daddr, int create);
b534ecf1c   David S. Miller   inetpeer: Make in...
74
75
76
  
  static inline struct inet_peer *inet_getpeer_v4(__be32 v4daddr, int create)
  {
8790ca172   David S. Miller   inetpeer: Kill us...
77
  	struct inetpeer_addr daddr;
b534ecf1c   David S. Miller   inetpeer: Make in...
78

7a71ed899   David S. Miller   inetpeer: Abstrac...
79
  	daddr.addr.a4 = v4daddr;
b534ecf1c   David S. Miller   inetpeer: Make in...
80
81
82
  	daddr.family = AF_INET;
  	return inet_getpeer(&daddr, create);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83

b71d1d426   Eric Dumazet   inet: constify ip...
84
  static inline struct inet_peer *inet_getpeer_v6(const struct in6_addr *v6daddr, int create)
672f007d6   David S. Miller   inetpeer: Add ine...
85
  {
8790ca172   David S. Miller   inetpeer: Kill us...
86
  	struct inetpeer_addr daddr;
672f007d6   David S. Miller   inetpeer: Add ine...
87

7a71ed899   David S. Miller   inetpeer: Abstrac...
88
  	ipv6_addr_copy((struct in6_addr *)daddr.addr.a6, v6daddr);
672f007d6   David S. Miller   inetpeer: Add ine...
89
90
91
  	daddr.family = AF_INET6;
  	return inet_getpeer(&daddr, create);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92
  /* can be called from BH context or outside */
4663afe2c   Eric Dumazet   [NET]: reduce siz...
93
  extern void inet_putpeer(struct inet_peer *p);
92d868292   David S. Miller   inetpeer: Move IC...
94
  extern bool inet_peer_xrlim_allow(struct inet_peer *peer, int timeout);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95

317fe0e6c   Eric Dumazet   inetpeer: restore...
96
97
98
99
100
101
102
103
  /*
   * temporary check to make sure we dont access rid, ip_id_count, tcp_ts,
   * tcp_ts_stamp if no refcount is taken on inet_peer
   */
  static inline void inet_peer_refcheck(const struct inet_peer *p)
  {
  	WARN_ON_ONCE(atomic_read(&p->refcnt) <= 0);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
104
  /* can be called with or without local BH being disabled */
87c48fa3b   Eric Dumazet   ipv6: make fragme...
105
  static inline int inet_getid(struct inet_peer *p, int more)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
106
  {
87c48fa3b   Eric Dumazet   ipv6: make fragme...
107
  	int old, new;
2c1409a0a   Eric Dumazet   inetpeer: Optimiz...
108
  	more++;
317fe0e6c   Eric Dumazet   inetpeer: restore...
109
  	inet_peer_refcheck(p);
87c48fa3b   Eric Dumazet   ipv6: make fragme...
110
111
112
113
114
115
116
  	do {
  		old = atomic_read(&p->ip_id_count);
  		new = old + more;
  		if (!new)
  			new = 1;
  	} while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
  	return new;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117
118
119
  }
  
  #endif /* _NET_INETPEER_H */