blob: 9719129962f51cccd96ad64d5fc5931e4ea26f22 [file] [log] [blame]
Ningyuan Wangb52786a2015-12-10 14:25:15 -08001//
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 DHCP_CLIENT_DHCPV4_H_
18#define DHCP_CLIENT_DHCPV4_H_
19
20#include <string>
21
22#include <base/macros.h>
23#include <base/strings/stringprintf.h>
24
25#include "dhcp_client/dhcp.h"
26#include "dhcp_client/event_dispatcher_interface.h"
Ningyuan Wang288ccd02015-12-16 16:24:43 -080027#include "shill/net/io_handler_factory_container.h"
28#include "shill/net/sockets.h"
Ningyuan Wangb52786a2015-12-10 14:25:15 -080029
30namespace dhcp_client {
31
32class DHCPV4 : public DHCP {
33 public:
34 DHCPV4(const std::string& interface_name,
35 const std::string& hardware_address,
36 unsigned int interface_index,
37 const std::string& network_id,
38 bool request_hostname,
39 bool arp_gateway,
40 bool unicast_arp,
41 EventDispatcherInterface* event_dispatcher);
42
43 virtual ~DHCPV4();
44
Ningyuan Wang288ccd02015-12-16 16:24:43 -080045 bool Start();
Ningyuan Wangb52786a2015-12-10 14:25:15 -080046 void Stop();
47
48 private:
49 // Interface parameters.
50 std::string interface_name_;
51 std::string hardware_address_;
52 unsigned int interface_index_;
53
54 // Unique network/connection identifier,
55 // lease will persist to storage if this identifier is specified.
56 std::string network_id_;
57
58 // DHCP IPv4 configurations:
59 // Request hostname from server.
60 bool request_hostname_;
61 // ARP for default gateway.
62 bool arp_gateway_;
63 // Enable unicast ARP on renew.
64 bool unicast_arp_;
65
66 EventDispatcherInterface* event_dispatcher_;
Ningyuan Wang288ccd02015-12-16 16:24:43 -080067 shill::IOHandlerFactory *io_handler_factory_;
68 std::unique_ptr<shill::IOHandler> input_handler_;
Ningyuan Wangb52786a2015-12-10 14:25:15 -080069
70 // DHCP state variables
71 State state_;
72
Ningyuan Wang288ccd02015-12-16 16:24:43 -080073 // Socket used for sending and receiving DHCP messages.
74 int socket_;
75 // Helper class with wrapped socket relavent functions.
76 std::unique_ptr<shill::Sockets> sockets_;
77
78 bool CreateRawSocket();
79 void ParseMessage(shill::InputData* data);
80 void OnReadError(const std::string& error_msg);
81
Ningyuan Wangb52786a2015-12-10 14:25:15 -080082 DISALLOW_COPY_AND_ASSIGN(DHCPV4);
83};
84
85} // namespace dhcp_client
86
87#endif // DHCP_CLIENT_DHCPV4_H_