diff options
| author | lijia <[email protected]> | 2019-08-23 18:21:39 +0800 |
|---|---|---|
| committer | lijia <[email protected]> | 2019-08-23 18:21:39 +0800 |
| commit | c85feeb44eef858cf53b8bc97082db25c0dcb3f7 (patch) | |
| tree | 8326ee7b71fc884ac3131c3eb62bcd26848cc3c3 | |
| parent | e3403925b9823bd4603825f7cc26701823d3d3c0 (diff) | |
增加新发包接口sapp_inject_pkt; 改polling_entry优先级; tcpdump_mesa配置文件修改
38 files changed, 455 insertions, 243 deletions
diff --git a/bin/etc/sapp.toml b/bin/etc/sapp.toml index 45e4fbe..a088f7a 100644 --- a/bin/etc/sapp.toml +++ b/bin/etc/sapp.toml @@ -1,7 +1,7 @@ ################################################################################################### # NOTE: # The format of this file is toml (https://github.com/cktan/tomlc99) -# to make vim editor display colorful easier to read, +# 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 ################################################################################################### @@ -14,118 +14,107 @@ worker_threads=1 bind_mask=[1,2,3,4] [PACKET_IO] -### note, packet filter, if you do not want to set any filter rule, keep it empty as "" - BSD_packet_filter="" +### note, BSD_packet_filter, if you do not want to set any filter rule, keep it empty as "" +BSD_packet_filter="" ### note, depolyment.mode options: [mirror, inline, transparent] - [packet_io.depolyment] + [packet_io.depolyment] mode=mirror ### note, interface.type options: [pag,pcap,marsio] - [packet_io.internal.interface] + [packet_io.internal.interface] type=pcap - name=lo + name="lo" - [packet_io.external.interface] + [packet_io.external.interface] type=pcap name=lo + + [packet_io.polling] +### note, polling_priority = call sapp_recv_pkt every call polling_entry times, + polling_priority=1 [STREAM] - [stream.tcp] + [stream.tcp] max=10000 timeout=60 syn_mandatory=0 reorder_pkt_max=5 analyse_option_enabled=1 - [stream.tcp.inject] - link_mss=1460 + [stream.tcp.inject] + link_mss=1460 - [stream.tcp.inject.rst] - number=3 - signature_enabled=1 + [stream.tcp.inject.rst] + number=3 + signature_enabled=1 signature_seed1=65535 signature_seed2=13 - [stream.udp] + [stream.udp] max=10000 timeout=60 - [PROFILING] - [profiling.pkt_latency] + [profiling.pkt_latency] enabled=0 ### note, threshold unit is microseconds (us) threshold=1000000 - [profiling.sanity_check] + [profiling.sanity_check] raw_pkt_broken_enabled=0 symbol_conflict_enabled=0 - [profiling.log] + [profiling.log] level=20 interval=5 - [profiling.log.local] - enabled=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 - log_file_name = "fs2_sysinfo.log" + file_truncate_enabled = 1 + log_file_name = "fs2_sysinfo.log" - [profiling.log.remote] - enabled=1 - server_ip="192.168.11.90" - server_port=8126 -### note, remote_send_out_type option value: [line_protocol, field_stat2] - remote_send_out_type=field_stat2 + [profiling.log.remote] + enabled=1 + server_ip="192.168.11.90" + server_port=8126 - [profiling.log.remote.field_stat2] + [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.remote.line_protocol] -### note, is valid when "remote_send_out_type=line_protocol" - [[profiling.log.remote.line_protocol.tags]] - tag_name = "tag1" - tag_value = "value1" - [[profiling.log.remote.line_protocol.tags]] - tag_name = "tag2" - tag_value = "value2" - [[profiling.log.remote.line_protocol.tags]] - tag_name = "tag3" - tag_value = "value3" - + metric_type = default + app_name=sapp + [TOOLS] - [tools.pkt_dump] + [tools.pkt_dump] enabled=1 ### note, mode options value:[storage, udp_socket] mode=udp_socket - BSD_packet_filter="ip" + BSD_packet_filter="" - [tools.pkt_dump.threads] + [tools.pkt_dump.threads] ### note, if you want enable pkt dump in all thread, set dump_thread_all_enabled=1, then 'dump_thread_id' is obsoleted. ### if dump_thread_all_enabled=0, then use dump_thread_id to specify separate specified thread index. - all_threads_enabled=1 + 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] + dump_thread_id=[0,1,2,3,4] - [tools.pkt_dump.udp] - command_port=12345 + [tools.pkt_dump.udp] + command_port=12345 - [tools.pkt_dump.storage] + [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" + path="/dev/shm/pkt_dump" ### note, file size unit: MB - file_size_max_per_thread=10000 + file_size_max_per_thread=10000 ### note: ### These configurations format is complex and difficult to describe with toml grammar, ### so, create a Independent config file to description specific information. [SPECIAL_CONFIG_LINK] - project_list_path="./etc/project_list.conf" - plugin_path="./etc/plugin.conf" - entrylist_path="./etc/entrylist.conf" - send_raw_pkt_path="./etc/send_raw_pkt.conf" - vxlan_sport_service_map_path="./etc/vxlan_sport_service_map.conf" + project_list_path="./etc/project_list.conf" + plugin_path="./etc/plugin.conf" + entrylist_path="./etc/entrylist.conf" + send_raw_pkt_path="./etc/send_raw_pkt.conf" + vxlan_sport_service_map_path="./etc/vxlan_sport_service_map.conf" diff --git a/cmake/Version.cmake b/cmake/Version.cmake index 77c84f4..7bc8543 100644 --- a/cmake/Version.cmake +++ b/cmake/Version.cmake @@ -21,7 +21,7 @@ string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VCS_TAG}") string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VCS_TAG}") if(NOT VERSION_MAJOR) - set(VERSION_MAJOR 3) + set(VERSION_MAJOR 4) endif() if(NOT VERSION_MINOR) diff --git a/include/private/sapp_global_val.h b/include/private/sapp_global_val.h index 8c2f796..19b4511 100644 --- a/include/private/sapp_global_val.h +++ b/include/private/sapp_global_val.h @@ -22,13 +22,14 @@ typedef struct{ char mode_str[NAME_MAX]; /* storage/udp_socket */ int mode_bin; unsigned int command_port; /* integer, host order, user should truncate to short */ - unsigned int storge_size_max; + unsigned int file_size_max_per_thread; /* MB */ char *bpf_filter; char *storge_path; int dump_all_thread_enabled; int dump_thread_id_array_num; int dump_thread_id_array[SAPP_MAX_THREADS]; /* �û������ļ�ԭʼ����, ��ʽ: [0,1,2,3], ��ʾ��0,1,2,3���߳����ò��� */ unsigned char dump_thread_id_mask[SAPP_MAX_THREADS]; /* ����ԭʼ������������������, ���߳�id��Ϊ�±�, ֵ��Ϊ0��ʾ��ǰ�߳̿�������, ֵ:{1,1,1,1} */ + int pkt_dump_ratio; /* capture one packet every 'pkt_dump_ratio' packets */ }sapp_config_tools_pktdump_t; typedef struct{ @@ -106,11 +107,8 @@ typedef struct{ char log_app_name[NAME_MAX]; char server_ip[INET_ADDRSTRLEN]; /* string */ unsigned int server_port; /* integer(4 byte), host order, user should truncate to short before use it */ - char remote_send_out_type[NAME_MAX]; /* field_stat2 or line_protocol */ - union{ - sapp_config_profiling_log_remote_field_stat2_t field_stat2; - sapp_config_profiling_log_remote_line_protocol_t line_protocol; - }; + char remote_send_out_type[NAME_MAX]; /* field_stat2 */ + sapp_config_profiling_log_remote_field_stat2_t field_stat2; }sapp_config_profiling_log_remote_t; @@ -156,6 +154,7 @@ typedef struct{ sapp_config_packet_io_dev_t internal; sapp_config_packet_io_dev_t external; char pcap_dumpfile_name[NAME_MAX]; + int polling_priority; }sapp_config_packet_io_t; typedef struct{ @@ -206,7 +205,7 @@ typedef struct{ typedef struct{ sapp_gval_mthread_sys_stat_t sys_stat; - char __padding[16]; + char __padding[48]; }sapp_gval_mthread_t; /* for multi-thread, must 64byte alignment */ diff --git a/include/private/sapp_pkt_stat.h b/include/private/sapp_pkt_stat.h index b9d51a2..bdc0a95 100644 --- a/include/private/sapp_pkt_stat.h +++ b/include/private/sapp_pkt_stat.h @@ -34,6 +34,9 @@ enum __sapp_sys_stat_type{ SAPP_STAT_DROP_ETHERNET, SAPP_STAT_DROP_IPV4, SAPP_STAT_DROP_IPV6, + + SAPP_POLLING_WORK, + SAPP_POLLING_IDLE, /************* tunnel stat *******************/ SAPP_STAT_TUNNEL_4OVER6, diff --git a/include/public/sapp_api.h b/include/public/sapp_api.h index 70c06a2..106615f 100644 --- a/include/public/sapp_api.h +++ b/include/public/sapp_api.h @@ -47,7 +47,7 @@ #include "MESA_ring_queue.h"
#include "wiredLB.h"
#include "wired_cfg.h"
-//#include "field_stat2.h" //must compile with g++, so move it.
+//#include "field_stat2.h" //must compile with g++, add it in source file.
/* sapp platform header */
#include "sapp_std.h"
diff --git a/include/public/stream.h b/include/public/stream.h index f70f4c7..6418b0e 100644 --- a/include/public/stream.h +++ b/include/public/stream.h @@ -9,6 +9,8 @@ #include "stream_inc/stream_entry.h"
#include "stream_inc/stream_rawpkt.h"
#include "stream_inc/stream_tunnel.h"
+#include "stream_inc/sapp_inject.h"
+
#define STREAM_H_VERSION (20170911)
diff --git a/include/public/stream_inc/sapp_inject.h b/include/public/stream_inc/sapp_inject.h new file mode 100644 index 0000000..cbcaab1 --- /dev/null +++ b/include/public/stream_inc/sapp_inject.h @@ -0,0 +1,37 @@ +#ifndef _SAPP_INJECT_H_ +#define _SAPP_INJECT_H_ 1 + +#ifdef __cplusplus +extern "C" { +#endif + +#include "stream_base.h" + +enum sapp_inject_opt{ + SIO_DEFAULT = (1<<0), /* ������ֻ���봿����, ��ƽ̨����Э��淶���쵱ǰ��Ĵ�����IPͷ��, ���������, ����������Ƕ�ײ��ͷ�� */ + SIO_EXCLUDE_THIS_LAYER_HDR = (1<<1), /* ��������, ��ǰ��Ĵ�����IPͷ��Ҳ�ɵ����߹���, ƽ̨���������ǰ��ij��ز�ͷ��, ���������, ����������Ƕ�ײ��ͷ�� */ +}; + +/* + ARGS: + stream: ��ǰ���ṹ��ָ��; + payload: Ҫ���͵ĸ���ָ��; + payload_len: Ҫ���͵ĸ��س���; + snd_routedir: Ҫ�������ݵ�route����, + ������͵İ��뵱ǰ��ͬ��, snd_routedir = stream->routedir, + ������͵İ��뵱ǰ������, snd_routedir = MESA_dir_reverse(stream->routedir). + + return value: + <=0 : error. + > 0 : ���͵����ݰ�ʵ���ܳ���(payload_len + �ײ��ͷ����); +*/ +int sapp_inject_pkt(struct streaminfo *stream, enum sapp_inject_opt sio, const void *payload, int payload_len, unsigned char snd_routedir); + + + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/include/public/stream_inc/stream_entry.h b/include/public/stream_inc/stream_entry.h index c145a45..09738c2 100644 --- a/include/public/stream_inc/stream_entry.h +++ b/include/public/stream_inc/stream_entry.h @@ -1,7 +1,7 @@ #ifndef _APP_STREAM_ENTRY_H_ #define _APP_STREAM_ENTRY_H_ -#define STREAM_ENTRY_H_VERSION (20160118) +#define STREAM_ENTRY_H_VERSION (20190818) /* CHN : ҵ�����ý�����ʱsession_state״̬; @@ -64,6 +64,19 @@ char UDP_ENTRY_EXAMPLE(const struct streaminfo *a_udp, void **pme, int thread_s char SAPP_PKT_EXAMPLE(const struct streaminfo *pstream, const void *this_hdr, const void *raw_pkt); char SAPP_STREAM_EXAMPLE(const struct streaminfo *pstream, const void *this_hdr, const void *raw_pkt, void **pme); +#define POLLING_STATE_WORK 0x80 +#define POLLING_STATE_IDLE 0x40 + +/* + ÿ��һ��ʱ��, ƽ̨����õ�ǰ�ӿ�, �����������Ƿ������ݰ�. + stream, pme, a_packet�̶�����NULL, thread_seq���հ��̵߳����. + + ����ֵ: + POLLING_STATE_WORK: �˴λص�����������������������; + POLLING_STATE_IDLE: �˴λص����ʲô��û��, ����������û����, ���������ģʽ�հ�, ��ʵ��û���յ���; +*/ +char POLLING_ENTRY(struct streaminfo *stream, void **pme, int thread_seq,void *a_packet); + /* CHN : ҵ���ص��ӿ� ; diff --git a/include/public/stream_inc/stream_inject.h b/include/public/stream_inc/stream_inject.h index f5f55c5..ecc9dae 100644 --- a/include/public/stream_inc/stream_inject.h +++ b/include/public/stream_inc/stream_inject.h @@ -163,7 +163,7 @@ int sapp_forward_current_pkt(const struct streaminfo *stream, unsigned int targe enum sapp_send_pkt_opt_type{
SAPP_SEND_OPT_IP_ID = 0x10,
- SAPP_SEND_OPT_IP_TTL = 0x11,
+ SAPP_SEND_OPT_IP_TTL = 0x11,
SAPP_SEND_OPT_TCP_WIN = 0x20,
@@ -184,7 +184,7 @@ enum sapp_send_pkt_opt_type{ SAPP_SEND_OPT_INNER_DMAC = 0x1303, /* �ڲ�Ŀ��MAC */
SAPP_SEND_OPT_INNER_VLANID = 0x1304, /* �ڲ������VLAN������ */
SAPP_SEND_OPT_VIRTUAL_LINK_ID = 0x1305, /* ����������·�ţ� ͬʱ��Ҫ��TUNNAT_CZ_ACTION_ENCAP_VIRTUAL_LINK_ID*/
- SAPP_SEND_OPT_REHASH_INDEX = 0x1306, /*����rehash index�� ͬʱ��Ҫ��TUNNAT_CZ_ACTION_ENCAP_VIRTUAL_LINK_ID*/
+ SAPP_SEND_OPT_REHASH_INDEX = 0x1306, /*����rehash index�� ͬʱ��Ҫ��TUNNAT_CZ_ACTION_ENCAP_VIRTUAL_LINK_ID*/
};
int MESA_fakepacket_send_ipv4_options(const struct streaminfo *stream, uint8_t protocol,
diff --git a/include/public/stream_inc/stream_rawpkt.h b/include/public/stream_inc/stream_rawpkt.h index 39b75d6..99aab94 100644 --- a/include/public/stream_inc/stream_rawpkt.h +++ b/include/public/stream_inc/stream_rawpkt.h @@ -1,7 +1,7 @@ #ifndef _APP_STREAM_RAWPKT_H_
#define _APP_STREAM_RAWPKT_H_
-#define STREAM_RAWPKT_H_VERSION (20160919)
+#define STREAM_RAWPKT_H_VERSION (20190817)
#include "stream_base.h"
@@ -22,6 +22,8 @@ enum{ RAW_PKT_GET_VIRTUAL_LINK_ID, //value type is uint64 *, out_value should be uint64 *
RAW_PKT_GET_REHASH_INDEX, // value type is uint64 *, out_value should be uint64 *
RAW_PKT_GET_VXLAN_VPNID, // network-order, VPN_ID, value type is int, out_value should be int *
+
+ RAW_PKT_GET_VXLAN_LOCAL_IP, // network-order, VXLAN Local IP, value type is int, out_value should be int *
};
#ifdef __cplusplus
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 7fa4e23..a43d894 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 2.8) -include_directories(${MESA_SDK_PREFIX}/include) -include_directories(${MESA_SDK_PREFIX}/include/MESA) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include/private) include_directories(${CMAKE_SOURCE_DIR}/include/public) include_directories(${CMAKE_SOURCE_DIR}/include/support) +include_directories(${MESA_SDK_PREFIX}/include) +include_directories(${MESA_SDK_PREFIX}/include/MESA) + if(OPT_IOMODE_MARSIO) include_directories(${MARSIO_SDK_PREFIX}/include) diff --git a/src/config/CMakeLists.txt b/src/config/CMakeLists.txt index 52e9fb8..fb87611 100644 --- a/src/config/CMakeLists.txt +++ b/src/config/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 2.8) -include_directories(${MESA_SDK_PREFIX}/include) -include_directories(${MESA_SDK_PREFIX}/include/MESA) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include/private) include_directories(${CMAKE_SOURCE_DIR}/include/public) include_directories(${CMAKE_SOURCE_DIR}/include/support) +include_directories(${MESA_SDK_PREFIX}/include) +include_directories(${MESA_SDK_PREFIX}/include/MESA) + if(OPT_IOMODE_MARSIO) include_directories(${MARSIO_SDK_PREFIX}/include) diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp index 0bdfc45..ee5ae0f 100644 --- a/src/config/config_parse.cpp +++ b/src/config/config_parse.cpp @@ -8,7 +8,7 @@ extern "C" { #include "field_stat2.h" -/* ��ֻ̬��ȫ�ֱ������Է����κδ����, ������sapp_global_val�� */ +/* ��ֻ̬��ȫ�ֱ������Է��ڴ����, ������sapp_global_val�� */ static const char *default_config_file = "./etc/sapp.toml"; static const unsigned char sample_sapp_toml[] = @@ -473,6 +473,13 @@ static int config_sanity_check(void) return -1; } + if(strncasecmp(pconfig->tools.pkt_dump.mode_str, "udp_socket" ,strlen("udp_socket")) == 0){ + if(pconfig->tools.pkt_dump.command_port <=0 || pconfig->tools.pkt_dump.command_port > 65535){ + sapp_log(30, ~0, ~0, "[Error] TOOLS.PKT_DUMP.command_port: %u invalid!", pconfig->tools.pkt_dump.command_port); + return -1; + } + } + old_config_file_detect("./conf/main.conf", "./etc/sapp.toml"); return 0; @@ -523,6 +530,11 @@ int sapp_parse_config(void) /******************************* SYSTEM *********************************/ ret = tomlc99_wrap_load_string_def(default_config_file, (char *)"SYSTEM", (char *)"instance_name", pconfig->system.instance_name, NAME_MAX, "sapp_v4.0"); + if(TOMLC99_RET_PATTERN_ERROR == ret){ + /* �״ν����ж������PATTERN_ERROR, ˵��toml��ʽ������, ���ټ������� */ + sapp_log(30, ~0, ~0, "parse config file %s error!", default_config_file); + exit(1); + } /******************************* CPU *********************************/ tomlc99_wrap_load_int_def(default_config_file, (char *)"CPU", (char *)"worker_threads", (int *)&pconfig->cpu.worker_threads, 1); @@ -539,6 +551,7 @@ int sapp_parse_config(void) tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.internal.interface", (char *)"name", pconfig->packet_io.internal.interface.name, NAME_MAX, "lo"); tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.external.interface", (char *)"type", pconfig->packet_io.external.interface.type_str, NAME_MAX, "pcap"); tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.external.interface", (char *)"name", pconfig->packet_io.external.interface.name, NAME_MAX, "lo"); + tomlc99_wrap_load_int_def(default_config_file, (char *)"packet_io.polling", (char *)"polling_priority", &pconfig->packet_io.polling_priority, 10); /******************************* STREAM.TCP ******************************/ @@ -575,8 +588,8 @@ int sapp_parse_config(void) tomlc99_wrap_load_int_def(default_config_file, (char *)"profiling.log.remote", (char *)"enabled", (int *)&pconfig->profiling.log.remote.enabled, 0); tomlc99_wrap_load_string_def(default_config_file, (char *)"profiling.log.remote", (char *)"server_ip", pconfig->profiling.log.remote.server_ip, INET_ADDRSTRLEN, "#"); tomlc99_wrap_load_int_def(default_config_file, (char *)"profiling.log.remote", (char *)"server_port", (int *)&pconfig->profiling.log.remote.server_port, 0); - tomlc99_wrap_load_string_def(default_config_file, (char *)"profiling.log.remote", (char *)"remote_send_out_type", pconfig->profiling.log.remote.remote_send_out_type, NAME_MAX, "field_stat2"); - +#if 0 + //tomlc99_wrap_load_string_def(default_config_file, (char *)"profiling.log.remote", (char *)"remote_send_out_type", pconfig->profiling.log.remote.remote_send_out_type, NAME_MAX, "field_stat2"); /******************************* PROFILING.LOG.remote.field_stat2 **********************/ if(strncasecmp(pconfig->profiling.log.remote.remote_send_out_type, "field_stat2", strlen("field_stat2")) == 0){ tomlc99_wrap_load_string_def(default_config_file, (char *)"profiling.log.remote.field_stat2", (char *)"app_name", pconfig->profiling.log.remote.field_stat2.app_name, NAME_MAX, "sapp"); @@ -596,7 +609,19 @@ int sapp_parse_config(void) sapp_log(30, ~0, ~0, "config parse error! invalid value of 'profiling.log.remote.remote_send_out_type'"); return -1; } - +#else + strncpy(pconfig->profiling.log.remote.remote_send_out_type, "field_stat2", strlen("field_stat2")); + tomlc99_wrap_load_string_def(default_config_file, (char *)"profiling.log.remote.field_stat2", (char *)"app_name", pconfig->profiling.log.remote.field_stat2.app_name, NAME_MAX, "sapp"); + tomlc99_wrap_load_string_def(default_config_file, (char *)"profiling.log.remote.field_stat2", (char *)"metric_type", str_tmp, ARG_MAX, "default"); + if(strncasecmp(str_tmp, "default", strlen("default")) == 0){ + pconfig->profiling.log.remote.field_stat2.metrics_type = FS_METRIS_OUTPUT_DEFAULT; + }else if(strncasecmp(str_tmp, "json", strlen("json")) == 0){ + pconfig->profiling.log.remote.field_stat2.metrics_type = FS_METRIS_OUTPUT_JSON; + }else{ + sapp_log(30, ~0, ~0, "config parse error! invalid value of 'profiling.log.remote.field_stat2.metric_type'"); + return -1; + } +#endif /******************************* TOOLS **********************************/ tomlc99_wrap_load_int_def(default_config_file, (char *)"tools.pkt_dump", (char *)"enabled", (int *)&pconfig->tools.pkt_dump.enabled, 0); tomlc99_wrap_load_string_def(default_config_file, (char *)"tools.pkt_dump", (char *)"mode", pconfig->tools.pkt_dump.mode_str, NAME_MAX, "udp_socket"); @@ -612,10 +637,11 @@ int sapp_parse_config(void) } tomlc99_wrap_load_int_def(default_config_file, (char *)"tools.pkt_dump.udp", (char *)"command_port", (int *)&pconfig->tools.pkt_dump.command_port, 0); + tomlc99_wrap_load_int_def(default_config_file, (char *)"tools.pkt_dump.udp", (char *)"pkt_dump_ratio", (int *)&pconfig->tools.pkt_dump.pkt_dump_ratio, 30); tomlc99_wrap_load_string_def(default_config_file, (char *)"tools.pkt_dump.storage", (char *)"path", str_tmp, ARG_MAX, "/dev/shm/pkt_dump"); pconfig->tools.pkt_dump.storge_path = strdup(str_tmp); - tomlc99_wrap_load_int_def(default_config_file, (char *)"tools.pkt_dump.storage", (char *)"file_size_max_per_thread", (int *)&pconfig->tools.pkt_dump.storge_size_max, 1000); + tomlc99_wrap_load_int_def(default_config_file, (char *)"tools.pkt_dump.storage", (char *)"file_size_max_per_thread", (int *)&pconfig->tools.pkt_dump.file_size_max_per_thread, 1000); /*************************** SPECIAL_CONFIG_LINK *************************/ tomlc99_wrap_load_string_def(default_config_file, (char *)"SPECIAL_CONFIG_LINK", (char *)"project_list_path", str_tmp, ARG_MAX, "./etc/project_list.conf"); diff --git a/src/dealpkt/CMakeLists.txt b/src/dealpkt/CMakeLists.txt index dc42a41..8e058c1 100644 --- a/src/dealpkt/CMakeLists.txt +++ b/src/dealpkt/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 2.8) -include_directories(${MESA_SDK_PREFIX}/include) -include_directories(${MESA_SDK_PREFIX}/include/MESA) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include/private) include_directories(${CMAKE_SOURCE_DIR}/include/public) include_directories(${CMAKE_SOURCE_DIR}/include/support) +include_directories(${MESA_SDK_PREFIX}/include) +include_directories(${MESA_SDK_PREFIX}/include/MESA) + if(OPT_IOMODE_MARSIO) include_directories(${MARSIO_SDK_PREFIX}/include) diff --git a/src/dealpkt/callapp.c b/src/dealpkt/callapp.c index fdb3330..0bbb942 100644 --- a/src/dealpkt/callapp.c +++ b/src/dealpkt/callapp.c @@ -859,14 +859,24 @@ int stream_process_ipv6_frag(struct streaminfo *pstream,const struct ip6_hdr *th int stream_process_polling(int thread_seq)
{
int i;
+ char plug_ret, fun_ret = 0;
__st_pkt_proc_context_check_timeout(thread_seq);
for(i = 0; i < g_PollingFunNum; i++){
- g_PollingFun[i].stream_fun(NULL, NULL, thread_seq, NULL);
+ plug_ret = g_PollingFun[i].stream_fun(NULL, NULL, thread_seq, NULL);
+ if(plug_ret & POLLING_STATE_WORK){
+ fun_ret = POLLING_STATE_WORK;
+ }
}
- return 0;
+ if(POLLING_STATE_WORK == fun_ret){
+ sapp_global_val->mthread_volatile[thread_seq]->sys_stat.count[SAPP_POLLING_WORK]++;
+ }else{
+ sapp_global_val->mthread_volatile[thread_seq]->sys_stat.count[SAPP_POLLING_IDLE]++;
+ }
+
+ return fun_ret;
}
extern int g_use_MESA_sleep_sw;
diff --git a/src/dealpkt/plug_support.c b/src/dealpkt/plug_support.c index 3f2e16a..876334b 100644 --- a/src/dealpkt/plug_support.c +++ b/src/dealpkt/plug_support.c @@ -84,6 +84,18 @@ int get_opt_from_rawpkt(const void *voidpkt, int type, void *void_value) } break; + case RAW_PKT_GET_VXLAN_LOCAL_IP: + { + const struct mr_tunnat_ctrlzone *mr_ctrlzone = (const struct mr_tunnat_ctrlzone *)marsio_buff_ctrlzone((marsio_buff_t *)rawpkt->io_lib_pkt_reference, 0); /* index */ + if(0 == (mr_ctrlzone->action & TUNNAT_CZ_ACTION_FORWARD)){/* ��vxlan��, �϶�û����Щѡ�� */ + ret = -1; + break; + } + int *out_value = (int *)void_value; + *out_value = mr_ctrlzone->l_device_in_addr; + } + break; + case RAW_PKT_GET_VXLAN_ID: { diff --git a/src/dealpkt/stream_manage.c b/src/dealpkt/stream_manage.c index a5c9a1e..ee37315 100644 --- a/src/dealpkt/stream_manage.c +++ b/src/dealpkt/stream_manage.c @@ -30,13 +30,13 @@ extern "C" { #endif -int sapp_version_v4_20190705; +int sapp_version_v4_20190820; /* ����İ汾������packet_io_libУ��, ��ֹƽ̨��dl.so��ƥ�䵼�������쳣, ��������BUGδ����. */ #if IOMODE_PCAP -int sapp_packet_io_v = 20190524; +int sapp_packet_io_v = 20190820; #elif IOMODE_PAG int sapp_packet_io_v = 20151106; #elif IOMODE_PFRING @@ -48,7 +48,7 @@ int sapp_packet_io_v = 20160426; #elif IOMODE_TOPSEC int sapp_packet_io_v = 20151014; #elif IOMODE_MARSIO -int sapp_packet_io_v = 20190527; +int sapp_packet_io_v = 20190820; #elif IOMODE_SMITH int sapp_packet_io_v = 20161027; #elif IOMODE_DPDK_VXLAN @@ -145,15 +145,15 @@ static int init_stream_detail(struct global_stream *g_stream) for (i = 0; i < g_stream->freeList.max_cnt-1; i++) { g_stream->freeList.head[i].next= &(g_stream->freeList.head[i + 1]); - g_stream->freeList.head[i+1].prev=&(g_stream->freeList.head[i]); - //g_stream->freeList.index=i; // Ϊÿ����������һ��ȫ�������� - //adjust by lqy 20150113 - g_stream->freeList.head[i].stream.stream_public.stream_index=i; + g_stream->freeList.head[i+1].prev=&(g_stream->freeList.head[i]); + //g_stream->freeList.index=i; // Ϊÿ����������һ��ȫ�������� + //adjust by lqy 20150113 + g_stream->freeList.head[i].stream.stream_public.stream_index=i; } g_stream->freeList.head[g_stream->freeList.max_cnt-1].next=NULL; //adjust by lqy 20150113 g_stream->freeList.head[g_stream->freeList.max_cnt-1].stream.stream_public.stream_index=i; - g_stream->freeList.cnt= g_stream->freeList.max_cnt; + g_stream->freeList.cnt=g_stream->freeList.max_cnt; g_stream->freeList.tail= &(g_stream->freeList.head[g_stream->freeList.max_cnt-1]); return 0; diff --git a/src/entry/CMakeLists.txt b/src/entry/CMakeLists.txt index a6dcf1e..69ce625 100644 --- a/src/entry/CMakeLists.txt +++ b/src/entry/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 2.8) -include_directories(${MESA_SDK_PREFIX}/include) -include_directories(${MESA_SDK_PREFIX}/include/MESA) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include/private) include_directories(${CMAKE_SOURCE_DIR}/include/public) include_directories(${CMAKE_SOURCE_DIR}/include/support) +include_directories(${MESA_SDK_PREFIX}/include) +include_directories(${MESA_SDK_PREFIX}/include/MESA) + LINK_DIRECTORIES(/opt/MESA/lib) LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/lib) diff --git a/src/entry/Makefile b/src/entry/Makefile index 50e548f..46f0bab 100644 --- a/src/entry/Makefile +++ b/src/entry/Makefile @@ -55,7 +55,6 @@ endif WHOLE_ARCH += ../lib/libtomlc99_wrap.a WHOLE_ARCH += ../lib/libconfig.a WHOLE_ARCH += ../lib/libtimer.a -WHOLE_ARCH += ../lib/libevent.a ifeq ($(debug), $(_DEBUG2)) LIB += ../lib/libiknow.a -lpcap @@ -82,6 +81,7 @@ LIB += -lMESA_field_stat2 #LIB += -lsapp_assistant LIB += -lcjson #LIB += -lsesame_door +LIB += -l event ifeq ($(iomode), $(_MODE_MARSIO)) LIB += -lmarsio diff --git a/src/entry/sapp_init.c b/src/entry/sapp_init.c index 7f77b83..0f946a9 100644 --- a/src/entry/sapp_init.c +++ b/src/entry/sapp_init.c @@ -341,7 +341,7 @@ int MESA_platform_init(int argc, char *argv[]) __sapp_timer_platform_init(); -#if CYCLE_PKT_DUMP +#if 1 if(cycle_pkt_dump_init(argc , argv) < 0){ return -1; } diff --git a/src/inner_plug/CMakeLists.txt b/src/inner_plug/CMakeLists.txt index fcc7a26..a328364 100644 --- a/src/inner_plug/CMakeLists.txt +++ b/src/inner_plug/CMakeLists.txt @@ -1,12 +1,13 @@ cmake_minimum_required(VERSION 2.8) -include_directories(${MESA_SDK_PREFIX}/include) -include_directories(${MESA_SDK_PREFIX}/include/MESA) -include_directories(${MESA_SDK_PREFIX}/include/MESA/stream_inc) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include/private) include_directories(${CMAKE_SOURCE_DIR}/include/public) include_directories(${CMAKE_SOURCE_DIR}/include/support) +include_directories(${MESA_SDK_PREFIX}/include) +include_directories(${MESA_SDK_PREFIX}/include/MESA) +include_directories(${MESA_SDK_PREFIX}/include/MESA/stream_inc) + if(OPT_IOMODE_MARSIO) include_directories(${MARSIO_SDK_PREFIX}/include) endif() diff --git a/src/inner_plug/sapp_assistant.cpp b/src/inner_plug/sapp_assistant.cpp index 5457cd3..db52c97 100644 --- a/src/inner_plug/sapp_assistant.cpp +++ b/src/inner_plug/sapp_assistant.cpp @@ -468,16 +468,29 @@ void sapp_fs2_set_latency(int thead_seq, long long time_cost) int sapp_assistant_init(void) { sapp_fs2_init(); - sapp_line_protocol_init(); + //sapp_line_protocol_init(); sapp_identify_broad_multicast_init(); pthread_mutex_init(&g_plug_Independent_thread_mutex, NULL); return 1; } + +int sapp_inject_pkt_with_feedback(struct streaminfo *stream, + enum sapp_inject_opt sio, const void *payload, int payload_len, unsigned char snd_routedir, + char *feedback_buf, int *feedback_buf_len) +{ + + +} + + + + #ifdef __cplusplus } #endif +/************************ C++ compiler **************************************/ static int sapp_fs2_init(void) { char cfg_ip_str[32]; diff --git a/src/packet_io/CMakeLists.txt b/src/packet_io/CMakeLists.txt index 87720e6..0d84e7f 100644 --- a/src/packet_io/CMakeLists.txt +++ b/src/packet_io/CMakeLists.txt @@ -4,12 +4,13 @@ add_definitions(-DPLATFORM_NSDPF_PAPP=1) LINK_DIRECTORIES(/opt/mrzcpd/lib) -include_directories(${MESA_SDK_PREFIX}/include) -include_directories(${MESA_SDK_PREFIX}/include/MESA) -include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include/private) include_directories(${CMAKE_SOURCE_DIR}/include/public) include_directories(${CMAKE_SOURCE_DIR}/include/support) +include_directories(${MESA_SDK_PREFIX}/include) +include_directories(${MESA_SDK_PREFIX}/include/MESA) +include_directories(${CMAKE_SOURCE_DIR}/include) + if(OPT_IOMODE_MARSIO) include_directories(${MARSIO_SDK_PREFIX}/include) endif() @@ -59,7 +60,8 @@ set(PACKET_IO_STATIC_SOURCE cycle_pkt_dump_through_write_offset.c packet_io_lib iknow_info.c packet_io_log.c sendpacket.c packet_io.c packet_io_status.cpp packet_io_status_new.c -packet_io_device.c sapp_compat_wangyan_api.c) +packet_io_device.c sapp_compat_wangyan_api.c +sapp_inject.c) add_library(packet_io STATIC ${PACKET_IO_STATIC_SOURCE}) if(CAPTURE_MODE MATCHES "MARSIO") diff --git a/src/packet_io/Makefile b/src/packet_io/Makefile index bc09a15..2a6338c 100644 --- a/src/packet_io/Makefile +++ b/src/packet_io/Makefile @@ -35,7 +35,7 @@ OBJS+=packet_io_status_new.o OBJS += cycle_pkt_dump_through_write_offset.o
OBJS += packet_io_device.o
OBJS += sapp_compat_wangyan_api.o
-
+OBJS += sapp_inject.o
DLL_LIB=
#ifeq ($(iomode), $(_MODE_PCAP))
diff --git a/src/packet_io/cycle_pkt_dump_through_write.c b/src/packet_io/cycle_pkt_dump_through_write.c.bak index 8eeafd3..8eeafd3 100644 --- a/src/packet_io/cycle_pkt_dump_through_write.c +++ b/src/packet_io/cycle_pkt_dump_through_write.c.bak diff --git a/src/packet_io/cycle_pkt_dump_through_write_offset.c b/src/packet_io/cycle_pkt_dump_through_write_offset.c index 0d2d51b..2262154 100644 --- a/src/packet_io/cycle_pkt_dump_through_write_offset.c +++ b/src/packet_io/cycle_pkt_dump_through_write_offset.c @@ -44,7 +44,7 @@ static pkt_dump_status_t PKT_DISCARD_STAT[MAX_THREAD_NUM]; #endif -const int tcpdump_mesa_version_VERSION_20181114 = 20181114; +const int tcpdump_mesa_version_VERSION_20190820 = 20190820; extern int g_use_MESA_sleep_sw; extern void MESA_sleep(void); @@ -64,6 +64,7 @@ static FILE *G_PKT_DUMP_FP[MAX_THREAD_NUM]; static int G_FILENAME_INDEX[MAX_THREAD_NUM]; static long G_PCAP_SIZE[MAX_THREAD_NUM]; static char G_PKT_DUMP_FILTER_STR[PATH_MAX]; + static struct bpf_program G_PKT_DUMP_BPF_FILTER[MAX_THREAD_NUM]; static pcap_t *phony_pcap_handle[MAX_THREAD_NUM]; /* ������BPF����ʱʹ�� */ static unsigned short pkt_dump_data_offset = 0; /* ����ʱ��ָ��ƫ����, ����vxlan�����²����ڲ����ݰ� */ @@ -421,6 +422,7 @@ static void __do_cycle_pkt_dump_udp_socket(int thread_seq, const raw_pkt_t *p_ra int pktlen, for_bpf_filter_len, ret; char modify_pkt_buf[2048]; /* ��Ҫ��ԭʼ��, ��copy����ʱ������ */ struct perceptive_info *pperceptive_info; + const sapp_config_tools_pktdump_t *pktdump_cfg = &sapp_global_val->config.tools.pkt_dump; if(0 == pkt_dump_udp_socket_peer_alive){ return; @@ -519,6 +521,7 @@ static void __do_cycle_pkt_dump(int thread_seq, const raw_pkt_t *p_raw_pkt) pkt_dump_pkt_hdr_t pcap_hdr[2]; int write_hdr_len; char dump_file_name[PATH_MAX]; + const sapp_config_tools_pktdump_t *pktdump_cfg = &sapp_global_val->config.tools.pkt_dump; if(PKT_DUMP_LOCAL_FILE == G_PKT_DUMP_MODE){ if(0 == G_PKT_DUMP_PER_THREAD_SW[thread_seq]){ @@ -529,7 +532,7 @@ static void __do_cycle_pkt_dump(int thread_seq, const raw_pkt_t *p_raw_pkt) return; } - if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ + if(pktdump_cfg->bpf_filter[0] != '\0'){ if(g_packet_io_cap_level != (enum addr_type_t)CAP_LEVEL_MAC){ if(0 == bpf_filter(G_PKT_DUMP_BPF_FILTER[thread_seq].bf_insns, (const unsigned char *)p_raw_pkt->raw_pkt_data-14, @@ -547,7 +550,7 @@ static void __do_cycle_pkt_dump(int thread_seq, const raw_pkt_t *p_raw_pkt) if(unlikely(NULL == G_PKT_DUMP_FP[thread_seq])){ snprintf(dump_file_name, PATH_MAX, "%s/pid_%d.tid_%d.%d.pcap", - G_PKT_DUMP_ROOT_DIR, getpid(), thread_seq, G_FILENAME_INDEX[thread_seq]); + pktdump_cfg->storge_path, getpid(), thread_seq, G_FILENAME_INDEX[thread_seq]); G_PKT_DUMP_FP[thread_seq] = fopen(dump_file_name, "wb+"); if(NULL == G_PKT_DUMP_FP[thread_seq]){ printf("fopen %s error!\n", dump_file_name); @@ -814,6 +817,7 @@ static int cycle_pkt_dump_get_core_num(void) return core_num; } +#if 0 /* config is like: "0,1,2,3,4,5" */ static int cycle_pkt_dump_parse_per_thread_switch(char *config_str) { @@ -841,6 +845,7 @@ static int cycle_pkt_dump_parse_per_thread_switch(char *config_str) return 0; } +#endif static long cycle_pkt_dump_get_cur_files_size(void) @@ -869,9 +874,10 @@ static long cycle_pkt_dump_get_cur_files_size(void) static int cycle_pkt_dump_get_cur_enable_thread(void) { int i, sum = 0; + const sapp_config_tools_pktdump_t *pktdump_cfg = &sapp_global_val->config.tools.pkt_dump; for(i = 0; i < MAX_THREAD_NUM; i++){ - if(G_PKT_DUMP_PER_THREAD_SW[i] > 0){ + if(G_PKT_DUMP_PER_THREAD_SW != 0){ sum++; } } @@ -932,15 +938,20 @@ static void pkt_dump_sig_handle(int sig) static void pkt_dump_set_default_opt(void) { + int i; + const sapp_config_tools_pktdump_t *pktdump_cfg = &sapp_global_val->config.tools.pkt_dump; udp_recv_addr.sin_family = AF_INET; udp_recv_addr.sin_addr.s_addr = htonl(0x7f000001); udp_recv_addr.sin_port = htons(12345); - - memset(G_PKT_DUMP_FILTER_STR, 0, sizeof(G_PKT_DUMP_FILTER_STR)); - pkt_dump_data_offset = 0; - /* Ĭ�������߳�ȫ������ */ - memset(G_PKT_DUMP_PER_THREAD_SW, 1, sizeof(G_PKT_DUMP_PER_THREAD_SW)); + /* ��ԭʼ���ø���һ��, ��Ϊudpģʽ��, ���ܻ�����-k�����ı��ֵ */ + for(i = 0; i < MAX_THREAD_NUM; i++){ + G_PKT_DUMP_PER_THREAD_SW[i] = pktdump_cfg->dump_thread_id_mask[i]; + } + + if(pktdump_cfg->bpf_filter != NULL){ + strncpy(G_PKT_DUMP_FILTER_STR, pktdump_cfg->bpf_filter, sizeof(G_PKT_DUMP_FILTER_STR)-1); + } } static void pkt_dump_parse_opt_rcv_port(const struct pkt_dump_opt *cmd_opt, const char *opt_val) @@ -1032,10 +1043,12 @@ static void cycle_pkt_dump_command_parse(int connfd) } /* �ݲ��ϸ����Զ�tcpdump_mesa�汾��, ֻ��ӡ������Ϣ */ +#if 0 if(ntohl(pkt_hdr.version) != (unsigned int)tcpdump_mesa_version_VERSION_20181114){ printf("Remote tcpdump_mesa version is incompatible!\n"); sapp_runtime_log(20, "Remote tcpdump_mesa version is incompatible!\n"); } +#endif pkt_dump_set_default_opt(); @@ -1210,71 +1223,50 @@ int cycle_pkt_dump_init(int argc, char *argv[]) int int_tmp, total_files_size, core_num; char per_thread_sw[PATH_MAX]; char pcap_errbuf[PCAP_ERRBUF_SIZE]; + const sapp_config_tools_pktdump_t *pktdump_cfg = &sapp_global_val->config.tools.pkt_dump; - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_switch", &G_PKT_DUMP_SW, 0); - - if(0 == G_PKT_DUMP_SW){ + if(0 == pktdump_cfg->enabled){ return 0; } - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_mode", &G_PKT_DUMP_MODE, 1); - if((G_PKT_DUMP_MODE != PKT_DUMP_LOCAL_FILE) && (G_PKT_DUMP_MODE != PKT_DUMP_UDP_SOCKET)){ - printf("\n\033[41mError! pkt_dump_mode only support 1 or 2!\033[0m\n"); - return -1; - } + G_PKT_DUMP_SW = pktdump_cfg->enabled; + pkt_dump_tcp_bind_port = (unsigned short)pktdump_cfg->command_port; + cur_conn_pkt_dump_ratio = pktdump_cfg->pkt_dump_ratio; + cur_conn_pkt_dump_ratio = pktdump_cfg->pkt_dump_ratio; + G_PKT_DUMP_MODE = pktdump_cfg->mode_bin; - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_cmd_port", &int_tmp, 12345); - if((int_tmp <=0) || (int_tmp > 65535)){ - printf("\n\033[41mError! pkt_dump_cmd_port invalid, %d!\033[0m\n", int_tmp); - return -1; + /* ��ԭʼ���ø���һ��, ��Ϊudpģʽ��, ���ܻ�����-k�����ı��ֵ */ + for(i = 0; i < MAX_THREAD_NUM; i++){ + G_PKT_DUMP_PER_THREAD_SW[i] = pktdump_cfg->dump_thread_id_mask[i]; + } + if(pktdump_cfg->bpf_filter != NULL){ + strncpy(G_PKT_DUMP_FILTER_STR, pktdump_cfg->bpf_filter, sizeof(G_PKT_DUMP_FILTER_STR)-1); } - pkt_dump_tcp_bind_port = (unsigned short)int_tmp; - - - MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_ratio", &raw_cfg_pkt_dump_ratio, 30); - cur_conn_pkt_dump_ratio = raw_cfg_pkt_dump_ratio; - -#if 0 == CYCLE_PKT_DUMP - printf("\n\033[33m[Warning]pkt_dump is enable, but sapp is not compile correct, please use debug=2.\033[0m\n"); - sleep(1); -#endif - if(PKT_DUMP_LOCAL_FILE == G_PKT_DUMP_MODE){ cycle_pkt_dump_set_thread_num(g_packet_io_thread_num); - core_num = cycle_pkt_dump_get_core_num(); - if(core_num < 0 || core_num > 10){ - printf("\033[33m[Warning]core.* number is more than 10, pkt dump is auto disabled!\n"); - G_PKT_DUMP_SW = 0; - return 0; - } - - MESA_load_profile_string_def((char *)"conf/main.conf",(char *)"pkt_dump", (char *)"pkt_dump_bpf_filter", G_PKT_DUMP_FILTER_STR, PATH_MAX, (char *)""); - if(G_PKT_DUMP_FILTER_STR[0] != '\0'){ + if(pktdump_cfg->bpf_filter[0] != '\0'){ for(i = 0; i < g_packet_io_thread_num; i++){ phony_pcap_handle[i] = pcap_open_dead(DLT_EN10MB, 65535); if(NULL == phony_pcap_handle[i]){ - printf("pcap_open %s error, %s\n", "lo", pcap_errbuf); - printf("\n\033[41mpkt_dump_bpf_filter is not enable!\033[0m\n"); - goto skip_bpf_filter; + sapp_log(30, 1, 1, "pcap_open %s error, %s\n", "lo", pcap_errbuf); + sapp_log(30, 1, 1, "pkt_dump_bpf_filter is not enable!\n"); + return -1; } - if(pcap_compile(phony_pcap_handle[i], &G_PKT_DUMP_BPF_FILTER[i], G_PKT_DUMP_FILTER_STR, 100, 0) < 0){ - printf("Compile pcap filter '%s' error:%s\n", G_PKT_DUMP_FILTER_STR, pcap_geterr(phony_pcap_handle[i])); + if(pcap_compile(phony_pcap_handle[i], &G_PKT_DUMP_BPF_FILTER[i], pktdump_cfg->bpf_filter, 100, 0) < 0){ + sapp_log(30, 1, 1, "Compile pcap filter '%s' error:%s\n", pktdump_cfg->bpf_filter, pcap_geterr(phony_pcap_handle[i])); return -1; } } } - skip_bpf_filter: - - MESA_load_profile_string_def((char *)"conf/main.conf",(char *)"pkt_dump", (char *)"pkt_dump_file_root_dir", G_PKT_DUMP_ROOT_DIR, PATH_MAX, (char *)"/tmp/pkt_dump"); - MESA_mkdir_p(G_PKT_DUMP_ROOT_DIR, 0755); - - MESA_load_profile_string_nodef((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_thread_seq", per_thread_sw, PATH_MAX); - if(cycle_pkt_dump_parse_per_thread_switch(per_thread_sw) < 0){ - return 0; + if(MESA_mkdir_p(pktdump_cfg->storge_path, 0755) < 0){ + sapp_log(30, 1, 1, "tools.pkt_dump.storage mkdir '%s' error!\n", pktdump_cfg->storge_path); + return -1; } - + + G_PKT_DUMP_FILE_SIZE = pktdump_cfg->file_size_max_per_thread * 1024 * 1024 ; +#if 0 MESA_load_profile_int_def((char *)"conf/main.conf", (char *)"pkt_dump", (char *)"pkt_dump_total_size", &total_files_size, 1000); if(total_files_size < 1 || (unsigned int)total_files_size >= 1024*1000 /* 1000GB */){ printf("pkt_dump_total_size invalid!\n"); @@ -1290,19 +1282,14 @@ int cycle_pkt_dump_init(int argc, char *argv[]) if(cycle_pkt_dump_set_file_size((long)total_files_size*1024*1024, (long)int_tmp*1024*512) < 0){ return 0; } - +#endif signal(SIGPIPE, SIG_IGN); /* ����SIGSEGV�ź�, ��֤�����쳣��ֹʱ, ���һ������BUG��pcap��������д��Ӳ�� */ if((SIG_ERR == signal(SIGSEGV, pkt_dump_sig_handle))){ printf("Catch SIGSEGV error!\n"); } -#if IKNOW_ENABLE - iknow_register_cmd(PLATFORM_IHANDLE, "show pkt dump summary", "display pkt dump summary", - ifuncb_show_pktdump_summary, NULL, 0, NULL); -#endif - printf("\n\033[33m[Warning]pkt dump enable, this maybe encumber performance.\033[0m\n"); - sleep(1); + sapp_log(20, 1, 1, "tools.pkt_dump enable, this maybe encumber performance!\n"); }else{ ret = cycle_pkt_dump_socket_init(); } diff --git a/src/packet_io/packet_io.c b/src/packet_io/packet_io.c index 03bdfd0..5df71e2 100644 --- a/src/packet_io/packet_io.c +++ b/src/packet_io/packet_io.c @@ -705,7 +705,8 @@ int packet_io_init(int argc, char *argv[]) printf("Warning, can't get %s mac addr!\n", g_send_dev_name); } }else{ - printf("Warning, not assign send device!\n"); + //printf("Warning, not assign send device!\n"); + ; } parse_send_gdev_ip_conf("conf/send_gdev.conf"); diff --git a/src/packet_io/packet_io_marsio.c b/src/packet_io/packet_io_marsio.c index be43cba..c7def66 100644 --- a/src/packet_io/packet_io_marsio.c +++ b/src/packet_io/packet_io_marsio.c @@ -26,8 +26,8 @@ typedef struct{ struct mr_sendpath *sendpath_up, *sendpath_down; /* ����ģʽ��, ֱ��ʹ��sendpath_up; ͬʱ����˫��������ģʽ */ }marsio4_io_handle; -int g_marsio4_version_VERSION_20190528; -int g_marsio4_version_VERSION = 20190528; +int g_marsio4_version_VERSION_20190820; +int g_marsio4_version_VERSION = 20190820; static PACKET_IO_CB_T g_marsio4_work_fun; static int g_marsio4_work_thread_num = 1; static int g_marsio4_cap_level = CAP_LEVEL_MAC; @@ -596,7 +596,7 @@ static int marsio4_process_packet(int tid, raw_pkt_t *raw_pkt) static int marsio4_sleep_time_table[100] = { 5, 5, 5, 5, 5, 3, 3, 3, 3, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -629,7 +629,7 @@ static void *marsio4_worker(void *arg) { int tid = *((int *)arg); raw_pkt_t raw_pkt; - int total_call_times = 0, rcv_pkt_tims = 0; + int total_call_times = 0, rcv_pkt_tims = 0, polling_work_times = 0; char thread_name[32] = ""; sprintf(thread_name, "sapp_marsio_%d", tid); @@ -652,17 +652,31 @@ static void *marsio4_worker(void *arg) while(1){ if(marsio4_process_packet(tid, &raw_pkt) > 0){ rcv_pkt_tims++; + }else{ + /* �ް�ʱҪ����polling�ӿ� */ + if(stream_process_polling(tid) > 0){ + polling_work_times++; + } } + total_call_times++; - stream_process_polling(tid); - if(total_call_times >= 100){ - if(rcv_pkt_tims < 99){ - marsio4_sleep(total_call_times, rcv_pkt_tims); + if((rcv_pkt_tims % sapp_global_val->config.packet_io.polling_priority) == 0){ + /* ���������, һֱ�а�ʱ, ÿ��polling_priority����ҲҪ����polling�ӿ� */ + if(stream_process_polling(tid) > 0){ + polling_work_times++; } + total_call_times++; + } + + if(total_call_times >= 100){ + marsio4_sleep(total_call_times, rcv_pkt_tims + polling_work_times); total_call_times = 0; rcv_pkt_tims = 0; + polling_work_times = 0; } + + } return NULL; diff --git a/src/packet_io/packet_io_pcap.c b/src/packet_io/packet_io_pcap.c index a9e8aa0..ba8d429 100644 --- a/src/packet_io/packet_io_pcap.c +++ b/src/packet_io/packet_io_pcap.c @@ -9,8 +9,8 @@ extern "C" { #define PROCESS_BAR_SW (1)
-int g_pcap_version_VERSION_20190524;
-static int g_pcap_version_internal = 20190524;
+int g_pcap_version_VERSION_20190820;
+static int g_pcap_version_internal = 20190820;
#define PCAP_SNAPLEN_MAX (65535)
@@ -740,6 +740,7 @@ static void *__pcap_work_thread(void *arg) pkt_queue_t pkt_queue_node;
long recv_len;
int ret;
+ int total_call_times = 0, rcv_pkt_tims = 0, polling_work_times = 0;
#if(__GNUC__ * 100 + __GNUC_MINOR__ * 10 + __GNUC_PATCHLEVEL__ >= 480) /* �汾�ж�, �ܶ��ϵͳ������ */
#ifdef _GNU_SOURCE
@@ -753,23 +754,21 @@ static void *__pcap_work_thread(void *arg) }
while(1){
- pthread_mutex_lock(&work_thread_pool[thread_num].mutex);
-
-#if 0/* for sapp timer */
- while(0 == MESA_lqueue_get_count(work_thread_pool[thread_num].pkt_queue)){
- pthread_cond_wait(&work_thread_pool[thread_num].cond, &work_thread_pool[thread_num].mutex);
- }
-#else
if(0 == MESA_lqueue_get_count(work_thread_pool[thread_num].pkt_queue)){
- pthread_mutex_unlock(&work_thread_pool[thread_num].mutex);
- stream_process_polling(thread_num);
- usleep(10);
- continue;
- }else{
- stream_process_polling(thread_num);
- }
+ if(stream_process_polling(thread_num) != 0){
+ polling_work_times++;
+ }
+ total_call_times++;
-#endif
+ if(total_call_times >= 100){
+ total_call_times = 0;
+ rcv_pkt_tims = 0;
+ polling_work_times = 0;
+ usleep(1);
+ }
+ continue;
+ }
+ pthread_mutex_lock(&work_thread_pool[thread_num].mutex);
recv_len = sizeof(pkt_queue_t);
ret = MESA_lqueue_get_head(work_thread_pool[thread_num].pkt_queue, &pkt_queue_node, &recv_len);
pthread_mutex_unlock(&work_thread_pool[thread_num].mutex);
@@ -777,6 +776,20 @@ static void *__pcap_work_thread(void *arg) continue;
}
+ total_call_times++;
+ if(total_call_times >= sapp_global_val->config.packet_io.polling_priority){
+ /* ���������, һֱ�а�ʱ, ÿ��polling_priority����ҲҪ����polling�ӿ� */
+ if(stream_process_polling(thread_num) > 0){
+ polling_work_times++;
+ }
+ }
+ if(total_call_times >= 100){
+ total_call_times = 0;
+ rcv_pkt_tims = 0;
+ polling_work_times = 0;
+ usleep(1);
+ }
+
if(PCAP_OP_FLAG_IDLE_POLLING == pkt_queue_node.op_flag){
idle_polling_call(thread_num);
continue;
diff --git a/src/packet_io/packet_io_status.cpp b/src/packet_io/packet_io_status.cpp index 1188bcd..3afab4c 100644 --- a/src/packet_io/packet_io_status.cpp +++ b/src/packet_io/packet_io_status.cpp @@ -72,7 +72,7 @@ void line_protocol_update_metrics(void) //} /* line_protocol����������sysinfo.log���ܲ�һ��, ������ͳһ��˲ʱֵ, �˴����б�����ʷ��ֵ, ���õ�ǰֵ��� */ - buf_len = snprintf(metrics_buf, 65000, "protocol,type=raw Eth_Pkt=%llu,Eth_Bit=%llu,Ipv4_Pkt=%llu,Ipv4_Bit=%llu,Ipv6_Pkt=%llu,Ipv6_Bit=%llu,Tcp_Pkt=%llu,Tcp_Bit=%llu,Udp_Pkt=%llu,Udp_Bit=%llu\n", + buf_len = snprintf(metrics_buf, 65000, "protocol,flow_type=inline Eth_Pkt=%llu,Eth_Bit=%llu,Ipv4_Pkt=%llu,Ipv4_Bit=%llu,Ipv6_Pkt=%llu,Ipv6_Bit=%llu,Tcp_Pkt=%llu,Tcp_Bit=%llu,Udp_Pkt=%llu,Udp_Bit=%llu\n", cur_count[SAPP_STAT_RCV_ETHERNET] - lp_handle->history_count[SAPP_STAT_RCV_ETHERNET], 8 *( cur_length[SAPP_STAT_RCV_ETHERNET]) - 8 * lp_handle->history_length[SAPP_STAT_RCV_ETHERNET], cur_count[SAPP_STAT_RCV_IPV4] - lp_handle->history_count[SAPP_STAT_RCV_IPV4], @@ -91,7 +91,7 @@ void line_protocol_update_metrics(void) Tcp_Concurrent����ֵ�Ƕ��μ���õ���, ��ʾ��ǰʱ����˲ʱֵ, ��û��ʱ������, ֱ��д��InfluxDB, ��ʾʱҪʹ��MEAN, ��ƽ��ֵ��ʾ����. */ - buf_len = snprintf(metrics_buf, 65000, "stream,type=raw Tcp_Concurrent=%llu,Tcp_Link_New=%llu,Tcp_Link_Del=%llu,Tcp_Link_Double=%llu,Tcp_Link_C2S=%llu,Tcp_Link_S2C=%llu\n", + buf_len = snprintf(metrics_buf, 65000, "stream,flow_type=inline Tcp_Concurrent=%llu,Tcp_Link_New=%llu,Tcp_Link_Del=%llu,Tcp_Link_Double=%llu,Tcp_Link_C2S=%llu,Tcp_Link_S2C=%llu\n", cur_count[SAPP_STAT_TCP_STREAM_DATA], (cur_count[SAPP_STAT_TCP_STREAM_NEW] - lp_handle->history_count[SAPP_STAT_TCP_STREAM_NEW])/sapp_global_val->config.profiling.log.interval, (cur_count[SAPP_STAT_TCP_STREAM_DEL] - lp_handle->history_count[SAPP_STAT_TCP_STREAM_DEL])/sapp_global_val->config.profiling.log.interval, @@ -184,13 +184,16 @@ void sysinfo_output(void) fprintf(fp,"\n*********************** %s *********************\n", time_string); fprintf(fp,"*********************** \033[41m%s\033[0m *************************\n", "sysinfo exactly"); - fprintf(fp,"%-10s %12s %12s %12s %12s\n","RCV-PKT", "total_pkt", "total_len","pps", "Bps"); - fprintf(fp,"%-10s %12llu %12llu %12llu %12llu\n", "Ethernet", cur_count[SAPP_STAT_RCV_ETHERNET],cur_length[SAPP_STAT_RCV_ETHERNET],(cur_count[SAPP_STAT_RCV_ETHERNET]-history_count[SAPP_STAT_RCV_ETHERNET]),(cur_length[SAPP_STAT_RCV_ETHERNET]-history_length[SAPP_STAT_RCV_ETHERNET])); - fprintf(fp,"%-10s %12llu %12llu %12llu %12llu\n", "IPv4", cur_count[SAPP_STAT_RCV_IPV4],cur_length[SAPP_STAT_RCV_IPV4],(cur_count[SAPP_STAT_RCV_IPV4]-history_count[SAPP_STAT_RCV_IPV4]),(cur_length[SAPP_STAT_RCV_IPV4]-history_length[SAPP_STAT_RCV_IPV4])); - fprintf(fp,"%-10s %12llu %12llu %12llu %12llu\n","IPv6",cur_count[SAPP_STAT_RCV_IPV6],cur_length[SAPP_STAT_RCV_IPV6],(cur_count[SAPP_STAT_RCV_IPV6]-history_count[SAPP_STAT_RCV_IPV6]),(cur_length[SAPP_STAT_RCV_IPV6]-history_length[SAPP_STAT_RCV_IPV6])); - fprintf(fp,"%-10s %12llu %12llu %12llu %12llu\n","TCP",cur_count[SAPP_STAT_RCV_TCP],cur_length[SAPP_STAT_RCV_TCP],(cur_count[SAPP_STAT_RCV_TCP]-history_count[SAPP_STAT_RCV_TCP]),(cur_length[SAPP_STAT_RCV_TCP]-history_length[SAPP_STAT_RCV_TCP])); - fprintf(fp,"%-10s %12llu %12llu %12llu %12llu\n","UDP",cur_count[SAPP_STAT_RCV_UDP],cur_length[SAPP_STAT_RCV_UDP],(cur_count[SAPP_STAT_RCV_UDP]-history_count[SAPP_STAT_RCV_UDP]),(cur_length[SAPP_STAT_RCV_UDP]-history_length[SAPP_STAT_RCV_UDP])); - fprintf(fp,"%-10s %12llu %12llu %12llu %12llu\n","Unknown",cur_count[SAPP_STAT_RCV_UNKNOWN],cur_length[SAPP_STAT_RCV_UNKNOWN],(cur_count[SAPP_STAT_RCV_UNKNOWN]-history_count[SAPP_STAT_RCV_UNKNOWN]),(cur_length[SAPP_STAT_RCV_UNKNOWN]-history_length[SAPP_STAT_RCV_UNKNOWN])); + fprintf(fp,"%-12s %12s %12s %12s %12s\n","RCV-PKT", "total_pkt", "total_len","pps", "Bps"); + fprintf(fp,"%-12s %12llu %12llu %12llu %12llu\n", "Polling_work", 0,0,(cur_count[SAPP_POLLING_WORK]-history_count[SAPP_POLLING_WORK]),0); + fprintf(fp,"%-12s %12llu %12llu %12llu %12llu\n", "Polling_idle", 0,0,(cur_count[SAPP_POLLING_IDLE]-history_count[SAPP_POLLING_IDLE]),0); + + fprintf(fp,"%-12s %12llu %12llu %12llu %12llu\n", "Ethernet", cur_count[SAPP_STAT_RCV_ETHERNET],cur_length[SAPP_STAT_RCV_ETHERNET],(cur_count[SAPP_STAT_RCV_ETHERNET]-history_count[SAPP_STAT_RCV_ETHERNET]),(cur_length[SAPP_STAT_RCV_ETHERNET]-history_length[SAPP_STAT_RCV_ETHERNET])); + fprintf(fp,"%-12s %12llu %12llu %12llu %12llu\n", "IPv4", cur_count[SAPP_STAT_RCV_IPV4],cur_length[SAPP_STAT_RCV_IPV4],(cur_count[SAPP_STAT_RCV_IPV4]-history_count[SAPP_STAT_RCV_IPV4]),(cur_length[SAPP_STAT_RCV_IPV4]-history_length[SAPP_STAT_RCV_IPV4])); + fprintf(fp,"%-12s %12llu %12llu %12llu %12llu\n","IPv6",cur_count[SAPP_STAT_RCV_IPV6],cur_length[SAPP_STAT_RCV_IPV6],(cur_count[SAPP_STAT_RCV_IPV6]-history_count[SAPP_STAT_RCV_IPV6]),(cur_length[SAPP_STAT_RCV_IPV6]-history_length[SAPP_STAT_RCV_IPV6])); + fprintf(fp,"%-12s %12llu %12llu %12llu %12llu\n","TCP",cur_count[SAPP_STAT_RCV_TCP],cur_length[SAPP_STAT_RCV_TCP],(cur_count[SAPP_STAT_RCV_TCP]-history_count[SAPP_STAT_RCV_TCP]),(cur_length[SAPP_STAT_RCV_TCP]-history_length[SAPP_STAT_RCV_TCP])); + fprintf(fp,"%-12s %12llu %12llu %12llu %12llu\n","UDP",cur_count[SAPP_STAT_RCV_UDP],cur_length[SAPP_STAT_RCV_UDP],(cur_count[SAPP_STAT_RCV_UDP]-history_count[SAPP_STAT_RCV_UDP]),(cur_length[SAPP_STAT_RCV_UDP]-history_length[SAPP_STAT_RCV_UDP])); + fprintf(fp,"%-12s %12llu %12llu %12llu %12llu\n","Unknown",cur_count[SAPP_STAT_RCV_UNKNOWN],cur_length[SAPP_STAT_RCV_UNKNOWN],(cur_count[SAPP_STAT_RCV_UNKNOWN]-history_count[SAPP_STAT_RCV_UNKNOWN]),(cur_length[SAPP_STAT_RCV_UNKNOWN]-history_length[SAPP_STAT_RCV_UNKNOWN])); fprintf(fp,"\n***************************************************************\n"); fprintf(fp,"%-10s %12s %12s %12s %12s\n","SND-PKT", "total_pkt", "total_len","pps", "Bps"); fprintf(fp,"%-10s %12llu %12llu %12llu %12llu\n", "TCP_RST", cur_count[SAPP_STAT_SND_TCP_RST],cur_length[SAPP_STAT_SND_TCP_RST],(cur_count[SAPP_STAT_SND_TCP_RST]-history_count[SAPP_STAT_SND_TCP_RST]),(cur_length[SAPP_STAT_SND_TCP_RST]-history_length[SAPP_STAT_SND_TCP_RST])); @@ -277,13 +280,16 @@ void sysinfo_output(void) fprintf(fp,"*****************************************************************\n\n"); fprintf(fp,"################# \033[41m%s\033[0m --- is same as above! #########\n", "sysinfo humanly"); - fprintf(fp,"%-10s %12s %12s %12s %12s\n", "RCV-PKT", "total_pkt", "total_len","pps", "bps"); - fprintf(fp,"%-10s %12llu %12s %12llu %12s\n","Ethernet",cur_count[SAPP_STAT_RCV_ETHERNET],byte_convert_human(cur_length[SAPP_STAT_RCV_ETHERNET],1 ,1,s1),(cur_count[SAPP_STAT_RCV_ETHERNET]-history_count[SAPP_STAT_RCV_ETHERNET]),byte_convert_human((cur_length[SAPP_STAT_RCV_ETHERNET]-history_length[SAPP_STAT_RCV_ETHERNET]),1,8,s2)); - fprintf(fp,"%-10s %12llu %12s %12llu %12s\n","IPv4",cur_count[SAPP_STAT_RCV_IPV4],byte_convert_human(cur_length[SAPP_STAT_RCV_IPV4],1 ,1,s1),(cur_count[SAPP_STAT_RCV_IPV4]-history_count[SAPP_STAT_RCV_IPV4]),byte_convert_human((cur_length[SAPP_STAT_RCV_IPV4]-history_length[SAPP_STAT_RCV_IPV4]),1,8,s2)); - fprintf(fp,"%-10s %12llu %12s %12llu %12s\n","IPv6",cur_count[SAPP_STAT_RCV_IPV6],byte_convert_human(cur_length[SAPP_STAT_RCV_IPV6],1,1,s1),(cur_count[SAPP_STAT_RCV_IPV6]-history_count[SAPP_STAT_RCV_IPV6]),byte_convert_human((cur_length[SAPP_STAT_RCV_IPV6]-history_length[SAPP_STAT_RCV_IPV6]),1,8,s2)); - fprintf(fp,"%-10s %12llu %12s %12llu %12s\n","TCP",cur_count[SAPP_STAT_RCV_TCP],byte_convert_human(cur_length[SAPP_STAT_RCV_TCP],1,1,s1),(cur_count[SAPP_STAT_RCV_TCP]-history_count[SAPP_STAT_RCV_TCP]),byte_convert_human((cur_length[SAPP_STAT_RCV_TCP]-history_length[SAPP_STAT_RCV_TCP]),1,8,s2)); - fprintf(fp,"%-10s %12llu %12s %12llu %12s\n","UDP",cur_count[SAPP_STAT_RCV_UDP],byte_convert_human(cur_length[SAPP_STAT_RCV_UDP],1,1,s1),(cur_count[SAPP_STAT_RCV_UDP]-history_count[SAPP_STAT_RCV_UDP]),byte_convert_human((cur_length[SAPP_STAT_RCV_UDP]-history_length[SAPP_STAT_RCV_UDP]),1,8,s2)); - fprintf(fp,"%-10s %12llu %12s %12llu %12s\n","Unknown",cur_count[SAPP_STAT_RCV_UNKNOWN],byte_convert_human(cur_length[SAPP_STAT_RCV_UNKNOWN],1,1,s1),(cur_count[SAPP_STAT_RCV_UNKNOWN]-history_count[SAPP_STAT_RCV_UNKNOWN]),byte_convert_human((cur_length[SAPP_STAT_RCV_UNKNOWN]-history_length[SAPP_STAT_RCV_UNKNOWN]),1,8,s2)); + fprintf(fp,"%-12s %12s %12s %12s %12s\n", "RCV-PKT", "total_pkt", "total_len","pps", "bps"); + fprintf(fp,"%-12s %12llu %12llu %12llu %12llu\n", "Polling_work", 0,0,(cur_count[SAPP_POLLING_WORK]-history_count[SAPP_POLLING_WORK]),0); + fprintf(fp,"%-12s %12llu %12llu %12llu %12llu\n", "Polling_idle", 0,0,(cur_count[SAPP_POLLING_IDLE]-history_count[SAPP_POLLING_IDLE]),0); + + fprintf(fp,"%-12s %12llu %12s %12llu %12s\n","Ethernet",cur_count[SAPP_STAT_RCV_ETHERNET],byte_convert_human(cur_length[SAPP_STAT_RCV_ETHERNET],1 ,1,s1),(cur_count[SAPP_STAT_RCV_ETHERNET]-history_count[SAPP_STAT_RCV_ETHERNET]),byte_convert_human((cur_length[SAPP_STAT_RCV_ETHERNET]-history_length[SAPP_STAT_RCV_ETHERNET]),1,8,s2)); + fprintf(fp,"%-12s %12llu %12s %12llu %12s\n","IPv4",cur_count[SAPP_STAT_RCV_IPV4],byte_convert_human(cur_length[SAPP_STAT_RCV_IPV4],1 ,1,s1),(cur_count[SAPP_STAT_RCV_IPV4]-history_count[SAPP_STAT_RCV_IPV4]),byte_convert_human((cur_length[SAPP_STAT_RCV_IPV4]-history_length[SAPP_STAT_RCV_IPV4]),1,8,s2)); + fprintf(fp,"%-12s %12llu %12s %12llu %12s\n","IPv6",cur_count[SAPP_STAT_RCV_IPV6],byte_convert_human(cur_length[SAPP_STAT_RCV_IPV6],1,1,s1),(cur_count[SAPP_STAT_RCV_IPV6]-history_count[SAPP_STAT_RCV_IPV6]),byte_convert_human((cur_length[SAPP_STAT_RCV_IPV6]-history_length[SAPP_STAT_RCV_IPV6]),1,8,s2)); + fprintf(fp,"%-12s %12llu %12s %12llu %12s\n","TCP",cur_count[SAPP_STAT_RCV_TCP],byte_convert_human(cur_length[SAPP_STAT_RCV_TCP],1,1,s1),(cur_count[SAPP_STAT_RCV_TCP]-history_count[SAPP_STAT_RCV_TCP]),byte_convert_human((cur_length[SAPP_STAT_RCV_TCP]-history_length[SAPP_STAT_RCV_TCP]),1,8,s2)); + fprintf(fp,"%-12s %12llu %12s %12llu %12s\n","UDP",cur_count[SAPP_STAT_RCV_UDP],byte_convert_human(cur_length[SAPP_STAT_RCV_UDP],1,1,s1),(cur_count[SAPP_STAT_RCV_UDP]-history_count[SAPP_STAT_RCV_UDP]),byte_convert_human((cur_length[SAPP_STAT_RCV_UDP]-history_length[SAPP_STAT_RCV_UDP]),1,8,s2)); + fprintf(fp,"%-12s %12llu %12s %12llu %12s\n","Unknown",cur_count[SAPP_STAT_RCV_UNKNOWN],byte_convert_human(cur_length[SAPP_STAT_RCV_UNKNOWN],1,1,s1),(cur_count[SAPP_STAT_RCV_UNKNOWN]-history_count[SAPP_STAT_RCV_UNKNOWN]),byte_convert_human((cur_length[SAPP_STAT_RCV_UNKNOWN]-history_length[SAPP_STAT_RCV_UNKNOWN]),1,8,s2)); fprintf(fp,"#################################################################\n"); diff --git a/src/packet_io/sapp_inject.c b/src/packet_io/sapp_inject.c new file mode 100644 index 0000000..3f2f3a9 --- /dev/null +++ b/src/packet_io/sapp_inject.c @@ -0,0 +1,55 @@ +#include "sapp_api.h" +#include "sapp_private_api.h" +#include "stream_inc/sapp_inject.h" + + +#ifdef __cplusplus +extern "C" { +#endif + +/* + MESA_kill_tcpʵ�����ȹ���õ�ǰ���IP, TCPͷ��, + �����Ҫ����ָ����Ϣ, Ҳ��дһ��assistantģ��, ��ô����ipttl, ipid, tcpwin��ֵ. + Ȼ�����__sapp_inject_pkt(), sio = SIO_EXCLUDE_THIS_LAYER_HDR. + + sapp����ֱ�Ӹ���ij��ͷ���ֶ���ô��ֵ, ��assistantģ�鸺��, sapp�����հ�����������. + + kill_remedyҲ�ǿ�assistant���ݵ�ǰseq, ����rst����seq, ���Ƶ��fd���ɹ�, ��Ҫ����Ӷ���. + ����assistant����. +*/ + + +extern int __do_inject_pkt(struct streaminfo *stream, const char *payload, int payload_len, const void *ext_raw_pkt, UCHAR snd_routedir, char *feedback_buf, int *feedback_buf_len); + + +int __sapp_inject_pkt(struct streaminfo *stream, enum sapp_inject_opt sio, const void *payload, int payload_len, unsigned char snd_routedir, void *user_arg) +{ + int ret = -1; + + switch((int)sio){ + case SIO_DEFAULT: + ret = __do_inject_pkt(stream, (const char *)payload, payload_len, NULL, snd_routedir, (char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER); + break; + + case SIO_EXCLUDE_THIS_LAYER_HDR: + ret = __do_inject_pkt(stream->pfather, (const char *)payload, payload_len, NULL, snd_routedir, (char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER); + break; + + + default: + break; + } + + return ret; +} + +int sapp_inject_pkt(struct streaminfo *stream, enum sapp_inject_opt sio, const void *payload, int payload_len, unsigned char snd_routedir) +{ + return __sapp_inject_pkt(stream, sio, payload, payload_len, snd_routedir, NULL); +} + + +#ifdef __cplusplus +} +#endif + diff --git a/src/packet_io/sendpacket.c b/src/packet_io/sendpacket.c index a74b844..3824e19 100644 --- a/src/packet_io/sendpacket.c +++ b/src/packet_io/sendpacket.c @@ -2528,7 +2528,7 @@ int MESA_kill_connection_feedback(struct streaminfo *stream, const void *ext_raw return ret; } -static int __do_inject_pkt(struct streaminfo *stream, const char *payload, int payload_len, +int __do_inject_pkt(struct streaminfo *stream, const char *payload, int payload_len, const void *ext_raw_pkt, UCHAR snd_routedir, char *feedback_buf, int *feedback_buf_len) { diff --git a/src/plugin/CMakeLists.txt b/src/plugin/CMakeLists.txt index 9c1b83a..01c4762 100644 --- a/src/plugin/CMakeLists.txt +++ b/src/plugin/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 2.8) -include_directories(${MESA_SDK_PREFIX}/include) -include_directories(${MESA_SDK_PREFIX}/include/MESA) include_directories(inc) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include/private) include_directories(${CMAKE_SOURCE_DIR}/include/public) include_directories(${CMAKE_SOURCE_DIR}/include/support) +include_directories(${MESA_SDK_PREFIX}/include) +include_directories(${MESA_SDK_PREFIX}/include/MESA) + add_library(plugctrl STATIC src/plugin_proc.c src/plugin.c src/plugin_platform.c src/plugin_protocol.c src/plugin_business.c)
\ No newline at end of file diff --git a/src/project/CMakeLists.txt b/src/project/CMakeLists.txt index 8662b50..822e387 100644 --- a/src/project/CMakeLists.txt +++ b/src/project/CMakeLists.txt @@ -2,11 +2,12 @@ cmake_minimum_required(VERSION 2.8) add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD=1 -DHAVE_NET_ETHERNET_H) add_definitions(-DPLATFORM_NSDPF_PAPP=1) -include_directories(${MESA_SDK_PREFIX}/include) -include_directories(${MESA_SDK_PREFIX}/include/MESA) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include/private) include_directories(${CMAKE_SOURCE_DIR}/include/public) include_directories(${CMAKE_SOURCE_DIR}/include/support) +include_directories(${MESA_SDK_PREFIX}/include) +include_directories(${MESA_SDK_PREFIX}/include/MESA) + add_library(project STATIC project_requirement.c raw_ip_frag_list.c ) diff --git a/src/timer/CMakeLists.txt b/src/timer/CMakeLists.txt index 494e9b7..9ba1fbf 100644 --- a/src/timer/CMakeLists.txt +++ b/src/timer/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 2.8) -include_directories(${MESA_SDK_PREFIX}/include) -include_directories(${MESA_SDK_PREFIX}/include/MESA) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include/private) include_directories(${CMAKE_SOURCE_DIR}/include/public) include_directories(${CMAKE_SOURCE_DIR}/include/support) +include_directories(${MESA_SDK_PREFIX}/include) +include_directories(${MESA_SDK_PREFIX}/include/MESA) + if(OPT_IOMODE_MARSIO) include_directories(${MARSIO_SDK_PREFIX}/include) diff --git a/src/timer/sapp_timer.c b/src/timer/sapp_timer.c index 92d50e7..dcf00d8 100644 --- a/src/timer/sapp_timer.c +++ b/src/timer/sapp_timer.c @@ -237,7 +237,7 @@ static void __st_add_time_event_entry(void) topt.tv_sec = sapp_global_val->config.profiling.log.interval; topt.tv_usec = 0; sapp_event_set_opt(tev, STEO_TIMEOUT_VAL, &topt, sizeof(topt)); - sapp_event_set_opt(tev, STEO_CALLBACK_FUN, (void *)&line_protocol_timer_cbfun, sizeof(void *)); + //sapp_event_set_opt(tev, STEO_CALLBACK_FUN, (void *)&line_protocol_timer_cbfun, sizeof(void *)); ret = sapp_timer_add(th, tev); assert(ret >= 0); @@ -255,7 +255,7 @@ int __sapp_timer_platform_init(void) sapp_global_val->individual_fixed.sapp_standalone_timer = __st_timer_new(STO_EFFECTIVE_SCOPE_STANDALONE_THREAD); - __st_add_time_event_entry(); + //__st_add_time_event_entry(); return 0; } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index fd6bc77..f2b67db 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 2.8) -include_directories(${MESA_SDK_PREFIX}/include) -include_directories(${MESA_SDK_PREFIX}/include/MESA) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_SOURCE_DIR}/include/private) include_directories(${CMAKE_SOURCE_DIR}/include/public) include_directories(${CMAKE_SOURCE_DIR}/include/support) +include_directories(${MESA_SDK_PREFIX}/include) +include_directories(${MESA_SDK_PREFIX}/include/MESA) + if(OPT_IOMODE_MARSIO) include_directories(${MARSIO_SDK_PREFIX}/include) diff --git a/test/test_app_sapp.c b/test/test_app_sapp.c index 71979d2..e504781 100644 --- a/test/test_app_sapp.c +++ b/test/test_app_sapp.c @@ -1392,36 +1392,53 @@ char test_inject_tcp_pkt(struct streaminfo *stream,void **pme, int thread_seq,co return APP_STATE_DROPME; } -char test_20140731(struct streaminfo *pstream,void **pme, int thread_seq,const void *raw_pkt) +char test_sapp_inject_pkt(struct streaminfo *stream,void **pme, int thread_seq,const void *raw_pkt) { - static int __tot_c2s_pkt = 0; - static int __tot_s2c_pkt = 0; - static int __tot_s2c_len = 0; - static int __tot_c2s_len = 0; - struct tcpdetail *a_tcp = (struct tcpdetail *)pstream->pdetail; - - /* 2014-07-31, lijia add for test, ���ò�ͬ��unorderֵ, ���ջ�ȡ�����ݿ��ܲ�һ�� */ - tcp_set_single_stream_max_unorder(pstream, DIR_DOUBLE, 1); + char MESA_inject_pkt_payload[] = "send by MESA_inject_pkt "; + char sapp_inject_pkt_def_payload[] = "send by sapp_inject_pkt def"; + char sapp_inject_pkt_no_hdr_payload[256]; + struct stream_tuple4_v4 *tuple_v4; - if(a_tcp->datalen <= 0){ - return APP_STATE_GIVEME; - } - - if(DIR_C2S == pstream->curdir){ - __tot_c2s_pkt++; - __tot_c2s_len += a_tcp->datalen; - }else{ - __tot_s2c_pkt++; - __tot_s2c_len += a_tcp->datalen; + if(OP_STATE_CLOSE == stream->opstate){ + return APP_STATE_DROPME; } - printf("tot pkt: C2S:%6d, S2C:%6d\n", __tot_c2s_pkt, __tot_s2c_pkt); - printf("tot len: C2S:%6d, S2C:%6d\n\n", __tot_c2s_len, __tot_s2c_len); + tuple_v4 = (struct stream_tuple4_v4 *)(stream->addr.paddr); + + MESA_inject_pkt(stream, MESA_inject_pkt_payload, strlen("send by MESA_inject_pkt "), raw_pkt, stream->routedir); + sapp_inject_pkt(stream, SIO_DEFAULT, sapp_inject_pkt_def_payload, strlen("send by sapp_inject_pkt def"), stream->routedir); + struct mesa_ip4_hdr *ip4hdr = (struct mesa_ip4_hdr *)sapp_inject_pkt_no_hdr_payload; + struct mesa_tcp_hdr *thdr = (struct mesa_tcp_hdr *)((char *)ip4hdr + sizeof(struct mesa_ip4_hdr)); //no options + + thdr->th_sport = tuple_v4->source; + thdr->th_dport = tuple_v4->dest; + thdr->th_seq = 0x11111111; + thdr->th_ack = 0x22222222; + thdr->th_off = 5; + thdr->th_win = 100; + thdr->th_sum = 0; + + ip4hdr->ip_v = 4; + ip4hdr->ip_hl = 5; + ip4hdr->ip_len = htons(sizeof(struct mesa_ip4_hdr) + sizeof(struct mesa_tcp_hdr) + strlen("send by sapp_inject_pkt hdr")); + ip4hdr->ip_id = 0x3333; + ip4hdr->ip_off = 0; + ip4hdr->ip_ttl = 128; + ip4hdr->ip_p = 6; + ip4hdr->ip_sum = 0; + ip4hdr->ip_src.s_addr = tuple_v4->saddr; + ip4hdr->ip_dst.s_addr = tuple_v4->daddr; + + strcpy(sapp_inject_pkt_no_hdr_payload + sizeof(struct mesa_ip4_hdr) + sizeof(struct mesa_tcp_hdr), "send by sapp_inject_pkt hdr"); + + sapp_inject_pkt(stream, SIO_EXCLUDE_THIS_LAYER_HDR, sapp_inject_pkt_no_hdr_payload, ntohs(ip4hdr->ip_len), stream->routedir); + return APP_STATE_GIVEME; } + char test_project_add(struct streaminfo *pstream,void **pme, int thread_seq,const void *a_packet) { static int __init_flag = 0; @@ -2363,12 +2380,14 @@ char IPv6_RAW_ENTRY(const struct streaminfo *pstream, const void *this_hdr, cons return APP_STATE_GIVEME; } +#endif + char POLLING_ENTRY(struct streaminfo *stream, void **pme, int thread_seq,void *a_packet) { + printf("polling entry, tid:%d\n", thread_seq); return APP_STATE_GIVEME; } -#endif int CHAR_INIT() |
