#include "capi_vpn_service_private.h"
-int vpn_daemon_init(const char* tun_name, size_t tun_name_len, int fd, vpnsvc_tun_s *handle_s);
+int vpn_daemon_init(const char* if_name, size_t if_name_len, int fd, vpnsvc_tun_s *handle_s);
int vpn_daemon_deinit(const char* dev_name);
int vpn_daemon_protect(int socket, const char* dev_name);
-int vpn_daemon_up(int tun_index, const char* local_ip, const char* remote_ip,
+int vpn_daemon_up(int if_index, const char* local_ip, const char* remote_ip,
const char* routes[], int prefix[], size_t nr_routes,
char** dns_servers, size_t nr_dns, size_t total_dns_string_cnt,
const char* dns_suffix, const unsigned int mtu);
-int vpn_daemon_down(int tun_index);
+int vpn_daemon_down(int if_index);
int vpn_daemon_block_networks(const char* nets_vpn[], int prefix_vpn[], size_t nr_nets_vpn,
const char* nets_orig[], int prefix_orig[], size_t nr_nets_orig);
int vpn_daemon_unblock_networks(void);
<node name='/org/tizen/vpnsvc'>
<interface name='org.tizen.vpnsvc'>
<method name='vpn_init'>
- <arg type='s' name='tun_name' direction='in'/>
- <arg type='u' name='tun_name_len' direction='in'/>
+ <arg type='s' name='if_name' direction='in'/>
+ <arg type='u' name='if_name_len' direction='in'/>
<arg type='i' name='result' direction='out'/>
<arg type='i' name='h_index' direction='out'/>
<arg type='s' name='h_name' direction='out'/>
<arg type='i' name='result' direction='out'/>
</method>
<method name='vpn_up'>
- <arg type='i' name='tun_index' direction='in'/>
+ <arg type='i' name='if_index' direction='in'/>
<arg type='s' name='local_ip' direction='in'/>
<arg type='s' name='remote_ip' direction='in'/>
<arg type='v' name='routes' direction='in'/>
<arg type='i' name='result' direction='out'/>
</method>
<method name='vpn_down'>
- <arg type='i' name='tun_index' direction='in'/>
+ <arg type='i' name='if_index' direction='in'/>
<arg type='i' name='result' direction='out'/>
</method>
<method name='vpn_block_networks'>
iptables_rule('D', addr, mask);
}
-static int get_interface_index(const char *tun_name)
+static int get_interface_index(const char *if_name)
{
struct ifreq ifr;
int sk = 0;
- LOGD("enter get_interface_index, tun_name : %s", tun_name);
+ LOGD("enter get_interface_index, if_name : %s", if_name);
sk = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (sk < 0) {
memset(&ifr, 0, sizeof(ifr));
- if (*tun_name)
- strncpy(ifr.ifr_name, tun_name, strlen(tun_name));
+ if (*if_name)
+ strncpy(ifr.ifr_name, if_name, strlen(if_name));
/* get an interface name by ifindex */
if (ioctl(sk, SIOCGIFINDEX, &ifr) < 0) {
}
-int vpn_daemon_init(const char* tun_name, size_t tun_name_len, int fd, vpnsvc_tun_s *handle_s)
+int vpn_daemon_init(const char* if_name, size_t if_name_len, int fd, vpnsvc_tun_s *handle_s)
{
struct ifreq ifr;
size_t len = 0;
- LOGD("enter vpn_daemon_init, tun_name : %s, tun_name_len : %d, fd : %d\n", tun_name, tun_name_len, fd);
+ LOGD("enter vpn_daemon_init, if_name : %s, if_name_len : %d, fd : %d\n", if_name, if_name_len, fd);
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;
- if (*tun_name)
- strncpy(ifr.ifr_name, tun_name, tun_name_len);
+ if (*if_name)
+ strncpy(ifr.ifr_name, if_name, if_name_len);
LOGD("before init, ifindex : %d", ifr.ifr_ifindex);
}
handle_s->fd = 0; /* server fd does not meaning */
- handle_s->index = get_interface_index(tun_name);
+ handle_s->index = get_interface_index(if_name);
len = strlen(ifr.ifr_name);
strncpy(handle_s->name, ifr.ifr_name, len);
handle_s->name[len] = '\0';
return ret;
}
-int vpn_daemon_up(int tun_index, const char* local_ip, const char* remote_ip,
+int vpn_daemon_up(int if_index, const char* local_ip, const char* remote_ip,
const char* routes[], int prefix[], size_t nr_routes,
char** dns_servers, size_t nr_dns, size_t total_dns_string_cnt,
const char* dns_suffix, const unsigned int mtu) {
LOGD("enter vpn_daemon_up");
- LOGD("tun_index : %d", tun_index);
+ LOGD("if_index : %d", if_index);
LOGD("local ip : %s", local_ip);
LOGD("remote ip : %s", remote_ip);
LOGD("route pointer : %p, nr_routes : %d, dns_server pointer : %p, nr_dns : %d, dns_suffix : %s, mtu : %d", routes, nr_routes, dns_servers, nr_dns, dns_suffix, mtu);
}
memset(&ifr_tun, 0, sizeof(ifr_tun));
- ifr_tun.ifr_ifindex = tun_index;
+ ifr_tun.ifr_ifindex = if_index;
/* get an interface name by ifindex */
if (ioctl(sk, SIOCGIFNAME, &ifr_tun) < 0) {
return ret;
}
-int vpn_daemon_down(int tun_index)
+int vpn_daemon_down(int if_index)
{
struct ifreq ifr, addr_ifr;
struct sockaddr_in *addr = NULL;
}
memset(&ifr, 0, sizeof(ifr));
- ifr.ifr_ifindex = tun_index;
+ ifr.ifr_ifindex = if_index;
if (ioctl(sk, SIOCGIFNAME, &ifr) < 0) {
LOGE("ioctl SIOCGIFNAME failed : %s", strerror(errno));
********************/
gboolean handle_vpn_init(Vpnsvc *object,
GDBusMethodInvocation *invocation,
- const gchar *arg_tun_name,
- guint arg_tun_name_len)
+ const gchar *arg_if_name,
+ guint arg_if_name_len)
{
LOGD("handle_vpn_init");
int fd_list_length;
const int *fds;
- LOGD("vpn_init, %s, %u\n", arg_tun_name, arg_tun_name_len);
+ LOGD("vpn_init, %s, %u\n", arg_if_name, arg_if_name_len);
msg = g_dbus_method_invocation_get_message(invocation);
fd_list = g_dbus_message_get_unix_fd_list(msg);
LOGD("fd:%d\n", *fds);
- result = vpn_daemon_init(arg_tun_name, arg_tun_name_len, *fds, &handle_s);
+ result = vpn_daemon_init(arg_if_name, arg_if_name_len, *fds, &handle_s);
LOGD("handle_s.fd : %d, handle_s.index : %d, handle_s.name : %s",
handle_s.fd, handle_s.index, handle_s.name);
gboolean handle_vpn_up(Vpnsvc *object,
GDBusMethodInvocation *invocation,
- gint arg_tun_index,
+ gint arg_if_index,
const gchar *arg_local_ip,
const gchar *arg_remote_ip,
GVariant *arg_routes,
gchar* route_dest;
gint route_prefix;
- LOGD("tun_index : %d", arg_tun_index);
+ LOGD("if_index : %d", arg_if_index);
LOGD("local ip : %s", arg_local_ip);
LOGD("remote ip : %s", arg_remote_ip);
LOGD("dns_suffix : %s", arg_dns_suffix);
}
}
- result = vpn_daemon_up(arg_tun_index, arg_local_ip, arg_remote_ip,
+ result = vpn_daemon_up(arg_if_index, arg_local_ip, arg_remote_ip,
routes, prefix, arg_nr_routes, dns_servers, arg_nr_dns,
total_dns_string_cnt, arg_dns_suffix, arg_mtu);
done:
gboolean handle_vpn_down(Vpnsvc *object,
GDBusMethodInvocation *invocation,
- gint arg_tun_index)
+ gint arg_if_index)
{
LOGD("handle_vpn_down");
int result = VPNSVC_ERROR_NONE;
- LOGD("vpn_down, %d\n", arg_tun_index);
+ LOGD("vpn_down, %d\n", arg_if_index);
- result = vpn_daemon_down(arg_tun_index);
+ result = vpn_daemon_down(arg_if_index);
vpnsvc_complete_vpn_down(object, invocation, result);
* 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 __TIZEN_NETWORK_VPN_DOC_H__
#define __TIZEN_NETWORK_VPN_DOC_H__
-/**
- * @defgroup CAPI_NETWORK_VPN_MODULE VPN
- * @brief The Virtual Private Network (VPN) API provides functions for managing VPN.
- * @ingroup CAPI_NETWORK_FRAMEWORK
- *
- * @section CAPI_NETWORK_VPN_MODULE_HEADER Required Header
- * \#include <vpn_service.h>
- *
- * @section CAPI_NETWORK_VPN_MODULE_OVERVIEW Overview
- * VPN allows your application to manage VPN features.
- * The VPN Service enables your application to init and deinit a VPN device(TUN(namely netowrk TUNel) interface),
- * Routing management, DNS management and Firewall management.
- */
/**
* @defgroup CAPI_NETWORK_VPN_SERVICE_MODULE VPN Service
- * @brief The VPN API provides functions for managing VPN.
- * @ingroup CAPI_NETWORK_VPN_MODULE
+ * @brief The Virtual Private Network (VPN) API provides functions for managing VPN.
+ * @ingroup CAPI_NETWORK_FRAMEWORK
*
* @section CAPI_NETWORK_VPN_SERVICE_MODULE_HEADER Required Header
* \#include <vpn_service.h>
*
* @section CAPI_NETWORK_VPN_SERVICE_MODULE_OVERVEW Overview
* The VPN Service functions for managing VPN.
+ * There can be only one VPN connection running at the same time. The existing interface is deactivated when a new one is created.
* Using the VPN Service, you can implement features that allow the users of your application to:
* - Initialize / Deinitialize the VPN device
* - Routing management
INSTALL(TARGETS ${PACKAGE_NAME} DESTINATION lib)
INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/vpn_service.h DESTINATION include)
-INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/tizen_vpn_error.h DESTINATION include)
SET_TARGET_PROPERTIES(${PACKAGE_NAME}
PROPERTIES
#include <gio/gio.h>
#include "vpn_service.h"
+#include "vpn_service_internal.h"
#ifdef __cplusplus
extern "C" {
GDBusConnection *connection; /**< D-Bus Connection */
int fd; /**< tun socket fd */
int index; /**< tun index (if.if_index) */
- char name[VPNSVC_TUN_IF_NAME_LEN]; /**< tun name (if.if_name) */
+ char name[VPNSVC_VPN_IF_NAME_LEN]; /**< tun name (if.if_name) */
char session[VPNSVC_SESSION_STRING_LEN];/**< session name (user setting) */
unsigned int mtu; /**< mtu (user setting) */
} vpnsvc_tun_s;
#include <system_info.h>
#include <gio/gunixfdlist.h>
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "CAPI_VPNSVC"
+
#define DBUS_REPLY_TIMEOUT (120 * 1000)
GVariant *op = NULL;
s->fd = 0;
s->index = 0;
- memset(s->name, 0, VPNSVC_TUN_IF_NAME_LEN);
+ memset(s->name, 0, VPNSVC_VPN_IF_NAME_LEN);
memset(s->session, 0, VPNSVC_SESSION_STRING_LEN);
if (s)
return reply;
}
-int vpnsvc_init(const char* tun_name, vpnsvc_tun_h *handle)
+EXPORT_API int vpnsvc_init(const char* if_name, vpnsvc_h *handle)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
int result = VPNSVC_ERROR_NONE;
int dbus_result;
- int tun_fd = 0;
+ int if_fd = 0;
- LOGD("enter vpnsvc_init, tun_name : %s", tun_name);
+ LOGD("enter vpnsvc_init, if_name : %s", if_name);
LOGD("handle : %p\n", handle);
/* parameter check */
- if (tun_name == NULL || strlen(tun_name) <= 0) {
- LOGE("tun_name is a NULL");
+ if (if_name == NULL || strlen(if_name) <= 0) {
+ LOGE("if_name is a NULL");
return VPNSVC_ERROR_INVALID_PARAMETER;
} else if (handle == NULL) {
LOGE("handle is a NULL");
op = NULL;
}
- if ((tun_fd = open("/dev/net/tun", O_RDWR)) < 0) {
+ if ((if_fd = open("/dev/net/tun", O_RDWR)) < 0) {
LOGE("tun device open fail\n");
_vpnsvc_deinit_vpnsvc_tun_s(tmp_s);
return VPNSVC_ERROR_IO_ERROR;
}
- LOGD("client tun_fd : %d", tun_fd);
+ LOGD("client if_fd : %d", if_fd);
op = _vpnsvc_invoke_dbus_method_with_fd(tmp_s->connection,
VPNSVC_DBUS_SERVICE_NAME,
VPNSVC_DBUS_INTERFACE_OBJ_NAME,
VPNSVC_DBUS_INTERFACE_NAME,
"vpn_init",
- g_variant_new("(su)", tun_name, strlen(tun_name)),
- tun_fd,
+ g_variant_new("(su)", if_name, strlen(if_name)),
+ if_fd,
&dbus_result);
if (op == NULL) {
- close(tun_fd);
+ close(if_fd);
_vpnsvc_deinit_vpnsvc_tun_s(tmp_s);
return VPNSVC_ERROR_IPC_FAILED;
} else {
result = VPNSVC_ERROR_IPC_FAILED;
} else {
LOGD("vpnsvc_init() succeed");
- tmp_s->fd = tun_fd; /* client fd must be set */
+ tmp_s->fd = if_fd; /* client fd must be set */
tmp_s->index = tmp_index;
- strncpy(tmp_s->name, tmp_name, VPNSVC_TUN_IF_NAME_LEN);
- tmp_s->name[VPNSVC_TUN_IF_NAME_LEN-1] = '\0';
+ strncpy(tmp_s->name, tmp_name, VPNSVC_VPN_IF_NAME_LEN);
+ tmp_s->name[VPNSVC_VPN_IF_NAME_LEN-1] = '\0';
*handle = tmp_s;
LOGD("handle : %p, handle->fd : %d, handle->index : %d, handle->name : %s",
(*handle), ((vpnsvc_tun_s*)*handle)->fd, ((vpnsvc_tun_s*)*handle)->index, ((vpnsvc_tun_s*)*handle)->name);
return result;
}
-int vpnsvc_deinit(vpnsvc_tun_h handle)
+EXPORT_API int vpnsvc_deinit(vpnsvc_h handle)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
}
tun_s = (vpnsvc_tun_s*)handle;
- LOGD("enter vpnsvc_deinit, tun_fd : %d", tun_s->fd);
+ LOGD("enter vpnsvc_deinit, if_fd : %d", tun_s->fd);
if (tun_s->fd > 0) {
op = _vpnsvc_invoke_dbus_method(tun_s->connection,
return result;
}
-int vpnsvc_protect(vpnsvc_tun_h handle, int socket_fd, const char* dev_name)
+EXPORT_API int vpnsvc_protect(vpnsvc_h handle, int socket_fd, const char* dev_name)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
return result;
}
-int vpnsvc_up(vpnsvc_tun_h handle, const char* local_ip, const char* remote_ip,
+EXPORT_API int vpnsvc_up(vpnsvc_h handle, const char* local_ip, const char* remote_ip,
const char* dest[], int prefix[], size_t nr_routes,
const char** dns_servers, size_t nr_dns_servers,
const char* dns_suffix)
return VPNSVC_ERROR_INVALID_PARAMETER;
}
- LOGD("tun_index %d", tun_s->index);
+ LOGD("if_index %d", tun_s->index);
LOGD("local_ip : %s, remote_ip : %s", local_ip, remote_ip);
/* make a route parameter */
return result;
}
-int vpnsvc_down(vpnsvc_tun_h handle)
+EXPORT_API int vpnsvc_down(vpnsvc_h handle)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
}
/* this API must not be use IPC */
-int vpnsvc_read(vpnsvc_tun_h handle, int timeout_ms)
+EXPORT_API int vpnsvc_read(vpnsvc_h handle, int timeout_ms)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
}
/* this API must not be use IPC */
-int vpnsvc_write(vpnsvc_tun_h handle, const char* data, size_t size)
+EXPORT_API int vpnsvc_write(vpnsvc_h handle, const char* data, size_t size)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
}
-int vpnsvc_block_networks(vpnsvc_tun_h handle,
+EXPORT_API int vpnsvc_block_networks(vpnsvc_h handle,
const char* dest_vpn[],
int prefix_vpn[],
size_t nr_allow_routes_vpn,
return result;
}
-int vpnsvc_unblock_networks(vpnsvc_tun_h handle)
+EXPORT_API int vpnsvc_unblock_networks(vpnsvc_h handle)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
return result;
}
-int vpnsvc_get_tun_fd(vpnsvc_tun_h handle, int* tun_fd)
+EXPORT_API int vpnsvc_get_if_fd(vpnsvc_h handle, int* if_fd)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
vpnsvc_tun_s *tun_s = NULL;
/* parameter check */
- if (handle == NULL || tun_fd == NULL) {
+ if (handle == NULL || if_fd == NULL) {
LOGE("Invalid parameter");
return VPNSVC_ERROR_INVALID_PARAMETER;
}
return VPNSVC_ERROR_INVALID_PARAMETER;
}
- *tun_fd = (int)(tun_s->fd);
+ *if_fd = (int)(tun_s->fd);
return VPNSVC_ERROR_NONE;
}
-int vpnsvc_get_tun_index(vpnsvc_tun_h handle, int* tun_index)
+EXPORT_API int vpnsvc_get_if_index(vpnsvc_h handle, int* if_index)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
vpnsvc_tun_s *tun_s = NULL;
/* parameter check */
- if (handle == NULL || tun_index == NULL) {
+ if (handle == NULL || if_index == NULL) {
LOGE("Invalid parameter");
return VPNSVC_ERROR_INVALID_PARAMETER;
}
return VPNSVC_ERROR_INVALID_PARAMETER;
}
- *tun_index = (int)(tun_s->index);
+ *if_index = (int)(tun_s->index);
return VPNSVC_ERROR_NONE;
}
-int vpnsvc_get_tun_name(vpnsvc_tun_h handle, char** tun_name)
+EXPORT_API int vpnsvc_get_if_name(vpnsvc_h handle, char** if_name)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
vpnsvc_tun_s *tun_s = NULL;
- char la_tun_name[VPNSVC_TUN_IF_NAME_LEN + 1] = { 0, };
+ char la_if_name[VPNSVC_VPN_IF_NAME_LEN + 1] = { 0, };
/* parameter check */
if (handle == NULL) {
return VPNSVC_ERROR_INVALID_PARAMETER;
}
- if (tun_name == NULL) {
+ if (if_name == NULL) {
LOGE("tun name string is NULL");
return VPNSVC_ERROR_INVALID_PARAMETER;
}
- g_strlcpy(la_tun_name, tun_s->name, VPNSVC_TUN_IF_NAME_LEN + 1);
- *tun_name = g_strdup(la_tun_name);
+ g_strlcpy(la_if_name, tun_s->name, VPNSVC_VPN_IF_NAME_LEN + 1);
+ *if_name = g_strdup(la_if_name);
return VPNSVC_ERROR_NONE;
}
-int vpnsvc_set_mtu(vpnsvc_tun_h handle, int mtu)
+EXPORT_API int vpnsvc_set_mtu(vpnsvc_h handle, int mtu)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
return VPNSVC_ERROR_NONE;
}
-int vpnsvc_set_blocking(vpnsvc_tun_h handle, bool blocking)
+EXPORT_API int vpnsvc_set_blocking(vpnsvc_h handle, bool blocking)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
return VPNSVC_ERROR_NONE;
}
-int vpnsvc_set_session(vpnsvc_tun_h handle, const char* session)
+EXPORT_API int vpnsvc_set_session(vpnsvc_h handle, const char* session)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
return VPNSVC_ERROR_NONE;
}
-int vpnsvc_get_session(vpnsvc_tun_h handle, char** session)
+EXPORT_API int vpnsvc_get_session(vpnsvc_h handle, char** session)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
+++ /dev/null
-/*
- * Copyright (c) 2011 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 __TIZEN_COMMON_VPN_ERROR_H__
-#define __TIZEN_COMMON_VPN_ERROR_H__
-
-#include <errno.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @defgroup CAPI_COMMON_VPN_ERROR Common VPN Error
- * @brief This file provides error codes that are common for the whole TIZEN VPN API.
- * @section CAPI_COMMON_VPN_ERROR_HEADER Required Header
- * \#include <tizen_vpn_error.h>
- * @ingroup CAPI_COMMON_ERROR
- * @{
- */
-
-#define TIZEN_ERROR_MIN_VPN_ERROR (-268435456) /* = -268435455(0x0FFFFFFF) -1 */
-
-/* Check if slp error or not */
-#define TIZEN_ERROR_IS_VPN_ERROR(x) (TIZEN_ERROR_MIN_VPN_ERROR >= (x) && (x) < 0)
-
-/* Tizen VPN Service Error */
-#define TIZEN_ERROR_VPNSVC -0x10000000
-
-/**
- * @}
- */
-#ifdef __cplusplus
-}
-#endif
-
-#endif /**<__TIZEN_COMMON_VPN_ERROR_H__ */
#ifndef __TIZEN_VPN_SERVICE_H__
#define __TIZEN_VPN_SERVICE_H__
-/**
- * @file vpn_service.h
- */
-
-/**
- *@defgroup VPNSVC_FRAMEWORK VPN_SERVICE
- *@brief The VPN service APIs to manage VPN features such as VPN device (TUN interface) initialization, routing management, DNS management and firewall management.
- *@section VPNSVC_FRAMEWORK_OVERVIEW Overview
- * <table>
- * <tr><th>API</th><th>Description></th></tr>
- * <tr><td> @ref VPNSVC_FRAMEWORK</td>
- * <td> Provides functions to vpnsvc_init/vpnsvc_deinit/vpnsvc_protect/vpnsvc_up/vpnsvc_down/vpnsvc_read/vpnsvc_write/vpnsvc_block_networks/vpnsvc_unblock_networks.</td>
- * </tr></table>
- **/
-
-/**
- * @addtogroup CAPI_NETWORK_VPN_MODULE
- * @{
- */
-
#include <tizen.h>
-#include <tizen_vpn_error.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "CAPI_VPNSVC"
+/**
+ * @file vpn_service.h
+ */
-#ifndef API
-#define API __attribute__ ((visibility("default")))
-#endif
+/**
+ * @addtogroup CAPI_NETWORK_VPN_SERVICE_MODULE
+ * @{
+ */
/**
* @brief IPv4 address string length (includes end null character).
#define VPNSVC_IP4_STRING_LEN 16
/**
- * @brief TUN interface name length.
+ * @brief VPN interface name length.
* @since_tizen 3.0
*/
-#define VPNSVC_TUN_IF_NAME_LEN 16
+#define VPNSVC_VPN_IF_NAME_LEN 16
/**
* @brief Session name string length (includes end null character).
*/
#define VPNSVC_SESSION_STRING_LEN 32
-#ifndef TIZEN_ERROR_VPNSVC
-#define TIZEN_ERROR_VPNSVC -0x03200000
-#endif
-
/**
* @brief Enumeration for VPN service error types.
* @details Indicate formats of error type field
/**
- * @brief The VPN tun interface handle.
+ * @brief The VPN interface handle.
* @details This handle can be obtained by calling vpnsvc_init() and destroyed by calling vpnsvc_deinit().
* @since_tizen 3.0
* @see vpnsvc_init()
* @see vpnsvc_deinit()
*/
-typedef void* vpnsvc_tun_h;
+typedef void* vpnsvc_h;
/**
- * @brief Initializes TUN interface.
- * @detail You should call vpnsvc_get_tun_name() for checking the actual initialized TUN interface name. (In case of duplicated interface name)
+ * @brief Initializes VPN interface.
+ * @detail You should call vpnsvc_get_if_name() for checking the actual initialized VPN interface name. (In case of duplicated interface name)
* @since_tizen 3.0
* @privlevel public
- * @privilege %http://tizen.org/privilege/vpnservice
+ * @privilege %http://tizen.org/privilege/vpnservice \n
+ * %http://tizen.org/privilege/internet
* @remarks The @a handle should be released using vpnsvc_deinit().
- * @param[in] tun_name The interface name
- * @param[out] handle The VPN tun interface handle
+ * @param[in] if_name The VPN interface name
+ * @param[out] handle The VPN interface handle
* @return 0 on success. otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #VPNSVC_ERROR_IPC_FAILED Cannot connect to service daemon
* @retval #VPNSVC_ERROR_PERMISSION_DENIED Permission Denied
* @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
- * @post Please call vpnsvc_deinit() if you want to de-initialize VPN tun interface.
- * @post Please call vpnsvc_get_tun_fd() if you want to know the fd of tun interface.
- * @post Please call vpnsvc_get_tun_index() if you want to know the fd of tun interface index.
- * @post Please call vpnsvc_get_tun_name() if you want to know the name of tun interface.
+ * @post Please call vpnsvc_deinit() if you want to de-initialize VPN interface.
+ * @post Please call vpnsvc_get_if_fd() if you want to know the fd of VPN interface.
+ * @post Please call vpnsvc_get_if_index() if you want to know the fd of VPN interface index.
+ * @post Please call vpnsvc_get_if_name() if you want to know the name of VPN interface.
* @see vpnsvc_deinit()
- * @see vpnsvc_get_tun_fd()
- * @see vpnsvc_get_tun_index()
- * @see vpnsvc_get_tun_name()
+ * @see vpnsvc_get_if_fd()
+ * @see vpnsvc_get_if_index()
+ * @see vpnsvc_get_if_name()
*/
-API int vpnsvc_init(const char* tun_name, vpnsvc_tun_h *handle);
+int vpnsvc_init(const char* if_name, vpnsvc_h *handle);
/**
- * @brief De-Initializes TUN interface.
+ * @brief De-Initializes VPN interface.
* @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
+ * @param[in] handle The VPN interface handle
* @return 0 on success. otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #VPNSVC_ERROR_IPC_FAILED Cannot connect to service daemon
* @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
- * @pre Before calling this function, VPN tun interface should be initialized already.
+ * @pre Before calling this function, VPN interface should be initialized already.
* @see vpnsvc_init()
*/
-API int vpnsvc_deinit(vpnsvc_tun_h handle);
+int vpnsvc_deinit(vpnsvc_h handle);
/**
* @brief Protect a socket from VPN connections.
* @details After protecting, data sent through this socket will go directly to the underlying network.
* @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
+ * @param[in] handle The VPN interface handle
* @param[in] socket_fd The opened socket file descriptor
- * @param[in] dev_name The network interface name (i.e. eth0 or ppp0, not to confuse with tunXXX) through which the VPN is working
+ * @param[in] dev_name The network interface name (e.g., interface name such as eth0, ppp0, etc) through which the VPN is working
* @return 0 on success. otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #VPNSVC_ERROR_IPC_FAILED Cannot connect to service daemon
* @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
*/
-API int vpnsvc_protect(vpnsvc_tun_h handle, int socket_fd, const char* dev_name);
+int vpnsvc_protect(vpnsvc_h handle, int socket_fd, const char* dev_name);
/**
- * @brief Sets-up TUN interface and brings it up. Installs specified routes/DNS servers/DNS suffix.
+ * @brief Reads the data event on VPN interface descriptor.
* @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
- * @param[in] local_ip The local IP address
- * @param[in] remote_ip The remote IP address
- * @param[in] dest Destination address of the route
- * @param[in] prefix The prefix of route
- * @param[in] nr_routes The number of routes
- * @param[in] dns_servers The list of DNS server names - Optional
- * @param[in] nr_dns_servers The number of DNS server names - Optionl
- * @param[in] dns_suffix The DNS suffix - Optional
- * @return 0 on success. otherwise, a negative error value.
- * @retval #VPNSVC_ERROR_NONE Success
- * @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #VPNSVC_ERROR_IPC_FAILED Cannot connect to service daemon
- * @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
- * @pre The VPN tun interface should be initialized already.
- * @post If you want to set interface down, please call vpnsvc_down().
- * @see vpnsvc_init()
- * @see vpnsvc_down()
- */
-API int vpnsvc_up(vpnsvc_tun_h handle, const char* local_ip, const char* remote_ip,
- const char *dest[], int prefix[], size_t nr_routes,
- const char** dns_servers, size_t nr_dns_servers,
- const char* dns_suffix);
-
-/**
- * @brief Brings the TUN interface down and restores original DNS servers/domains.
- * @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
- * @return 0 on success. otherwise, a negative error value.
- * @retval #VPNSVC_ERROR_NONE Success
- * @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #VPNSVC_ERROR_IPC_FAILED Cannot connect to service daemon
- * @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
- * @pre The VPN tun interface should be initialized already.
- * @post Please call vpnsvc_deinit() if you want to de-initialize VPN tun interface.
- * @see vpnsvc_up()
- * @see vpnsvc_deinit()
- */
-API int vpnsvc_down(vpnsvc_tun_h handle);
-
-/**
- * @brief Reads the data event on TUN descriptor.
- * @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
+ * @param[in] handle The VPN interface handle
* @param[in] timeout_ms The value of timeout (milliseconds)
* @return 0 on success. otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
* @pre The VPN interface should be initialized already.
* @see vpnsvc_init()
- * @see vpnsvc_up()
*/
-API int vpnsvc_read(vpnsvc_tun_h handle, int timeout_ms);
+int vpnsvc_read(vpnsvc_h handle, int timeout_ms);
/**
- * @brief Writes the data supplied into the TUN interface.
+ * @brief Writes the data supplied into the VPN interface.
* @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
- * @param[in] data Data writing to tun interface
+ * @param[in] handle The VPN interface handle
+ * @param[in] data Data writing to VPN interface
* @param[in] size The size of data
* @return On success, the number of bytes written is returned (zero indicates nothing was written). Otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval In case of negative error, please refer to standard posix write API's error code.
* @pre The VPN interface should be initialized already.
* @see vpnsvc_init()
- * @see vpnsvc_up()
*/
-API int vpnsvc_write(vpnsvc_tun_h handle, const char* data, size_t size);
+int vpnsvc_write(vpnsvc_h handle, const char* data, size_t size);
/**
* @brief Blocks all traffics except specified allowing networks.
* @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
+ * @param[in] handle The VPN interface handle
* @param[in] dest_vpn Allowing networks over VPN interface.
- * @param[in] prefix_vpn The prefix of VPN interface
+ * @param[in] prefix_vpn The prefix of VPN interface, netmask length (also called a prefix).
* @param[in] nr_allow_routes_vpn The number of allowing networks over VPN interface
* @param[in] dest_orig Allowing networks over the original interface.
- * @param[in] prefix_orig The prefix of Original interface.
+ * @param[in] prefix_orig The prefix of Original interface, netmask length (also called a prefix).
* @param[in] nr_allow_routes_orig The number of allowing networks over the original interface
* @return 0 on success. otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @post Please call vpnsvc_unblock_networks() if you want to allow all traffics.
* @see vpnsvc_unblock_networks()
*/
-API int vpnsvc_block_networks(vpnsvc_tun_h handle,
+int vpnsvc_block_networks(vpnsvc_h handle,
const char *dest_vpn[],
int prefix_vpn[],
size_t nr_allow_routes_vpn,
/**
* @brief Removes any restrictions imposed by vpnsvc_block_networks().
* @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
+ * @param[in] handle The VPN interface handle
* @return 0 on success. otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #VPNSVC_ERROR_IPC_FAILED Cannot connect to service daemon
* @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
*/
-API int vpnsvc_unblock_networks(vpnsvc_tun_h handle);
+int vpnsvc_unblock_networks(vpnsvc_h handle);
/**
- * @brief Gets the fd of the VPN tun interface.
+ * @brief Gets the fd of the VPN interface.
* @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
- * @param[out] tun_fd The tun fd
- * @return The fd value of VPN tun interface. Otherwise, a negative error value.
+ * @param[in] handle The VPN interface handle
+ * @param[out] if_fd The vpn interface fd
+ * @return The fd value of VPN interface. Otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
*/
-API int vpnsvc_get_tun_fd(vpnsvc_tun_h handle, int* tun_fd);
+int vpnsvc_get_if_fd(vpnsvc_h handle, int* if_fd);
/**
- * @brief Gets the index of VPN tun interface.
+ * @brief Gets the index of VPN interface.
* @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
- * @param[out] tun_index The tun index
- * @return The index of the VPN tun interface. otherwise, a negative error value.
+ * @param[in] handle The VPN interface handle
+ * @param[out] if_index The VPN interface index
+ * @return The index of the VPN interface. otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
- * @pre Before calling this function, VPN tun interface should be initialized already.
+ * @pre Before calling this function, VPN interface should be initialized already.
* @see vpnsvc_init()
*/
-API int vpnsvc_get_tun_index(vpnsvc_tun_h handle, int* tun_index);
+int vpnsvc_get_if_index(vpnsvc_h handle, int* if_index);
/**
- * @brief Gets the name of VPN tun interface.
+ * @brief Gets the name of VPN interface.
* @since_tizen 3.0
- * @remarks The @a tun_name should be released using free()
- * @param[in] handle The VPN tun interface handle
- * @param[out] tun_name The name of VPN tun interface name
+ * @remarks The @a if_name should be released using free()
+ * @param[in] handle The VPN interface handle
+ * @param[out] if_name The name of VPN interface name
* @return 0 on success. Otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
- * @pre Before calling this function, VPN tun interface should be initialized already.
+ * @pre Before calling this function, VPN interface should be initialized already.
* @see vpnsvc_init()
*/
-API int vpnsvc_get_tun_name(vpnsvc_tun_h handle, char** tun_name);
+int vpnsvc_get_if_name(vpnsvc_h handle, char** if_name);
/**
- * @brief Sets the MTU of the VPN tun interface.
+ * @brief Sets the MTU of the VPN interface.
* @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
- * @param[in] mtu The MTU (Maximum Transmission Unit) value to be set for VPN tun interface. Default MTU size is 1500.
+ * @param[in] handle The VPN interface handle
+ * @param[in] mtu The MTU (Maximum Transmission Unit) value to be set for VPN interface. Default MTU size is 1500.
* @return 0 on success. Otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
- * @pre Before calling this function, VPN tun interface should be initialized already.
+ * @pre Before calling this function, VPN interface should be initialized already.
* @see vpnsvc_init()
*/
-API int vpnsvc_set_mtu(vpnsvc_tun_h handle, int mtu);
+int vpnsvc_set_mtu(vpnsvc_h handle, int mtu);
/**
- * @brief Sets blocking mode of the file descriptor of VPN tun interface.
+ * @brief Sets blocking mode of the file descriptor of VPN interface.
* @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
- * @param[in] blocking The blocking mode flag; True = BLOCKING, False = NON_BLOCKING
+ * @param[in] handle The VPN interface handle
+ * @param[in] blocking The blocking mode flag; True = BLOCKING, False = NON_BLOCKING (Default : BLOCKING)
* @return 0 on success. Otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #VPNSVC_ERROR_IO_ERROR Failed to set the blocking flags
* @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
- * @pre Before calling this function, VPN tun interface should be initialized already.
+ * @pre Before calling this function, VPN interface should be initialized already.
* @see vpnsvc_init()
*/
-API int vpnsvc_set_blocking(vpnsvc_tun_h handle, bool blocking);
+int vpnsvc_set_blocking(vpnsvc_h handle, bool blocking);
/**
- * @brief Sets the session name for the VPN.
+ * @brief Sets the session name for the VPN. (It will be displayed in system-managed dialogs and notifications.)
* @since_tizen 3.0
- * @param[in] handle The VPN tun interface handle
+ * @param[in] handle The VPN interface handle
* @param[in] session The Session Name
* @return 0 on success. Otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
- * @pre Before calling this function, VPN tun interface should be initialized already.
+ * @pre Before calling this function, VPN interface should be initialized already.
* @see vpnsvc_init()
*/
-API int vpnsvc_set_session(vpnsvc_tun_h handle, const char* session);
+int vpnsvc_set_session(vpnsvc_h handle, const char* session);
/**
* @brief Gets the session name for the VPN.
* @since_tizen 3.0
* @remarks The @a session should be released using free()
- * @param[in] handle The VPN tun interface handle
+ * @param[in] handle The VPN interface handle
* @param[out] session The Session Name returned
* @return 0 on success. Otherwise, a negative error value.
* @retval #VPNSVC_ERROR_NONE Success
* @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
* @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
- * @pre Before calling this function, VPN tun interface should be initialized already.
+ * @pre Before calling this function, VPN interface should be initialized already.
* @see vpnsvc_init()
*/
-API int vpnsvc_get_session(vpnsvc_tun_h handle, char** session);
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
+int vpnsvc_get_session(vpnsvc_h handle, char** session);
/**
* @}
*/
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
#endif /* __TIZEN_CAPI_VPN_SERVICE_H__ */
--- /dev/null
+/*
+opyright (c) 2016 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 __TIZEN_VPN_SERVICE_INTERNAL_H__
+#define __TIZEN_VPN_SERVICE_INTERNAL_H__
+
+/**
+ * @addtogroup CAPI_NETWORK_VPN_MODULE
+ * @{
+ */
+
+#include <tizen.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+/**
+ * @file vpn_service_internal.h
+ */
+
+/**
+ * @internal
+ * @brief Sets-up TUN interface and brings it up. Installs specified routes/DNS servers/DNS suffix.
+ * @since_tizen 3.0
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/vpnservice.admin
+ * @param[in] handle The VPN tun interface handle
+ * @param[in] local_ip The local IP address
+ * @param[in] remote_ip The remote IP address
+ * @param[in] dest Destination address of the route
+ * @param[in] prefix The prefix of route
+ * @param[in] nr_routes The number of routes
+ * @param[in] dns_servers The list of DNS server names - Optional
+ * @param[in] nr_dns_servers The number of DNS server names - Optionl
+ * @param[in] dns_suffix The DNS suffix - Optional
+ * @return 0 on success. otherwise, a negative error value.
+ * @retval #VPNSVC_ERROR_NONE Success
+ * @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #VPNSVC_ERROR_IPC_FAILED Cannot connect to service daemon
+ * @retval #VPNSVC_ERROR_PERMISSION_DENIED Permission Denied
+ * @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
+ * @pre The VPN tun interface should be initialized already.
+ * @post If you want to set interface down, please call vpnsvc_down().
+ * @see vpnsvc_init()
+ * @see vpnsvc_down()
+ */
+int vpnsvc_up(vpnsvc_h handle, const char* local_ip, const char* remote_ip,
+ const char *dest[], int prefix[], size_t nr_routes,
+ const char** dns_servers, size_t nr_dns_servers,
+ const char* dns_suffix);
+
+/**
+ * @internal
+ * @brief Brings the TUN interface down and restores original DNS servers/domains.
+ * @since_tizen 3.0
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/vpnservice.admin
+ * @param[in] handle The VPN tun interface handle
+ * @return 0 on success. otherwise, a negative error value.
+ * @retval #VPNSVC_ERROR_NONE Success
+ * @retval #VPNSVC_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #VPNSVC_ERROR_IPC_FAILED Cannot connect to service daemon
+ * @retval #VPNSVC_ERROR_PERMISSION_DENIED Permission Denied
+ * @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
+ * @pre The VPN tun interface should be initialized already.
+ * @post Please call vpnsvc_deinit() if you want to de-initialize VPN tun interface.
+ * @see vpnsvc_up()
+ * @see vpnsvc_deinit()
+ */
+int vpnsvc_down(vpnsvc_h handle);
+
+
+#ifdef __cplusplus
+}
+#endif // __cplusplus
+
+/**
+* @}
+*/
+
+#endif /* __TIZEN_CAPI_VPN_SERVICE_H__ */
+
+
+
+
+
perror("fgets() failed!!!");\
} while (0);
-vpnsvc_tun_h handle = NULL;
+vpnsvc_h handle = NULL;
int test_vpnsvc_init()
{
char* result_name = NULL;
printf("vpnsvc_init Succeed : %d\n", ret);
- if (vpnsvc_get_tun_fd(handle, &int_value) == VPNSVC_ERROR_NONE)
- printf("tun_fd : %d\n", int_value);
+ if (vpnsvc_get_if_fd(handle, &int_value) == VPNSVC_ERROR_NONE)
+ printf("if_fd : %d\n", int_value);
else
- printf("Fail to get tun_fd\n");
+ printf("Fail to get if_fd\n");
- if (vpnsvc_get_tun_index(handle, &int_value) == VPNSVC_ERROR_NONE)
- printf("tun_index : %d\n", int_value);
+ if (vpnsvc_get_if_index(handle, &int_value) == VPNSVC_ERROR_NONE)
+ printf("if_index : %d\n", int_value);
else
- printf("Fail to get tun_index\n");
+ printf("Fail to get if_index\n");
- ret = vpnsvc_get_tun_name(handle, &result_name);
+ ret = vpnsvc_get_if_name(handle, &result_name);
if (ret == VPNSVC_ERROR_NONE)
- printf("tun_name : %s\n", result_name);
+ printf("if_name : %s\n", result_name);
}
return 0;