Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_DHCP_CONFIG_ |
| 6 | #define SHILL_DHCP_CONFIG_ |
| 7 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 8 | #include <base/memory/scoped_ptr.h> |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 9 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 10 | #include <dbus-c++/connection.h> |
| 11 | |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 12 | #include "shill/device.h" |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 13 | #include "shill/ipconfig.h" |
| 14 | |
| 15 | namespace shill { |
| 16 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 17 | class DHCPConfig; |
| 18 | class DHCPProvider; |
| 19 | class DHCPProxyInterface; |
| 20 | |
| 21 | typedef scoped_refptr<DHCPConfig> DHCPConfigRefPtr; |
| 22 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 23 | class DHCPConfig : public IPConfig { |
| 24 | public: |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 25 | typedef std::map<std::string, DBus::Variant> Configuration; |
| 26 | |
| 27 | static const char kConfigurationKeyBroadcastAddress[]; |
| 28 | static const char kConfigurationKeyDNS[]; |
| 29 | static const char kConfigurationKeyDomainName[]; |
| 30 | static const char kConfigurationKeyDomainSearch[]; |
| 31 | static const char kConfigurationKeyIPAddress[]; |
| 32 | static const char kConfigurationKeyMTU[]; |
| 33 | static const char kConfigurationKeyRouters[]; |
| 34 | static const char kConfigurationKeySubnetCIDR[]; |
| 35 | |
Chris Masone | c1e5041 | 2011-06-07 13:04:53 -0700 | [diff] [blame] | 36 | DHCPConfig(DHCPProvider *provider, DeviceConstRefPtr device); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 37 | virtual ~DHCPConfig(); |
| 38 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 39 | // Inherited from IPConfig. |
| 40 | virtual bool Request(); |
| 41 | virtual bool Renew(); |
| 42 | |
| 43 | // If |proxy_| is not initialized already, sets it to a new D-Bus proxy to |
| 44 | // |service|. |
| 45 | void InitProxy(DBus::Connection *connection, const char *service); |
| 46 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 47 | // Processes an Event signal from dhcpcd. |
| 48 | void ProcessEventSignal(const std::string &reason, |
| 49 | const Configuration &configuration); |
| 50 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 51 | private: |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 52 | FRIEND_TEST(DHCPConfigTest, GetIPv4AddressString); |
| 53 | FRIEND_TEST(DHCPConfigTest, ParseConfiguration); |
| 54 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 55 | static const char kDHCPCDPath[]; |
| 56 | |
| 57 | // Starts dhcpcd, returns true on success and false otherwise. |
| 58 | bool Start(); |
| 59 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 60 | // Parses |configuration| into |properties|. Returns true on success, and |
| 61 | // false otherwise. |
| 62 | bool ParseConfiguration(const Configuration& configuration, |
| 63 | IPConfig::Properties *properties); |
| 64 | |
| 65 | // Returns the string representation of the IP address |address|, or an |
| 66 | // empty string on failure. |
| 67 | std::string GetIPv4AddressString(unsigned int address); |
| 68 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 69 | DHCPProvider *provider_; |
| 70 | |
| 71 | // The PID of the spawned DHCP client. May be 0 if no client has been spawned |
| 72 | // yet or the client has died. |
| 73 | unsigned int pid_; |
| 74 | |
| 75 | // The proxy for communicating with the DHCP client. |
| 76 | scoped_ptr<DHCPProxyInterface> proxy_; |
| 77 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 78 | DISALLOW_COPY_AND_ASSIGN(DHCPConfig); |
| 79 | }; |
| 80 | |
| 81 | } // namespace shill |
| 82 | |
| 83 | #endif // SHILL_DHCP_CONFIG_ |