Skip to content

Commit

Permalink
tun: Allow zero remote tunnel addresses via --tunAnySrc=1
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Neumann committed Mar 8, 2019
1 parent 6a4fbc8 commit fd705f1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 10 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_any_src = DEF_TUN_ANY_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 = (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));
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 = (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);

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 @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions tun.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fd705f1

Please sign in to comment.