OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/cros/network_library_impl_cros.h" | 5 #include "chrome/browser/chromeos/cros/network_library_impl_cros.h" |
6 | 6 |
7 #include <dbus/dbus-glib.h> | 7 #include <dbus/dbus-glib.h> |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_writer.h" // for debug output only. | 9 #include "base/json/json_writer.h" // for debug output only. |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 } else { | 508 } else { |
509 DCHECK_EQ(format, FORMAT_RAW_HEX); | 509 DCHECK_EQ(format, FORMAT_RAW_HEX); |
510 } | 510 } |
511 return ipconfig_vector; | 511 return ipconfig_vector; |
512 } | 512 } |
513 | 513 |
514 void NetworkLibraryImplCros::SetIPConfig(const NetworkIPConfig& ipconfig) { | 514 void NetworkLibraryImplCros::SetIPConfig(const NetworkIPConfig& ipconfig) { |
515 if (ipconfig.device_path.empty()) | 515 if (ipconfig.device_path.empty()) |
516 return; | 516 return; |
517 | 517 |
| 518 VLOG(1) << "Setting IPConfig: " << ipconfig.ToString(); |
| 519 |
518 NetworkIPConfig* ipconfig_dhcp = NULL; | 520 NetworkIPConfig* ipconfig_dhcp = NULL; |
519 std::string ipconfig_dhcp_path; | 521 std::string ipconfig_dhcp_path; |
520 NetworkIPConfig* ipconfig_static = NULL; | 522 NetworkIPConfig* ipconfig_static = NULL; |
521 std::string ipconfig_static_path; | 523 std::string ipconfig_static_path; |
522 | 524 |
523 NetworkIPConfigVector ipconfigs; | 525 NetworkIPConfigVector ipconfigs; |
524 std::vector<std::string> ipconfig_paths; | 526 std::vector<std::string> ipconfig_paths; |
525 CrosListIPConfigs(ipconfig.device_path, &ipconfigs, &ipconfig_paths, NULL); | 527 CrosListIPConfigs(ipconfig.device_path, &ipconfigs, &ipconfig_paths, NULL); |
526 for (size_t i = 0; i < ipconfigs.size(); ++i) { | 528 for (size_t i = 0; i < ipconfigs.size(); ++i) { |
527 if (ipconfigs[i].type == chromeos::IPCONFIG_TYPE_DHCP) { | 529 if (ipconfigs[i].type == chromeos::IPCONFIG_TYPE_DHCP) { |
528 ipconfig_dhcp = &ipconfigs[i]; | 530 ipconfig_dhcp = &ipconfigs[i]; |
529 ipconfig_dhcp_path = ipconfig_paths[i]; | 531 ipconfig_dhcp_path = ipconfig_paths[i]; |
530 } else if (ipconfigs[i].type == chromeos::IPCONFIG_TYPE_IPV4) { | 532 } else if (ipconfigs[i].type == chromeos::IPCONFIG_TYPE_IPV4) { |
531 ipconfig_static = &ipconfigs[i]; | 533 ipconfig_static = &ipconfigs[i]; |
532 ipconfig_static_path = ipconfig_paths[i]; | 534 ipconfig_static_path = ipconfig_paths[i]; |
533 } | 535 } |
534 } | 536 } |
535 | 537 |
536 NetworkIPConfigVector ipconfigs2; | 538 NetworkIPConfigVector ipconfigs2; |
537 std::vector<std::string> ipconfig_paths2; | 539 std::vector<std::string> ipconfig_paths2; |
538 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) { | 540 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) { |
539 // If switching from static to dhcp, create new dhcp ip config. | 541 // If switching from static to DHCP, create new DHCP IPConfig. |
540 if (!ipconfig_dhcp) | 542 if (!ipconfig_dhcp && |
541 CrosAddIPConfig(ipconfig.device_path, chromeos::IPCONFIG_TYPE_DHCP); | 543 !CrosAddIPConfig(ipconfig.device_path, chromeos::IPCONFIG_TYPE_DHCP)) { |
542 // User wants DHCP now. So delete the static ip config. | 544 LOG(ERROR) << "Unable to add new DHCP IPConfig"; |
| 545 return; |
| 546 } |
| 547 // User wants DHCP now. So delete the static IPConfig. |
543 if (ipconfig_static) | 548 if (ipconfig_static) |
544 CrosRemoveIPConfig(ipconfig_static_path); | 549 CrosRemoveIPConfig(ipconfig_static_path); |
545 } else if (ipconfig.type == chromeos::IPCONFIG_TYPE_IPV4) { | 550 } else if (ipconfig.type == chromeos::IPCONFIG_TYPE_IPV4) { |
546 // If switching from dhcp to static, create new static ip config. | 551 // If switching from DHCP to static, create new static IPConfig. |
547 if (!ipconfig_static) { | 552 if (!ipconfig_static) { |
548 CrosAddIPConfig(ipconfig.device_path, chromeos::IPCONFIG_TYPE_IPV4); | 553 if (!CrosAddIPConfig(ipconfig.device_path, |
549 // Now find the newly created IP config. | 554 chromeos::IPCONFIG_TYPE_IPV4)) { |
| 555 LOG(ERROR) << "Unable to add new static IPConfig"; |
| 556 return; |
| 557 } |
| 558 // Now find the newly created IPConfig. |
550 if (CrosListIPConfigs(ipconfig.device_path, &ipconfigs2, | 559 if (CrosListIPConfigs(ipconfig.device_path, &ipconfigs2, |
551 &ipconfig_paths2, NULL)) { | 560 &ipconfig_paths2, NULL)) { |
552 for (size_t i = 0; i < ipconfigs2.size(); ++i) { | 561 for (size_t i = 0; i < ipconfigs2.size(); ++i) { |
553 if (ipconfigs2[i].type == chromeos::IPCONFIG_TYPE_IPV4) { | 562 if (ipconfigs2[i].type == chromeos::IPCONFIG_TYPE_IPV4) { |
554 ipconfig_static = &ipconfigs2[i]; | 563 ipconfig_static = &ipconfigs2[i]; |
555 ipconfig_static_path = ipconfig_paths2[i]; | 564 ipconfig_static_path = ipconfig_paths2[i]; |
556 } | 565 } |
557 } | 566 } |
558 } | 567 } |
| 568 if (!ipconfig_static) { |
| 569 LOG(ERROR) << "Unable to find newly added static IPConfig"; |
| 570 return; |
| 571 } |
559 } | 572 } |
560 if (ipconfig_static) { | 573 |
561 // Save any changed details. | 574 // Save any changed details. |
562 if (ipconfig.address != ipconfig_static->address) { | 575 if (ipconfig.address != ipconfig_static->address) { |
563 base::StringValue value(ipconfig.address); | 576 base::StringValue value(ipconfig.address); |
564 CrosSetNetworkIPConfigProperty(ipconfig_static->device_path, | 577 CrosSetNetworkIPConfigProperty(ipconfig_static_path, |
565 flimflam::kAddressProperty, value); | 578 flimflam::kAddressProperty, value); |
| 579 } |
| 580 if (ipconfig.netmask != ipconfig_static->netmask) { |
| 581 int prefixlen = ipconfig.GetPrefixLength(); |
| 582 if (prefixlen == -1) { |
| 583 VLOG(1) << "IPConfig prefix length is invalid for netmask " |
| 584 << ipconfig.netmask; |
| 585 } else { |
| 586 base::FundamentalValue value(prefixlen); |
| 587 CrosSetNetworkIPConfigProperty(ipconfig_static_path, |
| 588 flimflam::kPrefixlenProperty, value); |
566 } | 589 } |
567 if (ipconfig.netmask != ipconfig_static->netmask) { | |
568 int prefixlen = ipconfig.GetPrefixLength(); | |
569 if (prefixlen == -1) { | |
570 VLOG(1) << "IP config prefixlen is invalid for netmask " | |
571 << ipconfig.netmask; | |
572 } else { | |
573 base::FundamentalValue value(prefixlen); | |
574 CrosSetNetworkIPConfigProperty(ipconfig_static->device_path, | |
575 flimflam::kPrefixlenProperty, value); | |
576 } | |
577 } | |
578 if (ipconfig.gateway != ipconfig_static->gateway) { | |
579 base::StringValue value(ipconfig.gateway); | |
580 CrosSetNetworkIPConfigProperty(ipconfig_static->device_path, | |
581 flimflam::kGatewayProperty, value); | |
582 } | |
583 if (ipconfig.name_servers != ipconfig_static->name_servers) { | |
584 base::StringValue value(ipconfig.name_servers); | |
585 CrosSetNetworkIPConfigProperty(ipconfig_static->device_path, | |
586 flimflam::kNameServersProperty, value); | |
587 } | |
588 // Remove dhcp ip config if there is one. | |
589 if (ipconfig_dhcp) | |
590 CrosRemoveIPConfig(ipconfig_dhcp_path); | |
591 } | 590 } |
| 591 if (ipconfig.gateway != ipconfig_static->gateway) { |
| 592 base::StringValue value(ipconfig.gateway); |
| 593 CrosSetNetworkIPConfigProperty(ipconfig_static_path, |
| 594 flimflam::kGatewayProperty, value); |
| 595 } |
| 596 if (ipconfig.name_servers != ipconfig_static->name_servers) { |
| 597 base::StringValue value(ipconfig.name_servers); |
| 598 CrosSetNetworkIPConfigProperty(ipconfig_static_path, |
| 599 flimflam::kNameServersProperty, value); |
| 600 } |
| 601 // Remove DHCP IPConfig if there is one. |
| 602 if (ipconfig_dhcp) |
| 603 CrosRemoveIPConfig(ipconfig_dhcp_path); |
592 } | 604 } |
593 } | 605 } |
594 | 606 |
595 ///////////////////////////////////////////////////////////////////////////// | 607 ///////////////////////////////////////////////////////////////////////////// |
596 // Network Manager functions. | 608 // Network Manager functions. |
597 | 609 |
598 void NetworkLibraryImplCros::NetworkManagerStatusChangedHandler( | 610 void NetworkLibraryImplCros::NetworkManagerStatusChangedHandler( |
599 const std::string& path, | 611 const std::string& path, |
600 const std::string& key, | 612 const std::string& key, |
601 const Value& value) { | 613 const Value& value) { |
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 // Switch back to signed settings value. | 1169 // Switch back to signed settings value. |
1158 SetCellularDataRoamingAllowed(settings_value); | 1170 SetCellularDataRoamingAllowed(settings_value); |
1159 } | 1171 } |
1160 } | 1172 } |
1161 } | 1173 } |
1162 NotifyNetworkManagerChanged(false); // Not forced. | 1174 NotifyNetworkManagerChanged(false); // Not forced. |
1163 AddNetworkDeviceObserver(device_path, network_device_observer_.get()); | 1175 AddNetworkDeviceObserver(device_path, network_device_observer_.get()); |
1164 } | 1176 } |
1165 | 1177 |
1166 } // namespace chromeos | 1178 } // namespace chromeos |
OLD | NEW |