root/trunk/src/dataFlowSet.c @ 97

Revision 97, 46.9 KB (checked in by andreu, 14 years ago)

Rename old releases and update current

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