blob: 37f4de306fd690dad696609fa16fb3fa1ed2a58e [file] [log] [blame]
Garrick Evansf0ab7132019-06-18 14:50:42 +09001// Copyright 2019 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Garrick Evans3388a032020-03-24 11:25:55 +09005#ifndef PATCHPANEL_DATAPATH_H_
6#define PATCHPANEL_DATAPATH_H_
Garrick Evansf0ab7132019-06-18 14:50:42 +09007
Hugo Benichie8758b52020-04-03 14:49:01 +09008#include <net/route.h>
Hugo Benichi33860d72020-07-09 16:34:01 +09009#include <sys/types.h>
Hugo Benichie8758b52020-04-03 14:49:01 +090010
Hugo Benichifcf81022020-12-04 11:01:37 +090011#include <iostream>
Hugo Benichibb38bdd2021-05-14 10:36:11 +090012#include <map>
13#include <memory>
Hugo Benichi2a940542020-10-26 18:50:49 +090014#include <set>
Garrick Evansf0ab7132019-06-18 14:50:42 +090015#include <string>
Hugo Benichi2a940542020-10-26 18:50:49 +090016#include <vector>
Garrick Evansf0ab7132019-06-18 14:50:42 +090017
18#include <base/macros.h>
Hugo Benichi82ed5cf2020-09-08 21:30:22 +090019#include <gtest/gtest_prod.h> // for FRIEND_TEST
Garrick Evansf0ab7132019-06-18 14:50:42 +090020
Jason Jeremy Imana7273a32020-08-04 11:25:31 +090021#include "patchpanel/firewall.h"
Garrick Evans3388a032020-03-24 11:25:55 +090022#include "patchpanel/mac_address_generator.h"
23#include "patchpanel/minijailed_process_runner.h"
Hugo Benichi8d622b52020-08-13 15:24:12 +090024#include "patchpanel/routing_service.h"
Garrick Evans3388a032020-03-24 11:25:55 +090025#include "patchpanel/subnet.h"
Garrick Evansf0ab7132019-06-18 14:50:42 +090026
Garrick Evans3388a032020-03-24 11:25:55 +090027namespace patchpanel {
Garrick Evansf0ab7132019-06-18 14:50:42 +090028
Hugo Benichifcf81022020-12-04 11:01:37 +090029// Struct holding parameters for Datapath::StartRoutingNamespace requests.
30struct ConnectedNamespace {
31 // The pid of the client network namespace.
32 pid_t pid;
33 // The name attached to the client network namespace.
34 std::string netns_name;
Hugo Benichi93306e52020-12-04 16:08:00 +090035 // Source to which traffic from |host_ifname| will be attributed.
36 TrafficSource source;
Hugo Benichifcf81022020-12-04 11:01:37 +090037 // Name of the shill device for routing outbound traffic from the client
38 // namespace. Empty if outbound traffic should be forwarded to the highest
39 // priority network (physical or virtual).
40 std::string outbound_ifname;
Hugo Benichi93306e52020-12-04 16:08:00 +090041 // If |outbound_ifname| is empty and |route_on_vpn| is false, the traffic from
42 // the client namespace will be routed to the highest priority physical
43 // device. If |outbound_ifname| is empty and |route_on_vpn| is true, the
44 // traffic will be routed through VPN connections. If |outbound_ifname|
45 // specifies a valid physical device, |route_on_vpn| is ignored.
46 bool route_on_vpn;
Hugo Benichifcf81022020-12-04 11:01:37 +090047 // Name of the "local" veth device visible on the host namespace.
48 std::string host_ifname;
49 // Name of the "remote" veth device moved into the client namespace.
50 std::string peer_ifname;
51 // IPv4 subnet assigned to the client namespace.
52 std::unique_ptr<Subnet> peer_subnet;
53 // MAC address of the "remote" veth device.
54 MacAddress peer_mac_addr;
55};
56
57std::ostream& operator<<(std::ostream& stream,
58 const ConnectedNamespace& nsinfo);
59
Hugo Benichid82d8832020-08-14 10:05:03 +090060// Simple enum of bitmasks used for specifying a set of IP family values.
61enum IpFamily {
62 NONE = 0,
63 IPv4 = 1 << 0,
64 IPv6 = 1 << 1,
Taoyu Lia0727dc2020-09-24 19:54:59 +090065 Dual = IPv4 | IPv6, // (1 << 0) | (1 << 1);
Hugo Benichid82d8832020-08-14 10:05:03 +090066};
67
Taoyu Li90c13912019-11-26 17:56:54 +090068// cros lint will yell to force using int16/int64 instead of long here, however
69// note that unsigned long IS the correct signature for ioctl in Linux kernel -
70// it's 32 bits on 32-bit platform and 64 bits on 64-bit one.
71using ioctl_req_t = unsigned long;
72typedef int (*ioctl_t)(int, ioctl_req_t, ...);
Garrick Evansc7ae82c2019-09-04 16:25:10 +090073
Garrick Evans54861622019-07-19 09:05:09 +090074// Returns for given interface name the host name of a ARC veth pair.
Garrick Evans2f581a02020-05-11 10:43:35 +090075std::string ArcVethHostName(const std::string& ifname);
Garrick Evans54861622019-07-19 09:05:09 +090076
Garrick Evans8a067562020-05-11 12:47:30 +090077// Returns the ARC bridge interface name for the given interface.
78std::string ArcBridgeName(const std::string& ifname);
79
Garrick Evansf0ab7132019-06-18 14:50:42 +090080// ARC networking data path configuration utility.
Garrick Evans54861622019-07-19 09:05:09 +090081// IPV4 addresses are always specified in singular dotted-form (a.b.c.d)
82// (not in CIDR representation
Garrick Evansf0ab7132019-06-18 14:50:42 +090083class Datapath {
84 public:
Jason Jeremy Imana7273a32020-08-04 11:25:31 +090085 // |process_runner| and |firewall| must not be null; it is not owned.
86 Datapath(MinijailedProcessRunner* process_runner, Firewall* firewall);
Garrick Evansc7ae82c2019-09-04 16:25:10 +090087 // Provided for testing only.
Jason Jeremy Imana7273a32020-08-04 11:25:31 +090088 Datapath(MinijailedProcessRunner* process_runner,
89 Firewall* firewall,
90 ioctl_t ioctl_hook);
Qijiang Fan6bc59e12020-11-11 02:51:06 +090091 Datapath(const Datapath&) = delete;
92 Datapath& operator=(const Datapath&) = delete;
93
Garrick Evansf0ab7132019-06-18 14:50:42 +090094 virtual ~Datapath() = default;
95
Hugo Benichibf811c62020-09-07 17:30:45 +090096 // Start and stop the Datapath, creating or destroying the initial iptables
97 // setup needed for forwarding traffic from VMs and containers and for
98 // fwmark based routing.
99 virtual void Start();
100 virtual void Stop();
101
Hugo Benichi33860d72020-07-09 16:34:01 +0900102 // Attaches the name |netns_name| to a network namespace identified by
103 // |netns_pid|. If |netns_name| had already been created, it will be deleted
104 // first.
105 virtual bool NetnsAttachName(const std::string& netns_name, pid_t netns_pid);
106
107 // Deletes the name |netns_name| of a network namespace.
108 virtual bool NetnsDeleteName(const std::string& netns_name);
109
Garrick Evans8a949dc2019-07-18 16:17:53 +0900110 virtual bool AddBridge(const std::string& ifname,
Garrick Evans7a1a9ee2020-01-28 11:03:57 +0900111 uint32_t ipv4_addr,
112 uint32_t ipv4_prefix_len);
Garrick Evans8a949dc2019-07-18 16:17:53 +0900113 virtual void RemoveBridge(const std::string& ifname);
114
Garrick Evans621ed262019-11-13 12:28:43 +0900115 virtual bool AddToBridge(const std::string& br_ifname,
116 const std::string& ifname);
117
Garrick Evansc7ae82c2019-09-04 16:25:10 +0900118 // Adds a new TAP device.
119 // |name| may be empty, in which case a default device name will be used;
120 // it may be a template (e.g. vmtap%d), in which case the kernel will
121 // generate the name; or it may be fully defined. In all cases, upon success,
122 // the function returns the actual name of the interface.
Garrick Evans621ed262019-11-13 12:28:43 +0900123 // |mac_addr| and |ipv4_addr| should be null if this interface will be later
124 // bridged.
Garrick Evans4f9f5572019-11-26 10:25:16 +0900125 // If |user| is empty, no owner will be set
Garrick Evansc7ae82c2019-09-04 16:25:10 +0900126 virtual std::string AddTAP(const std::string& name,
Garrick Evans621ed262019-11-13 12:28:43 +0900127 const MacAddress* mac_addr,
128 const SubnetAddress* ipv4_addr,
Garrick Evans4f9f5572019-11-26 10:25:16 +0900129 const std::string& user);
Garrick Evansc7ae82c2019-09-04 16:25:10 +0900130
131 // |ifname| must be the actual name of the interface.
132 virtual void RemoveTAP(const std::string& ifname);
133
134 // The following are iptables methods.
135 // When specified, |ipv4_addr| is always singlar dotted-form (a.b.c.d)
136 // IPv4 address (not a CIDR representation).
137
Hugo Benichi76675592020-04-08 14:29:57 +0900138 // Creates a virtual interface pair split across the current namespace and the
139 // namespace corresponding to |pid|, and set up the remote interface
140 // |peer_ifname| according // to the given parameters.
141 virtual bool ConnectVethPair(pid_t pid,
Hugo Benichi33860d72020-07-09 16:34:01 +0900142 const std::string& netns_name,
Hugo Benichi76675592020-04-08 14:29:57 +0900143 const std::string& veth_ifname,
144 const std::string& peer_ifname,
145 const MacAddress& remote_mac_addr,
146 uint32_t remote_ipv4_addr,
147 uint32_t remote_ipv4_prefix_len,
148 bool remote_multicast_flag);
149
Garrick Evans54861622019-07-19 09:05:09 +0900150 virtual void RemoveInterface(const std::string& ifname);
151
Hugo Benichi954bae62021-04-09 09:12:30 +0900152 // Create an OUTPUT DROP rule for any locally originated traffic
Hugo Benichi321f23b2020-09-25 15:42:05 +0900153 // whose src IPv4 matches |src_ip| and would exit |oif|. This is mainly used
154 // for dropping Chrome webRTC traffic incorrectly bound on ARC and other
155 // guests virtual interfaces (chromium:898210).
156 virtual bool AddSourceIPv4DropRule(const std::string& oif,
157 const std::string& src_ip);
Hugo Benichi321f23b2020-09-25 15:42:05 +0900158
Hugo Benichi7c342672020-09-08 09:18:14 +0900159 // Creates a virtual ethernet interface pair shared with the client namespace
Hugo Benichifcf81022020-12-04 11:01:37 +0900160 // of |nsinfo.pid| and sets up routing outside and inside the client namespace
161 // for connecting the client namespace to the network.
162 bool StartRoutingNamespace(const ConnectedNamespace& nsinfo);
Hugo Benichi7c342672020-09-08 09:18:14 +0900163 // Destroys the virtual ethernet interface, routing, and network namespace
Hugo Benichifcf81022020-12-04 11:01:37 +0900164 // name set for |nsinfo.netns_name| by StartRoutingNamespace. The default
165 // route set inside the |nsinfo.netns_name| by patchpanel is not destroyed and
166 // it is assumed the client will teardown the namespace.
167 void StopRoutingNamespace(const ConnectedNamespace& nsinfo);
Hugo Benichi7c342672020-09-08 09:18:14 +0900168
Hugo Benichi8d622b52020-08-13 15:24:12 +0900169 // Sets up IPv4 SNAT, IP forwarding, and traffic marking for the given
170 // virtual device |int_ifname| associated to |source|. if |ext_ifname| is
171 // empty, the device is implicitly routed through the highest priority
Hugo Benichibfc49112020-12-14 12:54:44 +0900172 // physical network when |route_on_vpn| is false, or through the highest
173 // priority logical network when |route_on_vpn| is true. If |ext_ifname| is
174 // defined, the device is routed to |ext_ifname| and |route_on_vpn| is
175 // ignored.
Hugo Benichi8d622b52020-08-13 15:24:12 +0900176 virtual void StartRoutingDevice(const std::string& ext_ifname,
177 const std::string& int_ifname,
178 uint32_t int_ipv4_addr,
Hugo Benichi93306e52020-12-04 16:08:00 +0900179 TrafficSource source,
180 bool route_on_vpn);
Hugo Benichi8d622b52020-08-13 15:24:12 +0900181
182 // Removes IPv4 iptables, IP forwarding, and traffic marking for the given
183 // virtual device |int_ifname|.
184 virtual void StopRoutingDevice(const std::string& ext_ifname,
185 const std::string& int_ifname,
186 uint32_t int_ipv4_addr,
Hugo Benichi93306e52020-12-04 16:08:00 +0900187 TrafficSource source,
188 bool route_on_vpn);
Hugo Benichi8d622b52020-08-13 15:24:12 +0900189
Hugo Benichi76be34a2020-08-26 22:35:54 +0900190 // Starts or stops marking conntrack entries routed to |ext_ifname| with its
191 // associated fwmark routing tag. Once a conntrack entry is marked with the
192 // fwmark routing tag of a external device, the connection will be pinned
193 // to that deviced if conntrack fwmark restore is set for the source.
194 virtual void StartConnectionPinning(const std::string& ext_ifname);
195 virtual void StopConnectionPinning(const std::string& ext_ifname);
Hugo Benichi2a940542020-10-26 18:50:49 +0900196 // Starts or stops VPN routing for:
197 // - Local sockets of binaries running under uids eligible to be routed
198 // through VPN connections. These uids are defined by |kLocalSourceTypes|
199 // in routing_service.h
200 // - Forwarded virtual devices tracking the default network.
201 virtual void StartVpnRouting(const std::string& vpn_ifname);
202 virtual void StopVpnRouting(const std::string& vpn_ifname);
Hugo Benichi76be34a2020-08-26 22:35:54 +0900203
Hugo Benichibb38bdd2021-05-14 10:36:11 +0900204 // Starts and stops VPN lockdown mode. When patchpanel VPN lockdown is enabled
205 // and no VPN connection exists, any non-ARC traffic that would be routed to a
206 // VPN connection is instead rejected in iptables. ARC traffic is ignored
207 // because Android already implements VPN lockdown.
208 virtual void SetVpnLockdown(bool enable_vpn_lockdown);
209
Taoyu Li90c13912019-11-26 17:56:54 +0900210 // Methods supporting IPv6 configuration for ARC.
Garrick Evans664a82f2019-12-17 12:18:05 +0900211 virtual bool MaskInterfaceFlags(const std::string& ifname,
212 uint16_t on,
213 uint16_t off = 0);
Garrick Evans260ff302019-07-25 11:22:50 +0900214
Hugo Benichid82d8832020-08-14 10:05:03 +0900215 // Convenience functions for enabling or disabling IPv6 forwarding in both
216 // directions between a pair of interfaces
Taoyu Li90c13912019-11-26 17:56:54 +0900217 virtual bool AddIPv6Forwarding(const std::string& ifname1,
218 const std::string& ifname2);
219 virtual void RemoveIPv6Forwarding(const std::string& ifname1,
220 const std::string& ifname2);
221
Garrick Evans260ff302019-07-25 11:22:50 +0900222 virtual bool AddIPv6HostRoute(const std::string& ifname,
223 const std::string& ipv6_addr,
224 int ipv6_prefix_len);
225 virtual void RemoveIPv6HostRoute(const std::string& ifname,
226 const std::string& ipv6_addr,
227 int ipv6_prefix_len);
228
Taoyu Lia0727dc2020-09-24 19:54:59 +0900229 virtual bool AddIPv6Address(const std::string& ifname,
230 const std::string& ipv6_addr);
231 virtual void RemoveIPv6Address(const std::string& ifname,
232 const std::string& ipv6_addr);
Garrick Evans260ff302019-07-25 11:22:50 +0900233
Hugo Benichie8758b52020-04-03 14:49:01 +0900234 // Adds (or deletes) a route to direct to |gateway_addr| the traffic destined
235 // to the subnet defined by |addr| and |netmask|.
Garrick Evans3d97a392020-02-21 15:24:37 +0900236 virtual bool AddIPv4Route(uint32_t gateway_addr,
237 uint32_t addr,
238 uint32_t netmask);
Hugo Benichie8758b52020-04-03 14:49:01 +0900239 virtual bool DeleteIPv4Route(uint32_t gateway_addr,
240 uint32_t addr,
241 uint32_t netmask);
242 // Adds (or deletes) a route to direct to |ifname| the traffic destined to the
243 // subnet defined by |addr| and |netmask|.
244 virtual bool AddIPv4Route(const std::string& ifname,
245 uint32_t addr,
246 uint32_t netmask);
247 virtual bool DeleteIPv4Route(const std::string& ifname,
248 uint32_t addr,
249 uint32_t netmask);
Garrick Evans3d97a392020-02-21 15:24:37 +0900250
Jason Jeremy Imana7273a32020-08-04 11:25:31 +0900251 // Adds (or deletes) an iptables rule for ADB port forwarding.
252 virtual bool AddAdbPortForwardRule(const std::string& ifname);
253 virtual void DeleteAdbPortForwardRule(const std::string& ifname);
254
255 // Adds (or deletes) an iptables rule for ADB port access.
256 virtual bool AddAdbPortAccessRule(const std::string& ifname);
257 virtual void DeleteAdbPortAccessRule(const std::string& ifname);
258
Hugo Benichi1e0656f2021-02-15 15:43:38 +0900259 // Create (or delete) DNAT rules for redirecting DNS queries from system
260 // services to the nameservers of a particular physical networks. These
261 // DNAT rules are only applied if a VPN is connected and allows system
262 // services to resolve hostnames even if a VPN application configures DNS
263 // addresses only routable through the VPN (b/178331695).
264 // TODO(b/171157837) Replaces these rules with the system DNS proxy.
265 bool AddRedirectDnsRule(const std::string& ifname,
266 const std::string dns_ipv4_addr);
267 bool RemoveRedirectDnsRule(const std::string& ifname);
268
Hugo Benichiaf9d8a72020-08-26 13:28:13 +0900269 // Set or override the interface name to index mapping for |ifname|.
270 // Only used for testing.
271 void SetIfnameIndex(const std::string& ifname, int ifindex);
272
Hugo Benichif0f55562021-04-02 15:25:02 +0900273 // Add, remove, or flush chain |chain| in table |table|.
274 bool AddChain(IpFamily family,
275 const std::string& table,
276 const std::string& name);
277 bool RemoveChain(IpFamily family,
278 const std::string& table,
279 const std::string& name);
280 bool FlushChain(IpFamily family,
281 const std::string& table,
282 const std::string& name);
Hugo Benichicd27f4e2020-11-19 18:32:23 +0900283 // Manipulates a chain |chain| in table |table|.
284 bool ModifyChain(IpFamily family,
285 const std::string& table,
286 const std::string& op,
287 const std::string& chain,
288 bool log_failures = true);
Hugo Benichiddf00842020-11-20 10:24:08 +0900289 // Sends an iptables command for table |table|.
290 bool ModifyIptables(IpFamily family,
291 const std::string& table,
292 const std::vector<std::string>& argv,
293 bool log_failures = true);
Hugo Benichicd27f4e2020-11-19 18:32:23 +0900294
Garrick Evans260ff302019-07-25 11:22:50 +0900295 MinijailedProcessRunner& runner() const;
296
Garrick Evansf0ab7132019-06-18 14:50:42 +0900297 private:
Hugo Benichi91ee09f2020-12-03 22:24:22 +0900298 // Attempts to flush all built-in iptables chains used by patchpanel, and to
299 // delete all additionals chains created by patchpanel for routing. Traffic
300 // accounting chains are not deleted.
301 void ResetIptables();
Hugo Benichi82ed5cf2020-09-08 21:30:22 +0900302 // Creates a virtual interface pair.
303 bool AddVirtualInterfacePair(const std::string& netns_name,
304 const std::string& veth_ifname,
305 const std::string& peer_ifname);
306 // Sets the configuration of an interface.
307 bool ConfigureInterface(const std::string& ifname,
308 const MacAddress& mac_addr,
309 uint32_t ipv4_addr,
310 uint32_t ipv4_prefix_len,
311 bool up,
312 bool enable_multicast);
313 // Sets the link status.
314 bool ToggleInterface(const std::string& ifname, bool up);
Hugo Benichi82ed5cf2020-09-08 21:30:22 +0900315 // Create (or delete) pre-routing rules allowing direct ingress on |ifname|
316 // to guest destination |ipv4_addr|.
317 bool AddInboundIPv4DNAT(const std::string& ifname,
318 const std::string& ipv4_addr);
319 void RemoveInboundIPv4DNAT(const std::string& ifname,
320 const std::string& ipv4_addr);
Hugo Benichi1e0656f2021-02-15 15:43:38 +0900321 bool ModifyRedirectDnsDNATRule(const std::string& op,
322 const std::string& protocol,
323 const std::string& ifname,
324 const std::string& dns_ipv4_addr);
325 bool ModifyRedirectDnsJumpRule(const std::string& op);
Hugo Benichi82ed5cf2020-09-08 21:30:22 +0900326
Hugo Benichi3a9162b2020-09-09 15:47:40 +0900327 bool ModifyConnmarkSet(IpFamily family,
328 const std::string& chain,
329 const std::string& op,
Hugo Benichi3a9162b2020-09-09 15:47:40 +0900330 Fwmark mark,
331 Fwmark mask);
Hugo Benichiaf9d8a72020-08-26 13:28:13 +0900332 bool ModifyConnmarkRestore(IpFamily family,
333 const std::string& chain,
334 const std::string& op,
Hugo Benichi1af52392020-11-27 18:09:32 +0900335 const std::string& iif,
336 Fwmark mask);
337 bool ModifyConnmarkSave(IpFamily family,
338 const std::string& chain,
339 const std::string& op,
Hugo Benichi1af52392020-11-27 18:09:32 +0900340 Fwmark mask);
Hugo Benichi2a940542020-10-26 18:50:49 +0900341 bool ModifyFwmarkRoutingTag(const std::string& chain,
342 const std::string& op,
Hugo Benichid872d3d2021-03-29 10:20:53 +0900343 Fwmark routing_mark);
344 bool ModifyFwmarkSourceTag(const std::string& chain,
345 const std::string& op,
Hugo Benichi9be19b12020-08-14 15:33:40 +0900346 TrafficSource source);
Hugo Benichi3a9162b2020-09-09 15:47:40 +0900347 bool ModifyFwmarkDefaultLocalSourceTag(const std::string& op,
348 TrafficSource source);
349 bool ModifyFwmarkLocalSourceTag(const std::string& op,
350 const LocalSourceSpecs& source);
351 bool ModifyFwmark(IpFamily family,
352 const std::string& chain,
353 const std::string& op,
354 const std::string& iif,
355 const std::string& uid_name,
Hugo Benichi7e3b1fc2020-11-19 15:47:05 +0900356 uint32_t classid,
Hugo Benichi3a9162b2020-09-09 15:47:40 +0900357 Fwmark mark,
358 Fwmark mask,
359 bool log_failures = true);
Hugo Benichid82d8832020-08-14 10:05:03 +0900360 bool ModifyIpForwarding(IpFamily family,
361 const std::string& op,
362 const std::string& iif,
363 const std::string& oif,
364 bool log_failures = true);
Hugo Benichiff3cbcf2021-04-03 00:22:06 +0900365 bool ModifyJumpRule(IpFamily family,
366 const std::string& table,
367 const std::string& op,
368 const std::string& chain,
369 const std::string& target,
370 const std::string& iif,
371 const std::string& oif,
372 bool log_failures = true);
Hugo Benichi3ef370b2020-11-16 19:07:17 +0900373 bool ModifyFwmarkVpnJumpRule(const std::string& chain,
374 const std::string& op,
Hugo Benichi3ef370b2020-11-16 19:07:17 +0900375 Fwmark mark,
376 Fwmark mask);
Hugo Benichiaf9d8a72020-08-26 13:28:13 +0900377 bool ModifyRtentry(ioctl_req_t op, struct rtentry* route);
Hugo Benichi8c526e92021-03-25 14:59:59 +0900378 // Uses if_nametoindex to return the interface index of |ifname|. If |ifname|
379 // does not exist anymore, looks up the cache |if_nametoindex_|. It is
380 // incorrect to use this function in situations where the interface has been
381 // recreated and the older value must be recovered (b/183679000).
Hugo Benichiaf9d8a72020-08-26 13:28:13 +0900382 int FindIfIndex(const std::string& ifname);
Hugo Benichid82d8832020-08-14 10:05:03 +0900383
Garrick Evansf0ab7132019-06-18 14:50:42 +0900384 MinijailedProcessRunner* process_runner_;
Jason Jeremy Imana7273a32020-08-04 11:25:31 +0900385 Firewall* firewall_;
Garrick Evansc7ae82c2019-09-04 16:25:10 +0900386 ioctl_t ioctl_;
Garrick Evansf0ab7132019-06-18 14:50:42 +0900387
Hugo Benichi82ed5cf2020-09-08 21:30:22 +0900388 FRIEND_TEST(DatapathTest, AddInboundIPv4DNAT);
Hugo Benichi82ed5cf2020-09-08 21:30:22 +0900389 FRIEND_TEST(DatapathTest, AddVirtualInterfacePair);
390 FRIEND_TEST(DatapathTest, ConfigureInterface);
Hugo Benichi82ed5cf2020-09-08 21:30:22 +0900391 FRIEND_TEST(DatapathTest, RemoveInboundIPv4DNAT);
Hugo Benichi82ed5cf2020-09-08 21:30:22 +0900392 FRIEND_TEST(DatapathTest, RemoveOutboundIPv4SNATMark);
Hugo Benichi82ed5cf2020-09-08 21:30:22 +0900393 FRIEND_TEST(DatapathTest, ToggleInterface);
394
Hugo Benichiaf9d8a72020-08-26 13:28:13 +0900395 // A map used for remembering the interface index of an interface. This
396 // information is necessary when cleaning up iptables fwmark rules that
397 // directly references the interface index. When removing these rules on
398 // an RTM_DELLINK event, the interface index cannot be retrieved anymore.
399 // A new entry is only added when a new physical device appears, and entries
400 // are not removed.
401 // TODO(b/161507671) Rely on RoutingService to obtain this information once
402 // shill/routing_table.cc has been migrated to patchpanel.
403 std::map<std::string, int> if_nametoindex_;
Hugo Benichi1e0656f2021-02-15 15:43:38 +0900404
405 // A map used for tracking the primary IPv4 dns address associated to a given
406 // Shill Device known by its interface name. This is used for redirecting
407 // DNS queries of system services when a VPN is connected.
408 std::map<std::string, std::string> physical_dns_addresses_;
Garrick Evansf0ab7132019-06-18 14:50:42 +0900409};
410
Garrick Evans3388a032020-03-24 11:25:55 +0900411} // namespace patchpanel
Garrick Evansf0ab7132019-06-18 14:50:42 +0900412
Garrick Evans3388a032020-03-24 11:25:55 +0900413#endif // PATCHPANEL_DATAPATH_H_