Garrick Evans | 5d55f5e | 2019-07-17 15:28:10 +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 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 5 | #include "patchpanel/arc_service.h" |
Garrick Evans | 5d55f5e | 2019-07-17 15:28:10 +0900 | [diff] [blame] | 6 | |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 7 | #include <linux/rtnetlink.h> |
| 8 | #include <net/if.h> |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 9 | #include <sys/ioctl.h> |
Garrick Evans | 71e4a86 | 2020-05-18 12:22:23 +0900 | [diff] [blame^] | 10 | #include <sys/utsname.h> |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 11 | |
Garrick Evans | 5d55f5e | 2019-07-17 15:28:10 +0900 | [diff] [blame] | 12 | #include <utility> |
Jason Jeremy Iman | f4156cb | 2019-11-14 15:36:22 +0900 | [diff] [blame] | 13 | #include <vector> |
Garrick Evans | 5d55f5e | 2019-07-17 15:28:10 +0900 | [diff] [blame] | 14 | |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 15 | #include <base/bind.h> |
Garrick Evans | 5d55f5e | 2019-07-17 15:28:10 +0900 | [diff] [blame] | 16 | #include <base/files/file_path.h> |
| 17 | #include <base/files/file_util.h> |
| 18 | #include <base/logging.h> |
| 19 | #include <base/strings/string_number_conversions.h> |
| 20 | #include <base/strings/string_util.h> |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 21 | #include <base/strings/stringprintf.h> |
Qijiang Fan | 2d7aeb4 | 2020-05-19 02:06:39 +0900 | [diff] [blame] | 22 | #include <base/system/sys_info.h> |
Garrick Evans | 1f5a361 | 2019-11-08 12:59:03 +0900 | [diff] [blame] | 23 | #include <brillo/key_value_store.h> |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 24 | #include <chromeos/constants/vm_tools.h> |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 25 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 26 | #include "patchpanel/datapath.h" |
| 27 | #include "patchpanel/mac_address_generator.h" |
| 28 | #include "patchpanel/manager.h" |
| 29 | #include "patchpanel/minijailed_process_runner.h" |
| 30 | #include "patchpanel/net_util.h" |
| 31 | #include "patchpanel/scoped_ns.h" |
Garrick Evans | 5d55f5e | 2019-07-17 15:28:10 +0900 | [diff] [blame] | 32 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 33 | namespace patchpanel { |
Garrick Evans | f29f5a3 | 2019-12-06 11:34:25 +0900 | [diff] [blame] | 34 | namespace test { |
| 35 | GuestMessage::GuestType guest = GuestMessage::UNKNOWN_GUEST; |
| 36 | } // namespace test |
| 37 | |
Garrick Evans | 5d55f5e | 2019-07-17 15:28:10 +0900 | [diff] [blame] | 38 | namespace { |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 39 | constexpr pid_t kInvalidPID = 0; |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 40 | constexpr uint32_t kInvalidCID = 0; |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 41 | constexpr char kArcIfname[] = "arc0"; |
| 42 | constexpr char kArcBridge[] = "arcbr0"; |
| 43 | constexpr char kArcVmIfname[] = "arc1"; |
| 44 | constexpr char kArcVmBridge[] = "arc_br1"; |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 45 | constexpr std::array<const char*, 2> kEthernetInterfacePrefixes{{"eth", "usb"}}; |
| 46 | constexpr std::array<const char*, 2> kWifiInterfacePrefixes{{"wlan", "mlan"}}; |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 47 | constexpr std::array<const char*, 2> kCellInterfacePrefixes{{"wwan", "rmnet"}}; |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 48 | |
Garrick Evans | 71e4a86 | 2020-05-18 12:22:23 +0900 | [diff] [blame^] | 49 | bool KernelVersion(int* major, int* minor) { |
| 50 | struct utsname u; |
| 51 | if (uname(&u) != 0) { |
| 52 | PLOG(ERROR) << "uname failed"; |
| 53 | *major = *minor = 0; |
| 54 | return false; |
| 55 | } |
| 56 | int unused; |
| 57 | if (sscanf(u.release, "%d.%d.%d", major, minor, &unused) != 3) { |
| 58 | LOG(ERROR) << "unexpected release string: " << u.release; |
| 59 | *major = *minor = 0; |
| 60 | return false; |
| 61 | } |
| 62 | return true; |
| 63 | } |
| 64 | |
Garrick Evans | 6d227b9 | 2019-12-03 16:11:29 +0900 | [diff] [blame] | 65 | void OneTimeSetup(const Datapath& datapath) { |
Garrick Evans | a34b586 | 2019-11-20 09:34:01 +0900 | [diff] [blame] | 66 | static bool done = false; |
| 67 | if (done) |
| 68 | return; |
| 69 | |
Garrick Evans | 6d227b9 | 2019-12-03 16:11:29 +0900 | [diff] [blame] | 70 | auto& runner = datapath.runner(); |
| 71 | |
| 72 | // Load networking modules needed by Android that are not compiled in the |
| 73 | // kernel. Android does not allow auto-loading of kernel modules. |
Garrick Evans | c53b970 | 2020-05-13 13:20:09 +0900 | [diff] [blame] | 74 | // Expected for all kernels. |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 75 | if (runner.modprobe_all({ |
Garrick Evans | a34b586 | 2019-11-20 09:34:01 +0900 | [diff] [blame] | 76 | // The netfilter modules needed by netd for iptables commands. |
| 77 | "ip6table_filter", |
| 78 | "ip6t_ipv6header", |
| 79 | "ip6t_REJECT", |
Garrick Evans | a34b586 | 2019-11-20 09:34:01 +0900 | [diff] [blame] | 80 | // The ipsec modules for AH and ESP encryption for ipv6. |
| 81 | "ah6", |
| 82 | "esp6", |
| 83 | }) != 0) { |
| 84 | LOG(ERROR) << "One or more required kernel modules failed to load." |
| 85 | << " Some Android functionality may be broken."; |
| 86 | } |
Garrick Evans | c53b970 | 2020-05-13 13:20:09 +0900 | [diff] [blame] | 87 | // The xfrm modules needed for Android's ipsec APIs on kernels < 5.4. |
Garrick Evans | 71e4a86 | 2020-05-18 12:22:23 +0900 | [diff] [blame^] | 88 | int major, minor; |
| 89 | if (KernelVersion(&major, &minor) && |
| 90 | (major < 5 || (major == 5 && minor < 4)) && |
| 91 | runner.modprobe_all({ |
| 92 | "xfrm4_mode_transport", |
| 93 | "xfrm4_mode_tunnel", |
| 94 | "xfrm6_mode_transport", |
| 95 | "xfrm6_mode_tunnel", |
| 96 | }) != 0) { |
Garrick Evans | c53b970 | 2020-05-13 13:20:09 +0900 | [diff] [blame] | 97 | LOG(ERROR) << "One or more required kernel modules failed to load." |
| 98 | << " Some Android functionality may be broken."; |
| 99 | } |
| 100 | |
Garrick Evans | a34b586 | 2019-11-20 09:34:01 +0900 | [diff] [blame] | 101 | // Optional modules. |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 102 | if (runner.modprobe_all({ |
Garrick Evans | a34b586 | 2019-11-20 09:34:01 +0900 | [diff] [blame] | 103 | // This module is not available in kernels < 3.18 |
| 104 | "nf_reject_ipv6", |
| 105 | // These modules are needed for supporting Chrome traffic on Android |
| 106 | // VPN which uses Android's NAT feature. Android NAT sets up |
| 107 | // iptables |
| 108 | // rules that use these conntrack modules for FTP/TFTP. |
| 109 | "nf_nat_ftp", |
| 110 | "nf_nat_tftp", |
Hugo Benichi | a0cde9e | 2019-12-16 11:57:20 +0900 | [diff] [blame] | 111 | // The tun module is needed by the Android 464xlat clatd process. |
| 112 | "tun", |
Garrick Evans | a34b586 | 2019-11-20 09:34:01 +0900 | [diff] [blame] | 113 | }) != 0) { |
| 114 | LOG(WARNING) << "One or more optional kernel modules failed to load."; |
| 115 | } |
| 116 | |
Garrick Evans | 6d227b9 | 2019-12-03 16:11:29 +0900 | [diff] [blame] | 117 | // This is only needed for CTS (b/27932574). |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 118 | if (runner.chown("655360", "655360", "/sys/class/xt_idletimer") != 0) { |
Garrick Evans | 6d227b9 | 2019-12-03 16:11:29 +0900 | [diff] [blame] | 119 | LOG(ERROR) << "Failed to change ownership of xt_idletimer."; |
| 120 | } |
| 121 | |
Garrick Evans | a34b586 | 2019-11-20 09:34:01 +0900 | [diff] [blame] | 122 | done = true; |
| 123 | } |
| 124 | |
Garrick Evans | 508a4bc | 2019-11-14 08:45:52 +0900 | [diff] [blame] | 125 | bool IsArcVm() { |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 126 | if (test::guest == GuestMessage::ARC_VM) { |
| 127 | LOG(WARNING) << "Overridden for testing"; |
| 128 | return true; |
| 129 | } |
| 130 | |
Garrick Evans | 508a4bc | 2019-11-14 08:45:52 +0900 | [diff] [blame] | 131 | const base::FilePath path("/run/chrome/is_arcvm"); |
| 132 | std::string contents; |
| 133 | if (!base::ReadFileToString(path, &contents)) { |
| 134 | PLOG(ERROR) << "Could not read " << path.value(); |
| 135 | } |
| 136 | return contents == "1"; |
| 137 | } |
| 138 | |
Garrick Evans | f29f5a3 | 2019-12-06 11:34:25 +0900 | [diff] [blame] | 139 | GuestMessage::GuestType ArcGuest() { |
| 140 | if (test::guest != GuestMessage::UNKNOWN_GUEST) |
| 141 | return test::guest; |
Garrick Evans | 508a4bc | 2019-11-14 08:45:52 +0900 | [diff] [blame] | 142 | |
Garrick Evans | b05a7ff | 2020-02-18 12:59:55 +0900 | [diff] [blame] | 143 | return IsArcVm() ? GuestMessage::ARC_VM : GuestMessage::ARC; |
Garrick Evans | 508a4bc | 2019-11-14 08:45:52 +0900 | [diff] [blame] | 144 | } |
| 145 | |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 146 | ArcService::InterfaceType InterfaceTypeFor(const std::string& ifname) { |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 147 | for (const auto& prefix : kEthernetInterfacePrefixes) { |
| 148 | if (base::StartsWith(ifname, prefix, |
| 149 | base::CompareCase::INSENSITIVE_ASCII)) { |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 150 | return ArcService::InterfaceType::ETHERNET; |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 151 | } |
| 152 | } |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 153 | for (const auto& prefix : kWifiInterfacePrefixes) { |
| 154 | if (base::StartsWith(ifname, prefix, |
| 155 | base::CompareCase::INSENSITIVE_ASCII)) { |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 156 | return ArcService::InterfaceType::WIFI; |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 157 | } |
| 158 | } |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 159 | for (const auto& prefix : kCellInterfacePrefixes) { |
| 160 | if (base::StartsWith(ifname, prefix, |
| 161 | base::CompareCase::INSENSITIVE_ASCII)) { |
| 162 | return ArcService::InterfaceType::CELL; |
| 163 | } |
| 164 | } |
| 165 | return ArcService::InterfaceType::UNKNOWN; |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | bool IsMulticastInterface(const std::string& ifname) { |
| 169 | if (ifname.empty()) { |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | int fd = socket(AF_INET, SOCK_DGRAM, 0); |
| 174 | if (fd < 0) { |
| 175 | // If IPv4 fails, try to open a socket using IPv6. |
| 176 | fd = socket(AF_INET6, SOCK_DGRAM, 0); |
| 177 | if (fd < 0) { |
| 178 | LOG(ERROR) << "Unable to create socket"; |
| 179 | return false; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | struct ifreq ifr; |
| 184 | memset(&ifr, 0, sizeof(ifr)); |
| 185 | strncpy(ifr.ifr_name, ifname.c_str(), IFNAMSIZ); |
| 186 | if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { |
| 187 | PLOG(ERROR) << "SIOCGIFFLAGS failed for " << ifname; |
| 188 | close(fd); |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | close(fd); |
| 193 | return (ifr.ifr_flags & IFF_MULTICAST); |
| 194 | } |
| 195 | |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 196 | // Returns the configuration for the ARC management interface used for VPN |
| 197 | // forwarding, ADB-over-TCP and single-networked ARCVM. |
| 198 | std::unique_ptr<Device::Config> MakeArcConfig(AddressManager* addr_mgr, |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 199 | AddressManager::Guest guest) { |
| 200 | auto ipv4_subnet = addr_mgr->AllocateIPv4Subnet(guest); |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 201 | if (!ipv4_subnet) { |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 202 | LOG(ERROR) << "Subnet already in use or unavailable"; |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 203 | return nullptr; |
| 204 | } |
| 205 | auto host_ipv4_addr = ipv4_subnet->AllocateAtOffset(0); |
| 206 | if (!host_ipv4_addr) { |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 207 | LOG(ERROR) << "Bridge address already in use or unavailable"; |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 208 | return nullptr; |
| 209 | } |
| 210 | auto guest_ipv4_addr = ipv4_subnet->AllocateAtOffset(1); |
| 211 | if (!guest_ipv4_addr) { |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 212 | LOG(ERROR) << "ARC address already in use or unavailable"; |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 213 | return nullptr; |
| 214 | } |
| 215 | |
| 216 | return std::make_unique<Device::Config>( |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 217 | addr_mgr->GenerateMacAddress(IsArcVm() ? 1 : kAnySubnetIndex), |
| 218 | std::move(ipv4_subnet), std::move(host_ipv4_addr), |
| 219 | std::move(guest_ipv4_addr)); |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 220 | } |
| 221 | |
Garrick Evans | 5d55f5e | 2019-07-17 15:28:10 +0900 | [diff] [blame] | 222 | } // namespace |
| 223 | |
Garrick Evans | 69b8587 | 2020-02-04 11:40:26 +0900 | [diff] [blame] | 224 | ArcService::ArcService(ShillClient* shill_client, |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 225 | Datapath* datapath, |
| 226 | AddressManager* addr_mgr, |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 227 | TrafficForwarder* forwarder, |
| 228 | bool enable_arcvm_multinet) |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 229 | : shill_client_(shill_client), |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 230 | datapath_(datapath), |
| 231 | addr_mgr_(addr_mgr), |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 232 | forwarder_(forwarder), |
| 233 | enable_arcvm_multinet_(enable_arcvm_multinet) { |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 234 | AllocateAddressConfigs(); |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 235 | shill_client_->RegisterDevicesChangedHandler( |
| 236 | base::Bind(&ArcService::OnDevicesChanged, weak_factory_.GetWeakPtr())); |
Jie Jiang | 84c76a1 | 2020-04-17 16:45:20 +0900 | [diff] [blame] | 237 | shill_client_->ScanDevices(); |
Garrick Evans | bbdf4b4 | 2020-03-05 12:59:06 +0900 | [diff] [blame] | 238 | shill_client_->RegisterDefaultInterfaceChangedHandler(base::Bind( |
| 239 | &ArcService::OnDefaultInterfaceChanged, weak_factory_.GetWeakPtr())); |
Garrick Evans | f29f5a3 | 2019-12-06 11:34:25 +0900 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | ArcService::~ArcService() { |
Garrick Evans | 664a82f | 2019-12-17 12:18:05 +0900 | [diff] [blame] | 243 | if (impl_) { |
Garrick Evans | 664a82f | 2019-12-17 12:18:05 +0900 | [diff] [blame] | 244 | Stop(impl_->id()); |
Garrick Evans | 664a82f | 2019-12-17 12:18:05 +0900 | [diff] [blame] | 245 | } |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 246 | } |
Garrick Evans | 5d55f5e | 2019-07-17 15:28:10 +0900 | [diff] [blame] | 247 | |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 248 | void ArcService::AllocateAddressConfigs() { |
| 249 | configs_.clear(); |
| 250 | // The first usable subnet is the "other" ARC device subnet. |
| 251 | // TODO(garrick): This can be removed and ARC_NET will be widened once ARCVM |
| 252 | // switches over to use .0/30. |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 253 | const bool is_arcvm = IsArcVm(); |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 254 | AddressManager::Guest alloc = |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 255 | is_arcvm ? AddressManager::Guest::ARC : AddressManager::Guest::VM_ARC; |
| 256 | // As a temporary workaround, for ARCVM, allocate fixed MAC addresses. |
| 257 | uint8_t mac_addr_index = 2; |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 258 | // Allocate 2 subnets each for Ethernet and WiFi and 1 for LTE WAN interfaces. |
| 259 | for (const auto itype : |
| 260 | {InterfaceType::ETHERNET, InterfaceType::ETHERNET, InterfaceType::WIFI, |
| 261 | InterfaceType::WIFI, InterfaceType::CELL}) { |
| 262 | auto ipv4_subnet = addr_mgr_->AllocateIPv4Subnet(alloc); |
| 263 | if (!ipv4_subnet) { |
| 264 | LOG(ERROR) << "Subnet already in use or unavailable"; |
| 265 | continue; |
| 266 | } |
| 267 | // For here out, use the same slices. |
| 268 | alloc = AddressManager::Guest::ARC_NET; |
| 269 | auto host_ipv4_addr = ipv4_subnet->AllocateAtOffset(0); |
| 270 | if (!host_ipv4_addr) { |
| 271 | LOG(ERROR) << "Bridge address already in use or unavailable"; |
| 272 | continue; |
| 273 | } |
| 274 | auto guest_ipv4_addr = ipv4_subnet->AllocateAtOffset(1); |
| 275 | if (!guest_ipv4_addr) { |
| 276 | LOG(ERROR) << "ARC address already in use or unavailable"; |
| 277 | continue; |
| 278 | } |
| 279 | |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 280 | MacAddress mac_addr = is_arcvm |
| 281 | ? addr_mgr_->GenerateMacAddress(mac_addr_index++) |
| 282 | : addr_mgr_->GenerateMacAddress(); |
| 283 | |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 284 | configs_[itype].emplace_back(std::make_unique<Device::Config>( |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 285 | mac_addr, std::move(ipv4_subnet), std::move(host_ipv4_addr), |
| 286 | std::move(guest_ipv4_addr))); |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 290 | std::vector<Device::Config*> ArcService::ReallocateAddressConfigs() { |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 291 | std::vector<std::string> existing_devices; |
| 292 | for (const auto& d : devices_) { |
| 293 | existing_devices.emplace_back(d.first); |
| 294 | } |
| 295 | for (const auto& d : existing_devices) { |
| 296 | RemoveDevice(d); |
| 297 | } |
| 298 | AllocateAddressConfigs(); |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 299 | std::vector<Device::Config*> configs; |
| 300 | if (enable_arcvm_multinet_) { |
| 301 | for (const auto& kv : configs_) |
| 302 | for (const auto& c : kv.second) |
| 303 | configs.push_back(c.get()); |
| 304 | } |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 305 | for (const auto& d : existing_devices) { |
| 306 | AddDevice(d); |
| 307 | } |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 308 | return configs; |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | std::unique_ptr<Device::Config> ArcService::AcquireConfig( |
| 312 | const std::string& ifname) { |
| 313 | auto itype = InterfaceTypeFor(ifname); |
| 314 | if (itype == InterfaceType::UNKNOWN) { |
| 315 | LOG(ERROR) << "Unsupported interface: " << ifname; |
| 316 | return nullptr; |
| 317 | } |
| 318 | |
| 319 | auto& configs = configs_[itype]; |
| 320 | if (configs.empty()) { |
| 321 | LOG(ERROR) << "No more addresses available. Cannot make device for " |
| 322 | << ifname; |
| 323 | return nullptr; |
| 324 | } |
| 325 | std::unique_ptr<Device::Config> config; |
| 326 | config = std::move(configs.front()); |
| 327 | configs.pop_front(); |
| 328 | return config; |
| 329 | } |
| 330 | |
| 331 | void ArcService::ReleaseConfig(const std::string& ifname, |
| 332 | std::unique_ptr<Device::Config> config) { |
| 333 | auto itype = InterfaceTypeFor(ifname); |
| 334 | if (itype == InterfaceType::UNKNOWN) { |
| 335 | LOG(ERROR) << "Unsupported interface: " << ifname; |
| 336 | return; |
| 337 | } |
| 338 | |
| 339 | configs_[itype].push_front(std::move(config)); |
| 340 | } |
| 341 | |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 342 | bool ArcService::Start(uint32_t id) { |
Garrick Evans | f29f5a3 | 2019-12-06 11:34:25 +0900 | [diff] [blame] | 343 | if (impl_) { |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 344 | uint32_t prev_id; |
Garrick Evans | f29f5a3 | 2019-12-06 11:34:25 +0900 | [diff] [blame] | 345 | if (impl_->IsStarted(&prev_id)) { |
| 346 | LOG(WARNING) << "Already running - did something crash?" |
| 347 | << " Stopping and restarting..."; |
| 348 | Stop(prev_id); |
| 349 | } |
Garrick Evans | a51d0a1 | 2019-11-28 13:51:23 +0900 | [diff] [blame] | 350 | } |
| 351 | |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 352 | auto configs = ReallocateAddressConfigs(); |
Garrick Evans | f29f5a3 | 2019-12-06 11:34:25 +0900 | [diff] [blame] | 353 | const auto guest = ArcGuest(); |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 354 | if (guest == GuestMessage::ARC_VM) { |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 355 | impl_ = std::make_unique<VmImpl>(shill_client_, datapath_, addr_mgr_, |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 356 | forwarder_, configs); |
| 357 | } else { |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 358 | impl_ = std::make_unique<ContainerImpl>(datapath_, addr_mgr_, forwarder_, |
| 359 | guest); |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 360 | } |
Garrick Evans | f29f5a3 | 2019-12-06 11:34:25 +0900 | [diff] [blame] | 361 | if (!impl_->Start(id)) { |
| 362 | impl_.reset(); |
Garrick Evans | 508a4bc | 2019-11-14 08:45:52 +0900 | [diff] [blame] | 363 | return false; |
Garrick Evans | f29f5a3 | 2019-12-06 11:34:25 +0900 | [diff] [blame] | 364 | } |
Garrick Evans | cb791e7 | 2019-11-11 15:44:34 +0900 | [diff] [blame] | 365 | |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 366 | // Start already known Shill <-> ARC mapped devices. |
| 367 | for (const auto& d : devices_) |
| 368 | StartDevice(d.second.get()); |
Garrick Evans | cb791e7 | 2019-11-11 15:44:34 +0900 | [diff] [blame] | 369 | |
Garrick Evans | f29f5a3 | 2019-12-06 11:34:25 +0900 | [diff] [blame] | 370 | return true; |
Garrick Evans | cb791e7 | 2019-11-11 15:44:34 +0900 | [diff] [blame] | 371 | } |
| 372 | |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 373 | void ArcService::Stop(uint32_t id) { |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 374 | // Stop Shill <-> ARC mapped devices. |
| 375 | for (const auto& d : devices_) |
| 376 | StopDevice(d.second.get()); |
Garrick Evans | f29f5a3 | 2019-12-06 11:34:25 +0900 | [diff] [blame] | 377 | |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 378 | if (impl_) { |
| 379 | impl_->Stop(id); |
| 380 | impl_.reset(); |
| 381 | } |
Garrick Evans | 5d55f5e | 2019-07-17 15:28:10 +0900 | [diff] [blame] | 382 | } |
| 383 | |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 384 | void ArcService::OnDevicesChanged(const std::set<std::string>& added, |
| 385 | const std::set<std::string>& removed) { |
| 386 | for (const std::string& name : removed) |
| 387 | RemoveDevice(name); |
| 388 | |
| 389 | for (const std::string& name : added) |
| 390 | AddDevice(name); |
| 391 | } |
| 392 | |
| 393 | void ArcService::AddDevice(const std::string& ifname) { |
| 394 | if (ifname.empty()) |
| 395 | return; |
| 396 | |
| 397 | if (devices_.find(ifname) != devices_.end()) { |
| 398 | LOG(DFATAL) << "Attemping to add already tracked device: " << ifname; |
| 399 | return; |
| 400 | } |
| 401 | |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 402 | auto itype = InterfaceTypeFor(ifname); |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 403 | Device::Options opts{ |
| 404 | .fwd_multicast = IsMulticastInterface(ifname), |
| 405 | // TODO(crbug/726815) Also enable |ipv6_enabled| for cellular networks |
| 406 | // once IPv6 is enabled on cellular networks in shill. |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 407 | .ipv6_enabled = |
| 408 | (itype == InterfaceType::ETHERNET || itype == InterfaceType::WIFI), |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 409 | }; |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 410 | |
| 411 | auto config = AcquireConfig(ifname); |
| 412 | if (!config) { |
| 413 | LOG(ERROR) << "Cannot add device for " << ifname; |
| 414 | return; |
| 415 | } |
| 416 | |
Garrick Evans | 8a06756 | 2020-05-11 12:47:30 +0900 | [diff] [blame] | 417 | auto device = std::make_unique<Device>(ifname, ArcBridgeName(ifname), ifname, |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 418 | std::move(config), opts); |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 419 | |
| 420 | StartDevice(device.get()); |
| 421 | devices_.emplace(ifname, std::move(device)); |
| 422 | } |
| 423 | |
| 424 | void ArcService::StartDevice(Device* device) { |
| 425 | if (!impl_ || !impl_->IsStarted()) |
| 426 | return; |
| 427 | |
| 428 | // For now, only start devices for ARC++. |
| 429 | if (impl_->guest() != GuestMessage::ARC) |
| 430 | return; |
| 431 | |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 432 | const auto& config = device->config(); |
| 433 | |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 434 | LOG(INFO) << "Adding device " << device->phys_ifname() |
| 435 | << " bridge: " << device->host_ifname() |
| 436 | << " guest_iface: " << device->guest_ifname(); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 437 | |
| 438 | // Create the bridge. |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 439 | if (!datapath_->AddBridge(device->host_ifname(), config.host_ipv4_addr(), |
Garrick Evans | 7a1a9ee | 2020-01-28 11:03:57 +0900 | [diff] [blame] | 440 | 30)) { |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 441 | LOG(ERROR) << "Failed to setup arc bridge: " << device->host_ifname(); |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 442 | return; |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 443 | } |
| 444 | |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 445 | // Set up iptables. |
| 446 | if (!datapath_->AddInboundIPv4DNAT( |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 447 | device->phys_ifname(), IPv4AddressToString(config.guest_ipv4_addr()))) |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 448 | LOG(ERROR) << "Failed to configure ingress traffic rules for " |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 449 | << device->phys_ifname(); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 450 | |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 451 | if (!datapath_->AddOutboundIPv4(device->host_ifname())) |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 452 | LOG(ERROR) << "Failed to configure egress traffic rules for " |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 453 | << device->phys_ifname(); |
Garrick Evans | 2c26310 | 2019-07-26 16:07:18 +0900 | [diff] [blame] | 454 | |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 455 | if (!impl_->OnStartDevice(device)) { |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 456 | LOG(ERROR) << "Failed to start device " << device->phys_ifname(); |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
| 460 | void ArcService::RemoveDevice(const std::string& ifname) { |
| 461 | const auto it = devices_.find(ifname); |
| 462 | if (it == devices_.end()) { |
| 463 | LOG(WARNING) << "Unknown device: " << ifname; |
Garrick Evans | cb791e7 | 2019-11-11 15:44:34 +0900 | [diff] [blame] | 464 | return; |
| 465 | } |
| 466 | |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 467 | // If the container is down, this call does nothing. |
| 468 | StopDevice(it->second.get()); |
| 469 | |
Garrick Evans | 86c7d9c | 2020-03-17 09:25:48 +0900 | [diff] [blame] | 470 | ReleaseConfig(ifname, it->second->release_config()); |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 471 | devices_.erase(it); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 472 | } |
| 473 | |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 474 | void ArcService::StopDevice(Device* device) { |
| 475 | if (!impl_ || !impl_->IsStarted()) |
| 476 | return; |
| 477 | |
| 478 | // For now, devices are only started for ARC++. |
| 479 | if (impl_->guest() != GuestMessage::ARC) |
| 480 | return; |
| 481 | |
| 482 | impl_->OnStopDevice(device); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 483 | |
| 484 | const auto& config = device->config(); |
| 485 | |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 486 | LOG(INFO) << "Removing device " << device->phys_ifname() |
| 487 | << " bridge: " << device->host_ifname() |
| 488 | << " guest_iface: " << device->guest_ifname(); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 489 | |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 490 | datapath_->RemoveOutboundIPv4(device->host_ifname()); |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 491 | datapath_->RemoveInboundIPv4DNAT( |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 492 | device->phys_ifname(), IPv4AddressToString(config.guest_ipv4_addr())); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 493 | |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 494 | datapath_->RemoveBridge(device->host_ifname()); |
Garrick Evans | cb791e7 | 2019-11-11 15:44:34 +0900 | [diff] [blame] | 495 | } |
| 496 | |
Garrick Evans | 1b1f67c | 2020-02-04 16:21:25 +0900 | [diff] [blame] | 497 | void ArcService::OnDefaultInterfaceChanged(const std::string& new_ifname, |
| 498 | const std::string& prev_ifname) { |
Garrick Evans | f29f5a3 | 2019-12-06 11:34:25 +0900 | [diff] [blame] | 499 | if (impl_) |
Garrick Evans | 1b1f67c | 2020-02-04 16:21:25 +0900 | [diff] [blame] | 500 | impl_->OnDefaultInterfaceChanged(new_ifname, prev_ifname); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 501 | } |
Garrick Evans | ba57574 | 2019-07-17 15:48:08 +0900 | [diff] [blame] | 502 | |
Garrick Evans | 38b25a4 | 2020-04-06 15:17:42 +0900 | [diff] [blame] | 503 | std::vector<const Device::Config*> ArcService::GetDeviceConfigs() const { |
| 504 | if (impl_) |
| 505 | return impl_->GetDeviceConfigs(); |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 506 | |
Garrick Evans | 38b25a4 | 2020-04-06 15:17:42 +0900 | [diff] [blame] | 507 | return {}; |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 508 | } |
| 509 | |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 510 | // ARC++ specific functions. |
| 511 | |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 512 | ArcService::ContainerImpl::ContainerImpl(Datapath* datapath, |
| 513 | AddressManager* addr_mgr, |
| 514 | TrafficForwarder* forwarder, |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 515 | GuestMessage::GuestType guest) |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 516 | : pid_(kInvalidPID), |
| 517 | datapath_(datapath), |
| 518 | addr_mgr_(addr_mgr), |
| 519 | forwarder_(forwarder), |
| 520 | guest_(guest) { |
Garrick Evans | 6d227b9 | 2019-12-03 16:11:29 +0900 | [diff] [blame] | 521 | OneTimeSetup(*datapath_); |
Garrick Evans | a34b586 | 2019-11-20 09:34:01 +0900 | [diff] [blame] | 522 | } |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 523 | |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 524 | GuestMessage::GuestType ArcService::ContainerImpl::guest() const { |
| 525 | return guest_; |
| 526 | } |
| 527 | |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 528 | uint32_t ArcService::ContainerImpl::id() const { |
Garrick Evans | 664a82f | 2019-12-17 12:18:05 +0900 | [diff] [blame] | 529 | return pid_; |
| 530 | } |
| 531 | |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 532 | bool ArcService::ContainerImpl::Start(uint32_t pid) { |
Garrick Evans | a51d0a1 | 2019-11-28 13:51:23 +0900 | [diff] [blame] | 533 | // This could happen if something crashes and the stop signal is not sent. |
| 534 | // It can probably be addressed by stopping and restarting the service. |
| 535 | if (pid_ != kInvalidPID) |
| 536 | return false; |
| 537 | |
Garrick Evans | 4dec0c4 | 2019-11-29 12:51:57 +0900 | [diff] [blame] | 538 | if (pid == kInvalidPID) { |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 539 | LOG(ERROR) << "Cannot start service - invalid container PID"; |
| 540 | return false; |
| 541 | } |
Garrick Evans | 4dec0c4 | 2019-11-29 12:51:57 +0900 | [diff] [blame] | 542 | pid_ = pid; |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 543 | |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 544 | Device::Options opts{ |
| 545 | .fwd_multicast = false, |
| 546 | .ipv6_enabled = false, |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 547 | }; |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 548 | auto config = MakeArcConfig(addr_mgr_, AddressManager::Guest::ARC); |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 549 | |
| 550 | // Create the bridge. |
| 551 | // Per crbug/1008686 this device cannot be deleted and then re-added. |
| 552 | // So instead of removing the bridge when the service stops, bring down the |
| 553 | // device instead and re-up it on restart. |
| 554 | if (!datapath_->AddBridge(kArcBridge, config->host_ipv4_addr(), 30) && |
| 555 | !datapath_->MaskInterfaceFlags(kArcBridge, IFF_UP)) { |
| 556 | LOG(ERROR) << "Failed to bring up arc bridge: " << kArcBridge; |
| 557 | return false; |
| 558 | } |
| 559 | |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 560 | arc_device_ = std::make_unique<Device>(kArcIfname, kArcBridge, kArcIfname, |
| 561 | std::move(config), opts); |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 562 | |
| 563 | OnStartDevice(arc_device_.get()); |
| 564 | |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 565 | LOG(INFO) << "ARC++ network service started {pid: " << pid_ << "}"; |
| 566 | return true; |
| 567 | } |
| 568 | |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 569 | void ArcService::ContainerImpl::Stop(uint32_t /*pid*/) { |
Garrick Evans | 4dec0c4 | 2019-11-29 12:51:57 +0900 | [diff] [blame] | 570 | if (!IsStarted()) |
Taoyu Li | 1c96d27 | 2019-12-13 14:17:43 +0900 | [diff] [blame] | 571 | return; |
Garrick Evans | 4dec0c4 | 2019-11-29 12:51:57 +0900 | [diff] [blame] | 572 | |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 573 | // Per crbug/1008686 this device cannot be deleted and then re-added. |
| 574 | // So instead of removing the bridge, bring it down and mark it. This will |
| 575 | // allow us to detect if the device is re-added in case of a crash restart |
| 576 | // and do the right thing. |
| 577 | if (arc_device_) { |
| 578 | OnStopDevice(arc_device_.get()); |
| 579 | if (!datapath_->MaskInterfaceFlags(kArcBridge, IFF_DEBUG, IFF_UP)) |
| 580 | LOG(ERROR) << "Failed to bring down arc bridge " |
| 581 | << "- it may not restart correctly"; |
| 582 | } |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 583 | |
| 584 | LOG(INFO) << "ARC++ network service stopped {pid: " << pid_ << "}"; |
| 585 | pid_ = kInvalidPID; |
| 586 | } |
| 587 | |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 588 | bool ArcService::ContainerImpl::IsStarted(uint32_t* pid) const { |
Garrick Evans | a51d0a1 | 2019-11-28 13:51:23 +0900 | [diff] [blame] | 589 | if (pid) |
| 590 | *pid = pid_; |
| 591 | |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 592 | return pid_ != kInvalidPID; |
| 593 | } |
| 594 | |
| 595 | bool ArcService::ContainerImpl::OnStartDevice(Device* device) { |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 596 | LOG(INFO) << "Starting device " << device->phys_ifname() |
| 597 | << " bridge: " << device->host_ifname() |
| 598 | << " guest_iface: " << device->guest_ifname() << " pid: " << pid_; |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 599 | |
Garrick Evans | 2470caa | 2020-03-04 14:15:41 +0900 | [diff] [blame] | 600 | // Set up the virtual pair inside the container namespace. |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 601 | const std::string veth_ifname = ArcVethHostName(device->guest_ifname()); |
Hugo Benichi | 7667559 | 2020-04-08 14:29:57 +0900 | [diff] [blame] | 602 | const auto& config = device->config(); |
| 603 | if (!datapath_->ConnectVethPair(pid_, veth_ifname, device->guest_ifname(), |
| 604 | config.mac_addr(), config.guest_ipv4_addr(), |
| 605 | 30, device->options().fwd_multicast)) { |
| 606 | LOG(ERROR) << "Cannot create virtual link for device " |
| 607 | << device->phys_ifname(); |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 608 | return false; |
| 609 | } |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 610 | if (!datapath_->AddToBridge(device->host_ifname(), veth_ifname)) { |
Garrick Evans | 2470caa | 2020-03-04 14:15:41 +0900 | [diff] [blame] | 611 | datapath_->RemoveInterface(veth_ifname); |
| 612 | LOG(ERROR) << "Failed to bridge interface " << veth_ifname; |
| 613 | return false; |
| 614 | } |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 615 | |
Garrick Evans | 3bd0637 | 2020-03-23 10:42:58 +0900 | [diff] [blame] | 616 | if (device != arc_device_.get()) { |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 617 | forwarder_->StartForwarding(device->phys_ifname(), device->host_ifname(), |
| 618 | device->options().ipv6_enabled, |
| 619 | device->options().fwd_multicast); |
Garrick Evans | 3bd0637 | 2020-03-23 10:42:58 +0900 | [diff] [blame] | 620 | } else { |
| 621 | // Signal the container that the network device is ready. |
| 622 | datapath_->runner().WriteSentinelToContainer(pid_); |
| 623 | } |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 624 | |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 625 | return true; |
| 626 | } |
| 627 | |
| 628 | void ArcService::ContainerImpl::OnStopDevice(Device* device) { |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 629 | LOG(INFO) << "Stopping device " << device->phys_ifname() |
| 630 | << " bridge: " << device->host_ifname() |
| 631 | << " guest_iface: " << device->guest_ifname() << " pid: " << pid_; |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 632 | |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 633 | if (device != arc_device_.get()) |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 634 | forwarder_->StopForwarding(device->phys_ifname(), device->host_ifname(), |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 635 | device->options().ipv6_enabled, |
| 636 | device->options().fwd_multicast); |
| 637 | |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 638 | datapath_->RemoveInterface(ArcVethHostName(device->phys_ifname())); |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | void ArcService::ContainerImpl::OnDefaultInterfaceChanged( |
Garrick Evans | b05a7ff | 2020-02-18 12:59:55 +0900 | [diff] [blame] | 642 | const std::string& new_ifname, const std::string& prev_ifname) {} |
Garrick Evans | d90a382 | 2019-11-12 17:53:08 +0900 | [diff] [blame] | 643 | |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 644 | // VM specific functions |
| 645 | |
Garrick Evans | bbdf4b4 | 2020-03-05 12:59:06 +0900 | [diff] [blame] | 646 | ArcService::VmImpl::VmImpl(ShillClient* shill_client, |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 647 | Datapath* datapath, |
| 648 | AddressManager* addr_mgr, |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 649 | TrafficForwarder* forwarder, |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 650 | const std::vector<Device::Config*>& configs) |
Garrick Evans | bbdf4b4 | 2020-03-05 12:59:06 +0900 | [diff] [blame] | 651 | : cid_(kInvalidCID), |
| 652 | shill_client_(shill_client), |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 653 | datapath_(datapath), |
| 654 | addr_mgr_(addr_mgr), |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 655 | forwarder_(forwarder), |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 656 | configs_(configs) {} |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 657 | |
| 658 | GuestMessage::GuestType ArcService::VmImpl::guest() const { |
| 659 | return GuestMessage::ARC_VM; |
| 660 | } |
| 661 | |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 662 | uint32_t ArcService::VmImpl::id() const { |
Garrick Evans | 664a82f | 2019-12-17 12:18:05 +0900 | [diff] [blame] | 663 | return cid_; |
| 664 | } |
| 665 | |
Garrick Evans | 38b25a4 | 2020-04-06 15:17:42 +0900 | [diff] [blame] | 666 | std::vector<const Device::Config*> ArcService::VmImpl::GetDeviceConfigs() |
| 667 | const { |
| 668 | std::vector<const Device::Config*> configs; |
| 669 | for (const auto* c : configs_) |
| 670 | configs.emplace_back(c); |
| 671 | |
| 672 | return configs; |
| 673 | } |
| 674 | |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 675 | bool ArcService::VmImpl::Start(uint32_t cid) { |
Garrick Evans | a51d0a1 | 2019-11-28 13:51:23 +0900 | [diff] [blame] | 676 | // This can happen if concierge crashes and doesn't send the vm down RPC. |
| 677 | // It can probably be addressed by stopping and restarting the service. |
| 678 | if (cid_ != kInvalidCID) |
| 679 | return false; |
| 680 | |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 681 | if (cid == kInvalidCID) { |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 682 | LOG(ERROR) << "Invalid VM cid " << cid; |
| 683 | return false; |
| 684 | } |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 685 | cid_ = cid; |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 686 | |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 687 | Device::Options opts{ |
| 688 | .fwd_multicast = true, |
| 689 | .ipv6_enabled = true, |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 690 | }; |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 691 | auto arc_config = MakeArcConfig(addr_mgr_, AddressManager::Guest::VM_ARC); |
| 692 | configs_.insert(configs_.begin(), arc_config.get()); |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 693 | |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 694 | // Allocate TAP devices for all configs. |
| 695 | for (auto* config : configs_) { |
Garrick Evans | c707112 | 2020-04-17 12:31:57 +0900 | [diff] [blame] | 696 | auto mac = config->mac_addr(); |
| 697 | auto tap = |
| 698 | datapath_->AddTAP("" /* auto-generate name */, &mac, |
| 699 | nullptr /* no ipv4 subnet */, vm_tools::kCrosVmUser); |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 700 | if (tap.empty()) { |
| 701 | LOG(ERROR) << "Failed to create TAP device"; |
| 702 | continue; |
| 703 | } |
| 704 | |
| 705 | config->set_tap_ifname(tap); |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 706 | } |
| 707 | |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 708 | arc_device_ = std::make_unique<Device>( |
| 709 | kArcVmIfname, kArcVmBridge, kArcVmIfname, std::move(arc_config), opts); |
| 710 | // Create the bridge. |
| 711 | if (!datapath_->AddBridge(kArcVmBridge, |
| 712 | arc_device_->config().host_ipv4_addr(), 30)) { |
| 713 | LOG(ERROR) << "Failed to setup arc bridge for device " << *arc_device_; |
| 714 | return false; |
| 715 | } |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 716 | OnStartDevice(arc_device_.get()); |
| 717 | |
| 718 | LOG(INFO) << "ARCVM network service started {cid: " << cid_ << "}"; |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 719 | return true; |
| 720 | } |
| 721 | |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 722 | void ArcService::VmImpl::Stop(uint32_t cid) { |
Garrick Evans | 21173b1 | 2019-11-20 15:23:16 +0900 | [diff] [blame] | 723 | if (cid_ != cid) { |
| 724 | LOG(ERROR) << "Mismatched ARCVM CIDs " << cid_ << " != " << cid; |
| 725 | return; |
| 726 | } |
| 727 | |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 728 | for (auto* config : configs_) { |
| 729 | const auto& tap = config->tap_ifname(); |
| 730 | if (!tap.empty()) { |
| 731 | datapath_->RemoveInterface(tap); |
| 732 | config->set_tap_ifname(""); |
| 733 | } |
| 734 | } |
| 735 | |
Garrick Evans | e94b6de | 2020-02-20 09:19:13 +0900 | [diff] [blame] | 736 | OnStopDevice(arc_device_.get()); |
| 737 | datapath_->RemoveBridge(kArcVmBridge); |
| 738 | arc_device_.reset(); |
| 739 | |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 740 | LOG(INFO) << "ARCVM network service stopped {cid: " << cid_ << "}"; |
| 741 | cid_ = kInvalidCID; |
| 742 | } |
| 743 | |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 744 | bool ArcService::VmImpl::IsStarted(uint32_t* cid) const { |
Garrick Evans | a51d0a1 | 2019-11-28 13:51:23 +0900 | [diff] [blame] | 745 | if (cid) |
| 746 | *cid = cid_; |
| 747 | |
Garrick Evans | 015b0d6 | 2020-02-07 09:06:38 +0900 | [diff] [blame] | 748 | return cid_ != kInvalidCID; |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | bool ArcService::VmImpl::OnStartDevice(Device* device) { |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 752 | // TODO(garrick): Remove once ARCVM P is gone. |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 753 | if (device == arc_device_.get() && !IsMultinetEnabled()) |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 754 | return OnStartArcPDevice(); |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 755 | |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 756 | std::string tap; |
| 757 | for (auto* config : configs_) { |
| 758 | if (config == &device->config()) { |
| 759 | tap = config->tap_ifname(); |
| 760 | break; |
| 761 | } |
| 762 | } |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 763 | if (tap.empty()) { |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 764 | LOG(ERROR) << "No TAP device for: " << *device; |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 765 | return false; |
| 766 | } |
| 767 | |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 768 | LOG(INFO) << "Starting device " << *device << " cid: " << cid_; |
| 769 | |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 770 | if (!datapath_->AddToBridge(device->host_ifname(), tap)) { |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 771 | LOG(ERROR) << "Failed to bridge TAP device " << tap; |
| 772 | datapath_->RemoveInterface(tap); |
| 773 | return false; |
| 774 | } |
| 775 | |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 776 | if (device != arc_device_.get()) |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 777 | forwarder_->StartForwarding(device->phys_ifname(), device->host_ifname(), |
| 778 | device->options().ipv6_enabled, |
| 779 | device->options().fwd_multicast); |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 780 | |
| 781 | return true; |
| 782 | } |
| 783 | |
| 784 | bool ArcService::VmImpl::OnStartArcPDevice() { |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 785 | LOG(INFO) << "Starting device " << *arc_device_ << " cid: " << cid_; |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 786 | |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 787 | if (!datapath_->AddToBridge(kArcVmBridge, |
| 788 | arc_device_->config().tap_ifname())) { |
| 789 | LOG(ERROR) << "Failed to bridge TAP device " << *arc_device_; |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 790 | return false; |
| 791 | } |
| 792 | |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 793 | // Setup the iptables. |
| 794 | if (!datapath_->AddLegacyIPv4DNAT( |
| 795 | IPv4AddressToString(arc_device_->config().guest_ipv4_addr()))) |
| 796 | LOG(ERROR) << "Failed to configure ARC traffic rules"; |
| 797 | |
| 798 | if (!datapath_->AddOutboundIPv4(kArcVmBridge)) |
| 799 | LOG(ERROR) << "Failed to configure egress traffic rules"; |
| 800 | |
Garrick Evans | bbdf4b4 | 2020-03-05 12:59:06 +0900 | [diff] [blame] | 801 | OnDefaultInterfaceChanged(shill_client_->default_interface(), |
| 802 | "" /*previous*/); |
Garrick Evans | bcce09e | 2020-03-10 15:08:04 +0900 | [diff] [blame] | 803 | |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 804 | return true; |
| 805 | } |
| 806 | |
| 807 | void ArcService::VmImpl::OnStopDevice(Device* device) { |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 808 | // TODO(garrick): Remove once ARCVM P is gone. |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 809 | if (device == arc_device_.get() && !IsMultinetEnabled()) |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 810 | return OnStopArcPDevice(); |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 811 | |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 812 | LOG(INFO) << "Stopping device " << *device << " cid: " << cid_; |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 813 | |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 814 | if (device != arc_device_.get()) |
Garrick Evans | 6c7dcb8 | 2020-03-16 15:21:05 +0900 | [diff] [blame] | 815 | forwarder_->StopForwarding(device->phys_ifname(), device->host_ifname(), |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 816 | device->options().ipv6_enabled, |
| 817 | device->options().fwd_multicast); |
Garrick Evans | bcce09e | 2020-03-10 15:08:04 +0900 | [diff] [blame] | 818 | |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 819 | for (auto* config : configs_) { |
| 820 | if (config == &device->config()) { |
| 821 | config->set_tap_ifname(""); |
| 822 | break; |
| 823 | } |
| 824 | } |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 825 | } |
| 826 | |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 827 | void ArcService::VmImpl::OnStopArcPDevice() { |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 828 | LOG(INFO) << "Stopping device " << *arc_device_.get() << " cid: " << cid_; |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 829 | |
| 830 | datapath_->RemoveOutboundIPv4(kArcVmBridge); |
| 831 | datapath_->RemoveLegacyIPv4DNAT(); |
| 832 | |
| 833 | OnDefaultInterfaceChanged("" /*new_ifname*/, |
| 834 | shill_client_->default_interface()); |
| 835 | |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 836 | arc_device_->config().set_tap_ifname(""); |
Garrick Evans | f586212 | 2020-03-16 09:13:45 +0900 | [diff] [blame] | 837 | } |
| 838 | |
Garrick Evans | 1b1f67c | 2020-02-04 16:21:25 +0900 | [diff] [blame] | 839 | void ArcService::VmImpl::OnDefaultInterfaceChanged( |
| 840 | const std::string& new_ifname, const std::string& prev_ifname) { |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 841 | if (!IsStarted() || IsMultinetEnabled()) |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 842 | return; |
| 843 | |
Garrick Evans | 2e5c9ab | 2020-03-05 14:33:58 +0900 | [diff] [blame] | 844 | forwarder_->StopForwarding(prev_ifname, kArcVmBridge, true /*ipv6*/, |
| 845 | true /*multicast*/); |
| 846 | |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 847 | datapath_->RemoveLegacyIPv4InboundDNAT(); |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 848 | |
| 849 | // If a new default interface was given, then re-enable with that. |
Garrick Evans | 1b1f67c | 2020-02-04 16:21:25 +0900 | [diff] [blame] | 850 | if (!new_ifname.empty()) { |
Garrick Evans | 6e4eb3b | 2020-03-09 07:18:31 +0900 | [diff] [blame] | 851 | datapath_->AddLegacyIPv4InboundDNAT(new_ifname); |
Jason Jeremy Iman | 0e9f826 | 2020-03-06 14:50:49 +0900 | [diff] [blame] | 852 | forwarder_->StartForwarding(new_ifname, kArcVmBridge, true /*ipv6*/, |
| 853 | true /*multicast*/); |
Garrick Evans | b4eb389 | 2019-11-13 12:07:07 +0900 | [diff] [blame] | 854 | } |
| 855 | } |
| 856 | |
Garrick Evans | 2961c7c | 2020-04-03 11:34:40 +0900 | [diff] [blame] | 857 | bool ArcService::VmImpl::IsMultinetEnabled() const { |
| 858 | return configs_.size() > 1; |
| 859 | } |
| 860 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 861 | } // namespace patchpanel |