Skip to content

Commit

Permalink
UE TUN MTU decreased to 1400
Browse files Browse the repository at this point in the history
  • Loading branch information
aligungr committed Mar 9, 2021
1 parent 05f1c4f commit 4d79049
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ue/app/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void UeAppTask::setupTunInterface(const PduSession *pduSession)

std::string ipAddress = utils::OctetStringToIp(pduSession->pduAddress->pduAddressInformation);

bool r = tun::TunConfigure(allocatedName, ipAddress, m_base->config->configureRouting, error);
bool r = tun::TunConfigure(allocatedName, ipAddress, cons::TunMtu, m_base->config->configureRouting, error);
if (!r || error.length() > 0)
{
m_logger->err("TUN configuration failure [%s]", error.c_str());
Expand Down
13 changes: 7 additions & 6 deletions src/ue/tun/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ static const char *NextInterfaceName(const std::string &prefix)
return nullptr;
}

static void TunSetIpAndUp(const char *ifName, const char *ipAddr)
static void TunSetIpAndUp(const char *ifName, const char *ipAddr, int mtu)
{
ifreq ifr{};
memset(&ifr, 0, sizeof(struct ifreq));
Expand All @@ -133,14 +133,15 @@ static void TunSetIpAndUp(const char *ifName, const char *ipAddr)
memcpy((((char *)&ifr + offsetof(struct ifreq, ifr_addr))), p, sizeof(struct sockaddr));

if (ioctl(sockFd, SIOCSIFADDR, &ifr) < 0)
{
throw LibError("ioctl(SIOCSIFADDR)", errno);
}
if (ioctl(sockFd, SIOCGIFFLAGS, &ifr) < 0)
throw LibError("ioctl(SIOCGIFFLAGS)", errno);

ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
ifr.ifr_mtu = mtu;
if (ioctl(sockFd, SIOCSIFMTU, &ifr) < 0)
throw LibError("ioctl(SIOCSIFMTU)", errno);

ifr.ifr_flags |= IFF_UP | IFF_RUNNING;
if (ioctl(sockFd, SIOCSIFFLAGS, &ifr) < 0)
throw LibError("ioctl(SIOCSIFFLAGS)", errno);

Expand Down Expand Up @@ -349,12 +350,12 @@ int AllocateTun(const char *ifPrefix, char **allocatedName)
return fd;
}

void ConfigureTun(const char *tunName, const char *ipAddr, bool configureRoute)
void ConfigureTun(const char *tunName, const char *ipAddr, int mtu, bool configureRoute)
{
// acquire the configuration lock
const std::lock_guard<std::mutex> lock(configMutex);

TunSetIpAndUp(tunName, ipAddr);
TunSetIpAndUp(tunName, ipAddr, mtu);
if (configureRoute)
{
std::string table_name = ROUTING_TABLE_PREFIX + std::string(tunName);
Expand Down
2 changes: 1 addition & 1 deletion src/ue/tun/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ namespace nr::ue::tun
{

int AllocateTun(const char *ifPrefix, char **allocatedName);
void ConfigureTun(const char *tunName, const char *ipAddr, bool configureRoute);
void ConfigureTun(const char *tunName, const char *ipAddr, int mtu, bool configureRoute);

} // namespace nr::ue::tun
4 changes: 2 additions & 2 deletions src/ue/tun/tun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ int TunAllocate(const char *namePrefix, std::string &allocatedName, std::string
return fd;
}

bool TunConfigure(const std::string &tunName, const std::string &ipAddress, bool configureRouting, std::string &error)
bool TunConfigure(const std::string &tunName, const std::string &ipAddress, int mtu, bool configureRouting, std::string &error)
{
try
{
tun::ConfigureTun(tunName.c_str(), ipAddress.c_str(), configureRouting);
tun::ConfigureTun(tunName.c_str(), ipAddress.c_str(), mtu, configureRouting);
}
catch (const LibError &e)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ue/tun/tun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ namespace nr::ue::tun
{

int TunAllocate(const char *namePrefix, std::string &allocatedName, std::string &error);
bool TunConfigure(const std::string &tunName, const std::string &ipAddress, bool configureRouting, std::string &error);
bool TunConfigure(const std::string &tunName, const std::string &ipAddress, int mtu, bool configureRouting, std::string &error);

} // namespace nr::ue::tun
1 change: 1 addition & 0 deletions src/utils/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct cons

// TUN interface
static constexpr const char *TunNamePrefix = "uesimtun";
static constexpr const int TunMtu = 1400;

// Constraints
static constexpr const int MinNodeName = 3;
Expand Down

0 comments on commit 4d79049

Please sign in to comment.