summaryrefslogtreecommitdiff
path: root/sock.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-07-19 14:41:20 +0300
committerDaniel Borkmann <daniel@iogearbox.net>2015-07-20 10:06:29 +0200
commit96d822d2c0ef2be429b1c11bbe9a9c03bedd500d (patch)
tree32dc79e1aba012e6df3954203eba53550aefd9b2 /sock.c
parenta839a6ad1dd48802e50fddca2747eea511b65826 (diff)
sock: Use sysctl helpers to access /proc/sys/ params
Use helpers from sysctl.c module to set sock memory params via /proc/sys/net/core. Signed-off-by: Vadim Kochan <vadim4j@gmail.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'sock.c')
-rw-r--r--sock.c41
1 files changed, 9 insertions, 32 deletions
diff --git a/sock.c b/sock.c
index cfca05e..84723d0 100644
--- a/sock.c
+++ b/sock.c
@@ -10,6 +10,7 @@
#include "str.h"
#include "linktype.h"
#include "built_in.h"
+#include "sysctl.h"
int af_socket(int af)
{
@@ -149,50 +150,26 @@ enum {
#define SMEM_SUG_DEF 4194304
static const char *const sock_mem[] = {
- [sock_rmem_max] = "/proc/sys/net/core/rmem_max",
- [sock_rmem_def] = "/proc/sys/net/core/rmem_default",
- [sock_wmem_max] = "/proc/sys/net/core/wmem_max",
- [sock_wmem_def] = "/proc/sys/net/core/wmem_default",
+ [sock_rmem_max] = "net/core/rmem_max",
+ [sock_rmem_def] = "net/core/rmem_default",
+ [sock_wmem_max] = "net/core/wmem_max",
+ [sock_wmem_def] = "net/core/wmem_default",
};
static int get_system_socket_mem(int which)
{
- int fd, val = -1;
- ssize_t ret;
- const char *file = sock_mem[which];
- char buff[64];
+ int val;
- fd = open(file, O_RDONLY);
- if (fd < 0)
- return val;
+ if (sysctl_get_int(sock_mem[which], &val))
+ return -1;
- ret = read(fd, buff, sizeof(buff));
- if (ret > 0)
- val = atoi(buff);
-
- close(fd);
return val;
}
static void set_system_socket_mem(int which, int val)
{
- int fd;
- const char *file = sock_mem[which];
- ssize_t ret;
- char buff[64];
-
- fd = open(file, O_WRONLY);
- if (fd < 0)
- return;
-
- memset(buff, 0, sizeof(buff));
- slprintf(buff, sizeof(buff), "%d", val);
-
- ret = write(fd, buff, strlen(buff));
- if (ret < 0)
+ if (sysctl_set_int(sock_mem[which], val))
panic("Cannot set system socket memory!\n");
-
- close(fd);
}
void set_system_socket_memory(int *vals, size_t len)