Jie Jiang | 81c84db | 2020-09-29 17:40:16 +0900 | [diff] [blame] | 1 | // Copyright 2020 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 | #include "patchpanel/dbus/fake_client.h" |
| 6 | |
| 7 | namespace patchpanel { |
| 8 | |
Garrick Evans | d0a646e | 2020-11-25 21:08:32 +0900 | [diff] [blame] | 9 | void FakeClient::RegisterOnAvailableCallback( |
| 10 | base::RepeatingCallback<void(bool)> callback) {} |
| 11 | |
Garrick Evans | 6a06201 | 2021-02-15 09:25:44 +0900 | [diff] [blame] | 12 | void FakeClient::RegisterProcessChangedCallback( |
| 13 | base::RepeatingCallback<void(bool)> callback) {} |
| 14 | |
Jie Jiang | 81c84db | 2020-09-29 17:40:16 +0900 | [diff] [blame] | 15 | bool FakeClient::NotifyArcStartup(pid_t) { |
| 16 | return true; |
| 17 | } |
| 18 | |
| 19 | bool FakeClient::NotifyArcShutdown() { |
| 20 | return true; |
| 21 | } |
| 22 | |
| 23 | std::vector<NetworkDevice> FakeClient::NotifyArcVmStartup(uint32_t cid) { |
| 24 | return {}; |
| 25 | } |
| 26 | |
| 27 | bool FakeClient::NotifyArcVmShutdown(uint32_t cid) { |
| 28 | return true; |
| 29 | } |
| 30 | |
| 31 | bool FakeClient::NotifyTerminaVmStartup(uint32_t cid, |
| 32 | NetworkDevice* device, |
| 33 | IPv4Subnet* container_subnet) { |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | bool FakeClient::NotifyTerminaVmShutdown(uint32_t cid) { |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | bool FakeClient::NotifyPluginVmStartup(uint64_t vm_id, |
| 42 | int subnet_index, |
| 43 | NetworkDevice* device) { |
| 44 | return true; |
| 45 | } |
| 46 | |
| 47 | bool FakeClient::NotifyPluginVmShutdown(uint64_t vm_id) { |
| 48 | return true; |
| 49 | } |
| 50 | |
| 51 | bool FakeClient::DefaultVpnRouting(int socket) { |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | bool FakeClient::RouteOnVpn(int socket) { |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | bool FakeClient::BypassVpn(int socket) { |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | std::pair<base::ScopedFD, patchpanel::ConnectNamespaceResponse> |
| 64 | FakeClient::ConnectNamespace(pid_t pid, |
| 65 | const std::string& outbound_ifname, |
Garrick Evans | 5869702 | 2020-12-03 12:41:13 +0900 | [diff] [blame] | 66 | bool forward_user_traffic, |
| 67 | bool route_on_vpn, |
| 68 | TrafficCounter::Source traffic_source) { |
Jie Jiang | 81c84db | 2020-09-29 17:40:16 +0900 | [diff] [blame] | 69 | return {}; |
| 70 | } |
| 71 | |
| 72 | void FakeClient::GetTrafficCounters(const std::set<std::string>& devices, |
| 73 | GetTrafficCountersCallback callback) { |
| 74 | if (devices.size() == 0) { |
| 75 | std::move(callback).Run( |
| 76 | {stored_traffic_counters_.begin(), stored_traffic_counters_.end()}); |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | std::vector<TrafficCounter> return_counters; |
| 81 | for (const auto& counter : stored_traffic_counters_) { |
| 82 | if (devices.find(counter.device()) != devices.end()) |
| 83 | return_counters.push_back(counter); |
| 84 | } |
| 85 | |
| 86 | std::move(callback).Run({return_counters.begin(), return_counters.end()}); |
| 87 | } |
| 88 | |
| 89 | bool FakeClient::ModifyPortRule( |
| 90 | patchpanel::ModifyPortRuleRequest::Operation op, |
| 91 | patchpanel::ModifyPortRuleRequest::RuleType type, |
| 92 | patchpanel::ModifyPortRuleRequest::Protocol proto, |
| 93 | const std::string& input_ifname, |
| 94 | const std::string& input_dst_ip, |
| 95 | uint32_t input_dst_port, |
| 96 | const std::string& dst_ip, |
| 97 | uint32_t dst_port) { |
| 98 | return true; |
| 99 | } |
| 100 | |
Hugo Benichi | 007abcc | 2021-05-14 10:44:45 +0900 | [diff] [blame] | 101 | bool FakeClient::SetVpnLockdown(bool enable) { |
| 102 | return true; |
| 103 | } |
| 104 | |
Garrick Evans | 9e63798 | 2020-11-30 11:59:27 +0900 | [diff] [blame] | 105 | std::vector<NetworkDevice> FakeClient::GetDevices() { |
| 106 | return {}; |
| 107 | } |
| 108 | |
Garrick Evans | f04f044 | 2020-12-01 12:36:44 +0900 | [diff] [blame] | 109 | void FakeClient::RegisterNetworkDeviceChangedSignalHandler( |
| 110 | NetworkDeviceChangedSignalHandler handler) { |
| 111 | network_device_changed_handler_ = handler; |
| 112 | } |
| 113 | |
Jie Jiang | 25c1b97 | 2020-11-12 15:42:53 +0900 | [diff] [blame] | 114 | void FakeClient::RegisterNeighborReachabilityEventHandler( |
| 115 | NeighborReachabilityEventHandler handler) { |
Jie Jiang | 81c84db | 2020-09-29 17:40:16 +0900 | [diff] [blame] | 116 | neighbor_handlers_.push_back(handler); |
| 117 | } |
| 118 | |
Jie Jiang | 25c1b97 | 2020-11-12 15:42:53 +0900 | [diff] [blame] | 119 | void FakeClient::TriggerNeighborReachabilityEvent( |
| 120 | const NeighborReachabilityEventSignal& signal) { |
Jie Jiang | 81c84db | 2020-09-29 17:40:16 +0900 | [diff] [blame] | 121 | for (const auto& handler : neighbor_handlers_) |
| 122 | handler.Run(signal); |
| 123 | } |
| 124 | |
| 125 | } // namespace patchpanel |