Skip to content

Commit

Permalink
Merge pull request #376 from aligungr/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
aligungr committed Aug 11, 2021
2 parents 375d538 + 552a2eb commit ce21fef
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<a href="https://github.com/aligungr/UERANSIM"><img src="/.github/logo.png" width="75" title="UERANSIM"></a>
</p>
<p align="center">
<img src="https://img.shields.io/badge/UERANSIM-v3.2.2-blue" />
<img src="https://img.shields.io/badge/UERANSIM-v3.2.3-blue" />
<img src="https://img.shields.io/badge/3GPP-R15-orange" />
<img src="https://img.shields.io/badge/License-GPL--3.0-green"/>
</p>
Expand Down
2 changes: 1 addition & 1 deletion config/custom-ue.yaml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion config/free5gc-ue.yaml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion config/open5gs-ue.yaml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/utils/common_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions src/utils/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 70 additions & 0 deletions src/utils/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
#include <queue>
#include <stack>

#include <arpa/inet.h>
#include <dirent.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <netdb.h>

#include <utils/constants.hpp>
#include <utils/libc_error.hpp>
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions src/utils/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 13 additions & 5 deletions src/utils/yaml_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "yaml_utils.hpp"
#include "common.hpp"
#include "io.hpp"

#include <cctype>
#include <stdexcept>
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ce21fef

Please sign in to comment.