root/trunk/src/dataFlowSet.c @ 118

Revision 114, 53.8 KB (checked in by andreu, 14 years ago)

add some counters in software (see renetcol_mib.h & dataFlowSet.c

  • Property svn:eol-style set to native
Line 
1/*
2 * File: dataFlowSet.c
3 *
4 * Authors: ANDREU Francois-Xavier
5 *
6 * Copyright (C) 2005 - 2009 GIP RENATER
7 */
8
9/*  This file is part of renetcol.
10 *
11 *  renetcol is free software; you can redistribute it and/or modify
12 *  it under the terms of the GNU General Public License as published by
13 *  the Free Software Foundation; either version 2 of the License, or
14 *  (at your option) any later version.
15 *
16 *  renetcol is distributed in the hope that it will be useful,
17 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 *  GNU General Public License for more details.
20 *
21 *  You should have received a copy of the GNU General Public License
22 *  along with renetcol; if not, write to the Free Software
23 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 */
25
26#include "dataFlowSet.h"
27
28/*
29 * Check Data FlowSet
30 *
31 */
32short 
33checkDataFlowSet(short shift,
34                 struct MyPtrs *myPtrs,
35                 int myQueue,
36                 struct PrefixV4 *V4PTab,
37                 size_t nbPV4,
38                 struct PrefixV4 *V4STab,
39                 size_t nbSV4
40                 )
41{
42  TplFlowSetPtr tmp = NULL;
43  TplOptionPtr tmpOpt = NULL;
44  FieldPtr pftmp = NULL;
45  FieldPtr secondPftmp = NULL;
46  unsigned short data_length = 0;
47  unsigned short flow_size = 0;
48  unsigned short oldOffset = *myPtrs->offsetV9Ptr;
49  unsigned short secondOffset = 0;
50  unsigned short secondOldOffset = 0;
51  int moreIsNecessary = 1;
52  int field_size = 0;
53  int cpt = 0;
54  int secondCpt = 0;
55  int overflow = 0;
56  int noEnd = 1;
57  int i = 0;
58  int j = 0;
59  int pos = 0;
60  unsigned char buffer1; 
61  unsigned char buffer2[2];
62  unsigned char buffer4[4];
63  RulesPtr tmpRuleList = myPtrs->rulesListPtr;
64  RulesPtr tmpRL = myPtrs->rulesListPtr;
65  msgType myMsg;
66  char *msgTextIndex;
67
68  unsigned short tplMsgType = 11;
69  struct PrefixV4 prefixKey, *res, *res2, *resSub; /* for bsearch */
70#if defined(IPV4AGGIDSNMP)
71  struct PrefixV4 *res3;
72#endif
73#ifdef ASACC
74  struct AS asKey, *asres; /* for bsearch */
75#endif
76  struct AggCache agCache;
77  int bool = 0; /* in IPV4 Agg mode enabled, we need to now if it's an IPv4 */
78  int isIPv6 = 0;
79  /* flow, we test on the field and then put bool at 1 */
80  int isMplsFlow = 0;
81  int paddingCounter = 0;
82  int crazyCounter = 0;
83#ifdef DEBUG
84  int flowCpt = 0;
85#endif
86
87  buffer2[1] = *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
88  (*myPtrs->offsetV9Ptr)++;
89  buffer2[0] = *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
90  (*myPtrs->offsetV9Ptr)++;
91  (*myPtrs->currentFlowsetIdPtr) = *((unsigned short*)&buffer2);
92  buffer2[1] = *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
93  (*myPtrs->offsetV9Ptr)++;
94  buffer2[0] = *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
95  (*myPtrs->offsetV9Ptr)++;
96  data_length = *((unsigned short*)&buffer2);
97  if (data_length == 0) {
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)); */
107    return (-1);
108
109  }
110
111  if ( (tmp=existTplId(myPtrs->currentRouterPtr,
112                       myPtrs->currentHeaderV9Ptr->sourceId,
113                       (*myPtrs->currentFlowsetIdPtr)))!=NULL ) {
114    myPtrs->currentMIB->dataFlowSetNb += 1;
115#ifdef DEBUG
116    fprintf(stderr,
117            "{d id: %hu, lg %hu",
118            (*myPtrs->currentFlowsetIdPtr),
119            data_length);
120    if ( (*myPtrs->currentFlowsetIdPtr) > TRESHOLD_TEMPLATE_ID ) {
121        fprintf(stderr,"Bad TID from router: %lu.%lu.%lu.%lu\n",
122                (*myPtrs->currentFlowsetIdPtr),
123                (myPtrs->pcktPtr->ipH->srcAdd>>24),
124                (myPtrs->pcktPtr->ipH->srcAdd<<8>>24),
125                (myPtrs->pcktPtr->ipH->srcAdd<<16>>24),
126                (myPtrs->pcktPtr->ipH->srcAdd<<24>>24));
127        fprintf(stderr," Bytes : \n");
128        while ( ( myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr) ) > (myPtrs->ptr_buffer+1416) ){
129          buffer1= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));(*myPtrs->offsetV9Ptr)++;
130          tmp = *((unsigned char*)&buffer1);
131          fprintf (stderr, " %s ", tmp);
132        }
133        exit(-1);
134      return (data_length+shift);
135    }
136#endif
137    pftmp = tmp->lastField;
138    for (; pftmp; pftmp = pftmp->prev) {
139      flow_size += pftmp->fieldLength;
140    }
141    if ( data_length%flow_size >= 9 ) {
142      (*myPtrs->currentFlowsetNumberPtr) = myPtrs->currentHeaderV9Ptr->count;
143      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",
144             myPtrs->currentHeaderV9Ptr->sourceId,
145             (*myPtrs->currentFlowsetIdPtr),
146             (myPtrs->pcktPtr->ipH->srcAdd>>24),
147             (myPtrs->pcktPtr->ipH->srcAdd<<8>>24),
148             (myPtrs->pcktPtr->ipH->srcAdd<<16>>24),
149             (myPtrs->pcktPtr->ipH->srcAdd<<24>>24));
150#ifdef DEBUG   
151    fprintf (stderr, " dlg%flsz >=9 skip data ");
152#endif
153      return (data_length+shift);
154    }
155    if ( data_length >= 1452 ) {
156      syslog(LOG_INFO, "data flowset length too raised; all next informations of this data flowset are not considered! flowset ID: %hu, from router: %lu.%lu.%lu.%lu",
157             (*myPtrs->currentFlowsetIdPtr),
158             (myPtrs->pcktPtr->ipH->srcAdd>>24),
159             (myPtrs->pcktPtr->ipH->srcAdd<<8>>24),
160             (myPtrs->pcktPtr->ipH->srcAdd<<16>>24),
161             (myPtrs->pcktPtr->ipH->srcAdd<<24>>24));
162#ifdef DEBUG   
163    fprintf (stderr, " dlg >= 1452 skip pckt ");
164#endif
165      return (-1);
166    }
167#if defined(IPV4AGGIDR) || defined(IPV4AGGIDSNMP)
168    agCache.routerAd = myPtrs->pcktPtr->ipH->srcAdd;
169#endif
170
171    pftmp = tmp->lastField;
172    secondPftmp = tmp->lastField;   
173    secondOffset = *myPtrs->offsetV9Ptr;
174    secondOldOffset = secondOffset;
175    while ( (((*myPtrs->offsetV9Ptr)-48-shift) <= data_length)
176            && (overflow!=1) ) {
177      /*
178       * progression in a data flow Set
179       * notes:
180       *   48= IP header size + NetFlow header size
181       *   shift = shift because we have a template declaration
182       *           inside data templates
183       */
184      cpt++;
185      j = 0;
186      pos = (pftmp->fieldType)*MAX_RULES_PER_FIELD+j;
187      field_size = (int) pftmp->fieldLength;
188
189      /* special case: check yes on all flows from one router */
190      /* (phantom field nb 0) */
191      /* FIXME : this code is repeated, perhaps past before */
192      while ( ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+j))) != NULL ) {
193        if ( (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+j)))->value->stor.lvalue)
194             == myPtrs->pcktPtr->ipH->srcAdd )
195          {
196            ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+j)))->check = 1;
197          }     
198        j++;
199      }   
200      j = 0;
201
202      /*
203       * Comparaison between the field value and the rules
204       * ... if one rule exist
205       * FIXME : warning, if no rules, no accounting ?
206       */
207      if (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos))) != NULL) {
208        oldOffset = *myPtrs->offsetV9Ptr;
209        while (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos))) != NULL){
210          /*
211           * while on one cache table line
212           */
213          *myPtrs->offsetV9Ptr = oldOffset;
214          switch ((int)
215                  (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->operator)){
216          case 2:
217            /* operator: "=" */ 
218            switch (field_size) {
219            case 1:
220              buffer1 = *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
221              (*myPtrs->offsetV9Ptr)++;
222              /* rule check */
223              if (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.cvalue
224                  == *((unsigned char*)&buffer1)) {
225                ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 1;
226              }
227              /* end rule check */
228#if defined(IPV4AGGIDR) || defined(IPV4AGGIDSNMP)
229              if ((pftmp->fieldType==9)||(pftmp->fieldType==29)){
230                agCache.maskS = *((unsigned char*)&buffer1);
231              }
232              if ((pftmp->fieldType==13)||(pftmp->fieldType==30)){
233                agCache.maskD = *((unsigned char*)&buffer1);
234              }
235              if (pftmp->fieldType==60){
236                agCache.ipProt = *((unsigned char*)&buffer1);
237              }
238              if (pftmp->fieldType==4){
239                agCache.tProt = *((unsigned char*)&buffer1);
240              }
241              if (pftmp->fieldType==61){
242                agCache.sens = *((unsigned char*)&buffer1);
243              }
244              if (pftmp->fieldType==5){
245                agCache.dscp = *((unsigned char*)&buffer1);
246              }
247#endif       
248              break;
249            case 2:
250              buffer2[1]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
251              (*myPtrs->offsetV9Ptr)++;
252              buffer2[0]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
253              (*myPtrs->offsetV9Ptr)++;
254              if (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.svalue
255                  == *((unsigned short*)&buffer2))
256                ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 1;
257              if (pftmp->fieldType==7){
258                agCache.sPort = *((unsigned short*)&buffer2);
259              }   
260              if (pftmp->fieldType==11){
261                agCache.dPort = *((unsigned short*)&buffer2);
262              }
263#if defined(IPV4AGGIDR) || defined(IPV4AGGIDSNMP)
264              if (pftmp->fieldType==10){
265                agCache.inputSnmp = *((unsigned short*)&buffer2);
266              }
267              if (pftmp->fieldType==14){
268                agCache.outputSnmp = *((unsigned short*)&buffer2);
269              }
270#endif
271#ifdef ASACC
272              if (pftmp->fieldType==16){
273                agCache.asS = *((unsigned short*)&buffer2);
274              }   
275              if (pftmp->fieldType==17){
276                agCache.asD = *((unsigned short*)&buffer2);
277              }
278#endif
279              break;
280            case 3:
281              buffer4[3]= 0;
282              buffer4[2]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
283              (*myPtrs->offsetV9Ptr)++;
284              buffer4[1]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
285              (*myPtrs->offsetV9Ptr)++;
286              buffer4[0]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
287              (*myPtrs->offsetV9Ptr)++;
288              if (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue
289                  == *((unsigned long*)&buffer4))
290                ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 1;
291              /* aggregation */
292              /* end aggregation */
293              if (pftmp->fieldType==70){
294                isMplsFlow = 1;
295              }
296              break;
297            case 4:
298              buffer4[3]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
299              (*myPtrs->offsetV9Ptr)++;
300              buffer4[2]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
301              (*myPtrs->offsetV9Ptr)++;
302              buffer4[1]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
303              (*myPtrs->offsetV9Ptr)++;
304              buffer4[0]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
305              (*myPtrs->offsetV9Ptr)++;
306              /* FIXME : here , add a check on the field type */
307              if ((pftmp->fieldType==8)||(pftmp->fieldType==12)
308                  ||(pftmp->fieldType==15)||(pftmp->fieldType==18)){
309                if ((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue)
310                    == (*((unsigned long*)&buffer4))>>(32-((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask)<<(32-((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask) )
311                  {
312                    ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 1;
313                  }
314              }
315              if ((pftmp->fieldType==10)||(pftmp->fieldType==14)){
316                if ((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.svalue)
317                    == ((unsigned short)*((unsigned long*)&buffer4)))
318                  {
319                    ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 1;
320                  }
321              }
322              if ((pftmp->fieldType==16)||(pftmp->fieldType==17)){
323                if ((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.svalue)
324                    == ((unsigned short)*((unsigned long*)&buffer4)))
325                  {
326                    ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 1;
327                  }
328              }
329              if (pftmp->fieldType==1){
330                agCache.bytes = *((unsigned long*)&buffer4);
331                if (
332                    ((unsigned long)((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue) + ( (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue)*10/100))
333                     >= (*((unsigned long*)&buffer4)))
334                    &&
335                    ( (unsigned long)((((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue) - ( (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.lvalue)*10/100))
336                      <= (*((unsigned long*)&buffer4)) )
337                    )
338                  {
339                    ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 1;
340                  }
341              }
342#if defined(IPV4AGGIDR) || defined(IPV4AGGIDSNMP)
343              if (pftmp->fieldType==10){
344                agCache.inputSnmp = (unsigned short)*((unsigned long*)&buffer4);
345              }
346              if (pftmp->fieldType==14){
347                agCache.outputSnmp = (unsigned short)*((unsigned long*)&buffer4);
348              }
349              if ((pftmp->fieldType==8)){
350                bool = 1; /* very important, test if we have an IPv4 flow for Agg */
351                agCache.v4AdS = *((unsigned long*)&buffer4);
352              }
353              if ((pftmp->fieldType==12)){
354                agCache.v4AdD = *((unsigned long*)&buffer4);
355              }
356              if (pftmp->fieldType==1){
357                agCache.bytes = *((unsigned long*)&buffer4);
358              }
359              if (pftmp->fieldType==2){
360                agCache.pkts = *((unsigned long*)&buffer4);
361              }
362#endif
363#ifdef ASACC
364              if (pftmp->fieldType==16){
365                agCache.asS = (unsigned short)*((unsigned long*)&buffer4);
366              }   
367              if (pftmp->fieldType==17){
368                agCache.asD = (unsigned short)*((unsigned long*)&buffer4);
369              }
370#endif
371              break;
372            case 16:
373              if ((pftmp->fieldType==27)||(pftmp->fieldType==28)){
374                isIPv6 = 1;
375                for (i=0; i<4; i++) {
376                  buffer4[3]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
377                  (*myPtrs->offsetV9Ptr)++;
378                  buffer4[2]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
379                  (*myPtrs->offsetV9Ptr)++;
380                  buffer4[1]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
381                  (*myPtrs->offsetV9Ptr)++;
382                  buffer4[0]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
383                  (*myPtrs->offsetV9Ptr)++;
384                  if (1==moreIsNecessary){
385                    switch(i){
386                    case 0:
387                      if (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask <= 32){
388                        if (ntohl(((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.tabAdd6[i])
389                            ==
390                            (*((unsigned long*)&buffer4))>>(32-((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask)<<(32-((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask)
391                            )
392                          {
393                            ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 1;
394                            moreIsNecessary = 0;
395                          } else {
396                          ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 0;
397                          moreIsNecessary = 0;
398                        }
399                      } else {
400                        if (ntohl(((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.tabAdd6[i])
401                            ==
402                            (*((unsigned long*)&buffer4))
403                            )
404                          {
405                            ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 1;
406                          } else {
407                          ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 0;
408                          moreIsNecessary = 0;
409                        }
410                      }
411                      break;
412                    case 1:
413                      if (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask <= 64){
414                        if (ntohl(((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.tabAdd6[i])
415                            ==
416                            (*((unsigned long*)&buffer4))>>(64-((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask)<<(64-((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask)
417                            )
418                          {
419                            ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check =
420                              ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check && 1;
421                            moreIsNecessary = 0;
422                          } else {
423                          ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 0;
424                          moreIsNecessary = 0;
425                        }
426                      } else {
427                        if (ntohl(((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.tabAdd6[i])
428                            ==
429                            (*((unsigned long*)&buffer4))
430                            )
431                          {
432                            ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check =
433                              ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check && 1;
434                          } else {
435                          ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 0;
436                          moreIsNecessary = 0;
437                        }
438                      }
439                      break;
440                    case 2:
441                      if (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask <= 96){
442                        if (ntohl(((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.tabAdd6[i])
443                            ==
444                            (*((unsigned long*)&buffer4))>>(96-((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask)<<(96-((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask)
445                            )
446                          {
447                            ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check =
448                              ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check && 1;
449                            moreIsNecessary = 0;
450                          } else {
451                          ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 0;
452                        moreIsNecessary = 0;
453                        }
454                      } else {
455                        if (ntohl(((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.tabAdd6[i])
456                            ==
457                            (*((unsigned long*)&buffer4))
458                            )
459                          {
460                            ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check =
461                              ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check && 1;
462                          } else {
463                          ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 0;
464                          moreIsNecessary = 0;
465                        }
466                      }
467                      break;
468                    case 3:
469                      if (((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask <= 128){
470                        if (ntohl(((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.tabAdd6[i])
471                            ==
472                            (*((unsigned long*)&buffer4))>>(128-((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask)<<(128-((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->mask)
473                            )
474                          {
475                            ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check =
476                              ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check && 1;
477                          } else {
478                          ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 0;
479                          moreIsNecessary = 0;
480                        }
481                      } else {
482                        if (ntohl(((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->value->stor.tabAdd6[i])
483                            ==
484                            (*((unsigned long*)&buffer4))
485                            )
486                          {
487                            ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check =
488                              ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check && 1;
489                          } else {
490                          ((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->check = 0;
491                          moreIsNecessary = 0;
492                        }
493                      }
494                      break;
495                    default:
496                      break;
497                    } /* end of switch(i) */
498                  } /* end of if moreIsNecessary */
499#if defined IPV6AGGIDSNMP
500                  if ((pftmp->fieldType==27)){
501                    agCache.tabAdd6S[i] = *((unsigned long*)&buffer4);
502                  } else if ((pftmp->fieldType==28)){
503                    agCache.tabAdd6D[i] = *((unsigned long*)&buffer4);
504                  }
505#endif
506                }
507                moreIsNecessary = 1;
508                /* aggregation for IPv6 flows */
509               
510                /* end aggregation */
511              } /* end of : if ((pftmp->fieldType==27)||(pftmp->fieldType==28)){ */
512              break;
513            default:
514              syslog(LOG_INFO, "Field size not known: %d\n", field_size);
515              for (i=0; i<field_size; i++){
516                (*myPtrs->offsetV9Ptr)++;
517              }
518              break;
519            }
520            break;
521          default:
522            syslog(LOG_INFO, "Operator not known: %d\n",
523                   (int)(((RuleDefPtr)(*(myPtrs->rulesAddressPtr+pos)))->operator));
524            break;
525          }
526          j++;
527          pos = (pftmp->fieldType)*MAX_RULES_PER_FIELD+j;
528        } /* end while myPtrs->rulesAddressPtr */
529      } else {
530        /*
531         * no rule within this field type, but we must read the value
532         */
533        switch (field_size) {
534        case 1:
535          buffer1 = *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
536          (*myPtrs->offsetV9Ptr)++;
537#if defined(IPV4AGGIDR) || defined(IPV4AGGIDSNMP)
538          if ((pftmp->fieldType==9)||(pftmp->fieldType==29)){
539            agCache.maskS = *((unsigned char*)&buffer1);
540          }
541          if ((pftmp->fieldType==13)||(pftmp->fieldType==30)){
542            agCache.maskD = *((unsigned char*)&buffer1);
543          }
544          if (pftmp->fieldType==60){
545            agCache.ipProt = *((unsigned char*)&buffer1);
546          }
547          if (pftmp->fieldType==4){
548            agCache.tProt = *((unsigned char*)&buffer1);
549          }
550          if (pftmp->fieldType==61){
551            agCache.sens = *((unsigned char*)&buffer1);
552          }
553          if (pftmp->fieldType==5){
554            agCache.dscp = *((unsigned char*)&buffer1);
555          }       
556#endif
557          break;
558        case 2:
559          buffer2[1]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
560          (*myPtrs->offsetV9Ptr)++;
561          buffer2[0]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
562          (*myPtrs->offsetV9Ptr)++;
563          if (pftmp->fieldType==7){
564            agCache.sPort = *((unsigned short*)&buffer2);
565          }       
566          if (pftmp->fieldType==11){
567            agCache.dPort = *((unsigned short*)&buffer2);
568          }
569#if defined(IPV4AGGIDR) || defined(IPV4AGGIDSNMP)
570          if (pftmp->fieldType==10){
571            agCache.inputSnmp = *((unsigned short*)&buffer2);
572          }       
573          if (pftmp->fieldType==14){
574            agCache.outputSnmp = *((unsigned short*)&buffer2);
575          }       
576#endif
577#ifdef ASACC
578          if (pftmp->fieldType==16){
579            agCache.asS = *((unsigned short*)&buffer2);
580          }       
581          if (pftmp->fieldType==17){
582            agCache.asD = *((unsigned short*)&buffer2);
583          }
584#endif
585          break;
586        case 3:
587          buffer4[3]= 0;
588          buffer4[2]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
589          (*myPtrs->offsetV9Ptr)++;
590          buffer4[1]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
591          (*myPtrs->offsetV9Ptr)++;
592          buffer4[0]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
593          (*myPtrs->offsetV9Ptr)++;
594          /* aggregation */
595          /* end aggregation */
596          if (pftmp->fieldType==70){
597            isMplsFlow = 1;
598          }
599          break;
600        case 4:
601          buffer4[3]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
602          (*myPtrs->offsetV9Ptr)++;
603          buffer4[2]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
604          (*myPtrs->offsetV9Ptr)++;
605          buffer4[1]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
606          (*myPtrs->offsetV9Ptr)++;
607          buffer4[0]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
608          (*myPtrs->offsetV9Ptr)++;
609#if defined(IPV4AGGIDR) || defined(IPV4AGGIDSNMP)
610          if (pftmp->fieldType==10){
611            agCache.inputSnmp = (unsigned short)*((unsigned long*)&buffer4);
612          }
613          if (pftmp->fieldType==14){
614            agCache.outputSnmp = (unsigned short)*((unsigned long*)&buffer4);
615          }
616          if ((pftmp->fieldType==8)){
617            bool = 1;
618            agCache.v4AdS = *((unsigned long*)&buffer4);
619          } else if ((pftmp->fieldType==12)){
620            agCache.v4AdD = *((unsigned long*)&buffer4);
621          } else if (pftmp->fieldType==1){
622            agCache.bytes = *((unsigned long*)&buffer4);
623          } else if (pftmp->fieldType==2){
624            agCache.pkts = *((unsigned long*)&buffer4);
625          }
626#endif
627#ifdef ASACC
628          if (pftmp->fieldType==16){
629            agCache.asS = (unsigned short)*((unsigned long*)&buffer4);
630          }       
631          if (pftmp->fieldType==17){
632            agCache.asD = (unsigned short)*((unsigned long*)&buffer4);
633          }
634#endif
635          break;
636        case 16:
637          if ((pftmp->fieldType==27)||(pftmp->fieldType==28)){
638            isIPv6 = 1;
639          }
640          for (i=0; i<4; i++) {
641            buffer4[3]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
642            (*myPtrs->offsetV9Ptr)++;
643            buffer4[2]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
644            (*myPtrs->offsetV9Ptr)++;
645            buffer4[1]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
646            (*myPtrs->offsetV9Ptr)++;
647            buffer4[0]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr));
648            (*myPtrs->offsetV9Ptr)++;
649#if defined IPV6AGGIDSNMP
650            if ((pftmp->fieldType==27)){
651              agCache.tabAdd6S[i] = *((unsigned long*)&buffer4);
652            } else if ((pftmp->fieldType==28)){
653              agCache.tabAdd6D[i] = *((unsigned long*)&buffer4);
654            }
655#endif
656          }
657          break;
658        default:
659          syslog(LOG_INFO,"UNKNOWN FIELDS LENGTH: %d ", field_size);
660          for (i=0; i<field_size; i++){
661            (*myPtrs->offsetV9Ptr)++;
662          }
663        }
664      } /* end if one cache table line existence */
665      if (cpt==tmp->fieldCount) {
666        /*
667         * end of one flow (not the flowset)
668         */
669        myPtrs->currentMIB->realFlowNb += 1;
670#ifdef DEBUG
671        flowCpt++;
672        fprintf(stderr," F%d ", flowCpt);
673#endif 
674        /* put aggregation cache information to IPv4 Prefixes table */
675        /* Aggregation mode must be enable in ./configure options   */
676        /* first we must know if the address belong to our prefix   */
677        /*
678         * AS ACCOUNTING
679         */
680#if defined(ASACC) && defined(IPV4AGGIDSNMP)
681        if ( (bool == 1) && (isMplsFlow == 0) ){
682          asKey.as = agCache.asS;
683          asres = bsearch(&asKey, myPtrs->currentASTab, myPtrs->asNb, sizeof(struct AS), asGlobalCmp);
684          if (asres != NULL) {
685            if ( myPtrs->currentRouterPtr->snmpIndexList[agCache.inputSnmp] == 1  ) {
686#if defined(MULTISAMPLING)
687              if (myPtrs->currentRouterPtr->sampled != asres->sampling ){
688                /* OUT ("traffic from the AS")  */
689                asres->bytesNbOUT += agCache.bytes*myPtrs->currentRouterPtr->sampled/asres->sampling;
690                asres->pktsNbOUT += agCache.pkts*myPtrs->currentRouterPtr->sampled/asres->sampling;
691              }else{
692                asres->bytesNbOUT += agCache.bytes;
693                asres->pktsNbOUT += agCache.pkts;
694                (asres->flowNbOUT)++;
695              }
696#else
697              if (myPtrs->currentRouterPtr->sampled != 0 ){
698                /* OUT ("traffic from the AS")  */
699                asres->bytesNbOUT += agCache.bytes;
700                asres->pktsNbOUT += agCache.pkts;
701                (asres->flowNbOUT)++;
702              }
703              if (asres->sampling == 0
704                  && myPtrs->currentRouterPtr->sampled != 0){
705                asres->sampling = myPtrs->currentRouterPtr->sampled;
706              }
707#endif
708              asres = NULL;
709              asKey.as = agCache.asD;
710              asres = bsearch(&asKey, myPtrs->currentASTab, myPtrs->asNb, sizeof(struct AS), asGlobalCmp);
711              if (asres!=NULL){
712#if defined(MULTISAMPLING)
713                if (myPtrs->currentRouterPtr->sampled != asres->sampling ){
714                  /* IN ("traffic to the AS")  */
715                  asres->bytesNbIN += agCache.bytes*myPtrs->currentRouterPtr->sampled/asres->sampling;
716                  asres->pktsNbIN += agCache.pkts*myPtrs->currentRouterPtr->sampled/asres->sampling;
717                }else{
718                  asres->bytesNbIN += agCache.bytes;
719                  asres->pktsNbIN += agCache.pkts;
720                  (asres->flowNbIN)++;
721                }
722#else
723                if (myPtrs->currentRouterPtr->sampled != 0 ){
724                  /* IN ("traffic to the AS")  */
725                  asres->bytesNbIN += agCache.bytes;
726                  asres->pktsNbIN += agCache.pkts;
727                  (asres->flowNbIN)++;
728                }
729                if (asres->sampling == 0
730                    && myPtrs->currentRouterPtr->sampled != 0){
731                  asres->sampling = myPtrs->currentRouterPtr->sampled;
732                }
733#endif
734                asres = NULL;
735              }
736            }
737          } else {
738            asres = NULL;
739            asKey.as = agCache.asD;
740            asres = bsearch(&asKey, myPtrs->currentASTab, myPtrs->asNb, sizeof(struct AS), asGlobalCmp);
741            if (asres!=NULL){
742              if ( myPtrs->currentRouterPtr->snmpIndexList[agCache.inputSnmp] == 1  ) {
743#if defined(MULTISAMPLING)
744                if (myPtrs->currentRouterPtr->sampled != asres->sampling ){
745                  /* IN ("traffic to the AS")  */
746                  asres->bytesNbIN += agCache.bytes*myPtrs->currentRouterPtr->sampled/asres->sampling;
747                  asres->pktsNbIN += agCache.pkts*myPtrs->currentRouterPtr->sampled/asres->sampling;
748                }else{
749                  asres->bytesNbIN += agCache.bytes;
750                  asres->pktsNbIN += agCache.pkts;
751                  (asres->flowNbIN)++;
752                }
753#else
754                if (myPtrs->currentRouterPtr->sampled != 0 ){
755                  /* IN ("traffic to the AS")  */
756                  asres->bytesNbIN += agCache.bytes;
757                  asres->pktsNbIN += agCache.pkts;
758                  (asres->flowNbIN)++;
759                }
760                if (asres->sampling == 0
761                    && myPtrs->currentRouterPtr->sampled != 0){
762                  asres->sampling = myPtrs->currentRouterPtr->sampled;
763                }
764#endif
765              }
766            }
767          }
768        }
769#endif
770        if ( (bool == 1) && (isMplsFlow == 0) ){
771          /* Update the information db (aka RenetcolMIB) */
772          myPtrs->currentMIB->ipv4Bytes += agCache.bytes;
773          myPtrs->currentMIB->ipv4Pckts += agCache.pkts;
774          myPtrs->currentMIB->ipv4Flow += 1;
775          switch (agCache.tProt){
776          case 1:
777            myPtrs->currentMIB->ipv4IcmpFlowNb += 1;
778            myPtrs->currentMIB->ipv4IcmpBytesNb += agCache.bytes;
779            myPtrs->currentMIB->ipv4IcmpPktsNb += agCache.pkts;
780            break;
781          case 6:
782            myPtrs->currentMIB->ipv4TCPFlowNb += 1;
783            myPtrs->currentMIB->ipv4TCPBytesNb += agCache.bytes;
784            myPtrs->currentMIB->ipv4TCPPktsNb += agCache.pkts;
785            break;
786          case 17:
787            myPtrs->currentMIB->ipv4UDPFlowNb += 1;
788            myPtrs->currentMIB->ipv4UDPBytesNb += agCache.bytes;
789            myPtrs->currentMIB->ipv4UDPPktsNb += agCache.pkts;
790            break;
791          default:
792            myPtrs->currentMIB->ipv4OthersFlowNb += 1;
793            myPtrs->currentMIB->ipv4OthersBytesNb += agCache.bytes;
794            myPtrs->currentMIB->ipv4OthersPktsNb += agCache.pkts;
795            break;
796          }
797          if (agCache.pkts==1){
798            myPtrs->currentMIB->ipv4FlowSizePcktsE1 += 1;
799          } else if (agCache.pkts<10) {
800            myPtrs->currentMIB->ipv4FlowSizePcktsLT10 += 1;
801          } else if (agCache.pkts<100) {
802            myPtrs->currentMIB->ipv4FlowSizePcktsLT100 += 1;
803          } else if (agCache.pkts<1000) {
804            myPtrs->currentMIB->ipv4FlowSizePcktsLT1k += 1;
805          } else if (agCache.pkts<10000) {
806            myPtrs->currentMIB->ipv4FlowSizePcktsLT10k += 1;
807          } else if (agCache.pkts>=10000) {
808            myPtrs->currentMIB->ipv4FlowSizePcktsMT10k += 1;
809          }
810          if (agCache.bytes<50){
811            myPtrs->currentMIB->ipv4FlowSizeBytesLT50 += 1;
812          } else if (agCache.bytes<100) {
813            myPtrs->currentMIB->ipv4FlowSizeBytesLT100 += 1;
814          } else if (agCache.bytes<1000) {
815            myPtrs->currentMIB->ipv4FlowSizeBytesLT1k += 1;
816          } else if (agCache.bytes<10000) {
817            myPtrs->currentMIB->ipv4FlowSizeBytesLT10k += 1;
818          } else if (agCache.bytes<100000) {
819            myPtrs->currentMIB->ipv4FlowSizeBytesLT100k += 1;
820          } else if (agCache.bytes<1000000) {
821            myPtrs->currentMIB->ipv4FlowSizeBytesLT1M += 1;
822          } else if (agCache.bytes<10000000) {
823            myPtrs->currentMIB->ipv4FlowSizeBytesLT10M += 1;
824          } else if (agCache.bytes<100000000) {
825            myPtrs->currentMIB->ipv4FlowSizeBytesLT100M += 1;
826          } else if (agCache.bytes>=100000000) {
827            myPtrs->currentMIB->ipv4FlowSizeBytesMT100M += 1;
828          }
829          switch (agCache.dPort){
830          case 53:
831            myPtrs->currentMIB->ipv4DNSFlowNb += 1;
832            myPtrs->currentMIB->ipv4DNSBytesNb += agCache.bytes;
833            myPtrs->currentMIB->ipv4DNSPcktsNb += agCache.pkts;
834            break;
835          case 80:
836            myPtrs->currentMIB->ipv4WebFlowNb += 1;
837            myPtrs->currentMIB->ipv4WebBytesNb += agCache.bytes;
838            myPtrs->currentMIB->ipv4WebPcktsNb += agCache.pkts;
839            break;
840          default:
841            myPtrs->currentMIB->ipv4OthersApFlowNb += 1;
842            myPtrs->currentMIB->ipv4OthersApBytesNb += agCache.bytes;
843            myPtrs->currentMIB->ipv4OthersApPcktsNb += agCache.pkts;
844            break;
845          } 
846          /* end of mib update */
847        }
848        /*
849         * PREFIX &/or MATRIX ACCOUNTING
850         */
851#if defined(IPV4AGGIDR) || defined(IPV4AGGIDSNMP)
852        if ( (bool == 1) && (isMplsFlow == 0) ){
853          prefixKey.beginning = agCache.v4AdS>>(32-agCache.maskS)<<(32-agCache.maskS);
854          res = bsearch(&prefixKey, V4PTab, nbPV4,
855                        sizeof(struct PrefixV4), prefGlobalCmp);
856          if (res!=NULL){
857            /* WE HAVE FOUND SOURCE ADDRESS IN OUR LIST */
858            if (res->hasSubnet == 1) {
859              resSub = NULL;
860              resSub = bsearch(&prefixKey, V4STab, nbSV4,
861                               sizeof(struct PrefixV4), prefGlobalCmp);
862              if (resSub != NULL) {
863                res = resSub;
864                resSub = NULL;
865              }
866            }
867#ifdef DEBUG
868            fprintf(stderr,"S %lu.%lu.%lu.%lu/%hu %lu.%lu.%lu.%lu/%hu Rs %lu Ps %lu SNMPin(hu) %hu\n",
869                    (agCache.v4AdS>>24),
870                    (agCache.v4AdS<<8>>24),
871                    (agCache.v4AdS<<16>>24),
872                    (agCache.v4AdS<<24>>24),
873                    (agCache.maskS),
874                    (agCache.v4AdD>>24),
875                    (agCache.v4AdD<<8>>24),
876                    (agCache.v4AdD<<16>>24),
877                    (agCache.v4AdD<<24>>24),
878                    (agCache.maskD),
879                    myPtrs->currentRouterPtr->sampled,
880                    res->sampling,
881                    agCache.inputSnmp);
882#endif
883#if defined(IPV4AGGIDR)
884            if ( myPtrs->routersID[res->routerNb] == agCache.routerAd  ) {
885#elif defined(IPV4AGGIDSNMP)
886              if ( myPtrs->currentRouterPtr->snmpIndexList[agCache.inputSnmp] == 1  ) {       
887#endif
888                /* OUT ("traffic from the prefix/subnet")  */
889#if defined(MULTISAMPLING)
890                if (myPtrs->currentRouterPtr->sampled != res->sampling ){
891                  res->bytesNbOUT += agCache.bytes*myPtrs->currentRouterPtr->sampled/res->sampling;
892                  res->pktsNbOUT += agCache.pkts*myPtrs->currentRouterPtr->sampled/res->sampling;
893                  /* (res->flowNbOUT)++; FIXME : FIND SOMETHING*/
894                  if (agCache.dscp>>2 == FIRST_CoS) {
895                    res->firstCoSOUT += agCache.bytes*myPtrs->currentRouterPtr->sampled/res->sampling;
896                  } else if (agCache.dscp>>2 == SECOND_CoS) {
897                    res->secondCoSOUT += agCache.bytes*myPtrs->currentRouterPtr->sampled/res->sampling;
898                  } else if (agCache.dscp>>2 == THIRD_CoS) {
899                    res->thirdCoSOUT += agCache.bytes*myPtrs->currentRouterPtr->sampled/res->sampling;
900                  } else {
901                    res->fourthCoSOUT += agCache.bytes*myPtrs->currentRouterPtr->sampled/res->sampling;
902                  }
903                }else{
904                  res->bytesNbOUT += agCache.bytes;
905                  res->pktsNbOUT += agCache.pkts;
906                  (res->flowNbOUT)++;
907                  if (agCache.dscp>>2 == FIRST_CoS) {
908                    res->firstCoSOUT += agCache.bytes;
909                  } else if (agCache.dscp>>2 == SECOND_CoS) {
910                    res->secondCoSOUT += agCache.bytes;
911                  } else if (agCache.dscp>>2 == THIRD_CoS) {
912                    res->thirdCoSOUT += agCache.bytes;
913                  } else {
914                    res->fourthCoSOUT += agCache.bytes;
915                  }
916                }
917#else
918                if (myPtrs->currentRouterPtr->sampled != 0 ){
919                  res->bytesNbOUT += agCache.bytes;
920                  res->pktsNbOUT += agCache.pkts;
921                  (res->flowNbOUT)++;
922                  if (agCache.dscp>>2 == FIRST_CoS) {
923                    res->firstCoSOUT += agCache.bytes;
924                  } else if (agCache.dscp>>2 == SECOND_CoS) {
925                    res->secondCoSOUT += agCache.bytes;
926                  } else if (agCache.dscp>>2 == THIRD_CoS) {
927                    res->thirdCoSOUT += agCache.bytes;
928                  } else {
929                    res->fourthCoSOUT += agCache.bytes;
930                  }
931                }
932                if (res->sampling == 0
933                    && myPtrs->currentRouterPtr->sampled != 0){
934                  res->sampling = myPtrs->currentRouterPtr->sampled;
935                }
936#endif
937#if defined(IPV4AGGIDSNMP)
938                prefixKey.beginning = agCache.v4AdD>>(32-agCache.maskD)<<(32-agCache.maskD);
939                res3 = bsearch(&prefixKey, V4PTab, nbPV4,
940                               sizeof(struct PrefixV4), prefGlobalCmp);
941                if (res3!=NULL){
942                  /* res is supernet or subnet ? */
943                  if (res3->hasSubnet == 1) {
944                    resSub = NULL;
945                    resSub = bsearch(&prefixKey, V4STab, nbSV4,
946                                     sizeof(struct PrefixV4), prefGlobalCmp);
947                    if (resSub != NULL) {
948                      res3 = resSub;
949                      resSub = NULL;
950                    }
951                  }
952#ifdef DEBUG
953            fprintf(stderr,"S&D %lu.%lu.%lu.%lu/%hu %lu.%lu.%lu.%lu/%hu Rs %lu Ps %lu SNMPin %hu\n",
954                    (agCache.v4AdS>>24),
955                    (agCache.v4AdS<<8>>24),
956                    (agCache.v4AdS<<16>>24),
957                    (agCache.v4AdS<<24>>24),
958                    (agCache.maskS),
959                    (agCache.v4AdD>>24),
960                    (agCache.v4AdD<<8>>24),
961                    (agCache.v4AdD<<16>>24),
962                    (agCache.v4AdD<<24>>24),
963                    (agCache.maskD),
964                    myPtrs->currentRouterPtr->sampled,
965                    res3->sampling,
966                    agCache.inputSnmp);
967#endif
968#if defined(MULTISAMPLING)
969                  if (myPtrs->currentRouterPtr->sampled != res3->sampling ){
970                    res3->bytesNbIN += agCache.bytes*myPtrs->currentRouterPtr->sampled/res3->sampling;
971                    res3->pktsNbIN += agCache.pkts*myPtrs->currentRouterPtr->sampled/res3->sampling;
972                    /* (res3->flowNbIN)++;  FIXME : FIND SOMETHING */
973                    if (agCache.dscp>>2 == FIRST_CoS) {
974                      res3->firstCoSIN += agCache.bytes*myPtrs->currentRouterPtr->sampled/res3->sampling;
975                    } else if (agCache.dscp>>2 == SECOND_CoS) {
976                      res3->secondCoSIN += agCache.bytes*myPtrs->currentRouterPtr->sampled/res3->sampling;
977                    } else if (agCache.dscp>>2 == THIRD_CoS) {
978                      res3->thirdCoSIN += agCache.bytes*myPtrs->currentRouterPtr->sampled/res3->sampling;
979                    } else {
980                      res3->fourthCoSIN += agCache.bytes*myPtrs->currentRouterPtr->sampled/res3->sampling;
981                    }
982                  }else{
983                    res3->bytesNbIN += agCache.bytes;
984                    res3->pktsNbIN += agCache.pkts;
985                    (res3->flowNbIN)++;
986                    if (agCache.dscp>>2 == FIRST_CoS) {
987                      res3->firstCoSIN += agCache.bytes;
988                    } else if (agCache.dscp>>2 == SECOND_CoS) {
989                      res3->secondCoSIN += agCache.bytes;
990                    } else if (agCache.dscp>>2 == THIRD_CoS) {
991                      res3->thirdCoSIN += agCache.bytes;
992                    } else {
993                      res3->fourthCoSIN += agCache.bytes;
994                    }
995                  }
996#else
997                  if (myPtrs->currentRouterPtr->sampled != 0 ){
998                    /* IN ("traffic to the prefix/subnet")  */
999                    res3->bytesNbIN += agCache.bytes;
1000                    res3->pktsNbIN += agCache.pkts;
1001                    (res3->flowNbIN)++;
1002                    if (agCache.dscp>>2 == FIRST_CoS) {
1003                      res3->firstCoSIN += agCache.bytes;
1004                    } else if (agCache.dscp>>2 == SECOND_CoS) {
1005                      res3->secondCoSIN += agCache.bytes;
1006                    } else if (agCache.dscp>>2 == THIRD_CoS) {
1007                      res3->thirdCoSIN += agCache.bytes;
1008                    } else {
1009                      res3->fourthCoSIN += agCache.bytes;
1010                    }
1011                  }
1012                  if (res3->sampling == 0
1013                      && myPtrs->currentRouterPtr->sampled != 0){
1014                    res3->sampling = myPtrs->currentRouterPtr->sampled;
1015                  }
1016#endif
1017                }
1018#endif
1019#if defined(MATRIX) && defined(IPV4AGGIDR)
1020                /* inter-pop matrix Accounting */
1021                prefixKey.beginning = agCache.v4AdD>>(32-agCache.maskD)<<(32-agCache.maskD);
1022                res2 = bsearch(&prefixKey, V4PTab, nbPV4,
1023                               sizeof(struct PrefixV4), prefGlobalCmp);
1024                if (res2!=NULL){               
1025                  ((struct POP *)((myPtrs->matrixPOP)
1026                                  +((res->routerNb)*ROUTER_INDEX_MAX)
1027                                  +((res2->routerNb))))->pktsNb += agCache.pkts;
1028                  ((struct POP *)((myPtrs->matrixPOP)
1029                                  +((res->routerNb)*ROUTER_INDEX_MAX)
1030                                  +((res2->routerNb))))->bytesNb += agCache.bytes;
1031                  ((struct POP *)((myPtrs->matrixPOP)
1032                                  +((res->routerNb)*ROUTER_INDEX_MAX)
1033                                  +((res2->routerNb))))->flowNb++;
1034                } else {
1035                  (
1036                   ((struct POP *)(myPtrs->matrixPOP)
1037                    +((res->routerNb)*ROUTER_INDEX_MAX)
1038                    +((ROUTER_INDEX_MAX-1))))->pktsNb += agCache.pkts;
1039                  (
1040                   ((struct POP *)(myPtrs->matrixPOP)
1041                    +((res->routerNb)*ROUTER_INDEX_MAX)
1042                    +((ROUTER_INDEX_MAX-1))))->bytesNb += agCache.bytes;
1043                  (
1044                   ((struct POP *)(myPtrs->matrixPOP)
1045                    +((res->routerNb)*ROUTER_INDEX_MAX)
1046                    +((ROUTER_INDEX_MAX-1))))->flowNb++;
1047                }
1048                /* end interpop matrix accounting */
1049#endif /* matrix */
1050              } else {
1051                /* doublon or bad reference in prefix list */
1052#if defined(IPV4AGGIDR)
1053              }
1054#elif defined(IPV4AGGIDSNMP)
1055            }
1056#endif
1057          } else { /* SOURCE ADDRESS DOESN'T IN OUR LIST */
1058            prefixKey.beginning = agCache.v4AdD>>(32-agCache.maskD)<<(32-agCache.maskD);
1059            res = bsearch(&prefixKey, V4PTab, nbPV4,
1060                          sizeof(struct PrefixV4), prefGlobalCmp);
1061            if (res!=NULL){
1062              /* DESTINATION ADDRESS IS IN OUR LIST */
1063              if (res->hasSubnet == 1) {
1064                resSub = NULL;
1065                resSub = bsearch(&prefixKey, V4STab, nbSV4,
1066                                 sizeof(struct PrefixV4), prefGlobalCmp);
1067                if (resSub != NULL) {
1068                  res = resSub;
1069                  resSub = NULL;
1070                }
1071              }
1072#ifdef DEBUG
1073            fprintf(stderr,"D %lu.%lu.%lu.%lu/%hu %lu.%lu.%lu.%lu/%hu Rs %lu Ps %lu R@ %lu.%lu.%lu.%lu SNMPin %hu\n",
1074                    (agCache.v4AdS>>24),
1075                    (agCache.v4AdS<<8>>24),
1076                    (agCache.v4AdS<<16>>24),
1077                    (agCache.v4AdS<<24>>24),
1078                    (agCache.maskS),
1079                    (agCache.v4AdD>>24),
1080                    (agCache.v4AdD<<8>>24),
1081                    (agCache.v4AdD<<16>>24),
1082                    (agCache.v4AdD<<24>>24),
1083                    (agCache.maskD),
1084                    myPtrs->currentRouterPtr->sampled,
1085                    res->sampling,
1086                    (myPtrs->pcktPtr->ipH->srcAdd>>24),
1087                    (myPtrs->pcktPtr->ipH->srcAdd<<8>>24),
1088                    (myPtrs->pcktPtr->ipH->srcAdd<<16>>24),
1089                    (myPtrs->pcktPtr->ipH->srcAdd<<24>>24),
1090                    agCache.inputSnmp);
1091#endif
1092#if defined(IPV4AGGIDSNMP)
1093              if ( myPtrs->currentRouterPtr->snmpIndexList[agCache.inputSnmp] == 1  ) {
1094#if defined(MULTISAMPLING)
1095                if (myPtrs->currentRouterPtr->sampled != res->sampling ){
1096                  res->bytesNbIN += agCache.bytes*myPtrs->currentRouterPtr->sampled/res->sampling;
1097                  res->pktsNbIN += agCache.pkts*myPtrs->currentRouterPtr->sampled/res->sampling;
1098                  if (agCache.dscp>>2 == FIRST_CoS) {
1099                    res->firstCoSIN += agCache.bytes*myPtrs->currentRouterPtr->sampled/res->sampling;
1100                  } else if (agCache.dscp>>2 == SECOND_CoS) {
1101                    res->secondCoSIN += agCache.bytes*myPtrs->currentRouterPtr->sampled/res->sampling;
1102                  } else if (agCache.dscp>>2 == THIRD_CoS) {
1103                    res->thirdCoSIN += agCache.bytes*myPtrs->currentRouterPtr->sampled/res->sampling;
1104                  } else {
1105                    res->fourthCoSIN += agCache.bytes*myPtrs->currentRouterPtr->sampled/res->sampling;
1106                  }
1107                }else{
1108                  res->bytesNbIN += agCache.bytes;
1109                  res->pktsNbIN += agCache.pkts;
1110                  (res->flowNbIN)++;
1111                  if (agCache.dscp>>2 == FIRST_CoS) {
1112                    res->firstCoSIN += agCache.bytes;
1113                  } else if (agCache.dscp>>2 == SECOND_CoS) {
1114                    res->secondCoSIN += agCache.bytes;
1115                  } else if (agCache.dscp>>2 == THIRD_CoS) {
1116                    res->thirdCoSIN += agCache.bytes;
1117                  } else {
1118                    res->fourthCoSIN += agCache.bytes;
1119                  }
1120                }
1121#else
1122                if (myPtrs->currentRouterPtr->sampled != 0 ){
1123                  /* IN ("traffic to the prefix/subnet")  */
1124                  res->bytesNbIN += agCache.bytes;
1125                  res->pktsNbIN += agCache.pkts;
1126                  (res->flowNbIN)++;
1127                  if (agCache.dscp>>2 == FIRST_CoS) {
1128                    res->firstCoSIN += agCache.bytes;
1129                  } else if (agCache.dscp>>2 == SECOND_CoS) {
1130                    res->secondCoSIN += agCache.bytes;
1131                  } else if (agCache.dscp>>2 == THIRD_CoS) {
1132                    res->thirdCoSIN += agCache.bytes;
1133                  } else {
1134                    res->fourthCoSIN += agCache.bytes;
1135                  }
1136                }
1137#endif
1138              }
1139#endif
1140#if defined(IPV4AGGIDR)
1141              if ( myPtrs->routersID[res->routerNb] == agCache.routerAd  ) {
1142                if (myPtrs->currentRouterPtr->sampled != 0 ){
1143                  /* IN ("traffic to the prefix")  */
1144                  res->bytesNbIN += agCache.bytes;
1145                  res->pktsNbIN += agCache.pkts;
1146                  (res->flowNbIN)++;
1147                  if (agCache.dscp>>2 == FIRST_CoS) {
1148                    res->firstCoSIN += agCache.bytes;
1149                  } else if (agCache.dscp>>2 == SECOND_CoS) {
1150                    res->secondCoSIN += agCache.bytes;
1151                  } else if (agCache.dscp>>2 == THIRD_CoS) {
1152                    res->thirdCoSIN += agCache.bytes;
1153                  } else {
1154                    res->fourthCoSIN += agCache.bytes;
1155                  }
1156                }
1157              }
1158              if (res->sampling == 0
1159                  && myPtrs->currentRouterPtr->sampled != 0 ){
1160                res->sampling = myPtrs->currentRouterPtr->sampled;
1161              }
1162#endif
1163            } else {
1164              /* UNKNOW SUBNET CASE                                        */
1165              /*                                                           */
1166              /* HERE : we are in the cases of the address/mask don't      */
1167              /*        belong to a prefix listed in the IPv4 prefix file  */
1168              /* possibilities :                                           */
1169              /*     -  prefix not referenced but allowed to be routed     */
1170              /*     -  prefix not referenced but not allowed to be routed */
1171              /*     -  spoofing                                           */
1172#ifdef PRINTUNKNOWNSUBNET 
1173              fprintf(stderr, "%lu.%lu.%lu.%lu/%hu -> %lu.%lu.%lu.%lu/%hu (R:%lu.%lu.%lu.%lu) \n",
1174                      (agCache.v4AdS>>24),
1175                      (agCache.v4AdS<<8>>24),
1176                      (agCache.v4AdS<<16>>24),
1177                      (agCache.v4AdS<<24>>24),
1178                      (agCache.maskS),
1179                      (agCache.v4AdD>>24),
1180                      (agCache.v4AdD<<8>>24),
1181                      (agCache.v4AdD<<16>>24),
1182                      (agCache.v4AdD<<24>>24),
1183                      (agCache.maskD),
1184                      (myPtrs->pcktPtr->ipH->srcAdd>>24),
1185                      (myPtrs->pcktPtr->ipH->srcAdd<<8>>24),
1186                      (myPtrs->pcktPtr->ipH->srcAdd<<16>>24),
1187                      (myPtrs->pcktPtr->ipH->srcAdd<<24>>24)
1188                      );
1189#endif /* PRINTUNKNOWNSUBNET */
1190            }
1191          } /* end of the Destination prefix is in our list */
1192        } /* end of the prefix is in our list */
1193        bool = 0;
1194#endif /* (IPV4AGGIDR) || (IPV4AGGIDSNMP) */
1195        if ( ( isIPv6 == 1 ) && (isMplsFlow == 0) ){
1196#ifdef IPV6LINKAGG
1197          ((struct IndexV6 *)((myPtrs->currentV6IndexTab)
1198                              +((myPtrs->currentRouterPtr->ID)*MAX_INDEX_BY_ROUTER)
1199                              +(agCache.inputSnmp)))->routerIPAddress = myPtrs->currentRouterPtr->IpAddress;
1200          ((struct IndexV6 *)((myPtrs->currentV6IndexTab)
1201                              +((myPtrs->currentRouterPtr->ID)*MAX_INDEX_BY_ROUTER)
1202                              +(agCache.outputSnmp)))->routerIPAddress = myPtrs->currentRouterPtr->IpAddress;
1203          ((struct IndexV6 *)((myPtrs->currentV6IndexTab)
1204                              +((myPtrs->currentRouterPtr->ID)*MAX_INDEX_BY_ROUTER)
1205                              +(agCache.inputSnmp)))->indexSNMP = agCache.inputSnmp;
1206          ((struct IndexV6 *)((myPtrs->currentV6IndexTab)
1207                              +((myPtrs->currentRouterPtr->ID)*MAX_INDEX_BY_ROUTER)
1208                              +(agCache.outputSnmp)))->indexSNMP = agCache.outputSnmp;
1209          /* FIXME, error or warning if (indexSNMP != agCache.outputSnmp) */
1210          ((struct IndexV6 *)((myPtrs->currentV6IndexTab)
1211                              +((myPtrs->currentRouterPtr->ID)*MAX_INDEX_BY_ROUTER)
1212                              +(agCache.inputSnmp)))->hasStats = 1;
1213          ((struct IndexV6 *)((myPtrs->currentV6IndexTab)
1214                              +((myPtrs->currentRouterPtr->ID)*MAX_INDEX_BY_ROUTER)
1215                              +(agCache.outputSnmp)))->hasStats = 1;
1216          ((struct IndexV6 *)((myPtrs->currentV6IndexTab)
1217                              +((myPtrs->currentRouterPtr->ID)*MAX_INDEX_BY_ROUTER)
1218                              +(agCache.inputSnmp)))->bytesNbIN += agCache.bytes;
1219          ((struct IndexV6 *)((myPtrs->currentV6IndexTab)
1220                              +((myPtrs->currentRouterPtr->ID)*MAX_INDEX_BY_ROUTER)
1221                              +(agCache.outputSnmp)))->bytesNbOUT += agCache.bytes;
1222          ((struct IndexV6 *)((myPtrs->currentV6IndexTab)
1223                              +((myPtrs->currentRouterPtr->ID)*MAX_INDEX_BY_ROUTER)
1224                              +(agCache.inputSnmp)))->pktsNbIN += agCache.pkts;
1225          ((struct IndexV6 *)((myPtrs->currentV6IndexTab)
1226                              +((myPtrs->currentRouterPtr->ID)*MAX_INDEX_BY_ROUTER)
1227                              +(agCache.outputSnmp)))->pktsNbOUT += agCache.pkts;
1228          ((struct IndexV6 *)((myPtrs->currentV6IndexTab)
1229                              +((myPtrs->currentRouterPtr->ID)*MAX_INDEX_BY_ROUTER)
1230                              +(agCache.inputSnmp)))->flowNbIN++;
1231          ((struct IndexV6 *)((myPtrs->currentV6IndexTab)
1232                              +((myPtrs->currentRouterPtr->ID)*MAX_INDEX_BY_ROUTER)
1233                              +(agCache.outputSnmp)))->flowNbOUT++;
1234/*        fprintf(stderr,"IPV6LINKAGG;IN;%hu;OUT;%hu;router;%lu;bytes;%lu\n", */
1235/*                agCache.inputSnmp, */
1236/*                agCache.outputSnmp, */
1237/*                myPtrs->currentRouterPtr->IpAddress, */
1238/*                agCache.bytes */
1239/*               ); */
1240#endif /* IPV6LINKAGG */
1241          /* Update the information db (aka RenetcolMIB) */
1242          myPtrs->currentMIB->ipv6Bytes += agCache.bytes;
1243          myPtrs->currentMIB->ipv6Pckts += agCache.pkts;
1244          myPtrs->currentMIB->ipv6Flow += 1;
1245          switch (agCache.tProt){
1246          case 1:
1247            myPtrs->currentMIB->ipv6IcmpFlowNb += 1;
1248            myPtrs->currentMIB->ipv6IcmpBytesNb += agCache.bytes;
1249            myPtrs->currentMIB->ipv6IcmpPktsNb += agCache.pkts;
1250            break;
1251          case 6:
1252            myPtrs->currentMIB->ipv6TCPFlowNb += 1;
1253            myPtrs->currentMIB->ipv6TCPBytesNb += agCache.bytes;
1254            myPtrs->currentMIB->ipv6TCPPktsNb += agCache.pkts;
1255            break;
1256          case 17:
1257            myPtrs->currentMIB->ipv6UDPFlowNb += 1;
1258            myPtrs->currentMIB->ipv6UDPBytesNb += agCache.bytes;
1259            myPtrs->currentMIB->ipv6UDPPktsNb += agCache.pkts;
1260            break;
1261          default:
1262            myPtrs->currentMIB->ipv6OthersFlowNb += 1;
1263            myPtrs->currentMIB->ipv6OthersBytesNb += agCache.bytes;
1264            myPtrs->currentMIB->ipv6OthersPktsNb += agCache.pkts;
1265            break;
1266          }
1267          if (agCache.pkts==1){
1268            myPtrs->currentMIB->ipv6FlowSizePcktsE1 += 1;
1269          } else if (agCache.pkts<10) {
1270            myPtrs->currentMIB->ipv6FlowSizePcktsLT10 += 1;
1271          } else if (agCache.pkts<100) {
1272            myPtrs->currentMIB->ipv6FlowSizePcktsLT100 += 1;
1273          } else if (agCache.pkts<1000) {
1274            myPtrs->currentMIB->ipv6FlowSizePcktsLT1k += 1;
1275          } else if (agCache.pkts<10000) {
1276            myPtrs->currentMIB->ipv6FlowSizePcktsLT10k += 1;
1277          } else if (agCache.pkts>=10000) {
1278            myPtrs->currentMIB->ipv6FlowSizePcktsMT10k += 1;
1279          }
1280          if (agCache.bytes<50){
1281            myPtrs->currentMIB->ipv6FlowSizeBytesLT50 += 1;
1282          } else if (agCache.bytes<100) {
1283            myPtrs->currentMIB->ipv6FlowSizeBytesLT100 += 1;
1284          } else if (agCache.bytes<1000) {
1285            myPtrs->currentMIB->ipv6FlowSizeBytesLT1k += 1;
1286          } else if (agCache.bytes<10000) {
1287            myPtrs->currentMIB->ipv6FlowSizeBytesLT10k += 1;
1288          } else if (agCache.bytes<100000) {
1289            myPtrs->currentMIB->ipv6FlowSizeBytesLT100k += 1;
1290          } else if (agCache.bytes<1000000) {
1291            myPtrs->currentMIB->ipv6FlowSizeBytesLT1M += 1;
1292          } else if (agCache.bytes<10000000) {
1293            myPtrs->currentMIB->ipv6FlowSizeBytesLT10M += 1;
1294          } else if (agCache.bytes<100000000) {
1295            myPtrs->currentMIB->ipv6FlowSizeBytesLT100M += 1;
1296          } else if (agCache.bytes>=100000000) {
1297            myPtrs->currentMIB->ipv6FlowSizeBytesMT100M += 1;
1298          }
1299          switch (agCache.dPort){
1300          case 53:
1301            myPtrs->currentMIB->ipv6DNSFlowNb += 1;
1302            myPtrs->currentMIB->ipv6DNSBytesNb += agCache.bytes;
1303            myPtrs->currentMIB->ipv6DNSPcktsNb += agCache.pkts;
1304            break;
1305          case 80:
1306            myPtrs->currentMIB->ipv6WebFlowNb += 1;
1307            myPtrs->currentMIB->ipv6WebBytesNb += agCache.bytes;
1308            myPtrs->currentMIB->ipv6WebPcktsNb += agCache.pkts;
1309            break;
1310          default:
1311            myPtrs->currentMIB->ipv6OthersApFlowNb += 1;
1312            myPtrs->currentMIB->ipv6OthersApBytesNb += agCache.bytes;
1313            myPtrs->currentMIB->ipv6OthersApPcktsNb += agCache.pkts;
1314            break;
1315          } 
1316          /* end of mib update */
1317          isIPv6 = 0;
1318        }
1319        isMplsFlow = 0;
1320        /*
1321         *
1322         * SOCKET OUTPUT TO A REMOTE CLIENT
1323         *
1324         * switch the rules definition (check & fieldToRecord),
1325         * we send the flow or a part of the flow to a remote host or a file.
1326         * In a first time (until release 0.0.7, the information was sent via
1327         * the process renetcolSender with an IPC message queue. But, the perf
1328         * of IPC Msg was very bad with a default system compilation.
1329         * So, now, we send information directly from here through sockets.
1330         */
1331        tmpRuleList = myPtrs->rulesListPtr;
1332        tmpRL = myPtrs->rulesListPtr;
1333        while (tmpRuleList){
1334          RuleDefPtr tmpRuleDefList = tmpRuleList->def;
1335          unsigned short check = 1;
1336          int s=0;
1337          secondOffset = secondOldOffset;
1338          while (tmpRuleDefList){
1339            check = check && tmpRuleDefList->check;
1340            tmpRuleDefList->check = 0;
1341            tmpRuleDefList = tmpRuleDefList->next;
1342          }
1343          if ( (tmpRuleList->def != NULL) && (check == 1)) {
1344            /* msg building */
1345            secondPftmp = tmp->lastField;
1346            msgTextIndex = mempcpy(mempcpy(mempcpy(myMsg.text,   
1347                                                   &tplMsgType,
1348                                                   sizeof(unsigned short)
1349                                                   ),
1350                                           &tmpRuleList->id,
1351                                           sizeof(tmpRuleList->id)
1352                                           ),
1353                                   &myPtrs->currentRouterPtr->IpAddress,
1354                                   sizeof(unsigned long)
1355                                   );
1356            msgTextIndex = mempcpy(mempcpy(mempcpy(msgTextIndex,
1357                                                   &tmp->sourceId,
1358                                                   sizeof(unsigned long)
1359                                                   ),
1360                                           &tmp->templateFlowSetId,
1361                                           sizeof(tmp->templateFlowSetId)
1362                                           ),
1363                                   myPtrs->ptr_buffer+secondOffset,
1364                                   flow_size
1365                                   );
1366            myMsg.type = 1;
1367             
1368
1369            /* NEW transfert type */
1370            for ( ; tmpRL; tmpRL=tmpRL->next){
1371              if (tmpRL->id == tmpRuleList->id){       
1372                s = sendMessage(tmpRL->host->sockId, myMsg.text, sizeof(myMsg.text),
1373                                tmpRL->host->hostAddressPtr);
1374              }
1375            }
1376            /* FIXME : perhaps check "s" */
1377            noEnd = 1;
1378            secondCpt=0;
1379          } /* end if check */
1380          tmpRuleList = tmpRuleList->next;
1381          tmpRL = myPtrs->rulesListPtr; /* ticket #11 */
1382          secondPftmp = tmp->lastField;
1383        } /* end while tmpRuleList */
1384        /*
1385         * end redirection
1386         */
1387        secondOffset = *myPtrs->offsetV9Ptr;
1388        secondOldOffset = secondOffset;
1389        pftmp = tmp->lastField;
1390        cpt=0;
1391        (*myPtrs->currentFlowsetNumberPtr)++; /* pointer on the flows number */
1392        if (((*myPtrs->offsetV9Ptr)-48-shift+flow_size) > data_length){
1393          overflow = 1; /* buffer index not correct */
1394        }
1395      } else {
1396        /* not the flow end, progress in field list */
1397        pftmp = pftmp->prev;
1398      }   
1399    } /* end of the while on one flow record */
1400       
1401    while ( ((*myPtrs->offsetV9Ptr)-48-shift) < data_length ) {
1402      (*myPtrs->offsetV9Ptr)++; /* if padding */
1403      paddingCounter++;
1404#ifdef DEBUG
1405        fprintf(stderr,", pC: %d ", paddingCounter);
1406#endif
1407      if ( paddingCounter > 8 ) {
1408        syslog(LOG_INFO,"padding too high: %d ", paddingCounter);
1409#ifdef DEBUG
1410        fprintf(stderr,", pC: %d <--| ", paddingCounter);
1411#endif
1412        return (-1);
1413      }
1414    }
1415    while ( (*myPtrs->offsetV9Ptr)-48-shift > data_length ) {
1416      (*myPtrs->offsetV9Ptr)--; /* crazy loop (when bug appears in template def) */
1417      crazyCounter++;
1418    }
1419#ifdef DEBUG
1420    if (crazyCounter != 0){ fprintf(stderr," crazyCounter: %d ", crazyCounter); }
1421#endif
1422    if (crazyCounter!=0) { syslog(LOG_INFO,"crazyCounter: %d ", crazyCounter);}
1423     
1424#ifdef DEBUG
1425    fprintf(stderr,"(%hu,%hu)}", data_length, data_length+shift);
1426#endif
1427     
1428    return (data_length+shift);
1429    /* end new place */
1430
1431  } else {
1432    /*
1433     *
1434     *
1435     *  OPTIONAL TEMPLATE
1436     *
1437     *
1438     */
1439    if ((tmpOpt=existTplOptId(myPtrs->currentRouterPtr, myPtrs->currentHeaderV9Ptr->sourceId,
1440                              (*myPtrs->currentFlowsetIdPtr)))!=NULL) {       
1441
1442      myPtrs->currentMIB->optDataFlowSetNb += 1;
1443#ifdef DEBUG
1444      fprintf(stderr,"<d id: %hu, lg %hu", (*myPtrs->currentFlowsetIdPtr), data_length);
1445#endif
1446      for ( i=0; i<(tmpOpt->optionScopeLg/4); i++){
1447        /* FIXME : today we skip the scope fields, it's bad :( */ 
1448        if ((pftmp=tmpOpt->lastField)!=NULL) {
1449          for (j=0; j<pftmp->fieldLength; j++) {
1450            (*myPtrs->offsetV9Ptr)++;
1451          }
1452          pftmp = pftmp->prev;
1453        }
1454      }
1455      while (pftmp != NULL) {
1456        if (pftmp->fieldLength==1){
1457          buffer1 = *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr)); (*myPtrs->offsetV9Ptr)++;
1458        }
1459        if (pftmp->fieldLength==2){
1460          buffer2[1]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr)); (*myPtrs->offsetV9Ptr)++;
1461          buffer2[0]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr)); (*myPtrs->offsetV9Ptr)++;
1462        }
1463        if (pftmp->fieldLength==4){
1464          buffer4[3]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr)); (*myPtrs->offsetV9Ptr)++;
1465          buffer4[2]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr)); (*myPtrs->offsetV9Ptr)++;
1466          buffer4[1]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr)); (*myPtrs->offsetV9Ptr)++;
1467          buffer4[0]= *(myPtrs->ptr_buffer+(*myPtrs->offsetV9Ptr)); (*myPtrs->offsetV9Ptr)++;
1468          if (pftmp->fieldType==34||pftmp->fieldType==50){
1469            if ((*((unsigned long*)&buffer4)==1)
1470                || (*((unsigned long*)&buffer4)==10)
1471                || (*((unsigned long*)&buffer4)==100)
1472                || (*((unsigned long*)&buffer4)==1000)) {
1473              if (myPtrs->currentRouterPtr->sampled != *((unsigned long*)&buffer4) ) {
1474#ifdef DEBUGAGG
1475                fprintf(stderr,"\n SV (p) %lu != %lu (r)", *((unsigned long*)&buffer4),
1476                        myPtrs->currentRouterPtr->sampled);
1477#endif
1478                syslog(LOG_INFO,"Sampling value change for router : %lu.%lu.%lu.%lu, old: %lu, new: %lu",
1479                       (myPtrs->pcktPtr->ipH->srcAdd>>24),
1480                       (myPtrs->pcktPtr->ipH->srcAdd<<8>>24),
1481                       (myPtrs->pcktPtr->ipH->srcAdd<<16>>24),
1482                       (myPtrs->pcktPtr->ipH->srcAdd<<24>>24),
1483                       myPtrs->currentRouterPtr->sampled,
1484                       *((unsigned long*)&buffer4)
1485                       );
1486                myPtrs->currentRouterPtr->sampled = *((unsigned long*)&buffer4);
1487              }
1488            }else{
1489              syslog(LOG_INFO,"Sampling value not standard for router : %lu.%lu.%lu.%lu, value : %lu",
1490                     (myPtrs->pcktPtr->ipH->srcAdd>>24),
1491                     (myPtrs->pcktPtr->ipH->srcAdd<<8>>24),
1492                     (myPtrs->pcktPtr->ipH->srcAdd<<16>>24),
1493                     (myPtrs->pcktPtr->ipH->srcAdd<<24>>24),
1494                     *((unsigned long*)&buffer4)
1495                     );
1496            }
1497          }
1498        }       
1499        pftmp = pftmp->prev;
1500      }
1501      if ( pftmp == NULL ) {
1502        while ((*myPtrs->offsetV9Ptr)%4 != 0) {
1503          (*myPtrs->offsetV9Ptr)++;
1504#ifdef DEBUG
1505          fprintf(stderr," p ");
1506#endif
1507        }
1508      } else {
1509        fprintf(stderr,"PB ");
1510      }
1511#ifdef DEBUG
1512      fprintf(stderr,">");
1513#endif
1514      myPtrs->currentMIB->realFlowNb += 1;
1515      return (data_length+shift);
1516    } else {
1517      /*
1518       * template unknown, we skip the data
1519       */
1520      (*myPtrs->offsetV9Ptr)+=(data_length-4);
1521      (*myPtrs->currentFlowsetNumberPtr)+= 1 ;
1522      /*      (*myPtrs->currentFlowsetNumberPtr) = myPtrs->currentHeaderV9Ptr->count;*/
1523#ifdef DEBUG
1524      fprintf(stderr, " U, r: %lu.%lu.%lu.%lu, sourceId: %lu, TID: %hu ",
1525              (myPtrs->pcktPtr->ipH->srcAdd>>24),
1526              (myPtrs->pcktPtr->ipH->srcAdd<<8>>24),
1527              (myPtrs->pcktPtr->ipH->srcAdd<<16>>24),
1528              (myPtrs->pcktPtr->ipH->srcAdd<<24>>24),
1529              myPtrs->currentHeaderV9Ptr->sourceId,
1530              (*myPtrs->currentFlowsetIdPtr)
1531              );
1532      fprintf(stderr,"(%hu,%hu) ", data_length, data_length+shift);
1533#endif
1534      return (data_length+shift);
1535    }
1536  }
1537}
Note: See TracBrowser for help on using the browser.