root/trunk/src/dataFlowSet.c @ 18

Revision 18, 21.6 KB (checked in by andreu, 17 years ago)

ajout pour CRIHAN

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