diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-29 01:28:55 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-29 01:28:55 +0200 |
commit | aadf0a94b436990202cd2f13f1fe8528a9fd183c (patch) | |
tree | 87f5dd658b0503a4c33489e051b6a1b9dd0d85c1 /src/fastd.c | |
parent | 63e123738a9636618421d35ff97a278c06b69703 (diff) | |
download | fastd-aadf0a94b436990202cd2f13f1fe8528a9fd183c.tar fastd-aadf0a94b436990202cd2f13f1fe8528a9fd183c.zip |
Implement on-up commands; also fix log print conditions
Diffstat (limited to 'src/fastd.c')
-rw-r--r-- | src/fastd.c | 24 |
1 files changed, 24 insertions, 0 deletions
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); |