From: Jason Ish Date: Thu, 18 Jun 2015 20:18:49 +0000 (-0600) Subject: defrag: unit test for tracker reuse (current fails) X-Git-Tag: suricata-3.0RC1~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed400acf8e946404bbc0634df153bf155dcae345;p=thirdparty%2Fsuricata.git defrag: unit test for tracker reuse (current fails) Will be fixed in subsequent commits as tracker reuse is fixed. --- diff --git a/src/defrag.c b/src/defrag.c index 7418b93c66..6f0260e3ef 100644 --- a/src/defrag.c +++ b/src/defrag.c @@ -2328,6 +2328,70 @@ end: return ret; } +static int DefragTrackerReuseTest(void) +{ + int ret = 0; + int id = 1; + Packet *p1 = NULL; + DefragTracker *tracker1 = NULL, *tracker2 = NULL; + + DefragInit(); + + /* Build a packet, its not a fragment but shouldn't matter for + * this test. */ + p1 = BuildTestPacket(id, 0, 0, 'A', 8); + if (p1 == NULL) { + goto end; + } + + /* Get a tracker. It shouldn't look like its already in use. */ + tracker1 = DefragGetTracker(NULL, NULL, p1); + if (tracker1 == NULL) { + goto end; + } + if (tracker1->seen_last) { + goto end; + } + if (tracker1->remove) { + goto end; + } + DefragTrackerRelease(tracker1); + + /* Get a tracker again, it should be the same one. */ + tracker2 = DefragGetTracker(NULL, NULL, p1); + if (tracker2 == NULL) { + goto end; + } + if (tracker2 != tracker1) { + goto end; + } + DefragTrackerRelease(tracker1); + + /* Now mark the tracker for removal. It should not be returned + * when we get a tracker for a packet that may have the same + * attributes. */ + tracker1->remove = 1; + + tracker2 = DefragGetTracker(NULL, NULL, p1); + if (tracker2 == NULL) { + goto end; + } + if (tracker2 == tracker1) { + goto end; + } + if (tracker2->remove) { + goto end; + } + + ret = 1; +end: + if (p1 != NULL) { + SCFree(p1); + } + DefragDestroy(); + return ret; +} + #endif /* UNITTESTS */ void @@ -2374,6 +2438,8 @@ DefragRegisterTests(void) UtRegisterTest("DefragVlanTest", DefragVlanTest, 1); UtRegisterTest("DefragVlanQinQTest", DefragVlanQinQTest, 1); + UtRegisterTest("DefragTrackerReuseTest", DefragTrackerReuseTest, 1); + UtRegisterTest("DefragTimeoutTest", DefragTimeoutTest, 1); #endif /* UNITTESTS */