Commit 3b27ffb0 authored by Antonio Quartulli's avatar Antonio Quartulli Committed by Sven Eckelmann

batman-adv: Unify the first 3 bytes in each packet

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: default avatarAntonio Quartulli <ordex@autistici.org>
Signed-off-by: default avatarSven Eckelmann <sven@narfation.org>
parent b4e17054
...@@ -34,7 +34,7 @@ enum bat_packettype { ...@@ -34,7 +34,7 @@ enum bat_packettype {
}; };
/* this file is included by batctl which needs these defines */ /* this file is included by batctl which needs these defines */
#define COMPAT_VERSION 12 #define COMPAT_VERSION 14
enum batman_flags { enum batman_flags {
PRIMARIES_FIRST_HOP = 1 << 4, PRIMARIES_FIRST_HOP = 1 << 4,
...@@ -66,15 +66,15 @@ enum unicast_frag_flags { ...@@ -66,15 +66,15 @@ enum unicast_frag_flags {
struct batman_packet { struct batman_packet {
uint8_t packet_type; uint8_t packet_type;
uint8_t version; /* batman version field */ uint8_t version; /* batman version field */
uint8_t ttl;
uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */ uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
uint8_t tq;
uint32_t seqno; uint32_t seqno;
uint8_t orig[6]; uint8_t orig[6];
uint8_t prev_sender[6]; uint8_t prev_sender[6];
uint8_t ttl;
uint8_t num_tt;
uint8_t gw_flags; /* flags related to gateway class */ uint8_t gw_flags; /* flags related to gateway class */
uint8_t align; uint8_t tq;
uint8_t num_tt;
uint8_t reserved;
} __packed; } __packed;
#define BAT_PACKET_LEN sizeof(struct batman_packet) #define BAT_PACKET_LEN sizeof(struct batman_packet)
...@@ -82,12 +82,13 @@ struct batman_packet { ...@@ -82,12 +82,13 @@ struct batman_packet {
struct icmp_packet { struct icmp_packet {
uint8_t packet_type; uint8_t packet_type;
uint8_t version; /* batman version field */ uint8_t version; /* batman version field */
uint8_t msg_type; /* see ICMP message types above */
uint8_t ttl; uint8_t ttl;
uint8_t msg_type; /* see ICMP message types above */
uint8_t dst[6]; uint8_t dst[6];
uint8_t orig[6]; uint8_t orig[6];
uint16_t seqno; uint16_t seqno;
uint8_t uid; uint8_t uid;
uint8_t reserved;
} __packed; } __packed;
#define BAT_RR_LEN 16 #define BAT_RR_LEN 16
...@@ -97,8 +98,8 @@ struct icmp_packet { ...@@ -97,8 +98,8 @@ struct icmp_packet {
struct icmp_packet_rr { struct icmp_packet_rr {
uint8_t packet_type; uint8_t packet_type;
uint8_t version; /* batman version field */ uint8_t version; /* batman version field */
uint8_t msg_type; /* see ICMP message types above */
uint8_t ttl; uint8_t ttl;
uint8_t msg_type; /* see ICMP message types above */
uint8_t dst[6]; uint8_t dst[6];
uint8_t orig[6]; uint8_t orig[6];
uint16_t seqno; uint16_t seqno;
...@@ -110,16 +111,19 @@ struct icmp_packet_rr { ...@@ -110,16 +111,19 @@ struct icmp_packet_rr {
struct unicast_packet { struct unicast_packet {
uint8_t packet_type; uint8_t packet_type;
uint8_t version; /* batman version field */ uint8_t version; /* batman version field */
uint8_t dest[6];
uint8_t ttl; uint8_t ttl;
uint8_t reserved;
uint8_t dest[6];
} __packed; } __packed;
struct unicast_frag_packet { struct unicast_frag_packet {
uint8_t packet_type; uint8_t packet_type;
uint8_t version; /* batman version field */ uint8_t version; /* batman version field */
uint8_t dest[6];
uint8_t ttl; uint8_t ttl;
uint8_t reserved;
uint8_t dest[6];
uint8_t flags; uint8_t flags;
uint8_t align;
uint8_t orig[6]; uint8_t orig[6];
uint16_t seqno; uint16_t seqno;
} __packed; } __packed;
...@@ -127,18 +131,20 @@ struct unicast_frag_packet { ...@@ -127,18 +131,20 @@ struct unicast_frag_packet {
struct bcast_packet { struct bcast_packet {
uint8_t packet_type; uint8_t packet_type;
uint8_t version; /* batman version field */ uint8_t version; /* batman version field */
uint8_t orig[6];
uint8_t ttl; uint8_t ttl;
uint8_t reserved;
uint32_t seqno; uint32_t seqno;
uint8_t orig[6];
} __packed; } __packed;
struct vis_packet { struct vis_packet {
uint8_t packet_type; uint8_t packet_type;
uint8_t version; /* batman version field */ uint8_t version; /* batman version field */
uint8_t ttl; /* TTL */
uint8_t vis_type; /* which type of vis-participant sent this? */ 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 */ 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 vis_orig[6]; /* originator that announces its neighbors */
uint8_t target_orig[6]; /* who should receive this packet */ uint8_t target_orig[6]; /* who should receive this packet */
uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */ uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment