mirror of
https://github.com/cjdelisle/cjdns
synced 2025-10-06 00:32:50 +02:00
Changed all accesses to Message->msgbytes to Message_bytes() calls in prep for moving Message to Rust.
This commit is contained in:
@@ -131,7 +131,7 @@ static struct RTypes_Error_t* sendBenc(Dict* message,
|
||||
Message_reset(admin->tempSendMsg);
|
||||
Er_assert(BencMessageWriter_write(message, admin->tempSendMsg));
|
||||
struct Message* msg = Message_new(0, Message_getLength(admin->tempSendMsg) + 32, alloc);
|
||||
Er_assert(Message_epush(msg, admin->tempSendMsg->msgbytes, Message_getLength(admin->tempSendMsg)));
|
||||
Er_assert(Message_epush(msg, Message_bytes(admin->tempSendMsg), Message_getLength(admin->tempSendMsg)));
|
||||
Message_setAssociatedFd(msg, fd);
|
||||
return sendMessage(msg, dest, admin);
|
||||
}
|
||||
@@ -234,7 +234,7 @@ static inline bool authValid(Dict* message, struct Message* messageBytes, struct
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t* hashPtr = CString_strstr(messageBytes->msgbytes, submittedHash->bytes);
|
||||
uint8_t* hashPtr = CString_strstr(Message_bytes(messageBytes), submittedHash->bytes);
|
||||
|
||||
if (!hashPtr || !admin->password) {
|
||||
return false;
|
||||
@@ -246,7 +246,7 @@ static inline bool authValid(Dict* message, struct Message* messageBytes, struct
|
||||
crypto_hash_sha256(hash, passAndCookie, CString_strlen((char*) passAndCookie));
|
||||
Hex_encode(hashPtr, 64, hash, 32);
|
||||
|
||||
crypto_hash_sha256(hash, messageBytes->msgbytes, Message_getLength(messageBytes));
|
||||
crypto_hash_sha256(hash, Message_bytes(messageBytes), Message_getLength(messageBytes));
|
||||
Hex_encode(hashPtr, 64, hash, 32);
|
||||
int res = crypto_verify_32(hashPtr, submittedHash->bytes);
|
||||
res |= crypto_verify_32(hashPtr + 32, submittedHash->bytes + 32);
|
||||
@@ -421,18 +421,18 @@ static void handleMessage(struct Message* message,
|
||||
struct Admin_pvt* admin)
|
||||
{
|
||||
if (Defined(Log_KEYS)) {
|
||||
uint8_t lastChar = message->msgbytes[Message_getLength(message) - 1];
|
||||
message->msgbytes[Message_getLength(message) - 1] = '\0';
|
||||
uint8_t lastChar = Message_bytes(message)[Message_getLength(message) - 1];
|
||||
Message_bytes(message)[Message_getLength(message) - 1] = '\0';
|
||||
Log_keys(admin->logger, "Got message from [%s] [%s]",
|
||||
Sockaddr_print(src, alloc), message->msgbytes);
|
||||
message->msgbytes[Message_getLength(message) - 1] = lastChar;
|
||||
Sockaddr_print(src, alloc), Message_bytes(message));
|
||||
Message_bytes(message)[Message_getLength(message) - 1] = lastChar;
|
||||
}
|
||||
|
||||
// handle non empty message data
|
||||
if (Message_getLength(message) > Admin_MAX_REQUEST_SIZE) {
|
||||
#define TOO_BIG "d5:error16:Request too big.e"
|
||||
#define TOO_BIG_STRLEN (sizeof(TOO_BIG) - 1)
|
||||
Bits_memcpy(message->msgbytes, TOO_BIG, TOO_BIG_STRLEN);
|
||||
Bits_memcpy(Message_bytes(message), TOO_BIG, TOO_BIG_STRLEN);
|
||||
Er_assert(Message_truncate(message, TOO_BIG_STRLEN));
|
||||
sendMessage(message, src, admin);
|
||||
return;
|
||||
@@ -445,7 +445,7 @@ static void handleMessage(struct Message* message,
|
||||
Log_warn(admin->logger,
|
||||
"Unparsable data from [%s] content: [%s] error: [%s]",
|
||||
Sockaddr_print(src, alloc),
|
||||
Hex_print(message->msgbytes, Message_getLength(message), alloc),
|
||||
Hex_print(Message_bytes(message), Message_getLength(message), alloc),
|
||||
err);
|
||||
return;
|
||||
}
|
||||
@@ -453,7 +453,7 @@ static void handleMessage(struct Message* message,
|
||||
if (Message_getLength(message)) {
|
||||
Log_warn(admin->logger,
|
||||
"Message from [%s] contained garbage after byte [%d] content: [%s]",
|
||||
Sockaddr_print(src, alloc), Message_getLength(message), message->msgbytes);
|
||||
Sockaddr_print(src, alloc), Message_getLength(message), Message_bytes(message));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,7 @@ struct Context {
|
||||
|
||||
static int getColumn(struct Context* ctx)
|
||||
{
|
||||
return (uintptr_t) ctx->msg->msgbytes - ctx->beginningLastLine;
|
||||
return (uintptr_t) Message_bytes(ctx->msg) - ctx->beginningLastLine;
|
||||
}
|
||||
|
||||
#define ERROR0(ctx, message) \
|
||||
@@ -51,15 +51,15 @@ static int getColumn(struct Context* ctx)
|
||||
static Er_DEFUN(uint8_t peak(struct Context* ctx))
|
||||
{
|
||||
if (!Message_getLength(ctx->msg)) { ERROR0(ctx, "Out of content while reading"); }
|
||||
Er_ret(ctx->msg->msgbytes[0]);
|
||||
Er_ret(Message_bytes(ctx->msg)[0]);
|
||||
}
|
||||
|
||||
static Er_DEFUN(void skip(struct Context* ctx, int num))
|
||||
{
|
||||
if (num > Message_getLength(ctx->msg)) { ERROR0(ctx, "Out of content while reading"); }
|
||||
for (int i = 0; i < num; i++) {
|
||||
if (ctx->msg->msgbytes[i] == '\n') {
|
||||
ctx->beginningLastLine = (uintptr_t) &ctx->msg->msgbytes[i];
|
||||
if (Message_bytes(ctx->msg)[i] == '\n') {
|
||||
ctx->beginningLastLine = (uintptr_t) &Message_bytes(ctx->msg)[i];
|
||||
ctx->line++;
|
||||
}
|
||||
}
|
||||
@@ -314,7 +314,7 @@ Er_DEFUN(Dict* JsonBencMessageReader_read(
|
||||
.alloc = alloc,
|
||||
.lax = lax,
|
||||
.line = 1,
|
||||
.beginningLastLine = (uintptr_t) msg->msgbytes
|
||||
.beginningLastLine = (uintptr_t) Message_bytes(msg)
|
||||
};
|
||||
Er_ret( Er(parseDict(&ctx)) );
|
||||
}
|
||||
|
@@ -90,15 +90,15 @@ Er_DEFUN(void BencMessageWriter_write(Dict* toWrite, struct Message* msg))
|
||||
Er(writeDict(toWrite, msg));
|
||||
|
||||
// lucky
|
||||
if (!((uintptr_t)msg->msgbytes % 8)) { Er_ret(); }
|
||||
if (!((uintptr_t)Message_bytes(msg) % 8)) { Er_ret(); }
|
||||
|
||||
char d = Er(Message_epop8(msg));
|
||||
Assert_true(d == 'd');
|
||||
Assert_true(msg->msgbytes[0] != 'e' && "Can't serialize empty messages");
|
||||
Assert_true(msg->msgbytes[0] >= '1' && msg->msgbytes[0] <= '9');
|
||||
Assert_true(Message_bytes(msg)[0] != 'e' && "Can't serialize empty messages");
|
||||
Assert_true(Message_bytes(msg)[0] >= '1' && Message_bytes(msg)[0] <= '9');
|
||||
|
||||
// put the message into alignment by padding out the number with leading zeros :)
|
||||
do { Er(Message_epush8(msg, '0')); } while ((uintptr_t)msg->msgbytes % 8);
|
||||
do { Er(Message_epush8(msg, '0')); } while ((uintptr_t)Message_bytes(msg) % 8);
|
||||
|
||||
Er(Message_epop8(msg));
|
||||
Er(Message_epush8(msg, 'd'));
|
||||
|
@@ -94,7 +94,7 @@ static int calculateAuth(Dict* message,
|
||||
Er_assert(BencMessageWriter_write(message, msg));
|
||||
|
||||
// calculate the hash of the message with the password hash
|
||||
crypto_hash_sha256(hash, msg->msgbytes, Message_getLength(msg));
|
||||
crypto_hash_sha256(hash, Message_bytes(msg), Message_getLength(msg));
|
||||
|
||||
// swap the hash of the message with the password hash into the location
|
||||
// where the password hash was.
|
||||
@@ -159,7 +159,7 @@ static Iface_DEFUN receiveMessage(struct Message* msg, struct Iface* addrIface)
|
||||
? AdminClient_MAX_MESSAGE_SIZE
|
||||
: Message_getLength(msg);
|
||||
Bits_memset(req->res.messageBytes, 0, AdminClient_MAX_MESSAGE_SIZE);
|
||||
Bits_memcpy(req->res.messageBytes, msg->msgbytes, len);
|
||||
Bits_memcpy(req->res.messageBytes, Message_bytes(msg), len);
|
||||
done(req, AdminClient_Error_NONE);
|
||||
return NULL;
|
||||
}
|
||||
|
@@ -681,7 +681,7 @@ int cjdroute2_main(int argc, char** argv)
|
||||
// and if the old parser fails or the parsed content contains "version": 2,
|
||||
// fail to launch
|
||||
struct Message* confMsg = readToMsg(stdin, allocator);
|
||||
struct Reader* confReader = ArrayReader_new(confMsg->msgbytes, Message_getLength(confMsg), allocator);
|
||||
struct Reader* confReader = ArrayReader_new(Message_bytes(confMsg), Message_getLength(confMsg), allocator);
|
||||
Dict _config;
|
||||
Dict* config = &_config;
|
||||
const char* err = JsonBencMessageReader_readNoExcept(confMsg, allocator, &config, false);
|
||||
|
@@ -187,7 +187,7 @@ static inline Gcc_USE_RET int decryptRndNonce(const uint8_t nonce[24],
|
||||
return -1;
|
||||
}
|
||||
Assert_true(Message_getPadding(msg) >= 16);
|
||||
uint8_t* startAt = msg->msgbytes - 16;
|
||||
uint8_t* startAt = Message_bytes(msg) - 16;
|
||||
uint8_t paddingSpace[16];
|
||||
Bits_memcpy(paddingSpace, startAt, 16);
|
||||
Bits_memset(startAt, 0, 16);
|
||||
@@ -217,7 +217,7 @@ static inline void encryptRndNonce(const uint8_t nonce[24],
|
||||
const uint8_t secret[32])
|
||||
{
|
||||
Assert_true(Message_getPadding(msg) >= 32);
|
||||
uint8_t* startAt = msg->msgbytes - 32;
|
||||
uint8_t* startAt = Message_bytes(msg) - 32;
|
||||
// This function trashes 16 bytes of the padding so we will put it back
|
||||
uint8_t paddingSpace[16];
|
||||
Bits_memcpy(paddingSpace, startAt, 16);
|
||||
@@ -345,7 +345,7 @@ static void encryptHandshake(struct Message* message,
|
||||
{
|
||||
Er_assert(Message_eshift(message, CryptoHeader_SIZE));
|
||||
|
||||
struct CryptoHeader* header = (struct CryptoHeader*) message->msgbytes;
|
||||
struct CryptoHeader* header = (struct CryptoHeader*) Message_bytes(message);
|
||||
|
||||
// garbage the auth challenge and set the nonce which follows it
|
||||
Random_bytes(session->context->rand, (uint8_t*) &header->auth,
|
||||
@@ -459,7 +459,7 @@ static void encryptHandshake(struct Message* message,
|
||||
uint8_t nonceHex[49];
|
||||
Hex_encode(nonceHex, 49, header->handshakeNonce, 24);
|
||||
uint8_t cipherHex[65];
|
||||
printHexKey(cipherHex, message->msgbytes);
|
||||
printHexKey(cipherHex, Message_bytes(message));
|
||||
Log_keys(session->context->logger,
|
||||
"Encrypting message with:\n"
|
||||
" nonce: %s\n"
|
||||
@@ -485,7 +485,7 @@ static int encryptPacket(struct CryptoAuth_Session_pvt* session, struct Message*
|
||||
reset(session);
|
||||
}
|
||||
|
||||
Assert_true(!((uintptr_t)msg->msgbytes % 4) || !"alignment fault");
|
||||
Assert_true(!((uintptr_t)Message_bytes(msg) % 4) || !"alignment fault");
|
||||
|
||||
// nextNonce 0: sending hello, we are initiating connection.
|
||||
// nextNonce 1: sending another hello, nothing received yet.
|
||||
@@ -651,7 +651,7 @@ static enum CryptoAuth_DecryptErr decryptHandshake(struct CryptoAuth_Session_pvt
|
||||
uint8_t nonceHex[49];
|
||||
Hex_encode(nonceHex, 49, header->handshakeNonce, 24);
|
||||
uint8_t cipherHex[65];
|
||||
printHexKey(cipherHex, message->msgbytes);
|
||||
printHexKey(cipherHex, Message_bytes(message));
|
||||
Log_keys(session->context->logger,
|
||||
"Decrypting message with:\n"
|
||||
" nonce: %s\n"
|
||||
@@ -837,14 +837,14 @@ static enum CryptoAuth_DecryptErr decryptHandshake(struct CryptoAuth_Session_pvt
|
||||
static enum CryptoAuth_DecryptErr decryptPacket(struct CryptoAuth_Session_pvt* session,
|
||||
struct Message* msg)
|
||||
{
|
||||
struct CryptoHeader* header = (struct CryptoHeader*) msg->msgbytes;
|
||||
struct CryptoHeader* header = (struct CryptoHeader*) Message_bytes(msg);
|
||||
|
||||
if (Message_getLength(msg) < 20) {
|
||||
cryptoAuthDebug0(session, "DROP runt");
|
||||
return CryptoAuth_DecryptErr_RUNT;
|
||||
}
|
||||
Assert_true(Message_getPadding(msg) >= 12 || "need at least 12 bytes of padding in incoming message");
|
||||
Assert_true(!((uintptr_t)msg->msgbytes % 4) || !"alignment fault");
|
||||
Assert_true(!((uintptr_t)Message_bytes(msg) % 4) || !"alignment fault");
|
||||
Assert_true(!(Message_getCapacity(msg) % 4) || !"length fault");
|
||||
|
||||
Er_assert(Message_eshift(msg, -4));
|
||||
@@ -1074,7 +1074,7 @@ static Iface_DEFUN ciphertextMsg(struct Message* msg, struct Iface* iface)
|
||||
// Address is pushed on top of the message
|
||||
Er_assert(Message_epop(msg, NULL, 16));
|
||||
uint8_t firstSixteen[16];
|
||||
Bits_memcpy(firstSixteen, msg->msgbytes, 16);
|
||||
Bits_memcpy(firstSixteen, Message_bytes(msg), 16);
|
||||
enum CryptoAuth_DecryptErr e = decryptPacket(sess, msg);
|
||||
if (e == CryptoAuth_DecryptErr_NONE) {
|
||||
Er_assert(Message_epush32be(msg, CryptoAuth_DecryptErr_NONE));
|
||||
|
@@ -146,10 +146,10 @@ void Sign_signMsg(uint8_t keyPair[64], struct Message* msg, struct Random* rand)
|
||||
// hash message + secret number, this is the same as crypto_sign()
|
||||
// If there isn't enough space in the message, we abort the process
|
||||
Er_assert(Message_epush(msg, &az[32], 32));
|
||||
crypto_hash_sha512(r, msg->msgbytes, Message_getLength(msg));
|
||||
crypto_hash_sha512(r, Message_bytes(msg), Message_getLength(msg));
|
||||
|
||||
// Replace secret number with public key, this is the same as crypto_sign()
|
||||
Bits_memcpy(msg->msgbytes, &keyPair[32], 32);
|
||||
Bits_memcpy(Message_bytes(msg), &keyPair[32], 32);
|
||||
|
||||
// Now we scalar multiply the hash of the message + unique secret and push that
|
||||
// to the message, nothing different from crypto_sign()
|
||||
@@ -157,14 +157,14 @@ void Sign_signMsg(uint8_t keyPair[64], struct Message* msg, struct Random* rand)
|
||||
ge_scalarmult_base(&R,r);
|
||||
// If there isn't enough space in the message, we abort the process
|
||||
Er_assert(Message_eshift(msg, 32));
|
||||
ge_p3_tobytes(msg->msgbytes,&R);
|
||||
ge_p3_tobytes(Message_bytes(msg),&R);
|
||||
|
||||
// This final step is the same as crypto_sign()
|
||||
// Overwrite the public key which the verifier will replace in order to recompute
|
||||
// the hash.
|
||||
crypto_hash_sha512(hram, msg->msgbytes, Message_getLength(msg));
|
||||
crypto_hash_sha512(hram, Message_bytes(msg), Message_getLength(msg));
|
||||
sc_reduce(hram);
|
||||
sc_muladd(&msg->msgbytes[32], hram, az, r);
|
||||
sc_muladd(&Message_bytes(msg)[32], hram, az, r);
|
||||
}
|
||||
|
||||
// For verify, we're just using the normal sign_open() function, nothing special here.
|
||||
@@ -174,7 +174,7 @@ int Sign_verifyMsg(uint8_t publicSigningKey[32], struct Message* msg)
|
||||
struct Allocator* alloc = Allocator_child(Message_getAlloc(msg));
|
||||
uint8_t* buff = Allocator_malloc(alloc, Message_getLength(msg));
|
||||
unsigned long long ml = Message_getLength(msg);
|
||||
int ret = crypto_sign_ed25519_open(buff, &ml, msg->msgbytes, Message_getLength(msg), publicSigningKey);
|
||||
int ret = crypto_sign_ed25519_open(buff, &ml, Message_bytes(msg), Message_getLength(msg), publicSigningKey);
|
||||
Allocator_free(alloc);
|
||||
if (ret) {
|
||||
return -1;
|
||||
|
@@ -93,7 +93,7 @@ static void sign(Dict* args, void* vctx, String* txid, struct Allocator* request
|
||||
Er_assert(Message_epush(msg, msgHash->bytes, msgHash->len));
|
||||
Sign_signMsg(ctx->signingKeypair, msg, ctx->rand);
|
||||
uint8_t signB64[128];
|
||||
Assert_true(Base32_encode(signB64, 128, msg->msgbytes, 64) > 0);
|
||||
Assert_true(Base32_encode(signB64, 128, Message_bytes(msg), 64) > 0);
|
||||
String* sig = String_printf(requestAlloc, "%s_%s", ctx->pubSigningKey, signB64);
|
||||
Dict_putStringC(out, "signature", sig, requestAlloc);
|
||||
Dict_putStringCC(out, "error", "none", requestAlloc);
|
||||
|
@@ -117,7 +117,7 @@ static bool isMutableBit(int bitNum)
|
||||
static void flipBit(struct Message* msg, uint32_t bitNum)
|
||||
{
|
||||
Assert_true(Message_getLength(msg) * 8 > (int)bitNum);
|
||||
msg->msgbytes[bitNum / 8] ^= 128 >> (bitNum % 8);
|
||||
Message_bytes(msg)[bitNum / 8] ^= 128 >> (bitNum % 8);
|
||||
}
|
||||
|
||||
static void flipMutableBit(struct Context* ctx, struct Node* from, struct Message* msg)
|
||||
@@ -280,7 +280,7 @@ static Iface_DEFUN afterDecrypt(struct Message* msg, struct Iface* iface)
|
||||
enum CryptoAuth_DecryptErr e = Er_assert(Message_epop32h(msg));
|
||||
if (!e) {
|
||||
Assert_true(!flippedImmutable);
|
||||
Assert_true(Message_getLength(msg) == 4 && !Bits_memcmp(msg->msgbytes, "hey", 4));
|
||||
Assert_true(Message_getLength(msg) == 4 && !Bits_memcmp(Message_bytes(msg), "hey", 4));
|
||||
if (to == &to->ctx->nodeB) {
|
||||
// 1/10 chance the node decides not to reply.
|
||||
if (maybe(to->ctx, 10)) {
|
||||
@@ -346,7 +346,7 @@ void CryptoAuthFuzz_main(void* vctx, struct Message* fuzz)
|
||||
struct Context* ctx = Identity_check((struct Context*) vctx);
|
||||
|
||||
// This is not ideal, but this test was already written before AFL.
|
||||
RandomSeed_t* rs = DeterminentRandomSeed_new(ctx->alloc, fuzz->msgbytes);
|
||||
RandomSeed_t* rs = DeterminentRandomSeed_new(ctx->alloc, Message_bytes(fuzz));
|
||||
ctx->rand = Random_newWithSeed(ctx->alloc, NULL, rs, NULL);
|
||||
|
||||
if (maybe(ctx, 2)) {
|
||||
|
@@ -40,14 +40,14 @@ static void encryptRndNonceTest()
|
||||
|
||||
uint8_t* expected = (uint8_t*) "1391ac5d03ba9f7099bffbb6e6c69d67ae5bd79391a5b94399b293dc";
|
||||
uint8_t output[57];
|
||||
Hex_encode(output, 57, m.msgbytes, Message_getLength(&m));
|
||||
Hex_encode(output, 57, Message_bytes(&m), Message_getLength(&m));
|
||||
|
||||
printf("\n%s\n%s\n", (char*) expected, (char*) output);
|
||||
Assert_true(!Bits_memcmp(expected, output, 56));
|
||||
|
||||
Assert_true(!CryptoAuth_decryptRndNonce(nonce, &m, secret));
|
||||
Assert_true(Message_getLength(&m) == HELLOWORLDLEN
|
||||
&& !Bits_memcmp(m.msgbytes, HELLOWORLDLOWER, Message_getLength(&m)));
|
||||
&& !Bits_memcmp(Message_bytes(&m), HELLOWORLDLOWER, Message_getLength(&m)));
|
||||
}
|
||||
|
||||
int main()
|
||||
|
@@ -85,13 +85,13 @@ static Iface_DEFUN afterDecrypt(struct Message* msg, struct Iface* if1)
|
||||
if (e) {
|
||||
return NULL;
|
||||
}
|
||||
Assert_failure("expected <NULL>, got [%s](%d)\n", msg->msgbytes, Message_getLength(msg));
|
||||
Assert_failure("expected <NULL>, got [%s](%d)\n", Message_bytes(msg), Message_getLength(msg));
|
||||
}
|
||||
if ((int)CString_strlen(n->expectPlaintext) != Message_getLength(msg) ||
|
||||
CString_strncmp(msg->msgbytes, n->expectPlaintext, Message_getLength(msg)))
|
||||
CString_strncmp(Message_bytes(msg), n->expectPlaintext, Message_getLength(msg)))
|
||||
{
|
||||
Assert_failure("expected [%s](%d), got [%s](%d)\n",
|
||||
n->expectPlaintext, (int)CString_strlen(n->expectPlaintext), msg->msgbytes, Message_getLength(msg));
|
||||
n->expectPlaintext, (int)CString_strlen(n->expectPlaintext), Message_bytes(msg), Message_getLength(msg));
|
||||
}
|
||||
n->expectPlaintext = NULL;
|
||||
return NULL;
|
||||
@@ -161,7 +161,7 @@ static struct Message* encryptMsg(struct Context* ctx,
|
||||
struct Allocator* alloc = Allocator_child(ctx->alloc);
|
||||
int len = (((CString_strlen(x)+1) / 8) + 1) * 8;
|
||||
struct Message* msg = Message_new(len, CryptoHeader_SIZE + 32, alloc);
|
||||
CString_strcpy(msg->msgbytes, x);
|
||||
CString_strcpy(Message_bytes(msg), x);
|
||||
Er_assert(Message_truncate(msg, CString_strlen(x)));
|
||||
//msg->bytes[Message_getLength(msg)] = 0;
|
||||
struct RTypes_Error_t* e = Iface_send(&n->plaintext, msg);
|
||||
|
@@ -96,7 +96,7 @@ static void testHello(uint8_t* password, uint8_t* expectedOutput, enum TestCa_Co
|
||||
|
||||
Iface_send(&ctx->plaintext, msg);
|
||||
|
||||
char* actual = Hex_print(msg->msgbytes, Message_getLength(msg), alloc);
|
||||
char* actual = Hex_print(Message_bytes(msg), Message_getLength(msg), alloc);
|
||||
if (CString_strcmp(actual, expectedOutput)) {
|
||||
Assert_failure("Test failed.\n"
|
||||
"Expected %s\n"
|
||||
@@ -133,7 +133,7 @@ static void receiveHelloWithNoAuth(enum TestCa_Config cfg)
|
||||
struct Allocator* alloc = Allocator_new(1<<20);
|
||||
struct Context* ctx = setUp(PRIVATEKEY, herPublic, NULL, alloc, cfg);
|
||||
struct Message* msg = Message_new(132, 32, alloc);
|
||||
Assert_true(Hex_decode(msg->msgbytes, Message_getLength(msg),
|
||||
Assert_true(Hex_decode(Message_bytes(msg), Message_getLength(msg),
|
||||
"0000000000ffffffffffffff7fffffffffffffffffffffffffffffffffffffff"
|
||||
"ffffffffffffffff847c0d2c375234f365e660955187a3735a0f7613d1609d3a"
|
||||
"6a4d8c53aeaa5a22ea9cf275eee0185edf7f211192f12e8e642a325ed76925fe"
|
||||
@@ -146,7 +146,7 @@ static void receiveHelloWithNoAuth(enum TestCa_Config cfg)
|
||||
Assert_true(!err);
|
||||
|
||||
Assert_true(Message_getLength(msg) == HELLOWORLDLEN);
|
||||
Assert_true(Bits_memcmp(HELLOWORLD, msg->msgbytes, HELLOWORLDLEN) == 0);
|
||||
Assert_true(Bits_memcmp(HELLOWORLD, Message_bytes(msg), HELLOWORLDLEN) == 0);
|
||||
Allocator_free(alloc);
|
||||
//printf("bytes=%s length=%u\n", finalOut->bytes, finalOut->length);
|
||||
}
|
||||
@@ -172,7 +172,7 @@ static void repeatHello(enum TestCa_Config cfg)
|
||||
|
||||
Iface_send(&ctx->plaintext, msg);
|
||||
|
||||
char* actual = Hex_print(msg->msgbytes, Message_getLength(msg), alloc);
|
||||
char* actual = Hex_print(Message_bytes(msg), Message_getLength(msg), alloc);
|
||||
if (CString_strcmp(actual, expectedOutput)) {
|
||||
Assert_failure("Test failed.\n"
|
||||
"Expected %s\n"
|
||||
|
@@ -204,12 +204,12 @@ static bool check(Message_t *msg, TestCa_Session_pvt_t* sess)
|
||||
Assert_failure("Message_getLength(msg) != m2->length: %d != %d",
|
||||
Message_getLength(msg), Message_getLength(m2));
|
||||
}
|
||||
if (Bits_memcmp(msg->msgbytes, m2->msgbytes, Message_getLength(msg))) {
|
||||
const char* msgH = Hex_print(msg->msgbytes, Message_getLength(msg), Message_getAlloc(msg));
|
||||
const char* m2H = Hex_print(m2->msgbytes, Message_getLength(m2), Message_getAlloc(m2));
|
||||
if (Bits_memcmp(Message_bytes(msg), Message_bytes(m2), Message_getLength(msg))) {
|
||||
const char* msgH = Hex_print(Message_bytes(msg), Message_getLength(msg), Message_getAlloc(msg));
|
||||
const char* m2H = Hex_print(Message_bytes(m2), Message_getLength(m2), Message_getAlloc(m2));
|
||||
Assert_failure("msg->bytes != m2->bytes:\n%s\n%s\n", msgH, m2H);
|
||||
}
|
||||
Assert_true(!Bits_memcmp(msg->msgbytes, m2->msgbytes, Message_getLength(msg)));
|
||||
Assert_true(!Bits_memcmp(Message_bytes(msg), Message_bytes(m2), Message_getLength(msg)));
|
||||
} else {
|
||||
Assert_failure("unexpected flag [%d]", flag);
|
||||
}
|
||||
|
@@ -98,7 +98,7 @@ static int incomingFromDHT(struct DHTMessage* dmessage, void* vpf)
|
||||
Assert_true(AddressCalc_validAddress(addr->ip6.bytes));
|
||||
|
||||
Er_assert(Message_eshift(msg, PFChan_Msg_MIN_SIZE));
|
||||
struct PFChan_Msg* emsg = (struct PFChan_Msg*) msg->msgbytes;
|
||||
struct PFChan_Msg* emsg = (struct PFChan_Msg*) Message_bytes(msg);
|
||||
Bits_memset(emsg, 0, PFChan_Msg_MIN_SIZE);
|
||||
|
||||
DataHeader_setVersion(&emsg->data, DataHeader_CURRENT_VERSION);
|
||||
@@ -147,9 +147,9 @@ static Iface_DEFUN sendNode(struct Message* msg,
|
||||
{
|
||||
Message_reset(msg);
|
||||
Er_assert(Message_eshift(msg, PFChan_Node_SIZE));
|
||||
nodeForAddress((struct PFChan_Node*) msg->msgbytes, addr, metric);
|
||||
nodeForAddress((struct PFChan_Node*) Message_bytes(msg), addr, metric);
|
||||
if (addr->path == UINT64_MAX) {
|
||||
((struct PFChan_Node*) msg->msgbytes)->path_be = 0;
|
||||
((struct PFChan_Node*) Message_bytes(msg))->path_be = 0;
|
||||
}
|
||||
Er_assert(Message_epush32be(msg, PFChan_Pathfinder_NODE));
|
||||
return Iface_next(&pf->pub.eventIf, msg);
|
||||
@@ -407,7 +407,7 @@ static Iface_DEFUN handlePong(struct Message* msg, struct Pathfinder_pvt* pf)
|
||||
static Iface_DEFUN incomingMsg(struct Message* msg, struct Pathfinder_pvt* pf)
|
||||
{
|
||||
struct Address addr = {0};
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) Message_bytes(msg);
|
||||
Er_assert(Message_eshift(msg, -(RouteHeader_SIZE + DataHeader_SIZE)));
|
||||
Bits_memcpy(addr.ip6.bytes, hdr->ip6, 16);
|
||||
Bits_memcpy(addr.key, hdr->publicKey, 32);
|
||||
|
@@ -68,7 +68,7 @@ static int handleIncoming(struct DHTMessage* message, void* vcontext)
|
||||
Address_toString(message->address, message->allocator)->bytes);
|
||||
|
||||
Message_reset(message->binMessage);
|
||||
Assert_true(!((uintptr_t)message->binMessage->msgbytes % 4) || !"alignment fault0");
|
||||
Assert_true(!((uintptr_t)Message_bytes(message->binMessage) % 4) || !"alignment fault0");
|
||||
|
||||
struct DHTMessage* reply = Allocator_clone(message->allocator, (&(struct DHTMessage) {
|
||||
.replyTo = message,
|
||||
|
@@ -72,7 +72,7 @@ static int handleOutgoing(struct DHTMessage* message,
|
||||
{
|
||||
// This is always at the end of the message.
|
||||
Assert_true(!Message_getLength(message->binMessage));
|
||||
Assert_true(!((uintptr_t)message->binMessage->msgbytes % 4) || !"alignment fault0");
|
||||
Assert_true(!((uintptr_t)Message_bytes(message->binMessage) % 4) || !"alignment fault0");
|
||||
|
||||
if (Dict_getStringC(message->asDict, "q")) {
|
||||
String* txid = Dict_getStringC(message->asDict, "txid");
|
||||
@@ -86,7 +86,7 @@ static int handleOutgoing(struct DHTMessage* message,
|
||||
|
||||
Er_assert(BencMessageWriter_write(message->asDict, message->binMessage));
|
||||
|
||||
Assert_true(!((uintptr_t)message->binMessage->msgbytes % 4) || !"alignment fault");
|
||||
Assert_true(!((uintptr_t)Message_bytes(message->binMessage) % 4) || !"alignment fault");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -74,7 +74,7 @@ static Iface_DEFUN sendMessage(struct Message* msg, struct Iface* iface)
|
||||
{
|
||||
struct ETHInterface_pvt* ctx = Identity_containerOf(iface, struct ETHInterface_pvt, iface);
|
||||
|
||||
struct Sockaddr* sa = (struct Sockaddr*) msg->msgbytes;
|
||||
struct Sockaddr* sa = (struct Sockaddr*) Message_bytes(msg);
|
||||
Assert_true(Message_getLength(msg) >= Sockaddr_OVERHEAD);
|
||||
Assert_true(sa->addrLen <= ETHInterface_Sockaddr_SIZE);
|
||||
|
||||
@@ -107,7 +107,7 @@ static Iface_DEFUN sendMessage(struct Message* msg, struct Iface* iface)
|
||||
};
|
||||
Er_assert(Message_epush(msg, &bpfPkt, bpfPkt.bh_hdrlen));
|
||||
*/
|
||||
if (Message_getLength(msg) != write(ctx->socket, msg->msgbytes, Message_getLength(msg))) {
|
||||
if (Message_getLength(msg) != write(ctx->socket, Message_bytes(msg), Message_getLength(msg))) {
|
||||
Log_debug(ctx->logger, "Error writing to eth device [%s]", strerror(errno));
|
||||
}
|
||||
return NULL;
|
||||
@@ -131,7 +131,7 @@ static void handleEvent2(struct ETHInterface_pvt* context,
|
||||
struct ETHInterface_Header hdr;
|
||||
Bits_memcpy(&hdr, data, ETHInterface_Header_SIZE);
|
||||
|
||||
Bits_memcpy(msg->msgbytes, &data[ETHInterface_Header_SIZE], contentLength);
|
||||
Bits_memcpy(Message_bytes(msg), &data[ETHInterface_Header_SIZE], contentLength);
|
||||
|
||||
// here we could put a switch statement to handle different versions differently.
|
||||
if (hdr.version != ETHInterface_CURRENT_VERSION) {
|
||||
@@ -162,7 +162,7 @@ static void handleEvent2(struct ETHInterface_pvt* context,
|
||||
|
||||
Er_assert(Message_epush(msg, &sockaddr, ETHInterface_Sockaddr_SIZE));
|
||||
|
||||
Assert_true(!((uintptr_t)msg->msgbytes % 4) && "Alignment fault");
|
||||
Assert_true(!((uintptr_t)Message_bytes(msg) % 4) && "Alignment fault");
|
||||
|
||||
Iface_send(context->pub.generic.iface, msg);
|
||||
}
|
||||
|
@@ -79,7 +79,7 @@ static void sendMessageInternal(struct Message* message,
|
||||
*/
|
||||
|
||||
if (sendto(context->socket,
|
||||
message->msgbytes,
|
||||
Message_bytes(message),
|
||||
Message_getLength(message),
|
||||
0,
|
||||
(struct sockaddr*) addr,
|
||||
@@ -103,7 +103,7 @@ static Iface_DEFUN sendMessage(struct Message* msg, struct Iface* iface)
|
||||
{
|
||||
struct ETHInterface_pvt* ctx = Identity_containerOf(iface, struct ETHInterface_pvt, iface);
|
||||
|
||||
struct Sockaddr* sa = (struct Sockaddr*) msg->msgbytes;
|
||||
struct Sockaddr* sa = (struct Sockaddr*) Message_bytes(msg);
|
||||
Assert_true(Message_getLength(msg) >= Sockaddr_OVERHEAD);
|
||||
Assert_true(sa->addrLen <= ETHInterface_Sockaddr_SIZE);
|
||||
|
||||
@@ -142,7 +142,7 @@ static void handleEvent2(struct ETHInterface_pvt* context, struct Allocator* mes
|
||||
Er_assert(Message_eshift(msg, 2));
|
||||
|
||||
int rc = recvfrom(context->socket,
|
||||
msg->msgbytes,
|
||||
Message_bytes(msg),
|
||||
Message_getLength(msg),
|
||||
0,
|
||||
(struct sockaddr*) &addr,
|
||||
@@ -189,7 +189,7 @@ static void handleEvent2(struct ETHInterface_pvt* context, struct Allocator* mes
|
||||
|
||||
Er_assert(Message_epush(msg, &sockaddr, ETHInterface_Sockaddr_SIZE));
|
||||
|
||||
Assert_true(!((uintptr_t)msg->msgbytes % 4) && "Alignment fault");
|
||||
Assert_true(!((uintptr_t)Message_bytes(msg) % 4) && "Alignment fault");
|
||||
|
||||
Iface_send(context->pub.generic.iface, msg);
|
||||
}
|
||||
|
@@ -59,10 +59,10 @@ static struct Message* mergeMessage(struct FramingIface_pvt* fi, struct Message*
|
||||
}
|
||||
|
||||
struct Message* out = Message_new(0, length + REQUIRED_PADDING, fi->frameAlloc);
|
||||
Er_assert(Message_epush(out, last->msgbytes, Message_getLength(last)));
|
||||
Er_assert(Message_epush(out, Message_bytes(last), Message_getLength(last)));
|
||||
int fd = Message_getAssociatedFd(last);
|
||||
for (part = fi->frameParts; part; part = part->next) {
|
||||
Er_assert(Message_epush(out, part->msg->msgbytes, Message_getLength(part->msg)));
|
||||
Er_assert(Message_epush(out, Message_bytes(part->msg), Message_getLength(part->msg)));
|
||||
if (fd == -1) {
|
||||
fd = Message_getAssociatedFd(part->msg);
|
||||
}
|
||||
@@ -111,7 +111,7 @@ static Iface_DEFUN receiveMessage(struct Message* msg, struct Iface* streamIf)
|
||||
if (!Message_getLength(msg)) {
|
||||
return NULL;
|
||||
}
|
||||
fi->header.bytes[fi->headerIndex] = msg->msgbytes[0];
|
||||
fi->header.bytes[fi->headerIndex] = Message_bytes(msg)[0];
|
||||
Er_assert(Message_eshift(msg, -1));
|
||||
fi->headerIndex++;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ static Iface_DEFUN receiveMessage(struct Message* msg, struct Iface* streamIf)
|
||||
struct Allocator* alloc = Allocator_child(Message_getAlloc(msg));
|
||||
struct Message* m = Message_new(fi->bytesRemaining, REQUIRED_PADDING, alloc);
|
||||
Message_setAssociatedFd(m, Message_getAssociatedFd(msg));
|
||||
Bits_memcpy(m->msgbytes, msg->msgbytes, fi->bytesRemaining);
|
||||
Bits_memcpy(Message_bytes(m), Message_bytes(msg), fi->bytesRemaining);
|
||||
Er_assert(Message_eshift(msg, -fi->bytesRemaining));
|
||||
fi->bytesRemaining = 0;
|
||||
Iface_send(&fi->messageIf, m);
|
||||
@@ -143,7 +143,7 @@ static Iface_DEFUN receiveMessage(struct Message* msg, struct Iface* streamIf)
|
||||
fi->frameAlloc = Allocator_child(fi->alloc);
|
||||
struct Message* m = Message_new(0, Message_getLength(msg) + 4, fi->frameAlloc);
|
||||
Message_setAssociatedFd(m, Message_getAssociatedFd(msg));
|
||||
Er_assert(Message_epush(m, msg->msgbytes, Message_getLength(msg)));
|
||||
Er_assert(Message_epush(m, Message_bytes(msg), Message_getLength(msg)));
|
||||
Er_assert(Message_epush(m, fi->header.bytes, 4));
|
||||
|
||||
fi->bytesRemaining -= Message_getLength(msg);
|
||||
|
@@ -116,7 +116,7 @@ static Iface_DEFUN sendPacket(struct Message* m, struct Iface* iface)
|
||||
Identity_containerOf(iface, struct UDPInterface_pvt, iface);
|
||||
|
||||
Assert_true(Message_getLength(m) > Sockaddr_OVERHEAD);
|
||||
struct Sockaddr* sa = (struct Sockaddr*) m->msgbytes;
|
||||
struct Sockaddr* sa = (struct Sockaddr*) Message_bytes(m);
|
||||
Assert_true(Message_getLength(m) > sa->addrLen);
|
||||
|
||||
// Regular traffic
|
||||
|
@@ -48,7 +48,7 @@ static inline Er_DEFUN(void AddrIface_pushAddr(struct Message* msg, const struct
|
||||
|
||||
static inline Er_DEFUN(struct Sockaddr* AddrIface_popAddr(struct Message* msg))
|
||||
{
|
||||
struct Sockaddr* out = (struct Sockaddr*) msg->msgbytes;
|
||||
struct Sockaddr* out = (struct Sockaddr*) Message_bytes(msg);
|
||||
uint16_t len = Er(Message_epop16h(msg));
|
||||
Er(Message_epop(msg, NULL, len - 2));
|
||||
Er_ret(out);
|
||||
|
@@ -78,11 +78,11 @@ static Iface_DEFUN incomingFromInputIf(struct Message* msg, struct Iface* inputI
|
||||
return Error(msg, "RUNT");
|
||||
}
|
||||
|
||||
uint16_t addrLen = Bits_get16(msg->msgbytes);
|
||||
uint16_t addrLen = Bits_get16(Message_bytes(msg));
|
||||
Er_assert(AddrIface_pushAddr(msg, &cli->addr));
|
||||
|
||||
// After pushing the address, tweak the length
|
||||
Bits_put16(msg->msgbytes, cli->addr.addrLen + addrLen);
|
||||
Bits_put16(Message_bytes(msg), cli->addr.addrLen + addrLen);
|
||||
|
||||
return Iface_next(ctx->pub.iface.iface, msg);
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ static Iface_DEFUN ifaceRecvMsg(struct Message* message, struct Iface* thisInter
|
||||
Assert_true(!ctx->success);
|
||||
Assert_true(Message_getLength(message) == ctx->messageLen);
|
||||
Assert_true(Message_getLength(ctx->buf) == 0);
|
||||
Assert_true(!Bits_memcmp(ctx->bufPtr, message->msgbytes, ctx->messageLen));
|
||||
Assert_true(!Bits_memcmp(ctx->bufPtr, Message_bytes(message), ctx->messageLen));
|
||||
ctx->success = 1;
|
||||
return NULL;
|
||||
}
|
||||
@@ -51,13 +51,13 @@ void CJDNS_FUZZ_MAIN(void* vctx, struct Message* fuzz)
|
||||
Er_assert(Message_truncate(ctx->buf, ctx->messageLen));
|
||||
Er_assert(Message_epush32be(ctx->buf, ctx->messageLen));
|
||||
for (int i = 0; ; i++) {
|
||||
uint8_t len = fuzz->msgbytes[i % Message_getLength(fuzz)] + 1;
|
||||
uint8_t len = Message_bytes(fuzz)[i % Message_getLength(fuzz)] + 1;
|
||||
if (len > Message_getLength(ctx->buf)) {
|
||||
len = Message_getLength(ctx->buf);
|
||||
}
|
||||
struct Allocator* a = Allocator_child(ctx->alloc);
|
||||
struct Message* m = Message_new(len, 0, a);
|
||||
Er_assert(Message_epop(ctx->buf, m->msgbytes, len));
|
||||
Er_assert(Message_epop(ctx->buf, Message_bytes(m), len));
|
||||
Iface_send(&ctx->outer, m);
|
||||
Allocator_free(a);
|
||||
if (ctx->success) {
|
||||
@@ -74,8 +74,8 @@ void* CJDNS_FUZZ_INIT(struct Allocator* alloc, struct Random* rand)
|
||||
Iface_plumb(&ctx->iface, ctx->fi);
|
||||
ctx->alloc = alloc;
|
||||
ctx->buf = Message_new(BUF_SZ, 4, alloc);
|
||||
Random_bytes(rand, ctx->buf->msgbytes, BUF_SZ);
|
||||
ctx->bufPtr = ctx->buf->msgbytes;
|
||||
Random_bytes(rand, Message_bytes(ctx->buf), BUF_SZ);
|
||||
ctx->bufPtr = Message_bytes(ctx->buf);
|
||||
Identity_set(ctx);
|
||||
return ctx;
|
||||
}
|
@@ -44,7 +44,7 @@ static Iface_DEFUN receiveMessage(struct Message* msg, struct Iface* wireSide)
|
||||
|
||||
if (Message_getLength(msg) < 4) { return Error(msg, "RUNT"); }
|
||||
|
||||
uint16_t afType_be = ((uint16_t*) msg->msgbytes)[1];
|
||||
uint16_t afType_be = ((uint16_t*) Message_bytes(msg))[1];
|
||||
uint16_t ethertype = 0;
|
||||
if (afType_be == ctx->afInet_be) {
|
||||
ethertype = Ethernet_TYPE_IP4;
|
||||
@@ -55,8 +55,8 @@ static Iface_DEFUN receiveMessage(struct Message* msg, struct Iface* wireSide)
|
||||
Endian_bigEndianToHost16(afType_be));
|
||||
return Error(msg, "INVALID");
|
||||
}
|
||||
((uint16_t*) msg->msgbytes)[0] = 0;
|
||||
((uint16_t*) msg->msgbytes)[1] = ethertype;
|
||||
((uint16_t*) Message_bytes(msg))[0] = 0;
|
||||
((uint16_t*) Message_bytes(msg))[1] = ethertype;
|
||||
|
||||
return Iface_next(&ctx->pub.inside, msg);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ static Iface_DEFUN sendMessage(struct Message* msg, struct Iface* inside)
|
||||
|
||||
Assert_true(Message_getLength(msg) >= 4);
|
||||
|
||||
uint16_t ethertype = ((uint16_t*) msg->msgbytes)[1];
|
||||
uint16_t ethertype = ((uint16_t*) Message_bytes(msg))[1];
|
||||
uint16_t afType_be = 0;
|
||||
if (ethertype == Ethernet_TYPE_IP6) {
|
||||
afType_be = ctx->afInet6_be;
|
||||
@@ -77,8 +77,8 @@ static Iface_DEFUN sendMessage(struct Message* msg, struct Iface* inside)
|
||||
} else {
|
||||
Assert_true(!"Unsupported ethertype");
|
||||
}
|
||||
((uint16_t*) msg->msgbytes)[0] = 0;
|
||||
((uint16_t*) msg->msgbytes)[1] = afType_be;
|
||||
((uint16_t*) Message_bytes(msg))[0] = 0;
|
||||
((uint16_t*) Message_bytes(msg))[1] = afType_be;
|
||||
|
||||
return Iface_next(&ctx->pub.wireSide, msg);
|
||||
}
|
||||
|
@@ -47,7 +47,7 @@ static bool isNeighborSolicitation(struct Message* msg, struct NDPServer_pvt* ns
|
||||
return false;
|
||||
}
|
||||
|
||||
struct Headers_IP6Header* ip6 = (struct Headers_IP6Header*) msg->msgbytes;
|
||||
struct Headers_IP6Header* ip6 = (struct Headers_IP6Header*) Message_bytes(msg);
|
||||
struct NDPHeader_NeighborSolicitation* sol = (struct NDPHeader_NeighborSolicitation*) &ip6[1];
|
||||
|
||||
if (sol->oneThirtyFive != 135 || sol->zero != 0) {
|
||||
@@ -105,8 +105,8 @@ static Iface_DEFUN answerNeighborSolicitation(struct Message* msg, struct NDPSer
|
||||
ip6.hopLimit = 255;
|
||||
ip6.payloadLength_be = Endian_hostToBigEndian16(Message_getLength(msg));
|
||||
|
||||
struct NDPHeader_RouterAdvert* adv = (struct NDPHeader_RouterAdvert*) msg->msgbytes;
|
||||
adv->checksum = Checksum_icmp6_be(ip6.sourceAddr, msg->msgbytes, Message_getLength(msg));
|
||||
struct NDPHeader_RouterAdvert* adv = (struct NDPHeader_RouterAdvert*) Message_bytes(msg);
|
||||
adv->checksum = Checksum_icmp6_be(ip6.sourceAddr, Message_bytes(msg), Message_getLength(msg));
|
||||
|
||||
Er_assert(Message_epush(msg, &ip6, sizeof(struct Headers_IP6Header)));
|
||||
|
||||
|
@@ -68,8 +68,8 @@ static Iface_DEFUN incomingFromWire(struct Message* message, struct Iface* exter
|
||||
}
|
||||
|
||||
Er_assert(Message_eshift(message, 4));
|
||||
((uint16_t*) message->msgbytes)[0] = 0;
|
||||
((uint16_t*) message->msgbytes)[1] = ethertypeForPacketType(message->msgbytes[4]);
|
||||
((uint16_t*) Message_bytes(message))[0] = 0;
|
||||
((uint16_t*) Message_bytes(message))[1] = ethertypeForPacketType(Message_bytes(message)[4]);
|
||||
|
||||
return Iface_next(&ctx->internalIf, message);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ static Iface_DEFUN incomingFromUs(struct Message* message, struct Iface* interna
|
||||
Identity_containerOf(internalIf, struct TUNInterface_Illumos_pvt, internalIf);
|
||||
|
||||
Er_assert(Message_eshift(message, -4));
|
||||
uint16_t ethertype = ((uint16_t*) message->msgbytes)[-1];
|
||||
uint16_t ethertype = ((uint16_t*) Message_bytes(message))[-1];
|
||||
if (ethertype != Ethernet_TYPE_IP6 && ethertype != Ethernet_TYPE_IP4) {
|
||||
Assert_true(!"Unsupported ethertype");
|
||||
}
|
||||
|
@@ -22,15 +22,15 @@ static inline Er_DEFUN(void TUNMessageType_push(struct Message* message,
|
||||
uint16_t ethertype))
|
||||
{
|
||||
Er(Message_eshift(message, 4));
|
||||
((uint16_t*) message->msgbytes)[0] = 0;
|
||||
((uint16_t*) message->msgbytes)[1] = ethertype;
|
||||
((uint16_t*) Message_bytes(message))[0] = 0;
|
||||
((uint16_t*) Message_bytes(message))[1] = ethertype;
|
||||
Er_ret();
|
||||
}
|
||||
|
||||
static inline Er_DEFUN(uint16_t TUNMessageType_pop(struct Message* message))
|
||||
{
|
||||
Er(Message_eshift(message, -4));
|
||||
Er_ret( ((uint16_t*) message->msgbytes)[-1] );
|
||||
Er_ret( ((uint16_t*) Message_bytes(message))[-1] );
|
||||
}
|
||||
|
||||
enum TUNMessageType {
|
||||
|
@@ -39,7 +39,7 @@ static Iface_DEFUN receiveMessageTUN(struct Message* msg, struct TUNTools* tt)
|
||||
return Error(msg, "INVALID");
|
||||
}
|
||||
|
||||
struct Headers_IP4Header* header = (struct Headers_IP4Header*) msg->msgbytes;
|
||||
struct Headers_IP4Header* header = (struct Headers_IP4Header*) Message_bytes(msg);
|
||||
|
||||
Assert_true(Message_getLength(msg) == Headers_IP4Header_SIZE + Headers_UDPHeader_SIZE + 12);
|
||||
|
||||
|
@@ -87,7 +87,7 @@ Iface_DEFUN TUNTools_genericIP6Echo(struct Message* msg, struct TUNTools* tt)
|
||||
return Error(msg, "INVALID");
|
||||
}
|
||||
|
||||
struct Headers_IP6Header* header = (struct Headers_IP6Header*) msg->msgbytes;
|
||||
struct Headers_IP6Header* header = (struct Headers_IP6Header*) Message_bytes(msg);
|
||||
|
||||
if (Message_getLength(msg) != Headers_IP6Header_SIZE + Headers_UDPHeader_SIZE + 12) {
|
||||
int type = (Message_getLength(msg) >= Headers_IP6Header_SIZE) ? header->nextHeader : -1;
|
||||
|
@@ -127,7 +127,7 @@ static void postRead(struct TAPInterface_pvt* tap)
|
||||
// Choose odd numbers so that the message will be aligned despite the weird header size.
|
||||
struct Message* msg = tap->readMsg = Message_new(1534, 514, alloc);
|
||||
OVERLAPPED* readol = (OVERLAPPED*) tap->readIocp.overlapped;
|
||||
if (!ReadFile(tap->handle, msg->msgbytes, 1534, NULL, readol)) {
|
||||
if (!ReadFile(tap->handle, Message_bytes(msg), 1534, NULL, readol)) {
|
||||
switch (GetLastError()) {
|
||||
case ERROR_IO_PENDING:
|
||||
case ERROR_IO_INCOMPLETE: break;
|
||||
@@ -172,7 +172,7 @@ static void postWrite(struct TAPInterface_pvt* tap)
|
||||
tap->isPendingWrite = 1;
|
||||
struct Message* msg = tap->writeMsgs[0];
|
||||
OVERLAPPED* writeol = (OVERLAPPED*) tap->writeIocp.overlapped;
|
||||
if (!WriteFile(tap->handle, msg->msgbytes, Message_getLength(msg), NULL, writeol)) {
|
||||
if (!WriteFile(tap->handle, Message_bytes(msg), Message_getLength(msg), NULL, writeol)) {
|
||||
switch (GetLastError()) {
|
||||
case ERROR_IO_PENDING:
|
||||
case ERROR_IO_INCOMPLETE: break;
|
||||
|
@@ -71,11 +71,11 @@ static Iface_DEFUN handlePing(struct Message* msg,
|
||||
return Error(msg, "RUNT");
|
||||
}
|
||||
|
||||
struct Control* ctrl = (struct Control*) msg->msgbytes;
|
||||
struct Control* ctrl = (struct Control*) Message_bytes(msg);
|
||||
Er_assert(Message_eshift(msg, -Control_Header_SIZE));
|
||||
|
||||
// Ping and keyPing share version location
|
||||
struct Control_Ping* ping = (struct Control_Ping*) msg->msgbytes;
|
||||
struct Control_Ping* ping = (struct Control_Ping*) Message_bytes(msg);
|
||||
uint32_t herVersion = Endian_bigEndianToHost32(ping->version_be);
|
||||
if (!Version_isCompatible(Version_CURRENT_PROTOCOL, herVersion)) {
|
||||
Log_debug(ch->log, "DROP ping from incompatible version [%d]", herVersion);
|
||||
@@ -98,7 +98,7 @@ static Iface_DEFUN handlePing(struct Message* msg,
|
||||
return Error(msg, "INVALID");
|
||||
}
|
||||
|
||||
struct Control_KeyPing* keyPing = (struct Control_KeyPing*) msg->msgbytes;
|
||||
struct Control_KeyPing* keyPing = (struct Control_KeyPing*) Message_bytes(msg);
|
||||
keyPing->magic = Control_KeyPong_MAGIC;
|
||||
ctrl->header.type_be = Control_KEYPONG_be;
|
||||
Bits_memcpy(keyPing->key, ch->myPublicKey, 32);
|
||||
@@ -122,11 +122,11 @@ static Iface_DEFUN handlePing(struct Message* msg,
|
||||
Er_assert(Message_eshift(msg, Control_Header_SIZE));
|
||||
|
||||
ctrl->header.checksum_be = 0;
|
||||
ctrl->header.checksum_be = Checksum_engine_be(msg->msgbytes, Message_getLength(msg));
|
||||
ctrl->header.checksum_be = Checksum_engine_be(Message_bytes(msg), Message_getLength(msg));
|
||||
|
||||
Er_assert(Message_eshift(msg, RouteHeader_SIZE));
|
||||
|
||||
struct RouteHeader* routeHeader = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* routeHeader = (struct RouteHeader*) Message_bytes(msg);
|
||||
Bits_memset(routeHeader, 0, RouteHeader_SIZE);
|
||||
SwitchHeader_setVersion(&routeHeader->sh, SwitchHeader_CURRENT_VERSION);
|
||||
routeHeader->sh.label_be = Endian_hostToBigEndian64(label);
|
||||
@@ -150,7 +150,7 @@ static Iface_DEFUN handleRPathQuery(struct Message* msg,
|
||||
return Error(msg, "RUNT");
|
||||
}
|
||||
|
||||
struct Control* ctrl = (struct Control*) msg->msgbytes;
|
||||
struct Control* ctrl = (struct Control*) Message_bytes(msg);
|
||||
struct Control_RPath* rpa = &ctrl->content.rpath;
|
||||
|
||||
if (rpa->magic != Control_RPATH_QUERY_MAGIC) {
|
||||
@@ -165,10 +165,10 @@ static Iface_DEFUN handleRPathQuery(struct Message* msg,
|
||||
Bits_memcpy(rpa->rpath_be, &label_be, 8);
|
||||
|
||||
ctrl->header.checksum_be = 0;
|
||||
ctrl->header.checksum_be = Checksum_engine_be(msg->msgbytes, Message_getLength(msg));
|
||||
ctrl->header.checksum_be = Checksum_engine_be(Message_bytes(msg), Message_getLength(msg));
|
||||
|
||||
Er_assert(Message_eshift(msg, RouteHeader_SIZE));
|
||||
struct RouteHeader* routeHeader = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* routeHeader = (struct RouteHeader*) Message_bytes(msg);
|
||||
Bits_memset(routeHeader, 0, RouteHeader_SIZE);
|
||||
SwitchHeader_setVersion(&routeHeader->sh, SwitchHeader_CURRENT_VERSION);
|
||||
routeHeader->sh.label_be = label_be;
|
||||
@@ -191,7 +191,7 @@ static Iface_DEFUN handleGetSnodeQuery(struct Message* msg,
|
||||
return Error(msg, "RUNT");
|
||||
}
|
||||
|
||||
struct Control* ctrl = (struct Control*) msg->msgbytes;
|
||||
struct Control* ctrl = (struct Control*) Message_bytes(msg);
|
||||
struct Control_GetSnode* snq = &ctrl->content.getSnode;
|
||||
|
||||
if (snq->magic != Control_GETSNODE_QUERY_MAGIC) {
|
||||
@@ -226,10 +226,10 @@ static Iface_DEFUN handleGetSnodeQuery(struct Message* msg,
|
||||
}
|
||||
|
||||
ctrl->header.checksum_be = 0;
|
||||
ctrl->header.checksum_be = Checksum_engine_be(msg->msgbytes, Message_getLength(msg));
|
||||
ctrl->header.checksum_be = Checksum_engine_be(Message_bytes(msg), Message_getLength(msg));
|
||||
|
||||
Er_assert(Message_eshift(msg, RouteHeader_SIZE));
|
||||
struct RouteHeader* routeHeader = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* routeHeader = (struct RouteHeader*) Message_bytes(msg);
|
||||
Bits_memset(routeHeader, 0, RouteHeader_SIZE);
|
||||
SwitchHeader_setVersion(&routeHeader->sh, SwitchHeader_CURRENT_VERSION);
|
||||
routeHeader->sh.label_be = Endian_hostToBigEndian64(label);
|
||||
@@ -270,12 +270,12 @@ static Iface_DEFUN incomingFromCore(struct Message* msg, struct Iface* coreIf)
|
||||
|
||||
Assert_true(routeHdr.flags & RouteHeader_flags_CTRLMSG);
|
||||
|
||||
if (Checksum_engine_be(msg->msgbytes, Message_getLength(msg))) {
|
||||
if (Checksum_engine_be(Message_bytes(msg), Message_getLength(msg))) {
|
||||
Log_info(ch->log, "DROP ctrl packet from [%s] with invalid checksum", labelStr);
|
||||
return Error(msg, "INVALID");
|
||||
}
|
||||
|
||||
struct Control* ctrl = (struct Control*) msg->msgbytes;
|
||||
struct Control* ctrl = (struct Control*) Message_bytes(msg);
|
||||
|
||||
if (ctrl->header.type_be == Control_ERROR_be) {
|
||||
return handleError(msg, ch, label, labelStr, &routeHdr);
|
||||
|
@@ -176,7 +176,7 @@ Assert_compileTime(PFChan_Core__TOO_HIGH == 1040);
|
||||
static Iface_DEFUN incomingFromCore(struct Message* msg, struct Iface* trickIf)
|
||||
{
|
||||
struct EventEmitter_pvt* ee = Identity_containerOf(trickIf, struct EventEmitter_pvt, trickIf);
|
||||
Assert_true(!((uintptr_t)msg->msgbytes % 4) && "alignment");
|
||||
Assert_true(!((uintptr_t)Message_bytes(msg) % 4) && "alignment");
|
||||
enum PFChan_Core ev = Er_assert(Message_epop32be(msg));
|
||||
Assert_true(PFChan_Core_sizeOk(ev, Message_getLength(msg)+4));
|
||||
uint32_t pathfinderNum = Er_assert(Message_epop32be(msg));
|
||||
@@ -201,7 +201,7 @@ static struct Message* pathfinderMsg(enum PFChan_Core ev,
|
||||
struct Allocator* alloc)
|
||||
{
|
||||
struct Message* msg = Message_new(PFChan_Core_Pathfinder_SIZE, 512, alloc);
|
||||
struct PFChan_Core_Pathfinder* pathfinder = (struct PFChan_Core_Pathfinder*) msg->msgbytes;
|
||||
struct PFChan_Core_Pathfinder* pathfinder = (struct PFChan_Core_Pathfinder*) Message_bytes(msg);
|
||||
pathfinder->superiority_be = Endian_hostToBigEndian32(pf->superiority);
|
||||
pathfinder->pathfinderId_be = Endian_hostToBigEndian32(pf->pathfinderId);
|
||||
Bits_memcpy(pathfinder->userAgent, pf->userAgent, 64);
|
||||
|
@@ -256,7 +256,7 @@ static void sendPeer(uint32_t pathfinderId,
|
||||
struct InterfaceController_pvt* ic = Identity_check(peer->ici->ic);
|
||||
struct Allocator* alloc = Allocator_child(ic->alloc);
|
||||
struct Message* msg = Message_new(PFChan_Node_SIZE, 512, alloc);
|
||||
struct PFChan_Node* node = (struct PFChan_Node*) msg->msgbytes;
|
||||
struct PFChan_Node* node = (struct PFChan_Node*) Message_bytes(msg);
|
||||
Bits_memcpy(node->ip6, peer->addr.ip6.bytes, 16);
|
||||
Bits_memcpy(node->publicKey, peer->addr.key, 32);
|
||||
node->path_be = Endian_hostToBigEndian64(peer->addr.path);
|
||||
@@ -719,14 +719,14 @@ static Iface_DEFUN handleIncomingFromWire(struct Message* msg, struct Iface* add
|
||||
struct Sockaddr_storage lladdrStore;
|
||||
struct Sockaddr* lladdr = (struct Sockaddr*) &lladdrStore;
|
||||
{
|
||||
struct Sockaddr* lladdr0 = (struct Sockaddr*) msg->msgbytes;
|
||||
struct Sockaddr* lladdr0 = (struct Sockaddr*) Message_bytes(msg);
|
||||
if (Message_getLength(msg) < Sockaddr_OVERHEAD || Message_getLength(msg) < lladdr0->addrLen) {
|
||||
Log_debug(ici->ic->logger, "DROP runt");
|
||||
return Error(msg, "RUNT");
|
||||
}
|
||||
Er_assert(Message_epop(msg, lladdr, lladdr0->addrLen));
|
||||
}
|
||||
Assert_true(!((uintptr_t)msg->msgbytes % 4) && "alignment fault");
|
||||
Assert_true(!((uintptr_t)Message_bytes(msg) % 4) && "alignment fault");
|
||||
Assert_true(!((uintptr_t)lladdr->addrLen % 4) && "alignment fault");
|
||||
|
||||
char* printedAddr = "<unknown>";
|
||||
@@ -749,7 +749,7 @@ static Iface_DEFUN handleIncomingFromWire(struct Message* msg, struct Iface* add
|
||||
if (epIndex == -1) {
|
||||
// noise control message
|
||||
Er_assert(Message_epush(msg, NULL, 16));
|
||||
Sockaddr_asIp6(msg->msgbytes, lladdr);
|
||||
Sockaddr_asIp6(Message_bytes(msg), lladdr);
|
||||
|
||||
RTypes_CryptoAuth2_TryHandshake_Ret_t ret = { .code = 0 };
|
||||
Rffi_CryptoAuth2_tryHandshake(ici->ic->ca, msg, ici->alloc, true, &ret);
|
||||
@@ -825,7 +825,7 @@ static Iface_DEFUN handleIncomingFromWire(struct Message* msg, struct Iface* add
|
||||
Ca_resetIfTimeout(ep->caSession);
|
||||
|
||||
Er_assert(Message_epush(msg, NULL, 16));
|
||||
Sockaddr_asIp6(msg->msgbytes, lladdr);
|
||||
Sockaddr_asIp6(Message_bytes(msg), lladdr);
|
||||
|
||||
return Iface_next(&ep->ciphertext, msg); // -> afterDecrypt
|
||||
}
|
||||
@@ -850,7 +850,7 @@ static Iface_DEFUN afterDecrypt(struct Message* msg, struct Iface* plaintext)
|
||||
// prevent some kinds of nasty things which could be done with packet replay.
|
||||
// This is checking the message switch header and will drop it unless the label
|
||||
// directs it to *this* router.
|
||||
if (Message_getLength(msg) < 8 || msg->msgbytes[7] != 1) {
|
||||
if (Message_getLength(msg) < 8 || Message_bytes(msg)[7] != 1) {
|
||||
Log_info(ic->logger, "DROP message because CA is not established.");
|
||||
return Error(msg, "UNHANDLED");
|
||||
} else {
|
||||
@@ -927,7 +927,7 @@ static void sendBeacon(struct InterfaceController_Iface_pvt* ici, struct Allocat
|
||||
Er_assert(Message_epush(msg, &ici->ic->beacon, Headers_Beacon_SIZE));
|
||||
|
||||
if (Defined(Log_DEBUG)) {
|
||||
char* content = Hex_print(msg->msgbytes, Message_getLength(msg), tempAlloc);
|
||||
char* content = Hex_print(Message_bytes(msg), Message_getLength(msg), tempAlloc);
|
||||
Log_debug(ici->ic->logger, "SEND BEACON CONTENT[%s]", content);
|
||||
}
|
||||
|
||||
|
@@ -315,7 +315,7 @@ static Iface_DEFUN failedDecrypt(struct Message* msg,
|
||||
Er_assert(Message_epush32be(msg, Error_AUTHENTICATION));
|
||||
Er_assert(Message_epush16be(msg, Control_ERROR));
|
||||
Er_assert(Message_epush16be(msg, 0));
|
||||
uint16_t csum_be = Checksum_engine_be(msg->msgbytes, Message_getLength(msg));
|
||||
uint16_t csum_be = Checksum_engine_be(Message_bytes(msg), Message_getLength(msg));
|
||||
Er_assert(Message_epop16h(msg));
|
||||
Er_assert(Message_epush16h(msg, csum_be));
|
||||
|
||||
@@ -505,7 +505,7 @@ static Iface_DEFUN incomingFromSwitchIf(struct Message* msg, struct Iface* iface
|
||||
switchHeader.label_be = Bits_bitReverse64(switchHeader.label_be);
|
||||
|
||||
struct SessionManager_Session_pvt* session = NULL;
|
||||
uint32_t nonceOrHandle = Endian_bigEndianToHost32(((uint32_t*)msg->msgbytes)[0]);
|
||||
uint32_t nonceOrHandle = Endian_bigEndianToHost32(((uint32_t*)Message_bytes(msg))[0]);
|
||||
if (nonceOrHandle == 0xffffffff) {
|
||||
Er_assert(Message_epush(msg, &switchHeader, SwitchHeader_SIZE));
|
||||
return ctrlFrame(msg, sm);
|
||||
@@ -525,7 +525,7 @@ static Iface_DEFUN incomingFromSwitchIf(struct Message* msg, struct Iface* iface
|
||||
return Error(msg, "INVALID");
|
||||
}
|
||||
Er_assert(Message_eshift(msg, -4));
|
||||
uint32_t nonce = Endian_bigEndianToHost32(((uint32_t*)msg->msgbytes)[0]);
|
||||
uint32_t nonce = Endian_bigEndianToHost32(((uint32_t*)Message_bytes(msg))[0]);
|
||||
if (nonce < 4) {
|
||||
Log_debug(sm->log, "DROP setup message [%u] with specified handle [%u]",
|
||||
nonce, nonceOrHandle);
|
||||
@@ -537,7 +537,7 @@ static Iface_DEFUN incomingFromSwitchIf(struct Message* msg, struct Iface* iface
|
||||
Log_debug(sm->log, "DROP runt");
|
||||
return Error(msg, "RUNT");
|
||||
}
|
||||
struct CryptoHeader* caHeader = (struct CryptoHeader*) msg->msgbytes;
|
||||
struct CryptoHeader* caHeader = (struct CryptoHeader*) Message_bytes(msg);
|
||||
uint8_t ip6[16];
|
||||
// a packet which claims to be "from us" causes problems
|
||||
if (!AddressCalc_addressForPublicKey(ip6, caHeader->publicKey)) {
|
||||
@@ -674,7 +674,7 @@ static void periodically(void* vSessionManager)
|
||||
static void bufferPacket(struct SessionManager_pvt* sm, struct Message* msg)
|
||||
{
|
||||
Assert_true(Message_getLength(msg) >= (RouteHeader_SIZE + DataHeader_SIZE));
|
||||
struct RouteHeader* header = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* header = (struct RouteHeader*) Message_bytes(msg);
|
||||
|
||||
// We should never be sending CJDHT messages without full version, key, path known.
|
||||
struct DataHeader* dataHeader = (struct DataHeader*) &header[1];
|
||||
@@ -712,7 +712,7 @@ static void bufferPacket(struct SessionManager_pvt* sm, struct Message* msg)
|
||||
|
||||
static void needsLookup(struct SessionManager_pvt* sm, struct Message* msg)
|
||||
{
|
||||
struct RouteHeader* header = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* header = (struct RouteHeader*) Message_bytes(msg);
|
||||
bufferPacket(sm, msg);
|
||||
triggerSearch(sm, header->ip6, Endian_hostToBigEndian32(header->version_be));
|
||||
}
|
||||
@@ -743,7 +743,7 @@ static Iface_DEFUN readyToSend(struct Message* msg,
|
||||
static Iface_DEFUN outgoingCtrlFrame(struct Message* msg, struct SessionManager_pvt* sm)
|
||||
{
|
||||
Assert_true(Message_getLength(msg) >= RouteHeader_SIZE);
|
||||
struct RouteHeader* header = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* header = (struct RouteHeader*) Message_bytes(msg);
|
||||
if (!Bits_isZero(header->publicKey, 32) || !Bits_isZero(header->ip6, 16)) {
|
||||
Log_debug(sm->log, "DROP Ctrl frame with non-zero destination key or IP");
|
||||
return Error(msg, "INVALID");
|
||||
@@ -765,7 +765,7 @@ static Iface_DEFUN incomingFromInsideIf(struct Message* msg, struct Iface* iface
|
||||
struct SessionManager_pvt* sm =
|
||||
Identity_containerOf(iface, struct SessionManager_pvt, pub.insideIf);
|
||||
Assert_true(Message_getLength(msg) >= RouteHeader_SIZE);
|
||||
struct RouteHeader* header = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* header = (struct RouteHeader*) Message_bytes(msg);
|
||||
if (header->flags & RouteHeader_flags_CTRLMSG) {
|
||||
return outgoingCtrlFrame(msg, sm);
|
||||
}
|
||||
|
@@ -94,12 +94,12 @@ static Iface_DEFUN messageFromControlHandler(struct Message* msg, struct Iface*
|
||||
ctx->incomingSnodeKbps = 0;
|
||||
ctx->rpath = 0;
|
||||
|
||||
struct Control* ctrl = (struct Control*) msg->msgbytes;
|
||||
struct Control* ctrl = (struct Control*) Message_bytes(msg);
|
||||
if (ctrl->header.type_be == Control_PONG_be) {
|
||||
Er_assert(Message_eshift(msg, -Control_Header_SIZE));
|
||||
ctx->error = Error_NONE;
|
||||
if (Message_getLength(msg) >= Control_Pong_MIN_SIZE) {
|
||||
struct Control_Ping* pongHeader = (struct Control_Ping*) msg->msgbytes;
|
||||
struct Control_Ping* pongHeader = (struct Control_Ping*) Message_bytes(msg);
|
||||
ctx->incomingVersion = Endian_bigEndianToHost32(pongHeader->version_be);
|
||||
if (pongHeader->magic != Control_Pong_MAGIC) {
|
||||
Log_debug(ctx->logger, "dropped invalid switch pong");
|
||||
@@ -115,7 +115,7 @@ static Iface_DEFUN messageFromControlHandler(struct Message* msg, struct Iface*
|
||||
Er_assert(Message_eshift(msg, -Control_Header_SIZE));
|
||||
ctx->error = Error_NONE;
|
||||
if (Message_getLength(msg) >= Control_KeyPong_HEADER_SIZE && Message_getLength(msg) <= Control_KeyPong_MAX_SIZE) {
|
||||
struct Control_KeyPing* pongHeader = (struct Control_KeyPing*) msg->msgbytes;
|
||||
struct Control_KeyPing* pongHeader = (struct Control_KeyPing*) Message_bytes(msg);
|
||||
ctx->incomingVersion = Endian_bigEndianToHost32(pongHeader->version_be);
|
||||
if (pongHeader->magic != Control_KeyPong_MAGIC) {
|
||||
Log_debug(ctx->logger, "dropped invalid switch key-pong");
|
||||
@@ -138,7 +138,7 @@ static Iface_DEFUN messageFromControlHandler(struct Message* msg, struct Iface*
|
||||
Log_debug(ctx->logger, "got runt GetSnode message, length: [%d]", Message_getLength(msg));
|
||||
return Error(msg, "RUNT");
|
||||
}
|
||||
struct Control_GetSnode* hdr = (struct Control_GetSnode*) msg->msgbytes;
|
||||
struct Control_GetSnode* hdr = (struct Control_GetSnode*) Message_bytes(msg);
|
||||
if (hdr->magic != Control_GETSNODE_REPLY_MAGIC) {
|
||||
Log_debug(ctx->logger, "dropped invalid GetSnode");
|
||||
return Error(msg, "INVALID");
|
||||
@@ -167,7 +167,7 @@ static Iface_DEFUN messageFromControlHandler(struct Message* msg, struct Iface*
|
||||
Log_debug(ctx->logger, "got runt RPath message, length: [%d]", Message_getLength(msg));
|
||||
return Error(msg, "RUNT");
|
||||
}
|
||||
struct Control_RPath* hdr = (struct Control_RPath*) msg->msgbytes;
|
||||
struct Control_RPath* hdr = (struct Control_RPath*) Message_bytes(msg);
|
||||
if (hdr->magic != Control_RPATH_REPLY_MAGIC) {
|
||||
Log_debug(ctx->logger, "dropped invalid RPATH (bad magic)");
|
||||
return Error(msg, "INVALID");
|
||||
@@ -180,7 +180,7 @@ static Iface_DEFUN messageFromControlHandler(struct Message* msg, struct Iface*
|
||||
|
||||
} else if (ctrl->header.type_be == Control_ERROR_be) {
|
||||
Er_assert(Message_eshift(msg, -Control_Header_SIZE));
|
||||
Assert_true((uint8_t*)&ctrl->content.error.errorType_be == msg->msgbytes);
|
||||
Assert_true((uint8_t*)&ctrl->content.error.errorType_be == Message_bytes(msg));
|
||||
if (Message_getLength(msg) < (Control_Error_HEADER_SIZE + SwitchHeader_SIZE + Control_Header_SIZE)) {
|
||||
Log_debug(ctx->logger, "runt error packet");
|
||||
return Error(msg, "RUNT");
|
||||
@@ -191,7 +191,7 @@ static Iface_DEFUN messageFromControlHandler(struct Message* msg, struct Iface*
|
||||
|
||||
Er_assert(Message_eshift(msg, -(Control_Error_HEADER_SIZE + SwitchHeader_SIZE)));
|
||||
|
||||
struct Control* origCtrl = (struct Control*) msg->msgbytes;
|
||||
struct Control* origCtrl = (struct Control*) Message_bytes(msg);
|
||||
|
||||
Log_debug(ctx->logger, "error [%d] was caused by our [%s]",
|
||||
ctx->error,
|
||||
@@ -215,7 +215,7 @@ static Iface_DEFUN messageFromControlHandler(struct Message* msg, struct Iface*
|
||||
Assert_true(false);
|
||||
}
|
||||
|
||||
String* msgStr = &(String) { .bytes = (char*) msg->msgbytes, .len = Message_getLength(msg) };
|
||||
String* msgStr = &(String) { .bytes = (char*) Message_bytes(msg), .len = Message_getLength(msg) };
|
||||
Pinger_pongReceived(msgStr, ctx->pinger);
|
||||
Bits_memset(ctx->incomingKey, 0, 32);
|
||||
return NULL;
|
||||
@@ -264,30 +264,30 @@ static void sendPing(String* data, void* sendPingContext)
|
||||
|
||||
struct Message* msg = Message_new(0, data->len + 512, p->pub.pingAlloc);
|
||||
|
||||
while (((uintptr_t)msg->msgbytes - data->len) % 4) {
|
||||
while (((uintptr_t)Message_bytes(msg) - data->len) % 4) {
|
||||
Er_assert(Message_epush8(msg, 0));
|
||||
}
|
||||
Er_assert(Message_truncate(msg, 0));
|
||||
|
||||
Er_assert(Message_epush(msg, data->bytes, data->len));
|
||||
Assert_true(!((uintptr_t)msg->msgbytes % 4) && "alignment fault");
|
||||
Assert_true(!((uintptr_t)Message_bytes(msg) % 4) && "alignment fault");
|
||||
|
||||
if (p->pub.type == SwitchPinger_Type_KEYPING) {
|
||||
Er_assert(Message_epush(msg, NULL, Control_KeyPing_HEADER_SIZE));
|
||||
struct Control_KeyPing* keyPingHeader = (struct Control_KeyPing*) msg->msgbytes;
|
||||
struct Control_KeyPing* keyPingHeader = (struct Control_KeyPing*) Message_bytes(msg);
|
||||
keyPingHeader->magic = Control_KeyPing_MAGIC;
|
||||
keyPingHeader->version_be = Endian_hostToBigEndian32(Version_CURRENT_PROTOCOL);
|
||||
Bits_memcpy(keyPingHeader->key, p->context->myAddr->key, 32);
|
||||
|
||||
} else if (p->pub.type == SwitchPinger_Type_PING) {
|
||||
Er_assert(Message_epush(msg, NULL, Control_Ping_HEADER_SIZE));
|
||||
struct Control_Ping* pingHeader = (struct Control_Ping*) msg->msgbytes;
|
||||
struct Control_Ping* pingHeader = (struct Control_Ping*) Message_bytes(msg);
|
||||
pingHeader->magic = Control_Ping_MAGIC;
|
||||
pingHeader->version_be = Endian_hostToBigEndian32(Version_CURRENT_PROTOCOL);
|
||||
|
||||
} else if (p->pub.type == SwitchPinger_Type_GETSNODE) {
|
||||
Er_assert(Message_epush(msg, NULL, Control_GetSnode_HEADER_SIZE));
|
||||
struct Control_GetSnode* hdr = (struct Control_GetSnode*) msg->msgbytes;
|
||||
struct Control_GetSnode* hdr = (struct Control_GetSnode*) Message_bytes(msg);
|
||||
hdr->magic = Control_GETSNODE_QUERY_MAGIC;
|
||||
hdr->version_be = Endian_hostToBigEndian32(Version_CURRENT_PROTOCOL);
|
||||
hdr->kbps_be = Endian_hostToBigEndian32(p->pub.kbpsLimit);
|
||||
@@ -298,7 +298,7 @@ static void sendPing(String* data, void* sendPingContext)
|
||||
|
||||
} else if (p->pub.type == SwitchPinger_Type_RPATH) {
|
||||
Er_assert(Message_epush(msg, NULL, Control_RPath_HEADER_SIZE));
|
||||
struct Control_RPath* hdr = (struct Control_RPath*) msg->msgbytes;
|
||||
struct Control_RPath* hdr = (struct Control_RPath*) Message_bytes(msg);
|
||||
hdr->magic = Control_RPATH_QUERY_MAGIC;
|
||||
hdr->version_be = Endian_hostToBigEndian32(Version_CURRENT_PROTOCOL);
|
||||
uint64_t path_be = Endian_hostToBigEndian64(p->label);
|
||||
@@ -309,7 +309,7 @@ static void sendPing(String* data, void* sendPingContext)
|
||||
}
|
||||
|
||||
Er_assert(Message_eshift(msg, Control_Header_SIZE));
|
||||
struct Control* ctrl = (struct Control*) msg->msgbytes;
|
||||
struct Control* ctrl = (struct Control*) Message_bytes(msg);
|
||||
ctrl->header.checksum_be = 0;
|
||||
if (p->pub.type == SwitchPinger_Type_PING) {
|
||||
ctrl->header.type_be = Control_PING_be;
|
||||
@@ -322,7 +322,7 @@ static void sendPing(String* data, void* sendPingContext)
|
||||
} else {
|
||||
Assert_failure("unexpected type");
|
||||
}
|
||||
ctrl->header.checksum_be = Checksum_engine_be(msg->msgbytes, Message_getLength(msg));
|
||||
ctrl->header.checksum_be = Checksum_engine_be(Message_bytes(msg), Message_getLength(msg));
|
||||
|
||||
struct RouteHeader rh;
|
||||
Bits_memset(&rh, 0, RouteHeader_SIZE);
|
||||
|
@@ -40,7 +40,7 @@ static Iface_DEFUN incomingFromTunIf(struct Message* msg, struct Iface* tunIf)
|
||||
|
||||
uint16_t ethertype = Er_assert(TUNMessageType_pop(msg));
|
||||
|
||||
int version = Headers_getIpVersion(msg->msgbytes);
|
||||
int version = Headers_getIpVersion(Message_bytes(msg));
|
||||
if ((ethertype == Ethernet_TYPE_IP4 && version != 4)
|
||||
|| (ethertype == Ethernet_TYPE_IP6 && version != 6))
|
||||
{
|
||||
@@ -63,7 +63,7 @@ static Iface_DEFUN incomingFromTunIf(struct Message* msg, struct Iface* tunIf)
|
||||
return Error(msg, "RUNT");
|
||||
}
|
||||
|
||||
struct Headers_IP6Header* header = (struct Headers_IP6Header*) msg->msgbytes;
|
||||
struct Headers_IP6Header* header = (struct Headers_IP6Header*) Message_bytes(msg);
|
||||
if (!AddressCalc_validAddress(header->destinationAddr)) {
|
||||
return Iface_next(&ud->pub.ipTunnelIf, msg);
|
||||
}
|
||||
@@ -94,7 +94,7 @@ static Iface_DEFUN incomingFromTunIf(struct Message* msg, struct Iface* tunIf)
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
Er_assert(Message_eshift(msg, DataHeader_SIZE + RouteHeader_SIZE - Headers_IP6Header_SIZE));
|
||||
struct RouteHeader* rh = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* rh = (struct RouteHeader*) Message_bytes(msg);
|
||||
|
||||
struct DataHeader* dh = (struct DataHeader*) &rh[1];
|
||||
Bits_memset(dh, 0, DataHeader_SIZE);
|
||||
@@ -130,7 +130,7 @@ static Iface_DEFUN incomingFromUpperDistributorIf(struct Message* msg,
|
||||
struct TUNAdapter_pvt* ud =
|
||||
Identity_containerOf(upperDistributorIf, struct TUNAdapter_pvt, pub.upperDistributorIf);
|
||||
Assert_true(Message_getLength(msg) >= RouteHeader_SIZE + DataHeader_SIZE);
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) Message_bytes(msg);
|
||||
struct DataHeader* dh = (struct DataHeader*) &hdr[1];
|
||||
enum ContentType type = DataHeader_getContentType(dh);
|
||||
Assert_true(type <= ContentType_IP6_MAX);
|
||||
@@ -146,7 +146,7 @@ static Iface_DEFUN incomingFromUpperDistributorIf(struct Message* msg,
|
||||
Bits_memcpy(&hdr->ip6[DataHeader_SIZE], ud->myIp6, 16);
|
||||
|
||||
Er_assert(Message_eshift(msg, Headers_IP6Header_SIZE - DataHeader_SIZE - RouteHeader_SIZE));
|
||||
struct Headers_IP6Header* ip6 = (struct Headers_IP6Header*) msg->msgbytes;
|
||||
struct Headers_IP6Header* ip6 = (struct Headers_IP6Header*) Message_bytes(msg);
|
||||
Bits_memset(ip6, 0, Headers_IP6Header_SIZE - 32);
|
||||
Headers_setIpVersion(ip6);
|
||||
ip6->payloadLength_be = Endian_bigEndianToHost16(Message_getLength(msg) - Headers_IP6Header_SIZE);
|
||||
|
@@ -72,8 +72,8 @@ static Iface_DEFUN fromHandler(struct Message* msg, struct UpperDistributor_pvt*
|
||||
uint8_t srcAndDest[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
|
||||
AddressCalc_makeValidAddress(&srcAndDest[16]);
|
||||
Bits_memcpy(srcAndDest, ud->myAddress->ip6.bytes, 16);
|
||||
struct Headers_UDPHeader* udp = (struct Headers_UDPHeader*) msg->msgbytes;
|
||||
if (Checksum_udpIp6_be(srcAndDest, msg->msgbytes, Message_getLength(msg))) {
|
||||
struct Headers_UDPHeader* udp = (struct Headers_UDPHeader*) Message_bytes(msg);
|
||||
if (Checksum_udpIp6_be(srcAndDest, Message_bytes(msg), Message_getLength(msg))) {
|
||||
Log_debug(ud->log, "DROP Bad checksum");
|
||||
return Error(msg, "INVALID");
|
||||
}
|
||||
@@ -91,7 +91,7 @@ static Iface_DEFUN fromHandler(struct Message* msg, struct UpperDistributor_pvt*
|
||||
Er_assert(Message_epop(msg, NULL, Headers_UDPHeader_SIZE));
|
||||
|
||||
Assert_true(Message_getLength(msg) >= RouteHeader_SIZE);
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) Message_bytes(msg);
|
||||
if (!Bits_memcmp(hdr->ip6, ud->myAddress->ip6.bytes, 16)) {
|
||||
ud->noSendToHandler = 1;
|
||||
Log_debug(ud->log, "Message to self");
|
||||
@@ -138,8 +138,8 @@ static void sendToHandlers(struct Message* msg,
|
||||
uint8_t srcAndDest[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
|
||||
AddressCalc_makeValidAddress(srcAndDest);
|
||||
Bits_memcpy(&srcAndDest[16], ud->myAddress->ip6.bytes, 16);
|
||||
uint16_t checksum_be = Checksum_udpIp6_be(srcAndDest, cmsg->msgbytes, Message_getLength(cmsg));
|
||||
((struct Headers_UDPHeader*)cmsg->msgbytes)->checksum_be = checksum_be;
|
||||
uint16_t checksum_be = Checksum_udpIp6_be(srcAndDest, Message_bytes(cmsg), Message_getLength(cmsg));
|
||||
((struct Headers_UDPHeader*)Message_bytes(cmsg))->checksum_be = checksum_be;
|
||||
}
|
||||
{
|
||||
struct DataHeader dh = { .unused = 0 };
|
||||
@@ -164,7 +164,7 @@ static void sendToHandlers(struct Message* msg,
|
||||
static Iface_DEFUN toSessionManagerIf(struct Message* msg, struct UpperDistributor_pvt* ud)
|
||||
{
|
||||
Assert_true(Message_getLength(msg) >= RouteHeader_SIZE + DataHeader_SIZE);
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) Message_bytes(msg);
|
||||
struct DataHeader* dh = (struct DataHeader*) &hdr[1];
|
||||
enum ContentType type = DataHeader_getContentType(dh);
|
||||
sendToHandlers(msg, type, ud);
|
||||
@@ -186,7 +186,7 @@ static Iface_DEFUN incomingFromTunAdapterIf(struct Message* msg, struct Iface* t
|
||||
{
|
||||
struct UpperDistributor_pvt* ud =
|
||||
Identity_containerOf(tunAdapterIf, struct UpperDistributor_pvt, pub.tunAdapterIf);
|
||||
struct RouteHeader* rh = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* rh = (struct RouteHeader*) Message_bytes(msg);
|
||||
Assert_true(Message_getLength(msg) >= RouteHeader_SIZE);
|
||||
uint8_t expected_ip6[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
|
||||
AddressCalc_makeValidAddress(expected_ip6);
|
||||
@@ -208,7 +208,7 @@ static Iface_DEFUN incomingFromControlHandlerIf(struct Message* msg, struct Ifac
|
||||
struct UpperDistributor_pvt* ud =
|
||||
Identity_containerOf(iface, struct UpperDistributor_pvt, pub.controlHandlerIf);
|
||||
Assert_true(Message_getLength(msg) >= RouteHeader_SIZE);
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) Message_bytes(msg);
|
||||
Assert_true(hdr->flags & RouteHeader_flags_CTRLMSG);
|
||||
Assert_true(!(hdr->flags & RouteHeader_flags_INCOMING));
|
||||
sendToHandlers(msg, ContentType_CTRL, ud);
|
||||
@@ -220,7 +220,7 @@ static Iface_DEFUN incomingFromSessionManagerIf(struct Message* msg, struct Ifac
|
||||
struct UpperDistributor_pvt* ud =
|
||||
Identity_containerOf(sessionManagerIf, struct UpperDistributor_pvt, pub.sessionManagerIf);
|
||||
Assert_true(Message_getLength(msg) >= RouteHeader_SIZE);
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) Message_bytes(msg);
|
||||
if (hdr->flags & RouteHeader_flags_CTRLMSG) {
|
||||
sendToHandlers(msg, ContentType_CTRL, ud);
|
||||
return Iface_next(&ud->pub.controlHandlerIf, msg);
|
||||
|
@@ -8,15 +8,13 @@
|
||||
extern "C" {
|
||||
pub fn Assert_failure(format: *const ::std::os::raw::c_char, ...);
|
||||
}
|
||||
pub type Allocator_OnFreeCallback = ::std::option::Option<
|
||||
unsafe extern "C" fn(job: *mut Allocator_OnFreeJob) -> ::std::os::raw::c_int,
|
||||
>;
|
||||
pub type Allocator_OnFreeCallback =
|
||||
::std::option::Option<unsafe extern "C" fn(job: *mut Allocator_OnFreeJob)>;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Allocator_OnFreeJob {
|
||||
pub callback: Allocator_OnFreeCallback,
|
||||
pub userData: *mut ::std::os::raw::c_void,
|
||||
pub rContext: *mut ::std::os::raw::c_void,
|
||||
pub Identity_verifier: usize,
|
||||
}
|
||||
#[repr(C)]
|
||||
@@ -89,9 +87,6 @@ extern "C" {
|
||||
extern "C" {
|
||||
pub fn Allocator_cancelOnFree(toRemove: *mut Allocator_OnFreeJob) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Allocator_onFreeComplete(onFreeJob: *mut Allocator_OnFreeJob);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Allocator__adopt(
|
||||
parentAlloc: *mut Allocator,
|
||||
@@ -213,6 +208,14 @@ extern "C" {
|
||||
pub type Iface_t = Iface;
|
||||
#[repr(u32)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum RTypes_CryptoAuth2_TryHandshake_Code_t {
|
||||
RTypes_CryptoAuth2_TryHandshake_Code_t_ReplyToPeer = 0,
|
||||
RTypes_CryptoAuth2_TryHandshake_Code_t_RecvPlaintext = 1,
|
||||
RTypes_CryptoAuth2_TryHandshake_Code_t_Error = 2,
|
||||
RTypes_CryptoAuth2_TryHandshake_Code_t_Done = 3,
|
||||
}
|
||||
#[repr(u32)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub enum RTypes_CryptoAuth_State_t {
|
||||
RTypes_CryptoAuth_State_t_Init = 0,
|
||||
RTypes_CryptoAuth_State_t_SentHello = 1,
|
||||
@@ -228,6 +231,12 @@ pub struct RTypes_Error_t {
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct RTypes_IfWrapper_t {
|
||||
pub internal: *mut Iface_t,
|
||||
pub external: *mut Iface_t,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct RTypes_StrList_t {
|
||||
pub len: usize,
|
||||
pub items: *mut *mut String_t,
|
||||
@@ -243,6 +252,20 @@ pub struct RTypes_CryptoStats_t {
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct RTypes_CryptoAuth2_Session_t {
|
||||
pub plaintext: *mut Iface_t,
|
||||
pub ciphertext: *mut Iface_t,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct RTypes_CryptoAuth2_TryHandshake_Ret_t {
|
||||
pub code: RTypes_CryptoAuth2_TryHandshake_Code_t,
|
||||
pub err: u32,
|
||||
pub sess: *mut RTypes_CryptoAuth2_Session_t,
|
||||
pub alloc: *mut Allocator_t,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Er_Ret {
|
||||
pub message: *const ::std::os::raw::c_char,
|
||||
}
|
||||
@@ -274,7 +297,7 @@ extern "C" {
|
||||
pub struct Message {
|
||||
pub _length: i32,
|
||||
pub _padding: i32,
|
||||
pub msgbytes: *mut u8,
|
||||
pub _msgbytes: *mut u8,
|
||||
pub _capacity: i32,
|
||||
pub _adLen: i32,
|
||||
pub _ad: *mut u8,
|
||||
@@ -442,15 +465,463 @@ extern "C" {
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct EventBase {
|
||||
pub unused: ::std::os::raw::c_int,
|
||||
pub struct Sockaddr {
|
||||
pub addrLen: u16,
|
||||
pub flags: u8,
|
||||
pub type_: u8,
|
||||
pub prefix: u8,
|
||||
pub pad1: u8,
|
||||
pub pad2: u16,
|
||||
}
|
||||
pub type EventBase_t = EventBase;
|
||||
extern "C" {
|
||||
pub fn EventBase_new(alloc: *mut Allocator) -> *mut EventBase;
|
||||
pub type Sockaddr_t = Sockaddr;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Sockaddr_storage {
|
||||
pub addr: Sockaddr_t,
|
||||
pub nativeAddr: [u64; 16usize],
|
||||
}
|
||||
extern "C" {
|
||||
pub fn EventBase_eventCount(eventBase: *mut EventBase_t) -> ::std::os::raw::c_int;
|
||||
pub fn Sockaddr_addrHandle(addr: *const Sockaddr_t) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_addrFromHandle(addr: *mut Sockaddr_t, handle: u32);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_getPrefix(addr: *mut Sockaddr_t) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_parse(
|
||||
str_: *const ::std::os::raw::c_char,
|
||||
out: *mut Sockaddr_storage,
|
||||
) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_print(
|
||||
addr: *mut Sockaddr_t,
|
||||
alloc: *mut Allocator,
|
||||
) -> *mut ::std::os::raw::c_char;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_getPort(sa: *const Sockaddr_t) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_setPort(sa: *mut Sockaddr_t, port: u16) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub static Sockaddr_AF_INET: ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub static Sockaddr_AF_INET6: ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_getFamily(sa: *const Sockaddr_t) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_getAddress(
|
||||
sa: *mut Sockaddr_t,
|
||||
addrPtr: *mut ::std::os::raw::c_void,
|
||||
) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_asIp6(addrOut: *mut u8, sockaddr: *const Sockaddr_t);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_initFromBytes(
|
||||
out: *mut Sockaddr_storage,
|
||||
bytes: *const u8,
|
||||
addrFamily: ::std::os::raw::c_int,
|
||||
) -> *mut Sockaddr_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_fromBytes(
|
||||
bytes: *const u8,
|
||||
addrFamily: ::std::os::raw::c_int,
|
||||
alloc: *mut Allocator,
|
||||
) -> *mut Sockaddr_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_clone(addr: *const Sockaddr_t, alloc: *mut Allocator) -> *mut Sockaddr_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_normalizeNative(nativeSockaddr: *mut ::std::os::raw::c_void);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_hash(addr: *const Sockaddr_t) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_compare(a: *const Sockaddr_t, b: *const Sockaddr_t) -> ::std::os::raw::c_int;
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct RTypes_CryptoAuth2_t {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rffi_EventLoop {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rffi_FdReadableTx {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rffi_SocketServer {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rffi_TimerTx {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rffi_UDPIface_pvt {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rffi_UDPIface {
|
||||
pub pvt: *mut Rffi_UDPIface_pvt,
|
||||
pub iface: *mut Iface_t,
|
||||
pub local_addr: *mut Sockaddr_t,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rffi_Address {
|
||||
pub octets: [u8; 16usize],
|
||||
pub netmask: [u8; 16usize],
|
||||
pub is_ipv6: bool,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Rffi_NetworkInterface {
|
||||
pub name: *const ::std::os::raw::c_char,
|
||||
pub phys_addr: [u8; 6usize],
|
||||
pub is_internal: bool,
|
||||
pub address: Rffi_Address,
|
||||
}
|
||||
pub type OnFreeFun = ::std::option::Option<unsafe extern "C" fn(ctx: *mut ::std::os::raw::c_void)>;
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_addUser_ipv6(
|
||||
password: *mut String_t,
|
||||
login: *mut String_t,
|
||||
ipv6: *mut u8,
|
||||
ca: *mut RTypes_CryptoAuth2_t,
|
||||
) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_removeUsers(
|
||||
context: *mut RTypes_CryptoAuth2_t,
|
||||
user: *mut String_t,
|
||||
) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_getUsers(
|
||||
ca: *const RTypes_CryptoAuth2_t,
|
||||
alloc: *mut Allocator_t,
|
||||
) -> *mut RTypes_StrList_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_new(
|
||||
allocator: *mut Allocator_t,
|
||||
privateKey: *const u8,
|
||||
random: *mut Random_t,
|
||||
) -> *mut RTypes_CryptoAuth2_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_tryHandshake(
|
||||
ca: *mut RTypes_CryptoAuth2_t,
|
||||
c_msg: *mut Message_t,
|
||||
alloc: *mut Allocator_t,
|
||||
requireAuth: bool,
|
||||
ret: *mut RTypes_CryptoAuth2_TryHandshake_Ret_t,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_newSession(
|
||||
ca: *mut RTypes_CryptoAuth2_t,
|
||||
alloc: *mut Allocator_t,
|
||||
herPublicKey: *const u8,
|
||||
requireAuth: bool,
|
||||
name: *const ::std::os::raw::c_char,
|
||||
useNoise: bool,
|
||||
) -> *mut RTypes_CryptoAuth2_Session_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_noiseTick(
|
||||
sess: *mut RTypes_CryptoAuth2_Session_t,
|
||||
alloc: *mut Allocator_t,
|
||||
) -> *mut Message_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_setAuth(
|
||||
password: *const String_t,
|
||||
login: *const String_t,
|
||||
caSession: *mut RTypes_CryptoAuth2_Session_t,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_resetIfTimeout(session: *mut RTypes_CryptoAuth2_Session_t);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_reset(caSession: *mut RTypes_CryptoAuth2_Session_t);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_getState(
|
||||
session: *mut RTypes_CryptoAuth2_Session_t,
|
||||
) -> RTypes_CryptoAuth_State_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_getHerPubKey(
|
||||
session: *const RTypes_CryptoAuth2_Session_t,
|
||||
pkOut: *mut u8,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_getHerIp6(session: *const RTypes_CryptoAuth2_Session_t, ipOut: *mut u8);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_getName(
|
||||
session: *const RTypes_CryptoAuth2_Session_t,
|
||||
alloc: *mut Allocator_t,
|
||||
) -> *mut String_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_getPubKey(ca: *const RTypes_CryptoAuth2_t, pkOut: *mut u8);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_stats(
|
||||
session: *const RTypes_CryptoAuth2_Session_t,
|
||||
statsOut: *mut RTypes_CryptoStats_t,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_CryptoAuth2_cjdnsVer(session: *const RTypes_CryptoAuth2_Session_t) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_stopEventLoop(event_loop: *mut Rffi_EventLoop);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_startEventLoop(event_loop: *mut Rffi_EventLoop);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_mkEventLoop(alloc: *mut Allocator_t) -> *mut Rffi_EventLoop;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_exepath(out: *mut *const ::std::os::raw::c_char, alloc: *mut Allocator_t) -> i32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_spawn(
|
||||
file: *const ::std::os::raw::c_char,
|
||||
args: *const *const ::std::os::raw::c_char,
|
||||
num_args: ::std::os::raw::c_int,
|
||||
_alloc: *mut Allocator_t,
|
||||
cb: ::std::option::Option<unsafe extern "C" fn(arg1: i64, arg2: ::std::os::raw::c_int)>,
|
||||
) -> i32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_setTimeout(
|
||||
out_timer_tx: *mut *mut Rffi_TimerTx,
|
||||
cb: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void)>,
|
||||
cb_context: *mut ::std::os::raw::c_void,
|
||||
timeout_millis: ::std::os::raw::c_ulong,
|
||||
repeat: bool,
|
||||
event_loop: *mut Rffi_EventLoop,
|
||||
alloc: *mut Allocator_t,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_resetTimeout(
|
||||
timer_tx: *const Rffi_TimerTx,
|
||||
timeout_millis: ::std::os::raw::c_ulong,
|
||||
) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_clearTimeout(timer_tx: *const Rffi_TimerTx) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_isTimeoutActive(timer_tx: *const Rffi_TimerTx) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_clearAllTimeouts(event_loop: *mut Rffi_EventLoop);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_pollFdReadable(
|
||||
out: *mut *mut Rffi_FdReadableTx,
|
||||
errout: *mut *const ::std::os::raw::c_char,
|
||||
cb: ::std::option::Option<unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void)>,
|
||||
cb_context: *mut ::std::os::raw::c_void,
|
||||
fd: ::std::os::raw::c_int,
|
||||
alloc: *mut Allocator_t,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_udpIfaceGetFd(iface: *mut Rffi_UDPIface_pvt) -> i32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_udpIfaceSetBroadcast(iface: *mut Rffi_UDPIface_pvt, broadcast: bool) -> i32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_udpIfaceSetDscp(iface: *mut Rffi_UDPIface_pvt, dscp: u8) -> i32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_udpIfaceNew(
|
||||
outp: *mut *mut Rffi_UDPIface,
|
||||
errout: *mut *const ::std::os::raw::c_char,
|
||||
bind_addr: *const Sockaddr_t,
|
||||
c_alloc: *mut Allocator_t,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_fileExists(
|
||||
existsOut: *mut bool,
|
||||
path: *const ::std::os::raw::c_char,
|
||||
errorAlloc: *mut Allocator_t,
|
||||
) -> *mut RTypes_Error_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_socketForFd(
|
||||
ifOut: *mut *mut Iface_t,
|
||||
fd: ::std::os::raw::c_int,
|
||||
socket_type: ::std::os::raw::c_int,
|
||||
alloc: *mut Allocator_t,
|
||||
) -> *mut RTypes_Error_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_unixSocketConnect(
|
||||
ifOut: *mut *mut Iface_t,
|
||||
path: *const ::std::os::raw::c_char,
|
||||
alloc: *mut Allocator_t,
|
||||
) -> *mut RTypes_Error_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_unixSocketServerOnConnect(
|
||||
rss: *mut Rffi_SocketServer,
|
||||
f: ::std::option::Option<
|
||||
unsafe extern "C" fn(arg1: *mut ::std::os::raw::c_void, arg2: *const Sockaddr_t),
|
||||
>,
|
||||
ctx: *mut ::std::os::raw::c_void,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_unixSocketServer(
|
||||
rssOut: *mut *mut Rffi_SocketServer,
|
||||
ifaceOut: *mut *mut Iface_t,
|
||||
path: *const ::std::os::raw::c_char,
|
||||
alloc: *mut Allocator_t,
|
||||
) -> *mut RTypes_Error_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_inet_ntop(
|
||||
is_ip6: bool,
|
||||
addr: *const ::std::os::raw::c_void,
|
||||
dst: *mut u8,
|
||||
dst_sz: u32,
|
||||
) -> i32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_inet_pton(is_ip6: bool, src: *const ::std::os::raw::c_char, addr: *mut u8) -> i32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_interface_addresses(
|
||||
out: *mut *const Rffi_NetworkInterface,
|
||||
alloc: *mut Allocator_t,
|
||||
) -> i32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_hrtime() -> u64;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_now_ms() -> u64;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_testwrapper_create(a: *mut Allocator_t) -> RTypes_IfWrapper_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_android_create(a: *mut Allocator_t) -> RTypes_IfWrapper_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_panic(msg: *const ::std::os::raw::c_char);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_setLogger(l: *mut Log_t);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_error(
|
||||
msg: *const ::std::os::raw::c_char,
|
||||
alloc: *mut Allocator_t,
|
||||
) -> *mut RTypes_Error_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_error_fl(
|
||||
msg: *const ::std::os::raw::c_char,
|
||||
file: *const ::std::os::raw::c_char,
|
||||
line: ::std::os::raw::c_int,
|
||||
alloc: *mut Allocator_t,
|
||||
) -> *mut RTypes_Error_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_printError(
|
||||
e: *mut RTypes_Error_t,
|
||||
alloc: *mut Allocator_t,
|
||||
) -> *const ::std::os::raw::c_char;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_glock();
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_gunlock();
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_allocator_newRoot(
|
||||
file: *const ::std::os::raw::c_char,
|
||||
line: usize,
|
||||
) -> *mut Allocator_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_allocator_free(
|
||||
a: *mut Allocator_t,
|
||||
file: *const ::std::os::raw::c_char,
|
||||
line: usize,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_allocator_isFreeing(a: *mut Allocator_t) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_allocator_child(
|
||||
a: *mut Allocator_t,
|
||||
file: *const ::std::os::raw::c_char,
|
||||
line: usize,
|
||||
) -> *mut Allocator_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_allocator_malloc(a: *mut Allocator_t, size: usize) -> *mut u8;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_allocator_calloc(a: *mut Allocator_t, size: usize) -> *mut u8;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_allocator_realloc(a: *mut Allocator_t, ptr: *mut u8, new_size: usize) -> *mut u8;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_allocator_onFree(
|
||||
a: *mut Allocator_t,
|
||||
fun: OnFreeFun,
|
||||
ctx: *mut ::std::os::raw::c_void,
|
||||
file: *const ::std::os::raw::c_char,
|
||||
line: usize,
|
||||
);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Rffi_allocator_adopt(a: *mut Allocator_t, to_adopt: *mut Allocator_t);
|
||||
}
|
||||
pub type EventBase_t = Rffi_EventLoop;
|
||||
extern "C" {
|
||||
pub fn EventBase_new(alloc: *mut Allocator) -> *mut EventBase_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn EventBase_beginLoop(eventBase: *mut EventBase_t);
|
||||
@@ -458,15 +929,6 @@ extern "C" {
|
||||
extern "C" {
|
||||
pub fn EventBase_endLoop(eventBase: *mut EventBase_t);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn EventBase_ref();
|
||||
}
|
||||
extern "C" {
|
||||
pub fn EventBase_unref();
|
||||
}
|
||||
extern "C" {
|
||||
pub fn EventBase_wakeup(eventBase: *mut ::std::os::raw::c_void);
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct CryptoAuth {
|
||||
@@ -507,7 +969,7 @@ extern "C" {
|
||||
pub fn CryptoAuth_new(
|
||||
allocator: *mut Allocator,
|
||||
privateKey: *const u8,
|
||||
eventBase: *mut EventBase,
|
||||
eventBase: *mut EventBase_t,
|
||||
logger: *mut Log,
|
||||
rand: *mut Random,
|
||||
) -> *mut CryptoAuth;
|
||||
@@ -607,94 +1069,6 @@ extern "C" {
|
||||
extern "C" {
|
||||
pub fn DeterminentRandomSeed_new(alloc: *mut Allocator, buff: *mut u8) -> *mut RandomSeed_t;
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Sockaddr {
|
||||
pub addrLen: u16,
|
||||
pub flags: u8,
|
||||
pub type_: u8,
|
||||
pub prefix: u8,
|
||||
pub pad1: u8,
|
||||
pub pad2: u16,
|
||||
}
|
||||
pub type Sockaddr_t = Sockaddr;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct Sockaddr_storage {
|
||||
pub addr: Sockaddr_t,
|
||||
pub nativeAddr: [u64; 16usize],
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_addrHandle(addr: *const Sockaddr_t) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_addrFromHandle(addr: *mut Sockaddr_t, handle: u32);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_getPrefix(addr: *mut Sockaddr_t) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_parse(
|
||||
str_: *const ::std::os::raw::c_char,
|
||||
out: *mut Sockaddr_storage,
|
||||
) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_print(
|
||||
addr: *mut Sockaddr_t,
|
||||
alloc: *mut Allocator,
|
||||
) -> *mut ::std::os::raw::c_char;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_getPort(sa: *const Sockaddr_t) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_setPort(sa: *mut Sockaddr_t, port: u16) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub static Sockaddr_AF_INET: ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub static Sockaddr_AF_INET6: ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_getFamily(sa: *const Sockaddr_t) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_getAddress(
|
||||
sa: *mut Sockaddr_t,
|
||||
addrPtr: *mut ::std::os::raw::c_void,
|
||||
) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_asIp6(addrOut: *mut u8, sockaddr: *const Sockaddr_t);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_initFromBytes(
|
||||
out: *mut Sockaddr_storage,
|
||||
bytes: *const u8,
|
||||
addrFamily: ::std::os::raw::c_int,
|
||||
) -> *mut Sockaddr_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_fromBytes(
|
||||
bytes: *const u8,
|
||||
addrFamily: ::std::os::raw::c_int,
|
||||
alloc: *mut Allocator,
|
||||
) -> *mut Sockaddr_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_clone(addr: *const Sockaddr_t, alloc: *mut Allocator) -> *mut Sockaddr_t;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_normalizeNative(nativeSockaddr: *mut ::std::os::raw::c_void);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_hash(addr: *const Sockaddr_t) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Sockaddr_compare(a: *const Sockaddr_t, b: *const Sockaddr_t) -> ::std::os::raw::c_int;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn Version_isCompatible(one: u32, two: u32) -> ::std::os::raw::c_int;
|
||||
}
|
||||
|
@@ -127,16 +127,16 @@ impl Message {
|
||||
#[inline]
|
||||
pub fn data_ptr(&self) -> usize {
|
||||
let msg = unsafe { &mut (*self.msg) };
|
||||
msg.msgbytes as usize
|
||||
msg._msgbytes as usize
|
||||
}
|
||||
|
||||
/// Get the read-only view into the message data as byte slice.
|
||||
#[inline]
|
||||
pub fn bytes(&self) -> &[u8] {
|
||||
let msg = unsafe { &mut (*self.msg) };
|
||||
debug_assert!(!msg.msgbytes.is_null());
|
||||
debug_assert!(!msg._msgbytes.is_null());
|
||||
debug_assert!(msg._length >= 0);
|
||||
let ptr = msg.msgbytes as *const u8;
|
||||
let ptr = msg._msgbytes as *const u8;
|
||||
let len = msg._length as usize;
|
||||
unsafe { from_raw_parts(ptr, len) }
|
||||
}
|
||||
@@ -145,9 +145,9 @@ impl Message {
|
||||
#[inline]
|
||||
pub fn bytes_mut(&mut self) -> &mut [u8] {
|
||||
let msg = unsafe { &mut (*self.msg) };
|
||||
debug_assert!(!msg.msgbytes.is_null());
|
||||
debug_assert!(!msg._msgbytes.is_null());
|
||||
debug_assert!(msg._length >= 0);
|
||||
let ptr = msg.msgbytes;
|
||||
let ptr = msg._msgbytes;
|
||||
let len = msg._length as usize;
|
||||
unsafe { from_raw_parts_mut(ptr, len) }
|
||||
}
|
||||
@@ -345,7 +345,7 @@ impl Message {
|
||||
#[inline]
|
||||
fn data_ref<T>(&self) -> Option<&T> {
|
||||
let msg = unsafe { &mut (*self.msg) };
|
||||
let ptr = msg.msgbytes as usize;
|
||||
let ptr = msg._msgbytes as usize;
|
||||
let align = std::mem::align_of::<T>();
|
||||
if ptr % align == 0 {
|
||||
let ptr = ptr as *const T;
|
||||
@@ -359,7 +359,7 @@ impl Message {
|
||||
#[inline]
|
||||
fn data_ref_mut<T>(&mut self) -> Option<&mut T> {
|
||||
let msg = unsafe { &mut (*self.msg) };
|
||||
let ptr = msg.msgbytes as usize;
|
||||
let ptr = msg._msgbytes as usize;
|
||||
let align = std::mem::align_of::<T>();
|
||||
if ptr % align == 0 {
|
||||
let ptr = ptr as *mut T;
|
||||
@@ -390,7 +390,7 @@ impl Message {
|
||||
|
||||
msg._length += amount;
|
||||
msg._capacity += amount;
|
||||
msg.msgbytes = (msg.msgbytes as isize - amount as isize) as *mut u8;
|
||||
msg._msgbytes = (msg._msgbytes as isize - amount as isize) as *mut u8;
|
||||
msg._padding -= amount;
|
||||
|
||||
Ok(())
|
||||
|
@@ -15,10 +15,9 @@ struct FdReadable {
|
||||
|
||||
pub struct Rffi_FdReadableTx(Arc<FdReadable>);
|
||||
|
||||
pub extern "C" fn fd_readable_on_free(j: *mut Allocator_OnFreeJob) -> c_int {
|
||||
pub extern "C" fn fd_readable_on_free(j: *mut Allocator_OnFreeJob) {
|
||||
let timer_tx = unsafe { &*((*j).userData as *mut Rffi_FdReadableTx) };
|
||||
timer_tx.0.active.store(false, Ordering::Relaxed);
|
||||
0
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
@@ -25,11 +25,10 @@ pub struct TimerTx {
|
||||
active: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
pub extern "C" fn timeout_on_free(j: *mut Allocator_OnFreeJob) -> c_int {
|
||||
pub extern "C" fn timeout_on_free(j: *mut Allocator_OnFreeJob) {
|
||||
let timer_tx = unsafe { &*((*j).userData as *mut Rffi_TimerTx) };
|
||||
timer_tx.0.active.store(false, Ordering::Relaxed);
|
||||
timer_tx.0.rffi_send(TimerCommand::Free);
|
||||
0
|
||||
}
|
||||
|
||||
/// Spawn a timer task for a timeout or interval, that calls some callback whenever it triggers.
|
||||
|
@@ -45,9 +45,9 @@ static inline int LinkState_encode(
|
||||
if (Message_getPadding(msg) < 255) { return 1; }
|
||||
|
||||
struct VarInt_Iter iter = {
|
||||
.ptr = msg->msgbytes,
|
||||
.end = msg->msgbytes,
|
||||
.start = &msg->msgbytes[-Message_getPadding(msg)]
|
||||
.ptr = Message_bytes(msg),
|
||||
.end = Message_bytes(msg),
|
||||
.start = &Message_bytes(msg)[-Message_getPadding(msg)]
|
||||
};
|
||||
|
||||
// Take the newest X entries where X = MIN(ls->samples - lastSamples, LinkState_SLOTS)
|
||||
@@ -68,11 +68,11 @@ static inline int LinkState_encode(
|
||||
Assert_true(!VarInt_push(&iter, ls->nodeId));
|
||||
|
||||
int beginLength = Message_getLength(msg);
|
||||
Er_assert(Message_eshift(msg, (msg->msgbytes - iter.ptr)));
|
||||
Assert_true(msg->msgbytes == iter.ptr);
|
||||
Er_assert(Message_eshift(msg, (Message_bytes(msg) - iter.ptr)));
|
||||
Assert_true(Message_bytes(msg) == iter.ptr);
|
||||
|
||||
int padCount = 0;
|
||||
while ((uintptr_t)(&msg->msgbytes[-3]) & 7) {
|
||||
while ((uintptr_t)(&Message_bytes(msg)[-3]) & 7) {
|
||||
Er_assert(Message_epush8(msg, 0));
|
||||
padCount++;
|
||||
}
|
||||
@@ -82,19 +82,19 @@ static inline int LinkState_encode(
|
||||
int finalLength = Message_getLength(msg) - beginLength;
|
||||
Er_assert(Message_epush8(msg, finalLength + 1));
|
||||
|
||||
Assert_true(!(((uintptr_t)msg->msgbytes) & 7));
|
||||
Assert_true(!(((uintptr_t)Message_bytes(msg)) & 7));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int LinkState_mkDecoder(struct Message* msg, struct VarInt_Iter* it)
|
||||
{
|
||||
if (!Message_getLength(msg)) { return 1; }
|
||||
uint8_t len = msg->msgbytes[0];
|
||||
uint8_t len = Message_bytes(msg)[0];
|
||||
if (Message_getLength(msg) < len) { return 1; }
|
||||
if (len < 3) { return 1; }
|
||||
it->ptr = &msg->msgbytes[1];
|
||||
it->ptr = &Message_bytes(msg)[1];
|
||||
it->start = it->ptr;
|
||||
it->end = &msg->msgbytes[len];
|
||||
it->end = &Message_bytes(msg)[len];
|
||||
// Ok to pop this using VarInt because it's supposed to be 3, which is less than 253
|
||||
uint64_t type = 0;
|
||||
if (VarInt_pop(it, &type)) { return 1; }
|
||||
|
@@ -283,7 +283,7 @@ static Iface_DEFUN incoming(struct Message* msg, struct Iface* interRouterIf)
|
||||
Identity_containerOf(interRouterIf, struct MsgCore_pvt, pub.interRouterIf);
|
||||
|
||||
struct Address addr = { .padding = 0 };
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* hdr = (struct RouteHeader*) Message_bytes(msg);
|
||||
Er_assert(Message_eshift(msg, -(RouteHeader_SIZE + DataHeader_SIZE)));
|
||||
Bits_memcpy(addr.ip6.bytes, hdr->ip6, 16);
|
||||
Bits_memcpy(addr.key, hdr->publicKey, 32);
|
||||
@@ -291,7 +291,7 @@ static Iface_DEFUN incoming(struct Message* msg, struct Iface* interRouterIf)
|
||||
addr.path = Endian_bigEndianToHost64(hdr->sh.label_be);
|
||||
|
||||
Dict* content = NULL;
|
||||
uint8_t* msgBytes = msg->msgbytes;
|
||||
uint8_t* msgBytes = Message_bytes(msg);
|
||||
int length = Message_getLength(msg);
|
||||
//Log_debug(mcp->log, "Receive msg [%s] from [%s]",
|
||||
// Escape_getEscaped(msg->bytes, Message_getLength(msg), Message_getAlloc(msg)),
|
||||
|
@@ -80,7 +80,7 @@ static int64_t timeUntilReannounce(
|
||||
|
||||
static int64_t timestampFromMsg(struct Message* msg)
|
||||
{
|
||||
struct Announce_Header* hdr = (struct Announce_Header*) msg->msgbytes;
|
||||
struct Announce_Header* hdr = (struct Announce_Header*) Message_bytes(msg);
|
||||
Assert_true(Message_getLength(msg) >= Announce_Header_SIZE);
|
||||
return Announce_Header_getTimestamp(hdr);
|
||||
}
|
||||
@@ -110,7 +110,7 @@ static void hashMsgList(struct ArrayList_OfMessages* msgList, uint8_t out[64])
|
||||
for (int i = 0; i < msgList->length; i++) {
|
||||
struct Message* msg = ArrayList_OfMessages_get(msgList, i);
|
||||
Er_assert(Message_epush(msg, hash, 64));
|
||||
crypto_hash_sha512(hash, msg->msgbytes, Message_getLength(msg));
|
||||
crypto_hash_sha512(hash, Message_bytes(msg), Message_getLength(msg));
|
||||
Er_assert(Message_epop(msg, NULL, 64));
|
||||
}
|
||||
Bits_memcpy(out, hash, 64);
|
||||
@@ -358,7 +358,7 @@ static int updateItem(struct ReachabilityAnnouncer_pvt* rap,
|
||||
}
|
||||
|
||||
Er_assert(Message_epush(msg, refItem, refItem->length));
|
||||
while ((uintptr_t)msg->msgbytes % 4) {
|
||||
while ((uintptr_t)Message_bytes(msg) % 4) {
|
||||
// Ensure alignment
|
||||
Er_assert(Message_epush8(msg, 1));
|
||||
}
|
||||
@@ -686,7 +686,7 @@ static void onAnnounceCycle(void* vRap)
|
||||
|
||||
Er_assert(Message_epush(msg, NULL, Announce_Header_SIZE));
|
||||
|
||||
struct Announce_Header* hdr = (struct Announce_Header*) msg->msgbytes;
|
||||
struct Announce_Header* hdr = (struct Announce_Header*) Message_bytes(msg);
|
||||
Bits_memset(hdr, 0, Announce_Header_SIZE);
|
||||
Announce_Header_setVersion(hdr, Announce_Header_CURRENT_VERSION);
|
||||
Announce_Header_setReset(hdr, rap->resetState);
|
||||
@@ -711,7 +711,7 @@ static void onAnnounceCycle(void* vRap)
|
||||
qp->target = &q->target;
|
||||
|
||||
Dict_putStringCC(dict, "sq", "ann", qp->alloc);
|
||||
String* annString = String_newBinary(msg->msgbytes, Message_getLength(msg), qp->alloc);
|
||||
String* annString = String_newBinary(Message_bytes(msg), Message_getLength(msg), qp->alloc);
|
||||
Dict_putStringC(dict, "ann", annString, qp->alloc);
|
||||
|
||||
rap->onTheWire = q;
|
||||
@@ -773,7 +773,7 @@ static struct Announce_ItemHeader* mkEncodingSchemeItem(
|
||||
Er_assert(Message_epush8(esMsg, compressedScheme->len + 2));
|
||||
|
||||
struct Announce_ItemHeader* item = Allocator_calloc(alloc, Message_getLength(esMsg), 1);
|
||||
Bits_memcpy(item, esMsg->msgbytes, Message_getLength(esMsg));
|
||||
Bits_memcpy(item, Message_bytes(esMsg), Message_getLength(esMsg));
|
||||
Allocator_free(tmpAlloc);
|
||||
return item;
|
||||
}
|
||||
|
@@ -106,9 +106,9 @@ static Iface_DEFUN sendNode(struct Message* msg,
|
||||
{
|
||||
Message_reset(msg);
|
||||
Er_assert(Message_eshift(msg, PFChan_Node_SIZE));
|
||||
nodeForAddress((struct PFChan_Node*) msg->msgbytes, addr, metric);
|
||||
nodeForAddress((struct PFChan_Node*) Message_bytes(msg), addr, metric);
|
||||
if (addr->path == UINT64_MAX) {
|
||||
((struct PFChan_Node*) msg->msgbytes)->path_be = 0;
|
||||
((struct PFChan_Node*) Message_bytes(msg))->path_be = 0;
|
||||
}
|
||||
Er_assert(Message_epush32be(msg, msgType));
|
||||
return Iface_next(&pf->pub.eventIf, msg);
|
||||
@@ -473,7 +473,7 @@ static Iface_DEFUN incomingFromMsgCore(struct Message* msg, struct Iface* iface)
|
||||
struct SubnodePathfinder_pvt* pf =
|
||||
Identity_containerOf(iface, struct SubnodePathfinder_pvt, msgCoreIf);
|
||||
Assert_true(Message_getLength(msg) >= (RouteHeader_SIZE + DataHeader_SIZE));
|
||||
struct RouteHeader* rh = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* rh = (struct RouteHeader*) Message_bytes(msg);
|
||||
struct DataHeader* dh = (struct DataHeader*) &rh[1];
|
||||
Assert_true(DataHeader_getContentType(dh) == ContentType_CJDHT);
|
||||
Assert_true(!Bits_isZero(rh->publicKey, 32));
|
||||
|
@@ -75,7 +75,7 @@ static void randomLsUpdate(struct Random* rand, struct LinkState* ls)
|
||||
static void applyStateUpdates(struct LinkState* local, struct Message* msg)
|
||||
{
|
||||
if (!Message_getLength(msg)) { return; }
|
||||
uint8_t length = msg->msgbytes[0];
|
||||
uint8_t length = Message_bytes(msg)[0];
|
||||
struct VarInt_Iter it;
|
||||
Assert_true(!LinkState_mkDecoder(msg, &it));
|
||||
uint32_t id = 0;
|
||||
|
@@ -74,7 +74,7 @@ static inline Iface_DEFUN sendError(struct SwitchInterface* iface,
|
||||
return Error(cause, "RUNT");
|
||||
}
|
||||
|
||||
struct SwitchHeader* causeHeader = (struct SwitchHeader*) cause->msgbytes;
|
||||
struct SwitchHeader* causeHeader = (struct SwitchHeader*) Message_bytes(cause);
|
||||
|
||||
if (SwitchHeader_getSuppressErrors(causeHeader)) {
|
||||
// don't send errors if they're asking us to suppress them!
|
||||
@@ -90,7 +90,7 @@ static inline Iface_DEFUN sendError(struct SwitchInterface* iface,
|
||||
Er_assert(Message_epush(cause,
|
||||
NULL,
|
||||
SwitchHeader_SIZE + 4 + Control_Header_SIZE + Control_Error_HEADER_SIZE));
|
||||
struct ErrorPacket8* err = (struct ErrorPacket8*) cause->msgbytes;
|
||||
struct ErrorPacket8* err = (struct ErrorPacket8*) Message_bytes(cause);
|
||||
|
||||
err->switchHeader.label_be = Bits_bitReverse64(causeHeader->label_be);
|
||||
SwitchHeader_setSuppressErrors(&err->switchHeader, true);
|
||||
@@ -123,7 +123,7 @@ static Iface_DEFUN receiveMessage(struct Message* message, struct Iface* iface)
|
||||
return Error(message, "RUNT");
|
||||
}
|
||||
|
||||
struct SwitchHeader* header = (struct SwitchHeader*) message->msgbytes;
|
||||
struct SwitchHeader* header = (struct SwitchHeader*) Message_bytes(message);
|
||||
const uint64_t label = Endian_bigEndianToHost64(header->label_be);
|
||||
uint32_t bits = NumberCompress_bitsUsedForLabel(label);
|
||||
const uint32_t sourceIndex = sourceIf - core->interfaces;
|
||||
@@ -206,7 +206,7 @@ static Iface_DEFUN receiveMessage(struct Message* message, struct Iface* iface)
|
||||
int cloneLength = (Message_getLength(message) < Control_Error_MAX_SIZE) ?
|
||||
Message_getLength(message) : Control_Error_MAX_SIZE;
|
||||
uint8_t messageClone[Control_Error_MAX_SIZE];
|
||||
Bits_memcpy(messageClone, message->msgbytes, cloneLength);
|
||||
Bits_memcpy(messageClone, Message_bytes(message), cloneLength);
|
||||
|
||||
// Update the header
|
||||
header->label_be = Endian_hostToBigEndian64(targetLabel);
|
||||
|
@@ -67,7 +67,7 @@ static Iface_DEFUN incomingTunB(struct Message* msg, struct Iface* tunB)
|
||||
uint16_t t = Er_assert(TUNMessageType_pop(msg));
|
||||
Assert_true(t == Ethernet_TYPE_IP6);
|
||||
Er_assert(Message_eshift(msg, -Headers_IP6Header_SIZE));
|
||||
printf("Message from TUN in node B [%s]\n", msg->msgbytes);
|
||||
printf("Message from TUN in node B [%s]\n", Message_bytes(msg));
|
||||
tn->messageFrom = TUNB;
|
||||
return NULL;
|
||||
}
|
||||
@@ -79,8 +79,8 @@ static Iface_DEFUN incomingTunA(struct Message* msg, struct Iface* tunA)
|
||||
Assert_true(t == Ethernet_TYPE_IP6);
|
||||
Er_assert(Message_eshift(msg, -Headers_IP6Header_SIZE));
|
||||
uint8_t buff[1024];
|
||||
Hex_encode(buff, 1024, msg->msgbytes, Message_getLength(msg));
|
||||
printf("Message from TUN in node A [%s] [%d] [%s]\n", msg->msgbytes, Message_getLength(msg), buff);
|
||||
Hex_encode(buff, 1024, Message_bytes(msg), Message_getLength(msg));
|
||||
printf("Message from TUN in node A [%s] [%d] [%s]\n", Message_bytes(msg), Message_getLength(msg), buff);
|
||||
tn->messageFrom = TUNA;
|
||||
return NULL;
|
||||
}
|
||||
|
@@ -150,7 +150,7 @@ void CJDNS_FUZZ_MAIN(void* vctx, struct Message* msg)
|
||||
// Lets fill in the ipv6, pubkey & label so that any
|
||||
// old packet dump will work fine for testing
|
||||
{
|
||||
struct RouteHeader* rh = (struct RouteHeader*) msg->msgbytes;
|
||||
struct RouteHeader* rh = (struct RouteHeader*) Message_bytes(msg);
|
||||
Bits_memcpy(rh->ip6, to->ip, 16);
|
||||
Bits_memcpy(rh->publicKey, to->publicKey, 32);
|
||||
rh->version_be = Endian_hostToBigEndian32(Version_CURRENT_PROTOCOL);
|
||||
@@ -176,11 +176,11 @@ void CJDNS_FUZZ_MAIN(void* vctx, struct Message* msg)
|
||||
// fc00::1
|
||||
AddressCalc_makeValidAddress(&srcAndDest[16]);
|
||||
Bits_memcpy(&srcAndDest, from->ip, 16);
|
||||
uint16_t checksum_be = Checksum_udpIp6_be(srcAndDest, msg->msgbytes, Message_getLength(msg));
|
||||
((struct Headers_UDPHeader*)msg->msgbytes)->checksum_be = checksum_be;
|
||||
uint16_t checksum_be = Checksum_udpIp6_be(srcAndDest, Message_bytes(msg), Message_getLength(msg));
|
||||
((struct Headers_UDPHeader*)Message_bytes(msg))->checksum_be = checksum_be;
|
||||
|
||||
TestFramework_craftIPHeader(msg, srcAndDest, &srcAndDest[16]);
|
||||
((struct Headers_IP6Header*) msg->msgbytes)->nextHeader = 17;
|
||||
((struct Headers_IP6Header*) Message_bytes(msg))->nextHeader = 17;
|
||||
|
||||
Er_assert(TUNMessageType_push(msg, Ethernet_TYPE_IP6));
|
||||
|
||||
|
@@ -60,7 +60,7 @@ static Iface_DEFUN sendTo(struct Message* msg,
|
||||
struct TestFramework* srcTf,
|
||||
struct TestFramework* destTf)
|
||||
{
|
||||
Assert_true(!((uintptr_t)msg->msgbytes % 4) || !"alignment fault");
|
||||
Assert_true(!((uintptr_t)Message_bytes(msg) % 4) || !"alignment fault");
|
||||
Assert_true(!(Message_getCapacity(msg) % 4) || !"length fault");
|
||||
Assert_true(((int)Message_getCapacity(msg) >= Message_getLength(msg)) || !"length fault0");
|
||||
|
||||
@@ -175,7 +175,7 @@ void TestFramework_assertLastMessageUnaltered(struct TestFramework* tf)
|
||||
struct Message* b = tf->lastMsgBackup;
|
||||
Assert_true(Message_getLength(a) == Message_getLength(b));
|
||||
Assert_true(Message_getPadding(a) == Message_getPadding(b));
|
||||
Assert_true(!Bits_memcmp(a->msgbytes, b->msgbytes, Message_getLength(a)));
|
||||
Assert_true(!Bits_memcmp(Message_bytes(a), Message_bytes(b), Message_getLength(a)));
|
||||
}
|
||||
|
||||
void TestFramework_linkNodes(struct TestFramework* client,
|
||||
@@ -230,7 +230,7 @@ void TestFramework_linkNodes(struct TestFramework* client,
|
||||
void TestFramework_craftIPHeader(struct Message* msg, uint8_t srcAddr[16], uint8_t destAddr[16])
|
||||
{
|
||||
Er_assert(Message_eshift(msg, Headers_IP6Header_SIZE));
|
||||
struct Headers_IP6Header* ip = (struct Headers_IP6Header*) msg->msgbytes;
|
||||
struct Headers_IP6Header* ip = (struct Headers_IP6Header*) Message_bytes(msg);
|
||||
|
||||
ip->versionClassAndFlowLabel = 0;
|
||||
ip->flowLabelLow_be = 0;
|
||||
|
@@ -200,7 +200,7 @@ static Iface_DEFUN sendToNode(struct Message* message,
|
||||
struct IpTunnel_pvt* context)
|
||||
{
|
||||
Er_assert(Message_epush(message, NULL, DataHeader_SIZE));
|
||||
struct DataHeader* dh = (struct DataHeader*) message->msgbytes;
|
||||
struct DataHeader* dh = (struct DataHeader*) Message_bytes(message);
|
||||
DataHeader_setContentType(dh, ContentType_IPTUN);
|
||||
DataHeader_setVersion(dh, DataHeader_CURRENT_VERSION);
|
||||
Er_assert(Message_epush(message, &connection->routeHeader, RouteHeader_SIZE));
|
||||
@@ -219,7 +219,7 @@ static void sendControlMessage(Dict* dict,
|
||||
|
||||
// do UDP header.
|
||||
Er_assert(Message_eshift(msg, Headers_UDPHeader_SIZE));
|
||||
struct Headers_UDPHeader* uh = (struct Headers_UDPHeader*) msg->msgbytes;
|
||||
struct Headers_UDPHeader* uh = (struct Headers_UDPHeader*) Message_bytes(msg);
|
||||
uh->srcPort_be = 0;
|
||||
uh->destPort_be = 0;
|
||||
uh->length_be = Endian_hostToBigEndian16(length);
|
||||
@@ -228,7 +228,7 @@ static void sendControlMessage(Dict* dict,
|
||||
uint16_t payloadLength = Message_getLength(msg);
|
||||
|
||||
Er_assert(Message_eshift(msg, Headers_IP6Header_SIZE));
|
||||
struct Headers_IP6Header* header = (struct Headers_IP6Header*) msg->msgbytes;
|
||||
struct Headers_IP6Header* header = (struct Headers_IP6Header*) Message_bytes(msg);
|
||||
header->versionClassAndFlowLabel = 0;
|
||||
header->flowLabelLow_be = 0;
|
||||
header->nextHeader = 17;
|
||||
@@ -318,7 +318,7 @@ int IpTunnel_removeConnection(int connectionNumber, struct IpTunnel* tunnel)
|
||||
|
||||
static bool isControlMessageInvalid(struct Message* message, struct IpTunnel_pvt* context)
|
||||
{
|
||||
struct Headers_IP6Header* header = (struct Headers_IP6Header*) message->msgbytes;
|
||||
struct Headers_IP6Header* header = (struct Headers_IP6Header*) Message_bytes(message);
|
||||
uint16_t length = Endian_bigEndianToHost16(header->payloadLength_be);
|
||||
if (header->nextHeader != 17 || Message_getLength(message) < length + Headers_IP6Header_SIZE) {
|
||||
Log_warn(context->logger, "Invalid IPv6 packet (not UDP or length field too big)");
|
||||
@@ -326,9 +326,9 @@ static bool isControlMessageInvalid(struct Message* message, struct IpTunnel_pvt
|
||||
}
|
||||
|
||||
Er_assert(Message_eshift(message, -Headers_IP6Header_SIZE));
|
||||
struct Headers_UDPHeader* udp = (struct Headers_UDPHeader*) message->msgbytes;
|
||||
struct Headers_UDPHeader* udp = (struct Headers_UDPHeader*) Message_bytes(message);
|
||||
|
||||
if (Checksum_udpIp6_be(header->sourceAddr, message->msgbytes, length)) {
|
||||
if (Checksum_udpIp6_be(header->sourceAddr, Message_bytes(message), length)) {
|
||||
Log_warn(context->logger, "Checksum mismatch");
|
||||
return true;
|
||||
}
|
||||
@@ -585,7 +585,7 @@ static Iface_DEFUN incomingControlMessage(struct Message* message,
|
||||
}
|
||||
|
||||
Log_debug(context->logger, "Message content [%s]",
|
||||
Escape_getEscaped(message->msgbytes, Message_getLength(message), Message_getAlloc(message)));
|
||||
Escape_getEscaped(Message_bytes(message), Message_getLength(message), Message_getAlloc(message)));
|
||||
|
||||
struct Allocator* alloc = Allocator_child(Message_getAlloc(message));
|
||||
|
||||
@@ -708,12 +708,12 @@ static Iface_DEFUN incomingFromTun(struct Message* message, struct Iface* tunIf)
|
||||
struct IpTunnel_Connection* conn = NULL;
|
||||
if (!context->pub.connectionList.connections) {
|
||||
// No connections authorized, fall through to "unrecognized address"
|
||||
} else if (Message_getLength(message) > 40 && Headers_getIpVersion(message->msgbytes) == 6) {
|
||||
struct Headers_IP6Header* header = (struct Headers_IP6Header*) message->msgbytes;
|
||||
} else if (Message_getLength(message) > 40 && Headers_getIpVersion(Message_bytes(message)) == 6) {
|
||||
struct Headers_IP6Header* header = (struct Headers_IP6Header*) Message_bytes(message);
|
||||
conn = findConnection(
|
||||
header->sourceAddr, header->destinationAddr, NULL, NULL, true, context);
|
||||
} else if (Message_getLength(message) > 20 && Headers_getIpVersion(message->msgbytes) == 4) {
|
||||
struct Headers_IP4Header* header = (struct Headers_IP4Header*) message->msgbytes;
|
||||
} else if (Message_getLength(message) > 20 && Headers_getIpVersion(Message_bytes(message)) == 4) {
|
||||
struct Headers_IP4Header* header = (struct Headers_IP4Header*) Message_bytes(message);
|
||||
conn = findConnection(NULL, NULL, header->sourceAddr, header->destAddr, true, context);
|
||||
} else {
|
||||
Log_debug(context->logger, "Message of unknown type from TUN");
|
||||
@@ -732,7 +732,7 @@ static Iface_DEFUN ip6FromNode(struct Message* message,
|
||||
struct IpTunnel_Connection* conn,
|
||||
struct IpTunnel_pvt* context)
|
||||
{
|
||||
struct Headers_IP6Header* header = (struct Headers_IP6Header*) message->msgbytes;
|
||||
struct Headers_IP6Header* header = (struct Headers_IP6Header*) Message_bytes(message);
|
||||
if (Bits_isZero(header->sourceAddr, 16) || Bits_isZero(header->destinationAddr, 16)) {
|
||||
if (Bits_isZero(header->sourceAddr, 32)) {
|
||||
return incomingControlMessage(message, conn, context);
|
||||
@@ -755,7 +755,7 @@ static Iface_DEFUN ip4FromNode(struct Message* message,
|
||||
struct IpTunnel_Connection* conn,
|
||||
struct IpTunnel_pvt* context)
|
||||
{
|
||||
struct Headers_IP4Header* header = (struct Headers_IP4Header*) message->msgbytes;
|
||||
struct Headers_IP4Header* header = (struct Headers_IP4Header*) Message_bytes(message);
|
||||
if (Bits_isZero(header->sourceAddr, 4) || Bits_isZero(header->destAddr, 4)) {
|
||||
Log_debug(context->logger, "Got message with zero address");
|
||||
return Error(message, "INVALID");
|
||||
@@ -782,7 +782,7 @@ static Iface_DEFUN incomingFromNode(struct Message* message, struct Iface* nodeI
|
||||
//Log_debug(context->logger, "Got incoming message");
|
||||
|
||||
Assert_true(Message_getLength(message) >= RouteHeader_SIZE + DataHeader_SIZE);
|
||||
struct RouteHeader* rh = (struct RouteHeader*) message->msgbytes;
|
||||
struct RouteHeader* rh = (struct RouteHeader*) Message_bytes(message);
|
||||
struct DataHeader* dh = (struct DataHeader*) &rh[1];
|
||||
Assert_true(DataHeader_getContentType(dh) == ContentType_IPTUN);
|
||||
struct IpTunnel_Connection* conn = connectionByPubKey(rh->publicKey, context);
|
||||
@@ -797,10 +797,10 @@ static Iface_DEFUN incomingFromNode(struct Message* message, struct Iface* nodeI
|
||||
|
||||
Er_assert(Message_eshift(message, -(RouteHeader_SIZE + DataHeader_SIZE)));
|
||||
|
||||
if (Message_getLength(message) > 40 && Headers_getIpVersion(message->msgbytes) == 6) {
|
||||
if (Message_getLength(message) > 40 && Headers_getIpVersion(Message_bytes(message)) == 6) {
|
||||
return ip6FromNode(message, conn, context);
|
||||
}
|
||||
if (Message_getLength(message) > 20 && Headers_getIpVersion(message->msgbytes) == 4) {
|
||||
if (Message_getLength(message) > 20 && Headers_getIpVersion(Message_bytes(message)) == 4) {
|
||||
return ip4FromNode(message, conn, context);
|
||||
}
|
||||
|
||||
@@ -810,7 +810,7 @@ static Iface_DEFUN incomingFromNode(struct Message* message, struct Iface* nodeI
|
||||
Log_debug(context->logger,
|
||||
"Got message of unknown type, length: [%d], IP version [%d] from [%s]",
|
||||
Message_getLength(message),
|
||||
(Message_getLength(message) > 1) ? Headers_getIpVersion(message->msgbytes) : 0,
|
||||
(Message_getLength(message) > 1) ? Headers_getIpVersion(Message_bytes(message)) : 0,
|
||||
addr);
|
||||
}
|
||||
return Error(message, "INVALID");
|
||||
|
@@ -59,12 +59,12 @@ struct IfaceContext
|
||||
static Iface_DEFUN responseWithIpCallback(struct Message* message, struct Iface* iface)
|
||||
{
|
||||
struct Context* ctx = Identity_check(((struct IfaceContext*)iface)->ctx);
|
||||
struct RouteHeader* rh = (struct RouteHeader*) message->msgbytes;
|
||||
struct RouteHeader* rh = (struct RouteHeader*) Message_bytes(message);
|
||||
Assert_true(!Bits_memcmp(ctx->ipv6, rh->ip6, 16));
|
||||
Assert_true(!Bits_memcmp(ctx->pubKey, rh->publicKey, 32));
|
||||
|
||||
Er_assert(Message_eshift(message, -(RouteHeader_SIZE + DataHeader_SIZE)));
|
||||
struct Headers_IP6Header* ip = (struct Headers_IP6Header*) message->msgbytes;
|
||||
struct Headers_IP6Header* ip = (struct Headers_IP6Header*) Message_bytes(message);
|
||||
Assert_true(Headers_getIpVersion(ip) == 6);
|
||||
uint16_t length = Endian_bigEndianToHost16(ip->payloadLength_be);
|
||||
Assert_true(length + Headers_IP6Header_SIZE == Message_getLength(message));
|
||||
@@ -72,8 +72,8 @@ static Iface_DEFUN responseWithIpCallback(struct Message* message, struct Iface*
|
||||
Assert_true(Bits_isZero(ip->sourceAddr, 32));
|
||||
|
||||
Er_assert(Message_eshift(message, -Headers_IP6Header_SIZE));
|
||||
struct Headers_UDPHeader* uh = (struct Headers_UDPHeader*) message->msgbytes;
|
||||
Assert_true(!Checksum_udpIp6_be(ip->sourceAddr, message->msgbytes, length));
|
||||
struct Headers_UDPHeader* uh = (struct Headers_UDPHeader*) Message_bytes(message);
|
||||
Assert_true(!Checksum_udpIp6_be(ip->sourceAddr, Message_bytes(message), length));
|
||||
|
||||
Assert_true(uh->srcPort_be == 0);
|
||||
Assert_true(uh->destPort_be == 0);
|
||||
@@ -82,7 +82,7 @@ static Iface_DEFUN responseWithIpCallback(struct Message* message, struct Iface*
|
||||
Er_assert(Message_eshift(message, -Headers_UDPHeader_SIZE));
|
||||
|
||||
struct Allocator* alloc = Allocator_child(ctx->alloc);
|
||||
char* messageContent = Escape_getEscaped(message->msgbytes, Message_getLength(message), alloc);
|
||||
char* messageContent = Escape_getEscaped(Message_bytes(message), Message_getLength(message), alloc);
|
||||
char* expectedContent =
|
||||
Escape_getEscaped(ctx->expectedResponse->bytes, ctx->expectedResponse->len, alloc);
|
||||
Log_debug(ctx->log, "Response: [%s]", messageContent);
|
||||
@@ -93,7 +93,7 @@ static Iface_DEFUN responseWithIpCallback(struct Message* message, struct Iface*
|
||||
// alignment of the output but we can make sure the right content is there...
|
||||
// Message should start with "d0000" (with some number of zeros)
|
||||
Assert_true((int)ctx->expectedResponse->len == Message_getLength(message));
|
||||
Assert_true(!Bits_memcmp(message->msgbytes, ctx->expectedResponse->bytes, Message_getLength(message)));
|
||||
Assert_true(!Bits_memcmp(Message_bytes(message), ctx->expectedResponse->bytes, Message_getLength(message)));
|
||||
ctx->called |= 2;
|
||||
|
||||
return NULL;
|
||||
@@ -104,13 +104,13 @@ static Iface_DEFUN messageToTun(struct Message* msg, struct Iface* iface)
|
||||
struct Context* ctx = Identity_check(((struct IfaceContext*)iface)->ctx);
|
||||
uint16_t type = Er_assert(TUNMessageType_pop(msg));
|
||||
if (type == Ethernet_TYPE_IP6) {
|
||||
struct Headers_IP6Header* ip = (struct Headers_IP6Header*) msg->msgbytes;
|
||||
struct Headers_IP6Header* ip = (struct Headers_IP6Header*) Message_bytes(msg);
|
||||
Assert_true(Headers_getIpVersion(ip) == 6);
|
||||
Assert_true(!Bits_memcmp(ip->sourceAddr, ctx->sendingAddress, 16));
|
||||
Er_assert(Message_eshift(msg, -Headers_IP6Header_SIZE));
|
||||
ctx->called |= 4;
|
||||
} else if (type == Ethernet_TYPE_IP4) {
|
||||
struct Headers_IP4Header* ip = (struct Headers_IP4Header*) msg->msgbytes;
|
||||
struct Headers_IP4Header* ip = (struct Headers_IP4Header*) Message_bytes(msg);
|
||||
Assert_true(Headers_getIpVersion(ip) == 4);
|
||||
Assert_true(!Bits_memcmp(ip->sourceAddr, ctx->sendingAddress, 4));
|
||||
Er_assert(Message_eshift(msg, -Headers_IP4Header_SIZE));
|
||||
@@ -118,14 +118,14 @@ static Iface_DEFUN messageToTun(struct Message* msg, struct Iface* iface)
|
||||
} else {
|
||||
Assert_failure("unrecognized message type %u", (unsigned int)type);
|
||||
}
|
||||
Assert_true(Message_getLength(msg) == 12 && CString_strcmp(msg->msgbytes, "hello world") == 0);
|
||||
Assert_true(Message_getLength(msg) == 12 && CString_strcmp(Message_bytes(msg), "hello world") == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void pushRouteDataHeaders(struct Context* ctx, struct Message* message)
|
||||
{
|
||||
Er_assert(Message_eshift(message, RouteHeader_SIZE + DataHeader_SIZE));
|
||||
struct RouteHeader* rh = (struct RouteHeader*) message->msgbytes;
|
||||
struct RouteHeader* rh = (struct RouteHeader*) Message_bytes(message);
|
||||
struct DataHeader* dh = (struct DataHeader*) &rh[1];
|
||||
Bits_memset(rh, 0, RouteHeader_SIZE + DataHeader_SIZE);
|
||||
Bits_memcpy(rh->ip6, ctx->ipv6, 16);
|
||||
@@ -141,7 +141,7 @@ static bool trySend4(struct Allocator* alloc,
|
||||
struct Message* msg4 = Message_new(0, 512, alloc);
|
||||
Er_assert(Message_epush(msg4, "hello world", 12));
|
||||
Er_assert(Message_epush(msg4, NULL, Headers_IP4Header_SIZE));
|
||||
struct Headers_IP4Header* iph = (struct Headers_IP4Header*) msg4->msgbytes;
|
||||
struct Headers_IP4Header* iph = (struct Headers_IP4Header*) Message_bytes(msg4);
|
||||
Headers_setIpVersion(iph);
|
||||
uint32_t addr_be = Endian_hostToBigEndian32(addr);
|
||||
Bits_memcpy(iph->sourceAddr, &addr_be, 4);
|
||||
@@ -166,7 +166,7 @@ static bool trySend6(struct Allocator* alloc,
|
||||
struct Message* msg6 = Message_new(0, 512, alloc);
|
||||
Er_assert(Message_epush(msg6, "hello world", 12));
|
||||
Er_assert(Message_epush(msg6, NULL, Headers_IP6Header_SIZE));
|
||||
struct Headers_IP6Header* iph = (struct Headers_IP6Header*) msg6->msgbytes;
|
||||
struct Headers_IP6Header* iph = (struct Headers_IP6Header*) Message_bytes(msg6);
|
||||
Headers_setIpVersion(iph);
|
||||
uint64_t addrHigh_be = Endian_hostToBigEndian64(addrHigh);
|
||||
uint64_t addrLow_be = Endian_hostToBigEndian64(addrLow);
|
||||
@@ -216,7 +216,7 @@ static String* getExpectedResponse(struct Sockaddr* sa4, int prefix4, int alloc4
|
||||
struct Message* msg = Message_new(0, 512, alloc);
|
||||
Er_assert(BencMessageWriter_write(output, msg));
|
||||
|
||||
String* outStr = String_newBinary(msg->msgbytes, Message_getLength(msg), allocator);
|
||||
String* outStr = String_newBinary(Message_bytes(msg), Message_getLength(msg), allocator);
|
||||
Allocator_free(alloc);
|
||||
return outStr;
|
||||
}
|
||||
@@ -255,20 +255,20 @@ static void testAddr(struct Context* ctx,
|
||||
"1:q" "21:IpTunnel_getAddresses"
|
||||
"4:txid" "4:abcd"
|
||||
"e";
|
||||
CString_strcpy(msg->msgbytes, requestForAddresses);
|
||||
CString_strcpy(Message_bytes(msg), requestForAddresses);
|
||||
Er_assert(Message_truncate(msg, CString_strlen(requestForAddresses)));
|
||||
|
||||
Er_assert(Message_epush(msg, NULL, Headers_UDPHeader_SIZE));
|
||||
struct Headers_UDPHeader* uh = (struct Headers_UDPHeader*) msg->msgbytes;
|
||||
struct Headers_UDPHeader* uh = (struct Headers_UDPHeader*) Message_bytes(msg);
|
||||
uh->length_be = Endian_hostToBigEndian16(Message_getLength(msg) - Headers_UDPHeader_SIZE);
|
||||
|
||||
uint16_t* checksum_be = &((struct Headers_UDPHeader*) msg->msgbytes)->checksum_be;
|
||||
uint16_t* checksum_be = &((struct Headers_UDPHeader*) Message_bytes(msg))->checksum_be;
|
||||
*checksum_be = 0;
|
||||
uint32_t length = Message_getLength(msg);
|
||||
|
||||
// Because of old reasons, we need to have at least an empty IPv6 header
|
||||
Er_assert(Message_epush(msg, NULL, Headers_IP6Header_SIZE));
|
||||
struct Headers_IP6Header* ip = (struct Headers_IP6Header*) msg->msgbytes;
|
||||
struct Headers_IP6Header* ip = (struct Headers_IP6Header*) Message_bytes(msg);
|
||||
Headers_setIpVersion(ip);
|
||||
ip->payloadLength_be = Endian_hostToBigEndian16(Message_getLength(msg) - Headers_IP6Header_SIZE);
|
||||
ip->nextHeader = 17;
|
||||
|
@@ -144,7 +144,7 @@ static Er_DEFUN(void setRoutes(uint32_t ifIndex,
|
||||
struct Message* msg = Message_new(0, 1024, alloc);
|
||||
Er(mkRouteMsg(msg, pfx, ifIndex, ifName, seq++, true));
|
||||
//printf("DELETE ROUTE %s\n", Hex_print(msg->bytes, Message_getLength(msg), alloc));
|
||||
returnLen = write(sock, msg->msgbytes, Message_getLength(msg));
|
||||
returnLen = write(sock, Message_bytes(msg), Message_getLength(msg));
|
||||
if (returnLen < Message_getLength(msg)) { err = true; break; }
|
||||
}
|
||||
for (int i = 0; !err && i < toAdd->length; i++) {
|
||||
@@ -152,7 +152,7 @@ static Er_DEFUN(void setRoutes(uint32_t ifIndex,
|
||||
struct Message* msg = Message_new(0, 1024, alloc);
|
||||
Er(mkRouteMsg(msg, pfx, ifIndex, ifName, seq++, false));
|
||||
//printf("ADD ROUTE %s\n", Hex_print(msg->bytes, Message_getLength(msg), alloc));
|
||||
returnLen = write(sock, msg->msgbytes, Message_getLength(msg));
|
||||
returnLen = write(sock, Message_bytes(msg), Message_getLength(msg));
|
||||
if (returnLen < Message_getLength(msg)) { err = true; break; }
|
||||
}
|
||||
|
||||
|
@@ -241,7 +241,7 @@ static Er_DEFUN(bool getMoreMessages(struct RouteInfo** rio,
|
||||
bool retVal = false;
|
||||
struct Allocator* tempAlloc = Allocator_child(alloc);
|
||||
struct Message* msg = Message_new(BUFF_SZ, 0, tempAlloc);
|
||||
ssize_t sz = recv(sock, msg->msgbytes, BUFF_SZ, MSG_TRUNC);
|
||||
ssize_t sz = recv(sock, Message_bytes(msg), BUFF_SZ, MSG_TRUNC);
|
||||
if (sz < (ssize_t)sizeof(struct nlmsghdr)) {
|
||||
Er_raise(tempAlloc, "recv() -> %s", strerror(errno));
|
||||
} else if (sz > BUFF_SZ) {
|
||||
@@ -377,7 +377,7 @@ static Er_DEFUN(void addDeleteRoutes(int sock,
|
||||
Er(Message_epush(msg, &ifa, sizeof(struct IfIndexAttr)));
|
||||
int addrLen = (ri->af == AF_INET6) ? 16 : 4;
|
||||
Er(Message_epush(msg, ri->dstAddr, addrLen));
|
||||
bitShave(msg->msgbytes, ri->prefix, ri->af);
|
||||
bitShave(Message_bytes(msg), ri->prefix, ri->af);
|
||||
struct rtattr rta = { .rta_len = sizeof(struct rtattr) + addrLen, .rta_type = RTA_DST };
|
||||
Er(Message_epush(msg, &rta, sizeof(struct rtattr)));
|
||||
struct rtmsg route = {
|
||||
@@ -395,7 +395,7 @@ static Er_DEFUN(void addDeleteRoutes(int sock,
|
||||
.nlmsg_flags = NLM_F_REQUEST | ((delete) ? 0 : NLM_F_CREATE) // | NLM_F_ACK,
|
||||
};
|
||||
Er(Message_epush(msg, &hdr, sizeof(struct nlmsghdr)));
|
||||
ssize_t sz = send(sock, msg->msgbytes, Message_getLength(msg), 0);
|
||||
ssize_t sz = send(sock, Message_bytes(msg), Message_getLength(msg), 0);
|
||||
if (sz < 0) {
|
||||
Er_raise(tempAlloc, "send() -> %s", strerror(errno));
|
||||
}
|
||||
|
@@ -42,7 +42,7 @@ int main()
|
||||
snprintf(buff, 31, "%lld", num);
|
||||
|
||||
Assert_true(Message_getLength(msg) == (int)CString_strlen(buff));
|
||||
Assert_true(!Bits_memcmp(msg->msgbytes, buff, Message_getLength(msg)));
|
||||
Assert_true(!Bits_memcmp(Message_bytes(msg), buff, Message_getLength(msg)));
|
||||
|
||||
int64_t read = Er_assert(Base10_read(msg));
|
||||
Assert_true(read == num);
|
||||
|
@@ -79,7 +79,7 @@ static Iface_DEFUN receiveMessageParent(struct Message* msg, struct Iface* iface
|
||||
Er_assert(AddrIface_popAddr(msg));
|
||||
printf("msg length is %d\n", Message_getLength(msg));
|
||||
Assert_true(Message_getLength(msg) == (int)CString_strlen(MESSAGEB)+1);
|
||||
Assert_true(!Bits_memcmp(msg->msgbytes, MESSAGEB, CString_strlen(MESSAGEB)+1));
|
||||
Assert_true(!Bits_memcmp(Message_bytes(msg), MESSAGEB, CString_strlen(MESSAGEB)+1));
|
||||
g_context = c;
|
||||
if (g_childStopped) {
|
||||
printf("Parent stopped in receiveMessageParent\n");
|
||||
@@ -109,7 +109,7 @@ static Iface_DEFUN receiveMessageChild(struct Message* msg, struct Iface* iface)
|
||||
struct Message* m = Message_clone(msg, alloc1);
|
||||
printf("Child received message\n");
|
||||
Assert_true(Message_getLength(m) == (int)CString_strlen(MESSAGE)+1);
|
||||
Assert_true(!Bits_memcmp(m->msgbytes, MESSAGE, CString_strlen(MESSAGE)+1));
|
||||
Assert_true(!Bits_memcmp(Message_bytes(m), MESSAGE, CString_strlen(MESSAGE)+1));
|
||||
|
||||
if (!Defined(win32)) {
|
||||
int fd = Message_getAssociatedFd(msg);
|
||||
|
@@ -105,7 +105,7 @@ static Iface_DEFUN receiveMessageParent(struct Message* msg, struct Iface* iface
|
||||
// PipeServer pushes a uint32 identifier of the client who sent the message
|
||||
Er_assert(AddrIface_popAddr(msg));
|
||||
Assert_true(Message_getLength(msg) == 3);
|
||||
Assert_true(!Bits_memcmp(msg->msgbytes, "OK", 3));
|
||||
Assert_true(!Bits_memcmp(Message_bytes(msg), "OK", 3));
|
||||
printf("Parent got reply\n");
|
||||
EventBase_endLoop(ctx->eventBase);
|
||||
return NULL;
|
||||
|
@@ -77,7 +77,7 @@ static inline void Announce_EncodingScheme_push(struct Message* pushTo, String*
|
||||
Er_assert(Message_epush(pushTo, compressedScheme->bytes, compressedScheme->len));
|
||||
Er_assert(Message_epush8(pushTo, Announce_Type_ENCODING_SCHEME));
|
||||
Er_assert(Message_epush8(pushTo, compressedScheme->len + 2));
|
||||
while ((uintptr_t)pushTo->msgbytes % 4) {
|
||||
while ((uintptr_t)Message_bytes(pushTo) % 4) {
|
||||
Er_assert(Message_epush8(pushTo, 1));
|
||||
}
|
||||
}
|
||||
@@ -331,16 +331,16 @@ static inline struct Announce_ItemHeader* Announce_ItemHeader_next(struct Messag
|
||||
{
|
||||
struct Announce_ItemHeader* ih = (struct Announce_ItemHeader*) last;
|
||||
if (ih) {
|
||||
Assert_true((uint8_t*)ih > &msg->msgbytes[-Message_getPadding(msg)]);
|
||||
Assert_true((uint8_t*)ih < &msg->msgbytes[Message_getLength(msg)]);
|
||||
Assert_true((uint8_t*)ih > &Message_bytes(msg)[-Message_getPadding(msg)]);
|
||||
Assert_true((uint8_t*)ih < &Message_bytes(msg)[Message_getLength(msg)]);
|
||||
ih = (struct Announce_ItemHeader*) ( &((uint8_t*) ih)[ih->length] );
|
||||
} else {
|
||||
ih = (struct Announce_ItemHeader*) &msg->msgbytes[Announce_Header_SIZE];
|
||||
ih = (struct Announce_ItemHeader*) &Message_bytes(msg)[Announce_Header_SIZE];
|
||||
}
|
||||
while ((uint8_t*)ih < &msg->msgbytes[Message_getLength(msg)]) {
|
||||
while ((uint8_t*)ih < &Message_bytes(msg)[Message_getLength(msg)]) {
|
||||
if (!ih->length) { return NULL; } // invalid message
|
||||
if (ih->length > 1) {
|
||||
if ( &((uint8_t*) ih)[ih->length] > &msg->msgbytes[Message_getLength(msg)] ) {
|
||||
if ( &((uint8_t*) ih)[ih->length] > &Message_bytes(msg)[Message_getLength(msg)] ) {
|
||||
// invalid message, overflow...
|
||||
return NULL;
|
||||
}
|
||||
@@ -411,7 +411,7 @@ static inline bool Announce_isValid(struct Message* msg)
|
||||
for (;;) {
|
||||
ih = Announce_ItemHeader_next(msg, ih);
|
||||
if (!ih) { return false; }
|
||||
if ((uint8_t*)ih == &msg->msgbytes[Message_getLength(msg) - ih->length]) { return true; }
|
||||
if ((uint8_t*)ih == &Message_bytes(msg)[Message_getLength(msg) - ih->length]) { return true; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -23,7 +23,7 @@ struct Message* Message_new(uint32_t messageLength,
|
||||
struct Message* out = Allocator_calloc(alloc, sizeof(struct Message), 1);
|
||||
out->_ad = buff;
|
||||
out->_adLen = 0;
|
||||
out->msgbytes = &buff[amountOfPadding];
|
||||
out->_msgbytes = &buff[amountOfPadding];
|
||||
out->_length = out->_capacity = messageLength;
|
||||
out->_padding = amountOfPadding;
|
||||
out->_alloc = alloc;
|
||||
@@ -57,14 +57,14 @@ struct Message* Message_clone(struct Message* toClone, struct Allocator* alloc)
|
||||
Assert_true(toClone->_capacity >= toClone->_length);
|
||||
int32_t len = toClone->_capacity + toClone->_padding + toClone->_adLen;
|
||||
uint8_t* allocation = Allocator_malloc(alloc, len + 8);
|
||||
while (((uintptr_t)allocation % 8) != (((uintptr_t)toClone->msgbytes - toClone->_padding - toClone->_adLen) % 8)) {
|
||||
while (((uintptr_t)allocation % 8) != (((uintptr_t)toClone->_msgbytes - toClone->_padding - toClone->_adLen) % 8)) {
|
||||
allocation++;
|
||||
}
|
||||
Bits_memcpy(allocation, toClone->msgbytes - toClone->_padding - toClone->_adLen, len);
|
||||
Bits_memcpy(allocation, toClone->_msgbytes - toClone->_padding - toClone->_adLen, len);
|
||||
return Allocator_clone(alloc, (&(struct Message) {
|
||||
._length = toClone->_length,
|
||||
._padding = toClone->_padding,
|
||||
.msgbytes = allocation + toClone->_adLen + toClone->_padding,
|
||||
._msgbytes = allocation + toClone->_adLen + toClone->_padding,
|
||||
._ad = allocation + toClone->_adLen,
|
||||
._adLen = toClone->_adLen,
|
||||
._capacity = toClone->_capacity,
|
||||
|
@@ -33,7 +33,7 @@ typedef struct Message
|
||||
int32_t _padding;
|
||||
|
||||
/** The content. */
|
||||
uint8_t* msgbytes;
|
||||
uint8_t* _msgbytes;
|
||||
|
||||
/** Amount of bytes of storage space available in the message. */
|
||||
int32_t _capacity;
|
||||
@@ -60,6 +60,11 @@ typedef struct Message
|
||||
struct Allocator* _alloc;
|
||||
} Message_t;
|
||||
|
||||
static inline uint8_t* Message_bytes(struct Message* msg)
|
||||
{
|
||||
return msg->_msgbytes;
|
||||
}
|
||||
|
||||
static inline struct Allocator* Message_getAlloc(struct Message* msg)
|
||||
{
|
||||
return msg->_alloc;
|
||||
@@ -91,7 +96,7 @@ static inline int32_t Message_getCapacity(struct Message* msg)
|
||||
|
||||
static inline Message_t Message_foreign(uint32_t len, uint8_t* bytes)
|
||||
{
|
||||
return (Message_t){ ._length = len, .msgbytes = bytes, ._capacity = len };
|
||||
return (Message_t){ ._length = len, ._msgbytes = bytes, ._capacity = len };
|
||||
}
|
||||
|
||||
// static inline Er_DEFUN(void Message_ecopy(struct Message* to, struct Message* from, uint32_t amt))
|
||||
@@ -114,7 +119,7 @@ static inline Er_DEFUN(uint8_t* Message_peakBytes(struct Message* msg, int32_t l
|
||||
if (len > msg->_length) {
|
||||
Er_raise(msg->_alloc, "peakBytes(%d) too big, message length is %d", len, msg->_length);
|
||||
}
|
||||
Er_ret(msg->msgbytes);
|
||||
Er_ret(msg->_msgbytes);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,7 +137,7 @@ static inline Er_DEFUN(void Message_eshift(struct Message* toShift, int32_t amou
|
||||
|
||||
toShift->_length += amount;
|
||||
toShift->_capacity += amount;
|
||||
toShift->msgbytes -= amount;
|
||||
toShift->_msgbytes -= amount;
|
||||
toShift->_padding -= amount;
|
||||
|
||||
Er_ret();
|
||||
@@ -186,9 +191,9 @@ static inline Er_DEFUN(void Message_epush(struct Message* restrict msg,
|
||||
{
|
||||
Er(Message_eshift(msg, (int)size));
|
||||
if (object) {
|
||||
Bits_memcpy(msg->msgbytes, object, size);
|
||||
Bits_memcpy(msg->_msgbytes, object, size);
|
||||
} else {
|
||||
Bits_memset(msg->msgbytes, 0x00, size);
|
||||
Bits_memset(msg->_msgbytes, 0x00, size);
|
||||
}
|
||||
Er_ret();
|
||||
}
|
||||
@@ -199,7 +204,7 @@ static inline Er_DEFUN(void Message_epop(struct Message* restrict msg,
|
||||
{
|
||||
Er(Message_eshift(msg, -(int)size));
|
||||
if (object) {
|
||||
Bits_memcpy(object, &msg->msgbytes[-((int)size)], size);
|
||||
Bits_memcpy(object, &msg->_msgbytes[-((int)size)], size);
|
||||
}
|
||||
Er_ret();
|
||||
}
|
||||
|
Reference in New Issue
Block a user