~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to net/sctp/protocol.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
230
230
        }
231
231
}
232
232
 
233
 
void sctp_local_addr_free(struct rcu_head *head)
234
 
{
235
 
        struct sctp_sockaddr_entry *e = container_of(head,
236
 
                                struct sctp_sockaddr_entry, rcu);
237
 
        kfree(e);
238
 
}
239
 
 
240
233
/* Copy the local addresses which are valid for 'scope' into 'bp'.  */
241
234
int sctp_copy_local_addr_list(struct sctp_bind_addr *bp, sctp_scope_t scope,
242
235
                              gfp_t gfp, int copy_flags)
339
332
}
340
333
 
341
334
/* Initialize a sctp_addr from a dst_entry. */
342
 
static void sctp_v4_dst_saddr(union sctp_addr *saddr, struct dst_entry *dst,
 
335
static void sctp_v4_dst_saddr(union sctp_addr *saddr, struct flowi4 *fl4,
343
336
                              __be16 port)
344
337
{
345
 
        struct rtable *rt = (struct rtable *)dst;
346
338
        saddr->v4.sin_family = AF_INET;
347
339
        saddr->v4.sin_port = port;
348
 
        saddr->v4.sin_addr.s_addr = rt->rt_src;
 
340
        saddr->v4.sin_addr.s_addr = fl4->saddr;
349
341
}
350
342
 
351
343
/* Compare two addresses exactly. */
463
455
 * addresses. If an association is passed, trys to get a dst entry with a
464
456
 * source address that matches an address in the bind address list.
465
457
 */
466
 
static struct dst_entry *sctp_v4_get_dst(struct sctp_association *asoc,
467
 
                                         union sctp_addr *daddr,
468
 
                                         union sctp_addr *saddr)
 
458
static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
 
459
                                struct flowi *fl, struct sock *sk)
469
460
{
 
461
        struct sctp_association *asoc = t->asoc;
470
462
        struct rtable *rt;
471
 
        struct flowi fl;
 
463
        struct flowi4 *fl4 = &fl->u.ip4;
472
464
        struct sctp_bind_addr *bp;
473
465
        struct sctp_sockaddr_entry *laddr;
474
466
        struct dst_entry *dst = NULL;
 
467
        union sctp_addr *daddr = &t->ipaddr;
475
468
        union sctp_addr dst_saddr;
476
469
 
477
 
        memset(&fl, 0x0, sizeof(struct flowi));
478
 
        fl.fl4_dst  = daddr->v4.sin_addr.s_addr;
479
 
        fl.fl_ip_dport = daddr->v4.sin_port;
480
 
        fl.proto = IPPROTO_SCTP;
 
470
        memset(fl4, 0x0, sizeof(struct flowi4));
 
471
        fl4->daddr  = daddr->v4.sin_addr.s_addr;
 
472
        fl4->fl4_dport = daddr->v4.sin_port;
 
473
        fl4->flowi4_proto = IPPROTO_SCTP;
481
474
        if (asoc) {
482
 
                fl.fl4_tos = RT_CONN_FLAGS(asoc->base.sk);
483
 
                fl.oif = asoc->base.sk->sk_bound_dev_if;
484
 
                fl.fl_ip_sport = htons(asoc->base.bind_addr.port);
 
475
                fl4->flowi4_tos = RT_CONN_FLAGS(asoc->base.sk);
 
476
                fl4->flowi4_oif = asoc->base.sk->sk_bound_dev_if;
 
477
                fl4->fl4_sport = htons(asoc->base.bind_addr.port);
485
478
        }
486
479
        if (saddr) {
487
 
                fl.fl4_src = saddr->v4.sin_addr.s_addr;
488
 
                fl.fl_ip_sport = saddr->v4.sin_port;
 
480
                fl4->saddr = saddr->v4.sin_addr.s_addr;
 
481
                fl4->fl4_sport = saddr->v4.sin_port;
489
482
        }
490
483
 
491
484
        SCTP_DEBUG_PRINTK("%s: DST:%pI4, SRC:%pI4 - ",
492
 
                          __func__, &fl.fl4_dst, &fl.fl4_src);
 
485
                          __func__, &fl4->daddr, &fl4->saddr);
493
486
 
494
 
        if (!ip_route_output_key(&init_net, &rt, &fl)) {
 
487
        rt = ip_route_output_key(&init_net, fl4);
 
488
        if (!IS_ERR(rt))
495
489
                dst = &rt->dst;
496
 
        }
497
490
 
498
491
        /* If there is no association or if a source address is passed, no
499
492
         * more validation is required.
507
500
                /* Walk through the bind address list and look for a bind
508
501
                 * address that matches the source address of the returned dst.
509
502
                 */
510
 
                sctp_v4_dst_saddr(&dst_saddr, dst, htons(bp->port));
 
503
                sctp_v4_dst_saddr(&dst_saddr, fl4, htons(bp->port));
511
504
                rcu_read_lock();
512
505
                list_for_each_entry_rcu(laddr, &bp->address_list, list) {
513
506
                        if (!laddr->valid || (laddr->state != SCTP_ADDR_SRC))
533
526
                        continue;
534
527
                if ((laddr->state == SCTP_ADDR_SRC) &&
535
528
                    (AF_INET == laddr->a.sa.sa_family)) {
536
 
                        fl.fl4_src = laddr->a.v4.sin_addr.s_addr;
537
 
                        fl.fl_ip_sport = laddr->a.v4.sin_port;
538
 
                        if (!ip_route_output_key(&init_net, &rt, &fl)) {
 
529
                        fl4->saddr = laddr->a.v4.sin_addr.s_addr;
 
530
                        fl4->fl4_sport = laddr->a.v4.sin_port;
 
531
                        rt = ip_route_output_key(&init_net, fl4);
 
532
                        if (!IS_ERR(rt)) {
539
533
                                dst = &rt->dst;
540
534
                                goto out_unlock;
541
535
                        }
545
539
out_unlock:
546
540
        rcu_read_unlock();
547
541
out:
 
542
        t->dst = dst;
548
543
        if (dst)
549
544
                SCTP_DEBUG_PRINTK("rt_dst:%pI4, rt_src:%pI4\n",
550
 
                                  &rt->rt_dst, &rt->rt_src);
 
545
                                  &fl4->daddr, &fl4->saddr);
551
546
        else
552
547
                SCTP_DEBUG_PRINTK("NO ROUTE\n");
553
 
 
554
 
        return dst;
555
548
}
556
549
 
557
550
/* For v4, the source address is cached in the route entry(dst). So no need
558
551
 * to cache it separately and hence this is an empty routine.
559
552
 */
560
553
static void sctp_v4_get_saddr(struct sctp_sock *sk,
561
 
                              struct sctp_association *asoc,
562
 
                              struct dst_entry *dst,
563
 
                              union sctp_addr *daddr,
564
 
                              union sctp_addr *saddr)
 
554
                              struct sctp_transport *t,
 
555
                              struct flowi *fl)
565
556
{
566
 
        struct rtable *rt = (struct rtable *)dst;
567
 
 
568
 
        if (!asoc)
569
 
                return;
 
557
        union sctp_addr *saddr = &t->saddr;
 
558
        struct rtable *rt = (struct rtable *)t->dst;
570
559
 
571
560
        if (rt) {
572
561
                saddr->v4.sin_family = AF_INET;
573
 
                saddr->v4.sin_port = htons(asoc->base.bind_addr.port);
574
 
                saddr->v4.sin_addr.s_addr = rt->rt_src;
 
562
                saddr->v4.sin_addr.s_addr = fl->u.ip4.saddr;
575
563
        }
576
564
}
577
565
 
680
668
                }
681
669
                spin_unlock_bh(&sctp_local_addr_lock);
682
670
                if (found)
683
 
                        call_rcu(&addr->rcu, sctp_local_addr_free);
 
671
                        kfree_rcu(addr, rcu);
684
672
                break;
685
673
        }
686
674
 
853
841
 
854
842
        SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, src:%pI4, dst:%pI4\n",
855
843
                          __func__, skb, skb->len,
856
 
                          &skb_rtable(skb)->rt_src,
857
 
                          &skb_rtable(skb)->rt_dst);
 
844
                          &transport->fl.u.ip4.saddr,
 
845
                          &transport->fl.u.ip4.daddr);
858
846
 
859
847
        inet->pmtudisc = transport->param_flags & SPP_PMTUD_ENABLE ?
860
848
                         IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
861
849
 
862
850
        SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS);
863
 
        return ip_queue_xmit(skb);
 
851
        return ip_queue_xmit(skb, &transport->fl);
864
852
}
865
853
 
866
854
static struct sctp_af sctp_af_inet;
949
937
        .to_sk_daddr       = sctp_v4_to_sk_daddr,
950
938
        .from_addr_param   = sctp_v4_from_addr_param,
951
939
        .to_addr_param     = sctp_v4_to_addr_param,
952
 
        .dst_saddr         = sctp_v4_dst_saddr,
953
940
        .cmp_addr          = sctp_v4_cmp_addr,
954
941
        .addr_valid        = sctp_v4_addr_valid,
955
942
        .inaddr_any        = sctp_v4_inaddr_any,
1071
1058
        int status = -EINVAL;
1072
1059
        unsigned long goal;
1073
1060
        unsigned long limit;
1074
 
        unsigned long nr_pages;
1075
1061
        int max_share;
1076
1062
        int order;
1077
1063
 
1161
1147
        /* Initialize handle used for association ids. */
1162
1148
        idr_init(&sctp_assocs_id);
1163
1149
 
1164
 
        /* Set the pressure threshold to be a fraction of global memory that
1165
 
         * is up to 1/2 at 256 MB, decreasing toward zero with the amount of
1166
 
         * memory, with a floor of 128 pages.
1167
 
         * Note this initializes the data in sctpv6_prot too
1168
 
         * Unabashedly stolen from tcp_init
1169
 
         */
1170
 
        nr_pages = totalram_pages - totalhigh_pages;
1171
 
        limit = min(nr_pages, 1UL<<(28-PAGE_SHIFT)) >> (20-PAGE_SHIFT);
1172
 
        limit = (limit * (nr_pages >> (20-PAGE_SHIFT))) >> (PAGE_SHIFT-11);
 
1150
        limit = nr_free_buffer_pages() / 8;
1173
1151
        limit = max(limit, 128UL);
1174
1152
        sysctl_sctp_mem[0] = limit / 4 * 3;
1175
1153
        sysctl_sctp_mem[1] = limit;