Skip to content

Commit

Permalink
Merge branch 'testing'
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Neumann committed Mar 13, 2019
2 parents 3db1586 + cc245a2 commit d4f180b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
29 changes: 23 additions & 6 deletions lib/bmx7_tun/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_real_src = DEF_TUN_REAL_SRC;

STATIC_FUNC
void configure_tun_bit(uint8_t del, struct tun_bit_node *tbn, IDM_T asDfltTun);
Expand Down Expand Up @@ -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 = (tun_real_src >= TYP_TUN_REAL_SRC_ANY) ? ZERO_IP : tin->remote;

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));
Expand All @@ -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;

Expand Down Expand Up @@ -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 = (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, &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);

Expand All @@ -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*/);
Expand Down Expand Up @@ -2613,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)
{
Expand Down Expand Up @@ -2763,6 +2777,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_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):
{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,
Expand Down
4 changes: 2 additions & 2 deletions node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions tun.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@
#define MIN_TUN_OUT_DELAY 0
#define MAX_TUN_OUT_DELAY 1000000

#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
#define MIN_EXPORT_ONLY 0
Expand Down

0 comments on commit d4f180b

Please sign in to comment.