root/trunk/src/dataFlowSet.c

Revision 158, 60.0 KB (checked in by andreu, 11 years ago)

renetcol mib update

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