tunneldiggercpp

git clone git://archive.git.mtrnord.blog/MTRNord/tunneldiggercpp.git
Log | Files | Refs | README

commit 22eab850993d961e12e8d3acd42b85fd854a8e4d
parent 8ee762c8c75f9bf57a2e93bbe1479c3d97052db4
Author: MTRNord <mtrnord1@gmail.com>
Date:   Fri, 22 Sep 2017 20:03:42 +0200

Prepare iptables in broker.

Signed-off-by: MTRNord <mtrnord1@gmail.com>

Diffstat:
Mbroker.cpp | 60++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Mbroker.h | 4++++
Mmain.cpp | 1-
3 files changed, 56 insertions(+), 9 deletions(-)

diff --git a/broker.cpp b/broker.cpp @@ -2,13 +2,57 @@ // Created by marce on 22.09.2017. // -#include "broker.h" -#include <iostream> +#ifdef linux + #include "broker.h" + #include <iostream> + #include <sys/types.h> + #include <sys/wait.h> + #include <unistd.h> + #include <errno.h> + #include <stdlib.h> -using namespace std; + using namespace std; -int broker::TunnelManager::initialize() { - printf("Prepare Routing"); + broker::TunnelManager::TunnelManager(char * nspaceL) { + nspace = nspaceL; + } - return 0; -} -\ No newline at end of file + int broker::TunnelManager::initialize() { + printf("Prepare Routing"); + + char * prerouting_chain = (char *) printf("L2TP_PREROUTING_%s", nspace); + char * postrouting_chain = (char *) printf("L2TP_POSTROUTING_%s", nspace); + + pid_t pid; + int status; + pid_t ret; + char *const args[3] = {"iptables", "--version", NULL}; + char **env; + extern char **environ; + + /* ... Sanitize arguments ... */ + + pid = fork(); + if (pid == -1) { + /* Handle error */ + } else if (pid != 0) { + while ((ret = waitpid(pid, &status, 0)) == -1) { + if (errno != EINTR) { + /* Handle error */ + break; + } + } + if ((ret != -1) && + (!WIFEXITED(status) || !WEXITSTATUS(status)) ) { + /* Report unexpected child status */ + } + } else { + if (execve("iptables", args, env) == -1) { + /* Handle error */ + _Exit(127); + } + } + + return 0; + } +#endif +\ No newline at end of file diff --git a/broker.h b/broker.h @@ -10,7 +10,11 @@ class broker { public: class TunnelManager { public: + TunnelManager(char * nspaceL); int initialize(); + private: + //Namespace is a taken var name in C++ so I use nspace isntead + char * nspace; }; }; diff --git a/main.cpp b/main.cpp @@ -1,6 +1,5 @@ #ifdef linux #include <unistd.h> - #include <libiptc/libiptc.h> #endif #include <iostream>