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 | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 17 | #include "shill/vpn_driver.h" |
| 18 | |
| 19 | namespace shill { |
| 20 | |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 21 | class ControlInterface; |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 22 | class DeviceInfo; |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 23 | class Error; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 24 | class RPCTask; |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 25 | class DeviceStub; |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 26 | |
| 27 | class OpenVPNDriver : public VPNDriver { |
| 28 | public: |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 29 | OpenVPNDriver(ControlInterface *control, |
| 30 | DeviceInfo *device_info, |
| 31 | const KeyValueStore &args); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 32 | virtual ~OpenVPNDriver(); |
| 33 | |
Darin Petkov | 14c29ec | 2012-03-02 11:34:19 +0100 | [diff] [blame^] | 34 | bool Notify(const std::string &reason, |
| 35 | const std::map<std::string, std::string> &dict); |
| 36 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 37 | // Inherited from VPNDriver. |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 38 | virtual bool ClaimInterface(const std::string &link_name, |
| 39 | int interface_index); |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 40 | virtual void Connect(Error *error); |
| 41 | |
| 42 | private: |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 43 | friend class OpenVPNDriverTest; |
| 44 | FRIEND_TEST(OpenVPNDriverTest, AppendFlag); |
| 45 | FRIEND_TEST(OpenVPNDriverTest, AppendValueOption); |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 46 | FRIEND_TEST(OpenVPNDriverTest, ClaimInterface); |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 47 | FRIEND_TEST(OpenVPNDriverTest, InitOptions); |
| 48 | FRIEND_TEST(OpenVPNDriverTest, InitOptionsNoHost); |
Darin Petkov | 14c29ec | 2012-03-02 11:34:19 +0100 | [diff] [blame^] | 49 | FRIEND_TEST(OpenVPNDriverTest, ParseForeignOption); |
| 50 | FRIEND_TEST(OpenVPNDriverTest, ParseForeignOptions); |
| 51 | FRIEND_TEST(OpenVPNDriverTest, ParseIPConfiguration); |
| 52 | |
| 53 | // The map is a sorted container that allows us to iterate through the options |
| 54 | // in order. |
| 55 | typedef std::map<int, std::string> ForeignOptions; |
| 56 | |
| 57 | static void ParseIPConfiguration( |
| 58 | const std::map<std::string, std::string> &configuration, |
| 59 | IPConfig::Properties *properties); |
| 60 | static void ParseForeignOptions(const ForeignOptions &options, |
| 61 | IPConfig::Properties *properties); |
| 62 | static void ParseForeignOption(const std::string &option, |
| 63 | IPConfig::Properties *properties); |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 64 | |
| 65 | void InitOptions(std::vector<std::string> *options, Error *error); |
| 66 | |
| 67 | void AppendValueOption(const std::string &property, |
| 68 | const std::string &option, |
| 69 | std::vector<std::string> *options); |
| 70 | void AppendFlag(const std::string &property, |
| 71 | const std::string &option, |
| 72 | std::vector<std::string> *options); |
| 73 | |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 74 | ControlInterface *control_; |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 75 | DeviceInfo *device_info_; |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 76 | KeyValueStore args_; |
Darin Petkov | a9b1fed | 2012-02-29 11:49:05 +0100 | [diff] [blame] | 77 | scoped_ptr<RPCTask> rpc_task_; |
Paul Stewart | ca6abd4 | 2012-03-01 15:45:29 -0800 | [diff] [blame] | 78 | std::string tunnel_interface_; |
| 79 | int interface_index_; |
Darin Petkov | fe6a937 | 2012-02-28 16:25:06 +0100 | [diff] [blame] | 80 | |
Darin Petkov | 33af05c | 2012-02-28 10:10:30 +0100 | [diff] [blame] | 81 | DISALLOW_COPY_AND_ASSIGN(OpenVPNDriver); |
| 82 | }; |
| 83 | |
| 84 | } // namespace shill |
| 85 | |
| 86 | #endif // SHILL_OPENVPN_DRIVER_ |