233
void sctp_local_addr_free(struct rcu_head *head)
235
struct sctp_sockaddr_entry *e = container_of(head,
236
struct sctp_sockaddr_entry, rcu);
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)
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,
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;
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.
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)
461
struct sctp_association *asoc = t->asoc;
470
462
struct rtable *rt;
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;
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;
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);
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;
491
484
SCTP_DEBUG_PRINTK("%s: DST:%pI4, SRC:%pI4 - ",
492
__func__, &fl.fl4_dst, &fl.fl4_src);
485
__func__, &fl4->daddr, &fl4->saddr);
494
if (!ip_route_output_key(&init_net, &rt, &fl)) {
487
rt = ip_route_output_key(&init_net, fl4);
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.
510
sctp_v4_dst_saddr(&dst_saddr, dst, htons(bp->port));
503
sctp_v4_dst_saddr(&dst_saddr, fl4, htons(bp->port));
512
505
list_for_each_entry_rcu(laddr, &bp->address_list, list) {
513
506
if (!laddr->valid || (laddr->state != SCTP_ADDR_SRC))
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);
546
540
rcu_read_unlock();
549
544
SCTP_DEBUG_PRINTK("rt_dst:%pI4, rt_src:%pI4\n",
550
&rt->rt_dst, &rt->rt_src);
545
&fl4->daddr, &fl4->saddr);
552
547
SCTP_DEBUG_PRINTK("NO ROUTE\n");
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.
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,
566
struct rtable *rt = (struct rtable *)dst;
557
union sctp_addr *saddr = &t->saddr;
558
struct rtable *rt = (struct rtable *)t->dst;
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;
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);
859
847
inet->pmtudisc = transport->param_flags & SPP_PMTUD_ENABLE ?
860
848
IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
862
850
SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS);
863
return ip_queue_xmit(skb);
851
return ip_queue_xmit(skb, &transport->fl);
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,
1161
1147
/* Initialize handle used for association ids. */
1162
1148
idr_init(&sctp_assocs_id);
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
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;