summaryrefslogtreecommitdiff
path: root/src/packet_io/sapp_inject.c
blob: 559f33f87ca61fafa0858b19efa7ad17eeda58ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "sapp_api.h"
#include "sapp_private_api.h"
#include "stream_inc/sapp_inject.h"


#ifdef __cplusplus
extern "C" {
#endif

/*
	MESA_kill_tcpʵ�����ȹ���õ�ǰ���IP, TCPͷ��, 
	�����Ҫ����ָ����Ϣ, Ҳ��дһ��assistantģ��, ��ô����ipttl, ipid, tcpwin��ֵ.
	Ȼ�����__sapp_inject_pkt(), sio = SIO_EXCLUDE_THIS_LAYER_HDR.

	sapp����ֱ�Ӹ���ij��ͷ���ֶ���ô��ֵ, ��assistantģ�鸺��, sapp�����հ�����������.

	kill_remedyҲ�ǿ�assistant���ݵ�ǰseq, ����rst����seq, ���Ƶ��fd���ɹ�, ��Ҫ���׷�Ӷ���.
	����assistant����.
*/


extern int __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)
{
	char debug_log_buf[256];
	UCHAR send_stream_dir;
	const struct streaminfo_private *stream_pr = (struct streaminfo_private *)stream;
	
	if((ABBR_SAPP_LOG_LEVEL <= RLOG_LV_DEBUG) && (SIO_EXCLUDE_THIS_LAYER_HDR & sio)){
		/* injectʹ�õ���routedir, �˴�ת����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;
		}else{
			send_stream_dir = DIR_S2C; 
		}
	
		if(ADDR_TYPE_IPV4 == stream->addr.addrtype){
			const struct mesa_ip4_hdr *ip4hdr = (struct mesa_ip4_hdr *)payload;
			//inet_ntop(AF_INET, &ip4hdr->ip_src.s_addr, ipsrc_str, sizeof(ipsrc_str));
			//inet_ntop(AF_INET, &ip4hdr->ip_dst.s_addr, ipdst_str, sizeof(ipdst_str));
			sapp_runtime_log(RLOG_LV_DEBUG, "sapp_inject_pkt()->IPV4, stream:%s, send_ip_pkt_hdr:%s, stream_C2S_routedir:%d, send_routedir:%d, send_stream_dir:%d, ttl:%d, ipid:%u, ip_checksum:0x%x", 
							printaddr(&stream->addr, stream->threadnum),
							sapp_raw_ipv4_ntop(ip4hdr, debug_log_buf, sizeof(debug_log_buf)),  
							stream_pr->stream_c2s_route_dir, snd_routedir, send_stream_dir,
							ip4hdr->ip_ttl, ntohs(ip4hdr->ip_id), ntohs(ip4hdr->ip_sum));			
		}else{
			//todo ipv6;
		}
	}

	return __sapp_inject_pkt(stream, sio, payload, payload_len, snd_routedir, NULL);
}


#ifdef __cplusplus
}
#endif