亦庄编译通过版本
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
@@ -1096,8 +1097,11 @@ extern "C" char kni_ipv6_entry(const struct streaminfo *pstream,unsigned char ro
|
|||||||
addr.paddr = (void*)(&ipv6_addr);
|
addr.paddr = (void*)(&ipv6_addr);
|
||||||
|
|
||||||
memset(&ipv6_addr,0,sizeof(ipv6_addr));
|
memset(&ipv6_addr,0,sizeof(ipv6_addr));
|
||||||
ipv6_addr.saddr=ipv6_hdr->ip6_src;
|
memcpy(ipv6_addr.saddr,&(ipv6_hdr->ip6_src),sizeof(ipv6_addr.saddr));
|
||||||
ipv6_addr.daddr=ipv6_hdr->ip6_dst;
|
memcpy(ipv6_addr.daddr,&(ipv6_hdr->ip6_dst),sizeof(ipv6_addr.saddr));
|
||||||
|
|
||||||
|
// ipv6_addr.saddr=ipv6_hdr->ip6_src.s6_addr32;
|
||||||
|
// ipv6_addr.daddr=ipv6_hdr->ip6_dst.s6_addr32;
|
||||||
|
|
||||||
memset(&pmeinfo,0,sizeof(pmeinfo));
|
memset(&pmeinfo,0,sizeof(pmeinfo));
|
||||||
pmeinfo.mid = mid;
|
pmeinfo.mid = mid;
|
||||||
@@ -1528,7 +1532,6 @@ extern "C" char kni_init()
|
|||||||
pthread_t pid_kni_filestat2;
|
pthread_t pid_kni_filestat2;
|
||||||
|
|
||||||
g_kni_comminfo.tun_threadnum = g_iThreadNum;
|
g_kni_comminfo.tun_threadnum = g_iThreadNum;
|
||||||
// g_kni_comminfo.tun_threadnum = 5;
|
|
||||||
|
|
||||||
|
|
||||||
init_profile_info();
|
init_profile_info();
|
||||||
|
|||||||
@@ -75,7 +75,7 @@
|
|||||||
#define KNI_MAIN_MODE "main"
|
#define KNI_MAIN_MODE "main"
|
||||||
#define KNI_FS_MODE "field_stat"
|
#define KNI_FS_MODE "field_stat"
|
||||||
#define KNI_DYNMAAT_MODE "dynmic_maat"
|
#define KNI_DYNMAAT_MODE "dynmic_maat"
|
||||||
#define KNI_STATIC_MAAT_MODE "static_maat"
|
#define KNI_STATIC_MAAT_MODE "static_maat"
|
||||||
#define KNI_TUN_MODE "tun"
|
#define KNI_TUN_MODE "tun"
|
||||||
#define KNI_CONF_MODE "Module"
|
#define KNI_CONF_MODE "Module"
|
||||||
#define KNI_CONF_FILENAME_MAIN "./conf/main.conf"
|
#define KNI_CONF_FILENAME_MAIN "./conf/main.conf"
|
||||||
|
|||||||
@@ -30,11 +30,13 @@ size_t add_option(char* buff, size_t size, uint16_t opt_type, uint16_t opt_len,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*((uint16_t*)buff)=opt_type;
|
*((uint16_t*)buff)=opt_type;
|
||||||
*((uint16_t*)(buff+sizeof(uint16_t))=opt_len;
|
*((uint16_t*)(buff+sizeof(uint16_t)))=opt_len;
|
||||||
memcpy(buff+sizeof(uint16_t)*2, opt_cont, opt_len);
|
memcpy(buff+sizeof(uint16_t)*2, opt_cont, opt_len);
|
||||||
return opt_len+sizeof(uint16_t)*2;
|
return opt_len+sizeof(uint16_t)*2;
|
||||||
}
|
}
|
||||||
int kni_set_tlvinfo(char* buf, int buflen, struct kni_lqueue_datainfo datainfo)
|
|
||||||
|
|
||||||
|
int kni_set_tlvinfo(char* buf, int buflen, struct kni_repaired_fds datainfo)
|
||||||
{
|
{
|
||||||
int tlv_len = 0;
|
int tlv_len = 0;
|
||||||
|
|
||||||
@@ -45,10 +47,10 @@ int kni_set_tlvinfo(char* buf, int buflen, struct kni_lqueue_datainfo datainfo)
|
|||||||
|
|
||||||
tlv_len += sizeof(struct kni_tlv_header);
|
tlv_len += sizeof(struct kni_tlv_header);
|
||||||
|
|
||||||
tlv_len+=add_option(buf+tlv_len,buflen-tlv_len, KNI_TLV_TYPE_PROTOCOL, (uint16_t)sizeof(int), &(datainfo.protocol));
|
tlv_len+=add_option(buf+tlv_len,buflen-tlv_len, KNI_TLV_TYPE_PROTOCOL, (uint16_t)sizeof(int), (char*)&(datainfo.protocol));
|
||||||
tlv_len+=add_option(buf+tlv_len,buflen-tlv_len, KNI_TLV_TYPE_KEYRING_ID, (uint16_t)sizeof(int), &(datainfo.keyring));
|
tlv_len+=add_option(buf+tlv_len,buflen-tlv_len, KNI_TLV_TYPE_KEYRING_ID, (uint16_t)sizeof(int), (char*)&(datainfo.keyring));
|
||||||
|
|
||||||
assert(tlv_len=<buflen);
|
assert(tlv_len<=buflen);
|
||||||
|
|
||||||
return tlv_len;
|
return tlv_len;
|
||||||
|
|
||||||
@@ -278,6 +280,37 @@ int tun_error(int i,int* fds)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int tun_alloc(char *dev)
|
||||||
|
{
|
||||||
|
struct ifreq ifr;
|
||||||
|
int fd, err;
|
||||||
|
|
||||||
|
if ((fd = open("/dev/net/tun", O_RDWR)) < 0)
|
||||||
|
{
|
||||||
|
printf("open function errno %d is %s\n",errno,strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
|
ifr.ifr_flags = IFF_TUN | IFF_NO_PI;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>tun<75><6E><EFBFBD><EFBFBD>Ϣ
|
||||||
|
|
||||||
|
if (*dev)
|
||||||
|
{
|
||||||
|
strncpy(ifr.ifr_name, dev, IFNAMSIZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0)
|
||||||
|
{
|
||||||
|
printf("ioctl function err is %d,errno %d is %s\n",err,errno,strerror(errno));
|
||||||
|
close(fd);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
strcpy(dev, ifr.ifr_name);
|
||||||
|
|
||||||
|
return fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Flags: IFF_TUN - TUN device (no Ethernet headers)
|
/* Flags: IFF_TUN - TUN device (no Ethernet headers)
|
||||||
* IFF_TAP - TAP device
|
* IFF_TAP - TAP device
|
||||||
@@ -351,7 +384,6 @@ int tun_alloc_mq(char *dev, int queues, int *fds,char* tun_path)
|
|||||||
MESA_load_profile_string_def((char*)KNI_CONF_FILENAME,(char*)KNI_TUN_MODE,(char*)"tun_name",g_kni_comminfo.tun_name,KNI_CONF_MAXLEN,"tun0");
|
MESA_load_profile_string_def((char*)KNI_CONF_FILENAME,(char*)KNI_TUN_MODE,(char*)"tun_name",g_kni_comminfo.tun_name,KNI_CONF_MAXLEN,"tun0");
|
||||||
|
|
||||||
|
|
||||||
// g_kni_comminfo.tun_threadnum=g_iThreadNum;
|
|
||||||
if(g_kni_comminfo.tun_threadnum<=0)
|
if(g_kni_comminfo.tun_threadnum<=0)
|
||||||
{
|
{
|
||||||
MESA_handle_runtime_log(g_kni_comminfo.logger, RLOG_LV_FATAL,KNI_MODULE_INIT,"thread_num:%d,action:%s",g_kni_comminfo.thread_num,KNI_ACTION_EXIT);
|
MESA_handle_runtime_log(g_kni_comminfo.logger, RLOG_LV_FATAL,KNI_MODULE_INIT,"thread_num:%d,action:%s",g_kni_comminfo.thread_num,KNI_ACTION_EXIT);
|
||||||
@@ -359,6 +391,7 @@ int tun_alloc_mq(char *dev, int queues, int *fds,char* tun_path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_kni_comminfo.fd_tun=ALLOC(int, g_kni_comminfo.tun_threadnum);
|
g_kni_comminfo.fd_tun=ALLOC(int, g_kni_comminfo.tun_threadnum);
|
||||||
|
|
||||||
|
|
||||||
ret=tun_alloc_mq(g_kni_comminfo.tun_name,g_kni_comminfo.tun_threadnum,g_kni_comminfo.fd_tun,tun_path);
|
ret=tun_alloc_mq(g_kni_comminfo.tun_name,g_kni_comminfo.tun_threadnum,g_kni_comminfo.fd_tun,tun_path);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#define KNI_SENDFD_NUM 2
|
#define KNI_SENDFD_NUM 2
|
||||||
|
|
||||||
int kni_send_fds(int socket, int *fds, int n,int protocol);
|
int kni_send_fds(int socket, int *fds, int n,int protocol);
|
||||||
char tun_write_data(int fd,char* send_buf,int send_buflen,struct streaminfo* pstream,int thread_seq);
|
char tun_write_data(int fd, const char* send_buf, size_t send_buflen,struct streaminfo* pstream,int thread_seq);
|
||||||
char tun_write_data_listq(int fd,char* send_buf,int send_buflen,int thread_seq);
|
char tun_write_data_listq(int fd,char* send_buf,int send_buflen,int thread_seq);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ int kni_build_send_ipv4(unsigned char dir,int thread_seq,struct ip* a_packet,str
|
|||||||
unsigned short sendbuf_len = 0;
|
unsigned short sendbuf_len = 0;
|
||||||
int tmp_len = 0;
|
int tmp_len = 0;
|
||||||
|
|
||||||
pos = memmem(payload, payload_len,replace_info->find, replace_info->original_len);
|
pos = (char*)memmem(payload, payload_len,(replace_info->find), replace_info->original_len);
|
||||||
if(pos != NULL)
|
if(pos != NULL)
|
||||||
{
|
{
|
||||||
sendbuf_len = iplen - replace_info->original_len + replace_info->replace_len;
|
sendbuf_len = iplen - replace_info->original_len + replace_info->replace_len;
|
||||||
|
|||||||
Reference in New Issue
Block a user