Asterisk - The Open Source Telephony Project GIT-master-4f2b068
Loading...
Searching...
No Matches
Data Structures | Macros | Functions | Variables
config_system.c File Reference
#include "asterisk.h"
#include <pjsip.h>
#include <pjlib.h>
#include "asterisk/res_pjsip.h"
#include "asterisk/sorcery.h"
#include "include/res_pjsip_private.h"
#include "asterisk/taskpool.h"
#include "asterisk/dns.h"
#include "asterisk/res_pjsip_cli.h"
Include dependency graph for config_system.c:

Go to the source code of this file.

Data Structures

struct  system_config
 

Macros

#define DEFAULT_TIMER_B   32000
 
#define DEFAULT_TIMER_T1   500
 
#define TIMER_T1_MIN   100
 

Functions

void ast_sip_destroy_system (void)
 
void ast_sip_initialize_dns (void)
 
int ast_sip_initialize_system (void)
 
static struct system_configget_system_cfg (void)
 
int sip_cli_print_system (struct ast_sip_cli_context *context)
 
void sip_get_taskpool_options (struct ast_taskpool_options *taskpool_options)
 
static void * system_alloc (const char *name)
 
static int system_apply (const struct ast_sorcery *sorcery, void *obj)
 
static int system_create_resolver_and_set_nameservers (void *data)
 

Variables

static struct ast_taskpool_options sip_taskpool_options
 
static struct ast_sorcerysystem_sorcery
 

Macro Definition Documentation

◆ DEFAULT_TIMER_B

#define DEFAULT_TIMER_B   32000

Definition at line 33 of file config_system.c.

◆ DEFAULT_TIMER_T1

#define DEFAULT_TIMER_T1   500

Definition at line 32 of file config_system.c.

◆ TIMER_T1_MIN

#define TIMER_T1_MIN   100

Definition at line 31 of file config_system.c.

Function Documentation

◆ ast_sip_destroy_system()

void ast_sip_destroy_system ( void  )

Definition at line 258 of file config_system.c.

259{
261}
static struct ast_sorcery * system_sorcery
#define ast_sorcery_unref(sorcery)
Decrease the reference count of a sorcery structure.
Definition sorcery.h:1500

References ast_sorcery_unref, and system_sorcery.

Referenced by unload_pjsip().

◆ ast_sip_initialize_dns()

void ast_sip_initialize_dns ( void  )

Definition at line 327 of file config_system.c.

328{
330}
static int system_create_resolver_and_set_nameservers(void *data)
#define ast_sip_push_task_wait_servant(serializer, sip_task, task_data)
Definition res_pjsip.h:2133
#define NULL
Definition resample.c:96

References ast_sip_push_task_wait_servant, NULL, and system_create_resolver_and_set_nameservers().

Referenced by load_module(), and reload_configuration_task().

◆ ast_sip_initialize_system()

int ast_sip_initialize_system ( void  )

Definition at line 178 of file config_system.c.

179{
180 RAII_VAR(struct ao2_container *, system_configs, NULL, ao2_cleanup);
181 RAII_VAR(struct system_config *, system, NULL, ao2_cleanup);
182
184 if (!system_sorcery) {
185 ast_log(LOG_ERROR, "Failed to open SIP system sorcery\n");
186 return -1;
187 }
188
189 ast_sorcery_apply_default(system_sorcery, "system", "config", "pjsip.conf,criteria=type=system,single_object=yes,explicit_name=system");
190
192 ast_log(LOG_ERROR, "Failed to register with sorcery (is res_sorcery_config loaded?)\n");
195 return -1;
196 }
197
198 ast_sorcery_object_field_register(system_sorcery, "system", "type", "", OPT_NOOP_T, 0, 0);
200 OPT_UINT_T, 0, FLDSET(struct system_config, timert1));
202 OPT_UINT_T, 0, FLDSET(struct system_config, timerb));
203 ast_sorcery_object_field_register(system_sorcery, "system", "compact_headers", "no",
204 OPT_BOOL_T, 1, FLDSET(struct system_config, compactheaders));
205 ast_sorcery_object_field_register(system_sorcery, "system", "taskpool_minimum_size", "4",
206 OPT_UINT_T, 0, FLDSET(struct system_config, taskpool.minimum_size));
207 ast_sorcery_object_field_register(system_sorcery, "system", "taskpool_initial_size", "4",
208 OPT_UINT_T, 0, FLDSET(struct system_config, taskpool.initial_size));
209 ast_sorcery_object_field_register(system_sorcery, "system", "threadpool_initial_size", "4",
210 OPT_UINT_T, 0, FLDSET(struct system_config, taskpool.initial_size));
211 ast_sorcery_object_field_register(system_sorcery, "system", "taskpool_auto_increment", "1",
212 OPT_UINT_T, 0, FLDSET(struct system_config, taskpool.auto_increment));
213 ast_sorcery_object_field_register(system_sorcery, "system", "threadpool_auto_increment", "1",
214 OPT_UINT_T, 0, FLDSET(struct system_config, taskpool.auto_increment));
215 ast_sorcery_object_field_register(system_sorcery, "system", "taskpool_idle_timeout", "60",
216 OPT_UINT_T, 0, FLDSET(struct system_config, taskpool.idle_timeout));
217 ast_sorcery_object_field_register(system_sorcery, "system", "threadpool_idle_timeout", "60",
218 OPT_UINT_T, 0, FLDSET(struct system_config, taskpool.idle_timeout));
219 ast_sorcery_object_field_register(system_sorcery, "system", "taskpool_max_size", "50",
220 OPT_UINT_T, 0, FLDSET(struct system_config, taskpool.max_size));
221 ast_sorcery_object_field_register(system_sorcery, "system", "threadpool_max_size", "50",
222 OPT_UINT_T, 0, FLDSET(struct system_config, taskpool.max_size));
223 ast_sorcery_object_field_register(system_sorcery, "system", "disable_tcp_switch", "yes",
224 OPT_BOOL_T, 1, FLDSET(struct system_config, disable_tcp_switch));
225 ast_sorcery_object_field_register(system_sorcery, "system", "follow_early_media_fork", "yes",
226 OPT_BOOL_T, 1, FLDSET(struct system_config, follow_early_media_fork));
227 ast_sorcery_object_field_register(system_sorcery, "system", "accept_multiple_sdp_answers", "no",
228 OPT_BOOL_T, 1, FLDSET(struct system_config, accept_multiple_sdp_answers));
229 ast_sorcery_object_field_register(system_sorcery, "system", "disable_rport", "no",
230 OPT_BOOL_T, 1, FLDSET(struct system_config, disable_rport));
231
233
234 system_configs = ast_sorcery_retrieve_by_fields(system_sorcery, "system",
236
237 if (ao2_container_count(system_configs)) {
238 return 0;
239 }
240
241 /* No config present, allocate one and apply defaults */
242 system = ast_sorcery_alloc(system_sorcery, "system", NULL);
243 if (!system) {
244 ast_log(LOG_ERROR, "Unable to allocate default system config.\n");
246 return -1;
247 }
248
249 if (system_apply(system_sorcery, system)) {
250 ast_log(LOG_ERROR, "Failed to apply default system config.\n");
252 return -1;
253 }
254
255 return 0;
256}
#define __stringify(x)
Definition asterisk.h:216
#define ast_log
Definition astobj2.c:42
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_cleanup(obj)
Definition astobj2.h:1934
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
@ OPT_UINT_T
Type for default option handler for unsigned integers.
@ OPT_NOOP_T
Type for a default handler that should do nothing.
@ OPT_BOOL_T
Type for default option handler for bools (ast_true/ast_false)
static int system_apply(const struct ast_sorcery *sorcery, void *obj)
#define DEFAULT_TIMER_B
#define DEFAULT_TIMER_T1
static void * system_alloc(const char *name)
#define LOG_ERROR
static struct ast_taskpool * taskpool
Taskpool for observers.
Definition sorcery.c:87
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
Definition sorcery.h:120
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
Definition sorcery.h:123
void ast_sorcery_load(const struct ast_sorcery *sorcery)
Inform any wizards to load persistent objects.
Definition sorcery.c:1441
#define ast_sorcery_object_register_no_reload(sorcery, type, alloc, transform, apply)
Register an object type that is not reloadable.
Definition sorcery.h:852
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
Definition sorcery.h:955
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
Definition sorcery.c:1808
#define ast_sorcery_apply_default(sorcery, type, name, data)
Definition sorcery.h:476
#define ast_sorcery_open()
Open a new sorcery structure.
Definition sorcery.h:406
void * ast_sorcery_retrieve_by_fields(const struct ast_sorcery *sorcery, const char *type, unsigned int flags, struct ast_variable *fields)
Retrieve an object or multiple objects using specific fields.
Definition sorcery.c:1961
Generic container type.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981

References __stringify, system_config::accept_multiple_sdp_answers, ao2_cleanup, ao2_container_count(), ast_log, AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sorcery_alloc(), ast_sorcery_apply_default, ast_sorcery_load(), ast_sorcery_object_field_register, ast_sorcery_object_register_no_reload, ast_sorcery_open, ast_sorcery_retrieve_by_fields(), ast_sorcery_unref, system_config::compactheaders, DEFAULT_TIMER_B, DEFAULT_TIMER_T1, system_config::disable_rport, system_config::disable_tcp_switch, FLDSET, system_config::follow_early_media_fork, LOG_ERROR, NULL, OPT_BOOL_T, OPT_NOOP_T, OPT_UINT_T, RAII_VAR, system_alloc(), system_apply(), system_sorcery, taskpool, system_config::timerb, and system_config::timert1.

Referenced by load_module().

◆ get_system_cfg()

static struct system_config * get_system_cfg ( void  )
static

Definition at line 144 of file config_system.c.

145{
146 struct system_config *cfg;
147 struct ao2_container *systems;
150
151 if (!systems) {
152 return NULL;
153 }
154
155 cfg = ao2_find(systems, NULL, 0);
156 ao2_ref(systems, -1);
157 return cfg;
158}
#define ao2_find(container, arg, flags)
Definition astobj2.h:1736
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459

References ao2_find, ao2_ref, AST_RETRIEVE_FLAG_ALL, AST_RETRIEVE_FLAG_MULTIPLE, ast_sorcery_retrieve_by_fields(), NULL, and system_sorcery.

Referenced by sip_cli_print_system().

◆ sip_cli_print_system()

int sip_cli_print_system ( struct ast_sip_cli_context context)

Definition at line 160 of file config_system.c.

161{
162 struct system_config *cfg = get_system_cfg();
163
164 if (!cfg) {
165 cfg = ast_sorcery_alloc(system_sorcery, "system", NULL);
166 if (!cfg) {
167 return -1;
168 }
169 }
170
171 ast_str_append(&context->output_buffer, 0, "\nSystem Settings:\n\n");
173
174 ao2_ref(cfg, -1);
175 return 0;
176}
static struct system_config * get_system_cfg(void)
int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags)
Prints a sorcery object's ast_variable list.
Definition pjsip_cli.c:36
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139

References ao2_ref, ast_sip_cli_print_sorcery_objectset(), ast_sorcery_alloc(), ast_str_append(), get_system_cfg(), NULL, and system_sorcery.

Referenced by cli_show_settings().

◆ sip_get_taskpool_options()

void sip_get_taskpool_options ( struct ast_taskpool_options taskpool_options)

Definition at line 72 of file config_system.c.

73{
75}
static struct ast_taskpool_options sip_taskpool_options
static struct aco_type * taskpool_options[]
Definition stasis.c:2421

References sip_taskpool_options, and taskpool_options.

Referenced by load_module().

◆ system_alloc()

static void * system_alloc ( const char *  name)
static

Definition at line 79 of file config_system.c.

80{
81 struct system_config *system = ast_sorcery_generic_alloc(sizeof(*system), NULL);
82
83 if (!system) {
84 return NULL;
85 }
86
87 return system;
88}
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
Definition sorcery.c:1792

References ast_sorcery_generic_alloc(), and NULL.

Referenced by ast_sip_initialize_system().

◆ system_apply()

static int system_apply ( const struct ast_sorcery sorcery,
void *  obj 
)
static

Definition at line 90 of file config_system.c.

91{
92 struct system_config *system = obj;
93 int min_timerb;
94
95 if (system->timert1 < TIMER_T1_MIN) {
96 ast_log(LOG_WARNING, "Timer T1 setting is too low. Setting to %d\n", TIMER_T1_MIN);
97 system->timert1 = TIMER_T1_MIN;
98 }
99
100 min_timerb = 64 * system->timert1;
101
102 if (system->timerb < min_timerb) {
103 ast_log(LOG_WARNING, "Timer B setting is too low. Setting to %d\n", min_timerb);
104 system->timerb = min_timerb;
105 }
106
107 pjsip_cfg()->tsx.t1 = system->timert1;
108 pjsip_cfg()->tsx.td = system->timerb;
109
110 pjsip_cfg()->endpt.follow_early_media_fork = system->follow_early_media_fork;
111#ifdef HAVE_PJSIP_INV_ACCEPT_MULTIPLE_SDP_ANSWERS
112 pjsip_cfg()->endpt.accept_multiple_sdp_answers = system->accept_multiple_sdp_answers;
113#else
114 if (system->accept_multiple_sdp_answers) {
116 "The accept_multiple_sdp_answers flag is not supported in this version of pjproject. Ignoring\n");
117 }
118#endif
119
120 if (system->compactheaders) {
121#ifdef HAVE_PJSIP_ENDPOINT_COMPACT_FORM
122 pjsip_cfg()->endpt.use_compact_form = PJ_TRUE;
123#else
124 extern pj_bool_t pjsip_use_compact_form;
125
126 pjsip_use_compact_form = PJ_TRUE;
127#endif
128 }
129
135
136 pjsip_cfg()->endpt.disable_tcp_switch =
137 system->disable_tcp_switch ? PJ_TRUE : PJ_FALSE;
138
139 pjsip_cfg()->endpt.disable_rport = system->disable_rport ? PJ_TRUE : PJ_FALSE;
140
141 return 0;
142}
#define TIMER_T1_MIN
#define LOG_WARNING
int idle_timeout
Time limit in seconds for idle dynamic taskprocessors.
Definition taskpool.h:88
int max_size
Maximum number of taskprocessors a pool may have.
Definition taskpool.h:122
int auto_increment
Number of taskprocessors to increment the pool by.
Definition taskpool.h:92
int minimum_size
Number of taskprocessors that will always exist.
Definition taskpool.h:99
int initial_size
Number of taskprocessors the pool will start with.
Definition taskpool.h:109
unsigned int timert1
struct system_config::@490 taskpool
unsigned int compactheaders
unsigned int timerb
unsigned int disable_rport
unsigned int disable_tcp_switch
unsigned int follow_early_media_fork
unsigned int accept_multiple_sdp_answers

References system_config::accept_multiple_sdp_answers, ast_log, ast_taskpool_options::auto_increment, system_config::auto_increment, system_config::compactheaders, system_config::disable_rport, system_config::disable_tcp_switch, system_config::follow_early_media_fork, ast_taskpool_options::idle_timeout, system_config::idle_timeout, ast_taskpool_options::initial_size, system_config::initial_size, LOG_WARNING, ast_taskpool_options::max_size, system_config::max_size, ast_taskpool_options::minimum_size, system_config::minimum_size, sip_taskpool_options, system_config::taskpool, TIMER_T1_MIN, system_config::timerb, and system_config::timert1.

Referenced by ast_sip_initialize_system().

◆ system_create_resolver_and_set_nameservers()

static int system_create_resolver_and_set_nameservers ( void *  data)
static

Definition at line 263 of file config_system.c.

264{
265 struct ao2_container *discovered_nameservers;
266 struct ao2_iterator it_nameservers;
267 char *nameserver;
268 pj_status_t status;
269 pj_dns_resolver *resolver;
270 pj_str_t nameservers[PJ_DNS_RESOLVER_MAX_NS];
271 unsigned int count = 0;
272
273 discovered_nameservers = ast_dns_get_nameservers();
274 if (!discovered_nameservers) {
275 ast_log(LOG_ERROR, "Could not retrieve local system nameservers, resorting to system resolution\n");
276 return 0;
277 }
278
279 if (!ao2_container_count(discovered_nameservers)) {
280 ast_log(LOG_ERROR, "There are no local system nameservers configured, resorting to system resolution\n");
281 ao2_ref(discovered_nameservers, -1);
282 return -1;
283 }
284
285 if (!(resolver = pjsip_endpt_get_resolver(ast_sip_get_pjsip_endpoint()))) {
286 status = pjsip_endpt_create_resolver(ast_sip_get_pjsip_endpoint(), &resolver);
287 if (status != PJ_SUCCESS) {
288 ast_log(LOG_ERROR, "Could not create DNS resolver(%d), resorting to system resolution\n", status);
289 ao2_ref(discovered_nameservers, -1);
290 return 0;
291 }
292 }
293
294 it_nameservers = ao2_iterator_init(discovered_nameservers, 0);
295 while ((nameserver = ao2_iterator_next(&it_nameservers))) {
296 pj_strset2(&nameservers[count++], nameserver);
297 ao2_ref(nameserver, -1);
298
299 if (count == (PJ_DNS_RESOLVER_MAX_NS - 1)) {
300 break;
301 }
302 }
303 ao2_iterator_destroy(&it_nameservers);
304
305 status = pj_dns_resolver_set_ns(resolver, count, nameservers, NULL);
306
307 /* Since we no longer need the nameservers we can drop the list of them */
308 ao2_ref(discovered_nameservers, -1);
309
310 if (status != PJ_SUCCESS) {
311 ast_log(LOG_ERROR, "Could not set nameservers on DNS resolver in PJSIP(%d), resorting to system resolution\n",
312 status);
313 return 0;
314 }
315
316 if (!pjsip_endpt_get_resolver(ast_sip_get_pjsip_endpoint())) {
317 status = pjsip_endpt_set_resolver(ast_sip_get_pjsip_endpoint(), resolver);
318 if (status != PJ_SUCCESS) {
319 ast_log(LOG_ERROR, "Could not set DNS resolver in PJSIP(%d), resorting to system resolution\n", status);
320 return 0;
321 }
322 }
323
324 return 0;
325}
jack_status_t status
Definition app_jack.c:149
#define ao2_iterator_next(iter)
Definition astobj2.h:1911
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
struct ao2_container * ast_dns_get_nameservers(void)
Retrieve the configured nameservers of the system.
Definition dns.c:581
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition res_pjsip.c:514
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition astobj2.h:1821

References ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_ref, ast_dns_get_nameservers(), ast_log, ast_sip_get_pjsip_endpoint(), LOG_ERROR, NULL, and status.

Referenced by ast_sip_initialize_dns().

Variable Documentation

◆ sip_taskpool_options

struct ast_taskpool_options sip_taskpool_options
static
Initial value:
= {
}
#define AST_TASKPOOL_OPTIONS_VERSION
Definition taskpool.h:76

Definition at line 68 of file config_system.c.

68 {
70};

Referenced by sip_get_taskpool_options(), and system_apply().

◆ system_sorcery

struct ast_sorcery* system_sorcery
static