Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add OpenWRT Makefile #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
71 changes: 71 additions & 0 deletions openwrt/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

#
# Copyright (C) 2020 honwen ([email protected])
#
# 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 ([email protected])

# 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))
13 changes: 13 additions & 0 deletions openwrt/README.md
Original file line number Diff line number Diff line change
@@ -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`
17 changes: 17 additions & 0 deletions openwrt/files/dnsproxy.conf
Original file line number Diff line number Diff line change
@@ -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'
49 changes: 49 additions & 0 deletions openwrt/files/dnsproxy.init
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh /etc/rc.common
#
# Copyright (C) 2020 honwen ([email protected])
#
# 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}
}