Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [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_OPENVPN_DRIVER_ |
| 6 | #define SHILL_OPENVPN_DRIVER_ |
| 7 | |
Darin Petkov | 14c29ec | 2012-03-02 11:34:19 +0100 | [diff] [blame] | 8 | #include <map> |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 12 | #include <base/memory/scoped_ptr.h> |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 13 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
| 14 | |
Darin Petkov | 14c29ec | 2012-03-02 11:34:19 +0100 | [diff] [blame] | 15 | #include "shill/ipconfig.h" |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 16 | #include "shill/key_value_store.h" |
Darin Petkov | f20994f | 2012-03-05 16:12:19 +0100 | [diff] [blame^] | 17 | #include "shill/refptr_types.h" |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 18 | #include "shill/vpn_driver.h" |
| 19 | |
| 20 | namespace shill { |
| 21 | |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 22 | class ControlInterface; |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 23 | class DeviceInfo; |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 24 | class Error; |
Darin Petkov | f20994f | 2012-03-05 16:12:19 +0100 | [diff] [blame^] | 25 | class EventDispatcher; |
| 26 | class Manager; |
| 27 | class Metrics; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 28 | class RPCTask; |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 29 | class DeviceStub; |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 30 | |
| 31 | class OpenVPNDriver : public VPNDriver { |
| 32 | public: |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 33 | OpenVPNDriver(ControlInterface *control, |
Darin Petkov | f20994f | 2012-03-05 16:12:19 +0100 | [diff] [blame^] | 34 | EventDispatcher *dispatcher, |
| 35 | Metrics *metrics, |
| 36 | Manager *manager, |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 37 | DeviceInfo *device_info, |
| 38 | const KeyValueStore &args); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 39 | virtual ~OpenVPNDriver(); |
| 40 | |
Darin Petkov | 14c29ec | 2012-03-02 11:34:19 +0100 | [diff] [blame] | 41 | bool Notify(const std::string &reason, |
| 42 | const std::map<std::string, std::string> &dict); |
| 43 | |
Darin Petkov | f20994f | 2012-03-05 16:12:19 +0100 | [diff] [blame^] | 44 | // Inherited from VPNDriver. |Connect| initiates the VPN connection by |
| 45 | // creating a tunnel device. When the device index becomes available, this |
| 46 | // instance is notified through |ClaimInterface| and resumes the connection |
| 47 | // process by setting up and spawning an external 'openvpn' process. IP |
| 48 | // configuration settings are passed back from the external process through |
| 49 | // the |Notify| RPC service method. |
| 50 | virtual void Connect(Error *error); |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 51 | virtual bool ClaimInterface(const std::string &link_name, |
| 52 | int interface_index); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 53 | |
| 54 | private: |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 55 | friend class OpenVPNDriverTest; |
| 56 | FRIEND_TEST(OpenVPNDriverTest, AppendFlag); |
| 57 | FRIEND_TEST(OpenVPNDriverTest, AppendValueOption); |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 58 | FRIEND_TEST(OpenVPNDriverTest, ClaimInterface); |
Darin Petkov | f20994f | 2012-03-05 16:12:19 +0100 | [diff] [blame^] | 59 | FRIEND_TEST(OpenVPNDriverTest, Connect); |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 60 | FRIEND_TEST(OpenVPNDriverTest, InitOptions); |
| 61 | FRIEND_TEST(OpenVPNDriverTest, InitOptionsNoHost); |
Darin Petkov | 14c29ec | 2012-03-02 11:34:19 +0100 | [diff] [blame] | 62 | FRIEND_TEST(OpenVPNDriverTest, ParseForeignOption); |
| 63 | FRIEND_TEST(OpenVPNDriverTest, ParseForeignOptions); |
| 64 | FRIEND_TEST(OpenVPNDriverTest, ParseIPConfiguration); |
| 65 | |
| 66 | // The map is a sorted container that allows us to iterate through the options |
| 67 | // in order. |
| 68 | typedef std::map<int, std::string> ForeignOptions; |
| 69 | |
| 70 | static void ParseIPConfiguration( |
| 71 | const std::map<std::string, std::string> &configuration, |
| 72 | IPConfig::Properties *properties); |
| 73 | static void ParseForeignOptions(const ForeignOptions &options, |
| 74 | IPConfig::Properties *properties); |
| 75 | static void ParseForeignOption(const std::string &option, |
| 76 | IPConfig::Properties *properties); |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 77 | |
| 78 | void InitOptions(std::vector<std::string> *options, Error *error); |
| 79 | |
| 80 | void AppendValueOption(const std::string &property, |
| 81 | const std::string &option, |
| 82 | std::vector<std::string> *options); |
| 83 | void AppendFlag(const std::string &property, |
| 84 | const std::string &option, |
| 85 | std::vector<std::string> *options); |
| 86 | |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 87 | ControlInterface *control_; |
Darin Petkov | f20994f | 2012-03-05 16:12:19 +0100 | [diff] [blame^] | 88 | EventDispatcher *dispatcher_; |
| 89 | Metrics *metrics_; |
| 90 | Manager *manager_; |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 91 | DeviceInfo *device_info_; |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 92 | KeyValueStore args_; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 93 | scoped_ptr<RPCTask> rpc_task_; |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 94 | std::string tunnel_interface_; |
Darin Petkov | f20994f | 2012-03-05 16:12:19 +0100 | [diff] [blame^] | 95 | VPNRefPtr device_; |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 96 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 97 | DISALLOW_COPY_AND_ASSIGN(OpenVPNDriver); |
| 98 | }; |
| 99 | |
| 100 | } // namespace shill |
| 101 | |
| 102 | #endif // SHILL_OPENVPN_DRIVER_ |