Explorar el Código

Add explicit padding for all the structs

Indicate padding bytes explicitly in all the structures. Some of the
structures could have their size reduced by reordering their fields by
size (especially in owlps.h).
master
Matteo Cypriani hace 2 años
padre
commit
bce8896b4b

+ 1
- 0
libowlps-resultreader/owlps-resultreader.h Ver fichero

@@ -98,6 +98,7 @@ struct _owl_result
98 98
 {
99 99
   char mobile_mac_addr[OWL_ETHER_ADDR_STRLEN] ; ///< Mobile's MAC address
100 100
   uint8_t request_type ; ///< Type of the request
101
+  unsigned char __pad0; // 1 byte alignment
101 102
   /// Local time on the mobile when sending the request
102 103
   owl_timestamp mobile_timestamp ;
103 104
   unsigned int nb_results ; ///< Number of results generated

+ 15
- 3
libowlps/owlps.h Ver fichero

@@ -110,26 +110,30 @@ typedef struct _owl_timestamp owl_timestamp ;
110 110
 /**
111 111
  * Message sent by the Listener to the Aggregator for each captured
112 112
  * request.
113
+ *
114
+ * TODO: This structure's size could be reduced from 60 to 52 byte by reordering
115
+ * the fields by size.
113 116
  */
114 117
 struct _owl_captured_request
115 118
 {
116 119
   uint8_t type ; ///< Type of the captured request
117
-  // 1 byte alignment
120
+  unsigned char __pad0; // 1 byte alignment
118 121
   uint16_t nb_packets ; ///< Number of packets for this request
119 122
   uint16_t packet_id ; ///< Number of the current packet
120 123
   uint8_t cp_mac_addr_bytes[ETHER_ADDR_LEN] ; ///< MAC of the listener
121 124
   uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; ///< MAC of the mobile
122 125
   uint8_t mobile_ip_addr_bytes[4] ; ///< IP of the mobile
123
-  // 2 bytes alignment
126
+  unsigned char __pad1[2]; // 2 bytes alignment
124 127
   owl_timestamp request_time ; ///< Timestamp on the mobile
125 128
   owl_timestamp capture_time ; ///< Timestamp of arrival on the listener
126 129
   int8_t ss_dbm ; ///< Signal strength measured by the listener (dBm)
127
-  // 3 bytes alignment
130
+  unsigned char __pad2[3]; // 3 bytes alignment
128 131
   /* Calibration data */
129 132
   float x_position ; ///< X coordinate
130 133
   float y_position ; ///< Y coordinate
131 134
   float z_position ; ///< Z coordinate
132 135
   owl_direction direction ; ///< Orientation of the mobile
136
+  unsigned char __pad3[3]; // 3 bytes alignment
133 137
 } ;
134 138
 /// Captured request type
135 139
 typedef struct _owl_captured_request owl_captured_request ;
@@ -139,20 +143,27 @@ typedef struct _owl_captured_request owl_captured_request ;
139 143
 /**
140 144
  * Message sent by the Aggregator to the Positioner containing
141 145
  * the main data of a request.
146
+ *
147
+ * TODO: This structure's size could be reduced from 44 to 36 bytes by
148
+ * reordering the fields by size.
142 149
  */
143 150
 struct _owl_request
144 151
 {
145 152
   uint8_t type ; ///< Type of the request
153
+  unsigned char __pad0; // 1 byte alignment
146 154
   uint16_t nb_packets ; ///< Number of packets sent for this request
147 155
   uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; ///< MAC of the mobile
148 156
   uint8_t mobile_ip_addr_bytes[4] ; ///< IP of the mobile
157
+  unsigned char __pad1[2]; // 2 bytes alignment
149 158
   owl_timestamp request_time ; ///< Timestamp on the mobile
150 159
   uint16_t nb_info ; ///< Number of owl_request_info
160
+  unsigned char __pad2[2]; // 2 bytes alignment
151 161
   /* Calibration data */
152 162
   float x_position ; ///< X coordinate
153 163
   float y_position ; ///< Y coordinate
154 164
   float z_position ; ///< Z coordinate
155 165
   owl_direction direction ; ///< Orientation of the mobile
166
+  unsigned char __pad3[3]; // 3 bytes alignment
156 167
 } ;
157 168
 /// Aggregated request type
158 169
 typedef struct _owl_request owl_request ;
@@ -170,6 +181,7 @@ struct _owl_request_info
170 181
   uint8_t cp_mac_addr_bytes[ETHER_ADDR_LEN] ; ///< MAC of the listener
171 182
   owl_timestamp capture_time ; ///< Timestamp of arrival on the listener
172 183
   int8_t ss_dbm ; ///< Signal strength measured by the listener (dBm)
184
+  unsigned char __pad0[3]; // 3 bytes alignment
173 185
 } ;
174 186
 /// Aggregated request information type
175 187
 typedef struct _owl_request_info owl_request_info ;

+ 5
- 0
owlps-aggregator/owlps-aggregator.h Ver fichero

@@ -57,6 +57,7 @@ typedef struct _request_info_list
57 57
   owl_timestamp capture_time ;
58 58
   // Signal strength received by the CP from the mobile:
59 59
   int8_t ss_dbm ;
60
+  unsigned char __pad0[7]; // 7 bytes alignment
60 61
   struct _request_info_list *next ;
61 62
 } request_info_list ;
62 63
 
@@ -65,12 +66,14 @@ typedef struct _request_info_list
65 66
 typedef struct _request_list
66 67
 {
67 68
   uint8_t type ;
69
+  unsigned char __pad0; // 1 byte alignment
68 70
 
69 71
   // Number of packets sent by the mobile for this request:
70 72
   uint16_t nb_packets ;
71 73
 
72 74
   /* Request identifier */
73 75
   uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; // Mobile MAC address
76
+  unsigned char __pad1[2]; // 2 bytes alignment
74 77
   owl_timestamp request_time ; // Request time on the mobile
75 78
 
76 79
   /* Calibration data */
@@ -81,6 +84,7 @@ typedef struct _request_list
81 84
 
82 85
   /* Other data */
83 86
   uint8_t mobile_ip_addr_bytes[4] ; // Mobile IP address
87
+  unsigned char __pad2[3]; // 3 bytes alignment
84 88
   // Arrival time of the first packet of the request on the aggregator:
85 89
   owl_timestamp start_time ;
86 90
   request_info_list *info ; // Data for this request
@@ -95,6 +99,7 @@ typedef struct _cp_list
95 99
   uint8_t mac_addr_bytes[ETHER_ADDR_LEN] ;
96 100
   char ip_addr[INET_ADDRSTRLEN] ;
97 101
 
102
+  unsigned char __pad0[2]; // 2 bytes alignment
98 103
   owl_timestamp last_seen ;
99 104
 
100 105
   struct _cp_list *previous ;

+ 5
- 0
owlps-client/owlps-client.c Ver fichero

@@ -75,21 +75,26 @@ void print_version(void) ;
75 75
 
76 76
 
77 77
 /* Options */
78
+// TODO: the size of this structure could be reduced by reordering its fields.
78 79
 struct {
79 80
   bool daemon ;
80 81
   bool verbose ;
81 82
   char dest_host[MAXHOSTNAMELEN] ; // Destination host of the packets
83
+  // 6 bytes alignment
82 84
   uint_fast16_t dest_port ;
83 85
   char iface[IFNAMSIZ + 1] ; // Source network interface
86
+  // 7 bytes alignment
84 87
   int_fast32_t delay ; // Time between two packet transmissions
85 88
   uint_fast16_t nb_pkt ; // Number of packets to send
86 89
   uint_fast16_t pkt_size ; // Size of the packet to send
87 90
   int_fast32_t flood_delay ; // Time between two request transmissions
88 91
   bool add_flood_delay ; // Add the delay to the transmission time?
92
+  // 7 bytes alignment
89 93
   uint_fast16_t nb_requests ; // Number of requests to send
90 94
   uint_fast16_t listening_port ;
91 95
   // Calibration data:
92 96
   owl_direction direction ;
97
+  // 3 bytes alignment
93 98
   float x ;
94 99
   float y ;
95 100
   float z ;

+ 8
- 0
owlps-listener/owlps-listenerd.c Ver fichero

@@ -87,21 +87,27 @@ cfg_t *cfg = NULL ; // Configuration structure
87 87
 /* If we do not use libconfuse, we declare a structure to store getopt
88 88
  * options.
89 89
  */
90
+// TODO: the size of this structure could be reduced by reordering its fields.
91
+// Note: the alignment comments below are for the case where all the #ifdef
92
+//       match.
90 93
 struct {
91 94
   bool daemon ;
92 95
   char mode ;
93 96
   char aggregation_host[MAXHOSTNAMELEN] ;
97
+  // 6 bytes alignment
94 98
   uint_fast16_t aggregation_port ;
95 99
   uint_fast16_t listening_port ;
96 100
 #ifdef OWLPS_LISTENER_KEEPS_MONITOR
97 101
   bool keep_monitor ;
98 102
 #endif // OWLPS_LISTENER_KEEPS_MONITOR
99 103
   char rtap_iface[IFNAMSIZ + 1] ;
104
+  // 7 bytes alignment
100 105
   char *pcap_file ;
101 106
   char wifi_iface[IFNAMSIZ + 1] ;
102 107
 #ifdef OWLPS_LISTENER_USES_PTHREAD
103 108
   bool autocalibration ;
104 109
   char autocalibration_host[MAXHOSTNAMELEN] ;
110
+  // 6 bytes alignment
105 111
   uint_fast16_t autocalibration_request_port ;
106 112
   uint_fast16_t autocalibration_order_port ;
107 113
   uint_fast16_t autocalibration_hello_port ;
@@ -109,11 +115,13 @@ struct {
109 115
   uint_fast32_t autocalibration_delay ;
110 116
   uint_fast16_t autocalibration_nb_packets ;
111 117
   owl_direction my_direction ;
118
+  // 3 bytes alignment
112 119
   float my_position_x ;
113 120
   float my_position_y ;
114 121
   float my_position_z ;
115 122
 #endif // OWLPS_LISTENER_USES_PTHREAD
116 123
   uint_fast8_t verbose ;
124
+  // 7 bytes alignment
117 125
 } options = { // Initalise default options:
118 126
   false, // daemon
119 127
   MODE_ACTIVE, // mode

+ 4
- 0
owlps-udp-to-http/owlps-udp-to-http.c Ver fichero

@@ -31,11 +31,15 @@
31 31
 
32 32
 #include <assert.h>
33 33
 
34
+/* Options */
35
+// TODO: the size of this structure could be reduced by reordering its fields.
34 36
 struct {
35 37
   bool verbose ;
38
+  // 7 bytes alignment
36 39
   uint_fast16_t result_port ;
37 40
   uint_fast16_t http_port ;
38 41
   int nb_connections ;
42
+  // 4 bytes alignment
39 43
 } options = {
40 44
   true, // verbose
41 45
   OWL_DEFAULT_RESULT_PORT, // result_port

Loading…
Cancelar
Guardar