From: Ismaël Bouya Date: Wed, 12 Feb 2020 17:21:04 +0000 (+0100) Subject: Merge branch 'master' into android X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;h=refs%2Fheads%2Fandroid;p=perso%2FImmae%2FConfig%2Ftinc%2Fhosts.git Merge branch 'master' into android --- 6d0592b79d91196c9fe35cdf6b6a5407a6a44ea4 diff --cc ImmaeEu-down index 8a0ef22,8459778..1b6260e mode 100644,100755..100644 --- a/ImmaeEu-down +++ b/ImmaeEu-down @@@ -1,16 -1,12 +1,16 @@@ -#!/bin/sh +#!/system/xbin/sh # This file closes down the tap device. -[ -e /tmp/tinc_$NETNAME ] && . /tmp/tinc_$NETNAME -[ -e /run/tinc_$NETNAME.vars ] && . /run/tinc_$NETNAME.vars -rm -f /tmp/tinc_$NETNAME /run/tinc_$NETNAME.vars -[ -n "$GWIP" ] && ip -6 route del default via $GWIP +source /sdcard/.tinc/vars +rm /sdcard/.tinc/vars + +ip -6 rule del from all lookup 100 +ip route del table 100 $REMOTEADDRESS +ip -6 route del table 100 $GWIP dev vpn6 +ip -6 route del table 100 ::/1 via $GWIP dev vpn6 for MYIP in $MYIPS; do - ip -6 addr del $MYIP/96 dev vpn6 - ip -6 addr del $MYIP/96 dev $INTERFACE ++ ip -6 addr del $MYIP/96 dev vpn6 done -ip -6 link set $INTERFACE down +ip -6 link set vpn6 down + diff --cc ImmaeEu-up index 0921046,c2dc93a..b24eed8 mode 100644,100755..100644 --- a/ImmaeEu-up +++ b/ImmaeEu-up @@@ -1,18 -1,24 +1,19 @@@ -#!/bin/sh -# This file sets up the tap device. -# It gives you the freedom to do anything you want with it. -# Use the correct name for the tap device: -# The environment variable $INTERFACE is set to the right name -# on most platforms, but if it doesn't work try to set it manually. +#!/system/xbin/sh - SUBDOMAIN=$(cat /sdcard/.tinc/tinc_domaine | tr -c -d "[a-zA-Z0-9.]") -# Give it the right ip and netmask. Remember, the subnet of the -# tap device must be larger than that of the individual Subnets -# as defined in the host configuration file! -SUBDOMAIN=$(echo "$NAME" | sed -e "s/\([A-Z][a-z0-9]*\)/\L\1 /g;" | awk '{ for (i=NF; i>1; i--) printf("%s.",$i); print $1; }') -while [ -z "$MYIPS" -o -z "$GWIP" ]; do - MYIPS=`getent hosts ${SUBDOMAIN}.immae.eu | cut -d' ' -f1 | tr "\\n" ' '` - GWIP=`getent hosts gw.vpn.immae.eu | head -n1 | cut -d' ' -f1` - sleep 5 -done -rm -f /run/tinc_$NETNAME.vars -echo -e "MYIPS=\"$MYIPS\"\nGWIP=\"$GWIP\"" > /run/tinc_$NETNAME.vars -ip -6 link set $INTERFACE up mtu 1280 ++# Cannot expect awk to be present ++SUBDOMAIN=$(echo "$NAME" | sed -e "s/\([A-Z][a-z0-9]*\)\([A-Z][a-z0-9]*\)/\L\2.\L\1/;") + +MYIPS=$(nslookup $SUBDOMAIN.immae.eu |sed -n "/$SUBDOMAIN.immae.eu/"',$p' | grep ^Address | sed -e "s/^[^:]*:[^0-9]*//" | tr '\n' ' ') +GWIP=$(nslookup gw.vpn.immae.eu |sed -n "/gw.vpn.immae.eu/"',$p' | grep ^Address | head -n1 | sed -e "s/^[^:]*:[^0-9]*//" | tr '\n' ' ') + +echo -e "MYIPS=\"$MYIPS\"\nGWIP=\"$GWIP\"" > /sdcard/.tinc/vars +ip -6 link set vpn6 up mtu 1280 for MYIP in $MYIPS; do - ip -6 addr add $MYIP/96 dev vpn6 - ip -6 addr add $MYIP/96 dev $INTERFACE ++ ip -6 addr add $MYIP/96 dev vpn6 done -ip -6 route add default via $GWIP -(cd /etc/tinc/$NETNAME/hosts && git pull -q origin master) || true +ORIGINAL_GATEWAY=$(for a in $(ip rule show | grep lookup | sed -r 's/.* lookup ([^ ]+).*/\1/'); do ip route show table $a | grep ^default | cut -d ' ' -f 2-5; done | head -1) + +ip -6 rule add prio 100 from all lookup 100 +ip route add table 100 $REMOTEADDRESS $ORIGINAL_GATEWAY +ip -6 route add table 100 $GWIP dev vpn6 +ip -6 route add table 100 ::/1 via $GWIP dev vpn6