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:
parent
913a62377e
commit
bce8896b4b
|
@ -98,6 +98,7 @@ struct _owl_result
|
||||||
{
|
{
|
||||||
char mobile_mac_addr[OWL_ETHER_ADDR_STRLEN] ; ///< Mobile's MAC address
|
char mobile_mac_addr[OWL_ETHER_ADDR_STRLEN] ; ///< Mobile's MAC address
|
||||||
uint8_t request_type ; ///< Type of the request
|
uint8_t request_type ; ///< Type of the request
|
||||||
|
unsigned char __pad0; // 1 byte alignment
|
||||||
/// Local time on the mobile when sending the request
|
/// Local time on the mobile when sending the request
|
||||||
owl_timestamp mobile_timestamp ;
|
owl_timestamp mobile_timestamp ;
|
||||||
unsigned int nb_results ; ///< Number of results generated
|
unsigned int nb_results ; ///< Number of results generated
|
||||||
|
|
|
@ -110,26 +110,30 @@ typedef struct _owl_timestamp owl_timestamp ;
|
||||||
/**
|
/**
|
||||||
* Message sent by the Listener to the Aggregator for each captured
|
* Message sent by the Listener to the Aggregator for each captured
|
||||||
* request.
|
* request.
|
||||||
|
*
|
||||||
|
* TODO: This structure's size could be reduced from 60 to 52 byte by reordering
|
||||||
|
* the fields by size.
|
||||||
*/
|
*/
|
||||||
struct _owl_captured_request
|
struct _owl_captured_request
|
||||||
{
|
{
|
||||||
uint8_t type ; ///< Type of the 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 nb_packets ; ///< Number of packets for this request
|
||||||
uint16_t packet_id ; ///< Number of the current packet
|
uint16_t packet_id ; ///< Number of the current packet
|
||||||
uint8_t cp_mac_addr_bytes[ETHER_ADDR_LEN] ; ///< MAC of the listener
|
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_mac_addr_bytes[ETHER_ADDR_LEN] ; ///< MAC of the mobile
|
||||||
uint8_t mobile_ip_addr_bytes[4] ; ///< IP 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 request_time ; ///< Timestamp on the mobile
|
||||||
owl_timestamp capture_time ; ///< Timestamp of arrival on the listener
|
owl_timestamp capture_time ; ///< Timestamp of arrival on the listener
|
||||||
int8_t ss_dbm ; ///< Signal strength measured by the listener (dBm)
|
int8_t ss_dbm ; ///< Signal strength measured by the listener (dBm)
|
||||||
// 3 bytes alignment
|
unsigned char __pad2[3]; // 3 bytes alignment
|
||||||
/* Calibration data */
|
/* Calibration data */
|
||||||
float x_position ; ///< X coordinate
|
float x_position ; ///< X coordinate
|
||||||
float y_position ; ///< Y coordinate
|
float y_position ; ///< Y coordinate
|
||||||
float z_position ; ///< Z coordinate
|
float z_position ; ///< Z coordinate
|
||||||
owl_direction direction ; ///< Orientation of the mobile
|
owl_direction direction ; ///< Orientation of the mobile
|
||||||
|
unsigned char __pad3[3]; // 3 bytes alignment
|
||||||
} ;
|
} ;
|
||||||
/// Captured request type
|
/// Captured request type
|
||||||
typedef struct _owl_captured_request owl_captured_request ;
|
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
|
* Message sent by the Aggregator to the Positioner containing
|
||||||
* the main data of a request.
|
* 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
|
struct _owl_request
|
||||||
{
|
{
|
||||||
uint8_t type ; ///< Type of the 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
|
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_mac_addr_bytes[ETHER_ADDR_LEN] ; ///< MAC of the mobile
|
||||||
uint8_t mobile_ip_addr_bytes[4] ; ///< IP 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
|
owl_timestamp request_time ; ///< Timestamp on the mobile
|
||||||
uint16_t nb_info ; ///< Number of owl_request_info
|
uint16_t nb_info ; ///< Number of owl_request_info
|
||||||
|
unsigned char __pad2[2]; // 2 bytes alignment
|
||||||
/* Calibration data */
|
/* Calibration data */
|
||||||
float x_position ; ///< X coordinate
|
float x_position ; ///< X coordinate
|
||||||
float y_position ; ///< Y coordinate
|
float y_position ; ///< Y coordinate
|
||||||
float z_position ; ///< Z coordinate
|
float z_position ; ///< Z coordinate
|
||||||
owl_direction direction ; ///< Orientation of the mobile
|
owl_direction direction ; ///< Orientation of the mobile
|
||||||
|
unsigned char __pad3[3]; // 3 bytes alignment
|
||||||
} ;
|
} ;
|
||||||
/// Aggregated request type
|
/// Aggregated request type
|
||||||
typedef struct _owl_request owl_request ;
|
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
|
uint8_t cp_mac_addr_bytes[ETHER_ADDR_LEN] ; ///< MAC of the listener
|
||||||
owl_timestamp capture_time ; ///< Timestamp of arrival on the listener
|
owl_timestamp capture_time ; ///< Timestamp of arrival on the listener
|
||||||
int8_t ss_dbm ; ///< Signal strength measured by the listener (dBm)
|
int8_t ss_dbm ; ///< Signal strength measured by the listener (dBm)
|
||||||
|
unsigned char __pad0[3]; // 3 bytes alignment
|
||||||
} ;
|
} ;
|
||||||
/// Aggregated request information type
|
/// Aggregated request information type
|
||||||
typedef struct _owl_request_info owl_request_info ;
|
typedef struct _owl_request_info owl_request_info ;
|
||||||
|
|
|
@ -57,6 +57,7 @@ typedef struct _request_info_list
|
||||||
owl_timestamp capture_time ;
|
owl_timestamp capture_time ;
|
||||||
// Signal strength received by the CP from the mobile:
|
// Signal strength received by the CP from the mobile:
|
||||||
int8_t ss_dbm ;
|
int8_t ss_dbm ;
|
||||||
|
unsigned char __pad0[7]; // 7 bytes alignment
|
||||||
struct _request_info_list *next ;
|
struct _request_info_list *next ;
|
||||||
} request_info_list ;
|
} request_info_list ;
|
||||||
|
|
||||||
|
@ -65,12 +66,14 @@ typedef struct _request_info_list
|
||||||
typedef struct _request_list
|
typedef struct _request_list
|
||||||
{
|
{
|
||||||
uint8_t type ;
|
uint8_t type ;
|
||||||
|
unsigned char __pad0; // 1 byte alignment
|
||||||
|
|
||||||
// Number of packets sent by the mobile for this request:
|
// Number of packets sent by the mobile for this request:
|
||||||
uint16_t nb_packets ;
|
uint16_t nb_packets ;
|
||||||
|
|
||||||
/* Request identifier */
|
/* Request identifier */
|
||||||
uint8_t mobile_mac_addr_bytes[ETHER_ADDR_LEN] ; // Mobile MAC address
|
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
|
owl_timestamp request_time ; // Request time on the mobile
|
||||||
|
|
||||||
/* Calibration data */
|
/* Calibration data */
|
||||||
|
@ -81,6 +84,7 @@ typedef struct _request_list
|
||||||
|
|
||||||
/* Other data */
|
/* Other data */
|
||||||
uint8_t mobile_ip_addr_bytes[4] ; // Mobile IP address
|
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:
|
// Arrival time of the first packet of the request on the aggregator:
|
||||||
owl_timestamp start_time ;
|
owl_timestamp start_time ;
|
||||||
request_info_list *info ; // Data for this request
|
request_info_list *info ; // Data for this request
|
||||||
|
@ -95,6 +99,7 @@ typedef struct _cp_list
|
||||||
uint8_t mac_addr_bytes[ETHER_ADDR_LEN] ;
|
uint8_t mac_addr_bytes[ETHER_ADDR_LEN] ;
|
||||||
char ip_addr[INET_ADDRSTRLEN] ;
|
char ip_addr[INET_ADDRSTRLEN] ;
|
||||||
|
|
||||||
|
unsigned char __pad0[2]; // 2 bytes alignment
|
||||||
owl_timestamp last_seen ;
|
owl_timestamp last_seen ;
|
||||||
|
|
||||||
struct _cp_list *previous ;
|
struct _cp_list *previous ;
|
||||||
|
|
|
@ -75,21 +75,26 @@ void print_version(void) ;
|
||||||
|
|
||||||
|
|
||||||
/* Options */
|
/* Options */
|
||||||
|
// TODO: the size of this structure could be reduced by reordering its fields.
|
||||||
struct {
|
struct {
|
||||||
bool daemon ;
|
bool daemon ;
|
||||||
bool verbose ;
|
bool verbose ;
|
||||||
char dest_host[MAXHOSTNAMELEN] ; // Destination host of the packets
|
char dest_host[MAXHOSTNAMELEN] ; // Destination host of the packets
|
||||||
|
// 6 bytes alignment
|
||||||
uint_fast16_t dest_port ;
|
uint_fast16_t dest_port ;
|
||||||
char iface[IFNAMSIZ + 1] ; // Source network interface
|
char iface[IFNAMSIZ + 1] ; // Source network interface
|
||||||
|
// 7 bytes alignment
|
||||||
int_fast32_t delay ; // Time between two packet transmissions
|
int_fast32_t delay ; // Time between two packet transmissions
|
||||||
uint_fast16_t nb_pkt ; // Number of packets to send
|
uint_fast16_t nb_pkt ; // Number of packets to send
|
||||||
uint_fast16_t pkt_size ; // Size of the packet to send
|
uint_fast16_t pkt_size ; // Size of the packet to send
|
||||||
int_fast32_t flood_delay ; // Time between two request transmissions
|
int_fast32_t flood_delay ; // Time between two request transmissions
|
||||||
bool add_flood_delay ; // Add the delay to the transmission time?
|
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 nb_requests ; // Number of requests to send
|
||||||
uint_fast16_t listening_port ;
|
uint_fast16_t listening_port ;
|
||||||
// Calibration data:
|
// Calibration data:
|
||||||
owl_direction direction ;
|
owl_direction direction ;
|
||||||
|
// 3 bytes alignment
|
||||||
float x ;
|
float x ;
|
||||||
float y ;
|
float y ;
|
||||||
float z ;
|
float z ;
|
||||||
|
|
|
@ -87,21 +87,27 @@ cfg_t *cfg = NULL ; // Configuration structure
|
||||||
/* If we do not use libconfuse, we declare a structure to store getopt
|
/* If we do not use libconfuse, we declare a structure to store getopt
|
||||||
* options.
|
* 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 {
|
struct {
|
||||||
bool daemon ;
|
bool daemon ;
|
||||||
char mode ;
|
char mode ;
|
||||||
char aggregation_host[MAXHOSTNAMELEN] ;
|
char aggregation_host[MAXHOSTNAMELEN] ;
|
||||||
|
// 6 bytes alignment
|
||||||
uint_fast16_t aggregation_port ;
|
uint_fast16_t aggregation_port ;
|
||||||
uint_fast16_t listening_port ;
|
uint_fast16_t listening_port ;
|
||||||
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
#ifdef OWLPS_LISTENER_KEEPS_MONITOR
|
||||||
bool keep_monitor ;
|
bool keep_monitor ;
|
||||||
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
#endif // OWLPS_LISTENER_KEEPS_MONITOR
|
||||||
char rtap_iface[IFNAMSIZ + 1] ;
|
char rtap_iface[IFNAMSIZ + 1] ;
|
||||||
|
// 7 bytes alignment
|
||||||
char *pcap_file ;
|
char *pcap_file ;
|
||||||
char wifi_iface[IFNAMSIZ + 1] ;
|
char wifi_iface[IFNAMSIZ + 1] ;
|
||||||
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
#ifdef OWLPS_LISTENER_USES_PTHREAD
|
||||||
bool autocalibration ;
|
bool autocalibration ;
|
||||||
char autocalibration_host[MAXHOSTNAMELEN] ;
|
char autocalibration_host[MAXHOSTNAMELEN] ;
|
||||||
|
// 6 bytes alignment
|
||||||
uint_fast16_t autocalibration_request_port ;
|
uint_fast16_t autocalibration_request_port ;
|
||||||
uint_fast16_t autocalibration_order_port ;
|
uint_fast16_t autocalibration_order_port ;
|
||||||
uint_fast16_t autocalibration_hello_port ;
|
uint_fast16_t autocalibration_hello_port ;
|
||||||
|
@ -109,11 +115,13 @@ struct {
|
||||||
uint_fast32_t autocalibration_delay ;
|
uint_fast32_t autocalibration_delay ;
|
||||||
uint_fast16_t autocalibration_nb_packets ;
|
uint_fast16_t autocalibration_nb_packets ;
|
||||||
owl_direction my_direction ;
|
owl_direction my_direction ;
|
||||||
|
// 3 bytes alignment
|
||||||
float my_position_x ;
|
float my_position_x ;
|
||||||
float my_position_y ;
|
float my_position_y ;
|
||||||
float my_position_z ;
|
float my_position_z ;
|
||||||
#endif // OWLPS_LISTENER_USES_PTHREAD
|
#endif // OWLPS_LISTENER_USES_PTHREAD
|
||||||
uint_fast8_t verbose ;
|
uint_fast8_t verbose ;
|
||||||
|
// 7 bytes alignment
|
||||||
} options = { // Initalise default options:
|
} options = { // Initalise default options:
|
||||||
false, // daemon
|
false, // daemon
|
||||||
MODE_ACTIVE, // mode
|
MODE_ACTIVE, // mode
|
||||||
|
|
|
@ -31,11 +31,15 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
/* Options */
|
||||||
|
// TODO: the size of this structure could be reduced by reordering its fields.
|
||||||
struct {
|
struct {
|
||||||
bool verbose ;
|
bool verbose ;
|
||||||
|
// 7 bytes alignment
|
||||||
uint_fast16_t result_port ;
|
uint_fast16_t result_port ;
|
||||||
uint_fast16_t http_port ;
|
uint_fast16_t http_port ;
|
||||||
int nb_connections ;
|
int nb_connections ;
|
||||||
|
// 4 bytes alignment
|
||||||
} options = {
|
} options = {
|
||||||
true, // verbose
|
true, // verbose
|
||||||
OWL_DEFAULT_RESULT_PORT, // result_port
|
OWL_DEFAULT_RESULT_PORT, // result_port
|
||||||
|
|
Loading…
Reference in New Issue