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 | |
| 5 | #ifndef ARC_NETWORKD_MANAGER_H_ |
| 6 | #define ARC_NETWORKD_MANAGER_H_ |
| 7 | |
| 8 | #include <netinet/in.h> |
| 9 | #include <sys/socket.h> |
| 10 | #include <unistd.h> |
| 11 | |
| 12 | #include <memory> |
| 13 | #include <string> |
| 14 | |
| 15 | #include <base/memory/weak_ptr.h> |
| 16 | #include <brillo/daemons/dbus_daemon.h> |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame^] | 17 | #include <brillo/process_reaper.h> |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 18 | |
| 19 | #include "arc-networkd/arc_ip_config.h" |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame^] | 20 | #include "arc-networkd/helper_process.h" |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 21 | #include "arc-networkd/multicast_forwarder.h" |
| 22 | #include "arc-networkd/neighbor_finder.h" |
Kevin Cernekee | 4e62cc1 | 2016-12-03 11:50:53 -0800 | [diff] [blame] | 23 | #include "arc-networkd/options.h" |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 24 | #include "arc-networkd/router_finder.h" |
| 25 | #include "arc-networkd/shill_client.h" |
| 26 | |
| 27 | namespace arc_networkd { |
| 28 | |
| 29 | // Main class that runs the mainloop and responds to LAN interface changes. |
| 30 | class Manager final : public brillo::DBusDaemon { |
| 31 | public: |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame^] | 32 | explicit Manager(const Options& opt, |
| 33 | std::unique_ptr<HelperProcess> ip_helper); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 34 | |
| 35 | protected: |
| 36 | int OnInit() override; |
| 37 | |
| 38 | private: |
| 39 | // Called once, after the dbus connection is established. |
| 40 | void InitialSetup(); |
| 41 | |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame^] | 42 | // Delete ARC IPv6 address (if any). |
| 43 | void ClearArcIp(); |
| 44 | |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 45 | // Callback from ShillClient, invoked whenever the default network |
| 46 | // interface changes or goes away. |
| 47 | void OnDefaultInterfaceChanged(const std::string& ifname); |
| 48 | |
| 49 | // Callback from RouterFinder. May be triggered multiple times, e.g. |
| 50 | // if the route disappears or changes. |
| 51 | void OnRouteFound(const struct in6_addr& prefix, |
| 52 | int prefix_len, |
| 53 | const struct in6_addr& router); |
| 54 | |
| 55 | // Callback from NeighborFinder to indicate whether an IPv6 address |
| 56 | // collision was found or not found. |
| 57 | void OnNeighborCheckResult(bool found); |
| 58 | |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame^] | 59 | // Callback from ProcessReaper to notify Manager that one of the |
| 60 | // subprocesses died. |
| 61 | void OnSubprocessExited(pid_t pid, const siginfo_t& info); |
| 62 | |
| 63 | // Callback from Daemon to notify Manager that a signal was received and |
| 64 | // the daemon should clean up in preparation to exit. |
| 65 | void OnShutdown(int* exit_code) override; |
| 66 | |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 67 | // Persistent objects. |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame^] | 68 | brillo::ProcessReaper process_reaper_; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 69 | std::unique_ptr<ShillClient> shill_client_; |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame^] | 70 | std::unique_ptr<HelperProcess> ip_helper_; |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 71 | |
| 72 | std::string int_ifname_; |
| 73 | std::string lan_ifname_; |
| 74 | std::string con_ifname_; |
| 75 | |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 76 | struct in6_addr random_address_; |
| 77 | int random_address_prefix_len_; |
| 78 | int random_address_tries_; |
| 79 | |
| 80 | // These get nuked every time the connection changes. Deletion of |
| 81 | // the object immediately stops all callbacks and activity on the |
| 82 | // old interface. |
| 83 | std::unique_ptr<MulticastForwarder> mdns_forwarder_; |
| 84 | std::unique_ptr<MulticastForwarder> ssdp_forwarder_; |
| 85 | std::unique_ptr<RouterFinder> router_finder_; |
| 86 | std::unique_ptr<NeighborFinder> neighbor_finder_; |
| 87 | |
| 88 | base::WeakPtrFactory<Manager> weak_factory_{this}; |
| 89 | }; |
| 90 | |
| 91 | } // namespace arc_networkd |
| 92 | |
| 93 | #endif // ARC_NETWORKD_MANAGER_H_ |