2 #include <sys/sysctl.h>
9 #include "mptcp-internal.h"
12 #define NET_PROC_SYS_NET_MPTCP "/proc/sys/net/mptcp/"
13 #define NET_PROC_SYS_NET_MPTCP_VALUE_MAX_SIZE 15
15 static gboolean __write_mptcp_parameter(const char* key, const char* value)
20 snprintf(path, sizeof(path), NET_PROC_SYS_NET_MPTCP"%s", key);
22 fd = open(path, O_RDWR);
24 ERR("Fail to open %s", path);
28 DBG("write mptcp parameter. len: %d, value: %s", strlen(value), value);
29 if (write(fd, value, strlen(value)) < 0) {
30 ERR("Fail to write %s to %s", value, path);
39 static char* __read_mptcp_parameter(const char* key)
44 char buf[NET_PROC_SYS_NET_MPTCP_VALUE_MAX_SIZE];
46 snprintf(path, sizeof(path), NET_PROC_SYS_NET_MPTCP"%s", key);
48 fd = open(path, O_RDWR);
50 ERR("Fail to open %s", path);
54 if ((len = read(fd, buf, NET_PROC_SYS_NET_MPTCP_VALUE_MAX_SIZE)) < 0) {
55 ERR("Fail to read %s", path);
68 DBG("read mptcp parameter. len: %d, value: %s", len, buf);
70 return g_strndup(buf, strlen(buf));
73 gboolean mptcp_supported()
75 return g_file_test(NET_PROC_SYS_NET_MPTCP, G_FILE_TEST_EXISTS);
78 gboolean mptcp_set_enable(gint enable)
80 const char* sysctlname = "mptcp_enabled";
82 if (enable != 0 && enable != 1 && enable != 2) {
83 ERR("Invalid parameter enable %d", enable);
87 snprintf(buf, 2, "%d", enable);
88 return __write_mptcp_parameter(sysctlname, buf);
91 gint mptcp_get_enabled()
93 const char* sysctlname = "mptcp_enabled";
97 if ((buf = __read_mptcp_parameter(sysctlname)) == NULL) {
98 ERR("Fail to read %s, sysctlname");
108 gboolean mptcp_set_path_manager(const gchar* pm)
110 const char* sysctlname = "mptcp_path_manager";
111 return __write_mptcp_parameter(sysctlname, pm);
114 gchar* mptcp_get_path_manager()
116 const char* sysctlname = "mptcp_path_manager";
117 return __read_mptcp_parameter(sysctlname);
120 gboolean mptcp_mptcp_set_scheduler(const gchar* scheduler)
122 const char* sysctlname = "mptcp_scheduler";
123 return __write_mptcp_parameter(sysctlname, scheduler);
126 gchar* mptcp_get_scheduler()
128 const char* sysctlname = "mptcp_scheduler";
129 return __read_mptcp_parameter(sysctlname);