diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 10 | ||||
-rw-r--r-- | src/fastd.c | 8 | ||||
-rw-r--r-- | src/fastd.h | 2 | ||||
-rw-r--r-- | src/method_ec25519_fhmqvc_xsalsa20_poly1305.c (renamed from src/method_curve25519_fhmqvc_xsalsa20_poly1305.c) | 19 | ||||
-rw-r--r-- | src/method_null.c | 9 | ||||
-rw-r--r-- | src/peer.c | 4 | ||||
-rw-r--r-- | src/peer.h | 4 |
7 files changed, 45 insertions, 11 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca32e30..7315aa0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,11 +2,11 @@ set(METHODS method_null.c) set(FASTD_INCLUDES ${FASTD_BINARY_DIR}) set(FASTD_LIBS "") -if(WITH_CFXP) - set(METHODS ${METHODS} method_curve25519_fhmqvc_xsalsa20_poly1305.c) - set(FASTD_INCLUDES ${FASTD_INCLUDES} ${NACL_INCLUDE_DIR}) - set(FASTD_LIBS ${FASTD_LIBS} ${NACL_LIBRARY}) -endif(WITH_CFXP) +if(WITH_METHOD_ECFXP) + set(METHODS ${METHODS} method_ec25519_fhmqvc_xsalsa20_poly1305.c) + set(FASTD_INCLUDES ${FASTD_INCLUDES} ${UECC_INCLUDE_DIR} ${NACL_INCLUDE_DIR}) + set(FASTD_LIBS ${FASTD_LIBS} ${UECC_LIBRARY} ${NACL_LIBRARY}) +endif(WITH_METHOD_ECFXP) include_directories(${FASTD_INCLUDES}) diff --git a/src/fastd.c b/src/fastd.c index 5dcec14..496df97 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -47,8 +47,8 @@ extern fastd_method fastd_method_null; -#ifdef WITH_CFXP -extern fastd_method fastd_method_curve25519_fhmqvc_xsalsa20_poly1305; +#ifdef WITH_METHOD_ECFXP +extern fastd_method fastd_method_ec25519_fhmqvc_xsalsa20_poly1305; #endif @@ -255,6 +255,10 @@ static void configure(fastd_context *ctx, fastd_config *conf, int argc, char *ar case 'm': if (!strcmp(optarg, "null")) conf->method = &fastd_method_null; +#ifdef WITH_METHOD_ECFXP + if (!strcmp(optarg, "ecfxp")) + conf->method = &fastd_method_ec25519_fhmqvc_xsalsa20_poly1305; +#endif else exit_error(ctx, "invalid method `%s'", optarg); break; diff --git a/src/fastd.h b/src/fastd.h index 806beb7..834fa39 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -69,6 +69,8 @@ struct _fastd_method { void (*handle_recv)(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffer); void (*send)(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffer); + + void (*free_peer_private)(fastd_context *ctx, fastd_peer *peer); }; struct _fastd_config { diff --git a/src/method_curve25519_fhmqvc_xsalsa20_poly1305.c b/src/method_ec25519_fhmqvc_xsalsa20_poly1305.c index 9551ad9..2a01ccd 100644 --- a/src/method_curve25519_fhmqvc_xsalsa20_poly1305.c +++ b/src/method_ec25519_fhmqvc_xsalsa20_poly1305.c @@ -32,9 +32,17 @@ #include <arpa/inet.h> +#include <libuecc/ecc.h> #include <crypto_secretbox_xsalsa20poly1305.h> +typedef struct _method_peer_config { +} method_peer_config; + +typedef struct _method_peer_state { +} method_peer_state; + + static bool method_check_config(fastd_context *ctx, const fastd_config *conf) { return true; } @@ -77,6 +85,7 @@ static char* method_peer_str(const fastd_context *ctx, const fastd_peer *peer) { } static void method_init(fastd_context *ctx, fastd_peer *peer) { + pr_info(ctx, "Initializing session with %P...", peer); } static void method_handle_recv(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffer) { @@ -87,8 +96,12 @@ static void method_send(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffe fastd_buffer_free(buffer); } -const fastd_method fastd_method_curve25519_fhmqvc_xsalsa20_poly1305 = { - .name = "curve25519-fhmqvc-xsalsa20-poly1305", +static void method_free_peer_private(fastd_context *ctx, fastd_peer *peer) { +} + + +const fastd_method fastd_method_ec25519_fhmqvc_xsalsa20_poly1305 = { + .name = "ec25519-fhmqvc-xsalsa20-poly1305", .check_config = method_check_config, @@ -99,4 +112,6 @@ const fastd_method fastd_method_curve25519_fhmqvc_xsalsa20_poly1305 = { .init = method_init, .handle_recv = method_handle_recv, .send = method_send, + + .free_peer_private = method_free_peer_private, }; diff --git a/src/method_null.c b/src/method_null.c index e8d8f58..f5a0d74 100644 --- a/src/method_null.c +++ b/src/method_null.c @@ -81,11 +81,15 @@ static char* method_peer_str(const fastd_context *ctx, const fastd_peer *peer) { } static void method_init(fastd_context *ctx, fastd_peer *peer) { + pr_info(ctx, "Connection with %P established.", peer); + fastd_task_put_send(ctx, peer, fastd_buffer_alloc(0, 0, 0)); } static void method_handle_recv(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffer) { if (!fastd_peer_is_established(peer)) { + pr_info(ctx, "Connection with %P established.", peer); + fastd_peer_set_established(ctx, peer); } @@ -114,6 +118,9 @@ static void method_send(fastd_context *ctx, fastd_peer *peer, fastd_buffer buffe fastd_task_put_send(ctx, peer, buffer); } +static void method_free_peer_private(fastd_context *ctx, fastd_peer *peer) { +} + const fastd_method fastd_method_null = { .name = "null", @@ -127,4 +134,6 @@ const fastd_method fastd_method_null = { .init = method_init, .handle_recv = method_handle_recv, .send = method_send, + + .free_peer_private = method_free_peer_private, }; @@ -50,6 +50,9 @@ const fastd_eth_addr* fastd_get_dest_address(const fastd_context *ctx, fastd_buf } static inline void reset_peer(fastd_context *ctx, fastd_peer *peer) { + ctx->conf->method->free_peer_private(ctx, peer); + peer->method_private = NULL; + int i, deleted = 0; for (i = 0; i < ctx->n_eth_addr; i++) { if (ctx->eth_addr[i].peer == peer) { @@ -92,6 +95,7 @@ static fastd_peer* add_peer(fastd_context *ctx) { peer->next = ctx->peers; peer->last_req_id = 0; + peer->method_private = NULL; ctx->peers = peer; @@ -48,6 +48,8 @@ struct _fastd_peer { uint8_t last_req_id; struct timespec seen; + + void *method_private; }; struct _fastd_peer_config { @@ -103,8 +105,6 @@ static inline void fastd_peer_set_established(fastd_context *ctx, fastd_peer *pe pr_warn(ctx, "tried to set an already established connection to established"); return; } - - pr_info(ctx, "Connection with %P established.", peer); } static inline bool fastd_eth_addr_is_unicast(const fastd_eth_addr *addr) { |