blob: e069e543468960e8f4299dfb489544b3e50c664b [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
17// statics
18const char PPPDevice::kDaemonPath[] = "/usr/sbin/pppd";
19const char PPPDevice::kPluginPath[] = SHIMDIR "/shill-pppd-plugin.so";
20
21PPPDevice::PPPDevice(ControlInterface *control,
22 EventDispatcher *dispatcher,
23 Metrics *metrics,
24 Manager *manager,
25 const string &link_name,
26 int interface_index)
27 : VirtualDevice(control, dispatcher, metrics, manager, link_name,
28 interface_index, Technology::kPPP) {}
29
30PPPDevice::~PPPDevice() {}
31
32void PPPDevice::UpdateIPConfigFromPPP(const map<string, string> &configuration,
33 bool blackhole_ipv6) {
34 SLOG(PPP, 2) << __func__ << " on " << link_name();
mukesh agrawal4fef2492013-08-01 16:03:59 -070035 IPConfig::Properties properties =
36 ParseIPConfiguration(link_name(), configuration);
mukesh agrawal9da07772013-05-15 14:15:17 -070037 properties.blackhole_ipv6 = blackhole_ipv6;
38 UpdateIPConfig(properties);
39}
40
41// static
42string PPPDevice::GetInterfaceName(const map<string, string> &configuration) {
43 if (ContainsKey(configuration, kPPPInterfaceName)) {
44 return configuration.find(kPPPInterfaceName)->second;
45 }
46 return string();
47}
48
49// static
mukesh agrawal4fef2492013-08-01 16:03:59 -070050IPConfig::Properties PPPDevice::ParseIPConfiguration(
51 const string &link_name, const map<string, string> &configuration) {
mukesh agrawal9da07772013-05-15 14:15:17 -070052 SLOG(PPP, 2) << __func__ << " on " << link_name;
mukesh agrawal4fef2492013-08-01 16:03:59 -070053 IPConfig::Properties properties;
54 properties.address_family = IPAddress::kFamilyIPv4;
55 properties.subnet_prefix = IPAddress::GetMaxPrefixLength(
56 properties.address_family);
mukesh agrawal9da07772013-05-15 14:15:17 -070057 for (const auto &it : configuration) {
58 const string &key = it.first;
59 const string &value = it.second;
60 SLOG(PPP, 2) << "Processing: " << key << " -> " << value;
61 if (key == kPPPInternalIP4Address) {
mukesh agrawal4fef2492013-08-01 16:03:59 -070062 properties.address = value;
mukesh agrawal9da07772013-05-15 14:15:17 -070063 } else if (key == kPPPExternalIP4Address) {
mukesh agrawal4fef2492013-08-01 16:03:59 -070064 properties.peer_address = value;
mukesh agrawal9da07772013-05-15 14:15:17 -070065 } else if (key == kPPPGatewayAddress) {
mukesh agrawal4fef2492013-08-01 16:03:59 -070066 properties.gateway = value;
mukesh agrawal9da07772013-05-15 14:15:17 -070067 } else if (key == kPPPDNS1) {
mukesh agrawal4fef2492013-08-01 16:03:59 -070068 properties.dns_servers.insert(properties.dns_servers.begin(), value);
mukesh agrawal9da07772013-05-15 14:15:17 -070069 } else if (key == kPPPDNS2) {
mukesh agrawal4fef2492013-08-01 16:03:59 -070070 properties.dns_servers.push_back(value);
mukesh agrawal9da07772013-05-15 14:15:17 -070071 } else if (key == kPPPLNSAddress) {
72 // This is really a L2TPIPSec property. But it's sent to us by
73 // our PPP plugin.
mukesh agrawal4fef2492013-08-01 16:03:59 -070074 properties.trusted_ip = value;
mukesh agrawal9da07772013-05-15 14:15:17 -070075 } else {
76 SLOG(PPP, 2) << "Key ignored.";
77 }
78 }
mukesh agrawal4fef2492013-08-01 16:03:59 -070079 if (properties.gateway.empty()) {
mukesh agrawal9da07772013-05-15 14:15:17 -070080 // The gateway may be unspecified, since this is a point-to-point
81 // link. Set to the peer's address, so that Connection can set the
82 // routing table.
mukesh agrawal4fef2492013-08-01 16:03:59 -070083 properties.gateway = properties.peer_address;
mukesh agrawal9da07772013-05-15 14:15:17 -070084 }
mukesh agrawal4fef2492013-08-01 16:03:59 -070085 return properties;
mukesh agrawal9da07772013-05-15 14:15:17 -070086}
87
88} // namespace shill