Skip to content

Commit

Permalink
make homenode configindpendent of exit node ips. see sudomesh/bugs#23
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpoelen committed Mar 21, 2018
1 parent ae17214 commit a3b243e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,24 @@ config interface 'ext1mesh'
option ifname 'eth0.1'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_bitmask %>'

config interface 'ext2mesh'
option ifname 'eth0.2'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_bitmask %>'

config interface 'mesh2'
option ifname 'mesh2'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_mask %>'

config interface 'mesh5'
option ifname 'mesh5'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_mask %>'

# This will be our "peoplesopen.net" bridge
Expand All @@ -99,7 +95,6 @@ config interface 'open'
option ifname 'open2 open5 eth0.10'
option proto 'static'
option ipaddr '<%= open_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= open_subnet_ipv4_mask %>'

config interface 'priv'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@

# TODO: We need to somehow detect this after the tunnel comes up
MESHEXITIP=<%= exit_node_mesh_ipv4_addr %>

OPEN=br-open # The open peoplesopen.net SSID and ethernet ports
PRIV=br-priv # The private WPA2 wifi SSID
TUN=l2tp0 # The tunnel
Expand Down
62 changes: 28 additions & 34 deletions configs/ar71xx/home_nodes/templates/files/etc/udhcpc.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
# This callback is activated on dhcp events from wan interface

for file in /etc/sudomesh/*; do
depends="$depends $file"
Expand All @@ -19,54 +20,46 @@ ip_calc=$(ipcalc.sh "$ip" "$subnet")
cidr_prefix=$(echo "$ip_calc" | grep -o 'PREFIX=\([0-9]\+\)' | sed -n -e 's/PREFIX=//p');
network=$(echo "$ip_calc" | grep -o 'NETWORK=\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)' | sed -n -e 's/NETWORK=//p');

setup_rules() {
# To keep from continuously adding the same rule, we delete first
clear_rules() {
ip rule del from "$network"/"$cidr_prefix" prio 13000 table main
ip rule del to "$network"/"$cidr_prefix" prio 13000 table main
}

setup_rules() {
# To keep from continuously adding the same rule, we delete first
clear_rules
ip rule add from "$network"/"$cidr_prefix" prio 13000 table main
ip rule add to "$network"/"$cidr_prefix" prio 13000 table main

ip route flush cache

test_connection
}

clear_rules() {
ip rule del from "$network"/"$cidr_prefix" prio 13000 table main
ip rule del to "$network"/"$cidr_prefix" prio 13000 table main
}

test_connection() {
local tries
local ping_time
local retry_pause
local max_tries
local connected
tries=0
ping_time=5
retry_pause=5
max_tries=20
connected=false
check_mesh_routes() {
local try_count=0
local try_max=400
local try_sleep=5
local try_restart_interval=20

while [ "$tries" -lt "$max_tries" ]; do
logger "pinging $MESHEXITIP"
if /bin/ping -c 1 -w "$ping_time" -I "$TUN" "$MESHEXITIP" > /dev/null; then
logger "Got pong back from $MESHEXITIP"
connected=true
while [ "$try_count" -lt "$try_max" ]; do
# extract gateway ip from babeld managed routing table "public"
local exitnode_mesh_ip=$(ip route show table public | grep $TUN | grep via | awk -F ' ' '{print $3
}' | uniq | head -n1)
if [ -n "$exitnode_mesh_ip" ]; then
logger "found a mesh route to [$exitnode_mesh_ip] via [$TUN]."
break
fi
try_count=`expr $try_count + 1`

sleep $retry_pause
tries=`expr $tries + 1`
# restart every once in a while
if [ `expr $try_count % $try_restart_interval` -eq 0 ]; then
logger "no mesh routes available yet via [$TUN] on try [$try_count]: restarting meshrouting..."
/etc/init.d/meshrouting restart
else
logger "no mesh routes available yet via [$TUN] on try [$try_count]: checking again in [$try_sleep]s..."
sleep $try_sleep
fi
done

if [ "$connected" = false ]; then
# Do we just want to run /etc/init.d/tunneldigger restart here?
logger "Cannot connect to exit server. Restarting meshrouting"
/etc/init.d/meshrouting restart
else
logger "Successfully connected to exit server."
fi
}

case "$1" in
Expand All @@ -75,5 +68,6 @@ case "$1" in
;;
renew|bound)
setup_rules
check_mesh_routes
;;
esac
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,24 @@ config interface 'ext1mesh'
option ifname 'eth0.1'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_bitmask %>'

config interface 'ext2mesh'
option ifname 'eth0.2'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_bitmask %>'

config interface 'mesh2'
option ifname 'mesh2'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_mask %>'

config interface 'mesh5'
option ifname 'mesh5'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_mask %>'

# This will be our "peoplesopen.net" bridge
Expand All @@ -100,7 +96,6 @@ config interface 'open'
option ifname 'open2 open5 eth0.10'
option proto 'static'
option ipaddr '<%= open_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= open_subnet_ipv4_mask %>'

config interface 'priv'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,24 @@ config interface 'ext1mesh'
option ifname 'eth0.2'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_bitmask %>'

config interface 'ext2mesh'
option ifname 'eth0.3'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_bitmask %>'

config interface 'mesh2'
option ifname 'mesh2'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_mask %>'

config interface 'mesh5'
option ifname 'mesh5'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_mask %>'

# This will be our "peoplesopen.net" bridge
Expand All @@ -102,7 +98,6 @@ config interface 'open'
option ifname 'open2 open5 eth0.10'
option proto 'static'
option ipaddr '<%= open_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= open_subnet_ipv4_mask %>'

config interface 'priv'
Expand Down
2 changes: 0 additions & 2 deletions configs/templates/files/etc/config/network
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@ config interface 'adhoc'
option ifname 'adhoc0'
option proto 'static'
option ipaddr '<%= adhoc_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= adhoc_subnet_ipv4_mask %>'

config interface 'open'
option ifname 'open0'
option proto 'static'
option ipaddr '<%= open_addr_ipv4 %>'
option dns '<%= exit_node_mesh_ipv4_addr %>'
option netmask '<%= open_subnet_ipv4_mask %>'

config interface 'priv'
Expand Down

2 comments on commit a3b243e

@bennlich
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome changes to udhcpc.user!

I tried looking up the documentation for the dns option in /etc/config/network, but there doesn't appear to be any (see https://openwrt.org/docs/guide-user/base-system/basic-networking). Do you know anything about the meaning of this option? Is it totally bogus? Was it being used to store info in uci config that is read by our own scripts elsewhere?

@jhpoelen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intuitively, it would set the dns server used to resolve name through that interface, but I didn't look for far for documentation. Removing the settings doesn't seem to affect the functioning of the home node as far as I can tell.

Please sign in to comment.