batman-adv: Merge bugfixes from 2017.4
[feed/routing.git] / batman-adv / patches / 0008-batman-adv-Keep-fragments-equally-sized.patch
1 From: Sven Eckelmann <sven@narfation.org>
2 Date: Wed, 22 Feb 2017 17:25:42 +0100
3 Subject: [PATCH] batman-adv: Keep fragments equally sized
4
5 The batman-adv fragmentation packets have the design problem that they
6 cannot be refragmented. This often leads to problems when networks are
7 incorrectly configured and don't use a common MTU.
8
9 The sender could for example fragment a 1500 byte packet to fit in a 1280
10 bytes large MTU. This would create a 1280 large packet and a 284 bytes
11 large packet. But the next hop is then not able to transport 1280 bytes to
12 its next hop. The 1280 byte large packet will be dropped but the 284 bytes
13 large packet will still be forwarded to its destination.
14
15 This can partly being avoided by splitting packets more equally. In this
16 example, the two 782 bytes large packets could both potentially reach its
17 destination.
18
19 Signed-off-by: Sven Eckelmann <sven@narfation.org>
20 Acked-by: Linus Lüssing <linus.luessing@c0d3.blue>
21
22 Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/3caa5d14206ce8d4bd48bc931f213dec47ea1566
23 ---
24 net/batman-adv/fragmentation.c | 20 +++++++++++++-------
25 1 file changed, 13 insertions(+), 7 deletions(-)
26
27 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
28 index d33f16b9b8ac13ba630bf9ac8c5f4f0ca79fc878..70e512111528b0345889cea4ffd0ad5d984a4e6a 100644
29 --- a/net/batman-adv/fragmentation.c
30 +++ b/net/batman-adv/fragmentation.c
31 @@ -404,7 +404,7 @@ out:
32 * batadv_frag_create - create a fragment from skb
33 * @skb: skb to create fragment from
34 * @frag_head: header to use in new fragment
35 - * @mtu: size of new fragment
36 + * @fragment_size: size of new fragment
37 *
38 * Split the passed skb into two fragments: A new one with size matching the
39 * passed mtu and the old one with the rest. The new skb contains data from the
40 @@ -414,11 +414,11 @@ out:
41 */
42 static struct sk_buff *batadv_frag_create(struct sk_buff *skb,
43 struct batadv_frag_packet *frag_head,
44 - unsigned int mtu)
45 + unsigned int fragment_size)
46 {
47 struct sk_buff *skb_fragment;
48 unsigned int header_size = sizeof(*frag_head);
49 - unsigned int fragment_size = mtu - header_size;
50 + unsigned int mtu = fragment_size + header_size;
51
52 skb_fragment = netdev_alloc_skb(NULL, mtu + ETH_HLEN);
53 if (!skb_fragment)
54 @@ -456,7 +456,7 @@ int batadv_frag_send_packet(struct sk_buff *skb,
55 struct sk_buff *skb_fragment;
56 unsigned int mtu = neigh_node->if_incoming->net_dev->mtu;
57 unsigned int header_size = sizeof(frag_header);
58 - unsigned int max_fragment_size, max_packet_size;
59 + unsigned int max_fragment_size, num_fragments;
60 int ret;
61
62 /* To avoid merge and refragmentation at next-hops we never send
63 @@ -464,10 +464,15 @@ int batadv_frag_send_packet(struct sk_buff *skb,
64 */
65 mtu = min_t(unsigned int, mtu, BATADV_FRAG_MAX_FRAG_SIZE);
66 max_fragment_size = mtu - header_size;
67 - max_packet_size = max_fragment_size * BATADV_FRAG_MAX_FRAGMENTS;
68 +
69 + if (skb->len == 0 || max_fragment_size == 0)
70 + return -EINVAL;
71 +
72 + num_fragments = (skb->len - 1) / max_fragment_size + 1;
73 + max_fragment_size = (skb->len - 1) / num_fragments + 1;
74
75 /* Don't even try to fragment, if we need more than 16 fragments */
76 - if (skb->len > max_packet_size) {
77 + if (num_fragments > BATADV_FRAG_MAX_FRAGMENTS) {
78 ret = -EAGAIN;
79 goto free_skb;
80 }
81 @@ -507,7 +512,8 @@ int batadv_frag_send_packet(struct sk_buff *skb,
82 goto put_primary_if;
83 }
84
85 - skb_fragment = batadv_frag_create(skb, &frag_header, mtu);
86 + skb_fragment = batadv_frag_create(skb, &frag_header,
87 + max_fragment_size);
88 if (!skb_fragment) {
89 ret = -ENOMEM;
90 goto put_primary_if;