Thieu Le | 94eed56 | 2012-02-21 15:57:29 -0800 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 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/dhcp_config.h" |
| 6 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 7 | #include <arpa/inet.h> |
Thieu Le | 94eed56 | 2012-02-21 15:57:29 -0800 | [diff] [blame^] | 8 | #include <sys/wait.h> |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 9 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 10 | #include <base/file_util.h> |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 11 | #include <base/logging.h> |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 12 | #include <base/stringprintf.h> |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 13 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 14 | |
| 15 | #include "shill/dhcpcd_proxy.h" |
| 16 | #include "shill/dhcp_provider.h" |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 17 | #include "shill/event_dispatcher.h" |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 18 | #include "shill/glib.h" |
Paul Stewart | 1d18e8c | 2011-07-15 11:00:31 -0700 | [diff] [blame] | 19 | #include "shill/ip_address.h" |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 20 | #include "shill/proxy_factory.h" |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 21 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 22 | using std::string; |
| 23 | using std::vector; |
| 24 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 25 | namespace shill { |
| 26 | |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 27 | // static |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 28 | const char DHCPConfig::kConfigurationKeyBroadcastAddress[] = "BroadcastAddress"; |
| 29 | const char DHCPConfig::kConfigurationKeyDNS[] = "DomainNameServers"; |
| 30 | const char DHCPConfig::kConfigurationKeyDomainName[] = "DomainName"; |
| 31 | const char DHCPConfig::kConfigurationKeyDomainSearch[] = "DomainSearch"; |
| 32 | const char DHCPConfig::kConfigurationKeyIPAddress[] = "IPAddress"; |
| 33 | const char DHCPConfig::kConfigurationKeyMTU[] = "InterfaceMTU"; |
| 34 | const char DHCPConfig::kConfigurationKeyRouters[] = "Routers"; |
| 35 | const char DHCPConfig::kConfigurationKeySubnetCIDR[] = "SubnetCIDR"; |
Thieu Le | 94eed56 | 2012-02-21 15:57:29 -0800 | [diff] [blame^] | 36 | const int DHCPConfig::kDHCPCDExitPollMilliseconds = 50; |
| 37 | const int DHCPConfig::kDHCPCDExitWaitMilliseconds = 3000; |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 38 | const char DHCPConfig::kDHCPCDPath[] = "/sbin/dhcpcd"; |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 39 | const char DHCPConfig::kDHCPCDPathFormatLease[] = "var/run/dhcpcd-%s.lease"; |
| 40 | const char DHCPConfig::kDHCPCDPathFormatPID[] = "var/run/dhcpcd-%s.pid"; |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 41 | const char DHCPConfig::kReasonBound[] = "BOUND"; |
| 42 | const char DHCPConfig::kReasonFail[] = "FAIL"; |
| 43 | const char DHCPConfig::kReasonRebind[] = "REBIND"; |
| 44 | const char DHCPConfig::kReasonReboot[] = "REBOOT"; |
| 45 | const char DHCPConfig::kReasonRenew[] = "RENEW"; |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 46 | // static |
| 47 | const char DHCPConfig::kType[] = "dhcp"; |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 48 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 49 | |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 50 | DHCPConfig::DHCPConfig(ControlInterface *control_interface, |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 51 | EventDispatcher *dispatcher, |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 52 | DHCPProvider *provider, |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 53 | const string &device_name, |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 54 | const string &request_hostname, |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 55 | GLib *glib) |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 56 | : IPConfig(control_interface, device_name, kType), |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 57 | proxy_factory_(ProxyFactory::GetInstance()), |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 58 | provider_(provider), |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 59 | request_hostname_(request_hostname), |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 60 | pid_(0), |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 61 | child_watch_tag_(0), |
| 62 | root_("/"), |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 63 | task_factory_(this), |
| 64 | dispatcher_(dispatcher), |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 65 | glib_(glib) { |
mukesh agrawal | de29fa8 | 2011-09-16 16:16:36 -0700 | [diff] [blame] | 66 | mutable_store()->RegisterConstString(flimflam::kAddressProperty, |
| 67 | &(properties().address)); |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 68 | VLOG(2) << __func__ << ": " << device_name; |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | DHCPConfig::~DHCPConfig() { |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 72 | VLOG(2) << __func__ << ": " << device_name(); |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 73 | |
| 74 | // Don't leave behind dhcpcd running. |
| 75 | Stop(); |
| 76 | |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 77 | // Make sure we don't get any callbacks to the destroyed instance. |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 78 | CleanupClientState(); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 81 | bool DHCPConfig::RequestIP() { |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 82 | VLOG(2) << __func__ << ": " << device_name(); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 83 | if (!pid_) { |
| 84 | return Start(); |
| 85 | } |
| 86 | if (!proxy_.get()) { |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 87 | LOG(ERROR) << "Unable to request IP before acquiring destination."; |
| 88 | return Restart(); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 89 | } |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 90 | return RenewIP(); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 93 | bool DHCPConfig::RenewIP() { |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 94 | VLOG(2) << __func__ << ": " << device_name(); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 95 | if (!pid_) { |
| 96 | return false; |
| 97 | } |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 98 | proxy_->Rebind(device_name()); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 99 | return true; |
| 100 | } |
| 101 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 102 | bool DHCPConfig::ReleaseIP() { |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 103 | VLOG(2) << __func__ << ": " << device_name(); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 104 | if (!pid_) { |
| 105 | return true; |
| 106 | } |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 107 | if (proxy_.get()) { |
| 108 | proxy_->Release(device_name()); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 109 | } |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 110 | Stop(); |
| 111 | return true; |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 114 | void DHCPConfig::InitProxy(const string &service) { |
| 115 | // Defer proxy creation because dbus-c++ doesn't allow registration of new |
| 116 | // D-Bus objects in the context of a D-Bus signal handler. |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 117 | if (!proxy_.get()) { |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 118 | dispatcher_->PostTask( |
| 119 | task_factory_.NewRunnableMethod(&DHCPConfig::InitProxyTask, service)); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | void DHCPConfig::InitProxyTask(const string &service) { |
| 124 | if (!proxy_.get()) { |
| 125 | VLOG(2) << "Init DHCP Proxy: " << device_name() << " at " << service; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 126 | proxy_.reset(proxy_factory_->CreateDHCPProxy(service)); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 130 | void DHCPConfig::ProcessEventSignal(const string &reason, |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 131 | const Configuration &configuration) { |
| 132 | LOG(INFO) << "Event reason: " << reason; |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 133 | if (reason == kReasonFail) { |
| 134 | LOG(ERROR) << "Received failure event from DHCP client."; |
| 135 | UpdateProperties(IPConfig::Properties(), false); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 136 | return; |
| 137 | } |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 138 | if (reason != kReasonBound && |
| 139 | reason != kReasonRebind && |
| 140 | reason != kReasonReboot && |
| 141 | reason != kReasonRenew) { |
| 142 | LOG(WARNING) << "Event ignored."; |
| 143 | return; |
| 144 | } |
| 145 | IPConfig::Properties properties; |
| 146 | CHECK(ParseConfiguration(configuration, &properties)); |
| 147 | UpdateProperties(properties, true); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 150 | bool DHCPConfig::Start() { |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 151 | VLOG(2) << __func__ << ": " << device_name(); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 152 | |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 153 | vector<char *> args; |
| 154 | args.push_back(const_cast<char *>(kDHCPCDPath)); |
| 155 | args.push_back(const_cast<char *>("-B")); // foreground |
| 156 | args.push_back(const_cast<char *>(device_name().c_str())); |
| 157 | if (!request_hostname_.empty()) { |
| 158 | args.push_back(const_cast<char *>("-h")); // request hostname |
| 159 | args.push_back(const_cast<char *>(request_hostname_.c_str())); |
| 160 | } |
| 161 | args.push_back(NULL); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 162 | char *envp[1] = { NULL }; |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 163 | |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 164 | CHECK(!pid_); |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 165 | if (!glib_->SpawnAsync(NULL, |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 166 | args.data(), |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 167 | envp, |
| 168 | G_SPAWN_DO_NOT_REAP_CHILD, |
| 169 | NULL, |
| 170 | NULL, |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 171 | &pid_, |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 172 | NULL)) { |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 173 | LOG(ERROR) << "Unable to spawn " << kDHCPCDPath; |
| 174 | return false; |
| 175 | } |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 176 | LOG(INFO) << "Spawned " << kDHCPCDPath << " with pid: " << pid_; |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 177 | provider_->BindPID(pid_, this); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 178 | CHECK(!child_watch_tag_); |
| 179 | child_watch_tag_ = glib_->ChildWatchAdd(pid_, ChildWatchCallback, this); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 180 | return true; |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 183 | void DHCPConfig::Stop() { |
| 184 | if (pid_) { |
| 185 | VLOG(2) << "Terminating " << pid_; |
Thieu Le | 94eed56 | 2012-02-21 15:57:29 -0800 | [diff] [blame^] | 186 | if (kill(pid_, SIGTERM) < 0) { |
| 187 | PLOG(ERROR); |
| 188 | return; |
| 189 | } |
| 190 | pid_t ret; |
| 191 | int num_iterations = |
| 192 | kDHCPCDExitWaitMilliseconds / kDHCPCDExitPollMilliseconds; |
| 193 | for (int count = 0; count < num_iterations; ++count) { |
| 194 | ret = waitpid(pid_, NULL, WNOHANG); |
| 195 | if (ret == pid_ || ret == -1) |
| 196 | break; |
| 197 | usleep(kDHCPCDExitPollMilliseconds * 1000); |
| 198 | if (count == num_iterations / 2) // Make one last attempt to kill dhcpcd. |
| 199 | kill(pid_, SIGKILL); |
| 200 | } |
| 201 | if (ret != pid_) |
| 202 | PLOG(ERROR); |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 206 | bool DHCPConfig::Restart() { |
| 207 | // Check to ensure that this instance doesn't get destroyed in the middle of |
| 208 | // this call. If stopping a running client while there's only one reference to |
| 209 | // this instance, we will end up destroying it when the PID is unbound from |
| 210 | // the Provider. Since the Provider doesn't invoke Restart, this would mean |
| 211 | // that Restart was erroneously executed through a bare reference. |
| 212 | CHECK(!pid_ || !HasOneRef()); |
| 213 | Stop(); |
| 214 | if (pid_) { |
| 215 | provider_->UnbindPID(pid_); |
| 216 | } |
| 217 | CleanupClientState(); |
| 218 | return Start(); |
| 219 | } |
| 220 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 221 | string DHCPConfig::GetIPv4AddressString(unsigned int address) { |
| 222 | char str[INET_ADDRSTRLEN]; |
| 223 | if (inet_ntop(AF_INET, &address, str, arraysize(str))) { |
| 224 | return str; |
| 225 | } |
| 226 | LOG(ERROR) << "Unable to convert IPv4 address to string: " << address; |
| 227 | return ""; |
| 228 | } |
| 229 | |
| 230 | bool DHCPConfig::ParseConfiguration(const Configuration& configuration, |
| 231 | IPConfig::Properties *properties) { |
| 232 | VLOG(2) << __func__; |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 233 | properties->method = flimflam::kTypeDHCP; |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 234 | properties->address_family = IPAddress::kFamilyIPv4; |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 235 | for (Configuration::const_iterator it = configuration.begin(); |
| 236 | it != configuration.end(); ++it) { |
| 237 | const string &key = it->first; |
| 238 | const DBus::Variant &value = it->second; |
| 239 | VLOG(2) << "Processing key: " << key; |
| 240 | if (key == kConfigurationKeyIPAddress) { |
| 241 | properties->address = GetIPv4AddressString(value.reader().get_uint32()); |
| 242 | if (properties->address.empty()) { |
| 243 | return false; |
| 244 | } |
| 245 | } else if (key == kConfigurationKeySubnetCIDR) { |
| 246 | properties->subnet_cidr = value.reader().get_byte(); |
| 247 | } else if (key == kConfigurationKeyBroadcastAddress) { |
| 248 | properties->broadcast_address = |
| 249 | GetIPv4AddressString(value.reader().get_uint32()); |
| 250 | if (properties->broadcast_address.empty()) { |
| 251 | return false; |
| 252 | } |
| 253 | } else if (key == kConfigurationKeyRouters) { |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 254 | vector<unsigned int> routers = value.operator vector<unsigned int>(); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 255 | if (routers.empty()) { |
| 256 | LOG(ERROR) << "No routers provided."; |
| 257 | return false; |
| 258 | } |
| 259 | properties->gateway = GetIPv4AddressString(routers[0]); |
| 260 | if (properties->gateway.empty()) { |
| 261 | return false; |
| 262 | } |
| 263 | } else if (key == kConfigurationKeyDNS) { |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 264 | vector<unsigned int> servers = value.operator vector<unsigned int>(); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 265 | for (vector<unsigned int>::const_iterator it = servers.begin(); |
| 266 | it != servers.end(); ++it) { |
| 267 | string server = GetIPv4AddressString(*it); |
| 268 | if (server.empty()) { |
| 269 | return false; |
| 270 | } |
| 271 | properties->dns_servers.push_back(server); |
| 272 | } |
| 273 | } else if (key == kConfigurationKeyDomainName) { |
| 274 | properties->domain_name = value.reader().get_string(); |
| 275 | } else if (key == kConfigurationKeyDomainSearch) { |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 276 | properties->domain_search = value.operator vector<string>(); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 277 | } else if (key == kConfigurationKeyMTU) { |
| 278 | int mtu = value.reader().get_uint16(); |
| 279 | if (mtu >= 576) { |
| 280 | properties->mtu = mtu; |
| 281 | } |
| 282 | } else { |
| 283 | VLOG(2) << "Key ignored."; |
| 284 | } |
| 285 | } |
| 286 | return true; |
| 287 | } |
| 288 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 289 | void DHCPConfig::ChildWatchCallback(GPid pid, gint status, gpointer data) { |
| 290 | VLOG(2) << "pid " << pid << " exit status " << status; |
| 291 | DHCPConfig *config = reinterpret_cast<DHCPConfig *>(data); |
| 292 | config->child_watch_tag_ = 0; |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 293 | CHECK_EQ(pid, config->pid_); |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 294 | config->CleanupClientState(); |
| 295 | |
| 296 | // |config| instance may be destroyed after this call. |
| 297 | config->provider_->UnbindPID(pid); |
| 298 | } |
| 299 | |
| 300 | void DHCPConfig::CleanupClientState() { |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 301 | if (child_watch_tag_) { |
| 302 | glib_->SourceRemove(child_watch_tag_); |
| 303 | child_watch_tag_ = 0; |
| 304 | } |
| 305 | if (pid_) { |
| 306 | glib_->SpawnClosePID(pid_); |
| 307 | pid_ = 0; |
| 308 | } |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 309 | proxy_.reset(); |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 310 | file_util::Delete(root_.Append(base::StringPrintf(kDHCPCDPathFormatLease, |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 311 | device_name().c_str())), |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 312 | false); |
| 313 | file_util::Delete(root_.Append(base::StringPrintf(kDHCPCDPathFormatPID, |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 314 | device_name().c_str())), |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 315 | false); |
| 316 | } |
| 317 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 318 | } // namespace shill |