• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2015 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef SHILL_PPP_DAEMON_H_
18 #define SHILL_PPP_DAEMON_H_
19 
20 #include <string>
21 
22 #include <base/callback.h>
23 #include <base/memory/weak_ptr.h>
24 #include <gtest/gtest_prod.h>
25 
26 #include "shill/external_task.h"
27 
28 namespace shill {
29 
30 class ControlInterface;
31 class Error;
32 class ProcessManager;
33 
34 // PPPDaemon provides control over the configuration and instantiation of pppd
35 // processes.  All pppd instances created through PPPDaemon will use shill's
36 // pppd plugin.
37 class PPPDaemon {
38  public:
39   // The type of callback invoked when an ExternalTask wrapping a pppd instance
40   // dies.  The first argument is the pid of the process, the second is the exit
41   // code.
42   typedef base::Callback<void(pid_t, int)> DeathCallback;
43 
44   // Provides options used when preparing a pppd task for execution.  These map
45   // to pppd command-line options.  Refer to https://ppp.samba.org/pppd.html for
46   // more details about the meaning of each.
47   struct Options {
OptionsOptions48     Options()
49         : debug(false),
50           no_detach(false),
51           no_default_route(false),
52           use_peer_dns(false),
53           use_shim_plugin(true),
54           use_pppoe_plugin(false),
55           lcp_echo_interval(kUnspecifiedValue),
56           lcp_echo_failure(kUnspecifiedValue),
57           max_fail(kUnspecifiedValue),
58           use_ipv6(false) {}
59 
60     // Causes pppd to emit log messages useful for debugging connectivity.
61     bool debug;
62 
63     // Causes pppd to not fork and daemonize, remaining attached to the
64     // controlling terminal that spawned it.
65     bool no_detach;
66 
67     // Stops pppd from modifying the routing table.
68     bool no_default_route;
69 
70     // Instructs pppd to request DNS servers from the remote server.
71     bool use_peer_dns;
72 
73     // If set, will cause the shill pppd plugin to be used at the creation of
74     // the pppd instace.  This will result in connectivity events being plumbed
75     // over D-Bus to the RPCTaskDelegate provided during PPPDaemon::Start.
76     bool use_shim_plugin;
77 
78     // If set, enables the rp-pppoe plugin which allows pppd to be used over
79     // ethernet devices.
80     bool use_pppoe_plugin;
81 
82     // The number of seconds between sending LCP echo requests.
83     uint32_t lcp_echo_interval;
84 
85     // The number of missed LCP echo responses tolerated before disconnecting.
86     uint32_t lcp_echo_failure;
87 
88     // The number of allowed failed consecutive connection attempts before
89     // giving up.  A value of 0 means there is no limit.
90     uint32_t max_fail;
91 
92     // Instructs pppd to request an IPv6 address from the remote server.
93     bool use_ipv6;
94   };
95 
96   // The path to the pppd plugin provided by shill.
97   static const char kShimPluginPath[];
98 
99   // Starts a pppd instance.  |options| provides the configuration for the
100   // instance to be started, |device| specifies which device the PPP connection
101   // is to be established on, |death_callback| will be invoked when the
102   // underlying pppd process dies.  |error| is populated if the task cannot be
103   // started, and nullptr is returned.
104   static std::unique_ptr<ExternalTask> Start(
105       ControlInterface* control_interface,
106       ProcessManager* process_manager,
107       const base::WeakPtr<RPCTaskDelegate>& task_delegate,
108       const Options& options,
109       const std::string& device,
110       const DeathCallback& death_callback,
111       Error* error);
112 
113  private:
114   FRIEND_TEST(PPPDaemonTest, PluginUsed);
115 
116   static const char kDaemonPath[];
117   static const char kPPPoEPluginPath[];
118   static const uint32_t kUnspecifiedValue;
119 
120   PPPDaemon();
121   ~PPPDaemon();
122 
123   DISALLOW_COPY_AND_ASSIGN(PPPDaemon);
124 };
125 
126 }  // namespace shill
127 
128 #endif  // SHILL_PPP_DAEMON_H_
129