@@ -19,7 +19,11 @@ struct inet_peer
struct inet_peer *avl_left, *avl_right;
__be32 v4daddr; /* peer's address */
__u16 avl_height;
+#if defined(__HAVE_ARCH_CMPXCHG)
__u16 ip_id_count; /* IP ID for the next packet */
+#else
+ atomic_t ip_id_count;
+#endif
struct list_head unused;
__u32 dtime; /* the time of last use of not
* referenced entries */
@@ -37,17 +41,42 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create);
/* can be called from BH context or outside */
extern void inet_putpeer(struct inet_peer *p);
-extern spinlock_t inet_peer_idlock;
/* can be called with or without local BH being disabled */
static inline __u16 inet_getid(struct inet_peer *p, int more)
{
- __u16 id;
+ __u16 old;
- spin_lock_bh(&inet_peer_idlock);
- id = p->ip_id_count;
- p->ip_id_count += 1 + more;
- spin_unlock_bh(&inet_peer_idlock);
- return id;
+ more++;
+#if defined(__HAVE_ARCH_CMPXCHG)
+ while (1) {
+ old = p->ip_id_count;
+ if (cmpxchg(&p->ip_id_count, old, old + more) == old)
+ break;
+ }
+#else
+ old = atomic_add_return(more, &p->ip_id_count) - more;
+#endif
+ return old;
}
+static inline void inet_id_set(struct inet_peer *p, int val)
+{
+#if defined(__HAVE_ARCH_CMPXCHG)
+ p->ip_id_count = val;
+#else
+ atomic_set(&p->ip_id_count, val);
+#endif
+}
+
+static inline __u16 inet_id_read(const struct inet_peer *p)
+{
+#if defined(__HAVE_ARCH_CMPXCHG)
+ return p->ip_id_count;
+#else
+ return atomic_read(&p->ip_id_count);
+#endif
+}
+
+
+
#endif /* _NET_INETPEER_H */
@@ -67,9 +67,6 @@
* ip_id_count: idlock
*/
-/* Exported for inet_getid inline function. */
-DEFINE_SPINLOCK(inet_peer_idlock);
-
static struct kmem_cache *peer_cachep __read_mostly;
#define node_height(x) x->avl_height
@@ -390,7 +387,7 @@ struct inet_peer *inet_getpeer(__be32 daddr, int create)
n->v4daddr = daddr;
atomic_set(&n->refcnt, 1);
atomic_set(&n->rid, 0);
- n->ip_id_count = secure_ip_id(daddr);
+ inet_id_set(n, secure_ip_id(daddr));
n->tcp_ts_stamp = 0;
write_lock_bh(&peer_pool_lock);
@@ -2855,7 +2855,7 @@ static int rt_fill_info(struct net *net,
error = rt->u.dst.error;
expires = rt->u.dst.expires ? rt->u.dst.expires - jiffies : 0;
if (rt->peer) {
- id = rt->peer->ip_id_count;
+ id = inet_id_read(rt->peer);
if (rt->peer->tcp_ts_stamp) {
ts = rt->peer->tcp_ts;
tsage = get_seconds() - rt->peer->tcp_ts_stamp;