hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/net/sctp/protocol.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.
....@@ -9,22 +10,6 @@
910 * This file is part of the SCTP kernel implementation
1011 *
1112 * Initialization/cleanup for SCTP protocol support.
12
- *
13
- * This SCTP implementation is free software;
14
- * you can redistribute it and/or modify it under the terms of
15
- * the GNU General Public License as published by
16
- * the Free Software Foundation; either version 2, or (at your option)
17
- * any later version.
18
- *
19
- * This SCTP implementation is distributed in the hope that it
20
- * will be useful, but WITHOUT ANY WARRANTY; without even the implied
21
- * ************************
22
- * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23
- * See the GNU General Public License for more details.
24
- *
25
- * You should have received a copy of the GNU General Public License
26
- * along with GNU CC; see the file COPYING. If not, see
27
- * <http://www.gnu.org/licenses/>.
2813 *
2914 * Please send any bug reports or fixes you make to the
3015 * email address(es):
....@@ -46,7 +31,7 @@
4631 #include <linux/netdevice.h>
4732 #include <linux/inetdevice.h>
4833 #include <linux/seq_file.h>
49
-#include <linux/bootmem.h>
34
+#include <linux/memblock.h>
5035 #include <linux/highmem.h>
5136 #include <linux/swap.h>
5237 #include <linux/slab.h>
....@@ -96,7 +81,7 @@
9681 return;
9782 }
9883
99
- for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) {
84
+ in_dev_for_each_ifa_rcu(ifa, in_dev) {
10085 /* Add the address to the local list. */
10186 addr = kzalloc(sizeof(*addr), GFP_ATOMIC);
10287 if (addr) {
....@@ -373,7 +358,7 @@
373358 if (addr->v4.sin_addr.s_addr != htonl(INADDR_ANY) &&
374359 ret != RTN_LOCAL &&
375360 !sp->inet.freebind &&
376
- !net->ipv4.sysctl_ip_nonlocal_bind)
361
+ !READ_ONCE(net->ipv4.sysctl_ip_nonlocal_bind))
377362 return 0;
378363
379364 if (ipv6_only_sock(sctp_opt2sk(sp)))
....@@ -392,7 +377,7 @@
392377 * Level 3 - private addresses.
393378 * Level 4 - global addresses
394379 * For INIT and INIT-ACK address list, let L be the level of
395
- * of requested destination address, sender and receiver
380
+ * requested destination address, sender and receiver
396381 * SHOULD include all of its addresses with level greater
397382 * than or equal to L.
398383 *
....@@ -1048,6 +1033,7 @@
10481033 .getname = inet_getname, /* Semantics are different. */
10491034 .poll = sctp_poll,
10501035 .ioctl = inet_ioctl,
1036
+ .gettstamp = sock_gettstamp,
10511037 .listen = sctp_inet_listen,
10521038 .shutdown = inet_shutdown, /* Looks harmless. */
10531039 .setsockopt = sock_common_setsockopt, /* IP_SOL IP_OPTION is a problem */
....@@ -1056,10 +1042,6 @@
10561042 .recvmsg = inet_recvmsg,
10571043 .mmap = sock_no_mmap,
10581044 .sendpage = sock_no_sendpage,
1059
-#ifdef CONFIG_COMPAT
1060
- .compat_setsockopt = compat_sock_common_setsockopt,
1061
- .compat_getsockopt = compat_sock_common_getsockopt,
1062
-#endif
10631045 };
10641046
10651047 /* Registration with AF_INET family. */
....@@ -1113,10 +1095,6 @@
11131095 .net_header_len = sizeof(struct iphdr),
11141096 .sockaddr_len = sizeof(struct sockaddr_in),
11151097 .ip_options_len = sctp_v4_ip_options_len,
1116
-#ifdef CONFIG_COMPAT
1117
- .compat_setsockopt = compat_ip_setsockopt,
1118
- .compat_getsockopt = compat_ip_getsockopt,
1119
-#endif
11201098 };
11211099
11221100 struct sctp_pf *sctp_get_pf_specific(sa_family_t family)
....@@ -1253,8 +1231,14 @@
12531231 /* Max.Burst - 4 */
12541232 net->sctp.max_burst = SCTP_DEFAULT_MAX_BURST;
12551233
1234
+ /* Disable of Primary Path Switchover by default */
1235
+ net->sctp.ps_retrans = SCTP_PS_RETRANS_MAX;
1236
+
12561237 /* Enable pf state by default */
12571238 net->sctp.pf_enable = 1;
1239
+
1240
+ /* Ignore pf exposure feature by default */
1241
+ net->sctp.pf_expose = SCTP_PF_EXPOSE_UNSET;
12581242
12591243 /* Association.Max.Retrans - 10 attempts
12601244 * Path.Max.Retrans - 5 attempts (per destination address)
....@@ -1289,6 +1273,9 @@
12891273
12901274 /* Disable AUTH by default. */
12911275 net->sctp.auth_enable = 0;
1276
+
1277
+ /* Enable ECN by default. */
1278
+ net->sctp.ecn_enable = 1;
12921279
12931280 /* Set SCOPE policy to enabled */
12941281 net->sctp.scope_policy = SCTP_SCOPE_POLICY_ENABLE;
....@@ -1386,14 +1373,15 @@
13861373 /* Initialize the universe into something sensible. */
13871374 static __init int sctp_init(void)
13881375 {
1389
- int i;
1390
- int status = -EINVAL;
1391
- unsigned long goal;
1376
+ unsigned long nr_pages = totalram_pages();
13921377 unsigned long limit;
1393
- int max_share;
1394
- int order;
1395
- int num_entries;
1378
+ unsigned long goal;
13961379 int max_entry_order;
1380
+ int num_entries;
1381
+ int max_share;
1382
+ int status;
1383
+ int order;
1384
+ int i;
13971385
13981386 sock_skb_cb_check_size(sizeof(struct sctp_ulpevent));
13991387
....@@ -1448,10 +1436,10 @@
14481436 * The methodology is similar to that of the tcp hash tables.
14491437 * Though not identical. Start by getting a goal size
14501438 */
1451
- if (totalram_pages >= (128 * 1024))
1452
- goal = totalram_pages >> (22 - PAGE_SHIFT);
1439
+ if (nr_pages >= (128 * 1024))
1440
+ goal = nr_pages >> (22 - PAGE_SHIFT);
14531441 else
1454
- goal = totalram_pages >> (24 - PAGE_SHIFT);
1442
+ goal = nr_pages >> (24 - PAGE_SHIFT);
14551443
14561444 /* Then compute the page order for said goal */
14571445 order = get_order(goal);
....@@ -1501,10 +1489,10 @@
15011489 num_entries = (1UL << order) * PAGE_SIZE /
15021490 sizeof(struct sctp_bind_hashbucket);
15031491
1504
- /* And finish by rounding it down to the nearest power of two
1505
- * this wastes some memory of course, but its needed because
1492
+ /* And finish by rounding it down to the nearest power of two.
1493
+ * This wastes some memory of course, but it's needed because
15061494 * the hash function operates based on the assumption that
1507
- * that the number of entries is a power of two
1495
+ * the number of entries is a power of two.
15081496 */
15091497 sctp_port_hashsize = rounddown_pow_of_two(num_entries);
15101498