Skip to content

Commit 8369640

Browse files
lxindavem330
authored andcommitted
sctp: do state transition when receiving an icmp TOOBIG packet
PLPMTUD will short-circuit the old process for icmp TOOBIG packets. This part is described in rfc8899#section-4.6.2 (PL_PTB_SIZE = PTB_SIZE - other_headers_len). Note that from rfc8899#section-5.2 State Machine, each case below is for some specific states only: a) PL_PTB_SIZE < MIN_PLPMTU || PL_PTB_SIZE >= PROBED_SIZE, discard it, for any state b) MIN_PLPMTU < PL_PTB_SIZE < BASE_PLPMTU, Base -> Error, for Base state c) BASE_PLPMTU <= PL_PTB_SIZE < PLPMTU, Search -> Base or Complete -> Base, for Search and Complete states. d) PLPMTU < PL_PTB_SIZE < PROBED_SIZE, set pl.probe_size to PL_PTB_SIZE then verify it, for Search state. The most important one is case d), which will help find the optimal fast during searching. Like when pathmtu = 1392 for SCTP over IPv4, the search will be (20 is iphdr_len): 1. probe with 1200 - 20 2. probe with 1232 - 20 3. probe with 1264 - 20 ... 7. probe with 1388 - 20 8. probe with 1420 - 20 When sending the probe with 1420 - 20, TOOBIG may come with PL_PTB_SIZE = 1392 - 20. Then it matches case d), and saves some rounds to try with the 1392 - 20 probe. But of course, PLPMTUD doesn't trust TOOBIG packets, and it will go back to the common searching once the probe with the new size can't be verified. Signed-off-by: Xin Long <[email protected]> Acked-by: Marcelo Ricardo Leitner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b87641a commit 8369640

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

net/sctp/input.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,9 @@ static int sctp_add_backlog(struct sock *sk, struct sk_buff *skb)
385385
void sctp_icmp_frag_needed(struct sock *sk, struct sctp_association *asoc,
386386
struct sctp_transport *t, __u32 pmtu)
387387
{
388-
if (!t || (t->pathmtu <= pmtu))
388+
if (!t ||
389+
(t->pathmtu <= pmtu &&
390+
t->pl.probe_size + sctp_transport_pl_hlen(t) <= pmtu))
389391
return;
390392

391393
if (sock_owned_by_user(sk)) {

net/sctp/transport.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,55 @@ void sctp_transport_pl_recv(struct sctp_transport *t)
343343
}
344344
}
345345

346+
static bool sctp_transport_pl_toobig(struct sctp_transport *t, u32 pmtu)
347+
{
348+
pr_debug("%s: PLPMTUD: transport: %p, state: %d, pmtu: %d, size: %d, ptb: %d\n",
349+
__func__, t, t->pl.state, t->pl.pmtu, t->pl.probe_size, pmtu);
350+
351+
if (pmtu < SCTP_MIN_PLPMTU || pmtu >= t->pl.probe_size)
352+
return false;
353+
354+
if (t->pl.state == SCTP_PL_BASE) {
355+
if (pmtu >= SCTP_MIN_PLPMTU && pmtu < SCTP_BASE_PLPMTU) {
356+
t->pl.state = SCTP_PL_ERROR; /* Base -> Error */
357+
358+
t->pl.pmtu = SCTP_MIN_PLPMTU;
359+
t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t);
360+
}
361+
} else if (t->pl.state == SCTP_PL_SEARCH) {
362+
if (pmtu >= SCTP_BASE_PLPMTU && pmtu < t->pl.pmtu) {
363+
t->pl.state = SCTP_PL_BASE; /* Search -> Base */
364+
t->pl.probe_size = SCTP_BASE_PLPMTU;
365+
t->pl.probe_count = 0;
366+
367+
t->pl.probe_high = 0;
368+
t->pl.pmtu = SCTP_BASE_PLPMTU;
369+
t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t);
370+
} else if (pmtu > t->pl.pmtu && pmtu < t->pl.probe_size) {
371+
t->pl.probe_size = pmtu;
372+
t->pl.probe_count = 0;
373+
374+
return false;
375+
}
376+
} else if (t->pl.state == SCTP_PL_COMPLETE) {
377+
if (pmtu >= SCTP_BASE_PLPMTU && pmtu < t->pl.pmtu) {
378+
t->pl.state = SCTP_PL_BASE; /* Complete -> Base */
379+
t->pl.probe_size = SCTP_BASE_PLPMTU;
380+
t->pl.probe_count = 0;
381+
382+
t->pl.probe_high = 0;
383+
t->pl.pmtu = SCTP_BASE_PLPMTU;
384+
t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t);
385+
}
386+
}
387+
388+
return true;
389+
}
390+
346391
bool sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu)
347392
{
348-
struct dst_entry *dst = sctp_transport_dst_check(t);
349393
struct sock *sk = t->asoc->base.sk;
394+
struct dst_entry *dst;
350395
bool change = true;
351396

352397
if (unlikely(pmtu < SCTP_DEFAULT_MINSEGMENT)) {
@@ -357,6 +402,10 @@ bool sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu)
357402
}
358403
pmtu = SCTP_TRUNC4(pmtu);
359404

405+
if (sctp_transport_pl_enabled(t))
406+
return sctp_transport_pl_toobig(t, pmtu - sctp_transport_pl_hlen(t));
407+
408+
dst = sctp_transport_dst_check(t);
360409
if (dst) {
361410
struct sctp_pf *pf = sctp_get_pf_specific(dst->ops->family);
362411
union sctp_addr addr;

0 commit comments

Comments
 (0)