Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 | |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 5 | #ifndef ARC_NETWORK_MANAGER_H_ |
| 6 | #define ARC_NETWORK_MANAGER_H_ |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 7 | |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 8 | #include <map> |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 9 | #include <memory> |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 10 | #include <set> |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 11 | #include <string> |
| 12 | |
| 13 | #include <base/memory/weak_ptr.h> |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame^] | 14 | #include <base/message_loop/message_loop.h> |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 15 | #include <brillo/daemons/dbus_daemon.h> |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 16 | #include <brillo/process_reaper.h> |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 17 | |
Garrick Evans | f4a9329 | 2019-03-13 14:19:43 +0900 | [diff] [blame] | 18 | #include "arc/network/address_manager.h" |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 19 | #include "arc/network/arc_ip_config.h" |
Garrick Evans | 428e476 | 2018-12-11 15:18:42 +0900 | [diff] [blame] | 20 | #include "arc/network/device_manager.h" |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 21 | #include "arc/network/helper_process.h" |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 22 | #include "arc/network/shill_client.h" |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame^] | 23 | #include "arc/network/socket.h" |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 24 | |
| 25 | namespace arc_networkd { |
| 26 | |
| 27 | // Main class that runs the mainloop and responds to LAN interface changes. |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame^] | 28 | class Manager final : public brillo::DBusDaemon, |
| 29 | public base::MessageLoopForIO::Watcher { |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 30 | public: |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame^] | 31 | Manager(std::unique_ptr<HelperProcess> ip_helper, |
| 32 | std::unique_ptr<HelperProcess> adb_proxy, |
| 33 | bool enable_multinet); |
| 34 | ~Manager(); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 35 | |
| 36 | protected: |
| 37 | int OnInit() override; |
| 38 | |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame^] | 39 | void OnFileCanReadWithoutBlocking(int fd) override; |
| 40 | void OnFileCanWriteWithoutBlocking(int fd) override {} |
| 41 | |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 42 | private: |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 43 | void InitialSetup(); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 44 | |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 45 | // Callback from ProcessReaper to notify Manager that one of the |
| 46 | // subprocesses died. |
| 47 | void OnSubprocessExited(pid_t pid, const siginfo_t& info); |
| 48 | |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 49 | // Callback from Daemon to notify that a signal was received and |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 50 | // the daemon should clean up in preparation to exit. |
| 51 | void OnShutdown(int* exit_code) override; |
| 52 | |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame^] | 53 | // Processes notification messages received from guests. |
| 54 | void OnGuestNotification(const std::string& notification); |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 55 | |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame^] | 56 | // Relays guest messages to the helper processes. |
| 57 | void SendGuestMessage(const GuestMessage& msg); |
| 58 | |
| 59 | // Relays device messages to the IpHelper process. |
| 60 | void SendDeviceMessage(const DeviceMessage& msg); |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame] | 61 | |
Hugo Benichi | 935eca9 | 2018-07-03 13:47:24 +0900 | [diff] [blame] | 62 | friend std::ostream& operator<<(std::ostream& stream, const Manager& manager); |
| 63 | |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame^] | 64 | std::unique_ptr<HelperProcess> ip_helper_; |
| 65 | std::unique_ptr<HelperProcess> adb_proxy_; |
| 66 | |
Garrick Evans | f4a9329 | 2019-03-13 14:19:43 +0900 | [diff] [blame] | 67 | AddressManager addr_mgr_; |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 68 | brillo::ProcessReaper process_reaper_; |
Garrick Evans | 428e476 | 2018-12-11 15:18:42 +0900 | [diff] [blame] | 69 | std::unique_ptr<DeviceManager> device_mgr_; |
Garrick Evans | f4a9329 | 2019-03-13 14:19:43 +0900 | [diff] [blame] | 70 | |
| 71 | bool enable_multinet_; |
| 72 | |
Garrick Evans | 96e0304 | 2019-05-28 14:30:52 +0900 | [diff] [blame^] | 73 | Socket gsock_; |
| 74 | base::MessageLoopForIO::FileDescriptorWatcher gsock_watcher_; |
| 75 | |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 76 | base::WeakPtrFactory<Manager> weak_factory_{this}; |
Garrick Evans | f4a9329 | 2019-03-13 14:19:43 +0900 | [diff] [blame] | 77 | DISALLOW_COPY_AND_ASSIGN(Manager); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace arc_networkd |
| 81 | |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 82 | #endif // ARC_NETWORK_MANAGER_H_ |