Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_DEVICE_INFO_ |
| 6 | #define SHILL_DEVICE_INFO_ |
| 7 | |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 8 | #include <map> |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 9 | #include <set> |
| 10 | #include <string> |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 11 | #include <vector> |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 12 | |
Chris Masone | 487b8bf | 2011-05-13 16:27:57 -0700 | [diff] [blame] | 13 | #include <base/callback_old.h> |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 14 | #include <base/memory/ref_counted.h> |
Chris Masone | 487b8bf | 2011-05-13 16:27:57 -0700 | [diff] [blame] | 15 | #include <base/memory/scoped_ptr.h> |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 16 | #include <gtest/gtest_prod.h> // for FRIEND_TEST |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 17 | |
Darin Petkov | e3e1cfa | 2011-08-11 13:41:17 -0700 | [diff] [blame] | 18 | #include "shill/byte_string.h" |
Chris Masone | 9be4a9d | 2011-05-16 15:44:09 -0700 | [diff] [blame] | 19 | #include "shill/device.h" |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 20 | #include "shill/ip_address.h" |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 21 | #include "shill/rtnl_listener.h" |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 22 | |
| 23 | namespace shill { |
| 24 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 25 | class Manager; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 26 | class RTNLHandler; |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 27 | class RTNLMessage; |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 28 | |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 29 | class DeviceInfo { |
| 30 | public: |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 31 | struct AddressData { |
| 32 | AddressData() |
Paul Stewart | 7355ce1 | 2011-09-02 10:47:01 -0700 | [diff] [blame] | 33 | : address(IPAddress::kFamilyUnknown), flags(0), scope(0) {} |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 34 | AddressData(const IPAddress &address_in, |
| 35 | unsigned char flags_in, |
| 36 | unsigned char scope_in) |
| 37 | : address(address_in), flags(flags_in), scope(scope_in) {} |
| 38 | IPAddress address; |
| 39 | unsigned char flags; |
| 40 | unsigned char scope; |
| 41 | }; |
| 42 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 43 | DeviceInfo(ControlInterface *control_interface, |
| 44 | EventDispatcher *dispatcher, |
| 45 | Manager *manager); |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 46 | ~DeviceInfo(); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 47 | |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 48 | void AddDeviceToBlackList(const std::string &device_name); |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 49 | void Start(); |
| 50 | void Stop(); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 51 | |
Darin Petkov | 6f9eaa3 | 2011-08-09 15:26:44 -0700 | [diff] [blame] | 52 | // Adds |device| to this DeviceInfo instance so that we can handle its link |
| 53 | // messages, and registers it with the manager. |
| 54 | void RegisterDevice(const DeviceRefPtr &device); |
| 55 | |
Darin Petkov | e3e1cfa | 2011-08-11 13:41:17 -0700 | [diff] [blame] | 56 | DeviceRefPtr GetDevice(int interface_index) const; |
Paul Stewart | 3285296 | 2011-08-30 14:06:53 -0700 | [diff] [blame] | 57 | virtual bool GetMACAddress(int interface_index, ByteString *address) const; |
Chris Masone | 626719f | 2011-08-18 16:58:48 -0700 | [diff] [blame] | 58 | virtual bool GetFlags(int interface_index, unsigned int *flags) const; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 59 | virtual bool GetAddresses(int interface_index, |
| 60 | std::vector<AddressData> *addresses) const; |
| 61 | virtual void FlushAddresses(int interface_index) const; |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 62 | |
| 63 | private: |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 64 | friend class DeviceInfoTest; |
Darin Petkov | 0828f5f | 2011-08-11 10:18:52 -0700 | [diff] [blame] | 65 | FRIEND_TEST(CellularTest, StartLinked); |
Darin Petkov | 887f298 | 2011-07-14 16:10:17 -0700 | [diff] [blame] | 66 | |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 67 | struct Info { |
| 68 | Info() : flags(0) {} |
| 69 | |
| 70 | DeviceRefPtr device; |
Paul Stewart | 3285296 | 2011-08-30 14:06:53 -0700 | [diff] [blame] | 71 | ByteString mac_address; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 72 | std::vector<AddressData> ip_addresses; |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 73 | unsigned int flags; |
| 74 | }; |
| 75 | |
Paul Stewart | bf1861b | 2011-08-23 15:45:35 -0700 | [diff] [blame] | 76 | static const char kInterfaceUevent[]; |
| 77 | static const char kInterfaceDriver[]; |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 78 | static const char *kModemDrivers[]; |
Paul Stewart | bf1861b | 2011-08-23 15:45:35 -0700 | [diff] [blame] | 79 | static const char kInterfaceIPv6Privacy[]; |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 80 | |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 81 | static Device::Technology GetDeviceTechnology(const std::string &face_name); |
Darin Petkov | 6f9eaa3 | 2011-08-09 15:26:44 -0700 | [diff] [blame] | 82 | |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 83 | void AddLinkMsgHandler(const RTNLMessage &msg); |
| 84 | void DelLinkMsgHandler(const RTNLMessage &msg); |
| 85 | void LinkMsgHandler(const RTNLMessage &msg); |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 86 | void AddressMsgHandler(const RTNLMessage &msg); |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 87 | |
Darin Petkov | e3e1cfa | 2011-08-11 13:41:17 -0700 | [diff] [blame] | 88 | const Info *GetInfo(int interface_index) const; |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 89 | void RemoveInfo(int interface_index); |
Paul Stewart | bf1861b | 2011-08-23 15:45:35 -0700 | [diff] [blame] | 90 | void EnableDeviceIPv6Privacy(const std::string &link_name); |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 91 | |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 92 | ControlInterface *control_interface_; |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 93 | EventDispatcher *dispatcher_; |
Paul Stewart | b50f0b9 | 2011-05-16 16:31:42 -0700 | [diff] [blame] | 94 | Manager *manager_; |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 95 | std::map<int, Info> infos_; |
Chris Masone | 2aa9707 | 2011-08-09 17:35:08 -0700 | [diff] [blame] | 96 | scoped_ptr<Callback1<const RTNLMessage &>::Type> link_callback_; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 97 | scoped_ptr<Callback1<const RTNLMessage &>::Type> address_callback_; |
Paul Stewart | a3c56f9 | 2011-05-26 07:08:52 -0700 | [diff] [blame] | 98 | scoped_ptr<RTNLListener> link_listener_; |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 99 | scoped_ptr<RTNLListener> address_listener_; |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 100 | std::set<std::string> black_list_; |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 101 | |
Paul Stewart | 9a90808 | 2011-08-31 12:18:48 -0700 | [diff] [blame] | 102 | // Cache copy of singleton |
| 103 | RTNLHandler *rtnl_handler_; |
| 104 | |
Darin Petkov | e6193c0 | 2011-08-11 12:42:40 -0700 | [diff] [blame] | 105 | DISALLOW_COPY_AND_ASSIGN(DeviceInfo); |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 106 | }; |
| 107 | |
Paul Stewart | 0af98bf | 2011-05-10 17:38:08 -0700 | [diff] [blame] | 108 | } // namespace shill |
| 109 | |
| 110 | #endif // SHILL_DEVICE_INFO_ |