Added automatic unwiring when a session expires

This commit is contained in:
John Sharratt 2017-07-01 11:14:51 +02:00
parent e11d1943e9
commit 7e0948bf96
2 changed files with 29 additions and 1 deletions

View File

@ -60,7 +60,12 @@ session::~session()
logger::debug() << "session::~session() this=" << logger::format("%x", this); logger::debug() << "session::~session() this=" << logger::format("%x", this);
for (std::list<ptr<iface> >::iterator it = _ifaces.begin(); for (std::list<ptr<iface> >::iterator it = _ifaces.begin();
it != _ifaces.end(); it++) { it != _ifaces.end(); it++)
{
if (_autowire == true) {
handle_auto_unwire((*it));
}
(*it)->remove_session(_ptr); (*it)->remove_session(_ptr);
} }
} }
@ -120,6 +125,7 @@ void session::handle_auto_wire(const ptr<iface>& ifa)
std::stringstream route_cmd; std::stringstream route_cmd;
route_cmd << "ip"; route_cmd << "ip";
route_cmd << " " << "-6"; route_cmd << " " << "-6";
route_cmd << " " << "route";
route_cmd << " " << "replace"; route_cmd << " " << "replace";
route_cmd << " " << std::string(_taddr); route_cmd << " " << std::string(_taddr);
route_cmd << " " << "dev"; route_cmd << " " << "dev";
@ -131,6 +137,26 @@ void session::handle_auto_wire(const ptr<iface>& ifa)
system(route_cmd.str().c_str()); system(route_cmd.str().c_str());
} }
void session::handle_auto_unwire(const ptr<iface>& ifa)
{
logger::debug()
<< "session::handle_auto_unwire() taddr=" << _taddr << ", ifa=" << ifa->name();
std::stringstream route_cmd;
route_cmd << "ip";
route_cmd << " " << "-6";
route_cmd << " " << "route";
route_cmd << " " << "flush";
route_cmd << " " << std::string(_taddr);
route_cmd << " " << "dev";
route_cmd << " " << ifa->name();
logger::debug()
<< "session::system(" << route_cmd.str() << ")";
system(route_cmd.str().c_str());
}
void session::handle_advert(const ptr<iface>& ifa) void session::handle_advert(const ptr<iface>& ifa)
{ {
if (_autowire == true) { if (_autowire == true) {

View File

@ -81,6 +81,8 @@ public:
void handle_advert(const ptr<iface>& ifa); void handle_advert(const ptr<iface>& ifa);
void handle_auto_wire(const ptr<iface>& ifa); void handle_auto_wire(const ptr<iface>& ifa);
void handle_auto_unwire(const ptr<iface>& ifa);
void send_advert(); void send_advert();