Browse Source

TT#26513 Delete the kernel forwarding table on startup

If we are creating the kernel forwarding table, we have to make sure it
has been deleted already, otherwise we can get into collisions with the
already setup forwardings, and the subsequent add will fail anyway.

Change-Id: I2601c602543ff3e3493bae296d263dde545ff352
changes/54/17654/2
Guillem Jover 8 years ago
parent
commit
fd3c1d2519
2 changed files with 17 additions and 5 deletions
  1. +17
    -2
      daemon/kernel.c
  2. +0
    -3
      debian/ngcp-rtpengine-daemon.init

+ 17
- 2
daemon/kernel.c View File

@ -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]; char str[64];
int saved_errno; int saved_errno;
int fd; int fd;
@ -37,7 +37,9 @@ static int kernel_create_table(unsigned int id) {
fd = open(PREFIX "/control", O_WRONLY | O_TRUNC); fd = open(PREFIX "/control", O_WRONLY | O_TRUNC);
if (fd == -1) if (fd == -1)
return -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)); i = write(fd, str, strlen(str));
if (i == -1) if (i == -1)
goto fail; goto fail;
@ -52,6 +54,14 @@ fail:
return -1; 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) { static int kernel_open_table(unsigned int id) {
char str[64]; char str[64];
int saved_errno; int saved_errno;
@ -85,6 +95,11 @@ int kernel_setup_table(unsigned int id) {
kernel.is_wanted = 1; 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)) { if (kernel_create_table(id)) {
ilog(LOG_ERR, "FAILED TO CREATE KERNEL TABLE %i (%s), KERNEL FORWARDING DISABLED", ilog(LOG_ERR, "FAILED TO CREATE KERNEL TABLE %i (%s), KERNEL FORWARDING DISABLED",
id, strerror(errno)); id, strerror(errno));


+ 0
- 3
debian/ngcp-rtpengine-daemon.init View File

@ -182,9 +182,6 @@ case "$1" in
ip6tables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null ip6tables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null
ip6tables -I rtpengine -p udp -j RTPENGINE --id "$TABLE" ip6tables -I rtpengine -p udp -j RTPENGINE --id "$TABLE"
fi fi
if [ -e /proc/rtpengine/control ]; then
echo "del $TABLE" > /proc/rtpengine/control 2>/dev/null
fi
fi fi
set -e set -e
log_daemon_msg "Starting $DESC" "$NAME" log_daemon_msg "Starting $DESC" "$NAME"


Loading…
Cancel
Save