Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
D
Dnsmasq
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
Dnsmasq
Commits
1ab62aec
Commit
1ab62aec
authored
Jan 12, 2012
by
Simon Kelley
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Further tuning of the fast hostfile reading code.
Use the packet buffer for hash-buckets, better hash function.
parent
915363f9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
25 deletions
+19
-25
src/cache.c
src/cache.c
+19
-24
src/config.h
src/config.h
+0
-1
No files found.
src/cache.c
View file @
1ab62aec
...
@@ -635,7 +635,7 @@ struct crec *cache_find_by_addr(struct crec *crecp, struct all_addr *addr,
...
@@ -635,7 +635,7 @@ struct crec *cache_find_by_addr(struct crec *crecp, struct all_addr *addr,
}
}
static
void
add_hosts_entry
(
struct
crec
*
cache
,
struct
all_addr
*
addr
,
int
addrlen
,
static
void
add_hosts_entry
(
struct
crec
*
cache
,
struct
all_addr
*
addr
,
int
addrlen
,
unsigned
short
flags
,
int
index
,
struct
crec
**
rhash
)
unsigned
short
flags
,
int
index
,
struct
crec
**
rhash
,
int
hashsz
)
{
{
struct
crec
*
lookup
=
cache_find_by_name
(
NULL
,
cache
->
name
.
sname
,
0
,
flags
&
(
F_IPV4
|
F_IPV6
));
struct
crec
*
lookup
=
cache_find_by_name
(
NULL
,
cache
->
name
.
sname
,
0
,
flags
&
(
F_IPV4
|
F_IPV6
));
int
i
,
nameexists
=
0
;
int
i
,
nameexists
=
0
;
...
@@ -656,20 +656,18 @@ static void add_hosts_entry(struct crec *cache, struct all_addr *addr, int addrl
...
@@ -656,20 +656,18 @@ static void add_hosts_entry(struct crec *cache, struct all_addr *addr, int addrl
/* Ensure there is only one address -> name mapping (first one trumps)
/* Ensure there is only one address -> name mapping (first one trumps)
We do this by steam here, The entries are kept in hash chains, linked
We do this by steam here, The entries are kept in hash chains, linked
by ->next (which is unused at this point) held in hash buckets in
by ->next (which is unused at this point) held in hash buckets in
the array rhash
. Note that rhash and the values in ->next are only valid
the array rhash
, hashed on address. Note that rhash and the values
whilst reading hosts files: the buckets are then freed, and the
in ->next are only valid whilst reading hosts files: the buckets are
->next pointer used for other things.
then freed, and the
->next pointer used for other things.
Only insert each unique address one into this hashing structure.
Only insert each unique address on
c
e into this hashing structure.
This complexity avoids O(n^2) divergent CPU use whilst reading
This complexity avoids O(n^2) divergent CPU use whilst reading
large (10000 entry) hosts files. */
large (10000 entry) hosts files. */
/* hash address */
/* hash address */
for
(
j
=
0
,
i
=
0
;
i
<
addrlen
;
i
++
)
for
(
j
=
0
,
i
=
0
;
i
<
addrlen
;
i
++
)
j
+=
((
unsigned
char
*
)
addr
)[
i
]
+
(
j
<<
6
)
+
(
j
<<
16
)
-
j
;
j
=
(
j
*
2
+
((
unsigned
char
*
)
addr
)[
i
])
%
hashsz
;
j
=
j
%
RHASHSIZE
;
for
(
lookup
=
rhash
[
j
];
lookup
;
lookup
=
lookup
->
next
)
for
(
lookup
=
rhash
[
j
];
lookup
;
lookup
=
lookup
->
next
)
if
((
lookup
->
flags
&
F_HOSTS
)
&&
if
((
lookup
->
flags
&
F_HOSTS
)
&&
...
@@ -753,7 +751,7 @@ static int gettok(FILE *f, char *token)
...
@@ -753,7 +751,7 @@ static int gettok(FILE *f, char *token)
}
}
}
}
static
int
read_hostsfile
(
char
*
filename
,
int
index
,
int
cache_size
,
struct
crec
**
rhash
)
static
int
read_hostsfile
(
char
*
filename
,
int
index
,
int
cache_size
,
struct
crec
**
rhash
,
int
hashsz
)
{
{
FILE
*
f
=
fopen
(
filename
,
"r"
);
FILE
*
f
=
fopen
(
filename
,
"r"
);
char
*
token
=
daemon
->
namebuff
,
*
domain_suffix
=
NULL
;
char
*
token
=
daemon
->
namebuff
,
*
domain_suffix
=
NULL
;
...
@@ -833,13 +831,13 @@ static int read_hostsfile(char *filename, int index, int cache_size, struct crec
...
@@ -833,13 +831,13 @@ static int read_hostsfile(char *filename, int index, int cache_size, struct crec
strcpy
(
cache
->
name
.
sname
,
canon
);
strcpy
(
cache
->
name
.
sname
,
canon
);
strcat
(
cache
->
name
.
sname
,
"."
);
strcat
(
cache
->
name
.
sname
,
"."
);
strcat
(
cache
->
name
.
sname
,
domain_suffix
);
strcat
(
cache
->
name
.
sname
,
domain_suffix
);
add_hosts_entry
(
cache
,
&
addr
,
addrlen
,
flags
,
index
,
rhash
);
add_hosts_entry
(
cache
,
&
addr
,
addrlen
,
flags
,
index
,
rhash
,
hashsz
);
name_count
++
;
name_count
++
;
}
}
if
((
cache
=
whine_malloc
(
sizeof
(
struct
crec
)
+
strlen
(
canon
)
+
1
-
SMALLDNAME
)))
if
((
cache
=
whine_malloc
(
sizeof
(
struct
crec
)
+
strlen
(
canon
)
+
1
-
SMALLDNAME
)))
{
{
strcpy
(
cache
->
name
.
sname
,
canon
);
strcpy
(
cache
->
name
.
sname
,
canon
);
add_hosts_entry
(
cache
,
&
addr
,
addrlen
,
flags
,
index
,
rhash
);
add_hosts_entry
(
cache
,
&
addr
,
addrlen
,
flags
,
index
,
rhash
,
hashsz
);
name_count
++
;
name_count
++
;
}
}
free
(
canon
);
free
(
canon
);
...
@@ -861,9 +859,8 @@ static int read_hostsfile(char *filename, int index, int cache_size, struct crec
...
@@ -861,9 +859,8 @@ static int read_hostsfile(char *filename, int index, int cache_size, struct crec
void
cache_reload
(
void
)
void
cache_reload
(
void
)
{
{
struct
crec
*
cache
,
**
up
,
*
tmp
;
struct
crec
*
cache
,
**
up
,
*
tmp
;
int
i
,
total_size
=
daemon
->
cachesize
;
int
revhashsz
,
i
,
total_size
=
daemon
->
cachesize
;
struct
hostsfile
*
ah
;
struct
hostsfile
*
ah
;
struct
crec
**
reverse_hash
;
cache_inserted
=
cache_live_freed
=
0
;
cache_inserted
=
cache_live_freed
=
0
;
...
@@ -897,21 +894,19 @@ void cache_reload(void)
...
@@ -897,21 +894,19 @@ void cache_reload(void)
return
;
return
;
}
}
if
(
!
(
reverse_hash
=
whine_malloc
(
sizeof
(
struct
crec
*
)
*
RHASHSIZE
)))
/* borrow the packet buffer for a temporary by-address hash */
return
;
memset
(
daemon
->
packet
,
0
,
daemon
->
packet_buff_sz
)
;
revhashsz
=
daemon
->
packet_buff_sz
/
sizeof
(
struct
crec
*
);
for
(
i
=
0
;
i
<
RHASHSIZE
;
i
++
)
/* we overwrote the buffer... */
reverse_hash
[
i
]
=
NULL
;
daemon
->
srv_save
=
NULL
;
if
(
!
option_bool
(
OPT_NO_HOSTS
))
if
(
!
option_bool
(
OPT_NO_HOSTS
))
total_size
=
read_hostsfile
(
HOSTSFILE
,
0
,
total_size
,
reverse_hash
);
total_size
=
read_hostsfile
(
HOSTSFILE
,
0
,
total_size
,
(
struct
crec
**
)
daemon
->
packet
,
revhashsz
);
daemon
->
addn_hosts
=
expand_filelist
(
daemon
->
addn_hosts
);
daemon
->
addn_hosts
=
expand_filelist
(
daemon
->
addn_hosts
);
for
(
ah
=
daemon
->
addn_hosts
;
ah
;
ah
=
ah
->
next
)
for
(
ah
=
daemon
->
addn_hosts
;
ah
;
ah
=
ah
->
next
)
if
(
!
(
ah
->
flags
&
AH_INACTIVE
))
if
(
!
(
ah
->
flags
&
AH_INACTIVE
))
total_size
=
read_hostsfile
(
ah
->
fname
,
ah
->
index
,
total_size
,
reverse_hash
);
total_size
=
read_hostsfile
(
ah
->
fname
,
ah
->
index
,
total_size
,
(
struct
crec
**
)
daemon
->
packet
,
revhashsz
);
free
(
reverse_hash
);
}
}
char
*
get_domain
(
struct
in_addr
addr
)
char
*
get_domain
(
struct
in_addr
addr
)
...
...
src/config.h
View file @
1ab62aec
...
@@ -15,7 +15,6 @@
...
@@ -15,7 +15,6 @@
*/
*/
#define FTABSIZ 150
/* max number of outstanding requests (default) */
#define FTABSIZ 150
/* max number of outstanding requests (default) */
#define RHASHSIZE 1024
/* hash buckets for address lookup during hostfile read */
#define MAX_PROCS 20
/* max no children for TCP requests */
#define MAX_PROCS 20
/* max no children for TCP requests */
#define CHILD_LIFETIME 150
/* secs 'till terminated (RFC1035 suggests > 120s) */
#define CHILD_LIFETIME 150
/* secs 'till terminated (RFC1035 suggests > 120s) */
#define EDNS_PKTSZ 4096
/* default max EDNS.0 UDP packet from RFC5625 */
#define EDNS_PKTSZ 4096
/* default max EDNS.0 UDP packet from RFC5625 */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment