Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: oxen-io/lokinet
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3e14ff45285a8f7fcc4d270df927c58bbab0a9af
Choose a base ref
..
head repository: oxen-io/lokinet
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b1711f3e8bc3c7bd2c26dcd16737b4c42430cf8e
Choose a head ref
Showing with 6 additions and 7 deletions.
  1. +6 −7 llarp/vpn/linux.hpp
13 changes: 6 additions & 7 deletions llarp/vpn/linux.hpp
Original file line number Diff line number Diff line change
@@ -60,15 +60,14 @@ namespace llarp::vpn
if (::ioctl(_fd, TUNSETIFF, &ifr) == -1)
throw std::runtime_error("cannot set interface name: {}"_format(strerror(errno)));

ifreq ctrl_ifr{};
IOCTL control{AF_INET};

control.ioctl(SIOCGIFFLAGS, &ifr);
short int flags = ifr.ifr_flags;

control.ioctl(SIOCGIFINDEX, &ifr);
_info.index = ifr.ifr_ifindex;

control.ioctl(SIOCGIFFLAGS, &ctrl_ifr);
short int flags = ctrl_ifr.ifr_flags;

for (const auto& ifaddr : _info.addrs)
{
auto& range = ifaddr.range;
@@ -113,7 +112,7 @@ namespace llarp::vpn
}
}

ifr.ifr_flags |= static_cast<short int>(flags | IFF_UP | IFF_RUNNING);
ifr.ifr_flags = static_cast<short int>(flags | IFF_UP);
control.ioctl(SIOCSIFFLAGS, &ifr);
}

@@ -123,7 +122,7 @@ namespace llarp::vpn

IPPacket read_next_packet() override
{
log::debug(logcat, "{} called", __PRETTY_FUNCTION__);
log::trace(logcat, "{} called", __PRETTY_FUNCTION__);
std::vector<uint8_t> buf;
buf.resize(MAX_PACKET_SIZE);
const auto sz = read(_fd, buf.data(), buf.capacity());
@@ -144,7 +143,7 @@ namespace llarp::vpn
bool write_packet(IPPacket pkt) override
{
const auto sz = write(_fd, pkt.data(), pkt.size());
log::debug(logcat, "{} bytes written to fd {}", sz, _fd);
log::trace(logcat, "{} bytes written to fd {}", sz, _fd);
if (sz <= 0)
return false;
return sz == static_cast<ssize_t>(pkt.size());