TSG-13584: Firewall的安全日志依赖session record日志,修复TRAFFIC_SHAPING_PROFILE表是否生效字段编号定义错误,使用cppcheck进行代码检查

This commit is contained in:
刘学利
2023-02-09 07:14:55 +00:00
parent 6756fcdf7a
commit 1332eedb94
47 changed files with 1477 additions and 2078 deletions

View File

@@ -1,25 +0,0 @@
cmake_minimum_required(VERSION 2.8)
include_directories(${CMAKE_SOURCE_DIR}/inc)
include_directories(/opt/MESA/include/MESA/)
include_directories(/opt/MESA/include)
include_directories(/usr/include/)
set(CMAKE_INSTALL_PREFIX /home/mesasoft/sapp_run)
add_library(tsg_master_gtest SHARED src/tsg_master_gtest_protocol.cpp src/tsg_master_gtest_entry.cpp)
set_target_properties(tsg_master_gtest PROPERTIES PREFIX "")
add_definitions(-std=c++11)
LINK_DIRECTORIES(/opt/MESA/lib)
add_executable(master_gtest "src/tsg_master_gtest_main.cpp")
target_compile_options(master_gtest PUBLIC ${MEM_POOL_DEFINITIONS})
target_link_libraries(master_gtest pthread dl m pcap systemd cjson MESA_prof_load MESA_htable MESA_handle_logger MESA_jump_layer breakpad_mini MESA_field_stat2)
target_link_libraries(master_gtest /home/mesasoft/sapp_run/lib/libsapp_devel.so)
target_link_libraries(master_gtest gtest-static ctemplate-static)
install(TARGETS master_gtest DESTINATION ${CMAKE_INSTALL_PREFIX}/ COMPONENT EXECUTABLE)

View File

@@ -1,4 +0,0 @@
[platform]
./plug/platform/tsg_master/tsg_master.inf
[protocol]
[business]

View File

@@ -1,6 +0,0 @@
vlan[*]
mpls[*]
gre[*]
gtp[*]

View File

@@ -1,2 +0,0 @@
#

View File

@@ -1,27 +0,0 @@
IP
IPV6
IPV6_RAW
TCP_ALL
TCP
UDP
HTTP
SSL
MAIL
FTP
PHONY
POLLING
IPSEC
L2TP
PPTP
RTP
DNS
GTP
STRATUM
RADIUS
QUIC
RDP
SSH
SOCKS
BGP
DTLS
SIP

View File

@@ -1,5 +0,0 @@
[Module]
pcapdevice=ens1f0
sendto_gdev_card=ens1f0
sendto_gdev_ip=10.252.20.1
gdev_status_switch=1

View File

@@ -1,14 +0,0 @@
[main]
nfs_proto_stat_path=./log
nfs_ddos_flow_detail_path=./log
[gdev]
service_type=1
rule_scope=1
durable=0
auth_data=B9840E2442951834
#phony server
c3_list=10.0.6.201:22;
c3_server_ip=10.0.6.201
c3_server_port=22

View File

@@ -1,4 +0,0 @@
#以下插件如果加载,初始化失败, sapp平台会退出;
#插件的路径来自配置文件 ./plug/conflist.inf, 不需要加段落标识[platform],[protocol],[business]等.
#If the following plugins fail to initialize, the sapp platform will exit.
#The name of the plugin comes from the configuration ./plug/conflist.inf, section identification is not required.

View File

@@ -1,5 +0,0 @@
[PLUGIN]
platform_config = ./plug/platform/conflist_platform.inf
protocol_config = ./plug/protocol/conflist_protocol.inf
business_config = ./plug/business/conflist_business.inf
entrylist_config = ./etc/entrylist.conf

View File

@@ -1,18 +0,0 @@
tcp_flow_stat struct
udp_flow_stat struct
tcp_deduce_flow_stat struct
POLICY_PRIORITY struct
ESTABLISH_LATENCY long
MAIL_IDENTIFY int
TSG_MASTER_INTERNAL_LABEL struct
BASIC_PROTO_LABEL struct
SKETCH_TRANS_LAYER_CTX_LABEL struct
SKETCH_PROTO_CTX_LABEL struct
common_link_info_c2s struct
common_link_info_s2c struct
common_link_info struct
JA3_FINGERPRINT_LABEL struct
DKPT_PRO_V2 struct
DPKT_PROJECT_V2 struct
PPROJECT_PRO_V2 struct
DPKT_BHSTAT_PROJECT struct

View File

@@ -1,266 +0,0 @@
###################################################################################################
# NOTE: #
# The format of this file is toml (https://github.com/cktan/tomlc99) #
# to make vim editor display colorful and human readable, #
# you can create a symbolic links named sapp.ini to sapp.toml, ln -sf sapp.toml sapp.ini #
###################################################################################################
[SYSTEM]
instance_name = "sapp_v4.2"
[CPU]
worker_threads=1
send_only_threads_max=0
### note, bind_mask, if you do not want to bind thread to special CPU core, keep it empty as []
### there are two different grammars:
### toml array format: bind_mask=[1,2,3,4,5,11,12,13,14,15]
### MESA_load_profile range format: bind_mask="1-5,11-15"
bind_mask=[]
[MEM]
dictator_enable=1
[PACKET_IO]
[overlay_tunnel_definition]
### note, since 2020-10-01, L2-L3 tunnel(VLAN,MPLS,PPPOE,etc.) is process and offload by mrtunnat,
### after 2020-10-01, sapp support L2-L3 tunnel(VLAN,MPLS,PPPOE,etc.) without mrtunnat.
l2_l3_tunnel_support=0
### note, optional value is [none, vxlan]
overlay_mode=none
[packet_io.feature]
destroy_all_plug_enabled=0
### note, used to represent inbound or outbound direction value,
### because it comes from Third party device, so it needs to be specified manually,
### if inbound_route_dir=1, then outbound_route_dir=0, vice versa,
### in other words, outbound_route_dir = 1 ^ inbound_route_dir;
inbound_route_dir=1
### note, BSD_packet_filter, if you do not want to set any filter rule, keep it empty as ""
BSD_packet_filter=""
### note, same as tcpdump -Q/-P arg, possible values are `in', `out' and `inout', default is "in"
pcap_capture_direction="in"
### note, support two mode: "inner_tuple2", "outer_tuple2"
pcap_distmode="inner_tuple2"
### note, depolyment.mode options: [sys_route, vxlan_by_inline_device, raw_ethernet_single_gateway, raw_ethernet_multi_gateway]
### sys_route: send ip(ipv6) packet by system route table, this is default mode in mirror mode;
### vxlan_by_inline_device: encapsulation inject packet with vxlan, and then send to inline device by udp socket.
### raw_ethernet_single_gateway: send layer2 ethernet packet to specific gateway in same broadcast domain.
### raw_ethernet_multi_gateway: send layer2 ethernet packet to multiple gateway in same broadcast domain.
inject_pkt_mode=sys_route
### note, this config is valid if inject_pkt_mode==vxlan_by_inline_device, means udp socket src port.
inject_mode_inline_device_sport=54789
### note, this config is valid if inject_pkt_mode==raw_ethernet_single_gateway.
inject_mode_single_gateway_device="eth1"
### inject_mode_single_gateway_src_mac has lower priority than get smac from inject_mode_single_gateway_device
inject_mode_single_gateway_src_mac="00:11:22:77:88:99"
inject_mode_single_gateway_dst_mac="00:11:22:33:44:55"
dumpfile_sleep_time_before_exit=0
### note, for example, dst mac is 01:12:34:56:78:90, src src is 02:AA:BB:CC:DD:EE:FF,
### ether[0] is 0x01, dst mac first octet, ether[1] is 0x12, dst mac second octet,
### ether[6] is 0x02, src mac first octet, ether[11] is 0xFF, src mac sixth octet.
### the bit field is from 0 to 7, the 0 is least significant bit, the 7 is most significant bit.
##extract_linkdir_from_mac_in_mirror_mode="ether[4]:0" ## for Xj example
extract_linkdir_from_mac_in_mirror_mode=""
### note, depolyment.mode options: [mirror, inline, transparent]
[packet_io.depolyment]
mode=mirror
### note, interface.type options: [pag, pcap, marsio, tun]
### receive from internal interface, route dir is 0,
### receive from external interface, route dir is 1.
[packet_io.internal.interface]
type=pcap
name="lo"
[packet_io.external.interface]
type=pcap
name=lo
[packet_io.polling]
enabled=1
### note, polling_priority = call sapp_recv_pkt every call polling_entry times,
polling_priority=1
[packet_io.under_ddos]
### note, to reduce impact of ddos attack,set some stream bypass, all plugins will not process these streams
stream_bypass_enabled=0
### note, cpu usage value is percent, for example, config value is 85, means 85%, valid range: [1,100]
### sapp change to bypass state immediately when realtime cpu usage > bypass_trigger_cpu_usage
bypass_trigger_cpu_usage=85
### note, unit of get_cpu_usage_interval is milliseconds(ms)
get_cpu_usage_interval=500
### note, use the average of the last $smooth_avg_window times as current realtime value
smooth_avg_window=2
decrease_ratio="0.95"
increase_ratio="1.005"
### note, unit of bypass_observe_time is second(s)
recovery_observe_time=30
[PROTOCOL_FEATURE]
ipv6_decapsulation_enabled=1
ipv6_send_packet_enabled=1
tcp_drop_pure_ack_pkt=0
tcp_syn_option_parse_enabled=1
skip_not_ip_layer_over_eth=0
skip_gtp_S_PN_E_field_for_inject=0
[DUPLICATE_PKT]
[dup_pkt.traffic.original]
original_ipv4_tcp_enabled=1
original_ipv4_udp_enabled=0
### note, can't distinguish between duplicate traffic and application retransmit traffic for IPv6 packets,
### so not support IPv6 original duplicate traffic check.
[dup_pkt.traffic.inject]
inject_all_enabled=1
[dup_pkt.parameters]
bloom_capacity=1000000
bloom_error_rate=0.00001
bloom_timeout=10
[STREAM]
### note, stream_id_base_time format is "%Y-%m-%d %H:%M:%S"
stream_id_base_time="2021-01-01 00:00:00"
[stream.tcp]
max=1000
timeout=0
syn_mandatory=1
reorder_pkt_max=5
analyse_option_enabled=1
tuple4_reuse_time_interval=30
meaningful_statistics_minimum_pkt=3
meaningful_statistics_minimum_byte=5
special_timeout_ratio=10
[stream.tcp.inject]
link_mss=1460
[stream.tcp.inject.rst]
auto_remedy=1
number=1
signature_enabled=1
signature_seed1=65535
signature_seed2=13
remedy_kill_tcp_by_inline_device=0
[stream.udp]
max=1000
timeout=0
meaningful_statistics_minimum_pkt=3
meaningful_statistics_minimum_byte=5
special_timeout_ratio=20
[PROFILING]
[profiling.pkt_latency]
enabled=0
accurate_enable=0
### note, threshold unit is microseconds (us)
threshold=100000
[profiling.sanity_check]
raw_pkt_broken_enabled=0
symbol_conflict_enabled=0
[profiling.log]
level=20
interval=1
[profiling.log.local]
enabled=1
### note, if "file_truncate_open_enabled=1", file will be truncated, otherwise open the file for appending.
file_truncate_enabled = 1
[profiling.log.remote]
enabled=0
server_ip="127.0.0.1"
server_port=8126
[profiling.log.remote.field_stat2]
### note, is valid when "remote_send_out_type=field_stat2"
### note, metric_type option value: [default, json]
metric_type = default
app_name=sapp
[profiling.log.prometheus]
prometheus_enabled=0
prometheus_port=9273
prometheus_url_path="/metrics"
[TOOLS]
[tools.pkt_dump]
enabled=0
### note, mode options value:[storage, udp_socket]
mode=udp_socket
BSD_packet_filter=""
[tools.pkt_dump.threads]
### note, if you want enable pkt dump in all thread, set dump_thread_all_enabled=0
### if dump_thread_all_enabled=0, then use dump_thread_id to specify separate specified thread index.
all_threads_enabled=1
### note, dump_thread_id start from 0, max is CPU.worker_threads-1
dump_thread_id=[0,1,2,3,4]
[tools.pkt_dump.udp]
command_port=12345
pkt_dump_ratio=30
[tools.pkt_dump.storage]
### note, file path must be double quotation mark extension, for example, path="/dev/shm/pkt_dump"
path="/dev/shm/pkt_dump"
### note, file size unit: MB
file_size_max_per_thread=10000
[breakpad]
disable_coredump=0
enable_breakpad=0
breakpad_minidump_dir="/tmp/crashreport"
enable_breakpad_upload=0
breakpad_upload_url="http://127.0.0.1/"
breakpad_upload_tools="/opt/MESA/bin/minidump_upload"
### note:
### These configurations format is complex and difficult to describe with toml grammar,
### so, create a independent secondary config file to description specific information.
[SECONDARY_CONFIG_LINK]
cfg_file_sapp_log="etc/sapp_log.conf"
cfg_file_plug_list="plug/conflist.inf"
cfg_file_project_list="etc/project_list.conf"
cfg_file_entrylist="etc/entrylist.conf"
cfg_file_send_raw_pkt="etc/send_raw_pkt.conf"
cfg_file_vxlan_sport_map="etc/vxlan_sport_service_map.conf"
cfg_file_inline_device="etc/gdev.conf"
cfg_file_necessary_plug_list="etc/necessary_plug_list.conf"
cfg_file_stream_compare_layer="etc/stream_compare_layer.conf"
cfg_file_vlan_flipping="etc/vlan_flipping_map.conf"
cfg_file_asymmetric_addr_layer="etc/asymmetric_addr_layer.conf"
cfg_file_well_known_port="etc/well_known_port.conf"
[SECONDARY_DATA_LINK]
data_file_sysinfo_log="sysinfo.log"
data_file_field_stat_log="fs2_sysinfo.log"
data_file_inline_keepalive_log="gdev_keeplive_status.log"
data_file_load_plugin_stat_log="load_plugin_stat.log"
data_file_under_ddos_stat_log="under_ddos_stat.log"
data_file_memory_stat_log="memory_used_stat.log"
[LIBRARY_LINK]
marsio_library_path="/opt/mrzcpd/lib/libmarsio.so"

View File

@@ -1,16 +0,0 @@
[global]
default format = "%d(%c), %V, %U, %m%n"
[levels]
DEBUG=10
INFO=20
FATAL=30
STOP=40
[formats]
other = "%d(%c), %V, %F, %U, %m%n"
plugin = "%d(%c), %m%n"
[rules]
__log_runtimelog.info "./log/runtimelog.%d(%F)"
__log_runtimelog_plugin.fatal >stdout; plugin
__log_runtimelog_plugin.fatal "./log/plugin.log"; plugin
__log_http_runtime.stop "./log/%c.%d(%F)"; other
!.* "./log/%c.%d(%F)"; other

View File

@@ -1,2 +0,0 @@
3 10.3.127.1

View File

@@ -1,16 +0,0 @@
#<23><><EFBFBD><EFBFBD>ԭʼ<D4AD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
#<23><>ƽ̨<C6BD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20>ײ<EFBFBD><D7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҳ<EFBFBD><D2B2>ͬ,
#<23><><EFBFBD><EFBFBD>ͨģʽ<C4A3><CABD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, DPDKģʽ<C4A3><CABD>ʹ<EFBFBD>ö˿ں<CBBF>, PFRINGģʽ<C4A3><CABD>ʹ<EFBFBD><CAB9>index<65><78>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ.
#target_id<69><64><EFBFBD>ڱ<EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD>ն˷<D5B6><CBB7><EFBFBD>,
#<23><><EFBFBD>ڷ<EFBFBD><DAB7>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0>ײ<EFBFBD>MAC<41><43>Ŀ<EFBFBD><C4BF>IP<49><50>, <20><><EFBFBD>ϲ<EFBFBD><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, ƽֻ̨<CCA8><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭʼ<D4AD><CABC>.
#target_id<69><EFBFBD><E0B5B1><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#(0:pag,1:pcap,2:dumpfile,3:pfring,4:DPDK,5:ppf,6:NPacket,7:qnf,8:N95,9:pcap-dumpfile-list,10:topsec,
##(11:ipfile, 12:marsio4, 13:agent_smith, 14:dpdk_vxlan, 15:marsio_vxlan, 16:pag_marsio
#target_id
#0 pag p7p2 eth1 dna0 dpdk ppf npacket qnf n95 eth1 topsec eth1 vxlan_user smith dpdk dpdk pag
#1 pag eth1 eth1 dna0 dpdk ppf npacket qnf n95 eth1 topsec eth1 p7p1 smith dpdk dpdk pag
#2 pag eth1 eth1 dna0 dpdk ppf npacket qnf n95 eth1 topsec eth1 p7p1 smith dpdk dpdk pag
#3 pag eth1 eth1 dna0 dpdk ppf npacket qnf n95 eth1 topsec eth1 p7p2 smith dpdk dpdk pag
#4 pag eth1 eth1 dna0 dpdk ppf npacket qnf n95 eth1 topsec eth1 p7p2 smith dpdk dpdk pag

View File

@@ -1,3 +0,0 @@
#dev_id link_id mac_addr
3 2 00:50:56:f3:59:5c

View File

@@ -1,2 +0,0 @@
#

View File

@@ -1,12 +0,0 @@
#for inline a device vlan flipping
#数据包来自C路由器端, 即C2I(I2E)方向,
#数据包来自I路由器端, 即I2C(E2I)方向,
#平台会根据vlan_id,设置当前包route_dir的值, 以便上层业务插件做两个方向的流量统计,
#如果一对vlan_id写反了, 网络是通的, 但是I2E,E2I的流量统计就颠倒了.
#配置文件格式, pattern:
#来自C路由器vlan_id 来自I路由器vlan_id 是否开启mac地址翻转
#C_router_vlan_id I_router_vlan_id mac_flipping_enable
#1001 1002 1
#1003 1004 1
#4000 4001 0

View File

@@ -1,86 +0,0 @@
#service-id vpn-id sport-dport
1 101 50000-50016
2 102 50064-50080
3 103 50128-50144
4 104 50192-50208
5 105 50256-50272
6 106 50320-50336
7 107 50384-50384
8 108 50448-50464
9 109 50512-50512
10 110 50576-50592
11 111 50640-50656
12 112 50704-50720
13 113 50768-50784
14 114 50832-50848
15 115 50896-50912
16 116 50960-50960
17 117 51024-51024
18 118 51088-51088
19 119 51152-51168
20 120 51216-51232
21 121 51280-51296
22 122 51344-51360
23 123 51408-51408
24 124 51472-51472
25 125 51536-51536
26 126 51600-51600
27 127 51664-51664
28 128 51728-51728
29 129 51792-51792
30 130 51856-51856
31 131 51920-51920
32 132 51984-51984
33 133 52048-52064
34 134 52112-52128
35 135 52176-52192
36 136 52240-52256
37 137 52304-52320
38 138 52368-52384
39 139 52432-52448
40 140 52496-52512
41 141 52560-52576
42 142 52624-52640
43 143 52688-52704
44 144 52752-52768
45 145 52816-52832
46 146 52880-52896
47 147 52944-52960
48 148 53008-53024
49 149 53072-53088
50 150 53136-53152
51 151 53200-53216
52 152 53264-53280
53 153 53328-53344
54 154 53392-53408
55 155 53456-53472
56 156 53520-53536
57 157 53584-53600
58 158 53648-53664
59 159 53712-53712
60 160 53776-53776
61 161 53840-53840
62 162 53904-53904
63 163 53968-53968
64 164 54032-54032
65 165 54096-54096
66 166 54160-54176
67 167 54224-54240
68 168 54288-54304
69 169 54352-54368
70 170 54416-54432
71 171 54480-54496
72 172 54544-54560
73 173 54608-54624
74 174 54672-54688
75 175 54736-54736
76 176 54800-54800
77 177 54864-54864
78 178 54928-54928
79 179 54992-54992
80 180 55056-55056
81 181 55120-55120
82 182 55184-55184
83 183 55248-55248
84 184 55312-55312
85 185 55376-55376

View File

@@ -1,2 +0,0 @@
[TCP]
[UDP]

View File

@@ -1,9 +0,0 @@
[PLUGINFO]
PLUGNAME=GTEST_MASTER
SO_PATH=./plug/platform/tsg_master_gtest/tsg_master_gtest.so
INIT_FUNC=GTEST_INIT
DESTROY_FUNC=GTEST_UNLOAD
[TCP_ALL]
FUNC_FLAG=ALL
FUNC_NAME=GTEST_APP_FULL_PATH_1_ENTRY

View File

@@ -9,7 +9,7 @@ include_directories(${PROJECT_SOURCE_DIR}/src/)
add_definitions(-std=c++11)
LINK_DIRECTORIES(/opt/MESA/lib)
add_executable(gtest_rule ${PROJECT_SOURCE_DIR}/src/tsg_rule.cpp gtest_common.cpp gtest_rule.cpp)
add_executable(gtest_rule ${PROJECT_SOURCE_DIR}/src/tsg_rule.cpp ${PROJECT_SOURCE_DIR}/src/tsg_bridge.cpp ${PROJECT_SOURCE_DIR}/src/tsg_leaky_bucket.cpp gtest_common.cpp gtest_rule.cpp)
target_link_libraries(gtest_rule gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger MESA_jump_layer MESA_field_stat2 maatframe)
set(TSG_MASTER_SRC ${PROJECT_SOURCE_DIR}/src/tsg_entry.cpp
@@ -24,7 +24,8 @@ set(TSG_MASTER_SRC ${PROJECT_SOURCE_DIR}/src/tsg_entry.cpp
${PROJECT_SOURCE_DIR}/src/tsg_dns.cpp
${PROJECT_SOURCE_DIR}/src/tsg_icmp.cpp
${PROJECT_SOURCE_DIR}/src/tsg_tamper.cpp
${PROJECT_SOURCE_DIR}/src/tsg_bridge.cpp
)
add_executable(gtest_master ${TSG_MASTER_SRC} gtest_common.cpp gtest_master.cpp)
target_link_libraries(gtest_master gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger MESA_jump_layer MESA_field_stat2 maatframe rdkafka MESA_htable)
add_executable(gtest_master ${TSG_MASTER_SRC} gtest_kafka.cpp gtest_common.cpp gtest_master.cpp)
target_link_libraries(gtest_master gtest-static ctemplate-static cjson MESA_prof_load MESA_handle_logger MESA_jump_layer MESA_field_stat2 maatframe MESA_htable)

76
test/src/gtest_kafka.cpp Normal file
View File

@@ -0,0 +1,76 @@
#include <string.h>
#include <librdkafka/rdkafka.h>
#ifndef MIN
#define MIN(a,b) ((a)>(b) ? (b) : (a))
#endif
int g_kafka_sendlog_cnt=0;
char g_kafka_sendlog[16][1024]={0,0};
rd_kafka_conf_t *rd_kafka_conf_new(void)
{
return (rd_kafka_conf_t *)0x1;
}
rd_kafka_conf_res_t rd_kafka_conf_set(rd_kafka_conf_t *conf, const char *name, const char *value, char *errstr, size_t errstr_size)
{
return (rd_kafka_conf_res_t)0x1;
}
rd_kafka_t *rd_kafka_new(rd_kafka_type_t type, rd_kafka_conf_t *conf, char *errstr, size_t errstr_size)
{
return (rd_kafka_t *)0x2;
}
rd_kafka_topic_conf_t* rd_kafka_topic_conf_new(void)
{
return (rd_kafka_topic_conf_t*)0x3;
}
rd_kafka_topic_t* rd_kafka_topic_new(rd_kafka_t *rk, const char *topic, rd_kafka_topic_conf_t * conf)
{
return (rd_kafka_topic_t*)0x4;
}
void rd_kafka_topic_destroy (rd_kafka_topic_t *rkt)
{
}
void rd_kafka_destroy (rd_kafka_t *rk)
{
}
rd_kafka_resp_err_t rd_kafka_last_error(void)
{
return (rd_kafka_resp_err_t)0x5;
}
const char *rd_kafka_err2name(rd_kafka_resp_err_t err)
{
return "err2name";
}
const char *rd_kafka_err2str(rd_kafka_resp_err_t err)
{
return "err2str";
}
int rd_kafka_produce(rd_kafka_topic_t *rkt, int32_t partitition, int msgflags, void *payload, size_t len, const void *key, size_t keylen, void *msg_opaque)
{
int length=MIN(len, sizeof(g_kafka_sendlog[g_kafka_sendlog_cnt]));
memcpy((void *)(g_kafka_sendlog[g_kafka_sendlog_cnt++]), payload, length);
return 0;
}
int rd_kafka_get_sendlog_cnt(void)
{
return g_kafka_sendlog_cnt;
}
const char *rd_kafka_get_sendlog_payload(int idx)
{
if(idx>g_kafka_sendlog_cnt || idx <0)
{
return NULL;
}
return (const char *)g_kafka_sendlog[idx];
}

3
test/src/gtest_kafka.h Normal file
View File

@@ -0,0 +1,3 @@
#pragma once

View File

@@ -7,6 +7,9 @@
#include "tsg_entry.h"
#include <gtest/gtest.h>
extern int rd_kafka_get_sendlog_cnt(void);
extern const char *rd_kafka_get_sendlog_payload(int idx);
TEST(TSGMaster, SetAPPIDHttp)
{
struct streaminfo a_stream={0};
@@ -16,8 +19,8 @@ TEST(TSGMaster, SetAPPIDHttp)
gather_result[ORIGIN_BASIC_PROTOCOL].origin=ORIGIN_BASIC_PROTOCOL;
gather_result[ORIGIN_BASIC_PROTOCOL].attributes[0].app_id=67; //HTTP
project_req_add_struct(&a_stream, g_tsg_para.gather_app_project_id, (const void *)gather_result);
struct gather_app_result *get_result=(struct gather_app_result *)project_req_get_struct(&a_stream, g_tsg_para.gather_app_project_id);
tsg_set_xxx_to_bridge(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_GATHER_APP_RESULT].id, (void *)gather_result);
struct gather_app_result *get_result=(struct gather_app_result *)tsg_get_xxx_from_bridge(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_GATHER_APP_RESULT].id);
EXPECT_NE(nullptr, get_result);
EXPECT_EQ(1, get_result[ORIGIN_BASIC_PROTOCOL].app_num);
EXPECT_EQ(67, get_result[ORIGIN_BASIC_PROTOCOL].attributes[0].app_id);
@@ -32,8 +35,8 @@ TEST(TSGMaster, SetAPPIDHttp)
EXPECT_STREQ("{\"common_app_full_path\":\"http\",\"common_app_label\":\"http\"}", app_ids);
project_req_add_struct(&a_stream, g_tsg_para.gather_app_project_id, NULL);
get_result=(struct gather_app_result *)project_req_get_struct(&a_stream, g_tsg_para.gather_app_project_id);
tsg_set_xxx_to_bridge(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_GATHER_APP_RESULT].id, NULL);
get_result=(struct gather_app_result *)tsg_get_xxx_from_bridge(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_GATHER_APP_RESULT].id);
EXPECT_EQ(nullptr, get_result);
}
@@ -68,7 +71,7 @@ TEST(TSGMaster, ShapingSetRuleIds)
TLD_convert_json(handle, shaping_rule_ids, sizeof(shaping_rule_ids));
EXPECT_STREQ("{\"common_shaping_rule_ids\":\"32,33,34,35,36,37,38,39\"}", shaping_rule_ids);
struct notify_shaping_policy *shaping_label=(struct notify_shaping_policy *)stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT]);
struct notify_shaping_policy *shaping_label=(struct notify_shaping_policy *)stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id);
EXPECT_NE(nullptr, shaping_label);
EXPECT_EQ(MAX_RESULT_NUM, shaping_label->shaping_result_num);
for(int i=0; i<shaping_label->shaping_result_num; i++)
@@ -77,9 +80,9 @@ TEST(TSGMaster, ShapingSetRuleIds)
EXPECT_EQ(TSG_ACTION_SHAPING+i, shaping_label->shaping_result[i].config_id);
}
free_shaping_result(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT], (void *)shaping_label);
stream_bridge_async_data_put(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT], NULL);
EXPECT_EQ(nullptr, stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT]));
free_shaping_result(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id, (void *)shaping_label);
stream_bridge_async_data_put(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id, NULL);
EXPECT_EQ(nullptr, stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id));
}
int shaping_policy_notify_cb(const struct streaminfo *stream, int bridge_id, void *data)
@@ -107,7 +110,7 @@ TEST(TSGMaster, ShapingPolicyNotify)
shaping_result[i].config_id=TSG_ACTION_SHAPING+i;
}
stream_bridge_register_data_sync_cb(g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT], shaping_policy_notify_cb);
stream_bridge_register_data_sync_cb(g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id, shaping_policy_notify_cb);
tsg_notify_hited_shaping_result(&a_stream, shaping_result, MAX_RESULT_NUM, 0);
int shaping_result_num=tsg_pull_shaping_result((struct streaminfo *)&a_stream, shaping_result, MAX_RESULT_NUM);
@@ -118,7 +121,7 @@ TEST(TSGMaster, ShapingPolicyNotify)
EXPECT_EQ(TSG_ACTION_SHAPING+i, shaping_result[i].config_id);
}
struct notify_shaping_policy *shaping_label=(struct notify_shaping_policy *)stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT]);
struct notify_shaping_policy *shaping_label=(struct notify_shaping_policy *)stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id);
EXPECT_NE(nullptr, shaping_label);
EXPECT_EQ(MAX_RESULT_NUM, shaping_label->shaping_result_num);
for(int i=0; i<shaping_label->shaping_result_num; i++)
@@ -127,9 +130,9 @@ TEST(TSGMaster, ShapingPolicyNotify)
EXPECT_EQ(TSG_ACTION_SHAPING+i, shaping_label->shaping_result[i].config_id);
}
free_shaping_result(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT], (void *)shaping_label);
stream_bridge_async_data_put(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT], NULL);
EXPECT_EQ(nullptr, stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT]));
free_shaping_result(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id, (void *)shaping_label);
stream_bridge_async_data_put(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id, NULL);
EXPECT_EQ(nullptr, stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id));
}
int shaping_policy_notify_null_cb(const struct streaminfo *stream, int bridge_id, void *data)
@@ -143,10 +146,10 @@ TEST(TSGMaster, ShapingPolicyNotifyNULL)
const struct streaminfo a_stream={0};
struct Maat_rule_t shaping_result[MAX_RESULT_NUM]={0};
stream_bridge_register_data_sync_cb(g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT], shaping_policy_notify_null_cb);
stream_bridge_register_data_sync_cb(g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id, shaping_policy_notify_null_cb);
tsg_notify_hited_shaping_result(&a_stream, shaping_result, 0, 0);
struct notify_shaping_policy *shaping_label=(struct notify_shaping_policy *)stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT]);
struct notify_shaping_policy *shaping_label=(struct notify_shaping_policy *)stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id);
EXPECT_EQ(nullptr, shaping_label);
}
@@ -175,7 +178,7 @@ TEST(TSGMaster, ShapingDuplicatePolicyNotify)
shaping_result[i].config_id=TSG_ACTION_SHAPING+(i%4);
}
stream_bridge_register_data_sync_cb(g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT], shaping_duplicate_policy_notify_cb);
stream_bridge_register_data_sync_cb(g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id, shaping_duplicate_policy_notify_cb);
tsg_notify_hited_shaping_result(&a_stream, shaping_result, MAX_RESULT_NUM, 0);
int shaping_result_num=tsg_pull_shaping_result((struct streaminfo *)&a_stream, shaping_result, MAX_RESULT_NUM);
@@ -186,7 +189,7 @@ TEST(TSGMaster, ShapingDuplicatePolicyNotify)
EXPECT_EQ(TSG_ACTION_SHAPING+i, shaping_result[i].config_id);
}
struct notify_shaping_policy *shaping_label=(struct notify_shaping_policy *)stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT]);
struct notify_shaping_policy *shaping_label=(struct notify_shaping_policy *)stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id);
EXPECT_NE(nullptr, shaping_label);
EXPECT_EQ(MAX_RESULT_NUM/2, shaping_label->shaping_result_num);
for(int i=0; i<shaping_label->shaping_result_num; i++)
@@ -195,9 +198,9 @@ TEST(TSGMaster, ShapingDuplicatePolicyNotify)
EXPECT_EQ(TSG_ACTION_SHAPING+i, shaping_label->shaping_result[i].config_id);
}
free_shaping_result(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT], (void *)shaping_label);
stream_bridge_async_data_put(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT], NULL);
EXPECT_EQ(nullptr, stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT]));
free_shaping_result(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id, (void *)shaping_label);
stream_bridge_async_data_put(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id, NULL);
EXPECT_EQ(nullptr, stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id));
}
TEST(TSGMaster, ShapingDuplicatePolicyMultipleNotify)
@@ -211,7 +214,7 @@ TEST(TSGMaster, ShapingDuplicatePolicyMultipleNotify)
shaping_result[i].config_id=TSG_ACTION_SHAPING+i;
}
stream_bridge_register_data_sync_cb(g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT], shaping_duplicate_policy_notify_cb);
stream_bridge_register_data_sync_cb(g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id, shaping_duplicate_policy_notify_cb);
// First notify
tsg_notify_hited_shaping_result(&a_stream, shaping_result, MAX_RESULT_NUM/2, 0);
@@ -223,7 +226,7 @@ TEST(TSGMaster, ShapingDuplicatePolicyMultipleNotify)
EXPECT_EQ(TSG_ACTION_SHAPING+i, shaping_result[i].config_id);
}
struct notify_shaping_policy *shaping_label=(struct notify_shaping_policy *)stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT]);
struct notify_shaping_policy *shaping_label=(struct notify_shaping_policy *)stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id);
EXPECT_NE(nullptr, shaping_label);
EXPECT_EQ(MAX_RESULT_NUM/2, shaping_label->shaping_result_num);
for(int i=0; i<shaping_label->shaping_result_num; i++)
@@ -242,7 +245,7 @@ TEST(TSGMaster, ShapingDuplicatePolicyMultipleNotify)
EXPECT_EQ(TSG_ACTION_SHAPING+i, shaping_result[i].config_id);
}
shaping_label=(struct notify_shaping_policy *)stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT]);
shaping_label=(struct notify_shaping_policy *)stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id);
EXPECT_NE(nullptr, shaping_label);
EXPECT_EQ(MAX_RESULT_NUM/2, shaping_label->shaping_result_num);
for(int i=0; i<shaping_label->shaping_result_num; i++)
@@ -251,9 +254,94 @@ TEST(TSGMaster, ShapingDuplicatePolicyMultipleNotify)
EXPECT_EQ(TSG_ACTION_SHAPING+i, shaping_label->shaping_result[i].config_id);
}
free_shaping_result(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT], (void *)shaping_label);
stream_bridge_async_data_put(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT], NULL);
EXPECT_EQ(nullptr, stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge_id[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT]));
free_shaping_result(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id, (void *)shaping_label);
stream_bridge_async_data_put(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id, NULL);
EXPECT_EQ(nullptr, stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_NOTIFY_SHAPING_RESULT].id));
}
TEST(TSGMaster, SecurityPolicySendlog)
{
const struct streaminfo a_stream={0};
struct Maat_rule_t security_result[MAX_RESULT_NUM]={0};
for(int i=0; i<MAX_RESULT_NUM; i++)
{
security_result[i].do_log=1;
security_result[i].action=TSG_ACTION_MONITOR;
security_result[i].config_id=TSG_ACTION_MONITOR+i;
}
// First notify
tsg_notify_hited_security_result(&a_stream, security_result, MAX_RESULT_NUM, 0);
struct policy_priority_label *priority_label=(struct policy_priority_label *)tsg_get_xxx_from_bridge(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_POLICY_PRIORITY].id);
EXPECT_NE(nullptr, priority_label);
EXPECT_EQ(MAX_RESULT_NUM, priority_label->security_result_num);
for(int i=0; i<priority_label->security_result_num; i++)
{
EXPECT_EQ(TSG_ACTION_MONITOR, priority_label->security_result[i].action);
EXPECT_EQ(TSG_ACTION_MONITOR+i, priority_label->security_result[i].config_id);
}
struct TLD_handle_t * handle=TLD_create(0);
struct Maat_rule_t session_record={0, 2, 1, 0, 0, 0, 0, {0}};
tsg_log_t log_msg={1, &session_record, (struct streaminfo*)&a_stream};
tsg_send_log(g_tsg_log_instance, handle, &log_msg, 0);
int sendlog_cnt=rd_kafka_get_sendlog_cnt();
EXPECT_EQ(9, sendlog_cnt);
//EXPECT_STREQ("{}", rd_kafka_get_sendlog_payload(0));
//EXPECT_STREQ("{}", rd_kafka_get_sendlog_payload(1));
//EXPECT_STREQ("{}", rd_kafka_get_sendlog_payload(2));
//EXPECT_STREQ("{}", rd_kafka_get_sendlog_payload(3));
//EXPECT_STREQ("{}", rd_kafka_get_sendlog_payload(4));
//EXPECT_STREQ("{}", rd_kafka_get_sendlog_payload(5));
//EXPECT_STREQ("{}", rd_kafka_get_sendlog_payload(6));
//EXPECT_STREQ("{}", rd_kafka_get_sendlog_payload(7));
//EXPECT_STREQ("{}", rd_kafka_get_sendlog_payload(8));
priority_label=(struct policy_priority_label *)tsg_get_xxx_from_bridge(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_POLICY_PRIORITY].id);
EXPECT_EQ(nullptr, priority_label);
}
TEST(TSGMaster, SecurityDuplicatePolicyMultipleNotify)
{
const struct streaminfo a_stream={0};
struct Maat_rule_t security_result[MAX_RESULT_NUM]={0};
for(int i=0; i<MAX_RESULT_NUM/2; i++)
{
security_result[i].action=TSG_ACTION_MONITOR;
security_result[i].config_id=TSG_ACTION_MONITOR+i;
}
// First notify
tsg_notify_hited_security_result(&a_stream, security_result, MAX_RESULT_NUM/2, 0);
struct policy_priority_label *priority_label=(struct policy_priority_label *)tsg_get_xxx_from_bridge(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_POLICY_PRIORITY].id);
EXPECT_NE(nullptr, priority_label);
EXPECT_EQ(MAX_RESULT_NUM/2, priority_label->security_result_num);
for(int i=0; i<priority_label->security_result_num; i++)
{
EXPECT_EQ(TSG_ACTION_MONITOR, priority_label->security_result[i].action);
EXPECT_EQ(TSG_ACTION_MONITOR+i, priority_label->security_result[i].config_id);
}
// Second notify
tsg_notify_hited_security_result(&a_stream, security_result, MAX_RESULT_NUM/2, 0);
priority_label=(struct policy_priority_label *)tsg_get_xxx_from_bridge(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_POLICY_PRIORITY].id);
EXPECT_NE(nullptr, priority_label);
EXPECT_EQ(MAX_RESULT_NUM/2, priority_label->security_result_num);
for(int i=0; i<priority_label->security_result_num; i++)
{
EXPECT_EQ(TSG_ACTION_MONITOR, priority_label->security_result[i].action);
EXPECT_EQ(TSG_ACTION_MONITOR+i, priority_label->security_result[i].config_id);
}
free_shaping_result(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_POLICY_PRIORITY].id, (void *)priority_label);
stream_bridge_async_data_put(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_POLICY_PRIORITY].id, NULL);
EXPECT_EQ(nullptr, stream_bridge_async_data_get(&a_stream, g_tsg_para.bridge[BRIDGE_TYPE_POLICY_PRIORITY].id));
}
int main(int argc, char *argv[])

View File

@@ -8,7 +8,7 @@
#include <gtest/gtest.h>
g_tsg_para_t g_tsg_para;
id2field_t g_tsg_proto_name2id[PROTO_MAX]={{PROTO_UNKONWN, 0, "unknown"},
struct id2field g_tsg_proto_name2id[PROTO_MAX]={{PROTO_UNKONWN, 0, "unknown"},
{PROTO_IPv4, 0, "IPV4"},
{PROTO_IPv6, 0, "IPV6"},
{PROTO_TCP, 0, "TCP"},
@@ -35,13 +35,19 @@ id2field_t g_tsg_proto_name2id[PROTO_MAX]={{PROTO_UNKONWN, 0, "unknown"},
{PROTO_DTLS, 0, "DTLS"}
};
unsigned int tsg_l7_protocol_name2id(const char *l7_protocol_name)
int app_identify_result_cb(const struct streaminfo *a_stream, int bridge_id, void *data)
{
return 0;
}
void free_policy_label(int thread_seq, void *project_req_value)
int session_flags_identify_result_cb(const struct streaminfo *a_stream, int bridge_id, void *data)
{
return 0;
}
unsigned int tsg_l7_protocol_name2id(const char *l7_protocol_name)
{
return 0;
}
void set_session_attribute_label(const struct streaminfo *a_stream, enum TSG_ATTRIBUTE_TYPE type, void *value, int value_len, int thread_seq)