summaryrefslogtreecommitdiffstats
path: root/tinyIPSec
diff options
context:
space:
mode:
authorMamadou DIOP <bossiel@yahoo.fr>2016-02-23 22:00:35 +0100
committerMamadou DIOP <bossiel@yahoo.fr>2016-02-23 22:00:35 +0100
commit50dfb4359619563012997bc3ddafb7667741066c (patch)
treedb234c1edc3240a653363b5735fc4077af4b8720 /tinyIPSec
parent94b2219209038e05dd26395f6fb700be4d1062c0 (diff)
downloaddoubango-50dfb4359619563012997bc3ddafb7667741066c.zip
doubango-50dfb4359619563012997bc3ddafb7667741066c.tar.gz
Add new QoS implementation
Code formatting
Diffstat (limited to 'tinyIPSec')
-rwxr-xr-xtinyIPSec/src/tipsec.c106
-rwxr-xr-xtinyIPSec/src/tipsec.h8
-rwxr-xr-xtinyIPSec/test/test.c265
3 files changed, 190 insertions, 189 deletions
diff --git a/tinyIPSec/src/tipsec.c b/tinyIPSec/src/tipsec.c
index 2fe9976..2abcb41 100755
--- a/tinyIPSec/src/tipsec.c
+++ b/tinyIPSec/src/tipsec.c
@@ -36,7 +36,7 @@
static const tipsec_plugin_def_t* __tipsec_plugins[TIPSEC_MAX_PLUGINS] = { tsk_null };
/**
-* Create an IPSec context to manage the SAs.
+* Create an IPSec context to manage the SAs.
* Before calling this function at least one special implementation must be registered using @ref tipsec_plugin_register_static().
* @param ipproto IPSec internet protocol.
* @param use_ipv6 Whether to use IPv6 or not (IPv4).
@@ -80,16 +80,16 @@ tipsec_error_t tipsec_ctx_create(
p_ctx->ealg = ealg;
p_ctx->alg = alg;
p_ctx->protocol = protocol;
- p_ctx->ipproto = ipproto;
+ p_ctx->ipproto = ipproto;
break;
}
}
}
- if (!pc_plugin || !p_ctx) {
- TSK_DEBUG_ERROR("Failed to find/create a plugin instance");
+ if (!pc_plugin || !p_ctx) {
+ TSK_DEBUG_ERROR("Failed to find/create a plugin instance");
return tipsec_error_notfound;
- }
+ }
// Initialize the newly created context
err = pc_plugin->init(p_ctx);
@@ -116,10 +116,10 @@ tipsec_error_t tipsec_ctx_start(tipsec_ctx_t* p_ctx)
TSK_DEBUG_ERROR("Invalid parameter");
return tipsec_error_invalid_param;
}
- if (!p_ctx->initialized || p_ctx->state != tipsec_state_full) {
- TSK_DEBUG_ERROR("Invalid state (not initialized or not in full state)");
- return tipsec_error_invalid_state;
- }
+ if (!p_ctx->initialized || p_ctx->state != tipsec_state_full) {
+ TSK_DEBUG_ERROR("Invalid state (not initialized or not in full state)");
+ return tipsec_error_invalid_state;
+ }
return p_ctx->pc_plugin->start(p_ctx);
}
@@ -138,10 +138,10 @@ tipsec_error_t tipsec_ctx_set_local(tipsec_ctx_t* p_ctx, const char* addr_local,
TSK_DEBUG_ERROR("Invalid parameter");
return tipsec_error_invalid_param;
}
- if (!p_ctx->initialized || p_ctx->state != tipsec_state_initial) {
- TSK_DEBUG_ERROR("Invalid state (not initialized or not in initial state)");
- return tipsec_error_invalid_state;
- }
+ if (!p_ctx->initialized || p_ctx->state != tipsec_state_initial) {
+ TSK_DEBUG_ERROR("Invalid state (not initialized or not in initial state)");
+ return tipsec_error_invalid_state;
+ }
return p_ctx->pc_plugin->set_local(p_ctx, addr_local, addr_remote, port_uc, port_us);
}
@@ -178,10 +178,10 @@ tipsec_error_t tipsec_ctx_set_remote(tipsec_ctx_t* p_ctx, tipsec_spi_t spi_pc, t
TSK_DEBUG_ERROR("Invalid parameter");
return tipsec_error_invalid_param;
}
- if (!p_ctx->initialized || p_ctx->state != tipsec_state_inbound) {
- TSK_DEBUG_ERROR("Invalid state (not initialized or not in initial state)");
- return tipsec_error_invalid_state;
- }
+ if (!p_ctx->initialized || p_ctx->state != tipsec_state_inbound) {
+ TSK_DEBUG_ERROR("Invalid state (not initialized or not in initial state)");
+ return tipsec_error_invalid_state;
+ }
return p_ctx->pc_plugin->set_remote(p_ctx, spi_pc, spi_ps, port_pc, port_ps, lifetime);
}
@@ -276,33 +276,33 @@ tipsec_error_t tipsec_plugin_unregister_static(const tipsec_plugin_def_t* pc_plu
*/
tipsec_error_t tipsec_plugin_register_file(const char* pc_filepath, struct tsk_plugin_s** pp_plugin)
{
- struct tsk_plugin_s* p_plugin = tsk_null;
- tsk_plugin_def_ptr_const_t p_def;
- tipsec_error_t err = tipsec_error_success;
- int i = 0, count = 0;
+ struct tsk_plugin_s* p_plugin = tsk_null;
+ tsk_plugin_def_ptr_const_t p_def;
+ tipsec_error_t err = tipsec_error_success;
+ int i = 0, count = 0;
- p_plugin = tsk_plugin_create(pc_filepath);
- if (!p_plugin) {
- return tipsec_error_notfound;
- }
-
- while ((p_def = tsk_plugin_get_def_2(p_plugin, tsk_plugin_def_type_ipsec, tsk_plugin_def_media_type_all, i++))) {
- if (p_def) {
- err = tipsec_plugin_register_static(p_def);
- if (!err) {
- ++count;
- }
- }
- }
+ p_plugin = tsk_plugin_create(pc_filepath);
+ if (!p_plugin) {
+ return tipsec_error_notfound;
+ }
- if (count <= 0) {
- TSK_DEBUG_ERROR("No plugin in %s", pc_filepath);
- TSK_OBJECT_SAFE_FREE(p_plugin);
- return tipsec_error_notfound;
- }
-
- *pp_plugin = p_plugin;
- return err;
+ while ((p_def = tsk_plugin_get_def_2(p_plugin, tsk_plugin_def_type_ipsec, tsk_plugin_def_media_type_all, i++))) {
+ if (p_def) {
+ err = tipsec_plugin_register_static(p_def);
+ if (!err) {
+ ++count;
+ }
+ }
+ }
+
+ if (count <= 0) {
+ TSK_DEBUG_ERROR("No plugin in %s", pc_filepath);
+ TSK_OBJECT_SAFE_FREE(p_plugin);
+ return tipsec_error_notfound;
+ }
+
+ *pp_plugin = p_plugin;
+ return err;
}
/**
@@ -313,16 +313,16 @@ tipsec_error_t tipsec_plugin_register_file(const char* pc_filepath, struct tsk_p
*/
tipsec_error_t tipsec_plugin_unregister_file(struct tsk_plugin_s* p_plugin)
{
- int i = 0;
- tsk_plugin_def_ptr_const_t p_def;
- if (!p_plugin) {
- TSK_DEBUG_ERROR("Invalid parameter");
+ int i = 0;
+ tsk_plugin_def_ptr_const_t p_def;
+ if (!p_plugin) {
+ TSK_DEBUG_ERROR("Invalid parameter");
return tipsec_error_invalid_param;
- }
- while ((p_def = tsk_plugin_get_def_2(p_plugin, tsk_plugin_def_type_ipsec, tsk_plugin_def_media_type_all, i++))) {
- if (p_def) {
- tipsec_plugin_unregister_static(p_def);
- }
- }
- return tipsec_error_success;
+ }
+ while ((p_def = tsk_plugin_get_def_2(p_plugin, tsk_plugin_def_type_ipsec, tsk_plugin_def_media_type_all, i++))) {
+ if (p_def) {
+ tipsec_plugin_unregister_static(p_def);
+ }
+ }
+ return tipsec_error_success;
}
diff --git a/tinyIPSec/src/tipsec.h b/tinyIPSec/src/tipsec.h
index 5c4c5e5..d104e73 100755
--- a/tinyIPSec/src/tipsec.h
+++ b/tinyIPSec/src/tipsec.h
@@ -165,8 +165,8 @@ typedef enum tipsec_ipproto_e {
tipsec_ipproto_tcp,
//! ICMP.
tipsec_ipproto_icmp,
- //! ALL IP protocols
- tipsec_ipproto_all
+ //! ALL IP protocols
+ tipsec_ipproto_all
}
tipsec_ipproto_t;
@@ -211,14 +211,14 @@ tipsec_state_t;
typedef enum tipsec_error_e {
tipsec_error_success = 0, /**< Success */
tipsec_error_invalid_param, /**< Invalid parameter */
- tipsec_error_invalid_state, /**< Invalid state */
+ tipsec_error_invalid_state, /**< Invalid state */
tipsec_error_access_violation, /**< Access violation */
tipsec_error_permission_denied, /**< Permission denied */
tipsec_error_outofmemory, /**< Out of memory */
tipsec_error_outofbound, /**< Out of bound */
tipsec_error_notfound, /**< Not found */
tipsec_error_notimplemented, /**< Not implemented */
- tipsec_error_sys, /**< System error */
+ tipsec_error_sys, /**< System error */
}
tipsec_error_t;
diff --git a/tinyIPSec/test/test.c b/tinyIPSec/test/test.c
index d5b710a..1d6f4d0 100755
--- a/tinyIPSec/test/test.c
+++ b/tinyIPSec/test/test.c
@@ -46,32 +46,32 @@ static const char* __key_ck = "1234567890121234";
static tsk_bool_t test_ipsec_is_winvista_or_later()
{
- /*
- Version Number Description
- 6.1 Windows 7 / Windows 2008 R2
- 6.0 Windows Vista / Windows 2008
- 5.2 Windows 2003
- 5.1 Windows XP
- 5.0 Windows 2000
- */
- static DWORD dwMajorVersion = -1;
- static DWORD dwMinorVersion = -1;
-
- if(dwMajorVersion == -1 || dwMinorVersion == -1){
- OSVERSIONINFO osvi;
- ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
- GetVersionEx(&osvi);
- dwMajorVersion = osvi.dwMajorVersion;
- dwMinorVersion = osvi.dwMinorVersion;
- }
-
- return (dwMajorVersion >= 6);
+ /*
+ Version Number Description
+ 6.1 Windows 7 / Windows 2008 R2
+ 6.0 Windows Vista / Windows 2008
+ 5.2 Windows 2003
+ 5.1 Windows XP
+ 5.0 Windows 2000
+ */
+ static DWORD dwMajorVersion = -1;
+ static DWORD dwMinorVersion = -1;
+
+ if(dwMajorVersion == -1 || dwMinorVersion == -1) {
+ OSVERSIONINFO osvi;
+ ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&osvi);
+ dwMajorVersion = osvi.dwMajorVersion;
+ dwMinorVersion = osvi.dwMinorVersion;
+ }
+
+ return (dwMajorVersion >= 6);
}
#else
-static tsk_bool_t test_ipsec_is_winvista_or_later()
+static tsk_bool_t test_ipsec_is_winvista_or_later()
{
- return 0;
+ return 0;
}
#endif
@@ -81,115 +81,116 @@ int _tmain()
int main(int argc, const char* argv[])
#endif
{
- int err = 0;
- tsk_size_t i;
- struct tsk_plugin_s* p_plugin = tsk_null;
- tipsec_ctx_t* p_ctx = tsk_null;
- static const char* __plugins_path[] = /* Visual Studio requires "Debugging" -> "Working Directory" = "$(OutDir)" */
- {
- "pluginWinIPSecVista.DLL",
- "pluginWinIPSecXP.DLL",
- "pluginLinIPsecTools.so"
- };
- static const tsk_size_t __plugins_count = sizeof(__plugins_path)/sizeof(__plugins_path[0]);
-
- #define BUF_SIZE 1024
- char buffer[BUF_SIZE];
-
- /* Set debug level to INFO */
- tsk_debug_set_level(DEBUG_LEVEL_INFO);
-
- // Command line "local_ip" "local_port_in" "local_port_out" "remote_ip" "remote_port_in" "remote_port_out"
- if (argc == (6 + 1)) {
- __addr_local = argv[1];
- __port_local_in = atoi(argv[2]);
- __port_local_out = atoi(argv[3]);
- __addr_remote = argv[4];
- __port_remote_in = atoi(argv[5]);
- __port_remote_out = atoi(argv[6]);
- }
-
- TSK_DEBUG_INFO("Local node=%s:%d/%d, remote node=%s:%d/%d",
- __addr_local, __port_local_in, __port_local_out,
- __addr_remote, __port_remote_in, __port_remote_out);
-
- /* Create the plugin */
- for (i = 0; i < __plugins_count; ++i) {
- if (tsk_plugin_file_exist(__plugins_path[i])) {
- tipsec_plugin_register_file(__plugins_path[i], &p_plugin);
- if (p_plugin) {
- break;
- }
- }
- }
- if (!p_plugin) {
- TSK_DEBUG_ERROR("Failed to create IPSec plugin");
- err = -1; goto bail;
- }
-
- /* Create the context */
- err = tipsec_ctx_create(__ipproto, __use_ipv6, __mode, __ealg, __alg, __proto, &p_ctx);
- if (err) {
- goto bail;
- }
-
- /* Set local */
- err = tipsec_ctx_set_local(p_ctx, __addr_local, __addr_remote, __port_local_out, __port_local_in);
- if (err) {
- goto bail;
- }
- // Dump SPIs created by the OS after calling set_local()
- TSK_DEBUG_INFO("SPI-UC=%u, SPI-US=%u", p_ctx->spi_uc, p_ctx->spi_us);
-
- // Enter Remote SPI in
- TSK_DEBUG_INFO("Enter remote SPI in:");
- if (fgets(buffer, BUF_SIZE, stdin)) {
- if (buffer[0] != 10 && buffer[1] != 0) {
- __spi_remote_in = strtoul (buffer, NULL, 0);
- }
- }
-
- // Enter Remote SPI out
- TSK_DEBUG_INFO("Enter remote SPI out:");
- if (fgets(buffer, BUF_SIZE, stdin)) {
- if (buffer[0] != 10 && buffer[1] != 0) {
- __spi_remote_out = strtoul (buffer, NULL, 0);
- }
- }
-
- TSK_DEBUG_INFO("SPI remote %u/%u", __spi_remote_in, __spi_remote_out);
-
- /* Set remote */
- err = tipsec_ctx_set_remote(p_ctx, __spi_remote_out, __spi_remote_in, __port_remote_out, __port_remote_in, __lifetime);
- if (err) {
- goto bail;
- }
-
- /* Set Integrity (IK) and Confidentiality (CK) keys */
- err = tipsec_ctx_set_keys(p_ctx, __key_ik, __key_ck);
- if (err) {
- goto bail;
- }
-
- /* Start (Setup) the SAs */
- err = tipsec_ctx_start(p_ctx);
- if (err) {
- goto bail;
- }
-
- TSK_DEBUG_INFO("!!! IPSec SAs started (Press any key to stop) !!!");
-
- /* Wait */
- getchar();
+ int err = 0;
+ tsk_size_t i;
+ struct tsk_plugin_s* p_plugin = tsk_null;
+ tipsec_ctx_t* p_ctx = tsk_null;
+ static const char* __plugins_path[] = /* Visual Studio requires "Debugging" -> "Working Directory" = "$(OutDir)" */
+ {
+ "pluginWinIPSecVista.DLL",
+ "pluginWinIPSecXP.DLL",
+ "pluginLinIPsecTools.so"
+ };
+ static const tsk_size_t __plugins_count = sizeof(__plugins_path)/sizeof(__plugins_path[0]);
+
+#define BUF_SIZE 1024
+ char buffer[BUF_SIZE];
+
+ /* Set debug level to INFO */
+ tsk_debug_set_level(DEBUG_LEVEL_INFO);
+
+ // Command line "local_ip" "local_port_in" "local_port_out" "remote_ip" "remote_port_in" "remote_port_out"
+ if (argc == (6 + 1)) {
+ __addr_local = argv[1];
+ __port_local_in = atoi(argv[2]);
+ __port_local_out = atoi(argv[3]);
+ __addr_remote = argv[4];
+ __port_remote_in = atoi(argv[5]);
+ __port_remote_out = atoi(argv[6]);
+ }
+
+ TSK_DEBUG_INFO("Local node=%s:%d/%d, remote node=%s:%d/%d",
+ __addr_local, __port_local_in, __port_local_out,
+ __addr_remote, __port_remote_in, __port_remote_out);
+
+ /* Create the plugin */
+ for (i = 0; i < __plugins_count; ++i) {
+ if (tsk_plugin_file_exist(__plugins_path[i])) {
+ tipsec_plugin_register_file(__plugins_path[i], &p_plugin);
+ if (p_plugin) {
+ break;
+ }
+ }
+ }
+ if (!p_plugin) {
+ TSK_DEBUG_ERROR("Failed to create IPSec plugin");
+ err = -1;
+ goto bail;
+ }
+
+ /* Create the context */
+ err = tipsec_ctx_create(__ipproto, __use_ipv6, __mode, __ealg, __alg, __proto, &p_ctx);
+ if (err) {
+ goto bail;
+ }
+
+ /* Set local */
+ err = tipsec_ctx_set_local(p_ctx, __addr_local, __addr_remote, __port_local_out, __port_local_in);
+ if (err) {
+ goto bail;
+ }
+ // Dump SPIs created by the OS after calling set_local()
+ TSK_DEBUG_INFO("SPI-UC=%u, SPI-US=%u", p_ctx->spi_uc, p_ctx->spi_us);
+
+ // Enter Remote SPI in
+ TSK_DEBUG_INFO("Enter remote SPI in:");
+ if (fgets(buffer, BUF_SIZE, stdin)) {
+ if (buffer[0] != 10 && buffer[1] != 0) {
+ __spi_remote_in = strtoul (buffer, NULL, 0);
+ }
+ }
+
+ // Enter Remote SPI out
+ TSK_DEBUG_INFO("Enter remote SPI out:");
+ if (fgets(buffer, BUF_SIZE, stdin)) {
+ if (buffer[0] != 10 && buffer[1] != 0) {
+ __spi_remote_out = strtoul (buffer, NULL, 0);
+ }
+ }
+
+ TSK_DEBUG_INFO("SPI remote %u/%u", __spi_remote_in, __spi_remote_out);
+
+ /* Set remote */
+ err = tipsec_ctx_set_remote(p_ctx, __spi_remote_out, __spi_remote_in, __port_remote_out, __port_remote_in, __lifetime);
+ if (err) {
+ goto bail;
+ }
+
+ /* Set Integrity (IK) and Confidentiality (CK) keys */
+ err = tipsec_ctx_set_keys(p_ctx, __key_ik, __key_ck);
+ if (err) {
+ goto bail;
+ }
+
+ /* Start (Setup) the SAs */
+ err = tipsec_ctx_start(p_ctx);
+ if (err) {
+ goto bail;
+ }
+
+ TSK_DEBUG_INFO("!!! IPSec SAs started (Press any key to stop) !!!");
+
+ /* Wait */
+ getchar();
bail:
- // Stop the SAs, cleanup and destroy the context
- TSK_OBJECT_SAFE_FREE(p_ctx); // must destroy the contect before unloading the plugin (*.DLL or *.SO)
-
- // Unregister the plugin and close the file handle
- if (p_plugin) {
- tipsec_plugin_unregister_file(p_plugin);
- TSK_OBJECT_SAFE_FREE(p_plugin);
- }
- return err;
+ // Stop the SAs, cleanup and destroy the context
+ TSK_OBJECT_SAFE_FREE(p_ctx); // must destroy the contect before unloading the plugin (*.DLL or *.SO)
+
+ // Unregister the plugin and close the file handle
+ if (p_plugin) {
+ tipsec_plugin_unregister_file(p_plugin);
+ TSK_OBJECT_SAFE_FREE(p_plugin);
+ }
+ return err;
}
OpenPOWER on IntegriCloud