[asterisk-commits] mjordan: branch mjordan/12-hep r404722 - /team/mjordan/12-hep/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 3 10:39:08 CST 2014


Author: mjordan
Date: Fri Jan  3 10:39:05 2014
New Revision: 404722

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=404722
Log:
Add initial HEPv3 modules

Added:
    team/mjordan/12-hep/res/res_hepv3.c   (with props)
    team/mjordan/12-hep/res/res_hepv3.exports.in   (with props)
    team/mjordan/12-hep/res/res_pjsip_hepv3.c   (with props)

Added: team/mjordan/12-hep/res/res_hepv3.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-hep/res/res_hepv3.c?view=auto&rev=404722
==============================================================================
--- team/mjordan/12-hep/res/res_hepv3.c (added)
+++ team/mjordan/12-hep/res/res_hepv3.c Fri Jan  3 10:39:05 2014
@@ -1,0 +1,553 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2013, Digium, Inc.
+ *
+ * Alexandr Dubovikov <alexandr.dubovikov at sipcapture.org>
+ * Matt Jordan <mjordan at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief Routines for integration with Homer using HEPv3
+ *
+ * \author Alexandr Dubovikov <alexandr.dubovikov at sipcapture.org>
+ * \author Matt Jordan <mjordan at digium.com>
+ *
+ */
+
+/*!
+ * \li \ref res_hep.c uses the configuration file \ref hep.conf
+ * \addtogroup configuration_file Configuration Files
+ */
+
+/*!
+ * \page hep.conf hep.conf
+ * \verbinclude hep.conf.sample
+ */
+
+/*** MODULEINFO
+    <defaultenabled>no</defaultenabled>
+    <support_level>extended</support_level>
+ ***/
+
+/*** DOCUMENTATION
+	<configInfo name="res_hepv3" language="en_US">
+		<synopsis>Resource for integration with Homer using HEPv3</synopsis>
+		<configFile name="hep.conf">
+			<configObject name="general">
+				<synopsis>General settings.</synopsis>
+				<description><para>
+					The <emphasis>general</emphasis> settings section contains information
+					to configure Asterisk as a Homer capture agent.
+					</para>
+				</description>
+				<configOption name="enabled" default="yes">
+					<synopsis>Enable or disable packet capturing.</synopsis>
+					<description>
+						<enumlist>
+							<enum name="no" />
+							<enum name="yes" />
+						</enumlist>
+					</description>
+				</configOption>
+				<configOption name="capture-address" default="192.168.1.1:9061">
+					<synopsis>The address and port of the Homer server to send packets to.</synopsis>
+				</configOption>
+				<configOption name="capture-password">
+					<synopsis>If set, the authentication password to send to Homer.</synopsis>
+				</configOption>
+				<configOption name="capture-id" default="0">
+					<synopsis>The ID for this capture agent.</synopsis>
+				</configOption>
+			</configObject>
+		</configFile>
+	</configInfo>
+***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/module.h"
+#include "asterisk/astobj2.h"
+#include "asterisk/config_options.h"
+#include "asterisk/res_hepv3.h"
+
+#include <netinet/ip.h>
+#include <netinet/tcp.h>
+#include <netinet/udp.h>
+#include <netinet/ip6.h>
+
+#define DEFAULT_HEP_SERVER "192.168.1.1:9061"
+
+/*! Generic vendor ID. Used for HEPv3 standard packets */
+#define GENERIC_VENDOR_ID 0x0000
+
+/*! Asterisk vendor ID. Used for custom data to send to a capture node */
+#define ASTERISK_VENDOR_ID 0x0004
+
+/*! Chunk types from the HEPv3 Spec */
+
+/*! The IP protocol family */
+#define CHUNK_TYPE_IP_PROTOCOL_FAMILY 0x0001
+
+/*! The IP protocol ID (UDP, TCP, etc.) */
+#define CHUNK_TYPE_IP_PROTOCOL_ID 0x0002
+
+/*! If IPv4, the source address */
+#define CHUNK_TYPE_IPV4_SRC_ADDR 0x0003
+
+/*! If IPv4, the destination address */
+#define CHUNK_TYPE_IPV4_DST_ADDR 0x0004
+
+/*! If IPv6, the source address */
+#define CHUNK_TYPE_IPV6_SRC_ADDR 0x0005
+
+/*! If IPv6, the destination address */
+#define CHUNK_TYPE_IPV6_DST_ADDR 0x0006
+
+/*! The source port */
+#define CHUNK_TYPE_SRC_PORT 0x0007
+
+/*! The destination port */
+#define CHUNK_TYPE_DST_PORT 0x0008
+
+/*! The capture time (seconds) */
+#define CHUNK_TYPE_TIMESTAMP_SEC 0x0009
+
+/*! The capture time (microseconds) */
+#define CHUNK_TYPE_TIMESTAMP_USEC 0x000a
+
+/*! The protocol packet type. See /ref hepv3_capture_type */
+#define CHUNK_TYPE_PROTOCOL_TYPE 0x000b
+
+/*! Our capture agent ID */
+#define CHUNK_TYPE_CAPTURE_AGENT_ID 0x000c
+
+/*! A keep alive timer */
+#define CHUNK_TYPE_KEEP_ALIVE_TIMER 0x000d
+
+/*! The \ref capture_password if defined */
+#define CHUNK_TYPE_AUTH_KEY 0x000e
+
+/*! The one and only payload */
+#define CHUNK_TYPE_PAYLOAD 0x000f
+
+/*! The one and only (zipped) payload */
+#define CHUNK_TYPE_PAYLOAD_ZIP 0x0010
+
+/*! The UUID for this packet */
+#define CHUNK_TYPE_UUID 0x0011
+
+#define INITIALIZE_GENERIC_HEP_IDS(hep_chunk, type) do { \
+	(hep_chunk)->vendor_id = htons(GENERIC_VENDOR_ID); \
+	(hep_chunk)->type_id = htons((type)); \
+	} while (0)
+
+#define INITIALIZE_GENERIC_HEP_IDS_VAR(hep_chunk, type, len) do { \
+	INITIALIZE_GENERIC_HEP_IDS((hep_chunk), (type)); \
+	(hep_chunk)->length = htons(sizeof(*(hep_chunk)) + len); \
+	} while (0)
+
+#define INITIALIZE_GENERIC_HEP_CHUNK(hep_item, type) do { \
+	INITIALIZE_GENERIC_HEP_IDS(&(hep_item)->chunk, (type)); \
+	(hep_item)->chunk.length = htons(sizeof(*(hep_item))); \
+	} while (0)
+
+#define INITIALIZE_GENERIC_HEP_CHUNK_DATA(hep_item, type, value) do { \
+	INITIALIZE_GENERIC_HEP_CHUNK((hep_item), (type)); \
+	(hep_item)->data = (value); \
+	} while (0)
+
+/* HEPv3 Types */
+
+struct hep_chunk {
+	u_int16_t vendor_id;
+	u_int16_t type_id;
+	u_int16_t length;
+} __attribute__((packed));
+
+struct hep_chunk_uint8 {
+	struct hep_chunk chunk;
+	u_int8_t data;
+} __attribute__((packed));
+
+struct hep_chunk_uint16 {
+	struct hep_chunk chunk;
+	u_int16_t data;
+} __attribute__((packed));
+
+struct hep_chunk_uint32 {
+	struct hep_chunk chunk;
+	u_int32_t data;
+} __attribute__((packed));
+
+struct hep_chunk_str {
+	struct hep_chunk chunk;
+	char *data;
+} __attribute__((packed));
+
+struct hep_chunk_ip4 {
+	struct hep_chunk chunk;
+	struct in_addr data;
+} __attribute__((packed));
+
+struct hep_chunk_ip6 {
+	struct hep_chunk chunk;
+	struct in6_addr data;
+} __attribute__((packed));
+
+struct hep_ctrl {
+	char id[4];
+	u_int16_t length;
+} __attribute__((packed));
+
+struct hep_chunk_payload {
+	struct hep_chunk chunk;
+	char *data;
+} __attribute__((packed));
+
+/* Structure of HEP */
+
+struct hep_generic {
+	struct hep_ctrl         header;
+	struct hep_chunk_uint8  ip_family;
+	struct hep_chunk_uint8  ip_proto;
+	struct hep_chunk_uint16 src_port;
+	struct hep_chunk_uint16 dst_port;
+	struct hep_chunk_uint32 time_sec;
+	struct hep_chunk_uint32 time_usec;
+	struct hep_chunk_uint8  proto_t;
+	struct hep_chunk_uint32 capt_id;
+} __attribute__((packed));
+
+struct hep_hdr {
+	u_int8_t hp_v;            /* version */
+	u_int8_t hp_l;            /* length */
+	u_int8_t hp_f;            /* family */
+	u_int8_t hp_p;            /* protocol */
+	u_int16_t hp_sport;       /* source port */
+	u_int16_t hp_dport;       /* destination port */
+};
+
+struct hep_timehdr {
+	u_int32_t tv_sec;         /* seconds */
+	u_int32_t tv_usec;        /* useconds */
+	u_int16_t captid;         /* Capture ID node */
+};
+
+struct hep_iphdr {
+	struct in_addr hp_src;
+	struct in_addr hp_dst;      /* source and dest address */
+};
+
+struct hep_ip6hdr {
+	struct in6_addr hp6_src;        /* source address */
+	struct in6_addr hp6_dst;        /* destination address */
+};
+
+/*! \brief Global configuration for the module */
+struct hepv3_global_config {
+	unsigned int enabled;                    /*!< Whether or not sending is enabled */
+    unsigned int capture_id;                 /*!< Capture ID for this agent */
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(capture_address);   /*!< Address to send to */
+		AST_STRING_FIELD(capture_password);  /*!< Password for Homer server */
+	);
+};
+
+struct hepv3_runtime_data {
+    struct ast_sockaddr remote_addr;
+    int sockfd;
+};
+
+static struct aco_type global_option = {
+	.type = ACO_GLOBAL,
+	.name = "general",
+	.item_offset = 0,
+	.category_match = ACO_WHITELIST,
+	.category = "^general$",
+};
+
+struct aco_type *global_options[] = ACO_TYPES(&global_option);
+
+struct aco_file hepv3_conf = {
+	.filename = "hep.conf",
+	.types = ACO_TYPES(&global_option),
+};
+
+/*! \brief The module configuration container */
+static AO2_GLOBAL_OBJ_STATIC(global_config);
+
+static AO2_GLOBAL_OBJ_STATIC(global_data);
+
+static void *hepv3_config_alloc(void);
+static void hepv3_config_post_apply(void);
+
+/*! \brief Register information about the configs being processed by this module */
+CONFIG_INFO_STANDARD(cfg_info, global_config, hepv3_config_alloc,
+	.files = ACO_FILES(&hepv3_conf),
+    .post_apply_config = hepv3_config_post_apply,
+);
+
+/*! \brief HEPv3 configuration object destructor */
+static void hepv3_config_dtor(void *obj)
+{
+	struct hepv3_global_config *config = obj;
+
+	ast_string_field_free_memory(config);
+}
+
+/*! \brief HEPv3 configuration object allocation */
+static void *hepv3_config_alloc(void)
+{
+	struct hepv3_global_config *config;
+
+	config = ao2_alloc(sizeof(*config), hepv3_config_dtor);
+	if (!config || ast_string_field_init(config, 32)) {
+		return NULL;
+	}
+
+	return config;
+}
+
+static void hepv3_data_dtor(void *obj)
+{
+    struct hepv3_runtime_data *data = obj;
+
+    if (data->sockfd > -1) {
+        close(data->sockfd);
+        data->sockfd = -1;
+    }
+}
+
+static struct hepv3_runtime_data *hepv3_data_alloc(struct hepv3_global_config *config)
+{
+    struct hepv3_runtime_data *data;
+
+    data = ao2_alloc(sizeof(*data), hepv3_data_dtor);
+    if (!data) {
+        return NULL;
+    }
+
+    if (ast_sockaddr_parse(&data->remote_addr, config->capture_address, PARSE_PORT_REQUIRE)) {
+        ast_log(AST_LOG_WARNING, "Failed to create address from %s\n", config->capture_address);
+        ao2_ref(data, -1);
+        return NULL;
+    }
+
+    data->sockfd = socket(ast_sockaddr_is_ipv6(&data->remote_addr) ? AF_INET6 : AF_INET, SOCK_DGRAM, 0);
+    if (data->sockfd < 0) {
+        ast_log(AST_LOG_WARNING, "Failed to create socket for address %s: %s\n",
+                config->capture_address, strerror(errno));
+        ao2_ref(data, -1);
+        return NULL;
+    }
+
+    return data;
+}
+
+int hepv3_send_packet(struct hepv3_capture_info *capture_info, const void *buf, size_t len)
+{
+	RAII_VAR(struct hepv3_global_config *, hepv3_config, ao2_global_obj_ref(global_config), ao2_cleanup);
+	RAII_VAR(struct hepv3_runtime_data *, hepv3_data, ao2_global_obj_ref(global_data), ao2_cleanup);
+	struct hep_generic hg_pkt;
+	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;
+	void *sock_buffer;
+	int res;
+
+	if (!hepv3_config || !hepv3_data || !hepv3_config->enabled) {
+		return 0;
+	}
+
+	if (ast_sockaddr_is_ipv4(&capture_info->src_addr) != ast_sockaddr_is_ipv4(&capture_info->dst_addr)) {
+		ast_log(AST_LOG_NOTICE, "Unable to send packet: Address Family mismatch between source/destination\n");
+		return -1;
+	}
+
+	packet_len = sizeof(hg_pkt);
+
+	/* Build HEPv3 header, capture info, and calculate the total packet size */
+	memcpy(hg_pkt.header.id, "\x48\x45\x50\x33", 4);
+
+	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_proto, CHUNK_TYPE_IP_PROTOCOL_ID, 0x11);
+	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.src_port, CHUNK_TYPE_SRC_PORT, ast_sockaddr_port(&capture_info->src_addr));
+	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.dst_port, CHUNK_TYPE_DST_PORT, ast_sockaddr_port(&capture_info->dst_addr));
+	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.time_sec, CHUNK_TYPE_TIMESTAMP_SEC, htonl(capture_info->capture_time.tv_sec));
+	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.time_usec, CHUNK_TYPE_TIMESTAMP_USEC, htonl(capture_info->capture_time.tv_usec));
+	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.proto_t, CHUNK_TYPE_PROTOCOL_TYPE, capture_info->capture_type);
+	INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.capt_id, CHUNK_TYPE_CAPTURE_AGENT_ID, hepv3_config->capture_id);
+	if (ast_sockaddr_is_ipv4(&capture_info->src_addr)) {
+		INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_family,
+			CHUNK_TYPE_IP_PROTOCOL_FAMILY, AF_INET);
+
+		INITIALIZE_GENERIC_HEP_CHUNK(&ipv4_src, CHUNK_TYPE_IPV4_SRC_ADDR);
+		inet_pton(AF_INET, ast_sockaddr_stringify_addr(&capture_info->src_addr), &ipv4_src.data);
+
+		INITIALIZE_GENERIC_HEP_CHUNK(&ipv4_dst, CHUNK_TYPE_IPV4_DST_ADDR);
+		inet_pton(AF_INET, ast_sockaddr_stringify_addr(&capture_info->dst_addr), &ipv4_dst.data);
+
+		packet_len += (sizeof(ipv4_src) + sizeof(ipv4_dst));
+	} else {
+		INITIALIZE_GENERIC_HEP_CHUNK_DATA(&hg_pkt.ip_family,
+			CHUNK_TYPE_IP_PROTOCOL_FAMILY, AF_INET6);
+
+		INITIALIZE_GENERIC_HEP_CHUNK(&ipv6_src, CHUNK_TYPE_IPV4_SRC_ADDR);
+		inet_pton(AF_INET6, ast_sockaddr_stringify_addr(&capture_info->src_addr), &ipv6_src.data);
+
+		INITIALIZE_GENERIC_HEP_CHUNK(&ipv6_dst, CHUNK_TYPE_IPV4_DST_ADDR);
+		inet_pton(AF_INET6, ast_sockaddr_stringify_addr(&capture_info->dst_addr), &ipv6_dst.data);
+
+		packet_len += (sizeof(ipv6_src) + sizeof(ipv6_dst));
+	}
+
+	if (!ast_strlen_zero(hepv3_config->capture_password))  {
+		INITIALIZE_GENERIC_HEP_IDS_VAR(&auth_key, CHUNK_TYPE_AUTH_KEY, strlen(hepv3_config->capture_password));
+		packet_len += auth_key.length;
+	}
+
+	INITIALIZE_GENERIC_HEP_IDS_VAR(&uuid, CHUNK_TYPE_UUID, strlen(capture_info->uuid));
+	packet_len += uuid.length;
+
+	INITIALIZE_GENERIC_HEP_IDS_VAR(&payload,
+		capture_info->zipped ? CHUNK_TYPE_PAYLOAD_ZIP : CHUNK_TYPE_PAYLOAD, len);
+	packet_len += payload.length;
+
+	hg_pkt.header.length = htons(packet_len);
+
+	/* Build the buffer to send */
+	sock_buffer = ast_malloc(packet_len);
+	if (!sock_buffer) {
+		return -1;
+	}
+
+	/* Copy in the header */
+	memcpy(sock_buffer, &hg_pkt, sizeof(hg_pkt));
+	sock_buffer_len = sizeof(hg_pkt);
+
+	/* Addresses */
+	if (ast_sockaddr_is_ipv4(&capture_info->src_addr)) {
+		memcpy(sock_buffer + sock_buffer_len, &ipv4_src, sizeof(ipv4_src));
+		sock_buffer_len += sizeof(ipv4_src);
+		memcpy(sock_buffer + sock_buffer_len, &ipv4_dst, sizeof(ipv4_dst));
+		sock_buffer_len += sizeof(ipv4_dst);
+	} else {
+		memcpy(sock_buffer + sock_buffer_len, &ipv6_src, sizeof(ipv6_src));
+		sock_buffer_len += sizeof(ipv6_src);
+		memcpy(sock_buffer + sock_buffer_len, &ipv6_dst, sizeof(ipv6_dst));
+		sock_buffer_len += sizeof(ipv6_dst);
+	}
+
+	/* Auth Key */
+	if (!ast_strlen_zero(hepv3_config->capture_password)) {
+		memcpy(sock_buffer + sock_buffer_len, &auth_key, sizeof(auth_key));
+		sock_buffer_len += sizeof(auth_key);
+		memcpy(sock_buffer + sock_buffer_len, hepv3_config->capture_password, strlen(hepv3_config->capture_password));
+		sock_buffer_len += strlen(hepv3_config->capture_password);
+	}
+
+	/* UUID */
+	memcpy(sock_buffer + sock_buffer_len, &uuid, sizeof(uuid));
+	sock_buffer_len += sizeof(uuid);
+	memcpy(sock_buffer + sock_buffer_len, capture_info->uuid, strlen(capture_info->uuid));
+	sock_buffer_len += strlen(capture_info->uuid);
+
+	/* Packet! */
+	memcpy(sock_buffer + sock_buffer_len, &payload, sizeof(payload));
+	sock_buffer_len += sizeof(payload);
+	memcpy(sock_buffer + sock_buffer_len, buf, len);
+	sock_buffer_len += len;
+
+	ast_assert(sock_buffer_len == packet_len);
+
+	res = ast_sendto(hepv3_data->sockfd, sock_buffer, sock_buffer_len, 0, &hepv3_data->remote_addr);
+	if (res < 0) {
+		ast_log(AST_LOG_ERROR, "Error [%d] while sending packet to HEPv3 server: %s\n",
+			errno, strerror(errno));
+	} else if (res != sock_buffer_len) {
+		ast_log(AST_LOG_WARNING, "Failed to send complete packet to HEPv3 server: %d of %u sent\n",
+			res, sock_buffer_len);
+		res = -1;
+	}
+
+	ast_free(sock_buffer);
+	return res;
+}
+
+static void hepv3_config_post_apply(void)
+{
+    RAII_VAR(struct hepv3_global_config *, mod_cfg, ao2_global_obj_ref(global_config), ao2_cleanup);
+    struct hepv3_runtime_data *data;
+
+    data = hepv3_data_alloc(mod_cfg);
+    if (!data) {
+        return;
+    }
+
+    ao2_global_obj_replace_unref(global_data, data);
+}
+
+static int reload_module(void)
+{ 
+	if (aco_process_config(&cfg_info, 1) == ACO_PROCESS_ERROR) {
+		return -1;
+	}
+	return 0;
+}
+
+static int unload_module(void)
+{
+	ao2_global_obj_release(global_config);
+    ao2_global_obj_release(global_data);
+    aco_info_destroy(&cfg_info);
+
+	return 0;
+}
+
+/*!
+ * \brief Load the module
+ */
+static int load_module(void)
+{
+    RAII_VAR(struct hepv3_global_config *, mod_cfg, NULL, ao2_cleanup);
+
+	if (aco_info_init(&cfg_info)) {
+		goto error;
+	}
+
+	aco_option_register(&cfg_info, "enabled", ACO_EXACT, global_options, "yes", OPT_BOOL_T, 1, FLDSET(struct hepv3_global_config, enabled));
+	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));
+	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));
+
+	if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
+		goto error;
+	}
+
+	return AST_MODULE_LOAD_SUCCESS;
+
+error:
+	aco_info_destroy(&cfg_info);
+	return AST_MODULE_LOAD_DECLINE;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "HEPv3 API",
+	.load = load_module,
+	.unload = unload_module,
+	.reload = reload_module,
+	.load_pri = AST_MODPRI_CHANNEL_DEPEND,
+	);

Propchange: team/mjordan/12-hep/res/res_hepv3.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mjordan/12-hep/res/res_hepv3.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mjordan/12-hep/res/res_hepv3.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/mjordan/12-hep/res/res_hepv3.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-hep/res/res_hepv3.exports.in?view=auto&rev=404722
==============================================================================
--- team/mjordan/12-hep/res/res_hepv3.exports.in (added)
+++ team/mjordan/12-hep/res/res_hepv3.exports.in Fri Jan  3 10:39:05 2014
@@ -1,0 +1,6 @@
+{
+	global:
+		LINKER_SYMBOL_PREFIX*hepv3_send_packet;
+	local:
+		*;
+};

Propchange: team/mjordan/12-hep/res/res_hepv3.exports.in
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mjordan/12-hep/res/res_hepv3.exports.in
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mjordan/12-hep/res/res_hepv3.exports.in
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/mjordan/12-hep/res/res_pjsip_hepv3.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/12-hep/res/res_pjsip_hepv3.c?view=auto&rev=404722
==============================================================================
--- team/mjordan/12-hep/res/res_pjsip_hepv3.c (added)
+++ team/mjordan/12-hep/res/res_pjsip_hepv3.c Fri Jan  3 10:39:05 2014
@@ -1,0 +1,92 @@
+
+/*** MODULEINFO
+	<depend>pjproject</depend>
+	<depend>res_pjsip</depend>
+	<depend>res_hepv3</depend>
+	<defaultenabled>no</defaultenabled>
+	<support_level>extended</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <pjsip.h>
+
+#include "asterisk/res_pjsip.h"
+#include "asterisk/res_hepv3.h"
+#include "asterisk/module.h"
+#include "asterisk/netsock2.h"
+
+static pj_status_t logging_on_tx_msg(pjsip_tx_data *tdata)
+{
+	char local_buf[256];
+	char remote_buf[256];
+	struct hepv3_capture_info capture_info;
+	pjsip_cid_hdr *cid_hdr;
+
+	pj_sockaddr_print(&tdata->tp_info.transport->local_addr, local_buf, sizeof(local_buf), 1);
+	pj_sockaddr_print(&tdata->tp_info.dst_addr, remote_buf, sizeof(remote_buf), 1);
+	cid_hdr = PJSIP_MSG_CID_HDR(tdata->msg);
+
+	ast_sockaddr_parse(&capture_info.src_addr, local_buf, PARSE_PORT_REQUIRE);
+	ast_sockaddr_parse(&capture_info.dst_addr, remote_buf, PARSE_PORT_REQUIRE);
+	capture_info.capture_time = ast_tvnow();
+	capture_info.capture_type = hepv3_capture_type_sip;
+	capture_info.uuid = ast_strdupa(pj_strbuf(&cid_hdr->id));
+	capture_info.zipped = 0;
+
+	hepv3_send_packet(&capture_info, tdata->buf.start, (int)(tdata->buf.end - tdata->buf.start));
+
+	return PJ_SUCCESS;
+}
+
+static pj_bool_t logging_on_rx_msg(pjsip_rx_data *rdata)
+{
+	char local_buf[256];
+	char remote_buf[256];
+	struct hepv3_capture_info capture_info;
+
+	pj_sockaddr_print(&rdata->tp_info.transport->local_addr, local_buf, sizeof(local_buf), 1);
+	pj_sockaddr_print(&rdata->pkt_info.src_addr, remote_buf, sizeof(remote_buf), 1);
+
+	ast_sockaddr_parse(&capture_info.src_addr, local_buf, PARSE_PORT_REQUIRE);
+	ast_sockaddr_parse(&capture_info.dst_addr, remote_buf, PARSE_PORT_REQUIRE);
+	capture_info.capture_time.tv_sec = rdata->pkt_info.timestamp.sec;
+	capture_info.capture_time.tv_usec = rdata->pkt_info.timestamp.msec * 1000;
+	capture_info.capture_type = hepv3_capture_type_sip;
+	capture_info.uuid = ast_strdupa(pj_strbuf(&rdata->msg_info.cid->id));
+	capture_info.zipped = 0;
+
+	hepv3_send_packet(&capture_info, &rdata->pkt_info.packet, rdata->pkt_info.len);
+
+	return PJ_FALSE;
+}
+
+static pjsip_module logging_module = {
+	.name = { "HEPv3 Logging Module", 20 },
+	.priority = 0,
+	.on_rx_request = logging_on_rx_msg,
+	.on_rx_response = logging_on_rx_msg,
+	.on_tx_request = logging_on_tx_msg,
+	.on_tx_response = logging_on_tx_msg,
+};
+
+
+static int load_module(void)
+{
+	ast_sip_register_service(&logging_module);
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+static int unload_module(void)
+{
+	ast_sip_unregister_service(&logging_module);
+	return 0;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "PJSIP HEPv3 Logger",
+		.load = load_module,
+		.unload = unload_module,
+		.load_pri = AST_MODPRI_APP_DEPEND,
+	       );

Propchange: team/mjordan/12-hep/res/res_pjsip_hepv3.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mjordan/12-hep/res/res_pjsip_hepv3.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mjordan/12-hep/res/res_pjsip_hepv3.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list