diff --git a/src/handle_packets.c b/src/handle_packets.c index c78a9b5..db0373a 100644 --- a/src/handle_packets.c +++ b/src/handle_packets.c @@ -122,7 +122,7 @@ static void handle_client_init(struct SwiftNetClientConnection* user, const stru if(bytes_received != PACKET_HEADER_SIZE + sizeof(struct SwiftNetServerInformation) + client_connection->prepend_size) { #ifdef SWIFT_NET_DEBUG - if (check_debug_flag(INITIALIZATION)) { + if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) { send_debug_message("Invalid packet received from server. Expected server information: {\"bytes_received\": %u, \"expected_bytes\": %u}\n", bytes_received, PACKET_HEADER_SIZE + sizeof(struct SwiftNetServerInformation)); } #endif @@ -141,7 +141,7 @@ static void handle_client_init(struct SwiftNetClientConnection* user, const stru if(packet_info->port_info.destination_port != client_connection->port_info.source_port || packet_info->port_info.source_port != client_connection->port_info.destination_port) { #ifdef SWIFT_NET_DEBUG - if (check_debug_flag(INITIALIZATION)) { + if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) { send_debug_message("Port info does not match: {\"destination_port\": %d, \"source_port\": %d, \"source_ip_address\": \"%s\"}\n", packet_info->port_info.destination_port, packet_info->port_info.source_port, inet_ntoa(ip_header->ip_src)); } #endif @@ -151,7 +151,7 @@ static void handle_client_init(struct SwiftNetClientConnection* user, const stru if(packet_info->packet_type != REQUEST_INFORMATION) { #ifdef SWIFT_NET_DEBUG - if (check_debug_flag(INITIALIZATION)) { + if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) { send_debug_message("Invalid packet type: {\"packet_type\": %d}\n", packet_info->packet_type); } #endif diff --git a/src/initialize_client_connection.c b/src/initialize_client_connection.c index 95319d1..ddf4749 100644 --- a/src/initialize_client_connection.c +++ b/src/initialize_client_connection.c @@ -51,7 +51,7 @@ void* request_server_information(void* const request_server_information_args_voi } #ifdef SWIFT_NET_DEBUG - if (check_debug_flag(INITIALIZATION)) { + if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) { send_debug_message("Requested server information: {\"server_ip_address\": \"%s\"}\n", inet_ntoa(request_server_information_args->server_addr)); } #endif @@ -182,7 +182,7 @@ struct SwiftNetClientConnection* swiftnet_create_client(const char* const ip_add pthread_cond_init(&new_connection->execute_callback_cond, NULL); #ifdef SWIFT_NET_DEBUG - if (check_debug_flag(INITIALIZATION)) { + if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) { send_debug_message("Successfully initialized client\n"); } #endif diff --git a/src/initialize_server.c b/src/initialize_server.c index 6897ec2..874fa60 100644 --- a/src/initialize_server.c +++ b/src/initialize_server.c @@ -77,7 +77,7 @@ struct SwiftNetServer* swiftnet_create_server(const uint16_t port, const bool lo pthread_cond_init(&new_server->execute_callback_cond, NULL); #ifdef SWIFT_NET_DEBUG - if (check_debug_flag(INITIALIZATION)) { + if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) { send_debug_message("Successfully initialized server\n"); } #endif diff --git a/src/internal/internal.h b/src/internal/internal.h index a10c814..32ed98a 100644 --- a/src/internal/internal.h +++ b/src/internal/internal.h @@ -212,7 +212,7 @@ extern uint32_t items_leaked; #ifdef SWIFT_NET_DEBUG extern struct SwiftNetDebugger debugger; -static inline bool check_debug_flag(const enum SwiftNetDebugFlags flag) { +static inline bool check_debug_flag(const SwiftNetDebugFlags flag) { return (debugger.flags & flag) != 0; } diff --git a/src/manipulate_debug_flags.c b/src/manipulate_debug_flags.c index 407b9c6..d20e916 100644 --- a/src/manipulate_debug_flags.c +++ b/src/manipulate_debug_flags.c @@ -1,9 +1,9 @@ #include "internal/internal.h" #include "swift_net.h" -void swiftnet_add_debug_flags(const enum SwiftNetDebugFlags flags) { +void swiftnet_add_debug_flags(const SwiftNetDebugFlags flags) { debugger.flags |= flags; } -void swiftnet_remove_debug_flags(const enum SwiftNetDebugFlags flags) { +void swiftnet_remove_debug_flags(const SwiftNetDebugFlags flags) { debugger.flags &= ~flags; } diff --git a/src/process_packets.c b/src/process_packets.c index 7bb891c..a337b9d 100644 --- a/src/process_packets.c +++ b/src/process_packets.c @@ -363,7 +363,7 @@ static inline void swiftnet_process_packets( if(memcmp(&ip_header.ip_src, &ip_header.ip_dst, sizeof(struct in_addr)) != 0 && is_private_ip(ip_header.ip_src) == false && is_private_ip(ip_header.ip_dst)) { if(ip_header.ip_sum != 0 && packet_corrupted(checksum_received, node->data_read, packet_buffer) == true) { #ifdef SWIFT_NET_DEBUG - if (check_debug_flag(PACKETS_RECEIVING)) { + if (check_debug_flag(SWIFTNET_DEBUG_PACKETS_RECEIVING)) { send_debug_message("Received corrupted packet: {\"source_ip_address\": \"%s\", \"source_port\": %d, \"packet_id\": %d, \"received_checsum\": %d, \"real_checksum\": %d}\n", inet_ntoa(ip_header.ip_src), packet_info.port_info.source_port, ip_header.ip_id, checksum_received, crc16(packet_buffer, node->data_read)); } #endif @@ -375,7 +375,7 @@ static inline void swiftnet_process_packets( } #ifdef SWIFT_NET_DEBUG - if (check_debug_flag(PACKETS_RECEIVING)) { + if (check_debug_flag(SWIFTNET_DEBUG_PACKETS_RECEIVING)) { send_debug_message("Received packet: {\"source_ip_address\": \"%s\", \"source_port\": %d, \"packet_id\": %d, \"packet_type\": %d, \"packet_length\": %d, \"chunk_index\": %d, \"connection_type\": %d, \"checksum_received\": %d, \"real_checksum\": %d}\n", inet_ntoa(ip_header.ip_src), packet_info.port_info.source_port, ip_header.ip_id, packet_info.packet_type, packet_info.packet_length, packet_info.chunk_index, connection_type, checksum_received, crc16(node->data, node->data_read)); } #endif diff --git a/src/send_packet.c b/src/send_packet.c index 0c436ee..7c90b35 100644 --- a/src/send_packet.c +++ b/src/send_packet.c @@ -18,7 +18,7 @@ static inline enum RequestLostPacketsReturnType request_lost_packets_bitarray(const uint8_t* const raw_data, const uint32_t data_size, const struct sockaddr* const destination, pcap_t* const pcap, struct SwiftNetPacketSending* const packet_sending) { while(1) { - if(check_debug_flag(LOST_PACKETS)) { + if(check_debug_flag(SWIFTNET_DEBUG_LOST_PACKETS)) { send_debug_message("Requested list of lost packets: {\"packet_id\": %d}\n", packet_sending->packet_id); } @@ -145,7 +145,7 @@ static inline void handle_lost_packets( memcpy(current_buffer_header_ptr, prepend_buffer, prepend_size + PACKET_HEADER_SIZE); - if (check_debug_flag(LOST_PACKETS) == true) { + if (check_debug_flag(SWIFTNET_DEBUG_LOST_PACKETS) == true) { send_debug_message("Packet lost: {\"packet_id\": %d, \"chunk index\": %d}\n", packet_sending->packet_id, lost_chunk_index); } @@ -199,7 +199,7 @@ inline void swiftnet_send_packet( const uint32_t mtu = MIN(target_maximum_transmission_unit, maximum_transmission_unit); #ifdef SWIFT_NET_DEBUG - if (check_debug_flag(PACKETS_SENDING)) { + if (check_debug_flag(SWIFTNET_DEBUG_PACKETS_SENDING)) { send_debug_message("Sending packet: {\"destination_ip_address\": \"%s\", \"destination_port\": %d, \"packet_length\": %d}\n", inet_ntoa(*target_addr), port_info.destination_port, packet_length); } #endif @@ -291,7 +291,7 @@ inline void swiftnet_send_packet( const uint32_t current_offset = i * (mtu - PACKET_HEADER_SIZE); #ifdef SWIFT_NET_DEBUG - if (check_debug_flag(PACKETS_SENDING)) { + if (check_debug_flag(SWIFTNET_DEBUG_PACKETS_SENDING)) { send_debug_message("Sent chunk: {\"chunk_index\": %d}\n", i); } #endif diff --git a/src/swift_net.h b/src/swift_net.h index d9a248a..cb9776d 100644 --- a/src/swift_net.h +++ b/src/swift_net.h @@ -53,14 +53,14 @@ enum PacketType { extern uint32_t maximum_transmission_unit; #ifdef SWIFT_NET_DEBUG -#define SWIFTNET_DEBUG_FLAGS(num) ((enum SwiftNetDebugFlags)(num)) +#define SWIFTNET_DEBUG_FLAGS(num) ((SwiftNetDebugFlags)(num)) -enum SwiftNetDebugFlags { - PACKETS_SENDING = 1u << 1, - PACKETS_RECEIVING = 1u << 2, - INITIALIZATION = 1u << 3, - LOST_PACKETS = 1u << 4 -}; +typedef uint8_t SwiftNetDebugFlags; + +#define SWIFTNET_DEBUG_PACKETS_SENDING (1u << 1) +#define SWIFTNET_DEBUG_PACKETS_RECEIVING (1u << 2) +#define SWIFTNET_DEBUG_INITIALIZATION (1u << 3) +#define SWIFTNET_DEBUG_LOST_PACKETS (1u << 4) struct SwiftNetDebugger { int flags; @@ -425,9 +425,9 @@ extern void swiftnet_server_make_response( #ifdef SWIFT_NET_DEBUG // Adds one or more debug flags to the global debugger state. -extern void swiftnet_add_debug_flags(const enum SwiftNetDebugFlags flags); +extern void swiftnet_add_debug_flags(const SwiftNetDebugFlags flags); // Removes one or more debug flags from the global debugger state. -extern void swiftnet_remove_debug_flags(const enum SwiftNetDebugFlags flags); +extern void swiftnet_remove_debug_flags(const SwiftNetDebugFlags flags); #endif diff --git a/tests/integration_tests/src/run_tests.c b/tests/integration_tests/src/run_tests.c index 9915945..b1f04bf 100644 --- a/tests/integration_tests/src/run_tests.c +++ b/tests/integration_tests/src/run_tests.c @@ -217,7 +217,7 @@ int main() { swiftnet_initialize(); - swiftnet_add_debug_flags(SWIFTNET_DEBUG_FLAGS(PACKETS_SENDING | PACKETS_RECEIVING | INITIALIZATION | LOST_PACKETS)); + swiftnet_add_debug_flags(SWIFTNET_DEBUG_FLAGS(SWIFTNET_DEBUG_PACKETS_SENDING | SWIFTNET_DEBUG_PACKETS_RECEIVING | SWIFTNET_DEBUG_INITIALIZATION | SWIFTNET_DEBUG_LOST_PACKETS)); for (uint16_t i = 0; i < sizeof(tests) / sizeof(struct Test); i++) { const struct Test* current_test = &tests[i]; diff --git a/tests/performance_tests/src/main.c b/tests/performance_tests/src/main.c index 236dc4a..b64f6a4 100644 --- a/tests/performance_tests/src/main.c +++ b/tests/performance_tests/src/main.c @@ -86,7 +86,7 @@ void send_large_packets(const bool loopback) { int main() { swiftnet_initialize(); - swiftnet_add_debug_flags(SWIFTNET_DEBUG_FLAGS(PACKETS_SENDING | PACKETS_RECEIVING | INITIALIZATION | LOST_PACKETS)); + swiftnet_add_debug_flags(SWIFTNET_DEBUG_FLAGS(SWIFTNET_DEBUG_PACKETS_SENDING | SWIFTNET_DEBUG_PACKETS_RECEIVING | SWIFTNET_DEBUG_INITIALIZATION | SWIFTNET_DEBUG_LOST_PACKETS)); send_large_packets(false);