mirror of
https://github.com/neocturne/fastd.git
synced 2025-05-14 12:25:07 +02:00
peer: set peer name in on-up environment for peer-specific interfaces
This commit is contained in:
parent
e2402e41eb
commit
69fc8268d0
3 changed files with 43 additions and 34 deletions
34
src/fastd.c
34
src/fastd.c
|
@ -205,6 +205,32 @@ static void close_sockets(void) {
|
||||||
free(ctx.socks);
|
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 */
|
/** Closes all open FDs except stdin, stdout and stderr */
|
||||||
void fastd_close_all_fds(void) {
|
void fastd_close_all_fds(void) {
|
||||||
|
@ -498,7 +524,7 @@ static inline void init(int argc, char *argv[]) {
|
||||||
if (!fastd_socket_handle_binds())
|
if (!fastd_socket_handle_binds())
|
||||||
exit_error("unable to bind default socket");
|
exit_error("unable to bind default socket");
|
||||||
|
|
||||||
fastd_on_pre_up();
|
on_pre_up();
|
||||||
|
|
||||||
if (conf.mode == MODE_TAP || fastd_use_android_integration()) {
|
if (conf.mode == MODE_TAP || fastd_use_android_integration()) {
|
||||||
ctx.iface = fastd_iface_open(conf.ifname, NULL);
|
ctx.iface = fastd_iface_open(conf.ifname, NULL);
|
||||||
|
@ -526,7 +552,7 @@ static inline void init(int argc, char *argv[]) {
|
||||||
drop_caps();
|
drop_caps();
|
||||||
|
|
||||||
if (ctx.iface)
|
if (ctx.iface)
|
||||||
fastd_on_up(ctx.iface);
|
on_up(ctx.iface);
|
||||||
|
|
||||||
fastd_configure_peers();
|
fastd_configure_peers();
|
||||||
|
|
||||||
|
@ -628,7 +654,7 @@ static inline void cleanup(void) {
|
||||||
delete_peers();
|
delete_peers();
|
||||||
|
|
||||||
if (ctx.iface) {
|
if (ctx.iface) {
|
||||||
fastd_on_down(ctx.iface);
|
on_down(ctx.iface);
|
||||||
fastd_iface_close(ctx.iface);
|
fastd_iface_close(ctx.iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -636,7 +662,7 @@ static inline void cleanup(void) {
|
||||||
close_sockets();
|
close_sockets();
|
||||||
fastd_poll_free();
|
fastd_poll_free();
|
||||||
|
|
||||||
fastd_on_post_down();
|
on_post_down();
|
||||||
|
|
||||||
fastd_peer_hashtable_free();
|
fastd_peer_hashtable_free();
|
||||||
|
|
||||||
|
|
27
src/fastd.h
27
src/fastd.h
|
@ -542,33 +542,6 @@ static inline bool fastd_allow_verify(void) {
|
||||||
#endif
|
#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 */
|
/** Returns true if android integration is enabled */
|
||||||
static inline bool fastd_use_android_integration(void) {
|
static inline bool fastd_use_android_integration(void) {
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
|
|
16
src/peer.c
16
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);
|
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 */
|
/** Executes the on-establish command for a peer */
|
||||||
static inline void on_establish(const fastd_peer_t *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);
|
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 (!conf.iface_persist || peer->config_state == CONFIG_DISABLED) {
|
||||||
if (peer->iface && peer->iface->peer) {
|
if (peer->iface && peer->iface->peer) {
|
||||||
fastd_on_down(peer->iface);
|
on_down(peer);
|
||||||
fastd_iface_close(peer->iface);
|
fastd_iface_close(peer->iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,7 +413,7 @@ static void setup_peer(fastd_peer_t *peer) {
|
||||||
|
|
||||||
peer->iface = fastd_iface_open(ifname, peer);
|
peer->iface = fastd_iface_open(ifname, peer);
|
||||||
if (peer->iface)
|
if (peer->iface)
|
||||||
fastd_on_up(peer->iface);
|
on_up(peer);
|
||||||
else if (!peer->config_source_dir)
|
else if (!peer->config_source_dir)
|
||||||
/* Fail for statically configured peers;
|
/* Fail for statically configured peers;
|
||||||
an error message has already been printed by fastd_iface_open() */
|
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);
|
conf.protocol->free_peer_state(peer);
|
||||||
|
|
||||||
if (peer->iface && peer->iface->peer) {
|
if (peer->iface && peer->iface->peer) {
|
||||||
fastd_on_down(peer->iface);
|
on_down(peer);
|
||||||
fastd_iface_close(peer->iface);
|
fastd_iface_close(peer->iface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue