summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2023-08-14 16:01:46 +0800
committeryangwei <[email protected]>2023-08-15 13:46:04 +0800
commitd0493e0bf333ebf72ce29ceb760b3243d808ba23 (patch)
treea2d54f0857a7c92b06e9d1cb3f23cda49165c750
parent1ada79ef90474fb3c84c53aace7c0f59a6ad7697 (diff)
🐞 fix(stream_inject.h): remove legacy inject interface
-rw-r--r--bin/etc/sapp.toml12
-rw-r--r--include/private/packet_io.h1
-rw-r--r--include/private/packet_io_internal.h5
-rw-r--r--include/private/sendpacket.h77
-rw-r--r--include/public/stream_inc/stream_inject.h151
-rw-r--r--src/config/config_parse.cpp19
-rw-r--r--src/dealpkt/stream_manage.c2
-rw-r--r--src/packet_io/CMakeLists.txt2
-rw-r--r--src/packet_io/packet_io.c139
-rw-r--r--src/packet_io/sapp_compat_old_papp_api.c448
-rw-r--r--src/packet_io/sapp_inject.c10
-rw-r--r--src/packet_io/sendpacket.c1236
12 files changed, 132 insertions, 1970 deletions
diff --git a/bin/etc/sapp.toml b/bin/etc/sapp.toml
index aeab7d7..ac5662b 100644
--- a/bin/etc/sapp.toml
+++ b/bin/etc/sapp.toml
@@ -44,16 +44,16 @@
### 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"
+ inject_pkt_mode="default"
### note, this config is valid if inject_pkt_mode==vxlan_by_inline_device, means udp socket src port.
- inject_mode_inline_device_sport=54789
+ #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_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"
+ #inject_mode_single_gateway_src_mac="00:11:22:77:88:99"
+ #inject_mode_single_gateway_dst_mac="00:11:22:33:44:55"
monitor_thread_enabled=1
@@ -67,7 +67,7 @@
destroy_all_plug_enabled = 1
### note, depolyment.mode options: [mirror, inline, transparent]
[packet_io.depolyment]
- mode="mirror"
+ mode="inline"
### note, interface.type options: [pag, pcap, marsio, tun]
### receive from internal interface, route dir is 0,
diff --git a/include/private/packet_io.h b/include/private/packet_io.h
index d113c70..e91b6e6 100644
--- a/include/private/packet_io.h
+++ b/include/private/packet_io.h
@@ -78,6 +78,7 @@ enum send_fake_packet_mode{
SEND_PKT_MODE_STACK_2_LAYER_1_ROUTE = 1, /* ��������ģʽ��Э��ջ���㷢������һĿ��·��*/
SEND_PKT_MODE_STACK_2_LAYER_MUTI_ROUTE = 2, /* ��������ģʽ��Э��ջ���㷢�������Ŀ��·��*/
SEND_PKT_MODE_GDEV = 3, /* ��������ģʽ�� gdevע�� */
+ SEND_PKT_MODE_DEFAULT = 4, /* ��������ģʽ�� Ĭ�� */
};
typedef int (*PACKET_IO_CB_T)(const raw_pkt_t *p_raw_pkt,unsigned char dir,int thread_num);
diff --git a/include/private/packet_io_internal.h b/include/private/packet_io_internal.h
index bc8e214..36bcf79 100644
--- a/include/private/packet_io_internal.h
+++ b/include/private/packet_io_internal.h
@@ -176,8 +176,11 @@ extern int get_pkt_len_from_eth_hdr(const struct mesa_ethernet_hdr *ehdr);
extern int packet_io_send_fake_pkt_by_gdev(MESA_send_handle *send_handle, enum addr_type_t addrtype,
char *data, int datalen, int dir_reverse,char *feedback_buf, int *feedback_buf_len);
unsigned long long MESA_rand_range(unsigned long long start, unsigned long long end);
-int __MESA_rst_tcp_c(struct streaminfo *stream, unsigned char rst_th_flags, int rst_pkt_num, unsigned char snd_rst_dir,
+int __MESA_rst_tcp(struct streaminfo *stream, unsigned char rst_th_flags, int rst_pkt_num, unsigned char snd_rst_dir,
unsigned short signature_seed1, unsigned short signature_seed2);
+int __sapp_inject_pkt(struct streaminfo *raw_stream, enum sapp_inject_opt sio,
+ const void *payload, int payload_len, unsigned char snd_routedir, void *user_arg);
+
int packet_io_hook_input(raw_pkt_t *raw_pkt, unsigned char dir, int thread_num);
int packet_io_hook_input_mirror(raw_pkt_t *raw_pkt, unsigned char dir, int thread_num);
int packet_io_hook_forward(raw_pkt_t *raw_pkt, unsigned char dir, int thread_num);
diff --git a/include/private/sendpacket.h b/include/private/sendpacket.h
index 3688488..d7ad47a 100644
--- a/include/private/sendpacket.h
+++ b/include/private/sendpacket.h
@@ -411,69 +411,7 @@ extern "C" int g_UseSendpktCard;
#else
extern int g_UseSendpktCard;
#endif
-#ifdef PLATFORM_NSDPF_PAPP
-#define SENDBUF_LOCATION_TOOL (0) /* �Ѿ�COPY��sendpacketTool�ṹ�е����� */
-#define SENDBUF_LOCATION_APP (1) /* Ӧ�ò�����Լ�������ڴ� */
-typedef struct _sendpacketTool
-{
- int send_fd;
- int send_raw_eth_fd; /* 2013-11-08 LiJia add, ����ģʽ�·���eth�� */
- short threadnum;//add by lqy 20090313
- short sendtype;
- int errflag;
- int sendbuflen;
- u_int64_t pkt_send;
- u_int64_t bytes_send;
- u_int64_t pkt_senderr;
- unsigned char *__raw_send_buf; /* add by LiJia 2012-04-10��ȫ����������������̫��֡ͷ */
- unsigned char *send_buf; /* modify by LiJia 2012-04-10��ʹ�÷�ʽ�ı䣬IP�㼰Ӧ�ò㻺������Ϊ�˺�֮ǰ�ӿڱ��ּ����� */
- unsigned char *send_ptr; /* ָ������͵����ݣ����ݹ���ģʽ�ͷ�����ʽ��������__raw_send_buf, send_buf, ������Ӧ�ò��Լ�������ڴ� */
- //char device_name[IFNAMSIZ];//add by LiJia 2012-04-10����������
- struct sockaddr sa; /* 2012-07-17 LiJia add, RAW_LINKģʽ����ʱʹ�� */
- struct sockaddr sa2; /* 2012-07-17 LiJia add, ����˫������RAW_LINKģʽ����ʱʹ�� */
- struct sockaddr sa_raw_eth; /* 2013-11-08 LiJia add, ����ģʽ�·���eth�� */
- int protocol;//add by LiJia 2012-04-10��������
- int send_buf_location; /* �����͵����������ڴ�ռ䣬0:�Ѿ�COPY��sendpacketTool�ṹ�е�����; 1:Ӧ�ò�����Լ�������ڴ� */
- unsigned char linktype;
- unsigned char linkoffset;
-#ifdef CAPTURE_MODE_PFRING
- pfring *pf_handle;
- pfring_pkt_buff *pkt_handle;
- int pfring_if_index;
- int pfring_if_index2;
-#endif
-}sendpacketTool;
-#ifdef __cplusplus
-extern "C" {
-#endif
-int sendpacket_build_ip(u_int16_t len, u_char tos, u_int16_t id, u_int16_t frag, u_int8_t ttl,
- u_int8_t prot, u_int32_t src, u_int32_t dst, const char *payload,
- int payload_s, unsigned char *buf);
-int sendpacket_build_ipv4(u_int16_t len, u_int8_t tos, u_int16_t id, u_int16_t frag,
- u_int8_t ttl, u_int8_t prot, u_int32_t src, u_int32_t dst,
- const char *payload, int payload_s, unsigned char *buf);
-int sendpacket_build_tcp(u_int16_t sp, u_int16_t dp, u_int32_t seq, u_int32_t ack, u_int8_t control,
- u_int16_t win, u_int16_t urg, const char *payload, int payload_s,unsigned char *buf);
-int sendpacket_build_tcp_with_option(u_int16_t sp, u_int16_t dp, u_int32_t seq, u_int32_t ack, u_int8_t control,
- u_int16_t win, u_int16_t urg, const char *option, int option_len, const char *payload, int payload_s,
- unsigned char *buf);
-int sendpacket_build_udp_dual_stack(u_int16_t sp, u_int16_t dp, const char *payload, int payload_s,int, unsigned char *buf);
-int sendpacket_build_ethernet(u_char *dst, u_char *src, u_short type,
- const u_char *payload, int payload_s, u_char *buf);
-int sendpacket_build_arp(u_short hrd, u_short pro, u_char hln, u_char pln, u_short op,
- u_char *sha, u_char *spa, u_char *tha, u_char *tpa,
- const u_char *payload, int payload_s, u_char *buf);
-int sendpacket_do_checksum(unsigned char *buf, int protocol, int len);
-int sendpacket_init_packet(int p_size, unsigned char **buf);
-int sendpacket_tool_init(void);
-extern int sendpacket_write_new( sendpacketTool *pTool,int sendlen, char dir);
-int sendpacket_build_icmpv4_echo(u_int8_t type, u_int8_t code, u_int16_t sum,
- u_int16_t id, u_int16_t seq, u_int8_t *payload, u_int32_t payload_s, unsigned char *buf);
-#ifdef __cplusplus
-}
-#endif
-#else // #ifdef PLATFORM_PAPP
typedef struct _sendpacketTool
{
int send_fd;
@@ -497,9 +435,10 @@ int sendpacket_build_ipv4(u_int16_t len, u_int8_t tos, u_int16_t id, u_int16_t f
const char *payload, int payload_s, unsigned char *buf);
int sendpacket_build_icmpv4_echo(u_int8_t type, u_int8_t code, u_int16_t sum,
u_int16_t id, u_int16_t seq, u_int8_t *payload, u_int32_t payload_s, unsigned char *buf);
-int sendpacket_build_tcp(u_int16_t sp, u_int16_t dp, u_int32_t seq, u_int32_t ack, u_int8_t control,
- u_int16_t win, u_int16_t urg, const char *payload, int payload_s,
- char *buf);
+
+int sendpacket_build_tcp(u_int16_t sp, u_int16_t dp, u_int32_t seq, u_int32_t ack,
+ u_int8_t th_flags, u_int16_t win, u_int16_t urg,
+ const char *payload, int payload_s, unsigned char *buf);
int sendpacket_build_udp_dual_stack(u_int16_t sp, u_int16_t dp, const char *payload, int payload_s,int,unsigned char *buf);
int sendpacket_build_ethernet(u_char *dst, u_char *src, u_short type,
const u_char *payload, int payload_s, u_char *buf);
@@ -511,7 +450,6 @@ int sendpacket_init_packet(int p_size, char **buf);
#ifdef __cplusplus
}
#endif
-#endif
#ifdef __cplusplus
extern "C" {
@@ -530,13 +468,6 @@ char * sendpacket_geterr(sendpacketTool *pTool);
int sendpacket_write(sendpacketTool *pTool,int sendlen);
int sendpacket_checkbufsize(sendpacketTool *pTool,int sendlen);
-#ifdef CAPTURE_MODE_PFRING
-void pfring_set_ifindex(sendpacketTool *pTool, u_char dir);
-int pfring_get_sendbuf(sendpacketTool *pTool);
-void pfring_release_sendbuf(sendpacketTool *pTool);
-#endif
-
-
#ifdef __cplusplus
}
#endif
diff --git a/include/public/stream_inc/stream_inject.h b/include/public/stream_inc/stream_inject.h
index dd72cd4..0654dbe 100644
--- a/include/public/stream_inc/stream_inject.h
+++ b/include/public/stream_inc/stream_inject.h
@@ -9,9 +9,6 @@
extern "C" {
#endif
-#define STREAM_INJECT_H_VERSION (20191120)
-
-
/*
CHN : ����GK��غ���
ENG : to force terminate a stream;
@@ -25,8 +22,6 @@ extern "C" {
-1 : error.
*/
int MESA_kill_tcp(struct streaminfo *stream, const void *raw_pkt);
-int MESA_kill_tcp_synack(struct streaminfo *stream, const void *raw_pkt);
-int MESA_kill_connection(struct streaminfo *stream, const void *ext_raw_pkt);
struct rst_tcp_para{
unsigned char th_flags; /* TCPͷ����־λ, ��ѡֵΪ[TH_RST, TH_RST|TH_ACK] */
@@ -91,9 +86,7 @@ int MESA_rst_tcp(struct streaminfo *stream, struct rst_tcp_para *paras, int para
-1 : error.
-2 : feedback_buf or feedback_buf_len error.
*/
-int MESA_kill_tcp_feedback(struct streaminfo *stream, const void *raw_pkt, char *feedback_buf, int *feedback_buf_len);
-int MESA_kill_tcp_synack_feedback(struct streaminfo *stream, const void *raw_pkt, char *feedback_buf, int *feedback_buf_len);
-int MESA_kill_connection_feedback(struct streaminfo *stream, const void *raw_pkt, char *feedback_buf, int *feedback_buf_len);
+
int MESA_send_smart_offload(const struct streaminfo *pstream, const void *raw_pkt, int thread_num);
/*
@@ -133,147 +126,7 @@ int MESA_dir_human_to_link(int human_dir);
>0: ���͵����ݰ�ʵ���ܳ���(payload_len + �ײ��ͷ����);
*/
int MESA_inject_pkt(struct streaminfo *stream, const char *payload, int payload_len, const void *raw_pkt, UCHAR snd_routedir);
-
-/*
- ���������ܵ�MESA_inject_pkt_feedback����, ����ͬMESA_inject_pkt().
- ��ʵ�ʷ��͵����ݰ�copy��feedback_buf�ռ���, ������feedback_buf_lenΪʵ�����ݰ�����.
-
- ע��: feedback_buf_lenΪ���봫����, �����ʾfeedback_buf����, ������ʾʵ�ʷ��͵����ݰ�����.
-
- return value:
- >= 0: success.
- -1 : error.
- -2 : feedback_buf or feedback_buf_len error.
-*/
-int MESA_inject_pkt_feedback(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 MESA_sendpacket_ethlayer(int thread_index,const char *buf, int buf_len, unsigned int target_id);//papp online, shuihu
-
-/* �����ѹ���õ�����IP��, У��͵Ⱦ�������߼��� */
-int MESA_sendpacket_iplayer(int thread_index,const char *buf, int buf_len, __uint8_t dir);
-
-/* �����ѹ���õ�����IPv4��, ����vxlan����, options��������vxlan��ص�ѡ�� */
-int MESA_sendpacket_iplayer_options(int thread_index,const char *data, int data_len, u_int8_t dir, SAPP_TLV_T *options, int opt_num);
-
-/* �����ѹ���õ�����IPv6��, У��͵Ⱦ�������߼���, ����vxlan����, options��������vxlan��ص�ѡ�� */
-int MESA_sendpacket_ipv6_layer_options(int thread_index,const char *data, int data_len, u_int8_t dir, SAPP_TLV_T *options, int opt_num);
-/* ����ָ������IP��, ��ָ����������, У�����ƽ̨�Զ�����,
- sip, dip������. */
-int MESA_fakepacket_send_ipv4(int thread_index,__uint8_t ttl,__uint8_t protocol,
- u_int32_t sip_host_order, u_int32_t dip_host_order,
- const char *payload, int payload_len,__uint8_t dir);
-
-int MESA_fakepacket_send_ipv4_options(const struct streaminfo *stream, uint8_t protocol,
- uint32_t sip_host_order, uint32_t dip_host_order,
- const char *payload, int payload_len, uint8_t dir,
- SAPP_TLV_T *options, int opt_num);
-
-int MESA_fakepacket_send_ipv4_detail(int thread_index,u_int8_t ttl,
- u_int8_t protocol,u_int32_t sip, u_int32_t dip, u_int16_t ipid,
- const char *payload, int payload_len,u_int8_t dir);
-
-int MESA_fakepacket_send_ipv6_options(const struct streaminfo *stream, uint8_t protocol,
- struct in6_addr *sip, struct in6_addr *dip,
- const char *payload, int payload_len, uint8_t dir,
- SAPP_TLV_T *options, int opt_num);
-/* ����ָ������TCP��, ��ָ����������, У�����ƽ̨�Զ�����,
- sip, dip,sport,dport,sseq,sack��������. */
-int MESA_fakepacket_send_tcp(int thread_index,u_int sip_host_order,u_int dip_host_order,
- u_short sport_host_order,u_short dport_host_order,
- u_int sseq_host_order,u_int sack_host_order,
- u_char control,const char* payload,int payload_len, u_int8_t dir);
-
-int MESA_fakepacket_send_tcp_detail(int thread_index,u_int sip_host_order,u_int dip_host_order,
- u_short ipid, u_char ip_ttl,
- u_short sport_host_order,u_short dport_host_order,
- u_int sseq_host_order,u_int sack_host_order,
- u_char control, u_short tcp_win, const char* payload,int payload_len, u_int8_t dir);
-int MESA_fakepacket_send_tcp_options(const struct streaminfo *stream,
- u_int sip_host_order,u_int dip_host_order,
- u_short sport_host_order,u_short dport_host_order,
- u_int sseq_host_order,u_int sack_host_order,
- u_char control,
- const char* payload,int payload_len, u_int8_t dir,
- SAPP_TLV_T *options, int opt_num);
-int MESA_fakepacket_send_ipv6_tcp_options(const struct streaminfo *stream,
- struct in6_addr *sip, struct in6_addr *dip,
- u_short sport_host_order,u_short dport_host_order,
- u_int sseq_host_order,u_int sack_host_order,
- u_char control,
- const char* payload,int payload_len, u_int8_t dir,
- SAPP_TLV_T *options, int opt_num);
-/* ����ָ������UDP��, ��ָ����������, У�����ƽ̨�Զ�����,
- sip, dip,sport,dport��������. */
-int MESA_fakepacket_send_udp(int thread_index, u_int sip_host_order, u_int dip_host_order,
- u_short sport_host_order,u_short dport_host_order,
- const char *payload, int payload_len,u_int8_t dir);
-
-int MESA_fakepacket_send_udp_detail(int thread_index, u_int sip_host_order, u_int dip_host_order,
- u_short ipid, u_int8_t ip_ttl, u_short sport_host_order,u_short dport_host_order,
- const char *payload, int payload_len,u_int8_t dir);
-int MESA_fakepacket_send_udp_options(const struct streaminfo *stream,
- u_int sip_host_order, u_int dip_host_order,
- u_short sport_host_order,u_short dport_host_order,
- const char *payload, int payload_len,u_int8_t dir,
- SAPP_TLV_T *options, int opt_num);
-int MESA_fakepacket_send_ipv6_udp_options(const struct streaminfo *stream,
- struct in6_addr *sip, struct in6_addr *dip,
- u_short sport_host_order,u_short dport_host_order,
- const char *payload, int payload_len,u_int8_t dir,
- SAPP_TLV_T *options, int opt_num);
-/*
- ת��/���͵�ǰ���������ݰ�,
- target_id: ����ָ��ת��/����Ŀ��, �������ļ�conf->send_raw_pkt.confָ������Ŀ���������豸��.
-*/
-int sapp_forward_current_pkt(const struct streaminfo *stream, unsigned int target_id);
-
-enum sapp_send_pkt_opt_type{
- SAPP_SEND_OPT_IP_ID = 0x10,
- SAPP_SEND_OPT_IP_TTL = 0x11,
-
- SAPP_SEND_OPT_TCP_WIN = 0x20,
-
- SAPP_SEND_OPT_GDEV_DMAC = 0x1101, /* GDEV-DMAC, �������������DMAC */
- SAPP_SEND_OPT_GDEV_SMAC = 0x1102, /* local-SMAC, �������������SMAC */
- SAPP_SEND_OPT_GDEV_DIP = 0x1103, /* GDEV-DIP, network order */
- SAPP_SEND_OPT_GDEV_SIP = 0x1104, /* local-SIP, network order */
- SAPP_SEND_OPT_GDEV_UDP_DPORT=0x1105, /* GDEV udp dst port, network order */
- SAPP_SEND_OPT_GDEV_UDP_SPORT= 0x1106, /* local udp src port, network order */
- SAPP_SEND_OPT_VXLAN_FLAGS = 0x1201, /* vxlan ��־λ */
- SAPP_SEND_OPT_VXLAN_VPN_ID = 0x1202, /* vxlan vlan_id/vpn_id */
- SAPP_SEND_OPT_VXLAN_LINK_ID = 0x1203, /* vxlan ��·id */
- SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE = 0x1204, /* vxlanԭʼ�����װ��ʽ */
- SAPP_SEND_OPT_VXLAN_ONLINE_TEST_FLAG = 0x1205, /* vxlan���߲���λ */
- SAPP_SEND_OPT_VXLAN_LINK_DIR = 0x1206, /* vxlan��·����λ */
- SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE = 1301, /* �ڲ�����װ��ʽ */
- SAPP_SEND_OPT_INNER_SMAC = 0x1302, /* �ڲ�ԴMAC */
- 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*/
-};
-
-int MESA_fakepacket_send_ipv4_options(const struct streaminfo *stream, uint8_t protocol,
- uint32_t sip_host_order, uint32_t dip_host_order,
- const char *payload, int payload_len, uint8_t dir,
- SAPP_TLV_T *options, int opt_num);
-
-int MESA_fakepacket_send_tcp_options(const struct streaminfo *stream,
- u_int sip_host_order,u_int dip_host_order,
- u_short sport_host_order,u_short dport_host_order,
- u_int sseq_host_order,u_int sack_host_order,
- u_char control,
- const char* payload,int payload_len, u_int8_t dir,
- SAPP_TLV_T *options, int opt_num);
-
-int MESA_fakepacket_send_udp_options(const struct streaminfo *stream,
- u_int sip_host_order, u_int dip_host_order,
- u_short sport_host_order,u_short dport_host_order,
- const char *payload, int payload_len,u_int8_t dir,
- SAPP_TLV_T *options, int opt_num);
-
+
#ifdef __cplusplus
}
#endif
diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp
index 194439c..0368eb2 100644
--- a/src/config/config_parse.cpp
+++ b/src/config/config_parse.cpp
@@ -786,7 +786,7 @@ static int update_asymmetric_presence_layer(enum addr_type_t addrtype, embed_lay
*/
static int parse_asymmetric_addr_layer_config(void)
{
- int i, j, ret, asymmetric_addr_layer_config_num = 0;
+ int i, j, ret;
FILE *fp;
char line_cont[MAX_INPUT];
embed_layer_t embed_layer;
@@ -813,7 +813,6 @@ static int parse_asymmetric_addr_layer_config(void)
}
update_asymmetric_layer_info(&g_asymmetric_addr_layer_set, &embed_layer);
- asymmetric_addr_layer_config_num++;
}
char one_layer_index_str[NAME_MAX];
@@ -858,7 +857,7 @@ static int set_default_stream_compare_layer(embed_layer_t *stream_compare_layer_
*/
static int parse_stream_compare_layer_config(void)
{
- int i, j, ret, asymmetric_addr_layer_config_num = 0;
+ int i, j, ret;
FILE *fp;
char line_cont[MAX_INPUT];
embed_layer_t embed_layer;
@@ -886,7 +885,6 @@ static int parse_stream_compare_layer_config(void)
}
update_asymmetric_layer_info(&g_stream_compare_layer_set, &embed_layer);
- asymmetric_addr_layer_config_num++;
}
char one_layer_index_str[NAME_MAX];
@@ -1168,9 +1166,12 @@ static int config_expression_convert(void)
pconfig->packet_io.inject_pkt_mode = SEND_PKT_MODE_STACK_2_LAYER_1_ROUTE;
}else if(strncasecmp("raw_ethernet_multi_gateway", pconfig->packet_io.inject_pkt_mode_string, strlen("raw_ethernet_multi_gateway")) == 0){
pconfig->packet_io.inject_pkt_mode = SEND_PKT_MODE_STACK_2_LAYER_MUTI_ROUTE;
- }else{
- sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->PACKET_IO.inject_pkt_mode error, only support:%s!", "[sys_route, vxlan_by_inline_device, raw_ethernet_single_gateway, raw_ethernet_multi_gateway]");
- return -1;
+ }else if(strncasecmp("default", pconfig->packet_io.inject_pkt_mode_string, strlen("default")) == 0){
+ pconfig->packet_io.inject_pkt_mode = SEND_PKT_MODE_DEFAULT;
+ }
+ else{
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->PACKET_IO.inject_pkt_mode set error, only support:%s!", "[default, sys_route, vxlan_by_inline_device, raw_ethernet_single_gateway, raw_ethernet_multi_gateway]");
+ return -1;
}
if(strncasecmp(pconfig->packet_io.inject_pkt_mode_string, "raw_ethernet_single_gateway", strlen("raw_ethernet_single_gateway")) == 0){
@@ -2147,7 +2148,7 @@ static int sapp_config_check_sanity(sapp_config_check_t *local_cfg_check_attr)
*/
int sapp_config_check(void)
{
- int i, ret1, ret2, ret3, final_ret = 0;
+ int i, ret1, ret2, final_ret = 0;
/* ȫ�ֱ������й̶����������, Ҳ�ж�̬�������ļ���ȡ������, ���Դ˴�copyһ����ʱ���� */
sapp_config_check_t *local_cfg_check_attr = (sapp_config_check_t *)sapp_mem_calloc(SAPP_MEM_FIX_GLOBAL_VAL, MEM_STAT_GLOBAL_THREAD_ID,sizeof(g_sapp_cfg_check_attr));
@@ -2169,7 +2170,7 @@ int sapp_config_check(void)
goto done;
}
- ret3 = sapp_config_check_sanity(local_cfg_check_attr);
+ sapp_config_check_sanity(local_cfg_check_attr);
final_ret = SAPP_MAX(ret2, final_ret);
done:
diff --git a/src/dealpkt/stream_manage.c b/src/dealpkt/stream_manage.c
index 76dbc19..9ff5b84 100644
--- a/src/dealpkt/stream_manage.c
+++ b/src/dealpkt/stream_manage.c
@@ -2646,6 +2646,7 @@ int polling_stream_timeout(int tid)
ret = del_stream_by_time(plist, NULL, tid);
if(ret > 0){
has_work = POLLING_STATE_WORK;
+ break;
}
}
}
@@ -2656,6 +2657,7 @@ int polling_stream_timeout(int tid)
ret = del_stream_by_time(plist, NULL, tid);
if(ret > 0){
has_work = POLLING_STATE_WORK;
+ break;
}
}
}
diff --git a/src/packet_io/CMakeLists.txt b/src/packet_io/CMakeLists.txt
index dfe487c..998230b 100644
--- a/src/packet_io/CMakeLists.txt
+++ b/src/packet_io/CMakeLists.txt
@@ -43,7 +43,7 @@ set(PACKET_IO_STATIC_SOURCE cycle_pkt_dump_through_write_offset.c packet_io_lib
packet_io_log.c sendpacket.c
packet_io.c
packet_io_status.cpp packet_io_status_new.c
-packet_io_device.c sapp_compat_old_papp_api.c
+packet_io_device.c
sapp_inject.c packet_io_hook.c under_ddos.cpp)
add_library(packet_io STATIC ${PACKET_IO_STATIC_SOURCE})
diff --git a/src/packet_io/packet_io.c b/src/packet_io/packet_io.c
index 044c7ec..56f87e5 100644
--- a/src/packet_io/packet_io.c
+++ b/src/packet_io/packet_io.c
@@ -891,16 +891,9 @@ static int packet_io_send_by_sys_routev4(MESA_send_handle *send_handle,int datal
return -1;
}
- /* ʹ��ϵͳ·��ʱ, MAC��ַ��Э��ջ���, ָ��ͳ���Ҫ��ȥETHͷ�� */
-#if 0
- actual_data_ptr = (char *)send_handle->send_buf + sizeof(mesa_ethernet_hdr);
- datalen -= sizeof(mesa_ethernet_hdr);
-#else
actual_data_ptr = (char *)send_handle->send_buf + offset;
datalen -= offset;
-#endif
-
ip4_hdr = (struct mesa_ip4_hdr *)actual_data_ptr;
memset(&sock_addr_v4, 0, sizeof(struct sockaddr_in));
@@ -908,12 +901,6 @@ static int packet_io_send_by_sys_routev4(MESA_send_handle *send_handle,int datal
/* build_ipv4ʱ�Ѿ���dir������õ�ַ, �˴�ֱ��ʹ��ip_dst���� */
sock_addr_v4.sin_addr.s_addr = ip4_hdr->ip_dst.s_addr;
- //if(sapp_global_single.send_fake_pkt_mode != 0){
- // return packet_io_send_fake_pkt_by_gdev(send_handle, ADDR_TYPE_IPV4,
- // actual_data_ptr+VXLAN_HDR_RESERVED_LEN, datalen, dir,
- // feedback_buf, feedback_buf_len);
- //}
-
retry:
ret = sendto(send_handle->raw_ipv4_fd, actual_data_ptr, datalen, 0,
(struct sockaddr *)&sock_addr_v4, sizeof(struct sockaddr));
@@ -1085,107 +1072,67 @@ send_again:
return ret;
}
-int packet_io_send_fake_pkt(MESA_send_handle *send_handle,int datalen,int send_type,
+int packet_io_send(MESA_send_handle *send_handle,int datalen,int send_type,
int low_layer_type, int dir,int thread_num,
char *feedback_buf, int *feedback_buf_len, const raw_pkt_t *raw_pkt)
{
int ret;
UINT16 low_layer_ether_hproto;
const struct mesa_ethernet_hdr *ehdr = (struct mesa_ethernet_hdr *)send_handle->send_buf;
-
- if(g_topology_mode & __NET_CONN_PARALLEL)
+ low_layer_ether_hproto = ntohs(ehdr->ether_type);
+ switch (sapp_global_val->config.packet_io.inject_pkt_mode)
{
-
- low_layer_ether_hproto = ntohs(ehdr->ether_type);
-
- if(sapp_global_val->config.packet_io.inject_pkt_mode == SEND_PKT_MODE_GDEV)
- {
- ret = packet_io_send_fake_pkt_by_gdev(send_handle, (enum addr_type_t)low_layer_type,
- (char *)send_handle->send_buf, datalen, dir, feedback_buf, feedback_buf_len);
- }
- else if(sapp_global_val->config.packet_io.inject_pkt_mode == SEND_PKT_MODE_STACK_2_LAYER_1_ROUTE
- || sapp_global_val->config.packet_io.inject_pkt_mode == SEND_PKT_MODE_STACK_2_LAYER_MUTI_ROUTE)
- {
- ret = packet_io_send_by_manual_conf(send_handle, datalen, dir, low_layer_ether_hproto);
- }
- else
+ case SEND_PKT_MODE_GDEV:
+ ret = packet_io_send_fake_pkt_by_gdev(send_handle, (enum addr_type_t)low_layer_type,
+ (char *)send_handle->send_buf, datalen, dir, feedback_buf, feedback_buf_len);
+ break;
+ case SEND_PKT_MODE_STACK_2_LAYER_1_ROUTE:
+ case SEND_PKT_MODE_STACK_2_LAYER_MUTI_ROUTE:
+ ret = packet_io_send_by_manual_conf(send_handle, datalen, dir, low_layer_ether_hproto);
+ break;
+ case SEND_PKT_MODE_STACK_3_LAYER:
{
switch (low_layer_type)
{
- case __ADDR_TYPE_IP_PAIR_V4:
- case ADDR_TYPE_IPV4:
- ret = packet_io_send_by_sys_routev4(send_handle, datalen, dir, feedback_buf, feedback_buf_len);
- break;
-
- case __ADDR_TYPE_IP_PAIR_V6:
- case ADDR_TYPE_IPV6:
- ret = packet_io_send_by_sys_routev6(send_handle, datalen, dir, feedback_buf, feedback_buf_len);
- break;
-
- default:
- /* ����ģʽ�µķ�IPЭ��, ����ʹ��ϵͳ·�ɷ���, ����ʹ��raw_eth_fdͨ��ָ���������� */
- ret = packet_io_send_by_manual_conf(send_handle, datalen, dir, low_layer_ether_hproto);
- break;
+ case __ADDR_TYPE_IP_PAIR_V4:
+ case ADDR_TYPE_IPV4:
+ ret = packet_io_send_by_sys_routev4(send_handle, datalen, dir, feedback_buf, feedback_buf_len);
+ break;
+
+ case __ADDR_TYPE_IP_PAIR_V6:
+ case ADDR_TYPE_IPV6:
+ ret = packet_io_send_by_sys_routev6(send_handle, datalen, dir, feedback_buf, feedback_buf_len);
+ break;
+
+ default:
+ /* ����ģʽ�µķ�IPЭ��, ����ʹ��ϵͳ·�ɷ���, ����ʹ��raw_eth_fdͨ��ָ���������� */
+ //ret = packet_io_send_by_manual_conf(send_handle, datalen, dir, low_layer_ether_hproto);
+ ret=-1;
+ break;
}
}
- }
- else
- {
- if(NULL == raw_pkt){
+ break;
+ default:
+ if (NULL == raw_pkt)
+ {
raw_pkt = sapp_global_val->mthread_volatile[thread_num]->raw_pkt;
}
-
- ret = dl_io_fun_list.dl_io_low_level_send(send_handle->low_level_send_handle,
- (UINT8 *)send_handle->send_buf,
- datalen,
- low_layer_type,
- dir,
- thread_num,
- raw_pkt);
- if(ret < 0){
- sapp_global_val->mthread_volatile[thread_num]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- }
- }
-
- return ret;
-}
-
-/*
- send_type:��������, RST, ��־, �ش����ݵ�;
- low_layer_type:��MAC��֮��, ��ײ�Э������, ��IPv4, ipv6, VLAN��.
- datalen :�ϲ�APP�ܳ�, ������MAC���14�ֽ�.
-*/
-int packet_io_send(MESA_send_handle *send_handle,int datalen,int send_type,
- int low_layer_type, int dir,int thread_num,
- char *feedback_buf, int *feedback_buf_len, const raw_pkt_t *raw_pkt)
-{
- int ret = -1;
-
- switch(send_type){
- case SEND_TYPE_LINK_INJECT:
- ret = packet_io_send_fake_pkt(send_handle, datalen, send_type, low_layer_type,
- dir, thread_num, feedback_buf, feedback_buf_len, raw_pkt);
- break;
-
- case SEND_TYPE_LOG:
- /* to do */
- ret = -1;
+ ret = dl_io_fun_list.dl_io_low_level_send(send_handle->low_level_send_handle,
+ (UINT8 *)send_handle->send_buf,
+ datalen,
+ low_layer_type,
+ dir,
+ thread_num,
+ raw_pkt);
break;
-
- case SEND_TYPE_REDIRECT:
- /* to do, ˮ�ԭʼ����ת�� */
- ret = -1;
- break;
-
- default:
- break;
- }
-
+ }
+ if (ret < 0)
+ {
+ sapp_global_val->mthread_volatile[thread_num]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
+ }
return ret;
}
-
-
send_raw_pkt_info_t *get_raw_pkt_conf_by_id(unsigned int target_id)
{
int i;
diff --git a/src/packet_io/sapp_compat_old_papp_api.c b/src/packet_io/sapp_compat_old_papp_api.c
deleted file mode 100644
index 4450227..0000000
--- a/src/packet_io/sapp_compat_old_papp_api.c
+++ /dev/null
@@ -1,448 +0,0 @@
-/**************************************************************
- pappƽ̨����WY��Ŀ��������, �����½ӿ�,
- sapp��ƽ̨Ϊ�˱���������, �������½ӿ�.
-***************************************************************/
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#include "sapp_api.h"
-#include "sapp_private_api.h"
-#include "sapp_declaration.h"
-
-#ifndef GSERIAL_PLUGID_MAX
-#define GSERIAL_PLUGID_MAX (64)
-#endif
-
-unsigned long long g_plug_rx_pkts[MAX_THREAD_NUM][GSERIAL_PLUGID_MAX+1]; /* temp add, for�ܿؼ�¼���� */
-
-volatile unsigned long long Gserial_sendpacket_ip_info[MAX_THREAD_NUM][GSERIAL_PLUGID_MAX];
-volatile unsigned long long Gserial_sendpacket_ipv6_info[MAX_THREAD_NUM][GSERIAL_PLUGID_MAX];
-volatile unsigned long long Gserial_sendpacket_tcp_info[MAX_THREAD_NUM][GSERIAL_PLUGID_MAX];
-volatile unsigned long long Gserial_sendpacket_udp_info[MAX_THREAD_NUM][GSERIAL_PLUGID_MAX];
-
-#if IOMODE_MARSIO
-extern int MESA_fakepacket_send_ipv6_options(const struct streaminfo *stream, uint8_t protocol,
- struct in6_addr *sip, struct in6_addr *dip,
- const char *payload, int payload_len, uint8_t dir,
- SAPP_TLV_T *options, int opt_num);
-extern int MESA_fakepacket_send_ipv6_tcp_options(const struct streaminfo *stream,
- struct in6_addr *sip, struct in6_addr *dip,
- u_short sport_host_order,u_short dport_host_order,
- u_int sseq_host_order,u_int sack_host_order,
- u_char control,
- const char* payload,int payload_len, u_int8_t dir,
- SAPP_TLV_T *options, int opt_num);
-extern int MESA_fakepacket_send_ipv6_udp_options(const struct streaminfo *stream,
- struct in6_addr *sip, struct in6_addr *dip,
- u_short sport_host_order,u_short dport_host_order,
- const char *payload, int payload_len,u_int8_t dir,
- SAPP_TLV_T *options, int opt_num);
-extern int MESA_sendpacket_iplayer_options(int thread_index,const char *data, int data_len, u_int8_t dir, SAPP_TLV_T *options, int opt_num);
-#endif
-
-
-
-int Gserial_sendpacket_iplayer(int plug_id, struct streaminfo *stream,const char *buf, int buf_len, u_char dir)
-{
- int ret;
-
- if(plug_id <= 0 || plug_id >= GSERIAL_PLUGID_MAX)
- {
- sapp_runtime_log(30, "Gserial_sendpacket_iplayer(): Plug id error, must be [1,%d]!\n", GSERIAL_PLUGID_MAX);
- return -1;
- }
-
-#if IOMODE_MARSIO
- ret = MESA_sendpacket_iplayer_options(plug_id, buf, buf_len, dir, NULL, 0);
- return ret;
-#endif
-
- ret = MESA_sendpacket_iplayer(stream->threadnum, buf, buf_len, dir);
-
- Gserial_sendpacket_ip_info[stream->threadnum][plug_id]++;
-
- return ret;
-}
-
-int Gserial_sendpacket_ipv6_layer(int plug_id, struct streaminfo *stream,const char *buf, int buf_len, u_char dir)
-{
- int ret;
-
- if(plug_id <= 0 || plug_id >= GSERIAL_PLUGID_MAX)
- {
- printf("Plug id error, must be [1,%d]!\n", GSERIAL_PLUGID_MAX);
- return -1;
- }
-
-#if IOMODE_MARSIO
- ret = MESA_sendpacket_iplayer_options(plug_id, buf, buf_len, dir, NULL, 0);
- return ret;
-#endif
-
- ret = MESA_sendpacket_iplayer(stream->threadnum, buf, buf_len, dir);
-
- Gserial_sendpacket_ip_info[stream->threadnum][plug_id]++;
-
- return ret;
-}
-
-int Gserial_sendpacket_ipv4(int plug_id, struct streaminfo *stream,u_char ttl,u_char protocol,uint sip, uint dip,
- const char *payload,int payload_len,u_char dir)
-{
- int ret;
-
- if(plug_id <= 0 || plug_id >= GSERIAL_PLUGID_MAX)
- {
- printf("Plug id error, must be [1,%d]!\n", GSERIAL_PLUGID_MAX);
- return -1;
- }
-
-#if IOMODE_MARSIO
- SAPP_TLV_T opt;
- opt.type = SAPP_SEND_OPT_IP_TTL;
- opt.length = sizeof(char);
- opt.char_value = ttl;
- ret = MESA_fakepacket_send_ipv4_options(stream, protocol, sip, dip, payload, payload_len, dir, &opt, 1);
-#else
- ret = MESA_fakepacket_send_ipv4(stream->threadnum, ttl, protocol, sip, dip, payload, payload_len, dir);
-#endif
-
- Gserial_sendpacket_ip_info[stream->threadnum][plug_id]++;
-
- char sip_str[16], dip_str[16];
- uint sip_net = htonl(sip);
- uint dip_net = htonl(dip);
- inet_ntop(AF_INET, &sip_net, sip_str, 16);
- inet_ntop(AF_INET, &dip_net, dip_str, 16);
- sapp_runtime_log(20, "Gserial_sendpacket_ipv4: ret=%d, plugid:%d, %s->%s, protocol:%u, payload_len:%d\n",
- ret, plug_id, sip_str, dip_str, protocol, payload_len);
-
- return ret;
-}
-
-
-int Gserial_sendpacket_ipv4_detail(int plug_id,struct streaminfo *stream,u_char ttl,u_char protocol,uint sip, uint dip,
- u_short ipid, const char *payload,int payload_len,u_char dir)
-{
- int ret;
-
- if(plug_id <= 0 || plug_id >= GSERIAL_PLUGID_MAX)
- {
- printf("Plug id error, must be [1,%d]!\n", GSERIAL_PLUGID_MAX);
- return -1;
- }
-#if IOMODE_MARSIO
- SAPP_TLV_T opt[2];
- opt[0].type = SAPP_SEND_OPT_IP_TTL;
- opt[0].length = sizeof(char);
- opt[0].char_value = ttl;
- opt[1].type = SAPP_SEND_OPT_IP_ID;
- opt[1].length = sizeof(short);
- opt[1].short_value = (short)ipid;
- ret = MESA_fakepacket_send_ipv4_options(stream, protocol, sip, dip, payload, payload_len, dir, opt, 2);
-#else
- ret = MESA_fakepacket_send_ipv4_detail(stream->threadnum, ttl, protocol, sip, dip, ipid, payload, payload_len, dir);
-#endif
-
- Gserial_sendpacket_ip_info[stream->threadnum][plug_id]++;
-
- char sip_str[16], dip_str[16];
- uint sip_net = htonl(sip);
- uint dip_net = htonl(dip);
- inet_ntop(AF_INET, &sip_net, sip_str, 16);
- inet_ntop(AF_INET, &dip_net, dip_str, 16);
- sapp_runtime_log(20, "Gserial_sendpacket_ipv4_detail: ret=%d, plugid:%d, %s->%s, protocol:%u, ipid:0x%x, payload_len:%d\n",
- ret,plug_id,sip_str, dip_str, protocol, ipid, payload_len);
-
- return ret;
-}
-
-
-int Gserial_sendpacket_ipv6(int plug_id, struct streaminfo *stream,u_char ttl,u_char protocol,
- struct in6_addr *sip, struct in6_addr *dip,
- const char *payload,int payload_len,u_char dir)
-{
- int ret;
-
- if(plug_id <= 0 || plug_id >= GSERIAL_PLUGID_MAX)
- {
- printf("Plug id error, must be [1,%d]!\n", GSERIAL_PLUGID_MAX);
- return -1;
- }
-#if IOMODE_MARSIO
- SAPP_TLV_T opt[1];
- opt[0].type = SAPP_SEND_OPT_IP_TTL;
- opt[0].length = sizeof(char);
- opt[0].char_value = ttl;
- ret = MESA_fakepacket_send_ipv6_options(stream, protocol, sip, dip, payload, payload_len, dir, &opt[0], 1);
-#else
- ret = -1;
- assert(0);
-#endif
-
- Gserial_sendpacket_ipv6_info[stream->threadnum][plug_id]++;
-
- char sip_str[64], dip_str[64];
- inet_ntop(AF_INET6, sip, sip_str, 64);
- inet_ntop(AF_INET6, dip, dip_str, 64);
- sapp_runtime_log(20, "Gserial_sendpacket_ipv6: ret=%d, plugid:%d, %s->%s, protocol:%u, payload_len:%d\n",
- ret,plug_id,sip_str, dip_str, protocol, payload_len);
-
- return ret;
-}
-
-int Gserial_sendpacket_tcp(int plug_id,struct streaminfo *stream,u_int sip,u_int dip,u_short sport,
- u_short dport,u_int sseq,u_int sack,u_char control,
- const char* payload,int payload_len, u_char dir)
-{
- int ret;
-
- if(plug_id <= 0 || plug_id >= GSERIAL_PLUGID_MAX)
- {
- printf("Plug id error, must be [1,%d]!\n", GSERIAL_PLUGID_MAX);
- return -1;
- }
-
-#if IOMODE_MARSIO
- ret = MESA_fakepacket_send_tcp_options(stream, sip,dip,sport,dport,sseq,sack,control,payload, payload_len, dir, NULL, 0);
-#else
- ret = MESA_fakepacket_send_tcp(stream->threadnum, sip, dip, sport, dport, sseq, sack,
- control, payload, payload_len, dir);
-#endif
-
- Gserial_sendpacket_tcp_info[stream->threadnum][plug_id]++;
-
- char sip_str[16], dip_str[16];
- uint sip_net = htonl(sip);
- uint dip_net = htonl(dip);
- inet_ntop(AF_INET, &sip_net, sip_str, 16);
- inet_ntop(AF_INET, &dip_net, dip_str, 16);
- sapp_runtime_log(20, "Gserial_sendpacket_tcp: ret=%d, plugid:%d, %s:%u->%s:%u, seq:%u, ack:%u, payload_len:%d\n",
- ret, plug_id, sip_str, sport, dip_str, dport, sseq, sack, payload_len);
-
- return ret;
-}
-
-int Gserial_sendpacket_tcp_detail(int plug_id,struct streaminfo *stream, u_int sip,u_int dip, u_short ip_id,
- u_char ip_ttl, u_short sport, u_short dport,u_int sseq,
- u_int sack,u_char control, u_short tcp_win,
- const char* payload,int payload_len, u_char dir)
-{
- int ret;
-
- if(plug_id <= 0 || plug_id >= GSERIAL_PLUGID_MAX)
- {
- printf("Plug id error, must be [1,%d]!\n", GSERIAL_PLUGID_MAX);
- return -1;
- }
-
-#if IOMODE_MARSIO
- SAPP_TLV_T opt[3];
- opt[0].type = SAPP_SEND_OPT_IP_TTL;
- opt[0].length = sizeof(char);
- opt[0].char_value = ip_ttl;
- opt[1].type = SAPP_SEND_OPT_IP_ID;
- opt[1].length = sizeof(short);
- opt[1].short_value = (short)ip_id;
- opt[2].type = SAPP_SEND_OPT_TCP_WIN;
- opt[2].length = sizeof(short);
- opt[2].short_value = (short)tcp_win;
- ret = MESA_fakepacket_send_tcp_options(stream, sip,dip,sport,dport,sseq,sack,control,payload, payload_len, dir, opt,3);
-#else
- ret = MESA_fakepacket_send_tcp_detail(stream->threadnum, sip, dip, ip_id, ip_ttl, sport, dport, sseq, sack,
- control, tcp_win, payload, payload_len, dir);
-#endif
-
- Gserial_sendpacket_tcp_info[stream->threadnum][plug_id]++;
-
- char sip_str[16], dip_str[16];
- uint sip_net = htonl(sip);
- uint dip_net = htonl(dip);
- inet_ntop(AF_INET, &sip_net, sip_str, 16);
- inet_ntop(AF_INET, &dip_net, dip_str, 16);
- sapp_runtime_log(20, "Gserial_sendpacket_tcp_detail: ret=%d, plugid:%d, %s:%u->%s:%u, ipid:0x%x, seq:%u, ack:%u, payload_len:%d\n",
- ret, plug_id, sip_str, sport, dip_str, dport, ip_id, sseq, sack, payload_len);
-
- return ret;
-}
-
-
-int Gserial_sendpacket_ipv6_tcp_detail(int plug_id,struct streaminfo *stream,struct in6_addr *sip, struct in6_addr *dip,
- u_char ip_ttl, u_short sport, u_short dport,u_int sseq,
- u_int sack,u_char control, u_short tcp_win,
- const char* payload,int payload_len, u_char dir)
-{
- int ret;
-
- if(plug_id <= 0 || plug_id >= GSERIAL_PLUGID_MAX)
- {
- printf("Plug id error, must be [1,%d]!\n", GSERIAL_PLUGID_MAX);
- return -1;
- }
-
-#if IOMODE_MARSIO
- SAPP_TLV_T opt[2];
- opt[0].type = SAPP_SEND_OPT_IP_TTL;
- opt[0].length = sizeof(char);
- opt[0].char_value = ip_ttl;
- opt[1].type = SAPP_SEND_OPT_TCP_WIN;
- opt[1].length = sizeof(short);
- opt[1].short_value = (short)tcp_win;
- ret = MESA_fakepacket_send_ipv6_tcp_options(stream, sip,dip,sport,dport,sseq,sack,control,payload, payload_len, dir, opt,2);
-#else
- ret = -1;
- assert(0);
-#endif
-
- Gserial_sendpacket_tcp_info[stream->threadnum][plug_id]++;
-
- char sip_str[64], dip_str[64];
- inet_ntop(AF_INET6, sip, sip_str, 64);
- inet_ntop(AF_INET6, dip, dip_str, 64);
- sapp_runtime_log(20, "Gserial_sendpacket_tcp_detail: ret=%d, plugid:%d, %s.%u->%s.%u, seq:%u, ack:%u, payload_len:%d\n",
- ret, plug_id, sip_str, sport, dip_str, dport, sseq, sack, payload_len);
-
- return ret;
-}
-
-int Gserial_sendpacket_udp(int plug_id,struct streaminfo *stream, u_int sip, u_int dip, u_short sport,
- u_short dport, const char *payload, int payload_len,u_char dir)
-{
- int ret;
-
- if(plug_id <= 0 || plug_id >= GSERIAL_PLUGID_MAX)
- {
- printf("Plug id error, must be [1,%d]!\n", GSERIAL_PLUGID_MAX);
- return -1;
- }
-
-#if IOMODE_MARSIO
- ret = MESA_fakepacket_send_udp_options(stream, sip,dip,sport,dport, payload, payload_len, dir, NULL, 0);
-#else
- ret = MESA_fakepacket_send_udp(stream->threadnum, sip, dip, sport, dport, payload, payload_len, dir);
-#endif
-
- Gserial_sendpacket_udp_info[stream->threadnum][plug_id]++;
-
- char sip_str[16], dip_str[16];
- uint sip_net = htonl(sip);
- uint dip_net = htonl(dip);
- inet_ntop(AF_INET, &sip_net, sip_str, 16);
- inet_ntop(AF_INET, &dip_net, dip_str, 16);
- sapp_runtime_log(20, "Gserial_sendpacket_udp: ret=%d, plugid:%d, %s:%u->%s:%u, payload_len:%d\n",
- ret, plug_id, sip_str, sport, dip_str, dport, payload_len);
-
- return ret;
-}
-
-int Gserial_sendpacket_udp_detail(int plug_id,struct streaminfo *stream, u_int sip, u_int dip,
- u_short ip_id, u_char ip_ttl, u_short sport,
- u_short dport, const char *payload, int payload_len,u_char dir)
-{
- int ret;
-
- if(plug_id <= 0 || plug_id >= GSERIAL_PLUGID_MAX)
- {
- printf("Plug id error, must be [1,%d]!\n", GSERIAL_PLUGID_MAX);
- return -1;
- }
-
-#if IOMODE_MARSIO
- SAPP_TLV_T opt[2];
- opt[0].type = SAPP_SEND_OPT_IP_TTL;
- opt[0].length = sizeof(char);
- opt[0].char_value = ip_ttl;
- opt[1].type = SAPP_SEND_OPT_IP_ID;
- opt[1].length = sizeof(short);
- opt[1].short_value = (short)ip_id;
- ret = MESA_fakepacket_send_udp_options(stream, sip,dip,sport,dport, payload, payload_len, dir, opt, 2);
-#else
- ret = MESA_fakepacket_send_udp_detail(stream->threadnum, sip, dip, ip_id, ip_ttl, sport, dport, payload, payload_len, dir);
-#endif
-
- Gserial_sendpacket_udp_info[stream->threadnum][plug_id]++;
-
- char sip_str[16], dip_str[16];
- uint sip_net = htonl(sip);
- uint dip_net = htonl(dip);
- inet_ntop(AF_INET, &sip_net, sip_str, 16);
- inet_ntop(AF_INET, &dip_net, dip_str, 16);
- sapp_runtime_log(20, "Gserial_sendpacket_udp_detail: ret=%d, plugid:%d, %s:%u->%s:%u, ipid:0x%x, payload_len:%d\n",
- ret, plug_id, sip_str, sport, dip_str, dport, ip_id, payload_len);
-
- return ret;
-}
-
-int Gserial_sendpacket_ipv6_udp_detail(int plug_id,struct streaminfo *stream, struct in6_addr *sip, struct in6_addr *dip,
- u_char ip_ttl, u_short sport,
- u_short dport, const char *payload, int payload_len,u_char dir)
-{
- int ret;
-
- if(plug_id <= 0 || plug_id > GSERIAL_PLUGID_MAX-1)
- {
- printf("Plug id error, must be [1,%d]!\n", GSERIAL_PLUGID_MAX);
- return -1;
- }
-
-#if IOMODE_MARSIO
- SAPP_TLV_T opt[1];
- opt[0].type = SAPP_SEND_OPT_IP_TTL;
- opt[0].length = sizeof(char);
- opt[0].char_value = ip_ttl;
- ret = MESA_fakepacket_send_ipv6_udp_options(stream, sip,dip,sport,dport, payload, payload_len, dir, &opt[0], 1);
-#else
- ret = -1;
- assert(0);
-#endif
-
- Gserial_sendpacket_udp_info[stream->threadnum][plug_id]++;
-
- char sip_str[64], dip_str[64];
- inet_ntop(AF_INET6, sip, sip_str, 64);
- inet_ntop(AF_INET6, dip, dip_str, 64);
- sapp_runtime_log(20, "Gserial_sendpacket_udp_detail: ret=%d, plugid:%d, %s:%u->%s:%u, payload_len:%d\n",
- ret, plug_id, sip_str, sport, dip_str, dport, payload_len);
-
- return ret;
-}
-
-#if 0
-
-/*
- ������ͬʱ, ��tcpdump_mesaһ��, ���ڲ�������,
- ��ע�İ�����tcpdump_mesa����, ֱ���������ײ㲶�񼴿�.
-*/
-extern void cycle_pkt_dump(int thread_seq, const raw_pkt_t *p_raw_pkt);
-extern int G_PKT_DUMP_SW;
-int marsio_send_burst_with_options_for_tcpdumpmesa(struct mr_sendpath * sendpath, queue_id_t sid, marsio_buff_t * mbufs[],
- int nr_mbufs, uint16_t options)
-{
- raw_pkt_t rawpkt;
- char *rawpkt_data;
- uint32_t rawpkt_len;
-
- if(G_PKT_DUMP_SW != 0){
- rawpkt_data = marsio_buff_mtod(mbufs[0]);
- rawpkt_len = marsio_buff_buflen(mbufs[0]);
-
- rawpkt.magic_num = RAW_PKT_MAGIC_NUM;
- rawpkt.low_layer_type = ADDR_TYPE_MAC;
- rawpkt.raw_pkt_data = rawpkt_data;
- rawpkt.raw_pkt_len = rawpkt_len;
- rawpkt.__lib_raw_pkt_data = rawpkt_data;
- rawpkt.__lib_raw_pkt_len = rawpkt_len;
-
- cycle_pkt_dump(sid, &rawpkt);
- }
-
- return ptr_marsio_send_burst_with_options(sendpath, sid, mbufs, nr_mbufs, options);
-}
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
diff --git a/src/packet_io/sapp_inject.c b/src/packet_io/sapp_inject.c
index 7774d48..dd127f3 100644
--- a/src/packet_io/sapp_inject.c
+++ b/src/packet_io/sapp_inject.c
@@ -20,10 +20,6 @@ extern "C" {
*/
-extern int __sapp_inject_pkt(struct streaminfo *raw_stream, enum sapp_inject_opt sio,
- const void *payload, int payload_len, unsigned char snd_routedir, void *user_arg);
-
-
int sapp_inject_pkt(struct streaminfo *stream, enum sapp_inject_opt sio, const void *payload, int payload_len, unsigned char snd_routedir)
{
int ret;
@@ -37,9 +33,9 @@ int sapp_inject_pkt(struct streaminfo *stream, enum sapp_inject_opt sio, const v
int log_level;
const char *string_res;
/* injectʹ�õ���routedir, �˴�ת����stream dir,
- ע��: ��������Ķ������ܲ����ɵ�ǰ��������, ����kni, �Ǵ����������յ����ݰ�, ��ע����·��,
- ���ܴ�raw_pkt��raw_stream->routedir�жϷ���,
- Ҫ������������ʷ��¼���ж�route_dir��stream_dir�Ĺ�ϵ!!!!
+ ע��: ��������Ķ������ܲ����ɵ�ǰ��������, ����kni, �Ǵ����������յ����ݰ�, ��ע����·��,
+ ���ܴ�raw_pkt��raw_stream->routedir�жϷ���,
+ Ҫ������������ʷ��¼���ж�route_dir��stream_dir�Ĺ�ϵ!!!!
*/
if(stream_pr->stream_c2s_route_dir == snd_routedir){
send_stream_dir = DIR_C2S;
diff --git a/src/packet_io/sendpacket.c b/src/packet_io/sendpacket.c
index f666266..090b194 100644
--- a/src/packet_io/sendpacket.c
+++ b/src/packet_io/sendpacket.c
@@ -63,9 +63,6 @@ extern void *g_packet_dl_send_handle[MAX_THREAD_NUM];
extern dl_io_fun_list_t dl_io_fun_list;
extern int g_app_send_rst_type ;
extern int calc_l2tp_hdr_len_by_net_pkt(const struct l2tp_hdr_v2 *l2tp_hdr, size_t left_len);
-extern int packet_io_send_fake_pkt(MESA_send_handle *send_handle,int datalen,int send_type,
- int low_layer_type, int dir,int thread_num,
- char *feedback_buf, int *feedback_buf_len, const raw_pkt_t *raw_pkt);
static inline int dir_check(unsigned char raw_dir);
extern int set_mpls_addr(struct layer_addr_mpls *addr, const unsigned char *raw_mpls_pkt_data);
@@ -959,7 +956,6 @@ static int calc_reserved_hdr_len(struct streaminfo *stream, int *net_layer_type,
{
int reserved_hdr_len = 0;
struct streaminfo_private *stream_pr = (struct streaminfo_private *)stream;
- const raw_pkt_t *raw_pkt;
int pfather_hdr_len;
if(NULL == stream){ /* �ݹ�����ս�����! */
@@ -969,7 +965,6 @@ static int calc_reserved_hdr_len(struct streaminfo *stream, int *net_layer_type,
if(is_proxy_stream(stream)){ /* �������ṹΪ����ṹ, ʵ�ʹ����ʱ���������� */
return calc_reserved_hdr_len((struct streaminfo *)stream->pfather, net_layer_type, send_stream_dir);
}
- raw_pkt = (const raw_pkt_t *)stream_pr->raw_pkt;
switch(stream->addr.addrtype){
case ADDR_TYPE_IPV4:
@@ -1819,13 +1814,11 @@ static int build_net_layer_mpls(struct streaminfo_private *stream_pr, int carry_
static int build_net_layer_gtp(struct streaminfo_private *stream_pr, int carry_layer_type,
int carry_layer_len, unsigned char *buf, UCHAR send_stream_dir, const raw_pkt_t *raw_pkt)
{
- const struct gtp_hdr *raw_hdr;
struct gtp_hdr *gtp_send_hdr;
int gtp_net_layer_len = sizeof(struct gtp_hdr);
const struct layer_addr_gtp *p_gtp_layer_addr = stream_pr->stream_public.addr.gtp;
unsigned int this_pkt_teid;
- raw_hdr = (const struct gtp_hdr *)(stream_pr->offset_to_raw_pkt_hdr + (char *)raw_pkt->raw_pkt_data);
gtp_send_hdr = (struct gtp_hdr *)buf;
if(DIR_C2S == send_stream_dir){
@@ -2103,7 +2096,6 @@ static void sendpkt_dup_pkt_mark(const struct streaminfo *top_stream, unsigned c
void sendpkt_dup_pkt_mark_stream(const struct streaminfo *top_stream, const char *ip_hdr)
{
const struct mesa_ip4_hdr *ip4hdr;
- const struct mesa_ip6_hdr *ip6hdr;
const char *transport_layer_hdr;
if(ADDR_TYPE_IPV4 == top_stream->addr.addrtype){
@@ -2111,7 +2103,6 @@ void sendpkt_dup_pkt_mark_stream(const struct streaminfo *top_stream, const char
transport_layer_hdr = ip_hdr + ip4hdr->ip_hl * 4;
sendpkt_dup_pkt_mark(top_stream, ADDR_TYPE_IPV4, ip_hdr, transport_layer_hdr);
}else{
- ip6hdr = (struct mesa_ip6_hdr *)ip_hdr;
transport_layer_hdr = ip_hdr + sizeof(struct mesa_ip6_hdr);
sendpkt_dup_pkt_mark(top_stream, ADDR_TYPE_IPV6, ip_hdr, transport_layer_hdr);
}
@@ -2498,159 +2489,6 @@ static raw_pkt_t *update_raw_pkt(struct streaminfo_private *stream_pr, uchar snd
return inject_raw_pkt;
}
-static int __do_kill_tcp(struct streaminfo *stream, const void *ext_raw_pkt, int kill_num,
- char *feedback_buf, int *feedback_buf_len)
-{
- int i, ret = -1, reserved_hdr_len, send_len = 0;
- MESA_send_handle *send_handle;
- int thread_num;
- int low_net_layer_type = -1;
- tcp_rst_finger_mark_t *tcp_rst_finger;
- const raw_pkt_t *raw_pkt = NULL;
- struct streaminfo_private *stream_pr;
- sapp_gval_mthread_sys_stat_t *local_sys_stat;
-
- (void)ext_raw_pkt;
-
- if(NULL == stream){
- return -1;
- }
- thread_num = stream->threadnum;
- stream_pr = (struct streaminfo_private *)stream;
- send_handle = &g_send_handle[thread_num];
- /* ��ı���ijЩ�ص�������ԭʼ������ΪIP��ͷ(����֮ǰpappƽ̨), ���Բ���Ҫ�������ԭʼ��, ��Ϣ���洢��˽�����ṹ���� */
- raw_pkt = (const raw_pkt_t *)stream_pr->raw_pkt;
- if((NULL == raw_pkt) || (RAW_PKT_MAGIC_NUM != raw_pkt->magic_num)){
- return -1;
- }
- local_sys_stat = &sapp_global_val->mthread_volatile[thread_num]->sys_stat;
- send_handle->user_arg = (void *)stream;
-
- tcp_rst_finger = make_tcp_rst_finger_mark(thread_num, (const raw_pkt_t *)raw_pkt);
- set_build_layer_ipv4_args(thread_num, tcp_rst_finger->ip_ttl, tcp_rst_finger->ip_id_host_order);
-
- if(0 == ABBR_INJECT_RST_SIGN){
- set_build_layer_tcp_args(thread_num, TH_RST, tcp_rst_finger->tcp_win_host_order, 0);
- }else{
- set_build_layer_tcp_args(thread_num, TH_RST|TH_ACK, tcp_rst_finger->tcp_win_host_order, 0);
- }
-
- for(i = 0; i < kill_num; i++){
- /* ��MPLS�ǶԳ�����, calc_reserved_hdr_len()��Ҫ�ֲ�ͬ�������, �뵱ǰ��ͬ�򷢰� */
- reserved_hdr_len = calc_reserved_hdr_len(stream, &low_net_layer_type, stream_pr->stream_public.curdir);
- if((reserved_hdr_len < 0) || (-1 == low_net_layer_type)){
- sapp_global_val->mthread_volatile[thread_num]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- sapp_runtime_log(RLOG_LV_INFO, "__do_kill_tcp() calc_reserved_hdr_len error !");
- ret = -1;
- goto fun_exit;
- }
- low_net_layer_type = get_eth_carry_layer_type(stream, stream_pr->stream_public.curdir);
- if(low_net_layer_type < 0){
- sapp_global_val->mthread_volatile[thread_num]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- sapp_runtime_log(RLOG_LV_INFO, "__do_kill_tcp(): can't get ethernet carry layer type");
- ret = -1;
- goto fun_exit;
- }
- if(sapp_global_val->config.packet_io.inject_pkt_mode == SEND_PKT_MODE_GDEV){ /* gdevע��ģʽʱԤ���ײ��װvxlan���Ŀռ�, �����ٶ���copy */
- reserved_hdr_len += sizeof(inline_vxlan_hdr_t);
- }
-
- send_handle->send_buf = packet_io_get_sendbuf(SEND_TYPE_LINK_INJECT, thread_num);
-
- sapp_runtime_log(RLOG_LV_DEBUG, "before build_net_layer_pkt(), buf addr:%p, streamdir:%d, total layer len:%d", send_handle->send_buf, stream->curdir, reserved_hdr_len);
- send_len = build_net_layer_pkt(stream, stream, stream_pr, ADDR_TYPE_TCP, 0, send_handle->send_buf + reserved_hdr_len, 0, raw_pkt, stream->curdir);
- if(send_len > 0){
- /* �޸Ĵ����ж��߼�, ����ʧ�ܲ��˳�, �������Է�������� */
- ret = packet_io_send(send_handle, reserved_hdr_len, SEND_TYPE_LINK_INJECT,
- low_net_layer_type, stream_pr->stream_public.routedir, thread_num,
- feedback_buf, feedback_buf_len, stream_pr->raw_pkt);
- if(ret < 0){
- send_handle->tot_send_err++;
- }else{
- send_handle->tot_send_pkt++;
- send_handle->tot_send_byte += send_len;
- }
-
- packet_io_free_sendbuf(SEND_TYPE_LINK_INJECT, thread_num);
- local_sys_stat->count[SAPP_STAT_SND_TCP_RST]++;
-
- sapp_runtime_log(RLOG_LV_DEBUG, "do_kill_tcp() succ, stream:%s, streamdir:%d, routedir:%d, send_len=%d\n",
- printaddr(&stream->addr, thread_num),
- stream_pr->stream_public.curdir,
- stream_pr->stream_public.routedir, send_len);
- }else{
- sapp_global_val->mthread_volatile[thread_num]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- sapp_runtime_log(RLOG_LV_INFO, "do_kill_tcp()-->build_net_layer_pkt() error, send streamdir:%d, routedir:%d, send_len=%d\n",
- stream_pr->stream_public.curdir ^ DIR_DOUBLE,
- stream_pr->stream_public.routedir, send_len);
- }
-
- /******************************************
- ����ģʽ��, �����������һ��, �ܼ�����,
- �������ȷ�C2S���Ρ��ٷ�S2C����,
- ��ֹ��RST����ʱ����, ��һ���ٳ�û�а�;
- ******************************************/
- /* ��MPLS�ǶԳ�����, calc_reserved_hdr_len()��Ҫ�ֲ�ͬ�������, �뵱ǰ�����򷢰� */
- reserved_hdr_len = calc_reserved_hdr_len(stream, &low_net_layer_type, stream_pr->stream_public.curdir ^ DIR_DOUBLE);
- if((reserved_hdr_len < 0) || (-1 == low_net_layer_type)){
- sapp_runtime_log(RLOG_LV_INFO, "MESA_kill_tcp() calc_reserved_hdr_len error !");
- ret = -1;
- goto fun_exit;
- }
- if(sapp_global_val->config.packet_io.inject_pkt_mode == SEND_PKT_MODE_GDEV){ /* gdevע��ģʽʱԤ���ײ��װvxlan���Ŀռ�, �����ٶ���copy */
- reserved_hdr_len += sizeof(inline_vxlan_hdr_t);
- }
- low_net_layer_type = get_eth_carry_layer_type(stream, stream_pr->stream_public.curdir ^ DIR_DOUBLE);
- if(low_net_layer_type < 0){
- sapp_runtime_log(RLOG_LV_FATAL, "__do_kill_tcp(): can't get ethernet carry layer type");
- ret = -1;
- goto fun_exit;
- }
-
- send_handle->send_buf = packet_io_get_sendbuf(SEND_TYPE_LINK_INJECT, thread_num);
- sapp_runtime_log(10, "before build_net_layer_pkt(), buf addr:%p, streamdir:%d, total layer len:%d", send_handle->send_buf, stream->curdir ^ DIR_DOUBLE, reserved_hdr_len);
- send_len = build_net_layer_pkt(stream, stream, stream_pr, ADDR_TYPE_TCP, 0, send_handle->send_buf + reserved_hdr_len, 1, raw_pkt, stream->curdir ^ DIR_DOUBLE);
- if(send_len > 0){
- /* �޸Ĵ����ж��߼�, ����ʧ�ܲ��˳�, �������Է�������� */
- ret = packet_io_send(send_handle, reserved_hdr_len, SEND_TYPE_LINK_INJECT,
- low_net_layer_type, stream_pr->stream_public.routedir ^ 1, thread_num,
- feedback_buf, feedback_buf_len, stream_pr->raw_pkt);
- if(ret < 0){
- send_handle->tot_send_err++;
- }else{
- send_handle->tot_send_pkt++;
- send_handle->tot_send_byte += send_len;
- }
- packet_io_free_sendbuf(SEND_TYPE_LINK_INJECT, thread_num);
- local_sys_stat->count[SAPP_STAT_SND_TCP_RST]++;
-
- sapp_runtime_log(RLOG_LV_DEBUG, "do_kill_tcp() succ, stream:%s, streamdir:%d, routedir:%d, send_len=%d\n",
- printaddr(&stream->addr, thread_num),
- stream_pr->stream_public.curdir ^ DIR_DOUBLE,
- stream_pr->stream_public.routedir ^ 1, send_len);
- }else{
- sapp_runtime_log(RLOG_LV_INFO, "do_kill_tcp()-->build_net_layer_pkt() error, send streamdir:%d, routedir:%d, send_len=%d\n",
- stream_pr->stream_public.curdir ^ DIR_DOUBLE,
- stream_pr->stream_public.routedir ^ 1, send_len);
- }
- }
-
-fun_exit:
-
- detach_build_layer_ipv4_args(thread_num);
- detach_build_layer_tcp_args(thread_num);
-
- stream_pr->stream_killed_flag = 1;
-
- /* �����µı�־λ, kill_tcp�Զ�����, ���ֹ��ܸ�֮ǰһ�� */
- struct tcpdetail_private *pdetail_pr=(struct tcpdetail_private*)(stream->pdetail);
- pdetail_pr->auto_remedy_flag = sapp_global_val->config.stream.tcp.inject.auto_remedy;
- pdetail_pr->drop_stream_flag = 1;
-
- return ret;
-}
-
-
/*
LiJia note, to do:
@@ -2661,18 +2499,7 @@ fun_exit:
ʵ�ʵ�seq��ackʹ�õ��ǵ�5������!
Ӧ��ʹ��buf_unorder�е�seq��ack, �����ǵ�ǰ����ԭʼ��.
*/
-#if 0
-int MESA_kill_tcp(struct streaminfo *stream, const void *ext_raw_pkt)
-{
- if(STREAM_TYPE_TCP != stream->type){
- sapp_runtime_log(RLOG_LV_INFO, "MESA_kill_tcp error: stream type is not tcp!\n");
- return -1;
- }
- /* �ⲿ����, ��һ��FD, ����KILL_TCP_RST_NUM��. */
- return __do_kill_tcp(stream, ext_raw_pkt, ABBR_INJECT_RST_NUM, (char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER);
-}
-#else //2020-10-05 lijia modify
int MESA_kill_tcp(struct streaminfo *stream, const void *ext_raw_pkt)
{
int ret1,ret2;
@@ -2709,221 +2536,8 @@ int MESA_kill_tcp(struct streaminfo *stream, const void *ext_raw_pkt)
return 0;
}
-#endif
-
-int MESA_kill_tcp_feedback(struct streaminfo *stream, const void *raw_pkt, char *feedback_buf, int *feedback_buf_len)
-{
- if(STREAM_TYPE_TCP != stream->type){
- sapp_runtime_log(RLOG_LV_INFO, "MESA_kill_tcp error: stream type is not tcp!\n");
- return -1;
- }
-
- if((NULL == feedback_buf) || (NULL == feedback_buf_len)){
- return -2;
- }
- if(*feedback_buf_len <= 0){
- return -2;
- }
- return __do_kill_tcp(stream, raw_pkt, ABBR_INJECT_RST_NUM, feedback_buf, feedback_buf_len);
-}
-
-/* 2016-06-15 lijia add */
-int MESA_kill_tcp_remedy(struct streaminfo *stream, const void *ext_raw_pkt)
-{
- struct streaminfo_private *stream_pr = (struct streaminfo_private *)stream;
- int last_send_time = g_CurrentTime % 255;
-
- if((sapp_global_val->config.stream.tcp.inject.remedy_kill_tcp_by_inline_device != 0 )
- && (stream_pr->gdev_block_timer < last_send_time)){
- /* ��ֹFD����ЧƵ������c3�ӿ�, ����һ����, ÿ��1�����һ��C3 */
- stream_pr->gdev_block_timer = last_send_time;
- gdev_block_send_rule(stream);
- }
-
- /* FD����, RST�̶�ֻ����1��. */
- return __do_kill_tcp(stream, ext_raw_pkt, 1, (char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER);
-}
-
-static int __do_kill_tcp_synack(struct streaminfo *stream, const void *ext_raw_pkt,
- char *feedback_buf, int *feedback_buf_len)
-{
- int i, ret, reserved_hdr_len, send_len = 0;
- MESA_send_handle *send_handle;
- int thread_num;
- int low_net_layer_type;
- tcp_rst_finger_mark_t *tcp_rst_finger;
- const raw_pkt_t *raw_pkt = NULL;
- struct streaminfo_private *stream_pr;
- sapp_gval_mthread_sys_stat_t *local_sys_stat;
-
- (void)ext_raw_pkt;
-
- if(NULL == stream){
- return -1;
- }
- thread_num = stream->threadnum;
- stream_pr = (struct streaminfo_private *)stream;
- send_handle = &g_send_handle[thread_num];
- raw_pkt = (const raw_pkt_t *)stream_pr->raw_pkt;
- if((NULL == raw_pkt) || (RAW_PKT_MAGIC_NUM != raw_pkt->magic_num)){
- return -1;
- }
- local_sys_stat = &sapp_global_val->mthread_volatile[thread_num]->sys_stat;
- //send_handle->user_arg = (void *)stream;
- reserved_hdr_len = calc_reserved_hdr_len(stream, &low_net_layer_type, stream_pr->stream_c2s_route_dir ^ 1);
- if((reserved_hdr_len < 0) || (-1 == low_net_layer_type)){
- ret = -1;
- goto fun_exit;
- }
- tcp_rst_finger = make_tcp_rst_finger_mark(thread_num, (const raw_pkt_t *)raw_pkt);
- set_build_layer_ipv4_args(thread_num, tcp_rst_finger->ip_ttl, tcp_rst_finger->ip_id_host_order);
- set_build_layer_tcp_args(thread_num, TH_SYN|TH_ACK, tcp_rst_finger->tcp_win_host_order, MESA_rand());
-
- for(i = 0; i < KILL_TCP_SYN_ACK_NUM; i++){
- send_handle->send_buf = packet_io_get_sendbuf(SEND_TYPE_LINK_INJECT, thread_num);
-
- send_len = build_net_layer_pkt(stream, stream, stream_pr, ADDR_TYPE_TCP, 0, send_handle->send_buf + reserved_hdr_len, 1, raw_pkt, stream->curdir ^ DIR_DOUBLE);
- if(send_len < 0){
- ret = -1;
- goto fun_exit;
- }
- send_handle->user_arg = (void *)stream;
- ret = packet_io_send(send_handle, reserved_hdr_len, SEND_TYPE_LINK_INJECT,
- low_net_layer_type, stream->routedir ^ 1, thread_num,
- feedback_buf, feedback_buf_len, stream_pr->raw_pkt);
- if(ret < 0){
- send_handle->tot_send_err++;
- }else{
- send_handle->tot_send_pkt++;
- send_handle->tot_send_byte += send_len;
- }
-
- packet_io_free_sendbuf(SEND_TYPE_LINK_INJECT, thread_num);
- local_sys_stat->count[SAPP_STAT_SND_TCP_SYNACK]++;
- }
-fun_exit:
- detach_build_layer_ipv4_args(thread_num);
- detach_build_layer_tcp_args(thread_num);
-
- stream_pr->stream_killed_flag = 1;
-
- return ret;
-}
-
-int MESA_kill_tcp_synack(struct streaminfo *stream, const void *ext_raw_pkt)
-{
- return __do_kill_tcp_synack(stream, ext_raw_pkt, (char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER);
-}
-
-int MESA_kill_tcp_synack_feedback(struct streaminfo *stream, const void *ext_raw_pkt,
- char *feedback_buf, int *feedback_buf_len)
-{
- if((NULL == feedback_buf) || (NULL == feedback_buf_len)){
- return -2;
- }
- if(*feedback_buf_len <= 0){
- return -2;
- }
-
- return __do_kill_tcp_synack(stream, ext_raw_pkt, feedback_buf, feedback_buf_len);
-}
-
-
-/* 2014-11-15 lijia add, for drop NO-TCP protocol in serial mode.
- return value:
- >= 0: success.
- -1 : error.
-*/
-int MESA_kill_connection(struct streaminfo *stream, const void *ext_raw_pkt)
-{
- int ret;
- struct streaminfo_private *stream_pr;
-
- (void)ext_raw_pkt;
-
- if(NULL == stream){
- return -1;
- }
- stream_pr = (struct streaminfo_private *)stream;
-
- switch(stream->type){
- case STREAM_TYPE_TCP:
- //ret = MESA_kill_tcp(stream, ext_raw_pkt);
- /* ��ı���ijЩ�ص�������ԭʼ������ΪIP��ͷ, ���Բ���Ҫ�������ԭʼ��, ��Ϣ���洢��˽�����ṹ���� */
- ret = MESA_kill_tcp(stream, stream_pr->raw_pkt);
- break;
- case STREAM_TYPE_UDP:
- stream_pr->stream_killed_flag = 1;
- ret = 0;
- break;
-
- case STREAM_TYPE_SOCKS4:
- case STREAM_TYPE_SOCKS5:
- case STREAM_TYPE_HTTP_PROXY:
- case STREAM_TYPE_PPPOE:
- sapp_runtime_log(30, "stream type: %d, not support kill_connection!\n", stream->type);
- return -1;
- //assert(0);
- break;
-
- default:
- ret = -1;
- break;
- }
-
- return ret;
-}
-
-int MESA_kill_connection_feedback(struct streaminfo *stream, const void *ext_raw_pkt,
- char *feedback_buf, int *feedback_buf_len)
-{
- int ret;
- struct streaminfo_private *stream_pr;
-
- (void)ext_raw_pkt;
-
- if((NULL == feedback_buf) || (NULL == feedback_buf_len)){
- return -2;
- }
- if(*feedback_buf_len <= 0){
- return -2;
- }
-
- if(NULL == stream){
- return -1;
- }
- stream_pr = (struct streaminfo_private *)stream;
-
- switch(stream->type){
- case STREAM_TYPE_TCP:
- //ret = MESA_kill_tcp(stream, ext_raw_pkt);
- /* ��ı���ijЩ�ص�������ԭʼ������ΪIP��ͷ, ���Բ���Ҫ�������ԭʼ��, ��Ϣ���洢��˽�����ṹ���� */
- ret = MESA_kill_tcp_feedback(stream, stream_pr->raw_pkt, feedback_buf, feedback_buf_len);
- break;
- case STREAM_TYPE_UDP:
- stream_pr->stream_killed_flag = 1;
- ret = 0;
- break;
-
- case STREAM_TYPE_SOCKS4:
- case STREAM_TYPE_SOCKS5:
- case STREAM_TYPE_HTTP_PROXY:
- case STREAM_TYPE_PPPOE:
- sapp_runtime_log(30, "stream type: %d, not support kill_connection!\n", stream->type);
- return -1;
- //assert(0);
- break;
-
- default:
- ret = -1;
- break;
- }
-
- return ret;
-}
-
static int build_tcp_rst_pkt_finger(struct streaminfo *stream,
- unsigned short signature_seed1, unsigned short signature_seed2, tcp_rst_finger_mark_t *rst_finger)
+ unsigned short signature_seed1, unsigned short signature_seed2, tcp_rst_finger_mark_t *rst_finger)
{
const raw_pkt_t *raw_pkt;
struct streaminfo_private *stream_pr;
@@ -2933,34 +2547,41 @@ static int build_tcp_rst_pkt_finger(struct streaminfo *stream,
raw_pkt = (const raw_pkt_t *)stream_pr->raw_pkt;
ip4_hdr = (const struct mesa_ip4_hdr *)((char *)raw_pkt->raw_pkt_data + stream_pr->offset_to_raw_pkt_hdr);
-
- if(ADDR_TYPE_IPV4 == stream->addr.addrtype){
- if(signature_seed1 && signature_seed2){
- trick_algo_getrandval_with_seed(stream->threadnum,
- ip4_hdr->ip_src.s_addr,
- ip4_hdr->ip_dst.s_addr,
- &rst_finger->ip_id_host_order,
- &rst_finger->tcp_win_host_order,
- &rst_finger->ip_ttl,
- (int)signature_seed2,
- (int)signature_seed1);
-
- }else{
- if(sapp_global_val->config.stream.tcp.inject.rst_signature_enable != 0){
- trick_algo_getrandval_with_seed(stream->threadnum,
- ip4_hdr->ip_src.s_addr,
- ip4_hdr->ip_dst.s_addr,
- &rst_finger->ip_id_host_order,
- &rst_finger->tcp_win_host_order,
- &rst_finger->ip_ttl,
- (int)sapp_global_val->config.stream.tcp.inject.rst_signature_seed2,
- (int)sapp_global_val->config.stream.tcp.inject.rst_signature_seed1);
- }else{
+ if (ADDR_TYPE_IPV4 == stream->addr.addrtype)
+ {
+ if (signature_seed1 && signature_seed2)
+ {
+ trick_algo_getrandval_with_seed(stream->threadnum,
+ ip4_hdr->ip_src.s_addr,
+ ip4_hdr->ip_dst.s_addr,
+ &rst_finger->ip_id_host_order,
+ &rst_finger->tcp_win_host_order,
+ &rst_finger->ip_ttl,
+ (int)signature_seed2,
+ (int)signature_seed1);
+ }
+ else
+ {
+ if (sapp_global_val->config.stream.tcp.inject.rst_signature_enable != 0)
+ {
+ trick_algo_getrandval_with_seed(stream->threadnum,
+ ip4_hdr->ip_src.s_addr,
+ ip4_hdr->ip_dst.s_addr,
+ &rst_finger->ip_id_host_order,
+ &rst_finger->tcp_win_host_order,
+ &rst_finger->ip_ttl,
+ (int)sapp_global_val->config.stream.tcp.inject.rst_signature_seed2,
+ (int)sapp_global_val->config.stream.tcp.inject.rst_signature_seed1);
+ }
+ else
+ {
goto use_rand_value;
}
}
- }else{
+ }
+ else
+ {
goto use_rand_value;
}
@@ -2978,7 +2599,7 @@ use_rand_value:
int __MESA_rst_tcp(struct streaminfo *stream, unsigned char rst_th_flags, int rst_pkt_num, unsigned char snd_rst_dir,
unsigned short signature_seed1, unsigned short signature_seed2)
{
- int i, ret = -1, send_len = 0;
+ int i, ret = -1;
const raw_pkt_t *raw_pkt;
int threadnum = stream->threadnum;
struct streaminfo_private *stream_pr;
@@ -3081,27 +2702,28 @@ int MESA_rst_tcp(struct streaminfo *stream, struct rst_tcp_para *paras, int stru
return -1;
}
- if(struct_para_len > sizeof(struct rst_tcp_para)){
+ if(struct_para_len > (int)sizeof(struct rst_tcp_para)){
sapp_runtime_log(RLOG_LV_INFO, "MESA_rst_tcp() warning: the caller version is newer than sapp, not support new paras!\n");
}
-
- if((0 == paras->signature_seed1) && (0 == paras->signature_seed2)){
- if(0 == sapp_global_val->config.stream.tcp.inject.rst_signature_enable){
- tmp_signature_seed1 = 0;
- tmp_signature_seed2 = 0;
- }else{
+ tmp_signature_seed1 = paras->signature_seed1;
+ tmp_signature_seed2 = paras->signature_seed2;
+ if((0 == tmp_signature_seed1) && (0 == tmp_signature_seed2)){
+ if(0 != sapp_global_val->config.stream.tcp.inject.rst_signature_enable){
tmp_signature_seed1 = sapp_global_val->config.stream.tcp.inject.rst_signature_seed1;
tmp_signature_seed2 = sapp_global_val->config.stream.tcp.inject.rst_signature_seed2;
}
- }else{
- tmp_signature_seed1 = paras->signature_seed1;
- tmp_signature_seed2 = paras->signature_seed2;
}
-
return __MESA_rst_tcp((struct streaminfo *)stream, paras->th_flags, paras->rst_pkt_num, paras->dir,
- tmp_signature_seed1, tmp_signature_seed2);
+ tmp_signature_seed1, tmp_signature_seed2);
}
+/* 2016-06-15 lijia add */
+inline int MESA_kill_tcp_remedy(struct streaminfo *stream, const void *ext_raw_pkt)
+{
+ return __MESA_rst_tcp(stream, (unsigned char)(TH_RST | TH_ACK), 1, (unsigned char)(stream->curdir ^ DIR_DOUBLE),
+ (unsigned short )sapp_global_val->config.stream.tcp.inject.rst_signature_seed1,
+ (unsigned short )sapp_global_val->config.stream.tcp.inject.rst_signature_seed2);
+}
int __do_inject_pkt(struct streaminfo *stream, const char *payload, int payload_len,
@@ -3210,37 +2832,12 @@ fun_exit:
return ret;
}
-#if 0
-int MESA_inject_pkt(struct streaminfo *stream, const char *payload, int payload_len,
- const void *ext_raw_pkt, UCHAR snd_routedir)
-{
- return __do_inject_pkt(stream, payload, payload_len, ext_raw_pkt, snd_routedir,
- (char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER);
-}
-#else //2020-10-05 lijia modify
-int MESA_inject_pkt(struct streaminfo *stream, const char *payload, int payload_len,
+inline int MESA_inject_pkt(struct streaminfo *stream, const char *payload, int payload_len,
const void *ext_raw_pkt, UCHAR snd_routedir)
{
return sapp_inject_pkt(stream, SIO_DEFAULT, payload, payload_len, snd_routedir);
}
-#endif
-
-int MESA_inject_pkt_feedback(struct streaminfo *stream, const char *payload, int payload_len,
- const void *ext_raw_pkt, UCHAR snd_routedir,
- char *feedback_buf, int *feedback_buf_len)
-{
- if((NULL == feedback_buf) || (NULL == feedback_buf_len)){
- return -2;
- }
- if(*feedback_buf_len <= 0){
- return -2;
- }
-
- return __do_inject_pkt(stream, payload, payload_len, ext_raw_pkt, snd_routedir,
- feedback_buf, feedback_buf_len);
-}
-
/*
TODO:
@@ -3830,7 +3427,7 @@ static int __MESA_sendpacket_iplayer(int thread_index,const char *data, int dat
memcpy(send_handle->send_buf + offset, data, data_len);
- ret = packet_io_send_fake_pkt(send_handle, data_len+sizeof(struct mesa_ethernet_hdr), SEND_TYPE_LINK_INJECT,
+ ret = packet_io_send(send_handle, data_len+sizeof(struct mesa_ethernet_hdr), SEND_TYPE_LINK_INJECT,
layer_type, dir, thread_index,
(char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER, NULL);
@@ -3891,7 +3488,7 @@ int MESA_fakepacket_send_ipv4(int thread_index,u_int8_t ttl,
sendpacket_do_checksum(send_handle->send_buf+offset, IPPROTO_IP, SENDPACKET_IP_H);
- ret = packet_io_send_fake_pkt(send_handle, payload_len+sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr),
+ ret = packet_io_send(send_handle, payload_len+sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr),
SEND_TYPE_LINK_INJECT, __ADDR_TYPE_IP_PAIR_V4, dir, thread_index,
(char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER, NULL);
@@ -3939,7 +3536,7 @@ int MESA_fakepacket_send_ipv4_detail(int thread_index,u_int8_t ttl,
sendpacket_do_checksum(send_handle->send_buf+offset, IPPROTO_IP, SENDPACKET_IP_H);
- ret = packet_io_send_fake_pkt(send_handle, payload_len+sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr),
+ ret = packet_io_send(send_handle, payload_len+sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr),
SEND_TYPE_LINK_INJECT, __ADDR_TYPE_IP_PAIR_V4, dir, thread_index,
(char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER, NULL);
@@ -3998,7 +3595,7 @@ int MESA_fakepacket_send_tcp(int thread_index,u_int sip_host_order,u_int dip_hos
sendpacket_do_checksum(send_handle->send_buf+offset, IPPROTO_IP, SENDPACKET_IP_H);
- ret = packet_io_send_fake_pkt(send_handle, payload_len+sizeof(struct mesa_tcp_hdr)+sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr),
+ ret = packet_io_send(send_handle, payload_len+sizeof(struct mesa_tcp_hdr)+sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr),
SEND_TYPE_LINK_INJECT, __ADDR_TYPE_IP_PAIR_V4, dir, thread_index,
(char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER, NULL);
@@ -4054,7 +3651,7 @@ int MESA_fakepacket_send_tcp_detail(int thread_index,u_int sip_host_order,u_int
sendpacket_do_checksum(send_handle->send_buf+offset, IPPROTO_IP, SENDPACKET_IP_H);
- ret = packet_io_send_fake_pkt(send_handle, payload_len+sizeof(struct mesa_tcp_hdr)+sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr),
+ ret = packet_io_send(send_handle, payload_len+sizeof(struct mesa_tcp_hdr)+sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr),
SEND_TYPE_LINK_INJECT, __ADDR_TYPE_IP_PAIR_V4, dir, thread_index,
(char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER, NULL);
@@ -4109,7 +3706,7 @@ int MESA_fakepacket_send_udp(int thread_index, u_int sip_host_order, u_int dip_h
sendpacket_do_checksum(send_handle->send_buf+offset, IPPROTO_IP, SENDPACKET_IP_H);
- ret = packet_io_send_fake_pkt(send_handle, payload_len+sizeof(struct mesa_udp_hdr)+sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr),
+ ret = packet_io_send(send_handle, payload_len+sizeof(struct mesa_udp_hdr)+sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr),
SEND_TYPE_LINK_INJECT, __ADDR_TYPE_IP_PAIR_V4, dir, thread_index,
(char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER, NULL);
@@ -4163,7 +3760,7 @@ int MESA_fakepacket_send_udp_detail(int thread_index, u_int sip_host_order, u_in
sendpacket_do_checksum(send_handle->send_buf+offset, IPPROTO_IP, SENDPACKET_IP_H);
- ret = packet_io_send_fake_pkt(send_handle, payload_len+sizeof(struct mesa_udp_hdr)+sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr),
+ ret = packet_io_send(send_handle, payload_len+sizeof(struct mesa_udp_hdr)+sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr),
SEND_TYPE_LINK_INJECT, __ADDR_TYPE_IP_PAIR_V4, dir, thread_index,
(char *)KILL_TCP_PHONY_POINTER, (int *)KILL_TCP_PHONY_POINTER, NULL);
@@ -4177,725 +3774,6 @@ int MESA_fakepacket_send_udp_detail(int thread_index, u_int sip_host_order, u_in
return ret;
}
-#if IOMODE_MARSIO
-
-static struct mr_instance *dl_io_marsio4_instance = NULL;
-extern struct mr_instance *sapp_marsio4_instance;
-extern int marsio_send_burst_with_options_for_tcpdumpmesa(struct mr_sendpath * sendpath, queue_id_t sid, marsio_buff_t * mbufs[], int nr_mbufs, uint16_t options);
-extern int (*ptr_marsio_buff_malloc_global)(struct mr_instance * instance, marsio_buff_t *marsio_buff[], unsigned int nr_mbufs, int socket_id, int thread_id);
-extern char * (*ptr_marsio_buff_append)(marsio_buff_t *m, uint16_t len);
-extern void (*ptr_marsio_buff_ctrlzone_set)(marsio_buff_t *m, uint8_t id, void* ptr_data, uint8_t size);
-extern int (*ptr_marsio_send_burst)(struct mr_sendpath * sendpath, queue_id_t qid, marsio_buff_t * mbufs[], int nr_mbufs);
-extern marsio_buff_t * (*ptr_marsio_buff_clone_with_options)(struct mr_instance * instance, marsio_buff_t * md, int socket_id, int thread_id, uint16_t options);
-extern void (*ptr_marsio_buff_set_rehash_index)(marsio_buff_t *m, uint32_t hash);
-extern void (*ptr_marsio_buff_free)(struct mr_instance * instance, marsio_buff_t *marsio_buff[],unsigned int nr_mbufs, int socket_id, int thread_id);
-struct mr_instance *sapp_get_marsio_instance(void)
-{
- dl_io_marsio4_instance = sapp_marsio4_instance;
- return dl_io_marsio4_instance;
-}
-
-
-static void sapp_fakepacket_set_vxlan_options(struct mr_tunnat_ctrlzone *mr_ctrlzone, SAPP_TLV_T *option)
-{
- switch(option->type){
- case SAPP_SEND_OPT_GDEV_DMAC:
- memcpy(mr_ctrlzone->g_device_mac, option->array_value, 6);
- break;
-
- case SAPP_SEND_OPT_GDEV_SMAC:
- memcpy(mr_ctrlzone->l_device_mac, option->array_value, 6);
- break;
-
- case SAPP_SEND_OPT_GDEV_DIP:
- mr_ctrlzone->g_device_in_addr = option->int_value;
- break;
-
- case SAPP_SEND_OPT_GDEV_SIP:
- mr_ctrlzone->l_device_in_addr = option->int_value;
- break;
-
- case SAPP_SEND_OPT_GDEV_UDP_DPORT:
- /* default 4789, do nothing */
- break;
-
- case SAPP_SEND_OPT_GDEV_UDP_SPORT:
- mr_ctrlzone->l4_src_port = option->short_value;
- break;
-
- case SAPP_SEND_OPT_VXLAN_VPN_ID:
- mr_ctrlzone->g_device_vpn_id = option->int_value;
- mr_ctrlzone->action |= TUNNAT_CZ_ACTION_ENCAP_NO_SESSION; /* ֱ�ӹ�����������ٷ���, ����Ҫ������� */
- break;
-
- case SAPP_SEND_OPT_VXLAN_LINK_ID:
- mr_ctrlzone->g_device_linkpair = option->int_value;
- mr_ctrlzone->action |= TUNNAT_CZ_ACTION_ENCAP_NO_SESSION; /* ֱ�ӹ�����������ٷ���, ����Ҫ������� */
- break;
-
- case SAPP_SEND_OPT_VXLAN_LINK_ENCAP_TYPE:
- mr_ctrlzone->g_device_outer_encap_type = option->char_value;
- break;
-
- case SAPP_SEND_OPT_VXLAN_LINK_DIR:
- mr_ctrlzone->route_dir = option->char_value;
- mr_ctrlzone->action |= TUNNAT_CZ_ACTION_ENCAP_NO_SESSION; /* ֱ�ӹ�����������ٷ���, ����Ҫ������� */
- break;
-
- case SAPP_SEND_OPT_INNER_LINK_ENCAP_TYPE:
- mr_ctrlzone->g_device_inner_encap_type = option->char_value;
- break;
-
- case SAPP_SEND_OPT_VIRTUAL_LINK_ID:
- mr_ctrlzone->virtual_link_id = option->long_value;
- mr_ctrlzone->action |= TUNNAT_CZ_ACTION_ENCAP_VIRTUAL_LINK_ID;
- break;
-
- case SAPP_SEND_OPT_REHASH_INDEX:
- /* rehash_index������ctrlzone������, Ҫͨ���ӿ�marsio_buff_set_rehash_index() */
- //mr_ctrlzone->rehash_index = option->long_value;
- //mr_ctrlzone->action |= TUNNAT_CZ_ACTION_ENCAP_VIRTUAL_LINK_ID;
- sapp_runtime_log(30, "sendpacket set vxlan options error, cat't set REHASH_INDEX in ctrlzone\n");
- break;
-
- case SAPP_SEND_OPT_VXLAN_FLAGS:
- //dpdk driver not support, use fix value 0x08
- break;
-
- default:
- sapp_runtime_log(20, "sendpacket set vxlan options error, invalid opt type:%d\n", option->type);
- break;
- }
-
- return;
-}
-
-/*
- �˺�����ipv4, ipv6������������, ��ether_type_host��������.
- data: ����ipͷ��������ip��;
- data_len: ����ipͷ������.
-*/
-static int __MESA_sendpacket_iplayer_options(int thread_index,const char *data, int data_len,
- u_int8_t dir, SAPP_TLV_T *options, int opt_num, unsigned short ether_type_host)
-{
- /* marsioϵ�к���0��ʾ����, -1��ʾ����, g_serialϵ�к������������ֽ���, ���󷵻�-1 */
- int inner_ret;
- marsio_buff_t *send_mbuf[1];
- unsigned char *real_buf;
- struct mr_tunnat_ctrlzone mr_ctrlzone;
- int i;
-
- if(NULL == dl_io_marsio4_instance){
- dl_io_marsio4_instance = sapp_get_marsio_instance();
- }
-
- inner_ret = ptr_marsio_buff_malloc_global(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- if(inner_ret < 0){
- sapp_runtime_log(RLOG_LV_INFO, "call marsio_buff_malloc_global() failed!\n");
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
-
- real_buf = (unsigned char *)ptr_marsio_buff_append(send_mbuf[0], data_len+sizeof(struct mesa_ethernet_hdr));
- if(NULL == real_buf){
- ptr_marsio_buff_free(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
- struct mesa_ethernet_hdr *inner_ehdr = (struct mesa_ethernet_hdr *)real_buf;
- inner_ehdr->ether_type = ntohs(ether_type_host);/* �ײ���Ϊethernet */
-
- /* �˴�ֻ������IP����ص�ѡ��, vxlan���ѡ���ڹ�������sapp_fakepacket_set_vxlan_options()���� */
- memset(&mr_ctrlzone, 0 , sizeof(struct mr_tunnat_ctrlzone));
- for(i = 0; i < opt_num; i++){
- if(SAPP_SEND_OPT_INNER_SMAC == options[i].type){
- memcpy(inner_ehdr->ether_shost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_INNER_DMAC == options[i].type){
- memcpy(inner_ehdr->ether_dhost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_REHASH_INDEX == options[i].type){
- ptr_marsio_buff_set_rehash_index(send_mbuf[0], options[i].int_value);
- }else{
- sapp_fakepacket_set_vxlan_options(&mr_ctrlzone, &options[i]);
- }
- }
- memcpy(real_buf + sizeof(struct mesa_ethernet_hdr), data, data_len);
-
- mr_ctrlzone.action |= TUNNAT_CZ_ACTION_ENCAP_INNER | TUNNAT_CZ_ACTION_ENCAP_OUTER;
- mr_ctrlzone.route_dir = dir; /* ͨ��ѡ��Ҳ������, �����DZ����˽ӿ�ֱ������dir�IJ���, �ӿ�dir���� */
- ptr_marsio_buff_ctrlzone_set(send_mbuf[0], 0, &mr_ctrlzone, sizeof(struct mr_tunnat_ctrlzone));
- inner_ret = marsio_send_burst_with_options_for_tcpdumpmesa((struct mr_sendpath *)g_packet_device_alias[0].dl_io_param, thread_index,
- send_mbuf, 1, MARSIO_SEND_OPT_FAST);
- if(inner_ret < 0){
- return -1;
- }
-
- return data_len;
-}
-
-
-int MESA_sendpacket_iplayer_options(int thread_index,const char *data, int data_len,
- u_int8_t dir, SAPP_TLV_T *options, int opt_num)
-{
- sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_index]->sys_stat;
- int ret;
-
- ret = __MESA_sendpacket_iplayer_options(thread_index, data, data_len, dir, options, opt_num, ETHERTYPE_IP);
- if(ret > 0){
- local_sys_stat->count[SAPP_STAT_SND_IPV4]++;
- local_sys_stat->length[SAPP_STAT_SND_IPV4]+= data_len;
- }
-
- return ret;
-}
-
-int MESA_sendpacket_ipv6_layer_options(int thread_index,const char *data, int data_len,
- u_int8_t dir, SAPP_TLV_T *options, int opt_num)
-{
- sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_index]->sys_stat;
- int ret;
-
- ret = __MESA_sendpacket_iplayer_options(thread_index, data, data_len, dir, options, opt_num, ETHERTYPE_IPv6);
-
- if(ret > 0){
- local_sys_stat->count[SAPP_STAT_SND_IPV6]++;
- local_sys_stat->length[SAPP_STAT_SND_IPV6]+= data_len;
- }
-
- return ret;
-}
-
-int MESA_fakepacket_send_ipv4_options(const struct streaminfo *stream, uint8_t protocol,
- uint32_t sip_host_order, uint32_t dip_host_order,
- const char *payload, int payload_len, uint8_t dir,
- SAPP_TLV_T *options, int opt_num)
-{
- int snd_len, inner_ret;
- marsio_buff_t *send_mbuf[1];
- u_int16_t ipid = MESA_rand() & 0xFFFF;
- u_int8_t ip_ttl = MESA_rand() % 64 + 32;
- int thread_index = stream->threadnum;
- int i;
- sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_index]->sys_stat;
-
- struct mr_tunnat_ctrlzone mr_ctrlzone;
- unsigned char *real_buf;
-
- if(NULL == dl_io_marsio4_instance){
- dl_io_marsio4_instance = sapp_get_marsio_instance();
- }
-
- inner_ret = ptr_marsio_buff_malloc_global(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- if(inner_ret < 0){
- sapp_runtime_log(RLOG_LV_INFO, "MESA_fakepacket_send_ipv4_options-> marsio_buff_malloc_global() failed!\n");
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
-
- /* �˴�ʹ��append������mtod, append�ڲ�ʵ�ʰ�����set datalen�IJ��� */
- real_buf = (unsigned char *)ptr_marsio_buff_append(send_mbuf[0], payload_len + sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr));
- if(NULL == real_buf){
- ptr_marsio_buff_free(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
- struct mesa_ethernet_hdr *inner_ehdr = (struct mesa_ethernet_hdr *)real_buf;
- inner_ehdr->ether_type = ntohs(ETHERTYPE_IP);/* �ײ���Ϊethernte */
-
- /* �˴�ֻ������IP����ص�ѡ��, vxlan���ѡ���ڹ�������sapp_fakepacket_set_vxlan_options()���� */
- memset(&mr_ctrlzone, 0 , sizeof(struct mr_tunnat_ctrlzone));
- for(i = 0; i < opt_num; i++){
- if(SAPP_SEND_OPT_IP_ID == options[i].type){
- ipid = options[i].short_value;
- }else if(SAPP_SEND_OPT_IP_TTL == options[i].type){
- ip_ttl = options[i].char_value;
- }else if(SAPP_SEND_OPT_INNER_SMAC == options[i].type){
- memcpy(inner_ehdr->ether_shost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_INNER_DMAC == options[i].type){
- memcpy(inner_ehdr->ether_dhost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_REHASH_INDEX == options[i].type){
- ptr_marsio_buff_set_rehash_index(send_mbuf[0], options[i].int_value);
- }else{
- sapp_fakepacket_set_vxlan_options(&mr_ctrlzone, &options[i]);
- }
- }
- sendpacket_build_ipv4(payload_len, 0, ipid, 0 , ip_ttl, protocol,
- htonl(sip_host_order), htonl(dip_host_order), payload, payload_len,
- (unsigned char *)real_buf + sizeof(struct mesa_ethernet_hdr));
-
- sendpacket_do_checksum(real_buf + sizeof(struct mesa_ethernet_hdr), IPPROTO_IP, SENDPACKET_IP_H);
-
- if(payload){
- memcpy(real_buf + sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr), payload, payload_len);
- }
-
- mr_ctrlzone.action |= TUNNAT_CZ_ACTION_ENCAP_INNER | TUNNAT_CZ_ACTION_ENCAP_OUTER;
- mr_ctrlzone.route_dir = dir; /* ͨ��ѡ��Ҳ������, �����DZ����˽ӿ�ֱ������dir�IJ���, �ӿ�dir���� */
- ptr_marsio_buff_ctrlzone_set(send_mbuf[0], 0, &mr_ctrlzone, sizeof(struct mr_tunnat_ctrlzone));
- inner_ret = marsio_send_burst_with_options_for_tcpdumpmesa((struct mr_sendpath *)g_packet_device_alias[0].dl_io_param, thread_index,
- send_mbuf, 1, MARSIO_SEND_OPT_FAST);
-
- if(inner_ret < 0){
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
-
- snd_len = sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr) + payload_len;
- local_sys_stat->count[SAPP_STAT_SND_IPV4]++;
- local_sys_stat->length[SAPP_STAT_SND_IPV4]+= snd_len;
-
-
- return snd_len;
-}
-
-int MESA_fakepacket_send_ipv6_options(const struct streaminfo *stream, uint8_t protocol,
- struct in6_addr *sip, struct in6_addr *dip,
- const char *payload, int payload_len, uint8_t dir,
- SAPP_TLV_T *options, int opt_num)
-{
- int inner_ret, snd_len;
- u_int8_t ip_ttl = MESA_rand() % 64 + 32;
- int thread_index = stream->threadnum;
- int i;
- marsio_buff_t *send_mbuf[1];
- struct mr_tunnat_ctrlzone mr_ctrlzone;
- unsigned char *real_buf;
- sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_index]->sys_stat;
-
- if(NULL == dl_io_marsio4_instance){
- dl_io_marsio4_instance = sapp_get_marsio_instance();
- }
-
- inner_ret = ptr_marsio_buff_malloc_global(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- if(inner_ret < 0){
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
-
- /* �˴�ʹ��append������mtod, append�ڲ�ʵ�ʰ�����set datalen�IJ��� */
- real_buf = (unsigned char *)ptr_marsio_buff_append(send_mbuf[0], payload_len + sizeof(struct mesa_ip6_hdr)+sizeof(struct mesa_ethernet_hdr));
- if(NULL == real_buf){
- ptr_marsio_buff_free(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
- struct mesa_ethernet_hdr *inner_ehdr = (struct mesa_ethernet_hdr *)real_buf;
- inner_ehdr->ether_type = ntohs(ETHERTYPE_IPv6);/* �ײ���Ϊethernet */
-
- /* �˴�ֻ������IP����ص�ѡ��, vxlan���ѡ���ڹ�������sapp_fakepacket_set_vxlan_options()���� */
- memset(&mr_ctrlzone, 0 , sizeof(struct mr_tunnat_ctrlzone));
- for(i = 0; i < opt_num; i++){
- if(SAPP_SEND_OPT_IP_TTL == options[i].type){
- ip_ttl = options[i].char_value;
- }else if(SAPP_SEND_OPT_INNER_SMAC == options[i].type){
- memcpy(inner_ehdr->ether_shost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_INNER_DMAC == options[i].type){
- memcpy(inner_ehdr->ether_dhost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_REHASH_INDEX == options[i].type){
- ptr_marsio_buff_set_rehash_index(send_mbuf[0], options[i].int_value);
- }else{
- sapp_fakepacket_set_vxlan_options(&mr_ctrlzone, &options[i]);
- }
- }
- sendpacket_build_ipv6(0, 0, payload_len, protocol, ip_ttl, sip, dip,
- payload, payload_len,
- (unsigned char *)real_buf + sizeof(struct mesa_ethernet_hdr));
-
- mr_ctrlzone.action |= TUNNAT_CZ_ACTION_ENCAP_INNER | TUNNAT_CZ_ACTION_ENCAP_OUTER;
- mr_ctrlzone.route_dir = dir; /* ͨ��ѡ��Ҳ������, �����DZ����˽ӿ�ֱ������dir�IJ���, �ӿ�dir���� */
- ptr_marsio_buff_ctrlzone_set(send_mbuf[0], 0, &mr_ctrlzone, sizeof(struct mr_tunnat_ctrlzone));
- inner_ret = marsio_send_burst_with_options_for_tcpdumpmesa((struct mr_sendpath *)g_packet_device_alias[0].dl_io_param, thread_index,
- send_mbuf, 1, MARSIO_SEND_OPT_FAST);
- if(inner_ret < 0){
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
-
- snd_len = sizeof(struct mesa_ip6_hdr)+sizeof(struct mesa_ethernet_hdr) + payload_len;
- local_sys_stat->count[SAPP_STAT_SND_IPV6]++;
- local_sys_stat->length[SAPP_STAT_SND_IPV6]+= snd_len;
-
- return snd_len;
-}
-
-int MESA_fakepacket_send_tcp_options(const struct streaminfo *stream,
- u_int sip_host_order,u_int dip_host_order,
- u_short sport_host_order,u_short dport_host_order,
- u_int sseq_host_order,u_int sack_host_order,
- u_char control,
- const char* payload,int payload_len, u_int8_t dir,
- SAPP_TLV_T *options, int opt_num)
-{
- int i, snd_len, inner_ret, offset = sizeof(struct mesa_ethernet_hdr);
- int thread_index = stream->threadnum;
- marsio_buff_t *send_mbuf[1];
- struct mr_tunnat_ctrlzone mr_ctrlzone;
- unsigned char *real_buf;
- unsigned short ipid = MESA_rand() & 0xFFFF;
- unsigned short tcp_win = MESA_rand_range(8192, 32768);
- unsigned char ip_ttl = MESA_rand_range(32,65);
- sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_index]->sys_stat;
-
- if(NULL == dl_io_marsio4_instance){
- dl_io_marsio4_instance = sapp_get_marsio_instance();
- }
-
- inner_ret = ptr_marsio_buff_malloc_global(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- if(inner_ret < 0){
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- sapp_runtime_log(RLOG_LV_INFO, "MESA_fakepacket_send_tcp_options()-> marsio_buff_malloc_global() failed!\n");
- return -1;
- }
-
- /* �˴�ʹ��append������mtod, append�ڲ�ʵ�ʰ�����set datalen�IJ��� */
- real_buf = (unsigned char *)ptr_marsio_buff_append(send_mbuf[0], payload_len + sizeof(struct mesa_tcp_hdr) + sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr));
- if(NULL == real_buf){
- ptr_marsio_buff_free(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
- struct mesa_ethernet_hdr *inner_ehdr = (struct mesa_ethernet_hdr *)real_buf;
- inner_ehdr->ether_type = ntohs(ETHERTYPE_IP);/* �ײ���Ϊethernte */
-
- memset(&mr_ctrlzone, 0 , sizeof(struct mr_tunnat_ctrlzone));
- for(i = 0; i < opt_num; i++){
- if(SAPP_SEND_OPT_IP_ID == options[i].type){
- ipid = options[i].short_value;
- }else if(SAPP_SEND_OPT_IP_TTL == options[i].type){
- ip_ttl = options[i].char_value;
- }if(SAPP_SEND_OPT_TCP_WIN == options[i].type){
- tcp_win = options[i].short_value;
- }else if(SAPP_SEND_OPT_INNER_SMAC == options[i].type){
- memcpy(inner_ehdr->ether_shost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_INNER_DMAC == options[i].type){
- memcpy(inner_ehdr->ether_dhost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_REHASH_INDEX == options[i].type){
- ptr_marsio_buff_set_rehash_index(send_mbuf[0], options[i].int_value);
- }else{
- sapp_fakepacket_set_vxlan_options(&mr_ctrlzone, &options[i]);
- }
- }
-
- sendpacket_build_tcp(sport_host_order, dport_host_order, sseq_host_order, sack_host_order,
- control, tcp_win, 0, payload, payload_len, real_buf+offset+sizeof(struct mesa_ip4_hdr));
-
- sendpacket_build_ipv4(payload_len+SENDPACKET_TCP_H, 0, ipid, 0, ip_ttl, IPPROTO_TCP,
- htonl(sip_host_order), htonl(dip_host_order), NULL, 0, real_buf+offset);
-
- sendpacket_do_checksum(real_buf+offset, IPPROTO_TCP, SENDPACKET_TCP_H+payload_len);
-
- sendpacket_do_checksum(real_buf+offset, IPPROTO_IP, SENDPACKET_IP_H);
-
- mr_ctrlzone.action |= TUNNAT_CZ_ACTION_ENCAP_INNER | TUNNAT_CZ_ACTION_ENCAP_OUTER;
- mr_ctrlzone.route_dir = dir; /* ͨ��ѡ��Ҳ������, �����DZ����˽ӿ�ֱ������dir�IJ���, �ӿ�dir���� */
- ptr_marsio_buff_ctrlzone_set(send_mbuf[0], 0, &mr_ctrlzone, sizeof(struct mr_tunnat_ctrlzone));
- inner_ret = marsio_send_burst_with_options_for_tcpdumpmesa((struct mr_sendpath *)g_packet_device_alias[0].dl_io_param, thread_index,
- send_mbuf, 1, MARSIO_SEND_OPT_FAST);
-
- if(inner_ret < 0){
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
-
- snd_len = sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr) +sizeof(struct mesa_tcp_hdr) + payload_len;
-
- local_sys_stat->count[SAPP_STAT_SND_TCP]++;
- local_sys_stat->length[SAPP_STAT_SND_TCP]+= snd_len;
-
- return snd_len;
-}
-
-
-int MESA_fakepacket_send_ipv6_tcp_options(const struct streaminfo *stream,
- struct in6_addr *sip, struct in6_addr *dip,
- u_short sport_host_order,u_short dport_host_order,
- u_int sseq_host_order,u_int sack_host_order,
- u_char control,
- const char* payload,int payload_len, u_int8_t dir,
- SAPP_TLV_T *options, int opt_num)
-{
- int i, snd_len, inner_ret, offset = sizeof(struct mesa_ethernet_hdr);
- int thread_index = stream->threadnum;
- marsio_buff_t *send_mbuf[1];
- struct mr_tunnat_ctrlzone mr_ctrlzone;
- unsigned char *real_buf;
- unsigned short tcp_win = MESA_rand_range(8192, 32768);
- unsigned char ip_ttl = MESA_rand_range(32,65);
- sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_index]->sys_stat;
-
- if(NULL == dl_io_marsio4_instance){
- dl_io_marsio4_instance = sapp_get_marsio_instance();
- }
-
- inner_ret = ptr_marsio_buff_malloc_global(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- if(inner_ret < 0){
- sapp_runtime_log(RLOG_LV_INFO, "MESA_fakepacket_send_ipv6_tcp_options-> marsio_buff_malloc_global() failed!\n");
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
-
- /* �˴�ʹ��append������mtod, append�ڲ�ʵ�ʰ�����set datalen�IJ��� */
- real_buf = (unsigned char *)ptr_marsio_buff_append(send_mbuf[0], payload_len + sizeof(struct mesa_tcp_hdr) + sizeof(struct mesa_ip6_hdr)+sizeof(struct mesa_ethernet_hdr));
- if(NULL == real_buf){
- ptr_marsio_buff_free(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
- struct mesa_ethernet_hdr *inner_ehdr = (struct mesa_ethernet_hdr *)real_buf;
- inner_ehdr->ether_type = ntohs(ETHERTYPE_IPv6);/* �ײ���Ϊethernte */
-
- memset(&mr_ctrlzone, 0 , sizeof(struct mr_tunnat_ctrlzone));
- for(i = 0; i < opt_num; i++){
- if(SAPP_SEND_OPT_IP_TTL == options[i].type){
- ip_ttl = options[i].char_value;
- }if(SAPP_SEND_OPT_TCP_WIN == options[i].type){
- tcp_win = options[i].short_value;
- }else if(SAPP_SEND_OPT_INNER_SMAC == options[i].type){
- memcpy(inner_ehdr->ether_shost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_INNER_DMAC == options[i].type){
- memcpy(inner_ehdr->ether_dhost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_REHASH_INDEX == options[i].type){
- ptr_marsio_buff_set_rehash_index(send_mbuf[0], options[i].int_value);
- }else{
- sapp_fakepacket_set_vxlan_options(&mr_ctrlzone, &options[i]);
- }
- }
-
- sendpacket_build_tcp(sport_host_order, dport_host_order, sseq_host_order, sack_host_order,
- control, tcp_win, 0, payload, payload_len, real_buf+offset+sizeof(struct mesa_ip6_hdr));
-
- sendpacket_build_ipv6(0, 0, payload_len + sizeof(struct mesa_tcp_hdr), IPPROTO_TCP, ip_ttl, sip, dip,
- NULL, 0,
- (unsigned char *)real_buf + sizeof(struct mesa_ethernet_hdr));
-
- sendpacket_do_checksum(real_buf+offset, IPPROTO_TCP, SENDPACKET_TCP_H+payload_len);
-
- mr_ctrlzone.action |= TUNNAT_CZ_ACTION_ENCAP_INNER | TUNNAT_CZ_ACTION_ENCAP_OUTER;
- mr_ctrlzone.route_dir = dir; /* ͨ��ѡ��Ҳ������, �����DZ����˽ӿ�ֱ������dir�IJ���, �ӿ�dir���� */
- ptr_marsio_buff_ctrlzone_set(send_mbuf[0], 0, &mr_ctrlzone, sizeof(struct mr_tunnat_ctrlzone));
- inner_ret = marsio_send_burst_with_options_for_tcpdumpmesa((struct mr_sendpath *)g_packet_device_alias[0].dl_io_param, thread_index,
- send_mbuf, 1, MARSIO_SEND_OPT_FAST);
- if(inner_ret < 0){
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
-
- snd_len = sizeof(struct mesa_ip6_hdr)+sizeof(struct mesa_ethernet_hdr) +sizeof(struct mesa_tcp_hdr) + payload_len;
- local_sys_stat->count[SAPP_STAT_SND_TCP]++;
- local_sys_stat->length[SAPP_STAT_SND_TCP]+= snd_len;
-
- return snd_len;
-}
-
-int MESA_fakepacket_send_udp_options(const struct streaminfo *stream,
- u_int sip_host_order, u_int dip_host_order,
- u_short sport_host_order,u_short dport_host_order,
- const char *payload, int payload_len,u_int8_t dir,
- SAPP_TLV_T *options, int opt_num)
-{
- int i, snd_len, inner_ret, offset = sizeof(struct mesa_ethernet_hdr);
- int thread_index = stream->threadnum;
- marsio_buff_t *send_mbuf[1];
- struct mr_tunnat_ctrlzone mr_ctrlzone;
- unsigned char *real_buf;
- unsigned short ipid = MESA_rand();
- unsigned char ip_ttl = MESA_rand_range(32, 64);
- sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_index]->sys_stat;
-
- if(NULL == dl_io_marsio4_instance){
- dl_io_marsio4_instance = sapp_get_marsio_instance();
- }
-
- inner_ret = ptr_marsio_buff_malloc_global(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- if(inner_ret < 0){
- sapp_runtime_log(30, "call marsio_buff_malloc_global() failed!\n");
- return -1;
- }
-
- /* �˴�ʹ��append������mtod, append�ڲ�ʵ�ʰ�����set datalen�IJ��� */
- real_buf = (unsigned char *)ptr_marsio_buff_append(send_mbuf[0], payload_len + sizeof(struct mesa_udp_hdr) + sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr));
- if(NULL == real_buf){
- ptr_marsio_buff_free(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
- struct mesa_ethernet_hdr *inner_ehdr = (struct mesa_ethernet_hdr *)real_buf;
- inner_ehdr->ether_type = ntohs(ETHERTYPE_IP);/* �ײ���Ϊethernte */
-
- memset(&mr_ctrlzone, 0 , sizeof(struct mr_tunnat_ctrlzone));
- for(i = 0; i < opt_num; i++){
- if(SAPP_SEND_OPT_IP_ID == options[i].type){
- ipid = options[i].short_value;
- }else if(SAPP_SEND_OPT_IP_TTL == options[i].type){
- ip_ttl = options[i].char_value;
- }else if(SAPP_SEND_OPT_INNER_SMAC == options[i].type){
- memcpy(inner_ehdr->ether_shost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_INNER_DMAC == options[i].type){
- memcpy(inner_ehdr->ether_dhost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_REHASH_INDEX == options[i].type){
- ptr_marsio_buff_set_rehash_index(send_mbuf[0], options[i].int_value);
- }else{
- sapp_fakepacket_set_vxlan_options(&mr_ctrlzone, &options[i]);
- }
- }
-
- sendpacket_build_udp(sport_host_order, dport_host_order, payload, payload_len,
- real_buf+offset+sizeof(struct mesa_ip4_hdr));
-
- sendpacket_build_ipv4(payload_len+SENDPACKET_UDP_H, 0, ipid, 0, ip_ttl, IPPROTO_UDP,
- htonl(sip_host_order), htonl(dip_host_order), NULL, 0, real_buf+offset);
-
- sendpacket_do_checksum(real_buf+offset, IPPROTO_UDP, SENDPACKET_UDP_H+payload_len);
-
- sendpacket_do_checksum(real_buf+offset, IPPROTO_IP, SENDPACKET_IP_H);
-
- if((mr_ctrlzone.action & TUNNAT_CZ_ACTION_ENCAP_NO_SESSION) == 0){
- mr_ctrlzone.action |= TUNNAT_CZ_ACTION_ENCAP_INNER | TUNNAT_CZ_ACTION_ENCAP_OUTER;
- }
- mr_ctrlzone.route_dir = dir; /* ͨ��ѡ��Ҳ������, �����DZ����˽ӿ�ֱ������dir�IJ���, �ӿ�dir���� */
- ptr_marsio_buff_ctrlzone_set(send_mbuf[0], 0, &mr_ctrlzone, sizeof(struct mr_tunnat_ctrlzone));
-#if 0
- inner_ret = marsio_send_burst_with_options_for_tcpdumpmesa((struct mr_sendpath *)g_packet_device_alias[0].dl_io_param, thread_index,
- send_mbuf, 1, MARSIO_SEND_OPT_FAST);
-#else
- inner_ret = marsio_send_burst_with_options_for_tcpdumpmesa((struct mr_sendpath *)g_packet_device_alias[0].dl_io_param, thread_index,
- send_mbuf, 1, 0);
-#endif
- if(inner_ret < 0){
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
-
- snd_len = sizeof(struct mesa_ip4_hdr)+sizeof(struct mesa_ethernet_hdr) +sizeof(struct mesa_udp_hdr) + payload_len;
-
- local_sys_stat->count[SAPP_STAT_SND_TCP]++;
- local_sys_stat->length[SAPP_STAT_SND_TCP]+= snd_len;
- return snd_len;
-}
-
-int MESA_fakepacket_send_ipv6_udp_options(const struct streaminfo *stream,
- struct in6_addr *sip, struct in6_addr *dip,
- u_short sport_host_order,u_short dport_host_order,
- const char *payload, int payload_len,u_int8_t dir,
- SAPP_TLV_T *options, int opt_num)
-{
- int i, snd_len, inner_ret, offset = sizeof(struct mesa_ethernet_hdr);
- int thread_index = stream->threadnum;
- marsio_buff_t *send_mbuf[1];
- struct mr_tunnat_ctrlzone mr_ctrlzone;
- unsigned char *real_buf;
- unsigned char ip_ttl = MESA_rand_range(32, 64);
- sapp_gval_mthread_sys_stat_t *local_sys_stat = &sapp_global_val->mthread_volatile[thread_index]->sys_stat;
-
- if(NULL == dl_io_marsio4_instance){
- dl_io_marsio4_instance = sapp_get_marsio_instance();
- }
-
- inner_ret = ptr_marsio_buff_malloc_global(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- if(inner_ret < 0){
- sapp_runtime_log(RLOG_LV_INFO, "MESA_fakepacket_send_ipv6_udp_options-> marsio_buff_malloc_global() failed!\n");
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
-
- /* �˴�ʹ��append������mtod, append�ڲ�ʵ�ʰ�����set datalen�IJ��� */
- real_buf = (unsigned char *)ptr_marsio_buff_append(send_mbuf[0], payload_len + sizeof(struct mesa_udp_hdr) + sizeof(struct mesa_ip6_hdr)+sizeof(struct mesa_ethernet_hdr));
- if(NULL == real_buf){
- ptr_marsio_buff_free(dl_io_marsio4_instance, send_mbuf, 1, MARSIO_SOCKET_ID_ANY, thread_index);
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
- struct mesa_ethernet_hdr *inner_ehdr = (struct mesa_ethernet_hdr *)real_buf;
- inner_ehdr->ether_type = ntohs(ETHERTYPE_IPv6);/* �ײ���Ϊethernte */
-
- memset(&mr_ctrlzone, 0 , sizeof(struct mr_tunnat_ctrlzone));
- for(i = 0; i < opt_num; i++){
- if(SAPP_SEND_OPT_IP_TTL == options[i].type){
- ip_ttl = options[i].char_value;
- }else if(SAPP_SEND_OPT_INNER_SMAC == options[i].type){
- memcpy(inner_ehdr->ether_shost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_INNER_DMAC == options[i].type){
- memcpy(inner_ehdr->ether_dhost, options[i].array_value, ETHER_ADDR_LEN);
- }else if(SAPP_SEND_OPT_REHASH_INDEX == options[i].type){
- ptr_marsio_buff_set_rehash_index(send_mbuf[0], options[i].int_value);
- }else{
- sapp_fakepacket_set_vxlan_options(&mr_ctrlzone, &options[i]);
- }
- }
-
- sendpacket_build_udp(sport_host_order, dport_host_order, payload, payload_len,
- real_buf+offset+sizeof(struct mesa_ip6_hdr));
-
- sendpacket_build_ipv6(0, 0, payload_len + sizeof(struct mesa_udp_hdr), IPPROTO_UDP, ip_ttl, sip, dip,
- NULL, 0,
- (unsigned char *)real_buf + sizeof(struct mesa_ethernet_hdr));
-
- sendpacket_do_checksum(real_buf+offset, IPPROTO_UDP, SENDPACKET_UDP_H+payload_len);
-
- mr_ctrlzone.action |= TUNNAT_CZ_ACTION_ENCAP_INNER | TUNNAT_CZ_ACTION_ENCAP_OUTER;
- mr_ctrlzone.route_dir = dir; /* ͨ��ѡ��Ҳ������, �����DZ����˽ӿ�ֱ������dir�IJ���, �ӿ�dir���� */
- ptr_marsio_buff_ctrlzone_set(send_mbuf[0], 0, &mr_ctrlzone, sizeof(struct mr_tunnat_ctrlzone));
- inner_ret = marsio_send_burst_with_options_for_tcpdumpmesa((struct mr_sendpath *)g_packet_device_alias[0].dl_io_param, thread_index,
- send_mbuf, 1, MARSIO_SEND_OPT_FAST);
- if(inner_ret < 0){
- sapp_global_val->mthread_volatile[thread_index]->sys_stat.count[SAPP_STAT_SND_ERROR]++;
- return -1;
- }
-
- snd_len = sizeof(struct mesa_ip6_hdr)+sizeof(struct mesa_ethernet_hdr) +sizeof(struct mesa_udp_hdr) + payload_len;
- local_sys_stat->count[SAPP_STAT_SND_UDP]++;
- local_sys_stat->length[SAPP_STAT_SND_UDP]+= snd_len;
-
- return snd_len;
-}
-#endif
-
-int sapp_forward_current_pkt(const struct streaminfo *stream, unsigned int target_id)
-{
- int ret;
- marsio_buff_t *raw_mbuf, *new_clone_buf;
- const struct streaminfo_private *stream_pr = (const struct streaminfo_private *)stream;
-
- if(NULL == dl_io_marsio4_instance){
- dl_io_marsio4_instance = sapp_get_marsio_instance();
- }
-
- if(NULL == stream_pr->raw_pkt){ /* ����������ʱ��̭����, ����Ե��ô˽ӿ� */
- return 0;
- }
-
- /* TODO:
- �жϵ�ǰ���Ƿ��������, ���ӷ������ص�TCPALL��,
- �������io_lib_pkt_referenceָ��dpdk���ڴ�, ��û�и��Ʊ���,
- ����ʱ�ᵼ���ڴ����.
-
- NOTE:
- ��ʵ���������ޱ�Ҫ, ת����������ص�TCPALL��, ��deal_unorder���������������TCPALL�ӿ�!
- */
- if((stream->addr.pkttype & PKT_TYPE_TCPREORDER) != 0){
- return 0;
- }
- raw_mbuf = (marsio_buff_t *)stream_pr->raw_pkt->io_lib_pkt_reference;
-
- assert(raw_mbuf);
-
- /* NOTE,
- marsio��ͬʱ���հ����������Ӧ����������ʱ��������,
- ���Դ˴�����Ӧ����������֮ǰ, ��cloneһ��new_clone_buf, ���ͺ���Զ�free.
- ��עԭʼ���Ļ���ԭ����raw_mbuf.
- */
- new_clone_buf = ptr_marsio_buff_clone_with_options(dl_io_marsio4_instance, raw_mbuf,
- MARSIO_SOCKET_ID_ANY, stream->threadnum,
- MR_BUFF_CLONE_BUFF | MR_BUFF_CLONE_CTRLZONE);
-
- assert(new_clone_buf);
-
- ret = ptr_marsio_send_burst((struct mr_sendpath *)g_packet_device_alias[target_id].dl_io_param,
- stream->threadnum, &new_clone_buf, 1);
-
-
- return ret;
-}
-
int MESA_send_smart_offload(const struct streaminfo *pstream, const void *raw_pkt, int thread_num)
{
@@ -4907,13 +3785,13 @@ int MESA_send_smart_offload(const struct streaminfo *pstream, const void *raw_pk
switch(pstream->type)
{
case STREAM_TYPE_TCP:
- if(sapp_global_val->config.stream.tcp.meaningful_statistics_minimum_pkt>=(pstream->ptcpdetail->serverpktnum+pstream->ptcpdetail->clientpktnum))
+ if(sapp_global_val->config.stream.tcp.meaningful_statistics_minimum_pkt>=(int)(pstream->ptcpdetail->serverpktnum+pstream->ptcpdetail->clientpktnum))
{
return 0;
}
break;
case STREAM_TYPE_UDP:
- if(sapp_global_val->config.stream.udp.meaningful_statistics_minimum_pkt>=(pstream->pudpdetail->serverpktnum+pstream->pudpdetail->clientpktnum))
+ if(sapp_global_val->config.stream.udp.meaningful_statistics_minimum_pkt>=(int)(pstream->pudpdetail->serverpktnum+pstream->pudpdetail->clientpktnum))
{
return 0;
}
@@ -4923,8 +3801,6 @@ int MESA_send_smart_offload(const struct streaminfo *pstream, const void *raw_pk
}
const raw_pkt_t *_raw_pkt=(raw_pkt_t *)raw_pkt;
-
- MESA_send_handle *send_handle = packet_io_get_send_handle(thread_num);
return dl_io_fun_list.dl_io_smart_offload(_raw_pkt->device_index,
(unsigned char *)_raw_pkt->__lib_raw_pkt_data,