Skip to content

Commit

Permalink
sctp: add udphdr to overhead when udp_port is set
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Marcelo Ricardo Leitner <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
lxin authored and kuba-moo committed Oct 30, 2020
1 parent a1dd2cf commit f1bfe8b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions include/net/sctp/sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions include/net/sctp/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ struct sctp_sock {
*/
__u32 hbinterval;

__be16 udp_port;
__be16 encap_port;

/* This is the max_retrans value for new associations. */
Expand Down
1 change: 1 addition & 0 deletions net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f1bfe8b

Please sign in to comment.