From 5bb4cf4e3a17c1444d79f707de86954730de2fc8 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 25 Jan 2014 03:20:03 +0100 Subject: [PATCH] gluon-mesh-vpn-fastd: always use wan DNS servers to resolve the peers --- package/gluon-mesh-vpn-fastd/Makefile | 2 + .../hotplug.d/iface/50-gluon-mesh-vpn-fastd | 3 + .../lib/gluon/mesh-vpn-fastd/update-dnsmasq | 101 ++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 package/gluon-mesh-vpn-fastd/files/etc/hotplug.d/iface/50-gluon-mesh-vpn-fastd create mode 100755 package/gluon-mesh-vpn-fastd/files/lib/gluon/mesh-vpn-fastd/update-dnsmasq diff --git a/package/gluon-mesh-vpn-fastd/Makefile b/package/gluon-mesh-vpn-fastd/Makefile index 1553af90..b679b930 100644 --- a/package/gluon-mesh-vpn-fastd/Makefile +++ b/package/gluon-mesh-vpn-fastd/Makefile @@ -31,6 +31,8 @@ define Build/Compile endef define Package/gluon-mesh-vpn-fastd/install + $(CP) ./files/* $(1)/ + $(INSTALL_DIR) $(1)/lib/gluon/upgrade/mesh-vpn-fastd/invariant $(INSTALL_BIN) $(PKG_BUILD_DIR)/fastd.sh $(1)/lib/gluon/upgrade/mesh-vpn-fastd/invariant/010-mesh-vpn-fastd endef diff --git a/package/gluon-mesh-vpn-fastd/files/etc/hotplug.d/iface/50-gluon-mesh-vpn-fastd b/package/gluon-mesh-vpn-fastd/files/etc/hotplug.d/iface/50-gluon-mesh-vpn-fastd new file mode 100644 index 00000000..26ad4773 --- /dev/null +++ b/package/gluon-mesh-vpn-fastd/files/etc/hotplug.d/iface/50-gluon-mesh-vpn-fastd @@ -0,0 +1,3 @@ +[ "$INTERFACE" = 'wan' ] || exit 0 + +/lib/gluon/mesh-vpn-fastd/update-dnsmasq diff --git a/package/gluon-mesh-vpn-fastd/files/lib/gluon/mesh-vpn-fastd/update-dnsmasq b/package/gluon-mesh-vpn-fastd/files/lib/gluon/mesh-vpn-fastd/update-dnsmasq new file mode 100755 index 00000000..33e23a59 --- /dev/null +++ b/package/gluon-mesh-vpn-fastd/files/lib/gluon/mesh-vpn-fastd/update-dnsmasq @@ -0,0 +1,101 @@ +#!/bin/sh + + +. /lib/functions.sh + + +_json_push() { + export JSON_PATH="${JSON_PATH}/$1" +} + +_json_pop() { + export JSON_PATH="${JSON_PATH%/*}" +} + +json_init() { + export JSON_PATH='' +} + +json_add_object() { + _json_push "$1" +} + +json_close_object() { + _json_pop +} + +json_add_array() { + _json_push "$1" +} + +json_close_array() { + _json_pop +} + +json_add_int() { + return +} + +json_add_boolean() { + return +} + +json_add_double() { + return +} + +json_add_string() { + [ "$JSON_PATH" = '/inactive/dns_server' ] || return + echo "$2" +} + + +get_dns_server() { + eval `jshn -r "$(ubus call network.interface.wan status)"` +} + +generate_dnsmasq_conf_remote() { + local remote="$1"; local servers="$2" + + local hostname="$(echo "$remote" | awk -F \" '{print $2}')" + [ -n "$hostname" ] || return + + for ns in $servers; do + echo "server=/$hostname/$ns" + done +} + +generate_dnsmasq_conf_peer() { + local peer="$1"; local servers="$2" + local enabled; local net + + config_get_bool enabled "$peer" 'enabled' 0 + [ "$enabled" -gt 0 ] || return + + config_get net "$peer" 'net' + [ "$net" = 'mesh_vpn' ] || return + + config_list_foreach "$peer" 'remote' generate_dnsmasq_conf_remote "$servers" +} + +generate_dnsmasq_conf() { + local servers="$1" + + config_load fastd + config_foreach generate_dnsmasq_conf_peer 'peer' "$servers" +} + + +mkdir -p /var/gluon/mesh-vpn-fastd +generate_dnsmasq_conf "$(get_dns_server)" > /var/gluon/mesh-vpn-fastd/dnsmasq.conf.$$ + +lock /var/gluon/mesh-vpn-fastd/dnsmasq.conf.lock + +if cmp -s /var/gluon/mesh-vpn-fastd/dnsmasq.conf.$$ /var/gluon/dnsmasq.d/mesh-vpn-fastd.conf; then + rm /var/gluon/mesh-vpn-fastd/dnsmasq.conf.$$ +else + mv -f /var/gluon/mesh-vpn-fastd/dnsmasq.conf.$$ /var/gluon/dnsmasq.d/mesh-vpn-fastd.conf + /etc/init.d/dnsmasq restart +fi + +lock -u /var/gluon/mesh-vpn-fastd/dnsmasq.conf.lock