diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-08-12 18:54:16 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2013-08-12 18:54:16 +0200 |
commit | d468ffff4564ac0d6fb1b13d886ee72785d329ef (patch) | |
tree | 52b54fc5f1e020b928c01228d1be413dd3aa8e74 /src/fastd.c | |
parent | 78de22fd21b348fc00dde6fa0bfec73abb8fd651 (diff) | |
download | fastd-d468ffff4564ac0d6fb1b13d886ee72785d329ef.tar fastd-d468ffff4564ac0d6fb1b13d886ee72785d329ef.zip |
Add pre-up and post-down handlers
Diffstat (limited to 'src/fastd.c')
-rw-r--r-- | src/fastd.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/fastd.c b/src/fastd.c index ed47831..f8a5a75 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -256,6 +256,13 @@ void fastd_handle_receive(fastd_context_t *ctx, fastd_peer_t *peer, fastd_buffer fastd_buffer_free(buffer); } +static inline void on_pre_up(fastd_context_t *ctx) { + if (!ctx->conf->on_pre_up) + return; + + fastd_shell_exec(ctx, ctx->conf->on_pre_up, ctx->conf->on_pre_up_dir, NULL, NULL, NULL, NULL); +} + static inline void on_up(fastd_context_t *ctx) { if (!ctx->conf->on_up) return; @@ -270,6 +277,13 @@ static inline void on_down(fastd_context_t *ctx) { fastd_shell_exec(ctx, ctx->conf->on_down, ctx->conf->on_down_dir, NULL, NULL, NULL, NULL); } +static inline void on_post_down(fastd_context_t *ctx) { + if (!ctx->conf->on_post_down) + return; + + fastd_shell_exec(ctx, ctx->conf->on_post_down, ctx->conf->on_post_down_dir, NULL, NULL, NULL, NULL); +} + static fastd_peer_group_t* init_peer_group(const fastd_peer_group_config_t *config, fastd_peer_group_t *parent) { fastd_peer_group_t *ret = calloc(1, sizeof(fastd_peer_group_t)); @@ -708,8 +722,7 @@ static void drop_caps(fastd_context_t *ctx) { } int main(int argc, char *argv[]) { - fastd_context_t ctx; - memset(&ctx, 0, sizeof(ctx)); + fastd_context_t ctx = {}; close_fds(&ctx); @@ -752,6 +765,8 @@ int main(int argc, char *argv[]) { if (!fastd_socket_handle_binds(&ctx)) exit_error(&ctx, "unable to bind default socket"); + on_pre_up(&ctx); + fastd_tuntap_open(&ctx); init_peer_groups(&ctx); @@ -824,8 +839,11 @@ int main(int argc, char *argv[]) { fastd_tuntap_close(&ctx); close_sockets(&ctx); + on_post_down(&ctx); + free(ctx.protocol_state); free(ctx.eth_addr); + free(ctx.ifname); crypto_free(&ctx); |