OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef _VPN_MANAGER_L2TP_MANAGER_H_ |
| 6 #define _VPN_MANAGER_L2TP_MANAGER_H_ |
| 7 |
| 8 #include "base/file_util.h" |
| 9 #include "base/scoped_ptr.h" |
| 10 #include "base/time.h" |
| 11 #include "gtest/gtest_prod.h" // for FRIEND_TEST |
| 12 |
| 13 #include "vpn-manager/service_manager.h" |
| 14 |
| 15 namespace chromeos { |
| 16 class Process; |
| 17 } |
| 18 |
| 19 // Manages the L2TP daemon. This manager orchestrates configuring and |
| 20 // launching the L2TP daemon, initiating the L2TP connection, and |
| 21 // detecting when PPP has been set up. It also sends user credentials |
| 22 // to PPP through the L2TP control fifo unless the user has specified |
| 23 // a PPP plugin should be used, which it will defer to. Current |
| 24 // implementation assumes a connection that has been stopped will not |
| 25 // be started again with the same object. |
| 26 class L2tpManager : public ServiceManager { |
| 27 public: |
| 28 L2tpManager(); |
| 29 |
| 30 // Initialize the object using |remote|. Returns false if an illegal |
| 31 // set of parameters has been given. Has no side effects other than |
| 32 // setting up the object. |
| 33 bool Initialize(const std::string& remote); |
| 34 |
| 35 virtual bool Start(); |
| 36 virtual void Stop(); |
| 37 virtual int Poll(); |
| 38 virtual void ProcessOutput(); |
| 39 virtual bool IsChild(pid_t pid); |
| 40 |
| 41 // Returns the stderr output file descriptor of our child process. |
| 42 int output_fd() const { return output_fd_; } |
| 43 |
| 44 protected: |
| 45 friend class L2tpManagerTest; |
| 46 FRIEND_TEST(L2tpManagerTest, FormatL2tpdConfiguration); |
| 47 FRIEND_TEST(L2tpManagerTest, FormatPppdConfiguration); |
| 48 FRIEND_TEST(L2tpManagerTest, Initiate); |
| 49 FRIEND_TEST(L2tpManagerTest, PollInitiateConnection); |
| 50 FRIEND_TEST(L2tpManagerTest, PollNothingIfRunning); |
| 51 FRIEND_TEST(L2tpManagerTest, PollTimeoutWaitingForControl); |
| 52 FRIEND_TEST(L2tpManagerTest, PollTimeoutWaitingForUp); |
| 53 FRIEND_TEST(L2tpManagerTest, PollTransitionToUp); |
| 54 FRIEND_TEST(L2tpManagerTest, PollWaitIfNotUpYet); |
| 55 FRIEND_TEST(L2tpManagerTest, Start); |
| 56 FRIEND_TEST(L2tpManagerTest, Terminate); |
| 57 |
| 58 std::string FormatL2tpdConfiguration(const std::string& ppp_config_path); |
| 59 std::string FormatPppdConfiguration(); |
| 60 bool Initiate(); |
| 61 bool Terminate(); |
| 62 |
| 63 // Has the L2TP connection been initiated yet. |
| 64 bool was_initiated_; |
| 65 // l2tp daemon stderr pipe file descriptor. |
| 66 int output_fd_; |
| 67 // Start time of the l2tp daemon. |
| 68 base::TimeTicks start_ticks_; |
| 69 // Remote IP for L2TP connection. |
| 70 std::string remote_; |
| 71 // Last partial line read from output_fd_. |
| 72 std::string partial_output_line_; |
| 73 // Path to a file whose existence indicates the ppp device is up. |
| 74 FilePath ppp_interface_path_; |
| 75 // Path to l2tp daemon's control file. |
| 76 FilePath l2tpd_control_path_; |
| 77 // Running l2tp process. |
| 78 scoped_ptr<chromeos::Process> l2tpd_; |
| 79 }; |
| 80 |
| 81 #endif // _VPN_MANAGER_L2TP_MANAGER_H_ |
OLD | NEW |