3 Copyright (C) 2000-2005 Ivo Timmermans,
4 2000-2013 Guus Sliepen <guus@tinc-vpn.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "libmeshlink.h"
29 rmode_t routing_mode = RMODE_ROUTER;
30 fmode_t forwarding_mode = FMODE_INTERNAL;
31 bmode_t broadcast_mode = BMODE_MST;
32 bool decrement_ttl = false;
33 bool directonly = false;
34 bool priorityinheritance = false;
36 bool overwrite_mac = false;
37 mac_t mymac = {{0xFE, 0xFD, 0, 0, 0, 0}};
40 static bool ratelimit(int frequency) {
41 static time_t lasttime = 0;
44 if(lasttime == now.tv_sec) {
45 if(count >= frequency)
48 lasttime = now.tv_sec;
56 static bool checklength(node_t *source, vpn_packet_t *packet, length_t length) {
57 if(packet->len < length) {
58 logger(DEBUG_TRAFFIC, LOG_WARNING, "Got too short packet from %s (%s)", source->name, source->hostname);
64 void route(node_t *source,vpn_packet_t *packet) {
65 // TODO: route on name or key
68 tincpackethdr* hdr = (tincpackethdr*)packet->data;
69 owner = lookup_node(hdr->destination);
72 logger(DEBUG_TRAFFIC, LOG_WARNING, "Cant lookup the owner of a packet in the route() function. This should never happen \n");
76 if (owner == myself ) {
77 //TODO: implement sending received data from meshlink library to the application
78 logger(DEBUG_TRAFFIC, LOG_WARNING, "I received a packet for me with payload: %s \n", packet->data + 46);
82 if(!owner->status.reachable) {
83 //TODO: check what to do here, not just print a warning
84 logger(DEBUG_TRAFFIC, LOG_WARNING, "The owner of a packet in the route() function is unreachable. Dropping packet. \n");
88 //TODO: I skipped here a lot of checks !
90 send_packet(owner,packet);