blob: 0adffcb27c6e5a9d623500a96e9ee86642bd7a6f [file] [log] [blame]
Darin Petkov33af05c2012-02-28 10:10:30 +01001// 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#include "shill/vpn_provider.h"
6
7#include <base/logging.h>
8#include <chromeos/dbus/service_constants.h>
9
10#include "shill/error.h"
Paul Stewartca6abd42012-03-01 15:45:29 -080011#include "shill/manager.h"
Darin Petkov33af05c2012-02-28 10:10:30 +010012#include "shill/openvpn_driver.h"
13#include "shill/vpn_service.h"
14
15using std::string;
Paul Stewartca6abd42012-03-01 15:45:29 -080016using std::vector;
Darin Petkov33af05c2012-02-28 10:10:30 +010017
18namespace shill {
19
20VPNProvider::VPNProvider(ControlInterface *control_interface,
21 EventDispatcher *dispatcher,
22 Metrics *metrics,
23 Manager *manager)
24 : control_interface_(control_interface),
25 dispatcher_(dispatcher),
26 metrics_(metrics),
27 manager_(manager) {}
28
29VPNProvider::~VPNProvider() {}
30
31void VPNProvider::Start() {}
32
33void VPNProvider::Stop() {}
34
35VPNServiceRefPtr VPNProvider::GetService(const KeyValueStore &args,
36 Error *error) {
37 VLOG(2) << __func__;
38 if (!args.ContainsString(flimflam::kProviderTypeProperty)) {
39 Error::PopulateAndLog(
40 error, Error::kNotSupported, "Missing VPN type property.");
41 return NULL;
42 }
Paul Stewartca6abd42012-03-01 15:45:29 -080043
Darin Petkov33af05c2012-02-28 10:10:30 +010044 const string &type = args.GetString(flimflam::kProviderTypeProperty);
45 scoped_ptr<VPNDriver> driver;
46 if (type == flimflam::kProviderOpenVpn) {
Paul Stewartca6abd42012-03-01 15:45:29 -080047 driver.reset(new OpenVPNDriver(control_interface_,
48 manager_->device_info(), args));
Darin Petkov33af05c2012-02-28 10:10:30 +010049 } else {
50 Error::PopulateAndLog(
51 error, Error::kNotSupported, "Unsupported VPN type: " + type);
52 return NULL;
53 }
Paul Stewartca6abd42012-03-01 15:45:29 -080054
55 services_.push_back(
56 new VPNService(
57 control_interface_, dispatcher_, metrics_, manager_,
58 driver.release()));
59
60 return services_.back();
61
62}
63
64bool VPNProvider::OnDeviceInfoAvailable(const string &link_name,
65 int interface_index) {
66 for (vector<VPNServiceRefPtr>::const_iterator it = services_.begin();
67 it != services_.end();
68 ++it) {
69 if ((*it)->driver()->ClaimInterface(link_name, interface_index)) {
70 return true;
71 }
72 }
73
74 return false;
Darin Petkov33af05c2012-02-28 10:10:30 +010075}
76
77} // namespace shill