94 #include <netinet/ip.h> 95 #include <netinet/tcp.h> 96 #include <netinet/udp.h> 97 #include <netinet/ip6.h> 100 #define GENERIC_VENDOR_ID 0x0000 103 #define ASTERISK_VENDOR_ID 0x0004 160 #define INITIALIZE_GENERIC_HEP_IDS(hep_chunk, type) do { \ 161 (hep_chunk)->vendor_id = htons(GENERIC_VENDOR_ID); \ 162 (hep_chunk)->type_id = htons((type)); \ 165 #define INITIALIZE_GENERIC_HEP_IDS_VAR(hep_chunk, type, len) do { \ 166 INITIALIZE_GENERIC_HEP_IDS((hep_chunk), (type)); \ 167 (hep_chunk)->length = htons(sizeof(*(hep_chunk)) + len); \ 170 #define INITIALIZE_GENERIC_HEP_CHUNK(hep_item, type) do { \ 171 INITIALIZE_GENERIC_HEP_IDS(&(hep_item)->chunk, (type)); \ 172 (hep_item)->chunk.length = htons(sizeof(*(hep_item))); \ 175 #define INITIALIZE_GENERIC_HEP_CHUNK_DATA(hep_item, type, value) do { \ 176 INITIALIZE_GENERIC_HEP_CHUNK((hep_item), (type)); \ 177 (hep_item)->data = (value); \ 189 } __attribute__((packed));
194 } __attribute__((packed));
199 } __attribute__((packed));
204 } __attribute__((packed));
209 } __attribute__((packed));
213 struct in6_addr data;
214 } __attribute__((packed));
219 } __attribute__((packed));
233 } __attribute__((packed));
262 .category =
"general",
345 if (strcasecmp(var->
name,
"uuid_type")) {
349 if (!strcasecmp(var->
value,
"channel")) {
351 }
else if (!strcasecmp(var->
value,
"call-id")) {
418 return config->general->uuid_type;
442 memcpy(info->
payload, payload, len);
458 unsigned int packet_len = 0, sock_buffer_len;
461 struct hep_chunk auth_key, payload, uuid;
465 if (!capture_info || !
config || !hepv3_data) {
470 ast_log(
AST_LOG_NOTICE,
"Unable to send packet: Address Family mismatch between source/destination\n");
474 packet_len =
sizeof(hg_pkt);
477 memcpy(hg_pkt.
header.
id,
"\x48\x45\x50\x33", 4);
497 packet_len += (
sizeof(ipv4_src) +
sizeof(ipv4_dst));
508 packet_len += (
sizeof(ipv6_src) +
sizeof(ipv6_dst));
513 packet_len += (
sizeof(auth_key) + strlen(
config->general->capture_password));
516 packet_len += (
sizeof(uuid) + strlen(capture_info->uuid));
519 packet_len += (
sizeof(payload) + capture_info->len);
529 memcpy(sock_buffer, &hg_pkt,
sizeof(hg_pkt));
530 sock_buffer_len =
sizeof(hg_pkt);
534 memcpy(sock_buffer + sock_buffer_len, &ipv4_src,
sizeof(ipv4_src));
535 sock_buffer_len +=
sizeof(ipv4_src);
536 memcpy(sock_buffer + sock_buffer_len, &ipv4_dst,
sizeof(ipv4_dst));
537 sock_buffer_len +=
sizeof(ipv4_dst);
539 memcpy(sock_buffer + sock_buffer_len, &ipv6_src,
sizeof(ipv6_src));
540 sock_buffer_len +=
sizeof(ipv6_src);
541 memcpy(sock_buffer + sock_buffer_len, &ipv6_dst,
sizeof(ipv6_dst));
542 sock_buffer_len +=
sizeof(ipv6_dst);
547 memcpy(sock_buffer + sock_buffer_len, &auth_key,
sizeof(auth_key));
548 sock_buffer_len +=
sizeof(auth_key);
549 memcpy(sock_buffer + sock_buffer_len,
config->general->capture_password, strlen(
config->general->capture_password));
550 sock_buffer_len += strlen(
config->general->capture_password);
554 memcpy(sock_buffer + sock_buffer_len, &uuid,
sizeof(uuid));
555 sock_buffer_len +=
sizeof(uuid);
556 memcpy(sock_buffer + sock_buffer_len, capture_info->uuid, strlen(capture_info->uuid));
557 sock_buffer_len += strlen(capture_info->uuid);
560 memcpy(sock_buffer + sock_buffer_len, &payload,
sizeof(payload));
561 sock_buffer_len +=
sizeof(payload);
562 memcpy(sock_buffer + sock_buffer_len, capture_info->payload, capture_info->len);
563 sock_buffer_len += capture_info->len;
567 res =
ast_sendto(hepv3_data->sockfd, sock_buffer, sock_buffer_len, 0, &hepv3_data->remote_addr);
571 }
else if (res != sock_buffer_len) {
573 res, sock_buffer_len);
608 if (!config->
general->enabled) {
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
struct aco_type * global_options[]
#define INITIALIZE_GENERIC_HEP_CHUNK(hep_item, type)
static int load_module(void)
Load the module.
ssize_t ast_sendto(int sockfd, const void *buf, size_t len, int flags, const struct ast_sockaddr *dest_addr)
Wrapper around sendto(2) that uses ast_sockaddr.
Asterisk main include file. File version handling, generic pbx functions.
Run-time data derived from hepv3_global_config.
struct hep_chunk_uint32 capt_id
struct hep_chunk_uint8 ip_family
int hepv3_send_packet(struct hepv3_capture_info *capture_info)
Send a generic packet capture to HEPv3.
#define aco_option_register_custom(info, name, matchtype, types, default_val, handler, flags)
Register a config option.
#define INITIALIZE_GENERIC_HEP_IDS_VAR(hep_chunk, type, len)
struct hep_chunk_uint8 ip_proto
struct ast_taskprocessor * ast_taskprocessor_get(const char *name, enum ast_tps_options create)
Get a reference to a taskprocessor with the specified name and create the taskprocessor if necessary...
#define aco_option_register(info, name, matchtype, types, default_val, opt_type, flags,...)
Register a config option.
Structure for variables, used for configurations and for channel variables.
struct hep_chunk_uint8 proto_t
return a reference to a taskprocessor, create one if it does not exist
Routines for integration with Homer using HEPv3.
static int hepv3_config_pre_apply(void)
Pre-apply callback for the config framework.
enum hep_uuid_type hepv3_get_uuid_type(void)
Get the preferred UUID type.
enum aco_process_status aco_process_config(struct aco_info *info, int reload)
Process a config info via the options registered with an aco_info.
#define ao2_global_obj_ref(holder)
static int reload_module(void)
Reload the module.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
static int unload_module(void)
Unload the module.
The representation of a single configuration file to be processed.
Socket address structure.
#define ACO_TYPES(...)
A helper macro to ensure that aco_info types always have a sentinel.
struct hepv3_capture_info * hepv3_create_capture_info(const void *payload, size_t len)
Create a hepv3_capture_info object.
#define ast_strlen_zero(foo)
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
static void * hepv3_config_alloc(void)
HEPv3 configuration object allocation.
struct hepv3_global_config * general
static AO2_GLOBAL_OBJ_STATIC(global_config)
The module configuration container.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
int aco_info_init(struct aco_info *info)
Initialize an aco_info structure.
void * aco_pending_config(struct aco_info *info)
Get pending config changes.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Type for default option handler for unsigned integers.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define AST_STRING_FIELD(name)
Declare a string field.
#define ao2_ref(o, delta)
enum hep_uuid_type uuid_type
int ast_sockaddr_resolve_first_af(struct ast_sockaddr *addr, const char *name, int flag, int family)
Return the first entry from ast_sockaddr_resolve filtered by address family.
#define ast_malloc(len)
A wrapper for malloc()
The configuration settings for this module.
static int uuid_type_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Handler for the uuid_type attribute.
static struct hepv3_runtime_data * hepv3_data_alloc(struct hepv3_global_config *config)
Allocate the HEPv3 run-time data.
struct ast_sockaddr remote_addr
Their was an error and no changes were applied.
static void hepv3_config_dtor(void *obj)
Configuration option-handling.
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
#define ao2_global_obj_release(holder)
Type for default option handler for bools (ast_true/ast_false)
static struct ast_taskprocessor * hep_queue_tp
static void capture_info_dtor(void *obj)
Destructor for a hepv3_capture_info object.
static void module_config_dtor(void *obj)
Configuration object destructor.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static struct aco_type global_option
int hepv3_is_loaded(void)
Return whether or not we're currently loaded and active.
#define ao2_alloc(data_size, destructor_fn)
#define INITIALIZE_GENERIC_HEP_CHUNK_DATA(hep_item, type, value)
static void * module_config_alloc(void)
Module config constructor.
Global configuration for the module.
struct hep_chunk_uint16 dst_port
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
Module has failed to load, may be in an inconsistent state.
An API for managing task processing threads that can be shared across modules.
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
static void hepv3_data_dtor(void *obj)
HEPv3 run-time data destructor.
#define ao2_global_obj_replace_unref(holder, obj)
A ast_taskprocessor structure is a singleton by name.
int ast_taskprocessor_push(struct ast_taskprocessor *tps, int(*task_exe)(void *datap), void *datap) attribute_warn_unused_result
Push a task into the specified taskprocessor queue and signal the taskprocessor thread.
struct hep_chunk_uint32 time_usec
Type information about a category-level configurable object.
void * ast_taskprocessor_unreference(struct ast_taskprocessor *tps)
Unreference the specified taskprocessor and its reference count will decrement.
int ast_sockaddr_is_ipv4(const struct ast_sockaddr *addr)
Determine if the address is an IPv4 address.
CONFIG_INFO_STANDARD(cfg_info, global_config, module_config_alloc,.files=ACO_FILES(&hepv3_conf),.pre_apply_config=hepv3_config_pre_apply,.post_apply_config=hepv3_config_post_apply,)
Register information about the configs being processed by this module.
struct aco_file hepv3_conf
Type for default option handler for stringfields.
struct hep_chunk_uint32 time_sec
int error(const char *format,...)
static void hepv3_config_post_apply(void)
Post-apply callback for the config framework.
struct hep_chunk_uint16 src_port
#define ASTERISK_GPL_KEY
The text the key() function should return.
struct ast_cdr_config * general
Asterisk module definitions.
static int hep_queue_cb(void *data)
Callback function for the hep_queue_tp taskprocessor.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
int ast_sockaddr_is_ipv6(const struct ast_sockaddr *addr)
Determine if this is an IPv6 address.
const ast_string_field capture_address