From 03631ced8ee39a7278cad1cb4c7abef6325ca1f0 Mon Sep 17 00:00:00 2001 From: "honwen.chan" Date: Mon, 23 Nov 2020 01:32:29 +0800 Subject: [PATCH] add OpenWRT Makefile --- README.md | 1 + openwrt/Makefile | 71 +++++++++++++++++++++++++++++++++++++ openwrt/README.md | 13 +++++++ openwrt/files/dnsproxy.conf | 17 +++++++++ openwrt/files/dnsproxy.init | 49 +++++++++++++++++++++++++ 5 files changed, 151 insertions(+) create mode 100755 openwrt/Makefile create mode 100644 openwrt/README.md create mode 100644 openwrt/files/dnsproxy.conf create mode 100755 openwrt/files/dnsproxy.init diff --git a/README.md b/README.md index bc840f083..ee8ae05cd 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ A simple DNS proxy server that supports all existing DNS protocols including `DN > Note that `DNS-over-QUIC` support is experimental, don't use it in production. - [How to build](#how-to-build) + - [OpenWRT](openwrt/README.md) - [Usage](#usage) - [Examples](#examples) - [Simple options](#simple-options) diff --git a/openwrt/Makefile b/openwrt/Makefile new file mode 100755 index 000000000..8659cb4d8 --- /dev/null +++ b/openwrt/Makefile @@ -0,0 +1,71 @@ + +# +# Copyright (C) 2020 honwen (honwen.chan@gmail.com) +# +# This is free software, licensed under the GNU General Public License v3. +# See /LICENSE for more information. +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=dnsproxy +PKG_VERSION:=2020-11-10 +PKG_RELEASE:=0.33.2 +PKG_MAINTAINER:=honwen (honwen.chan@gmail.com) + +# OpenWrt ARCH: arm, aarch64, i386, x86_64, mips, mipsel +# Golang ARCH: arm6, arm64, 386, amd64, mips, mipsle +PKG_ARCH:=$(ARCH) +ifeq ($(ARCH),mipsel) + PKG_ARCH:=mipsle +endif +ifeq ($(ARCH),i386) + PKG_ARCH:=386 +endif +ifeq ($(ARCH),x86_64) + PKG_ARCH:=amd64 +endif +ifeq ($(ARCH),arm) + PKG_ARCH:=arm6 +endif +ifeq ($(ARCH),aarch64) + PKG_ARCH:=arm64 +endif + +PKG_SOURCE:=dnsproxy-linux-$(PKG_ARCH)-v$(PKG_RELEASE).tar.gz +PKG_SOURCE_URL:=https://github.com/AdguardTeam/dnsproxy/releases/download/v$(PKG_RELEASE)/ +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_RELEASE) +PKG_HASH:=skip + +include $(INCLUDE_DIR)/package.mk + +define Package/dnsproxy + SECTION:=net + CATEGORY:=Network + TITLE:=A simple DNS proxy server of AdguardTeam. + URL:=https://github.com/AdguardTeam/dnsproxy + DEPENDS:=+ca-bundle +endef + +define Package/dnsproxy/description + A simple DNS proxy server that supports all existing DNS protocols. +endef + +define Build/Prepare + gzip -dc "$(DL_DIR)/$(PKG_SOURCE)" | tar -C $(PKG_BUILD_DIR)/ -xf - +endef + +define Build/Compile + echo "$(PKG_NAME) Compile Skiped!" +endef + +define Package/dnsproxy/install + $(INSTALL_DIR) $(1)/etc/config + $(INSTALL_DATA) ./files/dnsproxy.conf $(1)/etc/config/dnsproxy + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/dnsproxy.init $(1)/etc/init.d/dnsproxy + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/linux-$(PKG_ARCH)/dnsproxy $(1)/usr/bin/dnsproxy +endef + +$(eval $(call BuildPackage,dnsproxy)) diff --git a/openwrt/README.md b/openwrt/README.md new file mode 100644 index 000000000..50f4dae5c --- /dev/null +++ b/openwrt/README.md @@ -0,0 +1,13 @@ +# Intro + +Makefile of [AdguardTeam-dnsproxy](https://github.com/AdguardTeam/dnsproxy) for [OpenWRT](https://openwrt.org/) + +# Compile + +Further Document: [OpenWRT-SDK](https://openwrt.org/docs/guide-developer/using_the_sdk#compile_packages) + +# Config + +- Defaule Port: `5300` + +- Further Config: `/etc/config/dnsproxy` diff --git a/openwrt/files/dnsproxy.conf b/openwrt/files/dnsproxy.conf new file mode 100644 index 000000000..8fd15fe06 --- /dev/null +++ b/openwrt/files/dnsproxy.conf @@ -0,0 +1,17 @@ + +config dnsproxy + option enable 1 + option port 5300 + option args '--cache --all-servers' + list upstream 'https://dns.adguard.com/dns-query' + list upstream 'tls://dns.adguard.com' + list fallback 'tcp://94.140.15.15' + list bootstrap '94.140.14.14' + + # list upstream 'tls://162.159.36.1' + # list upstream 'tls://185.222.222.222' + # list upstream 'tls://149.112.112.112' + # list upstream 'sdns://AgMAAAAAAAAADDQ1Ljc3LjE4MC4xMCBsA2QQ3lR1Nl9Ygfr8FdBIpL-doxmHECRx3T5NIXYYtxNkbnMuY29udGFpbmVycGkuY29tCi9kbnMtcXVlcnk' + # list upstream 'sdns://AgMAAAAAAAAADzE3Ni4xMDMuMTMwLjEzMCD5_zfwLmMstzhwJcB-V5CKPTcbfJXYzdA5DeIx7ZQ6Eg9kbnMuYWRndWFyZC5jb20KL2Rucy1xdWVyeQ' + # list fallback 'tls://8.8.8.8' + # list bootstrap 'tcp://8.8.4.4' diff --git a/openwrt/files/dnsproxy.init b/openwrt/files/dnsproxy.init new file mode 100755 index 000000000..22dff37be --- /dev/null +++ b/openwrt/files/dnsproxy.init @@ -0,0 +1,49 @@ +#!/bin/sh /etc/rc.common +# +# Copyright (C) 2020 honwen (honwen.chan@gmail.com) +# +# This is free software, licensed under the GNU General Public License v3. +# See /LICENSE for more information. +# + +START=90 +STOP=15 + +NAME=dnsproxy +USE_PROCD=1 + +uci_get_by_type() { + local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null) + echo ${ret:=$3} +} + +uci_bool_by_type() { + case "$(uci_get_by_type $1 $2)" in + 1|on|true|yes|enabled) return 0;; + esac + return 1 +} + +start_instance() { + procd_open_instance + procd_set_param respawn + procd_set_param stderr 1 + procd_set_param command $@ + procd_close_instance +} + +service_triggers() { + procd_add_reload_trigger $NAME +} + +start_service() { + uci_bool_by_type $NAME enable || exit 0 + + local port=$(uci_get_by_type $NAME port 5300) + local args=$(uci_get_by_type $NAME args) + local upstream=$(for it in $(uci_get_by_type $NAME upstream); do echo -n "-u $it "; done) + local fallback=$(for it in $(uci_get_by_type $NAME fallback); do echo -n "-f $it "; done) + local bootstrap=$(for it in $(uci_get_by_type $NAME bootstrap); do echo -n "-b $it "; done) + + start_instance /usr/bin/$NAME -p ${port} ${args} ${upstream} ${fallback} ${bootstrap} +}