blob: 90a33c6532f618bbef745d043d18e6495da850cd [file] [log] [blame]
Peter Qiu326b6cf2015-09-02 11:11:42 -07001//
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 Qiubf8e36c2014-12-03 22:59:45 -080016
17#ifndef APMANAGER_DHCP_SERVER_H_
18#define APMANAGER_DHCP_SERVER_H_
19
20#include <string>
21
22#include <base/macros.h>
Peter Qiubf8e36c2014-12-03 22:59:45 -080023#include <shill/net/ip_address.h>
24#include <shill/net/rtnl_handler.h>
25
Peter Qiu77517302015-01-08 16:22:16 -080026#include "apmanager/file_writer.h"
Peter Qiu1dbf9fd2015-01-09 13:36:55 -080027#include "apmanager/process_factory.h"
Peter Qiu77517302015-01-08 16:22:16 -080028
Peter Qiubf8e36c2014-12-03 22:59:45 -080029namespace apmanager {
30
31class 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 Qiu784aa322015-09-29 09:48:03 -070053#if defined(__ANDROID__)
54 static const char kDnsmasqPidFilePath[];
55#endif // __ANDROID__
Peter Qiubf8e36c2014-12-03 22:59:45 -080056
57 uint16_t server_address_index_;
58 std::string interface_name_;
59 shill::IPAddress server_address_;
Alex Vakulenko8d0c31b2015-10-13 09:14:24 -070060 std::unique_ptr<brillo::Process> dnsmasq_process_;
Peter Qiubf8e36c2014-12-03 22:59:45 -080061 shill::RTNLHandler* rtnl_handler_;
Peter Qiu77517302015-01-08 16:22:16 -080062 FileWriter* file_writer_;
Peter Qiu1dbf9fd2015-01-09 13:36:55 -080063 ProcessFactory* process_factory_;
Peter Qiubf8e36c2014-12-03 22:59:45 -080064
65 DISALLOW_COPY_AND_ASSIGN(DHCPServer);
66};
67
68} // namespace apmanager
69
70#endif // APMANAGER_DHCP_SERVER_H_