blob: c69dcd0da178631d2a2e8b321daa470fd8ba2581 [file] [log] [blame]
mukesh agrawal9da07772013-05-15 14:15:17 -07001// Copyright (c) 2013 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/ppp_device.h"
6
Thieu Le43ce4d42013-10-04 16:08:55 -07007#include <base/stl_util.h>
8
mukesh agrawal9da07772013-05-15 14:15:17 -07009#include "shill/logging.h"
10#include "shill/technology.h"
11
12using std::map;
13using std::string;
14
15namespace shill {
16
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070017namespace Logging {
18static auto kModuleLogScope = ScopeLogger::kPPP;
19static string ObjectID(PPPDevice *p) { return p->link_name(); }
20}
21
mukesh agrawal9da07772013-05-15 14:15:17 -070022// statics
23const char PPPDevice::kDaemonPath[] = "/usr/sbin/pppd";
24const char PPPDevice::kPluginPath[] = SHIMDIR "/shill-pppd-plugin.so";
25
26PPPDevice::PPPDevice(ControlInterface *control,
27 EventDispatcher *dispatcher,
28 Metrics *metrics,
29 Manager *manager,
30 const string &link_name,
31 int interface_index)
32 : VirtualDevice(control, dispatcher, metrics, manager, link_name,
33 interface_index, Technology::kPPP) {}
34
35PPPDevice::~PPPDevice() {}
36
37void PPPDevice::UpdateIPConfigFromPPP(const map<string, string> &configuration,
38 bool blackhole_ipv6) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070039 SLOG(this, 2) << __func__ << " on " << link_name();
mukesh agrawal4fef2492013-08-01 16:03:59 -070040 IPConfig::Properties properties =
41 ParseIPConfiguration(link_name(), configuration);
mukesh agrawal9da07772013-05-15 14:15:17 -070042 properties.blackhole_ipv6 = blackhole_ipv6;
43 UpdateIPConfig(properties);
44}
45
46// static
47string PPPDevice::GetInterfaceName(const map<string, string> &configuration) {
48 if (ContainsKey(configuration, kPPPInterfaceName)) {
49 return configuration.find(kPPPInterfaceName)->second;
50 }
51 return string();
52}
53
54// static
mukesh agrawal4fef2492013-08-01 16:03:59 -070055IPConfig::Properties PPPDevice::ParseIPConfiguration(
56 const string &link_name, const map<string, string> &configuration) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070057 SLOG(PPP, nullptr, 2) << __func__ << " on " << link_name;
mukesh agrawal4fef2492013-08-01 16:03:59 -070058 IPConfig::Properties properties;
59 properties.address_family = IPAddress::kFamilyIPv4;
60 properties.subnet_prefix = IPAddress::GetMaxPrefixLength(
61 properties.address_family);
mukesh agrawal9da07772013-05-15 14:15:17 -070062 for (const auto &it : configuration) {
63 const string &key = it.first;
64 const string &value = it.second;
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070065 SLOG(PPP, nullptr, 2) << "Processing: " << key << " -> " << value;
mukesh agrawal9da07772013-05-15 14:15:17 -070066 if (key == kPPPInternalIP4Address) {
mukesh agrawal4fef2492013-08-01 16:03:59 -070067 properties.address = value;
mukesh agrawal9da07772013-05-15 14:15:17 -070068 } else if (key == kPPPExternalIP4Address) {
mukesh agrawal4fef2492013-08-01 16:03:59 -070069 properties.peer_address = value;
mukesh agrawal9da07772013-05-15 14:15:17 -070070 } else if (key == kPPPGatewayAddress) {
mukesh agrawal4fef2492013-08-01 16:03:59 -070071 properties.gateway = value;
mukesh agrawal9da07772013-05-15 14:15:17 -070072 } else if (key == kPPPDNS1) {
mukesh agrawal4fef2492013-08-01 16:03:59 -070073 properties.dns_servers.insert(properties.dns_servers.begin(), value);
mukesh agrawal9da07772013-05-15 14:15:17 -070074 } else if (key == kPPPDNS2) {
mukesh agrawal4fef2492013-08-01 16:03:59 -070075 properties.dns_servers.push_back(value);
mukesh agrawal9da07772013-05-15 14:15:17 -070076 } else if (key == kPPPLNSAddress) {
77 // This is really a L2TPIPSec property. But it's sent to us by
78 // our PPP plugin.
mukesh agrawal4fef2492013-08-01 16:03:59 -070079 properties.trusted_ip = value;
mukesh agrawal9da07772013-05-15 14:15:17 -070080 } else {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070081 SLOG(PPP, nullptr, 2) << "Key ignored.";
mukesh agrawal9da07772013-05-15 14:15:17 -070082 }
83 }
mukesh agrawal4fef2492013-08-01 16:03:59 -070084 if (properties.gateway.empty()) {
mukesh agrawal9da07772013-05-15 14:15:17 -070085 // The gateway may be unspecified, since this is a point-to-point
86 // link. Set to the peer's address, so that Connection can set the
87 // routing table.
mukesh agrawal4fef2492013-08-01 16:03:59 -070088 properties.gateway = properties.peer_address;
mukesh agrawal9da07772013-05-15 14:15:17 -070089 }
mukesh agrawal4fef2492013-08-01 16:03:59 -070090 return properties;
mukesh agrawal9da07772013-05-15 14:15:17 -070091}
92
93} // namespace shill