]> git.baikalelectronics.ru Git - kernel.git/commitdiff
sctp: add udphdr to overhead when udp_port is set
authorXin Long <lucien.xin@gmail.com>
Thu, 29 Oct 2020 07:05:04 +0000 (15:05 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 30 Oct 2020 22:24:21 +0000 (15:24 -0700)
sctp_mtu_payload() is for calculating the frag size before making
chunks from a msg. So we should only add udphdr size to overhead
when udp socks are listening, as only then sctp can handle the
incoming sctp over udp packets and outgoing sctp over udp packets
will be possible.

Note that we can't do this according to transport->encap_port, as
different transports may be set to different values, while the
chunks were made before choosing the transport, we could not be
able to meet all rfc6951#section-5.6 recommends.

v1->v2:
  - Add udp_port for sctp_sock to avoid a potential race issue, it
    will be used in xmit path in the next patch.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/sctp/sctp.h
include/net/sctp/structs.h
net/sctp/socket.c

index bfd87a0aa2f16f3a6491750d1ede57c152ca5f7f..86f74f2fe6deab9067cd3dcfab2fe152af9c3dba 100644 (file)
@@ -578,10 +578,13 @@ static inline __u32 sctp_mtu_payload(const struct sctp_sock *sp,
 {
        __u32 overhead = sizeof(struct sctphdr) + extra;
 
-       if (sp)
+       if (sp) {
                overhead += sp->pf->af->net_header_len;
-       else
+               if (sp->udp_port)
+                       overhead += sizeof(struct udphdr);
+       } else {
                overhead += sizeof(struct ipv6hdr);
+       }
 
        if (WARN_ON_ONCE(mtu && mtu <= overhead))
                mtu = overhead;
index 81464ae2b1378de9d7c11e8e7e94ae850eef627f..80f71499b54357850ace30abdc1e53a988d1ae16 100644 (file)
@@ -178,6 +178,7 @@ struct sctp_sock {
         */
        __u32 hbinterval;
 
+       __be16 udp_port;
        __be16 encap_port;
 
        /* This is the max_retrans value for new associations. */
index 2a9ee9b3e46ce4697507d81c6558da274c34e279..a710917c5ac73ab823aa9f8d312c20083ca991ce 100644 (file)
@@ -4928,6 +4928,7 @@ static int sctp_init_sock(struct sock *sk)
         * be modified via SCTP_PEER_ADDR_PARAMS
         */
        sp->hbinterval  = net->sctp.hb_interval;
+       sp->udp_port    = htons(net->sctp.udp_port);
        sp->encap_port  = htons(net->sctp.encap_port);
        sp->pathmaxrxt  = net->sctp.max_retrans_path;
        sp->pf_retrans  = net->sctp.pf_retrans;