blob: fa431404e141983a14e4abeb4867dfa8c934aa60 [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
Christopher Wileyb691efd2012-08-09 13:51:51 -070010#include "shill/logging.h"
Paul Stewart536820d2012-03-19 16:05:59 -070011#include "shill/rtnl_handler.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 Petkov79d74c92012-03-07 17:20:32 +010041void VPN::SelectService(const VPNServiceRefPtr &service) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070042 SLOG(VPN, 2) << __func__;
Darin Petkov79d74c92012-03-07 17:20:32 +010043 Device::SelectService(service);
44}
45
46void VPN::UpdateIPConfig(const IPConfig::Properties &properties) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070047 SLOG(VPN, 2) << __func__;
Darin Petkov31a2eca2012-03-14 11:07:18 +010048 if (!ipconfig()) {
49 set_ipconfig(new IPConfig(control_interface(), link_name()));
50 }
Darin Petkov79d74c92012-03-07 17:20:32 +010051 ipconfig()->set_properties(properties);
52 OnIPConfigUpdated(ipconfig(), true);
53}
54
55void VPN::OnDisconnected() {
Darin Petkov09cb6682012-10-03 11:27:20 +020056 // TODO(petkov): Remove this method and update all callsites to invoke
57 // DropConnection directly.
Ben Chanfad4a0b2012-04-18 15:49:59 -070058 SLOG(VPN, 2) << __func__;
Darin Petkov09cb6682012-10-03 11:27:20 +020059 DropConnection();
Darin Petkov79d74c92012-03-07 17:20:32 +010060}
61
Darin Petkovf20994f2012-03-05 16:12:19 +010062} // namespace shill