summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.c10
-rw-r--r--src/config.h2
-rw-r--r--src/config.y7
-rw-r--r--src/peer.c8
-rw-r--r--src/peer.h3
5 files changed, 27 insertions, 3 deletions
diff --git a/src/config.c b/src/config.c
index 1fff240..7cc983e 100644
--- a/src/config.c
+++ b/src/config.c
@@ -576,6 +576,16 @@ void fastd_config_check(void) {
configure_methods();
}
+bool fastd_config_single_iface(void) {
+ if (conf.mode == MODE_TAP)
+ return true;
+
+ if (has_peer_group_peer_dirs(conf.peer_group))
+ return false;
+
+ return (VECTOR_LEN(ctx.peers) == 1);
+}
+
/** Performs the verify-config checks */
void fastd_config_verify(void) {
config_check_base();
diff --git a/src/config.h b/src/config.h
index 60be363..b96247f 100644
--- a/src/config.h
+++ b/src/config.h
@@ -63,4 +63,4 @@ void fastd_configure(int argc, char *const argv[]);
void fastd_configure_peers(void);
void fastd_config_check(void);
void fastd_config_load_peer_dirs(bool dirs_only);
-
+bool fastd_config_single_iface(void);
diff --git a/src/config.y b/src/config.y
index f2f597f..12beb4b 100644
--- a/src/config.y
+++ b/src/config.y
@@ -460,6 +460,7 @@ peer_conf: peer_conf peer_statement
peer_statement: TOK_REMOTE peer_remote ';'
| TOK_FLOAT peer_float ';'
| TOK_KEY peer_key ';'
+ | TOK_INTERFACE peer_interface ';'
| TOK_INCLUDE peer_include ';'
;
@@ -524,6 +525,12 @@ peer_key: TOK_STRING {
}
;
+peer_interface: TOK_STRING {
+ free(state->peer->ifname);
+ state->peer->ifname = fastd_strdup($1->str);
+ }
+ ;
+
peer_include: TOK_STRING {
if (!fastd_config_read($1->str, state->peer_group, state->peer, state->depth))
YYERROR;
diff --git a/src/peer.c b/src/peer.c
index 5bcc030..9964559 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -30,6 +30,7 @@
*/
#include "peer.h"
+#include "config.h"
#include "peer_hashtable.h"
#include "poll.h"
@@ -382,7 +383,12 @@ static void setup_peer(fastd_peer_t *peer) {
peer->iface = ctx.iface;
}
else if (conf.iface_persist && !peer->iface) {
- peer->iface = fastd_iface_open(conf.ifname, peer);
+ const char *ifname = peer->ifname;
+
+ if (!ifname && fastd_config_single_iface())
+ ifname = conf.ifname;
+
+ peer->iface = fastd_iface_open(ifname, peer);
if (peer->iface)
fastd_on_up(peer->iface);
else if (!peer->config_source_dir)
diff --git a/src/peer.h b/src/peer.h
index 631957e..1aff6cf 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -72,10 +72,11 @@ struct fastd_peer {
fastd_protocol_key_t *key; /**< The peer's public key */
fastd_protocol_peer_state_t *protocol_state; /**< Protocol-specific peer state */
- fastd_iface_t *iface; /**< The interface this peer is associated with */
+ char *ifname; /**< Peer-specific interface name */
/* Starting here, more dynamic fields follow: */
+ fastd_iface_t *iface; /**< The interface this peer is associated with */
/** The socket used by the peer. This can either be a common bound socket or a
dynamic, unbound socket that is used exclusively by this peer */
fastd_socket_t *sock;