X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Froute.c;h=43d26972a6465af91f8d868c4dd0805b5c0aece7;hb=46a5aa0d674914f4220d8583b1b2f87c7f05a804;hp=1d0c6f8a40efc15560bdade6fec92450ddbb35b4;hpb=1be7dc759a64d436fd7586aad43b545f2dc665b5;p=tinc diff --git a/src/route.c b/src/route.c index 1d0c6f8a..43d26972 100644 --- a/src/route.c +++ b/src/route.c @@ -1,7 +1,7 @@ /* route.c -- routing Copyright (C) 2000-2005 Ivo Timmermans, - 2000-2012 Guus Sliepen + 2000-2013 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -229,7 +229,7 @@ static void learn_mac(mac_t *address) { subnet = new_subnet(); subnet->type = SUBNET_MAC; - subnet->expires = time(NULL) + macexpire; + subnet->expires = now.tv_sec + macexpire; subnet->net.mac.address = *address; subnet->weight = 10; subnet_add(myself, subnet); @@ -244,7 +244,7 @@ static void learn_mac(mac_t *address) { timeout_add(&age_subnets_timeout, age_subnets, NULL, &(struct timeval){10, rand() % 100000}); } else { if(subnet->expires) - subnet->expires = time(NULL) + macexpire; + subnet->expires = now.tv_sec + macexpire; } } @@ -371,7 +371,10 @@ static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet, length_t et } } -static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) { +static void route_ipv4(node_t *source, vpn_packet_t *packet) { + if(!checklength(source, packet, ether_size + ip_size)) + return; + subnet_t *subnet; node_t *via; ipv4_t dest; @@ -391,6 +394,11 @@ static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) { return; } + if (!subnet->owner) { + broadcast_packet(source, packet); + return; + } + if(subnet->owner == source) { logger(DEBUG_TRAFFIC, LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname); return; @@ -432,20 +440,6 @@ static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) { send_packet(subnet->owner, packet); } -static void route_ipv4(node_t *source, vpn_packet_t *packet) { - if(!checklength(source, packet, ether_size + ip_size)) - return; - - if(broadcast_mode && (((packet->data[30] & 0xf0) == 0xe0) || ( - packet->data[30] == 255 && - packet->data[31] == 255 && - packet->data[32] == 255 && - packet->data[33] == 255))) - broadcast_packet(source, packet); - else - route_ipv4_unicast(source, packet); -} - /* RFC 2463 */ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, length_t ether_size, uint8_t type, uint8_t code) { @@ -526,7 +520,17 @@ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, length_ send_packet(source, packet); } -static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) { +static void route_neighborsol(node_t *source, vpn_packet_t *packet); + +static void route_ipv6(node_t *source, vpn_packet_t *packet) { + if(!checklength(source, packet, ether_size + ip6_size)) + return; + + if(packet->data[20] == IPPROTO_ICMPV6 && checklength(source, packet, ether_size + ip6_size + icmp6_size) && packet->data[54] == ND_NEIGHBOR_SOLICIT) { + route_neighborsol(source, packet); + return; + } + subnet_t *subnet; node_t *via; ipv6_t dest; @@ -550,6 +554,11 @@ static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) { return; } + if (!subnet->owner) { + broadcast_packet(source, packet); + return; + } + if(subnet->owner == source) { logger(DEBUG_TRAFFIC, LOG_WARNING, "Packet looping back to %s (%s)!", source->name, source->hostname); return; @@ -724,21 +733,6 @@ static void route_neighborsol(node_t *source, vpn_packet_t *packet) { send_packet(source, packet); } -static void route_ipv6(node_t *source, vpn_packet_t *packet) { - if(!checklength(source, packet, ether_size + ip6_size)) - return; - - if(packet->data[20] == IPPROTO_ICMPV6 && checklength(source, packet, ether_size + ip6_size + icmp6_size) && packet->data[54] == ND_NEIGHBOR_SOLICIT) { - route_neighborsol(source, packet); - return; - } - - if(broadcast_mode && packet->data[38] == 255) - broadcast_packet(source, packet); - else - route_ipv6_unicast(source, packet); -} - /* RFC 826 */ static void route_arp(node_t *source, vpn_packet_t *packet) { @@ -822,7 +816,7 @@ static void route_mac(node_t *source, vpn_packet_t *packet) { memcpy(&dest, &packet->data[0], sizeof dest); subnet = lookup_subnet_mac(NULL, &dest); - if(!subnet) { + if(!subnet || !subnet->owner) { broadcast_packet(source, packet); return; }