summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fastd.c34
-rw-r--r--src/fastd.h27
-rw-r--r--src/peer.c16
3 files changed, 43 insertions, 34 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();
diff --git a/src/fastd.h b/src/fastd.h
index f05fe47..dc4f04d 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -542,33 +542,6 @@ static inline bool fastd_allow_verify(void) {
#endif
}
-
-/** Calls the on-pre-up command */
-static inline void fastd_on_pre_up(void) {
- fastd_shell_command_exec(&conf.on_pre_up, NULL);
-}
-
-/** Calls the on-up command */
-static inline void fastd_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 fastd_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 fastd_on_post_down(void) {
- fastd_shell_command_exec(&conf.on_post_down, NULL);
-}
-
/** Returns true if android integration is enabled */
static inline bool fastd_use_android_integration(void) {
#ifdef __ANDROID__
diff --git a/src/peer.c b/src/peer.c
index f4b2bae..307d9b6 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -118,6 +118,16 @@ void fastd_peer_exec_shell_command(const fastd_shell_command_t *command, const f
fastd_shell_env_free(env);
}
+/** Calls the on-up command */
+static inline void on_up(const fastd_peer_t *peer) {
+ fastd_peer_exec_shell_command(&conf.on_up, peer, NULL, NULL);
+}
+
+/** Calls the on-down command */
+static inline void on_down(const fastd_peer_t *peer) {
+ fastd_peer_exec_shell_command(&conf.on_down, peer, NULL, NULL);
+}
+
/** Executes the on-establish command for a peer */
static inline void on_establish(const fastd_peer_t *peer) {
fastd_peer_exec_shell_command(&conf.on_establish, peer, &peer->local_address, &peer->address);
@@ -316,7 +326,7 @@ static void reset_peer(fastd_peer_t *peer) {
if (!conf.iface_persist || peer->config_state == CONFIG_DISABLED) {
if (peer->iface && peer->iface->peer) {
- fastd_on_down(peer->iface);
+ on_down(peer);
fastd_iface_close(peer->iface);
}
@@ -403,7 +413,7 @@ static void setup_peer(fastd_peer_t *peer) {
peer->iface = fastd_iface_open(ifname, peer);
if (peer->iface)
- fastd_on_up(peer->iface);
+ on_up(peer);
else if (!peer->config_source_dir)
/* Fail for statically configured peers;
an error message has already been printed by fastd_iface_open() */
@@ -465,7 +475,7 @@ static void delete_peer(fastd_peer_t *peer) {
conf.protocol->free_peer_state(peer);
if (peer->iface && peer->iface->peer) {
- fastd_on_down(peer->iface);
+ on_down(peer);
fastd_iface_close(peer->iface);
}