diff options
author | Darin Petkov <petkov@chromium.org> | 2011-06-01 18:25:07 -0700 |
---|---|---|
committer | Darin Petkov <petkov@chromium.org> | 2011-06-02 10:07:49 -0700 |
commit | 50308cd0cc10594b9f50fc4191ba4e9bd1fec0e5 (patch) | |
tree | ce34c1110666e2e78ed5cbf6e9e0aba543eb4dae | |
parent | ab87ea4808bd7d002eaad8b021f14c1cad90f65a (diff) | |
download | shill-50308cd0cc10594b9f50fc4191ba4e9bd1fec0e5.tar.gz |
Basic DHCP framework and DHCPCD proxies.
DHCPProvider singleton will instantiate and supply DHCPConfig objects. Each
DHCPConfig object corresponds to a separate DHCP client (dhcpcd). Each
DHCPConfig object will be associated with a single DHCPCDProxy object to
communicate with that client. DHCPProvider will use a DHCPCDListener singleton
to figure the D-Bus destination of each spawned DHCP client dispatch signals to
its DHCPCDProxy.
Also fix dhcpcd.xml (this needs to be fixed in dhcpcd itself, really).
BUG=chromium-os:16013
TEST=manual by modifying shill_main and instantiating the proxies.
Change-Id: I8fb0eadb8c751365997db2ed2bdfde0711c362a3
Reviewed-on: http://gerrit.chromium.org/gerrit/1934
Tested-by: Darin Petkov <petkov@chromium.org>
Reviewed-by: Darin Petkov <petkov@chromium.org>
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | dbus_control.h | 4 | ||||
-rw-r--r-- | dhcp_config.cc | 19 | ||||
-rw-r--r-- | dhcp_config.h | 23 | ||||
-rw-r--r-- | dhcp_provider.cc | 23 | ||||
-rw-r--r-- | dhcp_provider.h | 28 | ||||
-rw-r--r-- | dhcp_proxy_interface.h | 23 | ||||
-rw-r--r-- | dhcpcd.xml | 7 | ||||
-rw-r--r-- | dhcpcd_proxy.cc | 67 | ||||
-rw-r--r-- | dhcpcd_proxy.h | 61 | ||||
-rw-r--r-- | ipconfig.cc | 4 | ||||
-rw-r--r-- | ipconfig.h | 6 | ||||
-rw-r--r-- | ipconfig_unittest.cc | 2 |
13 files changed, 261 insertions, 9 deletions
@@ -45,6 +45,9 @@ SHILL_OBJS = \ device.o \ device_dbus_adaptor.o \ device_info.o \ + dhcp_config.o \ + dhcp_provider.o \ + dhcpcd_proxy.o \ ethernet.o \ ethernet_service.o \ glib_io_handler.o \ diff --git a/dbus_control.h b/dbus_control.h index 0e9c9ad2..4ec148e8 100644 --- a/dbus_control.h +++ b/dbus_control.h @@ -22,8 +22,10 @@ class DBusControl : public ControlInterface { ServiceAdaptorInterface *CreateServiceAdaptor(Service *service); DeviceAdaptorInterface *CreateDeviceAdaptor(Device *device); - private: void EnsureConnection(); + DBus::Connection *connection() { return connection_.get(); } + + private: scoped_ptr<DBus::Glib::BusDispatcher> dispatcher_; scoped_ptr<DBus::Connection> connection_; }; diff --git a/dhcp_config.cc b/dhcp_config.cc new file mode 100644 index 00000000..fbba26ea --- /dev/null +++ b/dhcp_config.cc @@ -0,0 +1,19 @@ +// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "shill/dhcp_config.h" + +#include <base/logging.h> + +namespace shill { + +DHCPConfig::DHCPConfig(const Device &device) : IPConfig(device) { + VLOG(2) << "DHCPConfig created."; +} + +DHCPConfig::~DHCPConfig() { + VLOG(2) << "DHCPConfig destroyed."; +} + +} // namespace shill diff --git a/dhcp_config.h b/dhcp_config.h new file mode 100644 index 00000000..735fa9c3 --- /dev/null +++ b/dhcp_config.h @@ -0,0 +1,23 @@ +// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SHILL_DHCP_CONFIG_ +#define SHILL_DHCP_CONFIG_ + +#include "shill/ipconfig.h" + +namespace shill { + +class DHCPConfig : public IPConfig { + public: + explicit DHCPConfig(const Device &device); + virtual ~DHCPConfig(); + + private: + DISALLOW_COPY_AND_ASSIGN(DHCPConfig); +}; + +} // namespace shill + +#endif // SHILL_DHCP_CONFIG_ diff --git a/dhcp_provider.cc b/dhcp_provider.cc new file mode 100644 index 00000000..abb97bdc --- /dev/null +++ b/dhcp_provider.cc @@ -0,0 +1,23 @@ +// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "shill/dhcp_provider.h" + +#include <base/logging.h> + +namespace shill { + +DHCPProvider::DHCPProvider() { + VLOG(2) << "DHCPProvider created."; +} + +DHCPProvider::~DHCPProvider() { + VLOG(2) << "DHCPProvider destroyed."; +} + +DHCPProvider* DHCPProvider::GetInstance() { + return Singleton<DHCPProvider>::get(); +} + +} // namespace shill diff --git a/dhcp_provider.h b/dhcp_provider.h new file mode 100644 index 00000000..c77d4562 --- /dev/null +++ b/dhcp_provider.h @@ -0,0 +1,28 @@ +// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SHILL_DHCP_PROVIDER_ +#define SHILL_DHCP_PROVIDER_ + +#include <base/memory/singleton.h> + +namespace shill { + +class DHCPProvider { + public: + // This is a singleton -- use DHCPProvider::GetInstance()->Foo() + static DHCPProvider *GetInstance(); + + private: + friend struct DefaultSingletonTraits<DHCPProvider>; + + DHCPProvider(); + virtual ~DHCPProvider(); + + DISALLOW_COPY_AND_ASSIGN(DHCPProvider); +}; + +} // namespace shill + +#endif // SHILL_DHCP_PROVIDER_ diff --git a/dhcp_proxy_interface.h b/dhcp_proxy_interface.h new file mode 100644 index 00000000..f9ba5bd2 --- /dev/null +++ b/dhcp_proxy_interface.h @@ -0,0 +1,23 @@ +// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SHILL_DHCP_PROXY_INTERFACE_ +#define SHILL_DHCP_PROXY_INTERFACE_ + +namespace shill { + +// These are the functions that a DHCP proxy and listener must support. +class DHCPProxyInterface { + public: + virtual ~DHCPProxyInterface() {} +}; + +class DHCPListenerInterface { + public: + virtual ~DHCPListenerInterface() {} +}; + +} // namespace shill + +#endif // SHILL_DHCP_PROXY_INTERFACE_ @@ -23,10 +23,13 @@ <arg name="interface" direction="in" type="s"/> </method> <signal name="Event"> - <arg name="configuration" type="usa{sv}"/> + <arg name="pid" type="u"/> + <arg name="reason" type="s"/> + <arg name="configuration" type="a{sv}"/> </signal> <signal name="StatusChanged"> - <arg name="status" type="us"/> + <arg name="pid" type="u"/> + <arg name="status" type="s"/> </signal> </interface> </node> diff --git a/dhcpcd_proxy.cc b/dhcpcd_proxy.cc new file mode 100644 index 00000000..3ff6983e --- /dev/null +++ b/dhcpcd_proxy.cc @@ -0,0 +1,67 @@ +// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "shill/dhcpcd_proxy.h" + +#include <base/logging.h> + +namespace shill { + +const char DHCPCDProxy::kDBusInterfaceName[] = "org.chromium.dhcpcd"; +const char DHCPCDProxy::kDBusPath[] = "/org/chromium/dhcpcd"; + +DHCPCDListener::DHCPCDListener(DBus::Connection *connection) + : DBus::InterfaceProxy(DHCPCDProxy::kDBusInterfaceName), + DBus::ObjectProxy(*connection, DHCPCDProxy::kDBusPath) { + VLOG(2) << __func__; + connect_signal(DHCPCDListener, Event, EventSignal); + connect_signal(DHCPCDListener, StatusChanged, StatusChangedSignal); +} + +void DHCPCDListener::EventSignal(const DBus::SignalMessage &signal) { + VLOG(2) << __func__; + DBus::MessageIter ri = signal.reader(); + unsigned int pid; + ri >> pid; + VLOG(2) << "sender(" << signal.sender() << ") pid(" << pid << ")"; + // TODO(petkov): Dispatch the signal to the appropriate DHCPCDProxy. +} + +void DHCPCDListener::StatusChangedSignal(const DBus::SignalMessage &signal) { + VLOG(2) << __func__; + DBus::MessageIter ri = signal.reader(); + unsigned int pid; + ri >> pid; + VLOG(2) << "sender(" << signal.sender() << ") pid(" << pid << ")"; + // TODO(petkov): Dispatch the signal to the appropriate DHCPCDProxy. +} + +DHCPCDProxy::DHCPCDProxy(unsigned int pid, + DBus::Connection *connection, + const char *service) + : DBus::ObjectProxy(*connection, kDBusPath, service), + pid_(pid) { + VLOG(2) << "DHCPCDListener(pid=" << pid_ << " service=" << service << ")."; + + // Don't catch signals directly in this proxy because they will be dispatched + // to us by the DHCPCD listener. + _signals.erase("Event"); + _signals.erase("StatusChanged"); +} + +void DHCPCDProxy::Event( + const uint32_t& pid, + const std::string& reason, + const std::map< std::string, DBus::Variant >& configuration) { + VLOG(2) << "Event(pid=" << pid << " reason=\"" << reason << "\")"; + CHECK_EQ(pid, pid_); +} + +void DHCPCDProxy::StatusChanged(const uint32_t& pid, + const std::string& status) { + VLOG(2) << "StatusChanged(pid=" << pid << " status=\"" << status << "\")"; + CHECK_EQ(pid, pid_); +} + +} // namespace shill diff --git a/dhcpcd_proxy.h b/dhcpcd_proxy.h new file mode 100644 index 00000000..576c0047 --- /dev/null +++ b/dhcpcd_proxy.h @@ -0,0 +1,61 @@ +// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef SHILL_DHCPCD_PROXY_ +#define SHILL_DHCPCD_PROXY_ + +#include <base/basictypes.h> + +#include "shill/dhcp_proxy_interface.h" +#include "shill/dhcpcd.h" + +namespace shill { + +// The DHCPCD listener is a singleton proxy that listens to signals from all +// DHCP clients and dispatches them through the DHCP provider to the appropriate +// client based on the PID. +class DHCPCDListener : public DHCPListenerInterface, + public DBus::InterfaceProxy, + public DBus::ObjectProxy { + public: + explicit DHCPCDListener(DBus::Connection *connection); + + private: + void EventSignal(const DBus::SignalMessage &signal); + void StatusChangedSignal(const DBus::SignalMessage &signal); + + DISALLOW_COPY_AND_ASSIGN(DHCPCDListener); +}; + +// There's a single DHCPCD proxy per DHCP client identified by its process id +// and service name. +class DHCPCDProxy : public DHCPProxyInterface, + public org::chromium::dhcpcd_proxy, + public DBus::ObjectProxy { + public: + static const char kDBusInterfaceName[]; + static const char kDBusPath[]; + + DHCPCDProxy(unsigned int pid, + DBus::Connection *connection, + const char *service); + + // Signal callbacks inherited from dhcpcd_proxy. + virtual void Event( + const uint32_t& pid, + const std::string& reason, + const std::map< std::string, DBus::Variant >& configuration); + virtual void StatusChanged(const uint32_t& pid, const std::string& status); + + private: + // Process ID of the associated dhcpcd process used for verification purposes + // only. + unsigned int pid_; + + DISALLOW_COPY_AND_ASSIGN(DHCPCDProxy); +}; + +} // namespace shill + +#endif // SHILL_DHCPCD_PROXY_ diff --git a/ipconfig.cc b/ipconfig.cc index 2d4869b0..af140034 100644 --- a/ipconfig.cc +++ b/ipconfig.cc @@ -12,7 +12,7 @@ using std::string; namespace shill { -IPConfig::IPConfig(const Device *device) : device_(device) { +IPConfig::IPConfig(const Device &device) : device_(device) { VLOG(2) << "IPConfig created."; } @@ -21,7 +21,7 @@ IPConfig::~IPConfig() { } const string &IPConfig::GetDeviceName() const { - return device()->Name(); + return device().Name(); } } // namespace shill @@ -17,17 +17,17 @@ class Device; // class. class IPConfig : public base::RefCounted<IPConfig> { public: - explicit IPConfig(const Device *device); + explicit IPConfig(const Device &device); virtual ~IPConfig(); - const Device *device() const { return device_; } + const Device &device() const { return device_; } const std::string &GetDeviceName() const; private: friend class base::RefCounted<IPConfig>; - const Device *device_; + const Device &device_; DISALLOW_COPY_AND_ASSIGN(IPConfig); }; diff --git a/ipconfig_unittest.cc b/ipconfig_unittest.cc index 8cc7182f..1210c618 100644 --- a/ipconfig_unittest.cc +++ b/ipconfig_unittest.cc @@ -20,7 +20,7 @@ class IPConfigTest : public Test { }; TEST_F(IPConfigTest, GetDeviceNameTest) { - scoped_refptr<IPConfig> ipconfig(new IPConfig(device_.get())); + scoped_refptr<IPConfig> ipconfig(new IPConfig(*device_)); EXPECT_EQ("testname", ipconfig->GetDeviceName()); } |