Asterisk - The Open Source Telephony Project  18.5.0
res_hep.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2014, Digium, Inc.
5  *
6  * Alexandr Dubovikov <[email protected]>
7  * Matt Jordan <[email protected]>
8  *
9  * See http://www.asterisk.org for more information about
10  * the Asterisk project. Please do not directly contact
11  * any of the maintainers of this project for assistance;
12  * the project provides a web site, mailing lists and IRC
13  * channels for your use.
14  *
15  * This program is free software, distributed under the terms of
16  * the GNU General Public License Version 2. See the LICENSE file
17  * at the top of the source tree.
18  */
19 
20 /*!
21  * \file
22  * \brief Routines for integration with Homer using HEPv3
23  *
24  * \author Alexandr Dubovikov <[email protected]>
25  * \author Matt Jordan <[email protected]>
26  *
27  */
28 
29 /*!
30  * \li \ref res_hep.c uses the configuration file \ref hep.conf
31  * \addtogroup configuration_file Configuration Files
32  */
33 
34 /*!
35  * \page hep.conf hep.conf
36  * \verbinclude hep.conf.sample
37  */
38 
39 /*** MODULEINFO
40  <support_level>extended</support_level>
41  ***/
42 
43 /*** DOCUMENTATION
44  <configInfo name="res_hep" language="en_US">
45  <synopsis>Resource for integration with Homer using HEPv3</synopsis>
46  <configFile name="hep.conf">
47  <configObject name="general">
48  <synopsis>General settings.</synopsis>
49  <description><para>
50  The <emphasis>general</emphasis> settings section contains information
51  to configure Asterisk as a Homer capture agent.
52  </para>
53  </description>
54  <configOption name="enabled" default="yes">
55  <synopsis>Enable or disable packet capturing.</synopsis>
56  <description>
57  <enumlist>
58  <enum name="no" />
59  <enum name="yes" />
60  </enumlist>
61  </description>
62  </configOption>
63  <configOption name="uuid_type" default="call-id">
64  <synopsis>The preferred type of UUID to pass to Homer.</synopsis>
65  <description>
66  <enumlist>
67  <enum name="call-id"><para>Use the PJSIP Call-Id</para></enum>
68  <enum name="channel"><para>Use the Asterisk channel name</para></enum>
69  </enumlist>
70  </description>
71  </configOption>
72  <configOption name="capture_address">
73  <synopsis>The address and port of the Homer server to send packets to.</synopsis>
74  </configOption>
75  <configOption name="capture_password">
76  <synopsis>If set, the authentication password to send to Homer.</synopsis>
77  </configOption>
78  <configOption name="capture_id" default="0">
79  <synopsis>The ID for this capture agent.</synopsis>
80  </configOption>
81  </configObject>
82  </configFile>
83  </configInfo>
84 ***/
85 
86 #include "asterisk.h"
87 
88 #include "asterisk/module.h"
89 #include "asterisk/astobj2.h"
91 #include "asterisk/taskprocessor.h"
92 #include "asterisk/res_hep.h"
93 
94 #include <netinet/ip.h>
95 #include <netinet/tcp.h>
96 #include <netinet/udp.h>
97 #include <netinet/ip6.h>
98 
99 /*! Generic vendor ID. Used for HEPv3 standard packets */
100 #define GENERIC_VENDOR_ID 0x0000
101 
102 /*! Asterisk vendor ID. Used for custom data to send to a capture node */
103 #define ASTERISK_VENDOR_ID 0x0004
104 
105 /*! Chunk types from the HEPv3 Spec */
107 
108  /*! THE IP PROTOCOL FAMILY */
110 
111  /*! THE IP PROTOCOL ID (UDP, TCP, ETC.) */
113 
114  /*! IF IPV4, THE SOURCE ADDRESS */
116 
117  /*! IF IPV4, THE DESTINATION ADDRESS */
119 
120  /*! IF IPV6, THE SOURCE ADDRESS */
122 
123  /*! IF IPV6, THE DESTINATION ADDRESS */
125 
126  /*! THE SOURCE PORT */
128 
129  /*! THE DESTINATION PORT */
131 
132  /*! THE CAPTURE TIME (SECONDS) */
134 
135  /*! THE CAPTURE TIME (MICROSECONDS) */
137 
138  /*! THE PROTOCOL PACKET TYPE. SEE /REF HEPV3_CAPTURE_TYPE */
140 
141  /*! OUR CAPTURE AGENT ID */
143 
144  /*! A KEEP ALIVE TIMER */
146 
147  /*! THE \REF CAPTURE_PASSWORD IF DEFINED */
149 
150  /*! THE ONE AND ONLY PAYLOAD */
152 
153  /*! THE ONE AND ONLY (ZIPPED) PAYLOAD */
155 
156  /*! THE UUID FOR THIS PACKET */
157  CHUNK_TYPE_UUID = 0X0011,
158 };
159 
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)); \
163  } while (0)
164 
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); \
168  } while (0)
169 
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))); \
173  } while (0)
174 
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); \
178  } while (0)
179 
180 /*
181  * HEPv3 Types.
182  * Note that the content in these is stored in network byte order.
183  */
184 
185 struct hep_chunk {
189 } __attribute__((packed));
190 
192  struct hep_chunk chunk;
194 } __attribute__((packed));
195 
197  struct hep_chunk chunk;
199 } __attribute__((packed));
200 
202  struct hep_chunk chunk;
204 } __attribute__((packed));
205 
207  struct hep_chunk chunk;
208  struct in_addr data;
209 } __attribute__((packed));
210 
212  struct hep_chunk chunk;
213  struct in6_addr data;
214 } __attribute__((packed));
215 
216 struct hep_ctrl {
217  char id[4];
219 } __attribute__((packed));
220 
221 /* HEP structures */
222 
223 struct hep_generic {
224  struct hep_ctrl header;
225  struct hep_chunk_uint8 ip_family;
226  struct hep_chunk_uint8 ip_proto;
227  struct hep_chunk_uint16 src_port;
228  struct hep_chunk_uint16 dst_port;
229  struct hep_chunk_uint32 time_sec;
230  struct hep_chunk_uint32 time_usec;
231  struct hep_chunk_uint8 proto_t;
232  struct hep_chunk_uint32 capt_id;
233 } __attribute__((packed));
234 
235 /*! \brief Global configuration for the module */
237  unsigned int enabled; /*!< Whether or not sending is enabled */
238  unsigned int capture_id; /*!< Capture ID for this agent */
239  enum hep_uuid_type uuid_type; /*!< The preferred type of the UUID */
241  AST_STRING_FIELD(capture_address); /*!< Address to send to */
242  AST_STRING_FIELD(capture_password); /*!< Password for Homer server */
243  );
244 };
245 
246 /*! \brief The actual module config */
247 struct module_config {
248  struct hepv3_global_config *general; /*!< The general config settings */
249 };
250 
251 /*! \brief Run-time data derived from \ref hepv3_global_config */
253  struct ast_sockaddr remote_addr; /*!< The address to send to */
254  int sockfd; /*!< The socket file descriptor */
255 };
256 
257 static struct aco_type global_option = {
258  .type = ACO_GLOBAL,
259  .name = "general",
260  .item_offset = offsetof(struct module_config, general),
261  .category_match = ACO_WHITELIST_EXACT,
262  .category = "general",
263 };
264 
265 struct aco_type *global_options[] = ACO_TYPES(&global_option);
266 
268  .filename = "hep.conf",
269  .types = ACO_TYPES(&global_option),
270 };
271 
272 /*! \brief The module configuration container */
274 
275 /*! \brief Current module data */
276 static AO2_GLOBAL_OBJ_STATIC(global_data);
277 
279 
280 static void *module_config_alloc(void);
281 static int hepv3_config_pre_apply(void);
282 static void hepv3_config_post_apply(void);
283 
284 /*! \brief Register information about the configs being processed by this module */
286  .files = ACO_FILES(&hepv3_conf),
287  .pre_apply_config = hepv3_config_pre_apply,
288  .post_apply_config = hepv3_config_post_apply,
289 );
290 
291 static void hepv3_config_dtor(void *obj)
292 {
293  struct hepv3_global_config *config = obj;
294 
296 }
297 
298 /*! \brief HEPv3 configuration object allocation */
299 static void *hepv3_config_alloc(void)
300 {
301  struct hepv3_global_config *config;
302 
303  config = ao2_alloc(sizeof(*config), hepv3_config_dtor);
304  if (!config || ast_string_field_init(config, 32)) {
305  return NULL;
306  }
307 
308  return config;
309 }
310 
311 /*! \brief Configuration object destructor */
312 static void module_config_dtor(void *obj)
313 {
314  struct module_config *config = obj;
315 
316  if (config->general) {
317  ao2_ref(config->general, -1);
318  }
319 }
320 
321 /*! \brief Module config constructor */
322 static void *module_config_alloc(void)
323 {
324  struct module_config *config;
325 
326  config = ao2_alloc(sizeof(*config), module_config_dtor);
327  if (!config) {
328  return NULL;
329  }
330 
331  config->general = hepv3_config_alloc();
332  if (!config->general) {
333  ao2_ref(config, -1);
334  config = NULL;
335  }
336 
337  return config;
338 }
339 
340 /*! \brief Handler for the uuid_type attribute */
341 static int uuid_type_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
342 {
343  struct hepv3_global_config *global_config = obj;
344 
345  if (strcasecmp(var->name, "uuid_type")) {
346  return -1;
347  }
348 
349  if (!strcasecmp(var->value, "channel")) {
350  global_config->uuid_type = HEP_UUID_TYPE_CHANNEL;
351  } else if (!strcasecmp(var->value, "call-id")) {
352  global_config->uuid_type = HEP_UUID_TYPE_CALL_ID;
353  } else {
354  return -1;
355  }
356  return 0;
357 }
358 
359 /*! \brief HEPv3 run-time data destructor */
360 static void hepv3_data_dtor(void *obj)
361 {
362  struct hepv3_runtime_data *data = obj;
363 
364  if (data->sockfd > -1) {
365  close(data->sockfd);
366  data->sockfd = -1;
367  }
368 }
369 
370 /*! \brief Allocate the HEPv3 run-time data */
372 {
373  struct hepv3_runtime_data *data;
374 
375  data = ao2_alloc(sizeof(*data), hepv3_data_dtor);
376  if (!data) {
377  return NULL;
378  }
379 
380  data->sockfd = -1;
381 
383  ast_log(AST_LOG_WARNING, "Failed to create address from %s\n", config->capture_address);
384  ao2_ref(data, -1);
385  return NULL;
386 
387  }
388 
389  data->sockfd = socket(ast_sockaddr_is_ipv6(&data->remote_addr) ? AF_INET6 : AF_INET, SOCK_DGRAM, 0);
390  if (data->sockfd < 0) {
391  ast_log(AST_LOG_WARNING, "Failed to create socket for address %s: %s\n",
392  config->capture_address, strerror(errno));
393  ao2_ref(data, -1);
394  return NULL;
395  }
396 
397  return data;
398 }
399 
400 /*! \brief Destructor for a \ref hepv3_capture_info object */
401 static void capture_info_dtor(void *obj)
402 {
403  struct hepv3_capture_info *info = obj;
404 
405  ast_free(info->uuid);
406  ast_free(info->payload);
407 }
408 
410 {
412 
413  if (!config) {
414  /* Well, that's unfortunate. Return something. */
415  return HEP_UUID_TYPE_CALL_ID;
416  }
417 
418  return config->general->uuid_type;
419 }
420 
422 {
424 
425  return config && config->general->enabled;
426 }
427 
429 {
430  struct hepv3_capture_info *info;
431 
432  info = ao2_alloc(sizeof(*info), capture_info_dtor);
433  if (!info) {
434  return NULL;
435  }
436 
437  info->payload = ast_malloc(len);
438  if (!info->payload) {
439  ao2_ref(info, -1);
440  return NULL;
441  }
442  memcpy(info->payload, payload, len);
443  info->len = len;
444 
445  /* Set a reasonable default */
446  info->protocol_id = IPPROTO_UDP;
447 
448  return info;
449 }
450 
451 /*! \brief Callback function for the \ref hep_queue_tp taskprocessor */
452 static int hep_queue_cb(void *data)
453 {
455  RAII_VAR(struct hepv3_runtime_data *, hepv3_data, ao2_global_obj_ref(global_data), ao2_cleanup);
456  RAII_VAR(struct hepv3_capture_info *, capture_info, data, ao2_cleanup);
457  struct hep_generic hg_pkt;
458  unsigned int packet_len = 0, sock_buffer_len;
459  struct hep_chunk_ip4 ipv4_src, ipv4_dst;
460  struct hep_chunk_ip6 ipv6_src, ipv6_dst;
461  struct hep_chunk auth_key, payload, uuid;
462  void *sock_buffer;
463  int res;
464 
465  if (!capture_info || !config || !hepv3_data) {
466  return 0;
467  }
468 
469  if (ast_sockaddr_is_ipv4(&capture_info->src_addr) != ast_sockaddr_is_ipv4(&capture_info->dst_addr)) {
470  ast_log(AST_LOG_NOTICE, "Unable to send packet: Address Family mismatch between source/destination\n");
471  return -1;
472  }
473 
474  packet_len = sizeof(hg_pkt);
475 
476  /* Build HEPv3 header, capture info, and calculate the total packet size */
477  memcpy(hg_pkt.header.id, "\x48\x45\x50\x33", 4);
478 
479  INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_proto, CHUNK_TYPE_IP_PROTOCOL_ID, capture_info->protocol_id);
480  INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.src_port, CHUNK_TYPE_SRC_PORT, htons(ast_sockaddr_port(&capture_info->src_addr)));
481  INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.dst_port, CHUNK_TYPE_DST_PORT, htons(ast_sockaddr_port(&capture_info->dst_addr)));
482  INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.time_sec, CHUNK_TYPE_TIMESTAMP_SEC, htonl(capture_info->capture_time.tv_sec));
483  INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.time_usec, CHUNK_TYPE_TIMESTAMP_USEC, htonl(capture_info->capture_time.tv_usec));
484  INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.proto_t, CHUNK_TYPE_PROTOCOL_TYPE, capture_info->capture_type);
485  INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.capt_id, CHUNK_TYPE_CAPTURE_AGENT_ID, htonl(config->general->capture_id));
486 
487  if (ast_sockaddr_is_ipv4(&capture_info->src_addr)) {
490 
492  inet_pton(AF_INET, ast_sockaddr_stringify_addr(&capture_info->src_addr), &ipv4_src.data);
493 
495  inet_pton(AF_INET, ast_sockaddr_stringify_addr(&capture_info->dst_addr), &ipv4_dst.data);
496 
497  packet_len += (sizeof(ipv4_src) + sizeof(ipv4_dst));
498  } else {
501 
503  inet_pton(AF_INET6, ast_sockaddr_stringify_addr(&capture_info->src_addr), &ipv6_src.data);
504 
506  inet_pton(AF_INET6, ast_sockaddr_stringify_addr(&capture_info->dst_addr), &ipv6_dst.data);
507 
508  packet_len += (sizeof(ipv6_src) + sizeof(ipv6_dst));
509  }
510 
511  if (!ast_strlen_zero(config->general->capture_password)) {
512  INITIALIZE_GENERIC_HEP_IDS_VAR(&auth_key, CHUNK_TYPE_AUTH_KEY, strlen(config->general->capture_password));
513  packet_len += (sizeof(auth_key) + strlen(config->general->capture_password));
514  }
515  INITIALIZE_GENERIC_HEP_IDS_VAR(&uuid, CHUNK_TYPE_UUID, strlen(capture_info->uuid));
516  packet_len += (sizeof(uuid) + strlen(capture_info->uuid));
518  capture_info->zipped ? CHUNK_TYPE_PAYLOAD_ZIP : CHUNK_TYPE_PAYLOAD, capture_info->len);
519  packet_len += (sizeof(payload) + capture_info->len);
520  hg_pkt.header.length = htons(packet_len);
521 
522  /* Build the buffer to send */
523  sock_buffer = ast_malloc(packet_len);
524  if (!sock_buffer) {
525  return -1;
526  }
527 
528  /* Copy in the header */
529  memcpy(sock_buffer, &hg_pkt, sizeof(hg_pkt));
530  sock_buffer_len = sizeof(hg_pkt);
531 
532  /* Addresses */
533  if (ast_sockaddr_is_ipv4(&capture_info->src_addr)) {
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);
538  } else {
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);
543  }
544 
545  /* Auth Key */
546  if (!ast_strlen_zero(config->general->capture_password)) {
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);
551  }
552 
553  /* UUID */
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);
558 
559  /* Packet! */
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;
564 
565  ast_assert(sock_buffer_len == packet_len);
566 
567  res = ast_sendto(hepv3_data->sockfd, sock_buffer, sock_buffer_len, 0, &hepv3_data->remote_addr);
568  if (res < 0) {
569  ast_log(AST_LOG_ERROR, "Error [%d] while sending packet to HEPv3 server: %s\n",
570  errno, strerror(errno));
571  } else if (res != sock_buffer_len) {
572  ast_log(AST_LOG_WARNING, "Failed to send complete packet to HEPv3 server: %d of %u sent\n",
573  res, sock_buffer_len);
574  res = -1;
575  }
576 
577  ast_free(sock_buffer);
578  return res;
579 }
580 
581 int hepv3_send_packet(struct hepv3_capture_info *capture_info)
582 {
584  int res;
585 
586  if (!config || !config->general->enabled) {
587  ao2_ref(capture_info, -1);
588  return 0;
589  }
590 
591  res = ast_taskprocessor_push(hep_queue_tp, hep_queue_cb, capture_info);
592  if (res == -1) {
593  ao2_ref(capture_info, -1);
594  }
595 
596  return res;
597 }
598 
599 /*!
600  * \brief Pre-apply callback for the config framework.
601  *
602  * This validates that required fields exist and are populated.
603  */
604 static int hepv3_config_pre_apply(void)
605 {
606  struct module_config *config = aco_pending_config(&cfg_info);
607 
608  if (!config->general->enabled) {
609  /* If we're not enabled, we don't care about anything else */
610  return 0;
611  }
612 
613  if (ast_strlen_zero(config->general->capture_address)) {
614  ast_log(AST_LOG_ERROR, "Missing required configuration option 'capture_address'\n");
615  return -1;
616  }
617 
618  return 0;
619 }
620 
621 /*!
622  * \brief Post-apply callback for the config framework.
623  *
624  * This will create the run-time information from the supplied
625  * configuration.
626  */
627 static void hepv3_config_post_apply(void)
628 {
630  struct hepv3_runtime_data *data;
631 
632  data = hepv3_data_alloc(mod_cfg->general);
633  if (!data) {
634  return;
635  }
636 
637  ao2_global_obj_replace_unref(global_data, data);
638  ao2_ref(data, -1);
639 }
640 
641 /*!
642  * \brief Reload the module
643  */
644 static int reload_module(void)
645 {
646  if (aco_process_config(&cfg_info, 1) == ACO_PROCESS_ERROR) {
647  return -1;
648  }
649  return 0;
650 }
651 
652 /*!
653  * \brief Unload the module
654  */
655 static int unload_module(void)
656 {
657  hep_queue_tp = ast_taskprocessor_unreference(hep_queue_tp);
658 
660  ao2_global_obj_release(global_data);
661  aco_info_destroy(&cfg_info);
662 
663  return 0;
664 }
665 
666 /*!
667  * \brief Load the module
668  */
669 static int load_module(void)
670 {
671  if (aco_info_init(&cfg_info)) {
672  goto error;
673  }
674 
675  hep_queue_tp = ast_taskprocessor_get("hep_queue_tp", TPS_REF_DEFAULT);
676  if (!hep_queue_tp) {
677  goto error;
678  }
679 
680  aco_option_register(&cfg_info, "enabled", ACO_EXACT, global_options, "yes", OPT_BOOL_T, 1, FLDSET(struct hepv3_global_config, enabled));
681  aco_option_register(&cfg_info, "capture_address", ACO_EXACT, global_options, "", OPT_STRINGFIELD_T, 1, STRFLDSET(struct hepv3_global_config, capture_address));
682  aco_option_register(&cfg_info, "capture_password", ACO_EXACT, global_options, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_password));
683  aco_option_register(&cfg_info, "capture_id", ACO_EXACT, global_options, "0", OPT_UINT_T, 0, STRFLDSET(struct hepv3_global_config, capture_id));
684  aco_option_register_custom(&cfg_info, "uuid_type", ACO_EXACT, global_options, "call-id", uuid_type_handler, 0);
685 
686  if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
687  goto error;
688  }
689 
691 
692 error:
693  aco_info_destroy(&cfg_info);
695 }
696 
698  .support_level = AST_MODULE_SUPPORT_EXTENDED,
699  .load = load_module,
700  .unload = unload_module,
702  .load_pri = AST_MODPRI_APP_DEPEND,
703 );
static char * ast_sockaddr_stringify_addr(const struct ast_sockaddr *addr)
Wrapper around ast_sockaddr_stringify_fmt() to return an address only.
Definition: netsock2.h:290
struct aco_type * global_options[]
Definition: res_hep.c:265
struct in_addr data
Definition: res_hep.c:208
#define INITIALIZE_GENERIC_HEP_CHUNK(hep_item, type)
Definition: res_hep.c:170
static int load_module(void)
Load the module.
Definition: res_hep.c:669
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.
Definition: netsock2.c:614
Asterisk main include file. File version handling, generic pbx functions.
Run-time data derived from hepv3_global_config.
Definition: res_hep.c:252
struct hep_ctrl header
Definition: res_hep.c:224
struct hep_chunk_uint32 capt_id
Definition: res_hep.c:232
struct hep_chunk_uint8 ip_family
Definition: res_hep.c:225
int hepv3_send_packet(struct hepv3_capture_info *capture_info)
Send a generic packet capture to HEPv3.
Definition: res_hep.c:581
#define aco_option_register_custom(info, name, matchtype, types, default_val, handler, flags)
Register a config option.
char * config
Definition: conf2ael.c:66
#define INITIALIZE_GENERIC_HEP_IDS_VAR(hep_chunk, type, len)
Definition: res_hep.c:165
unsigned int enabled
Definition: res_hep.c:237
struct hep_chunk_uint8 ip_proto
Definition: res_hep.c:226
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.
#define AST_LOG_WARNING
Definition: logger.h:279
#define var
Definition: ast_expr2f.c:614
struct hep_chunk_uint8 proto_t
Definition: res_hep.c:231
hepv3_chunk_types
Definition: res_hep.c:106
return a reference to a taskprocessor, create one if it does not exist
Definition: taskprocessor.h:75
Routines for integration with Homer using HEPv3.
static int hepv3_config_pre_apply(void)
Pre-apply callback for the config framework.
Definition: res_hep.c:604
enum hep_uuid_type hepv3_get_uuid_type(void)
Get the preferred UUID type.
Definition: res_hep.c:409
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)
Definition: astobj2.h:925
static int reload_module(void)
Reload the module.
Definition: res_hep.c:644
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Definition: stringfields.h:337
#define ast_assert(a)
Definition: utils.h:695
u_int16_t length
Definition: res_hep.c:218
static int unload_module(void)
Unload the module.
Definition: res_hep.c:655
#define NULL
Definition: resample.c:96
The representation of a single configuration file to be processed.
enum aco_type_t type
Socket address structure.
Definition: netsock2.h:97
#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.
Definition: res_hep.c:428
#define ast_strlen_zero(foo)
Definition: strings.h:52
HEPv3 Capture Info.
Definition: res_hep.h:58
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
Definition: netsock2.h:521
#define AST_LOG_NOTICE
Definition: logger.h:268
static void * hepv3_config_alloc(void)
HEPv3 configuration object allocation.
Definition: res_hep.c:299
struct hepv3_global_config * general
Definition: res_hep.c:248
#define ast_log
Definition: astobj2.c:42
u_int16_t length
Definition: res_hep.c:188
static AO2_GLOBAL_OBJ_STATIC(global_config)
The module configuration container.
#define AST_LOG_ERROR
Definition: logger.h:290
#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.
Definition: utils.h:911
Type for default option handler for unsigned integers.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
#define AST_STRING_FIELD(name)
Declare a string field.
Definition: stringfields.h:299
char id[4]
Definition: res_hep.c:217
#define ao2_ref(o, delta)
Definition: astobj2.h:464
enum hep_uuid_type uuid_type
Definition: res_hep.c:239
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.
Definition: netsock2.c:337
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
The configuration settings for this module.
Definition: cdr.c:222
struct in6_addr data
Definition: res_hep.c:213
static int uuid_type_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
Handler for the uuid_type attribute.
Definition: res_hep.c:341
static struct hepv3_runtime_data * hepv3_data_alloc(struct hepv3_global_config *config)
Allocate the HEPv3 run-time data.
Definition: res_hep.c:371
struct ast_sockaddr remote_addr
Definition: res_hep.c:253
Their was an error and no changes were applied.
static void hepv3_config_dtor(void *obj)
Definition: res_hep.c:291
Configuration option-handling.
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
#define ao2_global_obj_release(holder)
Definition: astobj2.h:865
Type for default option handler for bools (ast_true/ast_false)
static struct ast_taskprocessor * hep_queue_tp
Definition: res_hep.c:278
static void capture_info_dtor(void *obj)
Destructor for a hepv3_capture_info object.
Definition: res_hep.c:401
static void module_config_dtor(void *obj)
Configuration object destructor.
Definition: res_hep.c:312
def info(msg)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int errno
static struct aco_type global_option
Definition: res_hep.c:257
int hepv3_is_loaded(void)
Return whether or not we&#39;re currently loaded and active.
Definition: res_hep.c:421
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
unsigned short u_int16_t
#define INITIALIZE_GENERIC_HEP_CHUNK_DATA(hep_item, type, value)
Definition: res_hep.c:175
static void * module_config_alloc(void)
Module config constructor.
Definition: res_hep.c:322
unsigned int capture_id
Definition: res_hep.c:238
#define ast_free(a)
Definition: astmm.h:182
Global configuration for the module.
Definition: res_hep.c:236
static int reload(void)
Definition: cdr_mysql.c:741
struct hep_chunk_uint16 dst_port
Definition: res_hep.c:228
unsigned int u_int32_t
#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.
Definition: module.h:78
hep_uuid_type
Definition: res_hep.h:52
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.
Definition: res_hep.c:360
unsigned char u_int8_t
#define ao2_global_obj_replace_unref(holder, obj)
Definition: astobj2.h:908
#define ACO_FILES(...)
u_int16_t type_id
Definition: res_hep.c:187
A ast_taskprocessor structure is a singleton by name.
Definition: taskprocessor.c:69
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
Definition: res_hep.c:230
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
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.
u_int8_t data
Definition: res_hep.c:193
const char * filename
int ast_sockaddr_is_ipv4(const struct ast_sockaddr *addr)
Determine if the address is an IPv4 address.
Definition: netsock2.c:497
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
Definition: res_hep.c:267
Type for default option handler for stringfields.
struct hep_chunk_uint32 time_sec
Definition: res_hep.c:229
int error(const char *format,...)
Definition: utils/frame.c:999
static void hepv3_config_post_apply(void)
Post-apply callback for the config framework.
Definition: res_hep.c:627
u_int16_t data
Definition: res_hep.c:198
struct hep_chunk_uint16 src_port
Definition: res_hep.c:227
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
struct ast_cdr_config * general
Definition: cdr.c:223
Asterisk module definitions.
static int hep_queue_cb(void *data)
Callback function for the hep_queue_tp taskprocessor.
Definition: res_hep.c:452
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368
int ast_sockaddr_is_ipv6(const struct ast_sockaddr *addr)
Determine if this is an IPv6 address.
Definition: netsock2.c:524
u_int16_t vendor_id
Definition: res_hep.c:186
u_int32_t data
Definition: res_hep.c:203
void * payload
Definition: res_hep.h:66
const ast_string_field capture_address
Definition: res_hep.c:243