• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 SHILL_DHCP_DHCPV6_CONFIG_H_
18 #define SHILL_DHCP_DHCPV6_CONFIG_H_
19 
20 #include <string>
21 #include <vector>
22 
23 #include <gtest/gtest_prod.h>  // for FRIEND_TEST
24 
25 #include "shill/dhcp/dhcp_config.h"
26 
27 namespace shill {
28 
29 // This class provides a DHCPv6 client instance for the device |device_name|.
30 //
31 // The DHCPv6Config instance asks the DHCPv6 client to request both ia_na
32 // (Non-temporary Addresss) and ia_pd (Prefix Delegation) options from the
33 // DHCPv6 server.
34 class DHCPv6Config : public DHCPConfig {
35  public:
36   DHCPv6Config(ControlInterface* control_interface,
37                EventDispatcher* dispatcher,
38                DHCPProvider* provider,
39                const std::string& device_name,
40                const std::string& lease_file_suffix);
41   ~DHCPv6Config() override;
42 
43   // Inherited from DHCPConfig.
44   void ProcessEventSignal(const std::string& reason,
45                           const KeyValueStore& configuration) override;
46   void ProcessStatusChangeSignal(const std::string& status) override;
47 
48  protected:
49   // Inherited from DHCPConfig.
50   void CleanupClientState() override;
51   std::vector<std::string> GetFlags() override;
52 
53  private:
54   friend class DHCPv6ConfigTest;
55   FRIEND_TEST(DHCPv6ConfigCallbackTest, ProcessEventSignalFail);
56   FRIEND_TEST(DHCPv6ConfigCallbackTest, ProcessEventSignalSuccess);
57   FRIEND_TEST(DHCPv6ConfigCallbackTest, ProcessEventSignalUnknown);
58   FRIEND_TEST(DHCPv6ConfigCallbackTest, StoppedDuringFailureCallback);
59   FRIEND_TEST(DHCPv6ConfigCallbackTest, StoppedDuringSuccessCallback);
60   FRIEND_TEST(DHCPv6ConfigTest, ParseConfiguration);
61 
62   static const char kDHCPCDPathFormatPID[];
63 
64   static const char kConfigurationKeyDelegatedPrefix[];
65   static const char kConfigurationKeyDelegatedPrefixLength[];
66   static const char kConfigurationKeyDelegatedPrefixLeaseTime[];
67   static const char kConfigurationKeyDNS[];
68   static const char kConfigurationKeyDomainSearch[];
69   static const char kConfigurationKeyIPAddress[];
70   static const char kConfigurationKeyIPAddressLeaseTime[];
71   static const char kConfigurationKeyServerIdentifier[];
72 
73   static const char kReasonBound[];
74   static const char kReasonFail[];
75   static const char kReasonRebind[];
76   static const char kReasonReboot[];
77   static const char kReasonRenew[];
78 
79   static const char kType[];
80 
81   // Parses |configuration| into |properties|. Returns true on success, and
82   // false otherwise.
83   bool ParseConfiguration(const KeyValueStore& configuration);
84 
85   void UpdateLeaseTime(uint32_t lease_time);
86 
87   // Non-temporary address and prefix delegation are considered separate
88   // requests with separate leases, which mean there will be a dedicated
89   // response/event for each. So maintain a configuration properties here to
90   // combine the two lease/configuration into one. The lease time of the combine
91   // configuration will be the shorter of the two leases (most likely the two
92   // lease time will be identical).
93   IPConfig::Properties properties_;
94 
95   DISALLOW_COPY_AND_ASSIGN(DHCPv6Config);
96 };
97 
98 }  // namespace shill
99 
100 #endif  // SHILL_DHCP_DHCPV6_CONFIG_H_
101