From c4f7158f2cf6ce659540567211a10101e4be0f9a Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Tue, 14 Aug 2018 12:19:49 +0200 Subject: [PATCH 1/5] rename list_add_tail and struct list_head Rename some list stuff to avoid namespace collision with libubox --- control.c | 18 +++++++++--------- control.h | 12 ++++++------ lib/bmx7_tun/tun.c | 2 +- list.c | 26 +++++++++++++------------- list.h | 36 ++++++++++++++++++------------------ msg.h | 2 +- plugin.c | 8 ++++---- plugin.h | 2 +- schedule.c | 2 +- tun.h | 2 +- 10 files changed, 55 insertions(+), 55 deletions(-) diff --git a/control.c b/control.c index ee9df30..9ab778d 100644 --- a/control.c +++ b/control.c @@ -73,7 +73,7 @@ uint32_t My_pid = 0; LIST_SIMPEL(ctrl_list, struct ctrl_node, list, list); -struct list_head dbgl_clients[DBGL_MAX + 1]; +struct bmx_list_head dbgl_clients[DBGL_MAX + 1]; static struct dbg_histogram dbgl_history[2][DBG_HIST_SIZE]; static uint8_t debug_system_active = NO; @@ -136,7 +136,7 @@ void add_dbgl_node(struct ctrl_node *cn, int dbgl) dn->cn = cn; cn->dbgl = dbgl; - list_add_tail(&dbgl_clients[dbgl], &dn->list); + bmx_list_add_tail(&dbgl_clients[dbgl], &dn->list); if (dbgl == DBGL_SYS || dbgl == DBGL_CHANGES) { dbgf_all(DBGT_INFO, "resetting muted dbg history"); @@ -255,7 +255,7 @@ struct ctrl_node *create_ctrl_node(int fd, void (*cn_fd_handler) (struct ctrl_no { struct ctrl_node *cn = debugMallocReset(sizeof(struct ctrl_node), -300010); - list_add_tail(&ctrl_list, &cn->list); + bmx_list_add_tail(&ctrl_list, &cn->list); cn->fd = fd; cn->cn_fd_handler = cn_fd_handler; @@ -571,7 +571,7 @@ void debug_output(uint32_t check_len, struct ctrl_node *cn, int8_t dbgl, int8_t if (level == DBGL_SYS && mute_dbgl_sys == DBG_HIST_MUTED) continue; - list_for_each(list_pos, /*(struct list_head *)*/&(dbgl_clients[level])) + list_for_each(list_pos, /*(struct bmx_list_head *)*/&(dbgl_clients[level])) { struct dbgl_node *dn = list_entry(list_pos, struct dbgl_node, list); @@ -990,7 +990,7 @@ void register_option(struct opt_type *opt, const char * category_name) opt->d.parent_opt = tmp_opt; - list_add_tail(&tmp_opt->d.childs_type_list, &opt->d.list); + bmx_list_add_tail(&tmp_opt->d.childs_type_list, &opt->d.list); } else { @@ -1017,7 +1017,7 @@ void register_option(struct opt_type *opt, const char * category_name) } if (!tmp_opt) - list_add_tail(&opt_list, &opt->d.list); + bmx_list_add_tail(&opt_list, &opt->d.list); } @@ -1094,7 +1094,7 @@ struct opt_type *get_option(struct opt_type *parent_opt, uint8_t short_opt, char struct list_node *list_pos; int32_t len = 0; - struct list_head *list; + struct bmx_list_head *list; struct opt_type *opt = NULL; char *equalp = NULL; char s[MAX_ARG_SIZE] = ""; @@ -1305,7 +1305,7 @@ struct opt_child *add_opt_child(struct opt_type *opt, struct opt_parent *p) c->opt = opt; c->parent_instance = p; - list_add_tail(&p->childs_instance_list, &c->list); + bmx_list_add_tail(&p->childs_instance_list, &c->list); return c; } @@ -1347,7 +1347,7 @@ struct opt_parent *add_opt_parent(struct opt_type *opt) LIST_INIT_HEAD(p->childs_instance_list, struct opt_child, list, list); - list_add_tail(&opt->d.parents_instance_list, &p->list); + bmx_list_add_tail(&opt->d.parents_instance_list, &p->list); return p; } diff --git a/control.h b/control.h index df0176f..4ef0854 100644 --- a/control.h +++ b/control.h @@ -49,7 +49,7 @@ typedef uint32_t TIME_SEC_T; extern int unix_sock; -extern struct list_head ctrl_list; +extern struct bmx_list_head ctrl_list; extern int32_t Client_mode; @@ -115,7 +115,7 @@ struct ctrl_node { int8_t dbgl; }; -extern struct list_head dbgl_clients[DBGL_MAX + 1]; +extern struct bmx_list_head dbgl_clients[DBGL_MAX + 1]; struct dbgl_node { struct list_node list; @@ -227,7 +227,7 @@ struct ctrl_node *create_ctrl_node(int fd, void (*cn_fd_handler) (struct ctrl_no #define MAX_UNIX_MSG_SIZE 2000 -extern struct list_head opt_list; +extern struct bmx_list_head opt_list; /* opt_t types: @@ -292,7 +292,7 @@ struct opt_child { struct opt_parent { struct list_node list; - struct list_head childs_instance_list; + struct bmx_list_head childs_instance_list; char *val; //key @@ -311,9 +311,9 @@ struct opt_data { struct opt_type *parent_opt; //REMOVE THIS and use casting instead ! - struct list_head childs_type_list; //if this opt is a section type, then further sub-opts types can be listed here + struct bmx_list_head childs_type_list; //if this opt is a section type, then further sub-opts types can be listed here - struct list_head parents_instance_list; // + struct bmx_list_head parents_instance_list; // }; struct opt_type { diff --git a/lib/bmx7_tun/tun.c b/lib/bmx7_tun/tun.c index 2aa740c..265c47a 100644 --- a/lib/bmx7_tun/tun.c +++ b/lib/bmx7_tun/tun.c @@ -126,7 +126,7 @@ void set_tunXin6_net_adv_list_handl(uint8_t del, void **adv_list_ptr) n = debugMallocReset(sizeof( struct tunXin6_net_adv_list_node), -300517); n->adv_list = adv_list; - list_add_tail((&tunXin6_net_adv_list_list), &n->list); + bmx_list_add_tail((&tunXin6_net_adv_list_list), &n->list); } STATIC_FUNC diff --git a/list.c b/list.c index 5e0665d..b698874 100644 --- a/list.c +++ b/list.c @@ -39,7 +39,7 @@ * @head: list head of maintained nodes * @node: a node maintained in the list or NULL */ -void * list_iterate(struct list_head *head, void *node) +void * list_iterate(struct bmx_list_head *head, void *node) { struct list_node *ln = (node ? ((struct list_node*) (((char*) node) + head->list_node_offset)) : @@ -53,7 +53,7 @@ void * list_iterate(struct list_head *head, void *node) return(((char*) ln->next) - head->list_node_offset); } -void *list_find_next(struct list_head *head, void* key, void *node) +void *list_find_next(struct bmx_list_head *head, void* key, void *node) { while ((node = list_iterate(head, node))) { @@ -68,7 +68,7 @@ void *list_find_next(struct list_head *head, void* key, void *node) * @head: list head to add it after * @new: new entry to be added */ -void list_add_head(struct list_head *head, struct list_node *new) +void list_add_head(struct bmx_list_head *head, struct list_node *new) { new->next = head->next; @@ -82,12 +82,12 @@ void list_add_head(struct list_head *head, struct list_node *new) } /** - * list_add_tail - add a new entry + * bmx_list_add_tail - add a new entry * @head: list head to add it before * @new: new entry to be added */ -void list_add_tail(struct list_head *head, struct list_node *new) +void bmx_list_add_tail(struct bmx_list_head *head, struct list_node *new) { new->next = (struct list_node *) head; head->last->next = new; @@ -96,7 +96,7 @@ void list_add_tail(struct list_head *head, struct list_node *new) head->items++; } -void list_add_after(struct list_head *head, struct list_node *ln, struct list_node *new) +void list_add_after(struct bmx_list_head *head, struct list_node *ln, struct list_node *new) { new->next = ln->next; ln->next = new; @@ -112,7 +112,7 @@ void list_add_after(struct list_head *head, struct list_node *ln, struct list_no * @entry: the element to delete from the list. * Note: list_empty on entry does not return true after this, the entry is in an undefined state. */ -void list_del_next(struct list_head *head, struct list_node *ln) +void list_del_next(struct bmx_list_head *head, struct list_node *ln) { assertion(-502641, (ln->next != (struct list_node*) head)); @@ -126,7 +126,7 @@ void list_del_next(struct list_head *head, struct list_node *ln) head->items--; } -void *list_del_head(struct list_head *head) +void *list_del_head(struct bmx_list_head *head) { if (LIST_EMPTY(head)) return NULL; @@ -147,7 +147,7 @@ void *list_del_head(struct list_head *head) */ /* UNTESTED -void * plist_iterate(struct list_head *head, struct plist_node **pln) +void * plist_iterate(struct bmx_list_head *head, struct plist_node **pln) { if (head->last == (struct list_node*) @@ -169,17 +169,17 @@ static struct plist_node *plist_node_create(void *item) return plh; } -void plist_add_head(struct list_head *head, void *item) +void plist_add_head(struct bmx_list_head *head, void *item) { list_add_head(head, &((plist_node_create(item))->list)); } -void plist_add_tail(struct list_head *head, void *item) +void plist_add_tail(struct bmx_list_head *head, void *item) { - list_add_tail(head, &((plist_node_create(item))->list)); + bmx_list_add_tail(head, &((plist_node_create(item))->list)); } -void * plist_del_head(struct list_head *head) +void * plist_del_head(struct bmx_list_head *head) { struct plist_node *pln = list_del_head(head); diff --git a/list.h b/list.h index d40306c..770dc9f 100644 --- a/list.h +++ b/list.h @@ -28,7 +28,7 @@ #ifndef _LIST_H -#define _LIST_H +#define _LIST_H_ #include @@ -36,7 +36,7 @@ struct list_node { struct list_node *next; }; -struct list_head { +struct bmx_list_head { struct list_node *next; struct list_node *last; uint16_t items; @@ -52,7 +52,7 @@ struct plist_node { -#define LIST_SIMPEL(ptr, element_type, list_field, key_field ) struct list_head ptr = { \ +#define LIST_SIMPEL(ptr, element_type, list_field, key_field ) struct bmx_list_head ptr = { \ .next = (struct list_node *)&ptr, \ .last = (struct list_node *)&ptr, \ .items = 0, \ @@ -75,14 +75,14 @@ struct plist_node { #define list_get_first(head) ((void*)((LIST_EMPTY(head)) ? NULL : (((char*) (head)->next) - (head)->list_node_offset) )) #define list_get_last(head) ((void*)((LIST_EMPTY(head)) ? NULL : (((char*) (head)->last) - (head)->list_node_offset) )) -void *list_iterate(struct list_head *head, void *node); -void *list_find_next(struct list_head *head, void* key, void *node); +void *list_iterate(struct bmx_list_head *head, void *node); +void *list_find_next(struct bmx_list_head *head, void* key, void *node); -void list_add_head(struct list_head *head, struct list_node * new); -void list_add_tail(struct list_head *head, struct list_node * new); -void list_add_after(struct list_head *head, struct list_node *pos, struct list_node * new); -void list_del_next(struct list_head *head, struct list_node *pos); -void *list_del_head(struct list_head *head); +void list_add_head(struct bmx_list_head *head, struct list_node * new); +void bmx_list_add_tail(struct bmx_list_head *head, struct list_node * new); +void list_add_after(struct bmx_list_head *head, struct list_node *pos, struct list_node * new); +void list_del_next(struct bmx_list_head *head, struct list_node *pos); +void *list_del_head(struct bmx_list_head *head); #define plist_get_first(head) (LIST_EMPTY(head) ? NULL : \ @@ -91,17 +91,17 @@ void *list_del_head(struct list_head *head); #define plist_get_last(head) (LIST_EMPTY(head) ? NULL : \ ((struct plist_node*)(((char*) (head)->prev) - (head)->list_node_offset))-item ) -void * plist_iterate(struct list_head *head, struct plist_node **pln); +void * plist_iterate(struct bmx_list_head *head, struct plist_node **pln); -void plist_add_head(struct list_head *head, void *item); -void plist_add_tail(struct list_head *head, void *item); -void *plist_del_head(struct list_head *head); +void plist_add_head(struct bmx_list_head *head, void *item); +void plist_add_tail(struct bmx_list_head *head, void *item); +void *plist_del_head(struct bmx_list_head *head); /** * list_entry - get the struct for this entry - * @ptr: the &struct list_head pointer. + * @ptr: the &struct bmx_list_head pointer. * @type: the type of the struct this is embedded in. * @member: the name of the list_struct within the struct. */ @@ -109,7 +109,7 @@ void *plist_del_head(struct list_head *head); /** * list_for_each - iterate over a list - * @pos: the &struct list_head to use as a loop counter. + * @pos: the &struct bmx_list_head to use as a loop counter. * @head: the head for your list. */ #define list_for_each(pos, head) \ @@ -123,8 +123,8 @@ void *plist_del_head(struct list_head *head); /** * list_for_each_safe - iterate over a list safe against removal of list entry - * @pos: the &struct list_head to use as a loop counter. - * @n: another &struct list_head to use as temporary storage + * @pos: the &struct bmx_list_head to use as a loop counter. + * @n: another &struct bmx_list_head to use as temporary storage * @head: the head for your list. */ #define list_for_each_safe(pos, n, head) \ diff --git a/msg.h b/msg.h index d36f6e2..b881cef 100644 --- a/msg.h +++ b/msg.h @@ -357,7 +357,7 @@ struct tx_frame_iterator { // MUST be initialized: // remains unchanged: const char *caller; - struct list_head *tx_task_list; + struct bmx_list_head *tx_task_list; struct tx_task_node *ttn; // struct desc_contents *descContents; struct frame_db *db; diff --git a/plugin.c b/plugin.c index 5016956..102cdba 100644 --- a/plugin.c +++ b/plugin.c @@ -74,7 +74,7 @@ void _set_thread_hook(int32_t cb_type, void (*cb_handler) (void), int8_t del, st cleanup_all(-500143); } - list_for_each_safe(list_pos, tmp_pos, (struct list_head*) cb_list) + list_for_each_safe(list_pos, tmp_pos, (struct bmx_list_head*) cb_list) { cbn = list_entry(list_pos, struct cb_node, list); @@ -82,7 +82,7 @@ void _set_thread_hook(int32_t cb_type, void (*cb_handler) (void), int8_t del, st if (del) { - list_del_next(((struct list_head*) cb_list), prev_pos); + list_del_next(((struct bmx_list_head*) cb_list), prev_pos); debugFree(cbn, -300069); return; @@ -103,7 +103,7 @@ void _set_thread_hook(int32_t cb_type, void (*cb_handler) (void), int8_t del, st cbn->cb_type = cb_type; cbn->cb_handler = cb_handler; - list_add_tail(((struct list_head*) cb_list), &cbn->list); + bmx_list_add_tail(((struct bmx_list_head*) cb_list), &cbn->list); } @@ -261,7 +261,7 @@ int activate_plugin(struct plugin *p, void *dlhandle, const char *dl_name) pn->plugin = p; pn->dlhandle = dlhandle; - list_add_tail(&plugin_list, &pn->list); + bmx_list_add_tail(&plugin_list, &pn->list); dbgf_all(DBGT_INFO, "%s SUCCESS", pn->plugin->plugin_name); diff --git a/plugin.h b/plugin.h index 5028d4e..b5c9727 100644 --- a/plugin.h +++ b/plugin.h @@ -74,7 +74,7 @@ struct cb_fd_node { void (*cb_fd_handler) (int32_t fd); }; -extern struct list_head cb_fd_list; +extern struct bmx_list_head cb_fd_list; // cb_fd_handler is called when fd received data // called function may remove itself void set_fd_hook(int32_t fd, void (*cb_fd_handler) (int32_t fd), int8_t del); diff --git a/schedule.c b/schedule.c index 8e3f7a6..8868b01 100644 --- a/schedule.c +++ b/schedule.c @@ -205,7 +205,7 @@ void task_register(TIME_T timeout, void (* task) (void *), void *data, int32_t t } if ((tmp_tn == NULL) || (U32_LE(tmp_tn->expire, tn->expire))) - list_add_tail(&task_list, &tn->list); + bmx_list_add_tail(&task_list, &tn->list); } diff --git a/tun.h b/tun.h index 06b8c6f..102ee87 100644 --- a/tun.h +++ b/tun.h @@ -309,7 +309,7 @@ struct tunXin6_net_adv_list_node { }; -extern struct list_head tunXin6_net_adv_list_list; +extern struct bmx_list_head tunXin6_net_adv_list_list; struct tun_bit_key_nodes { struct tun_search_node *tsn; From 6a4fbc86e0f18ac9673adda80a0f03d871c269cf Mon Sep 17 00:00:00 2001 From: Axel Neumann Date: Thu, 7 Mar 2019 21:39:59 +0100 Subject: [PATCH 2/5] Set default CRYPTLIB to mbedtls 2.8.0 (compatible, at least, up to 2.18.0) --- crypt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypt.h b/crypt.h index 465d952..a678fb7 100644 --- a/crypt.h +++ b/crypt.h @@ -39,7 +39,7 @@ #ifndef CRYPTLIB -#define CRYPTLIB MBEDTLS_2_4_0 +#define CRYPTLIB MBEDTLS_2_8_0 #endif #define CRYPT_DER_BUF_SZ 16000 From fd705f1dd60b05ac878482ad216b133a639d8ae9 Mon Sep 17 00:00:00 2001 From: Axel Neumann Date: Mon, 21 May 2018 22:13:56 +0200 Subject: [PATCH 3/5] tun: Allow zero remote tunnel addresses via --tunAnySrc=1 --- lib/bmx7_tun/tun.c | 16 ++++++++++------ tun.h | 5 +++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/bmx7_tun/tun.c b/lib/bmx7_tun/tun.c index 265c47a..e592bcb 100644 --- a/lib/bmx7_tun/tun.c +++ b/lib/bmx7_tun/tun.c @@ -90,7 +90,7 @@ static int32_t tun_out_delay = DEF_TUN_OUT_DELAY; static int32_t tun_out_mtu = DEF_TUN_OUT_MTU; static int32_t tun_dedicated_to = DEF_TUN_OUT_TO; static int32_t tun_proactive_routes = DEF_TUN_PROACTIVE_ROUTES; - +static int32_t tun_any_src = DEF_TUN_ANY_SRC; STATIC_FUNC void configure_tun_bit(uint8_t del, struct tun_bit_node *tbn, IDM_T asDfltTun); @@ -205,9 +205,9 @@ IDM_T configure_tunnel_in(uint8_t del, struct tun_in_node *tin, int16_t tun6Id) } else if (!del && !tin->upIfIdx) { IPX_T *local = &my_primary_ip; - IPX_T *remote = &tin->remote; + IPX_T remoteIp = (tun6Id || !tun_any_src) ? tin->remote : ZERO_IP; - if (!is_ip_set(remote) || is_ip_local(remote) || + if (!is_ip_set(&tin->remote) || is_ip_local(&tin->remote) || (tin->ingressPrefix46[0].mask && find_overlapping_hna(&tin->ingressPrefix46[0].ip, tin->ingressPrefix46[0].mask, NULL))) { dbgf_sys(DBGT_WARN, "FAILED creating tun remoteIp=%s", ip6AsStr(&tin->remote)); @@ -216,7 +216,7 @@ IDM_T configure_tunnel_in(uint8_t del, struct tun_in_node *tin, int16_t tun6Id) assertion(-501312, (strlen(tin->nameKey.str))); - if ((tin->upIfIdx = kernel_tun_add(tin->nameKey.str, IPPROTO_IP, local, remote)) > 0) { + if ((tin->upIfIdx = kernel_tun_add(tin->nameKey.str, IPPROTO_IP, local, &remoteIp)) > 0) { tin->tun6Id = tun6Id; @@ -724,8 +724,9 @@ struct tun_dev_node *tun_dev_out_add(struct tun_bit_node *tbn, IDM_T tdn_state) AVL_INIT_TREE(tdn->tun_bit_tree[0], struct tun_bit_node, tunBitKey.keyNodes); AVL_INIT_TREE(tdn->tun_bit_tree[1], struct tun_bit_node, tunBitKey.keyNodes); + IPX_T *localIp = (ton->tunOutKey.tun6Id || !tun_any_src) ? &ton->localIp : &my_primary_ip; tdn->nameKey = tun_out_get_free_name(DEF_TUN_NAME_TYPE_OUT, cryptShaAsString(&ton->tunOutKey.on->k.nodeId)); - tdn->ifIdx = kernel_tun_add(tdn->nameKey.str, IPPROTO_IP, &ton->localIp, &ton->remoteIp); + tdn->ifIdx = kernel_tun_add(tdn->nameKey.str, IPPROTO_IP, localIp, &ton->remoteIp); tdn->orig_mtu = kernel_get_mtu(tdn->nameKey.str); tdn->curr_mtu = set_tun_out_mtu(tdn->nameKey.str, tdn->orig_mtu, DEF_TUN_OUT_MTU, tun_out_mtu); @@ -735,7 +736,7 @@ struct tun_dev_node *tun_dev_out_add(struct tun_bit_node *tbn, IDM_T tdn_state) assertion(-501486, (tdn->orig_mtu >= MIN_TUN_OUT_MTU)); assertion(-501487, (!tdn->tunCatch_fd)); - kernel_set_addr(ADD, tdn->ifIdx, AF_INET6, &ton->localIp, 128, YES /*deprecated*/); + kernel_set_addr(ADD, tdn->ifIdx, AF_INET6, localIp, 128, YES /*deprecated*/); if (tin->tunAddr46[1].mask) kernel_set_addr(ADD, tdn->ifIdx, AF_INET, &tin->tunAddr46[1].ip, 32, NO/*deprecated*/); @@ -2763,6 +2764,9 @@ static struct opt_type tun_options[]= { {ODI,0,ARG_TUN_OUT_DELAY, 0, 9,2,A_PS1,A_ADM,A_DYI,A_CFA,A_ANY, &tun_out_delay, MIN_TUN_OUT_DELAY,MAX_TUN_OUT_DELAY,DEF_TUN_OUT_DELAY,0, 0, ARG_VALUE_FORM, "Delay catched tunnel packets for given us before rescheduling (avoid dmesg warning ip6_tunnel: X7Out_.. xmit: Local address not yet configured!)"}, + {ODI,0,ARG_TUN_ANY_SRC, 0, 9,2,A_PS1,A_ADM,A_DYI,A_CFA,A_ANY, &tun_any_src, MIN_TUN_ANY_SRC,MAX_TUN_ANY_SRC,DEF_TUN_ANY_SRC,0, 0, + ARG_VALUE_FORM, "Accept any (not faked) source address for primary tunnel interface as outer ip-in-ip6 tunnel header"}, + //order must be after ARG_HOSTNAME (which initializes self via init_self(), called from opt_hostname): {ODI,0,ARG_TUN_DEV, 0,9,2,A_PM1N,A_ADM,A_DYI,A_CFA,A_ANY, 0, 0, 0, 0,0, opt_tun_in_dev, diff --git a/tun.h b/tun.h index 102ee87..d4494ba 100644 --- a/tun.h +++ b/tun.h @@ -143,6 +143,11 @@ #define MIN_TUN_OUT_DELAY 0 #define MAX_TUN_OUT_DELAY 1000000 +#define ARG_TUN_ANY_SRC "tunAnySrc" +#define DEF_TUN_ANY_SRC 0 +#define MIN_TUN_ANY_SRC 0 +#define MAX_TUN_ANY_SRC 1 + #define ARG_EXPORT_ONLY "exportOnly" #define DEF_EXPORT_ONLY 0 #define MIN_EXPORT_ONLY 0 From 56bb017774cb631150e7c08f037e914c68535107 Mon Sep 17 00:00:00 2001 From: Axel Neumann Date: Fri, 8 Mar 2019 00:36:42 +0100 Subject: [PATCH 4/5] Fix rx_msg_content_request from UNVERIFIED neigh --- node.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/node.h b/node.h index f8e0b7b..d6a5af9 100644 --- a/node.h +++ b/node.h @@ -354,10 +354,10 @@ union content_sizes { struct content_usage_node { struct { + struct desc_content *descContent; + struct content_node *content; uint8_t expanded_type; uint8_t expanded_gzip; - struct content_node *content; - struct desc_content *descContent; } __attribute__((packed)) k; uint8_t maxUsedLevel; From cc245a22e54b5e110384485f18d9b805c91d8b71 Mon Sep 17 00:00:00 2001 From: Axel Neumann Date: Fri, 8 Mar 2019 14:35:04 +0100 Subject: [PATCH 5/5] Replace tunAnySrc=<0|1> by tunRealSrc=<0|1|2> (current default is 0). Fix dynamic reconfiguration. --- lib/bmx7_tun/tun.c | 23 ++++++++++++++++++----- tun.h | 11 +++++++---- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/bmx7_tun/tun.c b/lib/bmx7_tun/tun.c index e592bcb..43351be 100644 --- a/lib/bmx7_tun/tun.c +++ b/lib/bmx7_tun/tun.c @@ -90,7 +90,7 @@ static int32_t tun_out_delay = DEF_TUN_OUT_DELAY; static int32_t tun_out_mtu = DEF_TUN_OUT_MTU; static int32_t tun_dedicated_to = DEF_TUN_OUT_TO; static int32_t tun_proactive_routes = DEF_TUN_PROACTIVE_ROUTES; -static int32_t tun_any_src = DEF_TUN_ANY_SRC; +static int32_t tun_real_src = DEF_TUN_REAL_SRC; STATIC_FUNC void configure_tun_bit(uint8_t del, struct tun_bit_node *tbn, IDM_T asDfltTun); @@ -205,7 +205,7 @@ IDM_T configure_tunnel_in(uint8_t del, struct tun_in_node *tin, int16_t tun6Id) } else if (!del && !tin->upIfIdx) { IPX_T *local = &my_primary_ip; - IPX_T remoteIp = (tun6Id || !tun_any_src) ? tin->remote : ZERO_IP; + IPX_T remoteIp = (tun_real_src >= TYP_TUN_REAL_SRC_ANY) ? ZERO_IP : tin->remote; if (!is_ip_set(&tin->remote) || is_ip_local(&tin->remote) || (tin->ingressPrefix46[0].mask && find_overlapping_hna(&tin->ingressPrefix46[0].ip, tin->ingressPrefix46[0].mask, NULL))) { @@ -724,7 +724,7 @@ struct tun_dev_node *tun_dev_out_add(struct tun_bit_node *tbn, IDM_T tdn_state) AVL_INIT_TREE(tdn->tun_bit_tree[0], struct tun_bit_node, tunBitKey.keyNodes); AVL_INIT_TREE(tdn->tun_bit_tree[1], struct tun_bit_node, tunBitKey.keyNodes); - IPX_T *localIp = (ton->tunOutKey.tun6Id || !tun_any_src) ? &ton->localIp : &my_primary_ip; + IPX_T *localIp = (tun_real_src >= TYP_TUN_REAL_SRC_USE) ? &my_primary_ip : &ton->localIp; tdn->nameKey = tun_out_get_free_name(DEF_TUN_NAME_TYPE_OUT, cryptShaAsString(&ton->tunOutKey.on->k.nodeId)); tdn->ifIdx = kernel_tun_add(tdn->nameKey.str, IPPROTO_IP, localIp, &ton->remoteIp); tdn->orig_mtu = kernel_get_mtu(tdn->nameKey.str); @@ -2614,6 +2614,19 @@ int32_t opt_tun_name_prefix(uint8_t cmd, uint8_t _save, struct opt_type *opt, st return SUCCESS; } +STATIC_FUNC +int32_t opt_tun_real_src(uint8_t cmd, uint8_t _save, struct opt_type *opt, struct opt_parent *patch, struct ctrl_node *cn) +{ + if (cmd == OPT_APPLY) { + upd_tun_bit_node(DEL, NULL, NULL); + purge_tunCatchTree(); + reconfigure_tun_ins(); + upd_tun_bit_node(ADD, NULL, NULL); + eval_tun_bit_tree(NULL); + } + return SUCCESS; +} + STATIC_FUNC int32_t opt_tun_state_dedicated_to(uint8_t cmd, uint8_t _save, struct opt_type *opt, struct opt_parent *patch, struct ctrl_node *cn) { @@ -2764,8 +2777,8 @@ static struct opt_type tun_options[]= { {ODI,0,ARG_TUN_OUT_DELAY, 0, 9,2,A_PS1,A_ADM,A_DYI,A_CFA,A_ANY, &tun_out_delay, MIN_TUN_OUT_DELAY,MAX_TUN_OUT_DELAY,DEF_TUN_OUT_DELAY,0, 0, ARG_VALUE_FORM, "Delay catched tunnel packets for given us before rescheduling (avoid dmesg warning ip6_tunnel: X7Out_.. xmit: Local address not yet configured!)"}, - {ODI,0,ARG_TUN_ANY_SRC, 0, 9,2,A_PS1,A_ADM,A_DYI,A_CFA,A_ANY, &tun_any_src, MIN_TUN_ANY_SRC,MAX_TUN_ANY_SRC,DEF_TUN_ANY_SRC,0, 0, - ARG_VALUE_FORM, "Accept any (not faked) source address for primary tunnel interface as outer ip-in-ip6 tunnel header"}, + {ODI,0,ARG_TUN_REAL_SRC, 0, 9,1,A_PS1,A_ADM,A_DYI,A_CFA,A_ANY, &tun_real_src, MIN_TUN_REAL_SRC,MAX_TUN_REAL_SRC,DEF_TUN_REAL_SRC,0, opt_tun_real_src, + ARG_VALUE_FORM, "1: Accept any src address for incoming outer ip6 tunnel header. 2: Use primary address as src address for outgoing outer ip6 tunnel header"}, //order must be after ARG_HOSTNAME (which initializes self via init_self(), called from opt_hostname): diff --git a/tun.h b/tun.h index d4494ba..8050d8a 100644 --- a/tun.h +++ b/tun.h @@ -143,10 +143,13 @@ #define MIN_TUN_OUT_DELAY 0 #define MAX_TUN_OUT_DELAY 1000000 -#define ARG_TUN_ANY_SRC "tunAnySrc" -#define DEF_TUN_ANY_SRC 0 -#define MIN_TUN_ANY_SRC 0 -#define MAX_TUN_ANY_SRC 1 +#define ARG_TUN_REAL_SRC "tunRealSrc" +#define DEF_TUN_REAL_SRC 0 +#define MIN_TUN_REAL_SRC 0 +#define TYP_TUN_REAL_SRC_OFF 0 +#define TYP_TUN_REAL_SRC_ANY 1 +#define TYP_TUN_REAL_SRC_USE 2 +#define MAX_TUN_REAL_SRC 2 #define ARG_EXPORT_ONLY "exportOnly" #define DEF_EXPORT_ONLY 0