aboutsummaryrefslogtreecommitdiffstats
path: root/include/net/inetpeer.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/net/inetpeer.h')
-rw-r--r--include/net/inetpeer.h42
1 files changed, 26 insertions, 16 deletions
diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
index 8a159cc3d68..e9ff3fc5e68 100644
--- a/include/net/inetpeer.h
+++ b/include/net/inetpeer.h
@@ -13,7 +13,7 @@
13#include <linux/spinlock.h> 13#include <linux/spinlock.h>
14#include <linux/rtnetlink.h> 14#include <linux/rtnetlink.h>
15#include <net/ipv6.h> 15#include <net/ipv6.h>
16#include <asm/atomic.h> 16#include <linux/atomic.h>
17 17
18struct inetpeer_addr_base { 18struct inetpeer_addr_base {
19 union { 19 union {
@@ -32,13 +32,18 @@ struct inet_peer {
32 struct inet_peer __rcu *avl_left, *avl_right; 32 struct inet_peer __rcu *avl_left, *avl_right;
33 struct inetpeer_addr daddr; 33 struct inetpeer_addr daddr;
34 __u32 avl_height; 34 __u32 avl_height;
35 struct list_head unused; 35
36 __u32 dtime; /* the time of last use of not 36 u32 metrics[RTAX_MAX];
37 * referenced entries */ 37 u32 rate_tokens; /* rate limiting for ICMP */
38 atomic_t refcnt; 38 int redirect_genid;
39 unsigned long rate_last;
40 unsigned long pmtu_expires;
41 u32 pmtu_orig;
42 u32 pmtu_learned;
43 struct inetpeer_addr_base redirect_learned;
39 /* 44 /*
40 * Once inet_peer is queued for deletion (refcnt == -1), following fields 45 * Once inet_peer is queued for deletion (refcnt == -1), following fields
41 * are not available: rid, ip_id_count, tcp_ts, tcp_ts_stamp, metrics 46 * are not available: rid, ip_id_count, tcp_ts, tcp_ts_stamp
42 * We can share memory with rcu_head to help keep inet_peer small. 47 * We can share memory with rcu_head to help keep inet_peer small.
43 */ 48 */
44 union { 49 union {
@@ -47,16 +52,14 @@ struct inet_peer {
47 atomic_t ip_id_count; /* IP ID for the next packet */ 52 atomic_t ip_id_count; /* IP ID for the next packet */
48 __u32 tcp_ts; 53 __u32 tcp_ts;
49 __u32 tcp_ts_stamp; 54 __u32 tcp_ts_stamp;
50 u32 metrics[RTAX_MAX];
51 u32 rate_tokens; /* rate limiting for ICMP */
52 unsigned long rate_last;
53 unsigned long pmtu_expires;
54 u32 pmtu_orig;
55 u32 pmtu_learned;
56 struct inetpeer_addr_base redirect_learned;
57 }; 55 };
58 struct rcu_head rcu; 56 struct rcu_head rcu;
57 struct inet_peer *gc_next;
59 }; 58 };
59
60 /* following fields might be frequently dirtied */
61 __u32 dtime; /* the time of last use of not referenced entries */
62 atomic_t refcnt;
60}; 63};
61 64
62void inet_initpeers(void) __init; 65void inet_initpeers(void) __init;
@@ -69,7 +72,7 @@ static inline bool inet_metrics_new(const struct inet_peer *p)
69} 72}
70 73
71/* can be called with or without local BH being disabled */ 74/* can be called with or without local BH being disabled */
72struct inet_peer *inet_getpeer(struct inetpeer_addr *daddr, int create); 75struct inet_peer *inet_getpeer(const struct inetpeer_addr *daddr, int create);
73 76
74static inline struct inet_peer *inet_getpeer_v4(__be32 v4daddr, int create) 77static inline struct inet_peer *inet_getpeer_v4(__be32 v4daddr, int create)
75{ 78{
@@ -104,11 +107,18 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
104 107
105 108
106/* can be called with or without local BH being disabled */ 109/* can be called with or without local BH being disabled */
107static inline __u16 inet_getid(struct inet_peer *p, int more) 110static inline int inet_getid(struct inet_peer *p, int more)
108{ 111{
112 int old, new;
109 more++; 113 more++;
110 inet_peer_refcheck(p); 114 inet_peer_refcheck(p);
111 return atomic_add_return(more, &p->ip_id_count) - more; 115 do {
116 old = atomic_read(&p->ip_id_count);
117 new = old + more;
118 if (!new)
119 new = 1;
120 } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
121 return new;
112} 122}
113 123
114#endif /* _NET_INETPEER_H */ 124#endif /* _NET_INETPEER_H */