hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/net/sctp/associola.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* SCTP kernel implementation
23 * (C) Copyright IBM Corp. 2001, 2004
34 * Copyright (c) 1999-2000 Cisco, Inc.
....@@ -8,22 +9,6 @@
89 * This file is part of the SCTP kernel implementation
910 *
1011 * This module provides the abstraction for an SCTP association.
11
- *
12
- * This SCTP implementation is free software;
13
- * you can redistribute it and/or modify it under the terms of
14
- * the GNU General Public License as published by
15
- * the Free Software Foundation; either version 2, or (at your option)
16
- * any later version.
17
- *
18
- * This SCTP implementation is distributed in the hope that it
19
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20
- * ************************
21
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22
- * See the GNU General Public License for more details.
23
- *
24
- * You should have received a copy of the GNU General Public License
25
- * along with GNU CC; see the file COPYING. If not, see
26
- * <http://www.gnu.org/licenses/>.
2712 *
2813 * Please send any bug reports or fixes you make to the
2914 * email address(es):
....@@ -69,7 +54,6 @@
6954 const struct sock *sk,
7055 enum sctp_scope scope, gfp_t gfp)
7156 {
72
- struct net *net = sock_net(sk);
7357 struct sctp_sock *sp;
7458 struct sctp_paramhdr *p;
7559 int i;
....@@ -102,7 +86,9 @@
10286 * socket values.
10387 */
10488 asoc->max_retrans = sp->assocparams.sasoc_asocmaxrxt;
105
- asoc->pf_retrans = net->sctp.pf_retrans;
89
+ asoc->pf_retrans = sp->pf_retrans;
90
+ asoc->ps_retrans = sp->ps_retrans;
91
+ asoc->pf_expose = sp->pf_expose;
10692
10793 asoc->rto_initial = msecs_to_jiffies(sp->rtoinfo.srto_initial);
10894 asoc->rto_max = msecs_to_jiffies(sp->rtoinfo.srto_max);
....@@ -132,6 +118,8 @@
132118 * in a burst.
133119 */
134120 asoc->max_burst = sp->max_burst;
121
+
122
+ asoc->subscribe = sp->subscribe;
135123
136124 /* initialize association timers */
137125 asoc->timeouts[SCTP_EVENT_TIMEOUT_T1_COOKIE] = asoc->rto_initial;
....@@ -228,14 +216,6 @@
228216 asoc->peer.sack_needed = 1;
229217 asoc->peer.sack_generation = 1;
230218
231
- /* Assume that the peer will tell us if he recognizes ASCONF
232
- * as part of INIT exchange.
233
- * The sctp_addip_noauth option is there for backward compatibility
234
- * and will revert old behavior.
235
- */
236
- if (net->sctp.addip_noauth)
237
- asoc->peer.asconf_capable = 1;
238
-
239219 /* Create an input queue. */
240220 sctp_inq_init(&asoc->base.inqueue);
241221 sctp_inq_set_th_handler(&asoc->base.inqueue, sctp_assoc_bh_rcv);
....@@ -246,9 +226,8 @@
246226 if (!sctp_ulpq_init(&asoc->ulpq, asoc))
247227 goto fail_init;
248228
249
- if (sctp_stream_init(&asoc->stream, asoc->c.sinit_num_ostreams,
250
- 0, gfp))
251
- goto fail_init;
229
+ if (sctp_stream_init(&asoc->stream, asoc->c.sinit_num_ostreams, 0, gfp))
230
+ goto stream_free;
252231
253232 /* Initialize default path MTU. */
254233 asoc->pathmtu = sp->pathmtu;
....@@ -275,8 +254,6 @@
275254 goto stream_free;
276255
277256 asoc->active_key_id = ep->active_key_id;
278
- asoc->prsctp_enable = ep->prsctp_enable;
279
- asoc->reconf_enable = ep->reconf_enable;
280257 asoc->strreset_enable = ep->strreset_enable;
281258
282259 /* Save the hmacs and chunks list into this association */
....@@ -349,7 +326,7 @@
349326 * socket.
350327 */
351328 if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))
352
- sk->sk_ack_backlog--;
329
+ sk_acceptq_removed(sk);
353330 }
354331
355332 /* Mark as dead, so other users can know this structure is
....@@ -454,6 +431,8 @@
454431 changeover = 1 ;
455432
456433 asoc->peer.primary_path = transport;
434
+ sctp_ulpevent_notify_peer_addr_change(transport,
435
+ SCTP_ADDR_MADE_PRIM, 0);
457436
458437 /* Set a default msg_name for events. */
459438 memcpy(&asoc->peer.primary_addr, &transport->ipaddr,
....@@ -594,6 +573,7 @@
594573
595574 asoc->peer.transport_count--;
596575
576
+ sctp_ulpevent_notify_peer_addr_change(peer, SCTP_ADDR_REMOVED, 0);
597577 sctp_transport_free(peer);
598578 }
599579
....@@ -603,7 +583,6 @@
603583 const gfp_t gfp,
604584 const int peer_state)
605585 {
606
- struct net *net = sock_net(asoc->base.sk);
607586 struct sctp_transport *peer;
608587 struct sctp_sock *sp;
609588 unsigned short port;
....@@ -633,7 +612,7 @@
633612 return peer;
634613 }
635614
636
- peer = sctp_transport_new(net, addr, gfp);
615
+ peer = sctp_transport_new(asoc->base.net, addr, gfp);
637616 if (!peer)
638617 return NULL;
639618
....@@ -649,6 +628,8 @@
649628
650629 /* And the partial failure retrans threshold */
651630 peer->pf_retrans = asoc->pf_retrans;
631
+ /* And the primary path switchover retrans threshold */
632
+ peer->ps_retrans = asoc->ps_retrans;
652633
653634 /* Initialize the peer's SACK delay timeout based on the
654635 * association configured value.
....@@ -732,6 +713,8 @@
732713 list_add_tail_rcu(&peer->transports, &asoc->peer.transport_addr_list);
733714 asoc->peer.transport_count++;
734715
716
+ sctp_ulpevent_notify_peer_addr_change(peer, SCTP_ADDR_ADDED, 0);
717
+
735718 /* If we do not yet have a primary path, set one. */
736719 if (!asoc->peer.primary_path) {
737720 sctp_assoc_set_primary(asoc, peer);
....@@ -806,9 +789,7 @@
806789 enum sctp_transport_cmd command,
807790 sctp_sn_error_t error)
808791 {
809
- struct sctp_ulpevent *event;
810
- struct sockaddr_storage addr;
811
- int spc_state = 0;
792
+ int spc_state = SCTP_ADDR_AVAILABLE;
812793 bool ulp_notify = true;
813794
814795 /* Record the transition on the transport. */
....@@ -818,19 +799,13 @@
818799 * to heartbeat success, report the SCTP_ADDR_CONFIRMED
819800 * state to the user, otherwise report SCTP_ADDR_AVAILABLE.
820801 */
821
- if (SCTP_UNCONFIRMED == transport->state &&
822
- SCTP_HEARTBEAT_SUCCESS == error)
823
- spc_state = SCTP_ADDR_CONFIRMED;
824
- else
825
- spc_state = SCTP_ADDR_AVAILABLE;
826
- /* Don't inform ULP about transition from PF to
827
- * active state and set cwnd to 1 MTU, see SCTP
828
- * Quick failover draft section 5.1, point 5
829
- */
830
- if (transport->state == SCTP_PF) {
802
+ if (transport->state == SCTP_PF &&
803
+ asoc->pf_expose != SCTP_PF_EXPOSE_ENABLE)
831804 ulp_notify = false;
832
- transport->cwnd = asoc->pathmtu;
833
- }
805
+ else if (transport->state == SCTP_UNCONFIRMED &&
806
+ error == SCTP_HEARTBEAT_SUCCESS)
807
+ spc_state = SCTP_ADDR_CONFIRMED;
808
+
834809 transport->state = SCTP_ACTIVE;
835810 break;
836811
....@@ -839,19 +814,21 @@
839814 * to inactive state. Also, release the cached route since
840815 * there may be a better route next time.
841816 */
842
- if (transport->state != SCTP_UNCONFIRMED)
817
+ if (transport->state != SCTP_UNCONFIRMED) {
843818 transport->state = SCTP_INACTIVE;
844
- else {
819
+ spc_state = SCTP_ADDR_UNREACHABLE;
820
+ } else {
845821 sctp_transport_dst_release(transport);
846822 ulp_notify = false;
847823 }
848
-
849
- spc_state = SCTP_ADDR_UNREACHABLE;
850824 break;
851825
852826 case SCTP_TRANSPORT_PF:
853827 transport->state = SCTP_PF;
854
- ulp_notify = false;
828
+ if (asoc->pf_expose != SCTP_PF_EXPOSE_ENABLE)
829
+ ulp_notify = false;
830
+ else
831
+ spc_state = SCTP_ADDR_POTENTIALLY_FAILED;
855832 break;
856833
857834 default:
....@@ -861,16 +838,9 @@
861838 /* Generate and send a SCTP_PEER_ADDR_CHANGE notification
862839 * to the user.
863840 */
864
- if (ulp_notify) {
865
- memset(&addr, 0, sizeof(struct sockaddr_storage));
866
- memcpy(&addr, &transport->ipaddr,
867
- transport->af_specific->sockaddr_len);
868
-
869
- event = sctp_ulpevent_make_peer_addr_change(asoc, &addr,
870
- 0, spc_state, error, GFP_ATOMIC);
871
- if (event)
872
- asoc->stream.si->enqueue_event(&asoc->ulpq, event);
873
- }
841
+ if (ulp_notify)
842
+ sctp_ulpevent_notify_peer_addr_change(transport,
843
+ spc_state, error);
874844
875845 /* Select new active and retran paths. */
876846 sctp_select_active_and_retran_path(asoc);
....@@ -1002,7 +972,7 @@
1002972 struct sctp_association *asoc =
1003973 container_of(work, struct sctp_association,
1004974 base.inqueue.immediate);
1005
- struct net *net = sock_net(asoc->base.sk);
975
+ struct net *net = asoc->base.net;
1006976 union sctp_subtype subtype;
1007977 struct sctp_endpoint *ep;
1008978 struct sctp_chunk *chunk;
....@@ -1102,7 +1072,7 @@
11021072
11031073 /* Decrement the backlog value for a TCP-style socket. */
11041074 if (sctp_style(oldsk, TCP))
1105
- oldsk->sk_ack_backlog--;
1075
+ sk_acceptq_removed(oldsk);
11061076
11071077 /* Release references to the old endpoint and the sock. */
11081078 sctp_endpoint_put(assoc->ep);
....@@ -1181,8 +1151,7 @@
11811151 /* Add any peer addresses from the new association. */
11821152 list_for_each_entry(trans, &new->peer.transport_addr_list,
11831153 transports)
1184
- if (!sctp_assoc_lookup_paddr(asoc, &trans->ipaddr) &&
1185
- !sctp_assoc_add_peer(asoc, &trans->ipaddr,
1154
+ if (!sctp_assoc_add_peer(asoc, &trans->ipaddr,
11861155 GFP_ATOMIC, trans->state))
11871156 return -ENOMEM;
11881157
....@@ -1380,7 +1349,7 @@
13801349 }
13811350
13821351 /* We did not find anything useful for a possible retransmission
1383
- * path; either primary path that we found is the the same as
1352
+ * path; either primary path that we found is the same as
13841353 * the current one, or we didn't generally find an active one.
13851354 */
13861355 if (trans_sec == NULL)
....@@ -1470,7 +1439,8 @@
14701439 /* Should we send a SACK to update our peer? */
14711440 static inline bool sctp_peer_needs_update(struct sctp_association *asoc)
14721441 {
1473
- struct net *net = sock_net(asoc->base.sk);
1442
+ struct net *net = asoc->base.net;
1443
+
14741444 switch (asoc->state) {
14751445 case SCTP_STATE_ESTABLISHED:
14761446 case SCTP_STATE_SHUTDOWN_PENDING:
....@@ -1565,7 +1535,7 @@
15651535
15661536 /* If we've reached or overflowed our receive buffer, announce
15671537 * a 0 rwnd if rwnd would still be positive. Store the
1568
- * the potential pressure overflow so that the window can be restored
1538
+ * potential pressure overflow so that the window can be restored
15691539 * back to original value.
15701540 */
15711541 if (rx_count >= asoc->base.sk->sk_rcvbuf)
....@@ -1607,7 +1577,7 @@
16071577 if (asoc->peer.ipv6_address)
16081578 flags |= SCTP_ADDR6_PEERSUPP;
16091579
1610
- return sctp_bind_addr_copy(sock_net(asoc->base.sk),
1580
+ return sctp_bind_addr_copy(asoc->base.net,
16111581 &asoc->base.bind_addr,
16121582 &asoc->ep->base.bind_addr,
16131583 scope, gfp, flags);
....@@ -1653,8 +1623,11 @@
16531623 if (preload)
16541624 idr_preload(gfp);
16551625 spin_lock_bh(&sctp_assocs_id_lock);
1656
- /* 0 is not a valid assoc_id, must be >= 1 */
1657
- ret = idr_alloc_cyclic(&sctp_assocs_id, asoc, 1, 0, GFP_NOWAIT);
1626
+ /* 0, 1, 2 are used as SCTP_FUTURE_ASSOC, SCTP_CURRENT_ASSOC and
1627
+ * SCTP_ALL_ASSOC, so an available id must be > SCTP_ALL_ASSOC.
1628
+ */
1629
+ ret = idr_alloc_cyclic(&sctp_assocs_id, asoc, SCTP_ALL_ASSOC + 1, 0,
1630
+ GFP_NOWAIT);
16581631 spin_unlock_bh(&sctp_assocs_id_lock);
16591632 if (preload)
16601633 idr_preload_end();