| 482 | time_t gGgsnInitTime; |
| 483 | |
| 484 | bool miniggsn_init() |
| 485 | { |
| 486 | static int initstatus = -1; // -1: uninited; 0:init failed; 1: init succeeded. |
| 487 | if (initstatus >= 0) {return initstatus;} |
| 488 | initstatus = 0; // assume failure. |
| 489 | |
| 490 | |
| 491 | // We init config options at GGSN startup. |
| 492 | // They cannot be changed while running. |
| 493 | // To change an option, you would have to stop and restart the GGSN. |
| 494 | ggConfig.mgIpTimeout = gConfig.getNum(SQL_IP_TIMEOUT); |
| 495 | ggConfig.mgMaxPduSize = gConfig.getNum(SQL_PDU_MAX_SIZE); |
| 496 | ggConfig.mgMaxConnections = gConfig.getNum(SQL_PDP_MAX_COUNT); |
| 497 | ggConfig.mgIpTossDup = gConfig.getNum(SQL_IP_TOSS_DUP); |
| 498 | |
| 499 | |
| 500 | string logfile = gConfig.getStr(SQL_LOG_FILE); |
| 501 | if (logfile.length()) { |
| 502 | mg_log_fp = fopen(logfile.c_str(),"w"); |
| 503 | if (mg_log_fp == 0) { |
| 504 | MGERROR("could not open %s log file:%s",SQL_LOG_FILE,logfile.c_str()); |
| 505 | // (pat) Add an alert to the console so people will notice this problem. |
| 506 | LOG(ALERT) << "Cound not open tun device, GPRS non-functional:"; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | // This is the first message in the newly opened file. |
| 511 | time(&gGgsnInitTime); |
| 512 | MGINFO("Initializing Mini GGSN %s",ctime(&gGgsnInitTime)); // ctime includes a newline. |
| 513 | |
| 514 | if (mg_log_fp) { |
| 515 | mg_debug_level = 1; |
| 516 | MGINFO("GGSN logging to file %s",logfile.c_str()); |
| 517 | } |
| 518 | |
| 519 | if (ggConfig.mgMaxConnections > 254) { |
| 520 | MGERROR("%s specifies too many connections (%d) specifed, using 254", |
| 521 | SQL_PDP_MAX_COUNT,ggConfig.mgMaxConnections); |
| 522 | ggConfig.mgMaxConnections = 254; |
| 523 | } |
| 524 | |
| 525 | // We need three IP things: |
| 526 | // 1. the route expressed using "/maskbits" notation, |
| 527 | // 2. the base ip address, |
| 528 | // 3. the mask for the MS (which has very little to do with the netmask of the host we are running on.) |
| 529 | // All three can be derived from the ipRoute, if specfied. |
| 530 | // But conceivably the user might want to start their base ip address elsewhere. |
| 531 | |
| 532 | const char *ip_base_str = gConfig.getStr(SQL_IP_BASE).c_str(); |
| 533 | uint32_t mgIpBasenl = inet_addr(ip_base_str); |
| 534 | if (mgIpBasenl == INADDR_NONE) { |
| 535 | MGERROR("miniggsn: %s address invalid:%s",SQL_IP_BASE,ip_base_str); |
| 536 | return false; |
| 537 | } |
| 538 | |
| 539 | if ((ntohl(mgIpBasenl) & 0xff) == 0) { |
| 540 | MGERROR("miniggsn: %s address should not end in .0 but proceeding anyway: %s",SQL_IP_BASE,ip_base_str); |
| 541 | } |
no test coverage detected