LCOV - code coverage report
Current view: top level - vnsw/agent/oper - crypt_tunnel.cc (source / functions) Hit Total Coverage
Test: OpenSDN C/C++ coverage (all TARGET_SET jobs) Lines: 32 365 8.8 %
Date: 2026-06-08 02:02:55 Functions: 7 54 13.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2018 Juniper Networks, Inc. All rights reserved.
       3             :  */
       4             : 
       5             : #include <algorithm>
       6             : #include <boost/uuid/uuid_io.hpp>
       7             : #include <base/parse_object.h>
       8             : #include <ifmap/ifmap_link.h>
       9             : #include <ifmap/ifmap_table.h>
      10             : #include <vnc_cfg_types.h>
      11             : #include <agent_types.h>
      12             : 
      13             : #include <cmn/agent_cmn.h>
      14             : #include <cfg/cfg_init.h>
      15             : #include <oper/instance_task.h>
      16             : #include <oper/crypt_tunnel.h>
      17             : #include <oper/agent_sandesh.h>
      18             : #include <oper/config_manager.h>
      19             : #include <oper/nexthop.h>
      20             : 
      21             : using namespace autogen;
      22             : using namespace std;
      23             : 
      24             : SandeshTraceBufferPtr
      25             :     CryptTunnelTraceBuf(SandeshTraceBufferCreate("CryptTunnel", 5000));
      26             : 
      27             : const std::string CryptTunnelTask::kCryptTunnelCmd
      28             : ("/usr/bin/contrail_crypt_tunnel_client.py");
      29             : 
      30             : 
      31             : CryptTunnelTable *CryptTunnelTable::crypt_tunnel_table_;
      32             : 
      33           0 : bool CryptTunnelEntry::IsLess(const DBEntry &rhs) const {
      34           0 :     const CryptTunnelEntry &a = static_cast<const CryptTunnelEntry &>(rhs);
      35           0 :     return (remote_ip_ < a.remote_ip_);
      36             : }
      37             : 
      38           0 : string CryptTunnelEntry::ToString() const {
      39           0 :     return remote_ip_.to_string();
      40             : }
      41             : 
      42           0 : DBEntryBase::KeyPtr CryptTunnelEntry::GetDBRequestKey() const {
      43           0 :     CryptTunnelKey *key = new CryptTunnelKey(remote_ip_);
      44           0 :     return DBEntryBase::KeyPtr(key);
      45             : }
      46             : 
      47           0 : void CryptTunnelEntry::SetKey(const DBRequestKey *key) {
      48           0 :     const CryptTunnelKey *k = static_cast<const CryptTunnelKey *>(key);
      49           0 :     remote_ip_ = k->remote_ip_;
      50           0 : }
      51             : 
      52           0 : void CryptTunnelEntry::PostAdd() {
      53           0 :     UpdateTunnelReference();
      54           0 :     ResyncNH();
      55           0 : }
      56           0 : void CryptTunnelEntry::ResyncNH() {
      57           0 :     Agent *agent = static_cast<CryptTunnelTable *>(get_table())->agent();
      58             :     typedef std::list<TunnelType::Type> TunnelTypeList;
      59           0 :     TunnelTypeList type_list;
      60           0 :     type_list.push_back(TunnelType::MPLS_GRE);
      61           0 :     type_list.push_back(TunnelType::MPLS_UDP);
      62           0 :     type_list.push_back(TunnelType::VXLAN);
      63           0 :     for (TunnelTypeList::const_iterator it = type_list.begin();
      64           0 :          it != type_list.end(); it++) {
      65           0 :         DBRequest nh_req(DBRequest::DB_ENTRY_ADD_CHANGE);
      66             :         TunnelNHKey *tnh_key =
      67           0 :                 new TunnelNHKey(agent->fabric_vrf_name(), agent->router_id(),
      68           0 :                                 remote_ip_.to_v4(), false, *it);
      69           0 :         tnh_key->sub_op_ = AgentKey::RESYNC;
      70           0 :         nh_req.key.reset(tnh_key);
      71           0 :         agent->nexthop_table()->Process(nh_req);
      72           0 :     }
      73           0 : }
      74             : 
      75           0 : void CryptTunnelTable::Process(DBRequest &req) {
      76           0 :     agent()->ConcurrencyCheck();
      77             :     DBTablePartition *tpart =
      78           0 :         static_cast<DBTablePartition *>(GetTablePartition(req.key.get()));
      79           0 :     Input(tpart, NULL, &req);
      80           0 : }
      81             : 
      82          11 : void CryptTunnelTable::CryptAvailability(const std::string &remote_ip,
      83             :                                          bool &crypt_traffic,
      84             :                                          bool &crypt_path_available) {
      85          11 :     crypt_traffic = false;
      86          11 :     crypt_path_available = false;
      87          11 :     CryptTunnelEntry *entry = Find(remote_ip);
      88          11 :     if (entry) {
      89           0 :         crypt_traffic = entry->GetVRToVRCrypt();
      90           0 :         crypt_path_available = entry->GetTunnelAvailable();
      91             :     }
      92          11 : }
      93             : 
      94           0 : bool CryptTunnelTable::IsCryptPathAvailable(const std::string &remote_ip) {
      95           0 :     bool ret = false;
      96           0 :     CryptTunnelEntry *entry = Find(remote_ip);
      97           0 :     if (entry && entry->GetTunnelAvailable())
      98           0 :         ret = true;
      99           0 :     return ret;
     100             : }
     101             : 
     102           0 : bool CryptTunnelTable::IsCryptTraffic(const std::string &remote_ip) {
     103           0 :     bool ret = false;
     104           0 :     CryptTunnelEntry *entry = Find(remote_ip);
     105           0 :     if (entry && entry->GetVRToVRCrypt())
     106           0 :         ret = true;
     107           0 :     return ret;
     108             : }
     109             : 
     110          11 : CryptTunnelEntry *CryptTunnelTable::Find(const std::string &remote_ip) {
     111          11 :     boost::system::error_code ec;
     112          11 :     IpAddress ip = IpAddress::from_string(remote_ip, ec);
     113          11 :     if (ec) {
     114           0 :         return NULL;
     115             :     }
     116          11 :     CryptTunnelKey key(ip);
     117          11 :     return static_cast<CryptTunnelEntry *>(FindActiveEntry(&key));
     118          11 : }
     119             : 
     120           0 : void CryptTunnelTable::Delete(const std::string &remote_ip) {
     121           0 :     DBRequest req(DBRequest::DB_ENTRY_DELETE);
     122           0 :     boost::system::error_code ec;
     123           0 :     IpAddress ip = IpAddress::from_string(remote_ip, ec);
     124           0 :     if (ec) {
     125           0 :         return;
     126             :     }
     127           0 :     req.key.reset(new CryptTunnelKey(ip));
     128           0 :     req.data.reset(NULL);
     129           0 :     Process(req);
     130           0 :     return;
     131           0 : }
     132             : 
     133           0 : void CryptTunnelTable::Create(const std::string &remote_ip, bool vr_to_vr_crypt) {
     134           0 :     DBRequest req(DBRequest::DB_ENTRY_ADD_CHANGE);
     135           0 :     boost::system::error_code ec;
     136           0 :     IpAddress ip = IpAddress::from_string(remote_ip, ec);
     137           0 :     if (ec) {
     138           0 :         return;
     139             :     }
     140           0 :     req.key.reset(new CryptTunnelKey(ip));
     141           0 :     req.data.reset(new CryptTunnelConfigData(vr_to_vr_crypt));
     142           0 :     Process(req);
     143           0 : }
     144             : 
     145           1 : DBTableBase *CryptTunnelTable::CreateTable(Agent *agent, DB *db, const std::string &name) {
     146           1 :     CryptTunnelTable *crypt_tunnel_table = new CryptTunnelTable(agent, db, name);
     147           1 :     (static_cast<DBTable *>(crypt_tunnel_table))->Init();
     148           1 :     crypt_tunnel_table_ = crypt_tunnel_table;
     149           1 :     return crypt_tunnel_table;
     150             : };
     151             : 
     152          11 : std::unique_ptr<DBEntry> CryptTunnelTable::AllocEntry(const DBRequestKey *k) const {
     153          11 :     const CryptTunnelKey *key = static_cast<const CryptTunnelKey *>(k);
     154          11 :     CryptTunnelEntry *e = new CryptTunnelEntry(key->remote_ip_);
     155          11 :     return std::unique_ptr<DBEntry>(static_cast<DBEntry *>(e));
     156             : }
     157             : 
     158           0 : DBEntry *CryptTunnelTable::Add(const DBRequest *req) {
     159           0 :     const CryptTunnelKey *key = static_cast<const CryptTunnelKey *>(req->key.get());
     160           0 :     CryptTunnelEntry *crypt_tunnel_entry = new CryptTunnelEntry(key->remote_ip_);
     161           0 :     ChangeHandler(crypt_tunnel_entry, req);
     162           0 :     crypt_tunnel_entry->SendObjectLog(GetOperDBTraceBuf(), AgentLogEvent::ADD);
     163           0 :     return crypt_tunnel_entry;
     164             : }
     165             : 
     166           0 : bool CryptTunnelTable::ChangeHandler(CryptTunnelEntry *entry, const DBRequest *req) {
     167           0 :     bool ret = false;
     168           0 :     CryptTunnelConfigData *cdata = dynamic_cast<CryptTunnelConfigData *>(req->data.get());
     169           0 :     if (cdata && cdata->vr_to_vr_crypt_ != entry->vr_to_vr_crypt_) {
     170           0 :         entry->vr_to_vr_crypt_ = cdata->vr_to_vr_crypt_;
     171           0 :         ret = true;
     172             :     }
     173           0 :     CryptTunnelAvailableData *tdata = dynamic_cast<CryptTunnelAvailableData *>(req->data.get());
     174           0 :     if (tdata && tdata->tunnel_available_ != entry->tunnel_available_) {
     175           0 :         entry->tunnel_available_ = tdata->tunnel_available_;
     176           0 :         ret = true;
     177             :     }
     178           0 :     if (!entry->tunnel_task_) {
     179           0 :         entry->StartCryptTunnel();
     180           0 :         ret = true;
     181             :     }
     182           0 :     boost::system::error_code ec;
     183           0 :     IpAddress source_ip = IpAddress::from_string(agent()->router_id().to_string(), ec);
     184           0 :     entry->source_ip_ = source_ip;
     185           0 :     return ret;
     186             : }
     187             : 
     188           0 : bool CryptTunnelTable::OnChange(DBEntry *entry, const DBRequest *req) {
     189             :     bool ret;
     190           0 :     CryptTunnelEntry *crypt_tunnel_entry = static_cast<CryptTunnelEntry *>(entry);
     191           0 :     ret = ChangeHandler(crypt_tunnel_entry, req);
     192           0 :     if (ret)
     193           0 :         crypt_tunnel_entry->ResyncNH();
     194           0 :     crypt_tunnel_entry->UpdateTunnelReference();
     195           0 :     crypt_tunnel_entry->SendObjectLog(GetOperDBTraceBuf(), AgentLogEvent::CHANGE);
     196           0 :     return ret;
     197             : }
     198             : 
     199           0 : bool CryptTunnelTable::Resync(DBEntry *entry, const DBRequest *req) {
     200             :     bool ret;
     201           0 :     CryptTunnelEntry *crypt_tunnel_entry = static_cast<CryptTunnelEntry *>(entry);
     202           0 :     ret = ChangeHandler(crypt_tunnel_entry, req);
     203           0 :     if (ret)
     204           0 :         crypt_tunnel_entry->ResyncNH();
     205           0 :     crypt_tunnel_entry->SendObjectLog(GetOperDBTraceBuf(), AgentLogEvent::RESYNC);
     206           0 :     return ret;
     207             : }
     208             : 
     209           0 : bool CryptTunnelTable::Delete(DBEntry *entry, const DBRequest *req) {
     210           0 :     CryptTunnelEntry *crypt_tunnel_entry = static_cast<CryptTunnelEntry *>(entry);
     211           0 :     crypt_tunnel_entry->StopCryptTunnel();
     212           0 :     crypt_tunnel_entry->SendObjectLog(GetOperDBTraceBuf(), AgentLogEvent::DEL);
     213           0 :     return true;
     214             : }
     215             : 
     216           1 : CryptTunnelTable::CryptTunnelTable(Agent *agent, DB *db, const std::string &name) :
     217           1 :         AgentDBTable(db, name), vr_to_vr_crypt_(false), crypt_interface_(NULL),
     218           1 :     tunnel_event_queue_(agent->task_scheduler()->GetTaskId(kTaskCryptTunnel), 0,
     219           1 :             boost::bind(&CryptTunnelTable::TunnelEventProcess, this, _1)) {
     220           1 :     tunnel_event_queue_.set_name("CryptTunnel event queue");
     221           1 :     set_agent(agent);
     222           1 : }
     223             : 
     224           2 : CryptTunnelTable::~CryptTunnelTable() {
     225           1 :     tunnel_event_queue_.Shutdown();
     226           2 : }
     227             : 
     228             : /////////////////////////////////////////////////////////////////////////////
     229             : // Introspect routines
     230             : /////////////////////////////////////////////////////////////////////////////
     231           0 : bool CryptTunnelEntry::DBEntrySandesh(Sandesh *sresp, std::string &name)  const {
     232           0 :     CryptTunnelResp *resp = static_cast<CryptTunnelResp *>(sresp);
     233           0 :     if (name.empty() ||
     234           0 :         name == remote_ip_.to_string()) {
     235           0 :         CryptTunnelSandeshData data;
     236           0 :         data.set_source(std::string());
     237           0 :         data.set_remote(remote_ip_.to_string());
     238           0 :         data.set_available(tunnel_available_);
     239           0 :         data.set_crypt(vr_to_vr_crypt_);
     240             :         std::vector<CryptTunnelSandeshData> &list =
     241           0 :            const_cast<std::vector<CryptTunnelSandeshData>&>(resp->get_crypt_tunnel_list());
     242           0 :         list.push_back(data);
     243           0 :         return true;
     244           0 :     }
     245           0 :     return false;
     246             : }
     247             : 
     248           0 : void CryptTunnelEntry::SendObjectLog(SandeshTraceBufferPtr buf,
     249             :                                      AgentLogEvent::type event) const {
     250           0 :     CryptTunnelObjectLogInfo info;
     251           0 :     string str;
     252           0 :     switch(event) {
     253           0 :         case AgentLogEvent::ADD:
     254           0 :             str.assign("Addition");
     255           0 :             break;
     256           0 :         case AgentLogEvent::DEL:
     257           0 :             str.assign("Deletion");
     258           0 :             break;
     259           0 :         case AgentLogEvent::CHANGE:
     260           0 :             str.assign("Modification");
     261           0 :             break;
     262           0 :         case AgentLogEvent::RESYNC:
     263           0 :             str.assign("Resync");
     264           0 :             break;
     265           0 :         default:
     266           0 :             str.assign("");
     267           0 :             break;
     268             :     }
     269           0 :     info.set_event(str);
     270           0 :     info.set_remote(remote_ip_.to_string());
     271           0 :     info.set_source(std::string());
     272           0 :     info.set_available(tunnel_available_);
     273           0 :     info.set_crypt(vr_to_vr_crypt_);
     274           0 :     CRYPT_TUNNEL_OBJECT_LOG_LOG("CryptTunnel", SandeshLevel::SYS_INFO, info);
     275           0 :     CRYPT_TUNNEL_TRACE_TRACE(buf, info);
     276           0 : }
     277             : 
     278           0 : void CryptTunnelReq::HandleRequest() const {
     279           0 :     AgentSandeshPtr sand(new AgentCryptTunnelSandesh(context(), get_remote()));
     280           0 :     sand->DoSandesh(sand);
     281           0 : }
     282             : 
     283           0 : AgentSandeshPtr CryptTunnelTable::GetAgentSandesh(const AgentSandeshArguments *args,
     284             :                                                   const std::string &context) {
     285             :     return AgentSandeshPtr(new AgentCryptTunnelSandesh(context,
     286           0 :                                               args->GetString("remote")));
     287             : }
     288             : 
     289             : 
     290             : 
     291           0 : CryptTunnelEvent::CryptTunnelEvent(CryptTunnelTaskBase *task,
     292             :                                    CryptTunnelEntry *entry, EventType type,
     293           0 :                                    const std::string &message) :
     294           0 :         tunnel_task_(task), entry_(entry), type_(type), message_(message) {
     295           0 : }
     296             : 
     297           0 : CryptTunnelEvent::~CryptTunnelEvent() {
     298           0 : }
     299             : 
     300             : 
     301             : /////////////////////////////////////////////////////////////////////////////
     302             : // Instance base class methods
     303             : /////////////////////////////////////////////////////////////////////////////
     304           0 : CryptTunnelTaskBase::CryptTunnelTaskBase(CryptTunnelEntry *entry) :
     305           0 :     entry_(NULL), active_(false), last_update_time_("-"), deleted_(false) {
     306           0 : }
     307             : 
     308           0 : CryptTunnelTaskBase::~CryptTunnelTaskBase() {
     309           0 :     entry_ = NULL;
     310           0 : }
     311             : 
     312           0 : void CryptTunnelTaskBase::UpdateTunnel(const CryptTunnelEntry *entry, bool available) const {
     313           0 :     DBRequest req;
     314           0 :     req.oper = DBRequest::DB_ENTRY_ADD_CHANGE;
     315           0 :     CryptTunnelKey *key = new CryptTunnelKey(*entry->GetRemoteIp());
     316           0 :     key->sub_op_ = AgentKey::RESYNC;
     317           0 :     req.key.reset(key);
     318           0 :     CryptTunnelTable *ctable = static_cast<CryptTunnelTable *>(entry->get_table());
     319           0 :     req.data.reset(new CryptTunnelAvailableData(available));
     320           0 :     ctable->Process(req);
     321           0 : }
     322             : 
     323           0 : void CryptTunnelTaskBase::set_tunnel_entry(CryptTunnelEntry *entry) {
     324           0 :     if (entry_ == entry) {
     325           0 :         UpdateTunnelTask();
     326           0 :         return;
     327             :     }
     328           0 :     entry_ = entry;
     329           0 :     CreateTunnelTask();
     330             : }
     331             : 
     332           0 : std::string CryptTunnelTaskBase::to_string() {
     333           0 :     std::string str("Instance for crypt tunnel ");
     334           0 :     str += entry_->ToString();
     335           0 :     return str;
     336           0 : }
     337             : 
     338           0 : void CryptTunnelTaskBase::OnRead(const std::string &data) {
     339             :     CryptTunnelEvent *event =
     340           0 :             new CryptTunnelEvent(this, entry_.get(),
     341             :                              CryptTunnelEvent::MESSAGE_READ,
     342           0 :                              data);
     343           0 :     static_cast<CryptTunnelTable *>(entry_->get_table())->TunnelEventEnqueue(event);
     344           0 : }
     345             : 
     346           0 : void CryptTunnelTaskBase::OnExit(const boost::system::error_code &ec) {
     347             :     CryptTunnelEvent *event =
     348           0 :             new CryptTunnelEvent(this, entry_.get(),
     349           0 :                                  CryptTunnelEvent::TASK_EXIT, "");
     350           0 :     static_cast<CryptTunnelTable *>(entry_->get_table())->TunnelEventEnqueue(event);
     351           0 : }
     352             : 
     353           0 : void CryptTunnelTaskBase::SetTunnelEntry(CryptTunnelEntry *entry) {
     354             :     CryptTunnelEvent *event =
     355             :             new CryptTunnelEvent(this, entry,
     356           0 :                                  CryptTunnelEvent::SET_TUNNEL_ENTRY, "");
     357           0 :     static_cast<CryptTunnelTable *>(entry_->get_table())->TunnelEventEnqueue(event);
     358           0 : }
     359             : 
     360           0 : void CryptTunnelTaskBase::StopTask(CryptTunnelEntry *entry) {
     361             :     CryptTunnelEvent *event =
     362             :             new CryptTunnelEvent(this, entry,
     363           0 :                                  CryptTunnelEvent::STOP_TASK, "");
     364           0 :     static_cast<CryptTunnelTable *>(entry_->get_table())->TunnelEventEnqueue(event);
     365           0 : }
     366             : 
     367             : 
     368             : ////////////////////////////////////////////////////////////////////////////////
     369             : 
     370           0 : CryptTunnelTask::CryptTunnelTask(CryptTunnelEntry *entry) :
     371             :     CryptTunnelTaskBase(entry),
     372           0 :     task_(NULL) {
     373           0 : }
     374             : 
     375           0 : CryptTunnelTask::~CryptTunnelTask() {
     376           0 : }
     377             : 
     378           0 : bool CryptTunnelTask::CreateTunnelTask() {
     379           0 :     if (!deleted_ && task_.get() != NULL) {
     380           0 :         return false;
     381             :     }
     382             : 
     383           0 :     deleted_ = false;
     384             : 
     385           0 :     CRYPT_TUNNEL_TASK_TRACE(Trace, "Starting " + this->to_string());
     386             : 
     387           0 :     Agent *agent = static_cast<CryptTunnelTable *>(entry_->get_table())->agent();
     388           0 :     task_.reset(new CryptTunnelProcessTunnel("CryptTunnel", "", 0,
     389           0 :                                              agent->event_manager()));
     390           0 :     if (task_.get() != NULL) {
     391           0 :         task_->set_pipe_stdout(true);
     392           0 :         task_->set_on_data_cb(
     393             :                 boost::bind(&CryptTunnelTaskBase::OnRead, this, _2));
     394           0 :         task_->set_on_exit_cb(
     395             :                 boost::bind(&CryptTunnelTaskBase::OnExit, this, _2));
     396           0 :         return RunTunnelTask(CryptTunnelTaskBase::CREATE_TUNNEL);
     397             :     }
     398             : 
     399           0 :     return false;
     400             : }
     401             : 
     402           0 : bool CryptTunnelTask::DestroyTunnelTask() {
     403           0 :     if (deleted_) {
     404           0 :         return true;
     405             :     }
     406           0 :     if (task_.get() == NULL) {
     407           0 :         return false;
     408             :     }
     409             : 
     410           0 :     CRYPT_TUNNEL_TASK_TRACE(Trace, "Deleting " + this->to_string());
     411           0 :     deleted_ = true;
     412           0 :     active_ = false;
     413             :     //StopTunnelTask();
     414           0 :     RunTunnelTask(CryptTunnelTaskBase::DELETE_TUNNEL);
     415           0 :     return true;
     416             : }
     417             : 
     418           0 : bool CryptTunnelTask::RunTunnelTask(CommandType cmd_type) {
     419           0 :     UpdateTunnelTaskCommand(cmd_type);
     420           0 :     return task_->Run();
     421             : }
     422             : 
     423           0 : bool CryptTunnelTask::StopTunnelTask() {
     424           0 :     task_->Stop();
     425           0 :     return true;
     426             : }
     427             : 
     428           0 : void CryptTunnelTask::UpdateTunnelTaskCommand(CommandType cmd_type) {
     429           0 :     Agent *agent = static_cast<CryptTunnelTable *>(entry_->get_table())->agent();
     430           0 :     if (agent->test_mode()) {
     431             :         // in test mode, set task instance to run no-op shell
     432           0 :         task_->set_cmd("echo success");
     433           0 :         return;
     434             :     }
     435           0 :     std::stringstream cmd_str;
     436           0 :     cmd_str << kCryptTunnelCmd;
     437           0 :     switch (cmd_type) {
     438           0 :     case CryptTunnelTaskBase::CREATE_TUNNEL:
     439             :         {
     440           0 :             cmd_str << " --oper create ";
     441             :         }
     442           0 :         break;
     443           0 :     case CryptTunnelTaskBase::UPDATE_TUNNEL:
     444             :         {
     445           0 :             cmd_str << " --oper update ";
     446             :         }
     447           0 :         break;
     448           0 :     case CryptTunnelTaskBase::MONITOR_TUNNEL:
     449             :         {
     450           0 :             cmd_str << " --oper status ";
     451             :         }
     452           0 :         break;
     453           0 :     case CryptTunnelTaskBase::DELETE_TUNNEL:
     454             :         {
     455           0 :             cmd_str << " --oper delete ";
     456             :         }
     457           0 :         break;
     458           0 :     default:
     459             :         // not supported
     460           0 :         assert(0);
     461             :     }
     462           0 :     cmd_str << " --source_ip " << entry_->GetSourceIp()->to_string();
     463           0 :     cmd_str << " --remote_ip " << entry_->GetRemoteIp()->to_string();
     464           0 :     task_->set_cmd(cmd_str.str());
     465           0 : }
     466             : 
     467           0 : bool CryptTunnelTask::IsRunning() const {
     468           0 :     return (task_.get() != NULL ? task_->is_running(): false);
     469             : }
     470             : 
     471             : ////////////////////////////////////////////////////////////////////////////////
     472             : 
     473           0 : void CryptTunnelEntry::UpdateTunnelReference() {
     474           0 :     if (tunnel_task_)
     475           0 :         tunnel_task_->set_tunnel_entry(this);
     476           0 : }
     477             : 
     478           0 : CryptTunnelTaskBase *CryptTunnelEntry::StartCryptTunnel() {
     479           0 :     if (!tunnel_task_) {
     480           0 :         tunnel_task_ = new CryptTunnelTask(this);
     481             :     }
     482           0 :     return tunnel_task_;
     483             : }
     484             : 
     485           0 : void CryptTunnelEntry::StopCryptTunnel() {
     486           0 :     if (!tunnel_task_->DestroyTunnelTask()) {
     487           0 :         delete tunnel_task_;
     488           0 :         tunnel_task_ = NULL;
     489             :     }
     490           0 :     tunnel_available_ = false;
     491           0 :     vr_to_vr_crypt_ = false;
     492           0 :     ResyncNH();
     493           0 : }
     494             : 
     495             : void
     496           0 : CryptTunnelTable::TunnelEventEnqueue(CryptTunnelEvent *event) {
     497           0 :     tunnel_event_queue_.Enqueue(event);
     498           0 : }
     499             : 
     500           0 : bool CryptTunnelTable::TunnelEventProcess(CryptTunnelEvent *event) {
     501           0 :     CryptTunnelTaskBase *tunnel_task = event->tunnel_task_;
     502           0 :     switch (event->type_) {
     503           0 :     case CryptTunnelEvent::MESSAGE_READ:
     504             :         {
     505           0 :             if (tunnel_task->deleted_)
     506           0 :                 break;
     507           0 :             tunnel_task->last_update_time_ = UTCUsecToString(UTCTimestampUsec());
     508           0 :             std::string msg = event->message_;
     509           0 :             boost::algorithm::to_lower(msg);
     510           0 :             if (msg.find("success") != std::string::npos) {
     511           0 :                 if (!tunnel_task->active_) {
     512           0 :                     tunnel_task->active_ = true;
     513           0 :                     tunnel_task->UpdateTunnel(tunnel_task->entry_.get(), true);
     514             :                 }
     515             :             }
     516           0 :             if (msg.find("failure") != std::string::npos) {
     517           0 :                 if (tunnel_task->active_) {
     518           0 :                     tunnel_task->active_ = false;
     519           0 :                     tunnel_task->UpdateTunnel(tunnel_task->entry_.get(), false);
     520             :                 }
     521             :             }
     522             :             //CRYPT_TUNNEL_TASK_TRACE(Trace, tunnel_task->to_string() +
     523             :             //                   " Received msg = " + event->message_);
     524           0 :         }
     525           0 :         break;
     526             : 
     527           0 :     case CryptTunnelEvent::TASK_EXIT:
     528           0 :         if (tunnel_task->deleted_) {
     529           0 :             CRYPT_TUNNEL_TASK_TRACE(Trace, "Exit Deleted " + tunnel_task->to_string());
     530           0 :             delete tunnel_task;
     531             :         } else {
     532           0 :             tunnel_task->RunTunnelTask(CryptTunnelTaskBase::MONITOR_TUNNEL);
     533             :         }
     534           0 :         break;
     535             : 
     536           0 :     case CryptTunnelEvent::SET_TUNNEL_ENTRY:
     537           0 :         tunnel_task->set_tunnel_entry(event->entry_);
     538           0 :         break;
     539             : 
     540           0 :     case CryptTunnelEvent::STOP_TASK:
     541           0 :         if (!tunnel_task->DestroyTunnelTask()) {
     542           0 :             CRYPT_TUNNEL_TASK_TRACE(Trace, "Stopped " + tunnel_task->to_string());
     543           0 :             delete tunnel_task;
     544             :         }
     545           0 :         break;
     546             : 
     547           0 :     default:
     548             :         // unhandled event
     549           0 :         assert(0);
     550             :     }
     551             : 
     552           0 :     delete event;
     553           0 :     return true;
     554             : }

Generated by: LCOV version 1.14