00001
00002
00003
00004
00005 #include <string.h>
00006 #include <stdio.h>
00007 #include "logistic.h"
00008 #include "mysql_interface.h"
00009 #include "modem.h"
00010 #include "logging.h"
00011
00012
00013
00014
00015
00016 static int my_fake_syslog (const char *file, const char * fmt,...) { return 0; }
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 int look_up_logistic (struct smysql *mysql_info_logistic,
00042 struct smysql *mysql_info_abonnes,
00043 struct mysql_tables *mysql_tables,
00044 struct global_config *config,
00045 struct dhcp_packet *packet_in)
00046 {
00047 char *mac_address;
00048 int rc, mcaddress_found;
00049 int (*my_syslog_abonnes)(const char *file, const char * fmt,...);
00050 int (*my_syslog_logistic)(const char *file, const char * fmt,...);
00051 int request_type;
00052
00053
00054 if ((mysql_info_abonnes->my_syslog != NULL) && (mysql_info_abonnes->log_file[0] != 0))
00055 { my_syslog_abonnes = mysql_info_abonnes->my_syslog; } else { my_syslog_abonnes = my_fake_syslog; }
00056
00057 if ((mysql_info_logistic->my_syslog != NULL) && (mysql_info_logistic->log_file[0] != 0))
00058 { my_syslog_logistic = mysql_info_logistic->my_syslog; } else { my_syslog_logistic = my_fake_syslog; }
00059
00060 request_type = packets_get_message_type(packet_in);
00061
00062
00063
00064
00065
00066
00067 if (config->debug > 1)
00068 {
00069 my_syslog (config->log_file,
00070 "[DEBUG] [%s,%d] Modem's manufacturor is = '%s'",
00071 __FILE__, __LINE__,
00072 id_manufacturor_to_string(mysql_tables->logistic.modem_manufacturor));
00073 }
00074
00075 mac_address = calculate_modem_mac_address (packet_in, mysql_tables->logistic.modem_manufacturor);
00076 strncpy (mysql_tables->logistic.MAC_ADDRESS, mac_address, LOGISTIC_MAC_ADDRESS_SIZE-1);
00077
00078 if (config->debug > 1)
00079 {
00080 my_syslog (config->log_file,
00081 "[DEBUG] [%s,%d] Calculated MAC address = '%s'",
00082 __FILE__, __LINE__, mac_address);
00083 }
00084
00085
00086
00087
00088
00089 snprintf (mysql_tables->logistic.LOGIN_MODEM,
00090 LOGIN_MODEM_SIZE,
00091 "%s@auto.hautdebit",
00092 mysql_tables->logistic.MAC_ADDRESS);
00093
00094 if (config->debug > 1)
00095 {
00096 my_syslog (config->log_file,
00097 "[DEBUG] [%s,%d] Login modem = '%s'",
00098 __FILE__, __LINE__, mysql_tables->logistic.LOGIN_MODEM);
00099 }
00100
00101
00102
00103
00104
00105 mcaddress_found = load_logistic (mysql_info_logistic, mysql_tables, config);
00106
00107 switch (mcaddress_found)
00108 {
00109 case MYSQL_INTERFACE_REQUEST_SKIPED:
00110 my_syslog (config->log_file,
00111 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00112 return MYSQL_INTERFACE_REQUEST_SKIPED;
00113 case MYSQL_INTERFACE_CONNECTION_LOST:
00114 my_syslog (config->log_file,
00115 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00116 return MYSQL_INTERFACE_CONNECTION_LOST;
00117 case MYSQL_INTERFACE_RECONNECTION_FAILED:
00118 my_syslog (config->log_file,
00119 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00120 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00121 case MYSQL_INTERFACE_SQL_PROBLEM:
00122 my_syslog (config->log_file,
00123 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00124 return MYSQL_INTERFACE_SQL_PROBLEM;
00125 case MYSQL_INTERFACE_MORE_THAN_ONE:
00126 my_syslog (config->log_file,
00127 "[ERROR] [%s,%d] More than one record MAC_ADDRESS='%s'",
00128 __FILE__, __LINE__, mysql_tables->logistic.MAC_ADDRESS);
00129 return MYSQL_INTERFACE_MORE_THAN_ONE;
00130 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
00131 my_syslog (config->log_file,
00132 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00133 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00134 case MYSQL_INTERFACE_NOT_FOUND: break;
00135 }
00136
00137
00138
00139
00140
00141 if (mcaddress_found == MYSQL_INTERFACE_NOT_FOUND)
00142 {
00143 if (config->debug > 1)
00144 {
00145 my_syslog (config->log_file,
00146 "[DEBUG] [%s,%d] MAC address (%s) not found in LOGISTIC_RADIUS",
00147 __FILE__, __LINE__, mac_address);
00148 }
00149
00150
00151
00152
00153
00154 my_syslog (config->log_file,
00155 "[WARNING] [%s,%d] user (node_id=%s, shelf=%u, numero_port=%u, numero_slot=%u, login_radius=%s) with (original - from DHCP packet) MAC address=%s not found in LOGISTIC_RADIUS! Manufacturor is '%s'",
00156 __FILE__, __LINE__,
00157 mysql_tables->abonnes.node_id,
00158 mysql_tables->abonnes.shelf,
00159 mysql_tables->abonnes.numero_port,
00160 mysql_tables->abonnes.numero_slot,
00161 mysql_tables->abonnes.login_radius,
00162 mac_address,
00163 id_manufacturor_to_string(mysql_tables->logistic.modem_manufacturor));
00164
00165
00166
00167
00168
00169
00170 if (config->debug > 1)
00171 {
00172 my_syslog (config->log_file,
00173 "[DEBUG] [%s,%d] Insert new MAC address (%s) into LOGISTIC_RADIUS / LOGIN_MODEM=%s",
00174 __FILE__, __LINE__, mac_address, mysql_tables->logistic.LOGIN_MODEM);
00175 }
00176
00177
00178
00179 rc = signal_unknown_mac_address (mysql_info_logistic,
00180 mysql_tables,
00181 config);
00182
00183 switch (rc)
00184 {
00185 case MYSQL_INTERFACE_REQUEST_SKIPED:
00186 my_syslog (config->log_file,
00187 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00188 return MYSQL_INTERFACE_REQUEST_SKIPED;
00189 case MYSQL_INTERFACE_CONNECTION_LOST:
00190 my_syslog (config->log_file,
00191 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00192 return MYSQL_INTERFACE_CONNECTION_LOST;
00193 case MYSQL_INTERFACE_RECONNECTION_FAILED:
00194 my_syslog (config->log_file,
00195 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00196 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00197 case MYSQL_INTERFACE_SQL_PROBLEM:
00198 my_syslog (config->log_file,
00199 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00200 return MYSQL_INTERFACE_SQL_PROBLEM;
00201 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
00202 my_syslog (config->log_file,
00203 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00204 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00205 }
00206
00207
00208
00209
00210
00211 if (config->debug > 1)
00212 { my_syslog (config->log_file, "[DEBUG] [%s,%d] Blackhole the client", __FILE__, __LINE__); }
00213
00214 rc = blackhole_abonne (mysql_info_abonnes,
00215 mysql_tables,
00216 config);
00217
00218 switch (rc)
00219 {
00220 case MYSQL_INTERFACE_REQUEST_SKIPED:
00221 my_syslog (config->log_file,
00222 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00223 return MYSQL_INTERFACE_REQUEST_SKIPED;
00224 case MYSQL_INTERFACE_CONNECTION_LOST:
00225 my_syslog (config->log_file,
00226 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00227 return MYSQL_INTERFACE_CONNECTION_LOST;
00228 case MYSQL_INTERFACE_RECONNECTION_FAILED:
00229 my_syslog (config->log_file,
00230 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00231 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00232 case MYSQL_INTERFACE_SQL_PROBLEM:
00233 my_syslog (config->log_file,
00234 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00235 return MYSQL_INTERFACE_SQL_PROBLEM;
00236 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
00237 my_syslog (config->log_file,
00238 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00239 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00240 case MYSQL_INTERFACE_MORE_THAN_ONE:
00241 my_syslog (config->log_file,
00242 "[ERROR] [%s,%d] More than one record abonnes_id='%lu' (login radius='%s')",
00243 __FILE__, __LINE__,
00244 mysql_tables->abonnes.abonnes_id,
00245 mysql_tables->abonnes.login_radius);
00246 return MYSQL_INTERFACE_MORE_THAN_ONE;
00247 case MYSQL_INTERFACE_NOT_FOUND:
00248 my_syslog (config->log_file,
00249 "[ERROR] [%s,%d] No record found with abonnes_id='%lu' (login radius='%s')",
00250 __FILE__, __LINE__,
00251 mysql_tables->abonnes.abonnes_id,
00252 mysql_tables->abonnes.login_radius);
00253 return MYSQL_INTERFACE_NOT_FOUND;
00254 }
00255
00256
00257
00258
00259
00260
00261 strncpy (mysql_tables->abonnes.profile,
00262 "autoconfblackhole",
00263 OPTIONNAL_PROFILE_SIZE);
00264
00265
00266
00267
00268
00269 memset ((void*)mysql_tables->logistic.radonline_acct_identifier, 0, ACCT_IDENTIFIER_SIZE);
00270 memset ((void*)mysql_tables->logistic.radonline_user_name, 0, LOGIN_RADIUS_SIZE);
00271 memset ((void*)mysql_tables->logistic.login_modem, 0, LOGISTIC_LOGIN_MODEM_SIZE);
00272
00273 strncpy (mysql_tables->logistic.radonline_acct_identifier,
00274 "Auth-BH-Autoconf",
00275 ACCT_IDENTIFIER_SIZE-1);
00276
00277 strncpy (mysql_tables->logistic.radonline_user_name,
00278 mysql_tables->logistic.LOGIN_MODEM,
00279 LOGIN_RADIUS_SIZE-1);
00280
00281 strncpy (mysql_tables->logistic.login_modem,
00282 mysql_tables->logistic.LOGIN_MODEM,
00283 LOGISTIC_LOGIN_MODEM_SIZE-1);
00284
00285 if (config->debug > 1)
00286 {
00287 my_syslog (config->log_file, "[DEBUG] [%s,%d] radonline_acct_identifier='%s'",
00288 __FILE__, __LINE__, mysql_tables->logistic.radonline_acct_identifier);
00289
00290 my_syslog (config->log_file, "[DEBUG] [%s,%d] radonline_user_name='%s'",
00291 __FILE__, __LINE__, mysql_tables->logistic.radonline_user_name);
00292
00293 my_syslog (config->log_file, "[DEBUG] [%s,%d] login_modem='%s'",
00294 __FILE__, __LINE__, mysql_tables->logistic.login_modem);
00295 }
00296
00297 return 0;
00298 }
00299
00300
00301
00302
00303
00304 if (mysql_tables->logistic.FLAG_CHECK_RADIUS == 1)
00305 {
00306 if (config->debug > 1)
00307 {
00308 my_syslog (config->log_file,
00309 "[DEBUG] [%s,%d] Modem already checked, nothing to do (Radius login='%s')",
00310 __FILE__, __LINE__, mysql_tables->logistic.RADIUS_LOGIN);
00311 }
00312
00313 return 0;
00314 }
00315
00316
00317
00318
00319
00320 if (strcmp (mysql_tables->logistic.RADIUS_LOGIN, mysql_tables->abonnes.login_radius) == 0)
00321 {
00322 if (config->debug > 1)
00323 {
00324 my_syslog (config->log_file,
00325 "[DEBUG] [%s,%d] First time modem check - Radius login identical (%s)",
00326 __FILE__, __LINE__, mysql_tables->abonnes.login_radius);
00327
00328 my_syslog (config->log_file,
00329 "[DEBUG] [%s,%d] Set flag FLAG_CHECK_RADIUS to value 1",
00330 __FILE__, __LINE__);
00331 }
00332
00333 rc = set_flag_check_radius (mysql_info_logistic,
00334 mysql_tables,
00335 config);
00336
00337 switch (rc)
00338 {
00339 case MYSQL_INTERFACE_REQUEST_SKIPED:
00340 my_syslog (config->log_file,
00341 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00342 return MYSQL_INTERFACE_REQUEST_SKIPED;
00343 case MYSQL_INTERFACE_CONNECTION_LOST:
00344 my_syslog (config->log_file,
00345 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00346 return MYSQL_INTERFACE_CONNECTION_LOST;
00347 case MYSQL_INTERFACE_RECONNECTION_FAILED:
00348 my_syslog (config->log_file,
00349 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00350 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00351 case MYSQL_INTERFACE_SQL_PROBLEM:
00352 my_syslog (config->log_file,
00353 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00354 return MYSQL_INTERFACE_SQL_PROBLEM;
00355 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
00356 my_syslog (config->log_file,
00357 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00358 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00359 case MYSQL_INTERFACE_NOT_FOUND:
00360 my_syslog (config->log_file,
00361 "[ERROR] [%s,%d] Record MAC address='%s' not found",
00362 __FILE__, __LINE__, mysql_tables->logistic.MAC_ADDRESS);
00363 return MYSQL_INTERFACE_NOT_FOUND;
00364 case MYSQL_INTERFACE_MORE_THAN_ONE:
00365 my_syslog (config->log_file,
00366 "[ERROR] [%s,%d] More than one record found MAC address='%s'",
00367 __FILE__, __LINE__, mysql_tables->logistic.MAC_ADDRESS);
00368 return MYSQL_INTERFACE_MORE_THAN_ONE;
00369 }
00370
00371 return 0;
00372 }
00373
00374
00375
00376
00377
00378
00379 my_syslog (config->log_file,
00380 "[WARNING] [%s,%d] user (node_id=%s, shelf=%u, numero_port=%u, numero_slot=%u, login_radius=%s) with MAC address=%s => Radius login not identical (LOGISTIC_RADIUS='%s' and abonnes='%s' and Manufacturor is '%s')",
00381 __FILE__, __LINE__,
00382 mysql_tables->abonnes.node_id,
00383 mysql_tables->abonnes.shelf,
00384 mysql_tables->abonnes.numero_port,
00385 mysql_tables->abonnes.numero_slot,
00386 mysql_tables->abonnes.login_radius,
00387 mac_address,
00388 mysql_tables->logistic.RADIUS_LOGIN,
00389 mysql_tables->abonnes.login_radius,
00390 id_manufacturor_to_string(mysql_tables->logistic.modem_manufacturor));
00391
00392
00393
00394
00395
00396 memset ((void*)mysql_tables->logistic.radonline_acct_identifier, 0, ACCT_IDENTIFIER_SIZE);
00397 memset ((void*)mysql_tables->logistic.radonline_user_name, 0, LOGIN_RADIUS_SIZE);
00398
00399 strncpy (mysql_tables->logistic.radonline_acct_identifier,
00400 "Auth-BH-Autoconf",
00401 ACCT_IDENTIFIER_SIZE-1);
00402
00403 strncpy (mysql_tables->logistic.radonline_user_name,
00404 mysql_tables->logistic.LOGIN_MODEM,
00405 LOGIN_RADIUS_SIZE-1);
00406
00407 strncpy (mysql_tables->logistic.login_modem,
00408 mysql_tables->logistic.LOGIN_MODEM,
00409 LOGISTIC_LOGIN_MODEM_SIZE-1);
00410
00411 if (config->debug > 1)
00412 {
00413 my_syslog (config->log_file, "[DEBUG] [%s,%d] radonline_acct_identifier='%s'",
00414 __FILE__, __LINE__, mysql_tables->logistic.radonline_acct_identifier);
00415
00416 my_syslog (config->log_file, "[DEBUG] [%s,%d] radonline_user_name='%s'",
00417 __FILE__, __LINE__, mysql_tables->logistic.radonline_user_name);
00418
00419 my_syslog (config->log_file, "[DEBUG] [%s,%d] login_modem='%s'",
00420 __FILE__, __LINE__, mysql_tables->logistic.login_modem);
00421 }
00422
00423
00424
00425
00426
00427 if (config->debug > 1)
00428 { my_syslog (config->log_file, "[DEBUG] [%s,%d] Blackhole the client", __FILE__, __LINE__); }
00429
00430 rc = blackhole_abonne (mysql_info_abonnes,
00431 mysql_tables,
00432 config);
00433
00434 switch (rc)
00435 {
00436 case MYSQL_INTERFACE_REQUEST_SKIPED:
00437 my_syslog (config->log_file,
00438 "[WARNING] [%s,%d] Request skiped", __FILE__, __LINE__);
00439 return MYSQL_INTERFACE_REQUEST_SKIPED;
00440 case MYSQL_INTERFACE_CONNECTION_LOST:
00441 my_syslog (config->log_file,
00442 "[WARNING] [%s,%d] Coonection lost", __FILE__, __LINE__);
00443 return MYSQL_INTERFACE_CONNECTION_LOST;
00444 case MYSQL_INTERFACE_RECONNECTION_FAILED:
00445 my_syslog (config->log_file,
00446 "[WARNING] [%s,%d] Could not reconnect", __FILE__, __LINE__);
00447 return MYSQL_INTERFACE_RECONNECTION_FAILED;
00448 case MYSQL_INTERFACE_SQL_PROBLEM:
00449 my_syslog (config->log_file,
00450 "[ERROR] [%s,%d] Some SQL error", __FILE__, __LINE__);
00451 return MYSQL_INTERFACE_SQL_PROBLEM;
00452 case MYSQL_INTERFACE_UNEXPECTED_ERROR:
00453 my_syslog (config->log_file,
00454 "[ERROR] [%s,%d] Unexpected error", __FILE__, __LINE__);
00455 return MYSQL_INTERFACE_UNEXPECTED_ERROR;
00456 case MYSQL_INTERFACE_MORE_THAN_ONE:
00457 my_syslog (config->log_file,
00458 "[ERROR] [%s,%d] More than one record abonnes_id='%lu' (login radius='%s')",
00459 __FILE__, __LINE__,
00460 mysql_tables->abonnes.abonnes_id,
00461 mysql_tables->abonnes.login_radius);
00462 return MYSQL_INTERFACE_MORE_THAN_ONE;
00463 case MYSQL_INTERFACE_NOT_FOUND:
00464 my_syslog (config->log_file,
00465 "[ERROR] [%s,%d] No record found with abonnes_id='%lu' (login radius='%s')",
00466 __FILE__, __LINE__,
00467 mysql_tables->abonnes.abonnes_id,
00468 mysql_tables->abonnes.login_radius);
00469 return MYSQL_INTERFACE_NOT_FOUND;
00470 }
00471
00472
00473
00474
00475
00476
00477
00478 strncpy (mysql_tables->abonnes.profile,
00479 "autoconfblackhole",
00480 OPTIONNAL_PROFILE_SIZE);
00481
00482 return 0;
00483 }
00484
00485
00486
00487