0005-batman-adv-Keep-fragments-equally-sized.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Tue, 28 Mar 2017 14:40:20 +0200
  3. Subject: batman-adv: Keep fragments equally sized
  4. diff --git a/batman-adv/patches/1004-batman-adv-Keep-fragments-equally-sized.patch b/batman-adv/patches/1004-batman-adv-Keep-fragments-equally-sized.patch
  5. new file mode 100644
  6. index 0000000000000000000000000000000000000000..431c0b4a1a722c4c2ebae390bc0c90be18966023
  7. --- /dev/null
  8. +++ b/batman-adv/patches/1004-batman-adv-Keep-fragments-equally-sized.patch
  9. @@ -0,0 +1,112 @@
  10. +From 450247570eacc8b6cf5484fe61c50eff804c6416 Mon Sep 17 00:00:00 2001
  11. +Message-Id: <450247570eacc8b6cf5484fe61c50eff804c6416.1489082253.git.mschiffer@universe-factory.net>
  12. +From: Sven Eckelmann <sven@narfation.org>
  13. +Date: Sat, 4 Mar 2017 17:29:25 +0100
  14. +Subject: [PATCH] batman-adv: Keep fragments equally sized
  15. +MIME-Version: 1.0
  16. +Content-Type: text/plain; charset=UTF-8
  17. +Content-Transfer-Encoding: 8bit
  18. +
  19. +The batman-adv fragmentation packets have the design problem that they
  20. +cannot be refragmented and cannot handle padding by the underlying link.
  21. +The latter often leads to problems when networks are incorrectly configured
  22. +and don't use a common MTU.
  23. +
  24. +The sender could for example fragment a 1271 byte frame (plus external
  25. +ethernet header (14) and batadv unicast header (10)) to fit in a 1280 bytes
  26. +large MTU of the underlying link (max. 1294 byte frames). This would create
  27. +a 1294 bytes large frame (fragment 2) and a 55 bytes large frame
  28. +(fragment 1). The extra 54 bytes are the fragment header (20) added to each
  29. +fragment and the external ethernet header (14) for the second fragment.
  30. +
  31. +Let us assume that the next hop is then not able to transport 1294 bytes to
  32. +its next hop. The 1294 byte large frame will be dropped but the 55 bytes
  33. +large fragment will still be forwarded to its destination.
  34. +
  35. +Or let us assume that the underlying hardware requires that each frame has
  36. +a minimum size (e.g. 60 bytes). Then it will pad the 55 bytes frame to 60
  37. +bytes. The receiver of the 60 bytes frame will no longer be able to
  38. +correctly assemble the two frames together because it is not aware that 5
  39. +bytes of the 60 bytes frame are padding and don't belong to the reassembled
  40. +frame.
  41. +
  42. +This can partly be avoided by splitting frames more equally. In this
  43. +example, the 675 and 674 bytes large fragment frames could both potentially
  44. +reach its destination without being too large or too small.
  45. +
  46. +Reported-by: Martin Weinelt <martin@darmstadt.freifunk.net>
  47. +Fixes: db56e4ecf5c2 ("batman-adv: Fragment and send skbs larger than mtu")
  48. +Signed-off-by: Sven Eckelmann <sven@narfation.org>
  49. +Acked-by: Linus Lüssing <linus.luessing@c0d3.blue>
  50. +Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
  51. +---
  52. + net/batman-adv/fragmentation.c | 20 +++++++++++++-------
  53. + 1 file changed, 13 insertions(+), 7 deletions(-)
  54. +
  55. +diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
  56. +index c3e293a3..89882ed7 100644
  57. +--- a/net/batman-adv/fragmentation.c
  58. ++++ b/net/batman-adv/fragmentation.c
  59. +@@ -396,7 +396,7 @@ out:
  60. + * batadv_frag_create - create a fragment from skb
  61. + * @skb: skb to create fragment from
  62. + * @frag_head: header to use in new fragment
  63. +- * @mtu: size of new fragment
  64. ++ * @fragment_size: size of new fragment
  65. + *
  66. + * Split the passed skb into two fragments: A new one with size matching the
  67. + * passed mtu and the old one with the rest. The new skb contains data from the
  68. +@@ -406,11 +406,11 @@ out:
  69. + */
  70. + static struct sk_buff *batadv_frag_create(struct sk_buff *skb,
  71. + struct batadv_frag_packet *frag_head,
  72. +- unsigned int mtu)
  73. ++ unsigned int fragment_size)
  74. + {
  75. + struct sk_buff *skb_fragment;
  76. + unsigned int header_size = sizeof(*frag_head);
  77. +- unsigned int fragment_size = mtu - header_size;
  78. ++ unsigned int mtu = fragment_size + header_size;
  79. +
  80. + skb_fragment = netdev_alloc_skb(NULL, mtu + ETH_HLEN);
  81. + if (!skb_fragment)
  82. +@@ -448,7 +448,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
  83. + struct sk_buff *skb_fragment;
  84. + unsigned int mtu = neigh_node->if_incoming->net_dev->mtu;
  85. + unsigned int header_size = sizeof(frag_header);
  86. +- unsigned int max_fragment_size, max_packet_size;
  87. ++ unsigned int max_fragment_size, num_fragments;
  88. + bool ret = false;
  89. +
  90. + /* To avoid merge and refragmentation at next-hops we never send
  91. +@@ -456,10 +456,15 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
  92. + */
  93. + mtu = min_t(unsigned int, mtu, BATADV_FRAG_MAX_FRAG_SIZE);
  94. + max_fragment_size = mtu - header_size;
  95. +- max_packet_size = max_fragment_size * BATADV_FRAG_MAX_FRAGMENTS;
  96. ++
  97. ++ if (skb->len == 0 || max_fragment_size == 0)
  98. ++ return -EINVAL;
  99. ++
  100. ++ num_fragments = (skb->len - 1) / max_fragment_size + 1;
  101. ++ max_fragment_size = (skb->len - 1) / num_fragments + 1;
  102. +
  103. + /* Don't even try to fragment, if we need more than 16 fragments */
  104. +- if (skb->len > max_packet_size)
  105. ++ if (num_fragments > BATADV_FRAG_MAX_FRAGMENTS)
  106. + goto out_err;
  107. +
  108. + bat_priv = orig_node->bat_priv;
  109. +@@ -480,7 +485,8 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
  110. +
  111. + /* Eat and send fragments from the tail of skb */
  112. + while (skb->len > max_fragment_size) {
  113. +- skb_fragment = batadv_frag_create(skb, &frag_header, mtu);
  114. ++ skb_fragment = batadv_frag_create(skb, &frag_header,
  115. ++ max_fragment_size);
  116. + if (!skb_fragment)
  117. + goto out_err;
  118. +
  119. +--
  120. +2.12.0
  121. +