summaryrefslogtreecommitdiffstats
path: root/src/fastd.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-03-23 06:30:10 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-03-23 06:30:10 +0100
commit69fc8268d0a17cf3b86b327a78e302f049c194e1 (patch)
treed4bdd69b06c1025a3d14a45b292f572a09ba0c8f /src/fastd.c
parente2402e41eb0e914078d860273bd7cf8c526664c6 (diff)
downloadfastd-69fc8268d0a17cf3b86b327a78e302f049c194e1.tar
fastd-69fc8268d0a17cf3b86b327a78e302f049c194e1.zip
peer: set peer name in on-up environment for peer-specific interfaces
Diffstat (limited to 'src/fastd.c')
-rw-r--r--src/fastd.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/fastd.c b/src/fastd.c
index fd6f19e..19fa10f 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -205,6 +205,32 @@ static void close_sockets(void) {
free(ctx.socks);
}
+/** Calls the on-pre-up command */
+static inline void on_pre_up(void) {
+ fastd_shell_command_exec(&conf.on_pre_up, NULL);
+}
+
+/** Calls the on-up command */
+static inline void on_up(fastd_iface_t *iface) {
+ fastd_shell_env_t *env = fastd_shell_env_alloc();
+ fastd_shell_env_set_iface(env, iface);
+ fastd_shell_command_exec(&conf.on_up, env);
+ fastd_shell_env_free(env);
+}
+
+/** Calls the on-down command */
+static inline void on_down(fastd_iface_t *iface) {
+ fastd_shell_env_t *env = fastd_shell_env_alloc();
+ fastd_shell_env_set_iface(env, iface);
+ fastd_shell_command_exec(&conf.on_down, env);
+ fastd_shell_env_free(env);
+}
+
+/** Calls the on-post-down command */
+static inline void on_post_down(void) {
+ fastd_shell_command_exec(&conf.on_post_down, NULL);
+}
+
/** Closes all open FDs except stdin, stdout and stderr */
void fastd_close_all_fds(void) {
@@ -498,7 +524,7 @@ static inline void init(int argc, char *argv[]) {
if (!fastd_socket_handle_binds())
exit_error("unable to bind default socket");
- fastd_on_pre_up();
+ on_pre_up();
if (conf.mode == MODE_TAP || fastd_use_android_integration()) {
ctx.iface = fastd_iface_open(conf.ifname, NULL);
@@ -526,7 +552,7 @@ static inline void init(int argc, char *argv[]) {
drop_caps();
if (ctx.iface)
- fastd_on_up(ctx.iface);
+ on_up(ctx.iface);
fastd_configure_peers();
@@ -628,7 +654,7 @@ static inline void cleanup(void) {
delete_peers();
if (ctx.iface) {
- fastd_on_down(ctx.iface);
+ on_down(ctx.iface);
fastd_iface_close(ctx.iface);
}
@@ -636,7 +662,7 @@ static inline void cleanup(void) {
close_sockets();
fastd_poll_free();
- fastd_on_post_down();
+ on_post_down();
fastd_peer_hashtable_free();