blob: 20de53cf1751824f3d865b088d02be8e509c422b [file] [log] [blame]
Garrick Evans08843932019-09-17 14:41:08 +09001// 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 Benichi8135e562019-12-12 15:56:36 +090015#include <patchpanel/proto_bindings/patchpanel_service.pb.h>
Garrick Evans08843932019-09-17 14:41:08 +090016
17namespace patchpanel {
18
Hugo Benichi7d9d8db2020-03-30 15:56:56 +090019// Simple wrapper around patchpanel DBus API. All public functions are
20// blocking DBus calls to patchpaneld.
Garrick Evans08843932019-09-17 14:41:08 +090021class BRILLO_EXPORT Client {
22 public:
23 static std::unique_ptr<Client> New();
24
Garrick Evans93a83fc2020-03-31 15:16:55 +090025 Client(const scoped_refptr<dbus::Bus>& bus, dbus::ObjectProxy* proxy)
Garrick Evans08843932019-09-17 14:41:08 +090026 : bus_(std::move(bus)), proxy_(proxy) {}
Garrick Evans93a83fc2020-03-31 15:16:55 +090027 ~Client();
Garrick Evans08843932019-09-17 14:41:08 +090028
29 bool NotifyArcStartup(pid_t pid);
Garrick Evansca2b41b2019-12-02 09:06:11 +090030 bool NotifyArcShutdown();
Garrick Evans27b74032019-11-19 13:33:47 +090031
Garrick Evans0a189372020-02-07 08:55:27 +090032 std::vector<patchpanel::Device> NotifyArcVmStartup(uint32_t cid);
33 bool NotifyArcVmShutdown(uint32_t cid);
Garrick Evans08843932019-09-17 14:41:08 +090034
Garrick Evans0a189372020-02-07 08:55:27 +090035 bool NotifyTerminaVmStartup(uint32_t cid,
Garrick Evans27b74032019-11-19 13:33:47 +090036 patchpanel::Device* device,
37 patchpanel::IPv4Subnet* container_subnet);
Garrick Evans0a189372020-02-07 08:55:27 +090038 bool NotifyTerminaVmShutdown(uint32_t cid);
Garrick Evans27b74032019-11-19 13:33:47 +090039
Garrick Evans376f0672020-01-07 15:31:50 +090040 bool NotifyPluginVmStartup(uint64_t vm_id,
41 int subnet_index,
42 patchpanel::Device* device);
43 bool NotifyPluginVmShutdown(uint64_t vm_id);
44
Hugo Benichi7d9d8db2020-03-30 15:56:56 +090045 // 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 Evans08843932019-09-17 14:41:08 +090058 private:
59 scoped_refptr<dbus::Bus> bus_;
60 dbus::ObjectProxy* proxy_ = nullptr; // owned by bus_
61
Hugo Benichi7d9d8db2020-03-30 15:56:56 +090062 bool SendSetVpnIntentRequest(int socket,
63 SetVpnIntentRequest::VpnRoutingPolicy policy);
64
Garrick Evans08843932019-09-17 14:41:08 +090065 DISALLOW_COPY_AND_ASSIGN(Client);
66};
67
68} // namespace patchpanel
69
70#endif // ARC_NETWORK_CLIENT_H_