blob: 46c35b7c7293684d97865de32fc7df81ca7edbad [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
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 Cernekee27bcaa62016-12-03 11:16:26 -080017#include <brillo/process_reaper.h>
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070018
19#include "arc-networkd/arc_ip_config.h"
Kevin Cernekee27bcaa62016-12-03 11:16:26 -080020#include "arc-networkd/helper_process.h"
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070021#include "arc-networkd/multicast_forwarder.h"
22#include "arc-networkd/neighbor_finder.h"
Kevin Cernekee4e62cc12016-12-03 11:50:53 -080023#include "arc-networkd/options.h"
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070024#include "arc-networkd/router_finder.h"
25#include "arc-networkd/shill_client.h"
26
27namespace arc_networkd {
28
29// Main class that runs the mainloop and responds to LAN interface changes.
30class Manager final : public brillo::DBusDaemon {
31 public:
Kevin Cernekee27bcaa62016-12-03 11:16:26 -080032 explicit Manager(const Options& opt,
33 std::unique_ptr<HelperProcess> ip_helper);
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070034
35 protected:
36 int OnInit() override;
37
38 private:
39 // Called once, after the dbus connection is established.
40 void InitialSetup();
41
Kevin Cernekee27bcaa62016-12-03 11:16:26 -080042 // Delete ARC IPv6 address (if any).
43 void ClearArcIp();
44
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070045 // 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 Cernekee27bcaa62016-12-03 11:16:26 -080059 // 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 Cernekee95d4ae92016-06-19 10:26:29 -070067 // Persistent objects.
Kevin Cernekee27bcaa62016-12-03 11:16:26 -080068 brillo::ProcessReaper process_reaper_;
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070069 std::unique_ptr<ShillClient> shill_client_;
Kevin Cernekee27bcaa62016-12-03 11:16:26 -080070 std::unique_ptr<HelperProcess> ip_helper_;
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070071
72 std::string int_ifname_;
73 std::string lan_ifname_;
74 std::string con_ifname_;
75
Kevin Cernekee95d4ae92016-06-19 10:26:29 -070076 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_