Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [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/dhcpcd_proxy.h" |
| 6 | |
| 7 | #include <base/logging.h> |
| 8 | |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 9 | #include "shill/dhcp_provider.h" |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 10 | #include "shill/scope_logger.h" |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 11 | |
| 12 | using std::string; |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 13 | using std::vector; |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 14 | |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 15 | namespace shill { |
| 16 | |
| 17 | const char DHCPCDProxy::kDBusInterfaceName[] = "org.chromium.dhcpcd"; |
| 18 | const char DHCPCDProxy::kDBusPath[] = "/org/chromium/dhcpcd"; |
| 19 | |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 20 | DHCPCDListener::DHCPCDListener(DBus::Connection *connection, |
| 21 | DHCPProvider *provider) |
| 22 | : proxy_(connection, provider) {} |
| 23 | |
| 24 | DHCPCDListener::Proxy::Proxy(DBus::Connection *connection, |
| 25 | DHCPProvider *provider) |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 26 | : DBus::InterfaceProxy(DHCPCDProxy::kDBusInterfaceName), |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 27 | DBus::ObjectProxy(*connection, DHCPCDProxy::kDBusPath), |
| 28 | provider_(provider) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 29 | SLOG(DHCP, 2) << __func__; |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 30 | connect_signal(DHCPCDListener::Proxy, Event, EventSignal); |
| 31 | connect_signal(DHCPCDListener::Proxy, StatusChanged, StatusChangedSignal); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 34 | void DHCPCDListener::Proxy::EventSignal(const DBus::SignalMessage &signal) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 35 | SLOG(DHCP, 2) << __func__; |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 36 | DBus::MessageIter ri = signal.reader(); |
| 37 | unsigned int pid; |
| 38 | ri >> pid; |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 39 | SLOG(DHCP, 2) << "sender(" << signal.sender() << ") pid(" << pid << ")"; |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 40 | |
| 41 | DHCPConfigRefPtr config = provider_->GetConfig(pid); |
| 42 | if (!config.get()) { |
| 43 | LOG(ERROR) << "Unknown DHCP client PID " << pid; |
| 44 | return; |
| 45 | } |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 46 | config->InitProxy(signal.sender()); |
Darin Petkov | e7cb7f8 | 2011-06-03 13:21:51 -0700 | [diff] [blame] | 47 | |
| 48 | string reason; |
| 49 | ri >> reason; |
| 50 | DHCPConfig::Configuration configuration; |
| 51 | ri >> configuration; |
| 52 | config->ProcessEventSignal(reason, configuration); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 55 | void DHCPCDListener::Proxy::StatusChangedSignal( |
| 56 | const DBus::SignalMessage &signal) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 57 | SLOG(DHCP, 2) << __func__; |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 58 | DBus::MessageIter ri = signal.reader(); |
| 59 | unsigned int pid; |
| 60 | ri >> pid; |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 61 | SLOG(DHCP, 2) << "sender(" << signal.sender() << ") pid(" << pid << ")"; |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 62 | |
| 63 | // Accept StatusChanged signals just to get the sender address and create an |
| 64 | // appropriate proxy for the PID/sender pair. |
| 65 | DHCPConfigRefPtr config = provider_->GetConfig(pid); |
| 66 | if (!config.get()) { |
| 67 | LOG(ERROR) << "Unknown DHCP client PID " << pid; |
| 68 | return; |
| 69 | } |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 70 | config->InitProxy(signal.sender()); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 73 | DHCPCDProxy::DHCPCDProxy(DBus::Connection *connection, const string &service) |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 74 | : proxy_(connection, service) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 75 | SLOG(DHCP, 2) << "DHCPCDProxy(service=" << service << ")."; |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 76 | } |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 77 | |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 78 | void DHCPCDProxy::Rebind(const string &interface) { |
| 79 | proxy_.Rebind(interface); |
| 80 | } |
| 81 | |
| 82 | void DHCPCDProxy::Release(const string &interface) { |
| 83 | proxy_.Release(interface); |
| 84 | } |
| 85 | |
| 86 | DHCPCDProxy::Proxy::Proxy(DBus::Connection *connection, |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 87 | const string &service) |
| 88 | : DBus::ObjectProxy(*connection, kDBusPath, service.c_str()) { |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 89 | // Don't catch signals directly in this proxy because they will be dispatched |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 90 | // to the client by the DHCPCD listener. |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 91 | _signals.erase("Event"); |
| 92 | _signals.erase("StatusChanged"); |
| 93 | } |
| 94 | |
Darin Petkov | a7b8949 | 2011-07-27 12:48:17 -0700 | [diff] [blame] | 95 | DHCPCDProxy::Proxy::~Proxy() {} |
| 96 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 97 | void DHCPCDProxy::Proxy::Event( |
| 98 | const uint32_t &/*pid*/, |
| 99 | const std::string &/*reason*/, |
| 100 | const DHCPConfig::Configuration &/*configuration*/) { |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 101 | NOTREACHED(); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 102 | } |
| 103 | |
mukesh agrawal | 1830fa1 | 2011-09-26 14:31:40 -0700 | [diff] [blame] | 104 | void DHCPCDProxy::Proxy::StatusChanged(const uint32_t &/*pid*/, |
| 105 | const std::string &/*status*/) { |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 106 | NOTREACHED(); |
Darin Petkov | 50308cd | 2011-06-01 18:25:07 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | } // namespace shill |