X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet_packet.c;h=84b2707d21e6780e8ce7930e68a1a1d2d681af5c;hb=531d5a904a3a91bca8b7d373fb6ab2869b31e7fa;hp=31e18b470fd552f1c53f3dd51586f0feb82c15a9;hpb=de78d79db84c486afcc353884ec1770866beb653;p=tinc diff --git a/src/net_packet.c b/src/net_packet.c index 31e18b47..84b2707d 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -29,14 +29,13 @@ #include #include -#include +#include LZO1X_H #include "avl_tree.h" #include "conf.h" #include "connection.h" #include "device.h" #include "ethernet.h" -#include "event.h" #include "graph.h" #include "list.h" #include "logger.h" @@ -61,15 +60,14 @@ static void send_udppacket(node_t *, vpn_packet_t *); #define MAX_SEQNO 1073741824 -void send_mtu_probe(node_t *n) -{ +static void send_mtu_probe_handler(int fd, short events, void *data) { + node_t *n = data; vpn_packet_t packet; int len, i; cp(); n->mtuprobes++; - n->mtuevent = NULL; if(n->mtuprobes >= 10 && !n->minmtu) { ifdebug(TRAFFIC) logger(LOG_INFO, _("No response to MTU probes from %s (%s)"), n->name, n->hostname); @@ -96,11 +94,13 @@ void send_mtu_probe(node_t *n) send_udppacket(n, &packet); } - n->mtuevent = xmalloc(sizeof(*n->mtuevent)); - n->mtuevent->handler = (event_handler_t)send_mtu_probe; - n->mtuevent->data = n; - n->mtuevent->time = now + 1; - event_add(n->mtuevent); + event_add(&n->mtuevent, &(struct timeval){1, 0}); +} + +void send_mtu_probe(node_t *n) { + if(!timeout_initialized(&n->mtuevent)) + timeout_set(&n->mtuevent, send_mtu_probe_handler, n); + send_mtu_probe_handler(0, 0, n); } void mtu_probe_h(node_t *n, vpn_packet_t *packet) { @@ -285,10 +285,11 @@ void receive_tcppacket(connection_t *c, char *buffer, int len) receive_packet(c->node, &outpkt); } -static void send_udppacket(node_t *n, vpn_packet_t *inpkt) +static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { vpn_packet_t pkt1, pkt2; vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 }; + vpn_packet_t *inpkt = origpkt; int nextpkt = 0; vpn_packet_t *outpkt; int origlen; @@ -404,7 +405,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *inpkt) } end: - inpkt->len = origlen; + origpkt->len = origlen; } /* @@ -457,11 +458,8 @@ void broadcast_packet(const node_t *from, vpn_packet_t *packet) ifdebug(TRAFFIC) logger(LOG_INFO, _("Broadcasting packet of %d bytes from %s (%s)"), packet->len, from->name, from->hostname); - if(from != myself) { - if(overwrite_mac) - memcpy(packet->data, mymac.x, ETH_ALEN); - write_packet(packet); - } + if(from != myself) + send_packet(myself, packet); for(node = connection_tree->head; node; node = node->next) { c = node->data; @@ -486,7 +484,7 @@ void flush_queue(node_t *n) } } -void handle_incoming_vpn_data(int sock) +void handle_incoming_vpn_data(int sock, short events, void *data) { vpn_packet_t pkt; char *hostname; @@ -517,3 +515,11 @@ void handle_incoming_vpn_data(int sock) receive_udppacket(n, &pkt); } + +void handle_device_data(int sock, short events, void *data) +{ + vpn_packet_t packet; + + if(read_packet(&packet)) + route(myself, &packet); +}