summaryrefslogtreecommitdiffstats
path: root/src/receive.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-05-27 22:33:41 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-05-27 22:33:41 +0200
commitadb7453fae67c777974e1d4c1a5f80f2378c61c3 (patch)
tree8fe97aa750de693c2b6d4d7ae2303fd27764375a /src/receive.c
parent073357bec4e65da17a30411798476e4abc81bf9d (diff)
downloadfastd-adb7453fae67c777974e1d4c1a5f80f2378c61c3.tar
fastd-adb7453fae67c777974e1d4c1a5f80f2378c61c3.zip
Merge handle_forward into fastd_send_data
Diffstat (limited to 'src/receive.c')
-rw-r--r--src/receive.c26
1 files changed, 7 insertions, 19 deletions
diff --git a/src/receive.c b/src/receive.c
index e5c1aeb..6009030 100644
--- a/src/receive.c
+++ b/src/receive.c
@@ -223,23 +223,11 @@ void fastd_receive(fastd_socket_t *sock) {
handle_socket_receive(sock, &local_addr, &recvaddr, buffer);
}
-static inline void handle_forward(fastd_peer_t *source_peer, fastd_buffer_t buffer) {
- fastd_eth_addr_t dest_addr = fastd_get_dest_address(buffer);
-
- if (fastd_eth_addr_is_unicast(dest_addr)) {
- fastd_peer_t *dest_peer = fastd_peer_find_by_eth_addr(dest_addr);
-
- if (dest_peer) {
- if (dest_peer != source_peer)
- conf.protocol->send(dest_peer, buffer);
- else
- fastd_buffer_free(buffer);
-
- return;
- }
- }
-
- fastd_send_all(source_peer, buffer);
+/** Returns the source address of an ethernet packet */
+static inline fastd_eth_addr_t get_source_address(const fastd_buffer_t buffer) {
+ fastd_eth_addr_t ret;
+ memcpy(&ret, buffer.data+offsetof(struct ethhdr, h_source), ETH_ALEN);
+ return ret;
}
/** Handles a received and decrypted payload packet */
@@ -251,7 +239,7 @@ void fastd_handle_receive(fastd_peer_t *peer, fastd_buffer_t buffer) {
return;
}
- fastd_eth_addr_t src_addr = fastd_get_source_address(buffer);
+ fastd_eth_addr_t src_addr = get_source_address(buffer);
if (fastd_eth_addr_is_unicast(src_addr))
fastd_peer_eth_addr_add(peer, src_addr);
@@ -263,7 +251,7 @@ void fastd_handle_receive(fastd_peer_t *peer, fastd_buffer_t buffer) {
fastd_tuntap_write(buffer);
if (conf.mode == MODE_TAP && conf.forward) {
- handle_forward(peer, buffer);
+ fastd_send_data(buffer, peer);
return;
}