]> Pileus Git - ~andy/linux/blobdiff - include/net/sock.h
udp: introduce sk_for_each_rcu_safenext()
[~andy/linux] / include / net / sock.h
index 75a312d3888a7a8de3578fe318615c03a20c6d1b..a4f6d3fc04700d6ebe5dd3048566e5ba8eb16ff3 100644 (file)
@@ -229,7 +229,9 @@ struct sock {
        } sk_backlog;
        wait_queue_head_t       *sk_sleep;
        struct dst_entry        *sk_dst_cache;
+#ifdef CONFIG_XFRM
        struct xfrm_policy      *sk_policy[2];
+#endif
        rwlock_t                sk_dst_lock;
        atomic_t                sk_rmem_alloc;
        atomic_t                sk_wmem_alloc;
@@ -361,6 +363,27 @@ static __inline__ int sk_del_node_init(struct sock *sk)
        return rc;
 }
 
+static __inline__ int __sk_del_node_init_rcu(struct sock *sk)
+{
+       if (sk_hashed(sk)) {
+               hlist_del_init_rcu(&sk->sk_node);
+               return 1;
+       }
+       return 0;
+}
+
+static __inline__ int sk_del_node_init_rcu(struct sock *sk)
+{
+       int rc = __sk_del_node_init_rcu(sk);
+
+       if (rc) {
+               /* paranoid for a while -acme */
+               WARN_ON(atomic_read(&sk->sk_refcnt) == 1);
+               __sock_put(sk);
+       }
+       return rc;
+}
+
 static __inline__ void __sk_add_node(struct sock *sk, struct hlist_head *list)
 {
        hlist_add_head(&sk->sk_node, list);
@@ -372,6 +395,17 @@ static __inline__ void sk_add_node(struct sock *sk, struct hlist_head *list)
        __sk_add_node(sk, list);
 }
 
+static __inline__ void __sk_add_node_rcu(struct sock *sk, struct hlist_head *list)
+{
+       hlist_add_head_rcu(&sk->sk_node, list);
+}
+
+static __inline__ void sk_add_node_rcu(struct sock *sk, struct hlist_head *list)
+{
+       sock_hold(sk);
+       __sk_add_node_rcu(sk, list);
+}
+
 static __inline__ void __sk_del_bind_node(struct sock *sk)
 {
        __hlist_del(&sk->sk_bind_node);
@@ -385,6 +419,8 @@ static __inline__ void sk_add_bind_node(struct sock *sk,
 
 #define sk_for_each(__sk, node, list) \
        hlist_for_each_entry(__sk, node, list, sk_node)
+#define sk_for_each_rcu_safenext(__sk, node, list, next) \
+       hlist_for_each_entry_rcu_safenext(__sk, node, list, sk_node, next)
 #define sk_for_each_from(__sk, node) \
        if (__sk && ({ node = &(__sk)->sk_node; 1; })) \
                hlist_for_each_entry_from(__sk, node, sk_node)
@@ -482,6 +518,11 @@ static inline void sk_add_backlog(struct sock *sk, struct sk_buff *skb)
        skb->next = NULL;
 }
 
+static inline int sk_backlog_rcv(struct sock *sk, struct sk_buff *skb)
+{
+       return sk->sk_backlog_rcv(sk, skb);
+}
+
 #define sk_wait_event(__sk, __timeo, __condition)                      \
        ({      int __rc;                                               \
                release_sock(__sk);                                     \
@@ -582,8 +623,9 @@ struct proto {
        int                     *sysctl_rmem;
        int                     max_header;
 
-       struct kmem_cache               *slab;
+       struct kmem_cache       *slab;
        unsigned int            obj_size;
+       int                     slab_flags;
 
        atomic_t                *orphan_count;
 
@@ -592,7 +634,7 @@ struct proto {
 
        union {
                struct inet_hashinfo    *hashinfo;
-               struct hlist_head       *udp_hash;
+               struct udp_table        *udp_table;
                struct raw_hashinfo     *raw_hash;
        } h;
 
@@ -1324,6 +1366,18 @@ static inline void sk_change_net(struct sock *sk, struct net *net)
        sock_net_set(sk, hold_net(net));
 }
 
+static inline struct sock *skb_steal_sock(struct sk_buff *skb)
+{
+       if (unlikely(skb->sk)) {
+               struct sock *sk = skb->sk;
+
+               skb->destructor = NULL;
+               skb->sk = NULL;
+               return sk;
+       }
+       return NULL;
+}
+
 extern void sock_enable_timestamp(struct sock *sk);
 extern int sock_get_timestamp(struct sock *, struct timeval __user *);
 extern int sock_get_timestampns(struct sock *, struct timespec __user *);