diff --git a/README.md b/README.md index 86ae8a1d7..eb38daba4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@

- +

diff --git a/config/custom-ue.yaml b/config/custom-ue.yaml index dc21a86a9..7672bb2f0 100644 --- a/config/custom-ue.yaml +++ b/config/custom-ue.yaml @@ -1,4 +1,4 @@ -# IMSI number of the UE. IMSI = [MCC|MNC|MSISDN] (In total 15 or 16 digits) +# IMSI number of the UE. IMSI = [MCC|MNC|MSISDN] (In total 15 digits) supi: 'imsi-286010000000001' # Mobile Country Code value of HPLMN mcc: '286' diff --git a/config/free5gc-ue.yaml b/config/free5gc-ue.yaml index bc47dd696..3a4725cc4 100644 --- a/config/free5gc-ue.yaml +++ b/config/free5gc-ue.yaml @@ -1,4 +1,4 @@ -# IMSI number of the UE. IMSI = [MCC|MNC|MSISDN] (In total 15 or 16 digits) +# IMSI number of the UE. IMSI = [MCC|MNC|MSISDN] (In total 15 digits) supi: 'imsi-208930000000003' # Mobile Country Code value of HPLMN mcc: '208' diff --git a/config/open5gs-ue.yaml b/config/open5gs-ue.yaml index 9f893cacd..ad85e0beb 100644 --- a/config/open5gs-ue.yaml +++ b/config/open5gs-ue.yaml @@ -1,4 +1,4 @@ -# IMSI number of the UE. IMSI = [MCC|MNC|MSISDN] (In total 15 or 16 digits) +# IMSI number of the UE. IMSI = [MCC|MNC|MSISDN] (In total 15 digits) supi: 'imsi-901700000000001' # Mobile Country Code value of HPLMN mcc: '901' diff --git a/src/utils/common_types.cpp b/src/utils/common_types.cpp index 0cddc21a5..0ba6eeb59 100644 --- a/src/utils/common_types.cpp +++ b/src/utils/common_types.cpp @@ -19,7 +19,7 @@ Supi Supi::Parse(const std::string &supi) if (supi[0] == 'i' && supi[1] == 'm' && supi[2] == 's' && supi[3] == 'i' && supi[4] == '-') { std::string val = supi.substr(5); - if (val.size() != 15 && val.size() != 16) + if (val.size() != 15) throw std::runtime_error("invalid IMSI value"); for (char c : val) if (c < '0' || c > '9') diff --git a/src/utils/constants.hpp b/src/utils/constants.hpp index 3bec6833b..2d1b669b7 100644 --- a/src/utils/constants.hpp +++ b/src/utils/constants.hpp @@ -15,10 +15,10 @@ struct cons // Version information static constexpr const uint8_t Major = 3; static constexpr const uint8_t Minor = 2; - static constexpr const uint8_t Patch = 2; + static constexpr const uint8_t Patch = 3; static constexpr const char *Project = "UERANSIM"; - static constexpr const char *Tag = "v3.2.2"; - static constexpr const char *Name = "UERANSIM v3.2.2"; + static constexpr const char *Tag = "v3.2.3"; + static constexpr const char *Name = "UERANSIM v3.2.3"; static constexpr const char *Owner = "ALİ GÜNGÖR"; // Some port values diff --git a/src/utils/io.cpp b/src/utils/io.cpp index d2345484b..218272dcd 100644 --- a/src/utils/io.cpp +++ b/src/utils/io.cpp @@ -14,10 +14,16 @@ #include #include +#include #include +#include +#include +#include +#include #include #include #include +#include #include #include @@ -183,4 +189,68 @@ void AppendPath(std::string &source, const std::string &target) source += target; } +std::string GetIp4OfInterface(const std::string &ifName) +{ + std::string res; + + struct ifreq ifr = {}; + + int fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd <= 0) + return ""; + + ifr.ifr_addr.sa_family = AF_INET; + strncpy(ifr.ifr_name, ifName.c_str(), IFNAMSIZ - 1); + + if (ioctl(fd, SIOCGIFADDR, &ifr)) + { + close(fd); + return ""; + } + + close(fd); + + auto address = ((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr; + + char str[INET_ADDRSTRLEN] = {0}; + if (inet_ntop(AF_INET, &address, str, INET_ADDRSTRLEN) == nullptr) + return ""; + + return std::string{str}; +} + +std::string GetHostByName(const std::string &name) +{ + struct addrinfo hints = {}; + + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_flags |= AI_CANONNAME; + + auto* res = gethostbyname(name.c_str()); + if (res == nullptr) + return ""; + if (res->h_addr_list == nullptr) + return ""; + + if (res->h_addrtype == AF_INET) + { + char str[INET_ADDRSTRLEN] = {0}; + if (inet_ntop(AF_INET, res->h_addr_list[0], str, INET_ADDRSTRLEN) == nullptr) + return ""; + return std::string{str}; + } + else if (res->h_addrtype == AF_INET) + { + char str[INET6_ADDRSTRLEN] = {0}; + if (inet_ntop(AF_INET6, res->h_addr_list[0], str, INET6_ADDRSTRLEN) == nullptr) + return ""; + return std::string{str}; + } + else + { + return ""; + } +} + } // namespace io diff --git a/src/utils/io.hpp b/src/utils/io.hpp index ae0163ba1..dd9cbbf63 100644 --- a/src/utils/io.hpp +++ b/src/utils/io.hpp @@ -40,4 +40,8 @@ std::string GetStem(const std::string &path); void AppendPath(std::string &source, const std::string &target); +std::string GetIp4OfInterface(const std::string &ifName); + +std::string GetHostByName(const std::string& name); + } // namespace io diff --git a/src/utils/yaml_utils.cpp b/src/utils/yaml_utils.cpp index 625b1e789..394a9791a 100644 --- a/src/utils/yaml_utils.cpp +++ b/src/utils/yaml_utils.cpp @@ -8,6 +8,7 @@ #include "yaml_utils.hpp" #include "common.hpp" +#include "io.hpp" #include #include @@ -143,11 +144,18 @@ int64_t GetInt64(const YAML::Node &node, const std::string &name, std::optional< std::string GetIp4(const YAML::Node &node, const std::string &name) { - std::string ip = GetString(node, name); - int version = utils::GetIpVersion(ip); - if (version != 4) - FieldError(name, "must be a valid IPv4 address"); - return ip; + std::string s = GetString(node, name); + + int version = utils::GetIpVersion(s); + if (version == 6) + FieldError(name, "must be a valid IPv4 address or a valid network interface with a IPv4 address"); + if (version == 4) + return s; + + auto ipFromIf = io::GetIp4OfInterface(s); + if (ipFromIf.empty()) + FieldError(name, "must be a valid IPv4 address or a valid network interface with a IPv4 address"); + return ipFromIf; } void AssertHasBool(const YAML::Node &node, const std::string &name)