Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 5 | #include "patchpanel/shill_client.h" |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 6 | |
Jie Jiang | 850a471 | 2020-04-08 21:06:36 +0900 | [diff] [blame^] | 7 | #include <utility> |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 10 | #include <base/bind.h> |
| 11 | #include <base/logging.h> |
Garrick Evans | e87bb4f | 2020-02-18 10:27:37 +0900 | [diff] [blame] | 12 | #include <base/strings/string_util.h> |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 13 | #include <chromeos/dbus/service_constants.h> |
| 14 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 15 | namespace patchpanel { |
Hugo Benichi | d17aa59 | 2019-04-26 15:15:01 +0900 | [diff] [blame] | 16 | |
Garrick Evans | 0884393 | 2019-09-17 14:41:08 +0900 | [diff] [blame] | 17 | ShillClient::ShillClient(const scoped_refptr<dbus::Bus>& bus) : bus_(bus) { |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 18 | manager_proxy_.reset(new org::chromium::flimflam::ManagerProxy(bus_)); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 19 | manager_proxy_->RegisterPropertyChangedSignalHandler( |
| 20 | base::Bind(&ShillClient::OnManagerPropertyChange, |
| 21 | weak_factory_.GetWeakPtr()), |
| 22 | base::Bind(&ShillClient::OnManagerPropertyChangeRegistration, |
| 23 | weak_factory_.GetWeakPtr())); |
| 24 | } |
| 25 | |
Garrick Evans | 1b1f67c | 2020-02-04 16:21:25 +0900 | [diff] [blame] | 26 | const std::string& ShillClient::default_interface() const { |
| 27 | return default_interface_; |
| 28 | } |
| 29 | |
Hugo Benichi | cc6850f | 2020-01-17 13:26:06 +0900 | [diff] [blame] | 30 | const std::set<std::string> ShillClient::get_devices() const { |
| 31 | return devices_; |
| 32 | } |
| 33 | |
| 34 | bool ShillClient::has_device(const std::string& ifname) const { |
| 35 | return devices_.find(ifname) != devices_.end(); |
| 36 | } |
| 37 | |
Jie Jiang | 84c76a1 | 2020-04-17 16:45:20 +0900 | [diff] [blame] | 38 | void ShillClient::ScanDevices() { |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 39 | brillo::VariantDictionary props; |
| 40 | if (!manager_proxy_->GetProperties(&props, nullptr)) { |
| 41 | LOG(ERROR) << "Unable to get manager properties"; |
| 42 | return; |
| 43 | } |
| 44 | const auto it = props.find(shill::kDevicesProperty); |
| 45 | if (it == props.end()) { |
| 46 | LOG(WARNING) << "Manager properties is missing devices"; |
| 47 | return; |
| 48 | } |
Garrick Evans | 139708f | 2020-02-06 14:38:59 +0900 | [diff] [blame] | 49 | UpdateDevices(it->second); |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 50 | } |
| 51 | |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 52 | std::string ShillClient::GetDefaultInterface() { |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 53 | brillo::VariantDictionary manager_props; |
| 54 | |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 55 | if (!manager_proxy_->GetProperties(&manager_props, nullptr)) { |
| 56 | LOG(ERROR) << "Unable to get manager properties"; |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 57 | return ""; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | auto it = manager_props.find(shill::kDefaultServiceProperty); |
| 61 | if (it == manager_props.end()) { |
| 62 | LOG(WARNING) << "Manager properties is missing default service"; |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 63 | return ""; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | dbus::ObjectPath service_path = it->second.TryGet<dbus::ObjectPath>(); |
| 67 | if (!service_path.IsValid() || service_path.value() == "/") { |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 68 | return ""; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | org::chromium::flimflam::ServiceProxy service_proxy(bus_, service_path); |
| 72 | brillo::VariantDictionary service_props; |
| 73 | if (!service_proxy.GetProperties(&service_props, nullptr)) { |
| 74 | LOG(ERROR) << "Can't retrieve properties for service"; |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 75 | return ""; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Alex Khouderchah | 05a8b5b | 2019-11-20 12:18:51 -0800 | [diff] [blame] | 78 | it = service_props.find(shill::kIsConnectedProperty); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 79 | if (it == service_props.end()) { |
Alex Khouderchah | 05a8b5b | 2019-11-20 12:18:51 -0800 | [diff] [blame] | 80 | LOG(WARNING) << "Service properties is missing \"IsConnected\""; |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 81 | return ""; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 82 | } |
Alex Khouderchah | 05a8b5b | 2019-11-20 12:18:51 -0800 | [diff] [blame] | 83 | if (!it->second.TryGet<bool>()) { |
| 84 | LOG(INFO) << "Ignoring non-connected service"; |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 85 | return ""; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | it = service_props.find(shill::kDeviceProperty); |
| 89 | if (it == service_props.end()) { |
| 90 | LOG(WARNING) << "Service properties is missing device path"; |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 91 | return ""; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | dbus::ObjectPath device_path = it->second.TryGet<dbus::ObjectPath>(); |
| 95 | if (!device_path.IsValid()) { |
| 96 | LOG(WARNING) << "Invalid device path"; |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 97 | return ""; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | org::chromium::flimflam::DeviceProxy device_proxy(bus_, device_path); |
| 101 | brillo::VariantDictionary device_props; |
| 102 | if (!device_proxy.GetProperties(&device_props, nullptr)) { |
| 103 | LOG(ERROR) << "Can't retrieve properties for device"; |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 104 | return ""; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | it = device_props.find(shill::kInterfaceProperty); |
| 108 | if (it == device_props.end()) { |
| 109 | LOG(WARNING) << "Device properties is missing interface name"; |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 110 | return ""; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | std::string interface = it->second.TryGet<std::string>(); |
| 114 | if (interface.empty()) { |
| 115 | LOG(WARNING) << "Device interface name is empty"; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 118 | return interface; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | void ShillClient::OnManagerPropertyChangeRegistration( |
| 122 | const std::string& interface, |
| 123 | const std::string& signal_name, |
| 124 | bool success) { |
| 125 | if (!success) |
| 126 | LOG(FATAL) << "Unable to register for interface change events"; |
| 127 | } |
| 128 | |
| 129 | void ShillClient::OnManagerPropertyChange(const std::string& property_name, |
| 130 | const brillo::Any& property_value) { |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 131 | if (property_name == shill::kDevicesProperty) { |
Garrick Evans | 139708f | 2020-02-06 14:38:59 +0900 | [diff] [blame] | 132 | UpdateDevices(property_value); |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 133 | |
| 134 | // Choose a fallback interface when any network device exist. Update the |
| 135 | // fallback interface if it that device does not exist anymore. |
Garrick Evans | d474283 | 2019-05-20 11:51:40 +0900 | [diff] [blame] | 136 | if (!devices_.empty() && |
| 137 | devices_.find(fallback_default_interface_) == devices_.end()) { |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 138 | fallback_default_interface_ = *devices_.begin(); |
| 139 | // When the system appears to have no default interface, use the fallback |
| 140 | // interface instead. |
Garrick Evans | d474283 | 2019-05-20 11:51:40 +0900 | [diff] [blame] | 141 | if (default_interface_.empty() || |
| 142 | default_interface_ != fallback_default_interface_) |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 143 | SetDefaultInterface(fallback_default_interface_); |
| 144 | } |
| 145 | |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 146 | // Remove the fallback interface when no network device is managed by shill. |
| 147 | if (!fallback_default_interface_.empty() && devices_.empty()) { |
| 148 | fallback_default_interface_ = ""; |
| 149 | SetDefaultInterface(""); |
| 150 | } |
| 151 | |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 152 | return; |
| 153 | } |
| 154 | |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 155 | if (property_name != shill::kDefaultServiceProperty && |
| 156 | property_name != shill::kConnectionStateProperty) |
| 157 | return; |
| 158 | |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 159 | SetDefaultInterface(GetDefaultInterface()); |
| 160 | } |
| 161 | |
Garrick Evans | 1b1f67c | 2020-02-04 16:21:25 +0900 | [diff] [blame] | 162 | std::string ShillClient::SetDefaultInterface(std::string new_default) { |
Hugo Benichi | ddee281 | 2019-05-10 16:03:43 +0900 | [diff] [blame] | 163 | // When the system default is lost, use the fallback interface instead. |
| 164 | if (new_default.empty()) |
| 165 | new_default = fallback_default_interface_; |
| 166 | |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 167 | if (default_interface_ == new_default) |
Garrick Evans | 1b1f67c | 2020-02-04 16:21:25 +0900 | [diff] [blame] | 168 | return default_interface_; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 169 | |
Garrick Evans | 139708f | 2020-02-06 14:38:59 +0900 | [diff] [blame] | 170 | LOG(INFO) << "Default interface changed from [" << default_interface_ |
| 171 | << "] to [" << new_default << "]"; |
| 172 | |
Garrick Evans | 1b1f67c | 2020-02-04 16:21:25 +0900 | [diff] [blame] | 173 | const std::string prev_default = default_interface_; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 174 | default_interface_ = new_default; |
Garrick Evans | 139708f | 2020-02-06 14:38:59 +0900 | [diff] [blame] | 175 | for (const auto& h : default_interface_handlers_) { |
| 176 | if (!h.is_null()) |
| 177 | h.Run(default_interface_, prev_default); |
Garrick Evans | c7fea0a | 2020-02-04 10:46:42 +0900 | [diff] [blame] | 178 | } |
Garrick Evans | 1b1f67c | 2020-02-04 16:21:25 +0900 | [diff] [blame] | 179 | return prev_default; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | void ShillClient::RegisterDefaultInterfaceChangedHandler( |
Garrick Evans | 139708f | 2020-02-06 14:38:59 +0900 | [diff] [blame] | 183 | const DefaultInterfaceChangeHandler& handler) { |
| 184 | default_interface_handlers_.emplace_back(handler); |
Garrick Evans | 1b1f67c | 2020-02-04 16:21:25 +0900 | [diff] [blame] | 185 | const auto prev_default = SetDefaultInterface(GetDefaultInterface()); |
Garrick Evans | 139708f | 2020-02-06 14:38:59 +0900 | [diff] [blame] | 186 | handler.Run(default_interface_, prev_default); |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | void ShillClient::RegisterDevicesChangedHandler( |
Garrick Evans | 139708f | 2020-02-06 14:38:59 +0900 | [diff] [blame] | 190 | const DevicesChangeHandler& handler) { |
| 191 | device_handlers_.emplace_back(handler); |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 192 | } |
| 193 | |
Jie Jiang | 850a471 | 2020-04-08 21:06:36 +0900 | [diff] [blame^] | 194 | void ShillClient::RegisterIPConfigsChangedHandler( |
| 195 | const IPConfigsChangeHandler& handler) { |
| 196 | ipconfigs_handlers_.emplace_back(handler); |
| 197 | } |
| 198 | |
Garrick Evans | 139708f | 2020-02-06 14:38:59 +0900 | [diff] [blame] | 199 | void ShillClient::UpdateDevices(const brillo::Any& property_value) { |
| 200 | std::set<std::string> new_devices, added, removed; |
| 201 | for (const auto& path : |
| 202 | property_value.TryGet<std::vector<dbus::ObjectPath>>()) { |
| 203 | std::string device = path.value(); |
| 204 | // Strip "/device/" prefix. |
| 205 | device = device.substr(device.find_last_of('/') + 1); |
Garrick Evans | e87bb4f | 2020-02-18 10:27:37 +0900 | [diff] [blame] | 206 | |
Garrick Evans | 139708f | 2020-02-06 14:38:59 +0900 | [diff] [blame] | 207 | new_devices.emplace(device); |
| 208 | if (devices_.find(device) == devices_.end()) |
| 209 | added.insert(device); |
Jie Jiang | 850a471 | 2020-04-08 21:06:36 +0900 | [diff] [blame^] | 210 | |
| 211 | // Registers handler if we see this device for the first time. |
| 212 | if (known_device_paths_.insert(std::make_pair(device, path)).second) { |
| 213 | org::chromium::flimflam::DeviceProxy proxy(bus_, path); |
| 214 | proxy.RegisterPropertyChangedSignalHandler( |
| 215 | base::Bind(&ShillClient::OnDevicePropertyChange, |
| 216 | weak_factory_.GetWeakPtr(), device), |
| 217 | base::Bind(&ShillClient::OnDevicePropertyChangeRegistration, |
| 218 | weak_factory_.GetWeakPtr())); |
| 219 | } |
Garrick Evans | 139708f | 2020-02-06 14:38:59 +0900 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | for (const auto& d : devices_) { |
| 223 | if (new_devices.find(d) == new_devices.end()) |
| 224 | removed.insert(d); |
| 225 | } |
| 226 | |
| 227 | devices_ = new_devices; |
| 228 | |
| 229 | for (const auto& h : device_handlers_) |
| 230 | h.Run(added, removed); |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 231 | } |
| 232 | |
Jie Jiang | 850a471 | 2020-04-08 21:06:36 +0900 | [diff] [blame^] | 233 | ShillClient::IPConfig ShillClient::ParseIPConfigsProperty( |
| 234 | const std::string& device, const brillo::Any& property_value) { |
| 235 | IPConfig ipconfig; |
| 236 | for (const auto& path : |
| 237 | property_value.TryGet<std::vector<dbus::ObjectPath>>()) { |
| 238 | std::unique_ptr<org::chromium::flimflam::IPConfigProxy> ipconfig_proxy( |
| 239 | new org::chromium::flimflam::IPConfigProxy(bus_, path)); |
| 240 | brillo::VariantDictionary ipconfig_props; |
| 241 | |
| 242 | if (!ipconfig_proxy->GetProperties(&ipconfig_props, nullptr)) { |
| 243 | // It is possible that an IPConfig object is removed after we know its |
| 244 | // path, especially when the interface is going down. |
| 245 | LOG(WARNING) << "[" << device << "]: " |
| 246 | << "Unable to get properties for " << path.value(); |
| 247 | continue; |
| 248 | } |
| 249 | |
| 250 | // Detects the type of IPConfig. For ipv4 and ipv6 configurations, there |
| 251 | // should be at most one for each type. |
| 252 | auto it = ipconfig_props.find(shill::kMethodProperty); |
| 253 | if (it == ipconfig_props.end()) { |
| 254 | LOG(WARNING) << "[" << device << "]: " |
| 255 | << "IPConfig properties is missing Method"; |
| 256 | continue; |
| 257 | } |
| 258 | const std::string& method = it->second.TryGet<std::string>(); |
| 259 | const bool is_ipv4_type = |
| 260 | (method == shill::kTypeIPv4 || method == shill::kTypeDHCP || |
| 261 | method == shill::kTypeBOOTP || method == shill::kTypeZeroConf); |
| 262 | const bool is_ipv6_type = (method == shill::kTypeIPv6); |
| 263 | if (!is_ipv4_type && !is_ipv6_type) { |
| 264 | LOG(WARNING) << "[" << device << "]: " |
| 265 | << "unknown type \"" << method << "\" for " << path.value(); |
| 266 | continue; |
| 267 | } |
| 268 | if ((is_ipv4_type && !ipconfig.ipv4_address.empty()) || |
| 269 | (is_ipv6_type && !ipconfig.ipv6_address.empty())) { |
| 270 | LOG(WARNING) << "[" << device << "]: " |
| 271 | << "Duplicated ipconfig for " << method; |
| 272 | continue; |
| 273 | } |
| 274 | |
| 275 | // Gets the value of address, prefix_length, gateway, and dns_servers. |
| 276 | it = ipconfig_props.find(shill::kAddressProperty); |
| 277 | if (it == ipconfig_props.end()) { |
| 278 | LOG(WARNING) << "[" << device << "]: " |
| 279 | << "IPConfig properties is missing Address"; |
| 280 | continue; |
| 281 | } |
| 282 | const std::string& address = it->second.TryGet<std::string>(); |
| 283 | |
| 284 | it = ipconfig_props.find(shill::kPrefixlenProperty); |
| 285 | if (it == ipconfig_props.end()) { |
| 286 | LOG(WARNING) << "[" << device << "]: " |
| 287 | << "IPConfig properties is missing Prefixlen"; |
| 288 | continue; |
| 289 | } |
| 290 | int prefix_length = it->second.TryGet<int>(); |
| 291 | |
| 292 | it = ipconfig_props.find(shill::kGatewayProperty); |
| 293 | if (it == ipconfig_props.end()) { |
| 294 | LOG(WARNING) << "[" << device << "]: " |
| 295 | << "IPConfig properties is missing Gateway"; |
| 296 | continue; |
| 297 | } |
| 298 | const std::string& gateway = it->second.TryGet<std::string>(); |
| 299 | |
| 300 | it = ipconfig_props.find(shill::kNameServersProperty); |
| 301 | if (it == ipconfig_props.end()) { |
| 302 | LOG(WARNING) << "[" << device << "]: " |
| 303 | << "IPConfig properties is missing NameServers"; |
| 304 | // Shill will emit this property with empty value if it has no dns for |
| 305 | // this device, so missing this property indicates an error. |
| 306 | continue; |
| 307 | } |
| 308 | const std::vector<std::string>& dns_addresses = |
| 309 | it->second.TryGet<std::vector<std::string>>(); |
| 310 | |
| 311 | // Checks if this ipconfig is valid: address, gateway, and prefix_length |
| 312 | // should not be empty. |
| 313 | if (address.empty() || gateway.empty() || prefix_length == 0) { |
| 314 | LOG(WARNING) << "[" << device << "]: " |
| 315 | << "Skipped invalid ipconfig: " |
| 316 | << "address.length()=" << address.length() |
| 317 | << ", gateway.length()=" << gateway.length() |
| 318 | << ", prefix_length=" << prefix_length; |
| 319 | continue; |
| 320 | } |
| 321 | |
| 322 | // Fills the IPConfig struct according to the type. |
| 323 | if (is_ipv4_type) { |
| 324 | ipconfig.ipv4_prefix_length = prefix_length; |
| 325 | ipconfig.ipv4_address = address; |
| 326 | ipconfig.ipv4_gateway = gateway; |
| 327 | ipconfig.ipv4_dns_addresses = dns_addresses; |
| 328 | } else { // is_ipv6_type |
| 329 | ipconfig.ipv6_prefix_length = prefix_length; |
| 330 | ipconfig.ipv6_address = address; |
| 331 | ipconfig.ipv6_gateway = gateway; |
| 332 | ipconfig.ipv6_dns_addresses = dns_addresses; |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | return ipconfig; |
| 337 | } |
| 338 | |
| 339 | void ShillClient::OnDevicePropertyChangeRegistration( |
| 340 | const std::string& interface, |
| 341 | const std::string& signal_name, |
| 342 | bool success) { |
| 343 | if (!success) |
| 344 | LOG(ERROR) << "[" << interface << "]: " |
| 345 | << "Unable to register listener for " << signal_name; |
| 346 | } |
| 347 | |
| 348 | void ShillClient::OnDevicePropertyChange(const std::string& device, |
| 349 | const std::string& property_name, |
| 350 | const brillo::Any& property_value) { |
| 351 | if (property_name != shill::kIPConfigsProperty) |
| 352 | return; |
| 353 | |
| 354 | const IPConfig& ipconfig = ParseIPConfigsProperty(device, property_value); |
| 355 | // TODO(jiejiang): Keep a cache of the last parsed IPConfig, and only |
| 356 | // trigger handlers if there is an actual change. |
| 357 | for (const auto& handler : ipconfigs_handlers_) |
| 358 | handler.Run(device, ipconfig); |
| 359 | } |
| 360 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 361 | } // namespace patchpanel |