Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WireGuard Tunneling Plugin #52

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion src/Common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GIT_REV ?= $(shell [ -r .git ] && git --no-pager log -n 1 --oneline | cut -d " "

CFLAGS += -pedantic -W -Wall -Wstrict-prototypes -Wno-unused-parameter -Os -g3 -std=gnu99 -DGIT_REV=\"$(GIT_REV)\"
# CFLAGS += -DHAVE_CONFIG_H
# CFLAGS += -DCRYPTLIB=MBEDTLS_2_4_0 # POLARSSL_1_2_5 POLARSSL_1_2_9 POLARSSL_1_3_3 POLARSSL_1_3_4 CYASSL_2_8_0
CFLAGS += -DCRYPTLIB=MBEDTLS_2_4_0 # POLARSSL_1_2_5 POLARSSL_1_2_9 POLARSSL_1_3_3 POLARSSL_1_3_4 CYASSL_2_8_0

# optional defines:
# CFLAGS += -static
Expand Down Expand Up @@ -83,3 +83,4 @@ OBJS = $(SRC_C:.c=.o)

PACKAGE_NAME := bmx7
BINARY_NAME := bmx7

4 changes: 2 additions & 2 deletions src/avl.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ void *avl_remove(struct avl_tree *tree, void *key, int32_t tag)

}

// remember and return the found node. It might have been another one than intended
// Remember and return the found node. It might have been another one than intended
void *node = it->item;

#ifdef AVL_5XLINKED
Expand Down Expand Up @@ -443,7 +443,7 @@ void *avl_remove(struct avl_tree *tree, void *key, int32_t tag)

debugFree(it, tag);

} else { // both childs NOT NULL:
} else { // both children NOT NULL:

// Find the inorder successor
struct avl_node *heir = it->down[1];
Expand Down
9 changes: 5 additions & 4 deletions src/avl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include <stdint.h>


#define AVL_MAX_HEIGHT 128

struct avl_node {
Expand All @@ -38,8 +37,10 @@ struct avl_node {
struct avl_node * up;
struct avl_node * down[2];
#ifdef AVL_5XLINKED
struct avl_node * left; // it less-equal node
struct avl_node * right; // it greater node
// The less-equal node
struct avl_node * left;
// The greater-equal node
struct avl_node * right;
#endif
};

Expand Down Expand Up @@ -102,7 +103,7 @@ void *avl_closest_item(struct avl_tree *tree, void *key);
void *avl_first_item(struct avl_tree *tree);
void *avl_iterate_item(struct avl_tree *tree, struct avl_node **it);
void *_avl_find_item_by_field(struct avl_tree *tree, void *value, unsigned long offset, uint32_t size);
#define avl_find_item_by_field(tree,val,s,field) _avl_find_item_by_field( tree, val, (unsigned long)((&(((struct s*)0)->field))), sizeof(((struct s*)0)->field) )
#define avl_find_item_by_field(tree,val,s,field) _avl_find_item_by_field( tree, val, (unsigned long)((&(((struct s*)0)->field))), sizeof(((struct s*)0)->field) )
void avl_insert(struct avl_tree *tree, void *node, int32_t tag);
void *avl_remove(struct avl_tree *tree, void *key, int32_t tag);
void *avl_remove_first_item(struct avl_tree *tree, int32_t tag);
Expand Down
82 changes: 18 additions & 64 deletions src/bmx.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,10 @@ int32_t my_conformance_tolerance = DEF_CONFORMANCE_TOLERANCE;

char my_Hostname[MAX_HOSTNAME_LEN] = "";


int32_t dad_to = DEF_DAD_TO;

uint16_t my_desc_capabilities = MY_DESC_CAPABILITIES;


const IPX_T ZERO_IP = { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } };
const MAC_T ZERO_MAC = {{0}};
const ADDR_T ZERO_ADDR = {{0}};
Expand All @@ -76,7 +74,6 @@ const struct net_key ZERO_NET_KEY = ZERO_NET_KEY_INIT;
const struct net_key ZERO_NET4_KEY = ZERO_NET4_KEY_INIT;
const struct net_key ZERO_NET6_KEY = ZERO_NET6_KEY_INIT;


IDM_T terminating = 0;
IDM_T initializing = YES;
IDM_T cleaning_up = NO;
Expand All @@ -86,16 +83,13 @@ const IDM_T CONST_NO = NO;

const void* FAILURE_PTR = (void*) & FAILURE_PTR;


TIME_T bmx_time = 0;
TIME_SEC_T bmx_time_sec = 0;


uint32_t s_curr_avg_cpu_load = 0;

int32_t totalOrigRoutes = 0;


AVL_TREE(status_tree, struct status_handl, status_name);

// TODO: move to tools.c/h
Expand All @@ -108,8 +102,6 @@ IDM_T validate_param(int32_t probe, int32_t min, int32_t max, char *name)
return SUCCESS;
}



/***********************************************************
Runtime Infrastructure
************************************************************/
Expand Down Expand Up @@ -248,22 +240,10 @@ void cleanup_all(int32_t status)
}
}











/***********************************************************
Configuration data and handlers
************************************************************/



static const int32_t field_standard_sizes[FIELD_TYPE_END] = FIELD_STANDARD_SIZES;

int64_t field_get_value(const struct field_format *format, uint32_t min_msg_size, uint8_t *data, uint32_t pos_bit, uint32_t bits)
Expand Down Expand Up @@ -355,7 +335,6 @@ char *field_dbg_value(const struct field_format *format, uint32_t min_msg_size,
assertion(-501243, (strlen(uint32_out) < sizeof(uint32_out)));
val = uint32_out;


} else {
val = memAsHexString(p, bytes);
}
Expand Down Expand Up @@ -462,7 +441,6 @@ uint32_t field_iterate(struct field_iterator *it)

const struct field_format *format;


it->field = (it->field_bits || it->field) ? (it->field + 1) : 0;

format = &(it->format[it->field]);
Expand All @@ -478,7 +456,6 @@ uint32_t field_iterate(struct field_iterator *it)
it->field_bit_pos = (format->field_pos == -1) ?
it->field_bit_pos + it->field_bits : it->msg_bit_pos + format->field_pos;


if (!format->field_bits && !it->var_bits)
it->var_bits = it->data_size ? ((8 * it->data_size) - it->field_bit_pos) : 0;

Expand All @@ -494,7 +471,6 @@ uint32_t field_iterate(struct field_iterator *it)
it->field, it->field_bits, it->field_bit_pos, it->var_bits, field_bits,
field_type, format->field_bits, std_bits);


if (it->msg_bit_pos + (it->min_msg_size * 8) + it->var_bits <=
8 * (it->data_size ? it->data_size : it->min_msg_size)) {

Expand Down Expand Up @@ -651,8 +627,6 @@ uint32_t fields_dbg_table(struct ctrl_node *cn, uint16_t relevance, uint32_t dat
}
}



struct field_iterator i2 = { .format = format, .data = data, .data_size = data_size, .min_msg_size = min_msg_size };
while (field_iterate(&i2) == SUCCESS) {

Expand Down Expand Up @@ -1142,7 +1116,6 @@ struct ref_status {
uint32_t unresolveds;
};


static const struct field_format ref_status_format[] = {
FIELD_FORMAT_INIT(FIELD_TYPE_POINTER_SHORT_ID, ref_status, shortId, 1, FIELD_RELEVANCE_HIGH),
FIELD_FORMAT_INIT(FIELD_TYPE_POINTER_GLOBAL_ID, ref_status, nodeId, 1, FIELD_RELEVANCE_MEDI),
Expand Down Expand Up @@ -1279,7 +1252,6 @@ static int32_t ref_status_creator(struct status_handl *handl, void *data)
}
}


//dbgf((droppedSRefs || (allRefs != i)) ? DBGL_CHANGES : DBGL_ALL, droppedSRefs ? DBGT_WARN : DBGT_INFO,
dbgf_track(DBGT_INFO,
"all=%d shown=%d != (%d = (named=%d + desc=%d + claimed=%d)) dDropped=%d sDropped=%d",
Expand Down Expand Up @@ -1502,62 +1474,50 @@ DESC_SQN_T newDescriptionSqn(char* newPath, uint8_t exitIfFailure)
return currSqn; }
}



static struct opt_type bmx_options[] ={
// ord parent long_name shrt Attributes *ival min max default *func,*syntax,*help

{ODI,0,ARG_VERSION, 'v',9,2,A_PS0,A_USR,A_DYI,A_ARG,A_ANY, 0, 0, 0, 0,0, opt_version,
0, "show version"},
{ODI, 0, ARG_VERSION, 'v', 9, 2, A_PS0, A_USR, A_DYI, A_ARG,A_ANY, 0, 0, 0, 0, 0, opt_version, 0, "show Version"},

{ODI, 0, ARG_COMPATIBILITY, 0, 3, 1, A_PS1, A_ADM, A_INI, A_CFA, A_ANY, &my_compatibility, MIN_COMPATIBILITY, MAX_COMPATIBILITY, DEF_COMPATIBILITY, 0, 0, ARG_VALUE_FORM, "set (elastic) compatibility version"},

{ODI,0,ARG_COMPATIBILITY, 0, 3,1,A_PS1,A_ADM,A_INI,A_CFA,A_ANY, &my_compatibility,MIN_COMPATIBILITY,MAX_COMPATIBILITY,DEF_COMPATIBILITY,0, 0,
ARG_VALUE_FORM, "set (elastic) compatibility version"},
//order must be after ARG_KEY_PATH and before ARG_AUTO_IP6_PREFIX and ARG_TUN_IN_DEV (which use self, initialized from init_self, called from opt_hostname):
{ODI,0,ARG_HOSTNAME, 0, 5,0,A_PS1,A_ADM,A_DYI,A_CFA,A_ANY, 0, 0, 0, 0,0, opt_hostname,
ARG_VALUE_FORM, "set advertised hostname of node"},
{ODI, 0, ARG_HOSTNAME, 0, 5, 0, A_PS1, A_ADM, A_DYI, A_CFA, A_ANY, 0, 0, 0, 0, 0, opt_hostname, ARG_VALUE_FORM, "Set Advertised Hostname of node"},

{ODI,0,ARG_LIST, 0 , 9,1,A_PS1N ,A_USR,A_DYN,A_ARG,A_ANY,0, 0, 0, 0,0, opt_list_show,
ARG_VALUE_FORM, "list status information about given context. E.g.:" ARG_STATUS ", " ARG_INTERFACES ", " ARG_LINKS ", " ARG_ORIGINATORS " " ARG_CREDITS ", ..." "\n"},
{ODI, 0, ARG_LIST, 0, 9, 1, A_PS1N, A_USR, A_DYN, A_ARG, A_ANY, 0, 0, 0, 0,0, opt_list_show, ARG_VALUE_FORM, "list status information about given context. E.g.:" ARG_STATUS ", " ARG_INTERFACES ", " ARG_LINKS ", " ARG_ORIGINATORS " " ARG_CREDITS ", ..." "\n"},
{ODI,ARG_LIST,ARG_RELEVANCE,'r',9,1,A_CS1,A_USR,A_DYN,A_ARG,A_ANY, 0, MIN_RELEVANCE, MAX_RELEVANCE, DEF_RELEVANCE,0, opt_list_show,
ARG_VALUE_FORM, HLP_ARG_RELEVANCE}
,
{ODI,0,ARG_SHOW, 's', 9,1,A_PS1N,A_USR,A_DYN,A_ARG,A_ANY,0, 0, 0, 0,0, opt_status,
ARG_VALUE_FORM, "show status information about given context. E.g.:" ARG_STATUS ", " ARG_INTERFACES ", " ARG_LINKS ", " ARG_ORIGINATORS " " ARG_CREDITS ", ..." "\n"},
{ODI,ARG_SHOW,ARG_RELEVANCE,'r',9,1,A_CS1,A_USR,A_DYN,A_ARG,A_ANY, 0, MIN_RELEVANCE, MAX_RELEVANCE, DEF_RELEVANCE,0, opt_status,
ARG_VALUE_FORM, HLP_ARG_RELEVANCE}
,
{ODI, 0, ARG_SHOW, 's', 9, 1, A_PS1N, A_USR, A_DYN, A_ARG,A_ANY, 0, 0, 0, 0, 0, opt_status, ARG_VALUE_FORM, "show status information about given context. E.g.:" ARG_STATUS ", " ARG_INTERFACES ", " ARG_LINKS ", " ARG_ORIGINATORS " " ARG_CREDITS ", ..." "\n"},
{ODI, ARG_SHOW, ARG_RELEVANCE, 'r', 9, 1, A_CS1, A_USR, A_DYN, A_ARG, A_ANY, 0, MIN_RELEVANCE, MAX_RELEVANCE, DEF_RELEVANCE, 0, opt_status, ARG_VALUE_FORM, HLP_ARG_RELEVANCE},

{ODI,0,ARG_STATUS, 0, 9,1,A_PS0,A_USR,A_DYN,A_ARG,A_ANY, 0, 0, 0, 0,0, opt_status,
0, "show status\n"},
{ODI, 0, ARG_STATUS, 0, 9, 1, A_PS0, A_USR, A_DYN, A_ARG, A_ANY, 0, 0, 0, 0, 0, opt_status, 0, "Show status"},

{ODI,0,ARG_ORIGINATORS, 0, 9,1,A_PS0N,A_USR,A_DYN,A_ARG,A_ANY, 0, 0, 0, 0,0, opt_status,
0, "show originators\n"}
{ODI, 0, ARG_ORIGINATORS, 0, 9, 1, A_PS0N, A_USR, A_DYN, A_ARG, A_ANY, 0, 0, 0, 0, 0, opt_status, 0, "Show originators"}
,
{ODI,0,ARG_KEYS, 0, 9,1,A_PS0N,A_USR,A_DYN,A_ARG,A_ANY, 0, 0, 0, 0,0, opt_status,
0, "show keys and their description references\n"}
{ODI, 0, ARG_KEYS, 0, 9, 1, A_PS0N, A_USR, A_DYN, A_ARG, A_ANY, 0, 0, 0, 0, 0, opt_status, 0, "Show Keys and their description references"}
,
{ODI,0,ARG_DESCREFS, 0, 9,1,A_PS0N,A_USR,A_DYN,A_ARG,A_ANY, 0, 0, 0, 0,0, opt_status,
0, "show description references\n"}
{ODI, 0, ARG_DESCREFS, 0, 9, 1, A_PS0N, A_USR, A_DYN, A_ARG, A_ANY, 0, 0, 0, 0, 0, opt_status, 0, "Show description references"}
,
{ODI,0,"flushAll", 0, 9,1,A_PS0,A_ADM,A_DYN,A_ARG,A_ANY, 0, 0, 0, 0,0, opt_flush_all,
0, "purge all neighbors and routes on the fly"}
{ODI, 0, "flushAll", 0, 9, 1, A_PS0, A_ADM, A_DYN, A_ARG, A_ANY, 0, 0, 0, 0, 0, opt_flush_all, 0, "Purge all neighbors and routes on the fly!"}
,
#ifndef LESS_OPTIONS
{ODI,0,ARG_DAD_TO, 0, 9,1,A_PS1,A_ADM,A_DYI,A_CFA,A_ANY, &dad_to, MIN_DAD_TO, MAX_DAD_TO, DEF_DAD_TO,0, 0,
ARG_VALUE_FORM, "duplicate address (DAD) detection timout in ms"}
{ODI, 0, ARG_DAD_TO, 0, 9, 1, A_PS1, A_ADM, A_DYI, A_CFA, A_ANY, &dad_to, MIN_DAD_TO, MAX_DAD_TO, DEF_DAD_TO, 0, 0, ARG_VALUE_FORM, "Duplicate ADdress (DAD) detection timout in ms"}
#endif
};

STATIC_FUNC
void bmx(void)
{

/* Initialize timers */
TIME_T frequent_timeout, seldom_timeout;

TIME_T s_last_cpu_time = 0, s_curr_cpu_time = 0;

frequent_timeout = seldom_timeout = bmx_time;

/* Post first description */
update_my_description();

initializing = NO;
Expand All @@ -1578,7 +1538,6 @@ void bmx(void)
// check for changed interface konfigurations...
sysctl_config(NULL);


close_ctrl_node(CTRL_CLEANUP, NULL);

/*
Expand All @@ -1601,15 +1560,13 @@ void bmx(void)
frequent_timeout = bmx_time;
}


if (U32_LT(seldom_timeout + 5000, bmx_time)) {

//node_tasks();

// check for corrupted memory..
checkIntegrity();


/* generating cpu load statistics... */
s_curr_cpu_time = (TIME_T) clock();
s_curr_avg_cpu_load = ((s_curr_cpu_time - s_last_cpu_time) / (TIME_T) (bmx_time - seldom_timeout));
Expand All @@ -1628,7 +1585,6 @@ int main(int argc, char *argv[])

sscanf(GIT_REV, "%7X", &bmx_git_rev_u32);


struct rlimit rlim = { .rlim_cur = (CORE_LIMIT * 1024), .rlim_max = (CORE_LIMIT * 1024) };

if (setrlimit(RLIMIT_CORE, &rlim) != 0) {
Expand All @@ -1638,7 +1594,6 @@ int main(int argc, char *argv[])
#endif
My_pid = getpid();


signal(SIGINT, handler);
signal(SIGTERM, handler);
signal(SIGPIPE, SIG_IGN);
Expand All @@ -1648,7 +1603,6 @@ int main(int argc, char *argv[])
debugMalloc(1, -300525); //testing debugMalloc
#endif


init_control();
init_schedule();

Expand Down Expand Up @@ -1682,17 +1636,17 @@ int main(int argc, char *argv[])
assertion(-500809, (0));
}

/* Start the runtime profiler */
prof_start(main, NULL);

register_options_array(bmx_options, sizeof( bmx_options), CODE_CATEGORY_NAME);
register_options_array(bmx_options, sizeof(bmx_options), CODE_CATEGORY_NAME);

register_status_handl(sizeof(struct bmx_status), 0, bmx_status_format, ARG_STATUS, bmx_status_creator);
register_status_handl(sizeof(struct orig_status), 1, orig_status_format, ARG_ORIGINATORS, origs_status_creator);
register_status_handl(sizeof(struct orig_status), 1, keys_status_format, ARG_KEYS, keys_status_creator);
register_status_handl(sizeof(struct ref_status), 1, ref_status_format, ARG_DESCREFS, ref_status_creator);



/* Apply command line arguments */
apply_init_args(argc, argv);

bmx();
Expand Down
Loading