Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
asterisk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Voice
asterisk
Commits
ee565da9
Commit
ee565da9
authored
8 months ago
by
Iryna Antsyferova
Browse files
Options
Downloads
Patches
Plain Diff
Implement dns cache handlers
parent
9556ab31
No related branches found
No related tags found
1 merge request
!180
DNS cache support, REF 14614
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
res/res_pjsip/pjsip_resolver.c
+65
-2
65 additions, 2 deletions
res/res_pjsip/pjsip_resolver.c
with
65 additions
and
2 deletions
res/res_pjsip/pjsip_resolver.c
+
65
−
2
View file @
ee565da9
...
...
@@ -68,8 +68,7 @@ struct host_track_entry {
struct
dns_cache_entry
{
char
*
host
;
pjsip_server_addresses
addresses
;
int
ttl
;
time_t
entry_time
;
int
expiration_time
;
AST_LIST_ENTRY
(
dns_cache_entry
)
next
;
};
...
...
@@ -921,6 +920,69 @@ static void sip_check_transport(pj_pool_t *pool, pjsip_transport_type_e transpor
}
}
static
int
dns_cache_get_addr
(
const
char
*
host
,
pjsip_server_addresses
*
addresses
)
{
struct
dns_cache_entry
*
cache_entry
=
NULL
;
int
ret
=
-
1
;
if
(
!
host
||
!
addresses
)
return
-
1
;
AST_LIST_LOCK
(
&
sip_dns_cache
);
AST_LIST_TRAVERSE_SAFE_BEGIN
(
&
sip_dns_cache
,
cache_entry
,
next
)
{
if
(
strcmp
(
host
,
cache_entry
->
host
)
==
0
)
{
if
(
cache_entry
->
expiration_time
>
time
(
NULL
))
{
ast_debug
(
5
,
"cache_entry '%s': record found
\n
"
,
cache_entry
->
host
);
pj_memcpy
(
addresses
,
&
cache_entry
->
addresses
,
sizeof
(
*
addresses
));
ret
=
0
;
}
break
;
}
}
AST_LIST_TRAVERSE_SAFE_END
;
AST_LIST_UNLOCK
(
&
sip_dns_cache
);
return
ret
;
}
static
int
dns_cache_update
(
const
char
*
host
,
pjsip_server_addresses
*
addresses
,
int
ttl
)
{
struct
dns_cache_entry
*
cache_entry
=
NULL
;
struct
dns_cache_entry
*
new_cache_entry
=
NULL
;
int
found
=
0
;
if
(
!
host
||
!
addresses
)
return
-
1
;
AST_LIST_LOCK
(
&
sip_dns_cache
);
AST_LIST_TRAVERSE_SAFE_BEGIN
(
&
sip_dns_cache
,
cache_entry
,
next
)
{
if
(
cache_entry
&&
strcmp
(
host
,
cache_entry
->
host
)
==
0
)
{
ast_debug
(
5
,
"cache_entry '%s' recond found: updating
\n
"
,
cache_entry
->
host
);
pj_memcpy
(
&
cache_entry
->
addresses
,
addresses
,
sizeof
(
*
addresses
));
cache_entry
->
expiration_time
=
time
(
NULL
)
+
ttl
;
found
=
1
;
break
;
}
}
AST_LIST_TRAVERSE_SAFE_END
;
if
(
!
found
)
{
new_cache_entry
=
ast_calloc
(
1
,
sizeof
(
*
new_cache_entry
));
new_cache_entry
->
host
=
strdup
(
host
);
pj_memcpy
(
&
new_cache_entry
->
addresses
,
addresses
,
sizeof
(
*
addresses
));
new_cache_entry
->
expiration_time
=
time
(
NULL
)
+
ttl
;
AST_LIST_INSERT_HEAD
(
&
sip_dns_cache
,
new_cache_entry
,
next
);
ast_debug
(
5
,
"cache_entry '%s': record added
\n
"
,
new_cache_entry
->
host
);
}
AST_LIST_UNLOCK
(
&
sip_dns_cache
);
return
0
;
}
/* External API to set DNS cache function pointers */
void
pjsip_resolver_set_dns_cache
(
dns_cache_get_addr_t
get_addr
,
dns_cache_update_t
update_cache
)
{
...
...
@@ -978,6 +1040,7 @@ void ast_sip_initialize_resolver(void)
{
/* Replace the existing PJSIP resolver with our own implementation */
ast_sip_push_task_wait_servant
(
NULL
,
sip_replace_resolver
,
NULL
);
pjsip_resolver_set_dns_cache
(
dns_cache_get_addr
,
dns_cache_update
);
}
#else
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment