root/trunk/src/renetcol.c @ 61

Revision 61, 19.8 KB (checked in by andreu, 15 years ago)

tickets 12,19 & 20 closed

  • 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#ifdef 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#ifdef 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. By.\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  k = getSNMPIndexList(INTERFACES_TYPE_LIST, routersListPtr);
227
228  /* INIT THE CURRENTS VARIABLES*/
229  myPtrs.currentRouterPtr = routersListPtr;
230  myPtrs.currentHeaderV9Ptr = (NetFlowV9HeaderPtr)
231    malloc(sizeof(struct NetFlowV9Header));
232  myPtrs.offsetV9Ptr = &offsetV9;
233  myPtrs.currentFlowsetIdPtr = &currentFlowsetId;
234  myPtrs.pcktPtr = (DatagramPtr) malloc(sizeof(struct Datagram));
235  myPtrs.currentFlowsetNumberPtr = &currentFlowsetNumber;
236#ifdef IPV4AGGIDR
237  myPtrs.routersID = &indexedRouterList;
238#endif
239  myPtrs.currentV4Tab = shmForAgg->prefixV4Tab[shmForAgg->currentTable];
240  myPtrs.secondV4Tab = shmForAgg->prefixV4Tab[shmForAgg->secondTable];
241#ifdef ASACC
242  myPtrs.asNb = shmForAgg->ASNb;
243  myPtrs.currentASTab = shmForAgg->ASTab[shmForAgg->currentTable];
244  myPtrs.secondASTab = shmForAgg->ASTab[shmForAgg->secondTable];
245#endif
246#ifdef MATRIX
247  myPtrs.matrixPOP = &(shmForAgg->matrixPOP[shmForAgg->currentTable][0][0]);
248#endif
249
250  /* INIT MATRIX TABLES */
251#ifdef MATRIX
252  for (i=0; i<ROUTER_INDEX_MAX; i++){
253    for (j=0; j<ROUTER_INDEX_MAX; j++) {
254      shmForAgg->matrixPOP[0][i][j].bytesNb = 0;
255      shmForAgg->matrixPOP[0][i][j].pktsNb = 0;
256      shmForAgg->matrixPOP[0][i][j].flowNb = 0;
257      shmForAgg->matrixPOP[1][i][j].bytesNb = 0;
258      shmForAgg->matrixPOP[1][i][j].pktsNb = 0;
259      shmForAgg->matrixPOP[1][i][j].flowNb = 0;
260    }
261  }
262#endif
263
264  /* Checkup */
265  if (myPtrs.pcktPtr==NULL) {
266    fprintf(stderr, "ERROR in struct Datagram allocation\n");
267    exit(1);
268  } else {
269    myPtrs.pcktPtr->ipH = (IpHeaderPtr) malloc(sizeof(struct IpHeader));
270    myPtrs.pcktPtr->udp_header = (UdpHeaderPtr) malloc(sizeof(struct UdpHeader));
271  }
272  if (! (myPtrs.ptr_buffer = malloc(sockBufSize))) 
273    {
274      printf("ERROR during socket buffer allocation\n");
275      exit(2);
276    }
277
278  /* INIT INPUT STREAM*/
279  initStream();
280
281  socketLoop(); /* all work on datagram is made here */
282
283  closelog();
284
285  fprintf(stderr, "END\n");
286
287  return (0);
288}
289
290/*
291 * send his PID to another program via IPC message queue
292 *
293 * @param queueID the IPC queue ident
294 *
295 */
296void 
297sendMyPid(int queueID)
298{
299  msgType myMsg;
300  char *msgTextIndex;
301  unsigned short tplMsgType = 12;
302  pid_t myPID;
303 
304  myPID = getpid();
305  msgTextIndex = mempcpy(mempcpy(myMsg.text,
306                                 &tplMsgType,
307                                 sizeof (unsigned short)
308                                 ),
309                         &myPID,
310                         sizeof(pid_t)
311                         );
312  myMsg.type = 1;
313  msgSend(queueID, myMsg);
314}
315
316/*
317 * Send the "read rules list" message to another program
318 *
319 * @param queueID the IPC queue ident
320 *
321 */
322void sendReadRulesSignal(int queueID)
323{
324  msgType myMsg;
325  char *msgTextIndex;
326  unsigned short tplMsgType = 13;
327 
328  msgTextIndex = mempcpy(myMsg.text,
329                         &tplMsgType,
330                         sizeof (unsigned short)
331                         );
332  myMsg.type = 1;
333  msgSend(queueID, myMsg);
334}
335
336/*
337 *
338 */
339void 
340sigusr1Mgmt(int num)
341{
342  sigusr1Up = 1;
343}
344
345/*
346 * init the rule structure
347 */
348void 
349initRule()
350{
351  RulesPtr tmp = NULL;
352  initCache();
353  tmp = myPtrs.rulesListPtr;
354  for ( ; tmp; tmp=tmp->next) {
355    myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr);
356  }
357  myPtrs.rulesListPtr = NULL;
358  myPtrs.rulesListPtr = getRules(myPtrs.rulesListPtr, RULES_FILE);
359  tmp = myPtrs.rulesListPtr;
360  for ( ; tmp; tmp=tmp->next) {
361    if (tmp->type != 2) {
362      myPtrs.rulesListPtr = delRule(tmp, myPtrs.rulesListPtr);
363    }
364  }
365  tmp = NULL;
366  initCache();
367  setCache(myPtrs.rulesListPtr);
368  sendReadRulesSignal(myQueue);
369#ifdef DEBUG
370  printRule(myPtrs.rulesListPtr);
371#endif
372}
373
374/*
375 * init cache table
376 */
377void
378initCache()
379{
380  int i,j;
381  for (i=0; i<FIELD_TYPE_NUMBER+1; i++){
382    for (j=0; j<MAX_RULES_PER_FIELD; j++){
383      rulesAddress[i][j] = NULL;
384    }
385  }
386}
387
388/*
389 * setCache()
390 */
391void
392setCache(RulesPtr rPtr)
393{
394  int i=0;
395  RulesPtr tmp = rPtr;
396  RuleDefPtr def = NULL;
397
398#ifdef DEBUG
399  fprintf(stderr,"Cache for Rules\n");
400#endif 
401  while (tmp) {
402    def = tmp->def;
403    while (def) {
404      i = 0;
405      while (rulesAddress[def->fieldType][i] != NULL){
406        i++;
407      }
408      rulesAddress[def->fieldType][i] = def;
409      def = def->next;
410#ifdef DEBUG
411      fprintf(stderr,"%d: %d ", def->fieldType, i);
412#endif     
413    }
414#ifdef DEBUG
415    fprintf(stderr,"\n");
416#endif     
417    tmp = tmp->next;
418  }
419}
420
421/*
422 * initStream()
423 */
424void 
425initStream()
426{
427  static unsigned short n0, n1, n2, n3;
428
429  initSocket();
430  if (sscanf(receptAddress,"%hu.%hu.%hu.%hu",&n0,&n1,&n2,&n3)==0) {
431    perror("sscanf");
432  }             
433  buffer4[0] = (unsigned char)n3;
434  buffer4[1] = (unsigned char)n2;
435  buffer4[2] = (unsigned char)n1;
436  buffer4[3] = (unsigned char)n0;
437}
438
439/*
440 * socketLoop()
441 */
442int 
443socketLoop()
444{
445  short shift;
446  short version = 0;
447  int regRouter = 0;
448  time_t now = time((time_t *)NULL);
449  int loopNb = 0;
450  int gardeFou = 0;
451  time_t lastIPOutput, lastMPLSOutput;
452
453  now = time((time_t *)NULL);
454  tmPtr = localtime(&now);
455  currentIntervalle = tmPtr->tm_min;
456  lastMPLSOutput = now;
457  lastIPOutput = now;
458  do {
459#ifdef DEBUG   
460    fprintf (stderr, "[");
461#endif
462    if ( ((tmPtr->tm_min)%STEP == 0) && (currentIntervalle != tmPtr->tm_min)){
463      currentIntervalle = tmPtr->tm_min;
464      if (shmForAgg->currentTable == 0) {
465        shmForAgg->currentTable = 1;
466        shmForAgg->secondTable = 0;
467      }else{
468        shmForAgg->currentTable = 0;
469        shmForAgg->secondTable = 1;
470      }
471      shmForAgg->readed = 1;
472#ifdef ASACC
473      myPtrs.currentASTab = shmForAgg->ASTab[shmForAgg->currentTable];
474#endif
475#ifdef MATRIX
476      myPtrs.matrixPOP = &(shmForAgg->matrixPOP[shmForAgg->currentTable][0][0]);
477#endif
478    }
479    if (sigusr1Up == 1){
480      sigusr1Up = 0;
481      initRule();
482    }
483    socketReading();
484    getIpHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer);
485    regRouter = checkIpHeader(myPtrs.pcktPtr, &sortedRouterList[0], routerNb);
486    getUdpHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer);
487    if ( checkUdpHeader(myPtrs.pcktPtr, regRouter, receptPort) == 1 ){
488      continue;
489    }
490   
491    switch( version =
492            getNetFlowHeader(myPtrs.pcktPtr, myPtrs.ptr_buffer,
493                             myPtrs.currentHeaderV9Ptr, myPtrs.offsetV9Ptr)){
494    case 9:
495      if ((myPtrs.currentRouterPtr=notExistRouter(routersListPtr,
496                                                  myPtrs.pcktPtr->ipH->srcAdd))==NULL) {
497        myPtrs.currentRouterPtr = routersListPtr;
498      }
499      currentFlowsetNumber = 0;
500      shift = 0;
501      gardeFou=0;
502      while ((currentFlowsetNumber < myPtrs.currentHeaderV9Ptr->count)) {
503        gardeFou++;
504        curTplFlSetPtr = NULL;
505        currentFlowsetId=getFlowsetId(currentFlowsetNumber,
506                                      myPtrs.offsetV9Ptr, myPtrs.ptr_buffer);
507        if ( currentFlowsetId == 0 ) {
508          if ( (shift = checkTemplateFlowSet(myPtrs.currentRouterPtr,
509                                             myPtrs.offsetV9Ptr,
510                                             myPtrs.ptr_buffer,
511                                             myPtrs.currentHeaderV9Ptr,
512                                             curTplFlSetPtr,
513                                             myPtrs.currentFlowsetNumberPtr,
514                                             myQueue)) < 0 ) {
515#ifdef DEBUG
516            fprintf (stderr, "w>\n");
517#endif
518            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
519          };
520          writeAllTplFlSet();
521        } else if (currentFlowsetId == 1) {
522          if ( (shift = checkTemplateOption(myPtrs.currentRouterPtr,
523                                            myPtrs.offsetV9Ptr,
524                                            myPtrs.ptr_buffer,
525                                            myPtrs.currentHeaderV9Ptr,
526                                            curTplOptionPtr,
527                                            myPtrs.currentFlowsetNumberPtr) ) < 0 ) {
528#ifdef DEBUG
529            fprintf (stderr, "wo>\n");
530#endif 
531            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
532          }
533        } else if (currentFlowsetId > 255) {
534          if ( (shift = checkDataFlowSet(shift,
535                                         &myPtrs,
536                                         myQueue,
537                                         shmForAgg->prefixV4Tab[shmForAgg->currentTable],
538                                         (size_t) shmForAgg->v4PrefixNb,
539                                         shmForAgg->prefixV4SubnetTab[shmForAgg->currentTable],
540                                         (size_t) shmForAgg->v4SubnetNb) ) < 0 ) {
541#ifdef DEBUG   
542            fprintf (stderr, "wd>\n");
543#endif
544            currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
545          }
546        } else {
547#ifdef DEBUG   
548          fprintf (stderr, "1<<255\n");
549#endif
550          currentFlowsetNumber = myPtrs.currentHeaderV9Ptr->count + 1;
551        }
552        if ( gardeFou > 200) { exit(-1); }
553      } /* end while flowset exist */
554      break;
555    default:
556      syslog(LOG_INFO,
557             "NetFlow exp. version unknown: %hu, from router: %lu.%lu.%lu.%lu",
558             (unsigned short) version,
559             (myPtrs.pcktPtr->ipH->srcAdd>>24),
560             (myPtrs.pcktPtr->ipH->srcAdd<<8>>24),
561             (myPtrs.pcktPtr->ipH->srcAdd<<16>>24),
562             (myPtrs.pcktPtr->ipH->srcAdd<<24>>24));
563      break;
564    }
565    if (loopNb  > 1000 ){
566      /* FIXME perhaps call this function via the compilation options */
567      writeAllTplFlSet();
568#ifdef DEBUG   
569      fprintf(stderr, "W");
570#endif
571      loopNb = 0;
572    }
573    loopNb++;
574
575    now = time((time_t *)NULL);
576    tmPtr = localtime(&now);
577#ifdef DEBUG   
578    fprintf (stderr, "]\n");
579#endif
580  } while (1);
581}
582
583/*
584 * initSocket()
585 */
586short 
587initSocket()
588{
589  inputSock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP);
590  if (inputSock < 0)
591    {
592      syslog(LOG_ERR,"socket : %s", strerror(errno));
593      exit(1);
594    }
595  memset((void*)&name, 0, sizeof(name));
596  name.sin_family = AF_INET;
597  name.sin_addr.s_addr = htonl(INADDR_ANY);
598  if (name.sin_addr.s_addr == INADDR_NONE){
599    syslog(LOG_ERR, " INADDR_NONE ");
600    exit(1);
601  }
602  name.sin_port = htons(receptPort);
603  if (bind(inputSock,(struct sockaddr *)(&name), sizeof(name)) < 0)
604    {
605      syslog(LOG_ERR, "bind : %s", strerror(errno));
606      exit(1);
607    }                                                           
608  sockNamelg = sizeof(name);
609  if (getsockname(inputSock, (struct sockaddr *) (&name),
610                  (socklen_t *)&sockNamelg) < 0)
611    {
612      syslog(LOG_ERR, "getsockname: %s", strerror(errno));
613      exit(1);
614    }
615  /* Here socket DGRAM creation, only to not have a unreachable service */
616  /* message in return */
617  inputSock2 = socket(AF_INET, SOCK_DGRAM, 0);
618  if (inputSock2 < 0)
619    {
620      syslog(LOG_ERR,"socket : %s", strerror(errno));
621      exit(1);
622    }
623  memset((void*)&name, 0, sizeof(name));
624  name2.sin_family = AF_INET;
625  name2.sin_addr.s_addr = htonl(INADDR_ANY);
626  if (name2.sin_addr.s_addr == INADDR_NONE){
627    syslog(LOG_ERR, " INADDR_NONE ");
628    exit(1);
629  }
630  name2.sin_port = htons(receptPort);
631  if (bind(inputSock2,(struct sockaddr *)(&name2), sizeof(name2)) < 0)
632    {
633      syslog(LOG_ERR, "bind : %s", strerror(errno));
634      exit(1);
635    }                                                           
636  sockNamelg = sizeof(name2);
637  if (getsockname(inputSock2, (struct sockaddr *) (&name2),
638                  (socklen_t *)&sockNamelg) < 0)
639    {
640      syslog(LOG_ERR, "getsockname: %s", strerror(errno));
641      exit(1);
642    }
643  return(0);
644}
645
646
647/*
648 * init socket
649 */
650short 
651socketReading()
652{
653  signed short sockLg;
654
655  sockNameFromlg = sizeof(fromName);
656  rcv = recvfrom(inputSock, myPtrs.ptr_buffer, sockBufSize, 0,
657                 (struct sockaddr *)(&fromName),
658                 (socklen_t *)&sockNameFromlg);   
659  sockLg = rcv;
660  if (sockLg < 0) {
661    syslog(LOG_ERR,"recvfrom : %s", strerror(errno));
662    exit(1);
663  }
664  if (sockLg == 0) {
665    syslog(LOG_ERR,"recvfrom : %s", strerror(errno));
666    exit(1);
667  }
668  return(0);
669}
670 
671/*
672 * check up flow datagramme 
673 */
674short 
675checkFlow(short flowNumber)
676{
677  return(0); /* FIXME : why this function ??? */
678}
679
680/*
681 * showAllTplFlSet
682 *
683 * to use only in debug mode
684 */
685void 
686showAllTplFlSet()
687{
688  RouterPtr tmp = routersListPtr;
689  TplFlowSetPtr tmpFS;
690  TplOptionPtr tmpOP;
691  fprintf(stderr,"\n*********************************************\n* All template definitions: (field, size) : *\n*********************************************\n");
692  for (; tmp; tmp=tmp->next) {
693    fprintf(stderr,"----------------------\nrouter %lu.%lu.%lu.%lu : \n----------------------\n",
694            (tmp->IpAddress>>24),
695            (tmp->IpAddress<<8>>24),
696            (tmp->IpAddress<<16>>24),
697            (tmp->IpAddress<<24>>24));
698    tmpFS =  tmp->tplList;
699    for (; tmpFS; tmpFS=tmpFS->next) {
700      fprintf(stderr,"TId %hu (sourceId: %lu):\n",
701              tmpFS->templateFlowSetId,
702              tmpFS->sourceId);
703      printFieldSet(stderr, tmpFS->fieldSet);
704      fprintf(stderr,"\n");
705    }
706    if ((tmpOP = tmp->tplOptList) != NULL){
707      for (; tmpOP; tmpOP=tmpOP->next) {
708        fprintf(stderr,"OpTId %hu (sourceId: %lu) >\n",
709                tmpOP->templateOptionId,
710                tmpOP->sourceId);
711        printFieldSet(stderr, tmpOP->fieldSet);
712        fprintf(stderr,"\n");
713      }
714      fprintf(stderr,"\n");
715    }
716  }
717}
718
719
720/*
721 * writeAllTplFlSet
722 *
723 */
724void 
725writeAllTplFlSet()
726{
727
728  RouterPtr tmp = routersListPtr;
729  TplFlowSetPtr tmpFS;
730  TplOptionPtr tmpOP;
731  FILE *TPLFILE;
732  if (!(TPLFILE = fopen("/tmp/TemplateDef.txt", "w"))) {
733    syslog (LOG_ERR, "error during %s opening", "/tmp/TemplateDef.txt");
734  }
735  fprintf(TPLFILE,"\n*********************************************\n* All template definitions: (field, size) : *\n*********************************************\n");
736  for (; tmp; tmp=tmp->next) {
737    fprintf(TPLFILE,"----------------------\nrouter %lu.%lu.%lu.%lu : \n----------------------\n",
738            (tmp->IpAddress>>24),
739            (tmp->IpAddress<<8>>24),
740            (tmp->IpAddress<<16>>24),
741            (tmp->IpAddress<<24>>24));
742    tmpFS =  tmp->tplList;
743    for (; tmpFS; tmpFS=tmpFS->next) {
744      fprintf(TPLFILE,"TId %hu (sourceId: %lu):\n",
745              tmpFS->templateFlowSetId,
746              tmpFS->sourceId);
747      printFieldSet(TPLFILE, tmpFS->fieldSet);
748      fprintf(TPLFILE,"\n");
749    }
750    if ((tmpOP = tmp->tplOptList) != NULL){
751      for (; tmpOP; tmpOP=tmpOP->next) {
752        fprintf(TPLFILE,"OpTId %hu (sourceId: %lu) last %d brackets are Scope >\n lg: %hu, opScopeLg: %hu, opLg: %hu\n",
753                tmpOP->templateOptionId,
754                tmpOP->sourceId,
755                tmpOP->optionScopeLg/4,
756                tmpOP->length,
757                tmpOP->optionScopeLg,
758                tmpOP->optionLg);
759        printFieldSet(TPLFILE, tmpOP->fieldSet);
760        fprintf(TPLFILE,"\n");
761      }
762      fprintf(TPLFILE,"\n");
763    }
764  }
765  fclose(TPLFILE);
766}
Note: See TracBrowser for help on using the browser.