[2] | 1 | |
---|
| 2 | |
---|
| 3 | |
---|
[28] | 4 | |
---|
[2] | 5 | |
---|
[127] | 6 | |
---|
[2] | 7 | |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | #include "routers_mgmt.h" |
---|
| 27 | |
---|
| 28 | RouterPtr notExistRouter(RouterPtr rL, unsigned long address) |
---|
| 29 | { |
---|
| 30 | RouterPtr tmp = rL; |
---|
[27] | 31 | int i = 0; |
---|
[2] | 32 | for ( ; tmp; tmp=tmp->next) { |
---|
[27] | 33 | i++; |
---|
[2] | 34 | if ( tmp->IpAddress == address ){ |
---|
| 35 | return tmp; |
---|
| 36 | } |
---|
| 37 | } |
---|
| 38 | return NULL; |
---|
| 39 | } |
---|
| 40 | |
---|
[95] | 41 | RouterPtr addRouter(RouterPtr routersList, unsigned long address, unsigned short id) |
---|
[2] | 42 | { |
---|
| 43 | RouterPtr tmp = (RouterPtr) malloc(sizeof(struct Router)); |
---|
| 44 | if (tmp==NULL) { |
---|
[95] | 45 | syslog(LOG_ERR, "ERROR in malloc in addRouter function\n"); |
---|
[2] | 46 | exit(1); |
---|
| 47 | } else { |
---|
| 48 | tmp->IpAddress = address; |
---|
[95] | 49 | tmp->ID = id; |
---|
[2] | 50 | tmp->tplList = NULL; |
---|
| 51 | tmp->tplOptList = NULL; |
---|
[113] | 52 | tmp->engineList = NULL; |
---|
[84] | 53 | #if defined(MULTISAMPLING) |
---|
| 54 | tmp->sampled = 1; |
---|
| 55 | #else |
---|
[59] | 56 | tmp->sampled = 0; |
---|
[84] | 57 | #endif |
---|
[2] | 58 | tmp->next = routersList; |
---|
| 59 | if (routersList!=NULL) { routersList->prev = tmp;} |
---|
| 60 | tmp->prev = NULL; |
---|
| 61 | return tmp; |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
[58] | 65 | RouterPtr updateRouter(RouterPtr routersList, unsigned long address, |
---|
| 66 | unsigned long spled) |
---|
| 67 | { |
---|
| 68 | RouterPtr tmp = NULL; |
---|
| 69 | if ((tmp = notExistRouter(routersList, |
---|
| 70 | address))==NULL) { |
---|
[80] | 71 | syslog(LOG_INFO,"Router Address not registered : %lu.%lu.%lu.%lu", |
---|
[58] | 72 | (address>>24), |
---|
| 73 | (address<<8>>24), |
---|
| 74 | (address<<16>>24), |
---|
| 75 | (address<<24>>24)); |
---|
| 76 | return routersList; |
---|
| 77 | } else { |
---|
| 78 | tmp->sampled = spled; |
---|
| 79 | return tmp; |
---|
| 80 | } |
---|
| 81 | return NULL; |
---|
| 82 | } |
---|
| 83 | |
---|
[2] | 84 | TplFlowSetPtr newRouterTplList() |
---|
| 85 | { |
---|
| 86 | TplFlowSetPtr tmp = (TplFlowSetPtr) malloc(sizeof(struct TemplateFlowSet)); |
---|
| 87 | tmp->sourceId = 0; |
---|
[30] | 88 | tmp->templateFlowSetId = 99; |
---|
[2] | 89 | tmp->fieldCount = 0; |
---|
| 90 | tmp->fieldSet = NULL; |
---|
| 91 | tmp->lastField = NULL; |
---|
| 92 | tmp->next = NULL; |
---|
| 93 | tmp->prev = NULL; |
---|
| 94 | return tmp; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | TplFlowSetPtr deleteTplFlSet(TplFlowSetPtr ptpl) |
---|
| 98 | { |
---|
| 99 | FieldPtr tmp = NULL; |
---|
| 100 | if (ptpl) { |
---|
| 101 | while ( ptpl->fieldSet != NULL ){ |
---|
| 102 | if (!(ptpl->lastField->prev)) { |
---|
| 103 | freeField(ptpl->lastField); |
---|
| 104 | ptpl->lastField = NULL; |
---|
| 105 | ptpl->fieldSet = NULL; |
---|
| 106 | } else { |
---|
| 107 | tmp = ptpl->lastField->prev; |
---|
| 108 | tmp->next = NULL; |
---|
| 109 | freeField(ptpl->lastField); |
---|
| 110 | ptpl->lastField = tmp; |
---|
| 111 | } |
---|
| 112 | } |
---|
| 113 | free(ptpl); |
---|
| 114 | ptpl = NULL; |
---|
| 115 | } |
---|
[30] | 116 | return NULL; |
---|
[2] | 117 | } |
---|
| 118 | |
---|
[113] | 119 | NDEEnginePtr newRouterEngineList() |
---|
| 120 | { |
---|
| 121 | NDEEnginePtr tmp = (NDEEnginePtr) malloc(sizeof(struct NDEEngine)); |
---|
| 122 | tmp->package_sequence = 0; |
---|
| 123 | tmp->engineId = 0; |
---|
| 124 | tmp->prev = NULL; |
---|
| 125 | tmp->next = NULL; |
---|
| 126 | return tmp; |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | NDEEnginePtr existEngId(RouterPtr cr, unsigned long sid) |
---|
| 136 | { |
---|
| 137 | NDEEnginePtr tmp=cr->engineList; |
---|
| 138 | for (; tmp; tmp=tmp->next) { |
---|
| 139 | if (tmp->engineId==sid) { |
---|
| 140 | return tmp; |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | return NULL; |
---|
| 144 | } |
---|
| 145 | |
---|
[2] | 146 | TplOptionPtr newRouterTplOptList() |
---|
| 147 | { |
---|
| 148 | TplOptionPtr tmp = (TplOptionPtr) malloc(sizeof(struct TemplateOption)); |
---|
| 149 | tmp->sourceId = 0; |
---|
[30] | 150 | tmp->templateOptionId = 66; |
---|
[2] | 151 | tmp->length = 0; |
---|
| 152 | tmp->optionScopeLg = 0; |
---|
| 153 | tmp->optionLg = 0; |
---|
| 154 | tmp->fieldSet = NULL; |
---|
| 155 | tmp->lastField = NULL; |
---|
| 156 | tmp->next = NULL; |
---|
| 157 | tmp->prev = NULL; |
---|
| 158 | return tmp; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | TplOptionPtr deleteTplOption(TplOptionPtr ptplo) |
---|
| 162 | { |
---|
| 163 | FieldPtr tmp = NULL; |
---|
| 164 | if (ptplo) { |
---|
| 165 | while ( ptplo->fieldSet != NULL ){ |
---|
| 166 | if (!(ptplo->lastField->prev)) { |
---|
| 167 | freeField(ptplo->lastField); |
---|
| 168 | ptplo->lastField = NULL; |
---|
| 169 | ptplo->fieldSet = NULL; |
---|
| 170 | } else { |
---|
| 171 | tmp = ptplo->lastField->prev; |
---|
| 172 | tmp->next = NULL; |
---|
| 173 | freeField(ptplo->lastField); |
---|
| 174 | ptplo->lastField = tmp; |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | free(ptplo); |
---|
| 178 | ptplo = NULL; |
---|
| 179 | } |
---|
| 180 | return NULL; |
---|
| 181 | } |
---|
[58] | 182 | |
---|
[76] | 183 | #ifdef IPV4AGGIDSNMP |
---|
[58] | 184 | int getSNMPIndexList(char *filename, RouterPtr routersListPtr) |
---|
| 185 | { |
---|
| 186 | FILE *indexFile = NULL; |
---|
| 187 | char line[200]; |
---|
| 188 | int cptLine = 0; |
---|
| 189 | char tindex[5]; |
---|
| 190 | char ttoken[2]; |
---|
| 191 | char tid[2]; |
---|
| 192 | char tad[16]; |
---|
| 193 | int index = 0; |
---|
[96] | 194 | int i = 0; |
---|
[58] | 195 | unsigned short n0, n1, n2, n3; |
---|
| 196 | unsigned char buffer4[4]; |
---|
| 197 | unsigned long ipAddress; |
---|
| 198 | RouterPtr routerTmp = NULL; |
---|
[95] | 199 | unsigned short snmpIndex = 0; |
---|
| 200 | unsigned short snmpCpt = 0; |
---|
[58] | 201 | |
---|
| 202 | if (!(indexFile = fopen(filename, "r"))) { |
---|
| 203 | fprintf (stderr, "error during %s opening\n", filename); |
---|
| 204 | exit(1); |
---|
| 205 | } |
---|
| 206 | while ( fgets(line, 200, indexFile) != 0) { |
---|
| 207 | cptLine++; |
---|
| 208 | if ( strspn(line, "R") == 1 ) { |
---|
| 209 | if (sscanf(line, "%s %s\n", |
---|
| 210 | ttoken, |
---|
| 211 | tad) == 0) { |
---|
| 212 | fprintf(stderr, "Error in file %s, line %d\n", |
---|
| 213 | filename, cptLine); |
---|
| 214 | exit(1); |
---|
| 215 | } |
---|
| 216 | if (sscanf(tad,"%hu.%hu.%hu.%hu\n",&n0,&n1,&n2,&n3) == 0){ |
---|
| 217 | fprintf(stderr, "Address error in file %s, line %d\n", |
---|
| 218 | filename, cptLine); |
---|
| 219 | exit(1); |
---|
| 220 | } |
---|
| 221 | buffer4[3] = (unsigned char)n0; |
---|
| 222 | buffer4[2] = (unsigned char)n1; |
---|
| 223 | buffer4[1] = (unsigned char)n2; |
---|
| 224 | buffer4[0] = (unsigned char)n3; |
---|
| 225 | ipAddress = *((unsigned long*)(&buffer4)); |
---|
| 226 | if ((routerTmp = notExistRouter(routersListPtr, |
---|
| 227 | ipAddress))==NULL){ |
---|
| 228 | fprintf(stderr, "Error in file %s, line %d : IP unknown : %lu\n", |
---|
| 229 | filename, cptLine, ipAddress); |
---|
| 230 | exit(1); |
---|
| 231 | } |
---|
[96] | 232 | for (i=0; i<MAX_INDEX_BY_ROUTER; i++) { |
---|
| 233 | routerTmp->snmpIndexType[i] = 2; |
---|
| 234 | routerTmp->snmpIndexID[i] = 0; |
---|
| 235 | } |
---|
[95] | 236 | snmpCpt = 0; |
---|
[58] | 237 | }else{ |
---|
[96] | 238 | if (snmpCpt==0){ |
---|
| 239 | routerTmp->snmpIndexType[0] = 1; |
---|
| 240 | routerTmp->snmpIndexID[0] = 0; |
---|
| 241 | snmpCpt++; |
---|
| 242 | } |
---|
[58] | 243 | if ( strspn(line, "I") == 1 ) { |
---|
| 244 | if (sscanf(line, "%s %s %s\n", |
---|
| 245 | ttoken, |
---|
| 246 | tindex, |
---|
| 247 | tid) == 0) { |
---|
| 248 | fprintf(stderr, "Error in file %s, line %d\n", |
---|
| 249 | filename, cptLine); |
---|
| 250 | exit(1); |
---|
| 251 | } |
---|
| 252 | index = atoi(tindex); |
---|
| 253 | if ( strcmp(tid, "B") == 0 ) { |
---|
| 254 | routerTmp->snmpIndexList[index] = 0; |
---|
[95] | 255 | routerTmp->snmpIndexID[snmpCpt] = index; |
---|
| 256 | routerTmp->snmpIndexType[snmpCpt] = 0; |
---|
[96] | 257 | |
---|
[58] | 258 | } else if ( strcmp(tid, "C") == 0 ) { |
---|
| 259 | routerTmp->snmpIndexList[index] = 1; |
---|
[95] | 260 | routerTmp->snmpIndexID[snmpCpt] = index; |
---|
| 261 | routerTmp->snmpIndexType[snmpCpt] = 1; |
---|
[96] | 262 | |
---|
[58] | 263 | } else { |
---|
| 264 | fprintf(stderr, "Error in file %s, line %d : bad code B or C \n", |
---|
| 265 | filename, cptLine); |
---|
| 266 | exit(1); |
---|
| 267 | } |
---|
[96] | 268 | snmpCpt++; |
---|
[58] | 269 | } else { |
---|
| 270 | fprintf(stderr, "Error in file %s, line %d : bad index line \n", |
---|
| 271 | filename, cptLine); |
---|
| 272 | exit(1); |
---|
| 273 | } |
---|
| 274 | } |
---|
| 275 | } |
---|
| 276 | return 1; |
---|
| 277 | } |
---|
[76] | 278 | #endif |
---|