Skip to content

Commit

Permalink
Merge branch 'sctp-packetization-path-MTU'
Browse files Browse the repository at this point in the history
Xin Long says:

====================
sctp: implement RFC8899: Packetization Layer Path MTU Discovery for SCTP transport

Overview(From RFC8899):

  In contrast to PMTUD, Packetization Layer Path MTU Discovery
  (PLPMTUD) [RFC4821] introduces a method that does not rely upon
  reception and validation of PTB messages.  It is therefore more
  robust than Classical PMTUD.  This has become the recommended
  approach for implementing discovery of the PMTU [BCP145].

  It uses a general strategy in which the PL sends probe packets to
  search for the largest size of unfragmented datagram that can be sent
  over a network path.  Probe packets are sent to explore using a
  larger packet size.  If a probe packet is successfully delivered (as
  determined by the PL), then the PLPMTU is raised to the size of the
  successful probe.  If a black hole is detected (e.g., where packets
  of size PLPMTU are consistently not received), the method reduces the
  PLPMTU.

SCTP Probe Packets:

  As the RFC suggested, the probe packets consist of an SCTP common header
  followed by a HEARTBEAT chunk and a PAD chunk. The PAD chunk is used to
  control the length of the probe packet.  The HEARTBEAT chunk is used to
  trigger the sending of a HEARTBEAT ACK chunk to confirm this probe on
  the HEARTBEAT sender.

  The HEARTBEAT chunk also carries a Heartbeat Information parameter that
  includes the probe size to help an implementation associate a HEARTBEAT
  ACK with the size of probe that was sent. The sender use the nonce and
  the probe size to verify the information returned.

Detailed Implementation on SCTP:

                       +------+
              +------->| Base |-----------------+ Connectivity
              |        +------+                 | or BASE_PLPMTU
              |           |                     | confirmation failed
              |           |                     v
              |           | Connectivity    +-------+
              |           | and BASE_PLPMTU | Error |
              |           | confirmed       +-------+
              |           |                     | Consistent
              |           v                     | connectivity
   Black Hole |       +--------+                | and BASE_PLPMTU
    detected  |       | Search |<---------------+ confirmed
              |       +--------+
              |          ^  |
              |          |  |
              |    Raise |  | Search
              |    timer |  | algorithm
              |  expired |  | completed
              |          |  |
              |          |  v
              |   +-----------------+
              +---| Search Complete |
                  +-----------------+

  When PLPMTUD is enabled, it's in Base state, and starts to probe with
  BASE_PLPMTU (1200). If this probe succeeds, it goes to Search state;
  If this probe fails, it goes to Error state under which pl.pmtu goes
  down to MIN_PLPMTU (512) and keeps probing with BASE_PLPMTU until it
  succeeds and goes to Search state.

  During the Search state, the probe size is growing by a Big step (32)
  every time when the last probe succeeds at the beginning. Once a probe
  (such as 1420) fails after trying MAX_PROBES (3) times, the probe_size
  goes back to the last one (1420 - 32 = 1388), meanwhile 'probe_high'
  is set to 1420 and the growing step becomes a Small one (4). Then the
  probe is continuing with a Small step grown each round. Until it gets
  the optimal size (such as 1400) when probe with its next probe size
  (1404) fails, it sync this size to pathmtu and goes to Complete state.

  In Complete state, it will only does a probe check for the pathmtu just
  set, if it fails, which means a Black Hole is detected and it goes back
  to Base state. If it succeeds, it goes back to Search state again, and
  probe is continuing with growing a Small step (1400 + 4). If this probe
  fails, probe_high is set and goes back to 1388 and then Complete state,
  which is kind of a loop normally. However if the env's pathmtu changes
  to a big size somehow, this probe will succeed and then probe continues
  with growing a Big step (1400 + 32) each round until another probe fails.

PTB Messages Process:

  PLPMTUD doesn't rely on these package to find the pmtu, and shouldn't
  trust it either. When processing them, it only changes the probe_size
  to PL_PTB_SIZE(info - hlen) if 'pl.pmtu < PL_PTB_SIZE < the current
  probe_size' druing Search state. As this could help probe_size to get
  to the optimal size faster, for exmaple:

  pl.pmtu = 1388, probe_size = 1420, while the env's pathmtu = 1400.
  When probe_size is 1420, a Toobig packet with 1400 comes back. If probe
  size changes to use 1400, it will save quite a few rounds to get there.
  But of course after having this value, PLPMTUD will still verify it on
  its own before using it.

Patches:

  - Patch 1-6: introduce some new constants/variables from the RFC, systcl
    and members in transport, APIs for the following patches, chunks and
    a timer for the probe sending and some codes for the probe receiving.

  - Patch 7-9: implement the state transition on the tx path, rx path and
    toobig ICMP packet processing. This is the main algorithm part.

  - Patch 10: activate this feature

  - Patch 11-14: improve the process for ICMP packets for SCTP over UDP,
    so that it can also be covered by this feature.

Tests:

  - do sysctl and setsockopt tests for this feature's enabling and disabling.

  - get these pr_debug points for this feature by
      # cat /sys/kernel/debug/dynamic_debug/control | grep PLP
    and enable them on kernel dynamic debug, then play with the pathmtu and
    check if the state transition and plpmtu change match the RFC.

  - do the above tests for SCTP over IPv4/IPv6 and SCTP over UDP.

v1->v2:
  - See Patch 06/14.
====================

Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
davem330 committed Jun 22, 2021
2 parents aff0824 + 9e47df0 commit a432c77
Show file tree
Hide file tree
Showing 23 changed files with 779 additions and 127 deletions.
8 changes: 8 additions & 0 deletions Documentation/networking/ip-sysctl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,14 @@ encap_port - INTEGER

Default: 0

plpmtud_probe_interval - INTEGER
The time interval (in milliseconds) for sending PLPMTUD probe chunks.
These chunks are sent at the specified interval with a variable size
to probe the mtu of a given path between 2 endpoints. PLPMTUD will
be disabled when 0 is set, and other values for it must be >= 5000.

Default: 0


``/proc/sys/net/core/*``
========================
Expand Down
7 changes: 7 additions & 0 deletions include/linux/sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ enum sctp_cid {
SCTP_CID_I_FWD_TSN = 0xC2,
SCTP_CID_ASCONF_ACK = 0x80,
SCTP_CID_RECONF = 0x82,
SCTP_CID_PAD = 0x84,
}; /* enum */


Expand Down Expand Up @@ -410,6 +411,12 @@ struct sctp_heartbeat_chunk {
};


/* PAD chunk could be bundled with heartbeat chunk to probe pmtu */
struct sctp_pad_chunk {
struct sctp_chunkhdr uh;
};


/* For the abort and shutdown ACK we must carry the init tag in the
* common header. Just the common header is all that is needed with a
* chunk descriptor.
Expand Down
3 changes: 3 additions & 0 deletions include/net/netns/sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ struct netns_sctp {
/* HB.interval - 30 seconds */
unsigned int hb_interval;

/* The interval for PLPMTUD probe timer */
unsigned int probe_interval;

/* Association.Max.Retrans - 10 attempts
* Path.Max.Retrans - 5 attempts (per destination address)
* Max.Init.Retransmits - 8 attempts
Expand Down
1 change: 1 addition & 0 deletions include/net/sctp/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum sctp_verb {
SCTP_CMD_HB_TIMERS_START, /* Start the heartbeat timers. */
SCTP_CMD_HB_TIMER_UPDATE, /* Update a heartbeat timers. */
SCTP_CMD_HB_TIMERS_STOP, /* Stop the heartbeat timers. */
SCTP_CMD_PROBE_TIMER_UPDATE, /* Update a probe timer. */
SCTP_CMD_TRANSPORT_HB_SENT, /* Reset the status of a transport. */
SCTP_CMD_TRANSPORT_IDLE, /* Do manipulations on idle transport */
SCTP_CMD_TRANSPORT_ON, /* Mark the transport as active. */
Expand Down
20 changes: 20 additions & 0 deletions include/net/sctp/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum sctp_event_timeout {
SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD,
SCTP_EVENT_TIMEOUT_HEARTBEAT,
SCTP_EVENT_TIMEOUT_RECONF,
SCTP_EVENT_TIMEOUT_PROBE,
SCTP_EVENT_TIMEOUT_SACK,
SCTP_EVENT_TIMEOUT_AUTOCLOSE,
};
Expand Down Expand Up @@ -200,6 +201,23 @@ enum sctp_sock_state {
SCTP_SS_CLOSING = TCP_CLOSE_WAIT,
};

enum sctp_plpmtud_state {
SCTP_PL_DISABLED,
SCTP_PL_BASE,
SCTP_PL_SEARCH,
SCTP_PL_COMPLETE,
SCTP_PL_ERROR,
};

#define SCTP_BASE_PLPMTU 1200
#define SCTP_MAX_PLPMTU 9000
#define SCTP_MIN_PLPMTU 512

#define SCTP_MAX_PROBES 3

#define SCTP_PL_BIG_STEP 32
#define SCTP_PL_MIN_STEP 4

/* These functions map various type to printable names. */
const char *sctp_cname(const union sctp_subtype id); /* chunk types */
const char *sctp_oname(const union sctp_subtype id); /* other events */
Expand Down Expand Up @@ -424,4 +442,6 @@ enum {
*/
#define SCTP_AUTH_RANDOM_LENGTH 32

#define SCTP_PROBE_TIMER_MIN 5000

#endif /* __sctp_constants_h__ */
57 changes: 54 additions & 3 deletions include/net/sctp/sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ struct sock *sctp_err_lookup(struct net *net, int family, struct sk_buff *,
struct sctphdr *, struct sctp_association **,
struct sctp_transport **);
void sctp_err_finish(struct sock *, struct sctp_transport *);
int sctp_udp_v4_err(struct sock *sk, struct sk_buff *skb);
int sctp_udp_v6_err(struct sock *sk, struct sk_buff *skb);
void sctp_icmp_frag_needed(struct sock *, struct sctp_association *,
struct sctp_transport *t, __u32 pmtu);
void sctp_icmp_redirect(struct sock *, struct sctp_transport *,
Expand Down Expand Up @@ -573,14 +575,15 @@ static inline struct dst_entry *sctp_transport_dst_check(struct sctp_transport *
/* 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)
static inline __u32 __sctp_mtu_payload(const struct sctp_sock *sp,
const struct sctp_transport *t,
__u32 mtu, __u32 extra)
{
__u32 overhead = sizeof(struct sctphdr) + extra;

if (sp) {
overhead += sp->pf->af->net_header_len;
if (sp->udp_port)
if (sp->udp_port && (!t || t->encap_port))
overhead += sizeof(struct udphdr);
} else {
overhead += sizeof(struct ipv6hdr);
Expand All @@ -592,6 +595,12 @@ static inline __u32 sctp_mtu_payload(const struct sctp_sock *sp,
return mtu ? mtu - overhead : overhead;
}

static inline __u32 sctp_mtu_payload(const struct sctp_sock *sp,
__u32 mtu, __u32 extra)
{
return __sctp_mtu_payload(sp, NULL, mtu, extra);
}

static inline __u32 sctp_dst_mtu(const struct dst_entry *dst)
{
return SCTP_TRUNC4(max_t(__u32, dst_mtu(dst),
Expand All @@ -615,6 +624,48 @@ static inline __u32 sctp_min_frag_point(struct sctp_sock *sp, __u16 datasize)
return sctp_mtu_payload(sp, SCTP_DEFAULT_MINSEGMENT, datasize);
}

static inline int sctp_transport_pl_hlen(struct sctp_transport *t)
{
return __sctp_mtu_payload(sctp_sk(t->asoc->base.sk), t, 0, 0);
}

static inline void sctp_transport_pl_reset(struct sctp_transport *t)
{
if (t->probe_interval && (t->param_flags & SPP_PMTUD_ENABLE) &&
(t->state == SCTP_ACTIVE || t->state == SCTP_UNKNOWN)) {
if (t->pl.state == SCTP_PL_DISABLED) {
t->pl.state = SCTP_PL_BASE;
t->pl.pmtu = SCTP_BASE_PLPMTU;
t->pl.probe_size = SCTP_BASE_PLPMTU;
sctp_transport_reset_probe_timer(t);
}
} else {
if (t->pl.state != SCTP_PL_DISABLED) {
if (del_timer(&t->probe_timer))
sctp_transport_put(t);
t->pl.state = SCTP_PL_DISABLED;
}
}
}

static inline void sctp_transport_pl_update(struct sctp_transport *t)
{
if (t->pl.state == SCTP_PL_DISABLED)
return;

if (del_timer(&t->probe_timer))
sctp_transport_put(t);

t->pl.state = SCTP_PL_BASE;
t->pl.pmtu = SCTP_BASE_PLPMTU;
t->pl.probe_size = SCTP_BASE_PLPMTU;
}

static inline bool sctp_transport_pl_enabled(struct sctp_transport *t)
{
return t->pl.state != SCTP_PL_DISABLED;
}

static inline bool sctp_newsk_ready(const struct sock *sk)
{
return sock_flag(sk, SOCK_DEAD) || sk->sk_socket;
Expand Down
6 changes: 5 additions & 1 deletion include/net/sctp/sm.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ sctp_state_fn_t sctp_sf_cookie_wait_icmp_abort;
/* Prototypes for timeout event state functions. */
sctp_state_fn_t sctp_sf_do_6_3_3_rtx;
sctp_state_fn_t sctp_sf_send_reconf;
sctp_state_fn_t sctp_sf_send_probe;
sctp_state_fn_t sctp_sf_do_6_2_sack;
sctp_state_fn_t sctp_sf_autoclose_timer_expire;

Expand Down Expand Up @@ -225,11 +226,13 @@ struct sctp_chunk *sctp_make_new_encap_port(
const struct sctp_association *asoc,
const struct sctp_chunk *chunk);
struct sctp_chunk *sctp_make_heartbeat(const struct sctp_association *asoc,
const struct sctp_transport *transport);
const struct sctp_transport *transport,
__u32 probe_size);
struct sctp_chunk *sctp_make_heartbeat_ack(const struct sctp_association *asoc,
const struct sctp_chunk *chunk,
const void *payload,
const size_t paylen);
struct sctp_chunk *sctp_make_pad(const struct sctp_association *asoc, int len);
struct sctp_chunk *sctp_make_op_error(const struct sctp_association *asoc,
const struct sctp_chunk *chunk,
__be16 cause_code, const void *payload,
Expand Down Expand Up @@ -310,6 +313,7 @@ int sctp_do_sm(struct net *net, enum sctp_event_type event_type,
void sctp_generate_t3_rtx_event(struct timer_list *t);
void sctp_generate_heartbeat_event(struct timer_list *t);
void sctp_generate_reconf_event(struct timer_list *t);
void sctp_generate_probe_event(struct timer_list *t);
void sctp_generate_proto_unreach_event(struct timer_list *t);

void sctp_ootb_pkt_free(struct sctp_packet *packet);
Expand Down
19 changes: 19 additions & 0 deletions include/net/sctp/structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ struct sctp_sock {
* will be inherited by all new associations.
*/
__u32 hbinterval;
__u32 probe_interval;

__be16 udp_port;
__be16 encap_port;
Expand Down Expand Up @@ -385,6 +386,7 @@ struct sctp_sender_hb_info {
union sctp_addr daddr;
unsigned long sent_at;
__u64 hb_nonce;
__u32 probe_size;
};

int sctp_stream_init(struct sctp_stream *stream, __u16 outcnt, __u16 incnt,
Expand Down Expand Up @@ -656,6 +658,7 @@ struct sctp_chunk {
data_accepted:1, /* At least 1 chunk accepted */
auth:1, /* IN: was auth'ed | OUT: needs auth */
has_asconf:1, /* IN: have seen an asconf before */
pmtu_probe:1, /* Used by PLPMTUD, can be set in s HB chunk */
tsn_missing_report:2, /* Data chunk missing counter. */
fast_retransmit:2; /* Is this chunk fast retransmitted? */
};
Expand Down Expand Up @@ -858,6 +861,7 @@ struct sctp_transport {
* the destination address every heartbeat interval.
*/
unsigned long hbinterval;
unsigned long probe_interval;

/* SACK delay timeout */
unsigned long sackdelay;
Expand Down Expand Up @@ -934,6 +938,9 @@ struct sctp_transport {
/* Timer to handler reconf chunk rtx */
struct timer_list reconf_timer;

/* Timer to send a probe HB packet for PLPMTUD */
struct timer_list probe_timer;

/* Since we're using per-destination retransmission timers
* (see above), we're also using per-destination "transmitted"
* queues. This probably ought to be a private struct
Expand Down Expand Up @@ -976,6 +983,14 @@ struct sctp_transport {
char cacc_saw_newack;
} cacc;

struct {
__u16 pmtu;
__u16 probe_size;
__u16 probe_high;
__u8 probe_count;
__u8 state;
} pl; /* plpmtud related */

/* 64-bit random number sent with heartbeat. */
__u64 hb_nonce;

Expand All @@ -993,6 +1008,7 @@ void sctp_transport_free(struct sctp_transport *);
void sctp_transport_reset_t3_rtx(struct sctp_transport *);
void sctp_transport_reset_hb_timer(struct sctp_transport *);
void sctp_transport_reset_reconf_timer(struct sctp_transport *transport);
void sctp_transport_reset_probe_timer(struct sctp_transport *transport);
int sctp_transport_hold(struct sctp_transport *);
void sctp_transport_put(struct sctp_transport *);
void sctp_transport_update_rto(struct sctp_transport *, __u32);
Expand All @@ -1007,6 +1023,8 @@ bool sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu);
void sctp_transport_immediate_rtx(struct sctp_transport *);
void sctp_transport_dst_release(struct sctp_transport *t);
void sctp_transport_dst_confirm(struct sctp_transport *t);
void sctp_transport_pl_send(struct sctp_transport *t);
void sctp_transport_pl_recv(struct sctp_transport *t);


/* This is the structure we use to queue packets as they come into
Expand Down Expand Up @@ -1795,6 +1813,7 @@ struct sctp_association {
* will be inherited by all new transports.
*/
unsigned long hbinterval;
unsigned long probe_interval;

__be16 encap_port;

Expand Down
8 changes: 8 additions & 0 deletions include/uapi/linux/sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ typedef __s32 sctp_assoc_t;
#define SCTP_EXPOSE_POTENTIALLY_FAILED_STATE 131
#define SCTP_EXPOSE_PF_STATE SCTP_EXPOSE_POTENTIALLY_FAILED_STATE
#define SCTP_REMOTE_UDP_ENCAPS_PORT 132
#define SCTP_PLPMTUD_PROBE_INTERVAL 133

/* PR-SCTP policies */
#define SCTP_PR_SCTP_NONE 0x0000
Expand Down Expand Up @@ -1213,4 +1214,11 @@ enum sctp_sched_type {
SCTP_SS_MAX = SCTP_SS_RR
};

/* Probe Interval socket option */
struct sctp_probeinterval {
sctp_assoc_t spi_assoc_id;
struct sockaddr_storage spi_address;
__u32 spi_interval;
};

#endif /* _UAPI_SCTP_H */
6 changes: 6 additions & 0 deletions net/sctp/associola.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static struct sctp_association *sctp_association_init(
* sock configured value.
*/
asoc->hbinterval = msecs_to_jiffies(sp->hbinterval);
asoc->probe_interval = msecs_to_jiffies(sp->probe_interval);

asoc->encap_port = sp->encap_port;

Expand Down Expand Up @@ -625,6 +626,7 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
* association configured value.
*/
peer->hbinterval = asoc->hbinterval;
peer->probe_interval = asoc->probe_interval;

peer->encap_port = asoc->encap_port;

Expand Down Expand Up @@ -714,6 +716,8 @@ struct sctp_transport *sctp_assoc_add_peer(struct sctp_association *asoc,
return NULL;
}

sctp_transport_pl_reset(peer);

/* Attach the remote transport to our asoc. */
list_add_tail_rcu(&peer->transports, &asoc->peer.transport_addr_list);
asoc->peer.transport_count++;
Expand Down Expand Up @@ -812,6 +816,7 @@ void sctp_assoc_control_transport(struct sctp_association *asoc,
spc_state = SCTP_ADDR_CONFIRMED;

transport->state = SCTP_ACTIVE;
sctp_transport_pl_reset(transport);
break;

case SCTP_TRANSPORT_DOWN:
Expand All @@ -821,6 +826,7 @@ void sctp_assoc_control_transport(struct sctp_association *asoc,
*/
if (transport->state != SCTP_UNCONFIRMED) {
transport->state = SCTP_INACTIVE;
sctp_transport_pl_reset(transport);
spc_state = SCTP_ADDR_UNREACHABLE;
} else {
sctp_transport_dst_release(transport);
Expand Down
1 change: 1 addition & 0 deletions net/sctp/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ static const char *const sctp_timer_tbl[] = {
"TIMEOUT_T5_SHUTDOWN_GUARD",
"TIMEOUT_HEARTBEAT",
"TIMEOUT_RECONF",
"TIMEOUT_PROBE",
"TIMEOUT_SACK",
"TIMEOUT_AUTOCLOSE",
};
Expand Down
Loading

0 comments on commit a432c77

Please sign in to comment.