root/trunk/src/dataFlowSet.c @ 20

Revision 20, 21.9 KB (checked in by andreu, 16 years ago)

new release 0.0.6, with CRIHAN compilation feature

  • Property svn:eol-style set to native
Line 
1/*
2 * File: dataFlowSet.c
3 *
4 * Authors: ANDREU Francois-Xavier
5 *
6 * Copyright (C) 2005 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 * checkDataFlowSet
30 *
31 */
32unsigned short 
33checkDataFlowSet(unsigned short shift, RouterPtr cr, NetFlowV9HeaderPtr v9Ptr,
34                 unsigned short *offV9, unsigned char *buf, short *cFNPtr,
35                 short *cFId, DatagramPtr pcktPtr, RuleDefPtr *rulesCache,
36                 RulesPtr rlPtr, int myQueue, struct PrefixV4 *V4PTab,
37                 size_t nbPV4,
38                 struct IPFLowCache *ipCache, struct MPLSFlowCache *mplsCache,
39                 unsigned long *ipCounter, unsigned long *mplsCounter)
40{
41  TplFlowSetPtr tmp;
42  FieldPtr pftmp;
43  FieldPtr secondPftmp;
44  unsigned short data_length = 0;
45  unsigned short flow_size = 0;
46  unsigned short oldOffset = *offV9;
47  unsigned short secondOffset = 0;
48  unsigned short secondOldOffset = 0;
49  int moreIsNecessary = 1;
50  int field_size = 0;
51  int cpt = 0;
52  int secondCpt = 0;
53  int overflow = 0;
54  int noEnd = 1;
55  int i = 0;
56  int j = 0;
57  int pos = 0;
58  unsigned char buffer1; 
59  unsigned char buffer2[2];
60  unsigned char buffer4[4];
61  RulesPtr tmpRuleList = rlPtr;
62  msgType myMsg;
63  char *msgTextIndex;
64  unsigned short tplMsgType = 11;
65  struct PrefixV4 prefixKey, *res; /* for bsearch */
66  struct AggCache agCache;
67#ifdef CRIHAN
68  struct IPFLowCache ipFirstCache; /* CRI */
69  struct MPLSFlowCache mplsFirstCache; /* CRI */
70  unsigned long firstTime = 0; /* CRI */
71  unsigned long lastTime = 0; /* CRI */
72#endif /* CRIHAN */
73  int bool = 0;
74
75#ifdef CRIHAN
76  ipFirstCache.ipProt = 0;
77  ipFirstCache.bytes = 0;
78  ipFirstCache.pkts = 0;
79  ipFirstCache.inSnmp = 0;
80  ipFirstCache.outSnmp = 0;
81  ipFirstCache.v4AdS = 0;
82  ipFirstCache.v4AdD = 0;
83  ipFirstCache.tProt = 0;
84  ipFirstCache.sPort = 0;
85  ipFirstCache.dPort = 0;
86  ipFirstCache.maskD = 0;
87  ipFirstCache.maskS = 0;
88  ipFirstCache.routerAd = 0;
89  ipFirstCache.liveTime = 0;
90  mplsFirstCache.ipProt = 0;
91  mplsFirstCache.v4AdS = 0;
92  mplsFirstCache.v4AdD = 0;
93  mplsFirstCache.routerAd = 0;
94  mplsFirstCache.mplsLabel1 = 0;
95#endif /* CRIHAN */
96
97  buffer2[1] = *(buf+(*offV9));(*offV9)++;
98  buffer2[0] = *(buf+(*offV9));(*offV9)++;
99  (*cFId) = *((unsigned short*)&buffer2);
100  buffer2[1] = *(buf+(*offV9));(*offV9)++;
101  buffer2[0] = *(buf+(*offV9));(*offV9)++;
102  data_length = *((unsigned short*)&buffer2);
103  if ((tmp=existTplId(cr, v9Ptr->sourceId,
104                      (*cFId)))!=NULL) {
105    pftmp = tmp->lastField;
106    for (; pftmp; pftmp = pftmp->prev) {
107      flow_size += pftmp->fieldLength;
108    }
109    if ( data_length%flow_size >= 9 ) {
110      (*cFNPtr) = v9Ptr->count;
111      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",
112             (*cFId),
113             (pcktPtr->ipH->srcAdd>>24),
114             (pcktPtr->ipH->srcAdd<<8>>24),
115             (pcktPtr->ipH->srcAdd<<16>>24),
116             (pcktPtr->ipH->srcAdd<<24>>24));
117      return (data_length+shift);
118    }
119    /* aggreg */
120/*     agCache.routerAd = pcktPtr->ipH->srcAdd; */
121    /* end aggreg */
122
123#ifdef CRIHAN
124    ipFirstCache.routerAd = pcktPtr->ipH->srcAdd;
125    mplsFirstCache.routerAd = pcktPtr->ipH->srcAdd;
126#endif /* CRIHAN */
127
128    pftmp = tmp->lastField;
129    secondPftmp = tmp->lastField;   
130    secondOffset = *offV9;
131    secondOldOffset = secondOffset;
132    while ( (((*offV9)-48-shift) <= data_length) && (overflow!=1) ) {
133      /*
134       * progression in a flow Set
135       * notes:
136       *   48=header ip + header netf
137       *   shift = shift if there is a template declaration
138       */
139      cpt++;
140      j=0;
141      pos = (pftmp->fieldType)*10+j;
142      field_size = (int) pftmp->fieldLength;
143      /*
144       * Comparaison between the field value and the rules
145       * ... if one rule exist
146       */
147      if (((RuleDefPtr)(*(rulesCache+pos))) != NULL) {
148        oldOffset = *offV9;
149        while (((RuleDefPtr)(*(rulesCache+pos))) != NULL){
150          /*
151           * while on one cache table line
152           */
153          *offV9 = oldOffset;
154          switch ((int)
155                  (((RuleDefPtr)(*(rulesCache+pos)))->operator)){
156          case 2:
157            switch (field_size) {
158            case 1:
159              buffer1 = *(buf+(*offV9)); (*offV9)++;
160              /* rule check */
161              if (((RuleDefPtr)(*(rulesCache+pos)))->value->stor.cvalue
162                  == *((unsigned char*)&buffer1)) {
163                ((RuleDefPtr)(*(rulesCache+pos)))->check = 1;
164              }
165              /* end rule check */
166              /* aggregation */
167/*            if ((pftmp->fieldType==9)||(pftmp->fieldType==29)){ */
168/*              agCache.maskS = *((unsigned char*)&buffer1); */
169/*            } */
170/*            if ((pftmp->fieldType==13)||(pftmp->fieldType==30)){ */
171/*              agCache.maskD = *((unsigned char*)&buffer1); */
172/*            } */
173/*            if (pftmp->fieldType==60){ */
174/*              agCache.ipProt = *((unsigned char*)&buffer1); */
175/*            } */
176/*            if (pftmp->fieldType==4){ */
177/*              agCache.tProt = *((unsigned char*)&buffer1); */
178/*            } */
179/*            if (pftmp->fieldType==61){ */
180/*              agCache.sens = *((unsigned char*)&buffer1); */
181/*            } */
182/*            if (pftmp->fieldType==5){ */
183/*              agCache.dscp = *((unsigned char*)&buffer1); */
184/*            } */
185              /* end aggregation */
186#ifdef CRIHAN
187              if ((pftmp->fieldType==9)||(pftmp->fieldType==29)){
188                ipFirstCache.maskS = *((unsigned char*)&buffer1);
189              }
190              if ((pftmp->fieldType==13)||(pftmp->fieldType==30)){
191                ipFirstCache.maskD = *((unsigned char*)&buffer1);
192              }
193              if (pftmp->fieldType==60){
194                ipFirstCache.ipProt = *((unsigned char*)&buffer1);
195                mplsFirstCache.ipProt = *((unsigned char*)&buffer1);
196              }
197              if (pftmp->fieldType==4){
198                ipFirstCache.tProt = *((unsigned char*)&buffer1);
199              }
200#endif /* CRIHAN */
201              break;
202            case 2:
203              buffer2[1]= *(buf+(*offV9)); (*offV9)++;
204              buffer2[0]= *(buf+(*offV9)); (*offV9)++;
205              if (((RuleDefPtr)(*(rulesCache+pos)))->value->stor.svalue
206                  == *((unsigned short*)&buffer2))
207                ((RuleDefPtr)(*(rulesCache+pos)))->check = 1;
208              /* aggregation */
209/*            if (pftmp->fieldType==10){ */
210/*              agCache.idSnmp = *((unsigned short*)&buffer2); */
211/*            } */
212              /* end aggregation */
213#ifdef CRIHAN
214              if (pftmp->fieldType==10){
215                ipFirstCache.inSnmp = *((unsigned short*)&buffer2);
216              }
217              if (pftmp->fieldType==14){
218                ipFirstCache.outSnmp = *((unsigned short*)&buffer2);
219              }
220              if (pftmp->fieldType==7){
221                ipFirstCache.sPort = *((unsigned short*)&buffer2);
222              }
223              if (pftmp->fieldType==11){
224                ipFirstCache.dPort = *((unsigned short*)&buffer2);
225              }
226#endif /* CRIHAN */ 
227              break;
228            case 3:
229              buffer4[3]= 0;
230              buffer4[2]= *(buf+(*offV9)); (*offV9)++;
231              buffer4[1]= *(buf+(*offV9)); (*offV9)++;
232              buffer4[0]= *(buf+(*offV9)); (*offV9)++;
233              if (((RuleDefPtr)(*(rulesCache+pos)))->value->stor.lvalue
234                  == *((unsigned long*)&buffer4))
235                ((RuleDefPtr)(*(rulesCache+pos)))->check = 1;
236              /* aggregation */
237              /* end aggregation */
238#ifdef CRIHAN
239              if (pftmp->fieldType==70){
240                mplsFirstCache.mplsLabel1 = (*((unsigned long*)&buffer4))>>4;
241              }
242#endif /* CRIHAN */
243              break;
244            case 4:
245              buffer4[3]= *(buf+(*offV9)); (*offV9)++;
246              buffer4[2]= *(buf+(*offV9)); (*offV9)++;
247              buffer4[1]= *(buf+(*offV9)); (*offV9)++;
248              buffer4[0]= *(buf+(*offV9)); (*offV9)++;
249              /* FIXME : here , add a check on the field type */
250              if ((pftmp->fieldType==8)||(pftmp->fieldType==12)){
251                if ((((RuleDefPtr)(*(rulesCache+pos)))->value->stor.lvalue)
252                    == (*((unsigned long*)&buffer4))>>(32-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)<<(32-((RuleDefPtr)(*(rulesCache+pos)))->value->mask) )
253                  {
254                    ((RuleDefPtr)(*(rulesCache+pos)))->check = 1;
255                  }
256              }       
257              /* aggregation */
258/*            if ((pftmp->fieldType==8)){ */
259/*              agCache.v4AdS = *((unsigned long*)&buffer4); */
260/*            } */
261/*            if ((pftmp->fieldType==12)){ */
262/*              agCache.v4AdD = *((unsigned long*)&buffer4); */
263/*            } */
264/*            if (pftmp->fieldType==1){ */
265/*              agCache.bytes = *((unsigned long*)&buffer4); */
266/*            } */
267/*            if (pftmp->fieldType==2){ */
268/*              agCache.pkts = *((unsigned long*)&buffer4); */
269/*            } */
270              /* end aggregation */
271#ifdef CRIHAN
272              if (pftmp->fieldType==8){
273                ipFirstCache.v4AdS = *((unsigned long*)&buffer4);
274                mplsFirstCache.v4AdS = *((unsigned long*)&buffer4);
275              }
276              if (pftmp->fieldType==12){
277                ipFirstCache.v4AdD = *((unsigned long*)&buffer4);
278                mplsFirstCache.v4AdD = *((unsigned long*)&buffer4);
279              }
280              if (pftmp->fieldType==1){
281                ipFirstCache.bytes = *((unsigned long*)&buffer4);
282              }
283              if (pftmp->fieldType==2){
284                ipFirstCache.pkts = *((unsigned long*)&buffer4);
285              }
286              if (pftmp->fieldType==22){
287                firstTime = *((unsigned long*)&buffer4);
288              }
289              if (pftmp->fieldType==21){
290                lastTime = *((unsigned long*)&buffer4);
291              }
292#endif /* CRIHAN */
293              break;
294            case 16:
295              for (i=0; i<4; i++) {
296                buffer4[3]= *(buf+(*offV9)); (*offV9)++;
297                buffer4[2]= *(buf+(*offV9)); (*offV9)++;
298                buffer4[1]= *(buf+(*offV9)); (*offV9)++;
299                buffer4[0]= *(buf+(*offV9)); (*offV9)++;
300                if (1==moreIsNecessary){
301                  switch(i){
302                  case 0:
303                    if (((RuleDefPtr)(*(rulesCache+pos)))->value->mask <= 32){
304                      if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i])
305                          ==
306                          (*((unsigned long*)&buffer4))>>(32-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)<<(32-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)
307                          )
308                        {
309                          ((RuleDefPtr)(*(rulesCache+pos)))->check = 1;
310                          moreIsNecessary = 0;
311                        } else {
312                          ((RuleDefPtr)(*(rulesCache+pos)))->check = 0;
313                          moreIsNecessary = 0;
314                        }
315                    } else {
316                      if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i])
317                          ==
318                          (*((unsigned long*)&buffer4))
319                          )
320                        {
321                          ((RuleDefPtr)(*(rulesCache+pos)))->check = 1;
322                        } else {
323                          ((RuleDefPtr)(*(rulesCache+pos)))->check = 0;
324                          moreIsNecessary = 0;
325                        }
326                    }
327                    break;
328                  case 1:
329                    if (((RuleDefPtr)(*(rulesCache+pos)))->value->mask <= 64){
330                      if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i])
331                          ==
332                          (*((unsigned long*)&buffer4))>>(64-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)<<(64-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)
333                          )
334                        {
335                          ((RuleDefPtr)(*(rulesCache+pos)))->check =
336                            ((RuleDefPtr)(*(rulesCache+pos)))->check && 1;
337                          moreIsNecessary = 0;
338                        } else {
339                          ((RuleDefPtr)(*(rulesCache+pos)))->check = 0;
340                          moreIsNecessary = 0;
341                        }
342                    } else {
343                      if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i])
344                          ==
345                          (*((unsigned long*)&buffer4))
346                          )
347                        {
348                          ((RuleDefPtr)(*(rulesCache+pos)))->check =
349                            ((RuleDefPtr)(*(rulesCache+pos)))->check && 1;
350                        } else {
351                          ((RuleDefPtr)(*(rulesCache+pos)))->check = 0;
352                          moreIsNecessary = 0;
353                        }
354                    }
355                    break;
356                  case 2:
357                    if (((RuleDefPtr)(*(rulesCache+pos)))->value->mask <= 96){
358                      if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i])
359                          ==
360                          (*((unsigned long*)&buffer4))>>(96-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)<<(96-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)
361                          )
362                        {
363                          ((RuleDefPtr)(*(rulesCache+pos)))->check =
364                            ((RuleDefPtr)(*(rulesCache+pos)))->check && 1;
365                          moreIsNecessary = 0;
366                        } else {
367                          ((RuleDefPtr)(*(rulesCache+pos)))->check = 0;
368                          moreIsNecessary = 0;
369                        }
370                    } else {
371                      if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i])
372                          ==
373                          (*((unsigned long*)&buffer4))
374                          )
375                        {
376                          ((RuleDefPtr)(*(rulesCache+pos)))->check =
377                            ((RuleDefPtr)(*(rulesCache+pos)))->check && 1;
378                        } else {
379                          ((RuleDefPtr)(*(rulesCache+pos)))->check = 0;
380                          moreIsNecessary = 0;
381                        }
382                    }
383                    break;
384                  case 3:
385                    if (((RuleDefPtr)(*(rulesCache+pos)))->value->mask <= 128){
386                      if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i])
387                          ==
388                          (*((unsigned long*)&buffer4))>>(128-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)<<(128-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)
389                          )
390                        {
391                          ((RuleDefPtr)(*(rulesCache+pos)))->check =
392                            ((RuleDefPtr)(*(rulesCache+pos)))->check && 1;
393                        } else {
394                          ((RuleDefPtr)(*(rulesCache+pos)))->check = 0;
395                          moreIsNecessary = 0;
396                        }
397                    } else {
398                      if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i])
399                          ==
400                          (*((unsigned long*)&buffer4))
401                          )
402                        {
403                          ((RuleDefPtr)(*(rulesCache+pos)))->check =
404                            ((RuleDefPtr)(*(rulesCache+pos)))->check && 1;
405                        } else {
406                          ((RuleDefPtr)(*(rulesCache+pos)))->check = 0;
407                          moreIsNecessary = 0;
408                        }
409                    }
410                    break;
411                  default:
412                    break;
413                  } /* end of switch(i) */
414                } /* end of if moreIsNecessary */
415              }
416              moreIsNecessary = 1;
417              /* aggregation */
418             
419              /* end aggregation */
420              break;
421            default:
422              syslog(LOG_INFO, "Field size not known: %d\n", field_size);
423              for (i=0; i<field_size; i++){
424                (*offV9)++;
425              }
426              break;
427            }
428            break;
429          default:
430            syslog(LOG_INFO, "Operator not known: %d\n",
431                   (int)(((RuleDefPtr)(*(rulesCache+pos)))->operator));
432            break;
433          }
434          j++;
435          pos = (pftmp->fieldType)*10+j;
436        } /* end while rulesCache */
437      } else {
438        /*
439         * no rule within this field type, but we must reading the value
440         */
441        switch (field_size) {
442        case 1:
443          buffer1 = *(buf+(*offV9)); (*offV9)++;
444          /* aggregation */
445/*        if ((pftmp->fieldType==9)||(pftmp->fieldType==29)){ */
446/*          agCache.maskS = *((unsigned char*)&buffer1); */
447/*        } */
448/*        if ((pftmp->fieldType==13)||(pftmp->fieldType==30)){ */
449/*          agCache.maskD = *((unsigned char*)&buffer1); */
450/*        } */
451/*        if (pftmp->fieldType==60){ */
452/*          agCache.ipProt = *((unsigned char*)&buffer1); */
453/*        } */
454/*        if (pftmp->fieldType==4){ */
455/*          agCache.tProt = *((unsigned char*)&buffer1); */
456/*        } */
457/*        if (pftmp->fieldType==61){ */
458/*          agCache.sens = *((unsigned char*)&buffer1); */
459/*        } */
460/*        if (pftmp->fieldType==5){ */
461/*          agCache.dscp = *((unsigned char*)&buffer1); */
462/*        }        */
463          /* end aggregation */
464#ifdef CRIHAN
465          if ((pftmp->fieldType==9)||(pftmp->fieldType==29)){
466            ipFirstCache.maskS = *((unsigned char*)&buffer1);
467          }
468          if ((pftmp->fieldType==13)||(pftmp->fieldType==30)){
469            ipFirstCache.maskD = *((unsigned char*)&buffer1);
470          }
471          if (pftmp->fieldType==60){
472            ipFirstCache.ipProt = *((unsigned char*)&buffer1);
473            mplsFirstCache.ipProt = *((unsigned char*)&buffer1);
474          }
475          if (pftmp->fieldType==4){
476            ipFirstCache.tProt = *((unsigned char*)&buffer1);
477          }
478#endif /* CRIHAN */
479          break;
480        case 2:
481          buffer2[1]= *(buf+(*offV9)); (*offV9)++;
482          buffer2[0]= *(buf+(*offV9)); (*offV9)++;
483          /* aggregation */
484          if (pftmp->fieldType==10){
485            agCache.idSnmp = *((unsigned short*)&buffer2);
486          }       
487          /* end aggregation */
488#ifdef CRIHAN
489          if (pftmp->fieldType==10){
490            ipFirstCache.inSnmp = *((unsigned short*)&buffer2);
491          }
492          if (pftmp->fieldType==14){
493            ipFirstCache.outSnmp = *((unsigned short*)&buffer2);
494          }
495          if (pftmp->fieldType==7){
496            ipFirstCache.sPort = *((unsigned short*)&buffer2);
497          }
498          if (pftmp->fieldType==11){
499            ipFirstCache.dPort = *((unsigned short*)&buffer2);
500          }
501#endif /* CRIHAN */
502          break;
503        case 3:
504          buffer4[3]= 0;
505          buffer4[2]= *(buf+(*offV9)); (*offV9)++;
506          buffer4[1]= *(buf+(*offV9)); (*offV9)++;
507          buffer4[0]= *(buf+(*offV9)); (*offV9)++;
508          /* aggregation */
509          /* end aggregation */
510#ifdef CRIHAN
511          if (pftmp->fieldType==70){
512            mplsFirstCache.mplsLabel1 = (*((unsigned long*)&buffer4))>>4;
513          }
514#endif /* CRIHAN */
515          break;
516        case 4:
517          buffer4[3]= *(buf+(*offV9)); (*offV9)++;
518          buffer4[2]= *(buf+(*offV9)); (*offV9)++;
519          buffer4[1]= *(buf+(*offV9)); (*offV9)++;
520          buffer4[0]= *(buf+(*offV9)); (*offV9)++;
521          /* aggregation */
522/*        if ((pftmp->fieldType==8)){ */
523/*          bool = 1; */
524/*          agCache.v4AdS = *((unsigned long*)&buffer4); */
525/*        } else if ((pftmp->fieldType==12)){ */
526/*          agCache.v4AdD = *((unsigned long*)&buffer4); */
527/*        } else if (pftmp->fieldType==1){ */
528/*          agCache.bytes = *((unsigned long*)&buffer4); */
529/*        } else if (pftmp->fieldType==2){ */
530/*          agCache.pkts = *((unsigned long*)&buffer4); */
531/*        } */
532          /* end aggregation */
533#ifdef CRIHAN
534          if (pftmp->fieldType==8){
535            ipFirstCache.v4AdS = *((unsigned long*)&buffer4);
536            mplsFirstCache.v4AdS = *((unsigned long*)&buffer4);
537          }
538          if (pftmp->fieldType==12){
539            ipFirstCache.v4AdD = *((unsigned long*)&buffer4);
540            mplsFirstCache.v4AdD = *((unsigned long*)&buffer4);
541          }
542          if (pftmp->fieldType==1){
543            ipFirstCache.bytes = *((unsigned long*)&buffer4);
544          }
545          if (pftmp->fieldType==2){
546            ipFirstCache.pkts = *((unsigned long*)&buffer4);
547          }
548          if (pftmp->fieldType==22){
549            firstTime = *((unsigned long*)&buffer4);
550          }
551          if (pftmp->fieldType==21){
552            lastTime = *((unsigned long*)&buffer4);
553          }
554#endif /* CRIHAN */
555          break;
556        case 16:
557          for (i=0; i<4; i++) {
558            buffer2[1]= *(buf+(*offV9)); (*offV9)++;
559            buffer2[0]= *(buf+(*offV9)); (*offV9)++;
560            buffer2[1]= *(buf+(*offV9)); (*offV9)++;
561            buffer2[0]= *(buf+(*offV9)); (*offV9)++;
562          }
563          /* aggregation */       
564          /* end aggregation */
565          break;
566        default:
567          syslog(LOG_INFO,"UNKNOWN FIELDS LENGTH: %d ", field_size);
568          for (i=0; i<field_size; i++){
569            (*offV9)++;
570          }
571        }
572      } /* end if one cache table line existence */
573      if (cpt==tmp->fieldCount) {
574        /*
575         * end of one flow (not the flowset)
576         */
577#ifdef CRIHAN
578        if ( mplsFirstCache.mplsLabel1 == 0 ) {
579          (ipCache+(*ipCounter))->ipProt = ipFirstCache.ipProt;
580          ipFirstCache.ipProt = 0;
581          (ipCache+(*ipCounter))->bytes = ipFirstCache.bytes;
582          ipFirstCache.bytes = 0;
583          (ipCache+(*ipCounter))->pkts = ipFirstCache.pkts;
584          ipFirstCache.pkts = 0;
585          (ipCache+(*ipCounter))->inSnmp = ipFirstCache.inSnmp;
586          ipFirstCache.inSnmp = 0;
587          (ipCache+(*ipCounter))->outSnmp = ipFirstCache.outSnmp;
588          ipFirstCache.outSnmp = 0;
589          (ipCache+(*ipCounter))->v4AdS = ipFirstCache.v4AdS;
590          ipFirstCache.outSnmp = 0;
591          (ipCache+(*ipCounter))->v4AdD = ipFirstCache.v4AdD;
592          ipFirstCache.v4AdD = 0;
593          (ipCache+(*ipCounter))->tProt = ipFirstCache.tProt;
594          ipFirstCache.tProt = 0;
595          (ipCache+(*ipCounter))->sPort = ipFirstCache.sPort;
596          ipFirstCache.sPort = 0;
597          (ipCache+(*ipCounter))->dPort = ipFirstCache.dPort;
598          ipFirstCache.dPort = 0;
599          (ipCache+(*ipCounter))->maskD = ipFirstCache.maskD;
600          ipFirstCache.maskD = 0;
601          (ipCache+(*ipCounter))->maskS = ipFirstCache.maskS;
602          ipFirstCache.maskS = 0;
603          (ipCache+(*ipCounter))->routerAd = ipFirstCache.routerAd;
604          (ipCache+(*ipCounter))->liveTime = lastTime - firstTime;
605          firstTime = 0; lastTime = 0;
606          (*ipCounter)++;
607        } else {
608          (mplsCache+(*mplsCounter))->ipProt = mplsFirstCache.ipProt;
609          mplsFirstCache.ipProt = 0;
610          (mplsCache+(*mplsCounter))->v4AdS =  mplsFirstCache.v4AdS;
611          mplsFirstCache.v4AdS = 0;
612          (mplsCache+(*mplsCounter))->v4AdD =  mplsFirstCache.v4AdD;
613          mplsFirstCache.v4AdD = 0;
614          (mplsCache+(*mplsCounter))->routerAd =  mplsFirstCache.routerAd;
615          (mplsCache+(*mplsCounter))->mplsLabel1 =  mplsFirstCache.mplsLabel1;
616          mplsFirstCache.mplsLabel1 = 0;
617          (*mplsCounter)++;
618        }
619#endif /* CRIHAN */
620        /* put aggregation cache information to tables */
621/*      if (bool == 1){ */
622/*        prefixKey.beginning = agCache.v4AdS>>(32-agCache.maskS)<<(32-agCache.maskS); */
623/*        res = bsearch(&prefixKey, V4PTab, nbPV4,  */
624/*                      sizeof(struct PrefixV4), prefCmp); */
625/*      } */
626        bool = 0;   
627        /* end put */
628        /*
629         * Redirection if needed
630         * switch the rules definition (check & fieldToRecord),
631         * we send the flow or a part of the flow to a remote host or a file
632         */
633        tmpRuleList = rlPtr;
634        while (tmpRuleList){
635          unsigned short check = 1;
636          RuleDefPtr tmpRuleDefList = tmpRuleList->def;
637          secondOffset = secondOldOffset;
638          while (tmpRuleDefList){
639            check = check && tmpRuleDefList->check;
640            tmpRuleDefList->check = 0;
641            tmpRuleDefList = tmpRuleDefList->next;
642          }
643          if ( (tmpRuleList->def != NULL) && (check == 1)) {
644            /* msg building */
645            secondPftmp = tmp->lastField;
646/*          memcpy(myMsg.text, (char*)(buf+secondOffset),flow_size); */
647            msgTextIndex = mempcpy(mempcpy(mempcpy(myMsg.text,
648                                                   &tplMsgType,
649                                                   sizeof(unsigned short)
650                                                   ),
651                                           &tmpRuleList->id,
652                                           sizeof(tmpRuleList->id)
653                                           ),
654                                   &cr->IpAddress,
655                                   sizeof(unsigned long)
656                                   );
657            msgTextIndex = mempcpy(mempcpy(mempcpy(msgTextIndex,
658                                                   &tmp->sourceId,
659                                                   sizeof(unsigned long)
660                                                   ),
661                                           &tmp->templateFlowSetId,
662                                           sizeof(tmp->templateFlowSetId)
663                                           ),
664                                   buf+secondOffset,
665                                   flow_size
666                                   );
667            myMsg.type = 1;
668            msgSend( myQueue, myMsg);
669            noEnd = 1;
670            secondCpt=0;
671          } /* end if check */
672          tmpRuleList = tmpRuleList->next;
673          secondPftmp = tmp->lastField;
674        } /* end while tmpRuleList */
675        /*
676         * end redirection
677         */
678        secondOffset = *offV9;
679        secondOldOffset = secondOffset;
680        pftmp = tmp->lastField;
681        cpt=0;
682        (*cFNPtr)++; /* pointer on the flows number */
683        if (((*offV9)-48-shift+flow_size) > data_length){
684          overflow = 1; /* buffer index not correct */
685        }
686      } else {
687        /* not the flow end, progress in field list */
688        pftmp = pftmp->prev;
689      }
690    } /* end of the while on one flow record */   
691  }else{
692    /*
693     * template unknown, we skip this all the data
694     */
695    (*offV9)+=(data_length-4);
696    (*cFNPtr) = v9Ptr->count;
697  }
698  while ( ((*offV9)-48-shift) < data_length ) {
699    (*offV9)++; /* if padding */
700  }
701  while ( (*offV9)-48-shift > data_length ) {
702    (*offV9)--; /* crazy loop (when bug appears in template def) */
703  }
704  return (data_length+shift);
705}
Note: See TracBrowser for help on using the browser.