Add bound IP

This commit is contained in:
Quentin 2019-06-21 16:50:49 +02:00
parent f05477cd56
commit a3d2b4a4b0
5 changed files with 20 additions and 8 deletions

View file

@ -14,7 +14,7 @@ int main(int argc, char** argv) {
struct donar_params dp = {0};
donar_init_params (&dp);
while ((dp.opt = getopt(argc, argv, "vcse:r:o:a:bhl:d:f:")) != -1) {
while ((dp.opt = getopt(argc, argv, "vcse:r:o:a:bhl:d:f:i:")) != -1) {
switch(dp.opt) {
case 'v':
dp.verbose++;
@ -53,6 +53,9 @@ int main(int argc, char** argv) {
case 'd':
sscanf(optarg, "%d,%d", &dp.fresh_data, &dp.redundant_data);
break;
case 'i':
dp.bound_ip = strdup(optarg);
break;
case 'f':
dp.capture_file = strdup(optarg);
break;
@ -63,6 +66,7 @@ int main(int argc, char** argv) {
if (!(dp.is_server ^ dp.is_client)) goto in_error;
if (dp.algo == NULL) goto in_error;
if (dp.bound_ip == NULL) dp.bound_ip = strdup("127.0.0.1");
if (dp.is_server) {
struct donar_server_ctx ctx;
@ -77,15 +81,17 @@ int main(int argc, char** argv) {
in_error:
dp.errored = 1;
fprintf(stderr, "Usage as client : %s -c -a <algo> -o <onion service file> [-h] [-b] [-f <dump packets>] [-l <links>] [-d <fresh>,<red>] [-e <exposed udp port>]* [-r <remote udp port>]*\n", argv[0]);
fprintf(stderr, "Usage as server : %s -s -a <algo> [-h] [-b] [-l <links>] [-f <dump_packets>] [-d <fresh>,<red>] [-e <exposed udp port>]* [-r <remote udp port>]*\n\n", argv[0]);
fprintf(stderr, "Usage as client : %s -c -a <algo> -o <onion service file> [-h] [-b] [-i <bound ip>] [-f <dump packets>] [-l <links>] [-d <fresh>,<red>] [-e <exposed udp port>]* [-r <remote udp port>]*\n", argv[0]);
fprintf(stderr, "Usage as server : %s -s -a <algo> [-h] [-b] [-i <bound ip>] [-l <links>] [-f <dump_packets>] [-d <fresh>,<red>] [-e <exposed udp port>]* [-r <remote udp port>]*\n\n", argv[0]);
fprintf(stderr, "Passed parameters: client=%d, server=%d, algo=%s, exposed_ports=%d, remote_ports=%d, onion_file=%s, links=%d, duplication=%d,%d\n",
dp.is_client, dp.is_server, dp.algo, dp.exposed_ports->len, dp.remote_ports->len, dp.onion_file, dp.links, dp.fresh_data, dp.redundant_data);
terminate:
// @FIXME: Should be refactored in free_donar_params()
if (dp.onion_file != NULL) free(dp.onion_file);
if (dp.algo != NULL) free(dp.algo);
if (dp.capture_file != NULL) free(dp.capture_file);
if (dp.bound_ip != NULL) free(dp.bound_ip);
g_ptr_array_free(dp.exposed_ports, TRUE);
g_ptr_array_free(dp.remote_ports, TRUE);

View file

@ -103,7 +103,9 @@ void donar_client(struct donar_client_ctx* ctx, struct donar_params* dp) {
g_ptr_array_foreach (dp->remote_ports, (void(*)(void*, void*))init_udp_remote, &(ctx->evts));
printf("--- Remote ports are binded locally\n");
g_ptr_array_foreach (dp->exposed_ports, (void(*)(void*, void*))init_udp_exposed, &(ctx->evts));
for (int i = 0; i < dp->exposed_ports->len; i++) {
init_udp_exposed(dp->bound_ip, g_ptr_array_index (dp->exposed_ports, i), &(ctx->evts));
}
printf("--- Local UDP services are exposed\n");
evt_core_loop(&(ctx->evts));

View file

@ -99,7 +99,7 @@ socket_failed:
exit(EXIT_FAILURE);
}
void init_udp_exposed(char* port, struct evt_core_ctx* evts) {
void init_udp_exposed(char* bound_ip, char* port, struct evt_core_ctx* evts) {
int sock1, sock2;
char url[1024];
@ -147,6 +147,7 @@ void donar_init_params(struct donar_params* dp) {
dp->onion_file = NULL;
dp->algo = NULL;
dp->capture_file = NULL;
dp->bound_ip = NULL;
dp->is_server = 0;
dp->is_client = 0;
dp->is_healing = 0;

View file

@ -10,11 +10,11 @@
struct donar_params {
int opt, is_server, is_client, is_waiting_bootstrap, is_healing, errored, verbose, links, fresh_data, redundant_data;
char *port, *onion_file, *algo, *capture_file;
char *bound_ip, *port, *onion_file, *algo, *capture_file;
GPtrArray *remote_ports, *exposed_ports;
};
void signal_init(struct evt_core_ctx* evts);
void init_udp_remote(char* port, struct evt_core_ctx* evts);
void init_udp_exposed(char* port, struct evt_core_ctx* evts);
void init_udp_exposed(char *bound_ip, char* port, struct evt_core_ctx* evts);
void donar_init_params(struct donar_params* dp);

View file

@ -82,8 +82,11 @@ void donar_server(struct donar_server_ctx* ctx, struct donar_params* dp) {
g_ptr_array_foreach (dp->remote_ports, (void(*)(void*, void*))init_udp_remote, &(ctx->evts));
printf("--- Remote ports are binded locally\n");
g_ptr_array_foreach (dp->exposed_ports, (void(*)(void*, void*))init_udp_exposed, &(ctx->evts));
for (int i = 0; i < dp->exposed_ports->len; i++) {
init_udp_exposed(dp->bound_ip, g_ptr_array_index (dp->exposed_ports, i), &(ctx->evts));
}
printf("--- Local UDP services are exposed\n");
evt_core_loop (&(ctx->evts));
destroy_resources (&(ctx->tos), &(ctx->tctl));