Darin Petkov | f20994f | 2012-03-05 16:12:19 +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 | #include "shill/vpn.h" |
| 6 | |
Paul Stewart | 536820d | 2012-03-19 16:05:59 -0700 | [diff] [blame] | 7 | #include <netinet/ether.h> |
| 8 | #include <linux/if.h> // Needs definitions from netinet/ether.h |
| 9 | |
| 10 | #include "shill/rtnl_handler.h" |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 11 | #include "shill/vpn_service.h" |
| 12 | |
Darin Petkov | f20994f | 2012-03-05 16:12:19 +0100 | [diff] [blame] | 13 | using std::string; |
| 14 | |
| 15 | namespace shill { |
| 16 | |
| 17 | VPN::VPN(ControlInterface *control, |
| 18 | EventDispatcher *dispatcher, |
| 19 | Metrics *metrics, |
| 20 | Manager *manager, |
| 21 | const string &link_name, |
| 22 | int interface_index) |
| 23 | : Device(control, dispatcher, metrics, manager, link_name, "", |
| 24 | interface_index, Technology::kVPN) {} |
| 25 | |
| 26 | VPN::~VPN() {} |
| 27 | |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 28 | void VPN::Start(Error *error, const EnabledStateChangedCallback &callback) { |
Paul Stewart | 536820d | 2012-03-19 16:05:59 -0700 | [diff] [blame] | 29 | RTNLHandler::GetInstance()->SetInterfaceFlags(interface_index(), IFF_UP, |
| 30 | IFF_UP); |
Eric Shienbrood | 9a24553 | 2012-03-07 14:20:39 -0500 | [diff] [blame] | 31 | if (error) |
| 32 | error->Reset(); |
| 33 | } |
| 34 | |
| 35 | void VPN::Stop(Error *error, const EnabledStateChangedCallback &callback) { |
| 36 | if (error) |
| 37 | error->Reset(); |
Paul Stewart | 536820d | 2012-03-19 16:05:59 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Darin Petkov | f20994f | 2012-03-05 16:12:19 +0100 | [diff] [blame] | 40 | bool VPN::TechnologyIs(const Technology::Identifier type) const { |
| 41 | return type == Technology::kVPN; |
| 42 | } |
| 43 | |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 44 | void VPN::SelectService(const VPNServiceRefPtr &service) { |
| 45 | VLOG(2) << __func__; |
| 46 | Device::SelectService(service); |
| 47 | } |
| 48 | |
| 49 | void VPN::UpdateIPConfig(const IPConfig::Properties &properties) { |
| 50 | VLOG(2) << __func__; |
Darin Petkov | 31a2eca | 2012-03-14 11:07:18 +0100 | [diff] [blame] | 51 | if (!ipconfig()) { |
| 52 | set_ipconfig(new IPConfig(control_interface(), link_name())); |
| 53 | } |
Darin Petkov | 79d74c9 | 2012-03-07 17:20:32 +0100 | [diff] [blame] | 54 | ipconfig()->set_properties(properties); |
| 55 | OnIPConfigUpdated(ipconfig(), true); |
| 56 | } |
| 57 | |
| 58 | void VPN::OnDisconnected() { |
| 59 | VLOG(2) << __func__; |
| 60 | OnIPConfigUpdated(ipconfig(), false); |
| 61 | } |
| 62 | |
Darin Petkov | f20994f | 2012-03-05 16:12:19 +0100 | [diff] [blame] | 63 | } // namespace shill |