Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

sctp: add the constants/variables and states and some APIs for transport

These are 4 constants described in rfc8899#section-5.1.2:

MAX_PROBES, MIN_PLPMTU, MAX_PLPMTU, BASE_PLPMTU;

And 2 variables described in rfc8899#section-5.1.3:

PROBED_SIZE, PROBE_COUNT;

And 5 states described in rfc8899#section-5.2:

DISABLED, BASE, SEARCH, SEARCH_COMPLETE, ERROR;

And these 4 APIs are used to reset/update PLPMTUD, check if PLPMTUD is
enabled, and calculate the additional headers length for a transport.

Note the member 'probe_high' in transport will be set to the probe
size when a probe fails with this probe size in the next patches.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Xin Long and committed by
David S. Miller
d9e2e410 3190b649

+70 -3
+17
include/net/sctp/constants.h
··· 200 200 SCTP_SS_CLOSING = TCP_CLOSE_WAIT, 201 201 }; 202 202 203 + enum sctp_plpmtud_state { 204 + SCTP_PL_DISABLED, 205 + SCTP_PL_BASE, 206 + SCTP_PL_SEARCH, 207 + SCTP_PL_COMPLETE, 208 + SCTP_PL_ERROR, 209 + }; 210 + 211 + #define SCTP_BASE_PLPMTU 1200 212 + #define SCTP_MAX_PLPMTU 9000 213 + #define SCTP_MIN_PLPMTU 512 214 + 215 + #define SCTP_MAX_PROBES 3 216 + 217 + #define SCTP_PL_BIG_STEP 32 218 + #define SCTP_PL_MIN_STEP 4 219 + 203 220 /* These functions map various type to printable names. */ 204 221 const char *sctp_cname(const union sctp_subtype id); /* chunk types */ 205 222 const char *sctp_oname(const union sctp_subtype id); /* other events */
+45 -3
include/net/sctp/sctp.h
··· 573 573 /* Calculate max payload size given a MTU, or the total overhead if 574 574 * given MTU is zero 575 575 */ 576 - static inline __u32 sctp_mtu_payload(const struct sctp_sock *sp, 577 - __u32 mtu, __u32 extra) 576 + static inline __u32 __sctp_mtu_payload(const struct sctp_sock *sp, 577 + const struct sctp_transport *t, 578 + __u32 mtu, __u32 extra) 578 579 { 579 580 __u32 overhead = sizeof(struct sctphdr) + extra; 580 581 581 582 if (sp) { 582 583 overhead += sp->pf->af->net_header_len; 583 - if (sp->udp_port) 584 + if (sp->udp_port && (!t || t->encap_port)) 584 585 overhead += sizeof(struct udphdr); 585 586 } else { 586 587 overhead += sizeof(struct ipv6hdr); ··· 591 590 mtu = overhead; 592 591 593 592 return mtu ? mtu - overhead : overhead; 593 + } 594 + 595 + static inline __u32 sctp_mtu_payload(const struct sctp_sock *sp, 596 + __u32 mtu, __u32 extra) 597 + { 598 + return __sctp_mtu_payload(sp, NULL, mtu, extra); 594 599 } 595 600 596 601 static inline __u32 sctp_dst_mtu(const struct dst_entry *dst) ··· 620 613 static inline __u32 sctp_min_frag_point(struct sctp_sock *sp, __u16 datasize) 621 614 { 622 615 return sctp_mtu_payload(sp, SCTP_DEFAULT_MINSEGMENT, datasize); 616 + } 617 + 618 + static inline int sctp_transport_pl_hlen(struct sctp_transport *t) 619 + { 620 + return __sctp_mtu_payload(sctp_sk(t->asoc->base.sk), t, 0, 0); 621 + } 622 + 623 + static inline void sctp_transport_pl_reset(struct sctp_transport *t) 624 + { 625 + if (t->probe_interval && (t->param_flags & SPP_PMTUD_ENABLE) && 626 + (t->state == SCTP_ACTIVE || t->state == SCTP_UNKNOWN)) { 627 + if (t->pl.state == SCTP_PL_DISABLED) { 628 + t->pl.state = SCTP_PL_BASE; 629 + t->pl.pmtu = SCTP_BASE_PLPMTU; 630 + t->pl.probe_size = SCTP_BASE_PLPMTU; 631 + } 632 + } else { 633 + if (t->pl.state != SCTP_PL_DISABLED) 634 + t->pl.state = SCTP_PL_DISABLED; 635 + } 636 + } 637 + 638 + static inline void sctp_transport_pl_update(struct sctp_transport *t) 639 + { 640 + if (t->pl.state == SCTP_PL_DISABLED) 641 + return; 642 + 643 + t->pl.state = SCTP_PL_BASE; 644 + t->pl.pmtu = SCTP_BASE_PLPMTU; 645 + t->pl.probe_size = SCTP_BASE_PLPMTU; 646 + } 647 + 648 + static inline bool sctp_transport_pl_enabled(struct sctp_transport *t) 649 + { 650 + return t->pl.state != SCTP_PL_DISABLED; 623 651 } 624 652 625 653 static inline bool sctp_newsk_ready(const struct sock *sk)
+8
include/net/sctp/structs.h
··· 978 978 char cacc_saw_newack; 979 979 } cacc; 980 980 981 + struct { 982 + __u16 pmtu; 983 + __u16 probe_size; 984 + __u16 probe_high; 985 + __u8 probe_count; 986 + __u8 state; 987 + } pl; /* plpmtud related */ 988 + 981 989 /* 64-bit random number sent with heartbeat. */ 982 990 __u64 hb_nonce; 983 991