root/trunk/src/dataFlowSet.c @ 19

Revision 19, 22.7 KB (checked in by andreu, 16 years ago)

last changes for Crihan -> 0.0.5

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