Changeset 111 for trunk

Show
Ignore:
Timestamp:
06/17/09 14:44:04 (13 years ago)
Author:
andreu
Message:

ticket #41 Pcap file integration

Location:
trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/configure.in

    r109 r111  
    2121CFLAGS_PRINTUNKNOWNSUBNET="-DPRINTUNKNOWNSUBNET" 
    2222CFLAGS_MULTISAMPLING="-DMULTISAMPLING" 
     23CFLAGS_READFROMFILE="-DREADFROMFILE -lpcap" 
    2324 
    2425# Checks for programs. 
     
    5152if test $multisampling = yes ; then 
    5253CFLAGS="$CFLAGS $CFLAGS_MULTISAMPLING" 
     54fi 
     55 
     56AC_ARG_ENABLE(readfromfile,[  --enable-readfromfile Read NDE from pcap FILE mode=no], 
     57readfromfile=$enableval,readfromfile=no) 
     58if test $readfromfile = yes ; then 
     59CFLAGS="$CFLAGS $CFLAGS_READFROMFILE" 
    5360fi 
    5461 
  • trunk/src/dataFlowSet.c

    r97 r111  
    8181  int paddingCounter = 0; 
    8282  int crazyCounter = 0; 
     83#ifdef DEBUG 
     84  int flowCpt = 0; 
     85#endif 
    8386 
    8487  buffer2[1] = *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr)); 
     
    9396  data_length = *((unsigned short*)&buffer2); 
    9497  if (data_length == 0) { 
    95     syslog(LOG_INFO, "data flowset length null; all next informations of this data flowset are not considered! flowset ID: %hu, from router: %lu.%lu.%lu.%lu", 
    96            (*myPtrs->currentFlowsetIdPtr), 
    97            (myPtrs->pcktPtr->ipH->srcAdd>>24), 
    98            (myPtrs->pcktPtr->ipH->srcAdd<<8>>24), 
    99            (myPtrs->pcktPtr->ipH->srcAdd<<16>>24), 
    100            (myPtrs->pcktPtr->ipH->srcAdd<<24>>24)); 
     98#ifdef DEBUG     
     99    fprintf (stderr, " dlg==0 <--| "); 
     100#endif 
     101/*     syslog(LOG_INFO, "data flowset length null; all next informations of this data flowset are not considered! flowset ID: %hu, from router: %lu.%lu.%lu.%lu", */ 
     102/*         (*myPtrs->currentFlowsetIdPtr), */ 
     103/*         (myPtrs->pcktPtr->ipH->srcAdd>>24), */ 
     104/*         (myPtrs->pcktPtr->ipH->srcAdd<<8>>24), */ 
     105/*         (myPtrs->pcktPtr->ipH->srcAdd<<16>>24), */ 
     106/*         (myPtrs->pcktPtr->ipH->srcAdd<<24>>24)); */ 
    101107    return (-1); 
    102108 
     
    112118            data_length); 
    113119    if ( (*myPtrs->currentFlowsetIdPtr) > TRESHOLD_TEMPLATE_ID ) { 
    114       /*        fprintf(stderr,"Bad TID from router: %lu.%lu.%lu.%lu\n", */ 
    115       /*                (*myPtrs->currentFlowsetIdPtr), */ 
    116       /*                (myPtrs->pcktPtr->ipH->srcAdd>>24), */ 
    117       /*                (myPtrs->pcktPtr->ipH->srcAdd<<8>>24), */ 
    118       /*                (myPtrs->pcktPtr->ipH->srcAdd<<16>>24), */ 
    119       /*                (myPtrs->pcktPtr->ipH->srcAdd<<24>>24)); */ 
    120       /*        fprintf(stderr," Bytes : \n"); */ 
    121       /*        while ( ( myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr) ) > (myPtrs->ptr_buffer+1416) ){ */ 
    122       /*          buffer1= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));(*myPtrs->offsetV9Ptr)++; */ 
    123       /*          tmp = *((unsigned char*)&buffer1); */ 
    124       /*          fprintf (stderr, " %s ", tmp); */ 
    125       /*        } */ 
    126       /*        exit(-1); */ 
     120        fprintf(stderr,"Bad TID from router: %lu.%lu.%lu.%lu\n", 
     121                (*myPtrs->currentFlowsetIdPtr), 
     122                (myPtrs->pcktPtr->ipH->srcAdd>>24), 
     123                (myPtrs->pcktPtr->ipH->srcAdd<<8>>24), 
     124                (myPtrs->pcktPtr->ipH->srcAdd<<16>>24), 
     125                (myPtrs->pcktPtr->ipH->srcAdd<<24>>24)); 
     126        fprintf(stderr," Bytes : \n"); 
     127        while ( ( myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr) ) > (myPtrs->ptr_buffer+1416) ){ 
     128          buffer1= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));(*myPtrs->offsetV9Ptr)++; 
     129          tmp = *((unsigned char*)&buffer1); 
     130          fprintf (stderr, " %s ", tmp); 
     131        } 
     132        exit(-1); 
    127133      return (data_length+shift); 
    128134    } 
     
    134140    if ( data_length%flow_size >= 9 ) { 
    135141      (*myPtrs->currentFlowsetNumberPtr) = myPtrs->currentHeaderV9Ptr->count; 
    136       syslog(LOG_INFO, "data flowset length not match with length from template definition, wrong template definition suspected; all next informations of this data flowset are not considered! flowset ID: %hu, from router: %lu.%lu.%lu.%lu", 
     142      syslog(LOG_INFO, "data flowset length not match with length from template definition, wrong template definition suspected; all next informations of this data flowset are not considered! sourceID: %lu flowset ID: %hu, from router: %lu.%lu.%lu.%lu", 
     143             myPtrs->currentHeaderV9Ptr->sourceId, 
    137144             (*myPtrs->currentFlowsetIdPtr), 
    138145             (myPtrs->pcktPtr->ipH->srcAdd>>24), 
     
    140147             (myPtrs->pcktPtr->ipH->srcAdd<<16>>24), 
    141148             (myPtrs->pcktPtr->ipH->srcAdd<<24>>24)); 
     149#ifdef DEBUG     
     150    fprintf (stderr, " dlg%flsz >=9 skip data "); 
     151#endif 
    142152      return (data_length+shift); 
    143153    } 
     
    149159             (myPtrs->pcktPtr->ipH->srcAdd<<16>>24), 
    150160             (myPtrs->pcktPtr->ipH->srcAdd<<24>>24)); 
     161#ifdef DEBUG     
     162    fprintf (stderr, " dlg >= 1452 skip pckt "); 
     163#endif 
    151164      return (-1); 
    152165    } 
     
    641654         * end of one flow (not the flowset)  
    642655         */ 
    643  
     656#ifdef DEBUG 
     657        flowCpt++; 
     658        fprintf(stderr," F%d ", flowCpt); 
     659#endif  
    644660        /* put aggregation cache information to IPv4 Prefixes table */ 
    645661        /* Aggregation mode must be enable in ./configure options   */ 
     
    12121228        /* not the flow end, progress in field list */ 
    12131229        pftmp = pftmp->prev; 
    1214       } 
     1230      }     
    12151231    } /* end of the while on one flow record */ 
    1216        
     1232        
    12171233    while ( ((*myPtrs->offsetV9Ptr)-48-shift) < data_length ) { 
    12181234      (*myPtrs->offsetV9Ptr)++; /* if padding */ 
    12191235      paddingCounter++; 
     1236#ifdef DEBUG 
     1237      fprintf(stderr,", pC: %d ", paddingCounter); 
    12201238      if ( paddingCounter > 8 ) { 
    1221 #ifdef DEBUG 
    1222         fprintf(stderr," padding too high: %d ", paddingCounter); 
    1223 #endif 
    12241239        syslog(LOG_INFO,"padding too high: %d ", paddingCounter); 
     1240        fprintf(stderr,", pC: %d <--| ", paddingCounter); 
    12251241        return (-1); 
     1242#endif 
    12261243      } 
     1244      return (-1); 
    12271245    } 
    12281246    while ( (*myPtrs->offsetV9Ptr)-48-shift > data_length ) {  
     
    12321250#ifdef DEBUG 
    12331251    if (crazyCounter != 0){ fprintf(stderr," crazyCounter: %d ", crazyCounter); } 
    1234 #endif 
    12351252    if (crazyCounter!=0) { syslog(LOG_INFO,"crazyCounter: %d ", crazyCounter);} 
    1236        
    1237 #ifdef DEBUG 
    1238     fprintf(stderr,"}"); 
     1253    fprintf(stderr,"(%hu,%hu)}", data_length, data_length+shift); 
    12391254#endif 
    12401255       
     
    13261341    } else { 
    13271342      /*  
    1328        * template unknown, we skip this all the data  
     1343       * template unknown, we skip the data  
    13291344       */ 
    13301345      (*myPtrs->offsetV9Ptr)+=(data_length-4); 
    1331       (*myPtrs->currentFlowsetNumberPtr) = myPtrs->currentHeaderV9Ptr->count; 
     1346      (*myPtrs->currentFlowsetNumberPtr)+= 1 ; 
     1347      /*      (*myPtrs->currentFlowsetNumberPtr) = myPtrs->currentHeaderV9Ptr->count;*/ 
    13321348#ifdef DEBUG 
    1333       fprintf(stderr, " U, r: %lu.%lu.%lu.%lu, sourceId: %lu, TID: %hu", 
     1349      fprintf(stderr, " U, r: %lu.%lu.%lu.%lu, sourceId: %lu, TID: %hu ", 
    13341350              (myPtrs->pcktPtr->ipH->srcAdd>>24), 
    13351351              (myPtrs->pcktPtr->ipH->srcAdd<<8>>24), 
     
    13391355              (*myPtrs->currentFlowsetIdPtr) 
    13401356              ); 
     1357      fprintf(stderr,"(%hu,%hu) ", data_length, data_length+shift); 
    13411358#endif 
    13421359      return (data_length+shift); 
  • trunk/src/renetcol.c

    r110 r111  
    8585static struct sockaddr_in name2; 
    8686static struct sockaddr_in fromName; 
     87#ifdef READFROMFILE 
     88  char *myPcapFileName, errBuffer[PCAP_ERRBUF_SIZE]; 
     89  pcap_t *myPcapHandle; 
     90#endif 
    8791 
    8892/*  
     
    100104  unsigned short routerIndex = 0; 
    101105 
     106#if defined(READFROMFILE) 
     107  if ( argc != 2) { 
     108    fprintf (stderr, 
     109             "%s: Usage: %s <pcap file>\n exp: %s /tmp/my_pcap_file.pcap\n",  
     110             argv[0], argv[0], argv[0]); 
     111    exit(1); 
     112  } 
     113  myPcapFileName = argv[1]; 
     114  if ((myPcapHandle = pcap_open_offline(myPcapFileName, errBuffer)) == NULL) { 
     115    fprintf(stderr, "Couldn't open PCAP file %s: %s\n", myPcapFileName, errBuffer); 
     116    exit(1); 
     117  } 
     118#endif 
     119 
    102120#if defined(IPV4AGGIDR) 
    103121  fprintf(stderr, "renetcol compilation and execution with IPv4 Prefixes Aggregation feature enable based on routers ID in %s file.\n", ROUTERS_LIST); 
     
    113131  fprintf(stderr, "renetcol compilation and execution with IPv6 Links Aggregation.\n"); 
    114132#endif 
    115    
     133 
    116134  openlog(argv[0], LOG_PID, LOG_USER); 
    117135 
     
    299317  for (i=0; i<ROUTER_INDEX_MAX; i++){ 
    300318    for (j=0; j<MAX_INDEX_BY_ROUTER; j++) { 
     319      shmForAgg->indexV6Tab[0][i][j].routerIPAddress = 0; 
     320      shmForAgg->indexV6Tab[0][i][j].indexSNMP = 0; 
    301321      shmForAgg->indexV6Tab[0][i][j].hasStats = 0; 
    302322      shmForAgg->indexV6Tab[0][i][j].sampling = 0; 
     
    307327      shmForAgg->indexV6Tab[0][i][j].pktsNbOUT = 0; 
    308328      shmForAgg->indexV6Tab[0][i][j].flowNbOUT = 0; 
     329      shmForAgg->indexV6Tab[1][i][j].routerIPAddress = 0; 
     330      shmForAgg->indexV6Tab[1][i][j].indexSNMP = 0; 
    309331      shmForAgg->indexV6Tab[1][i][j].hasStats = 0; 
    310332      shmForAgg->indexV6Tab[1][i][j].sampling = 0; 
     
    454476 
    455477#ifdef DEBUG 
    456   fprintf(stderr,"Cache for Rules\n"); 
     478  fprintf(stderr,"Cache for Rules: \n"); 
    457479#endif  
    458480  while (tmp) { 
     
    464486      } 
    465487      rulesAddress[def->fieldType][i] = def; 
     488#ifdef DEBUG 
     489      fprintf(stderr,"%d: %d \n", def->fieldType, i); 
     490#endif      
    466491      def = def->next; 
    467 #ifdef DEBUG 
    468       fprintf(stderr,"%d: %d ", def->fieldType, i); 
    469 #endif      
    470492    } 
    471493#ifdef DEBUG 
     
    474496    tmp = tmp->next; 
    475497  } 
     498#ifdef DEBUG 
     499  fprintf(stderr,"Cache for Rules: OK"); 
     500#endif  
    476501} 
    477502 
    478503/*  
    479504 * initStream() 
     505 * 
     506 * Stream can be a file (pcap format) or a socket 
    480507 */ 
    481508void  
     
    484511  static unsigned short n0, n1, n2, n3; 
    485512 
     513#ifdef READFROMFILE 
     514  initFile(); 
     515#else 
    486516  initSocket(); 
    487517  if (sscanf(receptAddress,"%hu.%hu.%hu.%hu",&n0,&n1,&n2,&n3)==0) { 
     
    492522  buffer4[2] = (unsigned char)n1; 
    493523  buffer4[3] = (unsigned char)n0; 
     524#endif 
    494525} 
    495526 
     
    572603      initRule(); 
    573604    }  
     605#ifdef READFROMFILE 
     606    fileReading(); 
     607#else 
    574608    socketReading(); 
     609#endif 
    575610    getIpHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer); 
    576611    regRouter = checkIpHeader(myPtrs.pcktPtr, &sortedRouterList[0], routerNb); 
     
    584619                             myPtrs.currentHeaderV9Ptr, myPtrs.offsetV9Ptr)){ 
    585620    case 9: 
     621#ifdef DEBUG 
     622      fprintf (stderr, ", %d %hu %lu ,",  
     623               myPtrs.currentHeaderV9Ptr->version, 
     624               myPtrs.currentHeaderV9Ptr->count, 
     625               myPtrs.currentHeaderV9Ptr->package_sequence); 
     626#endif 
    586627      if ((myPtrs.currentRouterPtr=notExistRouter(routersListPtr,  
    587628                                                  myPtrs.pcktPtr->ipH->srcAdd))==NULL) { 
     
    591632      shift = 0; 
    592633      gardeFou=0; 
    593       while ((currentFlowsetNumber < myPtrs.currentHeaderV9Ptr->count)) { 
     634      while ((currentFlowsetNumber < myPtrs.currentHeaderV9Ptr->count) && (shift <= 1456)) { 
    594635        gardeFou++; 
    595636        curTplFlSetPtr = NULL; 
     
    605646                                             myQueue)) < 0 ) { 
    606647#ifdef DEBUG 
    607             fprintf (stderr, "w>\n"); 
     648            fprintf (stderr, "w> "); 
    608649#endif 
    609650            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1; 
     
    618659                                            myPtrs.currentFlowsetNumberPtr) ) < 0 ) { 
    619660#ifdef DEBUG 
    620             fprintf (stderr, "wo>\n"); 
     661            fprintf (stderr, "wo> "); 
    621662#endif  
    622663            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1; 
     
    631672                                         (size_t) shmForAgg->v4SubnetNb) ) < 0 ) { 
    632673#ifdef DEBUG     
    633             fprintf (stderr, "wd>\n"); 
     674            fprintf (stderr, "wd> "); 
    634675#endif 
    635676            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1; 
     
    637678        } else { 
    638679#ifdef DEBUG     
    639           fprintf (stderr, "1<<255\n"); 
     680          fprintf (stderr, " 1<<255 "); 
    640681#endif 
    641682          currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1; 
     
    643684        if ( gardeFou > 200) { exit(-1); } 
    644685      } /* end while flowset exist */ 
     686#ifdef DEBUG 
     687      if (shift > 1456) { 
     688        fprintf(stderr," SHIT SHIFT > 1456 : %d \n", shift); 
     689      } 
     690#endif 
    645691      break; 
    646692    default: 
     
    735781} 
    736782 
     783/* 
     784 * initFile 
     785 */ 
     786short initFile() 
     787{ 
     788   
     789} 
    737790 
    738791/*  
    739  * init socket 
     792 * socketReading 
    740793 */ 
    741794short  
     
    758811  } 
    759812  return(0); 
     813} 
     814 
     815/* 
     816 * fileReading 
     817 */ 
     818short fileReading() 
     819{ 
     820#ifdef READFROMFILE 
     821  struct pcap_pkthdr myPcapHeader;   
     822  const u_char *ethernetPacket; 
     823 
     824  if ((ethernetPacket = pcap_next(myPcapHandle, &myPcapHeader)) == NULL) { 
     825    pcap_close(myPcapHandle); 
     826    exit(0); 
     827  } 
     828  myPtrs.ptr_buffer = (DatagramPtr) (ethernetPacket + 14); 
     829#ifdef DEBUG 
     830  fprintf(stderr,"P"); 
     831#endif 
     832#endif 
    760833} 
    761834  
  • trunk/src/renetcol.h

    r95 r111  
    4646#include <signal.h> 
    4747#include <setjmp.h> 
     48 
     49#ifdef READFROMFILE 
     50#include <pcap.h> 
     51#endif 
    4852 
    4953#include "routers_mgmt.h" 
     
    96100int socketLoop(); 
    97101short initSocket(); 
     102short initFile(); 
    98103short socketReading(); 
     104short fileReading(); 
    99105short getFlow(short); 
    100106short checkFlow(short); 
  • trunk/src/template.c

    r78 r111  
    212212#endif 
    213213          } 
     214#ifdef DEBUG   
    214215          syslog (LOG_INFO,  
    215                   "in new template: field nb gt 216, field lg gt 16 or too many fields, bad template definition possibility"); 
     216                  "New template: field nb, field lg or too many fields, bad template def possibility SId: %lu", 
     217                  v9Ptr->sourceId); 
     218#endif 
    216219          ptpltmp = cTFSPtr; 
    217220          if (ptpltmp->prev == NULL) { 
     
    309312#endif 
    310313          } 
     314#ifdef DEBUG 
    311315          syslog (LOG_INFO,  
    312316                  "in update template function: too many fields, bug collector or wrong template def in template update"); 
    313 #ifdef DEBUG 
    314317          fprintf(stderr,  
    315318                  "\nin update template function: too many fields, bug collector or wrong template def in template update\n");  
     
    469472                  cr->IpAddress<<16>>24, 
    470473                  cr->IpAddress<<24>>24); 
    471 #endif 
    472474          syslog (LOG_INFO,  
    473475                  "in option template function: too many fields, bug collector or wrong template def in template update"); 
    474 #ifdef DEBUG 
    475476          fprintf(stderr, 
    476477                  "\nin option template function: too many fields, bug collector or wrong template def in template update\n"); 
     
    566567                  cr->IpAddress<<16>>24, 
    567568                  cr->IpAddress<<24>>24); 
    568 #endif 
    569569          syslog (LOG_INFO,  
    570570                  "in update option tpl function: too many fields, bug collector or wrong template def in template update"); 
    571 #ifdef DEBUG 
    572571          fprintf(stderr, 
    573572                  "\nin update option tpl function: too many fields, bug collector or wrong template def in template update\n");