summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlijia <[email protected]>2020-03-25 15:06:03 +0800
committerlijia <[email protected]>2020-03-25 15:06:03 +0800
commitc43dbc185d7ef13b98fabc4c368fb33edafc3bb5 (patch)
tree9ace0497cc97d64eec561cab55f16ff62a127539
parent2e6da7600c366f3ff36d4d4db3cabcd245b5c3ec (diff)
支持pcap模式下, 指定捕包方向[in, out, inout];
支持ethernet跳过非ip层的协议,便于使用系统路由测试注入数据包功能.
-rw-r--r--bin/etc/sapp.toml11
-rw-r--r--include/private/sapp_declaration.h2
-rw-r--r--include/private/sapp_global_val.h2
-rw-r--r--include/private/stream_internal.h3
-rw-r--r--src/config/config_parse.cpp9
-rw-r--r--src/dealpkt/deal_vlan.c2
-rw-r--r--src/entry/sapp_init.c4
-rw-r--r--src/packet_io/packet_io.c2
-rw-r--r--src/packet_io/packet_io_pcap.c16
-rw-r--r--tools/tun_transparent/Makefile.user3
10 files changed, 37 insertions, 17 deletions
diff --git a/bin/etc/sapp.toml b/bin/etc/sapp.toml
index fece67f..a599265 100644
--- a/bin/etc/sapp.toml
+++ b/bin/etc/sapp.toml
@@ -14,20 +14,24 @@ worker_threads=1
bind_mask=[]
[PACKET_IO]
+ [packet_io.feature]
### note, used to represent inbound or outbound direction value,
### because it comes from other 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
+ 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=""
+ BSD_packet_filter=""
+
+### note, same as tcpdump -Q/-P arg, possible values are `in', `out' and `inout', default is "in"
+ pcap_capture_direction="inout"
### note, depolyment.mode options: [mirror, inline, transparent]
[packet_io.depolyment]
mode=mirror
-### note, interface.type options: [pag, pcap, marsio]
+### 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]
@@ -70,6 +74,7 @@ BSD_packet_filter=""
ipv6_send_packet_enabled=1
tcp_drop_pure_ack_pkt=0
tcp_syn_option_parse_enabled=1
+ skip_not_ip_layer_over_eth=1
[PROFILING]
[profiling.pkt_latency]
diff --git a/include/private/sapp_declaration.h b/include/private/sapp_declaration.h
index 62151c3..5bb924b 100644
--- a/include/private/sapp_declaration.h
+++ b/include/private/sapp_declaration.h
@@ -58,7 +58,7 @@ extern sapp_global_t *sapp_global_val;
#define g_tcp_syn_option_parse_enabled sapp_global_val->config.protocol_feature.tcp_syn_option_parse_enabled
#define g_ipv6_decapsulation_enabled sapp_global_val->config.protocol_feature.ipv6_decapsulation_enabled
#define g_ipv6_send_packet_enabled sapp_global_val->config.protocol_feature.ipv6_send_packet_enabled
-
+#define G_SKIP_NOT_IP_LAYER sapp_global_val->config.protocol_feature.skip_not_ip_layer_over_eth
#define sapp_runtime_log(log_level, format, args...) do{if(log_level>=ABBR_SAPP_LOG_LEVEL){MESA_handle_runtime_log(ABBR_SAPP_LOG_HANDLE, log_level, "sapp", format, ##args);}}while(0)
diff --git a/include/private/sapp_global_val.h b/include/private/sapp_global_val.h
index ee64e2d..812cadd 100644
--- a/include/private/sapp_global_val.h
+++ b/include/private/sapp_global_val.h
@@ -160,6 +160,7 @@ typedef struct{
int polling_enabled;
int polling_priority; /* call sapp_recv_pkt every call polling_entry times, ���ö��ٴ�polling�����һ��recv pkt, 1��ʾ�������ȼ���ͬ */
int inbound_route_dir; /* ��ʾ�뾳, I2C�����ֵ��0����1 */
+ char pcap_capture_direction[NAME_MAX]; /* in, out, inout */
}sapp_config_packet_io_t;
typedef struct{
@@ -175,6 +176,7 @@ typedef struct{
int ipv6_send_packet_enabled; /* �Ƿ�֧�ַ���ipv6���ݰ�, ��������ϵͳipv6�ں�ģ���Ƿ���� */
int tcp_drop_pure_ack_pkt; /* ����û�и��صĴ�ack��, ���Խ�Լһ��������ѯ, ����ҵ���������� */
int tcp_syn_option_parse_enabled; /* �Ƿ����tcp syn��ͷ��ѡ�� */
+ int skip_not_ip_layer_over_eth; /* ������ip��, ��֤�ڲ���ģʽ��, ����ͨ��ϵͳ·�ɷ���rst�� */
}sapp_protocol_feature_t;
diff --git a/include/private/stream_internal.h b/include/private/stream_internal.h
index fceb2d5..b9c2c4f 100644
--- a/include/private/stream_internal.h
+++ b/include/private/stream_internal.h
@@ -343,9 +343,6 @@ struct sapp_global_mthread_t{
extern struct sapp_global_single_t sapp_global_single;
extern struct sapp_global_mthread_t sapp_global_mthread[MAX_THREAD_NUM];
-extern int G_SKIP_NOT_IP_LAYER;
-
-
int MESA_kill_tcp_remedy(struct streaminfo *stream, const void *ext_raw_pkt);
long long sapp_get_cpu_cycle(void);
diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp
index d1250dd..0ac9b28 100644
--- a/src/config/config_parse.cpp
+++ b/src/config/config_parse.cpp
@@ -578,12 +578,14 @@ int sapp_parse_config(void)
tomlc99_wrap_load_long_array(default_config_file, (char *)"CPU", (char *)"bind_mask", pconfig->cpu.bind_mask_array, &pconfig->cpu.bind_mask_array_num);
/******************************* PACKET_IO ******************************/
- tomlc99_wrap_load_string_def(default_config_file, (char *)"PACKET_IO", (char *)"BSD_packet_filter", str_tmp, NAME_MAX, "");
+ /******************************* packet_io.feature ******************************/
+ tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.feature", (char *)"BSD_packet_filter", str_tmp, NAME_MAX, "");
if(str_tmp[0] != '\0'){
pconfig->packet_io.input_bpf_filter = strdup(str_tmp);
}
- tomlc99_wrap_load_int_def(default_config_file, (char *)"PACKET_IO", (char *)"inbound_route_dir", &pconfig->packet_io.inbound_route_dir, 0);
-
+ tomlc99_wrap_load_int_def(default_config_file, (char *)"packet_io.feature", (char *)"inbound_route_dir", &pconfig->packet_io.inbound_route_dir, 0);
+ tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.feature", (char *)"pcap_capture_direction", pconfig->packet_io.pcap_capture_direction, NAME_MAX, "in");
+
tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.depolyment", (char *)"mode", pconfig->packet_io.depolyment_mode_str, NAME_MAX, "mirror");
tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.internal.interface", (char *)"type", pconfig->packet_io.internal.interface.type_str, NAME_MAX, "pcap");
tomlc99_wrap_load_string_def(default_config_file, (char *)"packet_io.internal.interface", (char *)"name", pconfig->packet_io.internal.interface.name, NAME_MAX, "lo");
@@ -669,6 +671,7 @@ int sapp_parse_config(void)
tomlc99_wrap_load_int_def(default_config_file, (char *)"PROTOCOL_FEATURE", (char *)"ipv6_send_packet_enabled", (int *)&pconfig->protocol_feature.ipv6_send_packet_enabled, 1);
tomlc99_wrap_load_int_def(default_config_file, (char *)"PROTOCOL_FEATURE", (char *)"tcp_drop_pure_ack_pkt", (int *)&pconfig->protocol_feature.tcp_drop_pure_ack_pkt, 0);
tomlc99_wrap_load_int_def(default_config_file, (char *)"PROTOCOL_FEATURE", (char *)"tcp_syn_option_parse_enabled", (int *)&pconfig->protocol_feature.tcp_syn_option_parse_enabled, 1);
+ tomlc99_wrap_load_int_def(default_config_file, (char *)"PROTOCOL_FEATURE", (char *)"skip_not_ip_layer_over_eth", (int *)&pconfig->protocol_feature.skip_not_ip_layer_over_eth, 0);
/******************************* TOOLS **********************************/
tomlc99_wrap_load_int_def(default_config_file, (char *)"tools.pkt_dump", (char *)"enabled", (int *)&pconfig->tools.pkt_dump.enabled, 0);
diff --git a/src/dealpkt/deal_vlan.c b/src/dealpkt/deal_vlan.c
index 02dd847..92ed714 100644
--- a/src/dealpkt/deal_vlan.c
+++ b/src/dealpkt/deal_vlan.c
@@ -31,7 +31,7 @@ int vlan_8021q_entry(struct streaminfo_private *pfstream_pr,const void *this_lay
int next_layer_offset = offset_to_raw_pkt_hdr + VLAN_TAG_LEN;
sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_num]->sys_stat;
- if(unlikely(0 == G_SKIP_NOT_IP_LAYER)){
+ if(likely(0 == G_SKIP_NOT_IP_LAYER)){
memset(ptmp,0,sizeof(struct streamindex));
set_vlanid(&addr, (unsigned short *)this_layer_data);
#if IKNOW_ENABLE
diff --git a/src/entry/sapp_init.c b/src/entry/sapp_init.c
index 89937ff..ccb4e69 100644
--- a/src/entry/sapp_init.c
+++ b/src/entry/sapp_init.c
@@ -25,7 +25,6 @@ extern void sesame_open_door(const char *lock_path, const char *lock_name);
//int top_mode = 0;
extern int G_DICTATOR_SW;
extern struct global_stream **G_MESA_GLOBAL_STREAM;
-extern int G_SKIP_NOT_IP_LAYER; /* ������IPЭ��IJ�, ����˫ջ�������⻷����, RST������ */
//static int __times = 0;
//int g_timestamp_record_sw = 0;
extern long long g_timedelay_threshold;
@@ -189,12 +188,13 @@ int MESA_platform_init(int argc, char *argv[])
//udp_set_stream_timeout(udp_stream_timeout);
udp_set_stream_num(max_udp_stream_num*3,max_udp_stream_num,max_udp_stream_num*2);
-
+#if 0
MESA_load_profile_int_def("conf/main.conf","Module", "skip_not_ip_layer", &G_SKIP_NOT_IP_LAYER, 0);
if(G_SKIP_NOT_IP_LAYER != 0){
printf("\033[41mWarning! '%s' is enable!\033[0m\n", "skip_not_ip_layer");
sleep(1);
}
+#endif
//MESA_load_profile_int_def("conf/main.conf","Module", "timestamp_record", &g_timestamp_record_sw, 0);
MESA_load_profile_int_def("conf/main.conf","Module", "timedelay_threshold", &int_tmp, 10000000);
diff --git a/src/packet_io/packet_io.c b/src/packet_io/packet_io.c
index fc66d5a..44c9f0b 100644
--- a/src/packet_io/packet_io.c
+++ b/src/packet_io/packet_io.c
@@ -63,7 +63,7 @@ int g_encapsulate_with_L2E = 0; /* ʹ��DDPЭ���װ��x27ԭʼIP�� */
int g_skip_ethernet_layer_sw = 0;
void *g_packet_dl_send_handle[MAX_THREAD_NUM];/* ��̬IO��ķ������ */
//static int g_packet_io_dir; /* ���ڼ�¼��ǰ��������, �����ʱʹ�� */
-int G_SKIP_NOT_IP_LAYER = 0; /* ������IPЭ��IJ�, ����˫ջ�������⻷����, RST������ */
+//int G_SKIP_NOT_IP_LAYER = 0; /* ������IPЭ��IJ�, ����˫ջ�������⻷����, RST������ */
static int mesa_default_pkt_cb(const raw_pkt_t *p_raw_pkt, unsigned char dir, int thread_num);
PACKET_IO_CB_T G_DEFAULT_PKT_CB = mesa_default_pkt_cb;
diff --git a/src/packet_io/packet_io_pcap.c b/src/packet_io/packet_io_pcap.c
index 24ab773..3784b1c 100644
--- a/src/packet_io/packet_io_pcap.c
+++ b/src/packet_io/packet_io_pcap.c
@@ -48,6 +48,7 @@ static unsigned long long tot_up_rcv_pkt_num, tot_down_rcv_pkt_num;
static int pcap_device_up_mtu = 1500;
static int pcap_device_down_mtu = 1500;
+extern sapp_global_t *sapp_global_val;
extern int g_PollingFunNum;
extern int g_use_MESA_sleep_sw;
extern void MESA_sleep(void);
@@ -1259,6 +1260,11 @@ int pcap_dl_io_init(int argc, char *argv[])
}
else /* ����ץ��ģʽ */
{
+ if((strncasecmp(sapp_global_val->config.packet_io.depolyment_mode_str, "transparent", strlen("transparent")) == 0)
+ && (strstr(sapp_global_val->config.packet_io.pcap_capture_direction, "out") != NULL)){
+ printf("\033[1;31;40m[Error]in transparent mode, pcap_capture_direction must set 'in'![0m\n", g_pcap_up_dev_name, pcap_errbuf);
+ return -1;
+ }
pcap_up_handle = pcap_open_live(g_pcap_up_dev_name, PCAP_SNAPLEN_MAX,1,1,pcap_errbuf);
if(NULL == pcap_up_handle)
{
@@ -1267,8 +1273,14 @@ int pcap_dl_io_init(int argc, char *argv[])
}
pcap_set_filter(pcap_up_handle, g_pcap_cap_filter);
- pcap_setdirection(pcap_up_handle, PCAP_D_IN);
-
+ if(strncasecmp(sapp_global_val->config.packet_io.pcap_capture_direction, "inout", 5) == 0){
+ pcap_setdirection(pcap_up_handle, PCAP_D_INOUT);
+ }else if(strncasecmp(sapp_global_val->config.packet_io.pcap_capture_direction, "out", 3) == 0){
+ pcap_setdirection(pcap_up_handle, PCAP_D_OUT);
+ }else{
+ pcap_setdirection(pcap_up_handle, PCAP_D_IN);
+ }
+
opt_len = sizeof(int);
sapp_get_device_opt(g_pcap_up_dev_name, SDO_MTU, &pcap_device_up_mtu, &opt_len);
if(pcap_device_up_mtu < 1500){
diff --git a/tools/tun_transparent/Makefile.user b/tools/tun_transparent/Makefile.user
index b8cf9d1..6263278 100644
--- a/tools/tun_transparent/Makefile.user
+++ b/tools/tun_transparent/Makefile.user
@@ -25,7 +25,8 @@ all: $(TARGET)
sapp_tun_bridge_user:sapp_tun_bridge_user.c
- gcc -o $@ $^ -g -O0 $(CFLAGS) -lpthread -lpcap -lnetfilter_queue -lnfnetlink
+ #gcc -o $@ $^ -g -O0 $(CFLAGS) -lpthread -lpcap -lnetfilter_queue -lnfnetlink
+ gcc -o $@ $^ -g -O0 $(CFLAGS) -lpthread -lpcap
.c.o:
$(CC) -c -o $@ $(CFLAGS) -I. $(INCS) $<