Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc93156ee3 | ||
|
|
8433729186 | ||
|
|
4464bb982e | ||
|
|
371aab6d4b | ||
|
|
01e4140722 | ||
|
|
2b08ffee98 | ||
|
|
9f27bb9b70 | ||
|
|
528d5c6ccc | ||
|
|
6bf6315a6d | ||
|
|
aaca1c013b | ||
|
|
25c6cab4a8 | ||
|
|
408c199564 | ||
|
|
044536aef6 | ||
|
|
1fb5cbbcd9 | ||
|
|
4e0cbc50b3 |
33
ReadMe.md
33
ReadMe.md
@@ -23,7 +23,6 @@ SmartDNS是一个运行在本地的DNS服务器,SmartDNS接受本地客户端
|
||||
1. [Windows 10 WSL安装/WSL ubuntu](#windows-10-wsl安装wsl-ubuntu)
|
||||
1. [配置参数](#配置参数)
|
||||
1. [捐助](#donate)
|
||||
1. [声明](#声明)
|
||||
1. [FAQ](#faq)
|
||||
|
||||
## 软件效果展示
|
||||
@@ -595,6 +594,7 @@ https://github.com/pymumu/smartdns/releases
|
||||
* 高速缓存机制,使访问更快速。
|
||||
* 异步日志,审计机制,在记录信息的同时不影响DNS查询性能。
|
||||
* 域名组(group)机制,特定域名使用特定上游服务器组查询,避免隐私泄漏。
|
||||
* 第二DNS支持自定义更多行为。
|
||||
|
||||
1. 如何配置上游服务器最佳。
|
||||
smartdns有测速机制,在配置上游服务器时,建议配置多个上游DNS服务器,包含多个不同区域的服务器,但总数建议在10个左右。推荐配置
|
||||
@@ -648,7 +648,12 @@ https://github.com/pymumu/smartdns/releases
|
||||
nameserver /.office/office
|
||||
```
|
||||
|
||||
通过上述配置即可实现DNS解析分流
|
||||
通过上述配置即可实现DNS解析分流,如果需要实现按请求端端口分流,可以配置第二DNS服务器,bind配置增加--group参数指定分流名称。
|
||||
|
||||
```sh
|
||||
bind :7053 -group office
|
||||
bind :8053 -group home
|
||||
```
|
||||
|
||||
1. IPV4, IPV6双栈IP优选功能如何使用
|
||||
目前IPV6已经开始普及,但IPV6网络在速度上,某些情况下还不如IPV4,为在双栈网络下获得较好的体验,smartdns提供来双栈IP优选机制,同一个域名,若IPV4的速度远快与IPV6,那么smartdns就会阻止IPV6的解析,让PC使用IPV4访问,具体配置文件通过`dualstack-ip-selection yes`启用此功能,通过`dualstack-ip-selection-threshold [time]`来修改阈值。如果要完全禁止IPV6 AAAA记录解析,可设置`force-AAAA-SOA yes`。
|
||||
@@ -667,6 +672,18 @@ https://github.com/pymumu/smartdns/releases
|
||||
通过`prefetch-domain yes`来启用域名预先获取功能,提高查询命中率。
|
||||
配合上述ttl超时时间,smartdns将在域名ttl即将超时使,再次发送查询请求,并缓存查询结果供后续使用。频繁访问的域名将会持续缓存。此功能将在空闲时消耗更多的CPU。
|
||||
|
||||
1. 第二DNS如何自定义更多行为
|
||||
第二DNS可以作为其他DNS服务器的上游,提供更多的查询行为,通过bind配置支持可以绑定多个端口,不同端口可设置不同的标志,实现不同的功能,如
|
||||
|
||||
```sh
|
||||
# 绑定 6053端口,6053端口的请求将采用配置office组的上游查询,且不对结果进行测速,忽略address的配置地址。
|
||||
bind [::]:6053 -no-speed-check -group office -no-rule-addr
|
||||
```
|
||||
|
||||
## 编译
|
||||
|
||||
smartdns包含了编译软件包的脚本,支持编译luci,debian,openwrt,optare安装包,可执行`package/build-pkg.sh`编译。
|
||||
|
||||
## Donate
|
||||
|
||||
如果你觉得此项目对你有帮助,请捐助我们,以使项目能持续发展,更加完善。
|
||||
@@ -683,14 +700,6 @@ https://github.com/pymumu/smartdns/releases
|
||||
|
||||

|
||||
|
||||
## 声明
|
||||
## 开源声明
|
||||
|
||||
* `SmartDNS`著作权归属Nick Peng (pymumu at gmail.com)。
|
||||
* `SmartDNS`为免费软件,用户可以非商业性地复制和使用`SmartDNS`。
|
||||
* 禁止将 `SmartDNS` 用于商业用途。
|
||||
* 使用本软件的风险由用户自行承担,在适用法律允许的最大范围内,对因使用本产品所产生的损害及风险,包括但不限于直接或间接的个人损害、商业赢利的丧失、贸易中断、商业信息的丢失或任何其它经济损失,不承担任何责任。
|
||||
* 本软件不会未经用户同意收集任何用户信息。
|
||||
|
||||
## 说明
|
||||
|
||||
目前代码未开源,后续根据情况开源。
|
||||
Smartdns 基于GPL V3协议开源。
|
||||
|
||||
33
ReadMe_en.md
33
ReadMe_en.md
@@ -21,7 +21,6 @@ Support Raspberry Pi, openwrt, ASUS router, Windows and other devices.
|
||||
1. [Windows 10 WSL Installation/WSL ubuntu](#windows-10-wsl-installation/wsl-ubuntu)
|
||||
1. [Configuration parameter](#configuration-parameter)
|
||||
1. [Donate](#Donate)
|
||||
1. [Statement](#Statement)
|
||||
1. [FAQ](#FAQ)
|
||||
|
||||
## Software Show
|
||||
@@ -591,6 +590,7 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
|
||||
* Cache mechanism to make access faster.
|
||||
* Asynchronous log, audit log mechanism, does not affect DNS query performance while recording information.
|
||||
* Domain group mechanism, specific domain names use specific upstream server group queries to avoid privacy leakage.
|
||||
* The second DNS supports customizing more behavior.
|
||||
|
||||
1. What is the best practices for upstream server configuration?
|
||||
Smartdns has a speed measurement mechanism. When configuring an upstream server, it is recommended to configure multiple upstream DNS servers, including servers in different regions, but the total number is recommended to be around 10. Recommended configuration
|
||||
@@ -645,6 +645,13 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
|
||||
Nameserver /.office/office
|
||||
```
|
||||
|
||||
You can use the above configuration to implement DNS resolution and offload. If you need to implement traffic distribution on the requesting port, you can configure the second DNS server. The bind configuration is added. The group parameter specifies the traffic distribution name.
|
||||
|
||||
```sh
|
||||
Bind :7053 -group office
|
||||
Bind :8053 -group home
|
||||
```
|
||||
|
||||
1. How to use the IPV4, IPV6 dual stack IP optimization feature
|
||||
At present, IPV6 network is not as fast as IPV4 in some cases. In order to get a better experience in the dual-stack network, SmartDNS provides a dual-stack IP optimization mechanism, the same domain name, and the speed of IPV4. Far faster than IPV6, then SmartDNS will block the resolution of IPV6, let the PC use IPV4, the feature is enabled by `dualstack-ip-selection yes`, `dualstack-ip-selection-threshold [time]` is for threshold. if you want to disable IPV6 AAAA record complete, please try `force-AAAA-SOA yes`.
|
||||
|
||||
@@ -662,6 +669,18 @@ Note: Merlin firmware is derived from ASUS firmware and can theoretically be use
|
||||
Enable pre-fetching of domain names with `prefetch-domain yes` to improve query hit rate.
|
||||
by default, Smartdns will send domain query request again before cache expire, and cache the result for the next query. Frequently accessed domain names will continue to be cached. This feature will consume more CPU when idle.
|
||||
|
||||
1. How does the second DNS customize more behavior?
|
||||
The second DNS can be used as the upstream of other DNS servers to provide more query behaviors. Bind configuration support can bind multiple ports. Different ports can be set with different flags to implement different functions, such as
|
||||
|
||||
```sh
|
||||
# Binding 6053 port, request for port 6053 will be configured with the upstream query of the office group, and the result will not be measured. The address configuration address is ignored.
|
||||
bind [::]:6053 -no-speed-check -group office -no-rule-addr
|
||||
```
|
||||
|
||||
## Compile
|
||||
|
||||
smartdns contains scripts for compiling packages, supports compiling luci, debian, openwrt, opare installation packages, and can execute `package/build-pkg.sh` compilation.
|
||||
|
||||
## [Donate](#Donate)
|
||||
|
||||
If you feel that this project is helpful to you, please donate to us so that the project can continue to develop and be more perfect.
|
||||
@@ -678,14 +697,6 @@ If you feel that this project is helpful to you, please donate to us so that the
|
||||
|
||||

|
||||
|
||||
## Statement
|
||||
## Open Source License
|
||||
|
||||
* `SmartDNS` copyright belongs to Nick Peng (pymumu at gmail.com).
|
||||
* `SmartDNS` is free software, users can copy and use `SmartDNS` non-commercially.
|
||||
* It is forbidden to use `SmartDNS` for commercial purposes.
|
||||
* The use of the software is at the user's own risk and, to the fullest extent permitted by applicable law, damages and risks resulting from the use of this product, including but not limited to direct or indirect personal damage, loss of commercial profit, trade disruption No loss of business information or any other financial loss.
|
||||
* This software does not collect any user information without the user's consent.
|
||||
|
||||
## Additional information
|
||||
|
||||
Currently the code is not open source, and subsequent open source according to the situation.
|
||||
Smartdns is licensed to the public under the GPL V3 License.
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
### BEGIN INIT INFO
|
||||
# Provides: smartdns
|
||||
|
||||
18
install
18
install
@@ -1,7 +1,19 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018 Ruilin Peng (Nick) <pymumu@gmail.com>
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
INST_DIR=$(cd $(dirname $0);pwd)
|
||||
ISWSL=1 # 1 means not WSL, 0 means wsl
|
||||
@@ -82,7 +94,9 @@ install_files()
|
||||
|
||||
install -v -m 0755 -t $SMARTDNS_INIT_DIR etc/init.d/smartdns
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
if [ $ISSYSTEMD -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $ISSYSTEMD -eq 0 ]; then
|
||||
|
||||
180
package/build-pkg.sh
Normal file
180
package/build-pkg.sh
Normal file
@@ -0,0 +1,180 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2018-2019 Nick Peng (pymumu@gmail.com)
|
||||
|
||||
CURR_DIR=$(cd $(dirname $0);pwd)
|
||||
VER="`date +"1.%Y.%m.%d-%H%M"`"
|
||||
CODE_DIR="$CURR_DIR/.."
|
||||
IS_BUILD_SMARTDNS=1
|
||||
OUTPUTDIR=$CURR_DIR
|
||||
export CC
|
||||
export STRIP
|
||||
|
||||
showhelp()
|
||||
{
|
||||
echo "Usage: $0 [OPTION]"
|
||||
echo "Options:"
|
||||
echo " --platform [luci|debian|openwrt|optware|linux] build for platform. "
|
||||
echo " --arch [all|armhf|arm64|x86_64|...] build for architecture, e.g. "
|
||||
echo " --cross-tool [cross-tool] cross compiler, e.g. mips-openwrt-linux-"
|
||||
echo ""
|
||||
echo "Advance Options:"
|
||||
echo " --static static link smartdns"
|
||||
echo " --only-package only package, not build source"
|
||||
echo " --filearch [arch] output file arch, default: equal --arch"
|
||||
echo " --outputdir [dir] output package to specific directory"
|
||||
echo " "
|
||||
echo "Example:"
|
||||
echo " build luci:"
|
||||
echo " $0 --platform luci"
|
||||
echo " build debian:"
|
||||
echo " $0 --platform debian --arch x86_64"
|
||||
echo " build raspbian pi:"
|
||||
echo " $0 --platform debian --arch armhf"
|
||||
echo " build optware mips:"
|
||||
echo " $0 --platform optware --arch mipsbig"
|
||||
echo " build openwrt mips:"
|
||||
echo " $0 --platform openwrt --arch mips_24kc"
|
||||
echo " build generic linux:"
|
||||
echo " $0 --platform linux --arch x86_64"
|
||||
}
|
||||
|
||||
build_smartdns()
|
||||
{
|
||||
if [ "$PLATFORM" != "luci" ]; then
|
||||
make -C $CODE_DIR/src clean
|
||||
make -C $CODE_DIR/src all -j8 VER=$VER $MAKE_ARGS
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "make smartdns failed"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
$STRIP -d $CODE_DIR/src/smartdns >/dev/null 2>&1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
build()
|
||||
{
|
||||
echo "build package for $PLATFORM"
|
||||
|
||||
if [ $IS_BUILD_SMARTDNS -eq 1 ]; then
|
||||
build_smartdns
|
||||
if [ $? -ne 0 ]; then
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
chmod +x $CODE_DIR/package/$PLATFORM/make.sh
|
||||
$CODE_DIR/package/$PLATFORM/make.sh -o $CURR_DIR --arch $ARCH --ver $VER --filearch $FILEARCH -o $OUTPUTDIR
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "build package for $PLATFORM failed"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "build package for $PLATFORM success."
|
||||
return 0
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
OPTS=`getopt -o o:h --long arch:,filearch:,ver:,platform:,cross-tool:,static,only-package,outputdir: \
|
||||
-n "" -- "$@"`
|
||||
|
||||
if [ "$#" -le "1" ]; then
|
||||
showhelp
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
|
||||
|
||||
# Note the quotes around `$TEMP': they are essential!
|
||||
eval set -- "$OPTS"
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
--arch)
|
||||
ARCH="$2"
|
||||
shift 2;;
|
||||
--filearch)
|
||||
FILEARCH="$2"
|
||||
shift 2;;
|
||||
--platform)
|
||||
PLATFORM="$2"
|
||||
shift 2;;
|
||||
--cross-tool)
|
||||
CROSS_TOOL="$2"
|
||||
shift 2;;
|
||||
--static)
|
||||
export STATIC="yes"
|
||||
shift 1;;
|
||||
--only-package)
|
||||
IS_BUILD_SMARTDNS=0
|
||||
shift 1;;
|
||||
--outputdir)
|
||||
OUTPUTDIR="$2"
|
||||
shift 2;;
|
||||
--ver)
|
||||
VER="$2"
|
||||
shift 2;;
|
||||
-h | --help )
|
||||
showhelp
|
||||
return 0
|
||||
shift ;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$PLATFORM" ]; then
|
||||
echo "please input platform"
|
||||
echo "run $0 -h for help."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$PLATFORM" = "luci" ]; then
|
||||
ARCH="all"
|
||||
fi
|
||||
|
||||
if [ -z "$ARCH" ]; then
|
||||
echo "please input arch."
|
||||
echo "run $0 -h for help."
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ -z "$FILEARCH" ]; then
|
||||
FILEARCH="$ARCH"
|
||||
fi
|
||||
|
||||
if [ -z "$OUTPUTDIR" ]; then
|
||||
OUTPUTDIR=$CURR_DIR
|
||||
fi
|
||||
|
||||
if [ ! -z "$CROSS_TOOL" ]; then
|
||||
CC="${CROSS_TOOL}gcc"
|
||||
STRIP="${CROSS_TOOL}strip"
|
||||
fi
|
||||
|
||||
if [ -z "$CC" ]; then
|
||||
CC="gcc"
|
||||
fi
|
||||
|
||||
if [ -z "$STRIP" ]; then
|
||||
if [ ! -z "`echo $CC | grep '\-gcc'`" ]; then
|
||||
STRIP="`echo "$CC" | sed 's/-gcc\$/-strip/g'`"
|
||||
else
|
||||
STRIP="strip"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -e "`which $CC`" ]; then
|
||||
echo "Cannot find compiler $CC"
|
||||
return 1
|
||||
fi
|
||||
|
||||
build
|
||||
}
|
||||
|
||||
main $@
|
||||
exit $?
|
||||
@@ -3,5 +3,5 @@ Upstream-Name: smartdns
|
||||
Source: http://github.com/pymumu/smartdns
|
||||
|
||||
Files: *
|
||||
Copyright: 2018 Nick peng
|
||||
Copyright: 2018-2019 Nick peng
|
||||
License: proprietary
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
#/bin/sh
|
||||
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
CURR_DIR=$(cd $(dirname $0);pwd)
|
||||
VER="`date +"1.%Y.%m.%d-%H%M"`"
|
||||
SMARTDNS_DIR=$CURR_DIR/../../
|
||||
@@ -11,37 +25,41 @@ showhelp()
|
||||
echo "Options:"
|
||||
echo " -o output directory."
|
||||
echo " --arch archtecture."
|
||||
echo " --ver version."
|
||||
echo " --ver version."
|
||||
echo " -h show this message."
|
||||
}
|
||||
|
||||
build()
|
||||
{
|
||||
ROOT=/tmp/smartdns-deiban
|
||||
rm -fr $ROOT
|
||||
mkdir -p $ROOT
|
||||
cd $ROOT/
|
||||
ROOT=/tmp/smartdns-deiban
|
||||
rm -fr $ROOT
|
||||
mkdir -p $ROOT
|
||||
cd $ROOT/
|
||||
|
||||
cp $CURR_DIR/DEBIAN $ROOT/ -af
|
||||
CONTROL=$ROOT/DEBIAN/control
|
||||
mkdir $ROOT/usr/sbin -p
|
||||
mkdir $ROOT/etc/smartdns/ -p
|
||||
mkdir $ROOT/etc/default/ -p
|
||||
mkdir $ROOT/lib/systemd/system/ -p
|
||||
cp $CURR_DIR/DEBIAN $ROOT/ -af
|
||||
CONTROL=$ROOT/DEBIAN/control
|
||||
mkdir $ROOT/usr/sbin -p
|
||||
mkdir $ROOT/etc/smartdns/ -p
|
||||
mkdir $ROOT/etc/default/ -p
|
||||
mkdir $ROOT/lib/systemd/system/ -p
|
||||
|
||||
sed -i "s/Version:.*/Version: $VER/" $ROOT/DEBIAN/control
|
||||
sed -i "s/Architecture:.*/Architecture: $ARCH/" $ROOT/DEBIAN/control
|
||||
chmod 0755 $ROOT/DEBIAN/prerm
|
||||
sed -i "s/Version:.*/Version: $VER/" $ROOT/DEBIAN/control
|
||||
sed -i "s/Architecture:.*/Architecture: $ARCH/" $ROOT/DEBIAN/control
|
||||
chmod 0755 $ROOT/DEBIAN/prerm
|
||||
|
||||
cp $SMARTDNS_DIR/etc/smartdns/smartdns.conf $ROOT/etc/smartdns/
|
||||
cp $SMARTDNS_DIR/etc/default/smartdns $ROOT/etc/default/
|
||||
cp $SMARTDNS_DIR/systemd/smartdns.service $ROOT/lib/systemd/system/
|
||||
cp $SMARTDNS_DIR/src/smartdns $ROOT/usr/sbin
|
||||
chmod +x $ROOT/usr/sbin/smartdns
|
||||
cp $SMARTDNS_DIR/etc/smartdns/smartdns.conf $ROOT/etc/smartdns/
|
||||
cp $SMARTDNS_DIR/etc/default/smartdns $ROOT/etc/default/
|
||||
cp $SMARTDNS_DIR/systemd/smartdns.service $ROOT/lib/systemd/system/
|
||||
cp $SMARTDNS_DIR/src/smartdns $ROOT/usr/sbin
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "copy smartdns file failed."
|
||||
return 1
|
||||
fi
|
||||
chmod +x $ROOT/usr/sbin/smartdns
|
||||
|
||||
dpkg -b $ROOT $OUTPUTDIR/smartdns.$VER.$FILEARCH.deb
|
||||
dpkg -b $ROOT $OUTPUTDIR/smartdns.$VER.$FILEARCH.deb
|
||||
|
||||
rm -fr $ROOT/
|
||||
rm -fr $ROOT/
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -59,38 +77,38 @@ main()
|
||||
--arch)
|
||||
ARCH="$2"
|
||||
shift 2;;
|
||||
--filearch)
|
||||
FILEARCH="$2"
|
||||
shift 2;;
|
||||
--ver)
|
||||
VER="$2"
|
||||
shift 2;;
|
||||
--filearch)
|
||||
FILEARCH="$2"
|
||||
shift 2;;
|
||||
--ver)
|
||||
VER="$2"
|
||||
shift 2;;
|
||||
-o )
|
||||
OUTPUTDIR="$2"
|
||||
shift 2;;
|
||||
-h | --help )
|
||||
-h | --help )
|
||||
showhelp
|
||||
return 0
|
||||
shift ;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$ARCH" ]; then
|
||||
echo "please input arch."
|
||||
return 1;
|
||||
fi
|
||||
if [ -z "$ARCH" ]; then
|
||||
echo "please input arch."
|
||||
return 1;
|
||||
fi
|
||||
|
||||
if [ -z "$FILEARCH" ]; then
|
||||
FILEARCH=$ARCH
|
||||
fi
|
||||
if [ -z "$FILEARCH" ]; then
|
||||
FILEARCH=$ARCH
|
||||
fi
|
||||
|
||||
if [ -z "$OUTPUTDIR" ]; then
|
||||
OUTPUTDIR=$CURR_DIR;
|
||||
fi
|
||||
if [ -z "$OUTPUTDIR" ]; then
|
||||
OUTPUTDIR=$CURR_DIR;
|
||||
fi
|
||||
|
||||
build
|
||||
build
|
||||
}
|
||||
|
||||
main $@
|
||||
|
||||
98
package/linux/make.sh
Normal file
98
package/linux/make.sh
Normal file
@@ -0,0 +1,98 @@
|
||||
#!/bin/sh
|
||||
|
||||
CURR_DIR=$(cd $(dirname $0);pwd)
|
||||
VER="`date +"1.%Y.%m.%d-%H%M"`"
|
||||
SMARTDNS_DIR=$CURR_DIR/../../
|
||||
SMARTDNS_BIN=$SMARTDNS_DIR/src/smartdns
|
||||
|
||||
showhelp()
|
||||
{
|
||||
echo "Usage: make [OPTION]"
|
||||
echo "Options:"
|
||||
echo " -o output directory."
|
||||
echo " --arch archtecture."
|
||||
echo " --ver version."
|
||||
echo " -h show this message."
|
||||
}
|
||||
|
||||
build()
|
||||
{
|
||||
PKG_ROOT=/tmp/smartdns-linux
|
||||
rm -fr $PKG_ROOT
|
||||
mkdir -p $PKG_ROOT/smartdns
|
||||
cd $PKG_ROOT/
|
||||
|
||||
# Generic x86_64
|
||||
mkdir $PKG_ROOT/smartdns/src -p
|
||||
mkdir $PKG_ROOT/smartdns/package -p
|
||||
cd $SMARTDNS_DIR
|
||||
cp package/windows $PKG_ROOT/smartdns/package/ -a
|
||||
cp etc systemd *.md LICENSE install $PKG_ROOT/smartdns/ -a
|
||||
cp src/smartdns $PKG_ROOT/smartdns/src -a
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "copy smartdns file failed"
|
||||
rm -fr $PKG_ROOT
|
||||
exit 1
|
||||
fi
|
||||
cd $PKG_ROOT
|
||||
tar zcf $OUTPUTDIR/smartdns.$VER.$FILEARCH.tar.gz smartdns
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "create package failed"
|
||||
rm -fr $PKG_ROOT
|
||||
exit 1
|
||||
fi
|
||||
cd $CURR_DIR
|
||||
rm -fr $PKG_ROOT
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
OPTS=`getopt -o o:h --long arch:,ver:,filearch: \
|
||||
-n "" -- "$@"`
|
||||
|
||||
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
|
||||
|
||||
# Note the quotes around `$TEMP': they are essential!
|
||||
eval set -- "$OPTS"
|
||||
|
||||
while true; do
|
||||
case "$1" in
|
||||
--arch)
|
||||
ARCH="$2"
|
||||
shift 2;;
|
||||
--filearch)
|
||||
FILEARCH="$2"
|
||||
shift 2;;
|
||||
--ver)
|
||||
VER="$2"
|
||||
shift 2;;
|
||||
-o )
|
||||
OUTPUTDIR="$2"
|
||||
shift 2;;
|
||||
-h | --help )
|
||||
showhelp
|
||||
return 0
|
||||
shift ;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$ARCH" ]; then
|
||||
echo "please input arch."
|
||||
return 1;
|
||||
fi
|
||||
|
||||
if [ -z "$FILEARCH" ]; then
|
||||
FILEARCH=$ARCH
|
||||
fi
|
||||
|
||||
if [ -z "$OUTPUTDIR" ]; then
|
||||
OUTPUTDIR=$CURR_DIR;
|
||||
fi
|
||||
|
||||
build
|
||||
}
|
||||
|
||||
main $@
|
||||
exit $?
|
||||
@@ -1,4 +1,20 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
|
||||
[ -x ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0
|
||||
. ${IPKG_INSTROOT}/lib/functions.sh
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
[ -x ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0
|
||||
. ${IPKG_INSTROOT}/lib/functions.sh
|
||||
default_prerm $0 $@
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
delete ucitrack.@smartdns[-1]
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
-- Copyright 2018 Nick Peng (pymumu@gmail.com)
|
||||
--
|
||||
-- Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
--
|
||||
-- smartdns is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- smartdns is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
module("luci.controller.smartdns", package.seeall)
|
||||
local smartdns = require "luci.model.smartdns"
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
-- Copyright 2018 Nick Peng (pymumu@gmail.com)
|
||||
--
|
||||
-- Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
--
|
||||
-- smartdns is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- smartdns is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require ("nixio.fs")
|
||||
require ("luci.http")
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
--
|
||||
-- Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
--
|
||||
-- smartdns is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- smartdns is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
local sid = arg[1]
|
||||
|
||||
m = Map("smartdns", "%s - %s" %{translate("SmartDNS Server"), translate("Upstream DNS Server Configuration")})
|
||||
|
||||
@@ -1,4 +1,18 @@
|
||||
-- Copyright 2018 Nick Peng (pymumu@gmail.com)
|
||||
--
|
||||
-- Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
--
|
||||
-- smartdns is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU General Public License as published by
|
||||
-- the Free Software Foundation, either version 3 of the License, or
|
||||
-- (at your option) any later version.
|
||||
--
|
||||
-- smartdns is distributed in the hope that it will be useful,
|
||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
-- GNU General Public License for more details.
|
||||
--
|
||||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
require ("nixio.fs")
|
||||
require ("luci.http")
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
#/bin/sh
|
||||
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
CURR_DIR=$(cd $(dirname $0);pwd)
|
||||
|
||||
VER="`date +"1.%Y.%m.%d-%H%M"`"
|
||||
@@ -12,58 +26,58 @@ showhelp()
|
||||
echo "Options:"
|
||||
echo " -o output directory."
|
||||
echo " --arch archtecture."
|
||||
echo " --ver version."
|
||||
echo " --ver version."
|
||||
echo " -h show this message."
|
||||
}
|
||||
|
||||
build_tool()
|
||||
{
|
||||
make -C $ROOT/tool/po2lmo -j
|
||||
PO2LMO="$ROOT/tool/po2lmo/src/po2lmo"
|
||||
make -C $ROOT/tool/po2lmo -j
|
||||
PO2LMO="$ROOT/tool/po2lmo/src/po2lmo"
|
||||
|
||||
}
|
||||
|
||||
clean_tool()
|
||||
{
|
||||
make -C $ROOT/tool/po2lmo clean
|
||||
make -C $ROOT/tool/po2lmo clean
|
||||
}
|
||||
|
||||
build()
|
||||
{
|
||||
|
||||
ROOT=/tmp/luci-app-smartdns
|
||||
rm -fr $ROOT
|
||||
ROOT=/tmp/luci-app-smartdns
|
||||
rm -fr $ROOT
|
||||
|
||||
mkdir -p $ROOT
|
||||
cp $CURR_DIR/* $ROOT/ -af
|
||||
cd $ROOT/
|
||||
build_tool
|
||||
mkdir $ROOT/root/usr/lib/lua/ -p
|
||||
cp $ROOT/files/luci $ROOT/root/usr/lib/lua/ -af
|
||||
|
||||
#Generate Language
|
||||
$PO2LMO $ROOT/files/luci/i18n/smartdns.zh-cn.po $ROOT/root/usr/lib/lua/luci/i18n/smartdns.zh-cn.lmo
|
||||
rm $ROOT/root/usr/lib/lua/luci/i18n/smartdns.zh-cn.po
|
||||
mkdir -p $ROOT
|
||||
cp $CURR_DIR/* $ROOT/ -af
|
||||
cd $ROOT/
|
||||
build_tool
|
||||
mkdir $ROOT/root/usr/lib/lua/ -p
|
||||
cp $ROOT/files/luci $ROOT/root/usr/lib/lua/ -af
|
||||
|
||||
#Generate Language
|
||||
$PO2LMO $ROOT/files/luci/i18n/smartdns.zh-cn.po $ROOT/root/usr/lib/lua/luci/i18n/smartdns.zh-cn.lmo
|
||||
rm $ROOT/root/usr/lib/lua/luci/i18n/smartdns.zh-cn.po
|
||||
|
||||
cp $ROOT/files/etc $ROOT/root/ -af
|
||||
INST_SIZE="`du -sb $ROOT/root/ | awk '{print $1}'`"
|
||||
|
||||
sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control
|
||||
sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
|
||||
cp $ROOT/files/etc $ROOT/root/ -af
|
||||
INST_SIZE="`du -sb $ROOT/root/ | awk '{print $1}'`"
|
||||
|
||||
sed -i "s/^Architecture.*/Architecture: all/g" $ROOT/control/control
|
||||
sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
|
||||
|
||||
if [ ! -z "$INST_SIZE" ]; then
|
||||
echo "Installed-Size: $INST_SIZE" >> $ROOT/control/control
|
||||
fi
|
||||
if [ ! -z "$INST_SIZE" ]; then
|
||||
echo "Installed-Size: $INST_SIZE" >> $ROOT/control/control
|
||||
fi
|
||||
|
||||
cd $ROOT/control
|
||||
chmod +x *
|
||||
tar zcf ../control.tar.gz ./
|
||||
cd $ROOT
|
||||
cd $ROOT/control
|
||||
chmod +x *
|
||||
tar zcf ../control.tar.gz ./
|
||||
cd $ROOT
|
||||
|
||||
tar zcf $ROOT/data.tar.gz -C root .
|
||||
tar zcf $OUTPUTDIR/luci-app-smartdns.$VER.$FILEARCH.ipk control.tar.gz data.tar.gz debian-binary
|
||||
tar zcf $ROOT/data.tar.gz -C root .
|
||||
tar zcf $OUTPUTDIR/luci-app-smartdns.$VER.$FILEARCH.ipk control.tar.gz data.tar.gz debian-binary
|
||||
|
||||
rm -fr $ROOT/
|
||||
rm -fr $ROOT/
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -81,38 +95,38 @@ main()
|
||||
--arch)
|
||||
ARCH="$2"
|
||||
shift 2;;
|
||||
--filearch)
|
||||
FILEARCH="$2"
|
||||
shift 2;;
|
||||
--ver)
|
||||
VER="$2"
|
||||
shift 2;;
|
||||
--filearch)
|
||||
FILEARCH="$2"
|
||||
shift 2;;
|
||||
--ver)
|
||||
VER="$2"
|
||||
shift 2;;
|
||||
-o )
|
||||
OUTPUTDIR="$2"
|
||||
shift 2;;
|
||||
-h | --help )
|
||||
-h | --help )
|
||||
showhelp
|
||||
return 0
|
||||
shift ;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$ARCH" ]; then
|
||||
echo "please input arch."
|
||||
return 1;
|
||||
fi
|
||||
if [ -z "$ARCH" ]; then
|
||||
echo "please input arch."
|
||||
return 1;
|
||||
fi
|
||||
|
||||
if [ -z "$FILEARCH" ]; then
|
||||
FILEARCH=$ARCH
|
||||
fi
|
||||
if [ -z "$FILEARCH" ]; then
|
||||
FILEARCH=$ARCH
|
||||
fi
|
||||
|
||||
if [ -z "$OUTPUTDIR" ]; then
|
||||
OUTPUTDIR=$CURR_DIR;
|
||||
fi
|
||||
if [ -z "$OUTPUTDIR" ]; then
|
||||
OUTPUTDIR=$CURR_DIR;
|
||||
fi
|
||||
|
||||
build
|
||||
build
|
||||
}
|
||||
|
||||
main $@
|
||||
|
||||
@@ -1,34 +1,75 @@
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=smarttdns
|
||||
PKG_VERSION:=2018.7.1.1607
|
||||
PKG_RELEASE:=$(PKG_SOURCE_VERSION)
|
||||
PKG_NAME:=smartdns
|
||||
|
||||
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_URL:=https://github.com/pymumu/smartdns.git
|
||||
|
||||
PKG_REV:=d51f5e6eeba7bfde1b108fe32d540bd429550573
|
||||
PKG_VERSION:=1.2019.11.02-1102
|
||||
PKG_RELEASE:=1
|
||||
PKG_LICENSE:=GPL-3.0
|
||||
|
||||
PKG_SOURCE_VERSION:=$(PKG_REV)
|
||||
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
|
||||
PKG_SOURCE:=$(PKG_SOURCE_SUBDIR).tar.gz
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_SOURCE_SUBDIR)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
MAKE_ARGS := CFLAGS="$(TARGET_CFLAGS)" CC=$(TARGET_CC)
|
||||
|
||||
define Package/smartdns
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
TITLE:=smartdns
|
||||
URL:=https://github.com/pymumu/smartdns
|
||||
MAINTAINER:=Nick Peng <pymumu@gmail.com>
|
||||
DEPENDS:=
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
TITLE:=smartdns server
|
||||
URL:=http://github.com/pymumu/smartdns/
|
||||
MAINTAINER:=Nick Peng <pymumu@gmail.com>
|
||||
DEPENDS:=+libopenssl
|
||||
endef
|
||||
|
||||
define Package/smartdns/description
|
||||
smartdns server, find fastest ip.
|
||||
SmartDNS is a local DNS server. SmartDNS accepts DNS query requests from local clients, obtains DNS query results from multiple upstream DNS servers, and returns the fastest access results to clients.
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
mkdir -p $(PKG_BUILD_DIR)
|
||||
cp -r ../* $(PKG_BUILD_DIR)
|
||||
define Build/Configure
|
||||
mkdir -p $(PKG_INSTALL_DIR)
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(MAKE) -C $(PKG_BUILD_DIR)/src $(MAKE_ARGS) all
|
||||
endef
|
||||
|
||||
define Package/smartdns/conffiles
|
||||
/etc/config/smartdns
|
||||
/etc/smartdns/address.conf
|
||||
/etc/smartdns/blacklist-ip.conf
|
||||
/etc/smartdns/custom.conf
|
||||
endef
|
||||
|
||||
define Package/smartdns/install
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/smartdns $(1)/usr/sbin
|
||||
$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/config $(1)/etc/init.d $(1)/etc/smartdns
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/src/smartdns $(1)/usr/sbin/smartdns
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/package/openwrt/files/etc/init.d/smartdns $(1)/etc/init.d/smartdns
|
||||
$(INSTALL_CONF) $(PKG_BUILD_DIR)/package/openwrt/address.conf $(1)/etc/smartdns/address.conf
|
||||
$(INSTALL_CONF) $(PKG_BUILD_DIR)/package/openwrt/blacklist-ip.conf $(1)/etc/smartdns/blacklist-ip.conf
|
||||
$(INSTALL_CONF) $(PKG_BUILD_DIR)/package/openwrt/custom.conf $(1)/etc/smartdns/custom.conf
|
||||
$(INSTALL_CONF) $(PKG_BUILD_DIR)/package/openwrt/files/etc/config/smartdns $(1)/etc/config/smartdns
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage, smartdns))
|
||||
$(eval $(call BuildPackage,smartdns))
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
chmod +x /usr/sbin/smartdns
|
||||
chmod +x /etc/init.d/smartdns
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
. ${IPKG_INSTROOT}/lib/functions.sh
|
||||
default_prerm $0 $@
|
||||
rm /var/etc/smartdns.conf -f
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2018 Nick Peng (pymumu@gmail.com)
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
START=99
|
||||
NAME=smartdns
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
#/bin/sh
|
||||
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
CURR_DIR=$(cd $(dirname $0);pwd)
|
||||
|
||||
VER="`date +"1.%Y.%m.%d-%H%M"`"
|
||||
@@ -16,47 +30,52 @@ showhelp()
|
||||
echo "Options:"
|
||||
echo " -o output directory."
|
||||
echo " --arch archtecture."
|
||||
echo " --ver version."
|
||||
echo " --ver version."
|
||||
echo " -h show this message."
|
||||
}
|
||||
|
||||
build()
|
||||
{
|
||||
ROOT=/tmp/smartdns-openwrt
|
||||
rm -fr $ROOT
|
||||
ROOT=/tmp/smartdns-openwrt
|
||||
rm -fr $ROOT
|
||||
|
||||
mkdir -p $ROOT
|
||||
cp $CURR_DIR/* $ROOT/ -af
|
||||
cd $ROOT/
|
||||
mkdir $ROOT/root/usr/sbin -p
|
||||
mkdir $ROOT/root/etc/init.d -p
|
||||
mkdir $ROOT/root/etc/smartdns/ -p
|
||||
mkdir -p $ROOT
|
||||
cp $CURR_DIR/* $ROOT/ -af
|
||||
cd $ROOT/
|
||||
mkdir $ROOT/root/usr/sbin -p
|
||||
mkdir $ROOT/root/etc/init.d -p
|
||||
mkdir $ROOT/root/etc/smartdns/ -p
|
||||
|
||||
cp $SMARTDNS_CONF $ROOT/root/etc/smartdns/
|
||||
cp $ADDRESS_CONF $ROOT/root/etc/smartdns/
|
||||
cp $BLACKLIST_IP_CONF $ROOT/root/etc/smartdns/
|
||||
cp $CUSTOM_CONF $ROOT/root/etc/smartdns/
|
||||
cp $CURR_DIR/files/etc $ROOT/root/ -af
|
||||
cp $SMARTDNS_BIN $ROOT/root/usr/sbin
|
||||
cp $SMARTDNS_CONF $ROOT/root/etc/smartdns/
|
||||
cp $ADDRESS_CONF $ROOT/root/etc/smartdns/
|
||||
cp $BLACKLIST_IP_CONF $ROOT/root/etc/smartdns/
|
||||
cp $CUSTOM_CONF $ROOT/root/etc/smartdns/
|
||||
cp $CURR_DIR/files/etc $ROOT/root/ -af
|
||||
cp $SMARTDNS_BIN $ROOT/root/usr/sbin
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "copy smartdns file failed."
|
||||
rm -fr $ROOT/
|
||||
return 1
|
||||
fi
|
||||
|
||||
chmod +x $ROOT/root/etc/init.d/smartdns
|
||||
INST_SIZE="`du -sb $ROOT/root/ | awk '{print $1}'`"
|
||||
chmod +x $ROOT/root/etc/init.d/smartdns
|
||||
INST_SIZE="`du -sb $ROOT/root/ | awk '{print $1}'`"
|
||||
|
||||
sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control
|
||||
sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
|
||||
sed -i "s/^\(bind .*\):53/\1:6053/g" $ROOT/root/etc/smartdns/smartdns.conf
|
||||
if [ ! -z "$INST_SIZE" ]; then
|
||||
echo "Installed-Size: $INST_SIZE" >> $ROOT/control/control
|
||||
fi
|
||||
sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control
|
||||
sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
|
||||
sed -i "s/^\(bind .*\):53/\1:6053/g" $ROOT/root/etc/smartdns/smartdns.conf
|
||||
if [ ! -z "$INST_SIZE" ]; then
|
||||
echo "Installed-Size: $INST_SIZE" >> $ROOT/control/control
|
||||
fi
|
||||
|
||||
cd $ROOT/control
|
||||
chmod +x *
|
||||
tar zcf ../control.tar.gz --owner=0 --group=0 ./
|
||||
cd $ROOT
|
||||
cd $ROOT/control
|
||||
chmod +x *
|
||||
tar zcf ../control.tar.gz --owner=0 --group=0 ./
|
||||
cd $ROOT
|
||||
|
||||
tar zcf $ROOT/data.tar.gz -C root --owner=0 --group=0 .
|
||||
tar zcf $OUTPUTDIR/smartdns.$VER.$FILEARCH.ipk --owner=0 --group=0 control.tar.gz data.tar.gz debian-binary
|
||||
rm -fr $ROOT/
|
||||
tar zcf $ROOT/data.tar.gz -C root --owner=0 --group=0 .
|
||||
tar zcf $OUTPUTDIR/smartdns.$VER.$FILEARCH.ipk --owner=0 --group=0 control.tar.gz data.tar.gz debian-binary
|
||||
rm -fr $ROOT/
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -74,38 +93,38 @@ main()
|
||||
--arch)
|
||||
ARCH="$2"
|
||||
shift 2;;
|
||||
--filearch)
|
||||
FILEARCH="$2"
|
||||
shift 2;;
|
||||
--ver)
|
||||
VER="$2"
|
||||
shift 2;;
|
||||
--filearch)
|
||||
FILEARCH="$2"
|
||||
shift 2;;
|
||||
--ver)
|
||||
VER="$2"
|
||||
shift 2;;
|
||||
-o )
|
||||
OUTPUTDIR="$2"
|
||||
shift 2;;
|
||||
-h | --help )
|
||||
-h | --help )
|
||||
showhelp
|
||||
return 0
|
||||
shift ;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$ARCH" ]; then
|
||||
echo "please input arch."
|
||||
return 1;
|
||||
fi
|
||||
if [ -z "$ARCH" ]; then
|
||||
echo "please input arch."
|
||||
return 1;
|
||||
fi
|
||||
|
||||
if [ -z "$FILEARCH" ]; then
|
||||
FILEARCH=$ARCH
|
||||
fi
|
||||
if [ -z "$FILEARCH" ]; then
|
||||
FILEARCH=$ARCH
|
||||
fi
|
||||
|
||||
if [ -z "$OUTPUTDIR" ]; then
|
||||
OUTPUTDIR=$CURR_DIR;
|
||||
fi
|
||||
if [ -z "$OUTPUTDIR" ]; then
|
||||
OUTPUTDIR=$CURR_DIR;
|
||||
fi
|
||||
|
||||
build
|
||||
build
|
||||
}
|
||||
|
||||
main $@
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
#! /bin/sh
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
SMARTDNS_BIN=/opt/usr/sbin/smartdns
|
||||
SMARTDNS_CONF=/opt/etc/smartdns/smartdns.conf
|
||||
|
||||
@@ -1,4 +1,19 @@
|
||||
#! /bin/sh
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
chmod +x /opt/usr/sbin/smartdns
|
||||
chmod +x /opt/etc/init.d/S50smartdns
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
#! /bin/sh
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/opt/etc/init.d/S50smartdns stop
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
#/bin/sh
|
||||
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
CURR_DIR=$(cd $(dirname $0);pwd)
|
||||
VER="`date +"1.%Y.%m.%d-%H%M"`"
|
||||
SMARTDNS_DIR=$CURR_DIR/../../
|
||||
@@ -13,39 +27,44 @@ showhelp()
|
||||
echo "Options:"
|
||||
echo " -o output directory."
|
||||
echo " --arch archtecture."
|
||||
echo " --ver version."
|
||||
echo " --ver version."
|
||||
echo " -h show this message."
|
||||
}
|
||||
|
||||
build()
|
||||
{
|
||||
ROOT=/tmp/smartdns-optware
|
||||
rm -fr $ROOT
|
||||
ROOT=/tmp/smartdns-optware
|
||||
rm -fr $ROOT
|
||||
|
||||
mkdir -p $ROOT
|
||||
cp $CURR_DIR/* $ROOT/ -af
|
||||
cd $ROOT/
|
||||
mkdir $ROOT/opt/usr/sbin -p
|
||||
mkdir $ROOT/opt/etc/init.d -p
|
||||
mkdir $ROOT/opt/etc/smartdns/ -p
|
||||
mkdir -p $ROOT
|
||||
cp $CURR_DIR/* $ROOT/ -af
|
||||
cd $ROOT/
|
||||
mkdir $ROOT/opt/usr/sbin -p
|
||||
mkdir $ROOT/opt/etc/init.d -p
|
||||
mkdir $ROOT/opt/etc/smartdns/ -p
|
||||
|
||||
cp $SMARTDNS_CONF $ROOT/opt/etc/smartdns/
|
||||
cp $SMARTDNS_OPT $ROOT/opt/etc/smartdns/
|
||||
cp $CURR_DIR/S50smartdns $ROOT/opt/etc/init.d/
|
||||
cp $SMARTDNS_BIN $ROOT/opt/usr/sbin
|
||||
cp $SMARTDNS_CONF $ROOT/opt/etc/smartdns/
|
||||
cp $SMARTDNS_OPT $ROOT/opt/etc/smartdns/
|
||||
cp $CURR_DIR/S50smartdns $ROOT/opt/etc/init.d/
|
||||
cp $SMARTDNS_BIN $ROOT/opt/usr/sbin
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "copy smartdns file failed."
|
||||
rm -fr $ROOT/
|
||||
return 1
|
||||
fi
|
||||
|
||||
sed -i "s/# *server-name smartdns/server-name smartdns/g" $ROOT/opt/etc/smartdns/smartdns.conf
|
||||
sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control
|
||||
sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
|
||||
sed -i "s/# *server-name smartdns/server-name smartdns/g" $ROOT/opt/etc/smartdns/smartdns.conf
|
||||
sed -i "s/^Architecture.*/Architecture: $ARCH/g" $ROOT/control/control
|
||||
sed -i "s/Version:.*/Version: $VER/" $ROOT/control/control
|
||||
|
||||
cd $ROOT/control
|
||||
chmod +x *
|
||||
tar zcf ../control.tar.gz --owner=0 --group=0 ./
|
||||
cd $ROOT
|
||||
cd $ROOT/control
|
||||
chmod +x *
|
||||
tar zcf ../control.tar.gz --owner=0 --group=0 ./
|
||||
cd $ROOT
|
||||
|
||||
tar zcf data.tar.gz --owner=0 --group=0 opt
|
||||
tar zcf $OUTPUTDIR/smartdns.$VER.$FILEARCH.ipk --owner=0 --group=0 control.tar.gz data.tar.gz debian-binary
|
||||
rm -fr $ROOT/
|
||||
tar zcf data.tar.gz --owner=0 --group=0 opt
|
||||
tar zcf $OUTPUTDIR/smartdns.$VER.$FILEARCH.ipk --owner=0 --group=0 control.tar.gz data.tar.gz debian-binary
|
||||
rm -fr $ROOT/
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -63,38 +82,38 @@ main()
|
||||
--arch)
|
||||
ARCH="$2"
|
||||
shift 2;;
|
||||
--filearch)
|
||||
FILEARCH="$2"
|
||||
shift 2;;
|
||||
--ver)
|
||||
VER="$2"
|
||||
shift 2;;
|
||||
--filearch)
|
||||
FILEARCH="$2"
|
||||
shift 2;;
|
||||
--ver)
|
||||
VER="$2"
|
||||
shift 2;;
|
||||
-o )
|
||||
OUTPUTDIR="$2"
|
||||
shift 2;;
|
||||
-h | --help )
|
||||
-h | --help )
|
||||
showhelp
|
||||
return 0
|
||||
shift ;;
|
||||
-- ) shift; break ;;
|
||||
* ) break ;;
|
||||
esac
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$ARCH" ]; then
|
||||
echo "please input arch."
|
||||
return 1;
|
||||
fi
|
||||
if [ -z "$ARCH" ]; then
|
||||
echo "please input arch."
|
||||
return 1;
|
||||
fi
|
||||
|
||||
if [ -z "$FILEARCH" ]; then
|
||||
FILEARCH=$ARCH
|
||||
fi
|
||||
if [ -z "$FILEARCH" ]; then
|
||||
FILEARCH=$ARCH
|
||||
fi
|
||||
|
||||
if [ -z "$OUTPUTDIR" ]; then
|
||||
OUTPUTDIR=$CURR_DIR;
|
||||
fi
|
||||
if [ -z "$OUTPUTDIR" ]; then
|
||||
OUTPUTDIR=$CURR_DIR;
|
||||
fi
|
||||
|
||||
build
|
||||
build
|
||||
}
|
||||
|
||||
main $@
|
||||
|
||||
23
src/Makefile
23
src/Makefile
@@ -1,15 +1,30 @@
|
||||
|
||||
# Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
#
|
||||
# smartdns is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# smartdns is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
BIN=smartdns
|
||||
OBJS_LIB=lib/rbtree.o lib/art.o lib/bitops.o lib/radix.o lib/conf.o
|
||||
OBJS=smartdns.o fast_ping.o dns_client.o dns_server.o dns.o util.o tlog.o dns_conf.o dns_cache.o http_parse.o $(OBJS_LIB)
|
||||
CFLAGS +=-O2 -g -Wall -Wstrict-prototypes -fno-omit-frame-pointer -Wstrict-aliasing
|
||||
CFLAGS +=-Iinclude
|
||||
CFLAGS += -DBASE_FILE_NAME=\"$(notdir $<)\"
|
||||
override CFLAGS +=-Iinclude
|
||||
override CFLAGS += -DBASE_FILE_NAME=\"$(notdir $<)\"
|
||||
ifdef VER
|
||||
CFLAGS += -DSMARTDNS_VERION=\"$(VER)\"
|
||||
override CFLAGS += -DSMARTDNS_VERION=\"$(VER)\"
|
||||
endif
|
||||
CXXFLAGS=-O2 -g -Wall -std=c++11
|
||||
CXXFLAGS +=-Iinclude
|
||||
override CXXFLAGS +=-Iinclude
|
||||
ifeq ($(STATIC), yes)
|
||||
LDFLAGS += -lssl -lcrypto -Wl,--whole-archive -lpthread -Wl,--no-whole-archive -ldl -static
|
||||
else
|
||||
|
||||
12
src/dns.c
12
src/dns.c
@@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -622,15 +622,15 @@ int dns_add_SOA(struct dns_packet *packet, dns_rr_type type, char *domain, int t
|
||||
ptr += strnlen(soa->mname, DNS_MAX_CNAME_LEN - 1) + 1;
|
||||
safe_strncpy((char *)ptr, soa->rname, DNS_MAX_CNAME_LEN);
|
||||
ptr += strnlen(soa->rname, DNS_MAX_CNAME_LEN - 1) + 1;
|
||||
*((unsigned int *)ptr) = soa->serial;
|
||||
memcpy(ptr, &soa->serial, sizeof(unsigned int));
|
||||
ptr += 4;
|
||||
*((unsigned int *)ptr) = soa->refresh;
|
||||
memcpy(ptr, &soa->refresh, sizeof(unsigned int));
|
||||
ptr += 4;
|
||||
*((unsigned int *)ptr) = soa->retry;
|
||||
memcpy(ptr, &soa->retry, sizeof(unsigned int));
|
||||
ptr += 4;
|
||||
*((unsigned int *)ptr) = soa->expire;
|
||||
memcpy(ptr, &soa->expire, sizeof(unsigned int));
|
||||
ptr += 4;
|
||||
*((unsigned int *)ptr) = soa->minimum;
|
||||
memcpy(ptr, &soa->minimum, sizeof(unsigned int));
|
||||
ptr += 4;
|
||||
len = ptr - data;
|
||||
|
||||
|
||||
18
src/dns.h
18
src/dns.h
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _DNS_HEAD_H
|
||||
#define _DNS_HEAD_H
|
||||
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "dns_cache.h"
|
||||
#include "stringutil.h"
|
||||
#include "tlog.h"
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SMARTDNS_CACHE_H
|
||||
#define _SMARTDNS_CACHE_H
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -63,9 +63,6 @@
|
||||
#define SOCKET_PRIORITY (6)
|
||||
#define SOCKET_IP_TOS (IPTOS_LOWDELAY | IPTOS_RELIABILITY)
|
||||
|
||||
#ifndef TCP_FASTOPEN_CONNECT
|
||||
#define TCP_FASTOPEN_CONNECT 30
|
||||
#endif
|
||||
|
||||
/* ECS info */
|
||||
struct dns_client_ecs {
|
||||
@@ -249,6 +246,31 @@ static LIST_HEAD(pending_servers);
|
||||
static pthread_mutex_t pending_server_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static int dns_client_has_bootstrap_dns = 0;
|
||||
|
||||
const char *_dns_server_get_type_string(dns_server_type_t type)
|
||||
{
|
||||
const char *type_str = "";
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case DNS_SERVER_UDP:
|
||||
type_str = "udp";
|
||||
break;
|
||||
case DNS_SERVER_TCP:
|
||||
type_str = "tcp";
|
||||
break;
|
||||
case DNS_SERVER_TLS:
|
||||
type_str = "tls";
|
||||
break;
|
||||
case DNS_SERVER_HTTPS:
|
||||
type_str = "https";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return type_str;
|
||||
}
|
||||
|
||||
/* get addr info */
|
||||
static struct addrinfo *_dns_client_getaddr(const char *host, char *port, int type, int protocol)
|
||||
{
|
||||
@@ -826,6 +848,8 @@ static int _dns_client_server_add(char *server_ip, char *server_host, int port,
|
||||
atomic_inc(&client.dns_server_num);
|
||||
freeaddrinfo(gai);
|
||||
|
||||
tlog(TLOG_INFO, "add server %s:%d, type: %s", server_ip, port, _dns_server_get_type_string(server_info->type));
|
||||
|
||||
return 0;
|
||||
errout:
|
||||
if (server_info) {
|
||||
@@ -1380,6 +1404,9 @@ static int _DNS_client_create_socket_tcp(struct dns_server_info *server_info)
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
|
||||
setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority));
|
||||
setsockopt(fd, IPPROTO_IP, IP_TOS, &ip_tos, sizeof(ip_tos));
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_THIN_DUPACK, &yes, sizeof(yes));
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS, &yes, sizeof(yes));
|
||||
set_sock_keepalive(fd, 15, 3, 4);
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&server_info->addr, server_info->ai_addrlen) != 0) {
|
||||
if (errno != EINPROGRESS) {
|
||||
@@ -1447,8 +1474,11 @@ static int _DNS_client_create_socket_tls(struct dns_server_info *server_info, ch
|
||||
|
||||
// ? this cause ssl crash ?
|
||||
// setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &yes, sizeof(yes));
|
||||
// set_sock_keepalive(fd, 15, 3, 4);
|
||||
setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority, sizeof(priority));
|
||||
setsockopt(fd, IPPROTO_IP, IP_TOS, &ip_tos, sizeof(ip_tos));
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_THIN_DUPACK, &yes, sizeof(yes));
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_THIN_LINEAR_TIMEOUTS, &yes, sizeof(yes));
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&server_info->addr, server_info->ai_addrlen) != 0) {
|
||||
if (errno != EINPROGRESS) {
|
||||
@@ -1750,8 +1780,10 @@ static int _dns_client_process_tcp_buff(struct dns_server_info *server_info)
|
||||
}
|
||||
|
||||
if (http_head_get_httpcode(http_head) != 200) {
|
||||
tlog(TLOG_WARN, "http server query failed, server return http code : %d, %s", http_head_get_httpcode(http_head),
|
||||
http_head_get_httpcode_msg(http_head));
|
||||
tlog(TLOG_WARN, "http server query from %s:%d failed, server return http code : %d, %s",
|
||||
server_info->ip, server_info->port,
|
||||
http_head_get_httpcode(http_head),
|
||||
http_head_get_httpcode_msg(http_head));
|
||||
goto errout;
|
||||
}
|
||||
|
||||
@@ -1826,7 +1858,7 @@ static int _dns_client_process_tcp(struct dns_server_info *server_info, struct e
|
||||
goto errout;
|
||||
}
|
||||
|
||||
tlog(TLOG_ERROR, "recv failed, server %s, %s\n", server_info->ip, strerror(errno));
|
||||
tlog(TLOG_ERROR, "recv failed, server %s:%d, %s\n", server_info->ip, server_info->port, strerror(errno));
|
||||
goto errout;
|
||||
}
|
||||
|
||||
@@ -1871,30 +1903,27 @@ static int _dns_client_process_tcp(struct dns_server_info *server_info, struct e
|
||||
server_info->status = DNS_SERVER_STATUS_DISCONNECTED;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&client.server_list_lock);
|
||||
if (server_info->send_buff.len > 0) {
|
||||
/* send existing send_buffer data */
|
||||
len = _dns_client_socket_send(server_info);
|
||||
if (len < 0) {
|
||||
if (errno == EAGAIN) {
|
||||
pthread_mutex_unlock(&client.server_list_lock);
|
||||
return 0;
|
||||
}
|
||||
pthread_mutex_unlock(&client.server_list_lock);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&client.server_list_lock);
|
||||
server_info->send_buff.len -= len;
|
||||
if (server_info->send_buff.len > 0) {
|
||||
memmove(server_info->send_buff.data, server_info->send_buff.data + len, server_info->send_buff.len);
|
||||
}
|
||||
pthread_mutex_unlock(&client.server_list_lock);
|
||||
}
|
||||
/* still remain data, retry */
|
||||
if (server_info->send_buff.len > 0) {
|
||||
pthread_mutex_unlock(&client.server_list_lock);
|
||||
return 0;
|
||||
}
|
||||
pthread_mutex_unlock(&client.server_list_lock);
|
||||
|
||||
/* clear epllout event */
|
||||
memset(&event, 0, sizeof(event));
|
||||
@@ -1968,6 +1997,9 @@ static int _dns_client_tls_verify(struct dns_server_info *server_info)
|
||||
char *spki = NULL;
|
||||
int spki_len = 0;
|
||||
char *tls_host_verify = NULL;
|
||||
if (server_info->ssl == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cert = SSL_get_peer_certificate(server_info->ssl);
|
||||
if (cert == NULL) {
|
||||
@@ -2056,6 +2088,11 @@ static int _dns_client_process_tls(struct dns_server_info *server_info, struct e
|
||||
struct epoll_event fd_event;
|
||||
int ssl_ret;
|
||||
|
||||
if (unlikely(server_info->ssl == NULL)) {
|
||||
tlog(TLOG_ERROR, "ssl is invalid.");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (server_info->status == DNS_SERVER_STATUS_CONNECTING) {
|
||||
/* do SSL hand shake */
|
||||
ret = SSL_connect(server_info->ssl);
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SMART_DNS_CLIENT_H
|
||||
#define _SMART_DNS_CLIENT_H
|
||||
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "dns_conf.h"
|
||||
#include "list.h"
|
||||
#include "rbtree.h"
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _DNS_CONF
|
||||
#define _DNS_CONF
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -15,6 +15,7 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
@@ -1717,7 +1718,40 @@ static void _dns_server_log_rule(const char *domain, enum domain_rule rule_type,
|
||||
tlog(TLOG_INFO, "RULE-MATCH, type: %d, domain: %s, rule: %s", rule_type, domain, rule_name);
|
||||
}
|
||||
|
||||
int _dns_server_get_rules(unsigned char *key, uint32_t key_len, void *value, void *arg)
|
||||
static void _dns_server_update_rule_by_flags(struct dns_request *request)
|
||||
{
|
||||
struct dns_rule_flags *rule_flag =
|
||||
(struct dns_rule_flags *)request->domain_rule.rules[0];
|
||||
unsigned int flags = 0;
|
||||
|
||||
if (rule_flag == NULL) {
|
||||
return;
|
||||
}
|
||||
flags = rule_flag->flags;
|
||||
|
||||
if (flags & DOMAIN_FLAG_ADDR_IGN) {
|
||||
request->domain_rule.rules[DOMAIN_RULE_ADDRESS_IPV4] = NULL;
|
||||
request->domain_rule.rules[DOMAIN_RULE_ADDRESS_IPV6] = NULL;
|
||||
}
|
||||
|
||||
if (flags & DOMAIN_FLAG_ADDR_IPV4_IGN) {
|
||||
request->domain_rule.rules[DOMAIN_RULE_ADDRESS_IPV4] = NULL;
|
||||
}
|
||||
|
||||
if (flags & DOMAIN_FLAG_ADDR_IPV6_IGN) {
|
||||
request->domain_rule.rules[DOMAIN_RULE_ADDRESS_IPV6] = NULL;
|
||||
}
|
||||
|
||||
if (flags & DOMAIN_FLAG_IPSET_IGNORE) {
|
||||
request->domain_rule.rules[DOMAIN_RULE_IPSET] = NULL;
|
||||
}
|
||||
|
||||
if (flags & DOMAIN_FLAG_NAMESERVER_IGNORE) {
|
||||
request->domain_rule.rules[DOMAIN_RULE_NAMESERVER] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int _dns_server_get_rules(unsigned char *key, uint32_t key_len, void *value, void *arg)
|
||||
{
|
||||
struct rule_walk_args *walk_args = arg;
|
||||
struct dns_request *request = walk_args->args;
|
||||
@@ -1737,6 +1771,9 @@ int _dns_server_get_rules(unsigned char *key, uint32_t key_len, void *value, voi
|
||||
walk_args->key_len[i] = key_len;
|
||||
}
|
||||
|
||||
/* update rules by flags */
|
||||
_dns_server_update_rule_by_flags(request);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SMART_DNS_SERVER_H
|
||||
#define _SMART_DNS_SERVER_H
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FAST_PING_H
|
||||
#define FAST_PING_H
|
||||
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "http_parse.h"
|
||||
#include "hash.h"
|
||||
#include "hashtable.h"
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef HTTP_PARSER_H
|
||||
#define HTTP_PARSER_H
|
||||
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _GENERIC_ATOMIC_H
|
||||
#define _GENERIC_ATOMIC_H
|
||||
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _PERF_BITOPS_H
|
||||
#define _PERF_BITOPS_H
|
||||
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _GENERIC_BITOPS_H_
|
||||
#define _GENERIC_BITOPS_H_
|
||||
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _GENERIC_CONF_H
|
||||
#define _GENERIC_CONF_H
|
||||
|
||||
|
||||
@@ -1,5 +1,24 @@
|
||||
#ifndef _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_
|
||||
#define _TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _TOOLS_GENERIC_BITOPS_FIND_H_
|
||||
#define _TOOLS_GENERIC_BITOPS_FIND_H_
|
||||
|
||||
#ifndef find_next_bit
|
||||
/**
|
||||
@@ -74,4 +93,4 @@ extern unsigned long find_first_bit(const unsigned long *addr,
|
||||
unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size);
|
||||
#endif
|
||||
|
||||
#endif /*_TOOLS_LINUX_ASM_GENERIC_BITOPS_FIND_H_ */
|
||||
#endif /*_TOOLS_GENERIC_BITOPS_FIND_H_ */
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _TOOLS_LINUX_COMPILER_H_
|
||||
#define _TOOLS_LINUX_COMPILER_H_
|
||||
|
||||
|
||||
@@ -1,3 +1,22 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _GENERIC_HASH_H
|
||||
#define _GENERIC_HASH_H
|
||||
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
/*
|
||||
* Statically sized hash table implementation
|
||||
* (C) 2012 Sasha Levin <levinsasha928@gmail.com>
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _GENERIC_HASHTABLE_H
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _JHASH_H
|
||||
#define _JHASH_H
|
||||
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _GENERIC_LIST_H
|
||||
#define _GENERIC_LIST_H
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _GENERIC_RBTREE_H
|
||||
#define _GENERIC_RBTREE_H
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _GENERIC_STRING_UITL_H
|
||||
#define _GENERIC_STRING_UITL_H
|
||||
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "bitmap.h"
|
||||
#include "bitops.h"
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "conf.h"
|
||||
#include <getopt.h>
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "rbtree.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
@@ -1,6 +1,6 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@@ -416,12 +416,12 @@ int main(int argc, char *argv[])
|
||||
_reg_signal();
|
||||
}
|
||||
|
||||
if (dns_server_load_conf(config_file) != 0) {
|
||||
fprintf(stderr, "load config failed.\n");
|
||||
if (create_pid_file(pid_file) != 0) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
if (create_pid_file(pid_file) != 0) {
|
||||
if (dns_server_load_conf(config_file) != 0) {
|
||||
fprintf(stderr, "load config failed.\n");
|
||||
goto errout;
|
||||
}
|
||||
|
||||
|
||||
51
src/tlog.c
51
src/tlog.c
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* tinylog
|
||||
* Copyright (C) 2018-2019 Nick Peng <pymumu@gmail.com>
|
||||
* Copyright (C) 2018-2020 Nick Peng <pymumu@gmail.com>
|
||||
* https://github.com/pymumu/tinylog
|
||||
*/
|
||||
#ifndef _GNU_SOURCE
|
||||
@@ -315,7 +315,7 @@ static int _tlog_format(char *buff, int maxlen, struct tlog_info *info, void *us
|
||||
tlog_get_level_string(info->level), info->file, info->line);
|
||||
}
|
||||
|
||||
if (len < 0 || len == maxlen) {
|
||||
if (len < 0 || len >= maxlen) {
|
||||
return -1;
|
||||
}
|
||||
buff += len;
|
||||
@@ -340,9 +340,9 @@ static int _tlog_root_log_buffer(char *buff, int maxlen, void *userptr, const ch
|
||||
int log_len = 0;
|
||||
struct tlog_info_inter *info_inter = (struct tlog_info_inter *)userptr;
|
||||
struct tlog_segment_log_head *log_head = NULL;
|
||||
int max_format_len = 0;
|
||||
int max_format_len = 0;
|
||||
|
||||
if (tlog_format == NULL) {
|
||||
if (tlog_format == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -352,29 +352,32 @@ static int _tlog_root_log_buffer(char *buff, int maxlen, void *userptr, const ch
|
||||
memcpy(&log_head->info, &info_inter->info, sizeof(log_head->info));
|
||||
}
|
||||
|
||||
max_format_len = maxlen - len - 2;
|
||||
log_len = tlog_format(buff + len, max_format_len, &info_inter->info, info_inter->userptr, format, ap);
|
||||
if (log_len < 0) {
|
||||
max_format_len = maxlen - len - 2;
|
||||
buff[maxlen - 1] = 0;
|
||||
log_len = tlog_format(buff + len, max_format_len, &info_inter->info, info_inter->userptr, format, ap);
|
||||
if (log_len < 0) {
|
||||
return -1;
|
||||
} else if (log_len >= max_format_len) {
|
||||
buff[max_format_len - 1] = '.';
|
||||
buff[max_format_len - 2] = '.';
|
||||
buff[max_format_len - 3] = '.';
|
||||
log_len = max_format_len;
|
||||
}
|
||||
len += log_len;
|
||||
buff[len + max_format_len - 2] = '.';
|
||||
buff[len + max_format_len - 3] = '.';
|
||||
buff[len + max_format_len - 4] = '.';
|
||||
log_len = max_format_len - 1;
|
||||
}
|
||||
len += log_len;
|
||||
|
||||
/* add new line character*/
|
||||
if (*(buff + len - 1) != '\n' && len + 1 < maxlen - len) {
|
||||
if (*(buff + len - 1) != '\n' && len + 1 < maxlen - 1) {
|
||||
*(buff + len) = '\n';
|
||||
len++;
|
||||
log_len++;
|
||||
}
|
||||
|
||||
if (tlog.root->segment_log && len + 1 < maxlen - len) {
|
||||
*(buff + len) = '\0';
|
||||
len++;
|
||||
log_len++;
|
||||
if (tlog.root->segment_log) {
|
||||
if (len + 1 < maxlen - 1) {
|
||||
*(buff + len) = '\0';
|
||||
len++;
|
||||
log_len++;
|
||||
}
|
||||
log_head->len = log_len;
|
||||
}
|
||||
|
||||
@@ -452,12 +455,12 @@ static int _tlog_vprintf(struct tlog_log *log, vprint_callback print_callback, v
|
||||
if (len <= 0) {
|
||||
return -1;
|
||||
} else if (len >= TLOG_MAX_LINE_LEN) {
|
||||
strncpy(buff, "[LOG TOO LONG, DISCARD]\n", sizeof(buff));
|
||||
strncpy(buff, "[LOG TOO LONG, DISCARD]\n", sizeof(buff));
|
||||
buff[sizeof(buff) - 1] = '\0';
|
||||
len = strnlen(buff, sizeof(buff));
|
||||
}
|
||||
len = strnlen(buff, sizeof(buff));
|
||||
}
|
||||
|
||||
pthread_mutex_lock(&tlog.lock);
|
||||
pthread_mutex_lock(&tlog.lock);
|
||||
do {
|
||||
if (log->end == log->start) {
|
||||
if (log->ext_end == 0) {
|
||||
@@ -1299,6 +1302,10 @@ static int _tlog_root_write_log(struct tlog_log *log, char *buff, int bufflen)
|
||||
struct tlog_segment_log_head *head = NULL;
|
||||
static struct tlog_segment_log_head empty_info;
|
||||
if (tlog.output_func == NULL) {
|
||||
if (log->segment_log) {
|
||||
head = (struct tlog_segment_log_head *)buff;
|
||||
return _tlog_write(log, head->data, head->len);
|
||||
}
|
||||
return _tlog_write(log, buff, bufflen);
|
||||
}
|
||||
|
||||
|
||||
16
src/tlog.h
16
src/tlog.h
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* tinylog
|
||||
* Copyright (C) 2018-2019 Ruilin Peng (Nick) <pymumu@gmail.com>
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>
|
||||
* https://github.com/pymumu/tinylog
|
||||
*/
|
||||
|
||||
@@ -24,13 +24,13 @@ typedef enum {
|
||||
|
||||
struct tlog_time {
|
||||
int year;
|
||||
int mon;
|
||||
int mday;
|
||||
int hour;
|
||||
int min;
|
||||
int sec;
|
||||
int usec;
|
||||
};
|
||||
unsigned int usec;
|
||||
unsigned char mon;
|
||||
unsigned char mday;
|
||||
unsigned char hour;
|
||||
unsigned char min;
|
||||
unsigned char sec;
|
||||
} __attribute__((packed));
|
||||
|
||||
#ifndef TLOG_MAX_LINE_LEN
|
||||
#define TLOG_MAX_LINE_LEN (1024)
|
||||
|
||||
33
src/util.c
33
src/util.c
@@ -1,3 +1,21 @@
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _GNU_SOURCE
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
@@ -11,6 +29,7 @@
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/ssl.h>
|
||||
#include <pthread.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
@@ -933,3 +952,17 @@ int has_network_raw_cap(void)
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int set_sock_keepalive(int fd, int keepidle, int keepinterval, int keepcnt)
|
||||
{
|
||||
const int yes = 1;
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &yes, sizeof(yes))!= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepidle, sizeof(keepidle));
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepinterval, sizeof(keepinterval));
|
||||
setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &keepcnt, sizeof(keepcnt));
|
||||
|
||||
return 0;
|
||||
}
|
||||
31
src/util.h
31
src/util.h
@@ -1,4 +1,20 @@
|
||||
|
||||
/*************************************************************************
|
||||
*
|
||||
* Copyright (C) 2018-2020 Ruilin Peng (Nick) <pymumu@gmail.com>.
|
||||
*
|
||||
* smartdns is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* smartdns is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SMART_DNS_UTIL_H
|
||||
#define SMART_DNS_UTIL_H
|
||||
@@ -11,6 +27,17 @@
|
||||
extern "C" {
|
||||
#endif /*__cplusplus */
|
||||
|
||||
#ifndef TCP_FASTOPEN_CONNECT
|
||||
#define TCP_FASTOPEN_CONNECT 30
|
||||
#endif
|
||||
#ifndef TCP_THIN_LINEAR_TIMEOUTS
|
||||
#define TCP_THIN_LINEAR_TIMEOUTS 16
|
||||
#endif
|
||||
|
||||
#ifndef TCP_THIN_DUPACK
|
||||
#define TCP_THIN_DUPACK 17
|
||||
#endif
|
||||
|
||||
#define PORT_NOT_DEFINED -1
|
||||
#define MAX_IP_LEN 64
|
||||
|
||||
@@ -69,6 +96,8 @@ void get_compiled_time(struct tm *tm);
|
||||
|
||||
int has_network_raw_cap(void);
|
||||
|
||||
int set_sock_keepalive(int fd, int keepidle, int keepinterval, int keepcnt);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /*__cplusplus */
|
||||
|
||||
Reference in New Issue
Block a user