mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 1 | // 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 Le | 43ce4d4 | 2013-10-04 16:08:55 -0700 | [diff] [blame] | 7 | #include <base/stl_util.h> |
| 8 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 9 | #include "shill/logging.h" |
| 10 | #include "shill/technology.h" |
| 11 | |
| 12 | using std::map; |
| 13 | using std::string; |
| 14 | |
| 15 | namespace shill { |
| 16 | |
| 17 | // statics |
| 18 | const char PPPDevice::kDaemonPath[] = "/usr/sbin/pppd"; |
| 19 | const char PPPDevice::kPluginPath[] = SHIMDIR "/shill-pppd-plugin.so"; |
| 20 | |
| 21 | PPPDevice::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 | |
| 30 | PPPDevice::~PPPDevice() {} |
| 31 | |
| 32 | void PPPDevice::UpdateIPConfigFromPPP(const map<string, string> &configuration, |
| 33 | bool blackhole_ipv6) { |
| 34 | SLOG(PPP, 2) << __func__ << " on " << link_name(); |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 35 | IPConfig::Properties properties = |
| 36 | ParseIPConfiguration(link_name(), configuration); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 37 | properties.blackhole_ipv6 = blackhole_ipv6; |
| 38 | UpdateIPConfig(properties); |
| 39 | } |
| 40 | |
| 41 | // static |
| 42 | string 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 agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 50 | IPConfig::Properties PPPDevice::ParseIPConfiguration( |
| 51 | const string &link_name, const map<string, string> &configuration) { |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 52 | SLOG(PPP, 2) << __func__ << " on " << link_name; |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 53 | IPConfig::Properties properties; |
| 54 | properties.address_family = IPAddress::kFamilyIPv4; |
| 55 | properties.subnet_prefix = IPAddress::GetMaxPrefixLength( |
| 56 | properties.address_family); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 57 | 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 agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 62 | properties.address = value; |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 63 | } else if (key == kPPPExternalIP4Address) { |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 64 | properties.peer_address = value; |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 65 | } else if (key == kPPPGatewayAddress) { |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 66 | properties.gateway = value; |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 67 | } else if (key == kPPPDNS1) { |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 68 | properties.dns_servers.insert(properties.dns_servers.begin(), value); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 69 | } else if (key == kPPPDNS2) { |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 70 | properties.dns_servers.push_back(value); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 71 | } else if (key == kPPPLNSAddress) { |
| 72 | // This is really a L2TPIPSec property. But it's sent to us by |
| 73 | // our PPP plugin. |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 74 | properties.trusted_ip = value; |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 75 | } else { |
| 76 | SLOG(PPP, 2) << "Key ignored."; |
| 77 | } |
| 78 | } |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 79 | if (properties.gateway.empty()) { |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 80 | // 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 agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 83 | properties.gateway = properties.peer_address; |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 84 | } |
mukesh agrawal | 4fef249 | 2013-08-01 16:03:59 -0700 | [diff] [blame] | 85 | return properties; |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | } // namespace shill |