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> |
| 17 | |
| 18 | #include "arc-networkd/arc_ip_config.h" |
| 19 | #include "arc-networkd/multicast_forwarder.h" |
| 20 | #include "arc-networkd/neighbor_finder.h" |
| 21 | #include "arc-networkd/router_finder.h" |
| 22 | #include "arc-networkd/shill_client.h" |
| 23 | |
| 24 | namespace arc_networkd { |
| 25 | |
| 26 | // Main class that runs the mainloop and responds to LAN interface changes. |
| 27 | class Manager final : public brillo::DBusDaemon { |
| 28 | public: |
| 29 | struct Options { |
| 30 | std::string int_ifname; |
| 31 | std::string con_ifname; |
| 32 | pid_t con_netns; |
| 33 | }; |
| 34 | |
| 35 | explicit Manager(const Options& opt); |
| 36 | |
| 37 | protected: |
| 38 | int OnInit() override; |
| 39 | |
| 40 | private: |
| 41 | // Called once, after the dbus connection is established. |
| 42 | void InitialSetup(); |
| 43 | |
| 44 | // Callback from ShillClient, invoked whenever the default network |
| 45 | // interface changes or goes away. |
| 46 | void OnDefaultInterfaceChanged(const std::string& ifname); |
| 47 | |
| 48 | // Callback from RouterFinder. May be triggered multiple times, e.g. |
| 49 | // if the route disappears or changes. |
| 50 | void OnRouteFound(const struct in6_addr& prefix, |
| 51 | int prefix_len, |
| 52 | const struct in6_addr& router); |
| 53 | |
| 54 | // Callback from NeighborFinder to indicate whether an IPv6 address |
| 55 | // collision was found or not found. |
| 56 | void OnNeighborCheckResult(bool found); |
| 57 | |
| 58 | // Persistent objects. |
| 59 | std::unique_ptr<ShillClient> shill_client_; |
| 60 | std::unique_ptr<ArcIpConfig> arc_ip_config_; |
| 61 | int con_init_tries_; |
| 62 | |
| 63 | std::string int_ifname_; |
| 64 | std::string lan_ifname_; |
| 65 | std::string con_ifname_; |
| 66 | |
| 67 | pid_t con_netns_; |
| 68 | struct in6_addr random_address_; |
| 69 | int random_address_prefix_len_; |
| 70 | int random_address_tries_; |
| 71 | |
| 72 | // These get nuked every time the connection changes. Deletion of |
| 73 | // the object immediately stops all callbacks and activity on the |
| 74 | // old interface. |
| 75 | std::unique_ptr<MulticastForwarder> mdns_forwarder_; |
| 76 | std::unique_ptr<MulticastForwarder> ssdp_forwarder_; |
| 77 | std::unique_ptr<RouterFinder> router_finder_; |
| 78 | std::unique_ptr<NeighborFinder> neighbor_finder_; |
| 79 | |
| 80 | base::WeakPtrFactory<Manager> weak_factory_{this}; |
| 81 | }; |
| 82 | |
| 83 | } // namespace arc_networkd |
| 84 | |
| 85 | #endif // ARC_NETWORKD_MANAGER_H_ |