allow failure of setting ipv6 address when it is not allowed by kernel on linux

pull/1583/head
Jeff Becker 3 years ago
parent ec242447a0
commit c07358f084
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -3,9 +3,16 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <cerrno>
namespace llarp::vpn namespace llarp::vpn
{ {
class permission_error : public std::runtime_error
{
public:
using std::runtime_error::runtime_error;
};
struct IOCTL struct IOCTL
{ {
const int _fd; const int _fd;
@ -26,7 +33,14 @@ namespace llarp::vpn
ioctl(Command cmd, Args&&... args) ioctl(Command cmd, Args&&... args)
{ {
if (::ioctl(_fd, cmd, std::forward<Args>(args)...) == -1) if (::ioctl(_fd, cmd, std::forward<Args>(args)...) == -1)
throw std::runtime_error("ioctl failed: " + std::string{strerror(errno)}); {
if (errno == EACCES)
{
throw permission_error{"we are not allowed to call this ioctl"};
}
else
throw std::runtime_error("ioctl failed: " + std::string{strerror(errno)});
}
} }
}; };
} // namespace llarp::vpn } // namespace llarp::vpn

@ -66,7 +66,14 @@ namespace llarp::vpn
ifr6.addr = net::HUIntToIn6(ifaddr.range.addr); ifr6.addr = net::HUIntToIn6(ifaddr.range.addr);
ifr6.prefixlen = llarp::bits::count_bits(ifaddr.range.netmask_bits); ifr6.prefixlen = llarp::bits::count_bits(ifaddr.range.netmask_bits);
ifr6.ifindex = ifindex; ifr6.ifindex = ifindex;
control6.ioctl(SIOCSIFADDR, &ifr6); try
{
control6.ioctl(SIOCSIFADDR, &ifr6);
}
catch (permission_error& ex)
{
LogError("we are not allowed to use IPv6 on this system: ", ex.what());
}
} }
} }
ifr.ifr_flags = static_cast<short>(flags | IFF_UP | IFF_NO_PI); ifr.ifr_flags = static_cast<short>(flags | IFF_UP | IFF_NO_PI);
@ -75,8 +82,7 @@ namespace llarp::vpn
virtual ~LinuxInterface() virtual ~LinuxInterface()
{ {
if (m_fd != -1) ::close(m_fd);
::close(m_fd);
} }
int int

Loading…
Cancel
Save