Ningyuan Wang | b52786a | 2015-12-10 14:25:15 -0800 | [diff] [blame] | 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 | #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 Wang | 288ccd0 | 2015-12-16 16:24:43 -0800 | [diff] [blame^] | 27 | #include "shill/net/io_handler_factory_container.h" |
| 28 | #include "shill/net/sockets.h" |
Ningyuan Wang | b52786a | 2015-12-10 14:25:15 -0800 | [diff] [blame] | 29 | |
| 30 | namespace dhcp_client { |
| 31 | |
| 32 | class 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 Wang | 288ccd0 | 2015-12-16 16:24:43 -0800 | [diff] [blame^] | 45 | bool Start(); |
Ningyuan Wang | b52786a | 2015-12-10 14:25:15 -0800 | [diff] [blame] | 46 | 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 Wang | 288ccd0 | 2015-12-16 16:24:43 -0800 | [diff] [blame^] | 67 | shill::IOHandlerFactory *io_handler_factory_; |
| 68 | std::unique_ptr<shill::IOHandler> input_handler_; |
Ningyuan Wang | b52786a | 2015-12-10 14:25:15 -0800 | [diff] [blame] | 69 | |
| 70 | // DHCP state variables |
| 71 | State state_; |
| 72 | |
Ningyuan Wang | 288ccd0 | 2015-12-16 16:24:43 -0800 | [diff] [blame^] | 73 | // 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 Wang | b52786a | 2015-12-10 14:25:15 -0800 | [diff] [blame] | 82 | DISALLOW_COPY_AND_ASSIGN(DHCPV4); |
| 83 | }; |
| 84 | |
| 85 | } // namespace dhcp_client |
| 86 | |
| 87 | #endif // DHCP_CLIENT_DHCPV4_H_ |