diff options
author | Sven Eckelmann <sven@narfation.org> | 2011-01-25 17:02:31 -0500 |
---|---|---|
committer | Sven Eckelmann <sven@narfation.org> | 2011-01-31 08:57:08 -0500 |
commit | ae361ce19fa135035c6b83ac1f07090b72fd4b8f (patch) | |
tree | 00410704b2dd5f0d7310f5cb9796385d7e8b7e91 | |
parent | 5c77d8bb8aeb4ec6804b6c32061109ba2ea6988d (diff) |
batman-adv: Calculate correct size for merged packets
The routing algorithm must be able to decide if a fragment can be merged with
the missing part and still be passed to a forwarding interface. The fragments
can only differ by one byte in case that the original payload had an uneven
length. In that situation the sender has to inform all possible receivers that
the tail is one byte longer using the flag UNI_FRAG_LARGETAIL.
The combination of UNI_FRAG_LARGETAIL and UNI_FRAG_HEAD flag makes it possible
to calculate the correct length for even and uneven sized payloads.
The original formula missed to add the unicast header at all and forgot to
remove the fragment header of the second fragment. This made the results highly
unreliable and only useful for machines with large differences between the
configured MTUs.
Reported-by: Russell Senior <russell@personaltelco.net>
Reported-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
-rw-r--r-- | net/batman-adv/packet.h | 1 | ||||
-rw-r--r-- | net/batman-adv/routing.c | 2 | ||||
-rw-r--r-- | net/batman-adv/unicast.c | 8 | ||||
-rw-r--r-- | net/batman-adv/unicast.h | 23 |
4 files changed, 31 insertions, 3 deletions
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h index 2284e8129cb2..03ce0d314c9e 100644 --- a/net/batman-adv/packet.h +++ b/net/batman-adv/packet.h | |||
@@ -50,6 +50,7 @@ | |||
50 | 50 | ||
51 | /* fragmentation defines */ | 51 | /* fragmentation defines */ |
52 | #define UNI_FRAG_HEAD 0x01 | 52 | #define UNI_FRAG_HEAD 0x01 |
53 | #define UNI_FRAG_LARGETAIL 0x02 | ||
53 | 54 | ||
54 | struct batman_packet { | 55 | struct batman_packet { |
55 | uint8_t packet_type; | 56 | uint8_t packet_type; |
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index 8828eddd3f72..a8cd3897b7d0 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c | |||
@@ -1193,7 +1193,7 @@ int route_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if, | |||
1193 | dstaddr); | 1193 | dstaddr); |
1194 | 1194 | ||
1195 | if (unicast_packet->packet_type == BAT_UNICAST_FRAG && | 1195 | if (unicast_packet->packet_type == BAT_UNICAST_FRAG && |
1196 | 2 * skb->len - hdr_size <= batman_if->net_dev->mtu) { | 1196 | frag_can_reassemble(skb, batman_if->net_dev->mtu)) { |
1197 | 1197 | ||
1198 | ret = frag_reassemble_skb(skb, bat_priv, &new_skb); | 1198 | ret = frag_reassemble_skb(skb, bat_priv, &new_skb); |
1199 | 1199 | ||
diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c index 811f7fc7932d..fc77079b18bb 100644 --- a/net/batman-adv/unicast.c +++ b/net/batman-adv/unicast.c | |||
@@ -225,6 +225,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, | |||
225 | int uc_hdr_len = sizeof(struct unicast_packet); | 225 | int uc_hdr_len = sizeof(struct unicast_packet); |
226 | int ucf_hdr_len = sizeof(struct unicast_frag_packet); | 226 | int ucf_hdr_len = sizeof(struct unicast_frag_packet); |
227 | int data_len = skb->len - uc_hdr_len; | 227 | int data_len = skb->len - uc_hdr_len; |
228 | int large_tail = 0; | ||
228 | 229 | ||
229 | if (!bat_priv->primary_if) | 230 | if (!bat_priv->primary_if) |
230 | goto dropped; | 231 | goto dropped; |
@@ -254,8 +255,11 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, | |||
254 | memcpy(frag1->orig, bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN); | 255 | memcpy(frag1->orig, bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN); |
255 | memcpy(frag2, frag1, sizeof(struct unicast_frag_packet)); | 256 | memcpy(frag2, frag1, sizeof(struct unicast_frag_packet)); |
256 | 257 | ||
257 | frag1->flags |= UNI_FRAG_HEAD; | 258 | if (data_len & 1) |
258 | frag2->flags &= ~UNI_FRAG_HEAD; | 259 | large_tail = UNI_FRAG_LARGETAIL; |
260 | |||
261 | frag1->flags = UNI_FRAG_HEAD | large_tail; | ||
262 | frag2->flags = large_tail; | ||
259 | 263 | ||
260 | frag1->seqno = htons((uint16_t)atomic_inc_return( | 264 | frag1->seqno = htons((uint16_t)atomic_inc_return( |
261 | &batman_if->frag_seqno)); | 265 | &batman_if->frag_seqno)); |
diff --git a/net/batman-adv/unicast.h b/net/batman-adv/unicast.h index e32b7867a9a4..e7211c279201 100644 --- a/net/batman-adv/unicast.h +++ b/net/batman-adv/unicast.h | |||
@@ -22,6 +22,8 @@ | |||
22 | #ifndef _NET_BATMAN_ADV_UNICAST_H_ | 22 | #ifndef _NET_BATMAN_ADV_UNICAST_H_ |
23 | #define _NET_BATMAN_ADV_UNICAST_H_ | 23 | #define _NET_BATMAN_ADV_UNICAST_H_ |
24 | 24 | ||
25 | #include "packet.h" | ||
26 | |||
25 | #define FRAG_TIMEOUT 10000 /* purge frag list entrys after time in ms */ | 27 | #define FRAG_TIMEOUT 10000 /* purge frag list entrys after time in ms */ |
26 | #define FRAG_BUFFER_SIZE 6 /* number of list elements in buffer */ | 28 | #define FRAG_BUFFER_SIZE 6 /* number of list elements in buffer */ |
27 | 29 | ||
@@ -32,4 +34,25 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv); | |||
32 | int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, | 34 | int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, |
33 | struct batman_if *batman_if, uint8_t dstaddr[]); | 35 | struct batman_if *batman_if, uint8_t dstaddr[]); |
34 | 36 | ||
37 | static inline int frag_can_reassemble(struct sk_buff *skb, int mtu) | ||
38 | { | ||
39 | struct unicast_frag_packet *unicast_packet; | ||
40 | int uneven_correction = 0; | ||
41 | unsigned int merged_size; | ||
42 | |||
43 | unicast_packet = (struct unicast_frag_packet *)skb->data; | ||
44 | |||
45 | if (unicast_packet->flags & UNI_FRAG_LARGETAIL) { | ||
46 | if (unicast_packet->flags & UNI_FRAG_HEAD) | ||
47 | uneven_correction = 1; | ||
48 | else | ||
49 | uneven_correction = -1; | ||
50 | } | ||
51 | |||
52 | merged_size = (skb->len - sizeof(struct unicast_frag_packet)) * 2; | ||
53 | merged_size += sizeof(struct unicast_packet) + uneven_correction; | ||
54 | |||
55 | return merged_size <= mtu; | ||
56 | } | ||
57 | |||
35 | #endif /* _NET_BATMAN_ADV_UNICAST_H_ */ | 58 | #endif /* _NET_BATMAN_ADV_UNICAST_H_ */ |