summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOthmar Gsenger <otti@anytun.org>2008-12-21 21:13:19 +0000
committerOthmar Gsenger <otti@anytun.org>2008-12-21 21:13:19 +0000
commit3eb3af4681a96401c070f76fb78fb5593b795f1a (patch)
treeb2729b3b13b139bc909693a3459fbb5f64f5ddb1
parentrewrote syncClient and anytun-showtables (diff)
added route option to anytun
-rw-r--r--src/anytun.cpp9
-rw-r--r--src/options.cpp25
-rw-r--r--src/options.h12
3 files changed, 46 insertions, 0 deletions
diff --git a/src/anytun.cpp b/src/anytun.cpp
index ca77e63..a235786 100644
--- a/src/anytun.cpp
+++ b/src/anytun.cpp
@@ -409,6 +409,15 @@ int main(int argc, char* argv[])
createConnection(endpoint,cl,gOpt.getSeqWindowSize(), queue, gOpt.getMux());
}
+ RouteList routes = gOpt.getRoutes();
+ RouteList::const_iterator rit;
+ for(rit = routes.begin(); rit != routes.end(); ++rit)
+ {
+ NetworkAddress addr( rit->net_addr );
+ NetworkPrefix prefix( addr, rit->prefix_length );
+ gRoutingTable.addRoute( prefix, gOpt.getMux() );
+ }
+
#ifndef NODAEMON
if(gOpt.getChroot())
chrootAndDrop(gOpt.getChrootDir(), gOpt.getUsername());
diff --git a/src/options.cpp b/src/options.cpp
index 4bf4ef7..45db202 100644
--- a/src/options.cpp
+++ b/src/options.cpp
@@ -152,6 +152,7 @@ bool Options::parse(int argc, char* argv[])
progname_ = argv[0];
argc--;
+ std::queue<std::string> route_queue;
std::queue<std::string> host_port_queue;
for(int i=1; argc > 0; ++i)
{
@@ -187,6 +188,7 @@ bool Options::parse(int argc, char* argv[])
PARSE_SCALAR_PARAM("-a","--auth-algo", auth_algo_)
PARSE_CSLIST_PARAM("-M","--sync-hosts", host_port_queue)
PARSE_CSLIST_PARAM("-X","--control-host", host_port_queue)
+ PARSE_CSLIST_PARAM("-R","--route", route_queue)
else
return false;
}
@@ -205,6 +207,17 @@ bool Options::parse(int argc, char* argv[])
if(!ret) return false;
host_port_queue.pop();
}
+ while(!route_queue.empty())
+ {
+ std::stringstream tmp_stream(route_queue.front());
+ OptionRoute rt;
+ getline(tmp_stream,rt.net_addr,'/');
+ if(!tmp_stream.good())
+ return false;
+ tmp_stream >> rt.prefix_length;
+ route_queue.pop();
+ routes_.push_back(rt);
+ }
return true;
}
@@ -288,6 +301,7 @@ void Options::printUsage()
std::cout << " [-A|--salt] <master salt> master salt to use for encryption" << std::endl;
// std::cout << " [-k|--kd-prf] <kd-prf type> key derivation pseudo random function" << std::endl;
std::cout << " [-a|--auth-algo] <algo type> message authentication algorithm" << std::endl;
+ std::cout << " [-R|--route] <net>/<prefix length> add a route to connection, can be invoked several times" << std::endl;
}
void Options::printOptions()
@@ -324,6 +338,10 @@ void Options::printOptions()
for(; it != connect_to_.end(); ++it)
std::cout << "'" << it->host << "','" << it->port << "';";
std::cout << std::endl;
+ std::cout << "routes:" << std::endl;
+ RouteList::const_iterator rit;
+ for(rit = routes_.begin(); rit != routes_.end(); ++rit)
+ std::cout << " " << rit->net_addr << "/" << rit->prefix_length << std::endl;
}
std::string Options::getProgname()
@@ -675,3 +693,10 @@ Options& Options::setSalt(std::string s)
salt_ = s;
return *this;
}
+
+RouteList Options::getRoutes()
+{
+ Lock lock(mutex);
+ return routes_;
+}
+
diff --git a/src/options.h b/src/options.h
index f0054b2..11c1a93 100644
--- a/src/options.h
+++ b/src/options.h
@@ -43,6 +43,15 @@ typedef struct
std::string port;
} OptionConnectTo;
+typedef struct
+{
+ std::string net_addr;
+ u_int16_t prefix_length;
+} OptionRoute;
+
+typedef std::list<OptionRoute> RouteList;
+
+
typedef std::list<OptionConnectTo> ConnectToList;
class Options
@@ -110,6 +119,8 @@ public:
Buffer getKey();
Options& setSalt(std::string s);
Buffer getSalt();
+ RouteList getRoutes();
+
private:
Options();
@@ -159,6 +170,7 @@ private:
u_int16_t mux_;
Buffer key_;
Buffer salt_;
+ RouteList routes_;
};
extern Options& gOpt;