- Timestamp:
- 02/06/09 16:58:57 (14 years ago)
- Location:
- trunk/src
- Files:
-
- 9 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/dataFlowSet.c
r93 r94 4 4 * Authors: ANDREU Francois-Xavier 5 5 * 6 * Copyright (C) 2005 2006 2007GIP RENATER6 * Copyright (C) 2005 - 2009 GIP RENATER 7 7 */ 8 8 … … 494 494 } 495 495 j++; 496 pos = (pftmp->fieldType)* 10+j;496 pos = (pftmp->fieldType)*MAX_RULES_PER_FIELD+j; 497 497 } /* end while myPtrs->rulesAddressPtr */ 498 498 } else { -
trunk/src/get_conf.c
r86 r94 27 27 #include <string.h> 28 28 #include <stdlib.h> 29 #include <arpa/inet.h> 29 30 30 31 #include "get_conf.h" … … 488 489 } 489 490 491 /* 492 * prefixV6Cmp 493 */ 494 int 495 prefixV6Cmp(const void *elem1, const void *elem2){ 496 struct PrefixV6 *el1 = (struct PrefixV6 *) elem1; 497 struct PrefixV6 *el2 = (struct PrefixV6 *) elem2; 498 499 if (ntohl(el1->start[0]) < ntohl(el2->start[0])) { 500 return (-1); 501 } else if (ntohl(el1->start[0]) > ntohl(el2->start[0])) { 502 return (1); 503 } else { 504 if (ntohl(el1->start[1]) < ntohl(el2->start[1])) { 505 return (-1); 506 } else if (ntohl(el1->start[1]) > ntohl(el2->start[1])) { 507 return (1); 508 } else { 509 if (ntohl(el1->start[2]) < ntohl(el2->start[2])) { 510 return (-1); 511 } else if (ntohl(el1->start[2]) > ntohl(el2->start[2])) { 512 return (1); 513 } else { 514 if (ntohl(el1->start[3]) < ntohl(el2->start[3])) { 515 return (-1); 516 } else if (ntohl(el1->start[3]) > ntohl(el2->start[3])) { 517 return (1); 518 } else { 519 if (ntohl(el1->start[4]) < ntohl(el2->start[4])) { 520 return (-1); 521 } else if (ntohl(el1->start[4]) > ntohl(el2->start[4])) { 522 return (1); 523 } else { 524 if (ntohl(el1->start[5]) < ntohl(el2->start[5])) { 525 return (-1); 526 } else if (ntohl(el1->start[5]) > ntohl(el2->start[5])) { 527 return (1); 528 } else { 529 if (ntohl(el1->start[6]) < ntohl(el2->start[6])) { 530 return (-1); 531 } else if (ntohl(el1->start[6]) > ntohl(el2->start[6])) { 532 return (1); 533 } else { 534 if (ntohl(el1->start[7]) < ntohl(el2->start[7])) { 535 return (-1); 536 } else if (ntohl(el1->start[7]) > ntohl(el2->start[7])) { 537 return (1); 538 } else { 539 return 0; 540 } /* 7 */ 541 } /* 6 */ 542 } /* 5 */ 543 } /* 4 */ 544 } /* 3 */ 545 } /* 2 */ 546 } /* 1 */ 547 } /* 0 */ 548 } 549 550 /* 551 * getPrefixV6() 552 * 553 * read IPv6 prefix file and sort the list 554 */ 555 unsigned short getPrefixV6(char *filename, 556 struct PrefixV6 *pV6TabPtr) 557 { 558 FILE *prefixFile; 559 char line[200]; 560 unsigned short counter = 0; 561 char s0[40]; 562 unsigned short n0; 563 #if defined(MULTISAMPLING) 564 unsigned short n1; 565 #endif 566 struct in6_addr in6addr; 567 struct in6_addr in6addr16; 568 int i = 0; 569 char prefixStrTab[MAX_IPV6_PREFIX][50]; 570 unsigned short prefixIndex = 0; 571 int res = 0; 572 573 if (!(prefixFile = fopen(filename, "r"))) { 574 fprintf (stderr, "error during file \"%s\" opening\n", filename); 575 exit(1); 576 } 577 578 for(i=0;i<MAX_IPV6_PREFIX;i++){ 579 pV6TabPtr[i].start[0] = 0; 580 pV6TabPtr[i].start[1] = 0; 581 pV6TabPtr[i].start[2] = 0; 582 pV6TabPtr[i].start[3] = 0; 583 pV6TabPtr[i].end[0] = 0; 584 pV6TabPtr[i].end[1] = 0; 585 pV6TabPtr[i].end[2] = 0; 586 pV6TabPtr[i].end[3] = 0; 587 pV6TabPtr[i].mask = 0; 588 pV6TabPtr[i].hasSubnet = 0; 589 pV6TabPtr[i].sampling = 0; 590 pV6TabPtr[i].flowNbIN = 0; 591 pV6TabPtr[i].bytesNbIN = 0; 592 pV6TabPtr[i].pktsNbIN = 0; 593 pV6TabPtr[i].flowNbOUT = 0; 594 pV6TabPtr[i].bytesNbOUT = 0; 595 pV6TabPtr[i].pktsNbOUT = 0; 596 pV6TabPtr[i].firstCoSIN = 0; 597 pV6TabPtr[i].secondCoSIN = 0; 598 pV6TabPtr[i].thirdCoSIN = 0; 599 pV6TabPtr[i].fourthCoSIN = 0; 600 pV6TabPtr[i].firstCoSOUT = 0; 601 pV6TabPtr[i].secondCoSOUT = 0; 602 pV6TabPtr[i].thirdCoSOUT = 0; 603 pV6TabPtr[i].fourthCoSOUT = 0; 604 } 605 606 while (fgets(line, 50, prefixFile) != 0) 607 { 608 strcpy(prefixStrTab[counter], line); 609 counter++; 610 if (counter == MAX_IPV6_PREFIX) { 611 fprintf(stderr, "bufferoverflow in getPrefixV6 function (get_conf.c)\ 612 change the value of MAX_IPV6_PREFIX declaration and make again a compilation \n"); 613 exit(1); 614 } 615 } 616 #ifdef DEBUG 617 for(i=0;i<counter;i++) { 618 fprintf(stderr,"i : %hu - line : %s\n", i,prefixStrTab[i]); 619 } 620 #endif 621 for(i=0;i<counter;i++) 622 { 623 #if defined(IPV4AGGIDSNMP) 624 #if defined(MULTISAMPLING) 625 sscanf(prefixStrTab[i],"%s %hu %hu\n", 626 s0,&n0,&n1); 627 #else 628 sscanf(prefixStrTab[i],"%s %hu\n", 629 s0,&n0); 630 #endif 631 #endif 632 res = inet_pton(AF_INET6, 633 s0, 634 &in6addr16); 635 res = inet_pton(AF_INET6, 636 s0, 637 &in6addr); 638 if (res != 1){ 639 fprintf(stderr,"BAD Prefix %s \n",s0); 640 } else { 641 pV6TabPtr[prefixIndex].start[0] = in6addr.s6_addr32[0]; 642 pV6TabPtr[prefixIndex].start[1] = in6addr.s6_addr32[1]; 643 pV6TabPtr[prefixIndex].start[2] = in6addr.s6_addr32[2]; 644 pV6TabPtr[prefixIndex].start[3] = in6addr.s6_addr32[3]; 645 if ((unsigned short)n0 <= 16) { 646 in6addr16.s6_addr16[0] = htons( ntohs(in6addr16.s6_addr16[0]) |~((~0)<<(16-(n0)))); 647 in6addr16.s6_addr16[1] = (~0); 648 in6addr16.s6_addr16[2] = (~0); 649 in6addr16.s6_addr16[3] = (~0); 650 in6addr16.s6_addr16[4] = (~0); 651 in6addr16.s6_addr16[5] = (~0); 652 in6addr16.s6_addr16[6] = (~0); 653 in6addr16.s6_addr16[7] = (~0); 654 } else if ((unsigned short)n0 <= 32) { 655 in6addr16.s6_addr16[1] = htons( ntohs(in6addr16.s6_addr16[1]) |~((~0)<<(32-(n0)))); 656 in6addr16.s6_addr16[2] = (~0); 657 in6addr16.s6_addr16[3] = (~0); 658 in6addr16.s6_addr16[4] = (~0); 659 in6addr16.s6_addr16[5] = (~0); 660 in6addr16.s6_addr16[6] = (~0); 661 in6addr16.s6_addr16[7] = (~0); 662 } else if ((unsigned short)n0 <= 48) { 663 in6addr16.s6_addr16[2] = htons( ntohs(in6addr16.s6_addr16[2]) |~((~0)<<(48-(n0)))); 664 in6addr16.s6_addr16[3] = (~0); 665 in6addr16.s6_addr16[4] = (~0); 666 in6addr16.s6_addr16[5] = (~0); 667 in6addr16.s6_addr16[6] = (~0); 668 in6addr16.s6_addr16[7] = (~0); 669 } else if ((unsigned short)n0 <= 64) { 670 in6addr16.s6_addr16[3] = htons( ntohs(in6addr16.s6_addr16[3]) |~((~0)<<(64-(n0)))); 671 in6addr16.s6_addr16[4] = (~0); 672 in6addr16.s6_addr16[5] = (~0); 673 in6addr16.s6_addr16[6] = (~0); 674 in6addr16.s6_addr16[7] = (~0); 675 } else if ((unsigned short)n0 <= 80) { 676 in6addr16.s6_addr16[4] = htons( ntohs(in6addr16.s6_addr16[4]) |~((~0)<<(80-(n0)))); 677 in6addr16.s6_addr16[5] = (~0); 678 in6addr16.s6_addr16[6] = (~0); 679 in6addr16.s6_addr16[7] = (~0); 680 } else if ((unsigned short)n0 <= 96) { 681 in6addr16.s6_addr16[5] = htons( ntohs(in6addr16.s6_addr16[5]) |~((~0)<<(96-(n0)))); 682 in6addr16.s6_addr16[6] = (~0); 683 in6addr16.s6_addr16[7] = (~0); 684 } else if ((unsigned short)n0 <= 112) { 685 in6addr16.s6_addr16[6] = htons( ntohs(in6addr16.s6_addr16[6]) |~((~0)<<(112-(n0)))); 686 in6addr16.s6_addr16[7] = (~0); 687 } else { 688 in6addr16.s6_addr16[7] = htons( ntohs(in6addr16.s6_addr16[7]) |~((~0)<<(128-(n0)))); 689 } 690 pV6TabPtr[prefixIndex].end[0] = in6addr16.s6_addr32[0]; 691 pV6TabPtr[prefixIndex].end[1] = in6addr16.s6_addr32[1]; 692 pV6TabPtr[prefixIndex].end[2] = in6addr16.s6_addr32[2]; 693 pV6TabPtr[prefixIndex].end[3] = in6addr16.s6_addr32[3]; 694 pV6TabPtr[prefixIndex].mask = n0; 695 #if defined(MULTISAMPLING) 696 pV6TabPtr[prefixIndex].sampling = n1; 697 #else 698 pV6TabPtr[prefixIndex].sampling = 0; 699 #endif 700 prefixIndex++; 701 } 702 } 703 qsort(prefixStrTab, prefixIndex, sizeof(struct PrefixV6), prefixV6Cmp); 704 if( fclose(prefixFile) == 0) { 705 return (prefixIndex); 706 } else { 707 fprintf(stderr,"%s not closed, \n", filename); 708 exit(1); 709 return(prefixIndex); 710 } 711 } -
trunk/src/get_conf.h
r61 r94 54 54 }; 55 55 56 struct PrefixV6{ 57 unsigned long start[4]; 58 unsigned long end[4]; 59 unsigned short mask; 60 unsigned short hasSubnet; 61 unsigned long sampling; 62 unsigned long long flowNbIN; /* WARNING !!! */ 63 unsigned long long bytesNbIN; /* Here, IN means "to the prefix" */ 64 unsigned long long pktsNbIN; 65 unsigned long long flowNbOUT; /* WARNING !!! */ 66 unsigned long long bytesNbOUT; /* Here, OUT means "from the prefix" */ 67 unsigned long long pktsNbOUT; 68 unsigned long long firstCoSIN; /* only the bytes for CoS */ 69 unsigned long long secondCoSIN; 70 unsigned long long thirdCoSIN; 71 unsigned long long fourthCoSIN; 72 unsigned long long firstCoSOUT; 73 unsigned long long secondCoSOUT; 74 unsigned long long thirdCoSOUT; 75 unsigned long long fourthCoSOUT; 76 }; 77 56 78 void initConf(char *); 57 79 int longCmp(const void *, const void *); … … 59 81 unsigned short getPrefixV4(char *, struct PrefixV4 *, struct PrefixV4 *, 60 82 unsigned short *); 83 unsigned short getPrefixV6(char *, struct PrefixV6 *); 61 84 unsigned short getAS(char *, struct AS *); 62 85 -
trunk/src/prefix_mgmt.c
r28 r94 59 59 } 60 60 61 /* 62 * prefV6Cmp() 63 */ 64 int 65 prefV6Cmp(const void *elem1, const void *elem2){ 66 struct PrefixV6 *el1 = (struct PrefixV6 *) elem1; 67 struct PrefixV6 *el2 = (struct PrefixV6 *) elem2; 68 int i; 69 int moreIsNecessary = 1; 70 71 for (i=0;i<4;i++) { 72 switch(i){ 73 case 0: 74 if ( el2->mask <= 32 ) { 75 if ( el2->start[i] == el1->start[i] ) { 76 return 0; 77 }else{ 78 if (el2->end[i] < el1->start[i]) { 79 return 1; 80 }else{ 81 return 1; 82 } 83 } 84 } else { /* el2 > /32 */ 85 if ( el2->start[i] != el1->start[i] ) { 86 if (el2->end[i] < el1->start[i]) { 87 return 1; 88 }else{ 89 return 1; 90 } 91 } /* here we don't return, we'll continue in case */ 92 } 93 break; 94 case 1: 95 if ( el2->mask <= 64 ) { 96 if ( el2->start[i] == el1->start[i] ) { 97 return 0; 98 }else{ 99 if (el2->end[i] < el1->start[i]) { 100 return 1; 101 }else{ 102 return 1; 103 } 104 } 105 } else { /* el2 > /64 */ 106 if ( el2->start[i] != el1->start[i] ) { 107 if (el2->end[i] < el1->start[i]) { 108 return 1; 109 }else{ 110 return 1; 111 } 112 } /* here we don't return, we'll continue in case */ 113 } 114 break; 115 case 2: 116 if ( el2->mask <= 96 ) { 117 if ( el2->start[i] == el1->start[i] ) { 118 return 0; 119 }else{ 120 if (el2->end[i] < el1->start[i]) { 121 return 1; 122 }else{ 123 return 1; 124 } 125 } 126 } else { /* el2 > /96 */ 127 if ( el2->start[i] != el1->start[i] ) { 128 if (el2->end[i] < el1->start[i]) { 129 return 1; 130 }else{ 131 return 1; 132 } 133 } /* here we don't return, we'll continue in case */ 134 } 135 break; 136 case 3: 137 if ( el2->mask <= 128 ) { 138 if ( el2->start[i] == el1->start[i] ) { 139 return 0; 140 }else{ 141 if (el2->end[i] < el1->start[i]) { 142 return 1; 143 }else{ 144 return 1; 145 } 146 } 147 } else { /* el2 > /128 */ 148 if ( el2->start[i] != el1->start[i] ) { 149 if (el2->end[i] < el1->start[i]) { 150 return 1; 151 }else{ 152 return 1; 153 } 154 } /* here we don't return, we'll continue in case */ 155 } 156 break; 157 default: 158 syslog(LOG_ERR,"You have won !!! This IPv6 case doesn't exist !!!!"); 159 exit(1); 160 return 0; 161 break; 162 } 163 } 164 } -
trunk/src/renetcol.c
r88 r94 4 4 * Authors: ANDREU Francois-Xavier 5 5 * 6 * Copyright (C) 2005 2006 2007GIP RENATER6 * Copyright (C) 2005 - 2009 GIP RENATER 7 7 */ 8 8 … … 106 106 fprintf(stderr, "renetcol compilation and execution with IPv4 Aggregation feature enable based on SNMP ID in %s file.\n", INTERFACES_TYPE_LIST); 107 107 #endif 108 #if defined(IPV6AGGIDSNMP) 109 fprintf(stderr, "renetcol compilation and execution with IPv6 Aggregation feature enable based on SNMP ID in %s file.\n", INTERFACES_TYPE_LIST); 110 #endif 108 111 109 112 openlog(argv[0], LOG_PID, LOG_USER); … … 158 161 exit(1); 159 162 } 163 #if defined(IPV6AGGIDSNMP) 164 if ( (shmForAgg->v6PrefixNb = 165 getPrefixV6(SUBNETS_V6_LIST, 166 &(shmForAgg->prefixV6Tab[0][0]) 167 )) < 1){ 168 fprintf(stderr, "renetcol: Error in %s\n", SUBNETS_V6_LIST); 169 } else { 170 fprintf(stderr, "We have found %hu IPv6 prefixes from %s\n", 171 shmForAgg->v6PrefixNb, 172 SUBNETS_V6_LIST); 173 } 174 if ( (shmForAgg->v6PrefixNb = 175 getPrefixV6(SUBNETS_V6_LIST, 176 &(shmForAgg->prefixV6Tab[1][0]) 177 )) < 1){ 178 fprintf(stderr, "renetcol: Error in %s\n", SUBNETS_V6_LIST); 179 exit(1); 180 } 181 #endif 182 160 183 /* for (i=0; i<shmForAgg->v4PrefixNb; i++){ */ 161 184 /* fprintf(stderr, "SUPERNET : %lu, %hu\n",shmForAgg->prefixV4Tab[0][i].beginning, shmForAgg->prefixV4Tab[0][i].hasSubnet); */ -
trunk/src/renetcol.h
r61 r94 4 4 * Authors: ANDREU Francois-Xavier 5 5 * 6 * Copyright (C) 2005 2006 2007GIP RENATER6 * Copyright (C) 2005 - 2009 GIP RENATER 7 7 */ 8 8 … … 69 69 unsigned short v4PrefixNb; 70 70 unsigned short v4SubnetNb; 71 unsigned short v6PrefixNb; 71 72 #ifdef ASACC 72 73 unsigned short ASNb; … … 78 79 struct POP matrixPOP[2][ROUTER_INDEX_MAX][ROUTER_INDEX_MAX]; 79 80 #endif 80 /* struct PrefixV6 ; */81 struct PrefixV6 prefixV6Tab[2][MAX_IPV6_PREFIX]; 81 82 }; 82 83 -
trunk/src/renetcolAgg.h
r61 r94 50 50 unsigned short v4PrefixNb; 51 51 unsigned short v4SubnetNb; 52 unsigned short v6PrefixNb; 52 53 #ifdef ASACC 53 54 unsigned short ASNb; … … 59 60 struct POP matrixPOP[2][ROUTER_INDEX_MAX][ROUTER_INDEX_MAX]; 60 61 #endif 61 /* struct PrefixV6 ; */62 struct PrefixV6 prefixV6Tab[2][MAX_IPV6_PREFIX]; 62 63 }; -
trunk/src/renetcolParam.h
r93 r94 4 4 * Authors: ANDREU Francois-Xavier 5 5 * 6 * Copyright (C) 2007 GIP RENATER6 * Copyright (C) 2007-2009 GIP RENATER 7 7 */ 8 8 … … 33 33 */ 34 34 #define RECEPTION_ADDRESS "" 35 35 36 /* 36 37 * your collector port to recept netflow export 37 38 */ 38 39 #define RECEPTION_PORT 1111 40 39 41 /* 40 42 * routers index max + 1 (index of the beginning of the lines, and not number of routers) 41 43 */ 42 44 #define ROUTER_INDEX_MAX 55 45 43 46 /* 44 47 * FILE with your routers IP address 45 48 */ 46 49 #define ROUTERS_LIST "<path to renetcol>/renetcol-0.0.14beta/conf/routers.txt" 50 47 51 /* 48 52 * FILE with your prefix/subnet 49 53 */ 50 54 #define SUBNETS_LIST "<path to renetcol>/renetcol-0.0.14beta/conf/IPv4_Subnet_Aggregation_based_on_SNMP_index.txt" 55 56 /* 57 * FILE with your IPv6 prefixes list 58 */ 59 #define SUBNETS_V6_LIST "<path to renetcol>/renetcol-0.0.14beta/conf/IPv6_Subnet_Aggregation_based_on_SNMP_index.txt" 60 51 61 /* 52 62 * FILE with the list of AS with accounting 53 63 */ 54 64 #define AS_LIST "<path to renetcol>/renetcol-0.0.14beta/conf/AS.txt" 65 55 66 /* 56 67 * constants, here a subnet is include in a prefix … … 59 70 #define MAX_IPV4_SUBNET 1000 60 71 #define MAX_AS 3 72 #define MAX_IPV6_PREFIX 500 73 #define MAX_IPV6_SUBNET 100 74 61 75 /* 62 76 * FILE for the rules 63 77 */ 64 78 #define RULES_FILE "<path to renetcol>/renetcol-0.0.14beta/conf/rules.txt" 79 65 80 /* 66 81 * FILE with SNMP index of the interfaces … … 68 83 */ 69 84 #define INTERFACES_TYPE_LIST "<path to renetcol>/renetcol-0.0.14beta/conf/SNMP_INDEX.txt" 85 70 86 /* 71 * maximum SNMP index 87 * maximum SNMP index for one router 72 88 */ 73 89 #define MAX_SNMP_INDEX 900 90 74 91 /* 75 92 * Path to the rrd file … … 92 109 #define STEP 5 93 110 #define FIELD_TYPE_NUMBER 216 94 #define MAX_RULES_PER_FIELD 10 111 #define MAX_RULES_PER_FIELD 100 95 112 #define SHMSIZE 33554432 96 113 #define SOCKET_BUFFER_SIZE 1500 -
trunk/src/renetcolSender.c
r77 r94 72 72 char filters[249]; 73 73 /* char operator[2]; */ 74 char lines[ 256][256];74 char lines[1024][256]; /* FIXME : here perhaps use a constante like MAX_FILTERS *3 */ 75 75 char line[256]; 76 76 char lineCopy[256];