summaryrefslogtreecommitdiffstats
path: root/src/fastd.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-03-23 01:40:35 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-03-23 01:40:35 +0100
commit0e8493ea17c1bba64ee0de588bdbad7fdb6fd9ba (patch)
treeff1474d41067c45e4d9b2190601e43a03f8aec74 /src/fastd.c
parent08e782b27d47c4b5e74d505aecfee661ff9df4e0 (diff)
downloadfastd-0e8493ea17c1bba64ee0de588bdbad7fdb6fd9ba.tar
fastd-0e8493ea17c1bba64ee0de588bdbad7fdb6fd9ba.zip
Use peer-specific interface in TUN mode
Diffstat (limited to 'src/fastd.c')
-rw-r--r--src/fastd.c43
1 files changed, 11 insertions, 32 deletions
diff --git a/src/fastd.c b/src/fastd.c
index af6d147..6ab07be 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -205,32 +205,6 @@ 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) {
@@ -524,9 +498,10 @@ static inline void init(int argc, char *argv[]) {
if (!fastd_socket_handle_binds())
exit_error("unable to bind default socket");
- on_pre_up();
+ fastd_on_pre_up();
- ctx.iface = fastd_iface_open(NULL);
+ if (conf.mode == MODE_TAP)
+ ctx.iface = fastd_iface_open(NULL);
/* change groups before trying to write the PID file as they can be relevant for file access */
set_groups();
@@ -547,7 +522,9 @@ static inline void init(int argc, char *argv[]) {
if (conf.drop_caps == DROP_CAPS_EARLY)
drop_caps();
- on_up(ctx.iface);
+ if (ctx.iface)
+ fastd_on_up(ctx.iface);
+
fastd_configure_peers();
if (conf.drop_caps == DROP_CAPS_ON)
@@ -647,14 +624,16 @@ static inline void cleanup(void) {
delete_peers();
- on_down(ctx.iface);
- fastd_iface_close(ctx.iface);
+ if (ctx.iface) {
+ fastd_on_down(ctx.iface);
+ fastd_iface_close(ctx.iface);
+ }
fastd_status_close();
close_sockets();
fastd_poll_free();
- on_post_down();
+ fastd_on_post_down();
fastd_peer_hashtable_free();