batman-adv: Add bugfixes for 2017.0.1
[feed/routing.git] / batman-adv / patches / 0002-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 and cannot handle padding by the underlying link.
7 The latter often leads to problems when networks are incorrectly configured
8 and don't use a common MTU.
9
10 The sender could for example fragment a 1271 byte frame (plus external
11 ethernet header (14) and batadv unicast header (10)) to fit in a 1280 bytes
12 large MTU of the underlying link (max. 1294 byte frames). This would create
13 a 1294 bytes large frame (fragment 2) and a 55 bytes large frame
14 (fragment 1). The extra 54 bytes are the fragment header (20) added to each
15 fragment and the external ethernet header (14) for the second fragment.
16
17 Let us assume that the next hop is then not able to transport 1294 bytes to
18 its next hop. The 1294 byte large frame will be dropped but the 55 bytes
19 large fragment will still be forwarded to its destination.
20
21 Or let us assume that the underlying hardware requires that each frame has
22 a minimum size (e.g. 60 bytes). Then it will pad the 55 bytes frame to 60
23 bytes. The receiver of the 60 bytes frame will no longer be able to
24 correctly assemble the two frames together because it is not aware that 5
25 bytes of the 60 bytes frame are padding and don't belong to the reassembled
26 frame.
27
28 This can partly be avoided by splitting frames more equally. In this
29 example, the 675 and 674 bytes large fragment frames could both potentially
30 reach its destination without being too large or too small.
31
32 Reported-by: Martin Weinelt <martin@darmstadt.freifunk.net>
33 Fixes: db56e4ecf5c2 ("batman-adv: Fragment and send skbs larger than mtu")
34 Signed-off-by: Sven Eckelmann <sven@narfation.org>
35 Acked-by: Linus Lüssing <linus.luessing@c0d3.blue>
36 ---
37 net/batman-adv/fragmentation.c | 20 +++++++++++++-------
38 1 file changed, 13 insertions(+), 7 deletions(-)
39
40 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
41 index 11a23fd6..8f964bea 100644
42 --- a/net/batman-adv/fragmentation.c
43 +++ b/net/batman-adv/fragmentation.c
44 @@ -404,7 +404,7 @@ bool batadv_frag_skb_fwd(struct sk_buff *skb,
45 * batadv_frag_create - create a fragment from skb
46 * @skb: skb to create fragment from
47 * @frag_head: header to use in new fragment
48 - * @mtu: size of new fragment
49 + * @fragment_size: size of new fragment
50 *
51 * Split the passed skb into two fragments: A new one with size matching the
52 * passed mtu and the old one with the rest. The new skb contains data from the
53 @@ -414,11 +414,11 @@ bool batadv_frag_skb_fwd(struct sk_buff *skb,
54 */
55 static struct sk_buff *batadv_frag_create(struct sk_buff *skb,
56 struct batadv_frag_packet *frag_head,
57 - unsigned int mtu)
58 + unsigned int fragment_size)
59 {
60 struct sk_buff *skb_fragment;
61 unsigned int header_size = sizeof(*frag_head);
62 - unsigned int fragment_size = mtu - header_size;
63 + unsigned int mtu = fragment_size + header_size;
64
65 skb_fragment = netdev_alloc_skb(NULL, mtu + ETH_HLEN);
66 if (!skb_fragment)
67 @@ -456,7 +456,7 @@ int batadv_frag_send_packet(struct sk_buff *skb,
68 struct sk_buff *skb_fragment;
69 unsigned int mtu = neigh_node->if_incoming->net_dev->mtu;
70 unsigned int header_size = sizeof(frag_header);
71 - unsigned int max_fragment_size, max_packet_size;
72 + unsigned int max_fragment_size, num_fragments;
73 int ret;
74
75 /* To avoid merge and refragmentation at next-hops we never send
76 @@ -464,10 +464,15 @@ int batadv_frag_send_packet(struct sk_buff *skb,
77 */
78 mtu = min_t(unsigned int, mtu, BATADV_FRAG_MAX_FRAG_SIZE);
79 max_fragment_size = mtu - header_size;
80 - max_packet_size = max_fragment_size * BATADV_FRAG_MAX_FRAGMENTS;
81 +
82 + if (skb->len == 0 || max_fragment_size == 0)
83 + return -EINVAL;
84 +
85 + num_fragments = (skb->len - 1) / max_fragment_size + 1;
86 + max_fragment_size = (skb->len - 1) / num_fragments + 1;
87
88 /* Don't even try to fragment, if we need more than 16 fragments */
89 - if (skb->len > max_packet_size) {
90 + if (num_fragments > BATADV_FRAG_MAX_FRAGMENTS) {
91 ret = -EAGAIN;
92 goto free_skb;
93 }
94 @@ -507,7 +512,8 @@ int batadv_frag_send_packet(struct sk_buff *skb,
95 goto put_primary_if;
96 }
97
98 - skb_fragment = batadv_frag_create(skb, &frag_header, mtu);
99 + skb_fragment = batadv_frag_create(skb, &frag_header,
100 + max_fragment_size);
101 if (!skb_fragment) {
102 ret = -ENOMEM;
103 goto put_primary_if;