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 | #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 | |
| 16 | namespace shill { |
| 17 | |
| 18 | class ControlInterface; |
| 19 | class GLib; |
| 20 | class 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. |
| 25 | class 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 Kelly | 1e8414c | 2015-01-30 10:56:59 -0500 | [diff] [blame] | 37 | : debug(false), |
| 38 | no_detach(false), |
| 39 | no_default_route(false), |
| 40 | use_peer_dns(false), |
| 41 | use_shim_plugin(true), |
Garret Kelly | 75fba81 | 2015-03-09 15:18:02 -0400 | [diff] [blame] | 42 | use_pppoe_plugin(false), |
Garret Kelly | b84e02c | 2015-03-26 15:54:51 -0400 | [diff] [blame] | 43 | lcp_echo_interval(kUnspecifiedValue), |
| 44 | lcp_echo_failure(kUnspecifiedValue), |
| 45 | max_fail(kUnspecifiedValue) {} |
Garret Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 46 | |
Garret Kelly | 1e8414c | 2015-01-30 10:56:59 -0500 | [diff] [blame] | 47 | // 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 Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 52 | bool no_detach; |
Garret Kelly | 1e8414c | 2015-01-30 10:56:59 -0500 | [diff] [blame] | 53 | |
| 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 Kelly | 75fba81 | 2015-03-09 15:18:02 -0400 | [diff] [blame] | 68 | |
| 69 | // The number of seconds between sending LCP echo requests. |
Garret Kelly | b84e02c | 2015-03-26 15:54:51 -0400 | [diff] [blame] | 70 | uint32_t lcp_echo_interval; |
Garret Kelly | 75fba81 | 2015-03-09 15:18:02 -0400 | [diff] [blame] | 71 | |
| 72 | // The number of missed LCP echo responses tolerated before disconnecting. |
Garret Kelly | b84e02c | 2015-03-26 15:54:51 -0400 | [diff] [blame] | 73 | 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 Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | // The path to the pppd plugin provided by shill. |
Garret Kelly | 1e8414c | 2015-01-30 10:56:59 -0500 | [diff] [blame] | 81 | static const char kShimPluginPath[]; |
Garret Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 82 | |
| 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 Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 89 | 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 Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 96 | |
| 97 | private: |
| 98 | FRIEND_TEST(PPPDaemonTest, PluginUsed); |
| 99 | |
| 100 | static const char kDaemonPath[]; |
Garret Kelly | 1e8414c | 2015-01-30 10:56:59 -0500 | [diff] [blame] | 101 | static const char kPPPoEPluginPath[]; |
Garret Kelly | b84e02c | 2015-03-26 15:54:51 -0400 | [diff] [blame] | 102 | static const uint32_t kUnspecifiedValue; |
Garret Kelly | cb832e8 | 2015-01-14 16:37:27 -0500 | [diff] [blame] | 103 | |
| 104 | PPPDaemon(); |
| 105 | ~PPPDaemon(); |
| 106 | |
| 107 | DISALLOW_COPY_AND_ASSIGN(PPPDaemon); |
| 108 | }; |
| 109 | |
| 110 | } // namespace shill |
| 111 | |
| 112 | #endif // SHILL_PPP_DAEMON_H_ |