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);
send_mtu_probe_handler(n);
}
-static void mtu_probe_h(node_t *n, vpn_packet_t *packet, length_t len) {
+static void mtu_probe_h(node_t *n, vpn_packet_t *packet, uint16_t len) {
logger(DEBUG_TRAFFIC, LOG_INFO, "Got MTU probe length %d from %s (%s)", packet->len, n->name, n->hostname);
if(!packet->data[0]) {
}
}
-static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) {
+static uint16_t compress_packet(uint8_t *dest, const uint8_t *source, uint16_t len, int level) {
if(level == 0) {
memcpy(dest, source, len);
return len;
return -1;
}
-static length_t uncompress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) {
+static uint16_t uncompress_packet(uint8_t *dest, const uint8_t *source, uint16_t len, int level) {
if(level == 0) {
memcpy(dest, source, len);
return len;
}
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);
}
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) {
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);
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;
}
}
}
- sptps_send_record(&n->sptps, type, (char *)origpkt->data, origpkt->len);
+ sptps_send_record(&n->sptps, type, origpkt->data, origpkt->len);
return;
}
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);
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)) {
}
if(type & PKT_COMPRESSED) {
- length_t ulen = uncompress_packet(inpkt.data, (const uint8_t *)data, len, from->incompression);
+ uint16_t ulen = uncompress_packet(inpkt.data, (const uint8_t *)data, len, from->incompression);
if(ulen < 0) {
return false;
} else {
logger(DEBUG_TRAFFIC, LOG_INFO, "Broadcasting packet of %d bytes from %s (%s)",
packet->len, from->name, from->hostname);
- switch(broadcast_mode) {
- // In MST mode, broadcast packets travel via the Minimum Spanning Tree.
- // This guarantees all nodes receive the broadcast packet, and
- // usually distributes the sending of broadcast packets over all nodes.
- case BMODE_MST:
- for list_each(connection_t, c, connection_list)
- if(c->status.active && c->status.mst && c != from->nexthop->connection)
- send_packet(c->node, packet);
- break;
-
- // In direct mode, we send copies to each node we know of.
- // However, this only reaches nodes that can be reached in a single hop.
- // We don't have enough information to forward broadcast packets in this case.
- case BMODE_DIRECT:
- if(from != myself)
- break;
-
- for splay_each(node_t, n, node_tree)
- if(n->status.reachable && n != myself && ((n->via == myself && n->nexthop == n) || n->via == n))
- send_packet(n, packet);
- break;
-
- default:
- break;
- }
+ for list_each(connection_t, c, connection_list)
+ if(c->status.active && c->status.mst && c != from->nexthop->connection)
+ send_packet(c->node, packet);
}
static node_t *try_harder(const sockaddr_t *from, const vpn_packet_t *pkt) {
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))