[2] | 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) |
---|
| 37 | { |
---|
| 38 | TplFlowSetPtr tmp; |
---|
| 39 | FieldPtr pftmp; |
---|
| 40 | FieldPtr secondPftmp; |
---|
| 41 | unsigned short data_length = 0; |
---|
| 42 | unsigned short flow_size = 0; |
---|
| 43 | unsigned short oldOffset = *offV9; |
---|
| 44 | unsigned short secondOffset = 0; |
---|
| 45 | unsigned short secondOldOffset = 0; |
---|
[14] | 46 | int moreIsNecessary = 1; |
---|
[2] | 47 | int field_size = 0; |
---|
| 48 | int cpt = 0; |
---|
| 49 | int secondCpt = 0; |
---|
| 50 | int overflow = 0; |
---|
| 51 | int noEnd = 1; |
---|
| 52 | int i=0; |
---|
| 53 | int j=0; |
---|
| 54 | int pos = 0; |
---|
| 55 | unsigned char buffer1; |
---|
| 56 | unsigned char buffer2[2]; |
---|
| 57 | unsigned char buffer4[4]; |
---|
| 58 | RulesPtr tmpRuleList = rlPtr; |
---|
| 59 | msgType myMsg; |
---|
| 60 | char *msgTextIndex; |
---|
| 61 | unsigned short tplMsgType = 11; |
---|
| 62 | |
---|
| 63 | buffer2[1] = *(buf+(*offV9));(*offV9)++; |
---|
| 64 | buffer2[0] = *(buf+(*offV9));(*offV9)++; |
---|
| 65 | (*cFId) = *((unsigned short*)&buffer2); |
---|
| 66 | buffer2[1] = *(buf+(*offV9));(*offV9)++; |
---|
| 67 | buffer2[0] = *(buf+(*offV9));(*offV9)++; |
---|
| 68 | data_length = *((unsigned short*)&buffer2); |
---|
| 69 | if ((tmp=existTplId(cr, v9Ptr->sourceId, |
---|
| 70 | (*cFId)))!=NULL) { |
---|
| 71 | pftmp = tmp->lastField; |
---|
| 72 | for (; pftmp; pftmp = pftmp->prev) { |
---|
| 73 | flow_size += pftmp->fieldLength; |
---|
| 74 | } |
---|
| 75 | if ( data_length%flow_size >= 9 ) { |
---|
| 76 | (*cFNPtr) = v9Ptr->count; |
---|
| 77 | 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", |
---|
| 78 | (*cFId), |
---|
| 79 | (pcktPtr->ipH->srcAdd>>24), |
---|
| 80 | (pcktPtr->ipH->srcAdd<<8>>24), |
---|
| 81 | (pcktPtr->ipH->srcAdd<<16>>24), |
---|
| 82 | (pcktPtr->ipH->srcAdd<<24>>24)); |
---|
| 83 | return (data_length+shift); |
---|
| 84 | } |
---|
| 85 | pftmp = tmp->lastField; |
---|
| 86 | secondPftmp = tmp->lastField; |
---|
| 87 | secondOffset = *offV9; |
---|
| 88 | secondOldOffset = secondOffset; |
---|
| 89 | while ( (((*offV9)-48-shift) <= data_length) && (overflow!=1) ) { |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | cpt++; |
---|
| 97 | j=0; |
---|
| 98 | pos = (pftmp->fieldType)*10+j; |
---|
| 99 | field_size = (int) pftmp->fieldLength; |
---|
| 100 | |
---|
| 101 | |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | if (((RuleDefPtr)(*(rulesCache+pos))) != NULL) { |
---|
| 105 | oldOffset = *offV9; |
---|
| 106 | while (((RuleDefPtr)(*(rulesCache+pos))) != NULL){ |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | *offV9 = oldOffset; |
---|
| 111 | switch ((int) |
---|
| 112 | (((RuleDefPtr)(*(rulesCache+pos)))->operator)){ |
---|
| 113 | case 2: |
---|
| 114 | switch (field_size) { |
---|
| 115 | case 1: |
---|
| 116 | buffer1 = *(buf+(*offV9)); (*offV9)++; |
---|
| 117 | if (((RuleDefPtr)(*(rulesCache+pos)))->value->stor.cvalue |
---|
| 118 | == *((unsigned char*)&buffer1)) { |
---|
| 119 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 1; |
---|
| 120 | } |
---|
| 121 | break; |
---|
| 122 | case 2: |
---|
| 123 | buffer2[1]= *(buf+(*offV9)); (*offV9)++; |
---|
| 124 | buffer2[0]= *(buf+(*offV9)); (*offV9)++; |
---|
| 125 | if (((RuleDefPtr)(*(rulesCache+pos)))->value->stor.svalue |
---|
| 126 | == *((unsigned short*)&buffer2)) |
---|
| 127 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 1; |
---|
| 128 | break; |
---|
| 129 | case 4: |
---|
| 130 | buffer4[3]= *(buf+(*offV9)); (*offV9)++; |
---|
| 131 | buffer4[2]= *(buf+(*offV9)); (*offV9)++; |
---|
| 132 | buffer4[1]= *(buf+(*offV9)); (*offV9)++; |
---|
| 133 | buffer4[0]= *(buf+(*offV9)); (*offV9)++; |
---|
[11] | 134 | |
---|
[2] | 135 | if ((((RuleDefPtr)(*(rulesCache+pos)))->value->stor.lvalue) |
---|
[11] | 136 | == (*((unsigned long*)&buffer4))>>(32-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)<<(32-((RuleDefPtr)(*(rulesCache+pos)))->value->mask) ) |
---|
[2] | 137 | { |
---|
| 138 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 1; |
---|
| 139 | } |
---|
| 140 | break; |
---|
| 141 | case 16: |
---|
| 142 | for (i=0; i<4; i++) { |
---|
| 143 | buffer4[3]= *(buf+(*offV9)); (*offV9)++; |
---|
| 144 | buffer4[2]= *(buf+(*offV9)); (*offV9)++; |
---|
| 145 | buffer4[1]= *(buf+(*offV9)); (*offV9)++; |
---|
| 146 | buffer4[0]= *(buf+(*offV9)); (*offV9)++; |
---|
[14] | 147 | |
---|
| 148 | if (1==moreIsNecessary){ |
---|
| 149 | switch(i){ |
---|
| 150 | case 0: |
---|
| 151 | |
---|
| 152 | |
---|
| 153 | |
---|
| 154 | |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | if (((RuleDefPtr)(*(rulesCache+pos)))->value->mask <= 32){ |
---|
| 159 | if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i]) |
---|
| 160 | == |
---|
| 161 | (*((unsigned long*)&buffer4))>>(32-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)<<(32-((RuleDefPtr)(*(rulesCache+pos)))->value->mask) |
---|
| 162 | ) |
---|
| 163 | { |
---|
| 164 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 1; |
---|
| 165 | moreIsNecessary = 0; |
---|
| 166 | } else { |
---|
| 167 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 0; |
---|
| 168 | moreIsNecessary = 0; |
---|
| 169 | } |
---|
[2] | 170 | } else { |
---|
[14] | 171 | if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i]) |
---|
| 172 | == |
---|
| 173 | (*((unsigned long*)&buffer4)) |
---|
| 174 | ) |
---|
| 175 | { |
---|
| 176 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 1; |
---|
| 177 | } else { |
---|
| 178 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 0; |
---|
| 179 | moreIsNecessary = 0; |
---|
| 180 | } |
---|
[2] | 181 | } |
---|
[14] | 182 | break; |
---|
| 183 | case 1: |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | if (((RuleDefPtr)(*(rulesCache+pos)))->value->mask <= 64){ |
---|
| 190 | if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i]) |
---|
| 191 | == |
---|
| 192 | (*((unsigned long*)&buffer4))>>(64-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)<<(64-((RuleDefPtr)(*(rulesCache+pos)))->value->mask) |
---|
| 193 | ) |
---|
| 194 | { |
---|
| 195 | ((RuleDefPtr)(*(rulesCache+pos)))->check = |
---|
| 196 | ((RuleDefPtr)(*(rulesCache+pos)))->check && 1; |
---|
| 197 | moreIsNecessary = 0; |
---|
| 198 | } else { |
---|
| 199 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 0; |
---|
| 200 | moreIsNecessary = 0; |
---|
| 201 | } |
---|
| 202 | } else { |
---|
| 203 | if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i]) |
---|
| 204 | == |
---|
| 205 | (*((unsigned long*)&buffer4)) |
---|
| 206 | ) |
---|
| 207 | { |
---|
| 208 | ((RuleDefPtr)(*(rulesCache+pos)))->check = |
---|
| 209 | ((RuleDefPtr)(*(rulesCache+pos)))->check && 1; |
---|
| 210 | } else { |
---|
| 211 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 0; |
---|
| 212 | moreIsNecessary = 0; |
---|
| 213 | } |
---|
| 214 | } |
---|
| 215 | break; |
---|
| 216 | case 2: |
---|
| 217 | if (((RuleDefPtr)(*(rulesCache+pos)))->value->mask <= 96){ |
---|
| 218 | if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i]) |
---|
| 219 | == |
---|
| 220 | (*((unsigned long*)&buffer4))>>(96-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)<<(96-((RuleDefPtr)(*(rulesCache+pos)))->value->mask) |
---|
| 221 | ) |
---|
| 222 | { |
---|
| 223 | ((RuleDefPtr)(*(rulesCache+pos)))->check = |
---|
| 224 | ((RuleDefPtr)(*(rulesCache+pos)))->check && 1; |
---|
| 225 | moreIsNecessary = 0; |
---|
| 226 | } else { |
---|
| 227 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 0; |
---|
| 228 | moreIsNecessary = 0; |
---|
| 229 | } |
---|
| 230 | } else { |
---|
| 231 | if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i]) |
---|
| 232 | == |
---|
| 233 | (*((unsigned long*)&buffer4)) |
---|
| 234 | ) |
---|
| 235 | { |
---|
| 236 | ((RuleDefPtr)(*(rulesCache+pos)))->check = |
---|
| 237 | ((RuleDefPtr)(*(rulesCache+pos)))->check && 1; |
---|
| 238 | } else { |
---|
| 239 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 0; |
---|
| 240 | moreIsNecessary = 0; |
---|
| 241 | } |
---|
| 242 | } |
---|
| 243 | break; |
---|
| 244 | case 3: |
---|
| 245 | if (((RuleDefPtr)(*(rulesCache+pos)))->value->mask <= 128){ |
---|
| 246 | if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i]) |
---|
| 247 | == |
---|
| 248 | (*((unsigned long*)&buffer4))>>(128-((RuleDefPtr)(*(rulesCache+pos)))->value->mask)<<(128-((RuleDefPtr)(*(rulesCache+pos)))->value->mask) |
---|
| 249 | ) |
---|
| 250 | { |
---|
| 251 | ((RuleDefPtr)(*(rulesCache+pos)))->check = |
---|
| 252 | ((RuleDefPtr)(*(rulesCache+pos)))->check && 1; |
---|
| 253 | } else { |
---|
| 254 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 0; |
---|
| 255 | moreIsNecessary = 0; |
---|
| 256 | } |
---|
| 257 | } else { |
---|
| 258 | if (ntohl(((RuleDefPtr)(*(rulesCache+pos)))->value->stor.tabAdd6[i]) |
---|
| 259 | == |
---|
| 260 | (*((unsigned long*)&buffer4)) |
---|
| 261 | ) |
---|
| 262 | { |
---|
| 263 | ((RuleDefPtr)(*(rulesCache+pos)))->check = |
---|
| 264 | ((RuleDefPtr)(*(rulesCache+pos)))->check && 1; |
---|
| 265 | } else { |
---|
| 266 | ((RuleDefPtr)(*(rulesCache+pos)))->check = 0; |
---|
| 267 | moreIsNecessary = 0; |
---|
| 268 | } |
---|
| 269 | } |
---|
| 270 | break; |
---|
| 271 | default: |
---|
| 272 | break; |
---|
| 273 | } |
---|
| 274 | } |
---|
[2] | 275 | } |
---|
[14] | 276 | |
---|
| 277 | |
---|
| 278 | moreIsNecessary = 1; |
---|
[2] | 279 | break; |
---|
| 280 | default: |
---|
| 281 | syslog(LOG_INFO, "Field size not known: %d\n", field_size); |
---|
| 282 | for (i=0; i<field_size; i++){ |
---|
| 283 | (*offV9)++; |
---|
| 284 | } |
---|
| 285 | break; |
---|
| 286 | } |
---|
| 287 | break; |
---|
| 288 | default: |
---|
| 289 | syslog(LOG_INFO, "Operator not known: %d\n", |
---|
| 290 | (int)(((RuleDefPtr)(*(rulesCache+pos)))->operator)); |
---|
| 291 | break; |
---|
| 292 | } |
---|
| 293 | j++; |
---|
| 294 | pos = (pftmp->fieldType)*10+j; |
---|
| 295 | } |
---|
| 296 | } else { |
---|
| 297 | |
---|
| 298 | |
---|
| 299 | |
---|
| 300 | switch (field_size) { |
---|
| 301 | case 1: |
---|
| 302 | buffer1 = *(buf+(*offV9)); (*offV9)++; |
---|
| 303 | break; |
---|
| 304 | case 2: |
---|
| 305 | buffer2[1]= *(buf+(*offV9)); (*offV9)++; |
---|
| 306 | buffer2[0]= *(buf+(*offV9)); (*offV9)++; |
---|
| 307 | break; |
---|
| 308 | case 4: |
---|
| 309 | buffer4[3]= *(buf+(*offV9)); (*offV9)++; |
---|
| 310 | buffer4[2]= *(buf+(*offV9)); (*offV9)++; |
---|
| 311 | buffer4[1]= *(buf+(*offV9)); (*offV9)++; |
---|
| 312 | buffer4[0]= *(buf+(*offV9)); (*offV9)++; |
---|
| 313 | break; |
---|
| 314 | case 16: |
---|
| 315 | for (i=0; i<4; i++) { |
---|
| 316 | buffer2[1]= *(buf+(*offV9)); (*offV9)++; |
---|
| 317 | buffer2[0]= *(buf+(*offV9)); (*offV9)++; |
---|
| 318 | buffer2[1]= *(buf+(*offV9)); (*offV9)++; |
---|
| 319 | buffer2[0]= *(buf+(*offV9)); (*offV9)++; |
---|
| 320 | } |
---|
| 321 | break; |
---|
| 322 | default: |
---|
| 323 | syslog(LOG_INFO,"UNKNOWN FIELDS LENGTH: %d ", field_size); |
---|
| 324 | for (i=0; i<field_size; i++){ |
---|
| 325 | (*offV9)++; |
---|
| 326 | } |
---|
| 327 | } |
---|
| 328 | } |
---|
| 329 | if (cpt==tmp->fieldCount) { |
---|
| 330 | |
---|
| 331 | |
---|
| 332 | |
---|
| 333 | |
---|
| 334 | |
---|
| 335 | |
---|
| 336 | |
---|
| 337 | |
---|
| 338 | tmpRuleList = rlPtr; |
---|
| 339 | while (tmpRuleList){ |
---|
| 340 | unsigned short check = 1; |
---|
| 341 | RuleDefPtr tmpRuleDefList = tmpRuleList->def; |
---|
| 342 | secondOffset = secondOldOffset; |
---|
| 343 | while (tmpRuleDefList){ |
---|
| 344 | check = check && tmpRuleDefList->check; |
---|
| 345 | tmpRuleDefList->check = 0; |
---|
| 346 | tmpRuleDefList = tmpRuleDefList->next; |
---|
| 347 | } |
---|
| 348 | if ( (tmpRuleList->def != NULL) && (check == 1)) { |
---|
| 349 | |
---|
| 350 | secondPftmp = tmp->lastField; |
---|
| 351 | |
---|
| 352 | msgTextIndex = mempcpy(mempcpy(mempcpy(myMsg.text, |
---|
| 353 | &tplMsgType, |
---|
| 354 | sizeof(unsigned short) |
---|
| 355 | ), |
---|
| 356 | &tmpRuleList->id, |
---|
| 357 | sizeof(tmpRuleList->id) |
---|
| 358 | ), |
---|
| 359 | &cr->IpAddress, |
---|
| 360 | sizeof(unsigned long) |
---|
| 361 | ); |
---|
| 362 | msgTextIndex = mempcpy(mempcpy(mempcpy(msgTextIndex, |
---|
| 363 | &tmp->sourceId, |
---|
| 364 | sizeof(unsigned long) |
---|
| 365 | ), |
---|
| 366 | &tmp->templateFlowSetId, |
---|
| 367 | sizeof(tmp->templateFlowSetId) |
---|
| 368 | ), |
---|
| 369 | buf+secondOffset, |
---|
| 370 | flow_size |
---|
| 371 | ); |
---|
| 372 | myMsg.type = 1; |
---|
| 373 | msgSend( myQueue, myMsg); |
---|
| 374 | noEnd = 1; |
---|
| 375 | secondCpt=0; |
---|
| 376 | } |
---|
| 377 | tmpRuleList = tmpRuleList->next; |
---|
| 378 | secondPftmp = tmp->lastField; |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | |
---|
| 382 | |
---|
| 383 | secondOffset = *offV9; |
---|
| 384 | secondOldOffset = secondOffset; |
---|
| 385 | pftmp = tmp->lastField; |
---|
| 386 | cpt=0; |
---|
| 387 | (*cFNPtr)++; |
---|
| 388 | if (((*offV9)-48-shift+flow_size) > data_length){ |
---|
| 389 | overflow = 1; |
---|
| 390 | } |
---|
| 391 | } else { |
---|
| 392 | |
---|
| 393 | pftmp = pftmp->prev; |
---|
| 394 | } |
---|
| 395 | } |
---|
| 396 | }else{ |
---|
| 397 | |
---|
| 398 | |
---|
| 399 | |
---|
| 400 | (*offV9)+=(data_length-4); |
---|
| 401 | (*cFNPtr) = v9Ptr->count; |
---|
| 402 | } |
---|
| 403 | while ( ((*offV9)-48-shift) < data_length ) { |
---|
| 404 | (*offV9)++; |
---|
| 405 | } |
---|
| 406 | while ( (*offV9)-48-shift > data_length ) { |
---|
| 407 | (*offV9)--; |
---|
| 408 | } |
---|
| 409 | return (data_length+shift); |
---|
| 410 | } |
---|
| 411 | |
---|
| 412 | |
---|
| 413 | |
---|
| 414 | |
---|
| 415 | |
---|
| 416 | |
---|
| 417 | |
---|
| 418 | |
---|
| 419 | |
---|
| 420 | |
---|
| 421 | |
---|
| 422 | |
---|
| 423 | |
---|
| 424 | |
---|
| 425 | |
---|
| 426 | |
---|