diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/config.y | 7 | ||||
-rw-r--r-- | src/fastd.h | 1 | ||||
-rw-r--r-- | src/lex.c | 1 | ||||
-rw-r--r-- | src/options.c | 4 | ||||
-rw-r--r-- | src/options.def.h | 1 | ||||
-rw-r--r-- | src/protocols/ec25519_fhmqvc/handshake.c | 3 |
6 files changed, 17 insertions, 0 deletions
diff --git a/src/config.y b/src/config.y index 2bdd5d3..b4bd68b 100644 --- a/src/config.y +++ b/src/config.y @@ -74,6 +74,7 @@ %token TOK_BIND %token TOK_CAPABILITIES %token TOK_CIPHER +%token TOK_CONNECT %token TOK_DEBUG %token TOK_DEBUG2 %token TOK_DEFAULT @@ -198,6 +199,7 @@ statement: peer_group_statement | TOK_ON TOK_UP on_up ';' | TOK_ON TOK_DOWN on_down ';' | TOK_ON TOK_POST_DOWN on_post_down ';' + | TOK_ON TOK_CONNECT on_connect ';' | TOK_ON TOK_ESTABLISH on_establish ';' | TOK_ON TOK_DISESTABLISH on_disestablish ';' | TOK_ON TOK_VERIFY on_verify ';' @@ -398,6 +400,11 @@ on_post_down: sync_def_sync TOK_STRING { } ; +on_connect: sync_def_async TOK_STRING { + fastd_shell_command_set(&conf->on_connect, $2->str, $1); + } + ; + on_establish: sync_def_async TOK_STRING { fastd_shell_command_set(&conf->on_establish, $2->str, $1); } diff --git a/src/fastd.h b/src/fastd.h index c117cdc..1ce1055 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -209,6 +209,7 @@ struct fastd_config { fastd_shell_command_t on_up; fastd_shell_command_t on_down; fastd_shell_command_t on_post_down; + fastd_shell_command_t on_connect; fastd_shell_command_t on_establish; fastd_shell_command_t on_disestablish; fastd_shell_command_t on_verify; @@ -56,6 +56,7 @@ static const keyword_t keywords[] = { { "bind", TOK_BIND }, { "capabilities", TOK_CAPABILITIES }, { "cipher", TOK_CIPHER }, + { "connect", TOK_CONNECT }, { "debug", TOK_DEBUG }, { "debug2", TOK_DEBUG2 }, { "default", TOK_DEFAULT }, diff --git a/src/options.c b/src/options.c index a4c334f..0fb3baa 100644 --- a/src/options.c +++ b/src/options.c @@ -285,6 +285,10 @@ static void option_on_post_down(fastd_context_t *ctx UNUSED, fastd_config_t *con fastd_shell_command_set(&conf->on_post_down, arg, true); } +static void option_on_connect(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { + fastd_shell_command_set(&conf->on_connect, arg, false); +} + static void option_on_establish(fastd_context_t *ctx UNUSED, fastd_config_t *conf, const char *arg) { fastd_shell_command_set(&conf->on_establish, arg, false); } diff --git a/src/options.def.h b/src/options.def.h index 8a85751..cb4480f 100644 --- a/src/options.def.h +++ b/src/options.def.h @@ -40,6 +40,7 @@ OPTION_ARG(option_on_pre_up, "--on-pre-up", "<command>", "Sets a shell command t OPTION_ARG(option_on_up, "--on-up", "<command>", "Sets a shell command to execute after interface creation"); OPTION_ARG(option_on_down, "--on-down", "<command>", "Sets a shell command to execute before interface destruction"); OPTION_ARG(option_on_post_down, "--on-post-down", "<command>", "Sets a shell command to execute after interface destruction"); +OPTION_ARG(option_on_connect, "--on-connect", "<command>", "Sets a shell command to execute when a handshake is sent to establish a new connection"); OPTION_ARG(option_on_establish, "--on-establish", "<command>", "Sets a shell command to execute when a new connection is established"); OPTION_ARG(option_on_disestablish, "--on-disestablish", "<command>", "Sets a shell command to execute when a connection is lost"); OPTION_ARG(option_on_verify, "--on-verify", "<command>", "Sets a shell command to execute to check a connection attempt by an unknown peer"); diff --git a/src/protocols/ec25519_fhmqvc/handshake.c b/src/protocols/ec25519_fhmqvc/handshake.c index 6de47ef..27cb843 100644 --- a/src/protocols/ec25519_fhmqvc/handshake.c +++ b/src/protocols/ec25519_fhmqvc/handshake.c @@ -533,6 +533,9 @@ void fastd_protocol_ec25519_fhmqvc_handshake_init(fastd_context_t *ctx, const fa fastd_handshake_add(ctx, &buffer, RECORD_SENDER_HANDSHAKE_KEY, PUBLICKEYBYTES, &ctx->protocol_state->handshake_key.key.public); + if (!peer || !fastd_peer_is_established(peer)) + fastd_shell_command_exec(ctx, &ctx->conf->on_connect, peer, (local_addr && local_addr->sa.sa_family) ? local_addr : sock->bound_addr, remote_addr, NULL); + fastd_send_handshake(ctx, sock, local_addr, remote_addr, peer, buffer); } |