/**
* @internal
- * @brief Sets-up VPN interface and brings it up. Installs specified routes/DNS servers/DNS suffix.
+ * @brief Creates VPN service handle.
+ * @since_tizen 3.0
+ * @privlevel platform
+ * @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_PERMISSION_DENIED Permission Denied
+ * @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
+ * @post If you want to set interface down, please call vpnsvc_down().
+ */
+int vpnsvc_create(vpnsvc_h *handle);
+
+/**
+ * @internal
+ * @brief Destroys VPN service handle.
+ * @since_tizen 3.0
+ * @privlevel platform
+ * @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_PERMISSION_DENIED Permission Denied
+ * @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
+ * @pre The VPN interface should be created already.
+ */
+int vpnsvc_destroy(vpnsvc_h handle);
+
+/**
+ * @internal
+ * @brief Sets VPN interface name.
+ * @since_tizen 3.0
+ * @privlevel platform
+ * @param[in] handle The VPN interface handle
+ * @param[in] iface_name The 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_IPC_FAILED Cannot connect to service daemon
+ * @retval #VPNSVC_ERROR_PERMISSION_DENIED Permission Denied
+ * @retval #VPNSVC_ERROR_NOT_SUPPORTED Not Supported
+ * @pre The VPN interface should be initialized already.
+ * @post If you want to set interface down, please call vpnsvc_down().
+ */
+int vpnsvc_set_iface_name(vpnsvc_h handle, const char *iface_name);
+
+/**
+ * @internal
+ * @brief Sets-up VPN interface and brings it up.
* @since_tizen 3.0
* @privlevel platform
* @param[in] handle The VPN interface handle
}
/* Setting Default User Settings */
+ (*s)->index = 0;
(*s)->mtu = _USER_SETTING_DEFAULT_MTU;
strncpy((*s)->session, _USER_SETTING_DEFAULT_SESSION, VPNSVC_SESSION_STRING_LEN);
(*s)->session[VPNSVC_SESSION_STRING_LEN-1] = '\0';
return reply;
}
+EXPORT_API int vpnsvc_create(vpnsvc_h *handle)
+{
+ CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
+
+ LOGD("enter vpnsvc_create");
+
+ /* parameter check */
+ if (_vpn_check_handle_validity(*handle)) {
+ LOGE("Invalid parameter"); //LCOV_EXCL_LINE
+ return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+
+ vpnsvc_tun_s *tmp_s = NULL;
+ _vpnsvc_init_vpnsvc_tun_s(&tmp_s);
+ *handle = tmp_s;
+ LOGD("handle : %p", (*handle));
+
+ return VPNSVC_ERROR_NONE;
+}
+
+EXPORT_API int vpnsvc_destroy(vpnsvc_h handle)
+{
+ CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
+
+ int result = VPNSVC_ERROR_NONE;
+ vpnsvc_tun_s *tun_s = NULL;
+
+ /* parameter check */
+ if (handle == NULL) {
+ LOGE("handle is a NULL"); //LCOV_EXCL_LINE
+ return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+ tun_s = (vpnsvc_tun_s*)handle;
+
+ LOGD("enter vpnsvc_destroy");
+
+ _vpnsvc_deinit_vpnsvc_tun_s(tun_s);
+
+ return result;
+}
+
EXPORT_API int vpnsvc_init(const char* iface_name, vpnsvc_h *handle)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
int iface_fd = 0;
LOGD("enter vpnsvc_init, iface_name : %s", iface_name);
- LOGD("handle : %p\n", handle);
/* parameter check */
if (iface_name == NULL || strlen(iface_name) <= 0) {
LOGD("enter vpnsvc_up");
- if (tun_s->index <= 0) {
- LOGE("invalid handle"); //LCOV_EXCL_LINE
- return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
- } else if (tun_s->connection == NULL) {
+ if (tun_s->connection == NULL) {
LOGE("Connection Object is NULL"); //LCOV_EXCL_LINE
return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
- }
-
- if (tun_s->local_ip == NULL || tun_s->remote_ip == NULL) {
- LOGE("local and remote ip are invalid"); //LCOV_EXCL_LINE
+ } else if (tun_s->name[0] == 0) {
+ LOGE("invalid handle"); //LCOV_EXCL_LINE
return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
}
- LOGD("iface_index %d", tun_s->index);
- LOGD("local_ip : %s, remote_ip : %s", tun_s->local_ip, tun_s->remote_ip);
- LOGD("dns_suffix : %s", tun_s->dns_suffix);
+ LOGD("iface_index %d, iface_name %s", tun_s->index, tun_s->name);
op = _vpnsvc_invoke_dbus_method(tun_s->connection,
NETCONFIG_SERVICE_NAME,
NETCONFIG_VPNSVC_PATH,
NETCONFIG_VPNSVC_INTERFACE_NAME,
"vpn_up",
- g_variant_new("(i)", tun_s->index),
+ g_variant_new("(s)", tun_s->name),
&dbus_result);
if (dbus_result == VPNSVC_ERROR_PERMISSION_DENIED)
if (tun_s == NULL) {
LOGE("handle is a NULL"); //LCOV_EXCL_LINE
return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
- } else if (tun_s->index <= 0) {
- LOGE("invalid handle"); //LCOV_EXCL_LINE
- return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
} else if (tun_s->connection == NULL) {
LOGE("Connection Object is NULL"); //LCOV_EXCL_LINE
return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
NETCONFIG_VPNSVC_PATH,
NETCONFIG_VPNSVC_INTERFACE_NAME,
"vpn_down",
- g_variant_new("(i)", tun_s->index),
+ g_variant_new("(s)", tun_s->name),
&dbus_result);
if (dbus_result == VPNSVC_ERROR_PERMISSION_DENIED)
tun_s = (vpnsvc_tun_s*)handle;
op = _vpnsvc_invoke_dbus_method(tun_s->connection,
- NETCONFIG_SERVICE_NAME,
- NETCONFIG_NETWORK_PATH,
- NETCONFIG_NETWORK_INTERFACE,
- "CheckInternetPrivilege",
- NULL,
- &dbus_result);
-
- if (dbus_result == VPNSVC_ERROR_PERMISSION_DENIED)
- return VPNSVC_ERROR_PERMISSION_DENIED;
-
- op = _vpnsvc_invoke_dbus_method(tun_s->connection,
- NETCONFIG_SERVICE_NAME,
- NETCONFIG_VPNSVC_PATH,
- NETCONFIG_VPNSVC_INTERFACE_NAME,
- "vpn_set_local_ip_address",
- g_variant_new("(is)", tun_s->index, tun_s->local_ip),
- &dbus_result);
- if (dbus_result == VPNSVC_ERROR_PERMISSION_DENIED)
- return VPNSVC_ERROR_PERMISSION_DENIED;
-
- if (op == NULL) {
- return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
- } else {
- g_variant_get(op, "(i)", &result);
- if (result != VPNSVC_ERROR_NONE)
- LOGE("vpn_set_local_ip_address() failed"); //LCOV_EXCL_LINE
- else
- LOGD("vpn_set_local_ip_address() succeed");
- }
-
- op = _vpnsvc_invoke_dbus_method(tun_s->connection,
- NETCONFIG_SERVICE_NAME,
- NETCONFIG_VPNSVC_PATH,
- NETCONFIG_VPNSVC_INTERFACE_NAME,
- "vpn_set_remote_ip_address",
- g_variant_new("(is)", tun_s->index, tun_s->remote_ip),
- &dbus_result);
- if (dbus_result == VPNSVC_ERROR_PERMISSION_DENIED)
- return VPNSVC_ERROR_PERMISSION_DENIED;
-
- if (op == NULL) {
- return VPNSVC_ERROR_IPC_FAILED; //LCOV_EXCL_LINE
- } else {
- g_variant_get(op, "(i)", &result);
- if (result != VPNSVC_ERROR_NONE)
- LOGE("vpn_set_remote_ip_address() failed"); //LCOV_EXCL_LINE
- else
- LOGD("vpn_set_remote_ip-address() succeed");
- }
-
- op = _vpnsvc_invoke_dbus_method(tun_s->connection,
NETCONFIG_SERVICE_NAME,
NETCONFIG_VPNSVC_PATH,
NETCONFIG_VPNSVC_INTERFACE_NAME,
- "vpn_set_mtu",
- g_variant_new("(iu)", tun_s->index, tun_s->mtu),
+ "vpn_update_settings",
+ g_variant_new("(issu)", tun_s->index, tun_s->local_ip, tun_s->remote_ip, tun_s->mtu),
&dbus_result);
if (dbus_result == VPNSVC_ERROR_PERMISSION_DENIED)
return VPNSVC_ERROR_PERMISSION_DENIED;
} else {
g_variant_get(op, "(i)", &result);
if (result != VPNSVC_ERROR_NONE)
- LOGE("vpn_set_mtu() failed"); //LCOV_EXCL_LINE
+ LOGE("vpn_update_settings() failed"); //LCOV_EXCL_LINE
else
- LOGD("vpn_set_mtu() succeed");
+ LOGD("vpn_update_settings() succeed");
}
return result;
return VPNSVC_ERROR_NONE;
}
+EXPORT_API int vpnsvc_set_iface_name(vpnsvc_h handle, const char *iface_name)
+{
+ CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
+
+ vpnsvc_tun_s *tun_s = NULL;
+
+ /* parameter check */
+ if (handle == NULL) {
+ LOGE("handle is a NULL"); //LCOV_EXCL_LINE
+ return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+ tun_s = (vpnsvc_tun_s*)handle;
+
+ if (iface_name == NULL) {
+ LOGE("Remote IP address is NULL"); //LCOV_EXCL_LINE
+ return VPNSVC_ERROR_INVALID_PARAMETER; //LCOV_EXCL_LINE
+ }
+
+ strncpy(tun_s->name, iface_name, VPNSVC_VPN_IFACE_NAME_LEN);
+
+ return VPNSVC_ERROR_NONE;
+}
+
+
EXPORT_API int vpnsvc_set_mtu(vpnsvc_h handle, int mtu)
{
CHECK_FEATURE_SUPPORTED(VPN_SERVICE_FEATURE);
int result = VPNSVC_ERROR_NONE;
- int dbus_result;
vpnsvc_tun_s *tun_s = NULL;
/* parameter check */
char local_ip[VPNSVC_IP4_STRING_LEN];
printf("Input local IP address: ");
- rv = scanf("%s", local_ip);
+ rv = scanf("%15s", local_ip);
rv = vpnsvc_set_local_ip_address(handle, local_ip);
if (rv != VPNSVC_ERROR_NONE) {
char remote_ip[VPNSVC_IP4_STRING_LEN];
printf("Input remote IP address: ");
- rv = scanf("%s", remote_ip);
+ rv = scanf("%15s", remote_ip);
rv = vpnsvc_set_remote_ip_address(handle, remote_ip);
if (rv != VPNSVC_ERROR_NONE) {
return 1;
}
+int test_vpnsvc_update_settings()
+{
+ int rv;
+
+ rv = vpnsvc_update_settings(handle);
+ if (rv != VPNSVC_ERROR_NONE) {
+ printf("vpnsvc update settings [%s]\n", test_print_error(rv));
+ return -1;
+ }
+
+ return 1;
+}
+
int test_vpnsvc_add_route()
{
int rv;
char addr[VPNSVC_IP4_STRING_LEN];
printf("Input route address: ");
- rv = scanf("%s", addr);
+ rv = scanf("%15s", addr);
printf("Input prefix: ");
rv = scanf("%d", &prefix);
char addr[VPNSVC_IP4_STRING_LEN];
printf("Input route address: ");
- rv = scanf("%s", addr);
+ rv = scanf("%15s", addr);
printf("Input prefix: ");
rv = scanf("%d", &prefix);
char addr[VPNSVC_IP4_STRING_LEN];
printf("Input dns server: ");
- rv = scanf("%s", addr);
+ rv = scanf("%15s", addr);
rv = vpnsvc_add_dns_server(handle, addr);
if (rv != VPNSVC_ERROR_NONE) {
char addr[VPNSVC_IP4_STRING_LEN];
printf("Input dns server address: ");
- rv = scanf("%s", addr);
+ rv = scanf("%15s", addr);
rv = vpnsvc_remove_dns_server(handle, addr);
if (rv != VPNSVC_ERROR_NONE) {
return 1;
}
+int test_vpnsvc_create()
+{
+ int rv = VPNSVC_ERROR_NONE;
+ int int_value;
+
+ rv = vpnsvc_create(&handle);
+
+ if (rv != VPNSVC_ERROR_NONE) {
+ printf("vpnsvc create fail [%s]\n", test_print_error(rv));
+ return -1;
+ } else {
+ printf("vpnsvc create success(%p)\n", handle);
+ return 1;
+ }
+}
+
+int test_vpnsvc_destroy()
+{
+ int rv = VPNSVC_ERROR_NONE;
+ int int_value;
+
+ rv = vpnsvc_destroy(handle);
+
+ if (rv != VPNSVC_ERROR_NONE) {
+ printf("vpnsvc destroy fail [%s]\n", test_print_error(rv));
+ return -1;
+ } else {
+ printf("vpnsvc destroy success(%p)\n", handle);
+ return 1;
+ }
+}
+
+int test_vpnsvc_set_iface_name()
+{
+ int rv;
+ char iface_name[VPNSVC_VPN_IFACE_NAME_LEN];
+
+ if (!handle) {
+ printf("invalid handle - handle is NULL\n");
+ return -1;
+ }
+
+ printf("Interface name: ");
+ rv = scanf("%15s", iface_name);
+
+ rv = vpnsvc_set_iface_name(handle, iface_name);
+
+ if (rv != VPNSVC_ERROR_NONE)
+ printf("vpnsvc set iface name fail [%s]\n", test_print_error(rv));
+ else
+ printf("vpnsvc set iface name success\n");
+
+ return 1;
+}
+
int test_exit()
{
exit(0);
test_vpnsvc_set_session,
test_vpnsvc_set_local_ip_address,
test_vpnsvc_set_remote_ip_address,
+ test_vpnsvc_update_settings,
test_vpnsvc_add_route,
test_vpnsvc_remove_route,
test_vpnsvc_add_dns_server,
test_vpnsvc_remove_dns_server,
+ test_vpnsvc_create,
+ test_vpnsvc_destroy,
+ test_vpnsvc_set_iface_name,
test_exit,
};
printf("1 : vpnsvc_init\n");
printf("2 : vpnsvc_deinit\n");
printf("3 : vpnsvc_protect\n");
- printf("4 : vpnsvc_up(1->13->14)\n");
- printf("5 : vpnsvc_down\n");
+ printf("4 : vpnsvc_up(internal)\n");
+ printf("5 : vpnsvc_down(internal)\n");
printf("6 : vpnsvc_read\n");
printf("7 : vpnsvc_write\n");
printf("8 : vpnsvc_block_networks\n");
printf("12 : vpnsvc_set_session\n");
printf("13 : vpnsvc_set_local_ip_address\n");
printf("14 : vpnsvc_set_remote_ip_address\n");
- printf("15 : vpnsvc_add_route\n");
- printf("16 : vpnsvc_remove_route\n");
- printf("17 : vpnsvc_add_dns_server\n");
- printf("18 : vpnsvc_remove_dns_server\n");
+ printf("15 : vpnsvc_update_settings\n");
+ printf("16 : vpnsvc_add_route\n");
+ printf("17 : vpnsvc_remove_route\n");
+ printf("18 : vpnsvc_add_dns_server\n");
+ printf("19 : vpnsvc_remove_dns_server\n");
+ printf("20 : vpnsvc_create(internal)\n");
+ printf("21 : vpnsvc_destroy(internal)\n");
+ printf("22 : vpnsvc_set_iface_name(internal)\n");
printf("q : quit\n");
TEST_CONSOLE_INPUT(input, 3);