open5gs/lib/s6a/s6a_config.c

153 lines
4 KiB
C
Raw Normal View History

2017-02-28 02:21:10 +00:00
#define TRACE_MODULE _s6a_config
2017-02-26 08:03:01 +00:00
#include "core_debug.h"
#include "core_lib.h"
2017-02-26 11:54:45 +00:00
#include "core_file.h"
2017-02-26 08:03:01 +00:00
2017-03-04 15:50:22 +00:00
#include "s6a_lib.h"
2017-02-26 08:03:01 +00:00
2017-02-28 02:21:10 +00:00
static struct s6a_config_t g_conf;
struct s6a_config_t *s6a_config;
2017-02-26 08:03:01 +00:00
2017-02-28 02:21:10 +00:00
static char *s6a_hss_conffile = SYSCONFDIR "hss_fd.conf";
static char *s6a_mme_conffile = SYSCONFDIR "mme_fd.conf";
2017-02-26 09:14:50 +00:00
2017-02-28 02:21:10 +00:00
static int s6a_config_apply_internal()
2017-02-26 08:03:01 +00:00
{
struct peer_info fddpi;
struct addrinfo hints, *ai;
int ret;
int disc = 0;
2017-02-28 02:21:10 +00:00
fd_g_config->cnf_diamid = s6a_config->cnf_diamid;
2017-02-26 08:03:01 +00:00
fd_os_validate_DiameterIdentity(
&fd_g_config->cnf_diamid, &fd_g_config->cnf_diamid_len, 1);
2017-02-28 02:21:10 +00:00
fd_g_config->cnf_diamrlm = s6a_config->cnf_diamrlm;
2017-02-26 08:03:01 +00:00
fd_os_validate_DiameterIdentity(
&fd_g_config->cnf_diamrlm, &fd_g_config->cnf_diamrlm_len, 1);
2017-02-28 02:21:10 +00:00
if (s6a_config->cnf_port)
fd_g_config->cnf_port = s6a_config->cnf_port;
if (s6a_config->cnf_port_tls)
fd_g_config->cnf_port_tls = s6a_config->cnf_port_tls;
2017-02-26 08:03:01 +00:00
memset(&fddpi, 0, sizeof(fddpi));
fddpi.config.pic_flags.persist = PI_PRST_ALWAYS;
fddpi.config.pic_flags.pro3 = PI_P3_IP;
fddpi.config.pic_flags.pro4 = PI_P4_TCP;
fddpi.config.pic_flags.alg = PI_ALGPREF_TCP;
fddpi.config.pic_flags.sec |= PI_SEC_NONE;
2017-02-28 02:21:10 +00:00
fddpi.config.pic_port = s6a_config->pic_port;
fddpi.pi_diamid = s6a_config->pi_diamid;
2017-02-26 08:03:01 +00:00
fd_list_init( &fddpi.pi_endpoints, NULL );
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICHOST;
ret = getaddrinfo("127.0.0.1", NULL, &hints, &ai);
if (ret)
return CORE_ERROR;
fd_ep_add_merge( &fddpi.pi_endpoints,
ai->ai_addr, ai->ai_addrlen, EP_FL_CONF | (disc ?: EP_ACCEPTALL) );
fd_peer_add ( &fddpi, NULL, NULL, NULL );
freeaddrinfo(ai);
return 0;
}
2017-02-28 02:21:10 +00:00
status_t s6a_config_apply()
2017-02-26 08:03:01 +00:00
{
char * buf = NULL, *b;
size_t len = 0;
2017-02-28 02:21:10 +00:00
CHECK_FCT( s6a_config_apply_internal() );
2017-02-26 08:03:01 +00:00
/* The following module use data from the configuration */
int fd_rtdisp_init(void);
2017-02-26 11:54:45 +00:00
CHECK_FCT( fd_rtdisp_init() );
2017-02-26 08:03:01 +00:00
/* Display configuration */
b = fd_conf_dump(&buf, &len, NULL);
2017-02-27 12:29:32 +00:00
LOG_SPLIT(FD_LOG_NOTICE, NULL,
b ?: "<Error during configuration dump...>", NULL);
2017-02-26 08:03:01 +00:00
free(buf);
/* Since some extensions might have modified the definitions from the dict_base_protocol, we only load the objects now */
int fd_msg_init(void);
2017-02-26 11:54:45 +00:00
CHECK_FCT( fd_msg_init() );
2017-02-26 08:03:01 +00:00
return CORE_OK;
}
2017-02-28 02:21:10 +00:00
#define HSS_IDENTITY "hss.localdomain"
2017-02-26 11:54:45 +00:00
#define HSS_REALM "localdomain"
#define HSS_PORT 30868
#define HSS_SECURE_PORT 30869
2017-02-28 02:21:10 +00:00
#define MME_IDENTITY "mme.localdomain"
2017-02-26 11:54:45 +00:00
#define MME_REALM "localdomain"
#define MME_PORT DIAMETER_PORT
#define MME_SECURE_PORT DIAMETER_SECURE_PORT
2017-02-26 08:03:01 +00:00
2017-02-28 02:21:10 +00:00
static int s6a_common_config(void)
{
memset(&g_conf, 0, sizeof(struct s6a_config_t));
s6a_config = &g_conf;
/* Set the default values */
2017-02-28 11:31:06 +00:00
s6a_config->mode = MODE_MME | MODE_HSS;
2017-02-28 02:21:10 +00:00
s6a_config->vendor_id = 10415; /* 3GPP Vendor ID */
s6a_config->appli_id = 16777251; /* 3GPP S6A Application ID */
2017-02-28 11:31:06 +00:00
s6a_config->duration = 10; /* 10 seconds */
2017-02-28 02:21:10 +00:00
return 0;
}
char *s6a_hss_config()
2017-02-26 08:03:01 +00:00
{
2017-02-26 11:54:45 +00:00
status_t rv;
file_info_t file_info;
2017-02-28 02:21:10 +00:00
char *conffile = s6a_hss_conffile;
2017-02-26 09:14:50 +00:00
2017-02-28 02:21:10 +00:00
s6a_common_config();
s6a_config->cnf_diamid = HSS_IDENTITY;
s6a_config->cnf_diamrlm = HSS_REALM;
s6a_config->cnf_port = HSS_PORT;
s6a_config->cnf_port_tls = HSS_SECURE_PORT;
s6a_config->pi_diamid = MME_IDENTITY;
s6a_config->pic_port = MME_PORT;
2017-02-26 11:54:45 +00:00
rv = file_stat(&file_info, conffile, FILE_INFO_TYPE);
if (rv == CORE_OK && file_info.filetype == FILE_REG)
{
return conffile;
}
2017-02-26 09:14:50 +00:00
return NULL;
2017-02-26 08:03:01 +00:00
}
2017-02-28 02:21:10 +00:00
char *s6a_mme_config()
2017-02-26 08:03:01 +00:00
{
2017-02-26 11:54:45 +00:00
status_t rv;
file_info_t file_info;
2017-02-28 02:21:10 +00:00
char *conffile = s6a_mme_conffile;
2017-02-26 11:54:45 +00:00
2017-02-28 02:21:10 +00:00
s6a_common_config();
2017-02-26 11:54:45 +00:00
2017-02-28 02:21:10 +00:00
s6a_config->cnf_diamid = MME_IDENTITY;
s6a_config->cnf_diamrlm = MME_REALM;
s6a_config->pi_diamid = HSS_IDENTITY;
s6a_config->pic_port = HSS_PORT;
2017-02-26 08:03:01 +00:00
2017-02-26 11:54:45 +00:00
rv = file_stat(&file_info, conffile, FILE_INFO_TYPE);
if (rv == CORE_OK && file_info.filetype == FILE_REG)
{
return conffile;
}
2017-02-26 09:14:50 +00:00
return NULL;
2017-02-26 08:03:01 +00:00
}