arc: Move platform2/arc/network/ to platform2/patchpanel
Next step in the arc-networkd -> patchpanel rename, this patch moves the
location of the code.
BUG=b:151879931
TEST=units,flashed image to atlas
TEST=tasts arc.PlayStore, crostini.LaunchTerminal.download
Change-Id: I1b5cf8d670e1631d46f6449b725395157bf88dde
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2115863
Tested-by: Garrick Evans <garrick@chromium.org>
Commit-Queue: Garrick Evans <garrick@chromium.org>
Reviewed-by: Hidehiko Abe <hidehiko@chromium.org>
Reviewed-by: Eric Caruso <ejcaruso@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Hugo Benichi <hugobenichi@google.com>
diff --git a/patchpanel/client.h b/patchpanel/client.h
new file mode 100644
index 0000000..e8403c2
--- /dev/null
+++ b/patchpanel/client.h
@@ -0,0 +1,80 @@
+// Copyright 2019 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef PATCHPANEL_CLIENT_H_
+#define PATCHPANEL_CLIENT_H_
+
+#include <memory>
+#include <utility>
+#include <vector>
+
+#include "base/files/scoped_file.h"
+#include <brillo/brillo_export.h>
+#include <dbus/bus.h>
+#include <dbus/object_proxy.h>
+#include <patchpanel/proto_bindings/patchpanel_service.pb.h>
+
+namespace patchpanel {
+
+// Simple wrapper around patchpanel DBus API. All public functions are
+// blocking DBus calls to patchpaneld.
+class BRILLO_EXPORT Client {
+ public:
+ static std::unique_ptr<Client> New();
+
+ Client(const scoped_refptr<dbus::Bus>& bus, dbus::ObjectProxy* proxy)
+ : bus_(std::move(bus)), proxy_(proxy) {}
+ ~Client();
+
+ bool NotifyArcStartup(pid_t pid);
+ bool NotifyArcShutdown();
+
+ std::vector<NetworkDevice> NotifyArcVmStartup(uint32_t cid);
+ bool NotifyArcVmShutdown(uint32_t cid);
+
+ bool NotifyTerminaVmStartup(uint32_t cid,
+ NetworkDevice* device,
+ IPv4Subnet* container_subnet);
+ bool NotifyTerminaVmShutdown(uint32_t cid);
+
+ bool NotifyPluginVmStartup(uint64_t vm_id,
+ int subnet_index,
+ NetworkDevice* device);
+ bool NotifyPluginVmShutdown(uint64_t vm_id);
+
+ // Reset the VPN routing intent mark on a socket to the default policy for
+ // the current uid. This is in general incorrect to call this method for
+ // a socket that is already connected.
+ bool DefaultVpnRouting(int socket);
+
+ // Mark a socket to be always routed through a VPN if there is one.
+ // Must be called before the socket is connected.
+ bool RouteOnVpn(int socket);
+
+ // Mark a socket to be always routed through the physical network.
+ // Must be called before the socket is connected.
+ bool BypassVpn(int socket);
+
+ // Sends a ConnectNamespaceRequest for the given namespace pid. Returns a
+ // pair with a valid ScopedFD and the ConnectNamespaceResponse proto message
+ // received if the request succeeded. Closing the ScopedFD will teardown the
+ // veth and routing setup and free the allocated IPv4 subnet.
+ std::pair<base::ScopedFD, patchpanel::ConnectNamespaceResponse>
+ ConnectNamespace(pid_t pid,
+ const std::string& outbound_ifname,
+ bool forward_user_traffic);
+
+ private:
+ scoped_refptr<dbus::Bus> bus_;
+ dbus::ObjectProxy* proxy_ = nullptr; // owned by bus_
+
+ bool SendSetVpnIntentRequest(int socket,
+ SetVpnIntentRequest::VpnRoutingPolicy policy);
+
+ DISALLOW_COPY_AND_ASSIGN(Client);
+};
+
+} // namespace patchpanel
+
+#endif // PATCHPANEL_CLIENT_H_