Commit 284aa70e authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

Support FQDN Resolver

parent 036ddedb
......@@ -81,10 +81,10 @@ class smf_context_ref {
void clear() {
supi = {};
nssai = {};
dnn = "";
dnn = {};
pdu_session_id = 0;
amf_status_uri = "";
amf_addr = "";
amf_status_uri = {};
amf_addr = {};
upf_node_id = {};
}
......@@ -214,6 +214,7 @@ class smf_app {
void operator=(smf_app const&) = delete;
void test_dns();
/*
* Set the association between Seid and SM Context
* @param [const seid_t &] seid: SessionID
......
......@@ -49,6 +49,7 @@
#include "epc.h"
#include "if.hpp"
#include "logger.hpp"
#include "fqdn.hpp"
#include "smf_app.hpp"
using namespace std;
......@@ -580,6 +581,14 @@ int smf_config::load(const string& config_file) {
force_push_pco = false;
}
support_features.lookupValue(
SMF_CONFIG_STRING_SUPPORT_FEATURES_USE_FQDN_DNS, opt);
if (boost::iequals(opt, "yes")) {
use_fqdn_dns = true;
} else {
use_fqdn_dns = false;
}
} catch (const SettingNotFoundException& nfex) {
Logger::smf_app().error(
"%s : %s, using defaults", nfex.what(), nfex.getPath());
......@@ -590,7 +599,9 @@ int smf_config::load(const string& config_file) {
const Setting& amf_cfg = smf_cfg[SMF_CONFIG_STRING_AMF];
struct in_addr amf_ipv4_addr;
unsigned int amf_port = 0;
std::string amf_api_version;
std::string amf_api_version = {};
if (!use_fqdn_dns) {
amf_cfg.lookupValue(SMF_CONFIG_STRING_AMF_IPV4_ADDRESS, astring);
IPV4_STR_ADDR_TO_INADDR(
util::trim(astring).c_str(), amf_ipv4_addr,
......@@ -608,12 +619,38 @@ int smf_config::load(const string& config_file) {
throw(SMF_CONFIG_STRING_API_VERSION "failed");
}
amf_addr.api_version = amf_api_version;
} else {
amf_cfg.lookupValue(SMF_CONFIG_STRING_FQDN_DNS, astring);
// astring = "maserati";
uint8_t addr_type = 0;
std::string address = {};
fqdn::resolve(astring, address, amf_port, addr_type);
if (addr_type != 0) {
// IPv6
// TODO:
throw(
"DO NOT SUPPORT IPV6 ADDR FOR AMF"
"failed");
} else {
// IPv4
IPV4_STR_ADDR_TO_INADDR(
util::trim(address).c_str(), amf_ipv4_addr,
"BAD IPv4 ADDRESS FORMAT FOR AMF !");
amf_addr.ipv4_addr = amf_ipv4_addr;
amf_addr.port = amf_port;
}
// TODO: How to get API version from DNS
}
// UDM
const Setting& udm_cfg = smf_cfg[SMF_CONFIG_STRING_UDM];
struct in_addr udm_ipv4_addr;
unsigned int udm_port = 0;
std::string udm_api_version;
if (!use_fqdn_dns) {
udm_cfg.lookupValue(SMF_CONFIG_STRING_UDM_IPV4_ADDRESS, astring);
IPV4_STR_ADDR_TO_INADDR(
util::trim(astring).c_str(), udm_ipv4_addr,
......@@ -631,6 +668,29 @@ int smf_config::load(const string& config_file) {
throw(SMF_CONFIG_STRING_API_VERSION "failed");
}
udm_addr.api_version = udm_api_version;
} else {
udm_cfg.lookupValue(SMF_CONFIG_STRING_FQDN_DNS, astring);
uint8_t addr_type = 0;
std::string address = {};
fqdn::resolve(astring, address, udm_port, addr_type);
if (addr_type != 0) {
// IPv6
// TODO:
throw(
"DO NOT SUPPORT IPV6 ADDR FOR UDM"
"failed");
} else {
// IPv4
IPV4_STR_ADDR_TO_INADDR(
util::trim(address).c_str(), udm_ipv4_addr,
"BAD IPv4 ADDRESS FORMAT FOR UDM !");
udm_addr.ipv4_addr = udm_ipv4_addr;
udm_addr.port = udm_port;
}
// TODO: How to get API version from DNS
}
// UPF list
unsigned char buf_in_addr[sizeof(struct in_addr) + 1];
......@@ -638,8 +698,60 @@ int smf_config::load(const string& config_file) {
count = upf_list_cfg.getLength();
for (int i = 0; i < count; i++) {
const Setting& upf_cfg = upf_list_cfg[i];
// TODO FQDN
string address = {};
if (!use_fqdn_dns) {
if (upf_cfg.lookupValue(SMF_CONFIG_STRING_UPF_IPV4_ADDRESS, address)) {
pfcp::node_id_t n = {};
n.node_id_type = pfcp::NODE_ID_TYPE_IPV4_ADDRESS; // actually
if (inet_pton(AF_INET, util::trim(address).c_str(), buf_in_addr) ==
1) {
memcpy(&n.u1.ipv4_address, buf_in_addr, sizeof(struct in_addr));
} else {
Logger::smf_app().error(
"CONFIG: BAD IPV4 ADDRESS in " SMF_CONFIG_STRING_UPF_LIST
" item %d",
i);
throw("CONFIG: BAD ADDRESS in " SMF_CONFIG_STRING_UPF_LIST);
}
upfs.push_back(n);
}
} else {
unsigned int upf_port = 0;
upf_cfg.lookupValue(SMF_CONFIG_STRING_FQDN_DNS, astring);
uint8_t addr_type = 0;
std::string address = {};
fqdn::resolve(astring, address, upf_port, addr_type, "");
if (addr_type != 0) {
// IPv6
// TODO:
throw(
"DO NOT SUPPORT IPV6 ADDR FOR NRF"
"failed");
} else {
// IPv4
pfcp::node_id_t n = {};
n.node_id_type = pfcp::NODE_ID_TYPE_IPV4_ADDRESS; // actually
if (inet_pton(AF_INET, util::trim(address).c_str(), buf_in_addr) ==
1) {
memcpy(&n.u1.ipv4_address, buf_in_addr, sizeof(struct in_addr));
} else {
Logger::smf_app().error(
"CONFIG: BAD IPV4 ADDRESS in " SMF_CONFIG_STRING_UPF_LIST
" item %d",
i);
throw("CONFIG: BAD ADDRESS in " SMF_CONFIG_STRING_UPF_LIST);
}
upfs.push_back(n);
}
// TODO: How to get API version from DNS
}
if (upf_cfg.lookupValue(SMF_CONFIG_STRING_UPF_IPV4_ADDRESS, address)) {
pfcp::node_id_t n = {};
n.node_id_type = pfcp::NODE_ID_TYPE_IPV4_ADDRESS; // actually
......@@ -666,6 +778,7 @@ int smf_config::load(const string& config_file) {
struct in_addr nrf_ipv4_addr;
unsigned int nrf_port = 0;
std::string nrf_api_version;
if (!use_fqdn_dns) {
nrf_cfg.lookupValue(SMF_CONFIG_STRING_NRF_IPV4_ADDRESS, astring);
IPV4_STR_ADDR_TO_INADDR(
util::trim(astring).c_str(), nrf_ipv4_addr,
......@@ -683,6 +796,29 @@ int smf_config::load(const string& config_file) {
throw(SMF_CONFIG_STRING_API_VERSION "failed");
}
nrf_addr.api_version = nrf_api_version;
} else {
nrf_cfg.lookupValue(SMF_CONFIG_STRING_FQDN_DNS, astring);
uint8_t addr_type = 0;
std::string address = {};
fqdn::resolve(astring, address, nrf_port, addr_type);
if (addr_type != 0) {
// IPv6
// TODO:
throw(
"DO NOT SUPPORT IPV6 ADDR FOR NRF"
"failed");
} else {
// IPv4
IPV4_STR_ADDR_TO_INADDR(
util::trim(address).c_str(), nrf_ipv4_addr,
"BAD IPv4 ADDRESS FORMAT FOR NRF !");
nrf_addr.ipv4_addr = nrf_ipv4_addr;
nrf_addr.port = nrf_port;
}
// TODO: How to get API version from DNS
}
// Local configuration
num_session_management_subscription = 0;
......
......@@ -137,6 +137,9 @@
"USE_LOCAL_SUBSCRIPTION_INFO"
#define SMF_CONFIG_STRING_NAS_FORCE_PUSH_PCO \
"FORCE_PUSH_PROTOCOL_CONFIGURATION_OPTIONS"
#define SMF_CONFIG_STRING_SUPPORT_FEATURES_USE_FQDN_DNS "USE_FQDN_DNS"
#define SMF_CONFIG_STRING_FQDN_DNS "FQDN"
#define SMF_MAX_ALLOCATED_PDN_ADDRESSES 1024
......@@ -217,6 +220,7 @@ class smf_config {
bool register_nrf;
bool discover_upf;
bool use_local_subscription_info;
bool use_fqdn_dns;
struct {
struct in_addr ipv4_addr;
......@@ -314,6 +318,7 @@ class smf_config {
use_local_subscription_info = false;
register_nrf = false;
discover_upf = false;
use_fqdn_dns = false;
};
~smf_config();
void lock() { m_rw_lock.lock(); };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment