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 | 14c29ec | 2012-03-02 11:34:19 +0100 | [diff] [blame] | 41 | const int DHCPConfig::kMinMTU = 576; |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 42 | const char DHCPConfig::kReasonBound[] = "BOUND"; |
| 43 | const char DHCPConfig::kReasonFail[] = "FAIL"; |
| 44 | const char DHCPConfig::kReasonRebind[] = "REBIND"; |
| 45 | const char DHCPConfig::kReasonReboot[] = "REBOOT"; |
| 46 | const char DHCPConfig::kReasonRenew[] = "RENEW"; |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 47 | // static |
| 48 | const char DHCPConfig::kType[] = "dhcp"; |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 49 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 50 | |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 51 | DHCPConfig::DHCPConfig(ControlInterface *control_interface, |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 52 | EventDispatcher *dispatcher, |
Chris Masone | 19e3040 | 2011-07-19 15:48:47 -0700 | [diff] [blame] | 53 | DHCPProvider *provider, |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 54 | const string &device_name, |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 55 | const string &request_hostname, |
Darin Petkov | 3258a81 | 2011-06-23 11:28:45 -0700 | [diff] [blame] | 56 | GLib *glib) |
Chris Masone | 0756f23 | 2011-07-21 17:24:00 -0700 | [diff] [blame] | 57 | : IPConfig(control_interface, device_name, kType), |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 58 | proxy_factory_(ProxyFactory::GetInstance()), |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 59 | provider_(provider), |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 60 | request_hostname_(request_hostname), |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 61 | pid_(0), |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 62 | child_watch_tag_(0), |
| 63 | root_("/"), |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 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) { |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 115 | if (!proxy_.get()) { |
| 116 | VLOG(2) << "Init DHCP Proxy: " << device_name() << " at " << service; |
Darin Petkov | ab565bb | 2011-10-06 02:55:51 -0700 | [diff] [blame] | 117 | proxy_.reset(proxy_factory_->CreateDHCPProxy(service)); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 121 | void DHCPConfig::ProcessEventSignal(const string &reason, |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 122 | const Configuration &configuration) { |
| 123 | LOG(INFO) << "Event reason: " << reason; |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 124 | if (reason == kReasonFail) { |
| 125 | LOG(ERROR) << "Received failure event from DHCP client."; |
| 126 | UpdateProperties(IPConfig::Properties(), false); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 127 | return; |
| 128 | } |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 129 | if (reason != kReasonBound && |
| 130 | reason != kReasonRebind && |
| 131 | reason != kReasonReboot && |
| 132 | reason != kReasonRenew) { |
| 133 | LOG(WARNING) << "Event ignored."; |
| 134 | return; |
| 135 | } |
| 136 | IPConfig::Properties properties; |
| 137 | CHECK(ParseConfiguration(configuration, &properties)); |
| 138 | UpdateProperties(properties, true); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 141 | bool DHCPConfig::Start() { |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 142 | VLOG(2) << __func__ << ": " << device_name(); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 143 | |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 144 | vector<char *> args; |
| 145 | args.push_back(const_cast<char *>(kDHCPCDPath)); |
| 146 | args.push_back(const_cast<char *>("-B")); // foreground |
| 147 | args.push_back(const_cast<char *>(device_name().c_str())); |
| 148 | if (!request_hostname_.empty()) { |
| 149 | args.push_back(const_cast<char *>("-h")); // request hostname |
| 150 | args.push_back(const_cast<char *>(request_hostname_.c_str())); |
| 151 | } |
| 152 | args.push_back(NULL); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 153 | char *envp[1] = { NULL }; |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 154 | |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 155 | CHECK(!pid_); |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 156 | if (!glib_->SpawnAsync(NULL, |
Paul Stewart | d32f484 | 2012-01-11 16:08:13 -0800 | [diff] [blame] | 157 | args.data(), |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 158 | envp, |
| 159 | G_SPAWN_DO_NOT_REAP_CHILD, |
| 160 | NULL, |
| 161 | NULL, |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 162 | &pid_, |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 163 | NULL)) { |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 164 | LOG(ERROR) << "Unable to spawn " << kDHCPCDPath; |
| 165 | return false; |
| 166 | } |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 167 | LOG(INFO) << "Spawned " << kDHCPCDPath << " with pid: " << pid_; |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 168 | provider_->BindPID(pid_, this); |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 169 | CHECK(!child_watch_tag_); |
| 170 | child_watch_tag_ = glib_->ChildWatchAdd(pid_, ChildWatchCallback, this); |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 171 | return true; |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 174 | void DHCPConfig::Stop() { |
| 175 | if (pid_) { |
| 176 | VLOG(2) << "Terminating " << pid_; |
Thieu Le | 94eed56 | 2012-02-21 15:57:29 -0800 | [diff] [blame] | 177 | if (kill(pid_, SIGTERM) < 0) { |
| 178 | PLOG(ERROR); |
| 179 | return; |
| 180 | } |
| 181 | pid_t ret; |
| 182 | int num_iterations = |
| 183 | kDHCPCDExitWaitMilliseconds / kDHCPCDExitPollMilliseconds; |
| 184 | for (int count = 0; count < num_iterations; ++count) { |
| 185 | ret = waitpid(pid_, NULL, WNOHANG); |
| 186 | if (ret == pid_ || ret == -1) |
| 187 | break; |
| 188 | usleep(kDHCPCDExitPollMilliseconds * 1000); |
| 189 | if (count == num_iterations / 2) // Make one last attempt to kill dhcpcd. |
| 190 | kill(pid_, SIGKILL); |
| 191 | } |
| 192 | if (ret != pid_) |
| 193 | PLOG(ERROR); |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 197 | bool DHCPConfig::Restart() { |
| 198 | // Check to ensure that this instance doesn't get destroyed in the middle of |
| 199 | // this call. If stopping a running client while there's only one reference to |
| 200 | // this instance, we will end up destroying it when the PID is unbound from |
| 201 | // the Provider. Since the Provider doesn't invoke Restart, this would mean |
| 202 | // that Restart was erroneously executed through a bare reference. |
| 203 | CHECK(!pid_ || !HasOneRef()); |
| 204 | Stop(); |
| 205 | if (pid_) { |
| 206 | provider_->UnbindPID(pid_); |
| 207 | } |
| 208 | CleanupClientState(); |
| 209 | return Start(); |
| 210 | } |
| 211 | |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 212 | string DHCPConfig::GetIPv4AddressString(unsigned int address) { |
| 213 | char str[INET_ADDRSTRLEN]; |
| 214 | if (inet_ntop(AF_INET, &address, str, arraysize(str))) { |
| 215 | return str; |
| 216 | } |
| 217 | LOG(ERROR) << "Unable to convert IPv4 address to string: " << address; |
| 218 | return ""; |
| 219 | } |
| 220 | |
| 221 | bool DHCPConfig::ParseConfiguration(const Configuration& configuration, |
| 222 | IPConfig::Properties *properties) { |
| 223 | VLOG(2) << __func__; |
Chris Masone | 43b48a1 | 2011-07-01 13:37:07 -0700 | [diff] [blame] | 224 | properties->method = flimflam::kTypeDHCP; |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 225 | properties->address_family = IPAddress::kFamilyIPv4; |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 226 | for (Configuration::const_iterator it = configuration.begin(); |
| 227 | it != configuration.end(); ++it) { |
| 228 | const string &key = it->first; |
| 229 | const DBus::Variant &value = it->second; |
| 230 | VLOG(2) << "Processing key: " << key; |
| 231 | if (key == kConfigurationKeyIPAddress) { |
| 232 | properties->address = GetIPv4AddressString(value.reader().get_uint32()); |
| 233 | if (properties->address.empty()) { |
| 234 | return false; |
| 235 | } |
| 236 | } else if (key == kConfigurationKeySubnetCIDR) { |
Paul Stewart | 48100b0 | 2012-03-19 07:53:52 -0700 | [diff] [blame] | 237 | properties->subnet_prefix = value.reader().get_byte(); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 238 | } else if (key == kConfigurationKeyBroadcastAddress) { |
| 239 | properties->broadcast_address = |
| 240 | GetIPv4AddressString(value.reader().get_uint32()); |
| 241 | if (properties->broadcast_address.empty()) { |
| 242 | return false; |
| 243 | } |
| 244 | } else if (key == kConfigurationKeyRouters) { |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 245 | vector<unsigned int> routers = value.operator vector<unsigned int>(); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 246 | if (routers.empty()) { |
| 247 | LOG(ERROR) << "No routers provided."; |
| 248 | return false; |
| 249 | } |
| 250 | properties->gateway = GetIPv4AddressString(routers[0]); |
| 251 | if (properties->gateway.empty()) { |
| 252 | return false; |
| 253 | } |
| 254 | } else if (key == kConfigurationKeyDNS) { |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 255 | vector<unsigned int> servers = value.operator vector<unsigned int>(); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 256 | for (vector<unsigned int>::const_iterator it = servers.begin(); |
| 257 | it != servers.end(); ++it) { |
| 258 | string server = GetIPv4AddressString(*it); |
| 259 | if (server.empty()) { |
| 260 | return false; |
| 261 | } |
| 262 | properties->dns_servers.push_back(server); |
| 263 | } |
| 264 | } else if (key == kConfigurationKeyDomainName) { |
| 265 | properties->domain_name = value.reader().get_string(); |
| 266 | } else if (key == kConfigurationKeyDomainSearch) { |
Darin Petkov | f7897bc | 2011-06-08 17:13:36 -0700 | [diff] [blame] | 267 | properties->domain_search = value.operator vector<string>(); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 268 | } else if (key == kConfigurationKeyMTU) { |
| 269 | int mtu = value.reader().get_uint16(); |
Darin Petkov | 14c29ec | 2012-03-02 11:34:19 +0100 | [diff] [blame] | 270 | if (mtu >= kMinMTU) { |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 271 | properties->mtu = mtu; |
| 272 | } |
| 273 | } else { |
| 274 | VLOG(2) << "Key ignored."; |
| 275 | } |
| 276 | } |
| 277 | return true; |
| 278 | } |
| 279 | |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 280 | void DHCPConfig::ChildWatchCallback(GPid pid, gint status, gpointer data) { |
| 281 | VLOG(2) << "pid " << pid << " exit status " << status; |
| 282 | DHCPConfig *config = reinterpret_cast<DHCPConfig *>(data); |
| 283 | config->child_watch_tag_ = 0; |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 284 | CHECK_EQ(pid, config->pid_); |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 285 | config->CleanupClientState(); |
| 286 | |
| 287 | // |config| instance may be destroyed after this call. |
| 288 | config->provider_->UnbindPID(pid); |
| 289 | } |
| 290 | |
| 291 | void DHCPConfig::CleanupClientState() { |
Darin Petkov | 98dd6a0 | 2011-06-10 15:12:57 -0700 | [diff] [blame] | 292 | if (child_watch_tag_) { |
| 293 | glib_->SourceRemove(child_watch_tag_); |
| 294 | child_watch_tag_ = 0; |
| 295 | } |
| 296 | if (pid_) { |
| 297 | glib_->SpawnClosePID(pid_); |
| 298 | pid_ = 0; |
| 299 | } |
Darin Petkov | f9b0ca8 | 2011-06-20 12:10:23 -0700 | [diff] [blame] | 300 | proxy_.reset(); |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 301 | file_util::Delete(root_.Append(base::StringPrintf(kDHCPCDPathFormatLease, |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 302 | device_name().c_str())), |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 303 | false); |
| 304 | file_util::Delete(root_.Append(base::StringPrintf(kDHCPCDPathFormatPID, |
Darin Petkov | f65e928 | 2011-06-21 14:29:56 -0700 | [diff] [blame] | 305 | device_name().c_str())), |
Darin Petkov | 92c4390 | 2011-06-09 20:46:06 -0700 | [diff] [blame] | 306 | false); |
| 307 | } |
| 308 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 309 | } // namespace shill |