summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/fastd.c2
-rw-r--r--src/fastd.h2
-rw-r--r--src/iface.c14
-rw-r--r--src/peer.c15
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);
diff --git a/src/peer.c b/src/peer.c
index 979c074..79a4588 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -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