Show
Ignore:
Timestamp:
12/21/10 16:01:36 (12 years ago)
Author:
andreu
Message:

DoS detection - detection in core (todo: email notification with renetcolSEC module)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/dataFlowSet.c

    r127 r144  
    5858  int j = 0; 
    5959  int pos = 0; 
     60        int jdos = 0; 
     61        int posdos = 0; 
    6062  unsigned char buffer1;   
    6163  unsigned char buffer2[2]; 
     
    7577#endif 
    7678  struct AggCache agCache; 
     79        struct DoSCache dosCache; 
    7780  int bool = 0; /* in IPV4 Agg mode enabled, we need to now if it's an IPv4 */ 
    7881  int isIPv6 = 0; 
     
    330333                agCache.bytes = *((unsigned long*)&buffer4); 
    331334                if ( 
    332                     ((unsigned long)((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue) + ( (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue)*10/100)) 
     335                    ((unsigned long)((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue) + ( (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue)/5)) 
    333336                     >= (*((unsigned long*)&buffer4))) 
    334337                    && 
    335                     ( (unsigned long)((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue) - ( (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue)*10/100)) 
     338                    ( (unsigned long)((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue) - ( (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue)/5)) 
    336339                      <= (*((unsigned long*)&buffer4)) ) 
    337340                    ) 
     
    339342                    ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 1; 
    340343                  } 
    341               } 
     344                                } 
    342345#if defined(IPV4AGGIDR) || defined(IPV4AGGIDSNMP) 
    343346              if (pftmp->fieldType==10){ 
     
    369372              } 
    370373#endif 
     374              if (pftmp->fieldType==1){ 
     375                      dosCache.bytes = *((unsigned long*)&buffer4); 
     376                                        dosCache.sampling = *myPtrs->currentRouterPtr->sampled; 
     377              } 
     378              if (pftmp->fieldType==2){ 
     379                      dosCache.pkts = *((unsigned long*)&buffer4); 
     380                                } 
    371381              break; 
    372382            case 16: 
     
    633643          } 
    634644#endif 
     645                if (pftmp->fieldType==1){ 
     646            dosCache.bytes = *((unsigned long*)&buffer4); 
     647                        dosCache.sampling = *myPtrs->currentRouterPtr->sampled; 
     648          }  
     649                if (pftmp->fieldType==2){ 
     650            dosCache.pkts = *((unsigned long*)&buffer4); 
     651          } 
    635652          break; 
    636653        case 16: 
     
    14261443        } 
    14271444        isMplsFlow = 0; 
     1445 
     1446        /* DoS DETECTION */ 
     1447        if ( ( dosCache.packets*dosCache.sampling > MAX_PKTS_DOS )   
     1448                  && ((dosCache.packets)/(dosCache.bytes) < RATIO_DOS ) ) { 
     1449                                jdos = 0; 
     1450        posdos = 69*MAX_RULES_PER_FIELD+jdos; 
     1451        while ( ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+jdos))) != NULL ) { 
     1452                                        ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+posdos)))->check = 1; 
     1453                                        jdos++; 
     1454                                } 
     1455        } 
     1456 
    14281457        /*  
    14291458         * 
     
    14651494                                                   &tmp->sourceId,  
    14661495                                                   sizeof(unsigned long)  
    1467                                                    ),  
    1468                                            &tmp->templateFlowSetId,  
    1469                                            sizeof(tmp->templateFlowSetId)  
    1470                                            ),  
    1471                                    myPtrs->ptr_buffer+secondOffset,  
     1496                                                   ), 
     1497                                           &tmp->templateFlowSetId, 
     1498                                           sizeof(tmp->templateFlowSetId) 
     1499                                           ), 
     1500                                   myPtrs->ptr_buffer+secondOffset, 
    14721501                                   flow_size 
    14731502                                   );