Use helpers to obtain task pid in printks
[safe/jmp/linux-2.6] / net / sctp / bind_addr.c
index 50f3697..dfffa94 100644 (file)
@@ -43,7 +43,6 @@
  */
 
 #include <linux/types.h>
-#include <linux/sched.h>
 #include <linux/in.h>
 #include <net/sock.h>
 #include <net/ipv6.h>
@@ -62,7 +61,7 @@ static void sctp_bind_addr_clean(struct sctp_bind_addr *);
 /* Copy 'src' to 'dest' taking 'scope' into account.  Omit addresses
  * in 'src' which have a broader scope than 'scope'.
  */
-int sctp_bind_addr_copy(struct sctp_bind_addr *dest, 
+int sctp_bind_addr_copy(struct sctp_bind_addr *dest,
                        const struct sctp_bind_addr *src,
                        sctp_scope_t scope, gfp_t gfp,
                        int flags)
@@ -163,12 +162,16 @@ int sctp_add_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *new,
        if (!addr->a.v4.sin_port)
                addr->a.v4.sin_port = htons(bp->port);
 
-       flip_to_h(&addr->a_h, &addr->a);
-
        addr->use_as_src = use_as_src;
+       addr->valid = 1;
 
        INIT_LIST_HEAD(&addr->list);
-       list_add_tail(&addr->list, &bp->address_list);
+       INIT_RCU_HEAD(&addr->rcu);
+
+       /* We always hold a socket lock when calling this function,
+        * and that acts as a writer synchronizing lock.
+        */
+       list_add_tail_rcu(&addr->list, &bp->address_list);
        SCTP_DBG_OBJCNT_INC(addr);
 
        return 0;
@@ -177,23 +180,35 @@ int sctp_add_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *new,
 /* Delete an address from the bind address list in the SCTP_bind_addr
  * structure.
  */
-int sctp_del_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *del_addr)
+int sctp_del_bind_addr(struct sctp_bind_addr *bp, union sctp_addr *del_addr,
+                       void fastcall (*rcu_call)(struct rcu_head *head,
+                                        void (*func)(struct rcu_head *head)))
 {
-       struct list_head *pos, *temp;
-       struct sctp_sockaddr_entry *addr;
+       struct sctp_sockaddr_entry *addr, *temp;
 
-       list_for_each_safe(pos, temp, &bp->address_list) {
-               addr = list_entry(pos, struct sctp_sockaddr_entry, list);
+       /* We hold the socket lock when calling this function,
+        * and that acts as a writer synchronizing lock.
+        */
+       list_for_each_entry_safe(addr, temp, &bp->address_list, list) {
                if (sctp_cmp_addr_exact(&addr->a, del_addr)) {
                        /* Found the exact match. */
-                       list_del(pos);
-                       kfree(addr);
-                       SCTP_DBG_OBJCNT_DEC(addr);
-
-                       return 0;
+                       addr->valid = 0;
+                       list_del_rcu(&addr->list);
+                       break;
                }
        }
 
+       /* Call the rcu callback provided in the args.  This function is
+        * called by both BH packet processing and user side socket option
+        * processing, but it works on different lists in those 2 contexts.
+        * Each context provides it's own callback, whether call_rcu_bh()
+        * or call_rcu(), to make sure that we wait for an appropriate time.
+        */
+       if (addr && !addr->valid) {
+               rcu_call(&addr->rcu, sctp_local_addr_free);
+               SCTP_DBG_OBJCNT_DEC(addr);
+       }
+
        return -EINVAL;
 }
 
@@ -239,8 +254,8 @@ union sctp_params sctp_bind_addrs_to_raw(const struct sctp_bind_addr *bp,
 
        list_for_each(pos, &bp->address_list) {
                addr = list_entry(pos, struct sctp_sockaddr_entry, list);
-               af = sctp_get_af_specific(addr->a_h.v4.sin_family);
-               len = af->to_addr_param(&addr->a_h, &rawaddr);
+               af = sctp_get_af_specific(addr->a.v4.sin_family);
+               len = af->to_addr_param(&addr->a, &rawaddr);
                memcpy(addrparms.v, &rawaddr, len);
                addrparms.v += len;
                addrparms_len += len;
@@ -298,20 +313,25 @@ int sctp_raw_to_bind_addrs(struct sctp_bind_addr *bp, __u8 *raw_addr_list,
  ********************************************************************/
 
 /* Does this contain a specified address?  Allow wildcarding. */
-int sctp_bind_addr_match(struct sctp_bind_addr *bp, 
+int sctp_bind_addr_match(struct sctp_bind_addr *bp,
                         const union sctp_addr *addr,
                         struct sctp_sock *opt)
 {
        struct sctp_sockaddr_entry *laddr;
-       struct list_head *pos;
-
-       list_for_each(pos, &bp->address_list) {
-               laddr = list_entry(pos, struct sctp_sockaddr_entry, list);
-               if (opt->pf->cmp_addr(&laddr->a, addr, opt))
-                       return 1;
+       int match = 0;
+
+       rcu_read_lock();
+       list_for_each_entry_rcu(laddr, &bp->address_list, list) {
+               if (!laddr->valid)
+                       continue;
+               if (opt->pf->cmp_addr(&laddr->a, addr, opt)) {
+                       match = 1;
+                       break;
+               }
        }
+       rcu_read_unlock();
 
-       return 0;
+       return match;
 }
 
 /* Find the first address in the bind address list that is not present in
@@ -326,18 +346,19 @@ union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr     *bp,
        union sctp_addr                 *addr;
        void                            *addr_buf;
        struct sctp_af                  *af;
-       struct list_head                *pos;
        int                             i;
 
-       list_for_each(pos, &bp->address_list) {
-               laddr = list_entry(pos, struct sctp_sockaddr_entry, list);
-               
+       /* This is only called sctp_send_asconf_del_ip() and we hold
+        * the socket lock in that code patch, so that address list
+        * can't change.
+        */
+       list_for_each_entry(laddr, &bp->address_list, list) {
                addr_buf = (union sctp_addr *)addrs;
                for (i = 0; i < addrcnt; i++) {
                        addr = (union sctp_addr *)addr_buf;
                        af = sctp_get_af_specific(addr->v4.sin_family);
-                       if (!af) 
-                               return NULL;
+                       if (!af)
+                               break;
 
                        if (opt->pf->cmp_addr(&laddr->a, addr, opt))
                                break;
@@ -345,14 +366,14 @@ union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr     *bp,
                        addr_buf += af->sockaddr_len;
                }
                if (i == addrcnt)
-                       return &laddr->a_h;
+                       return &laddr->a;
        }
 
        return NULL;
 }
 
 /* Copy out addresses from the global local address list. */
-static int sctp_copy_one_addr(struct sctp_bind_addr *dest, 
+static int sctp_copy_one_addr(struct sctp_bind_addr *dest,
                              union sctp_addr *addr,
                              sctp_scope_t scope, gfp_t gfp,
                              int flags)