/** * \test Test the Rotate process * * \retval 1 on succces * \retval 0 on failure */ static int Unified2TestRotate01(void) { int ret = 0; int r = 0; ThreadVars tv; OutputCtx *oc; LogFileCtx *lf; void *data = NULL; char *filename = NULL; oc = Unified2AlertInitCtx(NULL); if (oc == NULL) return 0; lf = (LogFileCtx *)oc->data; if (lf == NULL) return 0; filename = SCStrdup(lf->filename); if (unlikely(filename == NULL)) return 0; memset(&tv, 0, sizeof(ThreadVars)); ret = Unified2AlertThreadInit(&tv, oc, &data); if (ret == TM_ECODE_FAILED) { LogFileFreeCtx(lf); if (filename != NULL) SCFree(filename); return 0; } TimeSetIncrementTime(1); ret = Unified2AlertRotateFile(&tv, data); if (ret == -1) goto error; if (strcmp(filename, lf->filename) == 0) { SCLogError(SC_ERR_UNIFIED2_ALERT_GENERIC, "filename \"%s\" == \"%s\": ", filename, lf->filename); goto error; } r = 1; error: ret = Unified2AlertThreadDeinit(&tv, data); if(ret == TM_ECODE_FAILED) { printf("Unified2AlertThreadDeinit error"); } if (oc != NULL) Unified2AlertDeInitCtx(oc); if (filename != NULL) SCFree(filename); return r; }
static int Unified2Test05 (void) { ThreadVars tv; DecodeThreadVars dtv; PacketQueue pq; void *data = NULL; OutputCtx *oc; LogFileCtx *lf; Signature s; uint8_t raw_ipv4_tcp[] = { 0x00, 0x14, 0xbf, 0xe8, 0xcb, 0x26, 0xaa, 0x00, 0x04, 0x00, 0x0a, 0x04, 0x08, 0x00, 0x45, 0x00, 0x00, 0x3c, 0x8c, 0x55, 0x40, 0x00, 0x40, 0x06, 0x69, 0x86, 0xc0, 0xa8, 0x0a, 0x68, 0x4a, 0x7d, 0x2f, 0x53, 0xc2, 0x40, 0x00, 0x50, 0x1f, 0x00, 0xa4, 0xd4, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x02, 0x16, 0xd0, 0x3d, 0x4e, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4, 0x04, 0x02, 0x08, 0x0a, 0x00, 0x1c, 0x28, 0x81, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x06}; Packet *p = PacketGetFromAlloc(); if (unlikely(p == NULL)) return 0; int ret; memset(&dtv, 0, sizeof(DecodeThreadVars)); memset(&tv, 0, sizeof(ThreadVars)); memset(&pq, 0, sizeof(PacketQueue)); p->pkt = (uint8_t *)(p + 1); memset(&s, 0, sizeof(Signature)); p->alerts.cnt++; p->alerts.alerts[p->alerts.cnt-1].s = &s; p->alerts.alerts[p->alerts.cnt-1].s->id = 1; p->alerts.alerts[p->alerts.cnt-1].s->gid = 1; p->alerts.alerts[p->alerts.cnt-1].s->rev = 1; SET_PKT_LEN(p, sizeof(raw_ipv4_tcp)); FlowInitConfig(FLOW_QUIET); DecodeEthernet(&tv, &dtv, p, raw_ipv4_tcp, sizeof(raw_ipv4_tcp), &pq); FlowShutdown(); p->action = ACTION_DROP; oc = Unified2AlertInitCtx(NULL); if (oc == NULL) { SCFree(p); return 0; } lf = (LogFileCtx *)oc->data; if(lf == NULL) { SCFree(p); return 0; } ret = Unified2AlertThreadInit(&tv, oc, &data); if(ret == -1) { SCFree(p); return 0; } ret = Unified2Alert(&tv, p, data, &pq, NULL); if(ret == TM_ECODE_FAILED) { SCFree(p); return 0; } ret = Unified2AlertThreadDeinit(&tv, data); if(ret == TM_ECODE_FAILED) { SCFree(p); return 0; } Unified2AlertDeInitCtx(oc); PACKET_CLEANUP(p); SCFree(p); return 1; }
static int Unified2Test03 (void) { ThreadVars tv; DecodeThreadVars dtv; PacketQueue pq; void *data = NULL; OutputCtx *oc; LogFileCtx *lf; Signature s; uint8_t raw_gre[] = { 0x00, 0x0e, 0x50, 0x06, 0x42, 0x96, 0xaa, 0x00, 0x04, 0x00, 0x0a, 0x04, 0x08, 0x00, 0x45, 0x00, 0x00, 0x74, 0x35, 0xa2, 0x40, 0x00, 0x40, 0x2f, 0xef, 0xcb, 0x0a, 0x00, 0x00, 0x64, 0x0a, 0x00, 0x00, 0x8a, 0x30, 0x01, 0x88, 0x0b, 0x00, 0x54, 0x00, 0x00, 0x00, 0x18, 0x29, 0x5f, 0xff, 0x03, 0x00, 0x21, 0x45, 0x00, 0x00, 0x50, 0xf4, 0x05, 0x40, 0x00, 0x3f, 0x06, 0x20, 0xb8, 0x50, 0x7e, 0x2b, 0x2d, 0xd4, 0xcc, 0xd6, 0x72, 0x0a, 0x92, 0x1a, 0x0b, 0xc9, 0xaf, 0x24, 0x02, 0x8c, 0xdd, 0x45, 0xf6, 0x80, 0x18, 0x21, 0xfc, 0x10, 0x7c, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x08, 0x19, 0x1a, 0xda, 0x84, 0xd6, 0xda, 0x3e, 0x50, 0x49, 0x4e, 0x47, 0x20, 0x73, 0x74, 0x65, 0x72, 0x6c, 0x69, 0x6e, 0x67, 0x2e, 0x66, 0x72, 0x65, 0x65, 0x6e, 0x6f, 0x64, 0x65, 0x2e, 0x6e, 0x65, 0x74, 0x0d, 0x0a}; Packet *p = PacketGetFromAlloc(); if (unlikely(p == NULL)) return 0; int ret; memset(&dtv, 0, sizeof(DecodeThreadVars)); memset(&tv, 0, sizeof(ThreadVars)); memset(&pq, 0, sizeof(PacketQueue)); p->pkt = (uint8_t *)(p + 1); memset(&s, 0, sizeof(Signature)); p->alerts.cnt++; p->alerts.alerts[p->alerts.cnt-1].s = &s; p->alerts.alerts[p->alerts.cnt-1].s->id = 1; p->alerts.alerts[p->alerts.cnt-1].s->gid = 1; p->alerts.alerts[p->alerts.cnt-1].s->rev = 1; SET_PKT_LEN(p, sizeof(raw_gre)); FlowInitConfig(FLOW_QUIET); DecodeEthernet(&tv, &dtv, p, raw_gre, sizeof(raw_gre), &pq); FlowShutdown(); oc = Unified2AlertInitCtx(NULL); if (oc == NULL) { SCFree(p); return 0; } lf = (LogFileCtx *)oc->data; if(lf == NULL) { SCFree(p); return 0; } ret = Unified2AlertThreadInit(&tv, oc, &data); if(ret == -1) { SCFree(p); return 0; } ret = Unified2Alert(&tv, p, data, &pq, NULL); if(ret == TM_ECODE_FAILED) { SCFree(p); return 0; } ret = Unified2AlertThreadDeinit(&tv, data); if(ret == -1) { SCFree(p); return 0; } Unified2AlertDeInitCtx(oc); Packet *pkt = PacketDequeue(&pq); while (pkt != NULL) { SCFree(pkt); pkt = PacketDequeue(&pq); } PACKET_CLEANUP(p); SCFree(p); return 1; }
static int Unified2Test04 (void) { ThreadVars tv; DecodeThreadVars dtv; PacketQueue pq; void *data = NULL; OutputCtx *oc; LogFileCtx *lf; Signature s; uint8_t raw_ppp[] = { 0xff, 0x03, 0x00, 0x21, 0x45, 0xc0, 0x00, 0x2c, 0x4d, 0xed, 0x00, 0x00, 0xff, 0x06, 0xd5, 0x17, 0xbf, 0x01, 0x0d, 0x01, 0xbf, 0x01, 0x0d, 0x03, 0xea, 0x37, 0x00, 0x17, 0x6d, 0x0b, 0xba, 0xc3, 0x00, 0x00, 0x00, 0x00, 0x60, 0x02, 0x10, 0x20, 0xdd, 0xe1, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4}; Packet *p = PacketGetFromAlloc(); if (unlikely(p == NULL)) return 0; int ret; memset(&dtv, 0, sizeof(DecodeThreadVars)); memset(&tv, 0, sizeof(ThreadVars)); memset(&pq, 0, sizeof(PacketQueue)); p->pkt = (uint8_t *)(p + 1); memset(&s, 0, sizeof(Signature)); p->alerts.cnt++; p->alerts.alerts[p->alerts.cnt-1].s = &s; p->alerts.alerts[p->alerts.cnt-1].s->id = 1; p->alerts.alerts[p->alerts.cnt-1].s->gid = 1; p->alerts.alerts[p->alerts.cnt-1].s->rev = 1; SET_PKT_LEN(p, sizeof(raw_ppp)); FlowInitConfig(FLOW_QUIET); DecodePPP(&tv, &dtv, p, raw_ppp, sizeof(raw_ppp), &pq); FlowShutdown(); oc = Unified2AlertInitCtx(NULL); if (oc == NULL) { SCFree(p); return 0; } lf = (LogFileCtx *)oc->data; if(lf == NULL) { SCFree(p); return 0; } ret = Unified2AlertThreadInit(&tv, oc, &data); if(ret == -1) { SCFree(p); return 0; } ret = Unified2Alert(&tv, p, data, &pq, NULL); if(ret == TM_ECODE_FAILED) { SCFree(p); return 0; } ret = Unified2AlertThreadDeinit(&tv, data); if(ret == -1) { SCFree(p); return 0; } Unified2AlertDeInitCtx(oc); PACKET_CLEANUP(p); SCFree(p); return 1; }
static int Unified2Test02 (void) { ThreadVars tv; DecodeThreadVars dtv; PacketQueue pq; void *data = NULL; OutputCtx *oc; LogFileCtx *lf; Signature s; uint8_t raw_ipv6_tcp[] = { 0x00, 0x11, 0x25, 0x82, 0x95, 0xb5, 0x00, 0xd0, 0x09, 0xe3, 0xe8, 0xde, 0x86, 0xdd, 0x60, 0x00, 0x00, 0x00, 0x00, 0x28, 0x06, 0x40, 0x20, 0x01, 0x06, 0xf8, 0x10, 0x2d, 0x00, 0x00, 0x02, 0xd0, 0x09, 0xff, 0xfe, 0xe3, 0xe8, 0xde, 0x20, 0x01, 0x06, 0xf8, 0x09, 0x00, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xe7, 0x41, 0x00, 0x50, 0xab, 0xdc, 0xd6, 0x60, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x02, 0x16, 0x80, 0x41, 0xa2, 0x00, 0x00, 0x02, 0x04, 0x05, 0xa0, 0x04, 0x02, 0x08, 0x0a, 0x00, 0x0a, 0x22, 0xa8, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x05 }; Packet *p = SCMalloc(SIZE_OF_PACKET); if (unlikely(p == NULL)) return 0; int ret; memset(&dtv, 0, sizeof(DecodeThreadVars)); memset(&tv, 0, sizeof(ThreadVars)); memset(&pq, 0, sizeof(PacketQueue)); memset(p, 0, SIZE_OF_PACKET); p->pkt = (uint8_t *)(p + 1); memset(&s, 0, sizeof(Signature)); PACKET_INITIALIZE(p); p->alerts.cnt++; p->alerts.alerts[p->alerts.cnt-1].s = &s; p->alerts.alerts[p->alerts.cnt-1].s->id = 1; p->alerts.alerts[p->alerts.cnt-1].s->gid = 1; p->alerts.alerts[p->alerts.cnt-1].s->rev = 1; SET_PKT_LEN(p, sizeof(raw_ipv6_tcp)); FlowInitConfig(FLOW_QUIET); DecodeEthernet(&tv, &dtv, p, raw_ipv6_tcp, sizeof(raw_ipv6_tcp), &pq); FlowShutdown(); oc = Unified2AlertInitCtx(NULL); if (oc == NULL) { SCFree(p); return 0; } lf = (LogFileCtx *)oc->data; if(lf == NULL) { SCFree(p); return 0; } ret = Unified2AlertThreadInit(&tv, oc, &data); if(ret == -1) { SCFree(p); return 0; } ret = Unified2Alert(&tv, p, data, &pq, NULL); if(ret == TM_ECODE_FAILED) { SCFree(p); return 0; } ret = Unified2AlertThreadDeinit(&tv, data); if(ret == -1) { SCFree(p); return 0; } Unified2AlertDeInitCtx(oc); PACKET_CLEANUP(p); SCFree(p); return 1; }