[v2,2/6] batman-adv: add build check macros for packet member offset

Message ID 1366401149-31600-3-git-send-email-siwu@hrz.tu-chemnitz.de (mailing list archive)
State Superseded, archived
Commit a36f66e669ecfbb8f701d15ce317cdf2e39e092a
Headers

Commit Message

Simon Wunderlich April 19, 2013, 7:52 p.m. UTC
  Since we removed the __packed from most of the packets, we should
make sure that the offset generated by the compile are correct for
sent/received data.

Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
---
 main.c |    8 ++++++++
 1 file changed, 8 insertions(+)
  

Comments

Marek Lindner April 20, 2013, 9:38 a.m. UTC | #1
On Saturday, April 20, 2013 03:52:25 Simon Wunderlich wrote:
> Since we removed the __packed from most of the packets, we should
> make sure that the offset generated by the compile are correct for
> sent/received data.

Small typo: by the compileR

Cheers,
Marek
  

Patch

diff --git a/main.c b/main.c
index a003067..5c76d6f 100644
--- a/main.c
+++ b/main.c
@@ -328,6 +328,14 @@  static void batadv_recv_handler_init(void)
 	for (i = 0; i < ARRAY_SIZE(batadv_rx_handler); i++)
 		batadv_rx_handler[i] = batadv_recv_unhandled_packet;
 
+	/* compile time checks for struct member offsets */
+	BUILD_BUG_ON(offsetof(struct batadv_unicast_4addr_packet, src) != 10);
+	BUILD_BUG_ON(offsetof(struct batadv_unicast_packet, dest) != 4);
+	BUILD_BUG_ON(offsetof(struct batadv_unicast_frag_packet, dest) != 4);
+	BUILD_BUG_ON(offsetof(struct batadv_unicast_tvlv_packet, dst) != 4);
+	BUILD_BUG_ON(offsetof(struct batadv_icmp_packet, dst) != 4);
+	BUILD_BUG_ON(offsetof(struct batadv_icmp_packet_rr, dst) != 4);
+
 	/* batman icmp packet */
 	batadv_rx_handler[BATADV_ICMP] = batadv_recv_icmp_packet;
 	/* unicast with 4 addresses packet */