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).
This commit is contained in:
Matteo Cypriani 2016-11-23 17:02:21 -05:00
förälder 913a62377e
incheckning bce8896b4b
6 ändrade filer med 38 tillägg och 3 borttagningar

Visa fil

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

Visa fil

@ -110,26 +110,30 @@ typedef struct _owl_timestamp owl_timestamp ;
/**
* Message sent by the Listener to the Aggregator for each captured
* request.
*
* TODO: This structure's size could be reduced from 60 to 52 byte by reordering
* the fields by size.
*/
struct _owl_captured_request
{
uint8_t type ; ///< Type of the captured request
// 1 byte alignment
unsigned char __pad0; // 1 byte alignment
uint16_t nb_packets ; ///< Number of packets for this request
uint16_t packet_id ; ///< Number of the current packet
uint8_t cp_mac_addr_bytes[ETHER_ADDR_LEN] ; ///< MAC of the listener
uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; ///< MAC of the mobile
uint8_t mobile_ip_addr_bytes[4] ; ///< IP of the mobile
// 2 bytes alignment
unsigned char __pad1[2]; // 2 bytes alignment
owl_timestamp request_time ; ///< Timestamp on the mobile
owl_timestamp capture_time ; ///< Timestamp of arrival on the listener
int8_t ss_dbm ; ///< Signal strength measured by the listener (dBm)
// 3 bytes alignment
unsigned char __pad2[3]; // 3 bytes alignment
/* Calibration data */
float x_position ; ///< X coordinate
float y_position ; ///< Y coordinate
float z_position ; ///< Z coordinate
owl_direction direction ; ///< Orientation of the mobile
unsigned char __pad3[3]; // 3 bytes alignment
} ;
/// Captured request type
typedef struct _owl_captured_request owl_captured_request ;
@ -139,20 +143,27 @@ typedef struct _owl_captured_request owl_captured_request ;
/**
* Message sent by the Aggregator to the Positioner containing
* the main data of a request.
*
* TODO: This structure's size could be reduced from 44 to 36 bytes by
* reordering the fields by size.
*/
struct _owl_request
{
uint8_t type ; ///< Type of the request
unsigned char __pad0; // 1 byte alignment
uint16_t nb_packets ; ///< Number of packets sent for this request
uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; ///< MAC of the mobile
uint8_t mobile_ip_addr_bytes[4] ; ///< IP of the mobile
unsigned char __pad1[2]; // 2 bytes alignment
owl_timestamp request_time ; ///< Timestamp on the mobile
uint16_t nb_info ; ///< Number of owl_request_info
unsigned char __pad2[2]; // 2 bytes alignment
/* Calibration data */
float x_position ; ///< X coordinate
float y_position ; ///< Y coordinate
float z_position ; ///< Z coordinate
owl_direction direction ; ///< Orientation of the mobile
unsigned char __pad3[3]; // 3 bytes alignment
} ;
/// Aggregated request type
typedef struct _owl_request owl_request ;
@ -170,6 +181,7 @@ struct _owl_request_info
uint8_t cp_mac_addr_bytes[ETHER_ADDR_LEN] ; ///< MAC of the listener
owl_timestamp capture_time ; ///< Timestamp of arrival on the listener
int8_t ss_dbm ; ///< Signal strength measured by the listener (dBm)
unsigned char __pad0[3]; // 3 bytes alignment
} ;
/// Aggregated request information type
typedef struct _owl_request_info owl_request_info ;

Visa fil

@ -57,6 +57,7 @@ typedef struct _request_info_list
owl_timestamp capture_time ;
// Signal strength received by the CP from the mobile:
int8_t ss_dbm ;
unsigned char __pad0[7]; // 7 bytes alignment
struct _request_info_list *next ;
} request_info_list ;
@ -65,12 +66,14 @@ typedef struct _request_info_list
typedef struct _request_list
{
uint8_t type ;
unsigned char __pad0; // 1 byte alignment
// Number of packets sent by the mobile for this request:
uint16_t nb_packets ;
/* Request identifier */
uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; // Mobile MAC address
unsigned char __pad1[2]; // 2 bytes alignment
owl_timestamp request_time ; // Request time on the mobile
/* Calibration data */
@ -81,6 +84,7 @@ typedef struct _request_list
/* Other data */
uint8_t mobile_ip_addr_bytes[4] ; // Mobile IP address
unsigned char __pad2[3]; // 3 bytes alignment
// Arrival time of the first packet of the request on the aggregator:
owl_timestamp start_time ;
request_info_list *info ; // Data for this request
@ -95,6 +99,7 @@ typedef struct _cp_list
uint8_t mac_addr_bytes[ETHER_ADDR_LEN] ;
char ip_addr[INET_ADDRSTRLEN] ;
unsigned char __pad0[2]; // 2 bytes alignment
owl_timestamp last_seen ;
struct _cp_list *previous ;

Visa fil

@ -75,21 +75,26 @@ void print_version(void) ;
/* Options */
// TODO: the size of this structure could be reduced by reordering its fields.
struct {
bool daemon ;
bool verbose ;
char dest_host[MAXHOSTNAMELEN] ; // Destination host of the packets
// 6 bytes alignment
uint_fast16_t dest_port ;
char iface[IFNAMSIZ + 1] ; // Source network interface
// 7 bytes alignment
int_fast32_t delay ; // Time between two packet transmissions
uint_fast16_t nb_pkt ; // Number of packets to send
uint_fast16_t pkt_size ; // Size of the packet to send
int_fast32_t flood_delay ; // Time between two request transmissions
bool add_flood_delay ; // Add the delay to the transmission time?
// 7 bytes alignment
uint_fast16_t nb_requests ; // Number of requests to send
uint_fast16_t listening_port ;
// Calibration data:
owl_direction direction ;
// 3 bytes alignment
float x ;
float y ;
float z ;

Visa fil

@ -87,21 +87,27 @@ cfg_t *cfg = NULL ; // Configuration structure
/* If we do not use libconfuse, we declare a structure to store getopt
* options.
*/
// TODO: the size of this structure could be reduced by reordering its fields.
// Note: the alignment comments below are for the case where all the #ifdef
// match.
struct {
bool daemon ;
char mode ;
char aggregation_host[MAXHOSTNAMELEN] ;
// 6 bytes alignment
uint_fast16_t aggregation_port ;
uint_fast16_t listening_port ;
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
bool keep_monitor ;
#endif // OWLPS_LISTENER_KEEPS_MONITOR
char rtap_iface[IFNAMSIZ + 1] ;
// 7 bytes alignment
char *pcap_file ;
char wifi_iface[IFNAMSIZ + 1] ;
#ifdef OWLPS_LISTENER_USES_PTHREAD
bool autocalibration ;
char autocalibration_host[MAXHOSTNAMELEN] ;
// 6 bytes alignment
uint_fast16_t autocalibration_request_port ;
uint_fast16_t autocalibration_order_port ;
uint_fast16_t autocalibration_hello_port ;
@ -109,11 +115,13 @@ struct {
uint_fast32_t autocalibration_delay ;
uint_fast16_t autocalibration_nb_packets ;
owl_direction my_direction ;
// 3 bytes alignment
float my_position_x ;
float my_position_y ;
float my_position_z ;
#endif // OWLPS_LISTENER_USES_PTHREAD
uint_fast8_t verbose ;
// 7 bytes alignment
} options = { // Initalise default options:
false, // daemon
MODE_ACTIVE, // mode

Visa fil

@ -31,11 +31,15 @@
#include <assert.h>
/* Options */
// TODO: the size of this structure could be reduced by reordering its fields.
struct {
bool verbose ;
// 7 bytes alignment
uint_fast16_t result_port ;
uint_fast16_t http_port ;
int nb_connections ;
// 4 bytes alignment
} options = {
true, // verbose
OWL_DEFAULT_RESULT_PORT, // result_port