X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet_packet.c;h=abfb55c411435af0e07d56ab021d9c7c01bbb742;hb=9e76c464b26b066e1eb3aa5232e573792e28020d;hp=69199a723dd2e770d3e7ab833cfb9471a586731f;hpb=8af2f3f5a4061a8dbfd4f7d259e0038df06a373e;p=tinc diff --git a/src/net_packet.c b/src/net_packet.c index 69199a72..abfb55c4 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -643,6 +643,14 @@ bool receive_sptps_record(void *handle, uint8_t type, const char *data, uint16_t return false; } + /* Check if we have the headers we need */ + if(routing_mode != RMODE_ROUTER && !(type & PKT_MAC)) { + logger(DEBUG_TRAFFIC, LOG_ERR, "Received packet from %s (%s) without MAC header (maybe Mode is not set correctly)", from->name, from->hostname); + return false; + } else if(routing_mode == RMODE_ROUTER && (type & PKT_MAC)) { + logger(DEBUG_TRAFFIC, LOG_WARNING, "Received packet from %s (%s) with MAC header (maybe Mode is not set correctly)", from->name, from->hostname); + } + int offset = (type & PKT_MAC) ? 0 : 14; if(type & PKT_COMPRESSED) { len = uncompress_packet(inpkt.data + offset, (const uint8_t *)data, len, from->incompression); @@ -658,6 +666,25 @@ bool receive_sptps_record(void *handle, uint8_t type, const char *data, uint16_t inpkt.len = len + offset; } + /* Generate the Ethernet packet type if necessary */ + if(offset) { + switch(inpkt.data[14] >> 4) { + case 4: + inpkt.data[12] = 0x08; + inpkt.data[13] = 0x00; + break; + case 6: + inpkt.data[12] = 0x86; + inpkt.data[13] = 0xDD; + break; + default: + logger(DEBUG_TRAFFIC, LOG_ERR, + "Unknown IP version %d while reading packet from %s (%s)", + inpkt.data[14] >> 4, from->name, from->hostname); + return false; + } + } + receive_packet(from, &inpkt); return true; } @@ -746,7 +773,7 @@ void broadcast_packet(const node_t *from, vpn_packet_t *packet) { if(from != myself) break; - for(node = node_udp_tree->head; node; node = node->next) { + for(node = node_tree->head; node; node = node->next) { n = node->data; if(n->status.reachable && ((n->via == myself && n->nexthop == n) || n->via == n)) @@ -770,7 +797,7 @@ static node_t *try_harder(const sockaddr_t *from, const vpn_packet_t *pkt) { for(node = edge_weight_tree->head; node; node = node->next) { e = node->data; - if(e->to == myself) + if(!e->to->status.reachable || e->to == myself) continue; if(sockaddrcmp_noport(from, &e->address)) { @@ -796,7 +823,7 @@ static node_t *try_harder(const sockaddr_t *from, const vpn_packet_t *pkt) { void handle_incoming_vpn_data(int sock, short events, void *data) { vpn_packet_t pkt; char *hostname; - sockaddr_t from; + sockaddr_t from = {{0}}; socklen_t fromlen = sizeof from; node_t *n; int len;