root/trunk/src/renetcol.c @ 76

Revision 76, 19.8 KB (checked in by andreu, 14 years ago)

error in configure.in, more checkpoints in template.c, few correction in others files

  • Property svn:eol-style set to native
Line 
1/*
2 * File: renetcol.c
3 *
4 * Authors: ANDREU Francois-Xavier
5 *
6 * Copyright (C) 2005 2006 2007 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 "renetcol.h"
27
28struct MyPtrs myPtrs; /* defined in routers_mgmt.h */
29
30struct SHMForAgg *shmForAgg;
31
32unsigned short currentIPOutputFile = 0;    /* index on the current IP file */
33unsigned short currentMPLSOutputFile = 0;  /* index on the current MPLS file */
34char outputName[256];
35char cof_str[20];                          /* current ouput file name */
36FILE *fIP;                                 /* pointer on the IP output file */
37FILE *fMPLS;                              /* pointer on the MPLS output file */
38
39struct sigaction myAction; /* handler for renetcolSender communication */
40sigjmp_buf contextSigalrm; /* '' */
41volatile sig_atomic_t sigusr1Up = 0;
42/* struct sigaction myAction;  for timer not used in this version */
43
44unsigned short currentIntervalle = 0;        /* based on 5 min intervalles */ 
45
46unsigned short offsetV9 = 0;                 /* index in a neflow v9 packet */
47
48unsigned char buffer1;
49unsigned char buffer2[2];
50unsigned char buffer4[4];
51unsigned char buffer6[6];
52
53short currentFlowsetNumber;
54short currentFlowsetId;
55TplFlowSetPtr curTplFlSetPtr; /* current template flowset pointer */
56TplOptionPtr curTplOptionPtr;
57RouterPtr routersListPtr;
58
59unsigned long sortedRouterList[ROUTER_INDEX_MAX];
60unsigned long indexedRouterList[ROUTER_INDEX_MAX];
61int routerNb = 0;                                  /* routers number */
62
63key_t myKey = 0;
64int myQueue = 0;
65
66/* Next structure used as cache in rules reading */
67RuleDefPtr rulesAddress[FIELD_TYPE_NUMBER+1][MAX_RULES_PER_FIELD];
68
69int reInitConf = 0;
70
71static struct tm *tmPtr;
72
73extern int errno;
74static int inputSock;
75static int sockNamelg;
76static int inputSock2;
77static int sockNameFromlg;
78static int rcv;
79static int sockBufSize = SOCKET_BUFFER_SIZE;           
80/* static unsigned short flowNumber; */
81static unsigned short receptPort = RECEPTION_PORT;
82/* static unsigned char *ptr_buffer; */
83static char *receptAddress = RECEPTION_ADDRESS;
84static struct sockaddr_in name;
85static struct sockaddr_in name2;
86static struct sockaddr_in fromName;
87
88/*
89 * Main
90 * ----
91 */
92int 
93main (int argc, char *argv[])
94{
95  RulesPtr tmp = NULL;
96  int shmid;
97  key_t key;
98  int i,j;
99  int k;
100
101#if defined(IPV4AGGIDR)
102  fprintf(stderr, "renetcol compilation and execution with IPv4 Aggregation feature enable based on routers ID in %s file.\n", ROUTERS_LIST);
103#endif
104
105#if defined(IPV4AGGIDSNMP)
106  fprintf(stderr, "renetcol compilation and execution with IPv4 Aggregation feature enable based on SNMP ID in %s file.\n", INTERFACES_TYPE_LIST);
107#endif
108 
109  openlog(argv[0], LOG_PID, LOG_USER);
110
111  initCache();
112  /* GET the list of routers who are available to send NDE to the collector */
113  if ( (routerNb = getRegisteredRouters(ROUTERS_LIST,
114                                        &sortedRouterList[0],
115                                        &indexedRouterList[0])) == -1) {
116    fprintf(stderr,
117            "ERROR in getRegisteredRouters from file %s\n",
118            ROUTERS_LIST);
119    exit(-1);
120  }
121  /* Create the list of routers */
122  for (i=0; i<routerNb; i++){
123    routersListPtr = addRouter(routersListPtr, sortedRouterList[i]);
124  }
125 
126  /* Shared memory */
127  key = 8765;
128  if ((shmid = shmget(key, SHMSIZE, IPC_CREAT | 0666)) < 0) {
129    perror("shmget");
130    exit(1);
131  }
132  if ((shmForAgg = (struct SHMForAgg *)shmat(shmid, (void *)0, 0)) == (void *) -1) {
133    perror("shmat");
134    exit(1);
135  }
136
137  if ( (shmForAgg->v4PrefixNb =
138        getPrefixV4(SUBNETS_LIST,
139                    &(shmForAgg->prefixV4Tab[0][0]),
140                    &(shmForAgg->prefixV4SubnetTab[0][0]),
141                    &(shmForAgg->v4SubnetNb)
142                    )) < 1){
143    fprintf(stderr, "renetcol: Error in %s\n", SUBNETS_LIST);
144  } else {
145    fprintf(stderr, "We have found %hu supernets from %s\n",
146            shmForAgg->v4PrefixNb,
147            SUBNETS_LIST);
148    fprintf(stderr, "and %hu subnets\n",
149            shmForAgg->v4SubnetNb);   
150  }
151  if ( (shmForAgg->v4PrefixNb =
152        getPrefixV4(SUBNETS_LIST,
153                    &(shmForAgg->prefixV4Tab[1][0]),
154                    &(shmForAgg->prefixV4SubnetTab[1][0]),
155                    &(shmForAgg->v4SubnetNb)
156                    )) < 1){
157    fprintf(stderr, "renetcol: Error in %s\n", SUBNETS_LIST);
158    exit(1);
159  }
160/*   for (i=0; i<shmForAgg->v4PrefixNb; i++){ */
161/*    fprintf(stderr, "SUPERNET : %lu, %hu\n",shmForAgg->prefixV4Tab[0][i].beginning, shmForAgg->prefixV4Tab[0][i].hasSubnet); */
162/*   } */
163/*   for (i=0; i<shmForAgg->v4SubnetNb; i++){ */
164/*    fprintf(stderr, "SUBNET : %lu, %hu\n",shmForAgg->prefixV4SubnetTab[0][i].beginning, shmForAgg->prefixV4SubnetTab[0][i].hasSubnet); */
165/*   } */
166
167  shmForAgg->currentTable = 0;
168  shmForAgg->secondTable = 1;
169  shmForAgg->readed = 0;
170
171  /* get the rules */
172  myPtrs.rulesListPtr = NULL;
173  myPtrs.rulesListPtr = getRules(myPtrs.rulesListPtr, RULES_FILE);
174  tmp = myPtrs.rulesListPtr;
175  for ( ; tmp->next; tmp=tmp->next) {
176    if (tmp->type != 2) {
177      myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr);
178    }
179  }
180  tmp = NULL;
181#ifdef DEBUG
182  printRule(rulesListPtr);
183#endif
184
185#ifdef ASACC
186  /* get the AS list */
187  if ( (shmForAgg->ASNb = getAS(AS_LIST, &(shmForAgg->ASTab[0][0]))) < 1){
188    fprintf(stderr, "renetcol: Error in %s\n", AS_LIST);
189    exit(1);
190  } else {
191    fprintf(stderr, "%hu AS are readed from %s\n",
192            shmForAgg->ASNb,
193            AS_LIST);
194  }
195  if ( (shmForAgg->ASNb = getAS(AS_LIST, &(shmForAgg->ASTab[1][0]))) < 1){
196    fprintf(stderr, "renetcol: Error in %s\n", AS_LIST);
197    exit(1);
198  }
199#endif
200
201  /* the fork */
202  fprintf(stderr, "renetcol: I become a deamon, next messages via syslogd. Bye.\n");
203  if (fork () != 0)
204    exit (0);
205  if (setsid() == -1){
206    exit(4);
207  }
208
209  /* handler, SIGUSR1 from renetcolSender */
210  myAction.sa_handler = sigusr1Mgmt;
211  myAction.sa_flags = SA_RESTART;
212  sigemptyset (&(myAction.sa_mask));
213  sigaddset (&(myAction.sa_mask), SIGALRM);
214  sigaction (SIGUSR1, &myAction, NULL);
215
216  /* Cache for fast rules access */
217  setCache(myPtrs.rulesListPtr);
218  myPtrs.rulesAddressPtr = (RuleDefPtr *)rulesAddress;
219
220  /* IPC messages queue init */
221  myKey = createKey(argv[0]);
222  myQueue = createQueue(myKey);
223  sendMyPid(myQueue);
224
225  /* get SNMP index information */
226#ifdef IPV4AGGIDSNMP
227  k = getSNMPIndexList(INTERFACES_TYPE_LIST, routersListPtr);
228#endif
229  /* INIT THE CURRENTS VARIABLES*/
230  myPtrs.currentRouterPtr = routersListPtr;
231  myPtrs.currentHeaderV9Ptr = (NetFlowV9HeaderPtr)
232    malloc(sizeof(struct NetFlowV9Header));
233  myPtrs.offsetV9Ptr = &offsetV9;
234  myPtrs.currentFlowsetIdPtr = &currentFlowsetId;
235  myPtrs.pcktPtr = (DatagramPtr) malloc(sizeof(struct Datagram));
236  myPtrs.currentFlowsetNumberPtr = &currentFlowsetNumber;
237#ifdef IPV4AGGIDR
238  myPtrs.routersID = &indexedRouterList;
239#endif
240  myPtrs.currentV4Tab = shmForAgg->prefixV4Tab[shmForAgg->currentTable];
241  myPtrs.secondV4Tab = shmForAgg->prefixV4Tab[shmForAgg->secondTable];
242#ifdef ASACC
243  myPtrs.asNb = shmForAgg->ASNb;
244  myPtrs.currentASTab = shmForAgg->ASTab[shmForAgg->currentTable];
245  myPtrs.secondASTab = shmForAgg->ASTab[shmForAgg->secondTable];
246#endif
247#ifdef MATRIX
248  myPtrs.matrixPOP = &(shmForAgg->matrixPOP[shmForAgg->currentTable][0][0]);
249#endif
250
251  /* INIT MATRIX TABLES */
252#ifdef MATRIX
253  for (i=0; i<ROUTER_INDEX_MAX; i++){
254    for (j=0; j<ROUTER_INDEX_MAX; j++) {
255      shmForAgg->matrixPOP[0][i][j].bytesNb = 0;
256      shmForAgg->matrixPOP[0][i][j].pktsNb = 0;
257      shmForAgg->matrixPOP[0][i][j].flowNb = 0;
258      shmForAgg->matrixPOP[1][i][j].bytesNb = 0;
259      shmForAgg->matrixPOP[1][i][j].pktsNb = 0;
260      shmForAgg->matrixPOP[1][i][j].flowNb = 0;
261    }
262  }
263#endif
264
265  /* Checkup */
266  if (myPtrs.pcktPtr==NULL) {
267    fprintf(stderr, "ERROR in struct Datagram allocation\n");
268    exit(1);
269  } else {
270    myPtrs.pcktPtr->ipH = (IpHeaderPtr) malloc(sizeof(struct IpHeader));
271    myPtrs.pcktPtr->udp_header = (UdpHeaderPtr) malloc(sizeof(struct UdpHeader));
272  }
273  if (! (myPtrs.ptr_buffer = malloc(sockBufSize))) 
274    {
275      printf("ERROR during socket buffer allocation\n");
276      exit(2);
277    }
278
279  /* INIT INPUT STREAM*/
280  initStream();
281
282  socketLoop(); /* all work on datagram is made here */
283
284  closelog();
285
286  fprintf(stderr, "END\n");
287
288  return (0);
289}
290
291/*
292 * send his PID to another program via IPC message queue
293 *
294 * @param queueID the IPC queue ident
295 *
296 */
297void 
298sendMyPid(int queueID)
299{
300  msgType myMsg;
301  char *msgTextIndex;
302  unsigned short tplMsgType = 12;
303  pid_t myPID;
304 
305  myPID = getpid();
306  msgTextIndex = mempcpy(mempcpy(myMsg.text,
307                                 &tplMsgType,
308                                 sizeof (unsigned short)
309                                 ),
310                         &myPID,
311                         sizeof(pid_t)
312                         );
313  myMsg.type = 1;
314  msgSend(queueID, myMsg);
315}
316
317/*
318 * Send the "read rules list" message to another program
319 *
320 * @param queueID the IPC queue ident
321 *
322 */
323void sendReadRulesSignal(int queueID)
324{
325  msgType myMsg;
326  char *msgTextIndex;
327  unsigned short tplMsgType = 13;
328 
329  msgTextIndex = mempcpy(myMsg.text,
330                         &tplMsgType,
331                         sizeof (unsigned short)
332                         );
333  myMsg.type = 1;
334  msgSend(queueID, myMsg);
335}
336
337/*
338 *
339 */
340void 
341sigusr1Mgmt(int num)
342{
343  sigusr1Up = 1;
344}
345
346/*
347 * init the rule structure
348 */
349void 
350initRule()
351{
352  RulesPtr tmp = NULL;
353  initCache();
354  tmp = myPtrs.rulesListPtr;
355  for ( ; tmp; tmp=tmp->next) {
356    myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr);
357  }
358  myPtrs.rulesListPtr = NULL;
359  myPtrs.rulesListPtr = getRules(myPtrs.rulesListPtr, RULES_FILE);
360  tmp = myPtrs.rulesListPtr;
361  for ( ; tmp; tmp=tmp->next) {
362    if (tmp->type != 2) {
363      myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr);
364    }
365  }
366  tmp = NULL;
367  initCache();
368  setCache(myPtrs.rulesListPtr);
369  sendReadRulesSignal(myQueue);
370#ifdef DEBUG
371  printRule(myPtrs.rulesListPtr);
372#endif
373}
374
375/*
376 * init cache table
377 */
378void
379initCache()
380{
381  int i,j;
382  for (i=0; i<FIELD_TYPE_NUMBER+1; i++){
383    for (j=0; j<MAX_RULES_PER_FIELD; j++){
384      rulesAddress[i][j] = NULL;
385    }
386  }
387}
388
389/*
390 * setCache()
391 */
392void
393setCache(RulesPtr rPtr)
394{
395  int i=0;
396  RulesPtr tmp = rPtr;
397  RuleDefPtr def = NULL;
398
399#ifdef DEBUG
400  fprintf(stderr,"Cache for Rules\n");
401#endif 
402  while (tmp) {
403    def = tmp->def;
404    while (def) {
405      i = 0;
406      while (rulesAddress[def->fieldType][i] != NULL){
407        i++;
408      }
409      rulesAddress[def->fieldType][i] = def;
410      def = def->next;
411#ifdef DEBUG
412      fprintf(stderr,"%d: %d ", def->fieldType, i);
413#endif     
414    }
415#ifdef DEBUG
416    fprintf(stderr,"\n");
417#endif     
418    tmp = tmp->next;
419  }
420}
421
422/*
423 * initStream()
424 */
425void 
426initStream()
427{
428  static unsigned short n0, n1, n2, n3;
429
430  initSocket();
431  if (sscanf(receptAddress,"%hu.%hu.%hu.%hu",&n0,&n1,&n2,&n3)==0) {
432    perror("sscanf");
433  }             
434  buffer4[0] = (unsigned char)n3;
435  buffer4[1] = (unsigned char)n2;
436  buffer4[2] = (unsigned char)n1;
437  buffer4[3] = (unsigned char)n0;
438}
439
440/*
441 * socketLoop()
442 */
443int 
444socketLoop()
445{
446  short shift;
447  short version = 0;
448  int regRouter = 0;
449  time_t now = time((time_t *)NULL);
450  int loopNb = 0;
451  int gardeFou = 0;
452  time_t lastIPOutput, lastMPLSOutput;
453
454  now = time((time_t *)NULL);
455  tmPtr = localtime(&now);
456  currentIntervalle = tmPtr->tm_min;
457  lastMPLSOutput = now;
458  lastIPOutput = now;
459  do {
460#ifdef DEBUG   
461    fprintf (stderr, "[");
462#endif
463    if ( ((tmPtr->tm_min)%STEP == 0) && (currentIntervalle != tmPtr->tm_min)){
464      currentIntervalle = tmPtr->tm_min;
465      if (shmForAgg->currentTable == 0) {
466        shmForAgg->currentTable = 1;
467        shmForAgg->secondTable = 0;
468      }else{
469        shmForAgg->currentTable = 0;
470        shmForAgg->secondTable = 1;
471      }
472      shmForAgg->readed = 1;
473#ifdef ASACC
474      myPtrs.currentASTab = shmForAgg->ASTab[shmForAgg->currentTable];
475#endif
476#ifdef MATRIX
477      myPtrs.matrixPOP = &(shmForAgg->matrixPOP[shmForAgg->currentTable][0][0]);
478#endif
479    }
480    if (sigusr1Up == 1){
481      sigusr1Up = 0;
482      initRule();
483    }
484    socketReading();
485    getIpHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer);
486    regRouter = checkIpHeader(myPtrs.pcktPtr, &sortedRouterList[0], routerNb);
487    getUdpHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer);
488    if ( checkUdpHeader(myPtrs.pcktPtr, regRouter, receptPort) == 1 ){
489      continue;
490    }
491   
492    switch( version =
493            getNetFlowHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer,
494                             myPtrs.currentHeaderV9Ptr, myPtrs.offsetV9Ptr)){
495    case 9:
496      if ((myPtrs.currentRouterPtr=notExistRouter(routersListPtr,
497                                                  myPtrs.pcktPtr->ipH->srcAdd))==NULL) {
498        myPtrs.currentRouterPtr = routersListPtr;
499      }
500      currentFlowsetNumber = 0;
501      shift = 0;
502      gardeFou=0;
503      while ((currentFlowsetNumber < myPtrs.currentHeaderV9Ptr->count)) {
504        gardeFou++;
505        curTplFlSetPtr = NULL;
506        currentFlowsetId=getFlowsetId(currentFlowsetNumber,
507                                      myPtrs.offsetV9Ptr, myPtrs.ptr_buffer);
508        if ( currentFlowsetId == 0 ) {
509          if ( (shift = checkTemplateFlowSet(myPtrs.currentRouterPtr,
510                                             myPtrs.offsetV9Ptr,
511                                             myPtrs.ptr_buffer,
512                                             myPtrs.currentHeaderV9Ptr,
513                                             curTplFlSetPtr,
514                                             myPtrs.currentFlowsetNumberPtr,
515                                             myQueue)) < 0 ) {
516#ifdef DEBUG
517            fprintf (stderr, "w>\n");
518#endif
519            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
520          };
521          writeAllTplFlSet();
522        } else if (currentFlowsetId == 1) {
523          if ( (shift = checkTemplateOption(myPtrs.currentRouterPtr,
524                                            myPtrs.offsetV9Ptr,
525                                            myPtrs.ptr_buffer,
526                                            myPtrs.currentHeaderV9Ptr,
527                                            curTplOptionPtr,
528                                            myPtrs.currentFlowsetNumberPtr) ) < 0 ) {
529#ifdef DEBUG
530            fprintf (stderr, "wo>\n");
531#endif 
532            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
533          }
534        } else if (currentFlowsetId > 255) {
535          if ( (shift = checkDataFlowSet(shift,
536                                         &myPtrs,
537                                         myQueue,
538                                         shmForAgg->prefixV4Tab[shmForAgg->currentTable],
539                                         (size_t) shmForAgg->v4PrefixNb,
540                                         shmForAgg->prefixV4SubnetTab[shmForAgg->currentTable],
541                                         (size_t) shmForAgg->v4SubnetNb) ) < 0 ) {
542#ifdef DEBUG   
543            fprintf (stderr, "wd>\n");
544#endif
545            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
546          }
547        } else {
548#ifdef DEBUG   
549          fprintf (stderr, "1<<255\n");
550#endif
551          currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
552        }
553        if ( gardeFou > 200) { exit(-1); }
554      } /* end while flowset exist */
555      break;
556    default:
557      syslog(LOG_INFO,
558             "NetFlow exp. version unknown: %hu, from router: %lu.%lu.%lu.%lu",
559             (unsigned short) version,
560             (myPtrs.pcktPtr->ipH->srcAdd>>24),
561             (myPtrs.pcktPtr->ipH->srcAdd<<8>>24),
562             (myPtrs.pcktPtr->ipH->srcAdd<<16>>24),
563             (myPtrs.pcktPtr->ipH->srcAdd<<24>>24));
564      break;
565    }
566    if (loopNb  > 1000 ){
567      /* FIXME perhaps call this function via the compilation options */
568      writeAllTplFlSet();
569#ifdef DEBUG   
570      fprintf(stderr, "W");
571#endif
572      loopNb = 0;
573    }
574    loopNb++;
575
576    now = time((time_t *)NULL);
577    tmPtr = localtime(&now);
578#ifdef DEBUG   
579    fprintf (stderr, "]\n");
580#endif
581  } while (1);
582}
583
584/*
585 * initSocket()
586 */
587short 
588initSocket()
589{
590  inputSock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
591  if (inputSock < 0)
592    {
593      syslog(LOG_ERR,"socket : %s", strerror(errno));
594      exit(1);
595    }
596  memset((void*)&name, 0, sizeof(name));
597  name.sin_family = AF_INET;
598  name.sin_addr.s_addr = htonl(INADDR_ANY);
599  if (name.sin_addr.s_addr == INADDR_NONE){
600    syslog(LOG_ERR, " INADDR_NONE ");
601    exit(1);
602  }
603  name.sin_port = htons(receptPort);
604  if (bind(inputSock,(struct sockaddr *)(&name), sizeof(name)) < 0)
605    {
606      syslog(LOG_ERR, "bind : %s", strerror(errno));
607      exit(1);
608    }                                                           
609  sockNamelg = sizeof(name);
610  if (getsockname(inputSock, (struct sockaddr *) (&name),
611                  (socklen_t *)&sockNamelg) < 0)
612    {
613      syslog(LOG_ERR, "getsockname: %s", strerror(errno));
614      exit(1);
615    }
616  /* Here socket DGRAM creation, only to not have a unreachable service */
617  /* message in return */
618  inputSock2 = socket(AF_INET, SOCK_DGRAM, 0);
619  if (inputSock2 < 0)
620    {
621      syslog(LOG_ERR,"socket : %s", strerror(errno));
622      exit(1);
623    }
624  memset((void*)&name, 0, sizeof(name));
625  name2.sin_family = AF_INET;
626  name2.sin_addr.s_addr = htonl(INADDR_ANY);
627  if (name2.sin_addr.s_addr == INADDR_NONE){
628    syslog(LOG_ERR, " INADDR_NONE ");
629    exit(1);
630  }
631  name2.sin_port = htons(receptPort);
632  if (bind(inputSock2,(struct sockaddr *)(&name2), sizeof(name2)) < 0)
633    {
634      syslog(LOG_ERR, "bind : %s", strerror(errno));
635      exit(1);
636    }                                                           
637  sockNamelg = sizeof(name2);
638  if (getsockname(inputSock2, (struct sockaddr *) (&name2),
639                  (socklen_t *)&sockNamelg) < 0)
640    {
641      syslog(LOG_ERR, "getsockname: %s", strerror(errno));
642      exit(1);
643    }
644  return(0);
645}
646
647
648/*
649 * init socket
650 */
651short 
652socketReading()
653{
654  signed short sockLg;
655
656  sockNameFromlg = sizeof(fromName);
657  rcv = recvfrom(inputSock, myPtrs.ptr_buffer, sockBufSize, 0,
658                 (struct sockaddr *)(&fromName),
659                 (socklen_t *)&sockNameFromlg);   
660  sockLg = rcv;
661  if (sockLg < 0) {
662    syslog(LOG_ERR,"recvfrom : %s", strerror(errno));
663    exit(1);
664  }
665  if (sockLg == 0) {
666    syslog(LOG_ERR,"recvfrom : %s", strerror(errno));
667    exit(1);
668  }
669  return(0);
670}
671 
672/*
673 * check up flow datagramme 
674 */
675short 
676checkFlow(short flowNumber)
677{
678  return(0); /* FIXME : why this function ??? */
679}
680
681/*
682 * showAllTplFlSet
683 *
684 * to use only in debug mode
685 */
686void 
687showAllTplFlSet()
688{
689  RouterPtr tmp = routersListPtr;
690  TplFlowSetPtr tmpFS;
691  TplOptionPtr tmpOP;
692  fprintf(stderr,"\n*********************************************\n* All template definitions: (field, size) : *\n*********************************************\n");
693  for (; tmp; tmp=tmp->next) {
694    fprintf(stderr,"----------------------\nrouter %lu.%lu.%lu.%lu : \n----------------------\n",
695            (tmp->IpAddress>>24),
696            (tmp->IpAddress<<8>>24),
697            (tmp->IpAddress<<16>>24),
698            (tmp->IpAddress<<24>>24));
699    tmpFS =  tmp->tplList;
700    for (; tmpFS; tmpFS=tmpFS->next) {
701      fprintf(stderr,"TId %hu (sourceId: %lu):\n",
702              tmpFS->templateFlowSetId,
703              tmpFS->sourceId);
704      printFieldSet(stderr, tmpFS->fieldSet);
705      fprintf(stderr,"\n");
706    }
707    if ((tmpOP = tmp->tplOptList) != NULL){
708      for (; tmpOP; tmpOP=tmpOP->next) {
709        fprintf(stderr,"OpTId %hu (sourceId: %lu) >\n",
710                tmpOP->templateOptionId,
711                tmpOP->sourceId);
712        printFieldSet(stderr, tmpOP->fieldSet);
713        fprintf(stderr,"\n");
714      }
715      fprintf(stderr,"\n");
716    }
717  }
718}
719
720
721/*
722 * writeAllTplFlSet
723 *
724 */
725void 
726writeAllTplFlSet()
727{
728
729  RouterPtr tmp = routersListPtr;
730  TplFlowSetPtr tmpFS;
731  TplOptionPtr tmpOP;
732  FILE *TPLFILE;
733  if (!(TPLFILE = fopen("/tmp/TemplateDef.txt", "w"))) {
734    syslog (LOG_ERR, "error during %s opening", "/tmp/TemplateDef.txt");
735  }
736  fprintf(TPLFILE,"\n*********************************************\n* All template definitions: (field, size) : *\n*********************************************\n");
737  for (; tmp; tmp=tmp->next) {
738    fprintf(TPLFILE,"----------------------\nrouter %lu.%lu.%lu.%lu : \n----------------------\n",
739            (tmp->IpAddress>>24),
740            (tmp->IpAddress<<8>>24),
741            (tmp->IpAddress<<16>>24),
742            (tmp->IpAddress<<24>>24));
743    tmpFS =  tmp->tplList;
744    for (; tmpFS; tmpFS=tmpFS->next) {
745      fprintf(TPLFILE,"TId %hu (sourceId: %lu):\n",
746              tmpFS->templateFlowSetId,
747              tmpFS->sourceId);
748      printFieldSet(TPLFILE, tmpFS->fieldSet);
749      fprintf(TPLFILE,"\n");
750    }
751    if ((tmpOP = tmp->tplOptList) != NULL){
752      for (; tmpOP; tmpOP=tmpOP->next) {
753        fprintf(TPLFILE,"OpTId %hu (sourceId: %lu) last %d brackets are Scope >\n lg: %hu, opScopeLg: %hu, opLg: %hu\n",
754                tmpOP->templateOptionId,
755                tmpOP->sourceId,
756                tmpOP->optionScopeLg/4,
757                tmpOP->length,
758                tmpOP->optionScopeLg,
759                tmpOP->optionLg);
760        printFieldSet(TPLFILE, tmpOP->fieldSet);
761        fprintf(TPLFILE,"\n");
762      }
763      fprintf(TPLFILE,"\n");
764    }
765  }
766  fclose(TPLFILE);
767}
Note: See TracBrowser for help on using the browser.