From 7e8acd6102a7406e0b50a4abd12330c193dd6eba Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 4 Apr 2024 15:46:35 -0400 Subject: [PATCH] MT#55283 split up table open and init Rename the "noop" method to "init" and split up the function to open the table into two parts. Open the control file first, then do the mmap(), then init other things, then finally call the init method. Change-Id: I832f6e90fbec4375e3e19ed6e72d7cce78488e9e --- daemon/kernel.c | 31 ++++++++++++++++--------------- daemon/main.c | 2 ++ include/kernel.h | 1 + kernel-module/xt_RTPENGINE.c | 12 ++++++------ kernel-module/xt_RTPENGINE.h | 8 ++++---- 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/daemon/kernel.c b/daemon/kernel.c index 69abb7494..53da87f4d 100644 --- a/daemon/kernel.c +++ b/daemon/kernel.c @@ -68,22 +68,29 @@ static void kernel_free(void *p, size_t len) { static int kernel_open_table(unsigned int id) { char s[64]; - int saved_errno; int fd; - struct rtpengine_command_noop cmd; - ssize_t ret; sprintf(s, PREFIX "/%u/control", id); fd = open(s, O_RDWR | O_TRUNC); if (fd == -1) return -1; - cmd.cmd = REMG_NOOP; + return fd; +} + +bool kernel_init_table(void) { + if (!kernel.is_open) + return true; + + struct rtpengine_command_init cmd; + ssize_t ret; + + cmd.cmd = REMG_INIT; - cmd.noop = (struct rtpengine_noop_info) { + cmd.init = (struct rtpengine_init_info) { .last_cmd = __REMG_LAST, .msg_size = { - [REMG_NOOP] = sizeof(struct rtpengine_command_noop), + [REMG_INIT] = sizeof(struct rtpengine_command_init), [REMG_ADD_TARGET] = sizeof(struct rtpengine_command_add_target), [REMG_DEL_TARGET_STATS] = sizeof(struct rtpengine_command_del_target_stats), [REMG_ADD_DESTINATION] = sizeof(struct rtpengine_command_destination), @@ -97,17 +104,11 @@ static int kernel_open_table(unsigned int id) { }, }; - ret = write(fd, &cmd, sizeof(cmd)); + ret = write(kernel.fd, &cmd, sizeof(cmd)); if (ret <= 0) - goto fail; - - return fd; + return false; -fail: - saved_errno = errno; - close(fd); - errno = saved_errno; - return -1; + return true; } bool kernel_setup_table(unsigned int id) { diff --git a/daemon/main.c b/daemon/main.c index 43fdb30b0..ca13cffd8 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1301,6 +1301,8 @@ static void init_everything(void) { abort(); codecs_init(); janus_init(); + if (!kernel_init_table()) + die("Kernel module version mismatch or other fatal error"); } diff --git a/include/kernel.h b/include/kernel.h index 0536ee1ed..bae2c656a 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -31,6 +31,7 @@ TYPED_GQUEUE(kernel, struct rtpengine_list_entry) bool kernel_setup_table(unsigned int); +bool kernel_init_table(void); void kernel_shutdown_table(void); void kernel_add_stream(struct rtpengine_target_info *); diff --git a/kernel-module/xt_RTPENGINE.c b/kernel-module/xt_RTPENGINE.c index 985cb6c4a..417214bde 100644 --- a/kernel-module/xt_RTPENGINE.c +++ b/kernel-module/xt_RTPENGINE.c @@ -3793,7 +3793,7 @@ out: static const size_t min_req_sizes[__REMG_LAST] = { - [REMG_NOOP] = sizeof(struct rtpengine_command_noop), + [REMG_INIT] = sizeof(struct rtpengine_command_init), [REMG_ADD_TARGET] = sizeof(struct rtpengine_command_add_target), [REMG_DEL_TARGET_STATS] = sizeof(struct rtpengine_command_del_target_stats), [REMG_ADD_DESTINATION] = sizeof(struct rtpengine_command_destination), @@ -3807,7 +3807,7 @@ static const size_t min_req_sizes[__REMG_LAST] = { }; static const size_t max_req_sizes[__REMG_LAST] = { - [REMG_NOOP] = sizeof(struct rtpengine_command_noop), + [REMG_INIT] = sizeof(struct rtpengine_command_init), [REMG_ADD_TARGET] = sizeof(struct rtpengine_command_add_target), [REMG_DEL_TARGET_STATS] = sizeof(struct rtpengine_command_del_target_stats), [REMG_ADD_DESTINATION] = sizeof(struct rtpengine_command_destination), @@ -3838,7 +3838,7 @@ static inline ssize_t proc_control_read_write(struct file *file, char __user *ub int i; union { - struct rtpengine_command_noop *noop; + struct rtpengine_command_init *init; struct rtpengine_command_add_target *add_target; struct rtpengine_command_del_target *del_target; struct rtpengine_command_del_target_stats *del_target_stats; @@ -3910,11 +3910,11 @@ static inline ssize_t proc_control_read_write(struct file *file, char __user *ub err = 0; switch (cmd) { - case REMG_NOOP: - if (msg.noop->noop.last_cmd != __REMG_LAST) + case REMG_INIT: + if (msg.init->init.last_cmd != __REMG_LAST) err = -ERANGE; for (i = 0; i < __REMG_LAST; i++) - if (msg.noop->noop.msg_size[i] != min_req_sizes[i]) + if (msg.init->init.msg_size[i] != min_req_sizes[i]) err = -EMSGSIZE; break; diff --git a/kernel-module/xt_RTPENGINE.h b/kernel-module/xt_RTPENGINE.h index c2f2f2d80..5066ca88a 100644 --- a/kernel-module/xt_RTPENGINE.h +++ b/kernel-module/xt_RTPENGINE.h @@ -182,7 +182,7 @@ struct rtpengine_stats_info { }; enum rtpengine_command { - REMG_NOOP = 1, + REMG_INIT = 1, REMG_ADD_TARGET, REMG_ADD_DESTINATION, REMG_ADD_CALL, @@ -197,7 +197,7 @@ enum rtpengine_command { __REMG_LAST }; -struct rtpengine_noop_info { +struct rtpengine_init_info { int last_cmd; size_t msg_size[__REMG_LAST]; }; @@ -210,9 +210,9 @@ struct rtpengine_send_packet_info { unsigned char data[]; }; -struct rtpengine_command_noop { +struct rtpengine_command_init { enum rtpengine_command cmd; - struct rtpengine_noop_info noop; + struct rtpengine_init_info init; }; struct rtpengine_command_add_target {