diff options
| author | Grant Limberg <grant.limberg@zerotier.com> | 2018-05-25 14:18:06 -0700 |
|---|---|---|
| committer | Grant Limberg <grant.limberg@zerotier.com> | 2018-05-25 14:18:06 -0700 |
| commit | be469f4dd034050ca95a953903b3170ace275b27 (patch) | |
| tree | 862260cd1a1de6abc98fe00dc22e5d53e7a40d7c /osdep/ManagedRoute.cpp | |
| parent | 7da4b0af15fe5ff48db75471a3b416bbf2a6b822 (diff) | |
| download | infinitytier-be469f4dd034050ca95a953903b3170ace275b27.tar.gz infinitytier-be469f4dd034050ca95a953903b3170ace275b27.zip | |
add/remove routes via rtnetlink
Diffstat (limited to 'osdep/ManagedRoute.cpp')
| -rw-r--r-- | osdep/ManagedRoute.cpp | 41 |
1 files changed, 6 insertions, 35 deletions
diff --git a/osdep/ManagedRoute.cpp b/osdep/ManagedRoute.cpp index 8d64fde3..fe7c6267 100644 --- a/osdep/ManagedRoute.cpp +++ b/osdep/ManagedRoute.cpp @@ -54,6 +54,7 @@ #include <asm/types.h> #include <linux/rtnetlink.h> #include <sys/socket.h> +#include "../osdep/LinuxNetLink.hpp" #endif #ifdef __BSD__ #include <net/if_dl.h> @@ -284,44 +285,14 @@ static void _routeCmd(const char *op,const InetAddress &target,const InetAddress #ifdef __LINUX__ // ---------------------------------------------------------- #define ZT_ROUTING_SUPPORT_FOUND 1 -static bool _hasRoute(const InetAddress &target, const InetAddress &via, const char *localInterface) -{ - if (target.ss_family == AF_INET) { - int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); - - char *buf; - int nll; - struct rtmsg *rtp; - int rtl; - struct rtattr *rtap; - - struct sockaddr_nl la; - bzero(&la, sizeof(la)); - la.nl_family = AF_NETLINK; - la.nl_pad = 0; - la.nl_pid = (uint32_t)((ptrdiff_t)&target % getpid()); - la.nl_groups = 0; - int rtn = bind(fd, (struct sockaddr*)&la, sizeof(la)); - - - - close(fd); - return false; - } else { - - return false; - } -} - - static void _routeCmd(const char *op, const InetAddress &target, const InetAddress &via, const char *localInterface) { - bool hasRoute = _hasRoute(target, via, localInterface); - if (hasRoute && (strcmp(op, "add") == 0 || strcmp(op, "replace") == 0)) { - return; - } else if (!hasRoute && (strcmp(op, "remove") == 0 || strcmp(op, "del") == 0)) { - return; + if ((strcmp(op, "add") == 0 || strcmp(op, "replace") == 0)) { + LinuxNetLink::getInstance().addRoute(target, via, localInterface); + } else if ((strcmp(op, "remove") == 0 || strcmp(op, "del") == 0)) { + LinuxNetLink::getInstance().delRoute(target, via, localInterface); } + return; char targetStr[64] = {0}; char viaStr[64] = {0}; |
