root/branches/renetcolSMP/src/renetcolAgg.c @ 162

Revision 162, 117.7 KB (checked in by andreu, 10 years ago)

first SMP version

  • Property svn:eol-style set to native
RevLine 
[24]1/*
2 * File: renetcolAgg.c
3 *
[157]4 * Authors: ANDREU Francois-Xavier
5 *
6 * Copyright (C) 2007-2011 GIP RENATER
[162]7 * Copyright (C) 2012 ANDREU Francois-Xavier
[24]8 */
9
[157]10/*  This file is part of renetcol.
[24]11 *
12 *  renetcol is free software; you can redistribute it and/or modify
13 *  it under the terms of the GNU General Public License as published by
14 *  the Free Software Foundation; either version 2 of the License, or
15 *  (at your option) any later version.
16 *
17 *  renetcol is distributed in the hope that it will be useful,
18 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
19 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 *  GNU General Public License for more details.
21 *
22 *  You should have received a copy of the GNU General Public License
23 *  along with renetcol; if not, write to the Free Software
24 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
25 */
26
[27]27/*
28 * In this file, I use directly the C rrd librairy to create and update
29 * the rrd files which contain the statistique for each subnet.
[58]30 * When your system is too fast and the number of your subnet too big
[157]31 * (> 1024), the create and update process can be too fast and before the
[121]32 * end of creation. So the maximum number of files which can be opened for one
33 * process in the same time is reached and we must temporize.
[27]34 */
35
[24]36#include "renetcolAgg.h"
37
[162]38struct SHMForAgg Global;
39struct SHMForAgg *shmForAgg = &Global;
40struct SHMForAgg *SMP1_shmForAgg;
41struct SHMForAgg *SMP2_shmForAgg;
42struct SHMForAgg *SMP3_shmForAgg;
43struct SHMForAgg *SMP4_shmForAgg;
[24]44
45int
46main(int argc, char *argv[])
47{
[162]48    int shmid1, shmid2, shmid3, shmid4;
[157]49    int i, j, k = 0;
50    int index = 1;
51    int rrd_update_er_ct = 0;
52    int rrd_update_ok_ct = 0;
53    int rrd_already_created_ct = 0;
54    int rrd_create_er_ct = 0;
55    int rrd_create_ok_ct = 0;
56    int isFirstUpdate = 1;
57    key_t key;
58    static char buf[2048];
59    static char name[2048];
60    static char ipStr[24];
[96]61#ifdef IPV6LINKAGG
[157]62    static char ipv6LinkStr[40]; /* 10_0_0_1_20_136 <router address> + <sampling> + <SNMP index> */
[96]63#endif
[61]64#if defined(MATRIX) && defined(IPV4AGGIDR)
[157]65    static char indexStr[24];
[61]66#endif
[157]67    static char asStr[7];
68    static char createstr[2048];
69    char *opt[27];
70    char *optUpdate[3];
71    FILE *fp;
72    static time_t now, now2;
73
74    key = 8765;
[162]75    if ((shmid1 = shmget(key, SHMSIZE, 0666)) < 0)
[157]76    {
77        perror("shmget");
78        exit(1);
79    }
[162]80    if ((SMP1_shmForAgg = (struct SHMForAgg *)shmat(shmid1, (void *)0, 0)) == (void *) -1)
[157]81    {
82        perror("shmat");
83        exit(1);
84    }
[162]85    key = 8766;
86    if ((shmid2 = shmget(key, SHMSIZE, 0666)) < 0)
87    {
88        perror("shmget");
89        exit(1);
90    }
91    if ((SMP2_shmForAgg = (struct SHMForAgg *)shmat(shmid2, (void *)0, 0)) == (void *) -1)
92    {
93        perror("shmat");
94        exit(1);
95    }
96    key = 8767;
97    if ((shmid3 = shmget(key, SHMSIZE, 0666)) < 0)
98    {
99        perror("shmget");
100        exit(1);
101    }
102    if ((SMP3_shmForAgg = (struct SHMForAgg *)shmat(shmid3, (void *)0, 0)) == (void *) -1)
103    {
104        perror("shmat");
105        exit(1);
106    }
107    key = 8768;
108    if ((shmid4 = shmget(key, SHMSIZE, 0666)) < 0)
109    {
110        perror("shmget");
111        exit(1);
112    }
113    if ((SMP4_shmForAgg = (struct SHMForAgg *)shmat(shmid4, (void *)0, 0)) == (void *) -1)
114    {
115        perror("shmat");
116        exit(1);
117    }
[157]118
119    fprintf(stderr, "renetcolAgg: I become a deamon, next messages via syslogd. Bye.\n");
120    if (fork () != 0)
121        exit (0);
122    if (setsid() == -1)
123    {
124        exit(4);
125    }
126
127    do
128    {
[162]129        if (SMP1_shmForAgg->readed == 1 && SMP2_shmForAgg->readed == 1 && SMP3_shmForAgg->readed == 1 && SMP4_shmForAgg->readed == 1)
[157]130        {
[162]131                fprintf(stderr,"\n\nall 4 at 1 OK\n\n");
132            SMP1_shmForAgg->readed = 0;
133            SMP2_shmForAgg->readed = 0;
134            SMP3_shmForAgg->readed = 0;
135            SMP4_shmForAgg->readed = 0;
136            shmForAgg->v4PrefixNb = SMP1_shmForAgg->v4PrefixNb;
137            shmForAgg->v4SubnetNb = SMP1_shmForAgg->v4SubnetNb;
138            shmForAgg->ASNb = SMP1_shmForAgg->ASNb;
139            /*shmForAgg->readed = 0;*/
140            if (SMP1_shmForAgg->currentTable == 0) /* FIXME : we should check on the four currentTable !!!! */
[157]141            {
142                index = 1;
143            }
144            else
145            {
146                index = 0;
147            }
[162]148            /* we add the four shared memory tables in one structure */
149            for (i=0; i<shmForAgg->v4PrefixNb; i++)
150            {
151                shmForAgg->prefixV4Tab[index][i].flowNbIN = SMP1_shmForAgg->prefixV4Tab[index][i].flowNbIN +
152                                                            SMP2_shmForAgg->prefixV4Tab[index][i].flowNbIN +
153                                                            SMP3_shmForAgg->prefixV4Tab[index][i].flowNbIN +
154                                                            SMP4_shmForAgg->prefixV4Tab[index][i].flowNbIN;
155                shmForAgg->prefixV4Tab[index][i].bytesNbIN = SMP1_shmForAgg->prefixV4Tab[index][i].bytesNbIN +
156                                                             SMP2_shmForAgg->prefixV4Tab[index][i].bytesNbIN +
157                                                             SMP3_shmForAgg->prefixV4Tab[index][i].bytesNbIN +
158                                                             SMP4_shmForAgg->prefixV4Tab[index][i].bytesNbIN;
159                shmForAgg->prefixV4Tab[index][i].pktsNbIN = SMP1_shmForAgg->prefixV4Tab[index][i].pktsNbIN +
160                                                            SMP2_shmForAgg->prefixV4Tab[index][i].pktsNbIN +
161                                                            SMP3_shmForAgg->prefixV4Tab[index][i].pktsNbIN +
162                                                            SMP4_shmForAgg->prefixV4Tab[index][i].pktsNbIN;
163                shmForAgg->prefixV4Tab[index][i].flowNbOUT = SMP1_shmForAgg->prefixV4Tab[index][i].flowNbOUT +
164                                                             SMP2_shmForAgg->prefixV4Tab[index][i].flowNbOUT +
165                                                             SMP3_shmForAgg->prefixV4Tab[index][i].flowNbOUT +
166                                                             SMP4_shmForAgg->prefixV4Tab[index][i].flowNbOUT;
167                shmForAgg->prefixV4Tab[index][i].bytesNbOUT = SMP1_shmForAgg->prefixV4Tab[index][i].bytesNbOUT +
168                                                              SMP2_shmForAgg->prefixV4Tab[index][i].bytesNbOUT +
169                                                              SMP3_shmForAgg->prefixV4Tab[index][i].bytesNbOUT +
170                                                              SMP4_shmForAgg->prefixV4Tab[index][i].bytesNbOUT;
171                shmForAgg->prefixV4Tab[index][i].pktsNbOUT = SMP1_shmForAgg->prefixV4Tab[index][i].pktsNbOUT +
172                                                             SMP2_shmForAgg->prefixV4Tab[index][i].pktsNbOUT +
173                                                             SMP3_shmForAgg->prefixV4Tab[index][i].pktsNbOUT +
174                                                             SMP4_shmForAgg->prefixV4Tab[index][i].pktsNbOUT;
175                shmForAgg->prefixV4Tab[index][i].firstCoSIN = SMP1_shmForAgg->prefixV4Tab[index][i].firstCoSIN +
176                                                              SMP2_shmForAgg->prefixV4Tab[index][i].firstCoSIN +
177                                                              SMP3_shmForAgg->prefixV4Tab[index][i].firstCoSIN +
178                                                              SMP4_shmForAgg->prefixV4Tab[index][i].firstCoSIN;
179                shmForAgg->prefixV4Tab[index][i].secondCoSIN = SMP1_shmForAgg->prefixV4Tab[index][i].secondCoSIN +
180                                                               SMP2_shmForAgg->prefixV4Tab[index][i].secondCoSIN +
181                                                               SMP3_shmForAgg->prefixV4Tab[index][i].secondCoSIN +
182                                                               SMP4_shmForAgg->prefixV4Tab[index][i].secondCoSIN;
183                shmForAgg->prefixV4Tab[index][i].thirdCoSIN = SMP1_shmForAgg->prefixV4Tab[index][i].thirdCoSIN +
184                                                              SMP2_shmForAgg->prefixV4Tab[index][i].thirdCoSIN +
185                                                              SMP3_shmForAgg->prefixV4Tab[index][i].thirdCoSIN +
186                                                              SMP4_shmForAgg->prefixV4Tab[index][i].thirdCoSIN;
187                shmForAgg->prefixV4Tab[index][i].fourthCoSIN = SMP1_shmForAgg->prefixV4Tab[index][i].fourthCoSIN +
188                                                               SMP2_shmForAgg->prefixV4Tab[index][i].fourthCoSIN +
189                                                               SMP3_shmForAgg->prefixV4Tab[index][i].fourthCoSIN +
190                                                               SMP4_shmForAgg->prefixV4Tab[index][i].fourthCoSIN;
191                shmForAgg->prefixV4Tab[index][i].firstCoSOUT = SMP1_shmForAgg->prefixV4Tab[index][i].firstCoSOUT +
192                                                               SMP2_shmForAgg->prefixV4Tab[index][i].firstCoSOUT +
193                                                               SMP3_shmForAgg->prefixV4Tab[index][i].firstCoSOUT +
194                                                               SMP4_shmForAgg->prefixV4Tab[index][i].firstCoSOUT;
195                shmForAgg->prefixV4Tab[index][i].secondCoSOUT = SMP1_shmForAgg->prefixV4Tab[index][i].secondCoSOUT +
196                                                                SMP2_shmForAgg->prefixV4Tab[index][i].secondCoSOUT +
197                                                                SMP3_shmForAgg->prefixV4Tab[index][i].secondCoSOUT +
198                                                                SMP4_shmForAgg->prefixV4Tab[index][i].secondCoSOUT;
199                shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = SMP1_shmForAgg->prefixV4Tab[index][i].thirdCoSOUT +
200                                                               SMP2_shmForAgg->prefixV4Tab[index][i].thirdCoSOUT +
201                                                               SMP3_shmForAgg->prefixV4Tab[index][i].thirdCoSOUT +
202                                                               SMP4_shmForAgg->prefixV4Tab[index][i].thirdCoSOUT;
203                shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = SMP1_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT +
204                                                                SMP2_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT +
205                                                                SMP3_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT +
206                                                                SMP4_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT;
207        fprintf(stderr,"%llu %llu %llu %llu %llu\n",SMP1_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT,
208SMP2_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT, SMP3_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT, SMP4_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT, shmForAgg->prefixV4Tab[index][i].fourthCoSOUT);
209            }
210            for (i=0; i<shmForAgg->v4SubnetNb; i++)
211            {
212                shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = SMP1_shmForAgg->prefixV4SubnetTab[index][i].flowNbIN +
213                                                            SMP2_shmForAgg->prefixV4SubnetTab[index][i].flowNbIN +
214                                                            SMP3_shmForAgg->prefixV4SubnetTab[index][i].flowNbIN +
215                                                            SMP4_shmForAgg->prefixV4SubnetTab[index][i].flowNbIN;
216                shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = SMP1_shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN +
217                                                             SMP2_shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN +
218                                                             SMP3_shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN +
219                                                             SMP4_shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN;
220                shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = SMP1_shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN +
221                                                            SMP2_shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN +
222                                                            SMP3_shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN +
223                                                            SMP4_shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN;
224                shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = SMP1_shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT +
225                                                             SMP2_shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT +
226                                                             SMP3_shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT +
227                                                             SMP4_shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT;
228                shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = SMP1_shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT +
229                                                              SMP2_shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT +
230                                                              SMP3_shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT +
231                                                              SMP4_shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT;
232                shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = SMP1_shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT +
233                                                             SMP2_shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT +
234                                                             SMP3_shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT +
235                                                             SMP4_shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT;
236                shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = SMP1_shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN +
237                                                              SMP2_shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN +
238                                                              SMP3_shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN +
239                                                              SMP4_shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN;
240                shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = SMP1_shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN +
241                                                               SMP2_shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN +
242                                                               SMP3_shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN +
243                                                               SMP4_shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN;
244                shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = SMP1_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN +
245                                                              SMP2_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN +
246                                                              SMP3_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN +
247                                                              SMP4_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN;
248                shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = SMP1_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN +
249                                                               SMP2_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN +
250                                                               SMP3_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN +
251                                                               SMP4_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN;
252                shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = SMP1_shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT +
253                                                               SMP2_shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT +
254                                                               SMP3_shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT +
255                                                               SMP4_shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT;
256                shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = SMP1_shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT +
257                                                                SMP2_shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT +
258                                                                SMP3_shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT +
259                                                                SMP4_shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT;
260                shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = SMP1_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT +
261                                                               SMP2_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT +
262                                                               SMP3_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT +
263                                                               SMP4_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT;
264                shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = SMP1_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT +
265                                                                SMP2_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT +
266                                                                SMP3_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT +
267                                                                SMP4_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT;
268            }
269            for (i=0; i<shmForAgg->ASNb; i++)
270            {
271                shmForAgg->ASTab[index][i].flowNbIN = SMP1_shmForAgg->ASTab[index][i].flowNbIN +
272                                                      SMP2_shmForAgg->ASTab[index][i].flowNbIN +
273                                                      SMP3_shmForAgg->ASTab[index][i].flowNbIN +
274                                                      SMP4_shmForAgg->ASTab[index][i].flowNbIN;
275                shmForAgg->ASTab[index][i].bytesNbIN = SMP1_shmForAgg->ASTab[index][i].bytesNbIN +
276                                                       SMP2_shmForAgg->ASTab[index][i].bytesNbIN +
277                                                       SMP3_shmForAgg->ASTab[index][i].bytesNbIN +
278                                                       SMP4_shmForAgg->ASTab[index][i].bytesNbIN;
279                shmForAgg->ASTab[index][i].pktsNbIN = SMP1_shmForAgg->ASTab[index][i].pktsNbIN +
280                                                      SMP2_shmForAgg->ASTab[index][i].pktsNbIN +
281                                                      SMP3_shmForAgg->ASTab[index][i].pktsNbIN +
282                                                      SMP4_shmForAgg->ASTab[index][i].pktsNbIN;
283                shmForAgg->ASTab[index][i].flowNbOUT = SMP1_shmForAgg->ASTab[index][i].flowNbOUT +
284                                                       SMP2_shmForAgg->ASTab[index][i].flowNbOUT +
285                                                       SMP3_shmForAgg->ASTab[index][i].flowNbOUT +
286                                                       SMP4_shmForAgg->ASTab[index][i].flowNbOUT;
287                shmForAgg->ASTab[index][i].bytesNbOUT = SMP1_shmForAgg->ASTab[index][i].bytesNbOUT +
288                                                        SMP2_shmForAgg->ASTab[index][i].bytesNbOUT +
289                                                        SMP3_shmForAgg->ASTab[index][i].bytesNbOUT +
290                                                        SMP4_shmForAgg->ASTab[index][i].bytesNbOUT;
291                shmForAgg->ASTab[index][i].pktsNbOUT = SMP1_shmForAgg->ASTab[index][i].pktsNbOUT +
292                                                       SMP2_shmForAgg->ASTab[index][i].pktsNbOUT +
293                                                       SMP3_shmForAgg->ASTab[index][i].pktsNbOUT +
294                                                       SMP4_shmForAgg->ASTab[index][i].pktsNbOUT;
295            }
296            /* end of the sum */
297            /* we need sampling information in the shmForAgg struct */
298            for (i=0; i<shmForAgg->v4PrefixNb; i++)
299            {
300              shmForAgg->prefixV4Tab[index][i].sampling = SMP1_shmForAgg->prefixV4Tab[index][i].sampling;
301              shmForAgg->prefixV4Tab[index][i].beginning = SMP1_shmForAgg->prefixV4Tab[index][i].beginning;
302              shmForAgg->prefixV4Tab[index][i].mask = SMP1_shmForAgg->prefixV4Tab[index][i].mask;
303            }
304            for (i=0; i<shmForAgg->v4SubnetNb; i++)
305            {
306              shmForAgg->prefixV4SubnetTab[index][i].sampling = SMP1_shmForAgg->prefixV4SubnetTab[index][i].sampling;
307              shmForAgg->prefixV4SubnetTab[index][i].beginning = SMP1_shmForAgg->prefixV4SubnetTab[index][i].beginning;
308              shmForAgg->prefixV4SubnetTab[index][i].mask = SMP1_shmForAgg->prefixV4SubnetTab[index][i].mask;
309            }
310            for (i=0; i<shmForAgg->ASNb; i++)
311            {
312              shmForAgg->ASTab[index][i].sampling = SMP1_shmForAgg->ASTab[index][i].sampling;
313              shmForAgg->ASTab[index][i].as = SMP1_shmForAgg->ASTab[index][i].as;
314            }
315            /* end */
[157]316            now = time((time_t *)NULL);
317            if (isFirstUpdate == 0)
318            {
319                /* RRD ACCOUNTING for prefixV4Tab */
320                for (i=0; i<shmForAgg->v4PrefixNb; i++)
321                {
322                    /* HERE create or update RRD FILE */
323                    if (shmForAgg->prefixV4Tab[index][i].sampling != 0)
324                    {
325                        for (j=0; j<strlen(name); j++)
326                        {
327                            name[j] = '\0';
328                        }
329                        for (j=0; j<strlen(createstr); j++)
330                        {
331                            createstr[j] = '\0';
332                        }
333                        for (j=0; j<strlen(ipStr); j++)
334                        {
335                            ipStr[j] = '\0';
336                        }
337                        for (j=0; j<strlen(buf); j++)
338                        {
339                            buf[j] = '\0';
340                        }
341                        strcat(name, PREFIX_RRD_LOCATION);
342                        sprintf(ipStr, "%lu_%lu_%lu_%lu_%hu_%lu",
343                                shmForAgg->prefixV4Tab[index][i].beginning>>24,
344                                shmForAgg->prefixV4Tab[index][i].beginning<<8>>24,
345                                shmForAgg->prefixV4Tab[index][i].beginning<<16>>24,
346                                shmForAgg->prefixV4Tab[index][i].beginning<<24>>24,
347                                shmForAgg->prefixV4Tab[index][i].mask,
348                                shmForAgg->prefixV4Tab[index][i].sampling
349                               );
350                        strcat(name, ipStr);
351                        strcat(name, RRD_EXTENSION);
352                        if ( (fp=fopen(name,"r")) == NULL )
353                        {
354                            opt[0]= (char *) malloc((strlen(RRD_PARAM_PREFIX_0) + 1) * sizeof(char));
355                            strcpy(opt[0], RRD_PARAM_PREFIX_0);
356                            opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
357                            strcpy(opt[1], name);
358                            opt[2]= (char *) malloc((strlen(RRD_PARAM_PREFIX_1) + 1) * sizeof(char));
359                            strcpy(opt[2], RRD_PARAM_PREFIX_1);
360                            opt[3]= (char *) malloc((strlen(RRD_PARAM_PREFIX_2) + 1) * sizeof(char));
361                            strcpy(opt[3], RRD_PARAM_PREFIX_2);
362                            opt[4]= (char *) malloc((strlen(RRD_PARAM_PREFIX_3) + 1) * sizeof(char));
363                            strcpy(opt[4], RRD_PARAM_PREFIX_3);
364                            opt[5]= (char *) malloc((strlen(RRD_PARAM_PREFIX_4) + 1) * sizeof(char));
365                            strcpy(opt[5], RRD_PARAM_PREFIX_4);
366                            opt[6]= (char *) malloc((strlen(RRD_PARAM_PREFIX_5) + 1) * sizeof(char));
367                            strcpy(opt[6], RRD_PARAM_PREFIX_5);
368                            opt[7]= (char *) malloc((strlen(RRD_PARAM_PREFIX_6) + 1) * sizeof(char));
369                            strcpy(opt[7], RRD_PARAM_PREFIX_6);
370                            opt[8]= (char *) malloc((strlen(RRD_PARAM_PREFIX_7) + 1) * sizeof(char));
371                            strcpy(opt[8], RRD_PARAM_PREFIX_7);
372                            opt[9]= (char *) malloc((strlen(RRD_PARAM_PREFIX_8) + 1) * sizeof(char));
373                            strcpy(opt[9], RRD_PARAM_PREFIX_8);
374                            opt[10]= (char *) malloc((strlen(RRD_PARAM_PREFIX_9) + 1) * sizeof(char));
375                            strcpy(opt[10], RRD_PARAM_PREFIX_9);
376                            opt[11]= (char *) malloc((strlen(RRD_PARAM_PREFIX_10) + 1) * sizeof(char));
377                            strcpy(opt[11], RRD_PARAM_PREFIX_10);
378                            opt[12]= (char *) malloc((strlen(RRD_PARAM_PREFIX_11) + 1) * sizeof(char));
379                            strcpy(opt[12], RRD_PARAM_PREFIX_11);
380                            opt[13]= (char *) malloc((strlen(RRD_PARAM_PREFIX_12) + 1) * sizeof(char));
381                            strcpy(opt[13], RRD_PARAM_PREFIX_12);
382                            opt[14]= (char *) malloc((strlen(RRD_PARAM_PREFIX_13) + 1) * sizeof(char));
383                            strcpy(opt[14], RRD_PARAM_PREFIX_13);
384                            opt[15]= (char *) malloc((strlen(RRD_PARAM_PREFIX_14) + 1) * sizeof(char));
385                            strcpy(opt[15], RRD_PARAM_PREFIX_14);
386                            opt[16]= (char *) malloc((strlen(RRD_PARAM_PREFIX_15) + 1) * sizeof(char));
387                            strcpy(opt[16], RRD_PARAM_PREFIX_15);
388                            opt[17]= (char *) malloc((strlen(RRD_PARAM_PREFIX_16) + 1) * sizeof(char));
389                            strcpy(opt[17], RRD_PARAM_PREFIX_16);
390                            opt[18]= (char *) malloc((strlen(RRD_PARAM_PREFIX_17) + 1) * sizeof(char));
391                            strcpy(opt[18], RRD_PARAM_PREFIX_17);
392                            opt[19]= (char *) malloc((strlen(RRD_PARAM_PREFIX_18) + 1) * sizeof(char));
393                            strcpy(opt[19], RRD_PARAM_PREFIX_18);
394                            opt[20]= (char *) malloc((strlen(RRD_PARAM_PREFIX_19) + 1) * sizeof(char));
395                            strcpy(opt[20], RRD_PARAM_PREFIX_19);
396                            opt[21]= (char *) malloc((strlen(RRD_PARAM_PREFIX_20) + 1) * sizeof(char));
397                            strcpy(opt[21], RRD_PARAM_PREFIX_20);
398                            opt[22]= (char *) malloc((strlen(RRD_PARAM_PREFIX_21) + 1) * sizeof(char));
399                            strcpy(opt[22], RRD_PARAM_PREFIX_21);
400                            opt[23]= (char *) malloc((strlen(RRD_PARAM_PREFIX_22) + 1) * sizeof(char));
401                            strcpy(opt[23], RRD_PARAM_PREFIX_22);
402                            opt[24]= (char *) malloc((strlen(RRD_PARAM_PREFIX_23) + 1) * sizeof(char));
403                            strcpy(opt[24], RRD_PARAM_PREFIX_23);
404                            opt[25]= (char *) malloc((strlen(RRD_PARAM_PREFIX_24) + 1) * sizeof(char));
405                            strcpy(opt[25], RRD_PARAM_PREFIX_24);
406                            opt[26]= (char *) malloc((strlen(RRD_PARAM_PREFIX_25) + 1) * sizeof(char));
407                            strcpy(opt[26], RRD_PARAM_PREFIX_25);
408                            optind = opterr = 0;
409                            rrd_clear_error();
410                            if ( rrd_create(27,opt) < 0)
411                            {
412                                syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error());
413                                rrd_create_er_ct++;
414                            }
415                            else
416                            {
417                                rrd_create_ok_ct++;
418                            }
419                            for ( j=0; j<27; j++)
420                            {
421                                free(opt[j]);
422                                opt[j] = NULL;
423                            }
424                        }
425                        else
426                        {
427                            fclose(fp);
428                            rrd_already_created_ct++;
429                            snprintf(buf,
430                                     2048,
431                                     "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",
432                                     now-300,  /* or ctime(&now) with %s */
433                                     shmForAgg->prefixV4Tab[index][i].flowNbIN,  /* 1 */
434                                     shmForAgg->prefixV4Tab[index][i].flowNbOUT,
435                                     shmForAgg->prefixV4Tab[index][i].bytesNbIN,
436                                     shmForAgg->prefixV4Tab[index][i].bytesNbOUT,
437                                     shmForAgg->prefixV4Tab[index][i].pktsNbIN,  /* 5 */
438                                     shmForAgg->prefixV4Tab[index][i].pktsNbOUT,
439                                     shmForAgg->prefixV4Tab[index][i].firstCoSIN,
440                                     shmForAgg->prefixV4Tab[index][i].firstCoSOUT,
441                                     shmForAgg->prefixV4Tab[index][i].secondCoSIN,
442                                     shmForAgg->prefixV4Tab[index][i].secondCoSOUT,
443                                     shmForAgg->prefixV4Tab[index][i].thirdCoSIN,
444                                     shmForAgg->prefixV4Tab[index][i].thirdCoSOUT,
445                                     shmForAgg->prefixV4Tab[index][i].fourthCoSIN,
446                                     shmForAgg->prefixV4Tab[index][i].fourthCoSOUT
447                                    );
448                            optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char));
449                            strcpy(optUpdate[0], RRD_UPDATE_0);
450                            optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
451                            strcpy(optUpdate[1], name);
452                            optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char));
453                            strcpy(optUpdate[2], buf);
454                            optind = opterr = 0;
455                            rrd_clear_error();
456                            if ( rrd_update(3, optUpdate) < 0 )
457                            {
458                                syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error());
459                                rrd_update_er_ct++;
460                            }
461                            else
462                            {
463                                rrd_update_ok_ct++;
464                            }
465                            for ( j=0; j<3; j++)
466                            {
467                                free(optUpdate[j]);
468                                optUpdate[j] = NULL;
469                            }
470                        }
471                        /* Reinit the shared tables */
472                        shmForAgg->prefixV4Tab[index][i].flowNbIN = 0;
473                        shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0;
474                        shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0;
475                        shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0;
476                        shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0;
477                        shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0;
478                        shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0;
479                        shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0;
480                        shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0;
481                        shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0;
482                        shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0;
483                        shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0;
484                        shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0;
485                        shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0;
[162]486
487                        SMP1_shmForAgg->prefixV4Tab[index][i].flowNbIN = 0;
488                        SMP1_shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0;
489                        SMP1_shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0;
490                        SMP1_shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0;
491                        SMP1_shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0;
492                        SMP1_shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0;
493                        SMP1_shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0;
494                        SMP1_shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0;
495                        SMP1_shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0;
496                        SMP1_shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0;
497                        SMP1_shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0;
498                        SMP1_shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0;
499                        SMP1_shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0;
500                        SMP1_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0;
501
502                        SMP2_shmForAgg->prefixV4Tab[index][i].flowNbIN = 0;
503                        SMP2_shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0;
504                        SMP2_shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0;
505                        SMP2_shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0;
506                        SMP2_shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0;
507                        SMP2_shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0;
508                        SMP2_shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0;
509                        SMP2_shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0;
510                        SMP2_shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0;
511                        SMP2_shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0;
512                        SMP2_shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0;
513                        SMP2_shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0;
514                        SMP2_shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0;
515                        SMP2_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0;
516
517                        SMP3_shmForAgg->prefixV4Tab[index][i].flowNbIN = 0;
518                        SMP3_shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0;
519                        SMP3_shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0;
520                        SMP3_shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0;
521                        SMP3_shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0;
522                        SMP3_shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0;
523                        SMP3_shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0;
524                        SMP3_shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0;
525                        SMP3_shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0;
526                        SMP3_shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0;
527                        SMP3_shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0;
528                        SMP3_shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0;
529                        SMP3_shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0;
530                        SMP3_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0;
531
532                        SMP4_shmForAgg->prefixV4Tab[index][i].flowNbIN = 0;
533                        SMP4_shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0;
534                        SMP4_shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0;
535                        SMP4_shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0;
536                        SMP4_shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0;
537                        SMP4_shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0;
538                        SMP4_shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0;
539                        SMP4_shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0;
540                        SMP4_shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0;
541                        SMP4_shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0;
542                        SMP4_shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0;
543                        SMP4_shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0;
544                        SMP4_shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0;
545                        SMP4_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0;
[157]546                    }
547                }
548                /* ACCOUNTING for prefixV4SubnetTab */
549                for (i=0; i<shmForAgg->v4SubnetNb; i++)
550                {
551                    /* HERE create or update RRD FILE */
552                    if (shmForAgg->prefixV4SubnetTab[index][i].sampling != 0)
553                    {
554                        for (j=0; j<strlen(name); j++)
555                        {
556                            name[j] = '\0';
557                        }
558                        for (j=0; j<strlen(createstr); j++)
559                        {
560                            createstr[j] = '\0';
561                        }
562                        for (j=0; j<strlen(ipStr); j++)
563                        {
564                            ipStr[j] = '\0';
565                        }
566                        for (j=0; j<strlen(buf); j++)
567                        {
568                            buf[j] = '\0';
569                        }
570                        strcat(name, PREFIX_RRD_LOCATION);
571                        sprintf(ipStr, "%lu_%lu_%lu_%lu_%hu_%lu",
572                                shmForAgg->prefixV4SubnetTab[index][i].beginning>>24,
573                                shmForAgg->prefixV4SubnetTab[index][i].beginning<<8>>24,
574                                shmForAgg->prefixV4SubnetTab[index][i].beginning<<16>>24,
575                                shmForAgg->prefixV4SubnetTab[index][i].beginning<<24>>24,
576                                shmForAgg->prefixV4SubnetTab[index][i].mask,
577                                shmForAgg->prefixV4SubnetTab[index][i].sampling
578                               );
579                        strcat(name, ipStr);
580                        strcat(name, RRD_EXTENSION);
581                        if ( (fp=fopen(name,"r")) == NULL )
582                        {
583                            opt[0]= (char *) malloc((strlen(RRD_PARAM_PREFIX_0) + 1) * sizeof(char));
584                            strcpy(opt[0], RRD_PARAM_PREFIX_0);
585                            opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
586                            strcpy(opt[1], name);
587                            opt[2]= (char *) malloc((strlen(RRD_PARAM_PREFIX_1) + 1) * sizeof(char));
588                            strcpy(opt[2], RRD_PARAM_PREFIX_1);
589                            opt[3]= (char *) malloc((strlen(RRD_PARAM_PREFIX_2) + 1) * sizeof(char));
590                            strcpy(opt[3], RRD_PARAM_PREFIX_2);
591                            opt[4]= (char *) malloc((strlen(RRD_PARAM_PREFIX_3) + 1) * sizeof(char));
592                            strcpy(opt[4], RRD_PARAM_PREFIX_3);
593                            opt[5]= (char *) malloc((strlen(RRD_PARAM_PREFIX_4) + 1) * sizeof(char));
594                            strcpy(opt[5], RRD_PARAM_PREFIX_4);
595                            opt[6]= (char *) malloc((strlen(RRD_PARAM_PREFIX_5) + 1) * sizeof(char));
596                            strcpy(opt[6], RRD_PARAM_PREFIX_5);
597                            opt[7]= (char *) malloc((strlen(RRD_PARAM_PREFIX_6) + 1) * sizeof(char));
598                            strcpy(opt[7], RRD_PARAM_PREFIX_6);
599                            opt[8]= (char *) malloc((strlen(RRD_PARAM_PREFIX_7) + 1) * sizeof(char));
600                            strcpy(opt[8], RRD_PARAM_PREFIX_7);
601                            opt[9]= (char *) malloc((strlen(RRD_PARAM_PREFIX_8) + 1) * sizeof(char));
602                            strcpy(opt[9], RRD_PARAM_PREFIX_8);
603                            opt[10]= (char *) malloc((strlen(RRD_PARAM_PREFIX_9) + 1) * sizeof(char));
604                            strcpy(opt[10], RRD_PARAM_PREFIX_9);
605                            opt[11]= (char *) malloc((strlen(RRD_PARAM_PREFIX_10) + 1) * sizeof(char));
606                            strcpy(opt[11], RRD_PARAM_PREFIX_10);
607                            opt[12]= (char *) malloc((strlen(RRD_PARAM_PREFIX_11) + 1) * sizeof(char));
608                            strcpy(opt[12], RRD_PARAM_PREFIX_11);
609                            opt[13]= (char *) malloc((strlen(RRD_PARAM_PREFIX_12) + 1) * sizeof(char));
610                            strcpy(opt[13], RRD_PARAM_PREFIX_12);
611                            opt[14]= (char *) malloc((strlen(RRD_PARAM_PREFIX_13) + 1) * sizeof(char));
612                            strcpy(opt[14], RRD_PARAM_PREFIX_13);
613                            opt[15]= (char *) malloc((strlen(RRD_PARAM_PREFIX_14) + 1) * sizeof(char));
614                            strcpy(opt[15], RRD_PARAM_PREFIX_14);
615                            opt[16]= (char *) malloc((strlen(RRD_PARAM_PREFIX_15) + 1) * sizeof(char));
616                            strcpy(opt[16], RRD_PARAM_PREFIX_15);
617                            opt[17]= (char *) malloc((strlen(RRD_PARAM_PREFIX_16) + 1) * sizeof(char));
618                            strcpy(opt[17], RRD_PARAM_PREFIX_16);
619                            opt[18]= (char *) malloc((strlen(RRD_PARAM_PREFIX_17) + 1) * sizeof(char));
620                            strcpy(opt[18], RRD_PARAM_PREFIX_17);
621                            opt[19]= (char *) malloc((strlen(RRD_PARAM_PREFIX_18) + 1) * sizeof(char));
622                            strcpy(opt[19], RRD_PARAM_PREFIX_18);
623                            opt[20]= (char *) malloc((strlen(RRD_PARAM_PREFIX_19) + 1) * sizeof(char));
624                            strcpy(opt[20], RRD_PARAM_PREFIX_19);
625                            opt[21]= (char *) malloc((strlen(RRD_PARAM_PREFIX_20) + 1) * sizeof(char));
626                            strcpy(opt[21], RRD_PARAM_PREFIX_20);
627                            opt[22]= (char *) malloc((strlen(RRD_PARAM_PREFIX_21) + 1) * sizeof(char));
628                            strcpy(opt[22], RRD_PARAM_PREFIX_21);
629                            opt[23]= (char *) malloc((strlen(RRD_PARAM_PREFIX_22) + 1) * sizeof(char));
630                            strcpy(opt[23], RRD_PARAM_PREFIX_22);
631                            opt[24]= (char *) malloc((strlen(RRD_PARAM_PREFIX_23) + 1) * sizeof(char));
632                            strcpy(opt[24], RRD_PARAM_PREFIX_23);
633                            opt[25]= (char *) malloc((strlen(RRD_PARAM_PREFIX_24) + 1) * sizeof(char));
634                            strcpy(opt[25], RRD_PARAM_PREFIX_24);
635                            opt[26]= (char *) malloc((strlen(RRD_PARAM_PREFIX_25) + 1) * sizeof(char));
636                            strcpy(opt[26], RRD_PARAM_PREFIX_25);
637                            optind = opterr = 0;
638                            rrd_clear_error();
639                            if ( rrd_create(27,opt) < 0)
640                            {
641                                syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error());
642                                rrd_create_er_ct++;
643                            }
644                            else
645                            {
646                                rrd_create_ok_ct++;
647                            }
648                            for ( j=0; j<27; j++)
649                            {
650                                free(opt[j]);
651                                opt[j] = NULL;
652                            }
653                        }
654                        else
655                        {
656                            fclose(fp);
657                            rrd_already_created_ct++;
658                            snprintf(buf,
659                                     2048,
660                                     "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",
661                                     now-300,  /* or ctime(&now) with %s */
662                                     shmForAgg->prefixV4SubnetTab[index][i].flowNbIN,  /* 1 */
663                                     shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT,
664                                     shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN,
665                                     shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT,
666                                     shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN,  /* 5 */
667                                     shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT,
668                                     shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN,
669                                     shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT,
670                                     shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN,
671                                     shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT,
672                                     shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN,
673                                     shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT,
674                                     shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN,
675                                     shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT
676                                    );
677                            optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char));
678                            strcpy(optUpdate[0], RRD_UPDATE_0);
679                            optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
680                            strcpy(optUpdate[1], name);
681                            optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char));
682                            strcpy(optUpdate[2], buf);
683                            optind = opterr = 0;
684                            rrd_clear_error();
685                            if ( rrd_update(3, optUpdate) < 0 )
686                            {
687                                syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error());
688                                rrd_update_er_ct++;
689                            }
690                            else
691                            {
692                                rrd_update_ok_ct++;
693                            }
694                            for ( j=0; j<3; j++)
695                            {
696                                free(optUpdate[j]);
697                                optUpdate[j] = NULL;
698                            }
699                        }
700                        /* Reinit the shared tables */
701                        shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0;
702                        shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0;
703                        shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0;
704                        shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0;
705                        shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0;
706                        shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0;
707                        shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0;
708                        shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0;
709                        shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0;
710                        shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0;
711                        shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0;
712                        shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0;
713                        shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0;
714                        shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0;
[162]715
716                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0;
717                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0;
718                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0;
719                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0;
720                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0;
721                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0;
722                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0;
723                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0;
724                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0;
725                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0;
726                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0;
727                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0;
728                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0;
729                        SMP1_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0;
730
731                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0;
732                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0;
733                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0;
734                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0;
735                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0;
736                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0;
737                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0;
738                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0;
739                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0;
740                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0;
741                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0;
742                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0;
743                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0;
744                        SMP2_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0;
745
746                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0;
747                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0;
748                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0;
749                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0;
750                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0;
751                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0;
752                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0;
753                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0;
754                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0;
755                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0;
756                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0;
757                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0;
758                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0;
759                        SMP3_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0;
760
761                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0;
762                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0;
763                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0;
764                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0;
765                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0;
766                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0;
767                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0;
768                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0;
769                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0;
770                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0;
771                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0;
772                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0;
773                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0;
774                        SMP4_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0;
[157]775                    }
776                }
[59]777#if defined(MATRIX) && defined(IPV4AGGIDR)
[157]778                /* MATRIX INTER POP ACCOUNTING */
779                /* rrd */
780                for (i=0; i<ROUTER_INDEX_MAX; i++)
781                {
782                    for (j=0; j<ROUTER_INDEX_MAX; j++)
783                    {
784                        /* HERE create or update RRD FILE */
785                        for (k=0; k<strlen(name); k++)
786                        {
787                            name[k] = '\0';
788                        }
789                        for (k=0; k<strlen(createstr); k++)
790                        {
791                            createstr[k] = '\0';
792                        }
793                        for (k=0; k<strlen(indexStr); k++)
794                        {
795                            indexStr[k] = '\0';
796                        }
797                        for (k=0; k<strlen(buf); k++)
798                        {
799                            buf[k] = '\0';
800                        }
801                        strcat(name, MATRIX_RRD_LOCATION);
802                        sprintf(indexStr, "%d_%d",
803                                i,
804                                j
805                               );
806                        strcat(name, indexStr);
807                        strcat(name, RRD_EXTENSION);
808                        if ( (fp=fopen(name,"r")) == NULL )
809                        {
810                            opt[0]= (char *) malloc((strlen(RRD_PARAM_MATRIX_0) + 1) * sizeof(char));
811                            strcpy(opt[0], RRD_PARAM_MATRIX_0);
812                            opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
813                            strcpy(opt[1], name);
814                            opt[2]= (char *) malloc((strlen(RRD_PARAM_MATRIX_1) + 1) * sizeof(char));
815                            strcpy(opt[2], RRD_PARAM_MATRIX_1);
816                            opt[3]= (char *) malloc((strlen(RRD_PARAM_MATRIX_2) + 1) * sizeof(char));
817                            strcpy(opt[3], RRD_PARAM_MATRIX_2);
818                            opt[4]= (char *) malloc((strlen(RRD_PARAM_MATRIX_3) + 1) * sizeof(char));
819                            strcpy(opt[4], RRD_PARAM_MATRIX_3);
820                            opt[5]= (char *) malloc((strlen(RRD_PARAM_MATRIX_4) + 1) * sizeof(char));
821                            strcpy(opt[5], RRD_PARAM_MATRIX_4);
822                            opt[6]= (char *) malloc((strlen(RRD_PARAM_MATRIX_5) + 1) * sizeof(char));
823                            strcpy(opt[6], RRD_PARAM_MATRIX_5);
824                            opt[7]= (char *) malloc((strlen(RRD_PARAM_MATRIX_6) + 1) * sizeof(char));
825                            strcpy(opt[7], RRD_PARAM_MATRIX_6);
826                            opt[8]= (char *) malloc((strlen(RRD_PARAM_MATRIX_7) + 1) * sizeof(char));
827                            strcpy(opt[8], RRD_PARAM_MATRIX_7);
828                            opt[9]= (char *) malloc((strlen(RRD_PARAM_MATRIX_8) + 1) * sizeof(char));
829                            strcpy(opt[9], RRD_PARAM_MATRIX_8);
830                            opt[10]= (char *) malloc((strlen(RRD_PARAM_MATRIX_9) + 1) * sizeof(char));
831                            strcpy(opt[10], RRD_PARAM_MATRIX_9);
832                            opt[11]= (char *) malloc((strlen(RRD_PARAM_MATRIX_10) + 1) * sizeof(char));
833                            strcpy(opt[11], RRD_PARAM_MATRIX_10);
834                            opt[12]= (char *) malloc((strlen(RRD_PARAM_MATRIX_11) + 1) * sizeof(char));
835                            strcpy(opt[12], RRD_PARAM_MATRIX_11);
836                            opt[13]= (char *) malloc((strlen(RRD_PARAM_MATRIX_12) + 1) * sizeof(char));
837                            strcpy(opt[13], RRD_PARAM_MATRIX_12);
838                            opt[14]= (char *) malloc((strlen(RRD_PARAM_MATRIX_13) + 1) * sizeof(char));
839                            strcpy(opt[14], RRD_PARAM_MATRIX_13);
840                            opt[15]= (char *) malloc((strlen(RRD_PARAM_MATRIX_14) + 1) * sizeof(char));
841                            strcpy(opt[15], RRD_PARAM_MATRIX_14);
842                            optind = opterr = 0;
843                            rrd_clear_error();
844                            if ( rrd_create(16,opt) < 0)
845                            {
846                                syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error());
847                                rrd_create_er_ct++;
848                            }
849                            else
850                            {
851                                rrd_create_ok_ct++;
852                            }
853                            for ( k=0; k<16; k++)
854                            {
855                                free(opt[k]);
856                                opt[k] = NULL;
857                            }
858                        }
859                        else
860                        {
861                            fclose(fp);
862                            rrd_already_created_ct++;
863                            snprintf(buf,
864                                     2048,
865                                     "%lu:%llu:%llu:%llu",
866                                     now-300,  /* or ctime(&now) with %s */
867                                     shmForAgg->matrixPOP[index][i][j].flowNb,
868                                     shmForAgg->matrixPOP[index][i][j].bytesNb,
869                                     shmForAgg->matrixPOP[index][i][j].pktsNb
870                                    );
871                            optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char));
872                            strcpy(optUpdate[0], RRD_UPDATE_0);
873                            optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
874                            strcpy(optUpdate[1], name);
875                            optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char));
876                            strcpy(optUpdate[2], buf);
877                            optind = opterr = 0;
878                            rrd_clear_error();
879                            if ( rrd_update(3, optUpdate) < 0 )
880                            {
881                                syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error());
882                                rrd_update_er_ct++;
883                            }
884                            else
885                            {
886                                rrd_update_ok_ct++;
887                            }
888                            for ( k=0; k<3; k++)
889                            {
890                                free(optUpdate[k]);
891                                optUpdate[k] = NULL;
892                            }
893                        }
[36]894
[157]895                    }
896                }
897                /* reinit */
898                for (i=0; i<ROUTER_INDEX_MAX; i++)
899                {
900                    for (j=0; j<ROUTER_INDEX_MAX; j++)
901                    {
902                        shmForAgg->matrixPOP[index][i][j].bytesNb = 0;
903                        shmForAgg->matrixPOP[index][i][j].pktsNb = 0;
904                        shmForAgg->matrixPOP[index][i][j].flowNb = 0;
905                    }
906                }
907                /* END MATRIX INTER POP ACC */
[59]908#endif /* MATRIX */
[60]909#ifdef ASACC
[157]910                /*
911                 *
912                 * AS ACCOUNTING
913                 *
914                 */
[162]915
[157]916                for (i=0; i<shmForAgg->ASNb; i++)
917                {
918                    /* HERE create or update RRD FILE */
919                    if (shmForAgg->ASTab[index][i].sampling != 0)
920                    {
921                        for (j=0; j<strlen(name); j++)
922                        {
923                            name[j] = '\0';
924                        }
925                        for (j=0; j<strlen(createstr); j++)
926                        {
927                            createstr[j] = '\0';
928                        }
929                        for (j=0; j<strlen(asStr); j++)
930                        {
931                            asStr[j] = '\0';
932                        }
933                        for (j=0; j<strlen(buf); j++)
934                        {
935                            buf[j] = '\0';
936                        }
937                        strcat(name, AS_RRD_LOCATION);
938                        sprintf(asStr, "%hu_%lu",
939                                shmForAgg->ASTab[index][i].as,
940                                shmForAgg->ASTab[index][i].sampling
941                               );
942                        strcat(name, asStr);
943                        strcat(name, RRD_EXTENSION);
944                        if ( (fp=fopen(name,"r")) == NULL )
945                        {
946                            opt[0]= (char *) malloc((strlen(RRD_PARAM_AS_0) + 1) * sizeof(char));
947                            strcpy(opt[0], RRD_PARAM_AS_0);
948                            opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
949                            strcpy(opt[1], name);
950                            opt[2]= (char *) malloc((strlen(RRD_PARAM_AS_1) + 1) * sizeof(char));
951                            strcpy(opt[2], RRD_PARAM_AS_1);
952                            opt[3]= (char *) malloc((strlen(RRD_PARAM_AS_2) + 1) * sizeof(char));
953                            strcpy(opt[3], RRD_PARAM_AS_2);
954                            opt[4]= (char *) malloc((strlen(RRD_PARAM_AS_3) + 1) * sizeof(char));
955                            strcpy(opt[4], RRD_PARAM_AS_3);
956                            opt[5]= (char *) malloc((strlen(RRD_PARAM_AS_4) + 1) * sizeof(char));
957                            strcpy(opt[5], RRD_PARAM_AS_4);
958                            opt[6]= (char *) malloc((strlen(RRD_PARAM_AS_5) + 1) * sizeof(char));
959                            strcpy(opt[6], RRD_PARAM_AS_5);
960                            opt[7]= (char *) malloc((strlen(RRD_PARAM_AS_6) + 1) * sizeof(char));
961                            strcpy(opt[7], RRD_PARAM_AS_6);
962                            opt[8]= (char *) malloc((strlen(RRD_PARAM_AS_7) + 1) * sizeof(char));
963                            strcpy(opt[8], RRD_PARAM_AS_7);
964                            opt[9]= (char *) malloc((strlen(RRD_PARAM_AS_8) + 1) * sizeof(char));
965                            strcpy(opt[9], RRD_PARAM_AS_8);
966                            opt[10]= (char *) malloc((strlen(RRD_PARAM_AS_9) + 1) * sizeof(char));
967                            strcpy(opt[10], RRD_PARAM_AS_9);
968                            opt[11]= (char *) malloc((strlen(RRD_PARAM_AS_10) + 1) * sizeof(char));
969                            strcpy(opt[11], RRD_PARAM_AS_10);
970                            opt[12]= (char *) malloc((strlen(RRD_PARAM_AS_11) + 1) * sizeof(char));
971                            strcpy(opt[12], RRD_PARAM_AS_11);
972                            opt[13]= (char *) malloc((strlen(RRD_PARAM_AS_12) + 1) * sizeof(char));
973                            strcpy(opt[13], RRD_PARAM_AS_12);
974                            opt[14]= (char *) malloc((strlen(RRD_PARAM_AS_13) + 1) * sizeof(char));
975                            strcpy(opt[14], RRD_PARAM_AS_13);
976                            opt[15]= (char *) malloc((strlen(RRD_PARAM_AS_14) + 1) * sizeof(char));
977                            strcpy(opt[15], RRD_PARAM_AS_14);
978                            opt[16]= (char *) malloc((strlen(RRD_PARAM_AS_15) + 1) * sizeof(char));
979                            strcpy(opt[16], RRD_PARAM_AS_15);
980                            opt[17]= (char *) malloc((strlen(RRD_PARAM_AS_16) + 1) * sizeof(char));
981                            strcpy(opt[17], RRD_PARAM_AS_16);
982                            opt[18]= (char *) malloc((strlen(RRD_PARAM_AS_17) + 1) * sizeof(char));
983                            strcpy(opt[18], RRD_PARAM_AS_17);
984                            optind = opterr = 0;
985                            rrd_clear_error();
986                            if ( rrd_create(19,opt) < 0)
987                            {
988                                syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error());
989                                rrd_create_er_ct++;
990                            }
991                            else
992                            {
993                                rrd_create_ok_ct++;
994                            }
995                            for ( j=0; j<19; j++)
996                            {
997                                free(opt[j]);
998                                opt[j] = NULL;
999                            }
1000                        }
1001                        else
1002                        {
1003                            fclose(fp);
1004                            rrd_already_created_ct++;
1005                            snprintf(buf,
1006                                     2048,
1007                                     "%lu:%llu:%llu:%llu:%llu:%llu:%llu",
1008                                     now-300,  /* or ctime(&now) with %s */
1009                                     shmForAgg->ASTab[index][i].flowNbIN,  /* 1 */
1010                                     shmForAgg->ASTab[index][i].flowNbOUT,
1011                                     shmForAgg->ASTab[index][i].bytesNbIN,
1012                                     shmForAgg->ASTab[index][i].bytesNbOUT,
1013                                     shmForAgg->ASTab[index][i].pktsNbIN,  /* 5 */
1014                                     shmForAgg->ASTab[index][i].pktsNbOUT
1015                                    );
1016                            optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char));
1017                            strcpy(optUpdate[0], RRD_UPDATE_0);
1018                            optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
1019                            strcpy(optUpdate[1], name);
1020                            optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char));
1021                            strcpy(optUpdate[2], buf);
1022                            optind = opterr = 0;
1023                            rrd_clear_error();
1024                            if ( rrd_update(3, optUpdate) < 0 )
1025                            {
1026                                syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error());
1027                                rrd_update_er_ct++;
1028                            }
1029                            else
1030                            {
1031                                rrd_update_ok_ct++;
1032                            }
1033                            for ( j=0; j<3; j++)
1034                            {
1035                                free(optUpdate[j]);
1036                                optUpdate[j] = NULL;
1037                            }
1038                        }
1039                        /* Reinit the shared tables */
1040                        shmForAgg->ASTab[index][i].flowNbIN = 0;
1041                        shmForAgg->ASTab[index][i].bytesNbIN = 0;
1042                        shmForAgg->ASTab[index][i].pktsNbIN = 0;
1043                        shmForAgg->ASTab[index][i].flowNbOUT = 0;
1044                        shmForAgg->ASTab[index][i].bytesNbOUT = 0;
1045                        shmForAgg->ASTab[index][i].pktsNbOUT = 0;
[162]1046
1047                        SMP1_shmForAgg->ASTab[index][i].flowNbIN = 0;
1048                        SMP1_shmForAgg->ASTab[index][i].bytesNbIN = 0;
1049                        SMP1_shmForAgg->ASTab[index][i].pktsNbIN = 0;
1050                        SMP1_shmForAgg->ASTab[index][i].flowNbOUT = 0;
1051                        SMP1_shmForAgg->ASTab[index][i].bytesNbOUT = 0;
1052                        SMP1_shmForAgg->ASTab[index][i].pktsNbOUT = 0;
1053
1054                        SMP2_shmForAgg->ASTab[index][i].flowNbIN = 0;
1055                        SMP2_shmForAgg->ASTab[index][i].bytesNbIN = 0;
1056                        SMP2_shmForAgg->ASTab[index][i].pktsNbIN = 0;
1057                        SMP2_shmForAgg->ASTab[index][i].flowNbOUT = 0;
1058                        SMP2_shmForAgg->ASTab[index][i].bytesNbOUT = 0;
1059                        SMP2_shmForAgg->ASTab[index][i].pktsNbOUT = 0;
1060
1061                        SMP3_shmForAgg->ASTab[index][i].flowNbIN = 0;
1062                        SMP3_shmForAgg->ASTab[index][i].bytesNbIN = 0;
1063                        SMP3_shmForAgg->ASTab[index][i].pktsNbIN = 0;
1064                        SMP3_shmForAgg->ASTab[index][i].flowNbOUT = 0;
1065                        SMP3_shmForAgg->ASTab[index][i].bytesNbOUT = 0;
1066                        SMP3_shmForAgg->ASTab[index][i].pktsNbOUT = 0;
1067
1068                        SMP4_shmForAgg->ASTab[index][i].flowNbIN = 0;
1069                        SMP4_shmForAgg->ASTab[index][i].bytesNbIN = 0;
1070                        SMP4_shmForAgg->ASTab[index][i].pktsNbIN = 0;
1071                        SMP4_shmForAgg->ASTab[index][i].flowNbOUT = 0;
1072                        SMP4_shmForAgg->ASTab[index][i].bytesNbOUT = 0;
1073                        SMP4_shmForAgg->ASTab[index][i].pktsNbOUT = 0;
1074
[157]1075                    }
1076                }
[96]1077#ifdef IPV6LINKAGG
[157]1078                /*
1079                 *
1080                 * IPv6 Links ACCOUNTING
1081                 *
1082                 */
1083                for (i=0; i<ROUTER_INDEX_MAX; i++)
1084                {
1085                    for (j=0; j<MAX_INDEX_BY_ROUTER; j++)
1086                    {
1087                        /* HERE create or update RRD FILE for IPV6 LINKs AGGregation */
1088                        if (shmForAgg->indexV6Tab[index][i][j].hasStats == 1)
1089                        {
1090                            for (k=0; k<strlen(name); k++)
1091                            {
1092                                name[k] = '\0';
1093                            }
1094                            for (k=0; k<strlen(createstr); k++)
1095                            {
1096                                createstr[k] = '\0';
1097                            }
1098                            for (k=0; k<strlen(ipv6LinkStr); k++)
1099                            {
1100                                ipv6LinkStr[k] = '\0';
1101                            }
1102                            for (k=0; k<strlen(buf); k++)
1103                            {
1104                                buf[k] = '\0';
1105                            }
1106                            strcat(name, SNMP_INDEX_RRD_LOCATION);
1107                            sprintf(ipv6LinkStr, "%lu_%lu_%lu_%lu_%hu_%hu",
1108                                    shmForAgg->indexV6Tab[index][i][j].routerIPAddress>>24,
1109                                    shmForAgg->indexV6Tab[index][i][j].routerIPAddress<<8>>24,
1110                                    shmForAgg->indexV6Tab[index][i][j].routerIPAddress<<16>>24,
1111                                    shmForAgg->indexV6Tab[index][i][j].routerIPAddress<<24>>24,
1112                                    (unsigned short) 1,
1113                                    shmForAgg->indexV6Tab[index][i][j].indexSNMP
1114                                   );
1115                            strcat(name, ipv6LinkStr);
1116                            strcat(name, RRD_EXTENSION);
1117                            if ( (fp=fopen(name,"r")) == NULL )
1118                            {
1119                                opt[0]= (char *) malloc((strlen(RRD_PARAM_INDEX_0) + 1) * sizeof(char));
1120                                strcpy(opt[0], RRD_PARAM_INDEX_0);
1121                                opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
1122                                strcpy(opt[1], name);
1123                                opt[2]= (char *) malloc((strlen(RRD_PARAM_INDEX_1) + 1) * sizeof(char));
1124                                strcpy(opt[2], RRD_PARAM_INDEX_1);
1125                                opt[3]= (char *) malloc((strlen(RRD_PARAM_INDEX_2) + 1) * sizeof(char));
1126                                strcpy(opt[3], RRD_PARAM_INDEX_2);
1127                                opt[4]= (char *) malloc((strlen(RRD_PARAM_INDEX_3) + 1) * sizeof(char));
1128                                strcpy(opt[4], RRD_PARAM_INDEX_3);
1129                                opt[5]= (char *) malloc((strlen(RRD_PARAM_INDEX_4) + 1) * sizeof(char));
1130                                strcpy(opt[5], RRD_PARAM_INDEX_4);
1131                                opt[6]= (char *) malloc((strlen(RRD_PARAM_INDEX_5) + 1) * sizeof(char));
1132                                strcpy(opt[6], RRD_PARAM_INDEX_5);
1133                                opt[7]= (char *) malloc((strlen(RRD_PARAM_INDEX_6) + 1) * sizeof(char));
1134                                strcpy(opt[7], RRD_PARAM_INDEX_6);
1135                                opt[8]= (char *) malloc((strlen(RRD_PARAM_INDEX_7) + 1) * sizeof(char));
1136                                strcpy(opt[8], RRD_PARAM_INDEX_7);
1137                                opt[9]= (char *) malloc((strlen(RRD_PARAM_INDEX_8) + 1) * sizeof(char));
1138                                strcpy(opt[9], RRD_PARAM_INDEX_8);
1139                                opt[10]= (char *) malloc((strlen(RRD_PARAM_INDEX_9) + 1) * sizeof(char));
1140                                strcpy(opt[10], RRD_PARAM_INDEX_9);
1141                                opt[11]= (char *) malloc((strlen(RRD_PARAM_INDEX_10) + 1) * sizeof(char));
1142                                strcpy(opt[11], RRD_PARAM_INDEX_10);
1143                                opt[12]= (char *) malloc((strlen(RRD_PARAM_INDEX_11) + 1) * sizeof(char));
1144                                strcpy(opt[12], RRD_PARAM_INDEX_11);
1145                                opt[13]= (char *) malloc((strlen(RRD_PARAM_INDEX_12) + 1) * sizeof(char));
1146                                strcpy(opt[13], RRD_PARAM_INDEX_12);
1147                                opt[14]= (char *) malloc((strlen(RRD_PARAM_INDEX_13) + 1) * sizeof(char));
1148                                strcpy(opt[14], RRD_PARAM_INDEX_13);
1149                                opt[15]= (char *) malloc((strlen(RRD_PARAM_INDEX_14) + 1) * sizeof(char));
1150                                strcpy(opt[15], RRD_PARAM_INDEX_14);
1151                                opt[16]= (char *) malloc((strlen(RRD_PARAM_INDEX_15) + 1) * sizeof(char));
1152                                strcpy(opt[16], RRD_PARAM_INDEX_15);
1153                                opt[17]= (char *) malloc((strlen(RRD_PARAM_INDEX_16) + 1) * sizeof(char));
1154                                strcpy(opt[17], RRD_PARAM_INDEX_16);
1155                                opt[18]= (char *) malloc((strlen(RRD_PARAM_INDEX_17) + 1) * sizeof(char));
1156                                strcpy(opt[18], RRD_PARAM_INDEX_17);
1157                                optind = opterr = 0;
1158                                rrd_clear_error();
1159                                if ( rrd_create(19,opt) < 0)
1160                                {
1161                                    syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error());
1162                                    rrd_create_er_ct++;
1163                                }
1164                                else
1165                                {
1166                                    rrd_create_ok_ct++;
1167                                }
1168                                for ( k=0; k<19; k++)
1169                                {
1170                                    free(opt[k]);
1171                                    opt[k] = NULL;
1172                                }
1173                            }
1174                            else
1175                            {
1176                                fclose(fp);
1177                                rrd_already_created_ct++;
1178                                snprintf(buf,
1179                                         2048,
1180                                         "%lu:%llu:%llu:%llu:%llu:%llu:%llu",
1181                                         now-300,  /* or ctime(&now) with %s */
1182                                         shmForAgg->indexV6Tab[index][i][j].flowNbIN,  /* 1 */
1183                                         shmForAgg->indexV6Tab[index][i][j].flowNbOUT,
1184                                         shmForAgg->indexV6Tab[index][i][j].bytesNbIN,
1185                                         shmForAgg->indexV6Tab[index][i][j].bytesNbOUT,
1186                                         shmForAgg->indexV6Tab[index][i][j].pktsNbIN,  /* 5 */
1187                                         shmForAgg->indexV6Tab[index][i][j].pktsNbOUT
1188                                        );
1189                                optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char));
1190                                strcpy(optUpdate[0], RRD_UPDATE_0);
1191                                optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
1192                                strcpy(optUpdate[1], name);
1193                                optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char));
1194                                strcpy(optUpdate[2], buf);
1195                                optind = opterr = 0;
1196                                rrd_clear_error();
1197                                if ( rrd_update(3, optUpdate) < 0 )
1198                                {
1199                                    syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error());
1200                                    rrd_update_er_ct++;
1201                                }
1202                                else
1203                                {
1204                                    rrd_update_ok_ct++;
1205                                }
1206                                for ( k=0; k<3; k++)
1207                                {
1208                                    free(optUpdate[k]);
1209                                    optUpdate[k] = NULL;
1210                                }
1211                            }
1212                            shmForAgg->indexV6Tab[index][i][j].bytesNbIN = 0;
1213                            shmForAgg->indexV6Tab[index][i][j].pktsNbIN = 0;
1214                            shmForAgg->indexV6Tab[index][i][j].flowNbIN = 0;
1215                            shmForAgg->indexV6Tab[index][i][j].bytesNbOUT = 0;
1216                            shmForAgg->indexV6Tab[index][i][j].pktsNbOUT = 0;
1217                            shmForAgg->indexV6Tab[index][i][j].flowNbOUT = 0;
1218                        }
1219                    }
1220                }
[96]1221#endif
[60]1222#endif /* AS */
[157]1223                if (rrdMibsUpdate(index) != 1)
1224                {
1225                    syslog(LOG_ERR, "ERROR in RRD MIBs update file\n");
1226                }
1227                if (rrdL7IPv4MibsUpdate(index) != 1)
1228                {
1229                    syslog(LOG_ERR, "ERROR in RRD MIBs update file\n");
1230                }
1231                now2 = time((time_t *)NULL);
[57]1232#ifdef DEBUGAGG
[157]1233                fprintf(stderr, "IPv4 subnet managment (rrd update) : \n %d sec, %d files updated, %d errors, total %d\n %d rrd file already created, %d errors in creation, %d new rrd file creations",
1234                        (int)now2-now,
1235                        rrd_update_ok_ct,
1236                        rrd_update_er_ct,
1237                        rrd_update_ok_ct+rrd_update_er_ct,
1238                        rrd_already_created_ct,
1239                        rrd_create_er_ct,
1240                        rrd_create_ok_ct);
[57]1241#endif
[157]1242                rrd_update_ok_ct = 0;
1243                rrd_update_er_ct = 0;
1244                rrd_already_created_ct = 0;
1245                rrd_create_er_ct = 0;
1246                rrd_create_ok_ct = 0;
1247                rrd_clear_error();
1248            }
1249            else
1250            {
[162]1251                isFirstUpdate = 0; /* first update after program start ? */
[157]1252                /* RRD Update only for the MIB counters, else we clear all counters in shared memory (after) */
1253                if (rrdMibsUpdate(index) != 1)
1254                {
1255                    syslog(LOG_ERR, "ERROR in RRD MIBs update file\n");
1256                }
1257                if (rrdL7IPv4MibsUpdate(index) != 1)
1258                {
1259                    syslog(LOG_ERR, "ERROR in RRD MIBs update file\n");
1260                }
1261                /* CLEAR */
1262                for (i=0; i<shmForAgg->v4PrefixNb; i++)
1263                {
1264                    shmForAgg->prefixV4Tab[index][i].flowNbIN = 0;
1265                    shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0;
1266                    shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0;
1267                    shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0;
1268                    shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0;
1269                    shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0;
1270                    shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0;
1271                    shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0;
1272                    shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0;
1273                    shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0;
1274                    shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0;
1275                    shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0;
1276                    shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0;
1277                    shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0;
[162]1278                    SMP1_shmForAgg->prefixV4Tab[index][i].flowNbIN = 0;
1279                    SMP1_shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0;
1280                    SMP1_shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0;
1281                    SMP1_shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0;
1282                    SMP1_shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0;
1283                    SMP1_shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0;
1284                    SMP1_shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0;
1285                    SMP1_shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0;
1286                    SMP1_shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0;
1287                    SMP1_shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0;
1288                    SMP1_shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0;
1289                    SMP1_shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0;
1290                    SMP1_shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0;
1291                    SMP1_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0;
1292                    SMP2_shmForAgg->prefixV4Tab[index][i].flowNbIN = 0;
1293                    SMP2_shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0;
1294                    SMP2_shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0;
1295                    SMP2_shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0;
1296                    SMP2_shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0;
1297                    SMP2_shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0;
1298                    SMP2_shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0;
1299                    SMP2_shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0;
1300                    SMP2_shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0;
1301                    SMP2_shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0;
1302                    SMP2_shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0;
1303                    SMP2_shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0;
1304                    SMP2_shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0;
1305                    SMP2_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0;
1306                    SMP3_shmForAgg->prefixV4Tab[index][i].flowNbIN = 0;
1307                    SMP3_shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0;
1308                    SMP3_shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0;
1309                    SMP3_shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0;
1310                    SMP3_shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0;
1311                    SMP3_shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0;
1312                    SMP3_shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0;
1313                    SMP3_shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0;
1314                    SMP3_shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0;
1315                    SMP3_shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0;
1316                    SMP3_shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0;
1317                    SMP3_shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0;
1318                    SMP3_shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0;
1319                    SMP3_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0;
1320                    SMP4_shmForAgg->prefixV4Tab[index][i].flowNbIN = 0;
1321                    SMP4_shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0;
1322                    SMP4_shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0;
1323                    SMP4_shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0;
1324                    SMP4_shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0;
1325                    SMP4_shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0;
1326                    SMP4_shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0;
1327                    SMP4_shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0;
1328                    SMP4_shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0;
1329                    SMP4_shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0;
1330                    SMP4_shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0;
1331                    SMP4_shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0;
1332                    SMP4_shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0;
1333                    SMP4_shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0;
[157]1334                }
1335                for (i=0; i<shmForAgg->v4SubnetNb; i++)
1336                {
1337                    shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0;
1338                    shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0;
1339                    shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0;
1340                    shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0;
1341                    shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0;
1342                    shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0;
1343                    shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0;
1344                    shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0;
1345                    shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0;
1346                    shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0;
1347                    shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0;
1348                    shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0;
1349                    shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0;
1350                    shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0;
[162]1351                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0;
1352                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0;
1353                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0;
1354                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0;
1355                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0;
1356                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0;
1357                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0;
1358                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0;
1359                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0;
1360                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0;
1361                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0;
1362                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0;
1363                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0;
1364                    SMP1_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0;
1365                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0;
1366                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0;
1367                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0;
1368                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0;
1369                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0;
1370                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0;
1371                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0;
1372                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0;
1373                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0;
1374                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0;
1375                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0;
1376                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0;
1377                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0;
1378                    SMP2_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0;
1379                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0;
1380                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0;
1381                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0;
1382                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0;
1383                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0;
1384                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0;
1385                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0;
1386                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0;
1387                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0;
1388                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0;
1389                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0;
1390                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0;
1391                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0;
1392                    SMP3_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0;
1393                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].flowNbIN = 0;
1394                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].bytesNbIN = 0;
1395                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].pktsNbIN = 0;
1396                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].flowNbOUT = 0;
1397                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].bytesNbOUT = 0;
1398                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].pktsNbOUT = 0;
1399                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].firstCoSIN = 0;
1400                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].secondCoSIN = 0;
1401                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSIN = 0;
1402                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSIN = 0;
1403                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].firstCoSOUT = 0;
1404                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].secondCoSOUT = 0;
1405                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].thirdCoSOUT = 0;
1406                    SMP4_shmForAgg->prefixV4SubnetTab[index][i].fourthCoSOUT = 0;
[157]1407                }
[59]1408#ifdef MATRIX
[157]1409                for (i=0; i<ROUTER_INDEX_MAX; i++)
1410                {
1411                    for (j=0; j<ROUTER_INDEX_MAX; j++)
1412                    {
1413                        shmForAgg->matrixPOP[index][i][j].bytesNb = 0;
1414                        shmForAgg->matrixPOP[index][i][j].pktsNb = 0;
1415                        shmForAgg->matrixPOP[index][i][j].flowNb = 0;
1416                    }
1417                }
[59]1418#endif
[60]1419#ifdef ASACC
[157]1420                for (i=0; i<shmForAgg->ASNb; i++)
1421                {
1422                    shmForAgg->ASTab[index][i].flowNbIN = 0;
1423                    shmForAgg->ASTab[index][i].bytesNbIN = 0;
1424                    shmForAgg->ASTab[index][i].pktsNbIN = 0;
1425                    shmForAgg->ASTab[index][i].flowNbOUT = 0;
1426                    shmForAgg->ASTab[index][i].bytesNbOUT = 0;
1427                    shmForAgg->ASTab[index][i].pktsNbOUT = 0;
[162]1428                    SMP1_shmForAgg->ASTab[index][i].flowNbIN = 0;
1429                    SMP1_shmForAgg->ASTab[index][i].bytesNbIN = 0;
1430                    SMP1_shmForAgg->ASTab[index][i].pktsNbIN = 0;
1431                    SMP1_shmForAgg->ASTab[index][i].flowNbOUT = 0;
1432                    SMP1_shmForAgg->ASTab[index][i].bytesNbOUT = 0;
1433                    SMP1_shmForAgg->ASTab[index][i].pktsNbOUT = 0;
1434                    SMP2_shmForAgg->ASTab[index][i].flowNbIN = 0;
1435                    SMP2_shmForAgg->ASTab[index][i].bytesNbIN = 0;
1436                    SMP2_shmForAgg->ASTab[index][i].pktsNbIN = 0;
1437                    SMP2_shmForAgg->ASTab[index][i].flowNbOUT = 0;
1438                    SMP2_shmForAgg->ASTab[index][i].bytesNbOUT = 0;
1439                    SMP2_shmForAgg->ASTab[index][i].pktsNbOUT = 0;
1440                    SMP3_shmForAgg->ASTab[index][i].flowNbIN = 0;
1441                    SMP3_shmForAgg->ASTab[index][i].bytesNbIN = 0;
1442                    SMP3_shmForAgg->ASTab[index][i].pktsNbIN = 0;
1443                    SMP3_shmForAgg->ASTab[index][i].flowNbOUT = 0;
1444                    SMP3_shmForAgg->ASTab[index][i].bytesNbOUT = 0;
1445                    SMP3_shmForAgg->ASTab[index][i].pktsNbOUT = 0;
1446                    SMP4_shmForAgg->ASTab[index][i].flowNbIN = 0;
1447                    SMP4_shmForAgg->ASTab[index][i].bytesNbIN = 0;
1448                    SMP4_shmForAgg->ASTab[index][i].pktsNbIN = 0;
1449                    SMP4_shmForAgg->ASTab[index][i].flowNbOUT = 0;
1450                    SMP4_shmForAgg->ASTab[index][i].bytesNbOUT = 0;
1451                    SMP4_shmForAgg->ASTab[index][i].pktsNbOUT = 0;
[157]1452                }
[60]1453#endif
[96]1454#ifdef IPV6LINKAGG
[157]1455                for (i=0; i<ROUTER_INDEX_MAX; i++)
1456                {
1457                    for (j=0; j<MAX_INDEX_BY_ROUTER; j++)
1458                    {
1459                        shmForAgg->indexV6Tab[index][i][j].bytesNbIN = 0;
1460                        shmForAgg->indexV6Tab[index][i][j].pktsNbIN = 0;
1461                        shmForAgg->indexV6Tab[index][i][j].flowNbIN = 0;
1462                        shmForAgg->indexV6Tab[index][i][j].bytesNbOUT = 0;
1463                        shmForAgg->indexV6Tab[index][i][j].pktsNbOUT = 0;
1464                        shmForAgg->indexV6Tab[index][i][j].flowNbOUT = 0;
1465                    }
1466                }
[96]1467#endif
[157]1468                /* reinit */
1469            } /* end is first update */
1470        } /* end read ok */
[162]1471      sleep(10);
1472
[157]1473    }
1474    while (1);
1475    exit(0);
[24]1476}
[115]1477
1478
1479/*
1480 * rrdMibsUpdate
1481 */
1482short rrdMibsUpdate(int index)
1483{
[157]1484    int i, j, k = 0;
1485    int rrd_update_er_ct = 0;
1486    int rrd_update_ok_ct = 0;
1487    int rrd_already_created_ct = 0;
1488    int rrd_create_er_ct = 0;
1489    int rrd_create_ok_ct = 0;
1490    static char buf[2048];
1491    static char name[2048];
1492    static char createstr[2048];
1493    char *opt[27];
1494    char *optUpdate[3];
1495    FILE *fp;
1496    static time_t now, now2;
[115]1497
[162]1498    shmForAgg->myMIB[index].ipPacketNb = SMP1_shmForAgg->myMIB[index].ipPacketNb +
1499                                         SMP2_shmForAgg->myMIB[index].ipPacketNb +
1500                                         SMP3_shmForAgg->myMIB[index].ipPacketNb +
1501                                         SMP4_shmForAgg->myMIB[index].ipPacketNb;
1502    shmForAgg->myMIB[index].udpPacketNb = SMP1_shmForAgg->myMIB[index].udpPacketNb +
1503                                          SMP2_shmForAgg->myMIB[index].udpPacketNb +
1504                                          SMP3_shmForAgg->myMIB[index].udpPacketNb +
1505                                          SMP4_shmForAgg->myMIB[index].udpPacketNb;
1506    shmForAgg->myMIB[index].v9PacketNb = SMP1_shmForAgg->myMIB[index].v9PacketNb +
1507                                         SMP2_shmForAgg->myMIB[index].v9PacketNb +
1508                                         SMP3_shmForAgg->myMIB[index].v9PacketNb +
1509                                         SMP4_shmForAgg->myMIB[index].v9PacketNb;
1510    shmForAgg->myMIB[index].v9UnSeqNb = SMP1_shmForAgg->myMIB[index].v9UnSeqNb +
1511                                        SMP2_shmForAgg->myMIB[index].v9UnSeqNb +
1512                                        SMP3_shmForAgg->myMIB[index].v9UnSeqNb +
1513                                        SMP4_shmForAgg->myMIB[index].v9UnSeqNb;
1514    shmForAgg->myMIB[index].flowSetNb = SMP1_shmForAgg->myMIB[index].flowSetNb +
1515                                        SMP2_shmForAgg->myMIB[index].flowSetNb +
1516                                        SMP3_shmForAgg->myMIB[index].flowSetNb +
1517                                        SMP4_shmForAgg->myMIB[index].flowSetNb;
1518    shmForAgg->myMIB[index].dataFlowSetNb = SMP1_shmForAgg->myMIB[index].dataFlowSetNb +
1519                                            SMP2_shmForAgg->myMIB[index].dataFlowSetNb +
1520                                            SMP3_shmForAgg->myMIB[index].dataFlowSetNb +
1521                                            SMP4_shmForAgg->myMIB[index].dataFlowSetNb;
1522    shmForAgg->myMIB[index].defFlowSetNb = SMP1_shmForAgg->myMIB[index].defFlowSetNb +
1523                                           SMP2_shmForAgg->myMIB[index].defFlowSetNb +
1524                                           SMP3_shmForAgg->myMIB[index].defFlowSetNb +
1525                                           SMP4_shmForAgg->myMIB[index].defFlowSetNb;
1526    shmForAgg->myMIB[index].optDataFlowSetNb = SMP1_shmForAgg->myMIB[index].optDataFlowSetNb +
1527                                               SMP2_shmForAgg->myMIB[index].optDataFlowSetNb +
1528                                               SMP3_shmForAgg->myMIB[index].optDataFlowSetNb +
1529                                               SMP4_shmForAgg->myMIB[index].optDataFlowSetNb;
1530    shmForAgg->myMIB[index].optDefFlowSetNb = SMP1_shmForAgg->myMIB[index].optDefFlowSetNb +
1531                                              SMP2_shmForAgg->myMIB[index].optDefFlowSetNb +
1532                                              SMP3_shmForAgg->myMIB[index].optDefFlowSetNb +
1533                                              SMP4_shmForAgg->myMIB[index].optDefFlowSetNb;
1534    shmForAgg->myMIB[index].flowNb = SMP1_shmForAgg->myMIB[index].flowNb +
1535                                     SMP2_shmForAgg->myMIB[index].flowNb +
1536                                     SMP3_shmForAgg->myMIB[index].flowNb +
1537                                     SMP4_shmForAgg->myMIB[index].flowNb;
1538    shmForAgg->myMIB[index].realFlowNb = SMP1_shmForAgg->myMIB[index].realFlowNb +
1539                                         SMP2_shmForAgg->myMIB[index].realFlowNb +
1540                                         SMP3_shmForAgg->myMIB[index].realFlowNb +
1541                                         SMP4_shmForAgg->myMIB[index].realFlowNb;
1542
[157]1543    now = time((time_t *)NULL);
1544    for (k=0; k<strlen(name); k++)
1545    {
1546        name[k] = '\0';
[115]1547    }
[157]1548    for (k=0; k<strlen(buf); k++)
1549    {
1550        buf[k] = '\0';
[115]1551    }
[157]1552    strcat(name, MIB_RRD_LOCATION);
1553    strcat(name, GLOBAL_MIB_RRD_FILE);
1554    if ( (fp=fopen(name,"r")) == NULL )
1555    {
1556        opt[0]= (char *) malloc((strlen(RRD_PARAM_MIB_0) + 1) * sizeof(char));
1557        strcpy(opt[0], RRD_PARAM_MIB_0);
1558        opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
1559        strcpy(opt[1], name);
1560        opt[2]= (char *) malloc((strlen(RRD_PARAM_MIB_1) + 1) * sizeof(char));
1561        strcpy(opt[2], RRD_PARAM_MIB_1);
1562        opt[3]= (char *) malloc((strlen(RRD_PARAM_MIB_2) + 1) * sizeof(char));
1563        strcpy(opt[3], RRD_PARAM_MIB_2);
1564        opt[4]= (char *) malloc((strlen(RRD_PARAM_MIB_3) + 1) * sizeof(char));
1565        strcpy(opt[4], RRD_PARAM_MIB_3);
1566        opt[5]= (char *) malloc((strlen(RRD_PARAM_MIB_4) + 1) * sizeof(char));
1567        strcpy(opt[5], RRD_PARAM_MIB_4);
1568        opt[6]= (char *) malloc((strlen(RRD_PARAM_MIB_5) + 1) * sizeof(char));
1569        strcpy(opt[6], RRD_PARAM_MIB_5);
1570        opt[7]= (char *) malloc((strlen(RRD_PARAM_MIB_6) + 1) * sizeof(char));
1571        strcpy(opt[7], RRD_PARAM_MIB_6);
1572        opt[8]= (char *) malloc((strlen(RRD_PARAM_MIB_7) + 1) * sizeof(char));
1573        strcpy(opt[8], RRD_PARAM_MIB_7);
1574        opt[9]= (char *) malloc((strlen(RRD_PARAM_MIB_8) + 1) * sizeof(char));
1575        strcpy(opt[9], RRD_PARAM_MIB_8);
1576        opt[10]= (char *) malloc((strlen(RRD_PARAM_MIB_9) + 1) * sizeof(char));
1577        strcpy(opt[10], RRD_PARAM_MIB_9);
1578        opt[11]= (char *) malloc((strlen(RRD_PARAM_MIB_10) + 1) * sizeof(char));
1579        strcpy(opt[11], RRD_PARAM_MIB_10);
1580        opt[12]= (char *) malloc((strlen(RRD_PARAM_MIB_11) + 1) * sizeof(char));
1581        strcpy(opt[12], RRD_PARAM_MIB_11);
1582        opt[13]= (char *) malloc((strlen(RRD_PARAM_MIB_12) + 1) * sizeof(char));
1583        strcpy(opt[13], RRD_PARAM_MIB_12);
1584        opt[14]= (char *) malloc((strlen(RRD_PARAM_MIB_13) + 1) * sizeof(char));
1585        strcpy(opt[14], RRD_PARAM_MIB_13);
1586        opt[15]= (char *) malloc((strlen(RRD_PARAM_MIB_14) + 1) * sizeof(char));
1587        strcpy(opt[15], RRD_PARAM_MIB_14);
1588        opt[16]= (char *) malloc((strlen(RRD_PARAM_MIB_15) + 1) * sizeof(char));
1589        strcpy(opt[16], RRD_PARAM_MIB_15);
1590        opt[17]= (char *) malloc((strlen(RRD_PARAM_MIB_16) + 1) * sizeof(char));
1591        strcpy(opt[17], RRD_PARAM_MIB_16);
1592        opt[18]= (char *) malloc((strlen(RRD_PARAM_MIB_17) + 1) * sizeof(char));
1593        strcpy(opt[18], RRD_PARAM_MIB_17);
1594        opt[19]= (char *) malloc((strlen(RRD_PARAM_MIB_18) + 1) * sizeof(char));
1595        strcpy(opt[19], RRD_PARAM_MIB_18);
1596        opt[20]= (char *) malloc((strlen(RRD_PARAM_MIB_19) + 1) * sizeof(char));
1597        strcpy(opt[20], RRD_PARAM_MIB_19);
1598        opt[21]= (char *) malloc((strlen(RRD_PARAM_MIB_20) + 1) * sizeof(char));
1599        strcpy(opt[21], RRD_PARAM_MIB_20);
1600        opt[22]= (char *) malloc((strlen(RRD_PARAM_MIB_21) + 1) * sizeof(char));
1601        strcpy(opt[22], RRD_PARAM_MIB_21);
1602        opt[23]= (char *) malloc((strlen(RRD_PARAM_MIB_22) + 1) * sizeof(char));
1603        strcpy(opt[23], RRD_PARAM_MIB_22);
1604        optind = opterr = 0;
1605        rrd_clear_error();
1606        if ( rrd_create(24,opt) < 0)
1607        {
1608            syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error());
1609            rrd_create_er_ct++;
1610        }
1611        else
1612        {
1613            rrd_create_ok_ct++;
1614        }
1615        for ( k=0; k<24; k++)
1616        {
1617            free(opt[k]);
1618            opt[k] = NULL;
1619        }
[115]1620    }
[157]1621    else
1622    {
1623        fclose(fp);
1624        rrd_already_created_ct++;
1625        snprintf(buf,
1626                 2048,
1627                 "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",
1628                 now-300,  /* or ctime(&now) with %s */
1629                 shmForAgg->myMIB[index].ipPacketNb,
1630                 shmForAgg->myMIB[index].udpPacketNb,
1631                 shmForAgg->myMIB[index].v9PacketNb,
1632                 shmForAgg->myMIB[index].v9UnSeqNb,
1633                 shmForAgg->myMIB[index].flowSetNb,
1634                 shmForAgg->myMIB[index].dataFlowSetNb,
1635                 shmForAgg->myMIB[index].defFlowSetNb,
1636                 shmForAgg->myMIB[index].optDataFlowSetNb,
1637                 shmForAgg->myMIB[index].optDefFlowSetNb,
1638                 shmForAgg->myMIB[index].flowNb,
1639                 shmForAgg->myMIB[index].realFlowNb
1640                );
1641        fprintf(stderr,"\n%s\n",buf);
1642        optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char));
1643        strcpy(optUpdate[0], RRD_UPDATE_0);
1644        optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
1645        strcpy(optUpdate[1], name);
1646        optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char));
1647        strcpy(optUpdate[2], buf);
1648        optind = opterr = 0;
1649        rrd_clear_error();
1650        if ( rrd_update(3, optUpdate) < 0 )
1651        {
1652            syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error());
1653            rrd_update_er_ct++;
1654        }
1655        else
1656        {
1657            rrd_update_ok_ct++;
1658        }
1659        for ( k=0; k<3; k++)
1660        {
1661            free(optUpdate[k]);
1662            optUpdate[k] = NULL;
1663        }
[115]1664    }
[157]1665    shmForAgg->myMIB[index].ipPacketNb = 0;
1666    shmForAgg->myMIB[index].udpPacketNb = 0;
1667    shmForAgg->myMIB[index].v9PacketNb = 0;
1668    shmForAgg->myMIB[index].v9UnSeqNb = 0;
1669    shmForAgg->myMIB[index].flowSetNb = 0;
1670    shmForAgg->myMIB[index].dataFlowSetNb = 0;
1671    shmForAgg->myMIB[index].defFlowSetNb = 0;
1672    shmForAgg->myMIB[index].optDataFlowSetNb = 0;
1673    shmForAgg->myMIB[index].optDefFlowSetNb = 0;
1674    shmForAgg->myMIB[index].flowNb = 0;
1675    shmForAgg->myMIB[index].realFlowNb = 0;
[162]1676    SMP1_shmForAgg->myMIB[index].ipPacketNb = 0;
1677    SMP1_shmForAgg->myMIB[index].udpPacketNb = 0;
1678    SMP1_shmForAgg->myMIB[index].v9PacketNb = 0;
1679    SMP1_shmForAgg->myMIB[index].v9UnSeqNb = 0;
1680    SMP1_shmForAgg->myMIB[index].flowSetNb = 0;
1681    SMP1_shmForAgg->myMIB[index].dataFlowSetNb = 0;
1682    SMP1_shmForAgg->myMIB[index].defFlowSetNb = 0;
1683    SMP1_shmForAgg->myMIB[index].optDataFlowSetNb = 0;
1684    SMP1_shmForAgg->myMIB[index].optDefFlowSetNb = 0;
1685    SMP1_shmForAgg->myMIB[index].flowNb = 0;
1686    SMP1_shmForAgg->myMIB[index].realFlowNb = 0;
1687    SMP2_shmForAgg->myMIB[index].ipPacketNb = 0;
1688    SMP2_shmForAgg->myMIB[index].udpPacketNb = 0;
1689    SMP2_shmForAgg->myMIB[index].v9PacketNb = 0;
1690    SMP2_shmForAgg->myMIB[index].v9UnSeqNb = 0;
1691    SMP2_shmForAgg->myMIB[index].flowSetNb = 0;
1692    SMP2_shmForAgg->myMIB[index].dataFlowSetNb = 0;
1693    SMP2_shmForAgg->myMIB[index].defFlowSetNb = 0;
1694    SMP2_shmForAgg->myMIB[index].optDataFlowSetNb = 0;
1695    SMP2_shmForAgg->myMIB[index].optDefFlowSetNb = 0;
1696    SMP2_shmForAgg->myMIB[index].flowNb = 0;
1697    SMP2_shmForAgg->myMIB[index].realFlowNb = 0;
1698    SMP3_shmForAgg->myMIB[index].ipPacketNb = 0;
1699    SMP3_shmForAgg->myMIB[index].udpPacketNb = 0;
1700    SMP3_shmForAgg->myMIB[index].v9PacketNb = 0;
1701    SMP3_shmForAgg->myMIB[index].v9UnSeqNb = 0;
1702    SMP3_shmForAgg->myMIB[index].flowSetNb = 0;
1703    SMP3_shmForAgg->myMIB[index].dataFlowSetNb = 0;
1704    SMP3_shmForAgg->myMIB[index].defFlowSetNb = 0;
1705    SMP3_shmForAgg->myMIB[index].optDataFlowSetNb = 0;
1706    SMP3_shmForAgg->myMIB[index].optDefFlowSetNb = 0;
1707    SMP3_shmForAgg->myMIB[index].flowNb = 0;
1708    SMP3_shmForAgg->myMIB[index].realFlowNb = 0;
1709    SMP4_shmForAgg->myMIB[index].ipPacketNb = 0;
1710    SMP4_shmForAgg->myMIB[index].udpPacketNb = 0;
1711    SMP4_shmForAgg->myMIB[index].v9PacketNb = 0;
1712    SMP4_shmForAgg->myMIB[index].v9UnSeqNb = 0;
1713    SMP4_shmForAgg->myMIB[index].flowSetNb = 0;
1714    SMP4_shmForAgg->myMIB[index].dataFlowSetNb = 0;
1715    SMP4_shmForAgg->myMIB[index].defFlowSetNb = 0;
1716    SMP4_shmForAgg->myMIB[index].optDataFlowSetNb = 0;
1717    SMP4_shmForAgg->myMIB[index].optDefFlowSetNb = 0;
1718    SMP4_shmForAgg->myMIB[index].flowNb = 0;
1719    SMP4_shmForAgg->myMIB[index].realFlowNb = 0;
[157]1720    return 1;
[115]1721}
[157]1722
1723/*
1724 * rrdL7IPv4MibsUpdate
1725 */
1726short rrdL7IPv4MibsUpdate(int index)
1727{
1728    int i, j, k = 0;
1729    int rrd_update_er_ct = 0;
1730    int rrd_update_ok_ct = 0;
1731    int rrd_already_created_ct = 0;
1732    int rrd_create_er_ct = 0;
1733    int rrd_create_ok_ct = 0;
1734    static char buf[2048];
1735    static char name[2048];
1736    static char createstr[2048];
1737    char *opt[27];
1738    char *optUpdate[3];
1739    FILE *fp;
1740    static time_t now, now2;
1741
[162]1742
1743    shmForAgg->myMIB[index].ipv4WebBytesNb = SMP1_shmForAgg->myMIB[index].ipv4WebBytesNb +
1744                                             SMP2_shmForAgg->myMIB[index].ipv4WebBytesNb +
1745                                             SMP3_shmForAgg->myMIB[index].ipv4WebBytesNb +
1746                                             SMP4_shmForAgg->myMIB[index].ipv4WebBytesNb;
1747    shmForAgg->myMIB[index].ipv4WebPcktsNb = SMP1_shmForAgg->myMIB[index].ipv4WebPcktsNb +
1748                                             SMP2_shmForAgg->myMIB[index].ipv4WebPcktsNb +
1749                                             SMP3_shmForAgg->myMIB[index].ipv4WebPcktsNb +
1750                                             SMP4_shmForAgg->myMIB[index].ipv4WebPcktsNb;
1751    shmForAgg->myMIB[index].ipv4WebFlowNb = SMP1_shmForAgg->myMIB[index].ipv4WebFlowNb +
1752                                            SMP2_shmForAgg->myMIB[index].ipv4WebFlowNb +
1753                                            SMP3_shmForAgg->myMIB[index].ipv4WebFlowNb +
1754                                            SMP4_shmForAgg->myMIB[index].ipv4WebFlowNb;
1755    shmForAgg->myMIB[index].ipv4MailBytesNb = SMP1_shmForAgg->myMIB[index].ipv4MailBytesNb +
1756                                              SMP2_shmForAgg->myMIB[index].ipv4MailBytesNb +
1757                                              SMP3_shmForAgg->myMIB[index].ipv4MailBytesNb +
1758                                              SMP4_shmForAgg->myMIB[index].ipv4MailBytesNb;
1759    shmForAgg->myMIB[index].ipv4MailPcktsNb = SMP1_shmForAgg->myMIB[index].ipv4MailPcktsNb +
1760                                              SMP2_shmForAgg->myMIB[index].ipv4MailPcktsNb +
1761                                              SMP3_shmForAgg->myMIB[index].ipv4MailPcktsNb +
1762                                              SMP4_shmForAgg->myMIB[index].ipv4MailPcktsNb;
1763    shmForAgg->myMIB[index].ipv4MailFlowNb = SMP1_shmForAgg->myMIB[index].ipv4MailFlowNb +
1764                                             SMP2_shmForAgg->myMIB[index].ipv4MailFlowNb +
1765                                             SMP3_shmForAgg->myMIB[index].ipv4MailFlowNb +
1766                                             SMP4_shmForAgg->myMIB[index].ipv4MailFlowNb;
1767    shmForAgg->myMIB[index].ipv4DNSBytesNb = SMP1_shmForAgg->myMIB[index].ipv4DNSBytesNb +
1768                                             SMP2_shmForAgg->myMIB[index].ipv4DNSBytesNb +
1769                                             SMP3_shmForAgg->myMIB[index].ipv4DNSBytesNb +
1770                                             SMP4_shmForAgg->myMIB[index].ipv4DNSBytesNb;
1771    shmForAgg->myMIB[index].ipv4DNSPcktsNb = SMP1_shmForAgg->myMIB[index].ipv4DNSPcktsNb +
1772                                             SMP2_shmForAgg->myMIB[index].ipv4DNSPcktsNb +
1773                                             SMP3_shmForAgg->myMIB[index].ipv4DNSPcktsNb +
1774                                             SMP4_shmForAgg->myMIB[index].ipv4DNSPcktsNb;
1775    shmForAgg->myMIB[index].ipv4DNSFlowNb = SMP1_shmForAgg->myMIB[index].ipv4DNSFlowNb +
1776                                            SMP2_shmForAgg->myMIB[index].ipv4DNSFlowNb +
1777                                            SMP3_shmForAgg->myMIB[index].ipv4DNSFlowNb +
1778                                            SMP4_shmForAgg->myMIB[index].ipv4DNSFlowNb;
1779    shmForAgg->myMIB[index].ipv4OthersApBytesNb = SMP1_shmForAgg->myMIB[index].ipv4OthersApBytesNb +
1780                                                  SMP2_shmForAgg->myMIB[index].ipv4OthersApBytesNb +
1781                                                  SMP3_shmForAgg->myMIB[index].ipv4OthersApBytesNb +
1782                                                  SMP4_shmForAgg->myMIB[index].ipv4OthersApBytesNb;
1783    shmForAgg->myMIB[index].ipv4OthersApPcktsNb = SMP1_shmForAgg->myMIB[index].ipv4OthersApPcktsNb +
1784                                                  SMP2_shmForAgg->myMIB[index].ipv4OthersApPcktsNb +
1785                                                  SMP3_shmForAgg->myMIB[index].ipv4OthersApPcktsNb +
1786                                                  SMP4_shmForAgg->myMIB[index].ipv4OthersApPcktsNb;
1787    shmForAgg->myMIB[index].ipv4OthersApFlowNb = SMP1_shmForAgg->myMIB[index].ipv4OthersApFlowNb +
1788                                                 SMP2_shmForAgg->myMIB[index].ipv4OthersApFlowNb +
1789                                                 SMP3_shmForAgg->myMIB[index].ipv4OthersApFlowNb +
1790                                                 SMP4_shmForAgg->myMIB[index].ipv4OthersApFlowNb;
1791
[157]1792    now = time((time_t *)NULL);
1793    for (k=0; k<strlen(name); k++)
1794    {
1795        name[k] = '\0';
1796    }
1797    for (k=0; k<strlen(buf); k++)
1798    {
1799        buf[k] = '\0';
1800    }
1801    strcat(name, MIB_RRD_LOCATION);
1802    strcat(name, L7_IPV4_MIB_RRD_FILE);
1803    if ( (fp=fopen(name,"r")) == NULL )
1804    {
1805        opt[0]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_0) + 1) * sizeof(char));
1806        strcpy(opt[0], RRD_PARAM_MIB_IPV4_AP_0);
1807        opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
1808        strcpy(opt[1], name);
1809        opt[2]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_1) + 1) * sizeof(char));
1810        strcpy(opt[2], RRD_PARAM_MIB_IPV4_AP_1);
1811        opt[3]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_2) + 1) * sizeof(char));
1812        strcpy(opt[3], RRD_PARAM_MIB_IPV4_AP_2);
1813        opt[4]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_3) + 1) * sizeof(char));
1814        strcpy(opt[4], RRD_PARAM_MIB_IPV4_AP_3);
1815        opt[5]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_4) + 1) * sizeof(char));
1816        strcpy(opt[5], RRD_PARAM_MIB_IPV4_AP_4);
1817        opt[6]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_5) + 1) * sizeof(char));
1818        strcpy(opt[6], RRD_PARAM_MIB_IPV4_AP_5);
1819        opt[7]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_6) + 1) * sizeof(char));
1820        strcpy(opt[7], RRD_PARAM_MIB_IPV4_AP_6);
1821        opt[8]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_7) + 1) * sizeof(char));
1822        strcpy(opt[8], RRD_PARAM_MIB_IPV4_AP_7);
1823        opt[9]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_8) + 1) * sizeof(char));
1824        strcpy(opt[9], RRD_PARAM_MIB_IPV4_AP_8);
1825        opt[10]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_9) + 1) * sizeof(char));
1826        strcpy(opt[10], RRD_PARAM_MIB_IPV4_AP_9);
1827        opt[11]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_10) + 1) * sizeof(char));
1828        strcpy(opt[11], RRD_PARAM_MIB_IPV4_AP_10);
1829        opt[12]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_11) + 1) * sizeof(char));
1830        strcpy(opt[12], RRD_PARAM_MIB_IPV4_AP_11);
1831        opt[13]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_12) + 1) * sizeof(char));
1832        strcpy(opt[13], RRD_PARAM_MIB_IPV4_AP_12);
1833        opt[14]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_13) + 1) * sizeof(char));
1834        strcpy(opt[14], RRD_PARAM_MIB_IPV4_AP_13);
1835        opt[15]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_14) + 1) * sizeof(char));
1836        strcpy(opt[15], RRD_PARAM_MIB_IPV4_AP_14);
1837        opt[16]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_15) + 1) * sizeof(char));
1838        strcpy(opt[16], RRD_PARAM_MIB_IPV4_AP_15);
1839        opt[17]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_16) + 1) * sizeof(char));
1840        strcpy(opt[17], RRD_PARAM_MIB_IPV4_AP_16);
1841        opt[18]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_17) + 1) * sizeof(char));
1842        strcpy(opt[18], RRD_PARAM_MIB_IPV4_AP_17);
1843        opt[19]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_18) + 1) * sizeof(char));
1844        strcpy(opt[19], RRD_PARAM_MIB_IPV4_AP_18);
1845        opt[20]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_19) + 1) * sizeof(char));
1846        strcpy(opt[20], RRD_PARAM_MIB_IPV4_AP_19);
1847        opt[21]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_20) + 1) * sizeof(char));
1848        strcpy(opt[21], RRD_PARAM_MIB_IPV4_AP_20);
1849        opt[22]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_21) + 1) * sizeof(char));
1850        strcpy(opt[22], RRD_PARAM_MIB_IPV4_AP_21);
1851        opt[23]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_22) + 1) * sizeof(char));
1852        strcpy(opt[23], RRD_PARAM_MIB_IPV4_AP_22);
1853        opt[24]= (char *) malloc((strlen(RRD_PARAM_MIB_IPV4_AP_23) + 1) * sizeof(char));
1854        strcpy(opt[24], RRD_PARAM_MIB_IPV4_AP_23);
1855        optind = opterr = 0;
1856        rrd_clear_error();
1857        if ( rrd_create(25,opt) < 0)
1858        {
1859            syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error());
1860            rrd_create_er_ct++;
1861        }
1862        else
1863        {
1864            rrd_create_ok_ct++;
1865        }
1866        for ( k=0; k<25; k++)
1867        {
1868            free(opt[k]);
1869            opt[k] = NULL;
1870        }
1871    }
1872    else
1873    {
1874        fclose(fp);
1875        rrd_already_created_ct++;
1876        snprintf(buf,
1877                 2048,
1878                 "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu",
1879                 now-300,  /* or ctime(&now) with %s */
1880                 shmForAgg->myMIB[index].ipv4WebBytesNb,
1881                 shmForAgg->myMIB[index].ipv4WebPcktsNb,
1882                 shmForAgg->myMIB[index].ipv4WebFlowNb,
1883                 shmForAgg->myMIB[index].ipv4MailBytesNb,
1884                 shmForAgg->myMIB[index].ipv4MailPcktsNb,
1885                 shmForAgg->myMIB[index].ipv4MailFlowNb,
1886                 shmForAgg->myMIB[index].ipv4DNSBytesNb,
1887                 shmForAgg->myMIB[index].ipv4DNSPcktsNb,
1888                 shmForAgg->myMIB[index].ipv4DNSFlowNb,
1889                 shmForAgg->myMIB[index].ipv4OthersApBytesNb,
1890                 shmForAgg->myMIB[index].ipv4OthersApPcktsNb,
1891                 shmForAgg->myMIB[index].ipv4OthersApFlowNb
1892                );
1893        fprintf(stderr,"\n%s\n",buf);
1894        optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char));
1895        strcpy(optUpdate[0], RRD_UPDATE_0);
1896        optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char));
1897        strcpy(optUpdate[1], name);
1898        optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char));
1899        strcpy(optUpdate[2], buf);
1900        optind = opterr = 0;
1901        rrd_clear_error();
1902        if ( rrd_update(3, optUpdate) < 0 )
1903        {
1904            syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error());
1905            rrd_update_er_ct++;
1906        }
1907        else
1908        {
1909            rrd_update_ok_ct++;
1910        }
1911        for ( k=0; k<3; k++)
1912        {
1913            free(optUpdate[k]);
1914            optUpdate[k] = NULL;
1915        }
1916    }
1917    shmForAgg->myMIB[index].ipv4WebBytesNb = 0;
1918    shmForAgg->myMIB[index].ipv4WebPcktsNb = 0;
1919    shmForAgg->myMIB[index].ipv4WebFlowNb = 0;
1920    shmForAgg->myMIB[index].ipv4MailBytesNb = 0;
1921    shmForAgg->myMIB[index].ipv4MailPcktsNb = 0;
1922    shmForAgg->myMIB[index].ipv4MailFlowNb = 0;
1923    shmForAgg->myMIB[index].ipv4DNSBytesNb = 0;
1924    shmForAgg->myMIB[index].ipv4DNSPcktsNb = 0;
1925    shmForAgg->myMIB[index].ipv4DNSFlowNb = 0;
1926    shmForAgg->myMIB[index].ipv4OthersApBytesNb = 0;
1927    shmForAgg->myMIB[index].ipv4OthersApPcktsNb = 0;
1928    shmForAgg->myMIB[index].ipv4OthersApFlowNb = 0;
[162]1929    SMP1_shmForAgg->myMIB[index].ipv4WebBytesNb = 0;
1930    SMP1_shmForAgg->myMIB[index].ipv4WebPcktsNb = 0;
1931    SMP1_shmForAgg->myMIB[index].ipv4WebFlowNb = 0;
1932    SMP1_shmForAgg->myMIB[index].ipv4MailBytesNb = 0;
1933    SMP1_shmForAgg->myMIB[index].ipv4MailPcktsNb = 0;
1934    SMP1_shmForAgg->myMIB[index].ipv4MailFlowNb = 0;
1935    SMP1_shmForAgg->myMIB[index].ipv4DNSBytesNb = 0;
1936    SMP1_shmForAgg->myMIB[index].ipv4DNSPcktsNb = 0;
1937    SMP1_shmForAgg->myMIB[index].ipv4DNSFlowNb = 0;
1938    SMP1_shmForAgg->myMIB[index].ipv4OthersApBytesNb = 0;
1939    SMP1_shmForAgg->myMIB[index].ipv4OthersApPcktsNb = 0;
1940    SMP1_shmForAgg->myMIB[index].ipv4OthersApFlowNb = 0;
1941    SMP2_shmForAgg->myMIB[index].ipv4WebBytesNb = 0;
1942    SMP2_shmForAgg->myMIB[index].ipv4WebPcktsNb = 0;
1943    SMP2_shmForAgg->myMIB[index].ipv4WebFlowNb = 0;
1944    SMP2_shmForAgg->myMIB[index].ipv4MailBytesNb = 0;
1945    SMP2_shmForAgg->myMIB[index].ipv4MailPcktsNb = 0;
1946    SMP2_shmForAgg->myMIB[index].ipv4MailFlowNb = 0;
1947    SMP2_shmForAgg->myMIB[index].ipv4DNSBytesNb = 0;
1948    SMP2_shmForAgg->myMIB[index].ipv4DNSPcktsNb = 0;
1949    SMP2_shmForAgg->myMIB[index].ipv4DNSFlowNb = 0;
1950    SMP2_shmForAgg->myMIB[index].ipv4OthersApBytesNb = 0;
1951    SMP2_shmForAgg->myMIB[index].ipv4OthersApPcktsNb = 0;
1952    SMP2_shmForAgg->myMIB[index].ipv4OthersApFlowNb = 0;
1953    SMP3_shmForAgg->myMIB[index].ipv4WebBytesNb = 0;
1954    SMP3_shmForAgg->myMIB[index].ipv4WebPcktsNb = 0;
1955    SMP3_shmForAgg->myMIB[index].ipv4WebFlowNb = 0;
1956    SMP3_shmForAgg->myMIB[index].ipv4MailBytesNb = 0;
1957    SMP3_shmForAgg->myMIB[index].ipv4MailPcktsNb = 0;
1958    SMP3_shmForAgg->myMIB[index].ipv4MailFlowNb = 0;
1959    SMP3_shmForAgg->myMIB[index].ipv4DNSBytesNb = 0;
1960    SMP3_shmForAgg->myMIB[index].ipv4DNSPcktsNb = 0;
1961    SMP3_shmForAgg->myMIB[index].ipv4DNSFlowNb = 0;
1962    SMP3_shmForAgg->myMIB[index].ipv4OthersApBytesNb = 0;
1963    SMP3_shmForAgg->myMIB[index].ipv4OthersApPcktsNb = 0;
1964    SMP3_shmForAgg->myMIB[index].ipv4OthersApFlowNb = 0;
1965    SMP4_shmForAgg->myMIB[index].ipv4WebBytesNb = 0;
1966    SMP4_shmForAgg->myMIB[index].ipv4WebPcktsNb = 0;
1967    SMP4_shmForAgg->myMIB[index].ipv4WebFlowNb = 0;
1968    SMP4_shmForAgg->myMIB[index].ipv4MailBytesNb = 0;
1969    SMP4_shmForAgg->myMIB[index].ipv4MailPcktsNb = 0;
1970    SMP4_shmForAgg->myMIB[index].ipv4MailFlowNb = 0;
1971    SMP4_shmForAgg->myMIB[index].ipv4DNSBytesNb = 0;
1972    SMP4_shmForAgg->myMIB[index].ipv4DNSPcktsNb = 0;
1973    SMP4_shmForAgg->myMIB[index].ipv4DNSFlowNb = 0;
1974    SMP4_shmForAgg->myMIB[index].ipv4OthersApBytesNb = 0;
1975    SMP4_shmForAgg->myMIB[index].ipv4OthersApPcktsNb = 0;
1976    SMP4_shmForAgg->myMIB[index].ipv4OthersApFlowNb = 0;
[157]1977    return 1;
1978}
Note: See TracBrowser for help on using the browser.