From: Guus Sliepen Date: Fri, 18 Apr 2014 19:16:59 +0000 (+0200) Subject: Remove legacy Ethernet header from vpn_packet_t, add a flag for PMTU probes. X-Git-Url: https://git.meshlink.io/?a=commitdiff_plain;h=11bf251190cb84a9d127bd8b940279413c5313b4;p=meshlink Remove legacy Ethernet header from vpn_packet_t, add a flag for PMTU probes. --- diff --git a/src/libmeshlink.c b/src/libmeshlink.c index e900dd11..f85f32e8 100644 --- a/src/libmeshlink.c +++ b/src/libmeshlink.c @@ -411,21 +411,19 @@ bool tinc_stop(); bool tinc_send_packet(node_t *receiver, const char* buf, unsigned int len) { vpn_packet_t packet; - tincpackethdr* hdr = malloc(sizeof(tincpackethdr)); + tincpackethdr* hdr = (tincpackethdr *)packet.data; if (sizeof(tincpackethdr) + len > MAXSIZE) { //log something return false; } - memset(hdr->legacymtu,1,sizeof(hdr->legacymtu)); + packet.probe = false; + memset(hdr, 0, sizeof *hdr); memcpy(hdr->destination,receiver->name,sizeof(hdr->destination)); memcpy(hdr->source,myself->name,sizeof(hdr->source)); - packet.priority = 0; packet.len = sizeof(tincpackethdr) + len; - - memcpy(packet.data,hdr,sizeof(tincpackethdr)); memcpy(packet.data+sizeof(tincpackethdr),buf,len); myself->in_packets++; diff --git a/src/libmeshlink.h b/src/libmeshlink.h index 0cbfec7e..471a90db 100644 --- a/src/libmeshlink.h +++ b/src/libmeshlink.h @@ -46,7 +46,6 @@ bool tinc_start(const char* path); bool tinc_stop(); typedef struct tincpackethdr { - u_int8_t legacymtu[14]; u_int8_t destination[16]; u_int8_t source[16]; } __attribute__ ((__packed__)) tincpackethdr; diff --git a/src/net.h b/src/net.h index 3454a96d..453fa74b 100644 --- a/src/net.h +++ b/src/net.h @@ -67,9 +67,11 @@ typedef union sockaddr_t { #endif typedef struct vpn_packet_t { + struct { + unsigned int probe:1; + unsigned int tcp:1; + }; length_t len; /* the actual number of bytes in the `data' field */ - int priority; /* priority or TOS */ - uint32_t seqno; /* 32 bits sequence number (network byte order of course) */ uint8_t data[MAXSIZE]; } vpn_packet_t; diff --git a/src/net_packet.c b/src/net_packet.c index 583835b9..5631a939 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -131,7 +131,6 @@ static void send_mtu_probe_handler(void *data) { memset(packet.data, 0, 14); randomize(packet.data + 14, len - 14); packet.len = len; - packet.priority = 0; n->status.broadcast = i >= 4 && n->mtuprobes <= 10 && n->prevedge; logger(DEBUG_TRAFFIC, LOG_INFO, "Sending MTU probe length %d to %s (%s)", len, n->name, n->hostname); @@ -285,16 +284,10 @@ static void receive_packet(node_t *n, vpn_packet_t *packet) { } static bool try_mac(node_t *n, const vpn_packet_t *inpkt) { - return sptps_verify_datagram(&n->sptps, (char *)&inpkt->seqno, inpkt->len); + return sptps_verify_datagram(&n->sptps, inpkt->data, inpkt->len); } static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) { - vpn_packet_t pkt1, pkt2; - vpn_packet_t *pkt[] = { &pkt1, &pkt2, &pkt1, &pkt2 }; - int nextpkt = 0; - vpn_packet_t *outpkt = pkt[0]; - size_t outlen; - if(!n->sptps.state) { if(!n->status.waitingforkey) { logger(DEBUG_TRAFFIC, LOG_DEBUG, "Got packet from %s (%s) but we haven't exchanged keys yet", n->name, n->hostname); @@ -304,7 +297,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) { } return; } - sptps_receive_data(&n->sptps, (char *)&inpkt->seqno, inpkt->len); + sptps_receive_data(&n->sptps, inpkt->data, inpkt->len); } void receive_tcppacket(connection_t *c, const char *buffer, int len) { @@ -314,10 +307,7 @@ void receive_tcppacket(connection_t *c, const char *buffer, int len) { return; outpkt.len = len; - if(c->options & OPTION_TCPONLY) - outpkt.priority = 0; - else - outpkt.priority = -1; + outpkt.tcp = true; memcpy(outpkt.data, buffer, len); receive_packet(c->node, &outpkt); @@ -339,9 +329,9 @@ static void send_sptps_packet(node_t *n, vpn_packet_t *origpkt) { uint8_t type = 0; - // TODO: use a better way to signal that this is a PMTU probe - if(!(origpkt->data[12] | origpkt->data[13])) { - sptps_send_record(&n->sptps, PKT_PROBE, (char *)origpkt->data, origpkt->len); + // If it's a probe, send it immediately without trying to compress it. + if(origpkt->probe) { + sptps_send_record(&n->sptps, PKT_PROBE, origpkt->data, origpkt->len); return; } @@ -358,7 +348,7 @@ static void send_sptps_packet(node_t *n, vpn_packet_t *origpkt) { } } - sptps_send_record(&n->sptps, type, (char *)origpkt->data, origpkt->len); + sptps_send_record(&n->sptps, type, origpkt->data, origpkt->len); return; } @@ -458,10 +448,6 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { vpn_packet_t *outpkt; int origlen = origpkt->len; size_t outlen; -#if defined(SOL_IP) && defined(IP_TOS) - static int priority = 0; -#endif - int origpriority = origpkt->priority; if(!n->status.reachable) { logger(DEBUG_TRAFFIC, LOG_INFO, "Trying to send UDP packet to unreachable node %s (%s)", n->name, n->hostname); @@ -535,9 +521,12 @@ bool receive_sptps_record(void *handle, uint8_t type, const char *data, uint16_t if(type == PKT_PROBE) { inpkt.len = len; + inpkt.probe = true; memcpy(inpkt.data, data, len); mtu_probe_h(from, &inpkt, len); return true; + } else { + inpkt.probe = false; } if(type & ~(PKT_COMPRESSED)) { @@ -645,7 +634,7 @@ void handle_incoming_vpn_data(void *data, int flags) { node_t *n; int len; - len = recvfrom(ls->udp.fd, (char *) &pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen); + len = recvfrom(ls->udp.fd, pkt.data, MAXSIZE, 0, &from.sa, &fromlen); if(len <= 0 || len > MAXSIZE) { if(!sockwouldblock(sockerrno)) diff --git a/src/route.c b/src/route.c index 8a952a78..a8516d07 100644 --- a/src/route.c +++ b/src/route.c @@ -73,8 +73,8 @@ void route(node_t *source,vpn_packet_t *packet) { if (owner == myself ) { //TODO: implement sending received data from meshlink library to the application - logger(DEBUG_TRAFFIC, LOG_WARNING, "I received a packet for me with payload: %s \n", packet->data + 46); - (recv_callback)(packet->data + 46); + logger(DEBUG_TRAFFIC, LOG_WARNING, "I received a packet for me with payload: %s \n", packet->data + sizeof *hdr); + (recv_callback)(packet->data + sizeof *hdr); return; }