blob: e4aa35f6992514a4ff9ac0acae43a089ef03294b [file] [log] [blame]
Garret Kellycb832e82015-01-14 16:37:27 -05001// 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 Kellyb84e02c2015-03-26 15:54:51 -04007#include <stdint.h>
8
Garret Kellycb832e82015-01-14 16:37:27 -05009#include <map>
10#include <string>
11#include <vector>
12
13#include <base/files/file_path.h>
14#include <base/memory/weak_ptr.h>
Garret Kelly75fba812015-03-09 15:18:02 -040015#include <base/strings/string_number_conversions.h>
Garret Kellycb832e82015-01-14 16:37:27 -050016
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
23namespace shill {
24
25const char PPPDaemon::kDaemonPath[] = "/usr/sbin/pppd";
Garret Kelly1e8414c2015-01-30 10:56:59 -050026const char PPPDaemon::kShimPluginPath[] = SHIMDIR "/shill-pppd-plugin.so";
27const char PPPDaemon::kPPPoEPluginPath[] = "rp-pppoe.so";
Garret Kellyb84e02c2015-03-26 15:54:51 -040028const uint32_t PPPDaemon::kUnspecifiedValue = UINT32_MAX;
Garret Kellycb832e82015-01-14 16:37:27 -050029
30std::unique_ptr<ExternalTask> PPPDaemon::Start(
Paul Stewart1a212a62015-06-16 13:13:10 -070031 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 Kellycb832e82015-01-14 16:37:27 -050038 std::vector<std::string> arguments;
Garret Kelly1e8414c2015-01-30 10:56:59 -050039 if (options.debug) {
40 arguments.push_back("debug");
41 }
Garret Kellycb832e82015-01-14 16:37:27 -050042 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 Kelly1e8414c2015-01-30 10:56:59 -050051 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 Kellyb84e02c2015-03-26 15:54:51 -040059 if (options.lcp_echo_interval != kUnspecifiedValue) {
Garret Kelly75fba812015-03-09 15:18:02 -040060 arguments.push_back("lcp-echo-interval");
61 arguments.push_back(base::UintToString(options.lcp_echo_interval));
62 }
Garret Kellyb84e02c2015-03-26 15:54:51 -040063 if (options.lcp_echo_failure != kUnspecifiedValue) {
Garret Kelly75fba812015-03-09 15:18:02 -040064 arguments.push_back("lcp-echo-failure");
65 arguments.push_back(base::UintToString(options.lcp_echo_failure));
66 }
Garret Kellyb84e02c2015-03-26 15:54:51 -040067 if (options.max_fail != kUnspecifiedValue) {
68 arguments.push_back("maxfail");
69 arguments.push_back(base::UintToString(options.max_fail));
70 }
Garret Kelly1e8414c2015-01-30 10:56:59 -050071
Garret Kellycb832e82015-01-14 16:37:27 -050072 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 Jiang5b3740f2015-05-27 15:33:33 -070080 return task;
Garret Kellycb832e82015-01-14 16:37:27 -050081 }
82 return nullptr;
83}
84
85} // namespace shill