res_hep.c File Reference

Routines for integration with Homer using HEPv3. More...

#include "asterisk.h"
#include "asterisk/module.h"
#include "asterisk/astobj2.h"
#include "asterisk/config_options.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/res_hep.h"
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <netinet/ip6.h>

Include dependency graph for res_hep.c:

Go to the source code of this file.

Data Structures

struct  hep_chunk
struct  hep_chunk_ip4
struct  hep_chunk_ip6
struct  hep_chunk_uint16
struct  hep_chunk_uint32
struct  hep_chunk_uint8
struct  hep_ctrl
struct  hep_generic
struct  hepv3_global_config
 Global configuration for the module. More...
struct  hepv3_runtime_data
 Run-time data derived from hepv3_global_config. More...
struct  module_config
 The configuration settings for this module. More...

Defines

#define ASTERISK_VENDOR_ID   0x0004
#define DEFAULT_HEP_SERVER   ""
#define GENERIC_VENDOR_ID   0x0000
#define INITIALIZE_GENERIC_HEP_CHUNK(hep_item, type)
#define INITIALIZE_GENERIC_HEP_CHUNK_DATA(hep_item, type, value)
#define INITIALIZE_GENERIC_HEP_IDS(hep_chunk, type)
#define INITIALIZE_GENERIC_HEP_IDS_VAR(hep_chunk, type, len)

Enumerations

enum  hepv3_chunk_types {
  CHUNK_TYPE_IP_PROTOCOL_FAMILY = 0X0001, CHUNK_TYPE_IP_PROTOCOL_ID = 0X0002, CHUNK_TYPE_IPV4_SRC_ADDR = 0X0003, CHUNK_TYPE_IPV4_DST_ADDR = 0X0004,
  CHUNK_TYPE_IPV6_SRC_ADDR = 0X0005, CHUNK_TYPE_IPV6_DST_ADDR = 0X0006, CHUNK_TYPE_SRC_PORT = 0X0007, CHUNK_TYPE_DST_PORT = 0X0008,
  CHUNK_TYPE_TIMESTAMP_SEC = 0X0009, CHUNK_TYPE_TIMESTAMP_USEC = 0X000A, CHUNK_TYPE_PROTOCOL_TYPE = 0X000B, CHUNK_TYPE_CAPTURE_AGENT_ID = 0X000C,
  CHUNK_TYPE_KEEP_ALIVE_TIMER = 0X000D, CHUNK_TYPE_AUTH_KEY = 0X000E, CHUNK_TYPE_PAYLOAD = 0X000F, CHUNK_TYPE_PAYLOAD_ZIP = 0X0010,
  CHUNK_TYPE_UUID = 0X0011
}

Functions

static void __reg_module (void)
static void __unreg_module (void)
static AO2_GLOBAL_OBJ_STATIC (global_data)
 Current module data.
static AO2_GLOBAL_OBJ_STATIC (global_config)
 The module configuration container.
static void capture_info_dtor (void *obj)
 Destructor for a hepv3_capture_info object.
 CONFIG_INFO_STANDARD (cfg_info, global_config, module_config_alloc,.files=ACO_FILES(&hepv3_conf),.post_apply_config=hepv3_config_post_apply,)
 Register information about the configs being processed by this module.
static int hep_queue_cb (void *data)
 Callback function for the hep_queue_tp taskprocessor.
static void * hepv3_config_alloc (void)
 HEPv3 configuration object allocation.
static void hepv3_config_dtor (void *obj)
static void hepv3_config_post_apply (void)
 Post-apply callback for the config framework.
struct hepv3_capture_infohepv3_create_capture_info (const void *payload, size_t len)
 Create a hepv3_capture_info object.
static struct hepv3_runtime_datahepv3_data_alloc (struct hepv3_global_config *config)
 Allocate the HEPv3 run-time data.
static void hepv3_data_dtor (void *obj)
 HEPv3 run-time data destructor.
int hepv3_send_packet (struct hepv3_capture_info *capture_info)
 Send a generic packet capture to HEPv3.
static int load_module (void)
 Load the module.
static void * module_config_alloc (void)
 Module config constructor.
static void module_config_dtor (void *obj)
 Configuration object destructor.
static int reload_module (void)
 Reload the module.
static int unload_module (void)
 Unload the module.

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "HEPv3 API" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_APP_DEPEND, }
static struct ast_module_infoast_module_info = &__mod_info
static struct aco_type global_option
struct aco_typeglobal_options [] = ACO_TYPES(&global_option)
static struct ast_taskprocessorhep_queue_tp
struct aco_file hepv3_conf


Detailed Description

Routines for integration with Homer using HEPv3.

Author:
Alexandr Dubovikov <alexandr.dubovikov@sipcapture.org>

Matt Jordan <mjordan@digium.com>

Definition in file res_hep.c.


Define Documentation

#define ASTERISK_VENDOR_ID   0x0004

Asterisk vendor ID. Used for custom data to send to a capture node

Definition at line 98 of file res_hep.c.

#define DEFAULT_HEP_SERVER   ""

Definition at line 92 of file res_hep.c.

Referenced by load_module().

#define GENERIC_VENDOR_ID   0x0000

Generic vendor ID. Used for HEPv3 standard packets

Definition at line 95 of file res_hep.c.

#define INITIALIZE_GENERIC_HEP_CHUNK ( hep_item,
type   ) 

Value:

do { \
   INITIALIZE_GENERIC_HEP_IDS(&(hep_item)->chunk, (type)); \
   (hep_item)->chunk.length = htons(sizeof(*(hep_item))); \
   } while (0)

Definition at line 165 of file res_hep.c.

Referenced by hep_queue_cb().

#define INITIALIZE_GENERIC_HEP_CHUNK_DATA ( hep_item,
type,
value   ) 

Value:

do { \
   INITIALIZE_GENERIC_HEP_CHUNK((hep_item), (type)); \
   (hep_item)->data = (value); \
   } while (0)

Definition at line 170 of file res_hep.c.

Referenced by hep_queue_cb().

#define INITIALIZE_GENERIC_HEP_IDS ( hep_chunk,
type   ) 

Value:

do { \
   (hep_chunk)->vendor_id = htons(GENERIC_VENDOR_ID); \
   (hep_chunk)->type_id = htons((type)); \
   } while (0)

Definition at line 155 of file res_hep.c.

#define INITIALIZE_GENERIC_HEP_IDS_VAR ( hep_chunk,
type,
len   ) 

Value:

do { \
   INITIALIZE_GENERIC_HEP_IDS((hep_chunk), (type)); \
   (hep_chunk)->length = htons(sizeof(*(hep_chunk)) + len); \
   } while (0)

Definition at line 160 of file res_hep.c.

Referenced by hep_queue_cb().


Enumeration Type Documentation

Chunk types from the HEPv3 Spec

Enumerator:
CHUNK_TYPE_IP_PROTOCOL_FAMILY  THE IP PROTOCOL FAMILY
CHUNK_TYPE_IP_PROTOCOL_ID  THE IP PROTOCOL ID (UDP, TCP, ETC.)
CHUNK_TYPE_IPV4_SRC_ADDR  IF IPV4, THE SOURCE ADDRESS
CHUNK_TYPE_IPV4_DST_ADDR  IF IPV4, THE DESTINATION ADDRESS
CHUNK_TYPE_IPV6_SRC_ADDR  IF IPV6, THE SOURCE ADDRESS
CHUNK_TYPE_IPV6_DST_ADDR  IF IPV6, THE DESTINATION ADDRESS
CHUNK_TYPE_SRC_PORT  THE SOURCE PORT
CHUNK_TYPE_DST_PORT  THE DESTINATION PORT
CHUNK_TYPE_TIMESTAMP_SEC  THE CAPTURE TIME (SECONDS)
CHUNK_TYPE_TIMESTAMP_USEC  THE CAPTURE TIME (MICROSECONDS)
CHUNK_TYPE_PROTOCOL_TYPE  THE PROTOCOL PACKET TYPE. SEE /REF HEPV3_CAPTURE_TYPE
CHUNK_TYPE_CAPTURE_AGENT_ID  OUR CAPTURE AGENT ID
CHUNK_TYPE_KEEP_ALIVE_TIMER  A KEEP ALIVE TIMER
CHUNK_TYPE_AUTH_KEY  THE CAPTURE_PASSWORD IF DEFINED
CHUNK_TYPE_PAYLOAD  THE ONE AND ONLY PAYLOAD
CHUNK_TYPE_PAYLOAD_ZIP  THE ONE AND ONLY (ZIPPED) PAYLOAD
CHUNK_TYPE_UUID  THE UUID FOR THIS PACKET

Definition at line 101 of file res_hep.c.

00101                        {
00102 
00103    /*! THE IP PROTOCOL FAMILY */
00104    CHUNK_TYPE_IP_PROTOCOL_FAMILY = 0X0001,
00105 
00106    /*! THE IP PROTOCOL ID (UDP, TCP, ETC.) */
00107    CHUNK_TYPE_IP_PROTOCOL_ID = 0X0002,
00108 
00109    /*! IF IPV4, THE SOURCE ADDRESS */
00110    CHUNK_TYPE_IPV4_SRC_ADDR = 0X0003,
00111 
00112    /*! IF IPV4, THE DESTINATION ADDRESS */
00113    CHUNK_TYPE_IPV4_DST_ADDR = 0X0004,
00114 
00115    /*! IF IPV6, THE SOURCE ADDRESS */
00116    CHUNK_TYPE_IPV6_SRC_ADDR = 0X0005,
00117 
00118    /*! IF IPV6, THE DESTINATION ADDRESS */
00119    CHUNK_TYPE_IPV6_DST_ADDR = 0X0006,
00120 
00121    /*! THE SOURCE PORT */
00122    CHUNK_TYPE_SRC_PORT = 0X0007,
00123 
00124    /*! THE DESTINATION PORT */
00125    CHUNK_TYPE_DST_PORT = 0X0008,
00126 
00127    /*! THE CAPTURE TIME (SECONDS) */
00128    CHUNK_TYPE_TIMESTAMP_SEC = 0X0009,
00129 
00130    /*! THE CAPTURE TIME (MICROSECONDS) */
00131    CHUNK_TYPE_TIMESTAMP_USEC = 0X000A,
00132 
00133    /*! THE PROTOCOL PACKET TYPE. SEE /REF HEPV3_CAPTURE_TYPE */
00134    CHUNK_TYPE_PROTOCOL_TYPE = 0X000B,
00135 
00136    /*! OUR CAPTURE AGENT ID */
00137    CHUNK_TYPE_CAPTURE_AGENT_ID = 0X000C,
00138 
00139    /*! A KEEP ALIVE TIMER */
00140    CHUNK_TYPE_KEEP_ALIVE_TIMER = 0X000D,
00141 
00142    /*! THE \REF CAPTURE_PASSWORD IF DEFINED */
00143    CHUNK_TYPE_AUTH_KEY = 0X000E,
00144 
00145    /*! THE ONE AND ONLY PAYLOAD */
00146    CHUNK_TYPE_PAYLOAD = 0X000F,
00147 
00148    /*! THE ONE AND ONLY (ZIPPED) PAYLOAD */
00149    CHUNK_TYPE_PAYLOAD_ZIP = 0X0010,
00150 
00151    /*! THE UUID FOR THIS PACKET */
00152    CHUNK_TYPE_UUID = 0X0011,
00153 };


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 628 of file res_hep.c.

static void __unreg_module ( void   )  [static]

Definition at line 628 of file res_hep.c.

static AO2_GLOBAL_OBJ_STATIC ( global_data   )  [static]

Current module data.

static AO2_GLOBAL_OBJ_STATIC ( global_config   )  [static]

The module configuration container.

static void capture_info_dtor ( void *  obj  )  [static]

Destructor for a hepv3_capture_info object.

Definition at line 371 of file res_hep.c.

References ast_free, hepv3_capture_info::payload, and hepv3_capture_info::uuid.

Referenced by hepv3_create_capture_info().

00372 {
00373    struct hepv3_capture_info *info = obj;
00374 
00375    ast_free(info->uuid);
00376    ast_free(info->payload);
00377 }

CONFIG_INFO_STANDARD ( cfg_info  ,
global_config  ,
module_config_alloc  ,
files = ACO_FILES(&hepv3_conf),
post_apply_config = hepv3_config_post_apply 
)

Register information about the configs being processed by this module.

static int hep_queue_cb ( void *  data  )  [static]

Callback function for the hep_queue_tp taskprocessor.

Definition at line 400 of file res_hep.c.

References ao2_cleanup, ao2_global_obj_ref, ast_assert, ast_free, ast_log, AST_LOG_ERROR, AST_LOG_NOTICE, AST_LOG_WARNING, ast_malloc, ast_sendto(), ast_sockaddr_is_ipv4(), ast_sockaddr_port, ast_sockaddr_stringify_addr(), ast_strlen_zero, hep_generic::capt_id, CHUNK_TYPE_AUTH_KEY, CHUNK_TYPE_CAPTURE_AGENT_ID, CHUNK_TYPE_DST_PORT, CHUNK_TYPE_IP_PROTOCOL_FAMILY, CHUNK_TYPE_IP_PROTOCOL_ID, CHUNK_TYPE_IPV4_DST_ADDR, CHUNK_TYPE_IPV4_SRC_ADDR, CHUNK_TYPE_IPV6_DST_ADDR, CHUNK_TYPE_IPV6_SRC_ADDR, CHUNK_TYPE_PAYLOAD, CHUNK_TYPE_PAYLOAD_ZIP, CHUNK_TYPE_PROTOCOL_TYPE, CHUNK_TYPE_SRC_PORT, CHUNK_TYPE_TIMESTAMP_SEC, CHUNK_TYPE_TIMESTAMP_USEC, CHUNK_TYPE_UUID, config, hep_chunk_ip6::data, hep_chunk_ip4::data, hep_generic::dst_port, errno, hep_generic::header, hep_ctrl::id, INITIALIZE_GENERIC_HEP_CHUNK, INITIALIZE_GENERIC_HEP_CHUNK_DATA, INITIALIZE_GENERIC_HEP_IDS_VAR, hep_generic::ip_family, hep_generic::ip_proto, hep_ctrl::length, hep_generic::proto_t, RAII_VAR, hep_generic::src_port, hep_generic::time_sec, and hep_generic::time_usec.

Referenced by hepv3_send_packet().

00401 {
00402    RAII_VAR(struct module_config *, config, ao2_global_obj_ref(global_config), ao2_cleanup);
00403    RAII_VAR(struct hepv3_runtime_data *, hepv3_data, ao2_global_obj_ref(global_data), ao2_cleanup);
00404    RAII_VAR(struct hepv3_capture_info *, capture_info, data, ao2_cleanup);
00405    struct hep_generic hg_pkt;
00406    unsigned int packet_len = 0, sock_buffer_len;
00407    struct hep_chunk_ip4 ipv4_src, ipv4_dst;
00408    struct hep_chunk_ip6 ipv6_src, ipv6_dst;
00409    struct hep_chunk auth_key, payload, uuid;
00410    void *sock_buffer;
00411    int res;
00412 
00413    if (!capture_info || !config || !hepv3_data) {
00414       return 0;
00415    }
00416 
00417    if (ast_sockaddr_is_ipv4(&capture_info->src_addr) != ast_sockaddr_is_ipv4(&capture_info->dst_addr)) {
00418       ast_log(AST_LOG_NOTICE, "Unable to send packet: Address Family mismatch between source/destination\n");
00419       return -1;
00420    }
00421 
00422    packet_len = sizeof(hg_pkt);
00423 
00424    /* Build HEPv3 header, capture info, and calculate the total packet size */
00425    memcpy(hg_pkt.header.id, "\x48\x45\x50\x33", 4);
00426 
00427    INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_proto, CHUNK_TYPE_IP_PROTOCOL_ID, 0x11);
00428    INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.src_port, CHUNK_TYPE_SRC_PORT, htons(ast_sockaddr_port(&capture_info->src_addr)));
00429    INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.dst_port, CHUNK_TYPE_DST_PORT, htons(ast_sockaddr_port(&capture_info->dst_addr)));
00430    INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.time_sec, CHUNK_TYPE_TIMESTAMP_SEC, htonl(capture_info->capture_time.tv_sec));
00431    INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.time_usec, CHUNK_TYPE_TIMESTAMP_USEC, htonl(capture_info->capture_time.tv_usec));
00432    INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.proto_t, CHUNK_TYPE_PROTOCOL_TYPE, capture_info->capture_type);
00433    INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.capt_id, CHUNK_TYPE_CAPTURE_AGENT_ID, htonl(config->general->capture_id));
00434 
00435    if (ast_sockaddr_is_ipv4(&capture_info->src_addr)) {
00436       INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_family,
00437          CHUNK_TYPE_IP_PROTOCOL_FAMILY, AF_INET);
00438 
00439       INITIALIZE_GENERIC_HEP_CHUNK(&ipv4_src, CHUNK_TYPE_IPV4_SRC_ADDR);
00440       inet_pton(AF_INET, ast_sockaddr_stringify_addr(&capture_info->src_addr), &ipv4_src.data);
00441 
00442       INITIALIZE_GENERIC_HEP_CHUNK(&ipv4_dst, CHUNK_TYPE_IPV4_DST_ADDR);
00443       inet_pton(AF_INET, ast_sockaddr_stringify_addr(&capture_info->dst_addr), &ipv4_dst.data);
00444 
00445       packet_len += (sizeof(ipv4_src) + sizeof(ipv4_dst));
00446    } else {
00447       INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_family,
00448          CHUNK_TYPE_IP_PROTOCOL_FAMILY, AF_INET6);
00449 
00450       INITIALIZE_GENERIC_HEP_CHUNK(&ipv6_src, CHUNK_TYPE_IPV6_SRC_ADDR);
00451       inet_pton(AF_INET6, ast_sockaddr_stringify_addr(&capture_info->src_addr), &ipv6_src.data);
00452 
00453       INITIALIZE_GENERIC_HEP_CHUNK(&ipv6_dst, CHUNK_TYPE_IPV6_DST_ADDR);
00454       inet_pton(AF_INET6, ast_sockaddr_stringify_addr(&capture_info->dst_addr), &ipv6_dst.data);
00455 
00456       packet_len += (sizeof(ipv6_src) + sizeof(ipv6_dst));
00457    }
00458 
00459    if (!ast_strlen_zero(config->general->capture_password))  {
00460       INITIALIZE_GENERIC_HEP_IDS_VAR(&auth_key, CHUNK_TYPE_AUTH_KEY, strlen(config->general->capture_password));
00461       packet_len += (sizeof(auth_key) + strlen(config->general->capture_password));
00462    }
00463    INITIALIZE_GENERIC_HEP_IDS_VAR(&uuid, CHUNK_TYPE_UUID, strlen(capture_info->uuid));
00464    packet_len += (sizeof(uuid) + strlen(capture_info->uuid));
00465    INITIALIZE_GENERIC_HEP_IDS_VAR(&payload,
00466       capture_info->zipped ? CHUNK_TYPE_PAYLOAD_ZIP : CHUNK_TYPE_PAYLOAD, capture_info->len);
00467    packet_len += (sizeof(payload) + capture_info->len);
00468    hg_pkt.header.length = htons(packet_len);
00469 
00470    /* Build the buffer to send */
00471    sock_buffer = ast_malloc(packet_len);
00472    if (!sock_buffer) {
00473       return -1;
00474    }
00475 
00476    /* Copy in the header */
00477    memcpy(sock_buffer, &hg_pkt, sizeof(hg_pkt));
00478    sock_buffer_len = sizeof(hg_pkt);
00479 
00480    /* Addresses */
00481    if (ast_sockaddr_is_ipv4(&capture_info->src_addr)) {
00482       memcpy(sock_buffer + sock_buffer_len, &ipv4_src, sizeof(ipv4_src));
00483       sock_buffer_len += sizeof(ipv4_src);
00484       memcpy(sock_buffer + sock_buffer_len, &ipv4_dst, sizeof(ipv4_dst));
00485       sock_buffer_len += sizeof(ipv4_dst);
00486    } else {
00487       memcpy(sock_buffer + sock_buffer_len, &ipv6_src, sizeof(ipv6_src));
00488       sock_buffer_len += sizeof(ipv6_src);
00489       memcpy(sock_buffer + sock_buffer_len, &ipv6_dst, sizeof(ipv6_dst));
00490       sock_buffer_len += sizeof(ipv6_dst);
00491    }
00492 
00493    /* Auth Key */
00494    if (!ast_strlen_zero(config->general->capture_password)) {
00495       memcpy(sock_buffer + sock_buffer_len, &auth_key, sizeof(auth_key));
00496       sock_buffer_len += sizeof(auth_key);
00497       memcpy(sock_buffer + sock_buffer_len, config->general->capture_password, strlen(config->general->capture_password));
00498       sock_buffer_len += strlen(config->general->capture_password);
00499    }
00500 
00501    /* UUID */
00502    memcpy(sock_buffer + sock_buffer_len, &uuid, sizeof(uuid));
00503    sock_buffer_len += sizeof(uuid);
00504    memcpy(sock_buffer + sock_buffer_len, capture_info->uuid, strlen(capture_info->uuid));
00505    sock_buffer_len += strlen(capture_info->uuid);
00506 
00507    /* Packet! */
00508    memcpy(sock_buffer + sock_buffer_len, &payload, sizeof(payload));
00509    sock_buffer_len += sizeof(payload);
00510    memcpy(sock_buffer + sock_buffer_len, capture_info->payload, capture_info->len);
00511    sock_buffer_len += capture_info->len;
00512 
00513    ast_assert(sock_buffer_len == packet_len);
00514 
00515    res = ast_sendto(hepv3_data->sockfd, sock_buffer, sock_buffer_len, 0, &hepv3_data->remote_addr);
00516    if (res < 0) {
00517       ast_log(AST_LOG_ERROR, "Error [%d] while sending packet to HEPv3 server: %s\n",
00518          errno, strerror(errno));
00519    } else if (res != sock_buffer_len) {
00520       ast_log(AST_LOG_WARNING, "Failed to send complete packet to HEPv3 server: %d of %u sent\n",
00521          res, sock_buffer_len);
00522       res = -1;
00523    }
00524 
00525    ast_free(sock_buffer);
00526    return res;
00527 }

static void* hepv3_config_alloc ( void   )  [static]

HEPv3 configuration object allocation.

Definition at line 291 of file res_hep.c.

References ao2_alloc, ast_string_field_init, config, hepv3_config_dtor(), and NULL.

Referenced by module_config_alloc().

00292 {
00293    struct hepv3_global_config *config;
00294 
00295    config = ao2_alloc(sizeof(*config), hepv3_config_dtor);
00296    if (!config || ast_string_field_init(config, 32)) {
00297       return NULL;
00298    }
00299 
00300    return config;
00301 }

static void hepv3_config_dtor ( void *  obj  )  [static]

Definition at line 283 of file res_hep.c.

References ast_string_field_free_memory, and config.

Referenced by hepv3_config_alloc().

00284 {
00285    struct hepv3_global_config *config = obj;
00286 
00287    ast_string_field_free_memory(config);
00288 }

static void hepv3_config_post_apply ( void   )  [static]

Post-apply callback for the config framework.

This will create the run-time information from the supplied configuration.

Definition at line 553 of file res_hep.c.

References ao2_cleanup, ao2_global_obj_ref, ao2_global_obj_replace_unref, ao2_ref, hepv3_data_alloc(), and RAII_VAR.

00554 {
00555    RAII_VAR(struct module_config *, mod_cfg, ao2_global_obj_ref(global_config), ao2_cleanup);
00556    struct hepv3_runtime_data *data;
00557 
00558    data = hepv3_data_alloc(mod_cfg->general);
00559    if (!data) {
00560       return;
00561    }
00562 
00563    ao2_global_obj_replace_unref(global_data, data);
00564    ao2_ref(data, -1);
00565 }

struct hepv3_capture_info* hepv3_create_capture_info ( const void *  payload,
size_t  len 
) [read]

Create a hepv3_capture_info object.

This returned object is an ao2 reference counted object.

Any attribute in the returned hepv3_capture_info that is a pointer should point to something that is allocated on the heap, as it will be free'd when the hepv3_capture_info object is reclaimed.

Parameters:
payload The payload to send to the HEP capture node
len Length of payload
Return values:
A hepv3_capture_info ref counted object on success
NULL on error

Definition at line 379 of file res_hep.c.

References ao2_alloc, ao2_ref, ast_malloc, capture_info_dtor(), hepv3_capture_info::len, NULL, and hepv3_capture_info::payload.

Referenced by logging_on_rx_msg(), logging_on_tx_msg(), and rtcp_message_handler().

00380 {
00381    struct hepv3_capture_info *info;
00382 
00383    info = ao2_alloc(sizeof(*info), capture_info_dtor);
00384    if (!info) {
00385       return NULL;
00386    }
00387 
00388    info->payload = ast_malloc(len);
00389    if (!info->payload) {
00390       ao2_ref(info, -1);
00391       return NULL;
00392    }
00393    memcpy(info->payload, payload, len);
00394    info->len = len;
00395 
00396    return info;
00397 }

static struct hepv3_runtime_data* hepv3_data_alloc ( struct hepv3_global_config config  )  [static, read]

Allocate the HEPv3 run-time data.

Definition at line 344 of file res_hep.c.

References ao2_alloc, ao2_ref, ast_log, AST_LOG_WARNING, ast_sockaddr_is_ipv6(), ast_sockaddr_parse(), hepv3_global_config::capture_address, errno, hepv3_data_dtor(), NULL, PARSE_PORT_REQUIRE, hepv3_runtime_data::remote_addr, and hepv3_runtime_data::sockfd.

Referenced by hepv3_config_post_apply().

00345 {
00346    struct hepv3_runtime_data *data;
00347 
00348    data = ao2_alloc(sizeof(*data), hepv3_data_dtor);
00349    if (!data) {
00350       return NULL;
00351    }
00352 
00353    if (!ast_sockaddr_parse(&data->remote_addr, config->capture_address, PARSE_PORT_REQUIRE)) {
00354       ast_log(AST_LOG_WARNING, "Failed to create address from %s\n", config->capture_address);
00355       ao2_ref(data, -1);
00356       return NULL;
00357    }
00358 
00359    data->sockfd = socket(ast_sockaddr_is_ipv6(&data->remote_addr) ? AF_INET6 : AF_INET, SOCK_DGRAM, 0);
00360    if (data->sockfd < 0) {
00361       ast_log(AST_LOG_WARNING, "Failed to create socket for address %s: %s\n",
00362             config->capture_address, strerror(errno));
00363       ao2_ref(data, -1);
00364       return NULL;
00365    }
00366 
00367    return data;
00368 }

static void hepv3_data_dtor ( void *  obj  )  [static]

HEPv3 run-time data destructor.

Definition at line 333 of file res_hep.c.

References hepv3_runtime_data::sockfd.

Referenced by hepv3_data_alloc().

00334 {
00335    struct hepv3_runtime_data *data = obj;
00336 
00337    if (data->sockfd > -1) {
00338       close(data->sockfd);
00339       data->sockfd = -1;
00340    }
00341 }

int hepv3_send_packet ( struct hepv3_capture_info capture_info  ) 

Send a generic packet capture to HEPv3.

Parameters:
capture_info Information describing the packet. This should be a reference counted object, created via hepv3_create_capture_info.
Once this function is called, it assumes ownership of the capture_info object and steals the reference of the object. Regardless of success or failure, the calling function should assumed that this function will own the object.

Return values:
0 on success
-1 on error

Definition at line 529 of file res_hep.c.

References ao2_cleanup, ao2_global_obj_ref, ao2_ref, ast_taskprocessor_push(), config, hep_queue_cb(), and RAII_VAR.

Referenced by logging_on_rx_msg(), logging_on_tx_msg(), and rtcp_message_handler().

00530 {
00531    RAII_VAR(struct module_config *, config, ao2_global_obj_ref(global_config), ao2_cleanup);
00532    int res;
00533 
00534    if (!config || !config->general->enabled) {
00535       ao2_ref(capture_info, -1);
00536       return 0;
00537    }
00538 
00539    res = ast_taskprocessor_push(hep_queue_tp, hep_queue_cb, capture_info);
00540    if (res == -1) {
00541       ao2_ref(capture_info, -1);
00542    }
00543 
00544    return res;
00545 }

static int load_module ( void   )  [static]

Load the module.

Definition at line 595 of file res_hep.c.

References ACO_EXACT, aco_info_destroy(), aco_info_init(), aco_option_register, aco_process_config(), ACO_PROCESS_ERROR, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_SUCCESS, ast_taskprocessor_get(), DEFAULT_HEP_SERVER, enabled, error(), FLDSET, OPT_BOOL_T, OPT_STRINGFIELD_T, OPT_UINT_T, STRFLDSET, and TPS_REF_DEFAULT.

00596 {
00597    if (aco_info_init(&cfg_info)) {
00598       goto error;
00599    }
00600 
00601    hep_queue_tp = ast_taskprocessor_get("hep_queue_tp", TPS_REF_DEFAULT);
00602    if (!hep_queue_tp) {
00603       goto error;
00604    }
00605 
00606    aco_option_register(&cfg_info, "enabled", ACO_EXACT, global_options, "yes", OPT_BOOL_T, 1, FLDSET(struct hepv3_global_config, enabled));
00607    aco_option_register(&cfg_info, "capture_address", ACO_EXACT, global_options, DEFAULT_HEP_SERVER, OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_address));
00608    aco_option_register(&cfg_info, "capture_password", ACO_EXACT, global_options, "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct hepv3_global_config, capture_password));
00609    aco_option_register(&cfg_info, "capture_id", ACO_EXACT, global_options, "0", OPT_UINT_T, 0, STRFLDSET(struct hepv3_global_config, capture_id));
00610 
00611    if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
00612       goto error;
00613    }
00614 
00615    return AST_MODULE_LOAD_SUCCESS;
00616 
00617 error:
00618    aco_info_destroy(&cfg_info);
00619    return AST_MODULE_LOAD_DECLINE;
00620 }

static void * module_config_alloc ( void   )  [static]

Module config constructor.

Definition at line 314 of file res_hep.c.

References ao2_alloc, ao2_ref, config, module_config::general, hepv3_config_alloc(), module_config_dtor(), and NULL.

00315 {
00316    struct module_config *config;
00317 
00318    config = ao2_alloc(sizeof(*config), module_config_dtor);
00319    if (!config) {
00320       return NULL;
00321    }
00322 
00323    config->general = hepv3_config_alloc();
00324    if (!config->general) {
00325       ao2_ref(config, -1);
00326       config = NULL;
00327    }
00328 
00329    return config;
00330 }

static void module_config_dtor ( void *  obj  )  [static]

Configuration object destructor.

Definition at line 304 of file res_hep.c.

References ao2_ref, config, and module_config::general.

Referenced by module_config_alloc().

00305 {
00306    struct module_config *config = obj;
00307 
00308    if (config->general) {
00309       ao2_ref(config->general, -1);
00310    }
00311 }

static int reload_module ( void   )  [static]

Reload the module.

Definition at line 570 of file res_hep.c.

References aco_process_config(), and ACO_PROCESS_ERROR.

00571 {
00572    if (aco_process_config(&cfg_info, 1) == ACO_PROCESS_ERROR) {
00573       return -1;
00574    }
00575    return 0;
00576 }

static int unload_module ( void   )  [static]

Unload the module.

Definition at line 581 of file res_hep.c.

References aco_info_destroy(), ao2_global_obj_release, and ast_taskprocessor_unreference().

00582 {
00583    hep_queue_tp = ast_taskprocessor_unreference(hep_queue_tp);
00584 
00585    ao2_global_obj_release(global_config);
00586    ao2_global_obj_release(global_data);
00587    aco_info_destroy(&cfg_info);
00588 
00589    return 0;
00590 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "HEPv3 API" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .support_level = AST_MODULE_SUPPORT_EXTENDED, .load = load_module, .unload = unload_module, .reload = reload_module, .load_pri = AST_MODPRI_APP_DEPEND, } [static]

Definition at line 628 of file res_hep.c.

Definition at line 628 of file res_hep.c.

struct aco_type global_option [static]

Definition at line 251 of file res_hep.c.

struct aco_type* global_options[] = ACO_TYPES(&global_option)

Definition at line 259 of file res_hep.c.

struct ast_taskprocessor* hep_queue_tp [static]

Definition at line 272 of file res_hep.c.

Initial value:

 {
   .filename = "hep.conf",
   .types = ACO_TYPES(&global_option),
}

Definition at line 261 of file res_hep.c.


Generated on Thu Apr 16 06:32:51 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6