00001
00002
00003
00004
00005
00006 #include <stdio.h>
00007 #include "find_ip_and_reply.h"
00008 #include "packets_operations.h"
00009 #include "logging.h"
00010 #include "packets.h"
00011 #include "strings_utils.h"
00012 #include "packets.h"
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 static unsigned int get_lease_from_context (struct mysql_tables *mysql_tables)
00025 {
00026 int option_number, e, i;
00027 unsigned int lease;
00028 char *option_value;
00029
00030
00031
00032
00033
00034 option_number = mysql_tables->option_number;
00035 if (option_number > MAX_PROFILE_OPTIONS) { return (unsigned int)(-1); }
00036
00037 option_value = NULL;
00038
00039 for (i=0; i<option_number; i++)
00040 {
00041 if (((mysql_tables->options)[i]).option_code == 51)
00042 { option_value = ((mysql_tables->options)[i]).option_value; break; }
00043 }
00044
00045 if (option_value == NULL) { return (unsigned int)(-1); }
00046
00047
00048
00049
00050
00051 lease = string2unsigned_int (option_value, &e);
00052
00053 if (e) { return (unsigned int)(-1); }
00054
00055 return lease;
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 int find_ip_and_reply (struct smysql *mysql_info_read,
00118 struct smysql *mysql_info_read_write,
00119 struct smysql *mysql_radonline,
00120 struct smysql *mysql_mydns,
00121 struct mysql_tables *mysql_tables,
00122 struct dhcp_packet *packet,
00123 struct global_config *config,
00124 int sck,
00125 unsigned long int broadcast,
00126 unsigned long int server_ip,
00127 struct sockaddr_in *client_address)
00128 {
00129 int rc, tip, request_type;
00130
00131
00132 if (config->debug > 1)
00133 {
00134 my_syslog (config->log_file,
00135 "[DEBUG] [%s:%d] Find IP for abonne (abonnes_id=%lu)",
00136 __FILE__, __LINE__,
00137 (mysql_tables->abonnes).abonnes_id);
00138 }
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 (mysql_tables->abonne_ip).abonnes_id = (mysql_tables->abonnes).abonnes_id;
00149 (mysql_tables->abonne_ip).vlan_id = (mysql_tables->vlan).vlan_id;
00150
00151 if (config->debug > 1)
00152 {
00153 my_syslog (config->log_file,
00154 "[DEBUG] [%s:%d] Looking for fixed IP for abonne 'abonnes_id=%lu' within VLAN 'vlan_id=%lu'",
00155 __FILE__, __LINE__,
00156 (mysql_tables->abonne_ip).abonnes_id,
00157 (mysql_tables->abonne_ip).vlan_id);
00158 }
00159
00160
00161
00162
00163
00164 rc = load_abonne_ip (mysql_info_read,
00165 mysql_tables,
00166 config);
00167
00168 switch (rc)
00169 {
00170 case MYSQL_INTERFACE_REQUEST_SKIPED:
00171 my_syslog (config->log_file,
00172 "[WARNING] [%s:%d] Could not look at the pool of STATIC IP, request skiped",
00173 __FILE__, __LINE__);
00174 return MYSQL_INTERFACE_REQUEST_SKIPED;
00175
00176 case MYSQL_INTERFACE_CONNECTION_LOST:
00177 my_syslog (config->log_file,
00178 "[WARNING] [%s:%d] Could not look at the pool of STATIC IP, connection lost",
00179 __FILE__, __LINE__);
00180 return MYSQL_INTERFACE_CONNECTION_LOST;
00181
00182 case MYSQL_INTERFACE_RECONNECTION_FAILED:
00183 my_syslog (config->log_file,
00184 "[WARNING] [%s:%d] Could not look at the pool of STATIC IP, could not reconnect",
00185 __FILE__, __LINE__);
00186 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00187
00188 case MYSQL_INTERFACE_SQL_PROBLEM:
00189 my_syslog (config->log_file,
00190 "[ERROR] [%s:%d] Could not look at the pool of STATIC IP, unexpected SQL error",
00191 __FILE__, __LINE__);
00192 return MYSQL_INTERFACE_SQL_PROBLEM;
00193
00194 case MYSQL_INTERFACE_MORE_THAN_ONE:
00195 my_syslog (config->log_file,
00196 "[ERROR] [%s:%d] More than one STATIC IP found",
00197 __FILE__, __LINE__);
00198 return MYSQL_INTERFACE_MORE_THAN_ONE;
00199
00200 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
00201 my_syslog (config->log_file,
00202 "[ERROR] [%s:%d] Unexpected SQL error",
00203 __FILE__, __LINE__);
00204 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00205 }
00206
00207 if (rc == MYSQL_INTERFACE_NOT_FOUND) { tip = DYNAMIC_IP; } else { tip = STATIC_IP; }
00208
00209
00210
00211
00212
00213 request_type = packets_get_message_type (packet);
00214
00215 if (request_type == -1)
00216 {
00217 my_syslog (config->log_file,
00218 "[WARNING] [%s:%d] Invalid message type (Skip)", __FILE__, __LINE__);
00219 return DHCP_INVALID_MESSAGE_TYPE;
00220 }
00221
00222
00223
00224
00225
00226 if (request_type == DHCPDISCOVER)
00227 {
00228 char *ip;
00229
00230 my_syslog (config->log_file, "[INFO] [%s:%d] Got DISCOVER", __FILE__, __LINE__);
00231
00232 if (tip == DYNAMIC_IP)
00233 {
00234 int rc;
00235
00236
00237
00238
00239
00240
00241
00242
00243 (mysql_tables->ip_lease).vlan_id = (unsigned long int) packets_get_vlan_id(packet);
00244 (mysql_tables->pool).abonnes_id = (mysql_tables->abonnes).abonnes_id;
00245
00246 if (config->debug > 1)
00247 {
00248 my_syslog (config->log_file,
00249 "[DEBUG] [%s:%d] Looking for free IP in pool for 'abonnes_id=%lu' within 'vlan_id=%lu'",
00250 __FILE__, __LINE__,
00251 (mysql_tables->pool).abonnes_id,
00252 (mysql_tables->ip_lease).vlan_id);
00253 }
00254
00255
00256
00257
00258
00259 rc = get_ip_from_pool (mysql_info_read_write,
00260 mysql_tables,
00261 config,
00262 (mysql_tables->vlan).offer_timeout,
00263 1);
00264
00265 switch (rc)
00266 {
00267 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
00268 my_syslog (config->log_file,
00269 "[ERROR] [%s:%d] Unexpected error",
00270 __FILE__, __LINE__);
00271 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00272
00273 case MYSQL_INTERFACE_SQL_PROBLEM:
00274 my_syslog (config->log_file,
00275 "[ERROR] [%s:%d] Some SQL error occured",
00276 __FILE__, __LINE__);
00277 return MYSQL_INTERFACE_SQL_PROBLEM;
00278
00279 case MYSQL_INTERFACE_RECONNECTION_FAILED:
00280 my_syslog (config->log_file,
00281 "[ERROR] [%s:%d] Could not reconnect to MySql server",
00282 __FILE__, __LINE__);
00283 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00284
00285 case MYSQL_INTERFACE_CONNECTION_LOST:
00286 my_syslog (config->log_file,
00287 "[ERROR] [%s:%d] Reconnection to MySql server failed",
00288 __FILE__, __LINE__);
00289 return MYSQL_INTERFACE_CONNECTION_LOST;
00290
00291 case MYSQL_INTERFACE_REQUEST_SKIPED:
00292 my_syslog (config->log_file,
00293 "[WARNING] [%s:%d] SQL request skiped",
00294 __FILE__, __LINE__);
00295 return MYSQL_INTERFACE_REQUEST_SKIPED;
00296
00297 case MYSQL_INTERFACE_NO_TIMESTAMP:
00298 my_syslog (config->log_file,
00299 "[ERROR] [%s:%d] Error while getting MySql server UNIX timestamp",
00300 __FILE__, __LINE__);
00301 return MYSQL_INTERFACE_NO_TIMESTAMP;
00302
00303 case MYSQL_INTERFACE_MORE_THAN_ONE:
00304 my_syslog (config->log_file,
00305 "[ERROR] [%s:%d] Internal error: More that one IP address selected in the pool",
00306 __FILE__, __LINE__);
00307 return MYSQL_INTERFACE_MORE_THAN_ONE;
00308
00309 case MYSQL_INTERFACE_NO_LEASE_ID:
00310 my_syslog (config->log_file,
00311 "[WARNING] [%s:%d] Table 'lease': no lease ID found",
00312 __FILE__, __LINE__);
00313 return MYSQL_INTERFACE_NO_LEASE_ID;
00314
00315 case 0:
00316 my_syslog (config->log_file,
00317 "[WARNING] [%s:%d] Could not find free dynamic IP address for VLAN ID %u",
00318 __FILE__, __LINE__, packets_get_vlan_id(packet));
00319 return DHCP_NO_DYNAMIC_IP_FOUND;
00320 }
00321
00322 if (config->debug > 1)
00323 {
00324 my_syslog (config->log_file, "[DEBUG] [%s:%d] Dynamic IP found is '%s' (pool_id=%lu)",
00325 __FILE__, __LINE__, (mysql_tables->pool).ip, (mysql_tables->pool).pool_id);
00326 }
00327 }
00328
00329
00330
00331
00332
00333 my_syslog (config->log_file, "[INFO] [%s:%d] Sending OFFER", __FILE__, __LINE__);
00334
00335 if (tip == STATIC_IP) { ip = (mysql_tables->abonne_ip).ip; }
00336 else { ip = (mysql_tables->pool).ip; }
00337
00338 rc = packets_send_offer (
00339 packet,
00340 mysql_tables,
00341 ip,
00342 broadcast,
00343 server_ip,
00344 sck,
00345 client_address,
00346 tip
00347 );
00348 }
00349
00350
00351
00352
00353
00354 if (request_type == DHCPREQUEST)
00355 {
00356 unsigned int lease;
00357 char *ip;
00358
00359 my_syslog (config->log_file, "[INFO] [%s:%d] Got REQUEST", __FILE__, __LINE__);
00360
00361
00362
00363
00364
00365 lease = get_lease_from_context (mysql_tables);
00366
00367 if (lease == (unsigned int)(-1))
00368 {
00369 my_syslog (config->log_file,
00370 "[WARNING] [%s:%d] Something wrong with the loaded profile (can not decode lease, option 51)",
00371 __FILE__, __LINE__);
00372 return DHCP_LEASE_INCONSTANCY;
00373 }
00374
00375 if (config->debug > 1)
00376 { my_syslog (config->log_file,
00377 "[DEBUG] [%s:%d] Lease is %u seconds", __FILE__, __LINE__, lease); }
00378
00379
00380
00381
00382
00383 if (tip == DYNAMIC_IP)
00384 {
00385 int rc;
00386
00387
00388
00389
00390
00391
00392
00393
00394 (mysql_tables->ip_lease).vlan_id = (unsigned long int) packets_get_vlan_id(packet);
00395 (mysql_tables->pool).abonnes_id = (mysql_tables->abonnes).abonnes_id;
00396
00397 if (config->debug > 1)
00398 {
00399 my_syslog (config->log_file,
00400 "[DEBUG] [%s:%d] Looking for free IP in pool for 'abonnes_id=%lu' within 'vlan_id=%lu'",
00401 __FILE__, __LINE__,
00402 (mysql_tables->pool).abonnes_id,
00403 (mysql_tables->ip_lease).vlan_id);
00404 }
00405
00406
00407
00408
00409
00410 rc = get_ip_from_pool (mysql_info_read_write,
00411 mysql_tables,
00412 config,
00413 lease,
00414 0);
00415
00416 switch (rc)
00417 {
00418 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
00419 my_syslog (config->log_file,
00420 "[ERROR] [%s:%d] Unexpected error",
00421 __FILE__, __LINE__);
00422 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00423
00424 case MYSQL_INTERFACE_SQL_PROBLEM:
00425 my_syslog (config->log_file,
00426 "[ERROR] [%s:%d] Some SQL error occured",
00427 __FILE__, __LINE__);
00428 return MYSQL_INTERFACE_SQL_PROBLEM;
00429
00430 case MYSQL_INTERFACE_RECONNECTION_FAILED:
00431 my_syslog (config->log_file,
00432 "[ERROR] [%s:%d] Could not reconnect to MySql server",
00433 __FILE__, __LINE__);
00434 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00435
00436 case MYSQL_INTERFACE_CONNECTION_LOST:
00437 my_syslog (config->log_file,
00438 "[ERROR] [%s:%d] Reconnection to MySql server failed",
00439 __FILE__, __LINE__);
00440 return MYSQL_INTERFACE_CONNECTION_LOST;
00441
00442 case MYSQL_INTERFACE_REQUEST_SKIPED:
00443 my_syslog (config->log_file,
00444 "[WARNING] [%s:%d] SQL request skiped",
00445 __FILE__, __LINE__);
00446 return MYSQL_INTERFACE_REQUEST_SKIPED;
00447
00448 case MYSQL_INTERFACE_NO_TIMESTAMP:
00449 my_syslog (config->log_file,
00450 "[ERROR] [%s:%d] Error while getting MySql server UNIX timestamp",
00451 __FILE__, __LINE__);
00452 return MYSQL_INTERFACE_NO_TIMESTAMP;
00453
00454 case MYSQL_INTERFACE_MORE_THAN_ONE:
00455 my_syslog (config->log_file,
00456 "[ERROR] [%s:%d] Internal error: More that one IP address selected in the pool",
00457 __FILE__, __LINE__);
00458 return MYSQL_INTERFACE_MORE_THAN_ONE;
00459
00460 case MYSQL_INTERFACE_NO_LEASE_ID:
00461 my_syslog (config->log_file,
00462 "[WARNING] [%s:%d] Table 'lease': no lease ID found",
00463 __FILE__, __LINE__);
00464 return MYSQL_INTERFACE_NO_LEASE_ID;
00465
00466 case 0:
00467 my_syslog (config->log_file,
00468 "[WARNING] [%s:%d] Could not find free dynamic IP address for VLAN ID %u",
00469 __FILE__, __LINE__, packets_get_vlan_id(packet));
00470 return DHCP_NO_DYNAMIC_IP_FOUND;
00471 }
00472
00473 if (config->debug > 1)
00474 {
00475 my_syslog (config->log_file, "[DEBUG] [%s:%d] Dynamic IP found is '%s' (pool_id=%lu)",
00476 __FILE__, __LINE__, (mysql_tables->pool).ip, (mysql_tables->pool).pool_id);
00477 }
00478 }
00479
00480
00481
00482
00483
00484 if (tip == STATIC_IP) { ip = (mysql_tables->abonne_ip).ip; }
00485 else { ip = (mysql_tables->pool).ip; }
00486
00487 if (config->debug > 1)
00488 {
00489 my_syslog (config->log_file, "[DEBUG] [%s:%d] Sending ACK (or NAK) (ip=%s)",
00490 __FILE__, __LINE__, ip);
00491 }
00492
00493
00494 if ((mysql_tables->abonnes).nack_flag == 0)
00495 {
00496
00497
00498
00499
00500 my_syslog (config->log_file, "[INFO] [%s:%d] Sending ACK", __FILE__, __LINE__);
00501
00502 if (config->debug > 1)
00503 {
00504 my_syslog (config->log_file, "[DEBUG] [%s:%d] Sending ACK (ip=%s). Note: nack_flag=0",
00505 __FILE__, __LINE__, ip);
00506 }
00507
00508 rc = packets_send_ack (
00509 packet,
00510 mysql_tables,
00511 ip,
00512 broadcast,
00513 server_ip,
00514 sck,
00515 client_address,
00516 tip
00517 );
00518
00519 if (rc == 1)
00520 {
00521 my_syslog (config->log_file,
00522 "[ERROR] [%s:%d] ACK not sent !!! packets_send_ack() failed !!!",
00523 __FILE__, __LINE__);
00524 }
00525 }
00526 else
00527 {
00528
00529
00530
00531
00532 unsigned long int new_nack_flag_value;
00533
00534 my_syslog (config->log_file, "[INFO] [%s:%d] Sending NAK", __FILE__, __LINE__);
00535
00536 new_nack_flag_value = (mysql_tables->abonnes).nack_flag - 1;
00537
00538 if (config->debug > 0)
00539 {
00540 my_syslog (config->log_file, "[DEBUG] [%s:%d] Sending NAK (ip=%s). Note: nack_flag=%lu",
00541 __FILE__, __LINE__, ip, (mysql_tables->abonnes).nack_flag);
00542 }
00543
00544
00545
00546
00547
00548 rc = packets_send_nack (
00549 packet,
00550 mysql_tables,
00551 ip,
00552 broadcast,
00553 server_ip,
00554 sck,
00555 client_address
00556 );
00557
00558 if (rc == 1)
00559 {
00560 my_syslog (config->log_file,
00561 "[ERROR] [%s:%d] NAK not sent !!! packets_send_nack() failed !!!",
00562 __FILE__, __LINE__);
00563 }
00564
00565
00566
00567
00568
00569 if (config->debug > 0)
00570 {
00571 my_syslog (config->log_file, "[DEBUG] [%s:%d] Update value of nack_flag (new value is %lu)",
00572 __FILE__, __LINE__, new_nack_flag_value);
00573 }
00574
00575 rc = nack_flag_abonne (mysql_info_read,
00576 mysql_tables,
00577 config,
00578 new_nack_flag_value);
00579
00580 switch (rc)
00581 {
00582 case MYSQL_INTERFACE_REQUEST_SKIPED:
00583 my_syslog (config->log_file,
00584 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00585 return MYSQL_INTERFACE_REQUEST_SKIPED;
00586 case MYSQL_INTERFACE_CONNECTION_LOST:
00587 my_syslog (config->log_file,
00588 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00589 return MYSQL_INTERFACE_CONNECTION_LOST;
00590 case MYSQL_INTERFACE_RECONNECTION_FAILED:
00591 my_syslog (config->log_file,
00592 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00593 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00594 case MYSQL_INTERFACE_SQL_PROBLEM:
00595 my_syslog (config->log_file,
00596 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00597 return MYSQL_INTERFACE_SQL_PROBLEM;
00598 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
00599 my_syslog (config->log_file,
00600 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00601 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00602 case MYSQL_INTERFACE_MORE_THAN_ONE:
00603 my_syslog (config->log_file,
00604 "[ERROR] [%s,%d] More than one record abonnes_id='%lu' (login radius='%s')",
00605 __FILE__, __LINE__,
00606 mysql_tables->abonnes.abonnes_id,
00607 mysql_tables->abonnes.login_radius);
00608 return MYSQL_INTERFACE_MORE_THAN_ONE;
00609 case MYSQL_INTERFACE_NOT_FOUND:
00610 my_syslog (config->log_file,
00611 "[ERROR] [%s,%d] No record found with abonnes_id='%lu' (login radius='%s')",
00612 __FILE__, __LINE__,
00613 mysql_tables->abonnes.abonnes_id,
00614 mysql_tables->abonnes.login_radius);
00615 return MYSQL_INTERFACE_NOT_FOUND;
00616 }
00617
00618
00619
00620
00621
00622 return 0;
00623 }
00624
00625
00626
00627
00628
00629 my_syslog (config->log_file, "[INFO] [%s:%d] Radonline(start)",
00630 __FILE__, __LINE__);
00631
00632 rc = send_to_radonline (mysql_radonline,
00633 mysql_tables,
00634 ip,
00635 RADONLINE_START,
00636 config);
00637
00638 switch (rc)
00639 {
00640 case MYSQL_REQUEST_SKIPED:
00641 my_syslog (config->log_file,
00642 "[WARNING] [%s:%d] Skip START to Radonline (request skiped)",
00643 __FILE__, __LINE__);
00644 break;
00645 case MYSQL_CONNECTION_LOST:
00646 my_syslog (config->log_file,
00647 "[WARNING] [%s:%d] Skip START to Radonline (Connection lost)",
00648 __FILE__, __LINE__);
00649 break;
00650 case MYSQL_RECONNECTION_FAILED:
00651 my_syslog (config->log_file,
00652 "[WARNING] [%s:%d] Skip START to Radonline (Reconnection failed)",
00653 __FILE__, __LINE__);
00654 break;
00655 case MYSQL_SQL_PROBLEM:
00656 my_syslog (config->log_file,
00657 "[ERROR] [%s:%d] Skip START to Radonline (SQL problem)",
00658 __FILE__, __LINE__);
00659 return DHCP_RADONLINE_MYSQL_SQL_PROBLEM;
00660 case MYSQL_UNEXPECTED_ERROR:
00661 my_syslog (config->log_file,
00662 "[ERROR] [%s:%d] Skip START to Radonline (Unexpected SQL error)",
00663 __FILE__, __LINE__);
00664 return DHCP_RADONLINE_MYSQL_UNEXPECTED_ERROR;
00665 }
00666
00667
00668 if ((packet->ctrl).dslam_data.vci != 37)
00669 {
00670 my_syslog (config->log_file,
00671 "[INFO] [%s:%d] MyDns(start)",
00672 __FILE__, __LINE__);
00673
00674 if (config->debug > 0)
00675 {
00676 my_syslog (config->log_file,
00677 "[DEBUG] [%s:%d] VCI=%d, therefore I send START to MyDns",
00678 __FILE__, __LINE__, (packet->ctrl).dslam_data.vci);
00679 }
00680
00681 rc = send_to_mydns (mysql_mydns,
00682 mysql_tables,
00683 ip,
00684 MYDNS_START,
00685 config);
00686
00687 switch (rc)
00688 {
00689 case MYSQL_REQUEST_SKIPED:
00690 my_syslog (config->log_file,
00691 "[WARNING] [%s:%d] Skip START to MyDns (request skiped)",
00692 __FILE__, __LINE__);
00693 break;
00694 case MYSQL_CONNECTION_LOST:
00695 my_syslog (config->log_file,
00696 "[WARNING] [%s:%d] Skip START to MyDns (Connection lost)",
00697 __FILE__, __LINE__);
00698 break;
00699 case MYSQL_RECONNECTION_FAILED:
00700 my_syslog (config->log_file,
00701 "[WARNING] [%s:%d] Skip START to MyDns (Reconnection failed)",
00702 __FILE__, __LINE__);
00703 break;
00704 case MYSQL_SQL_PROBLEM:
00705 my_syslog (config->log_file,
00706 "[ERROR] [%s:%d] Skip START to MyDns (SQL problem)",
00707 __FILE__, __LINE__);
00708 return DHCP_MYDNS_MYSQL_SQL_PROBLEM;
00709 case MYSQL_UNEXPECTED_ERROR:
00710 my_syslog (config->log_file,
00711 "[ERROR] [%s:%d] Skip START to MyDns (Unexpected SQL error)",
00712 __FILE__, __LINE__);
00713 return DHCP_MYDNS_MYSQL_UNEXPECTED_ERROR;
00714 }
00715 }
00716 else
00717 {
00718 if (config->debug > 0)
00719 { my_syslog (config->log_file, "[DEBUG] [%s:%d] VCI=%d - Do __NOT__ send START to MyDns!",
00720 __FILE__, __LINE__, (packet->ctrl).dslam_data.vci); }
00721 }
00722
00723 }
00724
00725
00726
00727
00728
00729 if (request_type == DHCPRELEASE)
00730 {
00731 char *ip;
00732
00733 my_syslog (config->log_file, "[INFO] [%s:%d] Got RELEASE", __FILE__, __LINE__);
00734
00735 if (tip == DYNAMIC_IP)
00736 {
00737 int rc;
00738
00739
00740
00741
00742
00743 (mysql_tables->ip_lease).vlan_id = packets_get_vlan_id(packet);
00744 (mysql_tables->pool).abonnes_id = (mysql_tables->abonnes).abonnes_id;
00745
00746 if (config->debug > 1)
00747 {
00748 my_syslog (config->log_file,
00749 "[DEBUG] [%s:%d] Try to find the dynamic IP for abonnes_id=%lu within vlan_id=%lu",
00750 __FILE__, __LINE__,
00751 (mysql_tables->pool).abonnes_id,
00752 (mysql_tables->ip_lease).vlan_id);
00753 }
00754
00755 rc = find_ip_in_vlan_pool (mysql_info_read_write,
00756 mysql_tables,
00757 config);
00758
00759 switch (rc)
00760 {
00761 case MYSQL_INTERFACE_REQUEST_SKIPED:
00762 my_syslog (config->log_file,
00763 "[WARNING] [%s:%d] Request skiped", __FILE__, __LINE__);
00764 return MYSQL_INTERFACE_REQUEST_SKIPED;
00765
00766 case MYSQL_INTERFACE_CONNECTION_LOST:
00767 my_syslog (config->log_file,
00768 "[WARNING] [%s:%d] Connection lost", __FILE__, __LINE__);
00769 return MYSQL_INTERFACE_CONNECTION_LOST;
00770
00771 case MYSQL_INTERFACE_RECONNECTION_FAILED:
00772 my_syslog (config->log_file,
00773 "[WARNING] [%s:%d] Could not reconnect with MySql server", __FILE__, __LINE__);
00774 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00775
00776 case MYSQL_INTERFACE_SQL_PROBLEM:
00777 my_syslog (config->log_file,
00778 "[ERROR] [%s:%d] Some SQL problem occured", __FILE__, __LINE__);
00779 return MYSQL_INTERFACE_SQL_PROBLEM;
00780
00781 case MYSQL_INTERFACE_MORE_THAN_ONE:
00782 my_syslog (config->log_file,
00783 "[ERROR] [%s:%d] Internal error: more that one dynamic IP found (should not happen!)",
00784 __FILE__, __LINE__);
00785 return MYSQL_INTERFACE_MORE_THAN_ONE;
00786
00787 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
00788 my_syslog (config->log_file,
00789 "[ERROR] [%s:%d] Unexpected error", __FILE__, __LINE__);
00790 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00791
00792 case MYSQL_INTERFACE_NO_TIMESTAMP:
00793 my_syslog (config->log_file,
00794 "[ERROR] [%s:%d] An error occured while getting timestamp", __FILE__, __LINE__);
00795 return MYSQL_INTERFACE_NO_TIMESTAMP;
00796
00797 case MYSQL_INTERFACE_NO_LEASE_ID:
00798 my_syslog (config->log_file,
00799 "[WARNING] [%s:%d] Can not find lease ID within the lease table", __FILE__, __LINE__);
00800 return MYSQL_INTERFACE_NO_LEASE_ID;
00801
00802 case MYSQL_INTERFACE_NO_IP_FOUND:
00803 my_syslog (config->log_file,
00804 "[WARNING] [%s:%d] Could not find abonne's dynamic IP (this is not a problem)",
00805 __FILE__, __LINE__);
00806 return DHCP_NO_DYNAMIC_IP_FOUND_RELEASE;
00807 }
00808
00809 if (config->debug > 1)
00810 {
00811 my_syslog (config->log_file, "[DEBUG] [%s:%d] Dynamic IP found is '%s' (pool_id=%lu)",
00812 __FILE__, __LINE__, (mysql_tables->pool).ip, (mysql_tables->pool).pool_id);
00813 }
00814
00815
00816
00817
00818
00819 if (config->debug > 1)
00820 {
00821 my_syslog (config->log_file,
00822 "[DEBUG] [%s,%d] Release found IP ip_lease_id=%lu and abonnes_id=%lu",
00823 __FILE__, __LINE__,
00824 (mysql_tables->pool).ip_lease_id,
00825 (mysql_tables->pool).abonnes_id);
00826 }
00827
00828 rc = release_ip_from_pool (mysql_info_read_write,
00829 mysql_tables,
00830 config);
00831
00832 switch (rc)
00833 {
00834 case MYSQL_INTERFACE_REQUEST_SKIPED:
00835 my_syslog (config->log_file,
00836 "[WARNING] [%s:%d] Request skiped", __FILE__, __LINE__);
00837 return MYSQL_INTERFACE_REQUEST_SKIPED;
00838
00839 case MYSQL_INTERFACE_CONNECTION_LOST:
00840 my_syslog (config->log_file,
00841 "[WARNING] [%s:%d] Connection lost", __FILE__, __LINE__);
00842 return MYSQL_INTERFACE_CONNECTION_LOST;
00843
00844 case MYSQL_INTERFACE_RECONNECTION_FAILED:
00845 my_syslog (config->log_file,
00846 "[WARNING] [%s:%d] Could not reconnect to the MySql server", __FILE__, __LINE__);
00847 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00848
00849 case MYSQL_INTERFACE_SQL_PROBLEM:
00850 my_syslog (config->log_file,
00851 "[ERROR] [%s:%d] Some SQL problem occured", __FILE__, __LINE__);
00852 return MYSQL_INTERFACE_SQL_PROBLEM;
00853
00854 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
00855 my_syslog (config->log_file,
00856 "[ERROR] [%s:%d] Unexpected error", __FILE__, __LINE__);
00857 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00858
00859 case MYSQL_INTERFACE_NO_TIMESTAMP:
00860 my_syslog (config->log_file,
00861 "[ERROR] [%s:%d] Could not get retrieve the UNIX timestamp from the MySql server",
00862 __FILE__, __LINE__);
00863 return MYSQL_INTERFACE_NO_TIMESTAMP;
00864 }
00865
00866 if (config->debug > 1)
00867 {
00868 my_syslog (config->log_file, "[DEBUG] [%s:%d] Dynamic IP '%s' (pool_id=%lu) freed",
00869 __FILE__, __LINE__, (mysql_tables->pool).ip, (mysql_tables->pool).pool_id);
00870 }
00871 }
00872
00873
00874
00875
00876
00877 if (tip == STATIC_IP) { ip = (mysql_tables->abonne_ip).ip; }
00878 else { ip = (mysql_tables->pool).ip; }
00879
00880
00881
00882
00883
00884 my_syslog (config->log_file, "[INFO] [%s:%d] Radonline(stop)",
00885 __FILE__, __LINE__);
00886
00887 rc = send_to_radonline (mysql_radonline,
00888 mysql_tables,
00889 ip,
00890 RADONLINE_STOP,
00891 config);
00892
00893 switch (rc)
00894 {
00895 case MYSQL_REQUEST_SKIPED:
00896 my_syslog (config->log_file,
00897 "[WARNING] [%s:%d] Skip STOP to Radonline (request skiped)",
00898 __FILE__, __LINE__);
00899 break;
00900 case MYSQL_CONNECTION_LOST:
00901 my_syslog (config->log_file,
00902 "[WARNING] [%s:%d] Skip STOP to Radonline (Connection lost)",
00903 __FILE__, __LINE__);
00904 break;
00905 case MYSQL_RECONNECTION_FAILED:
00906 my_syslog (config->log_file,
00907 "[WARNING] [%s:%d] Skip STOP to Radonline (Reconnection failed)",
00908 __FILE__, __LINE__);
00909 break;
00910 case MYSQL_SQL_PROBLEM:
00911 my_syslog (config->log_file,
00912 "[ERROR] [%s:%d] Skip STOP to Radonline (SQL problem)",
00913 __FILE__, __LINE__);
00914 return DHCP_RADONLINE_MYSQL_SQL_PROBLEM;
00915 case MYSQL_UNEXPECTED_ERROR:
00916 my_syslog (config->log_file,
00917 "[ERROR] [%s:%d] Skip STOP to Radonline (Unexpected SQL error)",
00918 __FILE__, __LINE__);
00919 return DHCP_RADONLINE_MYSQL_UNEXPECTED_ERROR;
00920 }
00921
00922
00923 if ((packet->ctrl).dslam_data.vci != 37)
00924 {
00925 my_syslog (config->log_file, "[INFO] [%s:%d] MyDns(stop)", __FILE__, __LINE__);
00926
00927 if (config->debug > 0)
00928 {
00929 my_syslog (config->log_file,
00930 "[DEBUG] [%s:%d] VCI=%d, Therefore I send STOP to MyDns",
00931 __FILE__, __LINE__, (packet->ctrl).dslam_data.vci);
00932 }
00933
00934 rc = send_to_mydns (mysql_mydns,
00935 mysql_tables,
00936 ip,
00937 MYDNS_STOP,
00938 config);
00939
00940 switch (rc)
00941 {
00942 case MYSQL_REQUEST_SKIPED:
00943 my_syslog (config->log_file,
00944 "[WARNING] [%s:%d] Skip STOP to MyDns (request skiped)",
00945 __FILE__, __LINE__);
00946 break;
00947 case MYSQL_CONNECTION_LOST:
00948 my_syslog (config->log_file,
00949 "[WARNING] [%s:%d] Skip STOP to MyDns (Connection lost)",
00950 __FILE__, __LINE__);
00951 break;
00952 case MYSQL_RECONNECTION_FAILED:
00953 my_syslog (config->log_file,
00954 "[WARNING] [%s:%d] Skip STOP to MyDns (Reconnection failed)",
00955 __FILE__, __LINE__);
00956 break;
00957 case MYSQL_SQL_PROBLEM:
00958 my_syslog (config->log_file,
00959 "[ERROR] [%s:%d] Skip STOP to MyDns (SQL problem)",
00960 __FILE__, __LINE__);
00961 return DHCP_MYDNS_MYSQL_SQL_PROBLEM;
00962 case MYSQL_UNEXPECTED_ERROR:
00963 my_syslog (config->log_file,
00964 "[ERROR] [%s:%d] Skip STOP to MyDns (Unexpected SQL error)",
00965 __FILE__, __LINE__);
00966 return DHCP_MYDNS_MYSQL_UNEXPECTED_ERROR;
00967 }
00968 }
00969 else
00970 {
00971 if (config->debug > 0)
00972 { my_syslog (config->log_file,
00973 "[DEBUG] [%s:%d] Wrong VCI (%d) - Do NOT send START to MyDns!",
00974 __FILE__, __LINE__, (packet->ctrl).dslam_data.vci); }
00975 }
00976 }
00977
00978
00979
00980
00981
00982 if (request_type == DHCPINFORM)
00983 {
00984 char *ip;
00985
00986 my_syslog (config->log_file, "[INFO] [%s:%d] Got INFORM", __FILE__, __LINE__);
00987
00988 if (tip == DYNAMIC_IP)
00989 {
00990 int rc;
00991
00992
00993
00994
00995
00996 (mysql_tables->ip_lease).vlan_id = packets_get_vlan_id(packet);
00997 (mysql_tables->pool).abonnes_id = (mysql_tables->abonnes).abonnes_id;
00998
00999 if (config->debug > 0)
01000 {
01001 my_syslog (config->log_file,
01002 "[DEBUG] [%s:%d] Try to find the dynamic IP for abonnes_id=%lu within vlan_id=%lu",
01003 __FILE__, __LINE__,
01004 (mysql_tables->pool).abonnes_id,
01005 (mysql_tables->ip_lease).vlan_id);
01006 }
01007
01008 rc = find_ip_in_vlan_pool (mysql_info_read_write,
01009 mysql_tables,
01010 config);
01011
01012 switch (rc)
01013 {
01014 case MYSQL_INTERFACE_REQUEST_SKIPED:
01015 my_syslog (config->log_file,
01016 "[WARNING] [%s:%d] Request skiped", __FILE__, __LINE__);
01017 return MYSQL_INTERFACE_REQUEST_SKIPED;
01018
01019 case MYSQL_INTERFACE_CONNECTION_LOST:
01020 my_syslog (config->log_file,
01021 "[WARNING] [%s:%d] Connection lost", __FILE__, __LINE__);
01022 return MYSQL_INTERFACE_CONNECTION_LOST;
01023
01024 case MYSQL_INTERFACE_RECONNECTION_FAILED:
01025 my_syslog (config->log_file,
01026 "[WARNING] [%s:%d] Could not reconnect with MySql server", __FILE__, __LINE__);
01027 return MYSQL_INTERFACE_RECONNECTION_FAILED;
01028
01029 case MYSQL_INTERFACE_SQL_PROBLEM:
01030 my_syslog (config->log_file,
01031 "[ERROR] [%s:%d] Some SQL problem occured", __FILE__, __LINE__);
01032 return MYSQL_INTERFACE_SQL_PROBLEM;
01033
01034 case MYSQL_INTERFACE_MORE_THAN_ONE:
01035 my_syslog (config->log_file,
01036 "[ERROR] [%s:%d] Internal error: more that one dynamic IP found (should not happen!)",
01037 __FILE__, __LINE__);
01038 return MYSQL_INTERFACE_MORE_THAN_ONE;
01039
01040 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
01041 my_syslog (config->log_file,
01042 "[ERROR] [%s:%d] Unexpected error", __FILE__, __LINE__);
01043 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
01044
01045 case MYSQL_INTERFACE_NO_TIMESTAMP:
01046 my_syslog (config->log_file,
01047 "[ERROR] [%s:%d] An error occured while getting timestamp", __FILE__, __LINE__);
01048 return MYSQL_INTERFACE_NO_TIMESTAMP;
01049
01050 case MYSQL_INTERFACE_NO_LEASE_ID:
01051 my_syslog (config->log_file,
01052 "[WARNING] [%s:%d] Could not find lease ID", __FILE__, __LINE__);
01053 return MYSQL_INTERFACE_NO_LEASE_ID;
01054
01055 case MYSQL_INTERFACE_NO_IP_FOUND:
01056 my_syslog (config->log_file,
01057 "[WARNING] [%s:%d] Could not find the abonne's dynamic IP (this is not a problem)",
01058 __FILE__, __LINE__);
01059 return DHCP_NO_DYNAMIC_IP_FOUND_RELEASE;
01060 }
01061
01062 if (config->debug > 0)
01063 {
01064 my_syslog (config->log_file, "[DEBUG] [%s:%d] Dynamic IP found is '%s' (pool_id=%lu)",
01065 __FILE__, __LINE__, (mysql_tables->pool).ip, (mysql_tables->pool).pool_id);
01066 }
01067 }
01068
01069
01070
01071
01072
01073 if (tip == STATIC_IP) { ip = (mysql_tables->abonne_ip).ip; }
01074 else { ip = (mysql_tables->pool).ip; }
01075
01076 my_syslog (config->log_file, "[INFO] [%s:%d] Sending ACK", __FILE__, __LINE__);
01077
01078 rc = reply_to_inform (
01079 packet,
01080 mysql_tables,
01081 broadcast,
01082 server_ip,
01083 sck,
01084 client_address
01085 );
01086
01087 }
01088
01089 return 0;
01090 }
01091
01092
01093
01094
01095
01096
01097
01098