第一次系统性的写blog,写的不好,请大家多多包涵。
在介绍Suricata源代码之前,大致介绍一下Suricata的工作流程。在suricata中主要使用了回调函数将所有的模块连接起来的。最后是通过DetectEngineCtx *global_de_ctx这个结构体启动起来的。整个的启动过程我用鞭炮来进行比喻,回调函数就好像鞭炮的引线一样,将所有的小的鞭炮连接起来,连接起来之后如果要放鞭炮就的要使用火柴将引线点燃。所以我将global_de_ctx比喻为火柴。在suricata中也是这样,最后通过global_de_ctx将suricata运行起来的。就好比是global_de_ctx打通了suricata的任督二脉。
DetectEngineCtx结构体在detect.h中。
typedef structDetectEngineCtx_ {
uint8_t flags;
int failure_fatal;
Signature *sig_list;
uint32_t sig_cnt;
/* version of the srep data */
uint32_t srep_version;
Signature **sig_array;
uint32_t sig_array_size; /* size in bytes*/
uint32_t sig_array_len; /* size in array members */
uint32_t signum;
/* used by the signature ordering module */
struct SCSigOrderFunc_ *sc_sig_order_funcs;
struct SCSigSignatureWrapper_*sc_sig_sig_wrapper;
/*hash table used for holding the classification config info */
HashTable *class_conf_ht;
/* hash table used for holding thereference config info */
HashTable *reference_conf_ht;
/* main sigs */
DetectEngineLookupFlowflow_gh[FLOW_STATES];
uint32_t mpm_unique, mpm_reuse, mpm_none,
mpm_uri_unique, mpm_uri_reuse,mpm_uri_none;
uint32_t gh_unique, gh_reuse;
uint32_t mpm_max_patcnt, mpm_min_patcnt,mpm_tot_patcnt,
mpm_uri_max_patcnt, mpm_uri_min_patcnt,mpm_uri_tot_patcnt;
/* init phase vars */
HashListTable *sgh_hash_table;
…….
}DetectEngineCtx;
下面还有很长没有贴出来,这个结构体非常的大。想想它确实是应该这么大的。毕竟它就是suricata的心脏嘛!
Suricata是c语言开发的,而c语言的起始点是从main()函数开始的,为了好找到入口点,所以在写代码的时候就规定了从main函数开始。而suricata的入口main函数是在suricata.c文件中。