Garret Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 1 | // Copyright 2015 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_daemon.h" |
| 6 | |
Garret Kelly | b84e02c | 2015-03-26 15:54:51 -0400 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
Garret Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 9 | #include <map> |
| 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
| 13 | #include <base/files/file_path.h> |
| 14 | #include <base/memory/weak_ptr.h> |
Garret Kelly | 75fba81 | 2015-03-09 15:18:02 -0400 | [diff] [blame] | 15 | #include <base/strings/string_number_conversions.h> |
Garret Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 16 | |
| 17 | #include "shill/control_interface.h" |
| 18 | #include "shill/error.h" |
| 19 | #include "shill/external_task.h" |
| 20 | #include "shill/glib.h" |
| 21 | #include "shill/ppp_device.h" |
| 22 | |
| 23 | namespace shill { |
| 24 | |
| 25 | const char PPPDaemon::kDaemonPath[] = "/usr/sbin/pppd"; |
Garret Kelly | 1e8414c | 2015-01-30 10:56:59 -0500 | [diff] [blame] | 26 | const char PPPDaemon::kShimPluginPath[] = SHIMDIR "/shill-pppd-plugin.so"; |
| 27 | const char PPPDaemon::kPPPoEPluginPath[] = "rp-pppoe.so"; |
Garret Kelly | b84e02c | 2015-03-26 15:54:51 -0400 | [diff] [blame] | 28 | const uint32_t PPPDaemon::kUnspecifiedValue = UINT32_MAX; |
Garret Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 29 | |
| 30 | std::unique_ptr<ExternalTask> PPPDaemon::Start( |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 31 | ControlInterface* control_interface, |
| 32 | GLib* glib, |
| 33 | const base::WeakPtr<RPCTaskDelegate>& task_delegate, |
| 34 | const PPPDaemon::Options& options, |
| 35 | const std::string& device, |
| 36 | const PPPDaemon::DeathCallback& death_callback, |
| 37 | Error* error) { |
Garret Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 38 | std::vector<std::string> arguments; |
Garret Kelly | 1e8414c | 2015-01-30 10:56:59 -0500 | [diff] [blame] | 39 | if (options.debug) { |
| 40 | arguments.push_back("debug"); |
| 41 | } |
Garret Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 42 | if (options.no_detach) { |
| 43 | arguments.push_back("nodetach"); |
| 44 | } |
| 45 | if (options.no_default_route) { |
| 46 | arguments.push_back("nodefaultroute"); |
| 47 | } |
| 48 | if (options.use_peer_dns) { |
| 49 | arguments.push_back("usepeerdns"); |
| 50 | } |
Garret Kelly | 1e8414c | 2015-01-30 10:56:59 -0500 | [diff] [blame] | 51 | if (options.use_shim_plugin) { |
| 52 | arguments.push_back("plugin"); |
| 53 | arguments.push_back(kShimPluginPath); |
| 54 | } |
| 55 | if (options.use_pppoe_plugin) { |
| 56 | arguments.push_back("plugin"); |
| 57 | arguments.push_back(kPPPoEPluginPath); |
| 58 | } |
Garret Kelly | b84e02c | 2015-03-26 15:54:51 -0400 | [diff] [blame] | 59 | if (options.lcp_echo_interval != kUnspecifiedValue) { |
Garret Kelly | 75fba81 | 2015-03-09 15:18:02 -0400 | [diff] [blame] | 60 | arguments.push_back("lcp-echo-interval"); |
| 61 | arguments.push_back(base::UintToString(options.lcp_echo_interval)); |
| 62 | } |
Garret Kelly | b84e02c | 2015-03-26 15:54:51 -0400 | [diff] [blame] | 63 | if (options.lcp_echo_failure != kUnspecifiedValue) { |
Garret Kelly | 75fba81 | 2015-03-09 15:18:02 -0400 | [diff] [blame] | 64 | arguments.push_back("lcp-echo-failure"); |
| 65 | arguments.push_back(base::UintToString(options.lcp_echo_failure)); |
| 66 | } |
Garret Kelly | b84e02c | 2015-03-26 15:54:51 -0400 | [diff] [blame] | 67 | if (options.max_fail != kUnspecifiedValue) { |
| 68 | arguments.push_back("maxfail"); |
| 69 | arguments.push_back(base::UintToString(options.max_fail)); |
| 70 | } |
Garret Kelly | 1e8414c | 2015-01-30 10:56:59 -0500 | [diff] [blame] | 71 | |
Garret Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 72 | arguments.push_back(device); |
| 73 | |
| 74 | std::unique_ptr<ExternalTask> task(new ExternalTask( |
| 75 | control_interface, glib, task_delegate, death_callback)); |
| 76 | |
| 77 | std::map<std::string, std::string> environment; |
| 78 | if (task->Start(base::FilePath(kDaemonPath), arguments, environment, true, |
| 79 | error)) { |
Yunlian Jiang | 5b3740f | 2015-05-27 15:33:33 -0700 | [diff] [blame] | 80 | return task; |
Garret Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 81 | } |
| 82 | return nullptr; |
| 83 | } |
| 84 | |
| 85 | } // namespace shill |