Skip to content

Commit

Permalink
Add new package gluon-wan-dnsmasq
Browse files Browse the repository at this point in the history
This package provides a secondary dnsmasq instance on port 54 which resolves
everything over the WAN interface.
  • Loading branch information
neocturne committed Jul 20, 2014
1 parent 0705625 commit 4052bcc
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 0 deletions.
35 changes: 35 additions & 0 deletions gluon/gluon-wan-dnsmasq/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=gluon-wan-dnsmasq
PKG_VERSION:=1

PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

include $(INCLUDE_DIR)/package.mk

define Package/gluon-wan-dnsmasq
SECTION:=gluon
CATEGORY:=Gluon
TITLE:=Support for a secondary DNS server using the WAN interface
DEPENDS:=+gluon-core +dnsmasq
endef

define Package/gluon-wan-dnsmasq/description
Gluon community wifi mesh firmware framework: Support for a secondary DNS server using the WAN interface
endef

define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
endef

define Build/Configure
endef

define Build/Compile
endef

define Package/gluon-wan-dnsmasq/install
$(CP) ./files/* $(1)/
endef

$(eval $(call BuildPackage,gluon-wan-dnsmasq))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if [ "$INTERFACE" = 'wan' -o "$INTERFACE" = 'wan6' ]; then
/lib/gluon/wan-dnsmasq/update.lua
fi
26 changes: 26 additions & 0 deletions gluon/gluon-wan-dnsmasq/files/etc/init.d/gluon-wan-dnsmasq
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh /etc/rc.common

START=60

SERVICE_NAME=gluon-wan-dnsmasq
SERVICE_USE_PID=1
SERVICE_PID_FILE=/var/run/gluon-wan-dnsmasq.pid


PORT=54
PACKET_MARK=1

RESOLV_CONF_DIR=/var/gluon/wan-dnsmasq
RESOLV_CONF=$RESOLV_CONF_DIR/resolv.conf


start() {
mkdir -p $RESOLV_CONF_DIR
touch $RESOLV_CONF

service_start /usr/sbin/dnsmasq -x $SERVICE_PID_FILE -u root -i lo -p $PORT --packet-mark=$PACKET_MARK -h -r $RESOLV_CONF
}

stop() {
service_stop /usr/sbin/dnsmasq
}
25 changes: 25 additions & 0 deletions gluon/gluon-wan-dnsmasq/files/lib/gluon/wan-dnsmasq/update.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/lua

local RESOLV_CONF_DIR = '/var/gluon/wan-dnsmasq'
local RESOLV_CONF = RESOLV_CONF_DIR .. '/resolv.conf'


local ubus = require('ubus').connect()
local fs = require 'nixio.fs'


local function write_servers(f, iface)
local servers = ubus:call('network.interface.' .. iface, 'status', {}).inactive['dns-server']
for _, server in ipairs(servers) do
f:write('nameserver ', server, '\n')
end
end


fs.mkdirr(RESOLV_CONF_DIR)
local f = io.open(RESOLV_CONF, 'w+')

pcall(write_servers, f, 'wan6')
pcall(write_servers, f, 'wan')

f:close()

0 comments on commit 4052bcc

Please sign in to comment.