clang-format

Signed-off-by: aiden <aiden@citalopram.reviews>
This commit is contained in:
aiden 2022-03-30 03:40:18 +01:00
parent 53b0d7bc4e
commit 2f6f10b992
18 changed files with 301 additions and 175 deletions

70
.clang-format Normal file

@ -0,0 +1,70 @@
AlignAfterOpenBracket: BlockIndent
AlignArrayOfStructures: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
AlignEscapedNewlines: DontAlign
AlignOperands: DontAlign
AlignTrailingComments: false
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
BinPackArguments: false
BinPackParameters: false
BitFieldColonSpacing: After
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterControlStatement: MultiLine
AfterEnum: false
AfterFunction: false
AfterStruct: false
AfterUnion: false
BeforeElse: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: false
BreakBeforeTernaryOperators: true
BreakStringLiterals: false
ColumnLimit: 300
DeriveLineEnding: false
DerivePointerAlignment: false
DisableFormat: false
IncludeBlocks: Regroup
IndentCaseBlocks: false
IndentCaseLabels: true
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth: 8
IndentWrappedFunctionNames: false
InsertBraces: false
InsertTrailingCommas: Wrapped
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 2
PointerAlignment: Right
QualifierAlignment: Leave
ReflowComments: false
SortIncludes: CaseSensitive
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceBeforeCaseColon: false
SpaceBeforeParens: ControlStatements
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 8
UseCRLF: false
UseTab: Always

1
clang-format.sh Normal file

@ -0,0 +1 @@
clang-format -i `find src | grep -E '*\.(c|h)'`

@ -1,4 +1,5 @@
#include "internal.h"
#include <errno.h>
#include <fcntl.h>
#include <openssl/err.h>
@ -15,7 +16,8 @@ int bdd_use_correct_ctx(SSL *client_ssl, int *_, struct bdd_accept_ctx *ctx) {
goto ucc__err;
}
// to-do: strlen is slow af, maybe openssl can give us the length instead
// to-do: strlen is slow af, maybe openssl can give us the length
// instead
size_t name_len = strlen(name);
if (name_len == 0 || (name_len == 254 && name[253] != '.') || name_len > 254) {
goto ucc__err;
@ -57,7 +59,7 @@ int bdd_use_correct_ctx(SSL *client_ssl, int *_, struct bdd_accept_ctx *ctx) {
}
if (name[idx] == '.') {
if (!fwc) {
ucc__place_wc:;
ucc__place_wc:;
name_len += 1;
name[--idx] = '*';
break;
@ -131,30 +133,30 @@ bdd_accept_thread__poll:;
}
switch (ctx->service_name_description->service_type) {
case (bdd_service_type_internal): {
case (bdd_service_type_internal): {
#ifndef BIDIRECTIOND_ACCEPT_OCBCNS
if ((connections = bdd_connections_obtain(instance)) == NULL) {
goto bdd_accept__err;
}
if ((connections = bdd_connections_obtain(instance)) == NULL) {
goto bdd_accept__err;
}
#endif
switch (bdd_connections_init(connections, &(client_ssl), cl_sockaddr, ctx->service_name_description->service.internal.service, ctx->service_name_description->service.internal.service_info)) {
case (bdd_connections_init_failed): {
goto bdd_accept__err;
}
case (bdd_connections_init_success): {
bdd_connections_link(instance, &(connections));
switch (bdd_connections_init(connections, &(client_ssl), cl_sockaddr, ctx->service_name_description->service.internal.service, ctx->service_name_description->service.internal.service_info)) {
case (bdd_connections_init_failed): {
goto bdd_accept__err;
}
case (bdd_connections_init_success): {
bdd_connections_link(instance, &(connections));
break;
}
case (bdd_connections_init_failed_wants_deinit): {
bdd_connections_deinit(connections);
goto bdd_accept__err;
}
}
break;
}
case (bdd_connections_init_failed_wants_deinit): {
bdd_connections_deinit(connections);
goto bdd_accept__err;
default: {
assert(false);
}
}
break;
}
default: {
assert(false);
}
}
locked_hashmap_unlock(&(ctx->locked_name_descriptions));

@ -17,8 +17,9 @@
#define POLLRDHUP 0x400
#endif
enum bdd_name_description_service_type { bdd_name_description_service_type_none,
bdd_name_description_service_type_internal,
enum bdd_name_description_service_type {
bdd_name_description_service_type_none,
bdd_name_description_service_type_internal,
} __attribute__((packed));
typedef unsigned short int bdd_io_id;
@ -36,7 +37,7 @@ struct bdd_connections_associated {
struct bdd_connections {
struct bdd_connections *next;
bool working : 1, broken : 1;
bool working: 1, broken: 1;
pthread_mutex_t working_mutex;
const struct bdd_internal_service *service;
@ -69,7 +70,7 @@ struct bdd_settings {
uint32_t client_timeout;
uint32_t buf_sz;
bool use_stack_buf : 1, use_work_queues : 1;
bool use_stack_buf: 1, use_work_queues: 1;
int n_connections;
int n_epoll_oevents;
@ -78,8 +79,9 @@ struct bdd_settings {
sigset_t sigmask;
};
enum bdd_service_type { bdd_service_type_none,
bdd_service_type_internal,
enum bdd_service_type {
bdd_service_type_none,
bdd_service_type_internal,
} __attribute__((packed));
struct bdd_name_description {
SSL_CTX *ssl_ctx;

@ -1,4 +1,5 @@
#include "internal.h"
#include <errno.h>
#include <openssl/x509v3.h>
#include <string.h>
@ -9,9 +10,9 @@ __attribute__((warn_unused_result)) int bdd_poll(struct bdd_connections *connect
struct bdd_io *io = &(connections->io[io_id]);
assert(io->fd != -1);
struct pollfd pollfd = {
.fd = io->fd,
.events = POLLIN | POLLOUT | POLLRDHUP,
.revents = 0,
.fd = io->fd,
.events = POLLIN | POLLOUT | POLLRDHUP,
.revents = 0,
};
poll(&(pollfd), 1, 0);
if (io->ssl != NULL && SSL_has_pending(io->ssl)) {
@ -123,8 +124,9 @@ bool bdd_create_io(struct bdd_connections *connections, bdd_io_id *io_id, int *f
}
SSL *ssl = NULL;
if (ssl_name != NULL) {
// i think it's not finna write to the ctx, so a global mutex lock is not required here
// also, BDD_GLOBAL_CL_SSL_CTX is guaranteed to be valid here
// i think it's not finna write to the ctx, so a global mutex
// lock is not required here also, BDD_GLOBAL_CL_SSL_CTX is
// guaranteed to be valid here
if ((ssl = SSL_new(BDD_GLOBAL_CL_SSL_CTX)) == NULL) {
return false;
}

@ -1,4 +1,5 @@
#include "internal.h"
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <unistd.h>
@ -64,7 +65,9 @@ struct bdd_instance *bdd_instance_alloc(void) {
}
struct bdd_instance *bdd_go(struct bdd_settings settings) {
if (settings.sv_socket < 0 || settings.buf_sz == 0 || settings.n_connections < 0 || settings.n_epoll_oevents < 0 || settings.name_descriptions == NULL || ((settings.n_connections == 0 || settings.n_worker_threads == 0 || settings.n_epoll_oevents == 0) && (settings.n_connections != 0 || settings.n_worker_threads != 0 || settings.n_epoll_oevents != 0))) {
if (settings.sv_socket < 0 || settings.buf_sz == 0 || settings.n_connections < 0 || settings.n_epoll_oevents < 0 || settings.name_descriptions == NULL ||
((settings.n_connections == 0 || settings.n_worker_threads == 0 || settings.n_epoll_oevents == 0) && (settings.n_connections != 0 || settings.n_worker_threads != 0 || settings.n_epoll_oevents != 0)))
{
return NULL;
}
bool uses_internal_services = settings.n_connections != 0;
@ -124,9 +127,7 @@ struct bdd_instance *bdd_go(struct bdd_settings settings) {
if (uses_internal_services) {
// connections
instance->connections.n_connections = settings.n_connections;
if ((instance->connections.connections = malloc(
(settings.n_connections * sizeof(struct bdd_connections)) + (settings.n_connections * sizeof(int))))
== NULL) {
if ((instance->connections.connections = malloc((settings.n_connections * sizeof(struct bdd_connections)) + (settings.n_connections * sizeof(int)))) == NULL) {
goto bdd_go__err;
}
// available stack
@ -178,9 +179,10 @@ struct bdd_instance *bdd_go(struct bdd_settings settings) {
goto bdd_go__err;
}
struct epoll_event event = {
.events = EPOLLIN,
.data = {
.ptr = NULL,
.events = EPOLLIN,
.data =
{
.ptr = NULL,
},
};
if (epoll_ctl(instance->epoll_fd, EPOLL_CTL_ADD, instance->serve_eventfd, &(event)) != 0) {

@ -10,7 +10,9 @@ extern SSL_CTX *BDD_GLOBAL_CL_SSL_CTX;
void bdd_mutex_preinit(pthread_mutex_t *dest);
void bdd_cond_preinit(pthread_cond_t *dest);
// my justification for the following shit is: bdd's memory usage is already kinda pushing it, so i'd like to save some heap space in exchange for a few extra instructions
// my justification for the following shit is: bdd's memory usage is already
// kinda pushing it, so i'd like to save some heap space in exchange for a few
// extra instructions
#define bdd_connections_n_max_io(c) (c->service->n_max_io)
#define bdd_connections_id(instance, c) (((char *)c - (char *)(instance->connections.connections)) / sizeof(struct bdd_connections))
@ -110,9 +112,10 @@ int bdd_vdl_pthread_mutex_trylock(void *_, char *name, int ln);
#define BDD_DEBUG_LOG(string, args...) (printf("[DEBUG (%p)] " string, (void *)pthread_self(), ##args), fflush(stdout))
#endif
enum bdd_connections_init_status { bdd_connections_init_success,
bdd_connections_init_failed_wants_deinit,
bdd_connections_init_failed,
enum bdd_connections_init_status {
bdd_connections_init_success,
bdd_connections_init_failed_wants_deinit,
bdd_connections_init_failed,
} __attribute__((packed));
enum bdd_connections_init_status bdd_connections_init(struct bdd_connections *connections, SSL **client_ssl, struct sockaddr client_sockaddr, const struct bdd_internal_service *service, void *service_info);
struct bdd_connections *bdd_connections_obtain(struct bdd_instance *instance);

@ -12,7 +12,9 @@ struct bdd_name_description *bdd_name_description_alloc(void) {
}
void bdd_name_description_clean_ssl_ctx(struct bdd_name_description *name_description) {
if (name_description->ssl_ctx != NULL) {
SSL_CTX_free(name_description->ssl_ctx); // misleading function name; it actually decs the ref count and frees the ssl_ctx if the rc hits 0
SSL_CTX_free(name_description->ssl_ctx); // misleading function name; it actually
// decs the ref count and frees the ssl_ctx
// if the rc hits 0
name_description->ssl_ctx = NULL;
}
return;
@ -44,24 +46,24 @@ void bdd_name_description_destroy(struct bdd_name_description *name_description)
}
// name_descriptions hashmap
#define bdd_name_descriptions() \
if (name_len == 0 || name_len > 254 || (name_len == 254 && name[253] != '.')) { \
return false; \
} \
if (name[name_len - 1] == '.') { \
if ((name_len -= 1) == 0) { \
return false; \
} \
} \
#define bdd_name_descriptions() \
if (name_len == 0 || name_len > 254 || (name_len == 254 && name[253] != '.')) { \
return false; \
} \
if (name[name_len - 1] == '.') { \
if ((name_len -= 1) == 0) { \
return false; \
} \
} \
struct bdd_name_description *name_description = locked_hashmap_get_wl(name_descriptions, name, name_len); \
if (name_description == NULL) { \
if ((name_description = bdd_name_description_alloc()) == NULL) { \
return false; \
} \
if (!locked_hashmap_set_wl(name_descriptions, name, name_len, name_description, 1)) { \
bdd_name_description_destroy(name_description); \
return false; \
} \
if (name_description == NULL) { \
if ((name_description = bdd_name_description_alloc()) == NULL) { \
return false; \
} \
if (!locked_hashmap_set_wl(name_descriptions, name, name_len, name_description, 1)) { \
bdd_name_description_destroy(name_description); \
return false; \
} \
}
bool bdd_name_descriptions_set_internal_service(struct locked_hashmap *name_descriptions, char *name, size_t name_len, struct bdd_internal_service *service, void *service_info) {
bdd_name_descriptions();

@ -1,4 +1,5 @@
#include "internal.h"
#include <errno.h>
#include <signal.h>
#include <sys/epoll.h>
@ -18,7 +19,12 @@ bdd_serve__find_connections:;
n_events = epoll_wait(instance->epoll_fd, instance->epoll_oevents, instance->n_epoll_oevents, -1);
} while (n_events < 0 && errno == EINTR);
if (unlikely(n_events < 0)) {
fprintf(stderr, "bidirectiond epoll error: %i - try increasing your rlimits for open files\n", errno);
fprintf(
stderr,
"bidirectiond epoll error: %i - try increasing your "
"rlimits for open files\n",
errno
);
bdd_stop(instance);
bdd_thread_exit(instance);
}
@ -33,16 +39,17 @@ bdd_serve__find_connections:;
struct bdd_connections *next = (*connections)->next;
(*connections)->working = false;
bool broken = true;
if (!(*connections)->broken)
if (!(*connections)->broken) {
for (bdd_io_id idx = 0; idx < bdd_connections_n_max_io((*connections)); ++idx) {
int fd = (*connections)->io[idx].fd;
if (fd < 0) {
continue;
}
struct epoll_event event = {
.events = EPOLLIN,
.data = {
.ptr = (*connections),
.events = EPOLLIN,
.data =
{
.ptr = (*connections),
},
};
if (epoll_ctl(instance->epoll_fd, EPOLL_CTL_ADD, fd, &(event)) != 0) {
@ -58,6 +65,7 @@ bdd_serve__find_connections:;
}
broken = false;
}
}
if (broken) {
bdd_connections_deinit((*connections));
bdd_connections_release(instance, connections);
@ -117,7 +125,10 @@ bdd_serve__find_connections:;
} else {
pthread_mutex_lock(&(workers->available_stack.mutex));
if (workers->available_stack.idx == workers->n_workers) {
BDD_DEBUG_LOG("no available worker threads; waiting...\n");
BDD_DEBUG_LOG(
"no available worker "
"threads; waiting...\n"
);
do {
pthread_cond_wait(&(workers->available_stack.cond), &(workers->available_stack.mutex));
} while (workers->available_stack.idx == workers->n_workers);

@ -1,16 +1,17 @@
#include "internal.h"
#include <unistd.h>
void bdd_signal(struct bdd_instance *instance) {
char buf[8] = {
~0,
0,
0,
0,
0,
0,
0,
~0,
~0,
0,
0,
0,
0,
0,
0,
~0,
};
int r = write(instance->serve_eventfd, (void *)buf, 8);
assert(r == 8 || r < 0);
@ -19,14 +20,14 @@ void bdd_signal(struct bdd_instance *instance) {
void bdd_stop_accept(struct bdd_instance *instance) {
char buf[8] = {
~0,
0,
0,
0,
0,
0,
0,
~0,
~0,
0,
0,
0,
0,
0,
0,
~0,
};
int r = write(instance->accept.eventfd, (void *)buf, 8);
assert(r == 8 || r < 0);

@ -1,4 +1,5 @@
#include "internal.h"
#include <signal.h>
void *bdd_worker(struct bdd_worker *worker) {

@ -1,4 +1,5 @@
#include "cp_pwd.h"
#include <assert.h>
#include <string.h>

@ -1,9 +1,9 @@
#ifndef bidirectiond__cp_pwd__h
#define bidirectiond__cp_pwd__h
#include <stdbool.h>
struct bdd_cp_ctx {
bool success;
char *password;
};
int bdd_cp_pwd(char *dest, int dest_sz, int rwflag, void *_ctx);
#ifndef bidirectiond__cp_pwd__h
#define bidirectiond__cp_pwd__h
#include <stdbool.h>
struct bdd_cp_ctx {
bool success;
char *password;
};
int bdd_cp_pwd(char *dest, int dest_sz, int rwflag, void *_ctx);
#endif

@ -1,7 +1,9 @@
#include "input_processor.h"
#include "core_settings.h"
#include "cp_pwd.h"
#include "tls_put.h"
#include <errno.h>
#include <fcntl.h>
#include <openssl/ssl.h>
@ -15,7 +17,9 @@ struct buffered_read_ctx {
char byte;
};
#define BUFFERED_READ_CTX_INITALISER \
{ .idx = 0, .len = 0, .byte = 0, }
{ \
.idx = 0, .len = 0, .byte = 0, \
}
static bool buffered_read(int fd, char *buf, int buf_sz, struct buffered_read_ctx *ctx) {
if (buf_sz < 0) {
return false;
@ -46,14 +50,14 @@ void input_processor(int sfd, char *br_buf, int br_buf_sz) {
char *str;
uint8_t str_sz;
} match_list[] = {
{
.str = "TLS_PEM_LOAD",
.str_sz = 12,
},
{
.str = "PING",
.str_sz = 4,
},
{
.str = "TLS_PEM_LOAD",
.str_sz = 12,
},
{
.str = "PING",
.str_sz = 4,
},
};
input_processor__process:;
@ -150,8 +154,8 @@ input_processor__matched:;
br_ctx.byte = 1;
}
struct bdd_cp_ctx cp_ctx = {
.success = false,
.password = NULL,
.success = false,
.password = NULL,
};
if (br_ctx.byte != 1) {
char env_variable_name[0x100];
@ -190,7 +194,7 @@ input_processor__matched:;
e |= 0b10;
}
locked_hashmap_unlock(&(lh));
input_processor__tls_pem_load_err:;
input_processor__tls_pem_load_err:;
if (ctx != NULL) {
SSL_CTX_free(ctx);
}

@ -3,6 +3,7 @@
#include "input_processor.h"
#include "strtoint.h"
#include "tls_put.h"
#include <arpa/inet.h>
#include <bddc/api.h>
#include <fcntl.h>
@ -26,29 +27,29 @@
#endif
struct bdd_settings settings = {
.name_descriptions = NULL,
.n_connections = 0x100,
.n_epoll_oevents = 0x100,
.buf_sz = 0x800,
.n_worker_threads = 16,
.client_timeout = 12000,
.use_stack_buf = false,
.sv_socket = -1,
.use_work_queues = false,
// .sigmask = x,
.name_descriptions = NULL,
.n_connections = 0x100,
.n_epoll_oevents = 0x100,
.buf_sz = 0x800,
.n_worker_threads = 16,
.client_timeout = 12000,
.use_stack_buf = false,
.sv_socket = -1,
.use_work_queues = false,
// .sigmask = x,
};
#define PASTE(x, y) x##y
#define sto(w, t) \
void PASTE(sto, w)(t * dest, char *str) { \
signed long long int v; \
#define sto(w, t) \
void PASTE(sto, w)(t * dest, char *str) { \
signed long long int v; \
if (!bdd_strtosll(str, strlen(str), &(v))) { \
return; \
} \
if (v == (t)v) { \
*dest = (t)v; \
} \
return; \
return; \
} \
if (v == (t)v) { \
*dest = (t)v; \
} \
return; \
}
sto(i, int);
sto(ui, unsigned int);
@ -81,8 +82,8 @@ int main(int argc, char *argv[], char *env[]) {
struct bdd_instance *bdd_instance = NULL;
int input_fd = -1;
struct sockaddr_un input_addr = {
0,
.sun_family = AF_UNIX,
0,
.sun_family = AF_UNIX,
};
int sig_fd = -1;
@ -131,11 +132,11 @@ int main(int argc, char *argv[], char *env[]) {
struct locked_hashmap *lh = hashmap_lock(settings.name_descriptions);
size_t big_alloc_sz = 0;
#define EXPECT_ARGS(n) \
for (size_t idx = 1; idx <= n; ++idx) { \
#define EXPECT_ARGS(n) \
for (size_t idx = 1; idx <= n; ++idx) { \
if (arg[idx] == NULL || arg[idx][0] == '-') { \
goto main__arg_fuck; \
} \
goto main__arg_fuck; \
} \
}
main__arg_iter:;
while ((*arg) != NULL) {
@ -180,8 +181,8 @@ main__arg_iter:;
arg += 1;
} else if (strcmp((*arg), "--nohup") == 0) {
struct sigaction action = {
.sa_handler = SIG_IGN,
.sa_flags = SA_RESTART,
.sa_handler = SIG_IGN,
.sa_flags = SA_RESTART,
};
sigaction(SIGHUP, &(action), 0);
arg += 1;
@ -196,8 +197,8 @@ main__arg_iter:;
goto main__arg_creds_err;
}
struct bdd_cp_ctx cp_ctx = {
.success = false,
.password = getenv(arg[3]),
.success = false,
.password = getenv(arg[3]),
};
SSL_CTX_set_default_passwd_cb(ctx, bdd_cp_pwd);
SSL_CTX_set_default_passwd_cb_userdata(ctx, &(cp_ctx));
@ -220,13 +221,17 @@ main__arg_iter:;
fputs("seemingly invalid certificate file\n", stderr);
goto main__arg_creds_err;
}
main__arg_creds_err:;
main__arg_creds_err:;
if (ctx != NULL) {
SSL_CTX_free(ctx);
}
arg += 4;
} else if (strcmp((*arg), "--UNSAFE allocate buffer on stack") == 0) {
fputs("'--UNSAFE allocate buffer on stack' is unsafe and shouldn't be used\n", stderr);
fputs(
"'--UNSAFE allocate buffer on stack' is unsafe and "
"shouldn't be used\n",
stderr
);
settings.use_stack_buf = true;
arg += 1;
} else if (getuid() == 0 && strcmp((*arg), "--uid") == 0) {
@ -273,23 +278,32 @@ main__arg_iter:;
}
}
}
main__arg_fuck:;
main__arg_fuck:;
puts(
"argument parsing failed\n"
"-t: set the amount of worker threads\n"
"--client-timeout: set the timeout (in ms) for client socket i/o\n"
"-l: set the rlimits for open files (soft limit, hard limit)\n"
"-b: set the size of the large worker buffers\n"
"--backlog: set the tcp backlog for sv_socket\n"
"-p: set the tcp port to bind sv_socket to\n"
"--max-connections: the max amount of bdd_connections structs\n"
"--disable-ipv6: sv_socket should not use ipv6\n"
"--use-work-queue: do not wait for worker threads before giving them work\n"
"--nohup: SIG_IGN SIGHUP\n"
"-c: load pem-encoded tls credentials (e.g. `-c cert.pem encrypted-key.pem name-of-password-environment-variable`)\n"
"--input: set the path for a udp unix socket, so that some bidirectiond settings can be modified without restarting\n"
"--n-epoll-oevents: epoll_wait maxevents\n"
"--big-alloc: reserve some ram");
"argument parsing failed\n"
"-t: set the amount of worker threads\n"
"--client-timeout: set the timeout (in ms) for "
"client socket i/o\n"
"-l: set the rlimits for open files (soft limit, "
"hard limit)\n"
"-b: set the size of the large worker buffers\n"
"--backlog: set the tcp backlog for sv_socket\n"
"-p: set the tcp port to bind sv_socket to\n"
"--max-connections: the max amount of "
"bdd_connections structs\n"
"--disable-ipv6: sv_socket should not use ipv6\n"
"--use-work-queue: do not wait for worker threads "
"before giving them work\n"
"--nohup: SIG_IGN SIGHUP\n"
"-c: load pem-encoded tls credentials (e.g. `-c "
"cert.pem encrypted-key.pem "
"name-of-password-environment-variable`)\n"
"--input: set the path for a udp unix socket, so "
"that some bidirectiond settings can be modified "
"without restarting\n"
"--n-epoll-oevents: epoll_wait maxevents\n"
"--big-alloc: reserve some ram"
);
for (size_t idx = 0; idx < N_INTERNAL_SERVICES; ++idx) {
if (internal_services[idx].arguments_help != NULL) {
fputs(internal_services[idx].arguments_help, stdout);
@ -321,7 +335,7 @@ main__arg_iter:;
struct sockaddr_in inet4;
struct sockaddr_in6 inet6;
} sv_addr = {
0,
0,
};
size_t sv_addr_sz = 0;
if (disable_ipv6) {
@ -341,7 +355,11 @@ main__arg_iter:;
int opt = 1;
setsockopt(settings.sv_socket, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &(opt), sizeof(opt));
if (bind(settings.sv_socket, (struct sockaddr *)&(sv_addr), sv_addr_sz) < 0 || listen(settings.sv_socket, backlog) < 0) {
fputs("failed to bind sv_socket! is the port already use? is the internet protocol enabled?\n", stderr);
fputs(
"failed to bind sv_socket! is the port already use? is the "
"internet protocol enabled?\n",
stderr
);
goto main__clean_up;
}
@ -384,15 +402,15 @@ main__arg_iter:;
goto main__clean_up;
}
struct pollfd pollfds[2] = {
{
.fd = sig_fd,
.events = POLLIN,
},
{
.fd = input_fd,
.events = POLLIN,
.revents = 0,
},
{
.fd = sig_fd,
.events = POLLIN,
},
{
.fd = input_fd,
.events = POLLIN,
.revents = 0,
},
};
// serve
@ -420,13 +438,13 @@ main__arg_iter:;
goto main__clean_up;
}
switch (sig.ssi_signo) {
case (SIGINT):
case (SIGTERM): {
goto main__clean_up;
}
default: {
assert(false);
}
case (SIGINT):
case (SIGTERM): {
goto main__clean_up;
}
default: {
assert(false);
}
}
}
if (pollfds[1].revents & POLLIN) {
@ -457,10 +475,10 @@ main__clean_up:;
hashmap_destroy(settings.name_descriptions);
}
// https://stackoverflow.com/questions/29845527/how-to-properly-uninitialize-openssl
//FIPS_mode_set(0);
// FIPS_mode_set(0);
CRYPTO_set_locking_callback(NULL);
CRYPTO_set_id_callback(NULL);
//ERR_remove_state(0);
// ERR_remove_state(0);
SSL_COMP_free_compression_methods();
ENGINE_cleanup();
CONF_modules_free();

@ -80,9 +80,9 @@ void general_service__service_info_destructor(void *hint) {
static bool handle_s(struct locked_hashmap *name_descriptions, struct bdd_internal_service *service, char *scope, char *addr, char *port, bool use_tls) {
struct general_service__info *info = malloc(sizeof(struct general_service__info));
struct addrinfo hints = {
0,
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
0,
.ai_family = AF_UNSPEC,
.ai_socktype = SOCK_STREAM,
};
struct addrinfo *res = NULL;
if (info == NULL) {

@ -4,7 +4,9 @@
"service_init": "general_service__service_init",
"connections_init": "general_service__connections_init",
"service_info_destructor": "general_service__service_info_destructor",
"supported_arguments": [ "-s" ],
"supported_arguments": [
"-s"
],
"arguments_help": "-s: creates a barebones proxy (e.g. `-s [service name] [target address/name] [target tcp port] [use ssl (true/false)]`)\n",
"n_max_io": 2
}

@ -1,5 +1,7 @@
#include "tls_put.h"
#include "core_settings.h"
#include <openssl/x509v3.h>
#include <string.h>
@ -61,7 +63,9 @@ bool tls_put(struct locked_hashmap *ns, SSL_CTX **ctx_ref) {
}
}
if (!should_up_rc) /* if `ctx` is not referenced by any hashmap values, then free `ctx` */ {
if (!should_up_rc) /* if `ctx` is not referenced by any hashmap values,
then free `ctx` */
{
SSL_CTX_free(ctx);
return false;
}