8 #include "mptcp-internal.h"
11 #define NET_PROC_SYS_NET_MPTCP "/proc/sys/net/mptcp/"
12 #define NET_PROC_SYS_NET_MPTCP_VALUE_MAX_SIZE 15
14 static gboolean __write_mptcp_parameter(const char* key, const char* value)
19 snprintf(path, sizeof(path), NET_PROC_SYS_NET_MPTCP"%s", key);
21 fd = open(path, O_RDWR);
23 ERR("Fail to open %s", path);
27 DBG("write mptcp parameter. len: %zd, value: %s", strlen(value), value);
28 if (write(fd, value, strlen(value)) < 0) {
29 ERR("Fail to write %s to %s", value, path);
38 static char* __read_mptcp_parameter(const char* key)
43 char buf[NET_PROC_SYS_NET_MPTCP_VALUE_MAX_SIZE];
45 snprintf(path, sizeof(path), NET_PROC_SYS_NET_MPTCP"%s", key);
47 fd = open(path, O_RDWR);
49 ERR("Fail to open %s", path);
53 if ((len = read(fd, buf, NET_PROC_SYS_NET_MPTCP_VALUE_MAX_SIZE)) < 0) {
54 ERR("Fail to read %s", path);
67 DBG("read mptcp parameter. len: %d, value: %s", len, buf);
69 return g_strndup(buf, strlen(buf));
72 gboolean mptcp_supported()
74 return g_file_test(NET_PROC_SYS_NET_MPTCP, G_FILE_TEST_EXISTS);
77 gboolean mptcp_set_enabled(gint enable)
79 const char* sysctlname = "mptcp_enabled";
81 if (enable != 0 && enable != 1 && enable != 2) {
82 ERR("Invalid parameter enable %d", enable);
86 snprintf(buf, 2, "%d", enable);
87 return __write_mptcp_parameter(sysctlname, buf);
90 gint mptcp_get_enabled()
92 const char* sysctlname = "mptcp_enabled";
96 if ((buf = __read_mptcp_parameter(sysctlname)) == NULL) {
97 ERR("Fail to read %s", sysctlname);
107 gboolean mptcp_set_path_manager(const gchar* pm)
109 const char* sysctlname = "mptcp_path_manager";
110 return __write_mptcp_parameter(sysctlname, pm);
113 gchar* mptcp_get_path_manager()
115 const char* sysctlname = "mptcp_path_manager";
116 return __read_mptcp_parameter(sysctlname);
119 gboolean mptcp_mptcp_set_scheduler(const gchar* scheduler)
121 const char* sysctlname = "mptcp_scheduler";
122 return __write_mptcp_parameter(sysctlname, scheduler);
125 gchar* mptcp_get_scheduler()
127 const char* sysctlname = "mptcp_scheduler";
128 return __read_mptcp_parameter(sysctlname);