Feature: SSL Decoder create version
This commit is contained in:
92
test/CMakeLists.txt
Normal file
92
test/CMakeLists.txt
Normal file
@@ -0,0 +1,92 @@
|
||||
include_directories(${PROJECT_SOURCE_DIR}/deps/)
|
||||
aux_source_directory(${PROJECT_SOURCE_DIR}/deps/toml DEPS_SRC)
|
||||
aux_source_directory(${PROJECT_SOURCE_DIR}/deps/yyjson DEPS_SRC)
|
||||
|
||||
add_library(${PROJECT_NAME}_test_plug SHARED ssl_decoder_test.cpp ${DEPS_SRC})
|
||||
add_dependencies(${PROJECT_NAME}_test_plug ${PROJECT_NAME})
|
||||
target_link_libraries(${PROJECT_NAME}_test_plug cjson)
|
||||
set_target_properties(${PROJECT_NAME}_test_plug PROPERTIES PREFIX "")
|
||||
|
||||
add_executable(ssl_decoder_perf_test
|
||||
ssl_decoder_perf_main.cpp
|
||||
ssl_decoder_perf_dummy.cpp
|
||||
${DEPS_SRC} ssl_decoder_test.cpp
|
||||
${PROJECT_SOURCE_DIR}/src/ssl_decoder.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(ssl_decoder_perf_test fieldstat4 pthread cjson -Wl,--no-whole-archive openssl-crypto-static -Wl,--no-whole-archive openssl-ssl-static)
|
||||
|
||||
set(TEST_RUN_DIR ${CMAKE_CURRENT_BINARY_DIR}/sapp)
|
||||
set(TEST_MAIN ${TEST_RUN_DIR}/plugin_test_main)
|
||||
|
||||
|
||||
# copy perf main
|
||||
add_test(NAME MKDIR_PERF COMMAND sh -c "mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/perf/ ${CMAKE_CURRENT_BINARY_DIR}/perf/etc/ssl/")
|
||||
add_test(NAME COPY_PERF_TEST_MAIN COMMAND sh -c "cp ${CMAKE_BINARY_DIR}/test/ssl_decoder_perf_test ${CMAKE_CURRENT_BINARY_DIR}/perf")
|
||||
add_test(NAME COPY_PERF_TEST_CONF COMMAND sh -c "cp ${PROJECT_SOURCE_DIR}/bin/${PROJECT_NAME}.toml ${CMAKE_CURRENT_BINARY_DIR}/perf/etc/ssl/${PROJECT_NAME}.toml")
|
||||
|
||||
# assemble test env
|
||||
add_test(NAME UNINSTALL_TEST_MAIN COMMAND sh -c "rpm -qa sapp | grep -v not | xargs -i rpm -e {} --nodeps")
|
||||
add_test(NAME INSTALL_TEST_MAIN COMMAND sh -c "rpm -i ${CMAKE_CURRENT_SOURCE_DIR}/env/sapp-4.3.59.c5b96a4-1.el8.x86_64.rpm --prefix=${CMAKE_CURRENT_BINARY_DIR}/sapp --force --nodeps")
|
||||
add_test(NAME UNINSTALL_STELLAR COMMAND sh -c "rpm -qa stellar-on-sapp | grep -v not | xargs -i rpm -e {} --nodeps")
|
||||
add_test(NAME INSTALL_STELLAR COMMAND sh -c "rpm -i ${CMAKE_CURRENT_SOURCE_DIR}/env/stellar-on-sapp-2.1.2.20b65ae-1.el8.x86_64.rpm --prefix=${CMAKE_CURRENT_BINARY_DIR}/ --force --nodeps")
|
||||
|
||||
add_test(NAME COPY_TEST_MAIN COMMAND sh -c "cp ${TEST_RUN_DIR}/tools/plugin_test_main ${TEST_RUN_DIR}/plugin_test_main")
|
||||
add_test(NAME COPY_SPEC COMMAND sh -c "cp ${CMAKE_CURRENT_SOURCE_DIR}/env/spec.toml ${TEST_RUN_DIR}/stellar_plugin/spec.toml")
|
||||
add_test(NAME COPY_CONFLIST COMMAND sh -c "cp ${CMAKE_CURRENT_SOURCE_DIR}/env/conflist.inf ${TEST_RUN_DIR}/plug/conflist.inf")
|
||||
add_test(NAME COPY_INF COMMAND sh -c "cp ${CMAKE_CURRENT_SOURCE_DIR}/env/start_loader.inf ${TEST_RUN_DIR}/plug/stellar_on_sapp/start_loader.inf")
|
||||
|
||||
# update config files
|
||||
add_test(NAME UPDATE_SAPP_LOG COMMAND bash -c "sed -i 's/sapp_log.fatal/sapp_log.info/' ${TEST_RUN_DIR}/etc/sapp_log.conf")
|
||||
add_test(NAME UPDATE_SAPP_SYN_MODE COMMAND bash -c "sed -i 's/syn_mandatory=1/syn_mandatory=0/' ${TEST_RUN_DIR}/etc/sapp.toml")
|
||||
add_test(NAME UPDATE_SAPP_REORDER COMMAND bash -c "sed -i 's/reorder_pkt_max=32/reorder_pkt_max=5/' ${TEST_RUN_DIR}/etc/sapp.toml")
|
||||
|
||||
# update plugin to be tested
|
||||
add_test(NAME UPDATE_PLUG_SO COMMAND sh -c "cp ${CMAKE_BINARY_DIR}/src/${PROJECT_NAME}.so ${TEST_RUN_DIR}/stellar_plugin/${PROJECT_NAME}.so")
|
||||
add_test(NAME UPDATE_TEST_SO COMMAND sh -c "cp ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}_test_plug.so ${TEST_RUN_DIR}/stellar_plugin/${PROJECT_NAME}_test_plug.so")
|
||||
add_test(NAME MKDIR_PLUG_CONF COMMAND sh -c "mkdir -p ${TEST_RUN_DIR}/etc/ssl/")
|
||||
add_test(NAME UPDATE_PLUG_CONF COMMAND sh -c "cp ${PROJECT_SOURCE_DIR}/bin/${PROJECT_NAME}.toml ${TEST_RUN_DIR}/etc/ssl/${PROJECT_NAME}.toml")
|
||||
|
||||
# set_tests_properties(INSTALL_TEST_MAIN INSTALL_STELLAR UPDATE_SAPP_LOG COPY_CONFLIST COPY_INF COPY_TEST_MAIN COPY_SPEC UPDATE_PLUG_SO UPDATE_TEST_SO MKDIR_PLUG_CONF UPDATE_PLUG_CONF PROPERTIES FIXTURES_SETUP TestFixture)
|
||||
|
||||
# # run tests
|
||||
# add_test(NAME MKDIR_METRICS COMMAND sh -c "mkdir -p ${TEST_RUN_DIR}/metrics/")
|
||||
# add_test(NAME ssl_QUERY COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/query/query_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/query/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_CNAME COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/cname/cname_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/cname/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_NSEC_RR COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/nsec/nsec_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/nsec/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_NSEC_10_1_RR COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/nsec_10_1/nsec_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/nsec_10_1/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_NSEC3_RR COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/nsec3/nsec3_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/nsec3/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_PTR COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/ptr/ptr_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/ptr/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_SRV COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/srv/srv_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/srv/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_TXT COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/txt/txt_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/txt/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_HTTPS COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/https/https_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/https/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_CERT1 COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/cernet1/cernet1_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/cernet1/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_CERT2 COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/cernet2/cernet2_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/cernet2/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_SEC COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/sslsec/sslsec_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/sslsec/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_TCP_MULTI_TRANSCATION COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/multi_transcation/multi_transcation_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/multi_transcation/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_TCP_MULTI_PKT_TRANS_2BYTES COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/multi_pkt_trans_2bytes/multi_pkt_trans_2bytes_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/multi_pkt_trans_2bytes/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_TCP_LOST_PKT COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/tcp_lost_pkt/lost_pkt_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/tcp_lost_pkt/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_MULTI_SESSION COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/multi_session/multi_session_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/multi_session/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_NS_NSEC3_RRSIG_A_OPT COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/ns_nsec3_rrsig_a_opt/ns_nsec3_rrsig_a_opt_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/ns_nsec3_rrsig_a_opt/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
# add_test(NAME ssl_PORT5353 COMMAND ${TEST_MAIN} ${CMAKE_CURRENT_SOURCE_DIR}/case/port5353/port5353_result.json -f "find ${CMAKE_CURRENT_SOURCE_DIR}/case/port5353/ -name *.pcap|sort -V" WORKING_DIRECTORY ${TEST_RUN_DIR})
|
||||
|
||||
# set_tests_properties(ssl_QUERY
|
||||
# ssl_CNAME
|
||||
# ssl_NSEC_RR
|
||||
# ssl_NSEC_10_1_RR
|
||||
# ssl_NSEC3_RR
|
||||
# ssl_PTR
|
||||
# ssl_SRV
|
||||
# ssl_TXT
|
||||
# ssl_HTTPS
|
||||
# ssl_CERT1
|
||||
# ssl_CERT2
|
||||
# ssl_SEC
|
||||
# ssl_TCP_MULTI_TRANSCATION
|
||||
# ssl_TCP_MULTI_PKT_TRANS_2BYTES
|
||||
# ssl_TCP_LOST_PKT
|
||||
# ssl_MULTI_SESSION
|
||||
# ssl_NS_NSEC3_RRSIG_A_OPT
|
||||
# ssl_PORT5353
|
||||
# PROPERTIES FIXTURES_REQUIRED TestFixture
|
||||
# )
|
||||
9
test/env/conflist.inf
vendored
Normal file
9
test/env/conflist.inf
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
[platform]
|
||||
./plug/stellar_on_sapp/start_loader.inf
|
||||
|
||||
|
||||
[protocol]
|
||||
|
||||
|
||||
[business]
|
||||
./plug/stellar_on_sapp/defer_loader.inf
|
||||
BIN
test/env/sapp-4.3.59.c5b96a4-1.el8.x86_64.rpm
vendored
Normal file
BIN
test/env/sapp-4.3.59.c5b96a4-1.el8.x86_64.rpm
vendored
Normal file
Binary file not shown.
11
test/env/spec.toml
vendored
Normal file
11
test/env/spec.toml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
# stellar_plugin.toml
|
||||
#
|
||||
[[plugin]]
|
||||
path = "./stellar_plugin/ssl_decoder.so"
|
||||
init = "ssl_decoder_init"
|
||||
exit = "ssl_decoder_exit"
|
||||
|
||||
[[plugin]]
|
||||
path = "./stellar_plugin/ssl_decoder_test_plug.so"
|
||||
init = "ssl_decoder_test_init"
|
||||
exit = "ssl_decoder_test_exit"
|
||||
17
test/env/start_loader.inf
vendored
Normal file
17
test/env/start_loader.inf
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
[PLUGINFO]
|
||||
PLUGNAME=stellar_start_loader
|
||||
SO_PATH=./plug/stellar_on_sapp/stellar_on_sapp.so
|
||||
INIT_FUNC=STELLAR_START_LOADER_INIT
|
||||
DESTROY_FUNC=STELLAR_START_LOADER_EXIT
|
||||
|
||||
[TCP_ALL]
|
||||
FUNC_FLAG=ALL
|
||||
FUNC_NAME=stellar_on_sapp_tcpall_entry
|
||||
|
||||
[TCP]
|
||||
FUNC_FLAG=ALL
|
||||
FUNC_NAME=stellar_on_sapp_tcp_entry
|
||||
|
||||
[UDP]
|
||||
FUNC_FLAG=ALL
|
||||
FUNC_NAME=stellar_on_sapp_udp_entry
|
||||
BIN
test/env/stellar-on-sapp-2.1.2.20b65ae-1.el8.x86_64.rpm
vendored
Normal file
BIN
test/env/stellar-on-sapp-2.1.2.20b65ae-1.el8.x86_64.rpm
vendored
Normal file
Binary file not shown.
227
test/ssl_decoder_perf_dummy.cpp
Normal file
227
test/ssl_decoder_perf_dummy.cpp
Normal file
@@ -0,0 +1,227 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "ssl_decoder_perf_dummy.h"
|
||||
|
||||
#define MAX_SUBSCRIBE_TOPIC_NUM 16
|
||||
#define MAX_MESSGEA_TOPIC_NUM 16
|
||||
#define MAX_STELLAR_PLUGIN_NUM 16
|
||||
|
||||
struct stellar_plugin
|
||||
{
|
||||
void *plugin_env;
|
||||
void *per_session_ctx;
|
||||
session_ctx_new_func *session_ctx_new;
|
||||
session_ctx_free_func *session_ctx_free;
|
||||
};
|
||||
|
||||
struct message_topic
|
||||
{
|
||||
char *name;
|
||||
void *msg_free_arg;
|
||||
int on_msg_cb_idx;
|
||||
session_msg_free_cb_func *msg_free_cb;
|
||||
int on_msg_plugin_id[MAX_SUBSCRIBE_TOPIC_NUM];
|
||||
on_session_msg_cb_func *plugin_on_msg_cb[MAX_SUBSCRIBE_TOPIC_NUM];
|
||||
};
|
||||
|
||||
struct stellar
|
||||
{
|
||||
int topic_idx;
|
||||
int plugin_idx;
|
||||
int worker_thread_num;
|
||||
int udp_topic_id;
|
||||
int tcp_steam_topic_id;
|
||||
struct message_topic topic[MAX_MESSGEA_TOPIC_NUM];
|
||||
struct stellar_plugin plugin[MAX_STELLAR_PLUGIN_NUM];
|
||||
};
|
||||
|
||||
struct session
|
||||
{
|
||||
int tid;
|
||||
int topic_idx;
|
||||
int plugin_idx;
|
||||
struct message_topic *topic;
|
||||
struct stellar_plugin *plugin;
|
||||
struct stellar_packet *curr_msg;
|
||||
struct session_addr addr;
|
||||
char *readable_addr;
|
||||
enum session_addr_type addr_type;
|
||||
};
|
||||
|
||||
const char *session_get0_current_payload(struct session *ss, size_t *payload_sz)
|
||||
{
|
||||
if(ss->curr_msg==NULL)
|
||||
{
|
||||
*payload_sz=0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*payload_sz=ss->curr_msg->payload_sz;
|
||||
return (const char *)ss->curr_msg->payload;
|
||||
}
|
||||
|
||||
int stellar_session_mq_create_topic(struct stellar *st, const char *topic_name, session_msg_free_cb_func *msg_free_cb, void *msg_free_arg)
|
||||
{
|
||||
int topic_id=st->topic_idx++;
|
||||
st->topic[topic_id].name=strdup(topic_name);
|
||||
st->topic[topic_id].msg_free_cb=msg_free_cb;
|
||||
st->topic[topic_id].msg_free_arg=msg_free_arg;
|
||||
|
||||
return topic_id;
|
||||
}
|
||||
|
||||
int stellar_session_mq_get_topic_id(struct stellar *st, const char *topic_name)
|
||||
{
|
||||
for(int i=0; i<st->topic_idx; i++)
|
||||
{
|
||||
if(strcmp(st->topic[i].name, topic_name)==0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int stellar_session_mq_subscribe(struct stellar *st, int topic_id, on_session_msg_cb_func *plugin_on_msg_cb, int plugin_id)
|
||||
{
|
||||
st->topic[topic_id].on_msg_plugin_id[st->topic[topic_id].on_msg_cb_idx]=plugin_id;
|
||||
st->topic[topic_id].plugin_on_msg_cb[st->topic[topic_id].on_msg_cb_idx]=plugin_on_msg_cb;
|
||||
st->topic[topic_id].on_msg_cb_idx++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int session_mq_publish_message(struct session *ss, int topic_id, void *msg)
|
||||
{
|
||||
for(int i=0; i<ss->topic[topic_id].on_msg_cb_idx; i++)
|
||||
{
|
||||
int plugin_id=ss->topic[topic_id].on_msg_plugin_id[i];
|
||||
ss->topic[topic_id].plugin_on_msg_cb[i](ss, topic_id, msg, ss->plugin[plugin_id].per_session_ctx, ss->plugin[plugin_id].plugin_env);
|
||||
}
|
||||
|
||||
if(ss->topic[topic_id].msg_free_cb!=NULL)
|
||||
{
|
||||
ss->topic[topic_id].msg_free_cb(ss, msg, ss->topic[topic_id].msg_free_arg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int session_mq_publish_message_by_name(struct session *ss, const char *topic_name, struct stellar_packet *msg)
|
||||
{
|
||||
for(int i=0; i<ss->topic_idx; i++)
|
||||
{
|
||||
if(strcmp(ss->topic[i].name, topic_name)==0)
|
||||
{
|
||||
ss->curr_msg=msg;
|
||||
session_mq_publish_message(ss, i, (void *)msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stellar_session_mq_destroy_topic(struct stellar *st, int topic_id)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int stellar_session_plugin_register(struct stellar *st, session_ctx_new_func session_ctx_new, session_ctx_free_func session_ctx_free, void *plugin_env)
|
||||
{
|
||||
int plugin_id=st->plugin_idx++;
|
||||
st->plugin[plugin_id].plugin_env=plugin_env;
|
||||
st->plugin[plugin_id].session_ctx_new=session_ctx_new;
|
||||
st->plugin[plugin_id].session_ctx_free=session_ctx_free;
|
||||
|
||||
return plugin_id;
|
||||
}
|
||||
|
||||
struct session *stellar_session_new(struct stellar *st, struct stellar_packet *cur_pkt, int tid)
|
||||
{
|
||||
struct session *ss=(struct session *)malloc(sizeof(struct session));
|
||||
ss->tid=tid;
|
||||
ss->addr_type=cur_pkt->addr_type;
|
||||
ss->readable_addr=cur_pkt->readable_addr;
|
||||
memcpy(&(ss->addr), &(cur_pkt->addr), sizeof(struct session_addr));
|
||||
|
||||
ss->plugin=st->plugin;
|
||||
ss->plugin_idx=st->plugin_idx;
|
||||
|
||||
ss->topic=st->topic;
|
||||
ss->topic_idx=st->topic_idx;
|
||||
|
||||
for(int i=0; i<ss->plugin_idx; i++)
|
||||
{
|
||||
ss->plugin[i].per_session_ctx=ss->plugin[i].session_ctx_new(ss, ss->plugin[i].plugin_env);
|
||||
}
|
||||
|
||||
return ss;
|
||||
}
|
||||
|
||||
int session_get_current_thread_id(struct session *ss)
|
||||
{
|
||||
return ss->tid;
|
||||
}
|
||||
|
||||
struct session_addr *session_get0_addr(struct session *ss, enum session_addr_type *addr_type)
|
||||
{
|
||||
*addr_type=ss->addr_type;
|
||||
return &(ss->addr);
|
||||
}
|
||||
|
||||
|
||||
void stellar_session_plugin_dettach_current_session(struct session *ss)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int session_is_innermost(struct session *ss, uint64_t *flag)
|
||||
{
|
||||
*flag=0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
enum session_state session_get_current_state(struct session *ss)
|
||||
{
|
||||
return SESSION_STATE_ACTIVE;
|
||||
}
|
||||
|
||||
const char *session_get0_readable_addr(struct session *ss)
|
||||
{
|
||||
return ss->readable_addr;
|
||||
}
|
||||
|
||||
void stellar_session_free(struct session *ss)
|
||||
{
|
||||
for(int i=0; i<ss->plugin_idx; i++)
|
||||
{
|
||||
ss->plugin[i].session_ctx_free(ss, ss->plugin[i].per_session_ctx, ss->plugin[i].plugin_env);
|
||||
}
|
||||
|
||||
free(ss);
|
||||
}
|
||||
|
||||
struct stellar *stellar_init(int worker_thread_num)
|
||||
{
|
||||
struct stellar *st=(struct stellar *)malloc(sizeof(struct stellar));
|
||||
st->topic_idx=0;
|
||||
st->plugin_idx=0;
|
||||
st->worker_thread_num=worker_thread_num;
|
||||
|
||||
st->udp_topic_id=stellar_session_mq_create_topic(st, TOPIC_UDP, NULL, NULL);
|
||||
st->tcp_steam_topic_id=stellar_session_mq_create_topic(st, TOPIC_TCP_STREAM, NULL, NULL);
|
||||
|
||||
return st;
|
||||
}
|
||||
|
||||
int stellar_get_worker_thread_num(struct stellar *st)
|
||||
{
|
||||
return st->worker_thread_num;
|
||||
}
|
||||
|
||||
32
test/ssl_decoder_perf_dummy.h
Normal file
32
test/ssl_decoder_perf_dummy.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "stellar/stellar.h"
|
||||
#include "stellar/session.h"
|
||||
#include <stellar/session_mq.h>
|
||||
|
||||
void perf_resource_record_decode(struct ssl_message *ssl_msg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
struct stellar_packet
|
||||
{
|
||||
size_t payload_sz;
|
||||
uint8_t payload[2048];
|
||||
struct session_addr addr;
|
||||
char *readable_addr;
|
||||
enum session_addr_type addr_type;
|
||||
};
|
||||
|
||||
struct stellar *stellar_init(int worker_thread_num);
|
||||
|
||||
struct session *stellar_session_new(struct stellar *st, struct stellar_packet *cur_pkt, int tid);
|
||||
void stellar_session_free(struct session *ss);
|
||||
|
||||
int session_mq_publish_message_by_name(struct session *ss, const char *topic_name, struct stellar_packet *msg);
|
||||
264
test/ssl_decoder_perf_main.cpp
Normal file
264
test/ssl_decoder_perf_main.cpp
Normal file
@@ -0,0 +1,264 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "fieldstat/fieldstat_easy.h"
|
||||
|
||||
#include <stellar/utils.h>
|
||||
#include "stellar/stellar.h"
|
||||
#include <stellar/session_mq.h>
|
||||
|
||||
#include "ssl_decoder.h"
|
||||
#include "toml/toml.h"
|
||||
#include "ssl_decoder_perf_dummy.h"
|
||||
|
||||
#define ssl_DECODER_TEST_TOML_PATH "./etc/ssl/ssl_decoder.toml"
|
||||
|
||||
#define TIME_START() struct timespec _start_time, _end_time; clock_gettime(CLOCK_REALTIME, &_start_time)
|
||||
#define TIME_DIFF() \
|
||||
long long time_diff_ns;\
|
||||
do { \
|
||||
clock_gettime(CLOCK_REALTIME, &_end_time); \
|
||||
if (likely(_end_time.tv_sec == _start_time.tv_sec))\
|
||||
{\
|
||||
time_diff_ns = (_end_time.tv_nsec - _start_time.tv_nsec);\
|
||||
}else{\
|
||||
time_diff_ns = (_end_time.tv_sec * 1000 * 1000 * 1000 + _end_time.tv_nsec) - (_start_time.tv_sec * 1000 * 1000 * 1000 + _start_time.tv_nsec);\
|
||||
}\
|
||||
}while (0)
|
||||
|
||||
struct ssl_decoder_context;
|
||||
struct ssl_decoder_plugin_env;
|
||||
|
||||
enum PERF_TAG
|
||||
{
|
||||
PERF_TAG_QUESTION,
|
||||
PERF_TAG_RESOURCE_RECORD,
|
||||
PERF_TAG_MAX
|
||||
};
|
||||
|
||||
struct fs_easy_schame
|
||||
{
|
||||
int id[PERF_TAG_MAX];
|
||||
struct field tag[PERF_TAG_MAX];
|
||||
struct fieldstat_easy *handle;
|
||||
};
|
||||
|
||||
struct perf_main_env
|
||||
{
|
||||
int worker_thread_num;
|
||||
int *worker_thread_pid;
|
||||
int n_worker_thread_pid;
|
||||
struct fs_easy_schame fse;
|
||||
struct stellar *st;
|
||||
struct stellar_packet *response;
|
||||
};
|
||||
|
||||
// form ssl_decoder_test.cpp
|
||||
extern "C" void *ssl_decoder_test_init(struct stellar *st);
|
||||
extern "C" void *ssl_decoder_init(struct stellar *st);
|
||||
|
||||
thread_local int local_worker_thread_id=-1;
|
||||
int firewall_current_worker_thread_id_get(struct perf_main_env *main_env)
|
||||
{
|
||||
if (local_worker_thread_id==-1)
|
||||
{
|
||||
pid_t my_pid = syscall(SYS_gettid);
|
||||
for(int i=0; i<main_env->n_worker_thread_pid; i++)
|
||||
{
|
||||
if (my_pid==main_env->worker_thread_pid[i])
|
||||
{
|
||||
local_worker_thread_id=i;
|
||||
return local_worker_thread_id;
|
||||
}
|
||||
}
|
||||
|
||||
main_env->worker_thread_pid[main_env->n_worker_thread_pid]=my_pid;
|
||||
local_worker_thread_id=main_env->n_worker_thread_pid++;
|
||||
}
|
||||
|
||||
return local_worker_thread_id;
|
||||
}
|
||||
|
||||
|
||||
extern "C" int commit_test_result_json(cJSON *node, const char *name)
|
||||
{
|
||||
char *real_result_str=cJSON_Print(node);
|
||||
printf("%s\n", real_result_str);
|
||||
free(real_result_str);
|
||||
|
||||
cJSON_Delete(node);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *pthread_message_publish(void *arg)
|
||||
{
|
||||
struct perf_main_env *main_env=(struct perf_main_env *)arg;
|
||||
int tid=firewall_current_worker_thread_id_get(main_env);
|
||||
struct session *ss=stellar_session_new(main_env->st, main_env->response, tid);
|
||||
|
||||
while(1)
|
||||
{
|
||||
TIME_START();
|
||||
session_mq_publish_message_by_name(ss, TOPIC_UDP, main_env->response);
|
||||
TIME_DIFF();
|
||||
fieldstat_easy_histogram_record(main_env->fse.handle, tid, main_env->fse.id[PERF_TAG_QUESTION], &(main_env->fse.tag[PERF_TAG_QUESTION]), 1, time_diff_ns);
|
||||
}
|
||||
|
||||
stellar_session_free(ss);
|
||||
}
|
||||
|
||||
static void main_stat_init(struct perf_main_env *main_env)
|
||||
{
|
||||
main_env->fse.handle=fieldstat_easy_new(main_env->worker_thread_num, "ssl_decoder_perf_test", NULL, 0);
|
||||
fieldstat_easy_enable_auto_output(main_env->fse.handle, "./metrics/ssl_decoder_perf_test.json", 1);
|
||||
|
||||
main_env->fse.tag[PERF_TAG_QUESTION].key="question";
|
||||
main_env->fse.tag[PERF_TAG_QUESTION].type=FIELD_VALUE_DOUBLE;
|
||||
main_env->fse.tag[PERF_TAG_QUESTION].value_double=0.00001;
|
||||
main_env->fse.id[PERF_TAG_QUESTION]=fieldstat_easy_register_histogram(main_env->fse.handle, "question", 1, 99999999, 5);
|
||||
|
||||
main_env->fse.tag[PERF_TAG_RESOURCE_RECORD].key="resource_record";
|
||||
main_env->fse.tag[PERF_TAG_RESOURCE_RECORD].type=FIELD_VALUE_DOUBLE;
|
||||
main_env->fse.tag[PERF_TAG_RESOURCE_RECORD].value_double=0.00001;
|
||||
main_env->fse.id[PERF_TAG_RESOURCE_RECORD]=fieldstat_easy_register_histogram(main_env->fse.handle, "resource-record", 1, 99999999, 5);
|
||||
}
|
||||
|
||||
void display_packet(struct stellar_packet *cur_pkt)
|
||||
{
|
||||
printf("query.payload_sz=%zu\n", cur_pkt->payload_sz);
|
||||
|
||||
for(size_t i=0; i<cur_pkt->payload_sz; i++)
|
||||
{
|
||||
printf("%02x ", cur_pkt->payload[i]);
|
||||
if(i>0 && (i%16==0))
|
||||
{
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
size_t hex_string_to_byte_array(const char *hex_str, size_t hex_str_sz, unsigned char *byte_array, size_t byte_array_sz)
|
||||
{
|
||||
size_t offset=0;
|
||||
for(size_t i=0; i<hex_str_sz; i+=2)
|
||||
{
|
||||
sscanf(hex_str+i, "%2hhx", &byte_array[offset++]);
|
||||
|
||||
}
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
int32_t ssl_decoder_test_config_load(const char *cfg_path, struct perf_main_env *main_env)
|
||||
{
|
||||
FILE *fp=fopen(cfg_path, "r");
|
||||
if (NULL==fp)
|
||||
{
|
||||
fprintf(stderr, "[%s:%d] Can't open config file: %s", __FUNCTION__, __LINE__, cfg_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ret=0;
|
||||
char errbuf[256]={0};
|
||||
|
||||
toml_table_t *root=toml_parse_file(fp, errbuf, sizeof(errbuf));
|
||||
fclose(fp);
|
||||
|
||||
toml_table_t *decoder_tbl=toml_table_in(root, "decoder");
|
||||
if(NULL==decoder_tbl)
|
||||
{
|
||||
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder]", __FUNCTION__, __LINE__, cfg_path);
|
||||
toml_free(root);
|
||||
return -1;
|
||||
}
|
||||
|
||||
toml_table_t *ssl_tbl=toml_table_in(decoder_tbl, "ssl");
|
||||
if(NULL==ssl_tbl)
|
||||
{
|
||||
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl]", __FUNCTION__, __LINE__, cfg_path);
|
||||
toml_free(root);
|
||||
return -1;
|
||||
}
|
||||
|
||||
toml_table_t *test_tbl=toml_table_in(ssl_tbl, "test");
|
||||
if(NULL==test_tbl)
|
||||
{
|
||||
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test]", __FUNCTION__, __LINE__, cfg_path);
|
||||
toml_free(root);
|
||||
return -1;
|
||||
}
|
||||
|
||||
toml_table_t *perf_tbl=toml_table_in(test_tbl, "perf");
|
||||
if(NULL==perf_tbl)
|
||||
{
|
||||
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test.perf]", __FUNCTION__, __LINE__, cfg_path);
|
||||
toml_free(root);
|
||||
return -1;
|
||||
}
|
||||
|
||||
toml_datum_t perf_worker_thread_num_val=toml_int_in(perf_tbl, "perf_worker_thread_num");
|
||||
if(perf_worker_thread_num_val.ok)
|
||||
{
|
||||
main_env->worker_thread_num=perf_worker_thread_num_val.u.i;
|
||||
}
|
||||
else
|
||||
{
|
||||
main_env->worker_thread_num=1;
|
||||
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test.perf_worker_thread_num]", __FUNCTION__, __LINE__, cfg_path);
|
||||
}
|
||||
|
||||
toml_free(root);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct perf_main_env *main_env=(struct perf_main_env *)calloc(1, sizeof(struct perf_main_env));
|
||||
ssl_decoder_test_config_load(ssl_DECODER_TEST_TOML_PATH, main_env);
|
||||
main_stat_init(main_env);
|
||||
main_env->st=stellar_init(main_env->worker_thread_num);
|
||||
ssl_decoder_init(main_env->st);
|
||||
ssl_decoder_test_init(main_env->st);
|
||||
main_env->n_worker_thread_pid=0;
|
||||
main_env->worker_thread_pid=(int *)calloc(main_env->worker_thread_num, sizeof(int));
|
||||
|
||||
// Internet Protocol Version 6, Src=2001:503:231d::2:30 Dst=2001:da8:2008::10
|
||||
struct stellar_packet *response=(struct stellar_packet *)calloc(1, sizeof(struct stellar_packet));
|
||||
main_env->response=response;
|
||||
|
||||
response->addr_type=SESSION_ADDR_TYPE_IPV6_UDP;
|
||||
response->readable_addr=(char *)("s=2001:503:231d::2:30.23856 d=2001:da8:2008::10.53");
|
||||
inet_pton(AF_INET6, "2001:da8:2008::10", response->addr.ipv6.daddr);
|
||||
inet_pton(AF_INET6, "2001:503:231d::2:30", response->addr.ipv6.saddr);
|
||||
response->addr.ipv6.dport=htons(53);
|
||||
response->addr.ipv6.sport=htons(23856);
|
||||
const char *response_hex_str="ce268000000100000006001404646174610862696c6963646e3203636f6d0000410001c011000200010002a300000c036e733305646e737635c01ac011000200010002a3000006036e7334c03320434b30504f4a4d473837344c4a5245463745464e38343330515649543842534dc01a003200010001518000230101000000146501a0c25720ee156f6c4e39636b3ada0312d92a000722000000000290c04d002e00010001518000b700320802000151806188b454617f5b5c3cbd03636f6d001f77dc4c5796eda9ced317925c67d91c52922152424c9dca024948c1169e8429053fdf50a23370d9c3dc79de909f2f79475b2c731d6060d1db7b5d294b8ee43c91a57b8a4afa06c25fb13127bfca3fb353c7d5a38eaf093e12ffa1e33bc80bd7118851ca730ed22bd27b6f16673b86b44898785c6e13b3dd3620750492e47bb8ca823ffa6e25225ffa5408184c25e4ff423497802deed0586629d78103b3e6e72039454d4644425347524c48514f4d4736515441534e534c4151343438454b4644c01a003200010001518000220101000000144bad0970b67bda0a716dcd12979d4451b22f7ac50006200000000012c160002e00010001518000b700320802000151806188bdde617f64e63cbd03636f6d00a9de4aee30c79978429e76969d02d2bd4c8942f1b4329a643e9d7703e9fd46dd9ab32c4feffe1f9fbed3418e40d42a00fe2c1c2cac66e1c718bf508c4f603171f9ea18e8e79a533d136c26907576ab033dc48e4ff3b355346c33ac54a359c9572c308c923f910e470315dd4de40bd3b443b7caa34309b22146dca1ed6f4758a476052fc8a33829216c5abe88f21981dfe8ae9b2b204958aac575bfaa9847af3ec02f000100010002a300000481d3b0d4c02f000100010002a3000004a20e12bcc02f000100010002a3000004a20e18fbc02f000100010002a3000004a20e19fbc02f000100010002a300000412c20289c02f000100010002a3000004b7c0c95ec02f000100010002a3000004dfa69710c02f001c00010002a300001024024e0014301102000091362b2bba61c02f000100010002a3000004344dee5cc02f000100010002a30000043d97b433c047000100010002a300000465e2dc0cc047000100010002a300000481d3b097c047000100010002a3000004a20e18f8c047000100010002a3000004a20e19f8c047000100010002a3000004b7c0a477c047000100010002a3000004dfa6977ec047001c00010002a300001024024e00102012640000913629b6fc32c047000100010002a300000434c69f92c047000100010002a30000043b2478930000291000000080000000";
|
||||
response->payload_sz=hex_string_to_byte_array(response_hex_str, strlen(response_hex_str), response->payload, sizeof(response->payload));
|
||||
//display_packet(response);
|
||||
|
||||
for(int i=0; i<main_env->worker_thread_num; i++)
|
||||
{
|
||||
pthread_t ptid;
|
||||
pthread_create(&ptid, NULL, pthread_message_publish, (void *)main_env);
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
221
test/ssl_decoder_test.cpp
Normal file
221
test/ssl_decoder_test.cpp
Normal file
@@ -0,0 +1,221 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
|
||||
#include "cJSON.h"
|
||||
#include "ssl_decoder.h"
|
||||
#include "toml/toml.h"
|
||||
|
||||
#include "stellar/stellar.h"
|
||||
#include "stellar/session.h"
|
||||
#include "stellar/session_exdata.h"
|
||||
#include "stellar/session_mq.h"
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "ssl_decoder.h"
|
||||
|
||||
#define ssl_DECODER_TEST_TOML_PATH "./etc/ssl/ssl_decoder.toml"
|
||||
|
||||
struct ssl_decoder_test_plugin_env
|
||||
{
|
||||
int plugin_id;
|
||||
int topic_id;
|
||||
int result_index;
|
||||
int commit_result_enable;
|
||||
int decode_resource_record_enable;
|
||||
int export_resource_record_enable;
|
||||
};
|
||||
|
||||
extern "C" void perf_resource_record_decode(struct ssl_message *ssl_msg);
|
||||
extern "C" int commit_test_result_json(cJSON *node, const char *name);
|
||||
|
||||
void ssl_real_result_write_file(char *result_str)
|
||||
{
|
||||
FILE *fp=fopen("ssl_real_result.json", "a+");
|
||||
if(fp!=NULL)
|
||||
{
|
||||
fwrite(result_str, 1, strlen(result_str), fp);
|
||||
fclose(fp);
|
||||
}
|
||||
}
|
||||
|
||||
void ssl_decoder_test_message_cb(struct session *ss, int topic_id, const void *msg, void *per_session_ctx, void *plugin_env_str)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void *ssl_decoder_test_per_session_context_new(struct session *sess, void *plugin_env)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void ssl_decoder_test_per_session_context_free(struct session *sess, void *session_ctx, void *plugin_env)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int32_t ssl_decoder_test_config_load(const char *cfg_path, struct ssl_decoder_test_plugin_env *plugin_env)
|
||||
{
|
||||
FILE *fp=fopen(cfg_path, "r");
|
||||
if (NULL==fp)
|
||||
{
|
||||
fprintf(stderr, "[%s:%d] Can't open config file: %s", __FUNCTION__, __LINE__, cfg_path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t ret=0;
|
||||
char errbuf[256]={0};
|
||||
|
||||
toml_table_t *root=toml_parse_file(fp, errbuf, sizeof(errbuf));
|
||||
fclose(fp);
|
||||
|
||||
toml_table_t *decoder_tbl=toml_table_in(root, "decoder");
|
||||
if(NULL==decoder_tbl)
|
||||
{
|
||||
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder]", __FUNCTION__, __LINE__, cfg_path);
|
||||
toml_free(root);
|
||||
return -1;
|
||||
}
|
||||
|
||||
toml_table_t *ssl_tbl=toml_table_in(decoder_tbl, "ssl");
|
||||
if(NULL==ssl_tbl)
|
||||
{
|
||||
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl]", __FUNCTION__, __LINE__, cfg_path);
|
||||
toml_free(root);
|
||||
return -1;
|
||||
}
|
||||
|
||||
toml_table_t *test_tbl=toml_table_in(ssl_tbl, "test");
|
||||
if(NULL==test_tbl)
|
||||
{
|
||||
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test]", __FUNCTION__, __LINE__, cfg_path);
|
||||
toml_free(root);
|
||||
return -1;
|
||||
}
|
||||
|
||||
toml_datum_t commit_result_enable_val=toml_string_in(test_tbl, "commit_result_enable");
|
||||
if(commit_result_enable_val.ok==0)
|
||||
{
|
||||
plugin_env->commit_result_enable=0;
|
||||
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test.commit_result_enable]", __FUNCTION__, __LINE__, cfg_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(memcmp("no", commit_result_enable_val.u.s, strlen("no"))==0)
|
||||
{
|
||||
plugin_env->commit_result_enable=0;
|
||||
}
|
||||
else if(memcmp("yes", commit_result_enable_val.u.s, strlen("yes"))==0)
|
||||
{
|
||||
plugin_env->commit_result_enable=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin_env->commit_result_enable=1;
|
||||
fprintf(stderr, "[%s:%d] config file: %s key: [decoder.ssl.test.commit_result_enable] value is not yes or no", __FUNCTION__, __LINE__, cfg_path);
|
||||
}
|
||||
}
|
||||
|
||||
toml_table_t *perf_tbl=toml_table_in(test_tbl, "perf");
|
||||
if(NULL==perf_tbl)
|
||||
{
|
||||
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test.perf]", __FUNCTION__, __LINE__, cfg_path);
|
||||
toml_free(root);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// decode_resource_record_enable
|
||||
toml_datum_t decode_resource_record_enable_val=toml_string_in(perf_tbl, "decode_resource_record_enable");
|
||||
if(decode_resource_record_enable_val.ok==0)
|
||||
{
|
||||
plugin_env->decode_resource_record_enable=0;
|
||||
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test.decode_resource_record_enable]", __FUNCTION__, __LINE__, cfg_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(memcmp("no", decode_resource_record_enable_val.u.s, strlen("no"))==0)
|
||||
{
|
||||
plugin_env->decode_resource_record_enable=0;
|
||||
}
|
||||
else if(memcmp("yes", decode_resource_record_enable_val.u.s, strlen("yes"))==0)
|
||||
{
|
||||
plugin_env->decode_resource_record_enable=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin_env->decode_resource_record_enable=1;
|
||||
fprintf(stderr, "[%s:%d] config file: %s key: [decoder.ssl.test.decode_resource_record_enable] value is not yes or no", __FUNCTION__, __LINE__, cfg_path);
|
||||
}
|
||||
}
|
||||
|
||||
// export_resource_record_enable
|
||||
toml_datum_t export_resource_record_enable_val=toml_string_in(perf_tbl, "export_resource_record_enable");
|
||||
if(export_resource_record_enable_val.ok==0)
|
||||
{
|
||||
plugin_env->export_resource_record_enable=0;
|
||||
fprintf(stderr, "[%s:%d] config file: %s has no key: [decoder.ssl.test.export_resource_record_enable]", __FUNCTION__, __LINE__, cfg_path);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(memcmp("no", export_resource_record_enable_val.u.s, strlen("no"))==0)
|
||||
{
|
||||
plugin_env->export_resource_record_enable=0;
|
||||
}
|
||||
else if(memcmp("yes", export_resource_record_enable_val.u.s, strlen("yes"))==0)
|
||||
{
|
||||
plugin_env->export_resource_record_enable=1;
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin_env->export_resource_record_enable=1;
|
||||
fprintf(stderr, "[%s:%d] config file: %s key: [decoder.ssl.test.export_resource_record_enable] value is not yes or no", __FUNCTION__, __LINE__, cfg_path);
|
||||
}
|
||||
}
|
||||
|
||||
toml_free(root);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" void *ssl_decoder_test_init(struct stellar *st)
|
||||
{
|
||||
struct ssl_decoder_test_plugin_env *plugin_env=(struct ssl_decoder_test_plugin_env *)calloc(1, sizeof(struct ssl_decoder_test_plugin_env));
|
||||
|
||||
plugin_env->result_index=1;
|
||||
ssl_decoder_test_config_load(ssl_DECODER_TEST_TOML_PATH, plugin_env);
|
||||
|
||||
plugin_env->plugin_id=stellar_session_plugin_register(st, ssl_decoder_test_per_session_context_new, ssl_decoder_test_per_session_context_free, plugin_env);
|
||||
if(plugin_env->plugin_id<0)
|
||||
{
|
||||
printf("ssl_decoder_test_init: stellar_plugin_register failed !!!\n");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
plugin_env->topic_id=stellar_session_mq_get_topic_id(st, SSL_DECODER_MESSAGE_TOPIC);
|
||||
if(plugin_env->topic_id<0)
|
||||
{
|
||||
printf("stellar_session_mq_get_topic_id failed, topic: %s \n", SSL_DECODER_MESSAGE_TOPIC);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
stellar_session_mq_subscribe(st, plugin_env->topic_id, ssl_decoder_test_message_cb, plugin_env->plugin_id);
|
||||
|
||||
return (void *)plugin_env;
|
||||
}
|
||||
|
||||
extern "C" void ssl_decoder_test_exit(void *plugin_env_str)
|
||||
{
|
||||
if(plugin_env_str!=NULL)
|
||||
{
|
||||
free(plugin_env_str);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user