|
16 | 16 |
|
17 | 17 | #include "cuttlefish/common/libs/utils/network.h" |
18 | 18 |
|
19 | | -#ifdef __linux__ |
20 | | -#include <linux/if_ether.h> |
21 | | -// Kernel headers don't mix well with userspace headers, but there is no |
22 | | -// userspace header that provides the if_tun.h #defines. Include the kernel |
23 | | -// header, but move conflicting definitions out of the way using macros. |
24 | | -#define ethhdr __kernel_ethhdr |
25 | | -#include <linux/if_tun.h> |
26 | | -#undef ethhdr |
27 | | -#endif |
28 | | - |
29 | 19 | #include <arpa/inet.h> |
30 | 20 | #include <fcntl.h> |
31 | 21 | #include <ifaddrs.h> |
32 | | -#include <net/if.h> |
33 | 22 | #include <stdint.h> |
34 | 23 |
|
35 | 24 | #include <cstring> |
@@ -86,68 +75,6 @@ bool NetworkInterfaceExists(const std::string& interface_name) { |
86 | 75 | return ret; |
87 | 76 | } |
88 | 77 |
|
89 | | -#ifdef __linux__ |
90 | | -static std::optional<Command> GrepCommand() { |
91 | | - if (FileExists("/usr/bin/grep")) { |
92 | | - return Command("/usr/bin/grep"); |
93 | | - } else if (FileExists("/bin/grep")) { |
94 | | - return Command("/bin/grep"); |
95 | | - } else { |
96 | | - return {}; |
97 | | - } |
98 | | -} |
99 | | - |
100 | | -std::set<std::string> TapInterfacesInUse() { |
101 | | - std::vector<std::string> fdinfo_list; |
102 | | - |
103 | | - Result<std::vector<std::string>> processes = DirectoryContents("/proc"); |
104 | | - if (!processes.ok()) { |
105 | | - LOG(ERROR) << "Failed to get contents of `/proc/`"; |
106 | | - return {}; |
107 | | - } |
108 | | - for (const std::string& process : *processes) { |
109 | | - std::string fdinfo_path = fmt::format("/proc/{}/fdinfo", process); |
110 | | - Result<std::vector<std::string>> fdinfos = DirectoryContents(fdinfo_path); |
111 | | - if (!fdinfos.ok()) { |
112 | | - VLOG(1) << "Failed to get contents of '" << fdinfo_path << "'"; |
113 | | - continue; |
114 | | - } |
115 | | - for (const std::string& fdinfo : *fdinfos) { |
116 | | - std::string path = fmt::format("/proc/{}/fdinfo/{}", process, fdinfo); |
117 | | - fdinfo_list.emplace_back(std::move(path)); |
118 | | - } |
119 | | - } |
120 | | - |
121 | | - std::optional<Command> cmd = GrepCommand(); |
122 | | - if (!cmd) { |
123 | | - LOG(WARNING) << "Unable to test TAP interface usage"; |
124 | | - return {}; |
125 | | - } |
126 | | - cmd->AddParameter("-E").AddParameter("-h").AddParameter("-e").AddParameter( |
127 | | - "^iff:.*"); |
128 | | - |
129 | | - for (const std::string& fdinfo : fdinfo_list) { |
130 | | - cmd->AddParameter(fdinfo); |
131 | | - } |
132 | | - |
133 | | - std::string stdout_str = RunAndCaptureStdout(std::move(*cmd)).value_or(""); |
134 | | - |
135 | | - std::vector<std::string_view> lines = absl::StrSplit(stdout_str, '\n'); |
136 | | - std::set<std::string> tap_interfaces; |
137 | | - for (const auto& line : lines) { |
138 | | - if (line.empty()) { |
139 | | - continue; |
140 | | - } |
141 | | - if (!absl::StartsWith(line, "iff:\t")) { |
142 | | - LOG(ERROR) << "Unexpected line \"" << line << "\""; |
143 | | - continue; |
144 | | - } |
145 | | - tap_interfaces.emplace(line.substr(std::string("iff:\t").size())); |
146 | | - } |
147 | | - return tap_interfaces; |
148 | | -} |
149 | | -#endif |
150 | | - |
151 | 78 | std::string MacAddressToString(const uint8_t mac[6]) { |
152 | 79 | std::vector<uint8_t> mac_vec(mac, mac + 6); |
153 | 80 | return fmt::format("{:0>2x}", fmt::join(mac_vec, ":")); |
|
0 commit comments