Skip to content

Commit 3b27ffb

Browse files
Antonio Quartulliecsv
authored andcommitted
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: Antonio Quartulli <ordex@autistici.org> Signed-off-by: Sven Eckelmann <sven@narfation.org>
1 parent b4e1705 commit 3b27ffb

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

net/batman-adv/packet.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ enum bat_packettype {
3434
};
3535

3636
/* this file is included by batctl which needs these defines */
37-
#define COMPAT_VERSION 12
37+
#define COMPAT_VERSION 14
3838

3939
enum batman_flags {
4040
PRIMARIES_FIRST_HOP = 1 << 4,
@@ -66,28 +66,29 @@ enum unicast_frag_flags {
6666
struct batman_packet {
6767
uint8_t packet_type;
6868
uint8_t version; /* batman version field */
69+
uint8_t ttl;
6970
uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
70-
uint8_t tq;
7171
uint32_t seqno;
7272
uint8_t orig[6];
7373
uint8_t prev_sender[6];
74-
uint8_t ttl;
75-
uint8_t num_tt;
7674
uint8_t gw_flags; /* flags related to gateway class */
77-
uint8_t align;
75+
uint8_t tq;
76+
uint8_t num_tt;
77+
uint8_t reserved;
7878
} __packed;
7979

8080
#define BAT_PACKET_LEN sizeof(struct batman_packet)
8181

8282
struct icmp_packet {
8383
uint8_t packet_type;
8484
uint8_t version; /* batman version field */
85-
uint8_t msg_type; /* see ICMP message types above */
8685
uint8_t ttl;
86+
uint8_t msg_type; /* see ICMP message types above */
8787
uint8_t dst[6];
8888
uint8_t orig[6];
8989
uint16_t seqno;
9090
uint8_t uid;
91+
uint8_t reserved;
9192
} __packed;
9293

9394
#define BAT_RR_LEN 16
@@ -97,8 +98,8 @@ struct icmp_packet {
9798
struct icmp_packet_rr {
9899
uint8_t packet_type;
99100
uint8_t version; /* batman version field */
100-
uint8_t msg_type; /* see ICMP message types above */
101101
uint8_t ttl;
102+
uint8_t msg_type; /* see ICMP message types above */
102103
uint8_t dst[6];
103104
uint8_t orig[6];
104105
uint16_t seqno;
@@ -110,35 +111,40 @@ struct icmp_packet_rr {
110111
struct unicast_packet {
111112
uint8_t packet_type;
112113
uint8_t version; /* batman version field */
113-
uint8_t dest[6];
114114
uint8_t ttl;
115+
uint8_t reserved;
116+
uint8_t dest[6];
115117
} __packed;
116118

117119
struct unicast_frag_packet {
118120
uint8_t packet_type;
119121
uint8_t version; /* batman version field */
120-
uint8_t dest[6];
121122
uint8_t ttl;
123+
uint8_t reserved;
124+
uint8_t dest[6];
122125
uint8_t flags;
126+
uint8_t align;
123127
uint8_t orig[6];
124128
uint16_t seqno;
125129
} __packed;
126130

127131
struct bcast_packet {
128132
uint8_t packet_type;
129133
uint8_t version; /* batman version field */
130-
uint8_t orig[6];
131134
uint8_t ttl;
135+
uint8_t reserved;
132136
uint32_t seqno;
137+
uint8_t orig[6];
133138
} __packed;
134139

135140
struct vis_packet {
136141
uint8_t packet_type;
137142
uint8_t version; /* batman version field */
143+
uint8_t ttl; /* TTL */
138144
uint8_t vis_type; /* which type of vis-participant sent this? */
139-
uint8_t entries; /* number of entries behind this struct */
140145
uint32_t seqno; /* sequence number */
141-
uint8_t ttl; /* TTL */
146+
uint8_t entries; /* number of entries behind this struct */
147+
uint8_t reserved;
142148
uint8_t vis_orig[6]; /* originator that announces its neighbors */
143149
uint8_t target_orig[6]; /* who should receive this packet */
144150
uint8_t sender_orig[6]; /* who sent or rebroadcasted this packet */

0 commit comments

Comments
 (0)