Pierre Imai | 1cfa543 | 2016-02-24 18:00:03 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 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 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 17 | #include <regex> |
| 18 | #include <set> |
| 19 | #include <string> |
| 20 | |
| 21 | #include <android-base/strings.h> |
Lorenzo Colitti | 05306fb | 2017-02-09 04:56:00 +0900 | [diff] [blame] | 22 | #include <android-base/stringprintf.h> |
| 23 | |
Lorenzo Colitti | 19ee8a8 | 2017-02-02 12:59:05 +0900 | [diff] [blame] | 24 | #define LOG_TAG "Netd" |
Logan Chien | 3f46148 | 2018-04-23 14:31:32 +0800 | [diff] [blame] | 25 | #include <log/log.h> |
Lorenzo Colitti | 19ee8a8 | 2017-02-02 12:59:05 +0900 | [diff] [blame] | 26 | |
Pierre Imai | 1cfa543 | 2016-02-24 18:00:03 +0900 | [diff] [blame] | 27 | #include "Controllers.h" |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 28 | #include "IdletimerController.h" |
| 29 | #include "NetworkController.h" |
| 30 | #include "RouteController.h" |
Lorenzo Colitti | 19ee8a8 | 2017-02-02 12:59:05 +0900 | [diff] [blame] | 31 | #include "Stopwatch.h" |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 32 | #include "oem_iptables_hook.h" |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 33 | #include "XfrmController.h" |
Pierre Imai | 1cfa543 | 2016-02-24 18:00:03 +0900 | [diff] [blame] | 34 | |
| 35 | namespace android { |
| 36 | namespace net { |
| 37 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 38 | using android::base::Join; |
| 39 | using android::base::StringPrintf; |
| 40 | using android::base::StringAppendF; |
| 41 | |
Lorenzo Colitti | 341d3a0 | 2017-08-08 17:31:35 +0900 | [diff] [blame] | 42 | auto Controllers::execIptablesRestore = ::execIptablesRestore; |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 43 | auto Controllers::execIptablesRestoreWithOutput = ::execIptablesRestoreWithOutput; |
Lorenzo Colitti | 341d3a0 | 2017-08-08 17:31:35 +0900 | [diff] [blame] | 44 | |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 45 | netdutils::Log gLog("netd"); |
| 46 | |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 47 | namespace { |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 48 | |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 49 | /** |
| 50 | * List of module chains to be created, along with explicit ordering. ORDERING |
| 51 | * IS CRITICAL, AND SHOULD BE TRIPLE-CHECKED WITH EACH CHANGE. |
| 52 | */ |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 53 | static const std::vector<const char*> FILTER_INPUT = { |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 54 | // Bandwidth should always be early in input chain, to make sure we |
| 55 | // correctly count incoming traffic against data plan. |
| 56 | BandwidthController::LOCAL_INPUT, |
| 57 | FirewallController::LOCAL_INPUT, |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 58 | }; |
| 59 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 60 | static const std::vector<const char*> FILTER_FORWARD = { |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 61 | OEM_IPTABLES_FILTER_FORWARD, |
| 62 | FirewallController::LOCAL_FORWARD, |
| 63 | BandwidthController::LOCAL_FORWARD, |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 64 | TetherController::LOCAL_FORWARD, |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 65 | }; |
| 66 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 67 | static const std::vector<const char*> FILTER_OUTPUT = { |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 68 | OEM_IPTABLES_FILTER_OUTPUT, |
| 69 | FirewallController::LOCAL_OUTPUT, |
| 70 | StrictController::LOCAL_OUTPUT, |
| 71 | BandwidthController::LOCAL_OUTPUT, |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 72 | }; |
| 73 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 74 | static const std::vector<const char*> RAW_PREROUTING = { |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 75 | BandwidthController::LOCAL_RAW_PREROUTING, |
| 76 | IdletimerController::LOCAL_RAW_PREROUTING, |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 77 | TetherController::LOCAL_RAW_PREROUTING, |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 78 | }; |
| 79 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 80 | static const std::vector<const char*> MANGLE_POSTROUTING = { |
Lorenzo Colitti | 05306fb | 2017-02-09 04:56:00 +0900 | [diff] [blame] | 81 | OEM_IPTABLES_MANGLE_POSTROUTING, |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 82 | BandwidthController::LOCAL_MANGLE_POSTROUTING, |
| 83 | IdletimerController::LOCAL_MANGLE_POSTROUTING, |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 84 | }; |
| 85 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 86 | static const std::vector<const char*> MANGLE_INPUT = { |
Joel Scherpelz | 08b84cd | 2017-05-22 13:11:54 +0900 | [diff] [blame] | 87 | WakeupController::LOCAL_MANGLE_INPUT, |
Lorenzo Colitti | d78843e | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 88 | RouteController::LOCAL_MANGLE_INPUT, |
Lorenzo Colitti | d78843e | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 89 | }; |
| 90 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 91 | static const std::vector<const char*> MANGLE_FORWARD = { |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 92 | TetherController::LOCAL_MANGLE_FORWARD, |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 93 | }; |
| 94 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 95 | static const std::vector<const char*> NAT_PREROUTING = { |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 96 | OEM_IPTABLES_NAT_PREROUTING, |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 97 | }; |
| 98 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 99 | static const std::vector<const char*> NAT_POSTROUTING = { |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 100 | TetherController::LOCAL_NAT_POSTROUTING, |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 101 | }; |
| 102 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 103 | // Commands to create child chains and to match created chains in iptables -S output. Keep in sync. |
| 104 | static const char* CHILD_CHAIN_TEMPLATE = "-A %s -j %s\n"; |
| 105 | static const std::regex CHILD_CHAIN_REGEX("^-A ([^ ]+) -j ([^ ]+)$", |
| 106 | std::regex_constants::extended); |
| 107 | |
Lorenzo Colitti | 341d3a0 | 2017-08-08 17:31:35 +0900 | [diff] [blame] | 108 | } // namespace |
| 109 | |
| 110 | /* static */ |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 111 | std::set<std::string> Controllers::findExistingChildChains(const IptablesTarget target, |
| 112 | const char* table, |
| 113 | const char* parentChain) { |
| 114 | if (target == V4V6) { |
| 115 | ALOGE("findExistingChildChains only supports one protocol at a time"); |
| 116 | abort(); |
| 117 | } |
| 118 | |
| 119 | std::set<std::string> existing; |
| 120 | |
| 121 | // List the current contents of parentChain. |
| 122 | // |
| 123 | // TODO: there is no guarantee that nothing else modifies the chain in the few milliseconds |
| 124 | // between when we list the existing rules and when we delete them. However: |
| 125 | // - Since this code is only run on startup, nothing else in netd will be running. |
| 126 | // - While vendor code is known to add its own rules to chains created by netd, it should never |
| 127 | // be modifying the rules in childChains or the rules that hook said chains into their parent |
| 128 | // chains. |
| 129 | std::string command = StringPrintf("*%s\n-S %s\nCOMMIT\n", table, parentChain); |
| 130 | std::string output; |
| 131 | if (Controllers::execIptablesRestoreWithOutput(target, command, &output) == -1) { |
| 132 | ALOGE("Error listing chain %s in table %s\n", parentChain, table); |
| 133 | return existing; |
| 134 | } |
| 135 | |
| 136 | // The only rules added by createChildChains are of the simple form "-A <parent> -j <child>". |
| 137 | // Find those rules and add each one's child chain to existing. |
| 138 | std::smatch matches; |
| 139 | std::stringstream stream(output); |
| 140 | std::string rule; |
| 141 | while (std::getline(stream, rule, '\n')) { |
| 142 | if (std::regex_search(rule, matches, CHILD_CHAIN_REGEX) && matches[1] == parentChain) { |
| 143 | existing.insert(matches[2]); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | return existing; |
| 148 | } |
| 149 | |
| 150 | /* static */ |
Lorenzo Colitti | 341d3a0 | 2017-08-08 17:31:35 +0900 | [diff] [blame] | 151 | void Controllers::createChildChains(IptablesTarget target, const char* table, |
| 152 | const char* parentChain, |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 153 | const std::vector<const char*>& childChains, |
Lorenzo Colitti | 341d3a0 | 2017-08-08 17:31:35 +0900 | [diff] [blame] | 154 | bool exclusive) { |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 155 | std::string command = StringPrintf("*%s\n", table); |
Lorenzo Colitti | cda022e | 2017-02-03 12:35:46 +0900 | [diff] [blame] | 156 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 157 | // We cannot just clear all the chains we create because vendor code modifies filter OUTPUT and |
| 158 | // mangle POSTROUTING directly. So: |
| 159 | // |
| 160 | // - If we're the exclusive owner of this chain, simply clear it entirely. |
| 161 | // - If not, then list the chain's current contents to ensure that if we restart after a crash, |
| 162 | // we leave the existing rules alone in the positions they currently occupy. This is faster |
| 163 | // than blindly deleting our rules and recreating them, because deleting a rule that doesn't |
| 164 | // exists causes iptables-restore to quit, which takes ~30ms per delete. It's also more |
| 165 | // correct, because if we delete rules and re-add them, they'll be in the wrong position with |
| 166 | // regards to the vendor rules. |
| 167 | // |
Lorenzo Colitti | cda022e | 2017-02-03 12:35:46 +0900 | [diff] [blame] | 168 | // TODO: Make all chains exclusive once vendor code uses the oem_* rules. |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 169 | std::set<std::string> existingChildChains; |
Lorenzo Colitti | cda022e | 2017-02-03 12:35:46 +0900 | [diff] [blame] | 170 | if (exclusive) { |
| 171 | // Just running ":chain -" flushes user-defined chains, but not built-in chains like INPUT. |
| 172 | // Since at this point we don't know if parentChain is a built-in chain, do both. |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 173 | StringAppendF(&command, ":%s -\n", parentChain); |
| 174 | StringAppendF(&command, "-F %s\n", parentChain); |
| 175 | } else { |
| 176 | existingChildChains = findExistingChildChains(target, table, parentChain); |
Lorenzo Colitti | cda022e | 2017-02-03 12:35:46 +0900 | [diff] [blame] | 177 | } |
| 178 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 179 | for (const auto& childChain : childChains) { |
| 180 | // Always clear the child chain. |
| 181 | StringAppendF(&command, ":%s -\n", childChain); |
| 182 | // But only add it to the parent chain if it's not already there. |
| 183 | if (existingChildChains.find(childChain) == existingChildChains.end()) { |
| 184 | StringAppendF(&command, CHILD_CHAIN_TEMPLATE, parentChain, childChain); |
Lorenzo Colitti | cda022e | 2017-02-03 12:35:46 +0900 | [diff] [blame] | 185 | } |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 186 | } |
Lorenzo Colitti | 341d3a0 | 2017-08-08 17:31:35 +0900 | [diff] [blame] | 187 | command += "COMMIT\n"; |
Lorenzo Colitti | 05306fb | 2017-02-09 04:56:00 +0900 | [diff] [blame] | 188 | execIptablesRestore(target, command); |
| 189 | } |
| 190 | |
Joel Scherpelz | 08b84cd | 2017-05-22 13:11:54 +0900 | [diff] [blame] | 191 | Controllers::Controllers() |
| 192 | : clatdCtrl(&netCtrl), |
| 193 | wakeupCtrl( |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 194 | [this](const WakeupController::ReportArgs& args) { |
| 195 | const auto listener = eventReporter.getNetdEventListener(); |
| 196 | if (listener == nullptr) { |
| 197 | gLog.error("getNetdEventListener() returned nullptr. dropping wakeup event"); |
| 198 | return; |
| 199 | } |
| 200 | String16 prefix = String16(args.prefix.c_str()); |
| 201 | String16 srcIp = String16(args.srcIp.c_str()); |
| 202 | String16 dstIp = String16(args.dstIp.c_str()); |
| 203 | listener->onWakeupEvent(prefix, args.uid, args.ethertype, args.ipNextHeader, |
| 204 | args.dstHw, srcIp, dstIp, args.srcPort, args.dstPort, |
| 205 | args.timestampNs); |
| 206 | }, |
| 207 | &iptablesRestoreCtrl) { |
Erik Kline | 2c5aaa1 | 2016-06-08 13:24:45 +0900 | [diff] [blame] | 208 | InterfaceController::initializeAll(); |
| 209 | } |
Pierre Imai | 1cfa543 | 2016-02-24 18:00:03 +0900 | [diff] [blame] | 210 | |
Lorenzo Colitti | 341d3a0 | 2017-08-08 17:31:35 +0900 | [diff] [blame] | 211 | void Controllers::initChildChains() { |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 212 | /* |
| 213 | * This is the only time we touch top-level chains in iptables; controllers |
| 214 | * should only mutate rules inside of their children chains, as created by |
| 215 | * the constants above. |
| 216 | * |
| 217 | * Modules should never ACCEPT packets (except in well-justified cases); |
| 218 | * they should instead defer to any remaining modules using RETURN, or |
| 219 | * otherwise DROP/REJECT. |
| 220 | */ |
| 221 | |
Lorenzo Colitti | 05306fb | 2017-02-09 04:56:00 +0900 | [diff] [blame] | 222 | // Create chains for child modules. |
Lorenzo Colitti | cda022e | 2017-02-03 12:35:46 +0900 | [diff] [blame] | 223 | createChildChains(V4V6, "filter", "INPUT", FILTER_INPUT, true); |
| 224 | createChildChains(V4V6, "filter", "FORWARD", FILTER_FORWARD, true); |
Lorenzo Colitti | cda022e | 2017-02-03 12:35:46 +0900 | [diff] [blame] | 225 | createChildChains(V4V6, "raw", "PREROUTING", RAW_PREROUTING, true); |
Lorenzo Colitti | cda022e | 2017-02-03 12:35:46 +0900 | [diff] [blame] | 226 | createChildChains(V4V6, "mangle", "FORWARD", MANGLE_FORWARD, true); |
Lorenzo Colitti | d78843e | 2017-03-27 05:52:31 +0900 | [diff] [blame] | 227 | createChildChains(V4V6, "mangle", "INPUT", MANGLE_INPUT, true); |
Lorenzo Colitti | cda022e | 2017-02-03 12:35:46 +0900 | [diff] [blame] | 228 | createChildChains(V4, "nat", "PREROUTING", NAT_PREROUTING, true); |
| 229 | createChildChains(V4, "nat", "POSTROUTING", NAT_POSTROUTING, true); |
Lorenzo Colitti | 341d3a0 | 2017-08-08 17:31:35 +0900 | [diff] [blame] | 230 | |
Lorenzo Colitti | adc3a5f | 2017-08-08 17:23:12 +0900 | [diff] [blame] | 231 | createChildChains(V4, "filter", "OUTPUT", FILTER_OUTPUT, false); |
| 232 | createChildChains(V6, "filter", "OUTPUT", FILTER_OUTPUT, false); |
| 233 | createChildChains(V4, "mangle", "POSTROUTING", MANGLE_POSTROUTING, false); |
| 234 | createChildChains(V6, "mangle", "POSTROUTING", MANGLE_POSTROUTING, false); |
Lorenzo Colitti | 341d3a0 | 2017-08-08 17:31:35 +0900 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | void Controllers::initIptablesRules() { |
| 238 | Stopwatch s; |
| 239 | initChildChains(); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 240 | gLog.info("Creating child chains: %.1fms", s.getTimeAndReset()); |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 241 | |
| 242 | // Let each module setup their child chains |
| 243 | setupOemIptablesHook(); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 244 | gLog.info("Setting up OEM hooks: %.1fms", s.getTimeAndReset()); |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 245 | |
| 246 | /* When enabled, DROPs all packets except those matching rules. */ |
| 247 | firewallCtrl.setupIptablesHooks(); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 248 | gLog.info("Setting up FirewallController hooks: %.1fms", s.getTimeAndReset()); |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 249 | |
| 250 | /* Does DROPs in FORWARD by default */ |
Lorenzo Colitti | a93126d | 2017-08-24 13:28:19 +0900 | [diff] [blame] | 251 | tetherCtrl.setupIptablesHooks(); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 252 | gLog.info("Setting up TetherController hooks: %.1fms", s.getTimeAndReset()); |
Lorenzo Colitti | 19ee8a8 | 2017-02-02 12:59:05 +0900 | [diff] [blame] | 253 | |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 254 | /* |
| 255 | * Does REJECT in INPUT, OUTPUT. Does counting also. |
| 256 | * No DROP/REJECT allowed later in netfilter-flow hook order. |
| 257 | */ |
| 258 | bandwidthCtrl.setupIptablesHooks(); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 259 | gLog.info("Setting up BandwidthController hooks: %.1fms", s.getTimeAndReset()); |
Lorenzo Colitti | 19ee8a8 | 2017-02-02 12:59:05 +0900 | [diff] [blame] | 260 | |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 261 | /* |
| 262 | * Counts in nat: PREROUTING, POSTROUTING. |
| 263 | * No DROP/REJECT allowed later in netfilter-flow hook order. |
| 264 | */ |
| 265 | idletimerCtrl.setupIptablesHooks(); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 266 | gLog.info("Setting up IdletimerController hooks: %.1fms", s.getTimeAndReset()); |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | void Controllers::init() { |
| 270 | initIptablesRules(); |
Lorenzo Colitti | 19ee8a8 | 2017-02-02 12:59:05 +0900 | [diff] [blame] | 271 | Stopwatch s; |
Chenbo Feng | c10a8a4 | 2017-12-15 13:56:33 -0800 | [diff] [blame] | 272 | netdutils::Status tcStatus = trafficCtrl.start(); |
| 273 | if (!isOk(tcStatus)) { |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 274 | gLog.error("Failed to start trafficcontroller: (%s)", toString(tcStatus).c_str()); |
Chenbo Feng | c10a8a4 | 2017-12-15 13:56:33 -0800 | [diff] [blame] | 275 | } |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 276 | gLog.info("Initializing traffic control: %.1fms", s.getTimeAndReset()); |
Chenbo Feng | c10a8a4 | 2017-12-15 13:56:33 -0800 | [diff] [blame] | 277 | |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 278 | bandwidthCtrl.enableBandwidthControl(false); |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 279 | gLog.info("Disabling bandwidth control: %.1fms", s.getTimeAndReset()); |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 280 | |
Chenbo Feng | c10a8a4 | 2017-12-15 13:56:33 -0800 | [diff] [blame] | 281 | if (int ret = RouteController::Init(NetworkController::LOCAL_NET_ID)) { |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 282 | gLog.error("Failed to initialize RouteController (%s)", strerror(-ret)); |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 283 | } |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 284 | gLog.info("Initializing RouteController: %.1fms", s.getTimeAndReset()); |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 285 | |
| 286 | netdutils::Status xStatus = XfrmController::Init(); |
| 287 | if (!isOk(xStatus)) { |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 288 | gLog.error("Failed to initialize XfrmController (%s)", netdutils::toString(xStatus).c_str()); |
Nathan Harold | 21299f7 | 2018-03-16 20:13:03 -0700 | [diff] [blame] | 289 | }; |
Erik Kline | b31fd69 | 2018-06-06 20:50:11 +0900 | [diff] [blame^] | 290 | gLog.info("Initializing XfrmController: %.1fms", s.getTimeAndReset()); |
Lorenzo Colitti | 1ed96e2 | 2017-02-02 12:21:56 +0900 | [diff] [blame] | 291 | } |
| 292 | |
Pierre Imai | 1cfa543 | 2016-02-24 18:00:03 +0900 | [diff] [blame] | 293 | Controllers* gCtls = nullptr; |
| 294 | |
| 295 | } // namespace net |
| 296 | } // namespace android |