Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | * |
| 16 | * binder_test.cpp - unit tests for netd binder RPCs. |
| 17 | */ |
| 18 | |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 19 | #include <cerrno> |
| 20 | #include <cinttypes> |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 21 | #include <cstdint> |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 22 | #include <cstdio> |
| 23 | #include <cstdlib> |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 24 | #include <set> |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 25 | #include <vector> |
| 26 | |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 27 | #include <fcntl.h> |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 28 | #include <ifaddrs.h> |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 29 | #include <netdb.h> |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 30 | #include <sys/socket.h> |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 31 | #include <sys/types.h> |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 32 | #include <netinet/in.h> |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 33 | #include <linux/if.h> |
| 34 | #include <linux/if_tun.h> |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 35 | #include <openssl/base64.h> |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 36 | |
Luke Huang | 531f5d3 | 2018-08-03 15:19:05 +0800 | [diff] [blame^] | 37 | #include <android-base/file.h> |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 38 | #include <android-base/macros.h> |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 39 | #include <android-base/stringprintf.h> |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 40 | #include <android-base/strings.h> |
Chenbo Feng | 837ddfc | 2018-05-08 13:45:08 -0700 | [diff] [blame] | 41 | #include <bpf/BpfUtils.h> |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 42 | #include <cutils/multiuser.h> |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 43 | #include <gtest/gtest.h> |
| 44 | #include <logwrap/logwrap.h> |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 45 | #include <netutils/ifc.h> |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 46 | |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 47 | #include "InterfaceController.h" |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 48 | #include "NetdConstants.h" |
Robin Lee | 7e05cc9 | 2016-09-21 16:31:33 +0900 | [diff] [blame] | 49 | #include "Stopwatch.h" |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 50 | #include "XfrmController.h" |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 51 | #include "tun_interface.h" |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 52 | #include "android/net/INetd.h" |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 53 | #include "android/net/UidRange.h" |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 54 | #include "binder/IServiceManager.h" |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 55 | #include "netdutils/Syscalls.h" |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 56 | |
Lorenzo Colitti | 5c68b9c | 2017-08-10 18:50:10 +0900 | [diff] [blame] | 57 | #define IP_PATH "/system/bin/ip" |
| 58 | #define IP6TABLES_PATH "/system/bin/ip6tables" |
| 59 | #define IPTABLES_PATH "/system/bin/iptables" |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 60 | #define TUN_DEV "/dev/tun" |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 61 | #define RAW_TABLE "raw" |
| 62 | #define MANGLE_TABLE "mangle" |
Luke Huang | 531f5d3 | 2018-08-03 15:19:05 +0800 | [diff] [blame^] | 63 | #define FILTER_TABLE "filter" |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 64 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 65 | namespace binder = android::binder; |
| 66 | namespace netdutils = android::netdutils; |
| 67 | |
| 68 | using android::IBinder; |
| 69 | using android::IServiceManager; |
| 70 | using android::sp; |
| 71 | using android::String16; |
| 72 | using android::String8; |
| 73 | using android::base::Join; |
Luke Huang | 531f5d3 | 2018-08-03 15:19:05 +0800 | [diff] [blame^] | 74 | using android::base::ReadFileToString; |
Lorenzo Colitti | aff2879 | 2017-09-26 17:46:18 +0900 | [diff] [blame] | 75 | using android::base::StartsWith; |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 76 | using android::base::StringPrintf; |
Luke Huang | 531f5d3 | 2018-08-03 15:19:05 +0800 | [diff] [blame^] | 77 | using android::base::Trim; |
Chenbo Feng | 837ddfc | 2018-05-08 13:45:08 -0700 | [diff] [blame] | 78 | using android::bpf::hasBpfSupport; |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 79 | using android::net::INetd; |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 80 | using android::net::TunInterface; |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 81 | using android::net::UidRange; |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 82 | using android::net::XfrmController; |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 83 | using android::os::PersistableBundle; |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 84 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 85 | #define SKIP_IF_BPF_SUPPORTED \ |
| 86 | do { \ |
| 87 | if (hasBpfSupport()) return; \ |
| 88 | } while (0) |
Chenbo Feng | 837ddfc | 2018-05-08 13:45:08 -0700 | [diff] [blame] | 89 | |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 90 | static const char* IP_RULE_V4 = "-4"; |
| 91 | static const char* IP_RULE_V6 = "-6"; |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 92 | static const int TEST_NETID1 = 65501; |
| 93 | static const int TEST_NETID2 = 65502; |
| 94 | constexpr int BASE_UID = AID_USER_OFFSET * 5; |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 95 | |
Benedict Wong | b2daefb | 2017-12-06 22:05:46 -0800 | [diff] [blame] | 96 | static const std::string NO_SOCKET_ALLOW_RULE("! owner UID match 0-4294967294"); |
| 97 | static const std::string ESP_ALLOW_RULE("esp"); |
| 98 | |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 99 | class BinderTest : public ::testing::Test { |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 100 | public: |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 101 | BinderTest() { |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 102 | sp<IServiceManager> sm = android::defaultServiceManager(); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 103 | sp<IBinder> binder = sm->getService(String16("netd")); |
| 104 | if (binder != nullptr) { |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 105 | mNetd = android::interface_cast<INetd>(binder); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 109 | void SetUp() override { |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 110 | ASSERT_NE(nullptr, mNetd.get()); |
| 111 | } |
| 112 | |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 113 | void TearDown() override { |
| 114 | mNetd->networkDestroy(TEST_NETID1); |
| 115 | mNetd->networkDestroy(TEST_NETID2); |
| 116 | } |
| 117 | |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 118 | bool allocateIpSecResources(bool expectOk, int32_t *spi); |
| 119 | |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 120 | // Static because setting up the tun interface takes about 40ms. |
| 121 | static void SetUpTestCase() { |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 122 | ASSERT_EQ(0, sTun.init()); |
| 123 | ASSERT_LE(sTun.name().size(), static_cast<size_t>(IFNAMSIZ)); |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | static void TearDownTestCase() { |
| 127 | // Closing the socket removes the interface and IP addresses. |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 128 | sTun.destroy(); |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static void fakeRemoteSocketPair(int *clientSocket, int *serverSocket, int *acceptedSocket); |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 132 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 133 | protected: |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 134 | sp<INetd> mNetd; |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 135 | static TunInterface sTun; |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 136 | }; |
| 137 | |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 138 | TunInterface BinderTest::sTun; |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 139 | |
Lorenzo Colitti | 699aa99 | 2016-04-15 10:22:37 +0900 | [diff] [blame] | 140 | class TimedOperation : public Stopwatch { |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 141 | public: |
Chih-Hung Hsieh | 1805105 | 2016-05-06 10:36:13 -0700 | [diff] [blame] | 142 | explicit TimedOperation(const std::string &name): mName(name) {} |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 143 | virtual ~TimedOperation() { |
Lorenzo Colitti | 699aa99 | 2016-04-15 10:22:37 +0900 | [diff] [blame] | 144 | fprintf(stderr, " %s: %6.1f ms\n", mName.c_str(), timeTaken()); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 145 | } |
| 146 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 147 | private: |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 148 | std::string mName; |
| 149 | }; |
| 150 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 151 | TEST_F(BinderTest, IsAlive) { |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 152 | TimedOperation t("isAlive RPC"); |
| 153 | bool isAlive = false; |
| 154 | mNetd->isAlive(&isAlive); |
| 155 | ASSERT_TRUE(isAlive); |
| 156 | } |
| 157 | |
| 158 | static int randomUid() { |
| 159 | return 100000 * arc4random_uniform(7) + 10000 + arc4random_uniform(5000); |
| 160 | } |
| 161 | |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 162 | static std::vector<std::string> runCommand(const std::string& command) { |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 163 | std::vector<std::string> lines; |
Bernie Innocenti | f691826 | 2018-06-11 17:37:35 +0900 | [diff] [blame] | 164 | FILE *f = popen(command.c_str(), "r"); // NOLINT(cert-env33-c) |
| 165 | if (f == nullptr) { |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 166 | perror("popen"); |
| 167 | return lines; |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 168 | } |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 169 | |
| 170 | char *line = nullptr; |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 171 | size_t bufsize = 0; |
| 172 | ssize_t linelen = 0; |
| 173 | while ((linelen = getline(&line, &bufsize, f)) >= 0) { |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 174 | lines.push_back(std::string(line, linelen)); |
| 175 | free(line); |
| 176 | line = nullptr; |
| 177 | } |
| 178 | |
| 179 | pclose(f); |
| 180 | return lines; |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 181 | } |
| 182 | |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 183 | static std::vector<std::string> listIpRules(const char *ipVersion) { |
| 184 | std::string command = StringPrintf("%s %s rule list", IP_PATH, ipVersion); |
| 185 | return runCommand(command); |
| 186 | } |
| 187 | |
| 188 | static std::vector<std::string> listIptablesRule(const char *binary, const char *chainName) { |
Lorenzo Colitti | 8054577 | 2016-06-09 14:20:08 +0900 | [diff] [blame] | 189 | std::string command = StringPrintf("%s -w -n -L %s", binary, chainName); |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 190 | return runCommand(command); |
| 191 | } |
| 192 | |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 193 | static int iptablesRuleLineLength(const char *binary, const char *chainName) { |
| 194 | return listIptablesRule(binary, chainName).size(); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 195 | } |
| 196 | |
Benedict Wong | b2daefb | 2017-12-06 22:05:46 -0800 | [diff] [blame] | 197 | static bool iptablesRuleExists(const char *binary, |
| 198 | const char *chainName, |
Bernie Innocenti | f691826 | 2018-06-11 17:37:35 +0900 | [diff] [blame] | 199 | const std::string& expectedRule) { |
Benedict Wong | b2daefb | 2017-12-06 22:05:46 -0800 | [diff] [blame] | 200 | std::vector<std::string> rules = listIptablesRule(binary, chainName); |
Bernie Innocenti | f691826 | 2018-06-11 17:37:35 +0900 | [diff] [blame] | 201 | for (const auto& rule : rules) { |
Benedict Wong | b2daefb | 2017-12-06 22:05:46 -0800 | [diff] [blame] | 202 | if(rule.find(expectedRule) != std::string::npos) { |
| 203 | return true; |
| 204 | } |
| 205 | } |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | static bool iptablesNoSocketAllowRuleExists(const char *chainName){ |
| 210 | return iptablesRuleExists(IPTABLES_PATH, chainName, NO_SOCKET_ALLOW_RULE) && |
| 211 | iptablesRuleExists(IP6TABLES_PATH, chainName, NO_SOCKET_ALLOW_RULE); |
| 212 | } |
| 213 | |
| 214 | static bool iptablesEspAllowRuleExists(const char *chainName){ |
| 215 | return iptablesRuleExists(IPTABLES_PATH, chainName, ESP_ALLOW_RULE) && |
| 216 | iptablesRuleExists(IP6TABLES_PATH, chainName, ESP_ALLOW_RULE); |
| 217 | } |
| 218 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 219 | TEST_F(BinderTest, FirewallReplaceUidChain) { |
Chenbo Feng | 837ddfc | 2018-05-08 13:45:08 -0700 | [diff] [blame] | 220 | SKIP_IF_BPF_SUPPORTED; |
| 221 | |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 222 | std::string chainName = StringPrintf("netd_binder_test_%u", arc4random_uniform(10000)); |
| 223 | const int kNumUids = 500; |
| 224 | std::vector<int32_t> noUids(0); |
| 225 | std::vector<int32_t> uids(kNumUids); |
| 226 | for (int i = 0; i < kNumUids; i++) { |
| 227 | uids[i] = randomUid(); |
| 228 | } |
| 229 | |
| 230 | bool ret; |
| 231 | { |
| 232 | TimedOperation op(StringPrintf("Programming %d-UID whitelist chain", kNumUids)); |
Erik Kline | f52d452 | 2018-03-14 15:01:46 +0900 | [diff] [blame] | 233 | mNetd->firewallReplaceUidChain(chainName, true, uids, &ret); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 234 | } |
| 235 | EXPECT_EQ(true, ret); |
Benedict Wong | b2daefb | 2017-12-06 22:05:46 -0800 | [diff] [blame] | 236 | EXPECT_EQ((int) uids.size() + 9, iptablesRuleLineLength(IPTABLES_PATH, chainName.c_str())); |
| 237 | EXPECT_EQ((int) uids.size() + 15, iptablesRuleLineLength(IP6TABLES_PATH, chainName.c_str())); |
| 238 | EXPECT_EQ(true, iptablesNoSocketAllowRuleExists(chainName.c_str())); |
| 239 | EXPECT_EQ(true, iptablesEspAllowRuleExists(chainName.c_str())); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 240 | { |
| 241 | TimedOperation op("Clearing whitelist chain"); |
Erik Kline | f52d452 | 2018-03-14 15:01:46 +0900 | [diff] [blame] | 242 | mNetd->firewallReplaceUidChain(chainName, false, noUids, &ret); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 243 | } |
| 244 | EXPECT_EQ(true, ret); |
Lorenzo Colitti | 50b198a | 2017-03-30 02:50:09 +0900 | [diff] [blame] | 245 | EXPECT_EQ(5, iptablesRuleLineLength(IPTABLES_PATH, chainName.c_str())); |
| 246 | EXPECT_EQ(5, iptablesRuleLineLength(IP6TABLES_PATH, chainName.c_str())); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 247 | |
| 248 | { |
| 249 | TimedOperation op(StringPrintf("Programming %d-UID blacklist chain", kNumUids)); |
Erik Kline | f52d452 | 2018-03-14 15:01:46 +0900 | [diff] [blame] | 250 | mNetd->firewallReplaceUidChain(chainName, false, uids, &ret); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 251 | } |
| 252 | EXPECT_EQ(true, ret); |
Lorenzo Colitti | 50b198a | 2017-03-30 02:50:09 +0900 | [diff] [blame] | 253 | EXPECT_EQ((int) uids.size() + 5, iptablesRuleLineLength(IPTABLES_PATH, chainName.c_str())); |
| 254 | EXPECT_EQ((int) uids.size() + 5, iptablesRuleLineLength(IP6TABLES_PATH, chainName.c_str())); |
Benedict Wong | b2daefb | 2017-12-06 22:05:46 -0800 | [diff] [blame] | 255 | EXPECT_EQ(false, iptablesNoSocketAllowRuleExists(chainName.c_str())); |
| 256 | EXPECT_EQ(false, iptablesEspAllowRuleExists(chainName.c_str())); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 257 | |
| 258 | { |
| 259 | TimedOperation op("Clearing blacklist chain"); |
Erik Kline | f52d452 | 2018-03-14 15:01:46 +0900 | [diff] [blame] | 260 | mNetd->firewallReplaceUidChain(chainName, false, noUids, &ret); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 261 | } |
| 262 | EXPECT_EQ(true, ret); |
Lorenzo Colitti | 50b198a | 2017-03-30 02:50:09 +0900 | [diff] [blame] | 263 | EXPECT_EQ(5, iptablesRuleLineLength(IPTABLES_PATH, chainName.c_str())); |
| 264 | EXPECT_EQ(5, iptablesRuleLineLength(IP6TABLES_PATH, chainName.c_str())); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 265 | |
| 266 | // Check that the call fails if iptables returns an error. |
| 267 | std::string veryLongStringName = "netd_binder_test_UnacceptablyLongIptablesChainName"; |
Erik Kline | f52d452 | 2018-03-14 15:01:46 +0900 | [diff] [blame] | 268 | mNetd->firewallReplaceUidChain(veryLongStringName, true, noUids, &ret); |
Lorenzo Colitti | 89faa34 | 2016-02-26 11:38:47 +0900 | [diff] [blame] | 269 | EXPECT_EQ(false, ret); |
| 270 | } |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 271 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 272 | TEST_F(BinderTest, VirtualTunnelInterface) { |
George Burgess IV | c4a6d27 | 2018-05-21 14:41:57 -0700 | [diff] [blame] | 273 | const struct TestData { |
| 274 | const std::string family; |
| 275 | const std::string deviceName; |
| 276 | const std::string localAddress; |
| 277 | const std::string remoteAddress; |
manojboopathi | 8707f23 | 2018-01-02 14:45:47 -0800 | [diff] [blame] | 278 | int32_t iKey; |
| 279 | int32_t oKey; |
| 280 | } kTestData[] = { |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 281 | {"IPV4", "test_vti", "127.0.0.1", "8.8.8.8", 0x1234 + 53, 0x1234 + 53}, |
| 282 | {"IPV6", "test_vti6", "::1", "2001:4860:4860::8888", 0x1234 + 50, 0x1234 + 50}, |
manojboopathi | 8707f23 | 2018-01-02 14:45:47 -0800 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | for (unsigned int i = 0; i < arraysize(kTestData); i++) { |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 286 | const auto& td = kTestData[i]; |
manojboopathi | 8707f23 | 2018-01-02 14:45:47 -0800 | [diff] [blame] | 287 | |
| 288 | binder::Status status; |
| 289 | |
| 290 | // Create Virtual Tunnel Interface. |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 291 | status = mNetd->addVirtualTunnelInterface(td.deviceName, td.localAddress, td.remoteAddress, |
| 292 | td.iKey, td.oKey); |
manojboopathi | 8707f23 | 2018-01-02 14:45:47 -0800 | [diff] [blame] | 293 | EXPECT_TRUE(status.isOk()) << td.family << status.exceptionMessage(); |
| 294 | |
| 295 | // Update Virtual Tunnel Interface. |
| 296 | status = mNetd->updateVirtualTunnelInterface(td.deviceName, td.localAddress, |
| 297 | td.remoteAddress, td.iKey, td.oKey); |
| 298 | EXPECT_TRUE(status.isOk()) << td.family << status.exceptionMessage(); |
| 299 | |
| 300 | // Remove Virtual Tunnel Interface. |
| 301 | status = mNetd->removeVirtualTunnelInterface(td.deviceName); |
| 302 | EXPECT_TRUE(status.isOk()) << td.family << status.exceptionMessage(); |
| 303 | } |
| 304 | } |
| 305 | |
Nathan Harold | 2deff32 | 2018-05-10 14:03:48 -0700 | [diff] [blame] | 306 | // IPsec tests are not run in 32 bit mode; both 32-bit kernels and |
| 307 | // mismatched ABIs (64-bit kernel with 32-bit userspace) are unsupported. |
| 308 | #if INTPTR_MAX != INT32_MAX |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 309 | static const int XFRM_DIRECTIONS[] = {static_cast<int>(android::net::XfrmDirection::IN), |
| 310 | static_cast<int>(android::net::XfrmDirection::OUT)}; |
| 311 | static const int ADDRESS_FAMILIES[] = {AF_INET, AF_INET6}; |
| 312 | |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 313 | #define RETURN_FALSE_IF_NEQ(_expect_, _ret_) \ |
| 314 | do { if ((_expect_) != (_ret_)) return false; } while(false) |
| 315 | bool BinderTest::allocateIpSecResources(bool expectOk, int32_t *spi) { |
| 316 | netdutils::Status status = XfrmController::ipSecAllocateSpi(0, "::", "::1", 123, spi); |
| 317 | SCOPED_TRACE(status); |
| 318 | RETURN_FALSE_IF_NEQ(status.ok(), expectOk); |
| 319 | |
| 320 | // Add a policy |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 321 | status = XfrmController::ipSecAddSecurityPolicy(0, AF_INET6, 0, "::", "::1", 123, 0, 0); |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 322 | SCOPED_TRACE(status); |
| 323 | RETURN_FALSE_IF_NEQ(status.ok(), expectOk); |
| 324 | |
| 325 | // Add an ipsec interface |
| 326 | status = netdutils::statusFromErrno( |
| 327 | XfrmController::addVirtualTunnelInterface( |
| 328 | "ipsec_test", "::", "::1", 0xF00D, 0xD00D, false), |
| 329 | "addVirtualTunnelInterface"); |
| 330 | return (status.ok() == expectOk); |
| 331 | } |
| 332 | |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 333 | TEST_F(BinderTest, XfrmDualSelectorTunnelModePoliciesV4) { |
| 334 | binder::Status status; |
| 335 | |
| 336 | // Repeat to ensure cleanup and recreation works correctly |
| 337 | for (int i = 0; i < 2; i++) { |
| 338 | for (int direction : XFRM_DIRECTIONS) { |
| 339 | for (int addrFamily : ADDRESS_FAMILIES) { |
| 340 | status = mNetd->ipSecAddSecurityPolicy(0, addrFamily, direction, "127.0.0.5", |
| 341 | "127.0.0.6", 123, 0, 0); |
| 342 | EXPECT_TRUE(status.isOk()) |
| 343 | << " family: " << addrFamily << " direction: " << direction; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | // Cleanup |
| 348 | for (int direction : XFRM_DIRECTIONS) { |
| 349 | for (int addrFamily : ADDRESS_FAMILIES) { |
| 350 | status = mNetd->ipSecDeleteSecurityPolicy(0, addrFamily, direction, 0, 0); |
| 351 | EXPECT_TRUE(status.isOk()); |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | TEST_F(BinderTest, XfrmDualSelectorTunnelModePoliciesV6) { |
| 358 | binder::Status status; |
| 359 | |
| 360 | // Repeat to ensure cleanup and recreation works correctly |
| 361 | for (int i = 0; i < 2; i++) { |
| 362 | for (int direction : XFRM_DIRECTIONS) { |
| 363 | for (int addrFamily : ADDRESS_FAMILIES) { |
| 364 | status = mNetd->ipSecAddSecurityPolicy(0, addrFamily, direction, "2001:db8::f00d", |
| 365 | "2001:db8::d00d", 123, 0, 0); |
| 366 | EXPECT_TRUE(status.isOk()) |
| 367 | << " family: " << addrFamily << " direction: " << direction; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | // Cleanup |
| 372 | for (int direction : XFRM_DIRECTIONS) { |
| 373 | for (int addrFamily : ADDRESS_FAMILIES) { |
| 374 | status = mNetd->ipSecDeleteSecurityPolicy(0, addrFamily, direction, 0, 0); |
| 375 | EXPECT_TRUE(status.isOk()); |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 381 | TEST_F(BinderTest, XfrmControllerInit) { |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 382 | netdutils::Status status; |
| 383 | status = XfrmController::Init(); |
| 384 | SCOPED_TRACE(status); |
Nathan Harold | 2deff32 | 2018-05-10 14:03:48 -0700 | [diff] [blame] | 385 | |
| 386 | // Older devices or devices with mismatched Kernel/User ABI cannot support the IPsec |
| 387 | // feature. |
| 388 | if (status.code() == EOPNOTSUPP) return; |
| 389 | |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 390 | ASSERT_TRUE(status.ok()); |
| 391 | |
| 392 | int32_t spi = 0; |
| 393 | |
| 394 | ASSERT_TRUE(allocateIpSecResources(true, &spi)); |
| 395 | ASSERT_TRUE(allocateIpSecResources(false, &spi)); |
| 396 | |
| 397 | status = XfrmController::Init(); |
Nathan Harold | 39ad662 | 2018-04-25 12:56:56 -0700 | [diff] [blame] | 398 | ASSERT_TRUE(status.ok()); |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 399 | ASSERT_TRUE(allocateIpSecResources(true, &spi)); |
| 400 | |
| 401 | // Clean up |
| 402 | status = XfrmController::ipSecDeleteSecurityAssociation(0, "::", "::1", 123, spi, 0); |
| 403 | SCOPED_TRACE(status); |
| 404 | ASSERT_TRUE(status.ok()); |
| 405 | |
Benedict Wong | a04ffa7 | 2018-05-09 21:42:42 -0700 | [diff] [blame] | 406 | status = XfrmController::ipSecDeleteSecurityPolicy(0, AF_INET6, 0, 0, 0); |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 407 | SCOPED_TRACE(status); |
| 408 | ASSERT_TRUE(status.ok()); |
| 409 | |
| 410 | // Remove Virtual Tunnel Interface. |
| 411 | status = netdutils::statusFromErrno( |
| 412 | XfrmController::removeVirtualTunnelInterface("ipsec_test"), |
| 413 | "removeVirtualTunnelInterface"); |
| 414 | |
| 415 | ASSERT_TRUE(status.ok()); |
| 416 | } |
Nathan Harold | 2deff32 | 2018-05-10 14:03:48 -0700 | [diff] [blame] | 417 | #endif |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 418 | |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 419 | static int bandwidthDataSaverEnabled(const char *binary) { |
Lorenzo Colitti | 464eabe | 2016-03-25 13:38:19 +0900 | [diff] [blame] | 420 | std::vector<std::string> lines = listIptablesRule(binary, "bw_data_saver"); |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 421 | |
| 422 | // Output looks like this: |
| 423 | // |
Lorenzo Colitti | 464eabe | 2016-03-25 13:38:19 +0900 | [diff] [blame] | 424 | // Chain bw_data_saver (1 references) |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 425 | // target prot opt source destination |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 426 | // RETURN all -- 0.0.0.0/0 0.0.0.0/0 |
Lorenzo Colitti | aff2879 | 2017-09-26 17:46:18 +0900 | [diff] [blame] | 427 | // |
| 428 | // or: |
| 429 | // |
| 430 | // Chain bw_data_saver (1 references) |
| 431 | // target prot opt source destination |
| 432 | // ... possibly connectivity critical packet rules here ... |
| 433 | // REJECT all -- ::/0 ::/0 |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 434 | |
Lorenzo Colitti | aff2879 | 2017-09-26 17:46:18 +0900 | [diff] [blame] | 435 | EXPECT_GE(lines.size(), 3U); |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 436 | |
Lorenzo Colitti | aff2879 | 2017-09-26 17:46:18 +0900 | [diff] [blame] | 437 | if (lines.size() == 3 && StartsWith(lines[2], "RETURN ")) { |
| 438 | // Data saver disabled. |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | size_t minSize = (std::string(binary) == IPTABLES_PATH) ? 3 : 9; |
| 443 | |
| 444 | if (lines.size() >= minSize && StartsWith(lines[lines.size() -1], "REJECT ")) { |
| 445 | // Data saver enabled. |
| 446 | return 1; |
| 447 | } |
| 448 | |
| 449 | return -1; |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | bool enableDataSaver(sp<INetd>& netd, bool enable) { |
| 453 | TimedOperation op(enable ? " Enabling data saver" : "Disabling data saver"); |
| 454 | bool ret; |
| 455 | netd->bandwidthEnableDataSaver(enable, &ret); |
| 456 | return ret; |
| 457 | } |
| 458 | |
| 459 | int getDataSaverState() { |
| 460 | const int enabled4 = bandwidthDataSaverEnabled(IPTABLES_PATH); |
| 461 | const int enabled6 = bandwidthDataSaverEnabled(IP6TABLES_PATH); |
| 462 | EXPECT_EQ(enabled4, enabled6); |
| 463 | EXPECT_NE(-1, enabled4); |
| 464 | EXPECT_NE(-1, enabled6); |
| 465 | if (enabled4 != enabled6 || (enabled6 != 0 && enabled6 != 1)) { |
| 466 | return -1; |
| 467 | } |
| 468 | return enabled6; |
| 469 | } |
| 470 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 471 | TEST_F(BinderTest, BandwidthEnableDataSaver) { |
Lorenzo Colitti | dedd271 | 2016-03-22 12:36:29 +0900 | [diff] [blame] | 472 | const int wasEnabled = getDataSaverState(); |
| 473 | ASSERT_NE(-1, wasEnabled); |
| 474 | |
| 475 | if (wasEnabled) { |
| 476 | ASSERT_TRUE(enableDataSaver(mNetd, false)); |
| 477 | EXPECT_EQ(0, getDataSaverState()); |
| 478 | } |
| 479 | |
| 480 | ASSERT_TRUE(enableDataSaver(mNetd, false)); |
| 481 | EXPECT_EQ(0, getDataSaverState()); |
| 482 | |
| 483 | ASSERT_TRUE(enableDataSaver(mNetd, true)); |
| 484 | EXPECT_EQ(1, getDataSaverState()); |
| 485 | |
| 486 | ASSERT_TRUE(enableDataSaver(mNetd, true)); |
| 487 | EXPECT_EQ(1, getDataSaverState()); |
| 488 | |
| 489 | if (!wasEnabled) { |
| 490 | ASSERT_TRUE(enableDataSaver(mNetd, false)); |
| 491 | EXPECT_EQ(0, getDataSaverState()); |
| 492 | } |
| 493 | } |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 494 | |
| 495 | static bool ipRuleExistsForRange(const uint32_t priority, const UidRange& range, |
| 496 | const std::string& action, const char* ipVersion) { |
| 497 | // Output looks like this: |
Robin Lee | 6c84ef6 | 2016-05-03 13:17:58 +0100 | [diff] [blame] | 498 | // "12500:\tfrom all fwmark 0x0/0x20000 iif lo uidrange 1000-2000 prohibit" |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 499 | std::vector<std::string> rules = listIpRules(ipVersion); |
| 500 | |
| 501 | std::string prefix = StringPrintf("%" PRIu32 ":", priority); |
| 502 | std::string suffix = StringPrintf(" iif lo uidrange %d-%d %s\n", |
| 503 | range.getStart(), range.getStop(), action.c_str()); |
Bernie Innocenti | f691826 | 2018-06-11 17:37:35 +0900 | [diff] [blame] | 504 | for (const auto& line : rules) { |
Elliott Hughes | 2f44508 | 2017-12-20 12:39:35 -0800 | [diff] [blame] | 505 | if (android::base::StartsWith(line, prefix) && android::base::EndsWith(line, suffix)) { |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 506 | return true; |
| 507 | } |
| 508 | } |
| 509 | return false; |
| 510 | } |
| 511 | |
| 512 | static bool ipRuleExistsForRange(const uint32_t priority, const UidRange& range, |
| 513 | const std::string& action) { |
| 514 | bool existsIp4 = ipRuleExistsForRange(priority, range, action, IP_RULE_V4); |
| 515 | bool existsIp6 = ipRuleExistsForRange(priority, range, action, IP_RULE_V6); |
| 516 | EXPECT_EQ(existsIp4, existsIp6); |
| 517 | return existsIp4; |
| 518 | } |
| 519 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 520 | TEST_F(BinderTest, NetworkInterfaces) { |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 521 | EXPECT_TRUE(mNetd->networkCreatePhysical(TEST_NETID1, "").isOk()); |
| 522 | EXPECT_EQ(EEXIST, mNetd->networkCreatePhysical(TEST_NETID1, "").serviceSpecificErrorCode()); |
| 523 | EXPECT_EQ(EEXIST, mNetd->networkCreateVpn(TEST_NETID1, false, true).serviceSpecificErrorCode()); |
| 524 | EXPECT_TRUE(mNetd->networkCreateVpn(TEST_NETID2, false, true).isOk()); |
| 525 | |
| 526 | EXPECT_TRUE(mNetd->networkAddInterface(TEST_NETID1, sTun.name()).isOk()); |
| 527 | EXPECT_EQ(EBUSY, |
| 528 | mNetd->networkAddInterface(TEST_NETID2, sTun.name()).serviceSpecificErrorCode()); |
| 529 | |
| 530 | EXPECT_TRUE(mNetd->networkDestroy(TEST_NETID1).isOk()); |
| 531 | EXPECT_TRUE(mNetd->networkAddInterface(TEST_NETID2, sTun.name()).isOk()); |
| 532 | EXPECT_TRUE(mNetd->networkDestroy(TEST_NETID2).isOk()); |
| 533 | } |
| 534 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 535 | TEST_F(BinderTest, NetworkUidRules) { |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 536 | const uint32_t RULE_PRIORITY_SECURE_VPN = 12000; |
| 537 | |
| 538 | EXPECT_TRUE(mNetd->networkCreateVpn(TEST_NETID1, false, true).isOk()); |
| 539 | EXPECT_EQ(EEXIST, mNetd->networkCreateVpn(TEST_NETID1, false, true).serviceSpecificErrorCode()); |
| 540 | EXPECT_TRUE(mNetd->networkAddInterface(TEST_NETID1, sTun.name()).isOk()); |
| 541 | |
| 542 | std::vector<UidRange> uidRanges = { |
| 543 | {BASE_UID + 8005, BASE_UID + 8012}, |
| 544 | {BASE_UID + 8090, BASE_UID + 8099} |
| 545 | }; |
| 546 | UidRange otherRange(BASE_UID + 8190, BASE_UID + 8299); |
| 547 | std::string suffix = StringPrintf("lookup %s ", sTun.name().c_str()); |
| 548 | |
| 549 | EXPECT_TRUE(mNetd->networkAddUidRanges(TEST_NETID1, uidRanges).isOk()); |
| 550 | |
| 551 | EXPECT_TRUE(ipRuleExistsForRange(RULE_PRIORITY_SECURE_VPN, uidRanges[0], suffix)); |
| 552 | EXPECT_FALSE(ipRuleExistsForRange(RULE_PRIORITY_SECURE_VPN, otherRange, suffix)); |
| 553 | EXPECT_TRUE(mNetd->networkRemoveUidRanges(TEST_NETID1, uidRanges).isOk()); |
| 554 | EXPECT_FALSE(ipRuleExistsForRange(RULE_PRIORITY_SECURE_VPN, uidRanges[0], suffix)); |
| 555 | |
| 556 | EXPECT_TRUE(mNetd->networkAddUidRanges(TEST_NETID1, uidRanges).isOk()); |
| 557 | EXPECT_TRUE(ipRuleExistsForRange(RULE_PRIORITY_SECURE_VPN, uidRanges[1], suffix)); |
| 558 | EXPECT_TRUE(mNetd->networkDestroy(TEST_NETID1).isOk()); |
| 559 | EXPECT_FALSE(ipRuleExistsForRange(RULE_PRIORITY_SECURE_VPN, uidRanges[1], suffix)); |
| 560 | |
| 561 | EXPECT_EQ(ENONET, mNetd->networkDestroy(TEST_NETID1).serviceSpecificErrorCode()); |
| 562 | } |
| 563 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 564 | TEST_F(BinderTest, NetworkRejectNonSecureVpn) { |
Robin Lee | 6c84ef6 | 2016-05-03 13:17:58 +0100 | [diff] [blame] | 565 | constexpr uint32_t RULE_PRIORITY = 12500; |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 566 | |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 567 | std::vector<UidRange> uidRanges = { |
Lorenzo Colitti | d33e96d | 2016-12-15 23:59:01 +0900 | [diff] [blame] | 568 | {BASE_UID + 150, BASE_UID + 224}, |
| 569 | {BASE_UID + 226, BASE_UID + 300} |
Robin Lee | b808736 | 2016-03-30 18:43:08 +0100 | [diff] [blame] | 570 | }; |
| 571 | |
| 572 | const std::vector<std::string> initialRulesV4 = listIpRules(IP_RULE_V4); |
| 573 | const std::vector<std::string> initialRulesV6 = listIpRules(IP_RULE_V6); |
| 574 | |
| 575 | // Create two valid rules. |
| 576 | ASSERT_TRUE(mNetd->networkRejectNonSecureVpn(true, uidRanges).isOk()); |
| 577 | EXPECT_EQ(initialRulesV4.size() + 2, listIpRules(IP_RULE_V4).size()); |
| 578 | EXPECT_EQ(initialRulesV6.size() + 2, listIpRules(IP_RULE_V6).size()); |
| 579 | for (auto const& range : uidRanges) { |
| 580 | EXPECT_TRUE(ipRuleExistsForRange(RULE_PRIORITY, range, "prohibit")); |
| 581 | } |
| 582 | |
| 583 | // Remove the rules. |
| 584 | ASSERT_TRUE(mNetd->networkRejectNonSecureVpn(false, uidRanges).isOk()); |
| 585 | EXPECT_EQ(initialRulesV4.size(), listIpRules(IP_RULE_V4).size()); |
| 586 | EXPECT_EQ(initialRulesV6.size(), listIpRules(IP_RULE_V6).size()); |
| 587 | for (auto const& range : uidRanges) { |
| 588 | EXPECT_FALSE(ipRuleExistsForRange(RULE_PRIORITY, range, "prohibit")); |
| 589 | } |
| 590 | |
| 591 | // Fail to remove the rules a second time after they are already deleted. |
| 592 | binder::Status status = mNetd->networkRejectNonSecureVpn(false, uidRanges); |
| 593 | ASSERT_EQ(binder::Status::EX_SERVICE_SPECIFIC, status.exceptionCode()); |
| 594 | EXPECT_EQ(ENOENT, status.serviceSpecificErrorCode()); |
| 595 | |
| 596 | // All rules should be the same as before. |
| 597 | EXPECT_EQ(initialRulesV4, listIpRules(IP_RULE_V4)); |
| 598 | EXPECT_EQ(initialRulesV6, listIpRules(IP_RULE_V6)); |
| 599 | } |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 600 | |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 601 | // Create a socket pair that isLoopbackSocket won't think is local. |
| 602 | void BinderTest::fakeRemoteSocketPair(int *clientSocket, int *serverSocket, int *acceptedSocket) { |
Bernie Innocenti | f691826 | 2018-06-11 17:37:35 +0900 | [diff] [blame] | 603 | *serverSocket = socket(AF_INET6, SOCK_STREAM | SOCK_CLOEXEC, 0); |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 604 | struct sockaddr_in6 server6 = { .sin6_family = AF_INET6, .sin6_addr = sTun.dstAddr() }; |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 605 | ASSERT_EQ(0, bind(*serverSocket, (struct sockaddr *) &server6, sizeof(server6))); |
| 606 | |
| 607 | socklen_t addrlen = sizeof(server6); |
| 608 | ASSERT_EQ(0, getsockname(*serverSocket, (struct sockaddr *) &server6, &addrlen)); |
| 609 | ASSERT_EQ(0, listen(*serverSocket, 10)); |
| 610 | |
Bernie Innocenti | f691826 | 2018-06-11 17:37:35 +0900 | [diff] [blame] | 611 | *clientSocket = socket(AF_INET6, SOCK_STREAM | SOCK_CLOEXEC, 0); |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 612 | struct sockaddr_in6 client6 = { .sin6_family = AF_INET6, .sin6_addr = sTun.srcAddr() }; |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 613 | ASSERT_EQ(0, bind(*clientSocket, (struct sockaddr *) &client6, sizeof(client6))); |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 614 | ASSERT_EQ(0, connect(*clientSocket, (struct sockaddr *) &server6, sizeof(server6))); |
| 615 | ASSERT_EQ(0, getsockname(*clientSocket, (struct sockaddr *) &client6, &addrlen)); |
| 616 | |
Bernie Innocenti | f691826 | 2018-06-11 17:37:35 +0900 | [diff] [blame] | 617 | *acceptedSocket = accept4(*serverSocket, (struct sockaddr *) &server6, &addrlen, SOCK_CLOEXEC); |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 618 | ASSERT_NE(-1, *acceptedSocket); |
| 619 | |
| 620 | ASSERT_EQ(0, memcmp(&client6, &server6, sizeof(client6))); |
| 621 | } |
| 622 | |
| 623 | void checkSocketpairOpen(int clientSocket, int acceptedSocket) { |
| 624 | char buf[4096]; |
| 625 | EXPECT_EQ(4, write(clientSocket, "foo", sizeof("foo"))); |
| 626 | EXPECT_EQ(4, read(acceptedSocket, buf, sizeof(buf))); |
| 627 | EXPECT_EQ(0, memcmp(buf, "foo", sizeof("foo"))); |
| 628 | } |
| 629 | |
| 630 | void checkSocketpairClosed(int clientSocket, int acceptedSocket) { |
| 631 | // Check that the client socket was closed with ECONNABORTED. |
| 632 | int ret = write(clientSocket, "foo", sizeof("foo")); |
| 633 | int err = errno; |
| 634 | EXPECT_EQ(-1, ret); |
| 635 | EXPECT_EQ(ECONNABORTED, err); |
| 636 | |
| 637 | // Check that it sent a RST to the server. |
| 638 | ret = write(acceptedSocket, "foo", sizeof("foo")); |
| 639 | err = errno; |
| 640 | EXPECT_EQ(-1, ret); |
| 641 | EXPECT_EQ(ECONNRESET, err); |
| 642 | } |
| 643 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 644 | TEST_F(BinderTest, SocketDestroy) { |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 645 | int clientSocket, serverSocket, acceptedSocket; |
Lorenzo Colitti | 755faa9 | 2016-07-27 22:10:49 +0900 | [diff] [blame] | 646 | ASSERT_NO_FATAL_FAILURE(fakeRemoteSocketPair(&clientSocket, &serverSocket, &acceptedSocket)); |
Lorenzo Colitti | 563d98b | 2016-04-24 13:13:14 +0900 | [diff] [blame] | 647 | |
| 648 | // Pick a random UID in the system UID range. |
| 649 | constexpr int baseUid = AID_APP - 2000; |
| 650 | static_assert(baseUid > 0, "Not enough UIDs? Please fix this test."); |
| 651 | int uid = baseUid + 500 + arc4random_uniform(1000); |
| 652 | EXPECT_EQ(0, fchown(clientSocket, uid, -1)); |
| 653 | |
| 654 | // UID ranges that don't contain uid. |
| 655 | std::vector<UidRange> uidRanges = { |
| 656 | {baseUid + 42, baseUid + 449}, |
| 657 | {baseUid + 1536, AID_APP - 4}, |
| 658 | {baseUid + 498, uid - 1}, |
| 659 | {uid + 1, baseUid + 1520}, |
| 660 | }; |
| 661 | // A skip list that doesn't contain UID. |
| 662 | std::vector<int32_t> skipUids { baseUid + 123, baseUid + 1600 }; |
| 663 | |
| 664 | // Close sockets. Our test socket should be intact. |
| 665 | EXPECT_TRUE(mNetd->socketDestroy(uidRanges, skipUids).isOk()); |
| 666 | checkSocketpairOpen(clientSocket, acceptedSocket); |
| 667 | |
| 668 | // UID ranges that do contain uid. |
| 669 | uidRanges = { |
| 670 | {baseUid + 42, baseUid + 449}, |
| 671 | {baseUid + 1536, AID_APP - 4}, |
| 672 | {baseUid + 498, baseUid + 1520}, |
| 673 | }; |
| 674 | // Add uid to the skip list. |
| 675 | skipUids.push_back(uid); |
| 676 | |
| 677 | // Close sockets. Our test socket should still be intact because it's in the skip list. |
| 678 | EXPECT_TRUE(mNetd->socketDestroy(uidRanges, skipUids).isOk()); |
| 679 | checkSocketpairOpen(clientSocket, acceptedSocket); |
| 680 | |
| 681 | // Now remove uid from skipUids, and close sockets. Our test socket should have been closed. |
| 682 | skipUids.resize(skipUids.size() - 1); |
| 683 | EXPECT_TRUE(mNetd->socketDestroy(uidRanges, skipUids).isOk()); |
| 684 | checkSocketpairClosed(clientSocket, acceptedSocket); |
| 685 | |
| 686 | close(clientSocket); |
| 687 | close(serverSocket); |
| 688 | close(acceptedSocket); |
| 689 | } |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 690 | |
| 691 | namespace { |
| 692 | |
| 693 | int netmaskToPrefixLength(const uint8_t *buf, size_t buflen) { |
| 694 | if (buf == nullptr) return -1; |
| 695 | |
| 696 | int prefixLength = 0; |
| 697 | bool endOfContiguousBits = false; |
| 698 | for (unsigned int i = 0; i < buflen; i++) { |
| 699 | const uint8_t value = buf[i]; |
| 700 | |
| 701 | // Bad bit sequence: check for a contiguous set of bits from the high |
| 702 | // end by verifying that the inverted value + 1 is a power of 2 |
| 703 | // (power of 2 iff. (v & (v - 1)) == 0). |
| 704 | const uint8_t inverse = ~value + 1; |
| 705 | if ((inverse & (inverse - 1)) != 0) return -1; |
| 706 | |
| 707 | prefixLength += (value == 0) ? 0 : CHAR_BIT - ffs(value) + 1; |
| 708 | |
| 709 | // Bogus netmask. |
| 710 | if (endOfContiguousBits && value != 0) return -1; |
| 711 | |
| 712 | if (value != 0xff) endOfContiguousBits = true; |
| 713 | } |
| 714 | |
| 715 | return prefixLength; |
| 716 | } |
| 717 | |
| 718 | template<typename T> |
| 719 | int netmaskToPrefixLength(const T *p) { |
| 720 | return netmaskToPrefixLength(reinterpret_cast<const uint8_t*>(p), sizeof(T)); |
| 721 | } |
| 722 | |
| 723 | |
| 724 | static bool interfaceHasAddress( |
| 725 | const std::string &ifname, const char *addrString, int prefixLength) { |
| 726 | struct addrinfo *addrinfoList = nullptr; |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 727 | |
| 728 | const struct addrinfo hints = { |
| 729 | .ai_flags = AI_NUMERICHOST, |
| 730 | .ai_family = AF_UNSPEC, |
| 731 | .ai_socktype = SOCK_DGRAM, |
| 732 | }; |
| 733 | if (getaddrinfo(addrString, nullptr, &hints, &addrinfoList) != 0 || |
| 734 | addrinfoList == nullptr || addrinfoList->ai_addr == nullptr) { |
| 735 | return false; |
| 736 | } |
Bernie Innocenti | 9bf749f | 2018-08-30 08:37:22 +0900 | [diff] [blame] | 737 | ScopedAddrinfo addrinfoCleanup(addrinfoList); |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 738 | |
| 739 | struct ifaddrs *ifaddrsList = nullptr; |
| 740 | ScopedIfaddrs ifaddrsCleanup(ifaddrsList); |
| 741 | |
| 742 | if (getifaddrs(&ifaddrsList) != 0) { |
| 743 | return false; |
| 744 | } |
| 745 | |
| 746 | for (struct ifaddrs *addr = ifaddrsList; addr != nullptr; addr = addr->ifa_next) { |
| 747 | if (std::string(addr->ifa_name) != ifname || |
| 748 | addr->ifa_addr == nullptr || |
| 749 | addr->ifa_addr->sa_family != addrinfoList->ai_addr->sa_family) { |
| 750 | continue; |
| 751 | } |
| 752 | |
| 753 | switch (addr->ifa_addr->sa_family) { |
| 754 | case AF_INET: { |
| 755 | auto *addr4 = reinterpret_cast<const struct sockaddr_in*>(addr->ifa_addr); |
| 756 | auto *want = reinterpret_cast<const struct sockaddr_in*>(addrinfoList->ai_addr); |
| 757 | if (memcmp(&addr4->sin_addr, &want->sin_addr, sizeof(want->sin_addr)) != 0) { |
| 758 | continue; |
| 759 | } |
| 760 | |
| 761 | if (prefixLength < 0) return true; // not checking prefix lengths |
| 762 | |
| 763 | if (addr->ifa_netmask == nullptr) return false; |
| 764 | auto *nm = reinterpret_cast<const struct sockaddr_in*>(addr->ifa_netmask); |
| 765 | EXPECT_EQ(prefixLength, netmaskToPrefixLength(&nm->sin_addr)); |
| 766 | return (prefixLength == netmaskToPrefixLength(&nm->sin_addr)); |
| 767 | } |
| 768 | case AF_INET6: { |
| 769 | auto *addr6 = reinterpret_cast<const struct sockaddr_in6*>(addr->ifa_addr); |
| 770 | auto *want = reinterpret_cast<const struct sockaddr_in6*>(addrinfoList->ai_addr); |
| 771 | if (memcmp(&addr6->sin6_addr, &want->sin6_addr, sizeof(want->sin6_addr)) != 0) { |
| 772 | continue; |
| 773 | } |
| 774 | |
| 775 | if (prefixLength < 0) return true; // not checking prefix lengths |
| 776 | |
| 777 | if (addr->ifa_netmask == nullptr) return false; |
| 778 | auto *nm = reinterpret_cast<const struct sockaddr_in6*>(addr->ifa_netmask); |
| 779 | EXPECT_EQ(prefixLength, netmaskToPrefixLength(&nm->sin6_addr)); |
| 780 | return (prefixLength == netmaskToPrefixLength(&nm->sin6_addr)); |
| 781 | } |
| 782 | default: |
| 783 | // Cannot happen because we have already screened for matching |
| 784 | // address families at the top of each iteration. |
| 785 | continue; |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | return false; |
| 790 | } |
| 791 | |
| 792 | } // namespace |
| 793 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 794 | TEST_F(BinderTest, InterfaceAddRemoveAddress) { |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 795 | static const struct TestData { |
| 796 | const char *addrString; |
| 797 | const int prefixLength; |
| 798 | const bool expectSuccess; |
| 799 | } kTestData[] = { |
| 800 | { "192.0.2.1", 24, true }, |
| 801 | { "192.0.2.2", 25, true }, |
| 802 | { "192.0.2.3", 32, true }, |
| 803 | { "192.0.2.4", 33, false }, |
| 804 | { "192.not.an.ip", 24, false }, |
| 805 | { "2001:db8::1", 64, true }, |
| 806 | { "2001:db8::2", 65, true }, |
| 807 | { "2001:db8::3", 128, true }, |
| 808 | { "2001:db8::4", 129, false }, |
| 809 | { "foo:bar::bad", 64, false }, |
| 810 | }; |
| 811 | |
| 812 | for (unsigned int i = 0; i < arraysize(kTestData); i++) { |
| 813 | const auto &td = kTestData[i]; |
| 814 | |
| 815 | // [1.a] Add the address. |
| 816 | binder::Status status = mNetd->interfaceAddAddress( |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 817 | sTun.name(), td.addrString, td.prefixLength); |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 818 | if (td.expectSuccess) { |
| 819 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 820 | } else { |
| 821 | ASSERT_EQ(binder::Status::EX_SERVICE_SPECIFIC, status.exceptionCode()); |
| 822 | ASSERT_NE(0, status.serviceSpecificErrorCode()); |
| 823 | } |
| 824 | |
| 825 | // [1.b] Verify the addition meets the expectation. |
| 826 | if (td.expectSuccess) { |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 827 | EXPECT_TRUE(interfaceHasAddress(sTun.name(), td.addrString, td.prefixLength)); |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 828 | } else { |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 829 | EXPECT_FALSE(interfaceHasAddress(sTun.name(), td.addrString, -1)); |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 830 | } |
| 831 | |
| 832 | // [2.a] Try to remove the address. If it was not previously added, removing it fails. |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 833 | status = mNetd->interfaceDelAddress(sTun.name(), td.addrString, td.prefixLength); |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 834 | if (td.expectSuccess) { |
| 835 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 836 | } else { |
| 837 | ASSERT_EQ(binder::Status::EX_SERVICE_SPECIFIC, status.exceptionCode()); |
| 838 | ASSERT_NE(0, status.serviceSpecificErrorCode()); |
| 839 | } |
| 840 | |
| 841 | // [2.b] No matter what, the address should not be present. |
Lorenzo Colitti | 1e299c6 | 2017-02-27 17:16:10 +0900 | [diff] [blame] | 842 | EXPECT_FALSE(interfaceHasAddress(sTun.name(), td.addrString, -1)); |
Erik Kline | cc4f273 | 2016-08-03 11:24:27 +0900 | [diff] [blame] | 843 | } |
| 844 | } |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 845 | |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 846 | TEST_F(BinderTest, GetProcSysNet) { |
| 847 | const char LOOPBACK[] = "lo"; |
| 848 | static const struct { |
| 849 | const int ipversion; |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 850 | const int which; |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 851 | const char* ifname; |
| 852 | const char* parameter; |
| 853 | const char* expectedValue; |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 854 | const int expectedReturnCode; |
| 855 | } kTestData[] = { |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 856 | {INetd::IPV4, INetd::CONF, LOOPBACK, "arp_ignore", "0", 0}, |
| 857 | {-1, INetd::CONF, sTun.name().c_str(), "arp_ignore", nullptr, EAFNOSUPPORT}, |
| 858 | {INetd::IPV4, -1, sTun.name().c_str(), "arp_ignore", nullptr, EINVAL}, |
| 859 | {INetd::IPV4, INetd::CONF, "..", "conf/lo/arp_ignore", nullptr, EINVAL}, |
| 860 | {INetd::IPV4, INetd::CONF, ".", "lo/arp_ignore", nullptr, EINVAL}, |
| 861 | {INetd::IPV4, INetd::CONF, sTun.name().c_str(), "../all/arp_ignore", nullptr, EINVAL}, |
| 862 | {INetd::IPV6, INetd::NEIGH, LOOPBACK, "ucast_solicit", "3", 0}, |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 863 | }; |
| 864 | |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 865 | for (int i = 0; i < arraysize(kTestData); i++) { |
| 866 | const auto& td = kTestData[i]; |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 867 | |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 868 | std::string value; |
| 869 | const binder::Status status = |
| 870 | mNetd->getProcSysNet(td.ipversion, td.which, td.ifname, td.parameter, &value); |
| 871 | |
| 872 | if (td.expectedReturnCode == 0) { |
| 873 | SCOPED_TRACE(String8::format("test case %d should have passed", i)); |
| 874 | EXPECT_EQ(0, status.exceptionCode()); |
| 875 | EXPECT_EQ(0, status.serviceSpecificErrorCode()); |
| 876 | EXPECT_EQ(td.expectedValue, value); |
| 877 | } else { |
| 878 | SCOPED_TRACE(String8::format("test case %d should have failed", i)); |
| 879 | EXPECT_EQ(binder::Status::EX_SERVICE_SPECIFIC, status.exceptionCode()); |
| 880 | EXPECT_EQ(td.expectedReturnCode, status.serviceSpecificErrorCode()); |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | |
| 885 | TEST_F(BinderTest, SetProcSysNet) { |
| 886 | static const struct { |
| 887 | const int ipversion; |
| 888 | const int which; |
| 889 | const char* ifname; |
| 890 | const char* parameter; |
| 891 | const char* value; |
| 892 | const int expectedReturnCode; |
| 893 | } kTestData[] = { |
| 894 | {INetd::IPV4, INetd::CONF, sTun.name().c_str(), "arp_ignore", "1", 0}, |
| 895 | {-1, INetd::CONF, sTun.name().c_str(), "arp_ignore", "1", EAFNOSUPPORT}, |
| 896 | {INetd::IPV4, -1, sTun.name().c_str(), "arp_ignore", "1", EINVAL}, |
| 897 | {INetd::IPV4, INetd::CONF, "..", "conf/lo/arp_ignore", "1", EINVAL}, |
| 898 | {INetd::IPV4, INetd::CONF, ".", "lo/arp_ignore", "1", EINVAL}, |
| 899 | {INetd::IPV4, INetd::CONF, sTun.name().c_str(), "../all/arp_ignore", "1", EINVAL}, |
| 900 | {INetd::IPV6, INetd::NEIGH, sTun.name().c_str(), "ucast_solicit", "7", 0}, |
| 901 | }; |
| 902 | |
| 903 | for (int i = 0; i < arraysize(kTestData); i++) { |
| 904 | const auto& td = kTestData[i]; |
| 905 | |
| 906 | const binder::Status status = |
| 907 | mNetd->setProcSysNet(td.ipversion, td.which, td.ifname, td.parameter, td.value); |
Erik Kline | 55b06f8 | 2016-07-04 09:57:18 +0900 | [diff] [blame] | 908 | |
| 909 | if (td.expectedReturnCode == 0) { |
| 910 | SCOPED_TRACE(String8::format("test case %d should have passed", i)); |
| 911 | EXPECT_EQ(0, status.exceptionCode()); |
| 912 | EXPECT_EQ(0, status.serviceSpecificErrorCode()); |
| 913 | } else { |
| 914 | SCOPED_TRACE(String8::format("test case %d should have failed", i)); |
| 915 | EXPECT_EQ(binder::Status::EX_SERVICE_SPECIFIC, status.exceptionCode()); |
| 916 | EXPECT_EQ(td.expectedReturnCode, status.serviceSpecificErrorCode()); |
| 917 | } |
| 918 | } |
| 919 | } |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 920 | |
Erik Kline | 38e51f1 | 2018-09-06 20:14:44 +0900 | [diff] [blame] | 921 | TEST_F(BinderTest, GetSetProcSysNet) { |
| 922 | const int ipversion = INetd::IPV6; |
| 923 | const int category = INetd::NEIGH; |
| 924 | const std::string& tun = sTun.name(); |
| 925 | const std::string parameter("ucast_solicit"); |
| 926 | |
| 927 | std::string value{}; |
| 928 | EXPECT_TRUE(mNetd->getProcSysNet(ipversion, category, tun, parameter, &value).isOk()); |
| 929 | EXPECT_FALSE(value.empty()); |
| 930 | const int ival = std::stoi(value); |
| 931 | EXPECT_GT(ival, 0); |
| 932 | // Try doubling the parameter value (always best!). |
| 933 | EXPECT_TRUE(mNetd->setProcSysNet(ipversion, category, tun, parameter, std::to_string(2 * ival)) |
| 934 | .isOk()); |
| 935 | EXPECT_TRUE(mNetd->getProcSysNet(ipversion, category, tun, parameter, &value).isOk()); |
| 936 | EXPECT_EQ(2 * ival, std::stoi(value)); |
| 937 | // Try resetting the parameter. |
| 938 | EXPECT_TRUE(mNetd->setProcSysNet(ipversion, category, tun, parameter, std::to_string(ival)) |
| 939 | .isOk()); |
| 940 | EXPECT_TRUE(mNetd->getProcSysNet(ipversion, category, tun, parameter, &value).isOk()); |
| 941 | EXPECT_EQ(ival, std::stoi(value)); |
| 942 | } |
| 943 | |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 944 | static std::string base64Encode(const std::vector<uint8_t>& input) { |
| 945 | size_t out_len; |
| 946 | EXPECT_EQ(1, EVP_EncodedLength(&out_len, input.size())); |
| 947 | // out_len includes the trailing NULL. |
| 948 | uint8_t output_bytes[out_len]; |
| 949 | EXPECT_EQ(out_len - 1, EVP_EncodeBlock(output_bytes, input.data(), input.size())); |
| 950 | return std::string(reinterpret_cast<char*>(output_bytes)); |
| 951 | } |
| 952 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 953 | TEST_F(BinderTest, SetResolverConfiguration_Tls) { |
Erik Kline | a1476fb | 2018-03-04 21:01:56 +0900 | [diff] [blame] | 954 | const std::vector<std::string> LOCALLY_ASSIGNED_DNS{"8.8.8.8", "2001:4860:4860::8888"}; |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 955 | std::vector<uint8_t> fp(SHA256_SIZE); |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 956 | std::vector<uint8_t> short_fp(1); |
| 957 | std::vector<uint8_t> long_fp(SHA256_SIZE + 1); |
| 958 | std::vector<std::string> test_domains; |
| 959 | std::vector<int> test_params = { 300, 25, 8, 8 }; |
| 960 | unsigned test_netid = 0; |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 961 | static const struct TestData { |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 962 | const std::vector<std::string> servers; |
| 963 | const std::string tlsName; |
| 964 | const std::vector<std::vector<uint8_t>> tlsFingerprints; |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 965 | const int expectedReturnCode; |
Erik Kline | a1476fb | 2018-03-04 21:01:56 +0900 | [diff] [blame] | 966 | } kTlsTestData[] = { |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 967 | { {"192.0.2.1"}, "", {}, 0 }, |
| 968 | { {"2001:db8::2"}, "host.name", {}, 0 }, |
| 969 | { {"192.0.2.3"}, "@@@@", { fp }, 0 }, |
| 970 | { {"2001:db8::4"}, "", { fp }, 0 }, |
Erik Kline | a1476fb | 2018-03-04 21:01:56 +0900 | [diff] [blame] | 971 | { {}, "", {}, 0 }, |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 972 | { {""}, "", {}, EINVAL }, |
Erik Kline | a1476fb | 2018-03-04 21:01:56 +0900 | [diff] [blame] | 973 | { {"192.0.*.5"}, "", {}, EINVAL }, |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 974 | { {"2001:dg8::6"}, "", {}, EINVAL }, |
| 975 | { {"2001:db8::c"}, "", { short_fp }, EINVAL }, |
| 976 | { {"192.0.2.12"}, "", { long_fp }, EINVAL }, |
| 977 | { {"2001:db8::e"}, "", { fp, fp, fp }, 0 }, |
| 978 | { {"192.0.2.14"}, "", { fp, short_fp }, EINVAL }, |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 979 | }; |
| 980 | |
Erik Kline | a1476fb | 2018-03-04 21:01:56 +0900 | [diff] [blame] | 981 | for (unsigned int i = 0; i < arraysize(kTlsTestData); i++) { |
| 982 | const auto &td = kTlsTestData[i]; |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 983 | |
| 984 | std::vector<std::string> fingerprints; |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 985 | for (const auto& fingerprint : td.tlsFingerprints) { |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 986 | fingerprints.push_back(base64Encode(fingerprint)); |
| 987 | } |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 988 | binder::Status status = mNetd->setResolverConfiguration( |
Erik Kline | a1476fb | 2018-03-04 21:01:56 +0900 | [diff] [blame] | 989 | test_netid, LOCALLY_ASSIGNED_DNS, test_domains, test_params, |
| 990 | td.tlsName, td.servers, fingerprints); |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 991 | |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 992 | if (td.expectedReturnCode == 0) { |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 993 | SCOPED_TRACE(String8::format("test case %d should have passed", i)); |
| 994 | SCOPED_TRACE(status.toString8()); |
| 995 | EXPECT_EQ(0, status.exceptionCode()); |
| 996 | } else { |
| 997 | SCOPED_TRACE(String8::format("test case %d should have failed", i)); |
| 998 | EXPECT_EQ(binder::Status::EX_SERVICE_SPECIFIC, status.exceptionCode()); |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 999 | EXPECT_EQ(td.expectedReturnCode, status.serviceSpecificErrorCode()); |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 1000 | } |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 1001 | } |
Ben Schwartz | 4204ecf | 2017-10-02 12:35:48 -0400 | [diff] [blame] | 1002 | // Ensure TLS is disabled before the start of the next test. |
| 1003 | mNetd->setResolverConfiguration( |
Erik Kline | a1476fb | 2018-03-04 21:01:56 +0900 | [diff] [blame] | 1004 | test_netid, kTlsTestData[0].servers, test_domains, test_params, |
| 1005 | "", {}, {}); |
Ben Schwartz | e760181 | 2017-04-28 16:38:29 -0400 | [diff] [blame] | 1006 | } |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 1007 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 1008 | namespace { |
| 1009 | |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 1010 | void expectNoTestCounterRules() { |
| 1011 | for (const auto& binary : { IPTABLES_PATH, IP6TABLES_PATH }) { |
| 1012 | std::string command = StringPrintf("%s -w -nvL tetherctrl_counters", binary); |
| 1013 | std::string allRules = Join(runCommand(command), "\n"); |
| 1014 | EXPECT_EQ(std::string::npos, allRules.find("netdtest_")); |
| 1015 | } |
| 1016 | } |
| 1017 | |
Bernie Innocenti | f691826 | 2018-06-11 17:37:35 +0900 | [diff] [blame] | 1018 | void addTetherCounterValues(const char* path, const std::string& if1, const std::string& if2, |
| 1019 | int byte, int pkt) { |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 1020 | runCommand(StringPrintf("%s -w -A tetherctrl_counters -i %s -o %s -j RETURN -c %d %d", |
| 1021 | path, if1.c_str(), if2.c_str(), pkt, byte)); |
| 1022 | } |
| 1023 | |
Bernie Innocenti | f691826 | 2018-06-11 17:37:35 +0900 | [diff] [blame] | 1024 | void delTetherCounterValues(const char* path, const std::string& if1, const std::string& if2) { |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 1025 | runCommand(StringPrintf("%s -w -D tetherctrl_counters -i %s -o %s -j RETURN", |
| 1026 | path, if1.c_str(), if2.c_str())); |
| 1027 | runCommand(StringPrintf("%s -w -D tetherctrl_counters -i %s -o %s -j RETURN", |
| 1028 | path, if2.c_str(), if1.c_str())); |
| 1029 | } |
| 1030 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 1031 | } // namespace |
| 1032 | |
| 1033 | TEST_F(BinderTest, TetherGetStats) { |
Lorenzo Colitti | 9a8a9ff | 2017-01-31 19:06:59 +0900 | [diff] [blame] | 1034 | expectNoTestCounterRules(); |
| 1035 | |
| 1036 | // TODO: fold this into more comprehensive tests once we have binder RPCs for enabling and |
| 1037 | // disabling tethering. We don't check the return value because these commands will fail if |
| 1038 | // tethering is already enabled. |
| 1039 | runCommand(StringPrintf("%s -w -N tetherctrl_counters", IPTABLES_PATH)); |
| 1040 | runCommand(StringPrintf("%s -w -N tetherctrl_counters", IP6TABLES_PATH)); |
| 1041 | |
| 1042 | std::string intIface1 = StringPrintf("netdtest_%u", arc4random_uniform(10000)); |
| 1043 | std::string intIface2 = StringPrintf("netdtest_%u", arc4random_uniform(10000)); |
| 1044 | std::string intIface3 = StringPrintf("netdtest_%u", arc4random_uniform(10000)); |
| 1045 | std::string extIface1 = StringPrintf("netdtest_%u", arc4random_uniform(10000)); |
| 1046 | std::string extIface2 = StringPrintf("netdtest_%u", arc4random_uniform(10000)); |
| 1047 | |
| 1048 | addTetherCounterValues(IPTABLES_PATH, intIface1, extIface1, 123, 111); |
| 1049 | addTetherCounterValues(IP6TABLES_PATH, intIface1, extIface1, 456, 10); |
| 1050 | addTetherCounterValues(IPTABLES_PATH, extIface1, intIface1, 321, 222); |
| 1051 | addTetherCounterValues(IP6TABLES_PATH, extIface1, intIface1, 654, 20); |
| 1052 | // RX is from external to internal, and TX is from internal to external. |
| 1053 | // So rxBytes is 321 + 654 = 975, txBytes is 123 + 456 = 579, etc. |
| 1054 | std::vector<int64_t> expected1 = { 975, 242, 579, 121 }; |
| 1055 | |
| 1056 | addTetherCounterValues(IPTABLES_PATH, intIface2, extIface2, 1000, 333); |
| 1057 | addTetherCounterValues(IP6TABLES_PATH, intIface2, extIface2, 3000, 30); |
| 1058 | |
| 1059 | addTetherCounterValues(IPTABLES_PATH, extIface2, intIface2, 2000, 444); |
| 1060 | addTetherCounterValues(IP6TABLES_PATH, extIface2, intIface2, 4000, 40); |
| 1061 | |
| 1062 | addTetherCounterValues(IP6TABLES_PATH, intIface3, extIface2, 1000, 25); |
| 1063 | addTetherCounterValues(IP6TABLES_PATH, extIface2, intIface3, 2000, 35); |
| 1064 | std::vector<int64_t> expected2 = { 8000, 519, 5000, 388 }; |
| 1065 | |
| 1066 | PersistableBundle stats; |
| 1067 | binder::Status status = mNetd->tetherGetStats(&stats); |
| 1068 | EXPECT_TRUE(status.isOk()) << "Getting tethering stats failed: " << status; |
| 1069 | |
| 1070 | std::vector<int64_t> actual1; |
| 1071 | EXPECT_TRUE(stats.getLongVector(String16(extIface1.c_str()), &actual1)); |
| 1072 | EXPECT_EQ(expected1, actual1); |
| 1073 | |
| 1074 | std::vector<int64_t> actual2; |
| 1075 | EXPECT_TRUE(stats.getLongVector(String16(extIface2.c_str()), &actual2)); |
| 1076 | EXPECT_EQ(expected2, actual2); |
| 1077 | |
| 1078 | for (const auto& path : { IPTABLES_PATH, IP6TABLES_PATH }) { |
| 1079 | delTetherCounterValues(path, intIface1, extIface1); |
| 1080 | delTetherCounterValues(path, intIface2, extIface2); |
| 1081 | if (path == IP6TABLES_PATH) { |
| 1082 | delTetherCounterValues(path, intIface3, extIface2); |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | expectNoTestCounterRules(); |
| 1087 | } |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 1088 | |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 1089 | namespace { |
| 1090 | |
Luke Huang | a521107 | 2018-08-01 23:36:29 +0800 | [diff] [blame] | 1091 | constexpr char IDLETIMER_RAW_PREROUTING[] = "idletimer_raw_PREROUTING"; |
| 1092 | constexpr char IDLETIMER_MANGLE_POSTROUTING[] = "idletimer_mangle_POSTROUTING"; |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 1093 | |
| 1094 | static std::vector<std::string> listIptablesRuleByTable(const char* binary, const char* table, |
| 1095 | const char* chainName) { |
| 1096 | std::string command = StringPrintf("%s -t %s -w -n -v -L %s", binary, table, chainName); |
| 1097 | return runCommand(command); |
| 1098 | } |
| 1099 | |
Luke Huang | a521107 | 2018-08-01 23:36:29 +0800 | [diff] [blame] | 1100 | bool iptablesIdleTimerInterfaceRuleExists(const char* binary, const char* chainName, |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 1101 | const std::string& expectedInterface, |
| 1102 | const std::string& expectedRule, const char* table) { |
| 1103 | std::vector<std::string> rules = listIptablesRuleByTable(binary, table, chainName); |
| 1104 | for (const auto& rule : rules) { |
| 1105 | if (rule.find(expectedInterface) != std::string::npos) { |
| 1106 | if (rule.find(expectedRule) != std::string::npos) { |
| 1107 | return true; |
| 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | return false; |
| 1112 | } |
| 1113 | |
| 1114 | void expectIdletimerInterfaceRuleExists(const std::string& ifname, int timeout, |
Luke Huang | a521107 | 2018-08-01 23:36:29 +0800 | [diff] [blame] | 1115 | const std::string& classLabel) { |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 1116 | std::string IdletimerRule = |
Luke Huang | a521107 | 2018-08-01 23:36:29 +0800 | [diff] [blame] | 1117 | StringPrintf("timeout:%u label:%s send_nl_msg:1", timeout, classLabel.c_str()); |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 1118 | for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) { |
Luke Huang | a521107 | 2018-08-01 23:36:29 +0800 | [diff] [blame] | 1119 | EXPECT_TRUE(iptablesIdleTimerInterfaceRuleExists(binary, IDLETIMER_RAW_PREROUTING, ifname, |
| 1120 | IdletimerRule, RAW_TABLE)); |
| 1121 | EXPECT_TRUE(iptablesIdleTimerInterfaceRuleExists(binary, IDLETIMER_MANGLE_POSTROUTING, |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 1122 | ifname, IdletimerRule, MANGLE_TABLE)); |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | void expectIdletimerInterfaceRuleNotExists(const std::string& ifname, int timeout, |
Luke Huang | a521107 | 2018-08-01 23:36:29 +0800 | [diff] [blame] | 1127 | const std::string& classLabel) { |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 1128 | std::string IdletimerRule = |
Luke Huang | a521107 | 2018-08-01 23:36:29 +0800 | [diff] [blame] | 1129 | StringPrintf("timeout:%u label:%s send_nl_msg:1", timeout, classLabel.c_str()); |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 1130 | for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) { |
Luke Huang | a521107 | 2018-08-01 23:36:29 +0800 | [diff] [blame] | 1131 | EXPECT_FALSE(iptablesIdleTimerInterfaceRuleExists(binary, IDLETIMER_RAW_PREROUTING, ifname, |
| 1132 | IdletimerRule, RAW_TABLE)); |
| 1133 | EXPECT_FALSE(iptablesIdleTimerInterfaceRuleExists(binary, IDLETIMER_MANGLE_POSTROUTING, |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 1134 | ifname, IdletimerRule, MANGLE_TABLE)); |
| 1135 | } |
| 1136 | } |
| 1137 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 1138 | } // namespace |
| 1139 | |
| 1140 | TEST_F(BinderTest, IdletimerAddRemoveInterface) { |
Luke Huang | 0051a62 | 2018-07-23 20:30:16 +0800 | [diff] [blame] | 1141 | // TODO: We will get error in if expectIdletimerInterfaceRuleNotExists if there are the same |
| 1142 | // rule in the table. Because we only check the result after calling remove function. We might |
| 1143 | // check the actual rule which is removed by our function (maybe compare the results between |
| 1144 | // calling function before and after) |
| 1145 | binder::Status status; |
| 1146 | const struct TestData { |
| 1147 | const std::string ifname; |
| 1148 | int32_t timeout; |
| 1149 | const std::string classLabel; |
| 1150 | } idleTestData[] = { |
| 1151 | {"wlan0", 1234, "happyday"}, |
| 1152 | {"rmnet_data0", 4567, "friday"}, |
| 1153 | }; |
| 1154 | for (const auto& td : idleTestData) { |
| 1155 | status = mNetd->idletimerAddInterface(td.ifname, td.timeout, td.classLabel); |
| 1156 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1157 | expectIdletimerInterfaceRuleExists(td.ifname, td.timeout, td.classLabel); |
| 1158 | |
| 1159 | status = mNetd->idletimerRemoveInterface(td.ifname, td.timeout, td.classLabel); |
| 1160 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1161 | expectIdletimerInterfaceRuleNotExists(td.ifname, td.timeout, td.classLabel); |
| 1162 | } |
| 1163 | } |
| 1164 | |
Luke Huang | a67dd56 | 2018-07-17 19:58:25 +0800 | [diff] [blame] | 1165 | namespace { |
| 1166 | |
| 1167 | constexpr char STRICT_OUTPUT[] = "st_OUTPUT"; |
| 1168 | constexpr char STRICT_CLEAR_CAUGHT[] = "st_clear_caught"; |
| 1169 | |
| 1170 | void expectStrictSetUidAccept(const int uid) { |
| 1171 | std::string uidRule = StringPrintf("owner UID match %u", uid); |
| 1172 | std::string perUidChain = StringPrintf("st_clear_caught_%u", uid); |
| 1173 | for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) { |
| 1174 | EXPECT_FALSE(iptablesRuleExists(binary, STRICT_OUTPUT, uidRule.c_str())); |
| 1175 | EXPECT_FALSE(iptablesRuleExists(binary, STRICT_CLEAR_CAUGHT, uidRule.c_str())); |
| 1176 | EXPECT_EQ(0, iptablesRuleLineLength(binary, perUidChain.c_str())); |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | void expectStrictSetUidLog(const int uid) { |
| 1181 | static const char logRule[] = "st_penalty_log all"; |
| 1182 | std::string uidRule = StringPrintf("owner UID match %u", uid); |
| 1183 | std::string perUidChain = StringPrintf("st_clear_caught_%u", uid); |
| 1184 | for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) { |
| 1185 | EXPECT_TRUE(iptablesRuleExists(binary, STRICT_OUTPUT, uidRule.c_str())); |
| 1186 | EXPECT_TRUE(iptablesRuleExists(binary, STRICT_CLEAR_CAUGHT, uidRule.c_str())); |
| 1187 | EXPECT_TRUE(iptablesRuleExists(binary, perUidChain.c_str(), logRule)); |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | void expectStrictSetUidReject(const int uid) { |
| 1192 | static const char rejectRule[] = "st_penalty_reject all"; |
| 1193 | std::string uidRule = StringPrintf("owner UID match %u", uid); |
| 1194 | std::string perUidChain = StringPrintf("st_clear_caught_%u", uid); |
| 1195 | for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) { |
| 1196 | EXPECT_TRUE(iptablesRuleExists(binary, STRICT_OUTPUT, uidRule.c_str())); |
| 1197 | EXPECT_TRUE(iptablesRuleExists(binary, STRICT_CLEAR_CAUGHT, uidRule.c_str())); |
| 1198 | EXPECT_TRUE(iptablesRuleExists(binary, perUidChain.c_str(), rejectRule)); |
| 1199 | } |
| 1200 | } |
| 1201 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 1202 | } // namespace |
| 1203 | |
| 1204 | TEST_F(BinderTest, StrictSetUidCleartextPenalty) { |
Luke Huang | a67dd56 | 2018-07-17 19:58:25 +0800 | [diff] [blame] | 1205 | binder::Status status; |
| 1206 | int32_t uid = randomUid(); |
| 1207 | |
| 1208 | // setUidCleartextPenalty Policy:Log with randomUid |
| 1209 | status = mNetd->strictUidCleartextPenalty(uid, INetd::PENALTY_POLICY_LOG); |
| 1210 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1211 | expectStrictSetUidLog(uid); |
| 1212 | |
| 1213 | // setUidCleartextPenalty Policy:Accept with randomUid |
| 1214 | status = mNetd->strictUidCleartextPenalty(uid, INetd::PENALTY_POLICY_ACCEPT); |
| 1215 | expectStrictSetUidAccept(uid); |
| 1216 | |
| 1217 | // setUidCleartextPenalty Policy:Reject with randomUid |
| 1218 | status = mNetd->strictUidCleartextPenalty(uid, INetd::PENALTY_POLICY_REJECT); |
| 1219 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1220 | expectStrictSetUidReject(uid); |
| 1221 | |
| 1222 | // setUidCleartextPenalty Policy:Accept with randomUid |
| 1223 | status = mNetd->strictUidCleartextPenalty(uid, INetd::PENALTY_POLICY_ACCEPT); |
| 1224 | expectStrictSetUidAccept(uid); |
| 1225 | |
| 1226 | // test wrong policy |
| 1227 | int32_t wrongPolicy = -123; |
| 1228 | status = mNetd->strictUidCleartextPenalty(uid, wrongPolicy); |
| 1229 | EXPECT_EQ(EINVAL, status.serviceSpecificErrorCode()); |
| 1230 | } |
| 1231 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 1232 | namespace { |
Luke Huang | 6d30123 | 2018-08-01 14:05:18 +0800 | [diff] [blame] | 1233 | |
Luke Huang | a521107 | 2018-08-01 23:36:29 +0800 | [diff] [blame] | 1234 | bool processExists(const std::string& processName) { |
Luke Huang | 6d30123 | 2018-08-01 14:05:18 +0800 | [diff] [blame] | 1235 | std::string cmd = StringPrintf("ps -A | grep '%s'", processName.c_str()); |
| 1236 | return (runCommand(cmd.c_str()).size()) ? true : false; |
| 1237 | } |
| 1238 | |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 1239 | } // namespace |
| 1240 | |
| 1241 | TEST_F(BinderTest, ClatdStartStop) { |
Luke Huang | 6d30123 | 2018-08-01 14:05:18 +0800 | [diff] [blame] | 1242 | binder::Status status; |
| 1243 | // use dummy0 for test since it is set ready |
| 1244 | static const char testIf[] = "dummy0"; |
| 1245 | const std::string clatdName = StringPrintf("clatd-%s", testIf); |
| 1246 | |
| 1247 | status = mNetd->clatdStart(testIf); |
| 1248 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1249 | EXPECT_TRUE(processExists(clatdName)); |
| 1250 | |
| 1251 | mNetd->clatdStop(testIf); |
| 1252 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1253 | EXPECT_FALSE(processExists(clatdName)); |
| 1254 | } |
Luke Huang | 457d470 | 2018-08-16 15:39:15 +0800 | [diff] [blame] | 1255 | |
| 1256 | namespace { |
| 1257 | |
| 1258 | bool getIpfwdV4Enable() { |
| 1259 | static const char ipv4IpfwdCmd[] = "cat /proc/sys/net/ipv4/ip_forward"; |
| 1260 | std::vector<std::string> result = runCommand(ipv4IpfwdCmd); |
| 1261 | EXPECT_TRUE(!result.empty()); |
| 1262 | int v4Enable = std::stoi(result[0]); |
| 1263 | return v4Enable; |
| 1264 | } |
| 1265 | |
| 1266 | bool getIpfwdV6Enable() { |
| 1267 | static const char ipv6IpfwdCmd[] = "cat proc/sys/net/ipv6/conf/all/forwarding"; |
| 1268 | std::vector<std::string> result = runCommand(ipv6IpfwdCmd); |
| 1269 | EXPECT_TRUE(!result.empty()); |
| 1270 | int v6Enable = std::stoi(result[0]); |
| 1271 | return v6Enable; |
| 1272 | } |
| 1273 | |
| 1274 | void expectIpfwdEnable(bool enable) { |
| 1275 | int enableIPv4 = getIpfwdV4Enable(); |
| 1276 | int enableIPv6 = getIpfwdV6Enable(); |
| 1277 | EXPECT_EQ(enable, enableIPv4); |
| 1278 | EXPECT_EQ(enable, enableIPv6); |
| 1279 | } |
| 1280 | |
Bernie Innocenti | 1bdf10d | 2018-09-10 18:46:07 +0900 | [diff] [blame] | 1281 | bool ipRuleIpfwdExists(const char* ipVersion, const std::string& ipfwdRule) { |
Luke Huang | 457d470 | 2018-08-16 15:39:15 +0800 | [diff] [blame] | 1282 | std::vector<std::string> rules = listIpRules(ipVersion); |
| 1283 | for (const auto& rule : rules) { |
| 1284 | if (rule.find(ipfwdRule) != std::string::npos) { |
| 1285 | return true; |
| 1286 | } |
| 1287 | } |
| 1288 | return false; |
| 1289 | } |
| 1290 | |
| 1291 | void expectIpfwdRuleExists(const char* fromIf, const char* toIf) { |
| 1292 | std::string ipfwdRule = StringPrintf("18000:\tfrom all iif %s lookup %s ", fromIf, toIf); |
| 1293 | |
| 1294 | for (const auto& ipVersion : {IP_RULE_V4, IP_RULE_V6}) { |
| 1295 | EXPECT_TRUE(ipRuleIpfwdExists(ipVersion, ipfwdRule)); |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | void expectIpfwdRuleNotExists(const char* fromIf, const char* toIf) { |
| 1300 | std::string ipfwdRule = StringPrintf("18000:\tfrom all iif %s lookup %s ", fromIf, toIf); |
| 1301 | |
| 1302 | for (const auto& ipVersion : {IP_RULE_V4, IP_RULE_V6}) { |
| 1303 | EXPECT_FALSE(ipRuleIpfwdExists(ipVersion, ipfwdRule)); |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | } // namespace |
| 1308 | |
| 1309 | TEST_F(BinderTest, TestIpfwdEnableDisableStatusForwarding) { |
| 1310 | // Netd default enable Ipfwd with requester NetdHwService |
| 1311 | const std::string defaultRequester = "NetdHwService"; |
| 1312 | |
| 1313 | binder::Status status = mNetd->ipfwdDisableForwarding(defaultRequester); |
| 1314 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1315 | expectIpfwdEnable(false); |
| 1316 | |
| 1317 | bool ipfwdEnabled; |
| 1318 | status = mNetd->ipfwdEnabled(&ipfwdEnabled); |
| 1319 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1320 | EXPECT_FALSE(ipfwdEnabled); |
| 1321 | |
| 1322 | status = mNetd->ipfwdEnableForwarding(defaultRequester); |
| 1323 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1324 | expectIpfwdEnable(true); |
| 1325 | |
| 1326 | status = mNetd->ipfwdEnabled(&ipfwdEnabled); |
| 1327 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1328 | EXPECT_TRUE(ipfwdEnabled); |
| 1329 | } |
| 1330 | |
| 1331 | TEST_F(BinderTest, TestIpfwdAddRemoveInterfaceForward) { |
| 1332 | static const char testFromIf[] = "dummy0"; |
| 1333 | static const char testToIf[] = "dummy0"; |
| 1334 | |
| 1335 | binder::Status status = mNetd->ipfwdAddInterfaceForward(testFromIf, testToIf); |
| 1336 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1337 | expectIpfwdRuleExists(testFromIf, testToIf); |
| 1338 | |
| 1339 | status = mNetd->ipfwdRemoveInterfaceForward(testFromIf, testToIf); |
| 1340 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1341 | expectIpfwdRuleNotExists(testFromIf, testToIf); |
Bernie Innocenti | 1bcc25a | 2018-08-10 17:15:00 +0900 | [diff] [blame] | 1342 | } |
Luke Huang | 531f5d3 | 2018-08-03 15:19:05 +0800 | [diff] [blame^] | 1343 | |
| 1344 | namespace { |
| 1345 | |
| 1346 | constexpr char BANDWIDTH_INPUT[] = "bw_INPUT"; |
| 1347 | constexpr char BANDWIDTH_OUTPUT[] = "bw_OUTPUT"; |
| 1348 | constexpr char BANDWIDTH_FORWARD[] = "bw_FORWARD"; |
| 1349 | constexpr char BANDWIDTH_NAUGHTY[] = "bw_penalty_box"; |
| 1350 | constexpr char BANDWIDTH_NICE[] = "bw_happy_box"; |
| 1351 | |
| 1352 | // TODO: move iptablesTargetsExists and listIptablesRuleByTable to the top. |
| 1353 | bool iptablesTargetsExists(const char* binary, int expectedCount, const char* table, |
| 1354 | const char* chainName, const std::string& expectedTargetA, |
| 1355 | const std::string& expectedTargetB) { |
| 1356 | std::vector<std::string> rules = listIptablesRuleByTable(binary, table, chainName); |
| 1357 | int matchCount = 0; |
| 1358 | |
| 1359 | for (const auto& rule : rules) { |
| 1360 | if (rule.find(expectedTargetA) != std::string::npos) { |
| 1361 | if (rule.find(expectedTargetB) != std::string::npos) { |
| 1362 | matchCount++; |
| 1363 | } |
| 1364 | } |
| 1365 | } |
| 1366 | return matchCount == expectedCount; |
| 1367 | } |
| 1368 | |
| 1369 | void expectXtQuotaValueEqual(const char* ifname, long quotaBytes) { |
| 1370 | std::string path = StringPrintf("/proc/net/xt_quota/%s", ifname); |
| 1371 | std::string result = ""; |
| 1372 | |
| 1373 | EXPECT_TRUE(ReadFileToString(path, &result)); |
| 1374 | EXPECT_EQ(std::to_string(quotaBytes), Trim(result)); |
| 1375 | } |
| 1376 | |
| 1377 | void expectBandwidthInterfaceQuotaRuleExists(const char* ifname, long quotaBytes) { |
| 1378 | std::string BANDWIDTH_COSTLY_IF = StringPrintf("bw_costly_%s", ifname); |
| 1379 | std::string quotaRule = StringPrintf("quota %s", ifname); |
| 1380 | |
| 1381 | for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) { |
| 1382 | EXPECT_TRUE(iptablesTargetsExists(binary, 1, FILTER_TABLE, BANDWIDTH_INPUT, ifname, |
| 1383 | BANDWIDTH_COSTLY_IF)); |
| 1384 | EXPECT_TRUE(iptablesTargetsExists(binary, 1, FILTER_TABLE, BANDWIDTH_OUTPUT, ifname, |
| 1385 | BANDWIDTH_COSTLY_IF)); |
| 1386 | EXPECT_TRUE(iptablesTargetsExists(binary, 2, FILTER_TABLE, BANDWIDTH_FORWARD, ifname, |
| 1387 | BANDWIDTH_COSTLY_IF)); |
| 1388 | EXPECT_TRUE(iptablesRuleExists(binary, BANDWIDTH_COSTLY_IF.c_str(), BANDWIDTH_NAUGHTY)); |
| 1389 | EXPECT_TRUE(iptablesRuleExists(binary, BANDWIDTH_COSTLY_IF.c_str(), quotaRule)); |
| 1390 | } |
| 1391 | expectXtQuotaValueEqual(ifname, quotaBytes); |
| 1392 | } |
| 1393 | |
| 1394 | void expectBandwidthInterfaceQuotaRuleDoesNotExist(const char* ifname) { |
| 1395 | std::string BANDWIDTH_COSTLY_IF = StringPrintf("bw_costly_%s", ifname); |
| 1396 | std::string quotaRule = StringPrintf("quota %s", ifname); |
| 1397 | |
| 1398 | for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) { |
| 1399 | EXPECT_FALSE(iptablesTargetsExists(binary, 1, FILTER_TABLE, BANDWIDTH_INPUT, ifname, |
| 1400 | BANDWIDTH_COSTLY_IF)); |
| 1401 | EXPECT_FALSE(iptablesTargetsExists(binary, 1, FILTER_TABLE, BANDWIDTH_OUTPUT, ifname, |
| 1402 | BANDWIDTH_COSTLY_IF)); |
| 1403 | EXPECT_FALSE(iptablesTargetsExists(binary, 2, FILTER_TABLE, BANDWIDTH_FORWARD, ifname, |
| 1404 | BANDWIDTH_COSTLY_IF)); |
| 1405 | EXPECT_FALSE(iptablesRuleExists(binary, BANDWIDTH_COSTLY_IF.c_str(), BANDWIDTH_NAUGHTY)); |
| 1406 | EXPECT_FALSE(iptablesRuleExists(binary, BANDWIDTH_COSTLY_IF.c_str(), quotaRule)); |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | void expectBandwidthInterfaceAlertRuleExists(const char* ifname, long alertBytes) { |
| 1411 | std::string BANDWIDTH_COSTLY_IF = StringPrintf("bw_costly_%s", ifname); |
| 1412 | std::string alertRule = StringPrintf("quota %sAlert", ifname); |
| 1413 | std::string alertName = StringPrintf("%sAlert", ifname); |
| 1414 | |
| 1415 | for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) { |
| 1416 | EXPECT_TRUE(iptablesRuleExists(binary, BANDWIDTH_COSTLY_IF.c_str(), alertRule)); |
| 1417 | } |
| 1418 | expectXtQuotaValueEqual(alertName.c_str(), alertBytes); |
| 1419 | } |
| 1420 | |
| 1421 | void expectBandwidthInterfaceAlertRuleDoesNotExist(const char* ifname) { |
| 1422 | std::string BANDWIDTH_COSTLY_IF = StringPrintf("bw_costly_%s", ifname); |
| 1423 | std::string alertRule = StringPrintf("quota %sAlert", ifname); |
| 1424 | |
| 1425 | for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) { |
| 1426 | EXPECT_FALSE(iptablesRuleExists(binary, BANDWIDTH_COSTLY_IF.c_str(), alertRule)); |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | void expectBandwidthGlobalAlertRuleExists(long alertBytes) { |
| 1431 | static const char globalAlertRule[] = "quota globalAlert"; |
| 1432 | static const char globalAlertName[] = "globalAlert"; |
| 1433 | |
| 1434 | for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) { |
| 1435 | EXPECT_TRUE(iptablesRuleExists(binary, BANDWIDTH_INPUT, globalAlertRule)); |
| 1436 | EXPECT_TRUE(iptablesRuleExists(binary, BANDWIDTH_OUTPUT, globalAlertRule)); |
| 1437 | } |
| 1438 | expectXtQuotaValueEqual(globalAlertName, alertBytes); |
| 1439 | } |
| 1440 | |
| 1441 | void expectBandwidthManipulateSpecialAppRuleExists(const char* chain, const char* target, int uid) { |
| 1442 | std::string uidRule = StringPrintf("owner UID match %u", uid); |
| 1443 | |
| 1444 | for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) { |
| 1445 | EXPECT_TRUE(iptablesTargetsExists(binary, 1, FILTER_TABLE, chain, target, uidRule)); |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | void expectBandwidthManipulateSpecialAppRuleDoesNotExist(const char* chain, int uid) { |
| 1450 | std::string uidRule = StringPrintf("owner UID match %u", uid); |
| 1451 | |
| 1452 | for (const auto& binary : {IPTABLES_PATH, IP6TABLES_PATH}) { |
| 1453 | EXPECT_FALSE(iptablesRuleExists(binary, chain, uidRule)); |
| 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | } // namespace |
| 1458 | |
| 1459 | TEST_F(BinderTest, BandwidthSetRemoveInterfaceQuota) { |
| 1460 | long testQuotaBytes = 5550; |
| 1461 | |
| 1462 | // Add test physical network |
| 1463 | EXPECT_TRUE(mNetd->networkCreatePhysical(TEST_NETID1, "").isOk()); |
| 1464 | EXPECT_TRUE(mNetd->networkAddInterface(TEST_NETID1, sTun.name()).isOk()); |
| 1465 | |
| 1466 | binder::Status status = mNetd->bandwidthSetInterfaceQuota(sTun.name(), testQuotaBytes); |
| 1467 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1468 | expectBandwidthInterfaceQuotaRuleExists(sTun.name().c_str(), testQuotaBytes); |
| 1469 | |
| 1470 | status = mNetd->bandwidthRemoveInterfaceQuota(sTun.name()); |
| 1471 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1472 | expectBandwidthInterfaceQuotaRuleDoesNotExist(sTun.name().c_str()); |
| 1473 | |
| 1474 | // Remove test physical network |
| 1475 | EXPECT_TRUE(mNetd->networkDestroy(TEST_NETID1).isOk()); |
| 1476 | } |
| 1477 | |
| 1478 | TEST_F(BinderTest, BandwidthSetRemoveInterfaceAlert) { |
| 1479 | long testAlertBytes = 373; |
| 1480 | |
| 1481 | // Add test physical network |
| 1482 | EXPECT_TRUE(mNetd->networkCreatePhysical(TEST_NETID1, "").isOk()); |
| 1483 | EXPECT_TRUE(mNetd->networkAddInterface(TEST_NETID1, sTun.name()).isOk()); |
| 1484 | |
| 1485 | // Need to have a prior interface quota set to set an alert |
| 1486 | binder::Status status = mNetd->bandwidthSetInterfaceQuota(sTun.name(), testAlertBytes); |
| 1487 | status = mNetd->bandwidthSetInterfaceAlert(sTun.name(), testAlertBytes); |
| 1488 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1489 | expectBandwidthInterfaceAlertRuleExists(sTun.name().c_str(), testAlertBytes); |
| 1490 | |
| 1491 | status = mNetd->bandwidthRemoveInterfaceAlert(sTun.name()); |
| 1492 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1493 | expectBandwidthInterfaceAlertRuleDoesNotExist(sTun.name().c_str()); |
| 1494 | |
| 1495 | // Remove interface quota |
| 1496 | status = mNetd->bandwidthRemoveInterfaceQuota(sTun.name()); |
| 1497 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1498 | expectBandwidthInterfaceQuotaRuleDoesNotExist(sTun.name().c_str()); |
| 1499 | |
| 1500 | // Remove test physical network |
| 1501 | EXPECT_TRUE(mNetd->networkDestroy(TEST_NETID1).isOk()); |
| 1502 | } |
| 1503 | |
| 1504 | TEST_F(BinderTest, BandwidthSetGlobalAlert) { |
| 1505 | long testAlertBytes = 2097149; |
| 1506 | |
| 1507 | binder::Status status = mNetd->bandwidthSetGlobalAlert(testAlertBytes); |
| 1508 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1509 | expectBandwidthGlobalAlertRuleExists(testAlertBytes); |
| 1510 | |
| 1511 | testAlertBytes = 2097152; |
| 1512 | status = mNetd->bandwidthSetGlobalAlert(testAlertBytes); |
| 1513 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1514 | expectBandwidthGlobalAlertRuleExists(testAlertBytes); |
| 1515 | } |
| 1516 | |
| 1517 | TEST_F(BinderTest, BandwidthManipulateSpecialApp) { |
| 1518 | SKIP_IF_BPF_SUPPORTED; |
| 1519 | |
| 1520 | int32_t uid = randomUid(); |
| 1521 | static const char targetReject[] = "REJECT"; |
| 1522 | static const char targetReturn[] = "RETURN"; |
| 1523 | |
| 1524 | // add NaughtyApp |
| 1525 | binder::Status status = mNetd->bandwidthAddNaughtyApp(uid); |
| 1526 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1527 | expectBandwidthManipulateSpecialAppRuleExists(BANDWIDTH_NAUGHTY, targetReject, uid); |
| 1528 | |
| 1529 | // remove NaughtyApp |
| 1530 | status = mNetd->bandwidthRemoveNaughtyApp(uid); |
| 1531 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1532 | expectBandwidthManipulateSpecialAppRuleDoesNotExist(BANDWIDTH_NAUGHTY, uid); |
| 1533 | |
| 1534 | // add NiceApp |
| 1535 | status = mNetd->bandwidthAddNiceApp(uid); |
| 1536 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1537 | expectBandwidthManipulateSpecialAppRuleExists(BANDWIDTH_NICE, targetReturn, uid); |
| 1538 | |
| 1539 | // remove NiceApp |
| 1540 | status = mNetd->bandwidthRemoveNiceApp(uid); |
| 1541 | EXPECT_TRUE(status.isOk()) << status.exceptionMessage(); |
| 1542 | expectBandwidthManipulateSpecialAppRuleDoesNotExist(BANDWIDTH_NICE, uid); |
| 1543 | } |