]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
sctp: do state transition when receiving an icmp TOOBIG packet
authorXin Long <lucien.xin@gmail.com>
Tue, 22 Jun 2021 18:04:55 +0000 (14:04 -0400)
committerDavid S. Miller <davem@davemloft.net>
Tue, 22 Jun 2021 18:28:52 +0000 (11:28 -0700)
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 <lucien.xin@gmail.com>
Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sctp/input.c
net/sctp/transport.c

index d508f6f3dd08a33419c010d7944f9f70cacdd700..9ffdbd6526e95052c88647e5ab1000ba78280dee 100644 (file)
@@ -385,7 +385,9 @@ static int sctp_add_backlog(struct sock *sk, struct sk_buff *skb)
 void sctp_icmp_frag_needed(struct sock *sk, struct sctp_association *asoc,
                           struct sctp_transport *t, __u32 pmtu)
 {
-       if (!t || (t->pathmtu <= pmtu))
+       if (!t ||
+           (t->pathmtu <= pmtu &&
+            t->pl.probe_size + sctp_transport_pl_hlen(t) <= pmtu))
                return;
 
        if (sock_owned_by_user(sk)) {
index 79ff5ca6b472f7702522df970f0a4c0da5722236..5cefb4eab8a04df9b6f3e6942cd9a32ddc8e3c29 100644 (file)
@@ -343,10 +343,55 @@ void sctp_transport_pl_recv(struct sctp_transport *t)
        }
 }
 
+static bool sctp_transport_pl_toobig(struct sctp_transport *t, u32 pmtu)
+{
+       pr_debug("%s: PLPMTUD: transport: %p, state: %d, pmtu: %d, size: %d, ptb: %d\n",
+                __func__, t, t->pl.state, t->pl.pmtu, t->pl.probe_size, pmtu);
+
+       if (pmtu < SCTP_MIN_PLPMTU || pmtu >= t->pl.probe_size)
+               return false;
+
+       if (t->pl.state == SCTP_PL_BASE) {
+               if (pmtu >= SCTP_MIN_PLPMTU && pmtu < SCTP_BASE_PLPMTU) {
+                       t->pl.state = SCTP_PL_ERROR; /* Base -> Error */
+
+                       t->pl.pmtu = SCTP_MIN_PLPMTU;
+                       t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t);
+               }
+       } else if (t->pl.state == SCTP_PL_SEARCH) {
+               if (pmtu >= SCTP_BASE_PLPMTU && pmtu < t->pl.pmtu) {
+                       t->pl.state = SCTP_PL_BASE;  /* Search -> Base */
+                       t->pl.probe_size = SCTP_BASE_PLPMTU;
+                       t->pl.probe_count = 0;
+
+                       t->pl.probe_high = 0;
+                       t->pl.pmtu = SCTP_BASE_PLPMTU;
+                       t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t);
+               } else if (pmtu > t->pl.pmtu && pmtu < t->pl.probe_size) {
+                       t->pl.probe_size = pmtu;
+                       t->pl.probe_count = 0;
+
+                       return false;
+               }
+       } else if (t->pl.state == SCTP_PL_COMPLETE) {
+               if (pmtu >= SCTP_BASE_PLPMTU && pmtu < t->pl.pmtu) {
+                       t->pl.state = SCTP_PL_BASE;  /* Complete -> Base */
+                       t->pl.probe_size = SCTP_BASE_PLPMTU;
+                       t->pl.probe_count = 0;
+
+                       t->pl.probe_high = 0;
+                       t->pl.pmtu = SCTP_BASE_PLPMTU;
+                       t->pathmtu = t->pl.pmtu + sctp_transport_pl_hlen(t);
+               }
+       }
+
+       return true;
+}
+
 bool sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu)
 {
-       struct dst_entry *dst = sctp_transport_dst_check(t);
        struct sock *sk = t->asoc->base.sk;
+       struct dst_entry *dst;
        bool change = true;
 
        if (unlikely(pmtu < SCTP_DEFAULT_MINSEGMENT)) {
@@ -357,6 +402,10 @@ bool sctp_transport_update_pmtu(struct sctp_transport *t, u32 pmtu)
        }
        pmtu = SCTP_TRUNC4(pmtu);
 
+       if (sctp_transport_pl_enabled(t))
+               return sctp_transport_pl_toobig(t, pmtu - sctp_transport_pl_hlen(t));
+
+       dst = sctp_transport_dst_check(t);
        if (dst) {
                struct sctp_pf *pf = sctp_get_pf_specific(dst->ops->family);
                union sctp_addr addr;