[marek] batman-adv: Unify the first 3 bytes in each packet
Commit Message
From: Antonio Quartulli <ordex@autistici.org>
The amount of duplicated code in the receive and routing code can be reduced
when all headers provide the packet type, version and ttl in the same first
bytes.
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
* Only the first 3 bytes have to be the same.
* vis_packet was not changed yet.
packet.h | 30 ++++++++++++++++++------------
1 files changed, 18 insertions(+), 12 deletions(-)
Comments
On Saturday 28 May 2011 13:45:29 Marek Lindner wrote:
> @@ -99,16 +100,19 @@ struct icmp_packet_rr {
> struct unicast_packet {
> uint8_t packet_type;
> uint8_t version; /* batman version field */
> - uint8_t dest[6];
> uint8_t ttl;
> + uint8_t reserved;
> + uint8_t dest[6];
> } __packed;
>
> struct unicast_frag_packet {
> uint8_t packet_type;
> uint8_t version; /* batman version field */
> - uint8_t dest[6];
> uint8_t ttl;
> + uint8_t reserved;
> + uint8_t dest[6];
> uint8_t flags;
> + uint8_t align;
> uint8_t orig[6];
> uint16_t seqno;
> } __packed;
Why dont you use the reserverd part for the flags which are currently not in
unicast? Then you could also remove that other align byte. It would still be
possible to add flags to unicast packets when necessary.
> @@ -116,18 +120,20 @@ struct unicast_frag_packet {
> struct bcast_packet {
> uint8_t packet_type;
> uint8_t version; /* batman version field */
> - uint8_t orig[6];
> uint8_t ttl;
> + uint8_t reserved;
> + uint8_t orig[6];
> uint32_t seqno;
> } __packed;
Wouldn't that lead to an unaligned seqno?
Kind regards,
Sven
On Saturday 28 May 2011 14:07:10 Sven Eckelmann wrote:
> Why dont you use the reserverd part for the flags which are currently not
> in unicast? Then you could also remove that other align byte. It would
> still be possible to add flags to unicast packets when necessary.
The unicast_frag header assumes it looks like the unicast header plus some
extra fields:
struct unicast_frag_packet {
struct unicast_packet unicast_packet;
uint8_t flags;
uint8_t align;
uint8_t orig[6];
uint16_t seqno;
};
We probably should add a little comment there to make that clear.
Both reserved fields (unicast + unicast frag) are going to be converted to
ttvn with the tt patches.
> > + uint8_t reserved;
> > + uint8_t orig[6];
> >
> > uint32_t seqno;
> >
> > } __packed;
>
> Wouldn't that lead to an unaligned seqno?
Yes, I overlooked that the seqno is 32bit wide.
Regards,
Marek
On Saturday 28 May 2011 14:17:14 Marek Lindner wrote:
> On Saturday 28 May 2011 14:07:10 Sven Eckelmann wrote:
> > Why dont you use the reserverd part for the flags which are currently not
> > in unicast? Then you could also remove that other align byte. It would
> > still be possible to add flags to unicast packets when necessary.
>
> The unicast_frag header assumes it looks like the unicast header plus some
> extra fields:
Where does it assume that the frag is _not_ part of the unicast_packet header?
>
> struct unicast_frag_packet {
> struct unicast_packet unicast_packet;
> uint8_t flags;
> uint8_t align;
> uint8_t orig[6];
> uint16_t seqno;
> };
>
> We probably should add a little comment there to make that clear.
>
> Both reserved fields (unicast + unicast frag) are going to be converted to
> ttvn with the tt patches.
Ok, makes sense to use reserve fields then
Kind regards,
Sven
@@ -32,7 +32,7 @@
#define BAT_UNICAST_FRAG 0x06
/* this file is included by batctl which needs these defines */
-#define COMPAT_VERSION 12
+#define COMPAT_VERSION 14
#define DIRECTLINK 0x40
#define VIS_SERVER 0x20
#define PRIMARIES_FIRST_HOP 0x10
@@ -55,15 +55,15 @@
struct batman_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
+ uint8_t ttl;
uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
- uint8_t tq;
uint32_t seqno;
uint8_t orig[6];
uint8_t prev_sender[6];
- uint8_t ttl;
- uint8_t num_tt;
uint8_t gw_flags; /* flags related to gateway class */
- uint8_t align;
+ uint8_t tq;
+ uint8_t num_tt;
+ uint8_t reserved;
} __packed;
#define BAT_PACKET_LEN sizeof(struct batman_packet)
@@ -71,12 +71,13 @@ struct batman_packet {
struct icmp_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
- uint8_t msg_type; /* see ICMP message types above */
uint8_t ttl;
+ uint8_t msg_type; /* see ICMP message types above */
uint8_t dst[6];
uint8_t orig[6];
uint16_t seqno;
uint8_t uid;
+ uint8_t reserved;
} __packed;
#define BAT_RR_LEN 16
@@ -86,8 +87,8 @@ struct icmp_packet {
struct icmp_packet_rr {
uint8_t packet_type;
uint8_t version; /* batman version field */
- uint8_t msg_type; /* see ICMP message types above */
uint8_t ttl;
+ uint8_t msg_type; /* see ICMP message types above */
uint8_t dst[6];
uint8_t orig[6];
uint16_t seqno;
@@ -99,16 +100,19 @@ struct icmp_packet_rr {
struct unicast_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
- uint8_t dest[6];
uint8_t ttl;
+ uint8_t reserved;
+ uint8_t dest[6];
} __packed;
struct unicast_frag_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
- uint8_t dest[6];
uint8_t ttl;
+ uint8_t reserved;
+ uint8_t dest[6];
uint8_t flags;
+ uint8_t align;
uint8_t orig[6];
uint16_t seqno;
} __packed;
@@ -116,18 +120,20 @@ struct unicast_frag_packet {
struct bcast_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
- uint8_t orig[6];
uint8_t ttl;
+ uint8_t reserved;
+ uint8_t orig[6];
uint32_t seqno;
} __packed;
struct vis_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
+ uint8_t ttl; /* TTL */
uint8_t vis_type; /* which type of vis-participant sent this? */
- uint8_t entries; /* number of entries behind this struct */
uint32_t seqno; /* sequence number */
- uint8_t ttl; /* TTL */
+ uint8_t entries; /* number of entries behind this struct */
+ uint8_t reserved;
uint8_t vis_orig[6]; /* originator that announces its neighbors */
uint8_t target_orig[6]; /* who should receive this packet */
uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */