diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-03-23 19:04:49 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-03-23 19:04:49 +0100 |
commit | 45d573ab617136670223de5e271f8e7398007c1c (patch) | |
tree | dee4d89c4646f9497dcd61ac4fe900371071a076 /src | |
parent | 1602e36635ad9523ae7dc4f7ab93b6a89b8741fd (diff) | |
download | fastd-45d573ab617136670223de5e271f8e7398007c1c.tar fastd-45d573ab617136670223de5e271f8e7398007c1c.zip |
Move ifname logic from peer to iface
Diffstat (limited to 'src')
-rw-r--r-- | src/fastd.c | 2 | ||||
-rw-r--r-- | src/fastd.h | 2 | ||||
-rw-r--r-- | src/iface.c | 14 | ||||
-rw-r--r-- | src/peer.c | 15 |
4 files changed, 16 insertions, 17 deletions
diff --git a/src/fastd.c b/src/fastd.c index 5ac1967..0d4f577 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -527,7 +527,7 @@ static inline void init(int argc, char *argv[]) { on_pre_up(); if (conf.mode == MODE_TAP || fastd_use_android_integration()) { - ctx.iface = fastd_iface_open(conf.ifname, NULL); + ctx.iface = fastd_iface_open(NULL); if (!ctx.iface) exit(1); /* An error message has already been printed by fastd_iface_open() */ } diff --git a/src/fastd.h b/src/fastd.h index dc4f04d..fa29bf0 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -371,7 +371,7 @@ bool fastd_android_protect_socket(int fd); void fastd_resolve_peer(fastd_peer_t *peer, fastd_remote_t *remote); -fastd_iface_t * fastd_iface_open(const char *ifname, fastd_peer_t *peer); +fastd_iface_t * fastd_iface_open(fastd_peer_t *peer); void fastd_iface_handle(fastd_iface_t *iface); void fastd_iface_write(fastd_iface_t *iface, fastd_buffer_t buffer); void fastd_iface_close(fastd_iface_t *iface); diff --git a/src/iface.c b/src/iface.c index d7caa30..6cad96d 100644 --- a/src/iface.c +++ b/src/iface.c @@ -33,7 +33,8 @@ Management of the TUN/TAP interface */ -#include "fastd.h" +#include "config.h" +#include "peer.h" #include "poll.h" #include <net/if.h> @@ -462,10 +463,19 @@ void fastd_iface_write(fastd_iface_t *iface, fastd_buffer_t buffer) { } /** Opens a new TUN/TAP interface, optionally associated with a specific peer */ -fastd_iface_t * fastd_iface_open(const char *ifname, fastd_peer_t *peer) { +fastd_iface_t * fastd_iface_open(fastd_peer_t *peer) { fastd_iface_t *iface = fastd_new(fastd_iface_t); iface->peer = peer; + const char *ifname = conf.ifname; + + if (peer) { + if (peer->ifname) + ifname = peer->ifname; + else if (!fastd_config_single_iface()) + ifname = NULL; + } + pr_debug("initializing TUN/TAP device..."); open_iface(iface, ifname); @@ -30,7 +30,6 @@ */ #include "peer.h" -#include "config.h" #include "peer_hashtable.h" #include "poll.h" @@ -411,12 +410,7 @@ static void setup_peer(fastd_peer_t *peer) { peer->iface = ctx.iface; } else if (conf.iface_persist && !peer->iface && !fastd_peer_is_dynamic(peer)) { - const char *ifname = peer->ifname; - - if (!ifname && fastd_config_single_iface()) - ifname = conf.ifname; - - peer->iface = fastd_iface_open(ifname, peer); + peer->iface = fastd_iface_open(peer); if (peer->iface) on_up(peer, true); else if (!peer->config_source_dir) @@ -879,12 +873,7 @@ bool fastd_peer_set_established(fastd_peer_t *peer) { return true; if (!peer->iface) { - const char *ifname = peer->ifname; - - if (!ifname && fastd_config_single_iface()) - ifname = conf.ifname; - - peer->iface = fastd_iface_open(ifname, peer); + peer->iface = fastd_iface_open(peer); if (peer->iface) on_up(peer, false); else |