The routing algorithm must know how large two fragments are to be able to decide that it is safe to merge them or if it should resubmit without waiting for the second part. When these two fragments have a too different size, it is not possible to guess right in every situation.
The user could easily configure the MTU of the attached cards so that one fragment is forwarded and the other one is added to the fragments table to wait for the missing part.
For even sized packages it is possible to split it so that the resulting packages are equal sized by ignoring the old non-fragment header at the beginning of the original packet.
This still creates different sized fragments for uneven sized packets.
Reported-by: Russell Senior russell@personaltelco.net Reported-by: Marek Lindner lindner_marek@yahoo.de Signed-off-by: Sven Eckelmann sven@narfation.org --- This patch is completely untested and is currently only to support marec and russell-- during their debugging sessions. Maybe it doesn't even compile.
batman-adv/unicast.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/batman-adv/unicast.c b/batman-adv/unicast.c index 677663b..84e70bc 100644 --- a/batman-adv/unicast.c +++ b/batman-adv/unicast.c @@ -230,7 +230,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, struct unicast_frag_packet *frag1, *frag2; int uc_hdr_len = sizeof(struct unicast_packet); int ucf_hdr_len = sizeof(struct unicast_frag_packet); - int data_len = skb->len; + int data_len = skb->len - uc_hdr_len;
if (!bat_priv->primary_if) goto dropped; @@ -238,10 +238,11 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, frag_skb = dev_alloc_skb(data_len - (data_len / 2) + ucf_hdr_len); if (!frag_skb) goto dropped; + skb_reserve(frag_skb, ucf_hdr_len);
unicast_packet = (struct unicast_packet *) skb->data; memcpy(&tmp_uc, unicast_packet, uc_hdr_len); - skb_split(skb, frag_skb, data_len / 2); + skb_split(skb, frag_skb, data_len / 2 + uc_hdr_len);
if (my_skb_head_push(skb, ucf_hdr_len - uc_hdr_len) < 0 || my_skb_head_push(frag_skb, ucf_hdr_len) < 0)
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 --- This patch is completely untested and is currently only to support marec and russell-- during their debugging sessions. Maybe it doesn't even compile.
batman-adv/packet.h | 1 + batman-adv/routing.c | 24 +++++++++++++++++++++++- batman-adv/unicast.c | 10 ++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/batman-adv/packet.h b/batman-adv/packet.h index 2284e81..03ce0d3 100644 --- a/batman-adv/packet.h +++ b/batman-adv/packet.h @@ -50,6 +50,7 @@
/* fragmentation defines */ #define UNI_FRAG_HEAD 0x01 +#define UNI_FRAG_LARGETAIL 0x02
struct batman_packet { uint8_t packet_type; diff --git a/batman-adv/routing.c b/batman-adv/routing.c index a90d105..71dd69f 100644 --- a/batman-adv/routing.c +++ b/batman-adv/routing.c @@ -1243,6 +1243,28 @@ static int check_unicast_packet(struct sk_buff *skb, int hdr_size) return 0; }
+static int frag_can_reassemble(struct sk_buff *skb, int mtu) +{ + struct unicast_frag_packet *unicast_packet; + int uneven_correction = 0; + unsigned int merged_size; + + unicast_packet = (struct unicast_frag_packet *)skb->data; + + if (unicast_packet->flags & UNI_FRAG_LARGETAIL) { + if (unicast_packet->flags & UNI_FRAG_HEAD) + uneven_correction = 1; + else + uneven_correction = -1; + } + + merged_size = (skb->len - sizeof(struct unicast_frag_packet)) * 2; + merged_size += sizeof(struct unicast_packet); + merged_size += uneven_correction; + + return merged_size <= mtu; +} + int route_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if, int hdr_size) { @@ -1297,7 +1319,7 @@ int route_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if, }
if (unicast_packet->packet_type == BAT_UNICAST_FRAG && - 2 * skb->len - hdr_size <= neigh_node->if_incoming->net_dev->mtu) { + frag_can_reassemble(skb, neigh_node->if_incoming->net_dev->mtu)) {
ret = frag_reassemble_skb(skb, bat_priv, &new_skb);
diff --git a/batman-adv/unicast.c b/batman-adv/unicast.c index 84e70bc..6340f28 100644 --- a/batman-adv/unicast.c +++ b/batman-adv/unicast.c @@ -231,6 +231,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, int uc_hdr_len = sizeof(struct unicast_packet); int ucf_hdr_len = sizeof(struct unicast_frag_packet); int data_len = skb->len - uc_hdr_len; + int large_tail;
if (!bat_priv->primary_if) goto dropped; @@ -260,8 +261,13 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, memcpy(frag1->orig, bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(frag2, frag1, sizeof(struct unicast_frag_packet));
- frag1->flags |= UNI_FRAG_HEAD; - frag2->flags &= ~UNI_FRAG_HEAD; + if (data_len & 1) + large_tail = UNI_FRAG_LARGETAIL; + else + large_tail = 0; + + frag1->flags = UNI_FRAG_HEAD | large_tail; + frag2->flags = large_tail;
frag1->seqno = htons((uint16_t)atomic_inc_return( &batman_if->frag_seqno));
The routing algorithm must know how large two fragments are to be able to decide that it is safe to merge them or if it should resubmit without waiting for the second part. When these two fragments have a too different size, it is not possible to guess right in every situation.
The user could easily configure the MTU of the attached cards so that one fragment is forwarded and the other one is added to the fragments table to wait for the missing part.
For even sized packets, it is possible to split it so that the resulting packages are equal sized by ignoring the old non-fragment header at the beginning of the original packet.
This still creates different sized fragments for uneven sized packets.
Reported-by: Russell Senior russell@personaltelco.net Reported-by: Marek Lindner lindner_marek@yahoo.de Signed-off-by: Sven Eckelmann sven@narfation.org --- This patch is completely untested and is currently only to support marec and russell-- during their debugging sessions. Maybe it doesn't even compile.
batman-adv/unicast.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/batman-adv/unicast.c b/batman-adv/unicast.c index 677663b..84e70bc 100644 --- a/batman-adv/unicast.c +++ b/batman-adv/unicast.c @@ -230,7 +230,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, struct unicast_frag_packet *frag1, *frag2; int uc_hdr_len = sizeof(struct unicast_packet); int ucf_hdr_len = sizeof(struct unicast_frag_packet); - int data_len = skb->len; + int data_len = skb->len - uc_hdr_len;
if (!bat_priv->primary_if) goto dropped; @@ -238,10 +238,11 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, frag_skb = dev_alloc_skb(data_len - (data_len / 2) + ucf_hdr_len); if (!frag_skb) goto dropped; + skb_reserve(frag_skb, ucf_hdr_len);
unicast_packet = (struct unicast_packet *) skb->data; memcpy(&tmp_uc, unicast_packet, uc_hdr_len); - skb_split(skb, frag_skb, data_len / 2); + skb_split(skb, frag_skb, data_len / 2 + uc_hdr_len);
if (my_skb_head_push(skb, ucf_hdr_len - uc_hdr_len) < 0 || my_skb_head_push(frag_skb, ucf_hdr_len) < 0)
On Friday 21 January 2011 00:00:18 Sven Eckelmann wrote:
The routing algorithm must know how large two fragments are to be able to decide that it is safe to merge them or if it should resubmit without waiting for the second part. When these two fragments have a too different size, it is not possible to guess right in every situation.
Applied in revision 1915.
Thanks, Marek
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 --- This patch is completely untested and is currently only to support marec and russell-- during their debugging sessions. Maybe it doesn't even compile.
Reduced size of patch slightly.
batman-adv/packet.h | 1 + batman-adv/routing.c | 24 +++++++++++++++++++++++- batman-adv/unicast.c | 8 ++++++-- 3 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/batman-adv/packet.h b/batman-adv/packet.h index 2284e81..03ce0d3 100644 --- a/batman-adv/packet.h +++ b/batman-adv/packet.h @@ -50,6 +50,7 @@
/* fragmentation defines */ #define UNI_FRAG_HEAD 0x01 +#define UNI_FRAG_LARGETAIL 0x02
struct batman_packet { uint8_t packet_type; diff --git a/batman-adv/routing.c b/batman-adv/routing.c index a90d105..71dd69f 100644 --- a/batman-adv/routing.c +++ b/batman-adv/routing.c @@ -1243,6 +1243,28 @@ static int check_unicast_packet(struct sk_buff *skb, int hdr_size) return 0; }
+static int frag_can_reassemble(struct sk_buff *skb, int mtu) +{ + struct unicast_frag_packet *unicast_packet; + int uneven_correction = 0; + unsigned int merged_size; + + unicast_packet = (struct unicast_frag_packet *)skb->data; + + if (unicast_packet->flags & UNI_FRAG_LARGETAIL) { + if (unicast_packet->flags & UNI_FRAG_HEAD) + uneven_correction = 1; + else + uneven_correction = -1; + } + + merged_size = (skb->len - sizeof(struct unicast_frag_packet)) * 2; + merged_size += sizeof(struct unicast_packet); + merged_size += uneven_correction; + + return merged_size <= mtu; +} + int route_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if, int hdr_size) { @@ -1297,7 +1319,7 @@ int route_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if, }
if (unicast_packet->packet_type == BAT_UNICAST_FRAG && - 2 * skb->len - hdr_size <= neigh_node->if_incoming->net_dev->mtu) { + frag_can_reassemble(skb, neigh_node->if_incoming->net_dev->mtu)) {
ret = frag_reassemble_skb(skb, bat_priv, &new_skb);
diff --git a/batman-adv/unicast.c b/batman-adv/unicast.c index 84e70bc..f88e86c 100644 --- a/batman-adv/unicast.c +++ b/batman-adv/unicast.c @@ -231,6 +231,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, int uc_hdr_len = sizeof(struct unicast_packet); int ucf_hdr_len = sizeof(struct unicast_frag_packet); int data_len = skb->len - uc_hdr_len; + int large_tail = 0;
if (!bat_priv->primary_if) goto dropped; @@ -260,8 +261,11 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, memcpy(frag1->orig, bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(frag2, frag1, sizeof(struct unicast_frag_packet));
- frag1->flags |= UNI_FRAG_HEAD; - frag2->flags &= ~UNI_FRAG_HEAD; + if (data_len & 1) + large_tail = UNI_FRAG_LARGETAIL; + + frag1->flags = UNI_FRAG_HEAD | large_tail; + frag2->flags = large_tail;
frag1->seqno = htons((uint16_t)atomic_inc_return( &batman_if->frag_seqno));
On Friday 21 January 2011 00:00:19 Sven Eckelmann wrote:
This patch is completely untested and is currently only to support marec and russell-- during their debugging sessions. Maybe it doesn't even compile.
Thanks Sven! I think this is another bugfix we'll need for the fragmentation.
--- a/batman-adv/routing.c +++ b/batman-adv/routing.c @@ -1243,6 +1243,28 @@ static int check_unicast_packet(struct sk_buff *skb, int hdr_size) return 0; }
+static int frag_can_reassemble(struct sk_buff *skb, int mtu)
I'd suggest we move this function into unicast.c to let it join all the other fragmentation related functions there. Apart from that it looks good. We might want to do some more testing though.
Regards, Marek
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 --- This patch is completely untested and is currently only to support marec and russell-- during their debugging sessions. Maybe it doesn't even compile.
Moved frag_can_reassemble to unicast.c -> makes it uninlinable
batman-adv/packet.h | 1 + batman-adv/routing.c | 2 +- batman-adv/unicast.c | 29 +++++++++++++++++++++++++++-- batman-adv/unicast.h | 1 + 4 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/batman-adv/packet.h b/batman-adv/packet.h index 2284e81..03ce0d3 100644 --- a/batman-adv/packet.h +++ b/batman-adv/packet.h @@ -50,6 +50,7 @@
/* fragmentation defines */ #define UNI_FRAG_HEAD 0x01 +#define UNI_FRAG_LARGETAIL 0x02
struct batman_packet { uint8_t packet_type; diff --git a/batman-adv/routing.c b/batman-adv/routing.c index a90d105..87ea1b8 100644 --- a/batman-adv/routing.c +++ b/batman-adv/routing.c @@ -1297,7 +1297,7 @@ int route_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if, }
if (unicast_packet->packet_type == BAT_UNICAST_FRAG && - 2 * skb->len - hdr_size <= neigh_node->if_incoming->net_dev->mtu) { + frag_can_reassemble(skb, neigh_node->if_incoming->net_dev->mtu)) {
ret = frag_reassemble_skb(skb, bat_priv, &new_skb);
diff --git a/batman-adv/unicast.c b/batman-adv/unicast.c index 84e70bc..20aefb5 100644 --- a/batman-adv/unicast.c +++ b/batman-adv/unicast.c @@ -231,6 +231,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, int uc_hdr_len = sizeof(struct unicast_packet); int ucf_hdr_len = sizeof(struct unicast_frag_packet); int data_len = skb->len - uc_hdr_len; + int large_tail = 0;
if (!bat_priv->primary_if) goto dropped; @@ -260,8 +261,11 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, memcpy(frag1->orig, bat_priv->primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(frag2, frag1, sizeof(struct unicast_frag_packet));
- frag1->flags |= UNI_FRAG_HEAD; - frag2->flags &= ~UNI_FRAG_HEAD; + if (data_len & 1) + large_tail = UNI_FRAG_LARGETAIL; + + frag1->flags = UNI_FRAG_HEAD | large_tail; + frag2->flags = large_tail;
frag1->seqno = htons((uint16_t)atomic_inc_return( &batman_if->frag_seqno)); @@ -366,3 +370,24 @@ out: kfree_skb(skb); return ret; } + +int frag_can_reassemble(struct sk_buff *skb, int mtu) +{ + struct unicast_frag_packet *unicast_packet; + int uneven_correction = 0; + unsigned int merged_size; + + unicast_packet = (struct unicast_frag_packet *)skb->data; + + if (unicast_packet->flags & UNI_FRAG_LARGETAIL) { + if (unicast_packet->flags & UNI_FRAG_HEAD) + uneven_correction = 1; + else + uneven_correction = -1; + } + + merged_size = (skb->len - sizeof(struct unicast_frag_packet)) * 2; + merged_size += sizeof(struct unicast_packet) + uneven_correction; + + return merged_size <= mtu; +} diff --git a/batman-adv/unicast.h b/batman-adv/unicast.h index e32b786..b0e29df 100644 --- a/batman-adv/unicast.h +++ b/batman-adv/unicast.h @@ -31,5 +31,6 @@ void frag_list_free(struct list_head *head); int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv); int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, struct batman_if *batman_if, uint8_t dstaddr[]); +int frag_can_reassemble(struct sk_buff *skb, int mtu);
#endif /* _NET_BATMAN_ADV_UNICAST_H_ */
On Friday 21 January 2011 18:39:04 Sven Eckelmann wrote:
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.
Applied in revision 1916.
Thanks, Marek
b.a.t.m.a.n@lists.open-mesh.org