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/device.cc b/patchpanel/device.cc
new file mode 100644
index 0000000..1a1c61a
--- /dev/null
+++ b/patchpanel/device.cc
@@ -0,0 +1,82 @@
+// Copyright 2018 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.
+
+#include "patchpanel/device.h"
+
+#include <arpa/inet.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+
+#include <map>
+#include <utility>
+
+#include <base/bind.h>
+#include <base/lazy_instance.h>
+#include <base/logging.h>
+
+#include "patchpanel/crostini_service.h"
+#include "patchpanel/net_util.h"
+
+namespace patchpanel {
+
+Device::Config::Config(const MacAddress& mac_addr,
+ std::unique_ptr<Subnet> ipv4_subnet,
+ std::unique_ptr<SubnetAddress> host_ipv4_addr,
+ std::unique_ptr<SubnetAddress> guest_ipv4_addr,
+ std::unique_ptr<Subnet> lxd_ipv4_subnet)
+ : mac_addr_(mac_addr),
+ ipv4_subnet_(std::move(ipv4_subnet)),
+ host_ipv4_addr_(std::move(host_ipv4_addr)),
+ guest_ipv4_addr_(std::move(guest_ipv4_addr)),
+ lxd_ipv4_subnet_(std::move(lxd_ipv4_subnet)) {}
+
+Device::Device(const std::string& phys_ifname,
+ const std::string& host_ifname,
+ const std::string& guest_ifname,
+ std::unique_ptr<Device::Config> config,
+ const Device::Options& options)
+ : phys_ifname_(phys_ifname),
+ host_ifname_(host_ifname),
+ guest_ifname_(guest_ifname),
+ config_(std::move(config)),
+ options_(options) {
+ DCHECK(config_);
+}
+
+Device::Config& Device::config() const {
+ CHECK(config_);
+ return *config_.get();
+}
+
+void Device::Config::set_tap_ifname(const std::string& tap_ifname) {
+ tap_ = tap_ifname;
+}
+
+const std::string& Device::Config::tap_ifname() const {
+ return tap_;
+}
+
+std::unique_ptr<Device::Config> Device::release_config() {
+ return std::move(config_);
+}
+
+const Device::Options& Device::options() const {
+ return options_;
+}
+
+std::ostream& operator<<(std::ostream& stream, const Device& device) {
+ stream << "{ ifname: " << device.phys_ifname_
+ << ", bridge_ifname: " << device.host_ifname_ << ", bridge_ipv4_addr: "
+ << device.config_->host_ipv4_addr_->ToCidrString()
+ << ", guest_ifname: " << device.guest_ifname_ << ", guest_ipv4_addr: "
+ << device.config_->guest_ipv4_addr_->ToCidrString()
+ << ", guest_mac_addr: "
+ << MacAddressToString(device.config_->mac_addr())
+ << ", fwd_multicast: " << device.options_.fwd_multicast
+ << ", ipv6_enabled: " << device.options_.ipv6_enabled
+ << ", tap_ifname: " << device.config_->tap_ifname() << '}';
+ return stream;
+}
+
+} // namespace patchpanel