From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Tue, 30 Nov 2021 17:54:38 +0000 (+0000) Subject: Don't die if the clock table is full or address list is malformed -- just ignore... X-Git-Tag: 1.2~69 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d99f2ba3998fb92a561fdfd7f37da2ce29f3e2a8;p=thirdparty%2Fnqptp.git Don't die if the clock table is full or address list is malformed -- just ignore any extra clocks or invalid ip specs. --- diff --git a/nqptp-clock-sources.c b/nqptp-clock-sources.c index ef95bdd..90349c9 100644 --- a/nqptp-clock-sources.c +++ b/nqptp-clock-sources.c @@ -58,12 +58,11 @@ int find_clock_source_record(char *sender_string, clock_source_private_data *clo int create_clock_source_record(char *sender_string, clock_source_private_data *clocks_private_info) { - // sometimes, the mutex will already be locked - // return the index of a clock entry in the clock information arrays or -1 if full + // return the index of a clock entry in the clock information arrays or -1 if full // initialise the entries in the shared and private arrays int response = -1; int i = 0; - int found = 0; + int found = 0; // trying to find an unused entry while ((found == 0) && (i < MAX_CLOCKS)) { if (clocks_private_info[i].in_use == 0) found = 1; @@ -92,10 +91,10 @@ int create_clock_source_record(char *sender_string, debug(2, "create record for ip: %s, family: %s.", &clocks_private_info[i].ip, clocks_private_info[i].family == AF_INET6 ? "IPv6" : "IPv4"); } else { - die("cannot getaddrinfo for ip: %s.", &clocks_private_info[i].ip); + debug(1, "cannot getaddrinfo for ip: %s.", &clocks_private_info[i].ip); } } else { - die("Clock tables full!"); + debug(1, "Clock tables full!"); } return response; } diff --git a/nqptp-message-handlers.c b/nqptp-message-handlers.c index acfa561..fafb3a4 100644 --- a/nqptp-message-handlers.c +++ b/nqptp-message-handlers.c @@ -50,7 +50,9 @@ void handle_control_port_messages(char *buf, ssize_t recv_len, int t = find_clock_source_record(new_ip, clock_private_info); if (t == -1) t = create_clock_source_record(new_ip, clock_private_info); - clock_private_info[t].flags |= (1 << clock_is_a_timing_peer); + if (t != -1) // if the clock table is not full, show it's a timing peer + clock_private_info[t].flags |= (1 << clock_is_a_timing_peer); + // otherwise, drop it } } diff --git a/nqptp-shm-structures.h b/nqptp-shm-structures.h index f4db8c6..f5edbd4 100644 --- a/nqptp-shm-structures.h +++ b/nqptp-shm-structures.h @@ -21,7 +21,7 @@ #define NQPTP_SHM_STRUCTURES_H #define STORAGE_ID "/nqptp" -#define MAX_CLOCKS 32 +#define MAX_CLOCKS 64 #define NQPTP_SHM_STRUCTURES_VERSION 6 #define NQPTP_CONTROL_PORT 9000 diff --git a/nqptp.c b/nqptp.c index 2d676f7..64f85c6 100644 --- a/nqptp.c +++ b/nqptp.c @@ -178,6 +178,7 @@ int main(int argc, char **argv) { debug_init(debug_level, 0, 1, 1); debug(1, "startup. self clock id: \"%" PRIx64 "\".", get_self_clock_id()); + debug(1, "size of a clock entry is %u bytes.", sizeof(clock_source_private_data)); atexit(goodbye); sockets_open_stuff.sockets_open = 0; @@ -396,7 +397,7 @@ int main(int argc, char **argv) { recv_len); // unusual messages will have debug level 1. break; } - } + } // otherwise, just forget it } } }