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