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