Garrick Evans | 0884393 | 2019-09-17 14:41:08 +0900 | [diff] [blame] | 1 | // Copyright 2019 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_NETWORK_CLIENT_H_ |
| 6 | #define ARC_NETWORK_CLIENT_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <utility> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include <brillo/brillo_export.h> |
| 13 | #include <dbus/bus.h> |
| 14 | #include <dbus/object_proxy.h> |
Hugo Benichi | 8135e56 | 2019-12-12 15:56:36 +0900 | [diff] [blame] | 15 | #include <patchpanel/proto_bindings/patchpanel_service.pb.h> |
Garrick Evans | 0884393 | 2019-09-17 14:41:08 +0900 | [diff] [blame] | 16 | |
| 17 | namespace patchpanel { |
| 18 | |
Hugo Benichi | 7d9d8db | 2020-03-30 15:56:56 +0900 | [diff] [blame] | 19 | // Simple wrapper around patchpanel DBus API. All public functions are |
| 20 | // blocking DBus calls to patchpaneld. |
Garrick Evans | 0884393 | 2019-09-17 14:41:08 +0900 | [diff] [blame] | 21 | class BRILLO_EXPORT Client { |
| 22 | public: |
| 23 | static std::unique_ptr<Client> New(); |
| 24 | |
Garrick Evans | 93a83fc | 2020-03-31 15:16:55 +0900 | [diff] [blame] | 25 | Client(const scoped_refptr<dbus::Bus>& bus, dbus::ObjectProxy* proxy) |
Garrick Evans | 0884393 | 2019-09-17 14:41:08 +0900 | [diff] [blame] | 26 | : bus_(std::move(bus)), proxy_(proxy) {} |
Garrick Evans | 93a83fc | 2020-03-31 15:16:55 +0900 | [diff] [blame] | 27 | ~Client(); |
Garrick Evans | 0884393 | 2019-09-17 14:41:08 +0900 | [diff] [blame] | 28 | |
| 29 | bool NotifyArcStartup(pid_t pid); |
Garrick Evans | ca2b41b | 2019-12-02 09:06:11 +0900 | [diff] [blame] | 30 | bool NotifyArcShutdown(); |
Garrick Evans | 27b7403 | 2019-11-19 13:33:47 +0900 | [diff] [blame] | 31 | |
Garrick Evans | 0a18937 | 2020-02-07 08:55:27 +0900 | [diff] [blame] | 32 | std::vector<patchpanel::Device> NotifyArcVmStartup(uint32_t cid); |
| 33 | bool NotifyArcVmShutdown(uint32_t cid); |
Garrick Evans | 0884393 | 2019-09-17 14:41:08 +0900 | [diff] [blame] | 34 | |
Garrick Evans | 0a18937 | 2020-02-07 08:55:27 +0900 | [diff] [blame] | 35 | bool NotifyTerminaVmStartup(uint32_t cid, |
Garrick Evans | 27b7403 | 2019-11-19 13:33:47 +0900 | [diff] [blame] | 36 | patchpanel::Device* device, |
| 37 | patchpanel::IPv4Subnet* container_subnet); |
Garrick Evans | 0a18937 | 2020-02-07 08:55:27 +0900 | [diff] [blame] | 38 | bool NotifyTerminaVmShutdown(uint32_t cid); |
Garrick Evans | 27b7403 | 2019-11-19 13:33:47 +0900 | [diff] [blame] | 39 | |
Garrick Evans | 376f067 | 2020-01-07 15:31:50 +0900 | [diff] [blame] | 40 | bool NotifyPluginVmStartup(uint64_t vm_id, |
| 41 | int subnet_index, |
| 42 | patchpanel::Device* device); |
| 43 | bool NotifyPluginVmShutdown(uint64_t vm_id); |
| 44 | |
Hugo Benichi | 7d9d8db | 2020-03-30 15:56:56 +0900 | [diff] [blame] | 45 | // Reset the VPN routing intent mark on a socket to the default policy for |
| 46 | // the current uid. This is in general incorrect to call this method for |
| 47 | // a socket that is already connected. |
| 48 | bool DefaultVpnRouting(int socket); |
| 49 | |
| 50 | // Mark a socket to be always routed through a VPN if there is one. |
| 51 | // Must be called before the socket is connected. |
| 52 | bool RouteOnVpn(int socket); |
| 53 | |
| 54 | // Mark a socket to be always routed through the physical network. |
| 55 | // Must be called before the socket is connected. |
| 56 | bool BypassVpn(int socket); |
| 57 | |
Garrick Evans | 0884393 | 2019-09-17 14:41:08 +0900 | [diff] [blame] | 58 | private: |
| 59 | scoped_refptr<dbus::Bus> bus_; |
| 60 | dbus::ObjectProxy* proxy_ = nullptr; // owned by bus_ |
| 61 | |
Hugo Benichi | 7d9d8db | 2020-03-30 15:56:56 +0900 | [diff] [blame] | 62 | bool SendSetVpnIntentRequest(int socket, |
| 63 | SetVpnIntentRequest::VpnRoutingPolicy policy); |
| 64 | |
Garrick Evans | 0884393 | 2019-09-17 14:41:08 +0900 | [diff] [blame] | 65 | DISALLOW_COPY_AND_ASSIGN(Client); |
| 66 | }; |
| 67 | |
| 68 | } // namespace patchpanel |
| 69 | |
| 70 | #endif // ARC_NETWORK_CLIENT_H_ |