blob: 910e31da770126baee1ea958a36b05446fc56d6b [file] [log] [blame]
Kevin Cernekee95d4ae92016-06-19 10:26:29 -07001// 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 Abe3a7e5132018-02-15 13:07:50 +09005#ifndef ARC_NETWORK_MANAGER_H_
6#define ARC_NETWORK_MANAGER_H_
Kevin Cernekee95d4ae92016-06-19 10:26:29 -07007
Garrick Evans49879532018-12-03 13:15:36 +09008#include <map>
Kevin Cernekee95d4ae92016-06-19 10:26:29 -07009#include <memory>
Garrick Evans49879532018-12-03 13:15:36 +090010#include <set>
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070011#include <string>
12
13#include <base/memory/weak_ptr.h>
Garrick Evans96e03042019-05-28 14:30:52 +090014#include <base/message_loop/message_loop.h>
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070015#include <brillo/daemons/dbus_daemon.h>
Kevin Cernekee27bcaa62016-12-03 11:16:26 -080016#include <brillo/process_reaper.h>
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070017
Garrick Evansf4a93292019-03-13 14:19:43 +090018#include "arc/network/address_manager.h"
Hidehiko Abe3a7e5132018-02-15 13:07:50 +090019#include "arc/network/arc_ip_config.h"
Garrick Evans428e4762018-12-11 15:18:42 +090020#include "arc/network/device_manager.h"
Hidehiko Abe3a7e5132018-02-15 13:07:50 +090021#include "arc/network/helper_process.h"
Hidehiko Abe3a7e5132018-02-15 13:07:50 +090022#include "arc/network/shill_client.h"
Garrick Evans96e03042019-05-28 14:30:52 +090023#include "arc/network/socket.h"
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070024
25namespace arc_networkd {
26
27// Main class that runs the mainloop and responds to LAN interface changes.
Garrick Evans96e03042019-05-28 14:30:52 +090028class Manager final : public brillo::DBusDaemon,
29 public base::MessageLoopForIO::Watcher {
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070030 public:
Garrick Evans96e03042019-05-28 14:30:52 +090031 Manager(std::unique_ptr<HelperProcess> ip_helper,
32 std::unique_ptr<HelperProcess> adb_proxy,
33 bool enable_multinet);
34 ~Manager();
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070035
36 protected:
37 int OnInit() override;
38
Garrick Evans96e03042019-05-28 14:30:52 +090039 void OnFileCanReadWithoutBlocking(int fd) override;
40 void OnFileCanWriteWithoutBlocking(int fd) override {}
41
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070042 private:
Garrick Evans49879532018-12-03 13:15:36 +090043 void InitialSetup();
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070044
Kevin Cernekee27bcaa62016-12-03 11:16:26 -080045 // 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 Evans49879532018-12-03 13:15:36 +090049 // Callback from Daemon to notify that a signal was received and
Kevin Cernekee27bcaa62016-12-03 11:16:26 -080050 // the daemon should clean up in preparation to exit.
51 void OnShutdown(int* exit_code) override;
52
Garrick Evans96e03042019-05-28 14:30:52 +090053 // Processes notification messages received from guests.
54 void OnGuestNotification(const std::string& notification);
Garrick Evans49879532018-12-03 13:15:36 +090055
Garrick Evans96e03042019-05-28 14:30:52 +090056 // 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 Evans49879532018-12-03 13:15:36 +090061
Hugo Benichi935eca92018-07-03 13:47:24 +090062 friend std::ostream& operator<<(std::ostream& stream, const Manager& manager);
63
Garrick Evans96e03042019-05-28 14:30:52 +090064 std::unique_ptr<HelperProcess> ip_helper_;
65 std::unique_ptr<HelperProcess> adb_proxy_;
66
Garrick Evansf4a93292019-03-13 14:19:43 +090067 AddressManager addr_mgr_;
Kevin Cernekee27bcaa62016-12-03 11:16:26 -080068 brillo::ProcessReaper process_reaper_;
Garrick Evans428e4762018-12-11 15:18:42 +090069 std::unique_ptr<DeviceManager> device_mgr_;
Garrick Evansf4a93292019-03-13 14:19:43 +090070
71 bool enable_multinet_;
72
Garrick Evans96e03042019-05-28 14:30:52 +090073 Socket gsock_;
74 base::MessageLoopForIO::FileDescriptorWatcher gsock_watcher_;
75
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070076 base::WeakPtrFactory<Manager> weak_factory_{this};
Garrick Evansf4a93292019-03-13 14:19:43 +090077 DISALLOW_COPY_AND_ASSIGN(Manager);
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070078};
79
80} // namespace arc_networkd
81
Hidehiko Abe3a7e5132018-02-15 13:07:50 +090082#endif // ARC_NETWORK_MANAGER_H_