• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2014 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 APMANAGER_DHCP_SERVER_H_
18 #define APMANAGER_DHCP_SERVER_H_
19 
20 #include <string>
21 
22 #include <base/macros.h>
23 #include <shill/net/ip_address.h>
24 #include <shill/net/rtnl_handler.h>
25 
26 #include "apmanager/file_writer.h"
27 #include "apmanager/process_factory.h"
28 
29 namespace apmanager {
30 
31 class DHCPServer {
32  public:
33   DHCPServer(uint16_t server_address_index,
34              const std::string& interface_name);
35   virtual ~DHCPServer();
36 
37   // Start the DHCP server
38   virtual bool Start();
39 
40  private:
41   friend class DHCPServerTest;
42 
43   std::string GenerateConfigFile();
44 
45   static const char kDnsmasqPath[];
46   static const char kDnsmasqConfigFilePathFormat[];
47   static const char kDHCPLeasesFilePathFormat[];
48   static const char kServerAddressFormat[];
49   static const char kAddressRangeLowFormat[];
50   static const char kAddressRangeHighFormat[];
51   static const int kServerAddressPrefix;
52   static const int kTerminationTimeoutSeconds;
53 #if defined(__ANDROID__)
54   static const char kDnsmasqPidFilePath[];
55 #endif  // __ANDROID__
56 
57   uint16_t server_address_index_;
58   std::string interface_name_;
59   shill::IPAddress server_address_;
60   std::unique_ptr<brillo::Process> dnsmasq_process_;
61   shill::RTNLHandler* rtnl_handler_;
62   FileWriter* file_writer_;
63   ProcessFactory* process_factory_;
64 
65   DISALLOW_COPY_AND_ASSIGN(DHCPServer);
66 };
67 
68 }  // namespace apmanager
69 
70 #endif  // APMANAGER_DHCP_SERVER_H_
71