Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

dhcp.c

Go to the documentation of this file.
00001 /*! \file dhcp.c
00002     Main entry point for the DHCP server.
00003  */
00004 
00005 
00006 #include <stdio.h>
00007 #include <string.h>
00008 #include <errno.h>
00009 #include <sys/types.h>
00010 #include <sys/stat.h>
00011 #include <fcntl.h>
00012 #include <unistd.h>
00013 #include <pwd.h>
00014 #include <grp.h>
00015 #include <time.h>
00016 
00017 #ifdef READ_PACKET_FROM_FILE
00018   #include <sys/stat.h>
00019   #include <fcntl.h>
00020   #include <dirent.h>
00021 #endif
00022 
00023 #ifdef DUMP_PACKETS
00024   #include <sys/stat.h>
00025   #include <fcntl.h>
00026 #endif
00027 
00028 #include "dhcp.h"
00029 #include "modem.h"
00030 #include "sockets.h"
00031 #include "server_config.h"
00032 #include "mysql_header.h"
00033 #include "mysql_interface.h"
00034 #include "logging.h"
00035 #include "deamon.h"
00036 #include "logistic.h"
00037 #include "packets_data.h"
00038 #include "conversion.h"
00039 #include "packets.h"
00040 #include "find_ip_and_reply.h"
00041 #include "packets_operations.h"
00042 
00043 #ifdef READ_PACKET_FROM_FILE
00044   #define INPUT_PACKET_DIRECTORY        "/tmp/dhcp"
00045   #define INPUT_PACKET_FILE_NAME_SIZE   2048
00046 #endif
00047 
00048 /*! \brief Last MySql error message. This variable is defined in the file 'mysql.c'.
00049  */
00050 
00051 extern char mysql_error_str[MYSQL_MAX_ERROR_SIZE];
00052 
00053 /*! \brief Last MySql error code. This variable is defined in the file 'mysql.c'.
00054  */
00055 
00056 extern int mysql_error_errno;
00057 
00058 /*! \brief This structure contains the global server configuration.
00059            It is defined in the C file 'configuration.c'.
00060  */
00061 
00062 extern struct global_config configuration_globale;
00063 
00064 /*! \brief This structure contains the configuration for the connection to the local DHCP database.
00065            This database is access only for READ operations.
00066  */
00067 
00068 static struct smysql conf_mysql_dhcp_read_only;
00069 
00070 /*! \brief This structure contains the configuration for the connection to the POOL database.
00071            This database contains the pool of dynamic IP addresses.
00072            It is accessed for READ and WRITE operations.
00073  */
00074 
00075 static struct smysql conf_mysql_dhcp_read_write;
00076 
00077 /*! \brief This structure contains the configuration for the connection to the Radonline database.
00078  */
00079 
00080 static struct smysql conf_mysql_radonline;
00081 
00082 /*! \brief This structure contains the configuration for the connection to the Mydns database.
00083  */
00084 
00085 static struct smysql conf_mysql_mydns;
00086 
00087 /*! \brief This structure contains the configuration for the connection to the Logistic database.
00088  */
00089 
00090 static struct smysql conf_mysql_logistic;
00091 
00092 /*! \brief This array contains the configuration tags associated to the local DHCP database
00093            (read only database).
00094  */
00095 
00096 static char *tags_read[MYSQL_CONFIGURATION_TAG_NUMBER] =
00097        {
00098          "mysql-host-dhcp-read",
00099          "mysql-user-dhcp-read",
00100          "mysql-passwd-dhcp-read",
00101          "mysql-db-dhcp-read",
00102          "mysql-port-dhcp-read",
00103          "mysql-socket-dhcp-read",
00104          "mysql-retry-dhcp-read",
00105          "mysql-timeout-dhcp-read",
00106          "mysql-sleep-dhcp-read",
00107          "mysql-debug-dhcp-read",
00108          "mysql-log-file-dhcp-read",
00109          "mysql-reconnection-delay-dhcp-read"
00110        };
00111 
00112 /*! \brief This array contains the configuration tags associated to the POOL DHCP database.
00113            (read/write database).
00114  */
00115 
00116 static char *tags_read_write[MYSQL_CONFIGURATION_TAG_NUMBER] =
00117        {
00118          "mysql-host-dhcp-read-write",
00119          "mysql-user-dhcp-read-write",
00120          "mysql-passwd-dhcp-read-write",
00121          "mysql-db-dhcp-read-write",
00122          "mysql-port-dhcp-read-write",
00123          "mysql-socket-dhcp-read-write",
00124          "mysql-retry-dhcp-read-write",
00125          "mysql-timeout-dhcp-read-write",
00126          "mysql-sleep-dhcp-read-write",
00127          "mysql-debug-dhcp-read-write",
00128          "mysql-log-file-dhcp-read-write",
00129          "mysql-reconnection-delay-dhcp-read-write"
00130        };
00131 
00132 /*! \brief This array contains the configuration tags associated to the radonline database.
00133  */
00134 
00135 static char *tags_radonline[MYSQL_CONFIGURATION_TAG_NUMBER] =
00136        {
00137          "mysql-host-radonline",
00138          "mysql-user-radonline",
00139          "mysql-passwd-radonline",
00140          "mysql-db-radonline",
00141          "mysql-port-radonline",
00142          "mysql-socket-radonline",
00143          "mysql-retry-radonline",
00144          "mysql-timeout-radonline",
00145          "mysql-sleep-radonline",
00146          "mysql-debug-radonline",
00147          "mysql-log-file-radonline",
00148          "mysql-reconnection-delay-radonline"
00149        };
00150 
00151 /*! \brief This array contains the configuration tags associated to the mydns database.
00152  */
00153 
00154 static char *tags_mydns[MYSQL_CONFIGURATION_TAG_NUMBER] =
00155        {
00156          "mysql-host-mydns",
00157          "mysql-user-mydns",
00158          "mysql-passwd-mydns",
00159          "mysql-db-mydns",
00160          "mysql-port-mydns",
00161          "mysql-socket-mydns",
00162          "mysql-retry-mydns",
00163          "mysql-timeout-mydns",
00164          "mysql-sleep-mydns",
00165          "mysql-debug-mydns",
00166          "mysql-log-file-mydns",
00167          "mysql-reconnection-delay-mydns"
00168        };
00169 
00170 /*! \brief This array contains the configuration tags associated to the Logistic database.
00171  */
00172 
00173 static char *tags_logistic[MYSQL_CONFIGURATION_TAG_NUMBER] =
00174        {
00175          "mysql-host-logistic",
00176          "mysql-user-logistic",
00177          "mysql-passwd-logistic",
00178          "mysql-db-logistic",
00179          "mysql-port-logistic",
00180          "mysql-socket-logistic",
00181          "mysql-retry-logistic",
00182          "mysql-timeout-logistic",
00183          "mysql-sleep-logistic",
00184          "mysql-debug-logistic",
00185          "mysql-log-file-logistic",
00186          "mysql-reconnection-delay-logistic"
00187        };
00188 
00189 /*! \brief Build information. The tags __DATE__ and __HOST__ will be replaced by the output of commands
00190            'date' and 'uname -a'.
00191  */
00192 
00193 #define BUILD "This binary was build the __DATE__ on __HOST__"
00194 
00195 /*! \brief CVS tags for all sources.
00196  */
00197 
00198 #define CVS_TAGS "__CVSTAGS__"
00199 
00200 
00201 #ifdef XID_FILTERING
00202   #define BUFFSIZE 32
00203   int packet_testing (unsigned long int xid);
00204 #endif
00205 
00206 
00207 #ifdef TEST_MYSQL_NOW
00208 
00209 #define MTSQL_TESTING(n,s) \
00210         if (mtest == n) \
00211         { my_syslog (configuration_globale.log_file, "[MYSQL TESTING] [%s:%d] Step %d (%s), wait 15 secondes", \
00212                      __FILE__, __LINE__, n, s); sleep(15); }
00213 #else
00214 
00215 #define MTSQL_TESTING(n,s)
00216 
00217 #endif
00218 
00219 
00220 
00221 static void dump_packet_hexa (void* packet, int size, char* file);
00222 
00223 /*! \brief File descriptor associated to the file used to synchronize access to the dump file.
00224  */
00225 
00226 int dump_sync_fd = 0;
00227 
00228 /*! \brief Main entry point for the DHCP server.
00229     \author Denis BEURIVE
00230  */
00231 
00232 int main (int argc, char **argv)
00233 {
00234   int                    sck, mess_size, adress_size, rc;
00235 
00236   #ifdef TEST_MYSQL_NOW
00237      int                 mtest;
00238   #endif
00239 
00240   #ifdef DUMP_PACKETS
00241      int                 dumpfd;
00242   #endif
00243 
00244   #ifdef READ_PACKET_FROM_FILE
00245      char                input_packet_file_name[INPUT_PACKET_FILE_NAME_SIZE];
00246      struct dirent       *input_packet_from_dir;
00247      DIR                 *input_directory;
00248      int                 packet_file;
00249   #endif
00250 
00251   struct dhcp_packet     packet_in;
00252   char                   interface[IFNAMSIZ], *error;
00253   struct sockaddr_in     addr_server, addr_original;
00254   unsigned long int      broadcast, netmask, server_ip;
00255   FILE                   *pid_file;
00256   pid_t                  pid;
00257   struct passwd          *passwords;
00258   struct group           *groups;
00259   gid_t                  grp_id;
00260   uid_t                  user_id;
00261   struct mysql_tables    mysql_tables;
00262   int                    modem_manufacturor;
00263 
00264 
00265   fprintf (stdout, "%s\n\n", BUILD);
00266   fprintf (stdout, "%s\n\n", CVS_TAGS);
00267 
00268   #ifdef READ_PACKET_FROM_FILE
00269 
00270      fprintf (stdout, "WARNING !!!!\n\n");
00271      fprintf (stdout, "This version of the DHCP server has been compiled with the option ");
00272      fprintf (stdout, "READ_PACKET_FROM_FILE! This means that it will __NOT__ listen to ");
00273      fprintf (stdout, "the network. It will load data from the directory <%s>\n\n",
00274               INPUT_PACKET_DIRECTORY);
00275 
00276   #endif
00277 
00278   /* ------------------------------------------------ */
00279   /* Check the command line                           */
00280   /* ------------------------------------------------ */
00281 
00282   #ifndef TEST_MYSQL_NOW
00283   if (argc != 2)
00284   {
00285     fprintf (stderr, "Usage: mydhcpd <path to configuration file>\n");
00286     fprintf (stderr, "       Log tag is [session ID] [mac address] [DSLAM's ID]\n");
00287     fprintf (stderr, "       session ID: Refers to a client's request.\n");
00288     fprintf (stderr, "       mac address: Mac address sent by the modem.\n");
00289     fprintf (stderr, "       DSLAM's ID: node/shelf/slot/port/vci/vlanID/gateway.\n\n");
00290     fprintf (stderr, "       CSV structure is:\n\n");
00291 
00292     fprintf (stderr, "       1  Date\n");
00293     fprintf (stderr, "       2  Auto increment\n");
00294     fprintf (stderr, "       3  Host name\n");
00295     fprintf (stderr, "       4  Direction (IN or OUT)\n");
00296     fprintf (stderr, "       5  Sender's IP address (if direction is IN)\n");
00297     fprintf (stderr, "       6  Sender's TCP port (if direction is IN)\n");
00298     fprintf (stderr, "       7  Receiver's IP address (if direction is OUT)\n");
00299     fprintf (stderr, "       8  Receiver's TCP port (if direction is OUT)\n");
00300     fprintf (stderr, "       9  Type of DHCP request\n");
00301     fprintf (stderr, "       10 Number of bytes of the UDP packet\n");
00302     fprintf (stderr, "       11 Opcode\n");
00303     fprintf (stderr, "       12 Hardware address type\n");
00304     fprintf (stderr, "       13 Hardware address length\n");
00305     fprintf (stderr, "       14 Hop count\n");
00306     fprintf (stderr, "       15 Transaction ID\n");
00307     fprintf (stderr, "       16 Ellapsed time\n");
00308     fprintf (stderr, "       17 Flags\n");
00309     fprintf (stderr, "       18 Client's IP address, as defined in the DHCP packet\n");
00310     fprintf (stderr, "       19 Your IP address, as defined in the DHCP packet\n"); 
00311     fprintf (stderr, "       20 Server IP address, as defined in the DHCP packet\n");
00312     fprintf (stderr, "       21 Gateway IP address, as defined in the DHCP packet\n");
00313     fprintf (stderr, "       22 Client's hardware address\n"); 
00314     fprintf (stderr, "       23 Server's host name\n");
00315     fprintf (stderr, "       24 Boot file name\n");
00316     fprintf (stderr, "       25 Modem's constructor\n");
00317     fprintf (stderr, "       26 82\n");
00318     fprintf (stderr, "       27 vendor ID\n");
00319     fprintf (stderr, "       28 port type\n");
00320     fprintf (stderr, "       29 version\n");
00321     fprintf (stderr, "       30 vlan ID\n");
00322     fprintf (stderr, "       31 nas mac\n");
00323     fprintf (stderr, "       32 nas IP\n");
00324     fprintf (stderr, "       33 node ID\n");
00325     fprintf (stderr, "       34 shelf\n");
00326     fprintf (stderr, "       35 slot\n");
00327     fprintf (stderr, "       36 port\n");
00328     fprintf (stderr, "       37 VPI\n");
00329     fprintf (stderr, "       38 VCI\n");
00330     fprintf (stderr, "       39 vendor\n");
00331     fprintf (stderr, "       40 Subnet (option 1)\n");
00332     fprintf (stderr, "       41 Router (option 3)\n");
00333     fprintf (stderr, "       42 Domain name (option 15)\n");
00334     fprintf (stderr, "       43 DNS (option 6)\n");
00335     fprintf (stderr, "       44 Option code|Literal description|Option value\n");
00336     fprintf (stderr, "       45 Option code|Literal description|Option value\n");
00337     fprintf (stderr, "       ...\n\n");
00338     return 1;
00339   }
00340   #else
00341   if (argc != 3)
00342   {
00343     fprintf (stderr, "This binary is compiled for MySql testing\n\n");
00344     fprintf (stderr, "Usage: mydhcpd <path to configuration file> <test ID>\n");
00345     return 1;
00346   }
00347 
00348   mtest = atoi(argv[2]);
00349 
00350   fprintf (stdout, "Testing step number %d\n\n\n", mtest); fflush(stdout);
00351   #endif
00352 
00353   /* ------------------------------------------------ */
00354   /* Load configuration file                          */
00355   /* ------------------------------------------------ */
00356 
00357   if (configuration_load (argv[1], &error) == 1)
00358   {
00359     fprintf (stderr, "[FATAL] %s\n", error);
00360     return 1;
00361   }
00362 
00363   /* ------------------------------------------------ */
00364   /* Test access to the log file                      */
00365   /* ------------------------------------------------ */
00366 
00367   init_syslogger();
00368 
00369   if (configuration_globale.log_size_management) { activate_log_size_management(); }
00370 
00371   if (my_syslog (configuration_globale.log_file, "[%s:%d] [INFO] Starting MyDhcp server (%s)",
00372                  __FILE__, __LINE__, BUILD))
00373   {
00374     fprintf (stderr, "[FATAL] Could not access my log file <%s> : %s\n",
00375              configuration_globale.log_file,
00376              logger_last_error());
00377     return 1;
00378   }
00379 
00380   #ifdef 0
00381   my_syslog (configuration_globale.log_file, "[%s:%d] [INFO] CVS: %s",
00382              __FILE__, __LINE__, CVS_TAGS);
00383   #endif
00384 
00385   /* ------------------------------------------------ */
00386   /* Give access to anybody for all logs              */
00387   /* ------------------------------------------------ */
00388 
00389   if (chmod(configuration_globale.log_file, S_IROTH | S_IWOTH | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) == -1)
00390   {
00391     fprintf (stderr, "[FATAL] Could not change access rights for log file <%s>. Please check permissions\n",
00392              configuration_globale.log_file);
00393     my_syslog (configuration_globale.log_file,
00394                "[FATAL] [%s:%d] Could not change access rights for log file <%s>. Please check permissions.",
00395                __FILE__,
00396                __LINE__,
00397                configuration_globale.log_file);
00398     return 1;
00399   }
00400 
00401   if (access (configuration_globale.debug_file, F_OK) == 0)
00402   {
00403     if (chmod(configuration_globale.debug_file, S_IROTH | S_IWOTH | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP) == -1)
00404     {
00405       fprintf (stderr, "[FATAL] Could not change access rights for dumper file <%s>. Please check permissions\n",
00406                configuration_globale.debug_file);
00407       my_syslog (configuration_globale.log_file,
00408                  "[FATAL] [%s:%d] Could not change access rights for dumper file <%s>. Please check permissions",
00409                  __FILE__,
00410                  __LINE__,
00411                  configuration_globale.debug_file);
00412       return 1;
00413     }
00414   }
00415 
00416   /* ------------------------------------------------ */
00417   /* Open synchronization files, create if necessary  */
00418   /* ------------------------------------------------ */
00419 
00420   dump_sync_fd = -1;
00421 
00422   if (strcmp (configuration_globale.sync_dump, "Desactivate synchronisation") != 0)
00423   {
00424      my_syslog (configuration_globale.log_file,
00425                 "[INFO] [%s:%d] Get synchronization file (%s) for dump access",
00426                  __FILE__,
00427                  __LINE__,
00428                  configuration_globale.sync_dump);
00429      
00430      dump_sync_fd = open (configuration_globale.sync_dump, O_CREAT);
00431    
00432      if (dump_sync_fd == -1)
00433      {
00434        fprintf (stderr, "[FATAL] Could not open sybchronization gile (%s) for dump access.",
00435                 configuration_globale.sync_dump);
00436        my_syslog (configuration_globale.log_file,
00437                   "[FATAL] [%s:%d] Could not open sybchronization gile (%s) for dump access.",
00438                   __FILE__,
00439                   __LINE__,
00440                   configuration_globale.sync_dump);
00441        return 1;
00442      }
00443   }
00444 
00445   /* ------------------------------------------------ */
00446   /* Convert symbolic UID and GID into system IDs     */
00447   /* ------------------------------------------------ */
00448 
00449   passwords = getpwnam (configuration_globale.deamon_user_id);
00450 
00451   if (passwords == NULL)
00452   {
00453     fprintf (stderr, "[FATAL] Could not find UNIX user <%s> into /etc/passwd! Make sure that this UNIX user exists\n",
00454                      configuration_globale.deamon_user_id);
00455     my_syslog (configuration_globale.log_file,
00456                "[FATAL] [%s:%d] Could not find UNIX user <%s> into /etc/passwd! Make sure that this UNIX user exists",
00457                __FILE__,
00458                __LINE__,
00459                configuration_globale.deamon_user_id);
00460     return 1;
00461   }
00462 
00463   groups = getgrnam (configuration_globale.deamon_group_id);
00464 
00465   if (groups == NULL)
00466   {
00467     fprintf (stderr, "[FATAL] Could not find group <%s> into /etc/group!",
00468                      configuration_globale.deamon_group_id);
00469     my_syslog (configuration_globale.log_file,
00470                "[FATAL] [%s:%d] Could not find group <%s> into /etc/group!",
00471                __FILE__,
00472                __LINE__,
00473                configuration_globale.deamon_group_id);
00474     return 1;
00475   }
00476 
00477   grp_id   = groups->gr_gid;
00478   user_id  = passwords->pw_uid;
00479 
00480   my_syslog (configuration_globale.log_file,
00481              "[INFO] [%s:%d] User %s -> %d and Group %s -> %d",
00482              __FILE__,
00483              __LINE__,
00484              configuration_globale.deamon_user_id,
00485              (int)user_id,
00486              configuration_globale.deamon_group_id,
00487              (int)grp_id);
00488 
00489   /* ------------------------------------------------ */
00490   /* Some security tests                              */
00491   /* ------------------------------------------------ */
00492 
00493   if (configuration_globale.dumper_mode == 2)
00494   {
00495     fprintf (stdout, "WARNING: You selected 'dumper-mode = total' in configuration file '%s'.\n", argv[1]);
00496     fprintf (stdout, "The server will __NOT__ respond to any incoming request.\n");
00497     fprintf (stdout, "Is it realy what you want ?\n\n");
00498 
00499     fprintf (stdout, "ALERTE: Vous avez selectionne 'dumper-mode = total' dans le fichier de configuration '%s'",
00500                      argv[1]);
00501     fprintf (stdout, "Le server ne repondra __PAS__ aux requetes en provenances des clients.\n");
00502     fprintf (stdout, "Est-ce vraiment ce que vous voulez?\n\n");
00503   }
00504 
00505   /* ------------------------------------------------ */
00506   /* Create socket                                    */
00507   /* ------------------------------------------------ */
00508 
00509   sck = create_socket (
00510                         SERVER_PORT,
00511                         &addr_server,
00512                         configuration_globale.dhcp_bind_ip,
00513                         interface,
00514                         IFNAMSIZ,
00515                         &broadcast,
00516                         &netmask,
00517                         &server_ip,
00518                         my_syslog,
00519                         configuration_globale.log_file);
00520 
00521   if (sck == -1)
00522   {
00523     fprintf (stderr, "[FATAL] %s\n", get_last_socket_error());
00524     my_syslog (configuration_globale.log_file, "[FATAL] [%s:%d] %s",
00525                __FILE__,
00526                __LINE__,
00527                get_last_socket_error());
00528     return 1;
00529   }
00530 
00531   /* ------------------------------------------------ */
00532   /* Load configuration for the connection to the     */
00533   /* local DHCP database (READ only).                 */
00534   /* ------------------------------------------------ */
00535 
00536   rc = load_mysql_configuration_from_file (argv[1], &conf_mysql_dhcp_read_only, tags_read, my_syslog);
00537 
00538   if (rc)
00539   {
00540     fprintf (stderr, "[FATAL] Error while loading configuration for local DHCP database connection - %s",
00541                      conf_mysql_dhcp_read_only.last_error_str);
00542     my_syslog (configuration_globale.log_file,
00543                "[FATAL] [%s:%d] Could not load configuration for local DHCP database connection - %s",
00544                __FILE__,
00545                __LINE__,
00546                conf_mysql_dhcp_read_only.last_error_str);
00547     return 1;
00548   }
00549 
00550   /* ------------------------------------------------ */
00551   /* Load configuration for the connection to the     */
00552   /* POOL database (READ/WRITE).                      */
00553   /* ------------------------------------------------ */
00554 
00555   rc = load_mysql_configuration_from_file (argv[1], &conf_mysql_dhcp_read_write, tags_read_write, my_syslog);
00556 
00557   if (rc)
00558   {
00559     fprintf (stderr, "[FATAL] Error while loading configuration for POOL DHCP database connection - %s",
00560                      conf_mysql_dhcp_read_write.last_error_str);
00561     my_syslog (configuration_globale.log_file,
00562                "[FATAL] [%s:%d] Could not load configuration for POOL DHCP database connection - %s",
00563                __FILE__,
00564                __LINE__,
00565                conf_mysql_dhcp_read_write.last_error_str);
00566     return 1;
00567   }
00568 
00569   /* ------------------------------------------------ */
00570   /* Load configuration for the connection to the     */
00571   /* radonline database.                              */
00572   /* ------------------------------------------------ */
00573 
00574   rc = load_mysql_configuration_from_file (argv[1], &conf_mysql_radonline, tags_radonline, my_syslog);
00575 
00576   if (rc)
00577   {
00578     fprintf (stderr, "[FATAL] Error while loading configuration for connection to Radonline - %s",
00579                      conf_mysql_radonline.last_error_str);
00580     my_syslog (configuration_globale.log_file,
00581                "[FATAL] [%s:%d] Could not load configuration for connection to Radonline - %s",
00582                __FILE__,
00583                __LINE__,
00584                conf_mysql_radonline.last_error_str);
00585     return 1;
00586   }
00587 
00588   /* ------------------------------------------------ */
00589   /* Load configuration for the connection to the     */
00590   /* mydns database.                                  */
00591   /* ------------------------------------------------ */
00592 
00593   rc = load_mysql_configuration_from_file (argv[1], &conf_mysql_mydns, tags_mydns, my_syslog);
00594 
00595   if (rc)
00596   {
00597     fprintf (stderr, "[FATAL] Error while loading configuration for connection to Mydns - %s",
00598                      conf_mysql_mydns.last_error_str);
00599     my_syslog (configuration_globale.log_file,
00600                "[FATAL] [%s:%d] Could not load configuration for connection to Mydns - %s",
00601                __FILE__,
00602                __LINE__,
00603                conf_mysql_mydns.last_error_str);
00604     return 1;
00605   }
00606 
00607   /* ------------------------------------------------ */
00608   /* Load configuration for the Logistic database.    */
00609   /* ------------------------------------------------ */
00610 
00611   rc = load_mysql_configuration_from_file (argv[1], &conf_mysql_logistic, tags_logistic, my_syslog);
00612 
00613   if (rc)
00614   {
00615     fprintf (stderr, "[FATAL] Error while loading configuration for connection to Logistic - %s",
00616                      conf_mysql_logistic.last_error_str);
00617     my_syslog (configuration_globale.log_file,
00618                "[FATAL] [%s:%d] Could not load configuration for connection to Mydns - %s",
00619                __FILE__,
00620                __LINE__,
00621                conf_mysql_logistic.last_error_str);
00622     return 1;
00623   }
00624 
00625   /* ------------------------------------------------ */
00626   /* Connect to local DHCP database                   */
00627   /* ------------------------------------------------ */
00628 
00629   init_mysql_structure (&conf_mysql_dhcp_read_only);
00630 
00631   rc = connect_to_mysql (&conf_mysql_dhcp_read_only);
00632 
00633   if (rc != 0)
00634   {
00635     fprintf (stderr, "[FATAL] Could not connect to local DHCP database - %s (%d)\n",
00636              conf_mysql_dhcp_read_only.last_error_str,
00637              conf_mysql_dhcp_read_only.last_error_int);
00638     my_syslog (configuration_globale.log_file,
00639                "[FATAL] [%s:%d] Could not connect to local DHCP database - %s (%d)",
00640                __FILE__,
00641                __LINE__,
00642                conf_mysql_dhcp_read_only.last_error_str,
00643                conf_mysql_dhcp_read_only.last_error_int);
00644     return 1;
00645   }
00646 
00647   /* ------------------------------------------------ */
00648   /* Connect to POOL DHCP database                    */
00649   /* ------------------------------------------------ */
00650 
00651   init_mysql_structure (&conf_mysql_dhcp_read_write);
00652 
00653   rc = connect_to_mysql (&conf_mysql_dhcp_read_write);
00654 
00655   if (rc != 0)
00656   {
00657     fprintf (stderr, "[FATAL] Could not connect to POOL DHCP database - %s (%d)\n",
00658              conf_mysql_dhcp_read_write.last_error_str,
00659              conf_mysql_dhcp_read_write.last_error_int);
00660     my_syslog (configuration_globale.log_file,
00661                "[FATAL] [%s:%d] Could not connect to POOL DHCP database - %s (%d)",
00662                __FILE__,
00663                __LINE__,
00664                conf_mysql_dhcp_read_write.last_error_str,
00665                conf_mysql_dhcp_read_write.last_error_int);
00666     return 1;
00667   }
00668 
00669   /* ------------------------------------------------ */
00670   /* Connect to Radonline database                    */
00671   /* ------------------------------------------------ */
00672 
00673   init_mysql_structure (&conf_mysql_radonline);
00674 
00675   rc = connect_to_mysql (&conf_mysql_radonline);
00676 
00677   if (rc != 0)
00678   {
00679     fprintf (stderr, "[FATAL] Could not connect to Radonline database - %s (%d)\n",
00680              conf_mysql_radonline.last_error_str,
00681              conf_mysql_radonline.last_error_int);
00682     my_syslog (configuration_globale.log_file,
00683                "[FATAL] [%s:%d] Could not connect to Radonline database - %s (%d)",
00684                __FILE__,
00685                __LINE__,
00686                conf_mysql_radonline.last_error_str,
00687                conf_mysql_radonline.last_error_int);
00688     return 1;
00689   }
00690 
00691   /* ------------------------------------------------ */
00692   /* Connect to MyDns database                        */
00693   /* ------------------------------------------------ */
00694 
00695   init_mysql_structure (&conf_mysql_mydns);
00696 
00697   rc = connect_to_mysql (&conf_mysql_mydns);
00698 
00699   if (rc != 0)
00700   {
00701     fprintf (stderr, "[FATAL] Could not connect to Mydns database - %s (%d)\n",
00702              conf_mysql_mydns.last_error_str,
00703              conf_mysql_mydns.last_error_int);
00704     my_syslog (configuration_globale.log_file,
00705                "[FATAL] [%s:%d] Could not connect to Mydns database - %s (%d)",
00706                __FILE__,
00707                __LINE__,
00708                conf_mysql_mydns.last_error_str,
00709                conf_mysql_mydns.last_error_int);
00710     return 1;
00711   }
00712 
00713   /* ------------------------------------------------ */
00714   /* Connect to Logistic database                     */
00715   /* ------------------------------------------------ */
00716 
00717   init_mysql_structure (&conf_mysql_logistic);
00718 
00719   rc = connect_to_mysql (&conf_mysql_logistic);
00720 
00721   if (rc != 0)
00722   {
00723     fprintf (stderr, "[FATAL] Could not connect to Logistic database - %s (%d)\n",
00724              conf_mysql_logistic.last_error_str,
00725              conf_mysql_logistic.last_error_int);
00726     my_syslog (configuration_globale.log_file,
00727                "[FATAL] [%s:%d] Could not connect to Logistic database - %s (%d)",
00728                __FILE__,
00729                __LINE__,
00730                conf_mysql_logistic.last_error_str,
00731                conf_mysql_logistic.last_error_int);
00732     return 1;
00733   }
00734 
00735   /* ------------------------------------------------ */
00736   /* Initialize all services that need logging        */
00737   /* service.                                         */
00738   /* ------------------------------------------------ */
00739 
00740   conversion_logging_service (configuration_globale.debug,
00741                               configuration_globale.log_file,
00742                               my_syslog);
00743 
00744   if (configuration_globale.debug > 0)
00745   { init_modem_syslog (my_syslog, configuration_globale.log_file, configuration_globale.debug); }
00746   else { init_modem_syslog (NULL, NULL, 0); }
00747 
00748   /* ------------------------------------------------ */
00749   /* Turn into deamon now                             */
00750   /* ------------------------------------------------ */
00751 
00752   rc = deamonizer (&pid, configuration_globale.working_dir);
00753 
00754   if (pid < 0)
00755   {
00756     my_syslog (configuration_globale.log_file,
00757                "[FATAL] [%s:%d] Could not fork! The system may run out of resources!",
00758                __FILE__, __LINE__);
00759     return 1;
00760   }
00761 
00762   if (pid > 0)
00763   {
00764     if (configuration_globale.debug > 0)
00765     { my_syslog (configuration_globale.log_file, "[DEBUG] [%s:%d] Father: PID of my child is %d",
00766                  __FILE__,
00767                  __LINE__,
00768                 (int)pid); }
00769     return 0;
00770   }
00771 
00772   if (rc == 1)
00773   {
00774     my_syslog (configuration_globale.log_file, "[FATAL] [%s:%d] Can not become a deamon (should never happen)",
00775                __FILE__, __LINE__);
00776     return 1;
00777   }
00778 
00779   /* ------------------------------------------------ */
00780   /* Change user into deamon user                     */
00781   /* ------------------------------------------------ */
00782 
00783   my_syslog (configuration_globale.log_file,
00784              "[INFO] [%s:%d] Change group ID to %s (%d) (Make sure the server is started as 'root' user)",
00785              __FILE__,
00786              __LINE__,
00787              configuration_globale.deamon_group_id,
00788              (int)grp_id);
00789 
00790   if (setgid(grp_id) == -1)
00791   {
00792     my_syslog (configuration_globale.log_file,
00793                "[FATAL] [%s:%d] Could not change GID to %d (%s) (Make sure the server is started as 'root' user)",
00794                __FILE__,
00795                __LINE__,
00796                (int)grp_id,
00797                configuration_globale.deamon_group_id);
00798 
00799     return 1;
00800   }
00801 
00802   my_syslog (configuration_globale.log_file,
00803              "[INFO] [%s:%d] Change user ID to %s (%d) (Make sure the server is started as 'root' user)",
00804              __FILE__,
00805              __LINE__,
00806              configuration_globale.deamon_user_id,
00807              (int)user_id);
00808 
00809   if (setuid(user_id) == -1)
00810   {
00811     my_syslog (configuration_globale.log_file,
00812                "[FATAL] [%s:%d] Could not change UID to %d (%s) (Make sure the server is started as 'root' user)",
00813                __FILE__,
00814                __LINE__,
00815                (int)user_id,
00816                configuration_globale.deamon_user_id);
00817 
00818     return 1;
00819   }
00820 
00821   /* ------------------------------------------------ */
00822   /* Create PID file                                  */
00823   /* ------------------------------------------------ */
00824 
00825   if (access (configuration_globale.pid_file, F_OK) == 0)
00826   {
00827     my_syslog (configuration_globale.log_file,
00828                "[FATAL] [%s:%d] PID file <%s> already exists, abort. The server should be running. Please check.",
00829                __FILE__,
00830                __LINE__,
00831                configuration_globale.pid_file);
00832     return 1;
00833   }
00834 
00835   pid_file = fopen (configuration_globale.pid_file, "w");
00836 
00837   if (pid_file == NULL)
00838   {
00839     int e = errno;
00840     my_syslog (configuration_globale.log_file,
00841                "[FATAL] [%s:%d] Could not create my PID file '%s' - %s (check file permissions)",
00842                __FILE__, __LINE__,
00843                configuration_globale.pid_file, strerror(e));
00844     return 1;
00845   }
00846 
00847   fprintf (pid_file, "%d", getpid());
00848 
00849   fclose (pid_file);
00850 
00851   /* ------------------------------------------------ */
00852   /* Security                                         */
00853   /* ------------------------------------------------ */
00854 
00855   #ifdef XID_FILTERING
00856 
00857     my_syslog (configuration_globale.log_file,
00858     "[WARNING] [%s:%d] This server is compiled with XID filtering !!! Don't use it for production !!!",
00859     __FILE__, __LINE__);
00860 
00861   #endif
00862 
00863   /* ------------------------------------------------ */
00864   /* Initialize the MyDns interface                   */
00865   /* ------------------------------------------------ */
00866 
00867   if (mydns_init (&conf_mysql_mydns))
00868   {
00869     my_syslog (configuration_globale.log_file,
00870     "[FATAL] [%s:%d] mydns_init() - Could not get id from 'soa' where origin='user.' (What's wrong with MyDns?)",
00871     __FILE__, __LINE__);
00872     unlink (configuration_globale.pid_file);
00873     return 1;
00874   }
00875 
00876   /* ------------------------------------------------ */
00877   /* Initialize the dump service for packets          */
00878   /* ------------------------------------------------ */
00879  
00880   packet_init_dump_service();
00881   packet_logging_service (configuration_globale.debug, 
00882                           configuration_globale.log_file,
00883                           my_syslog);
00884 
00885 
00886 
00887 
00888 
00889   /* ------------------------------------------------ */
00890   /* Listen for packets                               */
00891   /* ------------------------------------------------ */
00892 
00893   while (1)
00894   {
00895     logging_new_tag();
00896     my_syslog_skip_line (configuration_globale.log_file);
00897 
00898     if (configuration_globale.debug > 1)
00899     {
00900        my_syslog (configuration_globale.log_file, "[DEBUG] [%s:%d] Waiting for DHCP request",
00901                   __FILE__, __LINE__);
00902     }
00903 
00904     /* ---------------------------------------------- */
00905     /* Get the packet                                 */
00906     /* o If READ_PACKET_FROM_FILE is defined, the the */
00907     /*   server reads packets from the directory      */
00908     /*   defined by INPUT_PACKET_DIRECTORY.           */
00909     /*   Packets are stored in the files packetXXX.   */
00910     /* o Otherwize, the server reads packets from the */
00911     /*   socket.                                      */
00912     /* ---------------------------------------------- */
00913 
00914     packets_clear (&packet_in);
00915     adress_size = sizeof (struct sockaddr);
00916 
00917     #ifndef READ_PACKET_FROM_FILE
00918 
00919       mess_size = recvfrom (
00920                              sck,
00921                              (char*)&packet_in,
00922                              PACKET_SIZE,
00923                              0,
00924                              (struct sockaddr*)&addr_original,
00925                              (size_t*)&adress_size
00926                            );
00927   
00928       if (mess_size == -1)
00929       {
00930         my_syslog (configuration_globale.log_file,
00931                    "[WARNING] [%s:%d] Recvfrom() failed - %s (continue)",
00932                    __FILE__, __LINE__,
00933                    strerror(errno));
00934         continue;
00935       }
00936 
00937     #else
00938 
00939       input_directory = opendir (INPUT_PACKET_DIRECTORY);
00940       if (input_directory == NULL)
00941       {
00942         my_syslog (configuration_globale.log_file, "[FATAL] [%s:%d] Could not open directory <%s>",
00943                    __FILE__, __LINE__, INPUT_PACKET_DIRECTORY);
00944         unlink (configuration_globale.pid_file);
00945         return 1;
00946       }
00947   
00948       while (1)
00949       {
00950         input_packet_from_dir = readdir (input_directory);
00951         if (input_packet_from_dir == NULL) { break; }
00952   
00953         memset (input_packet_file_name, 0, INPUT_PACKET_FILE_NAME_SIZE);
00954         snprintf (input_packet_file_name, INPUT_PACKET_FILE_NAME_SIZE, "%s/%s",
00955                   INPUT_PACKET_DIRECTORY, input_packet_from_dir->d_name);
00956   
00957         my_syslog (configuration_globale.log_file, "[DEBUG] [%s:%d] Found <%s>",
00958                    __FILE__, __LINE__, input_packet_file_name);
00959   
00960         if (strncmp ("packet", input_packet_from_dir->d_name, 6) == 0) { break; }
00961       }
00962   
00963       closedir (input_directory);
00964   
00965       if (input_packet_from_dir == NULL)
00966       {
00967         my_syslog (configuration_globale.log_file,
00968                    "[DEBUG] [%s:%d] No more packet found in <%s>, exit",
00969                    __FILE__, __LINE__, INPUT_PACKET_DIRECTORY);
00970         unlink (configuration_globale.pid_file);
00971         return 0;
00972       }
00973   
00974       my_syslog (configuration_globale.log_file, "[DEBUG] [%s:%d] Loading packet from <%s>",
00975                  __FILE__, __LINE__, input_packet_file_name);
00976   
00977       packet_file = open(input_packet_file_name, O_RDONLY);
00978   
00979       if (packet_file == -1)
00980       {
00981         my_syslog (configuration_globale.log_file, "[FATAL] [%s:%d] Could not open file <%s>",
00982                    __FILE__, __LINE__, input_packet_file_name);
00983         unlink (configuration_globale.pid_file);
00984         return 1;
00985       }
00986   
00987       mess_size = read (packet_file, (void*)&packet_in, PACKET_SIZE);
00988   
00989       my_syslog (configuration_globale.log_file, "[DEBUG] [%s:%d] Read %d bytes from <%s>",
00990                  __FILE__, __LINE__, mess_size, input_packet_file_name);
00991   
00992       if (mess_size == -1)
00993       {
00994         my_syslog (configuration_globale.log_file, "[FATAL] [%s:%d] Error while loading <%s>",
00995                    __FILE__, __LINE__, input_packet_file_name);
00996         unlink (configuration_globale.pid_file);
00997         return 1;
00998       }
00999   
01000       close (packet_file);
01001   
01002       my_syslog (configuration_globale.log_file, "[DEBUG] [%s:%d] Unlink <%s>",
01003                  __FILE__, __LINE__, input_packet_file_name);
01004   
01005       if (unlink (input_packet_file_name) == -1)
01006       {
01007         my_syslog (configuration_globale.log_file, "[FATAL] Can not delete file <%s>",
01008                    __FILE__, __LINE__, input_packet_file_name);
01009         unlink (configuration_globale.pid_file);
01010         return 1;
01011       }
01012 
01013     #endif
01014 
01015 
01016     if (configuration_globale.debug > 1)
01017     { my_syslog (configuration_globale.log_file, "[DEBUG] [%s:%d] Got a request (%d bytes)",
01018                  __FILE__, __LINE__, mess_size); }
01019 
01020 
01021     #ifdef DUMP_PACKETS
01022 
01023       dumpfd = open("/tmp/packets_dhcp", O_WRONLY);
01024       if (dumpfd == -1)
01025       {
01026         my_syslog (configuration_globale.log_file,
01027                    "[WARNING] [%s:%d] Could not open file '/tmp/packets_dhcp' - %s",
01028                    __FILE__, __LINE__, strerror(errno));
01029       }
01030       else
01031       {
01032         write(dumpfd, (void*)&packet_in, mess_size);
01033         my_syslog (configuration_globale.log_file,
01034                    "[INFO] [%s:%d] One packet dumped into '/tmp/packets_dhcp'", __FILE__, __LINE__);
01035         close(dumpfd);
01036       }
01037 
01038     #endif
01039 
01040     /* ---------------------------------------------- */
01041     /* Set the size of the packet                     */
01042     /* ---------------------------------------------- */
01043 
01044     packet_set_taille (&packet_in, mess_size);
01045 
01046     /* ---------------------------------------------- */
01047     /* Sanity check                                   */
01048     /* ---------------------------------------------- */
01049 
01050     if (check_packet_size(mess_size) == 0)
01051     {
01052       my_syslog (configuration_globale.log_file,
01053                  "[WARNING] [%s:%d] Invalid DHCP packet (only %d bytes!). Drop this packet",
01054                  __FILE__, __LINE__, mess_size);
01055       dump_packet_hexa ((void*)&packet_in, mess_size, configuration_globale.log_file);
01056       packets_send_dummy_nak (
01057                                &packet_in,
01058                                &mysql_tables,
01059                                configuration_globale.dummy_ip,
01060                                broadcast,
01061                                server_ip,
01062                                sck,
01063                                &addr_original
01064                              );
01065       continue;
01066     }
01067 
01068     /* ---------------------------------------------- */
01069     /* Parse the packet's options                     */
01070     /* ---------------------------------------------- */
01071 
01072     if (packets_parse_options(&packet_in) == 1)
01073     {
01074       my_syslog (configuration_globale.log_file,
01075                  "[WARNING] [%s:%d] Invalid DHCP packet: option's part is not well formatted. Drop this packet",
01076                  __FILE__, __LINE__);
01077       dump_packet_hexa ((void*)&packet_in, mess_size, configuration_globale.log_file);
01078       packets_send_dummy_nak (
01079                                &packet_in,
01080                                &mysql_tables,
01081                                configuration_globale.dummy_ip,
01082                                broadcast,
01083                                server_ip,
01084                                sck,
01085                                &addr_original
01086                              );
01087       continue;
01088     }
01089 
01090     /* ---------------------------------------------- */
01091     /* At this point, the packet's data should be OK. */
01092     /* Get MAC address and DSLAM's ID.                */
01093     /* ---------------------------------------------- */
01094 
01095     init_client_ids (packets_get_chaddr(&packet_in),
01096                      packets_get_node_id(&packet_in),
01097                      packets_get_shelf(&packet_in),
01098                      packets_get_numero_slot(&packet_in),
01099                      packets_get_numero_port(&packet_in),
01100                      packets_get_vci(&packet_in),
01101                      packets_get_vlan_id(&packet_in));
01102 
01103     /* ---------------------------------------------- */
01104     /* If dumper mode selected, then dump the packet  */
01105     /* but do not reply.                              */
01106     /* dumper_mode = 0 => No dump at all.             */
01107     /* dumper_mode = 1 => Dump all packets.           */
01108     /* dumper_mode = 3 => Dump only (no response)     */
01109     /* ---------------------------------------------- */
01110 
01111     if (configuration_globale.dumper_mode > 0)
01112     { packet_dump (&packet_in, configuration_globale.debug_file,
01113                    configuration_globale.csv_file, &addr_original, NULL); }
01114 
01115     if (configuration_globale.dumper_mode > 1)
01116     {
01117       if (configuration_globale.debug > 0)
01118       { my_syslog (configuration_globale.log_file,
01119                    "[DEBUG] [%s:%d] WARNING: Dumper mode value is 'total' - Do not reply",
01120                    __FILE__, __LINE__); }
01121 
01122       continue;
01123     }
01124 
01125     /* ---------------------------------------------- */
01126     /* Process TEST mode                              */
01127     /* ---------------------------------------------- */
01128 
01129     #ifdef XID_FILTERING
01130 
01131     if (! packet_testing (packets_get_xid(&packet_in)))
01132     {
01133       my_syslog (configuration_globale.log_file,
01134                  "[INFO] [%s:%d] XID_FILTERING activated, this packet is rejected",
01135                  __FILE__, __LINE__);
01136       continue;
01137     }
01138 
01139     #endif
01140 
01141     /* ---------------------------------------------- */
01142     /* If DHCP DECLINE write WARNING and process next */
01143     /* packet.                                        */
01144     /* ---------------------------------------------- */
01145 
01146     if (packets_get_message_type(&packet_in) == DHCPDECLINE)
01147     {
01148       my_syslog (configuration_globale.log_file,
01149                  "[WARNING] [%s:%d] Got DECLINE",
01150                  __FILE__, __LINE__);
01151 
01152       packets_send_dummy_nak (
01153                                &packet_in,
01154                                &mysql_tables,
01155                                configuration_globale.dummy_ip,
01156                                broadcast,
01157                                server_ip,
01158                                sck,
01159                                &addr_original
01160                              );
01161       continue;
01162     }
01163 
01164     /* ---------------------------------------------- */
01165     /* Load user's context                            */
01166     /* The client may not broadcasts. In this case,   */
01167     /* the gateway does not touch the packets. This   */
01168     /* means that :                                   */
01169     /*    o The field "giaddr" is set to "0.0.0.0".   */
01170     /*    o We ignore the "vlan" data.                */
01171     /* ---------------------------------------------- */
01172 
01173     clear_tables(&mysql_tables);
01174 
01175     strncpy (mysql_tables.abonnes.node_id, packets_get_node_id(&packet_in), NODE_BUFFER_SIZE-1);
01176     mysql_tables.abonnes.shelf       = packets_get_shelf(&packet_in);
01177     mysql_tables.abonnes.numero_port = packets_get_numero_port(&packet_in);
01178     mysql_tables.abonnes.numero_slot = packets_get_numero_slot(&packet_in);
01179 
01180     strncpy (mysql_tables.vlan.vlan_gateway, packets_get_giaddr(&packet_in), IP_ADDRESS_STR_SIZE);
01181 
01182     if (strcmp(mysql_tables.vlan.vlan_gateway, "0.0.0.0") != 0)
01183     {
01184       /* -------------------------------------------- */
01185       /* Broadcast                                    */
01186       /* -------------------------------------------- */
01187 
01188       if (configuration_globale.debug > 1)
01189       {
01190         my_syslog (configuration_globale.log_file,
01191                    "[DEBUG] [%s:%d] 'giaddr' not '0.0.0.0' => Should be BROADCAST from client",
01192                    __FILE__, __LINE__);
01193       }
01194 
01195       mysql_tables.vlan.vlan_tag = packets_get_vlan_id(&packet_in);
01196     }
01197     else
01198     {
01199       /* -------------------------------------------- */
01200       /* Unicast                                      */
01201       /* Copy the sender's address as vlan_gateway    */
01202       /* -------------------------------------------- */
01203 
01204       int    i;
01205       char   addresse_from[16], *a;
01206 
01207       memset ((void*)addresse_from, 0, 16);
01208       a = inet_ntoa(addr_original.sin_addr);
01209       for (i=0; i<15; i++) { addresse_from[i] = *(a+i); };
01210       addresse_from[15] = 0;
01211 
01212       if (configuration_globale.debug > 0)
01213       {
01214         my_syslog (configuration_globale.log_file,
01215                    "[DEBUG] [%s:%d] 'giaddr' is '0.0.0.0' => It should be a UNICAST client (%s)",
01216                    __FILE__, __LINE__, addresse_from);
01217       }
01218 
01219       mysql_tables.vlan.vlan_tag = 0;
01220       strncpy (mysql_tables.vlan.vlan_gateway, addresse_from, IP_ADDRESS_STR_SIZE);
01221     }
01222 
01223     /* ---------------------------------------------- */
01224     /* Update logger sub-system and load context      */
01225     /* ---------------------------------------------- */
01226 
01227     if (configuration_globale.debug > 1)
01228     {
01229       my_syslog (configuration_globale.log_file,
01230       "[DEBUG] [%s:%d] Load context for vlan_id=%lu, vlan_gateway='%s'",
01231       __FILE__, __LINE__,
01232       mysql_tables.vlan.vlan_id,
01233       mysql_tables.vlan.vlan_gateway);
01234     }
01235 
01236     logger_set_gateway (mysql_tables.vlan.vlan_gateway);
01237 
01238     rc = load_context (&conf_mysql_dhcp_read_only,
01239                        &conf_mysql_dhcp_read_write,
01240                        &mysql_tables,
01241                        &configuration_globale);
01242 
01243     switch (rc)
01244     {
01245       case MYSQL_INTERFACE_REQUEST_SKIPED:
01246            my_syslog (configuration_globale.log_file,
01247            "[WARNING] [%s:%d] Load context, request skiped",
01248            __FILE__, __LINE__);
01249            packets_send_dummy_nak (
01250                                      &packet_in,
01251                                      &mysql_tables,
01252                                      configuration_globale.dummy_ip,
01253                                      broadcast,
01254                                      server_ip,
01255                                      sck,
01256                                      &addr_original
01257                                   );
01258            continue;
01259 
01260       case MYSQL_INTERFACE_CONNECTION_LOST:
01261            my_syslog (configuration_globale.log_file,
01262            "[WARNING] [%s:%d] Load context, connection loast",
01263            __FILE__, __LINE__);
01264            packets_send_dummy_nak (
01265                                      &packet_in,
01266                                      &mysql_tables,
01267                                      configuration_globale.dummy_ip,
01268                                      broadcast,
01269                                      server_ip,
01270                                      sck,
01271                                      &addr_original
01272                                   );
01273            continue;
01274 
01275       case MYSQL_INTERFACE_RECONNECTION_FAILED:
01276            my_syslog (configuration_globale.log_file,
01277            "[WARNING] [%s:%d] Load context, could not reconnect",
01278            __FILE__, __LINE__);
01279            packets_send_dummy_nak (
01280                                      &packet_in,
01281                                      &mysql_tables,
01282                                      configuration_globale.dummy_ip,
01283                                      broadcast,
01284                                      server_ip,
01285                                      sck,
01286                                      &addr_original
01287                                   );
01288            continue;
01289 
01290       case MYSQL_INTERFACE_SQL_PROBLEM:
01291            my_syslog (configuration_globale.log_file,
01292            "[FATAL] [%s:%d] Load context, unexpected SQL error. %s (%d).",
01293            __FILE__, __LINE__, mysql_error_str, mysql_error_errno);
01294            unlink (configuration_globale.pid_file);
01295            return 1;
01296 
01297       case MYSQL_INTERFACE_NOT_FOUND:
01298            my_syslog (configuration_globale.log_file,
01299            "[WARNING] [%s:%d] Load context, could not find vlan_id=%lu, vlan_gateway='%s' - Skip this request.",
01300            __FILE__, __LINE__,
01301            mysql_tables.vlan.vlan_id,
01302            mysql_tables.vlan.vlan_gateway);
01303            packets_send_dummy_nak (
01304                                      &packet_in,
01305                                      &mysql_tables,
01306                                      configuration_globale.dummy_ip,
01307                                      broadcast,
01308                                      server_ip,
01309                                      sck,
01310                                      &addr_original
01311                                   );
01312            continue;
01313 
01314       case MYSQL_INTERFACE_MORE_THAN_ONE:
01315            my_syslog (configuration_globale.log_file,
01316            "[WARNING] [%s:%d] Load context, more than one data for vlan_id=%lu, vlan_gateway='%s' - This should never happen because of database constraints - Abort server's execution now.",
01317            __FILE__, __LINE__,
01318            mysql_tables.vlan.vlan_id,
01319            mysql_tables.vlan.vlan_gateway);
01320            packets_send_dummy_nak (
01321                                      &packet_in,
01322                                      &mysql_tables,
01323                                      configuration_globale.dummy_ip,
01324                                      broadcast,
01325                                      server_ip,
01326                                      sck,
01327                                      &addr_original
01328                                   );
01329            continue;
01330 
01331       case MYSQL_INTERFACE_UNEXPECTED_ERROR:
01332            my_syslog (configuration_globale.log_file,
01333            "[WARNING] [%s:%d] Load context, unexpected error - Skip this request - %s (%d)",
01334            __FILE__, __LINE__, mysql_error_str, mysql_error_errno);
01335            packets_send_dummy_nak (
01336                                      &packet_in,
01337                                      &mysql_tables,
01338                                      configuration_globale.dummy_ip,
01339                                      broadcast,
01340                                      server_ip,
01341                                      sck,
01342                                      &addr_original
01343                                   );
01344            continue;
01345 
01346       case MYSQL_INTERFACE_TOO_MANY_ITEMS:
01347            my_syslog (configuration_globale.log_file,
01348            "[FATAL] [%s:%d] Load context, too many profile's option loaded. This should never happen since the buffer is really oversized. Abort server's execution now.",
01349            __FILE__, __LINE__);
01350            unlink (configuration_globale.pid_file);
01351            return 1;
01352     }
01353 
01354     if (configuration_globale.debug > 0)
01355     {
01356       my_syslog (configuration_globale.log_file,
01357       "[DEBUG] [%s:%d] Context successfully loaded", __FILE__, __LINE__);
01358     }
01359 
01360     /* ---------------------------------------------- */
01361     /* Find out the modem's manufacturor... If the    */
01362     /* modem supports "autoconf", then look up the    */
01363     /* logistic database.                             */ 
01364     /* ---------------------------------------------- */
01365 
01366     modem_manufacturor = get_modem_manufacturor (&packet_in);
01367 
01368     if (configuration_globale.debug > 0)
01369     {
01370       my_syslog (configuration_globale.log_file,
01371       "[DEBUG] [%s:%d] Modem's manufacturor is %s",
01372       __FILE__, __LINE__, id_manufacturor_to_string(modem_manufacturor));
01373     }
01374 
01375     mysql_tables.logistic.modem_manufacturor = modem_manufacturor;
01376 
01377     /* ---------------------------------------------- */
01378     /* If the modem supports "autoconf", then lookup  */
01379     /* the table LOGISTIC_RADIUS.                     */
01380     /* If not, then make sure that the user's profile */
01381     /* is not "autoconfblackhole". If so, remove the  */
01382     /* autoconf blackhole.                            */
01383     /* ---------------------------------------------- */
01384 
01385     #ifndef USE_PLUGINS
01386         if (
01387              (modem_manufacturor == MODEM_HITACHI)
01388              ||
01389              (modem_manufacturor == MODEM_SAGEM)
01390            )
01391     #else
01392         if (modem_conf_is_autoconf(modem_manufacturor))
01393     #endif
01394 
01395     {
01396       if (configuration_globale.debug > 0)
01397       {
01398         my_syslog (configuration_globale.log_file,
01399         "[DEBUG] [%s:%d] This modem supports auto-configuration - search LOGISTIC_RADIUS",
01400         __FILE__, __LINE__);
01401       }
01402 
01403       rc = look_up_logistic (&conf_mysql_logistic,
01404                              &conf_mysql_dhcp_read_only,
01405                              &mysql_tables,
01406                              &configuration_globale,
01407                              &packet_in);
01408 
01409       switch (rc)
01410       {
01411         case MYSQL_INTERFACE_CONNECTION_LOST:
01412              my_syslog (configuration_globale.log_file,
01413              "[WARNING] [%s:%d] look_up_logistic: connection lost", __FILE__, __LINE__);
01414              packets_send_dummy_nak (
01415                                       &packet_in,
01416                                       &mysql_tables,
01417                                       configuration_globale.dummy_ip,
01418                                       broadcast,
01419                                       server_ip,
01420                                       sck,
01421                                       &addr_original
01422                                    );
01423              continue;
01424 
01425         case MYSQL_INTERFACE_NOT_FOUND:
01426              my_syslog (configuration_globale.log_file,
01427              "[WARNING] [%s:%d] look_up_logistic: data not found", __FILE__, __LINE__);
01428              packets_send_dummy_nak (
01429                                        &packet_in,
01430                                        &mysql_tables,
01431                                        configuration_globale.dummy_ip,
01432                                        broadcast,
01433                                        server_ip,
01434                                        sck,
01435                                        &addr_original
01436                                     );
01437              continue;
01438 
01439         case MYSQL_INTERFACE_RECONNECTION_FAILED:
01440              my_syslog (configuration_globale.log_file,
01441              "[WARNING] [%s:%d] look_up_logistic: could not reconnect to Mysql server", __FILE__, __LINE__);
01442              packets_send_dummy_nak (
01443                                        &packet_in,
01444                                        &mysql_tables,
01445                                        configuration_globale.dummy_ip,
01446                                        broadcast,
01447                                        server_ip,
01448                                        sck,
01449                                        &addr_original
01450                                     );
01451              continue;
01452 
01453         case MYSQL_INTERFACE_REQUEST_SKIPED:
01454              my_syslog (configuration_globale.log_file,
01455              "[WARNING] [%s:%d] look_up_logistic: skip few packets before reconnection atempt.",
01456              __FILE__, __LINE__);
01457              packets_send_dummy_nak (
01458                                        &packet_in,
01459                                        &mysql_tables,
01460                                        configuration_globale.dummy_ip,
01461                                        broadcast,
01462                                        server_ip,
01463                                        sck,
01464                                        &addr_original
01465                                     );
01466              continue;
01467 
01468         case MYSQL_INTERFACE_MORE_THAN_ONE:
01469              my_syslog (configuration_globale.log_file,
01470              "[FATAL] [%s:%d] look_up_logistic: a request returned more than one result, which should never happen.", __FILE__, __LINE__);
01471              unlink (configuration_globale.pid_file);
01472              return 1;
01473 
01474         case MYSQL_INTERFACE_SQL_PROBLEM:
01475              my_syslog (configuration_globale.log_file,
01476              "[FATAL] [%s:%d] look_up_logistic: SQL error, abort", __FILE__, __LINE__);
01477              unlink (configuration_globale.pid_file);
01478              return 1;
01479 
01480         case MYSQL_INTERFACE_UNEXPECTED_ERROR:
01481              my_syslog (configuration_globale.log_file,
01482              "[FATAL] [%s:%d] look_up_logistic: Unexpected error, abort", __FILE__, __LINE__);
01483              unlink (configuration_globale.pid_file);
01484              return 1;
01485       }
01486 
01487       if (configuration_globale.debug > 0)
01488       {
01489         my_syslog (configuration_globale.log_file,
01490         "[DEBUG] [%s:%d] LOGISTIC_RADIUS successfully searched", __FILE__, __LINE__);
01491       }
01492 
01493       /* -------------------------------------------- */
01494       /* Reload options (if blackholed)               */
01495       /* -------------------------------------------- */
01496 
01497       if (configuration_globale.debug > 0)
01498       {
01499         my_syslog (configuration_globale.log_file,
01500         "[DEBUG] [%s:%d] Reload (overwrite) profile's options (client may have been blackholed)",
01501         __FILE__, __LINE__);
01502       }
01503 
01504       rc = load_options (&conf_mysql_dhcp_read_only, &mysql_tables, &configuration_globale);
01505     
01506       if (rc != 0)
01507       {
01508         switch (rc)
01509         {
01510           case MYSQL_INTERFACE_REQUEST_SKIPED:
01511                my_syslog (configuration_globale.log_file,
01512                "[WARNING] [%s,%d] Could not reload 'options' - Request skiped",
01513                __FILE__, __LINE__);
01514                packets_send_dummy_nak (
01515                                          &packet_in,
01516                                          &mysql_tables,
01517                                          configuration_globale.dummy_ip,
01518                                          broadcast,
01519                                          server_ip,
01520                                          sck,
01521                                          &addr_original
01522                                       );
01523                continue;
01524 
01525           case MYSQL_INTERFACE_CONNECTION_LOST:
01526                my_syslog (configuration_globale.log_file,
01527                "[WARNING] [%s,%d] Could not reload 'options' - Connection lost (skip this packet)",
01528                __FILE__, __LINE__);
01529                packets_send_dummy_nak (
01530                                          &packet_in,
01531                                          &mysql_tables,
01532                                          configuration_globale.dummy_ip,
01533                                          broadcast,
01534                                          server_ip,
01535                                          sck,
01536                                          &addr_original
01537                                       );
01538                continue;
01539 
01540           case MYSQL_INTERFACE_RECONNECTION_FAILED:
01541                my_syslog (configuration_globale.log_file,
01542                "[WARNING] [%s,%d] Could not reload 'options' - Could not reconnect (skip this packet)",
01543                __FILE__, __LINE__);
01544                packets_send_dummy_nak (
01545                                          &packet_in,
01546                                          &mysql_tables,
01547                                          configuration_globale.dummy_ip,
01548                                          broadcast,
01549                                          server_ip,
01550                                          sck,
01551                                          &addr_original
01552                                       );
01553                continue;
01554 
01555           case MYSQL_INTERFACE_SQL_PROBLEM:
01556                my_syslog (configuration_globale.log_file,
01557                "[FATAL] [%s,%d] Could not reload 'options' - Some SQL problem",
01558                __FILE__, __LINE__);
01559                unlink (configuration_globale.pid_file);
01560                return 1;
01561 
01562           case MYSQL_INTERFACE_UNEXPECTED_ERROR:
01563                my_syslog (configuration_globale.log_file,
01564                "[FATAL] [%s,%d] Could not reload 'options' - Unexpected error",
01565                __FILE__, __LINE__);
01566                unlink (configuration_globale.pid_file);
01567                return 1;
01568 
01569           case MYSQL_INTERFACE_NOT_FOUND:
01570                my_syslog (configuration_globale.log_file,
01571                "[FATAL] [%s,%d] Could not reload 'options' - Data not found",
01572                __FILE__, __LINE__);
01573                unlink (configuration_globale.pid_file);
01574                return 1;
01575 
01576           case MYSQL_INTERFACE_TOO_MANY_ITEMS:
01577                my_syslog (configuration_globale.log_file,
01578                "[FATAL] [%s,%d] Could not reload 'options' - Too many options",
01579                __FILE__, __LINE__);
01580                unlink (configuration_globale.pid_file);
01581                return 1;
01582         }
01583       }
01584     }
01585     else
01586     {
01587       /* -------------------------------------------- */
01588       /* This is not an autoconf modem, make sure     */
01589       /* that the user's profile is not set to        */
01590       /* "autoconfblackhole".                         */ 
01591       /* -------------------------------------------- */
01592 
01593       rc = remove_autoconf_bh (&conf_mysql_dhcp_read_only,
01594                                &mysql_tables,
01595                                &configuration_globale);
01596 
01597       switch (rc)
01598       {
01599         case MYSQL_INTERFACE_REQUEST_SKIPED:
01600              my_syslog (configuration_globale.log_file,
01601              "[WARNING] [%s,%d] Could not remove autoconf blackhole - Request skiped",
01602              __FILE__, __LINE__);
01603              packets_send_dummy_nak (
01604                                        &packet_in,
01605                                        &mysql_tables,
01606                                        configuration_globale.dummy_ip,
01607                                        broadcast,
01608                                        server_ip,
01609                                        sck,
01610                                        &addr_original
01611                                     );
01612              continue;
01613 
01614         case MYSQL_INTERFACE_CONNECTION_LOST:
01615              my_syslog (configuration_globale.log_file,
01616              "[WARNING] [%s,%d] Could not remove autoconf blackhole - Connection lost (skip this packet)",
01617              __FILE__, __LINE__);
01618              packets_send_dummy_nak (
01619                                        &packet_in,
01620                                        &mysql_tables,
01621                                        configuration_globale.dummy_ip,
01622                                        broadcast,
01623                                        server_ip,
01624                                        sck,
01625                                        &addr_original
01626                                     );
01627              continue;
01628 
01629         case MYSQL_INTERFACE_RECONNECTION_FAILED:
01630              my_syslog (configuration_globale.log_file,
01631              "[WARNING] [%s,%d] Could not remove autoconf blackhole - Could not reconnect (skip this packet)",
01632              __FILE__, __LINE__);
01633              packets_send_dummy_nak (
01634                                        &packet_in,
01635                                        &mysql_tables,
01636                                        configuration_globale.dummy_ip,
01637                                        broadcast,
01638                                        server_ip,
01639                                        sck,
01640                                        &addr_original
01641                                     );
01642              continue;
01643 
01644         case MYSQL_INTERFACE_SQL_PROBLEM:
01645              my_syslog (configuration_globale.log_file,
01646              "[FATAL] [%s,%d] Could not remove autoconf blackhole - Some SQL problem",
01647              __FILE__, __LINE__);
01648              unlink (configuration_globale.pid_file);
01649              return 1;
01650 
01651         case MYSQL_INTERFACE_UNEXPECTED_ERROR:
01652              my_syslog (configuration_globale.log_file,
01653              "[FATAL] [%s,%d] Could not remove autoconf blackhole - Unexpected error",
01654              __FILE__, __LINE__);
01655              unlink (configuration_globale.pid_file);
01656              return 1;
01657 
01658         case MYSQL_INTERFACE_MORE_THAN_ONE:
01659              my_syslog (configuration_globale.log_file,
01660              "[FATAL] [%s,%d] Could not remove autoconf blackhole - More than one record found (impossible)",
01661              __FILE__, __LINE__);
01662              unlink (configuration_globale.pid_file);
01663              return 1;
01664       }
01665       
01666     } 
01667 
01668     /* ---------------------------------------------- */
01669     /* The context is loaded, find the IP address and */
01670     /* send the response to the client.               */
01671     /* ---------------------------------------------- */
01672 
01673     rc = find_ip_and_reply (&conf_mysql_dhcp_read_only,
01674                             &conf_mysql_dhcp_read_write,
01675                             &conf_mysql_radonline,
01676                             &conf_mysql_mydns,
01677                             &mysql_tables,
01678                             &packet_in,
01679                             &configuration_globale,
01680                             sck,
01681                             broadcast,
01682                             server_ip,
01683                             &addr_original);
01684 
01685     switch (rc)
01686     {
01687      case MYSQL_INTERFACE_REQUEST_SKIPED:
01688           my_syslog (configuration_globale.log_file,
01689           "[WARNING] [%s:%d] find_ip_and_reply: request skiped (this is normal, skip few packet before reconnect)",
01690           __FILE__, __LINE__);
01691           packets_send_dummy_nak (
01692                                     &packet_in,
01693                                     &mysql_tables,
01694                                     configuration_globale.dummy_ip,
01695                                     broadcast,
01696                                     server_ip,
01697                                     sck,
01698                                     &addr_original
01699                                  );
01700           continue;
01701 
01702      case MYSQL_INTERFACE_CONNECTION_LOST:
01703           my_syslog (configuration_globale.log_file,
01704           "[WARNING] [%s:%d] find_ip_and_reply: connection lost",
01705           __FILE__, __LINE__);
01706           packets_send_dummy_nak (
01707                                     &packet_in,
01708                                     &mysql_tables,
01709                                     configuration_globale.dummy_ip,
01710                                     broadcast,
01711                                     server_ip,
01712                                     sck,
01713                                     &addr_original
01714                                  );
01715           continue;
01716 
01717      case MYSQL_INTERFACE_RECONNECTION_FAILED:
01718           my_syslog (configuration_globale.log_file,
01719           "[WARNING] [%s:%d] find_ip_and_reply: could not reconnect to MySql server",
01720           __FILE__, __LINE__);
01721           packets_send_dummy_nak (
01722                                     &packet_in,
01723                                     &mysql_tables,
01724                                     configuration_globale.dummy_ip,
01725                                     broadcast,
01726                                     server_ip,
01727                                     sck,
01728                                     &addr_original
01729                                  );
01730           continue;
01731 
01732      case MYSQL_INTERFACE_SQL_PROBLEM:
01733           my_syslog (configuration_globale.log_file,
01734           "[FATAL] [%s:%d] find_ip_and_reply: some unexpected SQL error occured. Abort server's execution now - %d (%d).",
01735           __FILE__, __LINE__, mysql_error_str, mysql_error_errno);
01736           unlink (configuration_globale.pid_file);
01737           return 1;
01738 
01739      case MYSQL_INTERFACE_MORE_THAN_ONE:
01740           my_syslog (configuration_globale.log_file,
01741           "[FATAL] [%s:%d] find_ip_and_reply: more than one result for SQL query. This should never happen because of database constraints. Abort server's execution now.",
01742           __FILE__, __LINE__);
01743           unlink (configuration_globale.pid_file);
01744           return 1;
01745 
01746      case MYSQL_INTERFACE_NOT_FOUND:
01747           my_syslog (configuration_globale.log_file,
01748           "[FATAL] [%s:%d] find_ip_and_reply: a record specified by a given abonnes_id not found in the database. This should not happen (never). Did somebody delete data into the database? Abort server's execution now.",
01749           __FILE__, __LINE__);
01750           unlink (configuration_globale.pid_file);
01751           return 1;
01752 
01753      case MYSQL_INTERFACE_UNEXPECTED_ERROR:
01754           my_syslog (configuration_globale.log_file,
01755           "[FATAL] [%s:%d] find_ip_and_reply: unexpected error. Abort server's execution now - %s (%d)",
01756           __FILE__, __LINE__, mysql_error_str, mysql_error_errno);
01757           unlink (configuration_globale.pid_file);
01758           return 1;
01759 
01760      case MYSQL_INTERFACE_NO_TIMESTAMP:
01761           my_syslog (configuration_globale.log_file,
01762           "[WARNING] [%s:%d] find_ip_and_reply: could not get MySql server's timestamp. %s (%d) Skip",
01763           __FILE__, __LINE__, mysql_error_str, mysql_error_errno);
01764           packets_send_dummy_nak (
01765                                     &packet_in,
01766                                     &mysql_tables,
01767                                     configuration_globale.dummy_ip,
01768                                     broadcast,
01769                                     server_ip,
01770                                     sck,
01771                                     &addr_original
01772                                  );
01773           continue;
01774 
01775      case MYSQL_INTERFACE_NO_LEASE_ID:
01776           my_syslog (configuration_globale.log_file,
01777           "[WARNING] [%s:%d] find_ip_and_reply: could not find lease ID for vlan_id=%lu, vlan_gateway='%s' in database. Skip this packet",
01778           __FILE__, __LINE__,
01779           mysql_tables.vlan.vlan_id,
01780           mysql_tables.vlan.vlan_gateway);
01781           packets_send_dummy_nak (
01782                                     &packet_in,
01783                                     &mysql_tables,
01784                                     configuration_globale.dummy_ip,
01785                                     broadcast,
01786                                     server_ip,
01787                                     sck,
01788                                     &addr_original
01789                                  );
01790           continue;
01791 
01792      case DHCP_NO_DYNAMIC_IP_FOUND:
01793           my_syslog (configuration_globale.log_file,
01794           "[WARNING] [%s:%d] find_ip_and_reply: could not find free dynamic IP address for vlan_id=%lu, vlan_gateway='%s' in database. Skip this packet",
01795           __FILE__, __LINE__,
01796           mysql_tables.vlan.vlan_id,
01797           mysql_tables.vlan.vlan_gateway);
01798           packets_send_dummy_nak (
01799                                     &packet_in,
01800                                     &mysql_tables,
01801                                     configuration_globale.dummy_ip,
01802                                     broadcast,
01803                                     server_ip,
01804                                     sck,
01805                                     &addr_original
01806                                  );
01807           continue;
01808 
01809      case DHCP_INVALID_MESSAGE_TYPE:
01810           my_syslog (configuration_globale.log_file,
01811           "[WARNING] [%s:%d] find_ip_and_reply: invalid DHCP message type from vlan_id=%lu, vlan_gateway='%s' in database. Skip this packet",
01812           __FILE__, __LINE__,
01813           mysql_tables.vlan.vlan_id,
01814           mysql_tables.vlan.vlan_gateway);
01815           packets_send_dummy_nak (
01816                                     &packet_in,
01817                                     &mysql_tables,
01818                                     configuration_globale.dummy_ip,
01819                                     broadcast,
01820                                     server_ip,
01821                                     sck,
01822                                     &addr_original
01823                                  );
01824           continue;
01825 
01826      case DHCP_LEASE_INCONSTANCY:
01827           my_syslog (configuration_globale.log_file,
01828           "[FATAL] [%s:%d] find_ip_and_reply: internal error. Could not get lease. Abort server's execution now.",
01829           __FILE__, __LINE__);
01830           unlink (configuration_globale.pid_file);
01831           return 1;
01832 
01833      case DHCP_NO_DYNAMIC_IP_FOUND_RELEASE:
01834           my_syslog (configuration_globale.log_file,
01835           "[WARNING] [%s:%d] find_ip_and_reply: vlan_id=%lu, vlan_gateway='%s' released its IP, but I could not find it (this might happen rarely)",
01836           __FILE__, __LINE__,
01837           mysql_tables.vlan.vlan_id,
01838           mysql_tables.vlan.vlan_gateway);
01839           packets_send_dummy_nak (
01840                                     &packet_in,
01841                                     &mysql_tables,
01842                                     configuration_globale.dummy_ip,
01843                                     broadcast,
01844                                     server_ip,
01845                                     sck,
01846                                     &addr_original
01847                                  );
01848           continue;
01849 
01850      case DHCP_RADONLINE_MYSQL_SQL_PROBLEM:
01851           my_syslog (configuration_globale.log_file,
01852           "[FATAL] [%s:%d] find_ip_and_reply: an SQL error occured while sending ticket to Radonline - %s (%d)",
01853           __FILE__, __LINE__, mysql_error_str, mysql_error_errno);
01854           unlink (configuration_globale.pid_file);
01855           return 1;
01856 
01857      case DHCP_RADONLINE_MYSQL_UNEXPECTED_ERROR:
01858           my_syslog (configuration_globale.log_file,
01859           "[FATAL] [%s:%d] find_ip_and_reply: unexpected SQL error occured while sending ticket to Radonline - %s (%d)",
01860           __FILE__, __LINE__, mysql_error_str, mysql_error_errno);
01861           unlink (configuration_globale.pid_file);
01862           return 1;
01863 
01864      case DHCP_MYDNS_MYSQL_SQL_PROBLEM:
01865           my_syslog (configuration_globale.log_file,
01866           "[FATAL] [%s:%d] find_ip_and_reply: an SQL error occured while sending ticket to MyDns - %s (%d)",
01867           __FILE__, __LINE__, mysql_error_str, mysql_error_errno);
01868           unlink (configuration_globale.pid_file);
01869           return 1;
01870 
01871      case DHCP_MYDNS_MYSQL_UNEXPECTED_ERROR:
01872           my_syslog (configuration_globale.log_file,
01873           "[FATAL] [%s:%d] find_ip_and_reply: unexpected SQL error occured while sending ticket to MyDns - %s (%d)",
01874           __FILE__, __LINE__, mysql_error_str, mysql_error_errno);
01875           unlink (configuration_globale.pid_file);
01876           return 1;
01877     }
01878 
01879 
01880     if (configuration_globale.debug > 0)
01881     {
01882       my_syslog (configuration_globale.log_file,
01883       "[DEBUG] [%s:%d] Packet successfully processed", __FILE__, __LINE__);
01884     }
01885 
01886 
01887   }
01888 
01889   unlink (configuration_globale.pid_file);
01890   return 0;
01891 }
01892 
01893 
01894 
01895 
01896 
01897 
01898 
01899 
01900 
01901 
01902 
01903 
01904 
01905 
01906 
01907 
01908 
01909 #ifdef XID_FILTERING
01910 
01911 int packet_testing (unsigned long int xid)
01912 {
01913    static char buffer[BUFFSIZE];
01914 
01915    memset ((void*)buffer, 0, BUFFSIZE);
01916    snprintf (buffer, BUFFSIZE, "%lu", xid);
01917 
01918    if (strlen (buffer) != 6) { return 0; }
01919 
01920    if (buffer[5] != buffer[2]) { return 0; }
01921    if (buffer[4] != buffer[1]) { return 0; }
01922    if (buffer[3] != buffer[0]) { return 0; }
01923 
01924    return 1;
01925 }
01926 
01927 #endif
01928 
01929 /*! \brief Dump a packet into hexa. This function is called when it is not possible to 
01930            parse the packet (invalid size ot invalid organisation).
01931     \param packet Pointer to the packet as received by the server.
01932     \param size Size, in bytes of the packet.
01933     \param file Path to the log file.
01934  */
01935 
01936 static void dump_packet_hexa (void* packet, int size, char* file)
01937 {
01938    char *buffer;
01939    int  bsize;
01940 
01941    bsize  = (2*size) + 1;
01942    buffer = (char*) malloc (bsize * sizeof(char));
01943 
01944    if (buffer == NULL)
01945    {
01946      my_syslog (file, "[ERROR] [%s:%d] Could allocate memory (bin2hex_binary() failed)",
01947                 __FILE__, __LINE__);
01948      return;
01949    }
01950  
01951    if (bin2hex_binary ((unsigned char*)packet, (unsigned char*)buffer, size, bsize) == 0)
01952    {
01953      my_syslog (file, "[ERROR] [%s:%d] Could not convert packet into hexa (bin2hex_binary() failed)",
01954                 __FILE__, __LINE__);
01955      free (buffer); 
01956      return;
01957    }
01958 
01959    my_syslog (file, "[INFO] [%s:%d] Packet is (in hexa) [%s]", __FILE__, __LINE__, buffer);
01960 
01961    free (buffer);
01962    return;
01963 }
01964 
01965 
01966 
01967 
01968 
01969 /*! \mainpage Documentation for the DHCP server
01970  *
01971  *  \section code_sec Auto-generated documentation
01972  *
01973  *  To consult the auto-generated documentation, use the links at the top of the page.
01974  *  <ul>
01975  *    <li>Globals : Alphabetical list of all functions, variables and constants. This is the main index.
01976  *    <li>Data Fields : All data structure fields.
01977  *    <li>File List : All source's files.
01978  *    <li>Data Structures : All data structures.
01979  *  </ul>
01980  *
01981  */
01982 

Generated on Mon Jun 19 12:31:05 2006 for MyDhcp_V2 by doxygen1.2.15