summaryrefslogtreecommitdiffstats
path: root/include/net/sctp
diff options
context:
space:
mode:
authorMarcelo Ricardo Leitner <marcelo.leitner@gmail.com>2018-04-26 16:58:54 -0300
committerDavid S. Miller <davem@davemloft.net>2018-04-27 14:35:23 -0400
commitfeddd6c1af30ab11d73ce0e4e76b40dfc899dbda (patch)
tree5103795b3aed0972f3be763097c9b9c11efda77f /include/net/sctp
parentc4b2893dae6427ce1e528033383c94cbf81e80d8 (diff)
downloadlinux-feddd6c1af30ab11d73ce0e4e76b40dfc899dbda.tar.gz
linux-feddd6c1af30ab11d73ce0e4e76b40dfc899dbda.tar.bz2
linux-feddd6c1af30ab11d73ce0e4e76b40dfc899dbda.zip
sctp: introduce sctp_mtu_payload
When given a MTU, this function calculates how much payload we can carry on it. Without a MTU, it calculates the amount of header overhead we have. So that when we have extra overhead, like the one added for IP options on SELinux patches, it is easier to handle it. Signed-off-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/net/sctp')
-rw-r--r--include/net/sctp/sctp.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
index 28b996d63490..0b98e4683f10 100644
--- a/include/net/sctp/sctp.h
+++ b/include/net/sctp/sctp.h
@@ -607,6 +607,25 @@ static inline struct dst_entry *sctp_transport_dst_check(struct sctp_transport *
return t->dst;
}
+/* Calculate max payload size given a MTU, or the total overhead if
+ * given MTU is zero
+ */
+static inline __u32 sctp_mtu_payload(const struct sctp_sock *sp,
+ __u32 mtu, __u32 extra)
+{
+ __u32 overhead = sizeof(struct sctphdr) + extra;
+
+ if (sp)
+ overhead += sp->pf->af->net_header_len;
+ else
+ overhead += sizeof(struct ipv6hdr);
+
+ if (WARN_ON_ONCE(mtu && mtu <= overhead))
+ mtu = overhead;
+
+ return mtu ? mtu - overhead : overhead;
+}
+
static inline bool sctp_transport_pmtu_check(struct sctp_transport *t)
{
__u32 pmtu = max_t(size_t, SCTP_TRUNC4(dst_mtu(t->dst)),