From fa259767f17a47de06442c4aca566a995c0bb73e Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 4 Apr 2024 15:55:14 -0400 Subject: [PATCH] MT#55283 push global rtpe_stats in shm to kernel Require rtpe_stats to be set before allowing a target to be created. Refactor init method into its own function. Otherwise currently unused. Change-Id: Ic66e7f92f875ede1a3a2d55fee4ed53c39ff93be --- daemon/kernel.c | 2 ++ kernel-module/xt_RTPENGINE.c | 34 ++++++++++++++++++++++++++++------ kernel-module/xt_RTPENGINE.h | 3 +++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/daemon/kernel.c b/daemon/kernel.c index 53da87f4d..07adab762 100644 --- a/daemon/kernel.c +++ b/daemon/kernel.c @@ -14,6 +14,7 @@ #include "log.h" #include "bufferpool.h" #include "main.h" +#include "statistics.h" #include "xt_RTPENGINE.h" @@ -102,6 +103,7 @@ bool kernel_init_table(void) { [REMG_GET_RESET_STATS] = sizeof(struct rtpengine_command_stats), [REMG_SEND_RTCP] = sizeof(struct rtpengine_command_send_packet), }, + .rtpe_stats = rtpe_stats, }; ret = write(kernel.fd, &cmd, sizeof(cmd)); diff --git a/kernel-module/xt_RTPENGINE.c b/kernel-module/xt_RTPENGINE.c index 417214bde..f97d23b8e 100644 --- a/kernel-module/xt_RTPENGINE.c +++ b/kernel-module/xt_RTPENGINE.c @@ -289,6 +289,13 @@ static inline int bitfield_clear(unsigned long *bf, unsigned int i); +// mirror global_stats_counter from userspace +struct global_stats_counter { +#define F(x) atomic64_t x; +#include "kernel_counter_stats_fields.inc" +#undef F +}; + struct re_crypto_context { spinlock_t lock; /* protects roc and last_*_index */ unsigned char session_key[32]; @@ -433,6 +440,8 @@ struct rtpengine_table { spinlock_t shm_lock; struct list_head shm_list; + + struct global_stats_counter *rtpe_stats; }; struct re_cipher { @@ -2415,6 +2424,8 @@ static int table_new_target(struct rtpengine_table *t, struct rtpengine_target_i /* validation */ + if (!t->rtpe_stats) + return -EIO; if (!is_valid_address(&i->local)) return -EINVAL; if (i->num_destinations > RTPE_MAX_FORWARD_DESTINATIONS) @@ -3825,6 +3836,22 @@ static const size_t input_req_sizes[__REMG_LAST] = { - sizeof(struct rtpengine_stats_info), }; +static int rtpengine_init_table(struct rtpengine_table *t, struct rtpengine_init_info *init) { + int i; + + if (t->rtpe_stats) + return -EBUSY; + t->rtpe_stats = shm_map_resolve(init->rtpe_stats, sizeof(*t->rtpe_stats)); + if (!t->rtpe_stats) + return -EFAULT; + if (init->last_cmd != __REMG_LAST) + return -ERANGE; + for (i = 0; i < __REMG_LAST; i++) + if (init->msg_size[i] != min_req_sizes[i]) + return -EMSGSIZE; + return 0; +} + static inline ssize_t proc_control_read_write(struct file *file, char __user *ubuf, size_t buflen, int writeable) { @@ -3835,7 +3862,6 @@ static inline ssize_t proc_control_read_write(struct file *file, char __user *ub enum rtpengine_command cmd; char scratchbuf[512]; size_t readlen, writelen, writeoffset; - int i; union { struct rtpengine_command_init *init; @@ -3911,11 +3937,7 @@ static inline ssize_t proc_control_read_write(struct file *file, char __user *ub switch (cmd) { case REMG_INIT: - if (msg.init->init.last_cmd != __REMG_LAST) - err = -ERANGE; - for (i = 0; i < __REMG_LAST; i++) - if (msg.init->init.msg_size[i] != min_req_sizes[i]) - err = -EMSGSIZE; + err = rtpengine_init_table(t, &msg.init->init); break; case REMG_ADD_TARGET: diff --git a/kernel-module/xt_RTPENGINE.h b/kernel-module/xt_RTPENGINE.h index 5066ca88a..cd371158a 100644 --- a/kernel-module/xt_RTPENGINE.h +++ b/kernel-module/xt_RTPENGINE.h @@ -11,6 +11,8 @@ +struct global_stats_counter; + struct xt_rtpengine_info { unsigned int id; }; @@ -200,6 +202,7 @@ enum rtpengine_command { struct rtpengine_init_info { int last_cmd; size_t msg_size[__REMG_LAST]; + struct global_stats_counter *rtpe_stats; }; struct rtpengine_send_packet_info {