|
@@ -18,12 +18,13 @@
|
|
|
#include "util/Identity.h"
|
|
|
#include "wire/SwitchHeader.h"
|
|
|
#include "wire/DataHeader.h"
|
|
|
-#include "net/BalingWire.h"
|
|
|
+#include "net/SessionManager.h"
|
|
|
#include "wire/ContentType.h"
|
|
|
#include "wire/Headers.h"
|
|
|
#include "util/Checksum.h"
|
|
|
+#include "wire/RouteHeader.h"
|
|
|
|
|
|
-#include "util/Hex.h"
|
|
|
+//#include "util/Hex.h"
|
|
|
|
|
|
struct ConverterV15_pvt
|
|
|
{
|
|
@@ -35,7 +36,7 @@ struct ConverterV15_pvt
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
- * Incoming packet with a BalingWire header followed by a ContentHeader and then whatever
|
|
|
+ * Incoming packet with a SessionManager header followed by a ContentHeader and then whatever
|
|
|
* content.
|
|
|
*/
|
|
|
static int incomingFromUpperDistributorIf(struct Interface_Two* upperDistributorIf,
|
|
@@ -44,13 +45,17 @@ static int incomingFromUpperDistributorIf(struct Interface_Two* upperDistributor
|
|
|
struct ConverterV15_pvt* conv =
|
|
|
Identity_containerOf(upperDistributorIf, struct ConverterV15_pvt, pub.upperDistributorIf);
|
|
|
|
|
|
- Assert_true(msg->length >= DataHeader_SIZE + BalingWire_InsideHeader_SIZE);
|
|
|
+ Assert_true(msg->length >= DataHeader_SIZE + RouteHeader_SIZE);
|
|
|
|
|
|
- struct BalingWire_InsideHeader* hdr = (struct BalingWire_InsideHeader*) msg->bytes;
|
|
|
+ struct RouteHeader* hdr = (struct RouteHeader*) msg->bytes;
|
|
|
struct SessionTable_Session* sess = SessionTable_sessionForIp6(hdr->ip6, conv->sm);
|
|
|
- if (!hdr->version && (!sess->version || sess->version > 15)) {
|
|
|
- // If nothing is known about a node, fuckit, assume it's new !
|
|
|
- return Interface_send(&conv->pub.balingWireIf, msg);
|
|
|
+ if (hdr->version_be && Endian_bigEndianToHost32(hdr->version_be) < 16) {
|
|
|
+ // definitely old
|
|
|
+ } else if (!hdr->version_be && sess->version && sess->version < 16) {
|
|
|
+ // session thinks it's old
|
|
|
+ } else {
|
|
|
+ // nothing is known about a node, fuckit, assume it's new !
|
|
|
+ return Interface_send(&conv->pub.sessionManagerIf, msg);
|
|
|
}
|
|
|
|
|
|
struct DataHeader* dh = (struct DataHeader*) &hdr[1];
|
|
@@ -64,7 +69,7 @@ static int incomingFromUpperDistributorIf(struct Interface_Two* upperDistributor
|
|
|
// My fears, come alive, in this place where I once died
|
|
|
// daemons dreamin', goin' eyed, I just needed to
|
|
|
// RE-ALIGN
|
|
|
- Message_shift(msg, -(DataHeader_SIZE + BalingWire_InsideHeader_SIZE), NULL);
|
|
|
+ Message_shift(msg, -(DataHeader_SIZE + RouteHeader_SIZE), NULL);
|
|
|
if (type == ContentType_CJDHT) {
|
|
|
// push a udp header and then an ip header and then checksum the udp
|
|
|
Message_shift(msg, Headers_UDPHeader_SIZE, NULL);
|
|
@@ -72,13 +77,13 @@ static int incomingFromUpperDistributorIf(struct Interface_Two* upperDistributor
|
|
|
if (type != ContentType_IPTUN) {
|
|
|
Message_shift(msg, Headers_IP6Header_SIZE, NULL);
|
|
|
}
|
|
|
- Message_shift(msg, BalingWire_InsideHeader_SIZE, NULL);
|
|
|
- Bits_memmove(msg->bytes, hdr, BalingWire_InsideHeader_SIZE);
|
|
|
- hdr = (struct BalingWire_InsideHeader*) msg->bytes;
|
|
|
+ Message_shift(msg, RouteHeader_SIZE, NULL);
|
|
|
+ Bits_memmove(msg->bytes, hdr, RouteHeader_SIZE);
|
|
|
+ hdr = (struct RouteHeader*) msg->bytes;
|
|
|
|
|
|
|
|
|
if (type == ContentType_IPTUN) {
|
|
|
- return Interface_send(&conv->pub.balingWireIf, msg);
|
|
|
+ return Interface_send(&conv->pub.sessionManagerIf, msg);
|
|
|
}
|
|
|
|
|
|
struct Headers_IP6Header* ip6 = (struct Headers_IP6Header*) &hdr[1];
|
|
@@ -87,7 +92,7 @@ static int incomingFromUpperDistributorIf(struct Interface_Two* upperDistributor
|
|
|
ip6->hopLimit = 42;
|
|
|
ip6->nextHeader = type;
|
|
|
ip6->payloadLength_be = Endian_hostToBigEndian16(
|
|
|
- msg->length - BalingWire_InsideHeader_SIZE - Headers_IP6Header_SIZE);
|
|
|
+ msg->length - RouteHeader_SIZE - Headers_IP6Header_SIZE);
|
|
|
Bits_memcpyConst(ip6->destinationAddr, hdr->ip6, 16);
|
|
|
Bits_memcpyConst(ip6->sourceAddr, conv->myIp6, 16);
|
|
|
|
|
@@ -97,31 +102,31 @@ static int incomingFromUpperDistributorIf(struct Interface_Two* upperDistributor
|
|
|
udp->srcPort_be = 0;
|
|
|
udp->destPort_be = 0;
|
|
|
udp->length_be = Endian_hostToBigEndian16(msg->length -
|
|
|
- BalingWire_InsideHeader_SIZE -
|
|
|
+ RouteHeader_SIZE -
|
|
|
Headers_IP6Header_SIZE -
|
|
|
Headers_UDPHeader_SIZE);
|
|
|
udp->checksum_be = 0;
|
|
|
udp->checksum_be =
|
|
|
Checksum_udpIp6(ip6->sourceAddr,
|
|
|
(uint8_t*) udp,
|
|
|
- msg->length - BalingWire_InsideHeader_SIZE - Headers_IP6Header_SIZE);
|
|
|
+ msg->length - RouteHeader_SIZE - Headers_IP6Header_SIZE);
|
|
|
|
|
|
Log_debug(conv->log, "Converted CJDHT->v15");
|
|
|
}
|
|
|
|
|
|
//Log_debug(conv->log, "send [%s]", Hex_print(ip6, 32, msg->alloc));
|
|
|
|
|
|
- return Interface_send(&conv->pub.balingWireIf, msg);
|
|
|
+ return Interface_send(&conv->pub.sessionManagerIf, msg);
|
|
|
}
|
|
|
|
|
|
//// --------------- Incoming, convert v15 to v16 --------------- ////
|
|
|
|
|
|
#define tryConvertDHT_OVERHEAD \
|
|
|
- (BalingWire_InsideHeader_SIZE + Headers_IP6Header_SIZE + Headers_UDPHeader_SIZE)
|
|
|
+ (RouteHeader_SIZE + Headers_IP6Header_SIZE + Headers_UDPHeader_SIZE)
|
|
|
static inline bool tryConvertDHT(struct Message* msg, struct Headers_IP6Header* ip6)
|
|
|
{
|
|
|
if (msg->length < tryConvertDHT_OVERHEAD) { return false; }
|
|
|
- struct BalingWire_InsideHeader* bih = (struct BalingWire_InsideHeader*) msg->bytes;
|
|
|
+ struct RouteHeader* bih = (struct RouteHeader*) msg->bytes;
|
|
|
struct Headers_UDPHeader* udp = (struct Headers_UDPHeader*) &ip6[1];
|
|
|
if (udp->srcPort_be || udp->destPort_be) { return false; }
|
|
|
Message_shift(msg, -tryConvertDHT_OVERHEAD, NULL);
|
|
@@ -130,32 +135,32 @@ static inline bool tryConvertDHT(struct Message* msg, struct Headers_IP6Header*
|
|
|
.versionAndFlags = DataHeader_CURRENT_VERSION << 4
|
|
|
};
|
|
|
Message_push(msg, &dh, DataHeader_SIZE, NULL);
|
|
|
- Message_shift(msg, BalingWire_InsideHeader_SIZE, NULL);
|
|
|
- Bits_memmoveConst(msg->bytes, bih, BalingWire_InsideHeader_SIZE);
|
|
|
+ Message_shift(msg, RouteHeader_SIZE, NULL);
|
|
|
+ Bits_memmoveConst(msg->bytes, bih, RouteHeader_SIZE);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Incoming packet with a BalingWire header and under that either an ipv6 or ipv4 header
|
|
|
+ * Incoming packet with a SessionManager header and under that either an ipv6 or ipv4 header
|
|
|
* depending on whether it's destine for TUN/DHT or IpTunnel.
|
|
|
*/
|
|
|
-static int incomingFromBalingWireIf(struct Interface_Two* balingWireIf, struct Message* msg)
|
|
|
+static int incomingFromSessionManagerIf(struct Interface_Two* sessionManagerIf, struct Message* msg)
|
|
|
{
|
|
|
struct ConverterV15_pvt* conv =
|
|
|
- Identity_containerOf(balingWireIf, struct ConverterV15_pvt, pub.balingWireIf);
|
|
|
+ Identity_containerOf(sessionManagerIf, struct ConverterV15_pvt, pub.sessionManagerIf);
|
|
|
|
|
|
- Log_debug(conv->log, "incomingFromBalingWireIf");
|
|
|
+ Log_debug(conv->log, "incomingFromSessionManagerIf");
|
|
|
|
|
|
- if (msg->length < BalingWire_InsideHeader_SIZE + 8) {
|
|
|
+ if (msg->length < RouteHeader_SIZE + 8) {
|
|
|
Log_debug(conv->log, "DROP runt");
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- struct BalingWire_InsideHeader* bih = (struct BalingWire_InsideHeader*) msg->bytes;
|
|
|
+ struct RouteHeader* bih = (struct RouteHeader*) msg->bytes;
|
|
|
|
|
|
uint8_t* ipPtr = (uint8_t*) &bih[1];
|
|
|
|
|
|
- Log_debug(conv->log, "recv [%s]", Hex_print(ipPtr, 32, msg->alloc));
|
|
|
+ //Log_debug(conv->log, "recv [%s]", Hex_print(ipPtr, 32, msg->alloc));
|
|
|
|
|
|
int ipVer = Headers_getIpVersion(ipPtr);
|
|
|
if (ipVer == DataHeader_CURRENT_VERSION) {
|
|
@@ -164,7 +169,7 @@ static int incomingFromBalingWireIf(struct Interface_Two* balingWireIf, struct M
|
|
|
}
|
|
|
|
|
|
if (ipVer == 6) {
|
|
|
- if (msg->length < BalingWire_InsideHeader_SIZE + Headers_IP6Header_SIZE) {
|
|
|
+ if (msg->length < RouteHeader_SIZE + Headers_IP6Header_SIZE) {
|
|
|
Log_debug(conv->log, "DROP runt");
|
|
|
return 0;
|
|
|
}
|
|
@@ -175,14 +180,14 @@ static int incomingFromBalingWireIf(struct Interface_Two* balingWireIf, struct M
|
|
|
return Interface_send(&conv->pub.upperDistributorIf, msg);
|
|
|
}
|
|
|
Log_debug(conv->log, "tryConvertDHT(fail)");
|
|
|
- Message_pop(msg, NULL, BalingWire_InsideHeader_SIZE + Headers_IP6Header_SIZE, NULL);
|
|
|
+ Message_pop(msg, NULL, RouteHeader_SIZE + Headers_IP6Header_SIZE, NULL);
|
|
|
struct DataHeader dh = {
|
|
|
.contentType_be = Endian_hostToBigEndian16(ip6->nextHeader),
|
|
|
.versionAndFlags = DataHeader_CURRENT_VERSION << 4
|
|
|
};
|
|
|
Message_push(msg, &dh, DataHeader_SIZE, NULL);
|
|
|
- Message_shift(msg, BalingWire_InsideHeader_SIZE, NULL);
|
|
|
- Bits_memmoveConst(msg->bytes, bih, BalingWire_InsideHeader_SIZE);
|
|
|
+ Message_shift(msg, RouteHeader_SIZE, NULL);
|
|
|
+ Bits_memmoveConst(msg->bytes, bih, RouteHeader_SIZE);
|
|
|
return Interface_send(&conv->pub.upperDistributorIf, msg);
|
|
|
}
|
|
|
Log_debug(conv->log, "iptunnel?");
|
|
@@ -192,9 +197,9 @@ static int incomingFromBalingWireIf(struct Interface_Two* balingWireIf, struct M
|
|
|
}
|
|
|
|
|
|
Message_shift(msg, DataHeader_SIZE, NULL);
|
|
|
- Bits_memmoveConst(msg->bytes, bih, BalingWire_InsideHeader_SIZE);
|
|
|
+ Bits_memmoveConst(msg->bytes, bih, RouteHeader_SIZE);
|
|
|
|
|
|
- bih = (struct BalingWire_InsideHeader*) msg->bytes;
|
|
|
+ bih = (struct RouteHeader*) msg->bytes;
|
|
|
ipPtr = (uint8_t*) &bih[1];
|
|
|
|
|
|
struct DataHeader* dh = (struct DataHeader*) &bih[1];
|
|
@@ -211,7 +216,7 @@ struct ConverterV15* ConverterV15_new(struct Allocator* alloc,
|
|
|
{
|
|
|
struct ConverterV15_pvt* out = Allocator_calloc(alloc, sizeof(struct ConverterV15_pvt), 1);
|
|
|
out->pub.upperDistributorIf.send = incomingFromUpperDistributorIf;
|
|
|
- out->pub.balingWireIf.send = incomingFromBalingWireIf;
|
|
|
+ out->pub.sessionManagerIf.send = incomingFromSessionManagerIf;
|
|
|
out->log = log;
|
|
|
out->sm = sm;
|
|
|
Bits_memcpyConst(out->myIp6, myIp6, 16);
|