suricata運(yùn)行模式

1.與運(yùn)行模式相關(guān)數(shù)據(jù)結(jié)構(gòu)

typedef struct RunMode_ {

? ? /* the runmode type */

? ? int runmode;

? ? const char *name;

? ? const char *description;

? ? /* runmode function */

? ? int (*RunModeFunc)(void);

} RunMode;


typedef struct RunModes_ {

? ? int no_of_runmodes;

? ? RunMode *runmodes;

} RunModes;

static RunModes runmodes[RUNMODE_USER_MAX];


/* Run mode */

enum RunModes {

? ? RUNMODE_UNKNOWN = 0,

? ? RUNMODE_PCAP_DEV,

? ? RUNMODE_PCAP_FILE,

? ? RUNMODE_PFRING,

? ? RUNMODE_NFQ,

? ? RUNMODE_NFLOG,

? ? RUNMODE_IPFW,

? ? RUNMODE_ERF_FILE,

? ? RUNMODE_DAG,

? ? RUNMODE_AFP_DEV,

? ? RUNMODE_NETMAP,

? ? RUNMODE_TILERA_MPIPE,

? ? RUNMODE_UNITTEST,

? ? RUNMODE_NAPATECH,

? ? RUNMODE_UNIX_SOCKET,

? ? RUNMODE_WINDIVERT,

? ? RUNMODE_USER_MAX, /* Last standard running mode */

? ? RUNMODE_LIST_KEYWORDS,

? ? RUNMODE_LIST_APP_LAYERS,

? ? RUNMODE_LIST_RUNMODES,

? ? RUNMODE_PRINT_VERSION,

? ? RUNMODE_PRINT_BUILDINFO,

? ? RUNMODE_PRINT_USAGE,

? ? RUNMODE_DUMP_CONFIG, /*將從配置文件加載的配置轉(zhuǎn)儲(chǔ)到終端并退出*/

? ? RUNMODE_CONF_TEST,

? ? RUNMODE_LIST_UNITTEST,

? ? RUNMODE_ENGINE_ANALYSIS,

#ifdef OS_WIN32

? ? RUNMODE_INSTALL_SERVICE,

? ? RUNMODE_REMOVE_SERVICE,

? ? RUNMODE_CHANGE_SERVICE_PARAMS,

#endif

? ? RUNMODE_MAX,

};

2.運(yùn)行模式注冊

void RunModeRegisterRunModes(void)

{

? ? memset(runmodes, 0, sizeof(runmodes));

? ? RunModeIdsPcapRegister();

? ? RunModeFilePcapRegister();

? ? RunModeIdsPfringRegister();

? ? RunModeIpsNFQRegister();

? ? RunModeIpsIPFWRegister();

? ? RunModeErfFileRegister();

? ? RunModeErfDagRegister();

? ? RunModeNapatechRegister();

? ? RunModeIdsAFPRegister();

? ? RunModeIdsNetmapRegister();

? ? RunModeIdsNflogRegister();

? ? RunModeTileMpipeRegister();

? ? RunModeUnixSocketRegister();

? ? RunModeIpsWinDivertRegister();

#ifdef UNITTESTS

? ? UtRunModeRegister();

#endif

? ? return;

}

這里以RunModeIdsPcapRegister()注冊為例進(jìn)行說明:

void RunModeIdsPcapRegister(void)

{

? ? RunModeRegisterNewRunMode(RUNMODE_PCAP_DEV, "single",

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "Single threaded pcap live mode",

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? RunModeIdsPcapSingle);

? ? default_mode = "autofp";

? ? RunModeRegisterNewRunMode(RUNMODE_PCAP_DEV, "autofp",

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "Multi threaded pcap live mode.? Packets from "

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "each flow are assigned to a single detect thread, "

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "unlike \"pcap_live_auto\" where packets from "

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "the same flow can be processed by any detect "

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "thread",

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? RunModeIdsPcapAutoFp);

? ? RunModeRegisterNewRunMode(RUNMODE_PCAP_DEV, "workers",

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? "Workers pcap live mode, each thread does all"

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? " tasks from acquisition to logging",

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? RunModeIdsPcapWorkers);

? ? return;

}

主要注冊函數(shù)為RunModeRegisterNewRunMode,該函數(shù)接收四個(gè)參數(shù):

runmode :運(yùn)行模式。

name :此特定運(yùn)行模式類型的自定義模式。在每個(gè)運(yùn)行模式類型中,每個(gè)自定義名稱都是主鍵(single/autofp/worker)。

description: 此運(yùn)行模式的說明。

RunModeFunc: 要為此運(yùn)行模式運(yùn)行的函數(shù)。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容