blob: 53387ad6203f2f71b755dbc69936bb82676c8ba3 [file] [log] [blame]
Darin Petkovf20994f2012-03-05 16:12:19 +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.h"
6
Paul Stewart536820d2012-03-19 16:05:59 -07007#include <netinet/ether.h>
8#include <linux/if.h> // Needs definitions from netinet/ether.h
9
10#include "shill/rtnl_handler.h"
Ben Chanfad4a0b2012-04-18 15:49:59 -070011#include "shill/scope_logger.h"
Darin Petkov79d74c92012-03-07 17:20:32 +010012#include "shill/vpn_service.h"
13
Darin Petkovf20994f2012-03-05 16:12:19 +010014using std::string;
15
16namespace shill {
17
18VPN::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
27VPN::~VPN() {}
28
Eric Shienbrood9a245532012-03-07 14:20:39 -050029void VPN::Start(Error *error, const EnabledStateChangedCallback &callback) {
Paul Stewart536820d2012-03-19 16:05:59 -070030 RTNLHandler::GetInstance()->SetInterfaceFlags(interface_index(), IFF_UP,
31 IFF_UP);
Eric Shienbrood9a245532012-03-07 14:20:39 -050032 if (error)
33 error->Reset();
34}
35
36void VPN::Stop(Error *error, const EnabledStateChangedCallback &callback) {
37 if (error)
38 error->Reset();
Paul Stewart536820d2012-03-19 16:05:59 -070039}
40
Darin Petkovf20994f2012-03-05 16:12:19 +010041bool VPN::TechnologyIs(const Technology::Identifier type) const {
42 return type == Technology::kVPN;
43}
44
Darin Petkov79d74c92012-03-07 17:20:32 +010045void VPN::SelectService(const VPNServiceRefPtr &service) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070046 SLOG(VPN, 2) << __func__;
Darin Petkov79d74c92012-03-07 17:20:32 +010047 Device::SelectService(service);
48}
49
50void VPN::UpdateIPConfig(const IPConfig::Properties &properties) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070051 SLOG(VPN, 2) << __func__;
Darin Petkov31a2eca2012-03-14 11:07:18 +010052 if (!ipconfig()) {
53 set_ipconfig(new IPConfig(control_interface(), link_name()));
54 }
Darin Petkov79d74c92012-03-07 17:20:32 +010055 ipconfig()->set_properties(properties);
56 OnIPConfigUpdated(ipconfig(), true);
57}
58
59void VPN::OnDisconnected() {
Ben Chanfad4a0b2012-04-18 15:49:59 -070060 SLOG(VPN, 2) << __func__;
Darin Petkov79d74c92012-03-07 17:20:32 +010061 OnIPConfigUpdated(ipconfig(), false);
62}
63
Darin Petkovf20994f2012-03-05 16:12:19 +010064} // namespace shill