summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2018-11-28 23:48:21 +0600
committeryangwei <[email protected]>2018-11-28 23:48:21 +0600
commitbaf1eff96552e319315967895c2a5e9db3a23fd4 (patch)
tree498d80b4e562f38f9d16ba13a3a1ef9d37983e09
parent26edec5e1555f30006af50b3fbba364bdd58b88f (diff)
UPDATE:
1.修改最外层Makefile,Werror改为Wall,以及packet_io下的Makefile保证make编译通过 2.调整CMakelist定义,和部分头文件,保证cmake编译通过
-rw-r--r--Makefile2
-rw-r--r--entry/Makefile1
-rw-r--r--include/support/dictator.h11
-rw-r--r--include/support/grule.h382
-rw-r--r--packet_io/CMakeLists.txt3
-rw-r--r--packet_io/Makefile2
-rw-r--r--support/c3_client/grule.h382
-rw-r--r--support/iknow/CMakeLists.txt12
-rw-r--r--support/iknow/src/server/CMakeLists.txt5
9 files changed, 792 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index b3e8932..c3d7a27 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ CC=g++
CCC=g++
CFLAGS =
#CFLAGS = -march=native
-CFLAGS += -g -D__FAVOR_BSD=1 -D__USE_BSD=1 -D_GNU_SOURCE=1 -Werror
+CFLAGS += -g -D__FAVOR_BSD=1 -D__USE_BSD=1 -D_GNU_SOURCE=1 -Wall
#CFLAGS += -D__FAVOR_BSD=1 -D__USE_BSD=1 -D_GNU_SOURCE=1
LIBS= -L/opt/MESA/lib
INC=-I./
diff --git a/entry/Makefile b/entry/Makefile
index 3405c6f..e25d365 100644
--- a/entry/Makefile
+++ b/entry/Makefile
@@ -57,6 +57,7 @@ CFLAGS += -DIOMODE_DPDK=1
endif
INC+=-I../include
+INC+=-I../include/support
INC+=-I../include/net
INC+=-I../dealpkt
INC += -I../packet_io
diff --git a/include/support/dictator.h b/include/support/dictator.h
index a5dd930..9ff4444 100644
--- a/include/support/dictator.h
+++ b/include/support/dictator.h
@@ -8,10 +8,6 @@
#ifdef __cplusplus
extern "C"{
#endif
-void *__real_malloc(size_t size);
-void *__real_calloc(size_t nmemb, size_t size);
-void *__real_realloc(void *ptr, size_t size);
-void __real_free(void *p);
void *__wrap_malloc(size_t size);
void __wrap_free(void *p);
@@ -22,9 +18,14 @@ void *__dictator_malloc(int t_seq,size_t size);
void __dictator_free(int t_seq,void*p);
void *__dictator_realloc(int t_seq,void *ptr, size_t size);
void *__dictator_calloc(int t_seq,size_t nmemb, size_t size);
+
+void *malloc(size_t size);
+void *calloc(size_t nmemb, size_t size);
+void *calloc(size_t nmemb, size_t size);
+void free(void *p);
+
#ifdef __cplusplus
}
#endif// end extern "C"
#endif
-
diff --git a/include/support/grule.h b/include/support/grule.h
new file mode 100644
index 0000000..7b77132
--- /dev/null
+++ b/include/support/grule.h
@@ -0,0 +1,382 @@
+#ifndef __GRULE_H
+#define __GRULE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <netinet/ip.h>
+
+typedef void * grule_hdl_t;
+//typedef void * rule_item_t;
+
+
+/*
+* ע��:
+* ���е�ַ��ṹʹ��������(�����ģʽ)��������ʹ��������
+*/
+
+#if __BYTE_ORDER != __LITTLE_ENDIAN
+#error "machine is not little-endian"
+#endif
+
+
+/*#define GRULE_TYPE_SIP 1
+#define GRULE_TYPE_SIP_DIP 5
+#define GRULE_TYPE_SIP_SPORT 9
+#define GRULE_TYPE_SIP_PROTO 257
+#define GRULE_TYPE_SIP_SPORT_PROTO 273
+#define GRULE_TYPE_SIP_DPORT 65
+#define GRULE_TYPE_SIP_DPORT_PROTO 321
+#define GRULE_TYPE_SIP_DIP_PROTO 261
+#define GRULE_TYPE_DIP 4
+#define GRULE_TYPE_DIP_DPORT 68
+#define GRULE_TYPE_DIP_DPORT_PROTO 324
+#define GRULE_TYPE_DIP_PROTO 260
+#define GRULE_TYPE_DIP_SPORT_PROTO 276
+*/
+
+typedef union{
+ struct{
+ uint16_t sip_flag:1;
+ uint16_t sipmsk_flag:1;
+ uint16_t dip_flag:1;
+ uint16_t dipmsk_flag:1;
+ uint16_t sport_flag:1;
+ uint16_t spmsk_flag:1;
+ uint16_t dport_flag:1;
+ uint16_t dpmsk_flag:1;
+ uint16_t proto_flag:1;
+ uint16_t pmsk_flag:1;
+ uint16_t resv:6; // resv must be zero
+ };
+ uint16_t grule_type;
+}grule_type_t;
+
+
+
+
+typedef uint32_t ip4_addr_t;
+typedef uint16_t port_t;
+typedef union{
+ unsigned long ip6_l[2];
+ unsigned int ip6_i[4];
+ unsigned char ip6_c[16];
+}ip6_addr_t;
+
+
+typedef struct{
+ ip4_addr_t sip;
+ ip4_addr_t dip;
+ port_t sport;
+ port_t dport;
+ uint8_t proto;
+}simple4_rule_t;
+
+typedef struct{
+ ip6_addr_t sip;
+ ip6_addr_t dip;
+ port_t sport;
+ port_t dport;
+ uint8_t proto;
+}simple6_rule_t;
+
+typedef struct{
+ ip4_addr_t sip;
+ ip4_addr_t sip_mask;
+ ip4_addr_t dip;
+ ip4_addr_t dip_mask;
+ port_t sport;
+ port_t sport_mask;
+ port_t dport;
+ port_t dport_mask;
+ uint8_t proto;
+ uint8_t proto_mask;
+}mask4_rule_t;
+
+
+typedef struct{
+ ip6_addr_t sip;
+ ip6_addr_t sip_mask;
+ ip6_addr_t dip;
+ ip6_addr_t dip_mask;
+ port_t sport;
+ port_t sport_mask;
+ port_t dport;
+ port_t dport_mask;
+ uint8_t proto;
+ uint8_t proto_mask;
+}mask6_rule_t;
+
+
+#define GRULE_BIG_TYPE_SIMPLE4 1
+#define GRULE_BIG_TYPE_SIMPLE6 2
+#define GRULE_BIG_TYPE_MASK4 3
+#define GRULE_BIG_TYPE_MASK6 4
+
+#define GRULE_ACTION_ADD 1
+#define GRULE_ACTION_DEL 2
+
+typedef struct{
+ uint64_t rule_id;// rule uniq id
+ uint32_t srv_type; // rule service type
+ uint32_t rule_scope; // rule scope, such as all of carrier, China unicom
+ uint16_t big_type; // GRULE_BIG_TYPE_SIMPLE4, GRULE_BIG_TYPE_SIMPLE6, GRULE_BIG_TYPE_MASK4,
+ uint16_t durable; // rule is durable
+ uint16_t action; // add or delete
+ grule_type_t rule_type;
+ union{
+ simple4_rule_t s4;
+ simple6_rule_t s6;
+ mask4_rule_t m4;
+ mask6_rule_t m6;
+ };
+}grule_t;
+
+
+
+#define GRULE_SOL_PROTO 1
+
+#define GRULE_TYPE_AUTH 1
+#define GRULE_TYPE_NONBLOCK 2
+
+#define GRULE_OK 0
+#define GRULE_ERR -1
+
+#define GRULE_ERRNO_AGAIN 99
+#define GRULE_ERRNO_BAD_RULE 100
+#define GRULE_ERRNO_BAD_OPT 101
+#define GRULE_ERRNO_BAD_CONNECTION 102
+#define GRULE_ERRNO_AUTH 103
+
+#define GRULE_RESP_OK 0
+#define GRULE_RESP_WHITELIST 1
+
+
+typedef struct{
+ //uint64_t rule_id;
+ uint32_t result;
+}grule_result_t;
+
+
+
+/*
+* return 0, if rule is ok. otherwise rule is bad.
+*/
+int grule_check_rule(const grule_t * rule);
+
+
+/*#define GRULE_APP_STATUS_AUTHING 1 // authenticaing, it cannot send data;
+#define GRULE_APP_STATUS_AUTH_ERROR 2
+//#define GRULE_APP_STATUS_AUTH_SUCC
+#define GRULE_APP_STATUS_CONNECTED 3 // connected, send all durable rules;
+#define GRULE_APP_STATUS_ACTIVE 4 // active, send one rule;
+#define GRULE_APP_STATUS_CLOSE 5 // close.
+*/
+
+
+#define GRULE_APP_STATUS_IDLE 1
+#define GRULE_APP_STATUS_CONNECTED 2
+#define GRULE_APP_STATUS_ACTIVE 3
+
+
+//int grule_restart(grule_hdl_t hdl);
+
+
+/*
+get app status
+ return -1 if it failed, otherwise return status
+*/
+int grule_app_status(grule_hdl_t hdl);
+
+/*
+ init grule handle
+*/
+grule_hdl_t grule_open();
+
+/*
+ get option value of rule handle, including rule handle, tcp.
+ return 0 if it succeded, otherwise -1. grule_errno() indicates the detailed error.
+*/
+int grule_opt_get(grule_hdl_t hdl, int level, int type, void * opt, size_t opt_size);
+
+
+/*
+* set option of rule handle
+return 0 if it succeded, otherwise -1. grule_errno() indicates the detailed error.
+
+*/
+int grule_opt_set(grule_hdl_t hdl, int level, int type, const void * opt, size_t opt_size);
+
+/*
+* connect server;
+return 0 if it succeded, otherwise -1. grule_errno() indicates the detailed error.
+
+*/
+int grule_connect(grule_hdl_t hdl, const char * addr);
+
+/*
+* send rules, flags=0
+* return > 1 if it succeded, 0: connecting state, try again, <0 rule error
+
+*/
+int grule_send(grule_hdl_t hdl, grule_t *rules, size_t rule_num, int flags);
+
+
+/*
+* recieve result;flags=0
+* return 0 if it succeded, otherwise -1. grule_errno() indicates the detailed error.
+*/
+int grule_recv(grule_hdl_t hdl, grule_result_t *rst, size_t rst_num, int flags);
+
+/*
+* get error info of result;
+*/
+const char * grule_bad_results_str(grule_result_t *rst);
+
+const char * grule_error_str(int err_no);
+
+int grule_errno(grule_hdl_t hdl);
+
+/*
+* release hdl
+*/
+int grule_close(grule_hdl_t hdl);
+
+void parse_rule(grule_t * rule);
+
+char * parse_rule_str(grule_t * rule, char * buf, size_t *size);
+char * parse_rule_str_full(grule_t * rule, char * buf, size_t *size);
+
+//usage
+
+#if 0
+
+#define CCC_MAX_SIZE 16
+int grule_service()
+{
+ grule_hdl_t handle;
+ const char *ccc_list[CCC_MAX_SIZE]; //it should be inited.
+ size_t ccc_num = 8;
+ size_t ccc_index = 0;
+ int state;
+ uint8_t auth_data[8]; // it should be inited
+ int ret;
+ size_t auth_err_num;
+ size_t i;
+
+ grule_t rule_list[16];
+ grule_result_t rst_list[16];
+ uint64_t rule_num;
+
+ #define SERVICE_STATE_IDLE 1
+ #define SERVICE_STATE_FIRSTCONNECT 2
+ #define SERVICE_STATE_CONNECTED 3
+ //#define SERVICE_STATE_
+
+ state = SERVICE_STATE_IDLE;
+ auth_err_num = 0;
+ handle = NULL;
+ while(1){
+
+ switch(state){
+ case SERVICE_STATE_IDLE:
+ handle = grule_open();
+ if(handle == NULL){
+ fprintf(stderr, "grule lib error\n");
+ abort();
+ }
+ grule_opt_set(handle, GRULE_SOL_PROTO, GRULE_TYPE_AUTH, auth_data, sizeof(auth_data));
+ ret = grule_connect(handle, ccc_list[ccc_index]);
+ ccc_index = (ccc_index + 1) % ccc_num;
+ if(ret == 0){
+ state = SERVICE_STATE_FIRSTCONNECT;
+ auth_err_num = 0;
+ continue;
+ }
+ if(grule_errno(handle) == GRULE_ERRNO_AUTH){
+ auth_err_num++;
+ if(auth_err_num >= ccc_num){
+ fprintf(stderr, "auth error\n");
+ abort();
+ }
+ // stop the program if trying many times
+ }else{
+ fprintf(stderr, "connect error: %s\n", grule_error_str(grule_errno(handle)));
+ }
+ goto _error;
+ break;
+ case SERVICE_STATE_FIRSTCONNECT:
+ // if having durable rules, send all of them.
+ state = SERVICE_STATE_CONNECTED;
+ break;
+ //break;
+ case SERVICE_STATE_CONNECTED:
+ //
+ while(1){
+ // has rule?????
+
+ memset(rule_list, 0, sizeof(rule_list));
+ // init
+ // set rule;
+ // sending
+ ret = grule_send(handle, rule_list, rule_num, 0);
+ if(ret != rule_num){
+ fprintf(stderr, "sending error: %s\n", grule_error_str(grule_errno(handle)));
+ goto _error;
+ }
+
+ ret = grule_recv(handle, rst_list, rule_num, 0);
+ if(ret != rule_num){
+ fprintf(stderr, "recv error: %s\n", grule_error_str(grule_errno(handle)));
+ goto _error;
+ }
+
+ for(i = 0; i < rule_num; i++){
+ if(rst_list[i].result != GRULE_RESP_OK && rst_list[i].result != GRULE_RESP_WHITELIST){ // rule is wrong.
+ fprintf(stderr, "rulerror: %s\n", grule_bad_results_str(&rst_list[i]));
+ abort();// fatal error.
+ }
+ }
+ }
+ break;
+ default:
+ fprintf(stderr, "bad state: %d\n", state);
+ abort();
+ break;
+ }
+ _noerror:
+ continue;
+ _error:
+ if(handle != NULL){
+ grule_close(handle);
+ }
+ sleep(2);
+ state = SERVICE_STATE_IDLE;
+
+ }
+}
+
+#endif
+
+
+#define RULE_SIP 0x0001
+#define RULE_SIPMASK 0x0002
+#define RULE_DIP 0x0004
+#define RULE_DIPMASK 0x0008
+#define RULE_SPORT 0x0010
+#define RULE_SPMASK 0x0020
+#define RULE_DPORT 0x0040
+#define RULE_DPMASK 0x0080
+#define RULE_PROTO 0x0100
+#define RULE_PMASK 0x0200
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
+
diff --git a/packet_io/CMakeLists.txt b/packet_io/CMakeLists.txt
index f2a3b76..5c6233b 100644
--- a/packet_io/CMakeLists.txt
+++ b/packet_io/CMakeLists.txt
@@ -41,7 +41,8 @@ endif()
set(PACKET_IO_STATIC_SOURCE cycle_pkt_dump_through_write_offset.c packet_io_lib_load.c pkt_dispatch_new.c
iknow_info.c packet_io_log.c sendpacket.c
sendpacket_wrap.c packet_io.c packet_io_device.c
-packet_io_status_by_mesafs.cpp packet_io_status.cpp packet_io_status_new.c )
+#packet_io_status_by_mesafs.cpp packet_io_status.cpp packet_io_status_new.c )
+packet_io_status.cpp packet_io_status_new.c )
add_library(packet_io STATIC ${PACKET_IO_STATIC_SOURCE})
diff --git a/packet_io/Makefile b/packet_io/Makefile
index ab95f57..5787d2d 100644
--- a/packet_io/Makefile
+++ b/packet_io/Makefile
@@ -96,7 +96,7 @@ OBJS+=packet_io_status.o
OBJS+=packet_io_status_new.o
#OBJS += cycle_pkt_dump.o
#OBJS += cycle_pkt_dump_unix.o
-OBJS += cycle_pkt_dump_through_write.o
+OBJS += cycle_pkt_dump_through_write_offset.o
OBJS += packet_io_device.o
OBJS += sapp_compat_wangyan_api.o
diff --git a/support/c3_client/grule.h b/support/c3_client/grule.h
new file mode 100644
index 0000000..7b77132
--- /dev/null
+++ b/support/c3_client/grule.h
@@ -0,0 +1,382 @@
+#ifndef __GRULE_H
+#define __GRULE_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <netinet/ip.h>
+
+typedef void * grule_hdl_t;
+//typedef void * rule_item_t;
+
+
+/*
+* ע��:
+* ���е�ַ��ṹʹ��������(�����ģʽ)��������ʹ��������
+*/
+
+#if __BYTE_ORDER != __LITTLE_ENDIAN
+#error "machine is not little-endian"
+#endif
+
+
+/*#define GRULE_TYPE_SIP 1
+#define GRULE_TYPE_SIP_DIP 5
+#define GRULE_TYPE_SIP_SPORT 9
+#define GRULE_TYPE_SIP_PROTO 257
+#define GRULE_TYPE_SIP_SPORT_PROTO 273
+#define GRULE_TYPE_SIP_DPORT 65
+#define GRULE_TYPE_SIP_DPORT_PROTO 321
+#define GRULE_TYPE_SIP_DIP_PROTO 261
+#define GRULE_TYPE_DIP 4
+#define GRULE_TYPE_DIP_DPORT 68
+#define GRULE_TYPE_DIP_DPORT_PROTO 324
+#define GRULE_TYPE_DIP_PROTO 260
+#define GRULE_TYPE_DIP_SPORT_PROTO 276
+*/
+
+typedef union{
+ struct{
+ uint16_t sip_flag:1;
+ uint16_t sipmsk_flag:1;
+ uint16_t dip_flag:1;
+ uint16_t dipmsk_flag:1;
+ uint16_t sport_flag:1;
+ uint16_t spmsk_flag:1;
+ uint16_t dport_flag:1;
+ uint16_t dpmsk_flag:1;
+ uint16_t proto_flag:1;
+ uint16_t pmsk_flag:1;
+ uint16_t resv:6; // resv must be zero
+ };
+ uint16_t grule_type;
+}grule_type_t;
+
+
+
+
+typedef uint32_t ip4_addr_t;
+typedef uint16_t port_t;
+typedef union{
+ unsigned long ip6_l[2];
+ unsigned int ip6_i[4];
+ unsigned char ip6_c[16];
+}ip6_addr_t;
+
+
+typedef struct{
+ ip4_addr_t sip;
+ ip4_addr_t dip;
+ port_t sport;
+ port_t dport;
+ uint8_t proto;
+}simple4_rule_t;
+
+typedef struct{
+ ip6_addr_t sip;
+ ip6_addr_t dip;
+ port_t sport;
+ port_t dport;
+ uint8_t proto;
+}simple6_rule_t;
+
+typedef struct{
+ ip4_addr_t sip;
+ ip4_addr_t sip_mask;
+ ip4_addr_t dip;
+ ip4_addr_t dip_mask;
+ port_t sport;
+ port_t sport_mask;
+ port_t dport;
+ port_t dport_mask;
+ uint8_t proto;
+ uint8_t proto_mask;
+}mask4_rule_t;
+
+
+typedef struct{
+ ip6_addr_t sip;
+ ip6_addr_t sip_mask;
+ ip6_addr_t dip;
+ ip6_addr_t dip_mask;
+ port_t sport;
+ port_t sport_mask;
+ port_t dport;
+ port_t dport_mask;
+ uint8_t proto;
+ uint8_t proto_mask;
+}mask6_rule_t;
+
+
+#define GRULE_BIG_TYPE_SIMPLE4 1
+#define GRULE_BIG_TYPE_SIMPLE6 2
+#define GRULE_BIG_TYPE_MASK4 3
+#define GRULE_BIG_TYPE_MASK6 4
+
+#define GRULE_ACTION_ADD 1
+#define GRULE_ACTION_DEL 2
+
+typedef struct{
+ uint64_t rule_id;// rule uniq id
+ uint32_t srv_type; // rule service type
+ uint32_t rule_scope; // rule scope, such as all of carrier, China unicom
+ uint16_t big_type; // GRULE_BIG_TYPE_SIMPLE4, GRULE_BIG_TYPE_SIMPLE6, GRULE_BIG_TYPE_MASK4,
+ uint16_t durable; // rule is durable
+ uint16_t action; // add or delete
+ grule_type_t rule_type;
+ union{
+ simple4_rule_t s4;
+ simple6_rule_t s6;
+ mask4_rule_t m4;
+ mask6_rule_t m6;
+ };
+}grule_t;
+
+
+
+#define GRULE_SOL_PROTO 1
+
+#define GRULE_TYPE_AUTH 1
+#define GRULE_TYPE_NONBLOCK 2
+
+#define GRULE_OK 0
+#define GRULE_ERR -1
+
+#define GRULE_ERRNO_AGAIN 99
+#define GRULE_ERRNO_BAD_RULE 100
+#define GRULE_ERRNO_BAD_OPT 101
+#define GRULE_ERRNO_BAD_CONNECTION 102
+#define GRULE_ERRNO_AUTH 103
+
+#define GRULE_RESP_OK 0
+#define GRULE_RESP_WHITELIST 1
+
+
+typedef struct{
+ //uint64_t rule_id;
+ uint32_t result;
+}grule_result_t;
+
+
+
+/*
+* return 0, if rule is ok. otherwise rule is bad.
+*/
+int grule_check_rule(const grule_t * rule);
+
+
+/*#define GRULE_APP_STATUS_AUTHING 1 // authenticaing, it cannot send data;
+#define GRULE_APP_STATUS_AUTH_ERROR 2
+//#define GRULE_APP_STATUS_AUTH_SUCC
+#define GRULE_APP_STATUS_CONNECTED 3 // connected, send all durable rules;
+#define GRULE_APP_STATUS_ACTIVE 4 // active, send one rule;
+#define GRULE_APP_STATUS_CLOSE 5 // close.
+*/
+
+
+#define GRULE_APP_STATUS_IDLE 1
+#define GRULE_APP_STATUS_CONNECTED 2
+#define GRULE_APP_STATUS_ACTIVE 3
+
+
+//int grule_restart(grule_hdl_t hdl);
+
+
+/*
+get app status
+ return -1 if it failed, otherwise return status
+*/
+int grule_app_status(grule_hdl_t hdl);
+
+/*
+ init grule handle
+*/
+grule_hdl_t grule_open();
+
+/*
+ get option value of rule handle, including rule handle, tcp.
+ return 0 if it succeded, otherwise -1. grule_errno() indicates the detailed error.
+*/
+int grule_opt_get(grule_hdl_t hdl, int level, int type, void * opt, size_t opt_size);
+
+
+/*
+* set option of rule handle
+return 0 if it succeded, otherwise -1. grule_errno() indicates the detailed error.
+
+*/
+int grule_opt_set(grule_hdl_t hdl, int level, int type, const void * opt, size_t opt_size);
+
+/*
+* connect server;
+return 0 if it succeded, otherwise -1. grule_errno() indicates the detailed error.
+
+*/
+int grule_connect(grule_hdl_t hdl, const char * addr);
+
+/*
+* send rules, flags=0
+* return > 1 if it succeded, 0: connecting state, try again, <0 rule error
+
+*/
+int grule_send(grule_hdl_t hdl, grule_t *rules, size_t rule_num, int flags);
+
+
+/*
+* recieve result;flags=0
+* return 0 if it succeded, otherwise -1. grule_errno() indicates the detailed error.
+*/
+int grule_recv(grule_hdl_t hdl, grule_result_t *rst, size_t rst_num, int flags);
+
+/*
+* get error info of result;
+*/
+const char * grule_bad_results_str(grule_result_t *rst);
+
+const char * grule_error_str(int err_no);
+
+int grule_errno(grule_hdl_t hdl);
+
+/*
+* release hdl
+*/
+int grule_close(grule_hdl_t hdl);
+
+void parse_rule(grule_t * rule);
+
+char * parse_rule_str(grule_t * rule, char * buf, size_t *size);
+char * parse_rule_str_full(grule_t * rule, char * buf, size_t *size);
+
+//usage
+
+#if 0
+
+#define CCC_MAX_SIZE 16
+int grule_service()
+{
+ grule_hdl_t handle;
+ const char *ccc_list[CCC_MAX_SIZE]; //it should be inited.
+ size_t ccc_num = 8;
+ size_t ccc_index = 0;
+ int state;
+ uint8_t auth_data[8]; // it should be inited
+ int ret;
+ size_t auth_err_num;
+ size_t i;
+
+ grule_t rule_list[16];
+ grule_result_t rst_list[16];
+ uint64_t rule_num;
+
+ #define SERVICE_STATE_IDLE 1
+ #define SERVICE_STATE_FIRSTCONNECT 2
+ #define SERVICE_STATE_CONNECTED 3
+ //#define SERVICE_STATE_
+
+ state = SERVICE_STATE_IDLE;
+ auth_err_num = 0;
+ handle = NULL;
+ while(1){
+
+ switch(state){
+ case SERVICE_STATE_IDLE:
+ handle = grule_open();
+ if(handle == NULL){
+ fprintf(stderr, "grule lib error\n");
+ abort();
+ }
+ grule_opt_set(handle, GRULE_SOL_PROTO, GRULE_TYPE_AUTH, auth_data, sizeof(auth_data));
+ ret = grule_connect(handle, ccc_list[ccc_index]);
+ ccc_index = (ccc_index + 1) % ccc_num;
+ if(ret == 0){
+ state = SERVICE_STATE_FIRSTCONNECT;
+ auth_err_num = 0;
+ continue;
+ }
+ if(grule_errno(handle) == GRULE_ERRNO_AUTH){
+ auth_err_num++;
+ if(auth_err_num >= ccc_num){
+ fprintf(stderr, "auth error\n");
+ abort();
+ }
+ // stop the program if trying many times
+ }else{
+ fprintf(stderr, "connect error: %s\n", grule_error_str(grule_errno(handle)));
+ }
+ goto _error;
+ break;
+ case SERVICE_STATE_FIRSTCONNECT:
+ // if having durable rules, send all of them.
+ state = SERVICE_STATE_CONNECTED;
+ break;
+ //break;
+ case SERVICE_STATE_CONNECTED:
+ //
+ while(1){
+ // has rule?????
+
+ memset(rule_list, 0, sizeof(rule_list));
+ // init
+ // set rule;
+ // sending
+ ret = grule_send(handle, rule_list, rule_num, 0);
+ if(ret != rule_num){
+ fprintf(stderr, "sending error: %s\n", grule_error_str(grule_errno(handle)));
+ goto _error;
+ }
+
+ ret = grule_recv(handle, rst_list, rule_num, 0);
+ if(ret != rule_num){
+ fprintf(stderr, "recv error: %s\n", grule_error_str(grule_errno(handle)));
+ goto _error;
+ }
+
+ for(i = 0; i < rule_num; i++){
+ if(rst_list[i].result != GRULE_RESP_OK && rst_list[i].result != GRULE_RESP_WHITELIST){ // rule is wrong.
+ fprintf(stderr, "rulerror: %s\n", grule_bad_results_str(&rst_list[i]));
+ abort();// fatal error.
+ }
+ }
+ }
+ break;
+ default:
+ fprintf(stderr, "bad state: %d\n", state);
+ abort();
+ break;
+ }
+ _noerror:
+ continue;
+ _error:
+ if(handle != NULL){
+ grule_close(handle);
+ }
+ sleep(2);
+ state = SERVICE_STATE_IDLE;
+
+ }
+}
+
+#endif
+
+
+#define RULE_SIP 0x0001
+#define RULE_SIPMASK 0x0002
+#define RULE_DIP 0x0004
+#define RULE_DIPMASK 0x0008
+#define RULE_SPORT 0x0010
+#define RULE_SPMASK 0x0020
+#define RULE_DPORT 0x0040
+#define RULE_DPMASK 0x0080
+#define RULE_PROTO 0x0100
+#define RULE_PMASK 0x0200
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif
+
diff --git a/support/iknow/CMakeLists.txt b/support/iknow/CMakeLists.txt
new file mode 100644
index 0000000..24e43eb
--- /dev/null
+++ b/support/iknow/CMakeLists.txt
@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 2.8)
+
+#include_directories(${CMAKE_SOURCE_DIR}/packet_io)
+#include_directories(${CMAKE_SOURCE_DIR}/project)
+#include_directories(${CMAKE_SOURCE_DIR}/include)
+#include_directories(${CMAKE_SOURCE_DIR}/include/support)
+include_directories(./include)
+
+add_definitions(-D_BSD_SOURCE -D_BSD_SOURCE -D__BSD_SOURCE -D__FAVOR_BSD -DHAVE_NET_ETHERNET_H)
+
+add_library(iknow STATIC src/server/iknow_cmd_parser.c
+ src/server/iknow_server.c src/server/iknow_task_scheduler.c)
diff --git a/support/iknow/src/server/CMakeLists.txt b/support/iknow/src/server/CMakeLists.txt
new file mode 100644
index 0000000..de60fde
--- /dev/null
+++ b/support/iknow/src/server/CMakeLists.txt
@@ -0,0 +1,5 @@
+#include_directories(${CMAKE_SOURCE_DIR}/packet_io)
+#include_directories(${CMAKE_SOURCE_DIR}/project)
+#include_directories(${CMAKE_SOURCE_DIR}/include)
+#include_directories(${CMAKE_SOURCE_DIR}/include/support)
+add_subdirectory(server)