#include "rsa.h"
#include "list.h"
#include "sptps.h"
+#include "logger.h"
#define OPTION_INDIRECT 0x0001
#define OPTION_TCPONLY 0x0002
#include "edge.h"
#include "net.h"
#include "node.h"
+#include "compression.h"
#ifndef DISABLE_LEGACY
typedef struct legacy_crypto_t {
sptps_t sptps;
int outmaclength;
- int outcompression; /* compression level from compression_level_t */
+
+ union {
+ compression_level_t outcompression;
+ debug_t log_level; // used for REQ_LOG
+ };
uint8_t *hischallenge; /* The challenge we sent to him */
uint8_t *mychallenge; /* The challenge we received */
pcap = true;
return true;
- case REQ_LOG:
- sscanf(request, "%*d %*d %d", &c->outcompression);
+ case REQ_LOG: {
+ int level = 0;
+ sscanf(request, "%*d %*d %d", &level);
+ c->log_level = CLAMP(level, DEBUG_UNSET, DEBUG_SCARY_THINGS);
c->status.log = true;
logcontrol = true;
return true;
+ }
default:
return send_request(c, "%d %d", CONTROL, REQ_INVALID);
}
}
-static void logcontrol(int fd, FILE *out, int level) {
+static void log_control(int fd, FILE *out, int level) {
sendline(fd, "%d %d %d", CONTROL, REQ_LOG, level);
char data[1024];
char line[32];
signal(SIGINT, sigint_handler);
#endif
- logcontrol(fd, stdout, argc > 1 ? atoi(argv[1]) : -1);
+ log_control(fd, stdout, argc > 1 ? atoi(argv[1]) : DEBUG_UNSET);
#ifdef SIGINT
signal(SIGINT, SIG_DFL);
--- /dev/null
+#include "unittest.h"
+
+static const char buf[3];
+
+static void test_min(void **state) {
+ (void)state;
+
+ assert_int_equal(-1, MIN(1, -1));
+ assert_int_equal(-2, MIN(1 + 2 * 3, 3 - 2 * 5 / 2));
+
+ assert_ptr_equal(buf[0], MIN(buf[1], buf[0]));
+}
+
+static void test_max(void **state) {
+ (void)state;
+
+ assert_int_equal(1, MAX(1, -1));
+ assert_int_equal(4, MAX(1 + 3 - 3 / 4 * 5, 10 / 5 + 2 - 2));
+
+ assert_ptr_equal(buf[1], MAX(buf[1], buf[0]));
+}
+
+static void test_clamp(void **state) {
+ (void)state;
+
+ assert_int_equal(10, CLAMP(INT_MAX, -10, 10));
+ assert_int_equal(-10, CLAMP(INT_MIN, -10, 10));
+ assert_int_equal(7, CLAMP(3 + 4, 6, 8));
+
+ assert_int_equal(5, CLAMP(-1000, 5, 5));
+ assert_int_equal(5, CLAMP(0, 5, 5));
+ assert_int_equal(5, CLAMP(1000, 5, 5));
+
+ assert_ptr_equal(buf[1], CLAMP(buf[2], buf[0], buf[1]));
+}
+
+int main(void) {
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test(test_min),
+ cmocka_unit_test(test_max),
+ cmocka_unit_test(test_clamp),
+ };
+ return cmocka_run_group_tests(tests, NULL, NULL);
+}