51 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
53 #include <linux/types.h>
54 #include <linux/fcntl.h>
55 #include <linux/poll.h>
58 #include <linux/slab.h>
73 static u32 idr_low = 1;
85 struct net *
net = sock_net(sk);
92 sp = sctp_sk((
struct sock *)sk);
100 sock_hold(asoc->
base.sk);
108 asoc->
base.malloced = 0;
184 (
unsigned long)asoc);
190 asoc->c.sinit_max_instreams = sp->
initmsg.sinit_max_instreams;
191 asoc->c.sinit_num_ostreams = sp->
initmsg.sinit_num_ostreams;
192 asoc->max_init_attempts = sp->
initmsg.sinit_max_attempts;
194 asoc->max_init_timeo =
212 asoc->a_rwnd = asoc->rwnd;
215 asoc->rwnd_press = 0;
221 asoc->sndbuf_used = 0;
229 asoc->peer.i.init_tag = 0;
230 asoc->c.peer_vtag = 0;
232 asoc->c.peer_ttag = 0;
233 asoc->c.my_port = ep->
base.bind_addr.port;
237 asoc->next_tsn = asoc->c.initial_tsn;
239 asoc->ctsn_ack_point = asoc->next_tsn - 1;
240 asoc->adv_peer_ack_point = asoc->ctsn_ack_point;
241 asoc->highest_sacked = asoc->ctsn_ack_point;
242 asoc->last_cwr_tsn = asoc->ctsn_ack_point;
243 asoc->unack_data = 0;
255 asoc->addip_serial = asoc->c.initial_tsn;
257 INIT_LIST_HEAD(&asoc->addip_chunk_list);
258 INIT_LIST_HEAD(&asoc->asconf_ack_list);
261 INIT_LIST_HEAD(&asoc->peer.transport_addr_list);
262 asoc->peer.transport_count = 0;
275 asoc->peer.sack_needed = 1;
276 asoc->peer.sack_cnt = 0;
277 asoc->peer.sack_generation = 1;
284 asoc->peer.asconf_capable = 0;
285 if (net->sctp.addip_noauth)
286 asoc->peer.asconf_capable = 1;
287 asoc->asconf_addr_del_pending =
NULL;
288 asoc->src_out_of_asoc_ok = 0;
289 asoc->new_transport =
NULL;
310 asoc->peer.ipv4_address = 1;
311 if (asoc->base.sk->sk_family ==
PF_INET6)
312 asoc->peer.ipv6_address = 1;
313 INIT_LIST_HEAD(&asoc->asocs);
325 INIT_LIST_HEAD(&asoc->endpoint_shared_keys);
331 asoc->asoc_shared_key =
NULL;
333 asoc->default_hmac_id = 0;
352 sock_put(asoc->base.sk);
358 const struct sock *sk,
368 if (!sctp_association_init(asoc, ep, sk, scope, gfp))
371 asoc->
base.malloced = 1;
434 if (timer_pending(&asoc->
timers[i]) &&
452 asoc->
peer.transport_count = 0;
475 sock_put(asoc->
base.sk);
478 spin_lock_bh(&sctp_assocs_id_lock);
480 spin_unlock_bh(&sctp_assocs_id_lock);
485 if (asoc->
base.malloced) {
500 if (asoc->
peer.primary_path !=
NULL &&
501 asoc->
peer.primary_path != transport)
534 if (transport->
cacc.changeover_active)
535 transport->
cacc.cycling_changeover = changeover;
540 transport->
cacc.changeover_active = changeover;
564 if (asoc->
peer.retran_path == peer)
571 pos = asoc->
peer.transport_addr_list.next;
575 if (asoc->
peer.primary_path == peer)
577 if (asoc->
peer.active_path == peer)
579 if (asoc->
peer.retran_path == peer)
581 if (asoc->
peer.last_data_from == peer)
634 asoc->
peer.transport_count--;
643 const int peer_state)
645 struct net *net = sock_net(asoc->
base.sk);
650 sp = sctp_sk(asoc->
base.sk);
653 port =
ntohs(addr->
v4.sin_port);
656 " port: %d state:%d\n",
663 if (0 == asoc->
peer.port)
765 peer->
state = peer_state;
769 asoc->
peer.transport_count++;
772 if (!asoc->
peer.primary_path) {
774 asoc->
peer.retran_path = peer;
777 if (asoc->
peer.active_path == asoc->
peer.retran_path &&
779 asoc->
peer.retran_path = peer;
851 bool ulp_notify =
true;
950 first != asoc->
peer.primary_path) {
952 first = asoc->
peer.primary_path;
959 first = asoc->
peer.primary_path;
960 second = asoc->
peer.primary_path;
980 sctp_association_destroy(asoc);
1063 active = asoc->
peer.active_path;
1078 if (transport == active)
1100 if ((
htons(asoc->
base.bind_addr.port) == laddr->
v4.sin_port) &&
1102 net_eq(sock_net(asoc->
base.sk), net)) {
1108 sctp_sk(asoc->
base.sk)))
1122 base.inqueue.immediate);
1123 struct net *net = sock_net(asoc->
base.sk);
1134 inqueue = &asoc->
base.inqueue;
1137 state = asoc->
state;
1138 subtype = SCTP_ST_CHUNK(chunk->
chunk_hdr->type);
1168 if (asoc->
base.dead)
1181 struct sctp_sock *newsp = sctp_sk(newsk);
1182 struct sock *oldsk = assoc->
base.sk;
1187 list_del_init(&assoc->
asocs);
1195 sock_put(assoc->
base.sk);
1198 assoc->
ep = newsp->
ep;
1202 assoc->
base.sk = newsk;
1203 sock_hold(assoc->
base.sk);
1218 asoc->
peer.rwnd =
new->peer.rwnd;
1219 asoc->
peer.sack_needed =
new->peer.sack_needed;
1220 asoc->
peer.i =
new->peer.i;
1276 asoc->
ssnmap =
new->ssnmap;
1292 asoc->
peer.peer_random =
new->peer.peer_random;
1293 new->peer.peer_random =
NULL;
1296 asoc->
peer.peer_chunks =
new->peer.peer_chunks;
1297 new->peer.peer_chunks =
NULL;
1300 asoc->
peer.peer_hmacs =
new->peer.peer_hmacs;
1301 new->peer.peer_hmacs =
NULL;
1318 if (asoc->
peer.transport_count == 1)
1322 t = asoc->
peer.retran_path;
1328 if (pos->
next == head)
1339 if (t == asoc->
peer.retran_path) {
1359 asoc->
peer.retran_path =
t;
1361 t = asoc->
peer.retran_path;
1380 return asoc->
peer.active_path;
1382 if (last_sent_to == asoc->
peer.retran_path)
1384 return asoc->
peer.retran_path;
1406 if (!pmtu || (t->
pathmtu < pmtu))
1412 asoc->
frag_point = sctp_frag_point(asoc, pmtu);
1422 struct net *net = sock_net(asoc->
base.sk);
1423 switch (asoc->
state) {
1430 (asoc->
base.sk->sk_rcvbuf >> net->sctp.rwnd_upd_shift),
1464 asoc->
rwnd += change;
1469 "- %u\n", __func__, asoc, len, asoc->
rwnd,
1477 if (sctp_peer_needs_update(asoc)) {
1480 "rwnd: %u a_rwnd: %u\n", __func__,
1486 asoc->
peer.sack_needed = 0;
1492 if (timer_pending(timer) &&
del_timer(timer))
1506 if (asoc->
ep->rcvbuf_policy)
1516 if (rx_count >= asoc->
base.sk->sk_rcvbuf)
1519 if (asoc->
rwnd >= len) {
1530 __func__, asoc, len, asoc->
rwnd,
1546 if (asoc->
peer.ipv4_address)
1548 if (asoc->
peer.ipv6_address)
1552 &asoc->
base.bind_addr,
1553 &asoc->
ep->base.bind_addr,
1567 asoc->
ep->base.bind_addr.port, gfp);
1576 if ((asoc->
base.bind_addr.port ==
ntohs(laddr->
v4.sin_port)) &&
1578 sctp_sk(asoc->
base.sk)))
1599 idr_low, &assoc_id);
1601 idr_low = assoc_id + 1;
1622 list_del_init(&asconf->
list);
1683 sctp_assoc_free_asconf_acks(asoc);
1686 sctp_assoc_free_asconf_queue(asoc);