summaryrefslogtreecommitdiff
path: root/include/MESA/stream_inc/stream_inject.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/MESA/stream_inc/stream_inject.h')
-rw-r--r--include/MESA/stream_inc/stream_inject.h282
1 files changed, 282 insertions, 0 deletions
diff --git a/include/MESA/stream_inc/stream_inject.h b/include/MESA/stream_inc/stream_inject.h
new file mode 100644
index 0000000..68259f0
--- /dev/null
+++ b/include/MESA/stream_inc/stream_inject.h
@@ -0,0 +1,282 @@
+#ifndef _APP_STREAM_INJECT_H_
+#define _APP_STREAM_INJECT_H_
+
+#include <sys/types.h>
+#include <stdint.h>
+#include "stream_base.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define STREAM_INJECT_H_VERSION (20191120)
+
+
+/*
+ CHN : ����GK��غ���
+ ENG : to force terminate a stream;
+
+ MESA_kill_tcp: use RST to terminate a TCP stream;
+ MESA_kill_tcp_synack: send phony SYN/ACK packet to cheat client and server.
+ MESA_kill_connection: for non-TCP stream, such as UDP stream, only available in serial mode.
+
+ return value:
+ >= 0: success.
+ -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] */
+ unsigned char rst_pkt_num; /* ����һ��MESA_rst_tcp()���͵�rst������, ��ѡֵ[1,2,3], ��Ե�������, ��rst_pkt_num=2, dir=DIR_DOUBLEʱ,�ܷ���������4�� */
+ /*
+ dir:
+ ����rst������, ��ѡֵΪ[DIR_C2S, DIR_S2C, DIR_DOUBLE], ��ֵ�ο�:streaminfo->curdir,
+ ��������͵İ��뵱ǰ��ͬ��, dir = stream->curdir,
+ ��������͵İ��뵱ǰ������, dir = stream->curdir ^ 3, ������.
+ �����˫����, dir = DIR_DOUBLE;
+ */
+ unsigned char dir;
+ unsigned char __pad_no_use; /* padding for alignment */
+
+ /*
+ rst��ָ����Ϣ, �Ƽ�ֵseed1=65535, seed2Ϊ����, ��13,17,19��;
+ signature_seed1=0 && signature_seed1=0, ��ʾ���ε��ò�ָ��signature, ʹ��ȫ������, ��������:
+ if(sapp.toml->stream.tcp.inject.signature_enabled == 1){
+ signature_seed1 = sapp.toml->stream.tcp.inject.signature_seed1;
+ signature_seed2 = sapp.toml->stream.tcp.inject.signature_seed2;
+ }else{
+ signature_seed1 = rand();
+ signature_seed2 = rand();
+ }
+ */
+ unsigned short signature_seed1;
+ unsigned short signature_seed2;
+};
+
+/*
+ args:
+ stream: ��ǰ��������;
+ paras : ����rst��ز���, ���struct rst_tcp_para�ṹ��˵��;
+ para_len: sizeof(struct rst_tcp_para), Ԥ��������������, ���ݴ˳����жϰ汾.
+
+ MESA_rst_tcp��MESA_kill_tcp����:
+ MESA_kill_tcpʵ�����Ǽ��������Ĵ��ӻ�: ����RST��, ���Ʒ�����APP_STATE_KILL_OTHER, ��DROP��ǰ���������а�;
+ MESA_rst_tcpֻר����һ������: ����RST��!
+
+ note: ������IJ���֮��, kill_tcp����һ��������FD����,
+ ��������Ϊ��������Ŵ���������ʱ��ԭ��, ���µ���FD����Ч, ����MESA_kill_tcp֮������Զ�����FD����,
+ ������MESA_rst_tcp��˵, ������Ϊֻ�Ե�ǰ����Ч,
+ remedy����������������stream��, ��Ҫ����MESA_set_stream_opt(), opt=MSO_TCP_RST_REMEDY ���.
+
+ return value:
+ >= 0: success.
+ -1 : error.
+*/
+int MESA_rst_tcp(struct streaminfo *stream, struct rst_tcp_para *paras, int para_len);
+
+
+
+/*
+ ���������ܵ�MESA_kill_xxxϵ�к���.
+ ���ӹ���Ϊ:
+ ��ʵ�ʷ��͵����ݰ�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_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);
+
+/*
+ CHN : ����route_dir����, Ϊ�˼���papp;
+ ENG : compat for papp, dir reverse.
+ */
+unsigned char MESA_dir_reverse(unsigned char raw_route_dir);
+
+/***************************************************************************************
+ NOTE:
+ �ڱ���ģʽ��, ����������route_dir�ľ���ֵ, ֻ��Ҫ����ͬ��ͷ��򼴿�,
+ ��������������Ҫ��ȷ����route_dir��0����1, �������������ģʽ��ͬ, ������ʱ��仯,
+ �������ô˽ӿ�, ���ֻ�贫����������ķ���, ���ص�ǰ��·��link route dir,
+ ע��etc/sapp.toml inbound_route_dirҪ������ȷ.
+
+ args: ��ʾ����Ŀ������ڵ�ǰ�豸���ڵĵ���λ��,
+ 'E' or 'e': ��ʾ���������Ǵ�Internal to External.
+ 'I' or 'i': ��ʾ���������Ǵ�External to Internal.
+
+ return value:
+ 0 or 1: success.
+ -1 : error.
+****************************************************************************************/
+int MESA_dir_human_to_link(int human_dir);
+
+/*
+ ARG:
+ stream: ���ṹ��ָ��;
+ payload: Ҫ���͵�����ָ��;
+ payload_len: Ҫ���͵����ݸ��س���;
+ raw_pkt: ԭʼ��ָ��;
+ snd_routedir: Ҫ�������ݵ�route����,
+ ��������͵İ��뵱ǰ��ͬ��, snd_routedir = stream->routedir,
+ ��������͵İ��뵱ǰ������, snd_routedir = MESA_dir_reverse(stream->routedir).
+ return value:
+ -1: error.
+ >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
+
+#endif
+