@@ -4263,7 +4263,6 @@ static int SigTestDropFlow02(void)
42634263 * any other packet of the stream */
42644264static int SigTestDropFlow03 (void )
42654265{
4266- int result = 0 ;
42674266 Flow f ;
42684267 HtpState * http_state = NULL ;
42694268 uint8_t http_buf1 [] = "POST /one HTTP/1.0\r\n"
@@ -4282,7 +4281,6 @@ static int SigTestDropFlow03(void)
42824281 TcpSession ssn ;
42834282 Packet * p1 = NULL ;
42844283 Packet * p2 = NULL ;
4285- Signature * s = NULL ;
42864284 ThreadVars tv ;
42874285 DetectEngineThreadCtx * det_ctx = NULL ;
42884286 AppLayerParserThreadCtx * alp_tctx = AppLayerParserThreadCtxAlloc ();
@@ -4314,107 +4312,62 @@ static int SigTestDropFlow03(void)
43144312 StreamTcpInitConfig (true);
43154313
43164314 DetectEngineCtx * de_ctx = DetectEngineCtxInit ();
4317- if (de_ctx == NULL ) {
4318- goto end ;
4319- }
4320-
4315+ FAIL_IF_NULL (de_ctx );
43214316 de_ctx -> flags |= DE_QUIET ;
43224317
4323- s = de_ctx -> sig_list = SigInit (de_ctx , "drop tcp any any -> any 80 "
4324- "(msg:\"Test proto match\"; uricontent:\"one\";"
4325- "sid:1;)" );
4326- if (s == NULL ) {
4327- goto end ;
4328- }
4318+ Signature * s = DetectEngineAppendSig (de_ctx , "drop tcp any any -> any 80 "
4319+ "(msg:\"Test proto match\"; uricontent:\"one\";"
4320+ "sid:1;)" );
4321+ FAIL_IF_NULL (s );
43294322
43304323 /* the no inspection flag should be set after the first sig gets triggered,
43314324 * so the second packet should not match the next sig (because of no inspection) */
4332- s = de_ctx -> sig_list -> next = SigInit (de_ctx , "alert tcp any any -> any 80 "
4333- "(msg:\"Test proto match\"; uricontent:\"two\";"
4334- "sid:2;)" );
4335- if (s == NULL ) {
4336- goto end ;
4337- }
4325+ s = DetectEngineAppendSig (de_ctx , "alert tcp any any -> any 80 "
4326+ "(msg:\"Test proto match\"; uricontent:\"two\";"
4327+ "sid:2;)" );
4328+ FAIL_IF_NULL (s );
43384329
43394330 SigGroupBuild (de_ctx );
43404331 DetectEngineThreadCtxInit (& tv , (void * )de_ctx , (void * )& det_ctx );
43414332
43424333 int r = AppLayerParserParse (
43434334 NULL , alp_tctx , & f , ALPROTO_HTTP1 , STREAM_TOSERVER , http_buf1 , http_buf1_len );
4344- if (r != 0 ) {
4345- printf ("toserver chunk 1 returned %" PRId32 ", expected 0: " , r );
4346- goto end ;
4347- }
4335+ FAIL_IF (r != 0 );
43484336
43494337 http_state = f .alstate ;
4350- if (http_state == NULL ) {
4351- printf ("no http state: " );
4352- goto end ;
4353- }
4338+ FAIL_IF_NULL (http_state );
43544339
43554340 /* do detect */
43564341 SigMatchSignatures (& tv , de_ctx , det_ctx , p1 );
4357-
4358- if (!PacketAlertCheck (p1 , 1 )) {
4359- printf ("sig 1 didn't alert on p1, but it should: " );
4360- goto end ;
4361- }
4362-
4363- if ( !(p1 -> flow -> flags & FLOW_ACTION_DROP )) {
4364- printf ("sig 1 alerted but flow was not flagged correctly: " );
4365- goto end ;
4366- }
4342+ FAIL_IF (!PacketAlertCheck (p1 , 1 ));
4343+ FAIL_IF (!(p1 -> flow -> flags & FLOW_ACTION_DROP ));
43674344
43684345 /* Second part.. Let's feed with another packet */
4369- if (StreamTcpCheckFlowDrops (p2 ) == 1 ) {
4370- SCLogDebug ("This flow/stream triggered a drop rule" );
4371- DecodeSetNoPacketInspectionFlag (p2 );
4372- StreamTcpDisableAppLayer (p2 -> flow );
4373- p2 -> action |= ACTION_DROP ;
4374- /* return the segments to the pool */
4375- StreamTcpSessionPktFree (p2 );
4376- }
4346+ FAIL_IF_NOT (StreamTcpCheckFlowDrops (p2 ) == 1 );
43774347
4348+ SCLogDebug ("This flow/stream triggered a drop rule" );
4349+ DecodeSetNoPacketInspectionFlag (p2 );
4350+ StreamTcpDisableAppLayer (p2 -> flow );
4351+ p2 -> action |= ACTION_DROP ;
4352+ /* return the segments to the pool */
4353+ StreamTcpSessionPktFree (p2 );
43784354
4379- if ( !(p2 -> flags & PKT_NOPACKET_INSPECTION )) {
4380- printf ("The packet was not flagged with no-inspection: " );
4381- goto end ;
4382- }
4355+ FAIL_IF (!(p2 -> flags & PKT_NOPACKET_INSPECTION ));
43834356
43844357 r = AppLayerParserParse (
43854358 NULL , alp_tctx , & f , ALPROTO_HTTP1 , STREAM_TOSERVER , http_buf2 , http_buf2_len );
4386- if (r != 0 ) {
4387- printf ("toserver chunk 2 returned %" PRId32 ", expected 0: " , r );
4388- goto end ;
4389- }
4359+ FAIL_IF (r != 0 );
43904360
43914361 /* do detect */
43924362 SigMatchSignatures (& tv , de_ctx , det_ctx , p2 );
43934363
4394- if (PacketAlertCheck (p2 , 1 )) {
4395- printf ("sig 1 alerted, but it should not since the no pkt inspection should be set: " );
4396- goto end ;
4397- }
4398-
4399- if (PacketAlertCheck (p2 , 2 )) {
4400- printf ("sig 2 alerted, but it should not since the no pkt inspection should be set: " );
4401- goto end ;
4402- }
4364+ FAIL_IF (PacketAlertCheck (p2 , 1 ));
4365+ FAIL_IF (PacketAlertCheck (p2 , 2 ));
4366+ FAIL_IF (!(PacketTestAction (p2 , ACTION_DROP )));
44034367
4404- if (!(PacketTestAction (p2 , ACTION_DROP ))) {
4405- printf ("A \"drop\" action should be set from the flow to the packet: " );
4406- goto end ;
4407- }
4408-
4409- result = 1 ;
4410-
4411- end :
4412- if (alp_tctx != NULL )
4413- AppLayerParserThreadCtxFree (alp_tctx );
4414- if (det_ctx != NULL )
4415- DetectEngineThreadCtxDeinit (& tv , det_ctx );
4416- if (de_ctx != NULL )
4417- DetectEngineCtxFree (de_ctx );
4368+ AppLayerParserThreadCtxFree (alp_tctx );
4369+ DetectEngineThreadCtxDeinit (& tv , det_ctx );
4370+ DetectEngineCtxFree (de_ctx );
44184371
44194372 StreamTcpFreeConfig (true);
44204373 FLOW_DESTROY (& f );
@@ -4425,7 +4378,7 @@ static int SigTestDropFlow03(void)
44254378 /* Restore mode to IDS */
44264379 EngineModeSetIDS ();
44274380 StatsThreadCleanup (& tv .stats );
4428- return result ;
4381+ PASS ;
44294382}
44304383
44314384/** \test ICMP packet shouldn't be matching port based sig
0 commit comments