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 | |
| 7 | #include "shill/logging.h" |
| 8 | #include "shill/technology.h" |
| 9 | |
| 10 | using std::map; |
| 11 | using std::string; |
| 12 | |
| 13 | namespace shill { |
| 14 | |
| 15 | // statics |
| 16 | const char PPPDevice::kDaemonPath[] = "/usr/sbin/pppd"; |
| 17 | const char PPPDevice::kPluginPath[] = SHIMDIR "/shill-pppd-plugin.so"; |
| 18 | |
| 19 | PPPDevice::PPPDevice(ControlInterface *control, |
| 20 | EventDispatcher *dispatcher, |
| 21 | Metrics *metrics, |
| 22 | Manager *manager, |
| 23 | const string &link_name, |
| 24 | int interface_index) |
| 25 | : VirtualDevice(control, dispatcher, metrics, manager, link_name, |
| 26 | interface_index, Technology::kPPP) {} |
| 27 | |
| 28 | PPPDevice::~PPPDevice() {} |
| 29 | |
| 30 | void PPPDevice::UpdateIPConfigFromPPP(const map<string, string> &configuration, |
| 31 | bool blackhole_ipv6) { |
| 32 | SLOG(PPP, 2) << __func__ << " on " << link_name(); |
| 33 | IPConfig::Properties properties; |
| 34 | ParseIPConfiguration(link_name(), configuration, &properties); |
| 35 | properties.blackhole_ipv6 = blackhole_ipv6; |
| 36 | UpdateIPConfig(properties); |
| 37 | } |
| 38 | |
| 39 | // static |
| 40 | string PPPDevice::GetInterfaceName(const map<string, string> &configuration) { |
| 41 | if (ContainsKey(configuration, kPPPInterfaceName)) { |
| 42 | return configuration.find(kPPPInterfaceName)->second; |
| 43 | } |
| 44 | return string(); |
| 45 | } |
| 46 | |
| 47 | // static |
| 48 | void PPPDevice::ParseIPConfiguration(const string &link_name, |
| 49 | const map<string, string> &configuration, |
| 50 | IPConfig::Properties *properties) { |
| 51 | SLOG(PPP, 2) << __func__ << " on " << link_name; |
| 52 | properties->address_family = IPAddress::kFamilyIPv4; |
| 53 | properties->subnet_prefix = IPAddress::GetMaxPrefixLength( |
| 54 | properties->address_family); |
| 55 | for (const auto &it : configuration) { |
| 56 | const string &key = it.first; |
| 57 | const string &value = it.second; |
| 58 | SLOG(PPP, 2) << "Processing: " << key << " -> " << value; |
| 59 | if (key == kPPPInternalIP4Address) { |
| 60 | properties->address = value; |
| 61 | } else if (key == kPPPExternalIP4Address) { |
| 62 | properties->peer_address = value; |
| 63 | } else if (key == kPPPGatewayAddress) { |
| 64 | properties->gateway = value; |
| 65 | } else if (key == kPPPDNS1) { |
| 66 | properties->dns_servers.insert(properties->dns_servers.begin(), value); |
| 67 | } else if (key == kPPPDNS2) { |
| 68 | properties->dns_servers.push_back(value); |
| 69 | } else if (key == kPPPLNSAddress) { |
| 70 | // This is really a L2TPIPSec property. But it's sent to us by |
| 71 | // our PPP plugin. |
| 72 | properties->trusted_ip = value; |
| 73 | } else { |
| 74 | SLOG(PPP, 2) << "Key ignored."; |
| 75 | } |
| 76 | } |
| 77 | if (properties->gateway.empty()) { |
| 78 | // The gateway may be unspecified, since this is a point-to-point |
| 79 | // link. Set to the peer's address, so that Connection can set the |
| 80 | // routing table. |
| 81 | properties->gateway = properties->peer_address; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | } // namespace shill |