136#define HOSTS_BUCKETS 53
204 struct pjsip_rx_data *rdata = arg;
206 pj_str_t pj_header_name;
218 (
header = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &pj_header_name,
header));
236 pos = strchr(
buf,
':');
253 ast_debug(3,
"Identify '%s': SIP message has '%s' header but value '%s' does not match '%s'.\n",
259 if (!header_present) {
260 ast_debug(3,
"Identify '%s': SIP message does not have '%s' header.\n",
271 struct pjsip_rx_data *rdata = arg;
273 char buf[PJSIP_MAX_URL_SIZE];
280 len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, rdata->msg_info.msg->line.req.uri,
buf,
sizeof(
buf) - 1);
295 ast_debug(3,
"Identify '%s': request URI not match '%s' (value='%s').\n",
311 ast_debug(3,
"Source address %s matches identify '%s'\n",
316 ast_debug(3,
"Source address %s does not match identify '%s'\n",
333 ast_debug(3,
"No identify sections to match against\n");
343 match->endpoint_name);
345 ast_debug(3,
"Identify '%s' SIP message matched to endpoint %s\n",
348 ast_log(
LOG_WARNING,
"Identify '%s' points to endpoint '%s' but endpoint could not be found\n",
392 int num_addrs = 0,
error = 0, i;
400 for (i = 0; i < num_addrs; ++i) {
429 unsigned short srvport;
458 char *current_string;
473 mask = strrchr(current_string,
'/');
481 ast_log(
LOG_ERROR,
"Failed to add address '%s' to ip endpoint identifier '%s'\n",
489 if (!identify->
hosts) {
491 if (!identify->
hosts) {
492 ast_log(
LOG_ERROR,
"Failed to create container to store hosts on ip endpoint identifier '%s'\n",
500 ast_log(
LOG_ERROR,
"Failed to store host '%s' for resolution on ip endpoint identifier '%s'\n",
513 char *current_string;
540 c_value = strchr(c_header,
':');
542 ast_log(
LOG_ERROR,
"Identify '%s' missing ':' separator in match_header '%s'.\n",
551 ast_log(
LOG_ERROR,
"Identify '%s' has no SIP header to match in match_header '%s'.\n",
556 if (!strcmp(c_value,
"//")) {
566 len = strlen(c_value);
567 if (2 <
len && c_value[0] ==
'/' && c_value[
len - 1] ==
'/') {
569 c_value[
len - 1] =
'\0';
572 if (regcomp(&identify->
regex_header_buf, c_value, REG_EXTENDED | REG_NOSUB)) {
573 ast_log(
LOG_ERROR,
"Identify '%s' failed to compile match_request_uri regex '%s'.\n",
588 if (!strcmp(c_string,
"//")) {
593 if (2 <
len && c_string[0] ==
'/' && c_string[
len - 1] ==
'/') {
595 c_string[
len - 1] =
'\0';
599 ast_log(
LOG_ERROR,
"Identify '%s' failed to compile match_header regex '%s'.\n",
607 if (!identify->
hosts) {
619 char *colon = strrchr(current_string,
':');
629 current_string, results);
633 current_string, results);
644 ast_log(
LOG_WARNING,
"Identify '%s' provided address '%s' did not resolve to any address\n",
646 }
else if (results == -1) {
647 ast_log(
LOG_ERROR,
"Identify '%s' failed when adding resolution results of '%s'\n",
697 for (; ha; ha = ha->
next) {
830 "%*s: <Identify/Endpoint%*.*s>\n",
839 "%*s: <criteria%*.*s>\n",
898 if (
context->indent_level == 0) {
904 || (
context->show_details_only_level_0 &&
context->indent_level == 0)) {
925 .
command =
"pjsip list identifies",
926 .
usage =
"Usage: pjsip list identifies [ like <pattern> ]\n"
927 " List the configured PJSIP Identifies\n"
928 " Optional regular expression pattern is used to filter the list.\n"),
930 .
command =
"pjsip show identifies",
931 .
usage =
"Usage: pjsip show identifies [ like <pattern> ]\n"
932 " Show the configured PJSIP Identifies\n"
933 " Optional regular expression pattern is used to filter the list.\n"),
935 .
command =
"pjsip show identify",
936 .
usage =
"Usage: pjsip show identify <id>\n"
937 " Show the configured PJSIP Identify\n"),
1008 .
requires =
"res_pjsip",
Access Control of various sorts.
void ast_free_ha(struct ast_ha *ha)
Free a list of HAs.
enum ast_acl_sense ast_apply_ha(const struct ast_ha *ha, const struct ast_sockaddr *addr)
Apply a set of rules to a given IP address.
void ast_ha_join(const struct ast_ha *ha, struct ast_str **buf)
Convert HAs to a comma separated string value.
struct ast_ha * ast_append_ha_with_port(const char *sense, const char *stuff, struct ast_ha *path, int *error)
Add a new rule with optional port to a list of HAs.
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdup(str)
A wrapper for strdup()
#define ast_strdupa(s)
duplicate a string in memory from the stack
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy all object references in the src container into the dest container.
#define ao2_iterator_next(iter)
@ AO2_ALLOC_OPT_LOCK_NOLOCK
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define ao2_callback_data(container, flags, cb_fn, arg, data)
int() ao2_callback_fn(void *obj, void *arg, int flags)
Type of a generic callback function.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
#define ao2_alloc(data_size, destructor_fn)
enum ast_cc_service_type service
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
#define AST_CLI_DEFINE(fn, txt,...)
#define ast_cli_register_multiple(e, len)
Register multiple commands.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
@ 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)
@ OPT_STRINGFIELD_T
Type for default option handler for stringfields.
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void astman_append(struct mansession *s, const char *fmt,...)
static char prefix[MAX_PREFIX]
char * strsep(char **str, const char *delims)
#define ast_variable_new(name, value, filename)
#define ast_variable_list_append(head, new_var)
#define ast_debug(level,...)
Log a DEBUG message.
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
Asterisk module definitions.
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
@ AST_MODPRI_CHANNEL_DEPEND
@ AST_MODULE_SUPPORT_CORE
#define ASTERISK_GPL_KEY
The text the key() function should return.
@ AST_MODULE_LOAD_SUCCESS
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
int ast_sockaddr_cidr_bits(const struct ast_sockaddr *sa)
Count the 1 bits in a netmask.
static char * ast_sockaddr_stringify(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() with default format.
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str, int flags, int family)
Parses a string with an IPv4 or IPv6 address and place results into an array.
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
struct ao2_container * container
void ast_sip_unregister_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier)
Unregister a SIP endpoint identifier.
void ast_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Register an endpoint formatter.
void ast_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj)
Unregister an endpoint formatter.
int ast_sip_sorcery_object_to_ami(const void *obj, struct ast_str **buf)
Converts a sorcery object to a string of object properties.
int ast_sip_register_endpoint_identifier_with_name(struct ast_sip_endpoint_identifier *identifier, const char *name)
Register a SIP endpoint identifier with a name.
struct ast_str * ast_sip_create_ami_event(const char *event, struct ast_sip_ami *ami)
Creates a string to store AMI event data in.
struct ast_sorcery * ast_sip_get_sorcery(void)
Get a pointer to the SIP sorcery structure.
int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Unregisters a CLI formatter.
#define CLI_HEADER_FILLER
int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags)
Prints a sorcery object's ast_variable list.
char * ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
#define CLI_INDENT_TO_SPACES(x)
int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter)
Registers a CLI formatter.
static int sip_identify_to_ami(const struct ip_identify_match *identify, struct ast_str **buf)
static int request_identify_match_check(void *obj, void *arg, int flags)
Comparator function for matching an object by request URI.
static int cli_print_header(void *obj, void *arg, int flags)
static int cli_iterator(void *container, ao2_callback_fn callback, void *args)
static void * ip_identify_alloc(const char *name)
Allocator function for a matching object.
static int ip_identify_match_check(void *obj, void *arg, int flags)
Comparator function for matching an object by IP address.
static struct ast_sip_endpoint_identifier request_identifier
static int format_ami_endpoint_identify(const struct ast_sip_endpoint *endpoint, struct ast_sip_ami *ami)
static int ip_identify_match_srv_lookup(struct ip_identify_match *identify, const char *prefix, const char *host, int results)
Helper function which performs an SRV lookup and then resolves the hostname.
static struct ast_sip_endpoint * ip_identify(pjsip_rx_data *rdata)
static int reload_module(void)
static int ip_identify_apply(const struct ast_sorcery *sorcery, void *obj)
Apply handler for identify type.
static int ip_identify_match_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Custom handler for match field.
static struct ast_sip_endpoint_identifier header_identifier
#define HOSTS_BUCKETS
The number of buckets for storing hosts for resolution.
static void * cli_retrieve_by_id(const char *id)
static int send_identify_ami_event(void *obj, void *arg, void *data, int flags)
static void ip_identify_destroy(void *obj)
Destructor function for a matching object.
static int ip_identify_match_host_lookup(struct ip_identify_match *identify, const char *host)
Helper function which performs a host lookup and adds result to identify match.
static struct ast_cli_entry cli_identify[]
static void match_to_var_list_append(struct ast_variable **head, struct ast_ha *ha)
static struct ao2_container * cli_get_container(const char *regex)
static struct ast_sip_endpoint * request_identify(pjsip_rx_data *rdata)
struct ast_sip_endpoint_formatter endpoint_identify_formatter
static int load_module(void)
static int cli_print_body(void *obj, void *arg, int flags)
static struct ast_sip_endpoint * header_identify(pjsip_rx_data *rdata)
static char * my_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int unload_module(void)
static struct ast_sip_endpoint * common_identify(ao2_callback_fn *identify_match_cb, void *arg)
static struct ast_sip_cli_formatter_entry * cli_formatter
static int header_identify_match_check(void *obj, void *arg, int flags)
Comparator function for matching an object by header.
static struct ast_sip_endpoint_identifier ip_identifier
static int match_to_str(const void *obj, const intptr_t *args, char **buf)
static int match_to_var_list(const void *obj, struct ast_variable **fields)
static struct ast_sorcery * sorcery
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
@ AST_RETRIEVE_FLAG_MULTIPLE
Return all matching objects.
@ AST_RETRIEVE_FLAG_ALL
Perform no matching, return all objects.
void ast_sorcery_object_set_has_dynamic_contents(const void *object)
Set the dynamic contents flag on a sorcery object.
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
#define ast_sorcery_object_register(sorcery, type, alloc, transform, apply)
Register an object type.
struct ao2_container * ast_sorcery_retrieve_by_regex(const struct ast_sorcery *sorcery, const char *type, const char *regex)
Retrieve multiple objects using a regular expression on their id.
void ast_sorcery_load_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to load persistent objects.
#define ast_sorcery_object_field_register_custom(sorcery, type, name, default_val, config_handler, sorcery_handler, multiple_handler, flags,...)
Register a field within an object with custom handlers.
void * ast_sorcery_generic_alloc(size_t size, ao2_destructor_fn destructor)
Allocate a generic sorcery capable object.
int ast_sorcery_object_id_compare(void *obj, void *arg, int flags)
ao2 object comparator based on sorcery id.
#define ast_sorcery_apply_config(sorcery, name)
#define ast_sorcery_object_field_register(sorcery, type, name, default_val, opt_type, flags,...)
Register a field within an object.
int ast_sorcery_object_id_sort(const void *obj, const void *arg, int flags)
ao2 object sorter based on sorcery id.
#define MAX_OBJECT_FIELD
Maximum length of an object field name.
#define ast_sorcery_apply_default(sorcery, type, name, data)
void ast_sorcery_reload_object(const struct ast_sorcery *sorcery, const char *type)
Inform any wizards of a specific object type to reload persistent objects.
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.
void ast_srv_cleanup(struct srv_context **context)
Cleanup resources associated with ast_srv_lookup.
int ast_srv_lookup(struct srv_context **context, const char *service, const char **host, unsigned short *port)
Retrieve set of SRV lookups, in order.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
struct ao2_container * ast_str_container_alloc_options(enum ao2_alloc_opts opts, int buckets)
Allocates a hash container for bare strings.
int ast_str_container_add(struct ao2_container *str_container, const char *add)
Adds a string to a string container allocated by ast_str_container_alloc.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
descriptor for a cli entry.
internal representation of ACL entries In principle user applications would have no need for this,...
struct ast_sockaddr netmask
CLI Formatter Context passed to all formatters.
CLI Formatter Registry Entry.
int(* iterate)(void *container, ao2_callback_fn callback, void *args)
ao2_callback_fn * print_header
void *(* retrieve_by_id)(const char *id)
const char *(* get_id)(const void *obj)
ao2_callback_fn * print_body
struct ao2_container *(* get_container)(const char *regex)
An entity responsible for identifying the source of a SIP message.
struct ast_sip_endpoint *(* identify_endpoint)(pjsip_rx_data *rdata)
Callback used to identify the source of a message. See ast_sip_identify_endpoint for more details.
An entity with which Asterisk communicates.
Socket address structure.
Full structure for sorcery.
Support for dynamic strings.
Structure for variables, used for configurations and for channel variables.
Structure for an IP identification matching object.
struct ao2_container * hosts
Hosts to be resolved when applying configuration.
SORCERY_OBJECT(details)
Sorcery object details.
const ast_string_field match_header
struct ast_ha * matches
Networks or addresses that should match this.
regex_t regex_request_uri_buf
unsigned int srv_lookups
Perform SRV resolution of hostnames.
const ast_string_field match_request_uri
const ast_string_field endpoint_name
const ast_string_field match_header_value
unsigned int is_header_regex
const ast_string_field match_header_name
unsigned int is_request_uri_regex
int error(const char *format,...)
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.