hc
2024-05-10 37f49e37ab4cb5d0bc4c60eb5c6d4dd57db767bb
kernel/net/sctp/sm_sideeffect.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 Cisco, Inc.
....@@ -8,22 +9,6 @@
89 * These functions work with the state functions in sctp_sm_statefuns.c
910 * to implement that state operations. These functions implement the
1011 * steps which require modifying existing data structures.
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):
....@@ -52,7 +37,7 @@
5237 #include <net/sctp/sm.h>
5338 #include <net/sctp/stream_sched.h>
5439
55
-static int sctp_cmd_interpreter(enum sctp_event event_type,
40
+static int sctp_cmd_interpreter(enum sctp_event_type event_type,
5641 union sctp_subtype subtype,
5742 enum sctp_state state,
5843 struct sctp_endpoint *ep,
....@@ -61,7 +46,7 @@
6146 enum sctp_disposition status,
6247 struct sctp_cmd_seq *commands,
6348 gfp_t gfp);
64
-static int sctp_side_effects(enum sctp_event event_type,
49
+static int sctp_side_effects(enum sctp_event_type event_type,
6550 union sctp_subtype subtype,
6651 enum sctp_state state,
6752 struct sctp_endpoint *ep,
....@@ -473,6 +458,10 @@
473458 goto out_unlock;
474459 }
475460
461
+ /* This happens when the response arrives after the timer is triggered. */
462
+ if (!asoc->strreset_chunk)
463
+ goto out_unlock;
464
+
476465 error = sctp_do_sm(net, SCTP_EVENT_T_TIMEOUT,
477466 SCTP_ST_TIMEOUT(SCTP_EVENT_TIMEOUT_RECONF),
478467 asoc->state, asoc->ep, asoc,
....@@ -531,8 +520,6 @@
531520 struct sctp_transport *transport,
532521 int is_hb)
533522 {
534
- struct net *net = sock_net(asoc->base.sk);
535
-
536523 /* The check for association's overall error counter exceeding the
537524 * threshold is done in the state function.
538525 */
....@@ -559,10 +546,10 @@
559546 * is SCTP_ACTIVE, then mark this transport as Partially Failed,
560547 * see SCTP Quick Failover Draft, section 5.1
561548 */
562
- if (net->sctp.pf_enable &&
563
- (transport->state == SCTP_ACTIVE) &&
564
- (transport->error_count < transport->pathmaxrxt) &&
565
- (transport->error_count > transport->pf_retrans)) {
549
+ if (asoc->base.net->sctp.pf_enable &&
550
+ transport->state == SCTP_ACTIVE &&
551
+ transport->error_count < transport->pathmaxrxt &&
552
+ transport->error_count > transport->pf_retrans) {
566553
567554 sctp_assoc_control_transport(asoc, transport,
568555 SCTP_TRANSPORT_PF,
....@@ -581,6 +568,11 @@
581568 SCTP_TRANSPORT_DOWN,
582569 SCTP_FAILED_THRESHOLD);
583570 }
571
+
572
+ if (transport->error_count > transport->ps_retrans &&
573
+ asoc->peer.primary_path == transport &&
574
+ asoc->peer.active_path != transport)
575
+ sctp_assoc_set_primary(asoc, asoc->peer.active_path);
584576
585577 /* E2) For the destination address for which the timer
586578 * expires, set RTO <- RTO * 2 ("back off the timer"). The
....@@ -623,7 +615,7 @@
623615 /* Worker routine to handle SCTP_CMD_ASSOC_FAILED. */
624616 static void sctp_cmd_assoc_failed(struct sctp_cmd_seq *commands,
625617 struct sctp_association *asoc,
626
- enum sctp_event event_type,
618
+ enum sctp_event_type event_type,
627619 union sctp_subtype subtype,
628620 struct sctp_chunk *chunk,
629621 unsigned int error)
....@@ -808,10 +800,8 @@
808800 int err = 0;
809801
810802 if (sctp_outq_sack(&asoc->outqueue, chunk)) {
811
- struct net *net = sock_net(asoc->base.sk);
812
-
813803 /* There are no more TSNs awaiting SACK. */
814
- err = sctp_do_sm(net, SCTP_EVENT_T_OTHER,
804
+ err = sctp_do_sm(asoc->base.net, SCTP_EVENT_T_OTHER,
815805 SCTP_ST_OTHER(SCTP_EVENT_NO_PENDING_TSN),
816806 asoc->state, asoc->ep, asoc, NULL,
817807 GFP_ATOMIC);
....@@ -844,7 +834,7 @@
844834 struct sctp_association *asoc,
845835 struct sctp_association *new)
846836 {
847
- struct net *net = sock_net(asoc->base.sk);
837
+ struct net *net = asoc->base.net;
848838 struct sctp_chunk *abort;
849839
850840 if (!sctp_assoc_update(asoc, new))
....@@ -1141,7 +1131,7 @@
11411131 * If you want to understand all of lksctp, this is a
11421132 * good place to start.
11431133 */
1144
-int sctp_do_sm(struct net *net, enum sctp_event event_type,
1134
+int sctp_do_sm(struct net *net, enum sctp_event_type event_type,
11451135 union sctp_subtype subtype, enum sctp_state state,
11461136 struct sctp_endpoint *ep, struct sctp_association *asoc,
11471137 void *event_arg, gfp_t gfp)
....@@ -1178,7 +1168,7 @@
11781168 /*****************************************************************
11791169 * This the master state function side effect processing function.
11801170 *****************************************************************/
1181
-static int sctp_side_effects(enum sctp_event event_type,
1171
+static int sctp_side_effects(enum sctp_event_type event_type,
11821172 union sctp_subtype subtype,
11831173 enum sctp_state state,
11841174 struct sctp_endpoint *ep,
....@@ -1251,7 +1241,10 @@
12511241 default:
12521242 pr_err("impossible disposition %d in state %d, event_type %d, event_id %d\n",
12531243 status, state, event_type, subtype.chunk);
1254
- BUG();
1244
+ error = status;
1245
+ if (error >= 0)
1246
+ error = -EINVAL;
1247
+ WARN_ON_ONCE(1);
12551248 break;
12561249 }
12571250
....@@ -1264,7 +1257,7 @@
12641257 ********************************************************************/
12651258
12661259 /* This is the side-effect interpreter. */
1267
-static int sctp_cmd_interpreter(enum sctp_event event_type,
1260
+static int sctp_cmd_interpreter(enum sctp_event_type event_type,
12681261 union sctp_subtype subtype,
12691262 enum sctp_state state,
12701263 struct sctp_endpoint *ep,
....@@ -1530,7 +1523,7 @@
15301523
15311524 if (timer_pending(timer))
15321525 break;
1533
- /* fall through */
1526
+ fallthrough;
15341527
15351528 case SCTP_CMD_TIMER_START:
15361529 timer = &asoc->timers[cmd->obj.to];