2019-04-27 14:54:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 by Sukchan Lee <acetcom@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of Open5GS.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2017-08-05 05:23:37 +00:00
|
|
|
#include "fd_logger.h"
|
|
|
|
#include "fd_lib.h"
|
2017-02-24 13:56:02 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
#undef OGS_LOG_DOMAIN
|
|
|
|
#define OGS_LOG_DOMAIN __base_fd_domain
|
|
|
|
|
2017-08-05 05:23:37 +00:00
|
|
|
static void fd_gnutls_log_func(int level, const char *str);
|
|
|
|
static void fd_log_func(int printlevel, const char *format, va_list ap);
|
2017-03-04 15:50:22 +00:00
|
|
|
|
2018-01-05 07:25:02 +00:00
|
|
|
int fd_init(int mode, const char *conffile, fd_config_t *fd_config)
|
2017-02-24 13:56:02 +00:00
|
|
|
{
|
|
|
|
int ret;
|
2017-07-30 13:29:27 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
gnutls_global_set_log_level(0);
|
2018-01-24 01:17:50 +00:00
|
|
|
gnutls_global_set_log_function(fd_gnutls_log_func);
|
2019-04-27 14:54:30 +00:00
|
|
|
|
|
|
|
fd_g_debug_lvl = FD_LOG_ERROR;
|
2017-08-05 05:23:37 +00:00
|
|
|
ret = fd_log_handler_register(fd_log_func);
|
2017-02-24 13:56:02 +00:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("fd_log_handler_register() failed");
|
2017-02-27 12:29:32 +00:00
|
|
|
return ret;
|
2017-02-24 13:56:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = fd_core_initialize();
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("fd_core_initialize() failed");
|
2017-02-27 12:29:32 +00:00
|
|
|
return ret;
|
2017-02-24 13:56:02 +00:00
|
|
|
}
|
|
|
|
|
2017-02-26 09:14:50 +00:00
|
|
|
/* Parse the configuration file */
|
2018-01-05 07:25:02 +00:00
|
|
|
if (conffile)
|
|
|
|
{
|
|
|
|
CHECK_FCT_DO( fd_core_parseconf(conffile), goto error );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHECK_FCT_DO( fd_config_init(fd_config), goto error );
|
|
|
|
}
|
2017-02-28 11:31:06 +00:00
|
|
|
|
2017-08-16 13:03:36 +00:00
|
|
|
/* Initialize FD Message */
|
|
|
|
CHECK_FCT( fd_message_init() );
|
|
|
|
|
2017-08-05 05:23:37 +00:00
|
|
|
/* Initialize FD logger */
|
2017-08-17 00:43:33 +00:00
|
|
|
CHECK_FCT_DO( fd_logger_init(mode), goto error );
|
2017-08-02 06:11:08 +00:00
|
|
|
|
2017-02-26 09:14:50 +00:00
|
|
|
/* Start the servers */
|
|
|
|
CHECK_FCT_DO( fd_core_start(), goto error );
|
2017-02-24 13:56:02 +00:00
|
|
|
|
2017-02-26 09:14:50 +00:00
|
|
|
CHECK_FCT_DO( fd_core_waitstartcomplete(), goto error );
|
2017-02-24 13:56:02 +00:00
|
|
|
|
2017-08-05 05:23:37 +00:00
|
|
|
CHECK_FCT( fd_logger_stats_start() );
|
|
|
|
|
2017-02-27 12:29:32 +00:00
|
|
|
return 0;
|
2017-02-26 09:14:50 +00:00
|
|
|
error:
|
|
|
|
CHECK_FCT_DO( fd_core_shutdown(), );
|
2017-02-26 12:16:03 +00:00
|
|
|
CHECK_FCT_DO( fd_core_wait_shutdown_complete(), );
|
2017-02-26 09:14:50 +00:00
|
|
|
|
2017-02-27 12:29:32 +00:00
|
|
|
return -1;
|
2017-02-24 13:56:02 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 05:23:37 +00:00
|
|
|
void fd_final()
|
2017-02-24 13:56:02 +00:00
|
|
|
{
|
2017-08-05 05:23:37 +00:00
|
|
|
fd_logger_final();
|
2017-08-02 06:11:08 +00:00
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
CHECK_FCT_DO( fd_core_shutdown(), ogs_error("fd_core_shutdown() failed") );
|
2017-02-26 12:16:03 +00:00
|
|
|
CHECK_FCT_DO( fd_core_wait_shutdown_complete(),
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("fd_core_wait_shutdown_complete() failed"));
|
2017-02-24 13:56:02 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 05:23:37 +00:00
|
|
|
static void fd_gnutls_log_func(int level, const char *str)
|
2017-02-24 13:56:02 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_trace("gnutls[%d]: %s", level, str);
|
2017-02-24 13:56:02 +00:00
|
|
|
}
|
|
|
|
|
2017-08-05 05:23:37 +00:00
|
|
|
static void fd_log_func(int printlevel, const char *format, va_list ap)
|
2017-02-24 13:56:02 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
char buffer[OGS_HUGE_LEN];
|
2017-02-24 13:56:02 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
2019-04-27 14:54:30 +00:00
|
|
|
ret = vsnprintf(buffer, OGS_HUGE_LEN, format, ap);
|
|
|
|
if (ret < 0 || ret > OGS_HUGE_LEN)
|
2017-02-24 13:56:02 +00:00
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("vsnprintf() failed");
|
2017-02-24 13:56:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(printlevel)
|
|
|
|
{
|
|
|
|
case FD_LOG_ANNOYING:
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_trace("freeDiameter[%d]: %s", printlevel, buffer);
|
2017-02-24 13:56:02 +00:00
|
|
|
break;
|
|
|
|
case FD_LOG_DEBUG:
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_trace("freeDiameter[%d]: %s", printlevel, buffer);
|
2017-02-24 13:56:02 +00:00
|
|
|
break;
|
|
|
|
case FD_LOG_NOTICE:
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_trace("freeDiameter[%d]: %s", printlevel, buffer);
|
2017-02-24 13:56:02 +00:00
|
|
|
break;
|
|
|
|
case FD_LOG_ERROR:
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("%s", buffer);
|
2018-08-17 01:00:15 +00:00
|
|
|
if (!strcmp(buffer, " - The certificate is expired."))
|
|
|
|
{
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_error("You can renew CERT as follows:");
|
|
|
|
ogs_error("./support/freeDiameter/make_certs.sh "
|
2018-08-17 01:00:15 +00:00
|
|
|
"./install/etc/nextepc/freeDiameter");
|
|
|
|
}
|
2017-02-24 13:56:02 +00:00
|
|
|
break;
|
|
|
|
case FD_LOG_FATAL:
|
|
|
|
{
|
|
|
|
char *except = "Initiating freeDiameter shutdown sequence";
|
|
|
|
if (strncmp(buffer, except, strlen(except)) == 0)
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_info("freeDiameter[%d]: %s", printlevel, buffer);
|
2017-02-24 13:56:02 +00:00
|
|
|
else
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_fatal("%s", buffer);
|
2017-02-24 13:56:02 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2019-04-27 14:54:30 +00:00
|
|
|
ogs_warn("%s", buffer);
|
2017-02-24 13:56:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|