Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +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/datapath.h" |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 6 | |
Garrick Evans | 3d97a39 | 2020-02-21 15:24:37 +0900 | [diff] [blame] | 7 | #include <arpa/inet.h> |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 8 | #include <fcntl.h> |
| 9 | #include <linux/if_tun.h> |
| 10 | #include <linux/sockios.h> |
| 11 | #include <net/if.h> |
| 12 | #include <net/if_arp.h> |
| 13 | #include <netinet/in.h> |
| 14 | #include <string.h> |
| 15 | #include <sys/ioctl.h> |
| 16 | #include <sys/socket.h> |
| 17 | |
| 18 | #include <base/files/scoped_file.h> |
| 19 | #include <base/logging.h> |
Taoyu Li | 79871c9 | 2020-07-02 16:09:39 +0900 | [diff] [blame^] | 20 | #include <base/posix/eintr_wrapper.h> |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 21 | #include <base/strings/string_number_conversions.h> |
Garrick Evans | 4f9f557 | 2019-11-26 10:25:16 +0900 | [diff] [blame] | 22 | #include <brillo/userdb_utils.h> |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 23 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 24 | #include "patchpanel/net_util.h" |
| 25 | #include "patchpanel/scoped_ns.h" |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 26 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 27 | namespace patchpanel { |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 28 | |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 29 | namespace { |
Hugo Benichi | 7667559 | 2020-04-08 14:29:57 +0900 | [diff] [blame] | 30 | // TODO(hugobenichi) Consolidate this constant definition in a single place. |
| 31 | constexpr pid_t kTestPID = -2; |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 32 | constexpr char kDefaultIfname[] = "vmtap%d"; |
| 33 | constexpr char kTunDev[] = "/dev/net/tun"; |
Hugo Benichi | e8758b5 | 2020-04-03 14:49:01 +0900 | [diff] [blame] | 34 | |
Garrick Evans | 8a06756 | 2020-05-11 12:47:30 +0900 | [diff] [blame] | 35 | std::string PrefixIfname(const std::string& prefix, const std::string& ifname) { |
| 36 | std::string n = prefix + ifname; |
Garrick Evans | 2f581a0 | 2020-05-11 10:43:35 +0900 | [diff] [blame] | 37 | if (n.length() < IFNAMSIZ) |
| 38 | return n; |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 39 | |
Garrick Evans | 2f581a0 | 2020-05-11 10:43:35 +0900 | [diff] [blame] | 40 | // Best effort attempt to preserve the interface number, assuming it's the |
| 41 | // last char in the name. |
| 42 | auto c = ifname[ifname.length() - 1]; |
| 43 | n.resize(IFNAMSIZ - 1); |
| 44 | n[n.length() - 1] = c; |
| 45 | return n; |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 46 | } |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 47 | |
Garrick Evans | 8a06756 | 2020-05-11 12:47:30 +0900 | [diff] [blame] | 48 | } // namespace |
| 49 | |
| 50 | std::string ArcVethHostName(const std::string& ifname) { |
| 51 | return PrefixIfname("veth", ifname); |
| 52 | } |
| 53 | |
| 54 | std::string ArcBridgeName(const std::string& ifname) { |
| 55 | return PrefixIfname("arc_", ifname); |
| 56 | } |
| 57 | |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 58 | Datapath::Datapath(MinijailedProcessRunner* process_runner) |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 59 | : Datapath(process_runner, ioctl) {} |
| 60 | |
| 61 | Datapath::Datapath(MinijailedProcessRunner* process_runner, ioctl_t ioctl_hook) |
| 62 | : process_runner_(process_runner), ioctl_(ioctl_hook) { |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 63 | CHECK(process_runner_); |
| 64 | } |
| 65 | |
Garrick Evans | 260ff30 | 2019-07-25 11:22:50 +0900 | [diff] [blame] | 66 | MinijailedProcessRunner& Datapath::runner() const { |
| 67 | return *process_runner_; |
| 68 | } |
| 69 | |
Garrick Evans | 8a949dc | 2019-07-18 16:17:53 +0900 | [diff] [blame] | 70 | bool Datapath::AddBridge(const std::string& ifname, |
Garrick Evans | 7a1a9ee | 2020-01-28 11:03:57 +0900 | [diff] [blame] | 71 | uint32_t ipv4_addr, |
| 72 | uint32_t ipv4_prefix_len) { |
Garrick Evans | 8a949dc | 2019-07-18 16:17:53 +0900 | [diff] [blame] | 73 | // Configure the persistent Chrome OS bridge interface with static IP. |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 74 | if (process_runner_->brctl("addbr", {ifname}) != 0) { |
Garrick Evans | 8a949dc | 2019-07-18 16:17:53 +0900 | [diff] [blame] | 75 | return false; |
| 76 | } |
| 77 | |
Garrick Evans | 6f4fa3a | 2020-02-10 16:15:09 +0900 | [diff] [blame] | 78 | if (process_runner_->ip( |
| 79 | "addr", "add", |
| 80 | {IPv4AddressToCidrString(ipv4_addr, ipv4_prefix_len), "brd", |
| 81 | IPv4AddressToString(Ipv4BroadcastAddr(ipv4_addr, ipv4_prefix_len)), |
| 82 | "dev", ifname}) != 0) { |
Garrick Evans | 7a1a9ee | 2020-01-28 11:03:57 +0900 | [diff] [blame] | 83 | RemoveBridge(ifname); |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | if (process_runner_->ip("link", "set", {ifname, "up"}) != 0) { |
Garrick Evans | 8a949dc | 2019-07-18 16:17:53 +0900 | [diff] [blame] | 88 | RemoveBridge(ifname); |
| 89 | return false; |
| 90 | } |
| 91 | |
| 92 | // See nat.conf in chromeos-nat-init for the rest of the NAT setup rules. |
Hugo Benichi | e8758b5 | 2020-04-03 14:49:01 +0900 | [diff] [blame] | 93 | if (!AddOutboundIPv4SNATMark(ifname)) { |
Garrick Evans | 8a949dc | 2019-07-18 16:17:53 +0900 | [diff] [blame] | 94 | RemoveBridge(ifname); |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | void Datapath::RemoveBridge(const std::string& ifname) { |
Hugo Benichi | e8758b5 | 2020-04-03 14:49:01 +0900 | [diff] [blame] | 102 | RemoveOutboundIPv4SNATMark(ifname); |
Garrick Evans | 7a1a9ee | 2020-01-28 11:03:57 +0900 | [diff] [blame] | 103 | process_runner_->ip("link", "set", {ifname, "down"}); |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 104 | process_runner_->brctl("delbr", {ifname}); |
Garrick Evans | 8a949dc | 2019-07-18 16:17:53 +0900 | [diff] [blame] | 105 | } |
| 106 | |
Garrick Evans | 621ed26 | 2019-11-13 12:28:43 +0900 | [diff] [blame] | 107 | bool Datapath::AddToBridge(const std::string& br_ifname, |
| 108 | const std::string& ifname) { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 109 | return (process_runner_->brctl("addif", {br_ifname, ifname}) == 0); |
Garrick Evans | 621ed26 | 2019-11-13 12:28:43 +0900 | [diff] [blame] | 110 | } |
| 111 | |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 112 | std::string Datapath::AddTAP(const std::string& name, |
Garrick Evans | 621ed26 | 2019-11-13 12:28:43 +0900 | [diff] [blame] | 113 | const MacAddress* mac_addr, |
| 114 | const SubnetAddress* ipv4_addr, |
Garrick Evans | 4f9f557 | 2019-11-26 10:25:16 +0900 | [diff] [blame] | 115 | const std::string& user) { |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 116 | base::ScopedFD dev(open(kTunDev, O_RDWR | O_NONBLOCK)); |
| 117 | if (!dev.is_valid()) { |
| 118 | PLOG(ERROR) << "Failed to open " << kTunDev; |
| 119 | return ""; |
| 120 | } |
| 121 | |
| 122 | struct ifreq ifr; |
| 123 | memset(&ifr, 0, sizeof(ifr)); |
| 124 | strncpy(ifr.ifr_name, name.empty() ? kDefaultIfname : name.c_str(), |
| 125 | sizeof(ifr.ifr_name)); |
| 126 | ifr.ifr_flags = IFF_TAP | IFF_NO_PI; |
| 127 | |
| 128 | // If a template was given as the name, ifr_name will be updated with the |
| 129 | // actual interface name. |
| 130 | if ((*ioctl_)(dev.get(), TUNSETIFF, &ifr) != 0) { |
Garrick Evans | 621ed26 | 2019-11-13 12:28:43 +0900 | [diff] [blame] | 131 | PLOG(ERROR) << "Failed to create tap interface " << name; |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 132 | return ""; |
| 133 | } |
| 134 | const char* ifname = ifr.ifr_name; |
| 135 | |
| 136 | if ((*ioctl_)(dev.get(), TUNSETPERSIST, 1) != 0) { |
Garrick Evans | 621ed26 | 2019-11-13 12:28:43 +0900 | [diff] [blame] | 137 | PLOG(ERROR) << "Failed to persist the interface " << ifname; |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 138 | return ""; |
| 139 | } |
| 140 | |
Garrick Evans | 4f9f557 | 2019-11-26 10:25:16 +0900 | [diff] [blame] | 141 | if (!user.empty()) { |
| 142 | uid_t uid = -1; |
| 143 | if (!brillo::userdb::GetUserInfo(user, &uid, nullptr)) { |
| 144 | PLOG(ERROR) << "Unable to look up UID for " << user; |
| 145 | RemoveTAP(ifname); |
| 146 | return ""; |
| 147 | } |
| 148 | if ((*ioctl_)(dev.get(), TUNSETOWNER, uid) != 0) { |
| 149 | PLOG(ERROR) << "Failed to set owner " << uid << " of tap interface " |
| 150 | << ifname; |
| 151 | RemoveTAP(ifname); |
| 152 | return ""; |
| 153 | } |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 154 | } |
| 155 | |
Hugo Benichi | b9b93fe | 2019-10-25 23:36:01 +0900 | [diff] [blame] | 156 | // Create control socket for configuring the interface. |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 157 | base::ScopedFD sock(socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0)); |
| 158 | if (!sock.is_valid()) { |
| 159 | PLOG(ERROR) << "Failed to create control socket for tap interface " |
Garrick Evans | 621ed26 | 2019-11-13 12:28:43 +0900 | [diff] [blame] | 160 | << ifname; |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 161 | RemoveTAP(ifname); |
| 162 | return ""; |
| 163 | } |
| 164 | |
Garrick Evans | 621ed26 | 2019-11-13 12:28:43 +0900 | [diff] [blame] | 165 | if (ipv4_addr) { |
| 166 | struct sockaddr_in* addr = |
| 167 | reinterpret_cast<struct sockaddr_in*>(&ifr.ifr_addr); |
| 168 | addr->sin_family = AF_INET; |
| 169 | addr->sin_addr.s_addr = static_cast<in_addr_t>(ipv4_addr->Address()); |
| 170 | if ((*ioctl_)(sock.get(), SIOCSIFADDR, &ifr) != 0) { |
| 171 | PLOG(ERROR) << "Failed to set ip address for vmtap interface " << ifname |
| 172 | << " {" << ipv4_addr->ToCidrString() << "}"; |
| 173 | RemoveTAP(ifname); |
| 174 | return ""; |
| 175 | } |
| 176 | |
| 177 | struct sockaddr_in* netmask = |
| 178 | reinterpret_cast<struct sockaddr_in*>(&ifr.ifr_netmask); |
| 179 | netmask->sin_family = AF_INET; |
| 180 | netmask->sin_addr.s_addr = static_cast<in_addr_t>(ipv4_addr->Netmask()); |
| 181 | if ((*ioctl_)(sock.get(), SIOCSIFNETMASK, &ifr) != 0) { |
| 182 | PLOG(ERROR) << "Failed to set netmask for vmtap interface " << ifname |
| 183 | << " {" << ipv4_addr->ToCidrString() << "}"; |
| 184 | RemoveTAP(ifname); |
| 185 | return ""; |
| 186 | } |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 187 | } |
| 188 | |
Garrick Evans | 621ed26 | 2019-11-13 12:28:43 +0900 | [diff] [blame] | 189 | if (mac_addr) { |
| 190 | struct sockaddr* hwaddr = &ifr.ifr_hwaddr; |
| 191 | hwaddr->sa_family = ARPHRD_ETHER; |
| 192 | memcpy(&hwaddr->sa_data, mac_addr, sizeof(*mac_addr)); |
| 193 | if ((*ioctl_)(sock.get(), SIOCSIFHWADDR, &ifr) != 0) { |
| 194 | PLOG(ERROR) << "Failed to set mac address for vmtap interface " << ifname |
| 195 | << " {" << MacAddressToString(*mac_addr) << "}"; |
| 196 | RemoveTAP(ifname); |
| 197 | return ""; |
| 198 | } |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | if ((*ioctl_)(sock.get(), SIOCGIFFLAGS, &ifr) != 0) { |
Garrick Evans | 621ed26 | 2019-11-13 12:28:43 +0900 | [diff] [blame] | 202 | PLOG(ERROR) << "Failed to get flags for tap interface " << ifname; |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 203 | RemoveTAP(ifname); |
| 204 | return ""; |
| 205 | } |
| 206 | |
| 207 | ifr.ifr_flags |= (IFF_UP | IFF_RUNNING); |
| 208 | if ((*ioctl_)(sock.get(), SIOCSIFFLAGS, &ifr) != 0) { |
Garrick Evans | 621ed26 | 2019-11-13 12:28:43 +0900 | [diff] [blame] | 209 | PLOG(ERROR) << "Failed to enable tap interface " << ifname; |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 210 | RemoveTAP(ifname); |
| 211 | return ""; |
| 212 | } |
| 213 | |
| 214 | return ifname; |
| 215 | } |
| 216 | |
| 217 | void Datapath::RemoveTAP(const std::string& ifname) { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 218 | process_runner_->ip("tuntap", "del", {ifname, "mode", "tap"}); |
Garrick Evans | c7ae82c | 2019-09-04 16:25:10 +0900 | [diff] [blame] | 219 | } |
| 220 | |
Hugo Benichi | 7667559 | 2020-04-08 14:29:57 +0900 | [diff] [blame] | 221 | bool Datapath::ConnectVethPair(pid_t pid, |
| 222 | const std::string& veth_ifname, |
| 223 | const std::string& peer_ifname, |
| 224 | const MacAddress& remote_mac_addr, |
| 225 | uint32_t remote_ipv4_addr, |
| 226 | uint32_t remote_ipv4_prefix_len, |
| 227 | bool remote_multicast_flag) { |
| 228 | // Set up the virtual pair inside the remote namespace. |
| 229 | { |
| 230 | ScopedNS ns(pid); |
| 231 | if (!ns.IsValid() && pid != kTestPID) { |
| 232 | LOG(ERROR) |
| 233 | << "Cannot create virtual link -- invalid container namespace?"; |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | if (!AddVirtualInterfacePair(veth_ifname, peer_ifname)) { |
| 238 | LOG(ERROR) << "Failed to create veth pair " << veth_ifname << "," |
| 239 | << peer_ifname; |
| 240 | return false; |
| 241 | } |
| 242 | |
| 243 | if (!ConfigureInterface(peer_ifname, remote_mac_addr, remote_ipv4_addr, |
| 244 | remote_ipv4_prefix_len, true /* link up */, |
| 245 | remote_multicast_flag)) { |
| 246 | LOG(ERROR) << "Failed to configure interface " << peer_ifname; |
| 247 | RemoveInterface(peer_ifname); |
| 248 | return false; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | // Now pull the local end out into the local namespace. |
| 253 | if (runner().RestoreDefaultNamespace(veth_ifname, pid) != 0) { |
| 254 | LOG(ERROR) << "Failed to prepare interface " << veth_ifname; |
| 255 | { |
| 256 | ScopedNS ns(pid); |
| 257 | if (ns.IsValid()) { |
| 258 | RemoveInterface(peer_ifname); |
| 259 | } else { |
| 260 | LOG(ERROR) << "Failed to re-enter container namespace pid " << pid; |
| 261 | } |
| 262 | } |
| 263 | return false; |
| 264 | } |
| 265 | if (!ToggleInterface(veth_ifname, true /*up*/)) { |
| 266 | LOG(ERROR) << "Failed to bring up interface " << veth_ifname; |
| 267 | RemoveInterface(veth_ifname); |
| 268 | return false; |
| 269 | } |
| 270 | return true; |
| 271 | } |
| 272 | |
Garrick Evans | 2470caa | 2020-03-04 14:15:41 +0900 | [diff] [blame] | 273 | bool Datapath::AddVirtualInterfacePair(const std::string& veth_ifname, |
| 274 | const std::string& peer_ifname) { |
| 275 | return process_runner_->ip( |
| 276 | "link", "add", |
| 277 | {veth_ifname, "type", "veth", "peer", "name", peer_ifname}) == 0; |
| 278 | } |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 279 | |
Garrick Evans | 2470caa | 2020-03-04 14:15:41 +0900 | [diff] [blame] | 280 | bool Datapath::ToggleInterface(const std::string& ifname, bool up) { |
| 281 | const std::string link = up ? "up" : "down"; |
| 282 | return process_runner_->ip("link", "set", {ifname, link}) == 0; |
| 283 | } |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 284 | |
Garrick Evans | 2470caa | 2020-03-04 14:15:41 +0900 | [diff] [blame] | 285 | bool Datapath::ConfigureInterface(const std::string& ifname, |
| 286 | const MacAddress& mac_addr, |
| 287 | uint32_t ipv4_addr, |
| 288 | uint32_t ipv4_prefix_len, |
| 289 | bool up, |
| 290 | bool enable_multicast) { |
| 291 | const std::string link = up ? "up" : "down"; |
| 292 | const std::string multicast = enable_multicast ? "on" : "off"; |
| 293 | return (process_runner_->ip( |
| 294 | "addr", "add", |
| 295 | {IPv4AddressToCidrString(ipv4_addr, ipv4_prefix_len), "brd", |
| 296 | IPv4AddressToString( |
| 297 | Ipv4BroadcastAddr(ipv4_addr, ipv4_prefix_len)), |
| 298 | "dev", ifname}) == 0) && |
| 299 | (process_runner_->ip("link", "set", |
| 300 | { |
| 301 | "dev", |
| 302 | ifname, |
| 303 | link, |
| 304 | "addr", |
| 305 | MacAddressToString(mac_addr), |
| 306 | "multicast", |
| 307 | multicast, |
| 308 | }) == 0); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | void Datapath::RemoveInterface(const std::string& ifname) { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 312 | process_runner_->ip("link", "delete", {ifname}, false /*log_failures*/); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 313 | } |
| 314 | |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 315 | bool Datapath::AddLegacyIPv4DNAT(const std::string& ipv4_addr) { |
| 316 | // Forward "unclaimed" packets to Android to allow inbound connections |
| 317 | // from devices on the LAN. |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 318 | if (process_runner_->iptables("nat", {"-N", "dnat_arc", "-w"}) != 0) |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 319 | return false; |
| 320 | |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 321 | if (process_runner_->iptables("nat", {"-A", "dnat_arc", "-j", "DNAT", |
| 322 | "--to-destination", ipv4_addr, "-w"}) != |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 323 | 0) { |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 324 | RemoveLegacyIPv4DNAT(); |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 325 | return false; |
| 326 | } |
| 327 | |
| 328 | // This chain is dynamically updated whenever the default interface |
| 329 | // changes. |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 330 | if (process_runner_->iptables("nat", {"-N", "try_arc", "-w"}) != 0) { |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 331 | RemoveLegacyIPv4DNAT(); |
| 332 | return false; |
| 333 | } |
| 334 | |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 335 | if (process_runner_->iptables( |
| 336 | "nat", {"-A", "PREROUTING", "-m", "socket", "--nowildcard", "-j", |
| 337 | "ACCEPT", "-w"}) != 0) { |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 338 | RemoveLegacyIPv4DNAT(); |
| 339 | return false; |
| 340 | } |
| 341 | |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 342 | if (process_runner_->iptables("nat", {"-A", "PREROUTING", "-p", "tcp", "-j", |
| 343 | "try_arc", "-w"}) != 0) { |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 344 | RemoveLegacyIPv4DNAT(); |
| 345 | return false; |
| 346 | } |
| 347 | |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 348 | if (process_runner_->iptables("nat", {"-A", "PREROUTING", "-p", "udp", "-j", |
| 349 | "try_arc", "-w"}) != 0) { |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 350 | RemoveLegacyIPv4DNAT(); |
| 351 | return false; |
| 352 | } |
| 353 | |
| 354 | return true; |
| 355 | } |
| 356 | |
| 357 | void Datapath::RemoveLegacyIPv4DNAT() { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 358 | process_runner_->iptables( |
| 359 | "nat", {"-D", "PREROUTING", "-p", "udp", "-j", "try_arc", "-w"}); |
| 360 | process_runner_->iptables( |
| 361 | "nat", {"-D", "PREROUTING", "-p", "tcp", "-j", "try_arc", "-w"}); |
| 362 | process_runner_->iptables("nat", {"-D", "PREROUTING", "-m", "socket", |
| 363 | "--nowildcard", "-j", "ACCEPT", "-w"}); |
| 364 | process_runner_->iptables("nat", {"-F", "try_arc", "-w"}); |
| 365 | process_runner_->iptables("nat", {"-X", "try_arc", "-w"}); |
| 366 | process_runner_->iptables("nat", {"-F", "dnat_arc", "-w"}); |
| 367 | process_runner_->iptables("nat", {"-X", "dnat_arc", "-w"}); |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 368 | } |
| 369 | |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 370 | bool Datapath::AddLegacyIPv4InboundDNAT(const std::string& ifname) { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 371 | return (process_runner_->iptables("nat", {"-A", "try_arc", "-i", ifname, "-j", |
| 372 | "dnat_arc", "-w"}) != 0); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | void Datapath::RemoveLegacyIPv4InboundDNAT() { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 376 | process_runner_->iptables("nat", {"-F", "try_arc", "-w"}); |
Garrick Evans | 5486162 | 2019-07-19 09:05:09 +0900 | [diff] [blame] | 377 | } |
| 378 | |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 379 | bool Datapath::AddInboundIPv4DNAT(const std::string& ifname, |
| 380 | const std::string& ipv4_addr) { |
| 381 | // Direct ingress IP traffic to existing sockets. |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 382 | if (process_runner_->iptables( |
| 383 | "nat", {"-A", "PREROUTING", "-i", ifname, "-m", "socket", |
| 384 | "--nowildcard", "-j", "ACCEPT", "-w"}) != 0) |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 385 | return false; |
| 386 | |
| 387 | // Direct ingress TCP & UDP traffic to ARC interface for new connections. |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 388 | if (process_runner_->iptables( |
| 389 | "nat", {"-A", "PREROUTING", "-i", ifname, "-p", "tcp", "-j", "DNAT", |
| 390 | "--to-destination", ipv4_addr, "-w"}) != 0) { |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 391 | RemoveInboundIPv4DNAT(ifname, ipv4_addr); |
| 392 | return false; |
| 393 | } |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 394 | if (process_runner_->iptables( |
| 395 | "nat", {"-A", "PREROUTING", "-i", ifname, "-p", "udp", "-j", "DNAT", |
| 396 | "--to-destination", ipv4_addr, "-w"}) != 0) { |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 397 | RemoveInboundIPv4DNAT(ifname, ipv4_addr); |
| 398 | return false; |
| 399 | } |
| 400 | |
| 401 | return true; |
| 402 | } |
| 403 | |
| 404 | void Datapath::RemoveInboundIPv4DNAT(const std::string& ifname, |
| 405 | const std::string& ipv4_addr) { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 406 | process_runner_->iptables( |
| 407 | "nat", {"-D", "PREROUTING", "-i", ifname, "-p", "udp", "-j", "DNAT", |
| 408 | "--to-destination", ipv4_addr, "-w"}); |
| 409 | process_runner_->iptables( |
| 410 | "nat", {"-D", "PREROUTING", "-i", ifname, "-p", "tcp", "-j", "DNAT", |
| 411 | "--to-destination", ipv4_addr, "-w"}); |
| 412 | process_runner_->iptables( |
| 413 | "nat", {"-D", "PREROUTING", "-i", ifname, "-m", "socket", "--nowildcard", |
| 414 | "-j", "ACCEPT", "-w"}); |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | bool Datapath::AddOutboundIPv4(const std::string& ifname) { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 418 | return process_runner_->iptables("filter", {"-A", "FORWARD", "-o", ifname, |
| 419 | "-j", "ACCEPT", "-w"}) == 0; |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | void Datapath::RemoveOutboundIPv4(const std::string& ifname) { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 423 | process_runner_->iptables( |
| 424 | "filter", {"-D", "FORWARD", "-o", ifname, "-j", "ACCEPT", "-w"}); |
Garrick Evans | f0ab713 | 2019-06-18 14:50:42 +0900 | [diff] [blame] | 425 | } |
| 426 | |
Garrick Evans | d291af6 | 2020-05-25 10:39:06 +0900 | [diff] [blame] | 427 | bool Datapath::AddSNATMarkRules() { |
Taoyu Li | 79871c9 | 2020-07-02 16:09:39 +0900 | [diff] [blame^] | 428 | // chromium:1050579: INVALID packets cannot be tracked by conntrack therefore |
| 429 | // need to be explicitly dropped. |
| 430 | if (process_runner_->iptables( |
| 431 | "filter", {"-A", "FORWARD", "-m", "mark", "--mark", "1", "-m", |
| 432 | "state", "--state", "INVALID", "-j", "DROP", "-w"}) != 0) { |
| 433 | return false; |
| 434 | } |
Garrick Evans | d291af6 | 2020-05-25 10:39:06 +0900 | [diff] [blame] | 435 | if (process_runner_->iptables( |
| 436 | "filter", {"-A", "FORWARD", "-m", "mark", "--mark", "1", "-j", |
| 437 | "ACCEPT", "-w"}) != 0) { |
| 438 | return false; |
| 439 | } |
| 440 | if (process_runner_->iptables( |
| 441 | "nat", {"-A", "POSTROUTING", "-m", "mark", "--mark", "1", "-j", |
| 442 | "MASQUERADE", "-w"}) != 0) { |
| 443 | RemoveSNATMarkRules(); |
| 444 | return false; |
| 445 | } |
| 446 | return true; |
| 447 | } |
| 448 | |
| 449 | void Datapath::RemoveSNATMarkRules() { |
| 450 | process_runner_->iptables("nat", {"-D", "POSTROUTING", "-m", "mark", "--mark", |
| 451 | "1", "-j", "MASQUERADE", "-w"}); |
| 452 | process_runner_->iptables("filter", {"-D", "FORWARD", "-m", "mark", "--mark", |
| 453 | "1", "-j", "ACCEPT", "-w"}); |
Taoyu Li | 79871c9 | 2020-07-02 16:09:39 +0900 | [diff] [blame^] | 454 | process_runner_->iptables( |
| 455 | "filter", {"-D", "FORWARD", "-m", "mark", "--mark", "1", "-m", "state", |
| 456 | "--state", "INVALID", "-j", "DROP", "-w"}); |
Garrick Evans | d291af6 | 2020-05-25 10:39:06 +0900 | [diff] [blame] | 457 | } |
| 458 | |
Garrick Evans | ff6e37f | 2020-05-25 10:54:47 +0900 | [diff] [blame] | 459 | bool Datapath::AddInterfaceSNAT(const std::string& ifname) { |
| 460 | return process_runner_->iptables("nat", {"-A", "POSTROUTING", "-o", ifname, |
| 461 | "-j", "MASQUERADE", "-w"}) == 0; |
| 462 | } |
| 463 | |
| 464 | void Datapath::RemoveInterfaceSNAT(const std::string& ifname) { |
| 465 | process_runner_->iptables( |
| 466 | "nat", {"-D", "POSTROUTING", "-o", ifname, "-j", "MASQUERADE", "-w"}); |
| 467 | } |
| 468 | |
Hugo Benichi | e8758b5 | 2020-04-03 14:49:01 +0900 | [diff] [blame] | 469 | bool Datapath::AddOutboundIPv4SNATMark(const std::string& ifname) { |
| 470 | return process_runner_->iptables( |
| 471 | "mangle", {"-A", "PREROUTING", "-i", ifname, "-j", "MARK", |
| 472 | "--set-mark", "1", "-w"}) == 0; |
| 473 | } |
| 474 | |
| 475 | void Datapath::RemoveOutboundIPv4SNATMark(const std::string& ifname) { |
| 476 | process_runner_->iptables("mangle", {"-D", "PREROUTING", "-i", ifname, "-j", |
| 477 | "MARK", "--set-mark", "1", "-w"}); |
| 478 | } |
| 479 | |
Garrick Evans | d291af6 | 2020-05-25 10:39:06 +0900 | [diff] [blame] | 480 | bool Datapath::AddForwardEstablishedRule() { |
| 481 | return process_runner_->iptables( |
| 482 | "filter", {"-A", "FORWARD", "-m", "state", "--state", |
| 483 | "ESTABLISHED,RELATED", "-j", "ACCEPT", "-w"}) == 0; |
| 484 | } |
| 485 | |
| 486 | void Datapath::RemoveForwardEstablishedRule() { |
| 487 | process_runner_->iptables("filter", |
| 488 | {"-D", "FORWARD", "-m", "state", "--state", |
| 489 | "ESTABLISHED,RELATED", "-j", "ACCEPT", "-w"}); |
| 490 | } |
| 491 | |
Garrick Evans | 664a82f | 2019-12-17 12:18:05 +0900 | [diff] [blame] | 492 | bool Datapath::MaskInterfaceFlags(const std::string& ifname, |
| 493 | uint16_t on, |
| 494 | uint16_t off) { |
Taoyu Li | 90c1391 | 2019-11-26 17:56:54 +0900 | [diff] [blame] | 495 | base::ScopedFD sock(socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0)); |
| 496 | if (!sock.is_valid()) { |
| 497 | PLOG(ERROR) << "Failed to create control socket"; |
| 498 | return false; |
| 499 | } |
| 500 | ifreq ifr; |
| 501 | snprintf(ifr.ifr_name, IFNAMSIZ, "%s", ifname.c_str()); |
| 502 | if ((*ioctl_)(sock.get(), SIOCGIFFLAGS, &ifr) < 0) { |
| 503 | PLOG(WARNING) << "ioctl() failed to get interface flag on " << ifname; |
| 504 | return false; |
| 505 | } |
Garrick Evans | 664a82f | 2019-12-17 12:18:05 +0900 | [diff] [blame] | 506 | ifr.ifr_flags |= on; |
| 507 | ifr.ifr_flags &= ~off; |
Taoyu Li | 90c1391 | 2019-11-26 17:56:54 +0900 | [diff] [blame] | 508 | if ((*ioctl_)(sock.get(), SIOCSIFFLAGS, &ifr) < 0) { |
Garrick Evans | 664a82f | 2019-12-17 12:18:05 +0900 | [diff] [blame] | 509 | PLOG(WARNING) << "ioctl() failed to set flag 0x" << std::hex << on |
| 510 | << " unset flag 0x" << std::hex << off << " on " << ifname; |
Taoyu Li | 90c1391 | 2019-11-26 17:56:54 +0900 | [diff] [blame] | 511 | return false; |
| 512 | } |
| 513 | return true; |
| 514 | } |
| 515 | |
Garrick Evans | 260ff30 | 2019-07-25 11:22:50 +0900 | [diff] [blame] | 516 | bool Datapath::AddIPv6HostRoute(const std::string& ifname, |
| 517 | const std::string& ipv6_addr, |
| 518 | int ipv6_prefix_len) { |
| 519 | std::string ipv6_addr_cidr = |
| 520 | ipv6_addr + "/" + std::to_string(ipv6_prefix_len); |
| 521 | |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 522 | return process_runner_->ip6("route", "replace", |
| 523 | {ipv6_addr_cidr, "dev", ifname}) == 0; |
Garrick Evans | 260ff30 | 2019-07-25 11:22:50 +0900 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | void Datapath::RemoveIPv6HostRoute(const std::string& ifname, |
| 527 | const std::string& ipv6_addr, |
| 528 | int ipv6_prefix_len) { |
| 529 | std::string ipv6_addr_cidr = |
| 530 | ipv6_addr + "/" + std::to_string(ipv6_prefix_len); |
| 531 | |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 532 | process_runner_->ip6("route", "del", {ipv6_addr_cidr, "dev", ifname}); |
Garrick Evans | 260ff30 | 2019-07-25 11:22:50 +0900 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | bool Datapath::AddIPv6Neighbor(const std::string& ifname, |
| 536 | const std::string& ipv6_addr) { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 537 | return process_runner_->ip6("neigh", "add", |
| 538 | {"proxy", ipv6_addr, "dev", ifname}) == 0; |
Garrick Evans | 260ff30 | 2019-07-25 11:22:50 +0900 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | void Datapath::RemoveIPv6Neighbor(const std::string& ifname, |
| 542 | const std::string& ipv6_addr) { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 543 | process_runner_->ip6("neigh", "del", {"proxy", ipv6_addr, "dev", ifname}); |
Garrick Evans | 260ff30 | 2019-07-25 11:22:50 +0900 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | bool Datapath::AddIPv6Forwarding(const std::string& ifname1, |
| 547 | const std::string& ifname2) { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 548 | if (process_runner_->ip6tables( |
| 549 | "filter", |
| 550 | {"-C", "FORWARD", "-i", ifname1, "-o", ifname2, "-j", "ACCEPT", "-w"}, |
| 551 | false /*log_failures*/) != 0 && |
| 552 | process_runner_->ip6tables( |
| 553 | "filter", {"-A", "FORWARD", "-i", ifname1, "-o", ifname2, "-j", |
| 554 | "ACCEPT", "-w"}) != 0) { |
Garrick Evans | 260ff30 | 2019-07-25 11:22:50 +0900 | [diff] [blame] | 555 | return false; |
| 556 | } |
| 557 | |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 558 | if (process_runner_->ip6tables( |
| 559 | "filter", |
| 560 | {"-C", "FORWARD", "-i", ifname2, "-o", ifname1, "-j", "ACCEPT", "-w"}, |
| 561 | false /*log_failures*/) != 0 && |
| 562 | process_runner_->ip6tables( |
| 563 | "filter", {"-A", "FORWARD", "-i", ifname2, "-o", ifname1, "-j", |
| 564 | "ACCEPT", "-w"}) != 0) { |
Garrick Evans | 260ff30 | 2019-07-25 11:22:50 +0900 | [diff] [blame] | 565 | RemoveIPv6Forwarding(ifname1, ifname2); |
| 566 | return false; |
| 567 | } |
| 568 | |
| 569 | return true; |
| 570 | } |
| 571 | |
| 572 | void Datapath::RemoveIPv6Forwarding(const std::string& ifname1, |
| 573 | const std::string& ifname2) { |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 574 | process_runner_->ip6tables("filter", {"-D", "FORWARD", "-i", ifname1, "-o", |
| 575 | ifname2, "-j", "ACCEPT", "-w"}); |
Garrick Evans | 260ff30 | 2019-07-25 11:22:50 +0900 | [diff] [blame] | 576 | |
Garrick Evans | 8e8e347 | 2020-01-23 14:03:50 +0900 | [diff] [blame] | 577 | process_runner_->ip6tables("filter", {"-D", "FORWARD", "-i", ifname2, "-o", |
| 578 | ifname1, "-j", "ACCEPT", "-w"}); |
Garrick Evans | 260ff30 | 2019-07-25 11:22:50 +0900 | [diff] [blame] | 579 | } |
| 580 | |
Garrick Evans | 3d97a39 | 2020-02-21 15:24:37 +0900 | [diff] [blame] | 581 | bool Datapath::AddIPv4Route(uint32_t gateway_addr, |
| 582 | uint32_t addr, |
| 583 | uint32_t netmask) { |
| 584 | struct rtentry route; |
| 585 | memset(&route, 0, sizeof(route)); |
Hugo Benichi | e8758b5 | 2020-04-03 14:49:01 +0900 | [diff] [blame] | 586 | SetSockaddrIn(&route.rt_gateway, gateway_addr); |
| 587 | SetSockaddrIn(&route.rt_dst, addr & netmask); |
| 588 | SetSockaddrIn(&route.rt_genmask, netmask); |
Garrick Evans | 3d97a39 | 2020-02-21 15:24:37 +0900 | [diff] [blame] | 589 | route.rt_flags = RTF_UP | RTF_GATEWAY; |
Hugo Benichi | e8758b5 | 2020-04-03 14:49:01 +0900 | [diff] [blame] | 590 | return ModifyRtentry(SIOCADDRT, &route); |
| 591 | } |
Garrick Evans | 3d97a39 | 2020-02-21 15:24:37 +0900 | [diff] [blame] | 592 | |
Hugo Benichi | e8758b5 | 2020-04-03 14:49:01 +0900 | [diff] [blame] | 593 | bool Datapath::DeleteIPv4Route(uint32_t gateway_addr, |
| 594 | uint32_t addr, |
| 595 | uint32_t netmask) { |
| 596 | struct rtentry route; |
| 597 | memset(&route, 0, sizeof(route)); |
| 598 | SetSockaddrIn(&route.rt_gateway, gateway_addr); |
| 599 | SetSockaddrIn(&route.rt_dst, addr & netmask); |
| 600 | SetSockaddrIn(&route.rt_genmask, netmask); |
| 601 | route.rt_flags = RTF_UP | RTF_GATEWAY; |
| 602 | return ModifyRtentry(SIOCDELRT, &route); |
| 603 | } |
| 604 | |
| 605 | bool Datapath::AddIPv4Route(const std::string& ifname, |
| 606 | uint32_t addr, |
| 607 | uint32_t netmask) { |
| 608 | struct rtentry route; |
| 609 | memset(&route, 0, sizeof(route)); |
| 610 | SetSockaddrIn(&route.rt_dst, addr & netmask); |
| 611 | SetSockaddrIn(&route.rt_genmask, netmask); |
| 612 | char rt_dev[IFNAMSIZ]; |
| 613 | strncpy(rt_dev, ifname.c_str(), IFNAMSIZ); |
| 614 | rt_dev[IFNAMSIZ - 1] = '\0'; |
| 615 | route.rt_dev = rt_dev; |
| 616 | route.rt_flags = RTF_UP | RTF_GATEWAY; |
| 617 | return ModifyRtentry(SIOCADDRT, &route); |
| 618 | } |
| 619 | |
| 620 | bool Datapath::DeleteIPv4Route(const std::string& ifname, |
| 621 | uint32_t addr, |
| 622 | uint32_t netmask) { |
| 623 | struct rtentry route; |
| 624 | memset(&route, 0, sizeof(route)); |
| 625 | SetSockaddrIn(&route.rt_dst, addr & netmask); |
| 626 | SetSockaddrIn(&route.rt_genmask, netmask); |
| 627 | char rt_dev[IFNAMSIZ]; |
| 628 | strncpy(rt_dev, ifname.c_str(), IFNAMSIZ); |
| 629 | rt_dev[IFNAMSIZ - 1] = '\0'; |
| 630 | route.rt_dev = rt_dev; |
| 631 | route.rt_flags = RTF_UP | RTF_GATEWAY; |
| 632 | return ModifyRtentry(SIOCDELRT, &route); |
| 633 | } |
| 634 | |
| 635 | bool Datapath::ModifyRtentry(unsigned long op, struct rtentry* route) { |
| 636 | DCHECK(route); |
| 637 | if (op != SIOCADDRT && op != SIOCDELRT) { |
| 638 | LOG(ERROR) << "Invalid operation " << op << " for rtentry " << route; |
Garrick Evans | 3d97a39 | 2020-02-21 15:24:37 +0900 | [diff] [blame] | 639 | return false; |
| 640 | } |
Hugo Benichi | e8758b5 | 2020-04-03 14:49:01 +0900 | [diff] [blame] | 641 | base::ScopedFD fd(socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0)); |
| 642 | if (!fd.is_valid()) { |
| 643 | PLOG(ERROR) << "Failed to create socket for adding rtentry " << route; |
| 644 | return false; |
| 645 | } |
| 646 | if (HANDLE_EINTR(ioctl_(fd.get(), op, route)) != 0) { |
| 647 | std::string opname = op == SIOCADDRT ? "add" : "delete"; |
| 648 | PLOG(ERROR) << "Failed to " << opname << " rtentry " << route; |
Garrick Evans | 3d97a39 | 2020-02-21 15:24:37 +0900 | [diff] [blame] | 649 | return false; |
| 650 | } |
| 651 | return true; |
| 652 | } |
| 653 | |
Garrick Evans | 3388a03 | 2020-03-24 11:25:55 +0900 | [diff] [blame] | 654 | } // namespace patchpanel |