Darin Petkov | 7476a26 | 2012-04-12 16:30:46 +0200 | [diff] [blame] | 1 | // Copyright (c) 2012 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 SHILL_L2TP_IPSEC_DRIVER_ |
| 6 | #define SHILL_L2TP_IPSEC_DRIVER_ |
| 7 | |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
| 10 | #include <base/file_path.h> |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 11 | #include <base/memory/scoped_ptr.h> |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 12 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 13 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 14 | #include "shill/glib.h" |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 15 | #include "shill/ipconfig.h" |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 16 | #include "shill/rpc_task.h" |
| 17 | #include "shill/service.h" |
Darin Petkov | 7476a26 | 2012-04-12 16:30:46 +0200 | [diff] [blame] | 18 | #include "shill/vpn_driver.h" |
| 19 | |
| 20 | namespace shill { |
| 21 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 22 | class ControlInterface; |
Darin Petkov | f8046b8 | 2012-04-24 16:29:23 +0200 | [diff] [blame] | 23 | class DeviceInfo; |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 24 | class GLib; |
Darin Petkov | f8046b8 | 2012-04-24 16:29:23 +0200 | [diff] [blame] | 25 | class Metrics; |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 26 | class NSS; |
Darin Petkov | 5a85047 | 2012-06-06 15:44:24 +0200 | [diff] [blame] | 27 | class ProcessKiller; |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 28 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 29 | class L2TPIPSecDriver : public VPNDriver, |
| 30 | public RPCTaskDelegate { |
Darin Petkov | 7476a26 | 2012-04-12 16:30:46 +0200 | [diff] [blame] | 31 | public: |
Darin Petkov | f8046b8 | 2012-04-24 16:29:23 +0200 | [diff] [blame] | 32 | L2TPIPSecDriver(ControlInterface *control, |
| 33 | EventDispatcher *dispatcher, |
| 34 | Metrics *metrics, |
| 35 | Manager *manager, |
| 36 | DeviceInfo *device_info, |
| 37 | GLib *glib); |
Darin Petkov | 7476a26 | 2012-04-12 16:30:46 +0200 | [diff] [blame] | 38 | virtual ~L2TPIPSecDriver(); |
| 39 | |
| 40 | // Inherited from VPNDriver. |
| 41 | virtual bool ClaimInterface(const std::string &link_name, |
| 42 | int interface_index); |
| 43 | virtual void Connect(const VPNServiceRefPtr &service, Error *error); |
| 44 | virtual void Disconnect(); |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 45 | virtual void OnConnectionDisconnected(); |
Darin Petkov | 7476a26 | 2012-04-12 16:30:46 +0200 | [diff] [blame] | 46 | virtual std::string GetProviderType() const; |
| 47 | |
| 48 | private: |
| 49 | friend class L2TPIPSecDriverTest; |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 50 | FRIEND_TEST(L2TPIPSecDriverTest, AppendFlag); |
| 51 | FRIEND_TEST(L2TPIPSecDriverTest, AppendValueOption); |
| 52 | FRIEND_TEST(L2TPIPSecDriverTest, Cleanup); |
Darin Petkov | 602303f | 2012-06-06 12:15:59 +0200 | [diff] [blame] | 53 | FRIEND_TEST(L2TPIPSecDriverTest, Connect); |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 54 | FRIEND_TEST(L2TPIPSecDriverTest, DeletePSKFile); |
Darin Petkov | a0e645e | 2012-04-25 11:38:59 +0200 | [diff] [blame] | 55 | FRIEND_TEST(L2TPIPSecDriverTest, Disconnect); |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 56 | FRIEND_TEST(L2TPIPSecDriverTest, GetLogin); |
| 57 | FRIEND_TEST(L2TPIPSecDriverTest, InitEnvironment); |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 58 | FRIEND_TEST(L2TPIPSecDriverTest, InitNSSOptions); |
| 59 | FRIEND_TEST(L2TPIPSecDriverTest, InitOptions); |
| 60 | FRIEND_TEST(L2TPIPSecDriverTest, InitOptionsNoHost); |
| 61 | FRIEND_TEST(L2TPIPSecDriverTest, InitPSKOptions); |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 62 | FRIEND_TEST(L2TPIPSecDriverTest, Notify); |
Darin Petkov | a0e645e | 2012-04-25 11:38:59 +0200 | [diff] [blame] | 63 | FRIEND_TEST(L2TPIPSecDriverTest, NotifyFail); |
Darin Petkov | 5eb0542 | 2012-05-11 15:45:25 +0200 | [diff] [blame] | 64 | FRIEND_TEST(L2TPIPSecDriverTest, OnConnectionDisconnected); |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 65 | FRIEND_TEST(L2TPIPSecDriverTest, OnL2TPIPSecVPNDied); |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 66 | FRIEND_TEST(L2TPIPSecDriverTest, ParseIPConfiguration); |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 67 | FRIEND_TEST(L2TPIPSecDriverTest, SpawnL2TPIPSecVPN); |
Darin Petkov | a0e645e | 2012-04-25 11:38:59 +0200 | [diff] [blame] | 68 | FRIEND_TEST(L2TPIPSecDriverTest, VerifyPaths); |
Darin Petkov | d432539 | 2012-04-23 15:48:22 +0200 | [diff] [blame] | 69 | |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 70 | static const char kPPPDPlugin[]; |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 71 | static const char kL2TPIPSecVPNPath[]; |
Darin Petkov | d432539 | 2012-04-23 15:48:22 +0200 | [diff] [blame] | 72 | static const Property kProperties[]; |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 73 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 74 | bool SpawnL2TPIPSecVPN(Error *error); |
| 75 | |
| 76 | void InitEnvironment(std::vector<std::string> *environment); |
| 77 | |
| 78 | bool InitOptions(std::vector<std::string> *options, Error *error); |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 79 | bool InitPSKOptions(std::vector<std::string> *options, Error *error); |
| 80 | void InitNSSOptions(std::vector<std::string> *options); |
| 81 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 82 | void Cleanup(Service::ConnectState state); |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 83 | |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 84 | void DeletePSKFile(); |
| 85 | |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 86 | // Returns true if an opton was appended. |
| 87 | bool AppendValueOption(const std::string &property, |
| 88 | const std::string &option, |
| 89 | std::vector<std::string> *options); |
| 90 | |
| 91 | // Returns true if a flag was appended. |
| 92 | bool AppendFlag(const std::string &property, |
| 93 | const std::string &true_option, |
| 94 | const std::string &false_option, |
| 95 | std::vector<std::string> *options); |
| 96 | |
Darin Petkov | 0e9735d | 2012-04-24 12:33:45 +0200 | [diff] [blame] | 97 | static void ParseIPConfiguration( |
| 98 | const std::map<std::string, std::string> &configuration, |
| 99 | IPConfig::Properties *properties, |
| 100 | std::string *interface_name); |
| 101 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 102 | // Called when the l2tpipsec_vpn process exits. |
| 103 | static void OnL2TPIPSecVPNDied(GPid pid, gint status, gpointer data); |
| 104 | |
Darin Petkov | b536a74 | 2012-04-26 11:31:28 +0200 | [diff] [blame] | 105 | // Inherit from VPNDriver to add custom properties. |
| 106 | virtual KeyValueStore GetProvider(Error *error); |
| 107 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 108 | // Implements RPCTaskDelegate. |
| 109 | virtual void GetLogin(std::string *user, std::string *password); |
| 110 | virtual void Notify(const std::string &reason, |
| 111 | const std::map<std::string, std::string> &dict); |
| 112 | |
| 113 | ControlInterface *control_; |
Darin Petkov | f8046b8 | 2012-04-24 16:29:23 +0200 | [diff] [blame] | 114 | Metrics *metrics_; |
| 115 | DeviceInfo *device_info_; |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 116 | GLib *glib_; |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 117 | NSS *nss_; |
Darin Petkov | 5a85047 | 2012-06-06 15:44:24 +0200 | [diff] [blame] | 118 | ProcessKiller *process_killer_; |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 119 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 120 | VPNServiceRefPtr service_; |
| 121 | scoped_ptr<RPCTask> rpc_task_; |
Darin Petkov | f7ef50a | 2012-04-16 20:54:31 +0200 | [diff] [blame] | 122 | FilePath psk_file_; |
Darin Petkov | f8046b8 | 2012-04-24 16:29:23 +0200 | [diff] [blame] | 123 | VPNRefPtr device_; |
Darin Petkov | 7476a26 | 2012-04-12 16:30:46 +0200 | [diff] [blame] | 124 | |
Darin Petkov | 209e629 | 2012-04-20 11:33:32 +0200 | [diff] [blame] | 125 | // The PID of the spawned l2tpipsec_vpn process. May be 0 if no process has |
| 126 | // been spawned yet or the process has died. |
| 127 | int pid_; |
| 128 | |
| 129 | // Child exit watch callback source tag. |
| 130 | unsigned int child_watch_tag_; |
| 131 | |
Darin Petkov | 7476a26 | 2012-04-12 16:30:46 +0200 | [diff] [blame] | 132 | DISALLOW_COPY_AND_ASSIGN(L2TPIPSecDriver); |
| 133 | }; |
| 134 | |
| 135 | } // namespace shill |
| 136 | |
| 137 | #endif // SHILL_L2TP_IPSEC_DRIVER_ |