Darin Petkov | e02b3ca | 2011-05-31 16:00:44 -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 | #include "shill/ipconfig.h" |
| 6 | |
| 7 | #include <base/logging.h> |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 8 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | e02b3ca | 2011-05-31 16:00:44 -0700 | [diff] [blame] | 9 | |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 10 | #include "shill/adaptor_interfaces.h" |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 11 | #include "shill/control_interface.h" |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 12 | #include "shill/error.h" |
Chris Masone | 8a7b8be | 2011-07-22 12:43:37 -0700 | [diff] [blame] | 13 | #include "shill/store_interface.h" |
Chris Masone | c6c6c13 | 2011-06-30 11:29:52 -0700 | [diff] [blame] | 14 | |
Darin Petkov | e02b3ca | 2011-05-31 16:00:44 -0700 | [diff] [blame] | 15 | using std::string; |
| 16 | |
| 17 | namespace shill { |
| 18 | |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 19 | // static |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 20 | const char IPConfig::kStorageType[] = "Method"; |
Chris Masone | 8a7b8be | 2011-07-22 12:43:37 -0700 | [diff] [blame] | 21 | // static |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 22 | const char IPConfig::kType[] = "ip"; |
| 23 | // static |
| 24 | uint IPConfig::global_serial_ = 0; |
| 25 | |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 26 | IPConfig::IPConfig(ControlInterface *control_interface, |
| 27 | const std::string &device_name) |
| 28 | : device_name_(device_name), |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 29 | type_(kType), |
| 30 | serial_(global_serial_++), |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 31 | adaptor_(control_interface->CreateIPConfigAdaptor(this)) { |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 32 | Init(); |
| 33 | } |
| 34 | |
| 35 | IPConfig::IPConfig(ControlInterface *control_interface, |
| 36 | const std::string &device_name, |
| 37 | const std::string &type) |
| 38 | : device_name_(device_name), |
| 39 | type_(type), |
| 40 | serial_(global_serial_++), |
| 41 | adaptor_(control_interface->CreateIPConfigAdaptor(this)) { |
| 42 | Init(); |
| 43 | } |
| 44 | |
| 45 | void IPConfig::Init() { |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 46 | // Address might be R/O or not, depending on the type of IPconfig, so |
| 47 | // we'll leave this up to the subclasses. |
| 48 | // Register(Const?)String(flimflam::kAddressProperty, &properties_.address); |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 49 | store_.RegisterString(flimflam::kBroadcastProperty, |
| 50 | &properties_.broadcast_address); |
| 51 | store_.RegisterString(flimflam::kDomainNameProperty, |
| 52 | &properties_.domain_name); |
| 53 | store_.RegisterString(flimflam::kGatewayProperty, &properties_.gateway); |
| 54 | store_.RegisterConstString(flimflam::kMethodProperty, &properties_.method); |
| 55 | store_.RegisterInt32(flimflam::kMtuProperty, &properties_.mtu); |
| 56 | store_.RegisterStrings(flimflam::kNameServersProperty, |
| 57 | &properties_.dns_servers); |
| 58 | store_.RegisterString(flimflam::kPeerAddressProperty, |
| 59 | &properties_.peer_address); |
| 60 | store_.RegisterInt32(flimflam::kPrefixlenProperty, &properties_.subnet_cidr); |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 61 | // TODO(cmasone): Does anyone use this? |
Chris Masone | 27c4aa5 | 2011-07-02 13:10:14 -0700 | [diff] [blame] | 62 | // store_.RegisterStrings(flimflam::kSearchDomainsProperty, |
| 63 | // &properties_.domain_search); |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 64 | VLOG(2) << __func__ << " device: " << device_name(); |
Darin Petkov | e02b3ca | 2011-05-31 16:00:44 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | IPConfig::~IPConfig() { |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 68 | VLOG(2) << __func__ << " device: " << device_name(); |
Darin Petkov | e02b3ca | 2011-05-31 16:00:44 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Chris Masone | 4e85161 | 2011-07-01 10:46:53 -0700 | [diff] [blame] | 71 | string IPConfig::GetRpcIdentifier() { |
| 72 | return adaptor_->GetRpcIdentifier(); |
| 73 | } |
| 74 | |
Chris Masone | 5dec5f4 | 2011-07-22 14:07:55 -0700 | [diff] [blame] | 75 | string IPConfig::GetStorageIdentifier() { |
| 76 | string id = GetRpcIdentifier(); |
| 77 | ControlInterface::RpcIdToStorageId(&id); |
| 78 | return id; |
| 79 | } |
| 80 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 81 | bool IPConfig::RequestIP() { |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 82 | return false; |
| 83 | } |
| 84 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 85 | bool IPConfig::RenewIP() { |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | bool IPConfig::ReleaseIP() { |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 90 | return false; |
| 91 | } |
| 92 | |
Chris Masone | 8a7b8be | 2011-07-22 12:43:37 -0700 | [diff] [blame] | 93 | bool IPConfig::Load(StoreInterface *storage) { |
| 94 | const string id = GetStorageIdentifier(); |
| 95 | if (!storage->ContainsGroup(id)) { |
| 96 | LOG(WARNING) << "IPConfig is not available in the persistent store: " << id; |
| 97 | return false; |
| 98 | } |
| 99 | string local_type; |
| 100 | storage->GetString(id, kStorageType, &local_type); |
| 101 | return local_type == type(); |
| 102 | } |
| 103 | |
| 104 | bool IPConfig::Save(StoreInterface *storage) { |
| 105 | const string id = GetStorageIdentifier(); |
| 106 | storage->SetString(id, kStorageType, type()); |
| 107 | return true; |
| 108 | } |
| 109 | |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 110 | void IPConfig::UpdateProperties(const Properties &properties, bool success) { |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 111 | properties_ = properties; |
Darin Petkov | efb09c3 | 2011-06-07 20:24:17 -0700 | [diff] [blame] | 112 | if (update_callback_.get()) { |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 113 | update_callback_->Run(this, success); |
Darin Petkov | efb09c3 | 2011-06-07 20:24:17 -0700 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
| 117 | void IPConfig::RegisterUpdateCallback( |
Chris Masone | 2b10554 | 2011-06-22 10:58:09 -0700 | [diff] [blame] | 118 | Callback2<const IPConfigRefPtr&, bool>::Type *callback) { |
Darin Petkov | efb09c3 | 2011-06-07 20:24:17 -0700 | [diff] [blame] | 119 | update_callback_.reset(callback); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Darin Petkov | e02b3ca | 2011-05-31 16:00:44 -0700 | [diff] [blame] | 122 | } // namespace shill |