Peter Qiu | 326b6cf | 2015-09-02 11:11:42 -0700 | [diff] [blame] | 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 | // |
Peter Qiu | bf8e36c | 2014-12-03 22:59:45 -0800 | [diff] [blame] | 16 | |
| 17 | #ifndef APMANAGER_DHCP_SERVER_H_ |
| 18 | #define APMANAGER_DHCP_SERVER_H_ |
| 19 | |
| 20 | #include <string> |
| 21 | |
| 22 | #include <base/macros.h> |
Peter Qiu | bf8e36c | 2014-12-03 22:59:45 -0800 | [diff] [blame] | 23 | #include <shill/net/ip_address.h> |
| 24 | #include <shill/net/rtnl_handler.h> |
| 25 | |
Peter Qiu | 7751730 | 2015-01-08 16:22:16 -0800 | [diff] [blame] | 26 | #include "apmanager/file_writer.h" |
Peter Qiu | 1dbf9fd | 2015-01-09 13:36:55 -0800 | [diff] [blame] | 27 | #include "apmanager/process_factory.h" |
Peter Qiu | 7751730 | 2015-01-08 16:22:16 -0800 | [diff] [blame] | 28 | |
Peter Qiu | bf8e36c | 2014-12-03 22:59:45 -0800 | [diff] [blame] | 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; |
Peter Qiu | 784aa32 | 2015-09-29 09:48:03 -0700 | [diff] [blame] | 53 | #if defined(__ANDROID__) |
| 54 | static const char kDnsmasqPidFilePath[]; |
| 55 | #endif // __ANDROID__ |
Peter Qiu | bf8e36c | 2014-12-03 22:59:45 -0800 | [diff] [blame] | 56 | |
| 57 | uint16_t server_address_index_; |
| 58 | std::string interface_name_; |
| 59 | shill::IPAddress server_address_; |
Alex Vakulenko | 8d0c31b | 2015-10-13 09:14:24 -0700 | [diff] [blame] | 60 | std::unique_ptr<brillo::Process> dnsmasq_process_; |
Peter Qiu | bf8e36c | 2014-12-03 22:59:45 -0800 | [diff] [blame] | 61 | shill::RTNLHandler* rtnl_handler_; |
Peter Qiu | 7751730 | 2015-01-08 16:22:16 -0800 | [diff] [blame] | 62 | FileWriter* file_writer_; |
Peter Qiu | 1dbf9fd | 2015-01-09 13:36:55 -0800 | [diff] [blame] | 63 | ProcessFactory* process_factory_; |
Peter Qiu | bf8e36c | 2014-12-03 22:59:45 -0800 | [diff] [blame] | 64 | |
| 65 | DISALLOW_COPY_AND_ASSIGN(DHCPServer); |
| 66 | }; |
| 67 | |
| 68 | } // namespace apmanager |
| 69 | |
| 70 | #endif // APMANAGER_DHCP_SERVER_H_ |