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