From 2047b3cfb63cffdad565eeb7b6af5ccf66f6df4c Mon Sep 17 00:00:00 2001 From: "chleun.moon" Date: Mon, 5 Feb 2018 11:07:54 +0900 Subject: [PATCH] Add Multipath TCP Change-Id: I6a8efc9ce14081d89328b19fda0cca8e7e9738c1 Signed-off-by: Cheoleun Moon --- CMakeLists.txt | 4 +- config/security-network-config.conf | 5 +- include/mptcp-internal.h | 32 +++++ include/mptcp.h | 42 ++++++ include/netdbus.h | 3 + interfaces/netconfig-iface-mptcp.xml | 26 ++++ packaging/net-config.spec | 2 +- src/dbus/netdbus.c | 12 ++ src/main.c | 3 + src/mptcp-internal.c | 126 ++++++++++++++++++ src/mptcp.c | 191 +++++++++++++++++++++++++++ 11 files changed, 443 insertions(+), 3 deletions(-) create mode 100755 include/mptcp-internal.h create mode 100755 include/mptcp.h create mode 100755 interfaces/netconfig-iface-mptcp.xml create mode 100644 src/mptcp-internal.c create mode 100755 src/mptcp.c diff --git a/CMakeLists.txt b/CMakeLists.txt index e6a40c7..331c979 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,8 @@ SET(SRCS src/utils/util.c src/vpnsvc.c src/vpnsvc-internal.c + src/mptcp.c + src/mptcp-internal.c src/dbus/netdbus.c src/network-clock.c src/network-state.c @@ -116,7 +118,7 @@ ADD_CUSTOM_COMMAND( --generate-c-code generated-code --c-generate-object-manager --generate-docbook generated-code-docs - ${INTERFACES}/netconfig-iface-network-state.xml ${INTERFACES}/netconfig-iface-network-statistics.xml ${INTERFACES}/netconfig-iface-wifi.xml ${INTERFACES}/netconfig-iface-vpnsvc.xml + ${INTERFACES}/netconfig-iface-network-state.xml ${INTERFACES}/netconfig-iface-network-statistics.xml ${INTERFACES}/netconfig-iface-wifi.xml ${INTERFACES}/netconfig-iface-vpnsvc.xml ${INTERFACES}/netconfig-iface-mptcp.xml COMMENT "Generating GDBus .c/.h") ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS} ${CMAKE_SOURCE_DIR}/generated-code.c) diff --git a/config/security-network-config.conf b/config/security-network-config.conf index 6ac2933..65ec777 100755 --- a/config/security-network-config.conf +++ b/config/security-network-config.conf @@ -1,3 +1,6 @@ z /sys/module/dhd/parameters/firmware_path 0660 root network_fw - z /sys/module/dhd/parameters/nvram_path 0660 root network_fw - -z /sys/devices/platform/sd8x-rfkill/pwr_ctrl 0660 root network_fw - \ No newline at end of file +z /sys/devices/platform/sd8x-rfkill/pwr_ctrl 0660 root network_fw - +z /proc/sys/net/mptcp/mptcp_enabled 0660 root network_fw - +z /proc/sys/net/mptcp/mptcp_path_manager 0660 root network_fw - +z /proc/sys/net/mptcp/mptcp_scheduler 0660 root network_fw - diff --git a/include/mptcp-internal.h b/include/mptcp-internal.h new file mode 100755 index 0000000..1be9209 --- /dev/null +++ b/include/mptcp-internal.h @@ -0,0 +1,32 @@ +/* + * Network Configuration - VPN Service Internal Module + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __NETCONFIG_MPTCP_INTERNAL_H__ +#define __NETCONFIG_MPTCP_INTERNAL_H__ + +gboolean mptcp_supported(); +gboolean mptcp_set_enable(gint enable); +gint mptcp_get_enabled(); +gboolean mptcp_set_path_manager(const gchar* pm); +gchar* mptcp_get_path_manager(); +gboolean mptcp_mptcp_set_scheduler(const gchar* scheduler); +gchar* mptcp_get_scheduler(); + +#endif /* __NETCONFIG_MPTCP_INTERNAL_H__ */ + diff --git a/include/mptcp.h b/include/mptcp.h new file mode 100755 index 0000000..fd1bb9c --- /dev/null +++ b/include/mptcp.h @@ -0,0 +1,42 @@ +/* + * Network Configuration - VPN Service Module + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef __NETCONFIG_MPTCP_H__ +#define __NETCONFIG_MPTCP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#include "generated-code.h" + +void mptcp_object_create_and_init(void); +void mptcp_object_deinit(void); +Mptcp *get_mptcp_object(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_MPTCP_H__ */ + diff --git a/include/netdbus.h b/include/netdbus.h index fe51502..36ec2ce 100755 --- a/include/netdbus.h +++ b/include/netdbus.h @@ -63,6 +63,8 @@ extern "C" { #define NETCONFIG_NETWORK_INTERFACE "net.netconfig.network" #define NETCONFIG_VPNSVC_PATH "/net/netconfig/vpnsvc" #define NETCONFIG_VPNSVC_INTERFACE "net.netconfig.vpnsvc" +#define NETCONFIG_MPTCP_PATH "/net/netconfig/mptcp" +#define NETCONFIG_MPTCP_INTERFACE "net.netconfig.mptcp" #define DBUS_PATH_MAX_BUFLEN 512 #define DBUS_STATE_MAX_BUFLEN 64 @@ -78,6 +80,7 @@ GDBusObjectManagerServer *netdbus_get_wifi_manager(void); GDBusObjectManagerServer *netdbus_get_state_manager(void); GDBusObjectManagerServer *netdbus_get_statistics_manager(void); GDBusObjectManagerServer *netdbus_get_vpn_manager(void); +GDBusObjectManagerServer *netdbus_get_mptcp_manager(void); GDBusConnection *netdbus_get_connection(void); GCancellable *netdbus_get_cancellable(void); diff --git a/interfaces/netconfig-iface-mptcp.xml b/interfaces/netconfig-iface-mptcp.xml new file mode 100755 index 0000000..e010c18 --- /dev/null +++ b/interfaces/netconfig-iface-mptcp.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packaging/net-config.spec b/packaging/net-config.spec index 3b8cfff..9c62717 100755 --- a/packaging/net-config.spec +++ b/packaging/net-config.spec @@ -1,6 +1,6 @@ Name: net-config Summary: TIZEN Network Configuration service -Version: 1.1.123 +Version: 1.1.124 Release: 2 Group: System/Network License: Apache-2.0 diff --git a/src/dbus/netdbus.c b/src/dbus/netdbus.c index c982aea..7c25df8 100755 --- a/src/dbus/netdbus.c +++ b/src/dbus/netdbus.c @@ -42,6 +42,7 @@ static GDBusObjectManagerServer *manager_server_wifi = NULL; static GDBusObjectManagerServer *manager_server_state = NULL; static GDBusObjectManagerServer *manager_server_statistics = NULL; static GDBusObjectManagerServer *manager_server_vpn = NULL; +static GDBusObjectManagerServer *manager_server_mptcp = NULL; static guint owner_id = 0; static got_name_cb g_callback = NULL; @@ -73,6 +74,11 @@ GDBusObjectManagerServer *netdbus_get_vpn_manager(void) return manager_server_vpn; } +GDBusObjectManagerServer *netdbus_get_mptcp_manager(void) +{ + return manager_server_mptcp; +} + GDBusConnection *netdbus_get_connection(void) { return gconn_data.connection; @@ -330,6 +336,12 @@ int setup_gdbus(got_name_cb cb) exit(1); } + manager_server_mptcp = g_dbus_object_manager_server_new(NETCONFIG_MPTCP_PATH); + if (manager_server_mptcp == NULL) { + ERR("Manager server for MPTCP_PATH not created."); + exit(1); + } + owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM, NETCONFIG_SERVICE, G_BUS_NAME_OWNER_FLAGS_NONE, _got_bus_cb, _got_name_cb, _lost_name_cb, diff --git a/src/main.c b/src/main.c index 9b6db87..107c9d0 100755 --- a/src/main.c +++ b/src/main.c @@ -32,6 +32,7 @@ #include "wifi-agent.h" #include "wifi-power.h" #include "vpnsvc.h" +#include "mptcp.h" #include "network-clock.h" #include "network-dpm.h" #include "network-state.h" @@ -58,6 +59,7 @@ void _got_name_cb(void) state_object_create_and_init(); statistics_object_create_and_init(); vpnsvc_create_and_init(); + mptcp_object_create_and_init(); register_gdbus_signal(); connman_register_agent(); @@ -73,6 +75,7 @@ static void _objects_deinit(void) state_object_deinit(); statistics_object_deinit(); vpnsvc_destroy_deinit(); + mptcp_object_deinit(); } int main(int argc, char *argv[]) diff --git a/src/mptcp-internal.c b/src/mptcp-internal.c new file mode 100644 index 0000000..7b3b6e5 --- /dev/null +++ b/src/mptcp-internal.c @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "mptcp-internal.h" +#include "log.h" + +#define NET_PROC_SYS_NET_MPTCP "/proc/sys/net/mptcp/" +#define NET_PROC_SYS_NET_MPTCP_VALUE_MAX_SIZE 15 + +static gboolean __write_mptcp_parameter(const char* key, const char* value) +{ + char path[50]; + int fd = -1; + + snprintf(path, sizeof(path), NET_PROC_SYS_NET_MPTCP"%s", key); + + fd = open(path, O_RDWR); + if (fd < 0) { + ERR("Fail to open %s", path); + return FALSE; + } + + DBG("write mptcp parameter. len: %d, value: %s", strlen(value), value); + if (write(fd, value, strlen(value)) < 0) { + ERR("Fail to write %s to %s", value, path); + close(fd); + return FALSE; + } + + close(fd); + return TRUE; +} + +static char* __read_mptcp_parameter(const char* key) +{ + char path[50]; + int fd = -1; + int len = -1; + char buf[NET_PROC_SYS_NET_MPTCP_VALUE_MAX_SIZE]; + + snprintf(path, sizeof(path), NET_PROC_SYS_NET_MPTCP"%s", key); + + fd = open(path, O_RDWR); + if (fd < 0) { + ERR("Fail to open %s", path); + return NULL; + } + + if ((len = read(fd, buf, NET_PROC_SYS_NET_MPTCP_VALUE_MAX_SIZE)) < 0) { + ERR("Fail to read %s", path); + close(fd); + return NULL; + } + + if (len < 1) { + ERR("Fail to read"); + close(fd); + return NULL; + } + + buf[len - 1] = '\0'; + + DBG("read mptcp parameter. len: %d, value: %s", len, buf); + close(fd); + return g_strndup(buf, strlen(buf)); +} + +gboolean mptcp_supported() +{ + return g_file_test(NET_PROC_SYS_NET_MPTCP, G_FILE_TEST_EXISTS); +} + +gboolean mptcp_set_enable(gint enable) +{ + const char* sysctlname = "mptcp_enabled"; + char buf[2]; + if (enable != 0 && enable != 1 && enable != 2) { + ERR("Invalid parameter enable %d", enable); + return FALSE; + } + + snprintf(buf, 2, "%d", enable); + return __write_mptcp_parameter(sysctlname, buf); +} + +gint mptcp_get_enabled() +{ + const char* sysctlname = "mptcp_enabled"; + char* buf; + if ((buf = __read_mptcp_parameter(sysctlname)) == NULL) { + ERR("Fail to read %s, sysctlname"); + return -1; + } + + return atoi(buf); +} + +gboolean mptcp_set_path_manager(const gchar* pm) +{ + const char* sysctlname = "mptcp_path_manager"; + return __write_mptcp_parameter(sysctlname, pm); +} + +gchar* mptcp_get_path_manager() +{ + const char* sysctlname = "mptcp_path_manager"; + return __read_mptcp_parameter(sysctlname); +} + +gboolean mptcp_mptcp_set_scheduler(const gchar* scheduler) +{ + const char* sysctlname = "mptcp_scheduler"; + return __write_mptcp_parameter(sysctlname, scheduler); +} + +gchar* mptcp_get_scheduler() +{ + const char* sysctlname = "mptcp_scheduler"; + return __read_mptcp_parameter(sysctlname); +} + diff --git a/src/mptcp.c b/src/mptcp.c new file mode 100755 index 0000000..25c679d --- /dev/null +++ b/src/mptcp.c @@ -0,0 +1,191 @@ +/* + * Network Configuration - VPN Service Module + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include + +#include "mptcp.h" +#include "mptcp-internal.h" +#include "netdbus.h" +#include "log.h" + +static Mptcp *mptcp_object = NULL; + +Mptcp *get_mptcp_object(void) +{ + return mptcp_object; +} + +/********************* + * Handler Functions * + ********************/ +gboolean handle_mptcp_supported(Mptcp *object, GDBusMethodInvocation *invocation) +{ + DBG("handle_mptcp_supported"); + gboolean value; + + value = mptcp_supported(); + + mptcp_complete_mptcp_supported(object, invocation, value); + return TRUE; +} + +gboolean handle_mptcp_set_enable(Mptcp *object, GDBusMethodInvocation *invocation, gint enable) +{ + DBG("handle_mptcp_set_enable"); + + if (mptcp_set_enable(enable) == FALSE) { + ERR("Fail to set mptcp_enabled[%d]", enable); + return FALSE; + } + + mptcp_complete_mptcp_set_enable(object, invocation); + return TRUE; +} + +gboolean handle_mptcp_get_enabled(Mptcp *object, GDBusMethodInvocation *invocation) +{ + DBG("handle_mptcp_get_enabled"); + gint value; + + value = mptcp_get_enabled(); + if (value != 0 && value != 1 && value != 2) { + ERR("Invalid value of mptcp_enabled[%d]", value); + return FALSE; + } + + mptcp_complete_mptcp_get_enabled(object, invocation, value); + return TRUE; +} + +gboolean handle_mptcp_set_path_manager(Mptcp *object, GDBusMethodInvocation *invocation, const gchar *pm) +{ + DBG("handle_mptcp_set_path_manager %s", pm); + + if (mptcp_set_path_manager(pm) == FALSE) { + ERR("Fail to set mptcp_path_manager[%d]", pm); + return FALSE; + } + + mptcp_complete_mptcp_set_path_manager(object, invocation); + return TRUE; +} + +gboolean handle_mptcp_get_path_manager(Mptcp *object, GDBusMethodInvocation *invocation) +{ + DBG("handle_mptcp_get_path_manager"); + gchar* pm; + + pm = mptcp_get_path_manager(); + if (pm == NULL) { + ERR("Fail to get mptcp_path_manager"); + return FALSE; + } + + DBG("get path manager %s", pm); + mptcp_complete_mptcp_get_path_manager(object, invocation, pm); + g_free(pm); + + return TRUE; +} + +gboolean handle_mptcp_set_scheduler(Mptcp *object, GDBusMethodInvocation *invocation, const gchar *scheduler) +{ + DBG("handle_mptcp_set_scheduler"); + + if (mptcp_mptcp_set_scheduler(scheduler) == FALSE) { + ERR("Fail to set mptcp_scheduler[%s]", scheduler); + return FALSE; + } + + mptcp_complete_mptcp_set_scheduler(object, invocation); + return TRUE; +} + +gboolean handle_mptcp_get_scheduler(Mptcp *object, GDBusMethodInvocation *invocation) +{ + DBG("handle_mptcp_get_scheduler"); + gchar* scheduler; + + scheduler = mptcp_get_scheduler(); + if (scheduler == NULL) { + ERR("Fail to get mptcp_scheduler"); + return FALSE; + } + + DBG("get scheduler %s", scheduler); + mptcp_complete_mptcp_get_scheduler(object, invocation, scheduler); + g_free(scheduler); + + return TRUE; +} + + +/***************************** + * Initializations Functions * + ****************************/ +void mptcp_object_create_and_init(void) +{ + DBG("Create mptcp object."); + GDBusInterfaceSkeleton *interface_mptcp = NULL; + GDBusConnection *connection = NULL; + GDBusObjectManagerServer *server = netdbus_get_mptcp_manager(); + if (server == NULL) + return; + + connection = netdbus_get_connection(); + g_dbus_object_manager_server_set_connection(server, connection); + + /* Interface */ + mptcp_object = mptcp_skeleton_new(); + interface_mptcp = G_DBUS_INTERFACE_SKELETON(mptcp_object); + + /* VPN Service */ + g_signal_connect(mptcp_object, "handle-mptcp-supported", + G_CALLBACK(handle_mptcp_supported), NULL); + g_signal_connect(mptcp_object, "handle-mptcp-set-enable", + G_CALLBACK(handle_mptcp_set_enable), NULL); + g_signal_connect(mptcp_object, "handle-mptcp-get-enabled", + G_CALLBACK(handle_mptcp_get_enabled), NULL); + g_signal_connect(mptcp_object, "handle-mptcp-set-path-manager", + G_CALLBACK(handle_mptcp_set_path_manager), NULL); + g_signal_connect(mptcp_object, "handle-mptcp-get-path-manager", + G_CALLBACK(handle_mptcp_get_path_manager), NULL); + g_signal_connect(mptcp_object, "handle-mptcp-set-scheduler", + G_CALLBACK(handle_mptcp_set_scheduler), NULL); + g_signal_connect(mptcp_object, "handle-mptcp-get-scheduler", + G_CALLBACK(handle_mptcp_get_scheduler), NULL); + + if (!g_dbus_interface_skeleton_export(interface_mptcp, connection, + NETCONFIG_MPTCP_PATH, NULL)) { + ERR("Export NETCONFIG_MPTCP_PATH for mptcp failed"); + } + + return; +} + +void mptcp_object_deinit(void) +{ + DBG("Deinit mptcp object."); + + g_object_unref(mptcp_object); +} + -- 2.34.1