ipv6: convert idev_list to list macros
[safe/jmp/linux-2.6] / net / sctp / ipv6.c
index e45e44c..240dceb 100644 (file)
@@ -97,8 +97,7 @@ static int sctp_inet6addr_event(struct notifier_block *this, unsigned long ev,
                if (addr) {
                        addr->a.v6.sin6_family = AF_INET6;
                        addr->a.v6.sin6_port = 0;
-                       memcpy(&addr->a.v6.sin6_addr, &ifa->addr,
-                                sizeof(struct in6_addr));
+                       ipv6_addr_copy(&addr->a.v6.sin6_addr, &ifa->addr);
                        addr->a.v6.sin6_scope_id = ifa->idev->dev->ifindex;
                        addr->valid = 1;
                        spin_lock_bh(&sctp_local_addr_lock);
@@ -134,7 +133,7 @@ static struct notifier_block sctp_inet6addr_notifier = {
 
 /* ICMP error handler. */
 SCTP_STATIC void sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
-                            int type, int code, int offset, __be32 info)
+                            u8 type, u8 code, int offset, __be32 info)
 {
        struct inet6_dev *idev;
        struct sock *sk;
@@ -156,7 +155,7 @@ SCTP_STATIC void sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
        skb->network_header   = saveip;
        skb->transport_header = savesctp;
        if (!sk) {
-               ICMP6_INC_STATS_BH(idev, ICMP6_MIB_INERRORS);
+               ICMP6_INC_STATS_BH(dev_net(skb->dev), idev, ICMP6_MIB_INERRORS);
                goto out;
        }
 
@@ -195,8 +194,7 @@ out:
 }
 
 /* Based on tcp_v6_xmit() in tcp_ipv6.c. */
-static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport,
-                       int ipfragok)
+static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport)
 {
        struct sock *sk = skb->sk;
        struct ipv6_pinfo *np = inet6_sk(sk);
@@ -224,14 +222,16 @@ static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport,
                ipv6_addr_copy(&fl.fl6_dst, rt0->addr);
        }
 
-       SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, "
-                         "src:" NIP6_FMT " dst:" NIP6_FMT "\n",
+       SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, src:%pI6 dst:%pI6\n",
                          __func__, skb, skb->len,
-                         NIP6(fl.fl6_src), NIP6(fl.fl6_dst));
+                         &fl.fl6_src, &fl.fl6_dst);
 
        SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS);
 
-       return ip6_xmit(sk, skb, &fl, np->opt, ipfragok);
+       if (!(transport->param_flags & SPP_PMTUD_ENABLE))
+               skb->local_df = 1;
+
+       return ip6_xmit(sk, skb, &fl, np->opt, 0);
 }
 
 /* Returns the dst cache entry for the given source and destination ip
@@ -250,23 +250,19 @@ static struct dst_entry *sctp_v6_get_dst(struct sctp_association *asoc,
                fl.oif = daddr->v6.sin6_scope_id;
 
 
-       SCTP_DEBUG_PRINTK("%s: DST=" NIP6_FMT " ",
-                         __func__, NIP6(fl.fl6_dst));
+       SCTP_DEBUG_PRINTK("%s: DST=%pI6 ", __func__, &fl.fl6_dst);
 
        if (saddr) {
                ipv6_addr_copy(&fl.fl6_src, &saddr->v6.sin6_addr);
-               SCTP_DEBUG_PRINTK(
-                       "SRC=" NIP6_FMT " - ",
-                       NIP6(fl.fl6_src));
+               SCTP_DEBUG_PRINTK("SRC=%pI6 - ", &fl.fl6_src);
        }
 
        dst = ip6_route_output(&init_net, NULL, &fl);
        if (!dst->error) {
                struct rt6_info *rt;
                rt = (struct rt6_info *)dst;
-               SCTP_DEBUG_PRINTK(
-                       "rt6_dst:" NIP6_FMT " rt6_src:" NIP6_FMT "\n",
-                       NIP6(rt->rt6i_dst.addr), NIP6(rt->rt6i_src.addr));
+               SCTP_DEBUG_PRINTK("rt6_dst:%pI6 rt6_src:%pI6\n",
+                       &rt->rt6i_dst.addr, &rt->rt6i_src.addr);
                return dst;
        }
        SCTP_DEBUG_PRINTK("NO ROUTE\n");
@@ -299,7 +295,8 @@ static inline int sctp_v6_addr_match_len(union sctp_addr *s1,
 /* Fills in the source address(saddr) based on the destination address(daddr)
  * and asoc's bind address list.
  */
-static void sctp_v6_get_saddr(struct sctp_association *asoc,
+static void sctp_v6_get_saddr(struct sctp_sock *sk,
+                             struct sctp_association *asoc,
                              struct dst_entry *dst,
                              union sctp_addr *daddr,
                              union sctp_addr *saddr)
@@ -311,17 +308,17 @@ static void sctp_v6_get_saddr(struct sctp_association *asoc,
        __u8 matchlen = 0;
        __u8 bmatchlen;
 
-       SCTP_DEBUG_PRINTK("%s: asoc:%p dst:%p "
-                         "daddr:" NIP6_FMT " ",
-                         __func__, asoc, dst, NIP6(daddr->v6.sin6_addr));
+       SCTP_DEBUG_PRINTK("%s: asoc:%p dst:%p daddr:%pI6 ",
+                         __func__, asoc, dst, &daddr->v6.sin6_addr);
 
        if (!asoc) {
-               ipv6_dev_get_saddr(dst ? ip6_dst_idev(dst)->dev : NULL,
+               ipv6_dev_get_saddr(sock_net(sctp_opt2sk(sk)),
+                                  dst ? ip6_dst_idev(dst)->dev : NULL,
                                   &daddr->v6.sin6_addr,
-                                  inet6_sk(asoc->base.sk)->srcprefs,
+                                  inet6_sk(&sk->inet.sk)->srcprefs,
                                   &saddr->v6.sin6_addr);
-               SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n",
-                                 NIP6(saddr->v6.sin6_addr));
+               SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: %pI6\n",
+                                 &saddr->v6.sin6_addr);
                return;
        }
 
@@ -349,12 +346,11 @@ static void sctp_v6_get_saddr(struct sctp_association *asoc,
 
        if (baddr) {
                memcpy(saddr, baddr, sizeof(union sctp_addr));
-               SCTP_DEBUG_PRINTK("saddr: " NIP6_FMT "\n",
-                                 NIP6(saddr->v6.sin6_addr));
+               SCTP_DEBUG_PRINTK("saddr: %pI6\n", &saddr->v6.sin6_addr);
        } else {
                printk(KERN_ERR "%s: asoc:%p Could not find a valid source "
-                      "address for the dest:" NIP6_FMT "\n",
-                      __func__, asoc, NIP6(daddr->v6.sin6_addr));
+                      "address for the dest:%pI6\n",
+                      __func__, asoc, &daddr->v6.sin6_addr);
        }
 
        rcu_read_unlock();
@@ -375,7 +371,7 @@ static void sctp_v6_copy_addrlist(struct list_head *addrlist,
        }
 
        read_lock_bh(&in6_dev->lock);
-       for (ifp = in6_dev->addr_list; ifp; ifp = ifp->if_next) {
+       list_for_each_entry(ifp, &in6_dev->addr_list, if_list) {
                /* Add the address to the local list.  */
                addr = t_new(struct sctp_sockaddr_entry, GFP_ATOMIC);
                if (addr) {
@@ -385,7 +381,6 @@ static void sctp_v6_copy_addrlist(struct list_head *addrlist,
                        addr->a.v6.sin6_scope_id = dev->ifindex;
                        addr->valid = 1;
                        INIT_LIST_HEAD(&addr->list);
-                       INIT_RCU_HEAD(&addr->rcu);
                        list_add_tail(&addr->list, addrlist);
                }
        }
@@ -631,9 +626,7 @@ static sctp_scope_t sctp_v6_scope(union sctp_addr *addr)
 static struct sock *sctp_v6_create_accept_sk(struct sock *sk,
                                             struct sctp_association *asoc)
 {
-       struct inet_sock *inet = inet_sk(sk);
        struct sock *newsk;
-       struct inet_sock *newinet;
        struct ipv6_pinfo *newnp, *np = inet6_sk(sk);
        struct sctp6_sock *newsctp6sk;
 
@@ -643,17 +636,7 @@ static struct sock *sctp_v6_create_accept_sk(struct sock *sk,
 
        sock_init_data(NULL, newsk);
 
-       newsk->sk_type = SOCK_STREAM;
-
-       newsk->sk_prot = sk->sk_prot;
-       newsk->sk_no_check = sk->sk_no_check;
-       newsk->sk_reuse = sk->sk_reuse;
-
-       newsk->sk_destruct = inet_sock_destruct;
-       newsk->sk_family = PF_INET6;
-       newsk->sk_protocol = IPPROTO_SCTP;
-       newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv;
-       newsk->sk_shutdown = sk->sk_shutdown;
+       sctp_copy_sock(newsk, sk, asoc);
        sock_reset_flag(sk, SOCK_ZAPPED);
 
        newsctp6sk = (struct sctp6_sock *)newsk;
@@ -661,7 +644,6 @@ static struct sock *sctp_v6_create_accept_sk(struct sock *sk,
 
        sctp_sk(newsk)->v4mapped = sctp_sk(sk)->v4mapped;
 
-       newinet = inet_sk(newsk);
        newnp = inet6_sk(newsk);
 
        memcpy(newnp, np, sizeof(struct ipv6_pinfo));
@@ -669,26 +651,8 @@ static struct sock *sctp_v6_create_accept_sk(struct sock *sk,
        /* Initialize sk's sport, dport, rcv_saddr and daddr for getsockname()
         * and getpeername().
         */
-       newinet->sport = inet->sport;
-       newnp->saddr = np->saddr;
-       newnp->rcv_saddr = np->rcv_saddr;
-       newinet->dport = htons(asoc->peer.port);
        sctp_v6_to_sk_daddr(&asoc->peer.primary_addr, newsk);
 
-       /* Init the ipv4 part of the socket since we can have sockets
-        * using v6 API for ipv4.
-        */
-       newinet->uc_ttl = -1;
-       newinet->mc_loop = 1;
-       newinet->mc_ttl = 1;
-       newinet->mc_index = 0;
-       newinet->mc_list = NULL;
-
-       if (ipv4_config.no_pmtu_disc)
-               newinet->pmtudisc = IP_PMTUDISC_DONT;
-       else
-               newinet->pmtudisc = IP_PMTUDISC_WANT;
-
        sk_refcnt_debug_inc(newsk);
 
        if (newsk->sk_prot->init(newsk)) {
@@ -723,7 +687,12 @@ static int sctp_v6_is_ce(const struct sk_buff *skb)
 /* Dump the v6 addr to the seq file. */
 static void sctp_v6_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr)
 {
-       seq_printf(seq, NIP6_FMT " ", NIP6(addr->v6.sin6_addr));
+       seq_printf(seq, "%pI6 ", &addr->v6.sin6_addr);
+}
+
+static void sctp_v6_ecn_capable(struct sock *sk)
+{
+       inet6_sk(sk)->tclass |= INET_ECN_ECT_0;
 }
 
 /* Initialize a PF_INET6 socket msg_name. */
@@ -812,7 +781,7 @@ static int sctp_inet6_af_supported(sa_family_t family, struct sctp_sock *sp)
                return 1;
        /* v4-mapped-v6 addresses */
        case AF_INET:
-               if (!__ipv6_only_sock(sctp_opt2sk(sp)) && sp->v4mapped)
+               if (!__ipv6_only_sock(sctp_opt2sk(sp)))
                        return 1;
        default:
                return 0;
@@ -828,14 +797,20 @@ static int sctp_inet6_cmp_addr(const union sctp_addr *addr1,
                               struct sctp_sock *opt)
 {
        struct sctp_af *af1, *af2;
+       struct sock *sk = sctp_opt2sk(opt);
 
        af1 = sctp_get_af_specific(addr1->sa.sa_family);
        af2 = sctp_get_af_specific(addr2->sa.sa_family);
 
        if (!af1 || !af2)
                return 0;
+
+       /* If the socket is IPv6 only, v4 addrs will not match */
+       if (__ipv6_only_sock(sk) && af1 != af2)
+               return 0;
+
        /* Today, wildcard AF_INET/AF_INET6. */
-       if (sctp_is_any(addr1) || sctp_is_any(addr2))
+       if (sctp_is_any(sk, addr1) || sctp_is_any(sk, addr2))
                return 1;
 
        if (addr1->sa.sa_family != addr2->sa.sa_family)
@@ -861,16 +836,21 @@ static int sctp_inet6_bind_verify(struct sctp_sock *opt, union sctp_addr *addr)
                if (type & IPV6_ADDR_LINKLOCAL) {
                        if (!addr->v6.sin6_scope_id)
                                return 0;
-                       dev = dev_get_by_index(&init_net, addr->v6.sin6_scope_id);
-                       if (!dev)
-                               return 0;
-                       if (!ipv6_chk_addr(&init_net, &addr->v6.sin6_addr,
+                       rcu_read_lock();
+                       dev = dev_get_by_index_rcu(&init_net,
+                                                  addr->v6.sin6_scope_id);
+                       if (!dev ||
+                           !ipv6_chk_addr(&init_net, &addr->v6.sin6_addr,
                                           dev, 0)) {
-                               dev_put(dev);
+                               rcu_read_unlock();
                                return 0;
                        }
-                       dev_put(dev);
+                       rcu_read_unlock();
+               } else if (type == IPV6_ADDR_MAPPED) {
+                       if (!opt->v4mapped)
+                               return 0;
                }
+
                af = opt->pf->af;
        }
        return af->available(addr, opt);
@@ -893,10 +873,12 @@ static int sctp_inet6_send_verify(struct sctp_sock *opt, union sctp_addr *addr)
                if (type & IPV6_ADDR_LINKLOCAL) {
                        if (!addr->v6.sin6_scope_id)
                                return 0;
-                       dev = dev_get_by_index(&init_net, addr->v6.sin6_scope_id);
+                       rcu_read_lock();
+                       dev = dev_get_by_index_rcu(&init_net,
+                                                  addr->v6.sin6_scope_id);
+                       rcu_read_unlock();
                        if (!dev)
                                return 0;
-                       dev_put(dev);
                }
                af = opt->pf->af;
        }
@@ -913,9 +895,12 @@ static int sctp_inet6_send_verify(struct sctp_sock *opt, union sctp_addr *addr)
 static int sctp_inet6_supported_addrs(const struct sctp_sock *opt,
                                      __be16 *types)
 {
-       types[0] = SCTP_PARAM_IPV4_ADDRESS;
-       types[1] = SCTP_PARAM_IPV6_ADDRESS;
-       return 2;
+       types[0] = SCTP_PARAM_IPV6_ADDRESS;
+       if (!opt || !ipv6_only_sock(sctp_opt2sk(opt))) {
+               types[1] = SCTP_PARAM_IPV4_ADDRESS;
+               return 2;
+       }
+       return 1;
 }
 
 static const struct proto_ops inet6_seqpacket_ops = {
@@ -947,7 +932,6 @@ static struct inet_protosw sctpv6_seqpacket_protosw = {
        .protocol      = IPPROTO_SCTP,
        .prot          = &sctpv6_prot,
        .ops           = &inet6_seqpacket_ops,
-       .capability    = -1,
        .no_check      = 0,
        .flags         = SCTP_PROTOSW_FLAG
 };
@@ -956,7 +940,6 @@ static struct inet_protosw sctpv6_stream_protosw = {
        .protocol      = IPPROTO_SCTP,
        .prot          = &sctpv6_prot,
        .ops           = &inet6_seqpacket_ops,
-       .capability    = -1,
        .no_check      = 0,
        .flags         = SCTP_PROTOSW_FLAG,
 };
@@ -966,7 +949,7 @@ static int sctp6_rcv(struct sk_buff *skb)
        return sctp_rcv(skb) ? -1 : 0;
 }
 
-static struct inet6_protocol sctpv6_protocol = {
+static const struct inet6_protocol sctpv6_protocol = {
        .handler      = sctp6_rcv,
        .err_handler  = sctp_v6_err,
        .flags        = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
@@ -996,6 +979,7 @@ static struct sctp_af sctp_af_inet6 = {
        .skb_iif           = sctp_v6_skb_iif,
        .is_ce             = sctp_v6_is_ce,
        .seq_dump_addr     = sctp_v6_seq_dump_addr,
+       .ecn_capable       = sctp_v6_ecn_capable,
        .net_header_len    = sizeof(struct ipv6hdr),
        .sockaddr_len      = sizeof(struct sockaddr_in6),
 #ifdef CONFIG_COMPAT