Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cleanup_swiftnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void swiftnet_cleanup() {
allocator_destroy(&client_packet_data_memory_allocator ENABLE_INTERNAL_CHECK);
allocator_destroy(&packet_buffer_memory_allocator ENABLE_INTERNAL_CHECK);

#ifdef SWIFT_NET_REQUESTS
#ifndef SWIFT_NET_DISABLE_REQUESTS
allocator_destroy(&requests_sent_memory_allocator ENABLE_INTERNAL_CHECK);

hashmap_destroy(&requests_sent);
Expand Down
8 changes: 4 additions & 4 deletions src/execute_packet_callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#include <stdlib.h>
#include <unistd.h>

static struct PacketCallbackQueueNode* wait_for_next_packet_callback(struct PacketCallbackQueue* const packet_queue) {
struct PacketCallbackQueueNode* restrict node_to_process;
static struct SwiftNetPacketCallbackQueueNode* wait_for_next_packet_callback(struct SwiftNetPacketCallbackQueue* const packet_queue) {
struct SwiftNetPacketCallbackQueueNode* restrict node_to_process;


LOCK_ATOMIC_DATA_TYPE(&packet_queue->locked);
Expand Down Expand Up @@ -48,7 +48,7 @@ static inline void remove_pending_message_from_hashmap(struct SwiftNetHashMap* c
}

void execute_packet_callback(
struct PacketCallbackQueue* const queue,
struct SwiftNetPacketCallbackQueue* const queue,
void (*const _Atomic * const packet_handler)(void *const, void *const),
const enum ConnectionType connection_type,
const _Atomic bool * const closing,
Expand All @@ -61,7 +61,7 @@ void execute_packet_callback(
) {
void (*packet_handler_loaded)(void *const, void *const);

struct PacketCallbackQueueNode* restrict current_node;
struct SwiftNetPacketCallbackQueueNode* restrict current_node;

uint8_t idle_stage;

Expand Down
2 changes: 1 addition & 1 deletion src/generic_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// Set the handler for incoming packets/messages on the server or client
static inline void swiftnet_validate_new_handler(void(*new_handler)(void)) {
#ifdef SWIFT_NET_ERROR
#ifndef SWIFT_NET_DISABLE_ERROR_CHECKING
if(unlikely(new_handler == NULL)) {
PRINT_ERROR("Error: Invalid arguments given");
exit(EXIT_FAILURE);
Expand Down
18 changes: 9 additions & 9 deletions src/handle_packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include <stddef.h>

static inline void insert_queue_node(
struct PacketQueueNode* restrict const new_node,
struct PacketQueue* const packet_queue
struct SwiftNetPacketQueueNode* restrict const new_node,
struct SwiftNetPacketQueue* const packet_queue
) {
if(unlikely(new_node == NULL)) {
return;
Expand All @@ -38,8 +38,8 @@ static inline void insert_queue_node(
return;
}

static inline struct PacketQueueNode* construct_node(const uint32_t data_read, void* restrict const data, const uint32_t sender_address) {
struct PacketQueueNode* restrict node;
static inline struct SwiftNetPacketQueueNode* construct_node(const uint32_t data_read, void* restrict const data, const uint32_t sender_address) {
struct SwiftNetPacketQueueNode* restrict node;


node = allocator_allocate(&packet_queue_node_memory_allocator);
Expand All @@ -51,7 +51,7 @@ static inline struct PacketQueueNode* construct_node(const uint32_t data_read, v


node_assign_values:
*node = (struct PacketQueueNode){
*node = (struct SwiftNetPacketQueueNode){
.data = data,
.data_read = data_read,
.sender_address = (struct in_addr){.s_addr = sender_address},
Expand All @@ -66,7 +66,7 @@ static inline struct PacketQueueNode* construct_node(const uint32_t data_read, v
}

static inline void swiftnet_handle_packets(
struct PacketQueue* const packet_queue,
struct SwiftNetPacketQueue* const packet_queue,
pthread_mutex_t* const process_packets_mtx,
pthread_cond_t* const process_packets_cond,
_Atomic bool *const processing_packets,
Expand Down Expand Up @@ -165,7 +165,7 @@ static void handle_client_init(struct SwiftNetClientConnection* const client_con

validate_packet_size:
if(bytes_received != PACKET_HEADER_SIZE + sizeof(struct SwiftNetServerInformation) + prepend_size) {
#ifdef SWIFT_NET_DEBUG
#ifndef SWIFT_NET_DISABLE_DEBUGGING
if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) {
send_debug_message("Invalid packet received from server. Expected server information: {\"bytes_received\": %u, \"expected_bytes\": %lu}\n", bytes_received, PACKET_HEADER_SIZE + sizeof(struct SwiftNetServerInformation));
}
Expand All @@ -189,7 +189,7 @@ static void handle_client_init(struct SwiftNetClientConnection* const client_con
server_information = (struct SwiftNetServerInformation*)(buffer + prepend_size+ sizeof(struct ip) + sizeof(struct SwiftNetPacketInfo));

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
#ifndef SWIFT_NET_DISABLE_DEBUGGING
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(((struct ip*)(buffer + prepend_size))->ip_src));
}
Expand All @@ -199,7 +199,7 @@ static void handle_client_init(struct SwiftNetClientConnection* const client_con
}

if(packet_info->packet_type != REQUEST_INFORMATION) {
#ifdef SWIFT_NET_DEBUG
#ifndef SWIFT_NET_DISABLE_DEBUGGING
if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) {
send_debug_message("Invalid packet type: {\"packet_type\": %d}\n", packet_info->packet_type);
}
Expand Down
8 changes: 4 additions & 4 deletions src/initialize_client_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void* request_server_information(void* restrict const request_server_information
goto exit;
}

#ifdef SWIFT_NET_DEBUG
#ifndef SWIFT_NET_DISABLE_DEBUGGING
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));
}
Expand Down Expand Up @@ -97,7 +97,7 @@ static inline struct SwiftNetClientConnection* construct_client_connection(const
.packets_completed = hashmap_create(&packet_completed_key_allocator),
.packets_sending = hashmap_create(&uint16_memory_allocator),
.pending_messages = hashmap_create(&pending_message_key_allocator),
.packet_queue = (struct PacketQueue){
.packet_queue = (struct SwiftNetPacketQueue){
.first_node = NULL,
.last_node = NULL
},
Expand All @@ -112,7 +112,7 @@ static inline struct SwiftNetClientConnection* construct_client_connection(const
atomic_store_explicit(&new_connection->initialized, false, memory_order_release);
atomic_store_explicit(&new_connection->packet_handler_user_arg, NULL, memory_order_release);

memset(&new_connection->packet_callback_queue, 0x00, sizeof(struct PacketCallbackQueue));
memset(&new_connection->packet_callback_queue, 0x00, sizeof(struct SwiftNetPacketCallbackQueue));

return new_connection;
}
Expand Down Expand Up @@ -212,7 +212,7 @@ struct SwiftNetClientConnection* swiftnet_create_client(const char* const ip_add
pthread_cond_init(&new_connection->process_packets_cond, NULL);
pthread_cond_init(&new_connection->execute_callback_cond, NULL);

#ifdef SWIFT_NET_DEBUG
#ifndef SWIFT_NET_DISABLE_DEBUGGING
if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) {
send_debug_message("Successfully initialized client\n");
}
Expand Down
6 changes: 3 additions & 3 deletions src/initialize_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ static inline struct SwiftNetServer* construct_server(const bool loopback, const
.eth_header = eth_header,
.server_port = server_port,
.loopback = loopback,
.packet_queue = (struct PacketQueue){
.packet_queue = (struct SwiftNetPacketQueue){
.first_node = NULL,
.last_node = NULL
},
};

memset(&new_server->packet_callback_queue, 0x00, sizeof(struct PacketCallbackQueue));
memset(&new_server->packet_callback_queue, 0x00, sizeof(struct SwiftNetPacketCallbackQueue));

UNLOCK_ATOMIC_DATA_TYPE(&new_server->packet_queue.locked);
UNLOCK_ATOMIC_DATA_TYPE(&new_server->packet_callback_queue.locked);
Expand Down Expand Up @@ -79,7 +79,7 @@ struct SwiftNetServer* swiftnet_create_server(const uint16_t port, const bool lo
pthread_cond_init(&new_server->process_packets_cond, NULL);
pthread_cond_init(&new_server->execute_callback_cond, NULL);

#ifdef SWIFT_NET_DEBUG
#ifndef SWIFT_NET_DISABLE_DEBUGGING
if (check_debug_flag(SWIFTNET_DEBUG_INITIALIZATION)) {
send_debug_message("Successfully initialized server\n");
}
Expand Down
12 changes: 6 additions & 6 deletions src/initialize_swiftnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "internal/internal.h"
#include <unistd.h>

#ifdef SWIFT_NET_DEBUG
#ifndef SWIFT_NET_DISABLE_DEBUGGING
struct SwiftNetDebugger debugger = {.flags = 0};
#endif

Expand Down Expand Up @@ -38,7 +38,7 @@ struct SwiftNetMemoryAllocator uint16_memory_allocator;
struct SwiftNetMemoryAllocator pending_message_key_allocator;
struct SwiftNetMemoryAllocator packet_completed_key_allocator;

#ifdef SWIFT_NET_REQUESTS
#ifndef SWIFT_NET_DISABLE_REQUESTS
struct SwiftNetMemoryAllocator requests_sent_memory_allocator;
struct SwiftNetHashMap requests_sent;
#endif
Expand All @@ -50,8 +50,8 @@ pthread_t memory_cleanup_thread;
_Atomic bool swiftnet_closing;

static inline void initialize_allocators() {
packet_queue_node_memory_allocator = allocator_create(sizeof(struct PacketQueueNode), 40 * SWIFT_NET_MEMORY_USAGE);
packet_callback_queue_node_memory_allocator = allocator_create(sizeof(struct PacketCallbackQueueNode), 40 * SWIFT_NET_MEMORY_USAGE);
packet_queue_node_memory_allocator = allocator_create(sizeof(struct SwiftNetPacketQueueNode), 40 * SWIFT_NET_MEMORY_USAGE);
packet_callback_queue_node_memory_allocator = allocator_create(sizeof(struct SwiftNetPacketCallbackQueueNode), 40 * SWIFT_NET_MEMORY_USAGE);
server_packet_data_memory_allocator = allocator_create(sizeof(struct SwiftNetServerPacketData), 40 * SWIFT_NET_MEMORY_USAGE);
client_packet_data_memory_allocator = allocator_create(sizeof(struct SwiftNetClientPacketData), 40 * SWIFT_NET_MEMORY_USAGE);
packet_buffer_memory_allocator = allocator_create(maximum_transmission_unit + sizeof(struct ether_header), 40 * SWIFT_NET_MEMORY_USAGE);
Expand All @@ -63,13 +63,13 @@ static inline void initialize_allocators() {
pending_message_key_allocator = allocator_create(sizeof(struct PendingMessagesKey), 0xFF * SWIFT_NET_MEMORY_USAGE);
packet_completed_key_allocator = allocator_create(sizeof(struct PacketCompletedKey), 0xFF * SWIFT_NET_MEMORY_USAGE);

#ifdef SWIFT_NET_REQUESTS
#ifndef SWIFT_NET_DISABLE_REQUESTS
requests_sent_memory_allocator = allocator_create(sizeof(struct RequestSent), 40 * SWIFT_NET_MEMORY_USAGE);
#endif
}

static inline void initialize_vectors() {
#ifdef SWIFT_NET_REQUESTS
#ifndef SWIFT_NET_DISABLE_REQUESTS
requests_sent = hashmap_create(&uint16_memory_allocator);
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/internal/dpdk/dpdk_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static inline void validate_append_to_packet_args(const void* restrict const dat
}

void swiftnet_append_to_buffer(const void* restrict const data, const uint32_t data_size, struct SwiftNetPacketBuffer* restrict const buffer) {
#ifdef SWIFT_NET_ERROR
#ifndef SWIFT_NET_DISABLE_ERROR_CHECKING
validate_append_to_packet_args(data, data_size);
#endif

Expand Down
8 changes: 5 additions & 3 deletions src/internal/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ extern uint32_t bytes_leaked;
extern uint32_t items_leaked;
#endif

#ifdef SWIFT_NET_DEBUG
#ifndef SWIFT_NET_DISABLE_DEBUGGING
extern struct SwiftNetDebugger debugger;

static inline ALWAYS_INLINE bool check_debug_flag(const SwiftNetDebugFlags flag) {
Expand Down Expand Up @@ -307,7 +307,7 @@ extern void* hashmap_get(const void* const key_data, const uint32_t data_size, s
extern void* server_start_pcap(void* const server_void);
extern void* client_start_pcap(void* const client_void);

#ifdef SWIFT_NET_REQUESTS
#ifndef SWIFT_NET_DISABLE_REQUESTS
struct RequestSent {
_Atomic(void*) packet_data;
struct in_addr address;
Expand All @@ -318,6 +318,8 @@ extern struct SwiftNetMemoryAllocator requests_sent_memory_allocator;
extern struct SwiftNetHashMap requests_sent;
#endif

extern uint16_t maximum_transmission_unit;

extern void swiftnet_send_packet(
const uint16_t target_maximum_transmission_unit,
const struct SwiftNetPortInfo port_info,
Expand All @@ -328,7 +330,7 @@ extern void swiftnet_send_packet(
struct SwiftNetMemoryAllocator* const packets_sending_memory_allocator,
const struct ether_header eth_hdr,
const struct SwiftNetNetworkData network_data
#ifdef SWIFT_NET_REQUESTS
#ifndef SWIFT_NET_DISABLE_REQUESTS
, struct RequestSent* const request_sent
, const bool response
, const uint16_t request_packet_id
Expand Down
2 changes: 1 addition & 1 deletion src/internal/pcap/pcap_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static inline void append_data(uint8_t* restrict * restrict const append_pointer
}

void swiftnet_append_to_buffer(const void* restrict const data, const uint32_t data_size, struct SwiftNetPacketBuffer* restrict const buffer) {
#ifdef SWIFT_NET_ERROR
#ifndef SWIFT_NET_DISABLE_ERROR_CHECKING
validate_append_to_packet_args(data, data_size);
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/make_request.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <unistd.h>
#include <sys/time.h>

#ifdef SWIFT_NET_REQUESTS
#ifndef SWIFT_NET_DISABLE_REQUESTS

static inline void delete_request_sent(struct RequestSent* restrict const request_sent) {
LOCK_ATOMIC_DATA_TYPE(&requests_sent.atomic_lock)
Expand Down
2 changes: 1 addition & 1 deletion src/make_response.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "internal/internal.h"
#include "swift_net.h"

#ifdef SWIFT_NET_REQUESTS
#ifndef SWIFT_NET_DISABLE_REQUESTS

void swiftnet_client_make_response(struct SwiftNetClientConnection* const client, struct SwiftNetClientPacketData* const packet_data, struct SwiftNetPacketBuffer* restrict const buffer) {
#ifdef SWIFT_NET_BACKEND_DPDK
Expand Down
2 changes: 1 addition & 1 deletion src/manipulate_debug_flags.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "internal/internal.h"
#include "swift_net.h"

#ifdef SWIFT_NET_DEBUG
#ifndef SWIFT_NET_DISABLE_DEBUGGING
void swiftnet_add_debug_flags(const SwiftNetDebugFlags flags) {
debugger.flags |= flags;
}
Expand Down
Loading
Loading