17 #ifndef __LINUX_ROUTING_LINK_INTERNAL_HPP__
18 #define __LINUX_ROUTING_LINK_INTERNAL_HPP__
23 #include <sys/ioctl.h>
24 #include <sys/socket.h>
28 #include <netlink/cache.h>
29 #include <netlink/errno.h>
30 #include <netlink/socket.h>
32 #include <netlink/route/link.h>
47 inline void cleanup(
struct rtnl_link* link)
66 struct nl_cache* c =
nullptr;
67 int error = rtnl_link_alloc_cache(socket.
get().get(), AF_UNSPEC, &c);
69 return Error(nl_geterror(error));
73 struct rtnl_link* l = rtnl_link_get_by_name(cache.
get(), link.c_str());
93 struct nl_cache* c =
nullptr;
94 int error = rtnl_link_alloc_cache(socket.
get().get(), AF_UNSPEC, &c);
96 return Error(nl_geterror(error));
100 struct rtnl_link* l = rtnl_link_get(cache.
get(),
index);
116 }
else if (link.
isNone()) {
120 return flags == (rtnl_link_get_flags(link.
get().get()) & flags);
130 }
else if (link.
isNone()) {
137 memset(&ifr, 0,
sizeof(ifr));
140 ifr.ifr_flags = (rtnl_link_get_flags(link.
get().get()) | flags);
142 strncpy(ifr.ifr_name, _link.c_str(), IFNAMSIZ);
144 int fd =
::socket(AF_INET, SOCK_STREAM, 0);
149 if (ioctl(fd, SIOCSIFFLAGS, &ifr) == -1) {
150 if (errno == ENODEV) {
157 return Error(message);
169 #endif // __LINUX_ROUTING_LINK_INTERNAL_HPP__
std::string strerror(int errno_)
A thread-safe version of strerror.
Definition: strerror.hpp:30
bool isNone() const
Definition: result.hpp:112
Definition: errorbase.hpp:35
static Result< T > error(const std::string &message)
Definition: result.hpp:53
Definition: errorbase.hpp:49
Definition: result.hpp:40
Try< bool > set(const std::string &_link, unsigned int flags)
Definition: internal.hpp:125
Result< int > index(const std::string &link)
Try< Nothing > close(int fd)
Definition: close.hpp:24
T * get() const
Definition: internal.hpp:65
const T & get() const
Definition: result.hpp:115
Definition: internal.hpp:60
static Try error(const E &e)
Definition: try.hpp:42
#define flags
Definition: decoder.hpp:18
bool isError() const
Definition: try.hpp:71
std::string error(const std::string &msg, uint32_t code)
bool isError() const
Definition: result.hpp:113
void cleanup(struct rtnl_cls *cls)
Definition: internal.hpp:64
Result< bool > test(const std::string &_link, unsigned int flags)
Definition: internal.hpp:111
Try< Netlink< struct nl_sock > > socket(int protocol=NETLINK_ROUTE)
Definition: internal.hpp:91
const T & get() const
Definition: try.hpp:73