diff --git a/daemon/kernel.c b/daemon/kernel.c index 0b17700ee..269e757b9 100644 --- a/daemon/kernel.c +++ b/daemon/kernel.c @@ -28,7 +28,7 @@ struct kernel_interface kernel; -static int kernel_create_table(unsigned int id) { +static int kernel_action_table(const char *action, unsigned int id) { char str[64]; int fd; int i; @@ -36,7 +36,9 @@ static int kernel_create_table(unsigned int id) { fd = open(PREFIX "/control", O_WRONLY | O_TRUNC); if (fd == -1) return -1; - sprintf(str, "add %u\n", id); + i = snprintf(str, sizeof(str), "%s %u\n", action, id); + if (i >= sizeof(str)) + goto fail; i = write(fd, str, strlen(str)); if (i == -1) goto fail; @@ -49,6 +51,14 @@ fail: return -1; } +static int kernel_create_table(unsigned int id) { + return kernel_action_table("add", id); +} + +static int kernel_delete_table(unsigned int id) { + return kernel_action_table("del", id); +} + static int kernel_open_table(unsigned int id) { char str[64]; int fd; @@ -79,6 +89,11 @@ int kernel_setup_table(unsigned int id) { kernel.is_wanted = 1; + if (kernel_delete_table(id) && errno != ENOENT) { + ilog(LOG_ERR, "FAILED TO DELETE KERNEL TABLE %i (%s), KERNEL FORWARDING DISABLED", + id, strerror(errno)); + return -1; + } if (kernel_create_table(id)) { ilog(LOG_ERR, "FAILED TO CREATE KERNEL TABLE %i (%s), KERNEL FORWARDING DISABLED", id, strerror(errno)); diff --git a/debian/ngcp-rtpengine-daemon.init b/debian/ngcp-rtpengine-daemon.init index 249316555..f3a1cdb3e 100755 --- a/debian/ngcp-rtpengine-daemon.init +++ b/debian/ngcp-rtpengine-daemon.init @@ -182,9 +182,6 @@ case "$1" in ip6tables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null ip6tables -I rtpengine -p udp -j RTPENGINE --id "$TABLE" fi - if [ -e /proc/rtpengine/control ]; then - echo "del $TABLE" > /proc/rtpengine/control 2>/dev/null - fi fi set -e log_daemon_msg "Starting $DESC" "$NAME"