Generate debian / asus-optware package

This commit is contained in:
Nick Peng
2018-07-18 00:14:50 +08:00
parent 806acb2f96
commit 9391f709fc
14 changed files with 119 additions and 36 deletions

View File

@@ -36,11 +36,12 @@ log-level error
# remote udp dns server list
# server [IP]:[PORT], default port is 53
# CNNIC
#qinghua TUNA DNS666
server 101.6.6.6
# 114
server 114.114.114.114
#pure DNS
server 123.207.137.88
server 123.207.13.111
#dnspod
server 119.29.29.29
@@ -48,9 +49,6 @@ server 119.29.29.29
# alibaba dns
server 223.5.5.5
#BAU DNS
server 223.113.97.99
#OpenDNS
server 208.67.222.222:5353
@@ -64,4 +62,4 @@ server 202.141.162.123:53
# specific address to domain
# address /domain/ip
# address /www.example.com/1.2.3.4
# address /www.example.com/1.2.3.4

View File

@@ -0,0 +1,5 @@
smartdns (1.2018.7.9) stable; urgency=low
* Initial build
-- initial release. <pymumu@gmail.com> Mon, 9 jul 2018 21:20:28 +0800

View File

@@ -0,0 +1 @@
9

View File

@@ -0,0 +1,9 @@
Source: smartdns
Maintainer: Nick Peng <pymumu@gmail.com>
Build-Depends: debhelper (>= 8.0.0)
Version:
Section: net
Package: smartdns
Priority: extra
Architecture: armhf
Description: a smartdns server

View File

@@ -0,0 +1,7 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: smartdns
Source: http://github.com/pymumu/smartdns
Files: *
Copyright: 2018 Nick peng
License: proprietary

View File

@@ -0,0 +1,4 @@
#!/bin/sh
systemctl stop smartdns
systemctl disable smartdns

View File

@@ -0,0 +1,21 @@
#!/usr/bin/make -f
%:
dh $@ --with systemd --builddirectory=./target/
clean:
make -C ../src clean
build:
make -C ../src
override_dh_systemd_enable:
dh_systemd_enable --name=smartdns
override_dh_installinit:
dh_installinit --name=smartdns
override_dh_installdeb:
dh_installdeb
cp ../systemd/smartdns.service ${CURDIR}/debian/

30
package/debian/make.sh Normal file
View File

@@ -0,0 +1,30 @@
#/bin/sh
CURR_DIR=`pwd`
VER="`date +"1.%Y.%m.%d-%H%M"`"
SMARTDNS_DIR=$CURR_DIR/../../
SMARTDNS_BIN=$SMARTDNS_DIR/src/smartdns
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
sed -i "s/Version:.*/Version: $VER/" $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
dpkg -b $ROOT $CURR_DIR/smartdns.$VER.armhf.deb
rm -fr $ROOT/

View File

@@ -1,9 +1,10 @@
#/bin/sh
CURR_DIR=`pwd`
SMARTDNS_BIN=$CURR_DIR/../../src/smartdns
SMARTDNS_CONF=$CURR_DIR/../../etc/smartdns/smartdns.conf
VER="`date +"1.%Y.%m.%d-%H%M"`"
SMARTDNS_DIR=$CURR_DIR/../../
SMARTDNS_BIN=$SMARTDNS_DIR/src/smartdns
SMARTDNS_CONF=$SMARTDNS_DIR/etc/smartdns/smartdns.conf
ROOT=/tmp/smartdns-optware
rm -fr $ROOT
@@ -18,11 +19,13 @@ cp $SMARTDNS_CONF $ROOT/opt/etc/smartdns/
cp S50smartdns $ROOT/opt/etc/init.d/
cp $SMARTDNS_BIN $ROOT/opt/usr/sbin
sed -i "s/^\(bind .*\):53/\1:535/g" $ROOT/opt/etc/smartdns/smartdns.conf
cd $ROOT/control
chmod +x *
tar zcf ../control.tar.gz ./
cd $ROOT
tar zcf data.tar.gz opt
tar zcf $CURR_DIR/smartdns.2018.7.6-1933.mipsbig.ipk control.tar.gz data.tar.gz debian-binary
tar zcf $CURR_DIR/smartdns.$VER.mipsbig.ipk control.tar.gz data.tar.gz debian-binary
rm -fr $ROOT/

View File

@@ -42,7 +42,7 @@ int config_server_name(char *value)
return 0;
}
int config_server(char *value, dns_conf_server_type_t type)
int config_server(char *value, dns_server_type_t type)
{
int index = dns_conf_server_num;
struct dns_servers *server;
@@ -172,17 +172,17 @@ errout:
int config_server_udp(char *value)
{
return config_server(value, DNS_CONF_TYPE_UDP);
return config_server(value, DNS_SERVER_UDP);
}
int config_server_tcp(char *value)
{
return config_server(value, DNS_CONF_TYPE_TCP);
return config_server(value, DNS_SERVER_TCP);
}
int config_server_http(char *value)
{
return config_server(value, DNS_CONF_TYPE_HTTP);
return config_server(value, DNS_SERVER_HTTP);
}
int config_cache_size(char *value)

View File

@@ -4,6 +4,7 @@
#include "list.h"
#include "art.h"
#include "dns.h"
#include "dns_client.h"
#define DNS_MAX_SERVERS 32
#define DNS_MAX_IPLEN 64
@@ -11,16 +12,10 @@
#define DEFAULT_DNS_PORT 53
#define DNS_MAX_CONF_CNAME_LEN 128
typedef enum dns_conf_server_type {
DNS_CONF_TYPE_UDP,
DNS_CONF_TYPE_TCP,
DNS_CONF_TYPE_HTTP,
} dns_conf_server_type_t;
struct dns_servers {
char server[DNS_MAX_IPLEN];
unsigned short port;
dns_conf_server_type_t type;
dns_server_type_t type;
};
struct dns_address {

View File

@@ -35,6 +35,8 @@
#define RCODE_MASK 0x000F
#define DNS_RR_END (0XFFFF)
#define UNUSED(expr) do { (void)(expr); } while (0)
/* read short and move pointer */
short dns_read_short(unsigned char **buffer)
{
@@ -833,7 +835,7 @@ static int _dns_decode_domain(struct dns_context *context, char *output, int siz
context->ptr = ptr;
}
ptr = context->data + len;
if (context->maxsize - (ptr - context->data) < 0) {
if (context->maxsize < (ptr - context->data)) {
tlog(TLOG_ERROR, "length is not enouth %u:%ld, %p, %p", context->maxsize, (long)(ptr - context->data), context->ptr, context->data);
return -1;
}
@@ -847,7 +849,7 @@ static int _dns_decode_domain(struct dns_context *context, char *output, int siz
output++;
}
if (context->maxsize - (ptr - context->data) < 0) {
if (context->maxsize < (ptr - context->data)) {
tlog(TLOG_ERROR, "length is not enouth %u:%ld, %p, %p", context->maxsize, (long)(ptr - context->data), context->ptr, context->data);
return -1;
}
@@ -856,7 +858,7 @@ static int _dns_decode_domain(struct dns_context *context, char *output, int siz
if (output_len < size - 1) {
/* copy sub string */
copy_len = (len < size - output_len) ? len : size - 1 - output_len;
if (context->maxsize - (ptr - context->data) < 0) {
if (context->maxsize < (ptr - context->data)) {
tlog(TLOG_ERROR, "length is not enouth %u:%ld, %p, %p", context->maxsize, (long)(ptr - context->data), context->ptr, context->data);
return -1;
}
@@ -1250,6 +1252,9 @@ static int _dns_decode_opt(struct dns_context *context, dns_rr_type type, unsign
unsigned char *start = context->ptr;
struct dns_packet *packet = context->packet;
int ret = 0;
UNUSED(ever);
/*
Field Name Field Type Description
------------------------------------------------------
@@ -1284,7 +1289,7 @@ static int _dns_decode_opt(struct dns_context *context, dns_rr_type type, unsign
tlog(TLOG_ERROR, "extend rcode invalid.");
return -1;
}
ever = ever;
tlog(TLOG_DEBUG, "decode opt.");
while (context->ptr - start < rr_len) {

View File

@@ -119,6 +119,8 @@ struct dns_request {
atomic_t notified;
atomic_t adblock;
/* send original raw packet to server/client like proxy */
int passthrough;
@@ -535,12 +537,6 @@ static int _dns_server_process_answer(struct dns_request *request, char *domain,
break;
}
if (addr[0] == 0) {
_dns_server_request_release(request);
tlog(TLOG_WARN, "Ad blocker, domain: %s", domain);
break;
}
if (request->has_ipv4 == 0) {
memcpy(request->ipv4_addr, addr, DNS_RR_A_LEN);
request->ttl_v4 = _dns_server_get_conf_ttl(ttl);
@@ -550,6 +546,14 @@ static int _dns_server_process_answer(struct dns_request *request, char *domain,
request->ttl_v4 = _dns_server_get_conf_ttl(ttl);
}
}
if (addr[0] == 0 || addr[0] == 127) {
if (atomic_inc_return(&request->adblock) <= 1) {
_dns_server_request_release(request);
break;
}
}
if (_dns_ip_address_check_add(request, addr, DNS_T_A) != 0) {
_dns_server_request_release(request);
break;
@@ -859,6 +863,7 @@ static int _dns_server_recv(unsigned char *inpacket, int inpacket_len, struct so
request = malloc(sizeof(*request));
memset(request, 0, sizeof(*request));
pthread_mutex_init(&request->ip_map_lock, 0);
atomic_set(&request->adblock, 0);
request->ping_ttl_v4 = -1;
request->ping_ttl_v6 = -1;
request->rcode = DNS_RC_SERVFAIL;

View File

@@ -61,7 +61,7 @@ void help(void)
"Online help: http://smartdns.github.io"
"\n";
/* clang-format on */
printf(help);
printf("%s", help);
}
int smartdns_load_from_resolv(void)
@@ -283,10 +283,10 @@ int main(int argc, char *argv[])
is_forground = 1;
break;
case 'c':
snprintf(config_file, sizeof(config_file), optarg);
snprintf(config_file, sizeof(config_file), "%s", optarg);
break;
case 'p':
snprintf(pid_file, sizeof(pid_file), optarg);
snprintf(pid_file, sizeof(pid_file), "%s", optarg);
break;
case 'h':
help();