summaryrefslogtreecommitdiffstats
path: root/src/fastd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fastd.c')
-rw-r--r--src/fastd.c22
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);