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