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