blob: ed97c6e47d25ffeb2760a634018060546ca8e375 [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#ifndef SHILL_PPP_DAEMON_H_
6#define SHILL_PPP_DAEMON_H_
7
8#include <string>
9
10#include <base/callback.h>
11#include <base/memory/weak_ptr.h>
12#include <gtest/gtest_prod.h>
13
14#include "shill/external_task.h"
15
16namespace shill {
17
18class ControlInterface;
19class GLib;
20class Error;
21
22// PPPDaemon provides control over the configuration and instantiation of pppd
23// processes. All pppd instances created through PPPDaemon will use shill's
24// pppd plugin.
25class PPPDaemon {
26 public:
27 // The type of callback invoked when an ExternalTask wrapping a pppd instance
28 // dies. The first argument is the pid of the process, the second is the exit
29 // code.
30 typedef base::Callback<void(pid_t, int)> DeathCallback;
31
32 // Provides options used when preparing a pppd task for execution. These map
33 // to pppd command-line options. Refer to https://ppp.samba.org/pppd.html for
34 // more details about the meaning of each.
35 struct Options {
36 Options()
Garret Kelly1e8414c2015-01-30 10:56:59 -050037 : debug(false),
38 no_detach(false),
39 no_default_route(false),
40 use_peer_dns(false),
41 use_shim_plugin(true),
Garret Kelly75fba812015-03-09 15:18:02 -040042 use_pppoe_plugin(false),
Garret Kellyb84e02c2015-03-26 15:54:51 -040043 lcp_echo_interval(kUnspecifiedValue),
44 lcp_echo_failure(kUnspecifiedValue),
45 max_fail(kUnspecifiedValue) {}
Garret Kellycb832e82015-01-14 16:37:27 -050046
Garret Kelly1e8414c2015-01-30 10:56:59 -050047 // Causes pppd to emit log messages useful for debugging connectivity.
48 bool debug;
49
50 // Causes pppd to not fork and daemonize, remaining attached to the
51 // controlling terminal that spawned it.
Garret Kellycb832e82015-01-14 16:37:27 -050052 bool no_detach;
Garret Kelly1e8414c2015-01-30 10:56:59 -050053
54 // Stops pppd from modifying the routing table.
55 bool no_default_route;
56
57 // Instructs pppd to request DNS servers from the remote server.
58 bool use_peer_dns;
59
60 // If set, will cause the shill pppd plugin to be used at the creation of
61 // the pppd instace. This will result in connectivity events being plumbed
62 // over D-Bus to the RPCTaskDelegate provided during PPPDaemon::Start.
63 bool use_shim_plugin;
64
65 // If set, enables the rp-pppoe plugin which allows pppd to be used over
66 // ethernet devices.
67 bool use_pppoe_plugin;
Garret Kelly75fba812015-03-09 15:18:02 -040068
69 // The number of seconds between sending LCP echo requests.
Garret Kellyb84e02c2015-03-26 15:54:51 -040070 uint32_t lcp_echo_interval;
Garret Kelly75fba812015-03-09 15:18:02 -040071
72 // The number of missed LCP echo responses tolerated before disconnecting.
Garret Kellyb84e02c2015-03-26 15:54:51 -040073 uint32_t lcp_echo_failure;
74
75 // The number of allowed failed consecutive connection attempts before
76 // giving up. A value of 0 means there is no limit.
77 uint32_t max_fail;
Garret Kellycb832e82015-01-14 16:37:27 -050078 };
79
80 // The path to the pppd plugin provided by shill.
Garret Kelly1e8414c2015-01-30 10:56:59 -050081 static const char kShimPluginPath[];
Garret Kellycb832e82015-01-14 16:37:27 -050082
83 // Starts a pppd instance. |options| provides the configuration for the
84 // instance to be started, |device| specifies which device the PPP connection
85 // is to be established on, |death_callback| will be invoked when the
86 // underlying pppd process dies. |error| is populated if the task cannot be
87 // started, and nullptr is returned.
88 static std::unique_ptr<ExternalTask> Start(
Paul Stewart1a212a62015-06-16 13:13:10 -070089 ControlInterface* control_interface,
90 GLib* glib,
91 const base::WeakPtr<RPCTaskDelegate>& task_delegate,
92 const Options& options,
93 const std::string& device,
94 const DeathCallback& death_callback,
95 Error* error);
Garret Kellycb832e82015-01-14 16:37:27 -050096
97 private:
98 FRIEND_TEST(PPPDaemonTest, PluginUsed);
99
100 static const char kDaemonPath[];
Garret Kelly1e8414c2015-01-30 10:56:59 -0500101 static const char kPPPoEPluginPath[];
Garret Kellyb84e02c2015-03-26 15:54:51 -0400102 static const uint32_t kUnspecifiedValue;
Garret Kellycb832e82015-01-14 16:37:27 -0500103
104 PPPDaemon();
105 ~PPPDaemon();
106
107 DISALLOW_COPY_AND_ASSIGN(PPPDaemon);
108};
109
110} // namespace shill
111
112#endif // SHILL_PPP_DAEMON_H_