summaryrefslogtreecommitdiffstats
path: root/src/receive.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-05-22 02:16:44 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-05-22 02:16:44 +0200
commit09f525417c6c3d778c9e2811f8a4ffcb7bbf68fb (patch)
tree2f6e9ec0fede0c42c5ecaa667347b72442d68e05 /src/receive.c
parent47d84679d6fe71f56d3a013578007dff92ff72db (diff)
downloadfastd-09f525417c6c3d778c9e2811f8a4ffcb7bbf68fb.tar
fastd-09f525417c6c3d778c9e2811f8a4ffcb7bbf68fb.zip
Move fastd_handle_receive() to receive.c
Diffstat (limited to 'src/receive.c')
-rw-r--r--src/receive.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/receive.c b/src/receive.c
index 4ebd185..8fd5bf8 100644
--- a/src/receive.c
+++ b/src/receive.c
@@ -221,3 +221,49 @@ 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);
+}
+
+void fastd_handle_receive(fastd_peer_t *peer, fastd_buffer_t buffer) {
+ if (conf.mode == MODE_TAP) {
+ if (buffer.len < ETH_HLEN) {
+ pr_debug("received truncated packet");
+ fastd_buffer_free(buffer);
+ return;
+ }
+
+ fastd_eth_addr_t src_addr = fastd_get_source_address(buffer);
+
+ if (fastd_eth_addr_is_unicast(src_addr))
+ fastd_peer_eth_addr_add(peer, src_addr);
+ }
+
+ ctx.rx.packets++;
+ ctx.rx.bytes += buffer.len;
+
+ fastd_tuntap_write(buffer);
+
+ if (conf.mode == MODE_TAP && conf.forward) {
+ handle_forward(peer, buffer);
+ return;
+ }
+
+ fastd_buffer_free(buffer);
+}