res_hep: Add support for named capture agents.

Adds support for the capture agent name field
of the Homer protocol to Asterisk by allowing
users to specify a name that will be sent to
the HEP server.

ASTERISK-30322 #close

Change-Id: I6136583017f9dd08daeb8be02f60fb8df4639a2b
This commit is contained in:
Naveen Albert 2022-11-21 18:53:49 +00:00 committed by George Joseph
parent 97d1613afa
commit 1c5738771d
3 changed files with 29 additions and 1 deletions

View File

@ -22,6 +22,9 @@ capture_password = foo ; If specified, the authorization password
capture_id = 1234 ; A unique integer identifier for this
; server. This ID will be embedded sent
; with each packet from this server.
;capture_name = asterisk ; A unique string identifier for this
; server. This ID will be embedded sent
; with each packet from this server.
uuid_type = call-id ; Specify the preferred source for the Homer
; correlation UUID. Valid options are:
; - 'call-id' for the PJSIP or chan_sip SIP

View File

@ -0,0 +1,5 @@
Subject: Add support for named capture agent.
A name for the capture agent can now be specified
using the capture_name option which, if specified,
will be sent to the HEP server.

View File

@ -78,6 +78,9 @@
<configOption name="capture_id" default="0">
<synopsis>The ID for this capture agent.</synopsis>
</configOption>
<configOption name="capture_name" default="">
<synopsis>The name for this capture agent.</synopsis>
</configOption>
</configObject>
</configFile>
</configInfo>
@ -155,6 +158,9 @@ enum hepv3_chunk_types {
/*! THE UUID FOR THIS PACKET */
CHUNK_TYPE_UUID = 0X0011,
/*! THE CAPTURE AGENT NAME */
CHUNK_TYPE_CAPTURE_AGENT_NAME = 0X0013,
};
#define INITIALIZE_GENERIC_HEP_IDS(hep_chunk, type) do { \
@ -240,6 +246,7 @@ struct hepv3_global_config {
AST_DECLARE_STRING_FIELDS(
AST_STRING_FIELD(capture_address); /*!< Address to send to */
AST_STRING_FIELD(capture_password); /*!< Password for Homer server */
AST_STRING_FIELD(capture_name); /*!< Capture name for this agent */
);
};
@ -458,7 +465,7 @@ static int hep_queue_cb(void *data)
unsigned int packet_len = 0, sock_buffer_len;
struct hep_chunk_ip4 ipv4_src, ipv4_dst;
struct hep_chunk_ip6 ipv6_src, ipv6_dst;
struct hep_chunk auth_key, payload, uuid;
struct hep_chunk auth_key, payload, uuid, capturename;
void *sock_buffer;
int res;
@ -512,6 +519,10 @@ static int hep_queue_cb(void *data)
INITIALIZE_GENERIC_HEP_IDS_VAR(&auth_key, CHUNK_TYPE_AUTH_KEY, strlen(config->general->capture_password));
packet_len += (sizeof(auth_key) + strlen(config->general->capture_password));
}
if (!ast_strlen_zero(config->general->capture_name)) {
INITIALIZE_GENERIC_HEP_IDS_VAR(&capturename, CHUNK_TYPE_CAPTURE_AGENT_NAME, strlen(config->general->capture_name));
packet_len += (sizeof(capturename) + strlen(config->general->capture_name));
}
INITIALIZE_GENERIC_HEP_IDS_VAR(&uuid, CHUNK_TYPE_UUID, strlen(capture_info->uuid));
packet_len += (sizeof(uuid) + strlen(capture_info->uuid));
INITIALIZE_GENERIC_HEP_IDS_VAR(&payload,
@ -556,6 +567,14 @@ static int hep_queue_cb(void *data)
memcpy(sock_buffer + sock_buffer_len, capture_info->uuid, strlen(capture_info->uuid));
sock_buffer_len += strlen(capture_info->uuid);
/* Capture Agent Name */
if (!ast_strlen_zero(config->general->capture_name)) {
memcpy(sock_buffer + sock_buffer_len, &capturename, sizeof(capturename));
sock_buffer_len += sizeof(capturename);
memcpy(sock_buffer + sock_buffer_len, config->general->capture_name, strlen(config->general->capture_name));
sock_buffer_len += strlen(config->general->capture_name);
}
/* Packet! */
memcpy(sock_buffer + sock_buffer_len, &payload, sizeof(payload));
sock_buffer_len += sizeof(payload);
@ -681,6 +700,7 @@ static int load_module(void)
aco_option_register(&cfg_info, "capture_address", ACO_EXACT, global_options, "", OPT_STRINGFIELD_T, 1, STRFLDSET(struct hepv3_global_config, capture_address));
aco_option_register(&cfg_info, "capture_password", ACO_EXACT, global_options, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_password));
aco_option_register(&cfg_info, "capture_id", ACO_EXACT, global_options, "0", OPT_UINT_T, 0, STRFLDSET(struct hepv3_global_config, capture_id));
aco_option_register(&cfg_info, "capture_name", ACO_EXACT, global_options, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_name));
aco_option_register_custom(&cfg_info, "uuid_type", ACO_EXACT, global_options, "call-id", uuid_type_handler, 0);
if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {