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 handling 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 requires.

Signed-off-by: Xin Long <lucien....@gmail.com>
---
 include/net/sctp/sctp.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index bfd87a0..6408bbb 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -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 (sock_net(&sp->inet.sk)->sctp.udp_port)
+                       overhead += sizeof(struct udphdr);
+       } else {
                overhead += sizeof(struct ipv6hdr);
+       }
 
        if (WARN_ON_ONCE(mtu && mtu <= overhead))
                mtu = overhead;
-- 
2.1.0

Reply via email to