| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
|---|
| 1 | 2 | /* SCTP kernel implementation |
|---|
| 2 | 3 | * (C) Copyright IBM Corp. 2001, 2004 |
|---|
| 3 | 4 | * Copyright (c) 1999-2000 Cisco, Inc. |
|---|
| .. | .. |
|---|
| 5 | 6 | * Copyright (c) 2001 Intel Corp. |
|---|
| 6 | 7 | * |
|---|
| 7 | 8 | * This file is part of the SCTP kernel implementation |
|---|
| 8 | | - * |
|---|
| 9 | | - * This SCTP implementation is free software; |
|---|
| 10 | | - * you can redistribute it and/or modify it under the terms of |
|---|
| 11 | | - * the GNU General Public License as published by |
|---|
| 12 | | - * the Free Software Foundation; either version 2, or (at your option) |
|---|
| 13 | | - * any later version. |
|---|
| 14 | | - * |
|---|
| 15 | | - * This SCTP implementation is distributed in the hope that it |
|---|
| 16 | | - * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
|---|
| 17 | | - * ************************ |
|---|
| 18 | | - * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 19 | | - * See the GNU General Public License for more details. |
|---|
| 20 | | - * |
|---|
| 21 | | - * You should have received a copy of the GNU General Public License |
|---|
| 22 | | - * along with GNU CC; see the file COPYING. If not, see |
|---|
| 23 | | - * <http://www.gnu.org/licenses/>. |
|---|
| 24 | 9 | * |
|---|
| 25 | 10 | * Please send any bug reports or fixes you make to the |
|---|
| 26 | 11 | * email addresses: |
|---|
| .. | .. |
|---|
| 48 | 33 | #define __sctp_structs_h__ |
|---|
| 49 | 34 | |
|---|
| 50 | 35 | #include <linux/ktime.h> |
|---|
| 36 | +#include <linux/generic-radix-tree.h> |
|---|
| 51 | 37 | #include <linux/rhashtable-types.h> |
|---|
| 52 | 38 | #include <linux/socket.h> /* linux/in.h needs this!! */ |
|---|
| 53 | 39 | #include <linux/in.h> /* We get struct sockaddr_in. */ |
|---|
| .. | .. |
|---|
| 57 | 43 | #include <linux/atomic.h> /* This gets us atomic counters. */ |
|---|
| 58 | 44 | #include <linux/skbuff.h> /* We need sk_buff_head. */ |
|---|
| 59 | 45 | #include <linux/workqueue.h> /* We need tq_struct. */ |
|---|
| 60 | | -#include <linux/flex_array.h> /* We need flex_array. */ |
|---|
| 61 | 46 | #include <linux/sctp.h> /* We need sctp* header structs. */ |
|---|
| 62 | 47 | #include <net/sctp/auth.h> /* We need auth specific structs */ |
|---|
| 63 | 48 | #include <net/ip.h> /* For inet_skb_parm */ |
|---|
| .. | .. |
|---|
| 96 | 81 | |
|---|
| 97 | 82 | struct sctp_bind_bucket { |
|---|
| 98 | 83 | unsigned short port; |
|---|
| 99 | | - unsigned short fastreuse; |
|---|
| 84 | + signed char fastreuse; |
|---|
| 85 | + signed char fastreuseport; |
|---|
| 86 | + kuid_t fastuid; |
|---|
| 100 | 87 | struct hlist_node node; |
|---|
| 101 | 88 | struct hlist_head owner; |
|---|
| 102 | 89 | struct net *net; |
|---|
| .. | .. |
|---|
| 197 | 184 | __u32 flowlabel; |
|---|
| 198 | 185 | __u8 dscp; |
|---|
| 199 | 186 | |
|---|
| 187 | + __u16 pf_retrans; |
|---|
| 188 | + __u16 ps_retrans; |
|---|
| 189 | + |
|---|
| 200 | 190 | /* The initial Path MTU to use for new associations. */ |
|---|
| 201 | 191 | __u32 pathmtu; |
|---|
| 202 | 192 | |
|---|
| .. | .. |
|---|
| 207 | 197 | /* Flags controlling Heartbeat, SACK delay, and Path MTU Discovery. */ |
|---|
| 208 | 198 | __u32 param_flags; |
|---|
| 209 | 199 | |
|---|
| 200 | + __u32 default_ss; |
|---|
| 201 | + |
|---|
| 210 | 202 | struct sctp_rtoinfo rtoinfo; |
|---|
| 211 | 203 | struct sctp_paddrparams paddrparam; |
|---|
| 212 | 204 | struct sctp_assocparams assocparams; |
|---|
| .. | .. |
|---|
| 215 | 207 | * These two structures must be grouped together for the usercopy |
|---|
| 216 | 208 | * whitelist region. |
|---|
| 217 | 209 | */ |
|---|
| 218 | | - struct sctp_event_subscribe subscribe; |
|---|
| 210 | + __u16 subscribe; |
|---|
| 219 | 211 | struct sctp_initmsg initmsg; |
|---|
| 220 | 212 | |
|---|
| 221 | 213 | int user_frag; |
|---|
| .. | .. |
|---|
| 224 | 216 | __u32 adaptation_ind; |
|---|
| 225 | 217 | __u32 pd_point; |
|---|
| 226 | 218 | __u16 nodelay:1, |
|---|
| 219 | + pf_expose:2, |
|---|
| 227 | 220 | reuse:1, |
|---|
| 228 | 221 | disable_fragments:1, |
|---|
| 229 | 222 | v4mapped:1, |
|---|
| 230 | 223 | frag_interleave:1, |
|---|
| 231 | | - strm_interleave:1, |
|---|
| 232 | 224 | recvrcvinfo:1, |
|---|
| 233 | 225 | recvnxtinfo:1, |
|---|
| 234 | 226 | data_ready_signalled:1; |
|---|
| 235 | 227 | |
|---|
| 236 | 228 | atomic_t pd_mode; |
|---|
| 229 | + |
|---|
| 230 | + /* Fields after this point will be skipped on copies, like on accept |
|---|
| 231 | + * and peeloff operations |
|---|
| 232 | + */ |
|---|
| 233 | + |
|---|
| 237 | 234 | /* Receive to here while partial delivery is in effect. */ |
|---|
| 238 | 235 | struct sk_buff_head pd_lobby; |
|---|
| 239 | 236 | |
|---|
| 240 | | - /* These must be the last fields, as they will skipped on copies, |
|---|
| 241 | | - * like on accept and peeloff operations |
|---|
| 242 | | - */ |
|---|
| 243 | 237 | struct list_head auto_asconf_list; |
|---|
| 244 | 238 | int do_auto_asconf; |
|---|
| 245 | 239 | }; |
|---|
| .. | .. |
|---|
| 334 | 328 | * the association TCB is re-constructed from the cookie. |
|---|
| 335 | 329 | */ |
|---|
| 336 | 330 | __u32 raw_addr_list_len; |
|---|
| 337 | | - struct sctp_init_chunk peer_init[0]; |
|---|
| 331 | + struct sctp_init_chunk peer_init[]; |
|---|
| 338 | 332 | }; |
|---|
| 339 | 333 | |
|---|
| 340 | 334 | |
|---|
| .. | .. |
|---|
| 439 | 433 | int (*setsockopt) (struct sock *sk, |
|---|
| 440 | 434 | int level, |
|---|
| 441 | 435 | int optname, |
|---|
| 442 | | - char __user *optval, |
|---|
| 436 | + sockptr_t optval, |
|---|
| 443 | 437 | unsigned int optlen); |
|---|
| 444 | 438 | int (*getsockopt) (struct sock *sk, |
|---|
| 445 | | - int level, |
|---|
| 446 | | - int optname, |
|---|
| 447 | | - char __user *optval, |
|---|
| 448 | | - int __user *optlen); |
|---|
| 449 | | - int (*compat_setsockopt) (struct sock *sk, |
|---|
| 450 | | - int level, |
|---|
| 451 | | - int optname, |
|---|
| 452 | | - char __user *optval, |
|---|
| 453 | | - unsigned int optlen); |
|---|
| 454 | | - int (*compat_getsockopt) (struct sock *sk, |
|---|
| 455 | 439 | int level, |
|---|
| 456 | 440 | int optname, |
|---|
| 457 | 441 | char __user *optval, |
|---|
| .. | .. |
|---|
| 906 | 890 | * and will be initialized from the assocs value. This can be changed |
|---|
| 907 | 891 | * using the SCTP_PEER_ADDR_THLDS socket option |
|---|
| 908 | 892 | */ |
|---|
| 909 | | - int pf_retrans; |
|---|
| 893 | + __u16 pf_retrans; |
|---|
| 894 | + /* Used for primary path switchover. */ |
|---|
| 895 | + __u16 ps_retrans; |
|---|
| 910 | 896 | /* PMTU : The current known path MTU. */ |
|---|
| 911 | 897 | __u32 pathmtu; |
|---|
| 912 | 898 | |
|---|
| .. | .. |
|---|
| 1190 | 1176 | struct sctp_sock *, struct sctp_sock *); |
|---|
| 1191 | 1177 | int sctp_bind_addr_state(const struct sctp_bind_addr *bp, |
|---|
| 1192 | 1178 | const union sctp_addr *addr); |
|---|
| 1179 | +int sctp_bind_addrs_check(struct sctp_sock *sp, |
|---|
| 1180 | + struct sctp_sock *sp2, int cnt2); |
|---|
| 1193 | 1181 | union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp, |
|---|
| 1194 | 1182 | const union sctp_addr *addrs, |
|---|
| 1195 | 1183 | int addrcnt, |
|---|
| .. | .. |
|---|
| 1333 | 1321 | /* SCTP-AUTH: endpoint shared keys */ |
|---|
| 1334 | 1322 | struct list_head endpoint_shared_keys; |
|---|
| 1335 | 1323 | __u16 active_key_id; |
|---|
| 1336 | | - __u8 auth_enable:1, |
|---|
| 1324 | + __u8 ecn_enable:1, |
|---|
| 1325 | + auth_enable:1, |
|---|
| 1326 | + intl_enable:1, |
|---|
| 1337 | 1327 | prsctp_enable:1, |
|---|
| 1328 | + asconf_enable:1, |
|---|
| 1338 | 1329 | reconf_enable:1; |
|---|
| 1339 | 1330 | |
|---|
| 1340 | 1331 | __u8 strreset_enable; |
|---|
| .. | .. |
|---|
| 1400 | 1391 | struct list_head prio_sched; |
|---|
| 1401 | 1392 | /* List of streams scheduled */ |
|---|
| 1402 | 1393 | struct list_head active; |
|---|
| 1403 | | - /* The next stream stream in line */ |
|---|
| 1394 | + /* The next stream in line */ |
|---|
| 1404 | 1395 | struct sctp_stream_out_ext *next; |
|---|
| 1405 | 1396 | __u16 prio; |
|---|
| 1397 | + __u16 users; |
|---|
| 1406 | 1398 | }; |
|---|
| 1407 | 1399 | |
|---|
| 1408 | 1400 | struct sctp_stream_out_ext { |
|---|
| .. | .. |
|---|
| 1445 | 1437 | }; |
|---|
| 1446 | 1438 | |
|---|
| 1447 | 1439 | struct sctp_stream { |
|---|
| 1448 | | - struct flex_array *out; |
|---|
| 1449 | | - struct flex_array *in; |
|---|
| 1440 | + GENRADIX(struct sctp_stream_out) out; |
|---|
| 1441 | + GENRADIX(struct sctp_stream_in) in; |
|---|
| 1442 | + |
|---|
| 1450 | 1443 | __u16 outcnt; |
|---|
| 1451 | 1444 | __u16 incnt; |
|---|
| 1452 | 1445 | /* Current stream being sent, if any */ |
|---|
| .. | .. |
|---|
| 1461 | 1454 | struct { |
|---|
| 1462 | 1455 | /* List of streams scheduled */ |
|---|
| 1463 | 1456 | struct list_head rr_list; |
|---|
| 1464 | | - /* The next stream stream in line */ |
|---|
| 1457 | + /* The next stream in line */ |
|---|
| 1465 | 1458 | struct sctp_stream_out_ext *rr_next; |
|---|
| 1466 | 1459 | }; |
|---|
| 1467 | 1460 | }; |
|---|
| .. | .. |
|---|
| 1469 | 1462 | }; |
|---|
| 1470 | 1463 | |
|---|
| 1471 | 1464 | static inline struct sctp_stream_out *sctp_stream_out( |
|---|
| 1472 | | - const struct sctp_stream *stream, |
|---|
| 1465 | + struct sctp_stream *stream, |
|---|
| 1473 | 1466 | __u16 sid) |
|---|
| 1474 | 1467 | { |
|---|
| 1475 | | - return flex_array_get(stream->out, sid); |
|---|
| 1468 | + return genradix_ptr(&stream->out, sid); |
|---|
| 1476 | 1469 | } |
|---|
| 1477 | 1470 | |
|---|
| 1478 | 1471 | static inline struct sctp_stream_in *sctp_stream_in( |
|---|
| 1479 | | - const struct sctp_stream *stream, |
|---|
| 1472 | + struct sctp_stream *stream, |
|---|
| 1480 | 1473 | __u16 sid) |
|---|
| 1481 | 1474 | { |
|---|
| 1482 | | - return flex_array_get(stream->in, sid); |
|---|
| 1475 | + return genradix_ptr(&stream->in, sid); |
|---|
| 1483 | 1476 | } |
|---|
| 1484 | 1477 | |
|---|
| 1485 | 1478 | #define SCTP_SO(s, i) sctp_stream_out((s), (i)) |
|---|
| .. | .. |
|---|
| 1689 | 1682 | __be16 addip_disabled_mask; |
|---|
| 1690 | 1683 | |
|---|
| 1691 | 1684 | /* These are capabilities which our peer advertised. */ |
|---|
| 1692 | | - __u8 ecn_capable:1, /* Can peer do ECN? */ |
|---|
| 1685 | + __u16 ecn_capable:1, /* Can peer do ECN? */ |
|---|
| 1693 | 1686 | ipv4_address:1, /* Peer understands IPv4 addresses? */ |
|---|
| 1694 | 1687 | ipv6_address:1, /* Peer understands IPv6 addresses? */ |
|---|
| 1695 | 1688 | hostname_address:1, /* Peer understands DNS addresses? */ |
|---|
| 1696 | 1689 | asconf_capable:1, /* Does peer support ADDIP? */ |
|---|
| 1697 | 1690 | prsctp_capable:1, /* Can peer do PR-SCTP? */ |
|---|
| 1698 | 1691 | reconf_capable:1, /* Can peer do RE-CONFIG? */ |
|---|
| 1699 | | - auth_capable:1; /* Is peer doing SCTP-AUTH? */ |
|---|
| 1700 | | - |
|---|
| 1701 | | - /* sack_needed : This flag indicates if the next received |
|---|
| 1702 | | - * : packet is to be responded to with a |
|---|
| 1703 | | - * : SACK. This is initialized to 0. When a packet |
|---|
| 1704 | | - * : is received sack_cnt is incremented. If this value |
|---|
| 1705 | | - * : reaches 2 or more, a SACK is sent and the |
|---|
| 1706 | | - * : value is reset to 0. Note: This is used only |
|---|
| 1707 | | - * : when no DATA chunks are received out of |
|---|
| 1708 | | - * : order. When DATA chunks are out of order, |
|---|
| 1709 | | - * : SACK's are not delayed (see Section 6). |
|---|
| 1710 | | - */ |
|---|
| 1711 | | - __u8 sack_needed:1, /* Do we need to sack the peer? */ |
|---|
| 1692 | + intl_capable:1, /* Can peer do INTERLEAVE */ |
|---|
| 1693 | + auth_capable:1, /* Is peer doing SCTP-AUTH? */ |
|---|
| 1694 | + /* sack_needed: |
|---|
| 1695 | + * This flag indicates if the next received |
|---|
| 1696 | + * packet is to be responded to with a |
|---|
| 1697 | + * SACK. This is initialized to 0. When a packet |
|---|
| 1698 | + * is received sack_cnt is incremented. If this value |
|---|
| 1699 | + * reaches 2 or more, a SACK is sent and the |
|---|
| 1700 | + * value is reset to 0. Note: This is used only |
|---|
| 1701 | + * when no DATA chunks are received out of |
|---|
| 1702 | + * order. When DATA chunks are out of order, |
|---|
| 1703 | + * SACK's are not delayed (see Section 6). |
|---|
| 1704 | + */ |
|---|
| 1705 | + sack_needed:1, /* Do we need to sack the peer? */ |
|---|
| 1712 | 1706 | sack_generation:1, |
|---|
| 1713 | 1707 | zero_window_announced:1; |
|---|
| 1708 | + |
|---|
| 1714 | 1709 | __u32 sack_cnt; |
|---|
| 1715 | 1710 | |
|---|
| 1716 | 1711 | __u32 adaptation_ind; /* Adaptation Code point. */ |
|---|
| .. | .. |
|---|
| 1769 | 1764 | int max_burst; |
|---|
| 1770 | 1765 | |
|---|
| 1771 | 1766 | /* This is the max_retrans value for the association. This value will |
|---|
| 1772 | | - * be initialized initialized from system defaults, but can be |
|---|
| 1767 | + * be initialized from system defaults, but can be |
|---|
| 1773 | 1768 | * modified by the SCTP_ASSOCINFO socket option. |
|---|
| 1774 | 1769 | */ |
|---|
| 1775 | 1770 | int max_retrans; |
|---|
| .. | .. |
|---|
| 1778 | 1773 | * and will be initialized from the assocs value. This can be |
|---|
| 1779 | 1774 | * changed using the SCTP_PEER_ADDR_THLDS socket option |
|---|
| 1780 | 1775 | */ |
|---|
| 1781 | | - int pf_retrans; |
|---|
| 1776 | + __u16 pf_retrans; |
|---|
| 1777 | + /* Used for primary path switchover. */ |
|---|
| 1778 | + __u16 ps_retrans; |
|---|
| 1782 | 1779 | |
|---|
| 1783 | 1780 | /* Maximum number of times the endpoint will retransmit INIT */ |
|---|
| 1784 | 1781 | __u16 max_init_attempts; |
|---|
| .. | .. |
|---|
| 2059 | 2056 | |
|---|
| 2060 | 2057 | __u8 need_ecne:1, /* Need to send an ECNE Chunk? */ |
|---|
| 2061 | 2058 | temp:1, /* Is it a temporary association? */ |
|---|
| 2062 | | - force_delay:1, |
|---|
| 2063 | | - intl_enable:1, |
|---|
| 2064 | | - prsctp_enable:1, |
|---|
| 2065 | | - reconf_enable:1; |
|---|
| 2059 | + pf_expose:2, /* Expose pf state? */ |
|---|
| 2060 | + force_delay:1; |
|---|
| 2066 | 2061 | |
|---|
| 2067 | 2062 | __u8 strreset_enable; |
|---|
| 2068 | 2063 | __u8 strreset_outstanding; /* request param count on the fly */ |
|---|
| .. | .. |
|---|
| 2077 | 2072 | |
|---|
| 2078 | 2073 | int sent_cnt_removable; |
|---|
| 2079 | 2074 | |
|---|
| 2075 | + __u16 subscribe; |
|---|
| 2076 | + |
|---|
| 2080 | 2077 | __u64 abandoned_unsent[SCTP_PR_INDEX(MAX) + 1]; |
|---|
| 2081 | 2078 | __u64 abandoned_sent[SCTP_PR_INDEX(MAX) + 1]; |
|---|
| 2082 | 2079 | |
|---|