Home | History | Annotate | Download | only in shill
      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 #include "shill/ppp_daemon.h"
     18 
     19 #include <stdint.h>
     20 
     21 #include <map>
     22 #include <string>
     23 #include <vector>
     24 
     25 #include <base/files/file_path.h>
     26 #include <base/memory/weak_ptr.h>
     27 #include <base/strings/string_number_conversions.h>
     28 
     29 #include "shill/control_interface.h"
     30 #include "shill/error.h"
     31 #include "shill/external_task.h"
     32 #include "shill/ppp_device.h"
     33 
     34 namespace shill {
     35 
     36 const char PPPDaemon::kDaemonPath[] = "/usr/sbin/pppd";
     37 const char PPPDaemon::kShimPluginPath[] = SHIMDIR "/shill-pppd-plugin.so";
     38 const char PPPDaemon::kPPPoEPluginPath[] = "rp-pppoe.so";
     39 const uint32_t PPPDaemon::kUnspecifiedValue = UINT32_MAX;
     40 
     41 std::unique_ptr<ExternalTask> PPPDaemon::Start(
     42     ControlInterface* control_interface,
     43     ProcessManager* process_manager,
     44     const base::WeakPtr<RPCTaskDelegate>& task_delegate,
     45     const PPPDaemon::Options& options,
     46     const std::string& device,
     47     const PPPDaemon::DeathCallback& death_callback,
     48     Error* error) {
     49   std::vector<std::string> arguments;
     50   if (options.debug) {
     51     arguments.push_back("debug");
     52   }
     53   if (options.no_detach) {
     54     arguments.push_back("nodetach");
     55   }
     56   if (options.no_default_route) {
     57     arguments.push_back("nodefaultroute");
     58   }
     59   if (options.use_peer_dns) {
     60     arguments.push_back("usepeerdns");
     61   }
     62   if (options.use_shim_plugin) {
     63     arguments.push_back("plugin");
     64     arguments.push_back(kShimPluginPath);
     65   }
     66   if (options.use_pppoe_plugin) {
     67     arguments.push_back("plugin");
     68     arguments.push_back(kPPPoEPluginPath);
     69   }
     70   if (options.lcp_echo_interval != kUnspecifiedValue) {
     71     arguments.push_back("lcp-echo-interval");
     72     arguments.push_back(base::UintToString(options.lcp_echo_interval));
     73   }
     74   if (options.lcp_echo_failure != kUnspecifiedValue) {
     75     arguments.push_back("lcp-echo-failure");
     76     arguments.push_back(base::UintToString(options.lcp_echo_failure));
     77   }
     78   if (options.max_fail != kUnspecifiedValue) {
     79     arguments.push_back("maxfail");
     80     arguments.push_back(base::UintToString(options.max_fail));
     81   }
     82   if (options.use_ipv6) {
     83     arguments.push_back("+ipv6");
     84     arguments.push_back("ipv6cp-use-ipaddr");
     85   }
     86 
     87   arguments.push_back(device);
     88 
     89   std::unique_ptr<ExternalTask> task(new ExternalTask(
     90       control_interface, process_manager, task_delegate, death_callback));
     91 
     92   std::map<std::string, std::string> environment;
     93   if (task->Start(base::FilePath(kDaemonPath), arguments, environment, true,
     94                   error)) {
     95     return task;
     96   }
     97   return nullptr;
     98 }
     99 
    100 }  // namespace shill
    101