Author: tuexen
Date: Wed Jun  6 19:56:19 2018
New Revision: 334729
URL: https://svnweb.freebsd.org/changeset/base/334729

Log:
  MFC r333603:
  
  Ensure that the MTU's used are multiple of 4.
  
  The length of SCTP packets is always a multiple of 4. Therefore,
  ensure that the MTUs used are also a multiple of 4.
  
  Thanks to Irene Ruengeler for providing an earlier version of this
  patch.
  
  MFC r334286:
  
  Use correct mask.
  Introduced in https://svnweb.freebsd.org/changeset/base/333603.
  Thanks to Irene Ruengler for testing and reporting the issue.

Modified:
  stable/11/sys/netinet/sctputil.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/netinet/sctputil.c
==============================================================================
--- stable/11/sys/netinet/sctputil.c    Wed Jun  6 19:51:55 2018        
(r334728)
+++ stable/11/sys/netinet/sctputil.c    Wed Jun  6 19:56:19 2018        
(r334729)
@@ -756,8 +756,8 @@ sctp_stop_timers_for_shutdown(struct sctp_tcb *stcb)
 }
 
 /*
- * a list of sizes based on typical mtu's, used only if next hop size not
- * returned.
+ * A list of sizes based on typical mtu's, used only if next hop size not
+ * returned. These values MUST be multiples of 4 and MUST be ordered.
  */
 static uint32_t sctp_mtu_sizes[] = {
        68,
@@ -766,29 +766,32 @@ static uint32_t sctp_mtu_sizes[] = {
        512,
        544,
        576,
-       1006,
+       1004,
        1492,
        1500,
        1536,
-       2002,
+       2000,
        2048,
        4352,
        4464,
        8166,
-       17914,
+       17912,
        32000,
-       65535
+       65532
 };
 
 /*
- * Return the largest MTU smaller than val. If there is no
- * entry, just return val.
+ * Return the largest MTU in sctp_mtu_sizes smaller than val.
+ * If val is smaller than the minimum, just return the largest
+ * multiple of 4 smaller or equal to val.
+ * Ensure that the result is a multiple of 4.
  */
 uint32_t
 sctp_get_prev_mtu(uint32_t val)
 {
        uint32_t i;
 
+       val &= 0xfffffffc;
        if (val <= sctp_mtu_sizes[0]) {
                return (val);
        }
@@ -797,12 +800,16 @@ sctp_get_prev_mtu(uint32_t val)
                        break;
                }
        }
+       KASSERT((sctp_mtu_sizes[i - 1] & 0x00000003) == 0,
+           ("sctp_mtu_sizes[%u] not a multiple of 4", i - 1));
        return (sctp_mtu_sizes[i - 1]);
 }
 
 /*
- * Return the smallest MTU larger than val. If there is no
- * entry, just return val.
+ * Return the smallest MTU in sctp_mtu_sizes larger than val.
+ * If val is larger than the maximum, just return the largest multiple of 4 
smaller
+ * or equal to val.
+ * Ensure that the result is a multiple of 4.
  */
 uint32_t
 sctp_get_next_mtu(uint32_t val)
@@ -810,8 +817,11 @@ sctp_get_next_mtu(uint32_t val)
        /* select another MTU that is just bigger than this one */
        uint32_t i;
 
+       val &= 0xfffffffc;
        for (i = 0; i < (sizeof(sctp_mtu_sizes) / sizeof(uint32_t)); i++) {
                if (val < sctp_mtu_sizes[i]) {
+                       KASSERT((sctp_mtu_sizes[i] & 0x00000003) == 0,
+                           ("sctp_mtu_sizes[%u] not a multiple of 4", i));
                        return (sctp_mtu_sizes[i]);
                }
        }
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to