|
@@ -361,7 +361,7 @@ static Iface_DEFUN requestForAddresses(Dict* request,
|
|
|
|
|
|
if (conn->isOutgoing) {
|
|
|
Log_warn(context->logger, "got request for addresses from outgoing connection");
|
|
|
- return Error(INVALID);
|
|
|
+ return Rffi_error("INVALID", requestAlloc);
|
|
|
}
|
|
|
Dict* addresses = Dict_new(requestAlloc);
|
|
|
bool noAddresses = true;
|
|
@@ -396,7 +396,7 @@ static Iface_DEFUN requestForAddresses(Dict* request,
|
|
|
if (noAddresses) {
|
|
|
Log_warn(context->logger, "no addresses to provide");
|
|
|
// The message is ok, this one is our fault
|
|
|
- return Error(NONE);
|
|
|
+ return NULL;
|
|
|
}
|
|
|
|
|
|
Dict* msg = Dict_new(requestAlloc);
|
|
@@ -408,7 +408,7 @@ static Iface_DEFUN requestForAddresses(Dict* request,
|
|
|
}
|
|
|
|
|
|
sendControlMessage(msg, conn, requestAlloc, context);
|
|
|
- return Error(NONE);
|
|
|
+ return NULL;
|
|
|
}
|
|
|
|
|
|
static void addAddress(char* printedAddr, uint8_t prefixLen,
|
|
@@ -456,20 +456,20 @@ static Iface_DEFUN incomingAddresses(Dict* d,
|
|
|
{
|
|
|
if (!conn->isOutgoing) {
|
|
|
Log_warn(context->logger, "got offer of addresses from incoming connection");
|
|
|
- return Error(INVALID);
|
|
|
+ return Rffi_error("INVALID", alloc);
|
|
|
}
|
|
|
|
|
|
String* txid = Dict_getStringC(d, "txid");
|
|
|
if (!txid || txid->len != 4) {
|
|
|
Log_info(context->logger, "missing or wrong length txid");
|
|
|
- return Error(INVALID);
|
|
|
+ return Rffi_error("INVALID", alloc);
|
|
|
}
|
|
|
|
|
|
int number;
|
|
|
Bits_memcpy(&number, txid->bytes, 4);
|
|
|
if (number < 0 || number >= (int)context->nextConnectionNumber) {
|
|
|
Log_info(context->logger, "txid out of range");
|
|
|
- return Error(INVALID);
|
|
|
+ return Rffi_error("INVALID", alloc);
|
|
|
}
|
|
|
|
|
|
if (number != conn->number) {
|
|
@@ -480,7 +480,7 @@ static Iface_DEFUN incomingAddresses(Dict* d,
|
|
|
32))
|
|
|
{
|
|
|
Log_info(context->logger, "txid doesn't match origin");
|
|
|
- return Error(INVALID);
|
|
|
+ return Rffi_error("INVALID", alloc);
|
|
|
} else {
|
|
|
conn = &context->pub.connectionList.connections[i];
|
|
|
}
|
|
@@ -557,16 +557,16 @@ static Iface_DEFUN incomingAddresses(Dict* d,
|
|
|
String* tunName = GlobalConfig_getTunName(context->globalConf);
|
|
|
if (!tunName) {
|
|
|
Log_error(context->logger, "Failed to set routes because TUN interface is not setup");
|
|
|
- return Error(INVALID);
|
|
|
+ return Rffi_error("INVALID", alloc);
|
|
|
}
|
|
|
struct Er_Ret* er = NULL;
|
|
|
Er_check(&er, RouteGen_commit(context->rg, tunName->bytes, alloc));
|
|
|
if (er) {
|
|
|
Log_error(context->logger, "Error setting routes for TUN [%s]", er->message);
|
|
|
- return Error(INVALID);
|
|
|
+ return Rffi_error("INVALID", alloc);
|
|
|
}
|
|
|
}
|
|
|
- return Error(NONE);
|
|
|
+ return NULL;
|
|
|
}
|
|
|
|
|
|
static Iface_DEFUN incomingControlMessage(struct Message* message,
|
|
@@ -581,7 +581,7 @@ static Iface_DEFUN incomingControlMessage(struct Message* message,
|
|
|
|
|
|
// This aligns the message on the content.
|
|
|
if (isControlMessageInvalid(message, context)) {
|
|
|
- return Error(INVALID);
|
|
|
+ return Error(message, "INVALID");
|
|
|
}
|
|
|
|
|
|
Log_debug(context->logger, "Message content [%s]",
|
|
@@ -593,7 +593,7 @@ static Iface_DEFUN incomingControlMessage(struct Message* message,
|
|
|
const char* err = BencMessageReader_readNoExcept(message, alloc, &d);
|
|
|
if (err) {
|
|
|
Log_info(context->logger, "Failed to parse message [%s]", err);
|
|
|
- return Error(INVALID);
|
|
|
+ return Error(message, "INVALID");
|
|
|
}
|
|
|
|
|
|
if (Dict_getDictC(d, "addresses")) {
|
|
@@ -605,7 +605,7 @@ static Iface_DEFUN incomingControlMessage(struct Message* message,
|
|
|
return requestForAddresses(d, conn, alloc, context);
|
|
|
}
|
|
|
Log_warn(context->logger, "Message which is unhandled");
|
|
|
- return Error(INVALID);
|
|
|
+ return Error(message, "INVALID");
|
|
|
}
|
|
|
|
|
|
#define GET64(buffer) \
|
|
@@ -699,7 +699,7 @@ static Iface_DEFUN incomingFromTun(struct Message* message, struct Iface* tunIf)
|
|
|
|
|
|
if (Message_getLength(message) < 20) {
|
|
|
Log_debug(context->logger, "DROP runt");
|
|
|
- return Error(RUNT);
|
|
|
+ return Error(message, "RUNT");
|
|
|
}
|
|
|
|
|
|
struct IpTunnel_Connection* conn = NULL;
|
|
@@ -713,12 +713,12 @@ static Iface_DEFUN incomingFromTun(struct Message* message, struct Iface* tunIf)
|
|
|
conn = findConnection(NULL, header->sourceAddr, true, context);
|
|
|
} else {
|
|
|
Log_debug(context->logger, "Message of unknown type from TUN");
|
|
|
- return Error(INVALID);
|
|
|
+ return Error(message, "INVALID");
|
|
|
}
|
|
|
|
|
|
if (!conn) {
|
|
|
Log_debug(context->logger, "Message with unrecognized address from TUN");
|
|
|
- return Error(INVALID);
|
|
|
+ return Error(message, "INVALID");
|
|
|
}
|
|
|
|
|
|
return sendToNode(message, conn, context);
|
|
@@ -734,13 +734,13 @@ static Iface_DEFUN ip6FromNode(struct Message* message,
|
|
|
return incomingControlMessage(message, conn, context);
|
|
|
}
|
|
|
Log_debug(context->logger, "Got message with zero address");
|
|
|
- return Error(INVALID);
|
|
|
+ return Error(message, "INVALID");
|
|
|
}
|
|
|
if (!isValidAddress6(header->sourceAddr, false, conn)) {
|
|
|
uint8_t addr[40];
|
|
|
AddrTools_printIp(addr, header->sourceAddr);
|
|
|
Log_debug(context->logger, "Got message with wrong address for connection [%s]", addr);
|
|
|
- return Error(INVALID);
|
|
|
+ return Error(message, "INVALID");
|
|
|
}
|
|
|
|
|
|
Er_assert(TUNMessageType_push(message, Ethernet_TYPE_IP6));
|
|
@@ -754,7 +754,7 @@ static Iface_DEFUN ip4FromNode(struct Message* message,
|
|
|
struct Headers_IP4Header* header = (struct Headers_IP4Header*) message->msgbytes;
|
|
|
if (Bits_isZero(header->sourceAddr, 4) || Bits_isZero(header->destAddr, 4)) {
|
|
|
Log_debug(context->logger, "Got message with zero address");
|
|
|
- return Error(INVALID);
|
|
|
+ return Error(message, "INVALID");
|
|
|
} else if (!isValidAddress4(header->sourceAddr, false, conn)) {
|
|
|
Log_debug(context->logger, "Got message with wrong address [%d.%d.%d.%d] for connection "
|
|
|
"[%d.%d.%d.%d/%d:%d]",
|
|
@@ -763,7 +763,7 @@ static Iface_DEFUN ip4FromNode(struct Message* message,
|
|
|
conn->connectionIp4[0], conn->connectionIp4[1],
|
|
|
conn->connectionIp4[2], conn->connectionIp4[3],
|
|
|
conn->connectionIp4Alloc, conn->connectionIp4Prefix);
|
|
|
- return Error(INVALID);
|
|
|
+ return Error(message, "INVALID");
|
|
|
}
|
|
|
|
|
|
Er_assert(TUNMessageType_push(message, Ethernet_TYPE_IP4));
|
|
@@ -788,7 +788,7 @@ static Iface_DEFUN incomingFromNode(struct Message* message, struct Iface* nodeI
|
|
|
AddrTools_printIp(addr, rh->ip6);
|
|
|
Log_debug(context->logger, "Got message from unrecognized node [%s]", addr);
|
|
|
}
|
|
|
- return Error(NONE);
|
|
|
+ return NULL;
|
|
|
}
|
|
|
|
|
|
Er_assert(Message_eshift(message, -(RouteHeader_SIZE + DataHeader_SIZE)));
|
|
@@ -809,7 +809,7 @@ static Iface_DEFUN incomingFromNode(struct Message* message, struct Iface* nodeI
|
|
|
(Message_getLength(message) > 1) ? Headers_getIpVersion(message->msgbytes) : 0,
|
|
|
addr);
|
|
|
}
|
|
|
- return Error(INVALID);
|
|
|
+ return Error(message, "INVALID");
|
|
|
}
|
|
|
|
|
|
static void timeout(void* vcontext)
|