diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-05-27 04:53:38 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-05-27 04:53:38 +0200 |
commit | e90be1577d672068878118fc61fab75e3028b56f (patch) | |
tree | c6b154f25da7ff9e6d81b7a4313599233f678cbd /src/send.c | |
parent | a0e0e9898a7c1abeb4dbf6ba188a9bcaf523e003 (diff) | |
download | fastd-e90be1577d672068878118fc61fab75e3028b56f.tar fastd-e90be1577d672068878118fc61fab75e3028b56f.zip |
Move tuntap handling out of poll.c
Diffstat (limited to 'src/send.c')
-rw-r--r-- | src/send.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -197,3 +197,34 @@ void fastd_send_all(fastd_peer_t *source_peer, fastd_buffer_t buffer) { fastd_buffer_free(buffer); } + +static inline bool send_data_tap_single(fastd_buffer_t buffer) { + if (conf.mode != MODE_TAP) + return false; + + if (buffer.len < ETH_HLEN) { + pr_debug("truncated packet on tap interface"); + fastd_buffer_free(buffer); + return true; + } + + fastd_eth_addr_t dest_addr = fastd_get_dest_address(buffer); + if (!fastd_eth_addr_is_unicast(dest_addr)) + return false; + + fastd_peer_t *peer = fastd_peer_find_by_eth_addr(dest_addr); + + if (!peer) + return false; + + conf.protocol->send(peer, buffer); + return true; +} + +void fastd_send_data(fastd_buffer_t buffer) { + if (send_data_tap_single(buffer)) + return; + + /* TUN mode or multicast packet */ + fastd_send_all(NULL, buffer); +} |