From aadf0a94b436990202cd2f13f1fe8528a9fd183c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Thu, 29 Mar 2012 01:28:55 +0200 Subject: Implement on-up commands; also fix log print conditions --- src/fastd.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/fastd.c') diff --git a/src/fastd.c b/src/fastd.c index 423c8c2..2311ba8 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -24,6 +24,8 @@ */ +#define _GNU_SOURCE + #include "fastd.h" #include "handshake.h" #include "peer.h" @@ -69,6 +71,8 @@ static void init_tuntap(fastd_context *ctx) { if (ioctl(ctx->tunfd, TUNSETIFF, (void *)&ifr) < 0) exit_errno(ctx, "TUNSETIFF ioctl failed"); + ctx->ifname = strdup(ifr.ifr_name); + pr_debug(ctx, "Tun/tap device initialized."); } @@ -113,6 +117,24 @@ static void init_socket(fastd_context *ctx) { } } +static void on_up(fastd_context *ctx) { + if (!ctx->conf->on_up) + return; + + char *cwd = get_current_dir_name(); + chdir(ctx->conf->on_up_dir); + + setenv("INTERFACE", ctx->ifname, 1); + int ret = system(ctx->conf->on_up); + + if (WIFSIGNALED(ret)) + pr_error(ctx, "on-up command exited with signal %i", WTERMSIG(ret)); + else if(ret) + pr_warn(ctx, "on-up command exited with status %i", WEXITSTATUS(ret)); + + chdir(cwd); +} + static void init_peers(fastd_context *ctx) { fastd_peer_config *peer_conf; for (peer_conf = ctx->conf->peers; peer_conf; peer_conf = peer_conf->next) { @@ -400,6 +422,8 @@ int main(int argc, char *argv[]) { init_tuntap(&ctx); init_socket(&ctx); + on_up(&ctx); + while (1) { handle_tasks(&ctx); handle_input(&ctx); -- cgit v1.2.3