Skip to content

Commit

Permalink
Bug fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
buttonfly1000 committed Feb 15, 2017
1 parent 0014347 commit c3f62e8
Show file tree
Hide file tree
Showing 20 changed files with 274 additions and 125 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,8 @@ codeblocks/*.layout
codeblocks_win/obj/
codeblocks_win/bin/Debug/
codeblocks_win/bin/Debug_x64/
codeblocks_win/bin/Release_Android/
codeblocks_win/bin/Release_Android_id/
codeblocks_win/bin/Release_x64_id/
codeblocks_win/*.depend
codeblocks_win/*.layout
vc/Debug/
vc/Release/
vc/*.sdf
codeblocks_win/bin/*/cache
codeblocks_win/bin/*/*.txt
codeblocks_win/bin/*/*.bat
Expand Down
1 change: 0 additions & 1 deletion codeblocks_win/dnsforwarder.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@
<Option compilerVar="CC" />
</Unit>
<Unit filename="../readline.h" />
<Unit filename="../request_response.h" />
<Unit filename="../rwlock.h" />
<Unit filename="../simpleht.c">
<Option compilerVar="CC" />
Expand Down
6 changes: 6 additions & 0 deletions default.config
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ BlockIP 243.185.187.39,46.82.174.68,37.61.54.158,93.46.8.89,59.24.3.173,203.98.7
# �����滻��Ŀ�ð�Ƕ��� (`,') �ָ���Ҳ����д���� `IPSubstituting'
IPSubstituting

# BlockNegativeResponse <BOOLEAN>
# �Ƿ�����������η������IJ�ѯδ�ɹ�����Ӧ (since 6.1.1)
# ��ѯδ�ɹ�ָ����ʽ���󡢷������������������ںͷ������ܾ������
# �μ� RFC 6895��`2.3. RCODE Assignment'
BlockNegativeResponse false

#########################
# IP �б�����֧�� IPv4 ��ַ��
#########################
Expand Down
16 changes: 14 additions & 2 deletions default.en.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
##################################################

# LogOn <BOOLEAN>
# Whether to record logs to file (since 5.0.4)
# Log to file (since 5.0.4)
# `true' or `false'
LogOn false

Expand All @@ -43,7 +43,7 @@ LogFileFolder
##################################################

# UDPLocal <IP[:PORT]>,<IP[:PORT]>,...
# Bound local UDP interfaces (IP[:PORT]-tuples, comma-separated),
# Bound local UDP interfaces (IP[:PORT]-tuples, comma-separated),
# which could contain loopback addresses (127.0.0.1), LAN addresses and internet addresses (since 6.0.0)
# An IPv6 address should be square-bracket-rounded, e.g. [::1]:53 and [fe80::699c:f79a:9bb6:1]:5353
# `[:PORT]' can be ommited, in which case the port number 53 is to be used
Expand Down Expand Up @@ -141,6 +141,18 @@ BlockIP 243.185.187.39,46.82.174.68,37.61.54.158,93.46.8.89,59.24.3.173,203.98.7
# Adjacent items should be delimited by a comma, or split them to different lines of `IPSubstituting'
IPSubstituting

# BlockNegativeResponse <BOOLEAN>
# Ignore negative responses from upstream servers (since 6.1.1)
# Negative responses are, for example:
# Format Error
# Server Failure
# Non-Existent Domain
# Query Refused
# etc.
# Refer RFC 6895, section `2.3. RCODE Assignment' for more details
# `true' or `false'
BlockNegativeResponse false

#########################
# IP List (only IPv4 supported)
#########################
Expand Down
5 changes: 2 additions & 3 deletions dnsparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ int DNSGetHostNameLength(const char *DNSBody, int DNSBodyLength, const char *Nam
#define DNSGetRecordClass(rec_start_ptr) ((rec_start_ptr) == NULL ? DNS_CLASS_UNKNOWN : GET_16_BIT_U_INT(DNSJumpOverName(rec_start_ptr) + 2))

#ifdef HOST_BIG_ENDIAN
/* DNSMessageFlags, on offset 2(bytes) of a DNS message body, is 2 bytes length.
* For details: http://www.freesoft.org/CIE/RFC/1035/40.htm and
* http://www.ietf.org/rfc/rfc2535.txt (Section 6.1)
/* DNSMessageFlags, at 2-byte offset of a DNS header, is 2 bytes length.
* https://tools.ietf.org/html/rfc6895
*/
typedef struct _DNSMessageProperties{
uint16_t Direction : 1; /* query (0), or response (1) */
Expand Down
2 changes: 1 addition & 1 deletion dynamichosts.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ int DynamicHosts_Init(ConfigFileInfo *ConfigInfo)
} else {
TimedTask_Add(TRUE,
TRUE,
UpdateInterval,
UpdateInterval * 1000,
(TaskFunc)GetHostsFromInternet_Thread,
NULL,
NULL,
Expand Down
2 changes: 1 addition & 1 deletion hostscontainer.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ PUBFUNC HostsRecordType HostsContainer_Load(HostsContainer *Container,
)
!= 2 )
{
INFO("Unrecognisable hosts : %s, it may be too long.\n", MetaLine);
INFO("Unrecognisable host : %s, it may be too long.\n", MetaLine);
return HOSTS_TYPE_UNKNOWN;
}

Expand Down
31 changes: 25 additions & 6 deletions ipmisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,19 @@ static int IPMisc_Process(IPMisc *m,

if( DnsSimpleParser_Init(&p, DNSPackage, PackageLength, FALSE) != 0 )
{
return IP_MISC_ACTION_NOTHING;
return IP_MISC_NOTHING;
}

if( m->BlockNegative &&
p._Flags.ResponseCode(&p) != RESPONSE_CODE_NO_ERROR
)
{
return IP_MISC_NEGATIVE_RESULT;
}

if( DnsSimpleParserIterator_Init(&i, &p) != 0 )
{
return IP_MISC_ACTION_NOTHING;
return IP_MISC_NOTHING;
}

i.GotoAnswers(&i);
Expand Down Expand Up @@ -106,7 +113,7 @@ static int IPMisc_Process(IPMisc *m,
switch( ActionType )
{
case IP_MISC_TYPE_BLOCK:
return IP_MISC_ACTION_BLOCK;
return IP_MISC_FILTERED_IP;
break;

case IP_MISC_TYPE_SUBSTITUTE:
Expand All @@ -119,7 +126,12 @@ static int IPMisc_Process(IPMisc *m,

}

return IP_MISC_ACTION_NOTHING;
return IP_MISC_NOTHING;
}

static void IPMisc_SetBlockNegative(IPMisc *m, BOOL Value)
{
m->BlockNegative = Value;
}

int IPMisc_Init(IPMisc *m)
Expand All @@ -129,8 +141,11 @@ int IPMisc_Init(IPMisc *m)
return -1;
}

m->BlockNegative = FALSE;

m->AddBlockFromString = IPMisc_AddBlockFromString;
m->AddSubstituteFromString = IPMisc_AddSubstituteFromString;
m->SetBlockNegative = IPMisc_SetBlockNegative;
m->Process = IPMisc_Process;

return 0;
Expand All @@ -147,9 +162,11 @@ int IpMiscSingleton_Init(ConfigFileInfo *ConfigInfo)
StringList *IPSubstituting =
ConfigGetStringList(ConfigInfo, "IPSubstituting");

BOOL BlockNegative = ConfigGetBoolean(ConfigInfo, "BlockNegativeResponse");

StringListIterator i;

if( BlockIP == NULL && IPSubstituting == NULL )
if( BlockIP == NULL && IPSubstituting == NULL && !BlockNegative )
{
return 0;
}
Expand All @@ -159,6 +176,8 @@ int IpMiscSingleton_Init(ConfigFileInfo *ConfigInfo)
return -147;
}

IpMiscSingleton.SetBlockNegative(&IpMiscSingleton, BlockNegative);

if( BlockIP != NULL )
{
const char *Itr;
Expand Down Expand Up @@ -202,7 +221,7 @@ int IPMiscSingleton_Process(IHeader *h /* Entity followed */)
{
if( !SingletonInited )
{
return IP_MISC_ACTION_NOTHING;
return IP_MISC_NOTHING;
}

return IpMiscSingleton.Process(&IpMiscSingleton,
Expand Down
8 changes: 6 additions & 2 deletions ipmisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ typedef enum _MiscType {
IP_MISC_TYPE_SUBSTITUTE,
} MiscType;

#define IP_MISC_ACTION_NOTHING 0
#define IP_MISC_ACTION_BLOCK (-1)
#define IP_MISC_NOTHING 0
#define IP_MISC_FILTERED_IP (-1)
#define IP_MISC_NEGATIVE_RESULT (-2)

typedef struct _IPMisc IPMisc;

struct _IPMisc{
/* private */
IpChunk c;

BOOL BlockNegative;

int (*AddBlockFromString)(IPMisc *m, const char *Ip);
int (*AddSubstituteFromString)(IPMisc *m,
const char *Ip,
const char *Substituter
);
void (*SetBlockNegative)(IPMisc *m, BOOL Value);
int (*Process)(IPMisc *m,
char *DNSPackage, /* Without TCPLength */
int PackageLength
Expand Down
3 changes: 2 additions & 1 deletion logs.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ void ShowBlockedMessage(IHeader *h, const char *Message)
GetAllAnswers(Package, h->EntityLength, InfoBuffer, sizeof(InfoBuffer));

Log_Print(NULL,
"[B][%s] %s :\n%s",
"[B][%s][%s] %s :\n%s",
DNSGetTypeName(h->Type),
h->Domain,
Message == NULL ? "" : Message,
InfoBuffer
Expand Down
17 changes: 11 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include "timedtask.h"
#include "domainstatistic.h"

#define VERSION__ "6.1.0"
#define VERSION__ "6.1.2"

static char *ConfigFile;
static BOOL DeamonMode;
Expand Down Expand Up @@ -59,7 +59,7 @@ static int EnvironmentInit(char *ConfigFile)
TmpTypeDescriptor.str = NULL;
ConfigAddOption(&ConfigInfo, "UDPLocal", STRATEGY_APPEND_DISCARD_DEFAULT, TYPE_STRING, TmpTypeDescriptor);
ConfigSetStringDelimiters(&ConfigInfo, "UDPLocal", ",");
TmpTypeDescriptor.str = "127.0.0.1";
TmpTypeDescriptor.str = "127.0.0.1:53";
ConfigSetDefaultValue(&ConfigInfo, TmpTypeDescriptor, "UDPLocal");

TmpTypeDescriptor.str = NULL;
Expand All @@ -68,15 +68,17 @@ static int EnvironmentInit(char *ConfigFile)
TmpTypeDescriptor.str = "UDP 1.2.4.8,114.114.114.114 * on";
ConfigSetDefaultValue(&ConfigInfo, TmpTypeDescriptor, "ServerGroup");

ConfigAddAlias(&ConfigInfo, "ServerGroup", "GroupFile", "FILE", "");

/* UDPGroup 1.2.4.8,114.114.114.114 * on */
ConfigAddAlias(&ConfigInfo, "ServerGroup", "UDPGroup", "UDP");
ConfigAddAlias(&ConfigInfo, "ServerGroup", "UDPGroup", "UDP", NULL);

/* TCPGroup 1.2.4.8,114.114.114.114 example.com 192.168.50.5:8080, 192.168.50.6:8080*/
/* TCPGroup 1.2.4.8,114.114.114.114 * no*/
ConfigAddAlias(&ConfigInfo, "ServerGroup", "TCPGroup", "TCP");
ConfigAddAlias(&ConfigInfo, "ServerGroup", "TCPGroup", "TCP", NULL);

/* TLSGroup getdnsapi.net:853:185.49.141.38|foxZRnIh9gZpWnl+zEiKa0EJ2rdCGroMWm02gaxSc9S= example.com */
ConfigAddAlias(&ConfigInfo, "ServerGroup", "TLSGroup", "TLS");
ConfigAddAlias(&ConfigInfo, "ServerGroup", "TLSGroup", "TLS", NULL);

TmpTypeDescriptor.str = NULL;
ConfigAddOption(&ConfigInfo, "BlockIP", STRATEGY_APPEND, TYPE_STRING, TmpTypeDescriptor);
Expand All @@ -88,6 +90,9 @@ static int EnvironmentInit(char *ConfigFile)
ConfigAddOption(&ConfigInfo, "IPSubstituting", STRATEGY_APPEND, TYPE_STRING, TmpTypeDescriptor);
ConfigSetStringDelimiters(&ConfigInfo, "IPSubstituting", "\t ,");

TmpTypeDescriptor.boolean = FALSE;
ConfigAddOption(&ConfigInfo, "BlockNegativeResponse", STRATEGY_DEFAULT, TYPE_BOOLEAN, TmpTypeDescriptor);

TmpTypeDescriptor.boolean = FALSE;
ConfigAddOption(&ConfigInfo, "DomainStatistic", STRATEGY_DEFAULT, TYPE_BOOLEAN, TmpTypeDescriptor);

Expand All @@ -104,7 +109,7 @@ static int EnvironmentInit(char *ConfigFile)
ConfigAddOption(&ConfigInfo, "StatisticUpdateInterval", STRATEGY_DEFAULT, TYPE_INT32, TmpTypeDescriptor);

TmpTypeDescriptor.str = NULL;
ConfigAddOption(&ConfigInfo, "Hosts", STRATEGY_APPEND, TYPE_STRING, TmpTypeDescriptor);
ConfigAddOption(&ConfigInfo, "Hosts", STRATEGY_APPEND, TYPE_PATH, TmpTypeDescriptor);

TmpTypeDescriptor.INT32 = 18000;
ConfigAddOption(&ConfigInfo, "HostsUpdateInterval", STRATEGY_DEFAULT, TYPE_INT32, TmpTypeDescriptor);
Expand Down
2 changes: 1 addition & 1 deletion makefile.am
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bin_PROGRAMS = dnsforwarder
dnsforwarder_SOURCES = addresslist.c downloader.h logs.h socketpuller.h addresslist.h dynamichosts.c main.c array.c dynamichosts.h mcontext.c array.h filter.c mcontext.h stablebuffer.c bst.c filter.h mmgr.c stablebuffer.h bst.h goodiplist.c mmgr.h statichosts.c cacheht.c goodiplist.h oo.h statichosts.h cacheht.h hcontext.c pipes.c stringchunk.c cachettlcrtl.c hcontext.h pipes.h stringchunk.h cachettlcrtl.h hosts.c ptimer.c stringlist.c hosts.h ptimer.h stringlist.h hostscontainer.c tcpm.c common.h hostscontainer.h tcpm.h dnscache.c hostsutils.c readconfig.c timedtask.c dnscache.h hostsutils.h readconfig.h timedtask.h dnsgenerator.c iheader.c readline.c udpfrontend.c dnsgenerator.h iheader.h readline.h udpfrontend.h dnsparser.c ipchunk.c request_response.h udpm.c dnsparser.h ipchunk.h rwlock.h udpm.h dnsrelated.c ipmisc.c simpleht.c utils.c dnsrelated.h ipmisc.h simpleht.h utils.h domainstatistic.c linkedqueue.c socketpool.c winmsgque.c domainstatistic.h linkedqueue.h socketpool.h winmsgque.h downloader.c logs.c socketpuller.c
dnsforwarder_SOURCES = addresslist.c downloader.h logs.h socketpuller.h addresslist.h dynamichosts.c main.c array.c dynamichosts.h mcontext.c array.h filter.c mcontext.h stablebuffer.c bst.c filter.h mmgr.c stablebuffer.h bst.h goodiplist.c mmgr.h statichosts.c cacheht.c goodiplist.h oo.h statichosts.h cacheht.h hcontext.c pipes.c stringchunk.c cachettlcrtl.c hcontext.h pipes.h stringchunk.h cachettlcrtl.h hosts.c ptimer.c stringlist.c hosts.h ptimer.h stringlist.h hostscontainer.c tcpm.c common.h hostscontainer.h tcpm.h dnscache.c hostsutils.c readconfig.c timedtask.c dnscache.h hostsutils.h readconfig.h timedtask.h dnsgenerator.c iheader.c readline.c udpfrontend.c dnsgenerator.h iheader.h readline.h udpfrontend.h dnsparser.c ipchunk.c udpm.c dnsparser.h ipchunk.h rwlock.h udpm.h dnsrelated.c ipmisc.c simpleht.c utils.c dnsrelated.h ipmisc.h simpleht.h utils.h domainstatistic.c linkedqueue.c socketpool.c winmsgque.c domainstatistic.h linkedqueue.h socketpool.h winmsgque.h downloader.c logs.c socketpuller.c
19 changes: 1 addition & 18 deletions makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -283,24 +283,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
dnsforwarder_SOURCES = addresslist.c downloader.h logs.h \
socketpuller.h addresslist.h dynamichosts.c main.c array.c \
dynamichosts.h mcontext.c array.h filter.c mcontext.h \
stablebuffer.c bst.c filter.h mmgr.c stablebuffer.h bst.h \
goodiplist.c mmgr.h statichosts.c cacheht.c goodiplist.h oo.h \
statichosts.h cacheht.h hcontext.c pipes.c stringchunk.c \
cachettlcrtl.c hcontext.h pipes.h stringchunk.h cachettlcrtl.h \
hosts.c ptimer.c stringlist.c hosts.h ptimer.h stringlist.h \
hostscontainer.c tcpm.c common.h hostscontainer.h tcpm.h \
dnscache.c hostsutils.c readconfig.c timedtask.c dnscache.h \
hostsutils.h readconfig.h timedtask.h dnsgenerator.c iheader.c \
readline.c udpfrontend.c dnsgenerator.h iheader.h readline.h \
udpfrontend.h dnsparser.c ipchunk.c request_response.h udpm.c \
dnsparser.h ipchunk.h rwlock.h udpm.h dnsrelated.c ipmisc.c \
simpleht.c utils.c dnsrelated.h ipmisc.h simpleht.h utils.h \
domainstatistic.c linkedqueue.c socketpool.c winmsgque.c \
domainstatistic.h linkedqueue.h socketpool.h winmsgque.h \
downloader.c logs.c socketpuller.c
dnsforwarder_SOURCES = addresslist.c downloader.h logs.h socketpuller.h addresslist.h dynamichosts.c main.c array.c dynamichosts.h mcontext.c array.h filter.c mcontext.h stablebuffer.c bst.c filter.h mmgr.c stablebuffer.h bst.h goodiplist.c mmgr.h statichosts.c cacheht.c goodiplist.h oo.h statichosts.h cacheht.h hcontext.c pipes.c stringchunk.c cachettlcrtl.c hcontext.h pipes.h stringchunk.h cachettlcrtl.h hosts.c ptimer.c stringlist.c hosts.h ptimer.h stringlist.h hostscontainer.c tcpm.c common.h hostscontainer.h tcpm.h dnscache.c hostsutils.c readconfig.c timedtask.c dnscache.h hostsutils.h readconfig.h timedtask.h dnsgenerator.c iheader.c readline.c udpfrontend.c dnsgenerator.h iheader.h readline.h udpfrontend.h dnsparser.c ipchunk.c udpm.c dnsparser.h ipchunk.h rwlock.h udpm.h dnsrelated.c ipmisc.c simpleht.c utils.c dnsrelated.h ipmisc.h simpleht.h utils.h domainstatistic.c linkedqueue.c socketpool.c winmsgque.c domainstatistic.h linkedqueue.h socketpool.h winmsgque.h downloader.c logs.c socketpuller.c
all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-am

Expand Down
Loading

0 comments on commit c3f62e8

Please sign in to comment.