diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-03-23 04:40:56 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-03-23 04:40:56 +0100 |
commit | a5a7b233b728f6d26a9f593f0a47265465522f4b (patch) | |
tree | 55994836c4dc15c98c344345004c025e812c2282 /src | |
parent | c162b223b8965490839b4d56701a8f37d5304a71 (diff) | |
download | fastd-a5a7b233b728f6d26a9f593f0a47265465522f4b.tar fastd-a5a7b233b728f6d26a9f593f0a47265465522f4b.zip |
peer: make interface name configurable per peer
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 10 | ||||
-rw-r--r-- | src/config.h | 2 | ||||
-rw-r--r-- | src/config.y | 7 | ||||
-rw-r--r-- | src/peer.c | 8 | ||||
-rw-r--r-- | src/peer.h | 3 |
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; @@ -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) @@ -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; |