Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
| 17 | #include "RouteController.h" |
| 18 | |
| 19 | #include "Fwmark.h" |
| 20 | #include "NetdConstants.h" |
| 21 | |
Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 22 | #include <linux/rtnetlink.h> |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 23 | #include <logwrap/logwrap.h> |
| 24 | #include <net/if.h> |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 25 | |
| 26 | namespace { |
| 27 | |
Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 28 | const uint32_t RULE_PRIORITY_PRIVILEGED_LEGACY = 11000; |
Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 29 | const uint32_t RULE_PRIORITY_PER_NETWORK_EXPLICIT = 13000; |
| 30 | const uint32_t RULE_PRIORITY_PER_NETWORK_INTERFACE = 14000; |
Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 31 | const uint32_t RULE_PRIORITY_LEGACY = 16000; |
Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 32 | const uint32_t RULE_PRIORITY_PER_NETWORK_NORMAL = 17000; |
| 33 | const uint32_t RULE_PRIORITY_DEFAULT_NETWORK = 19000; |
| 34 | const uint32_t RULE_PRIORITY_MAIN = 20000; |
Sreeram Ramachandran | 56afacf | 2014-05-28 15:07:00 -0700 | [diff] [blame^] | 35 | // TODO: Uncomment once we are sure everything works. |
| 36 | #if 0 |
Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 37 | const uint32_t RULE_PRIORITY_UNREACHABLE = 21000; |
Sreeram Ramachandran | 56afacf | 2014-05-28 15:07:00 -0700 | [diff] [blame^] | 38 | #endif |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 39 | |
Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 40 | // TODO: These should be turned into per-UID tables once the kernel supports UID-based routing. |
| 41 | const int ROUTE_TABLE_PRIVILEGED_LEGACY = RouteController::ROUTE_TABLE_OFFSET_FROM_INDEX - 901; |
| 42 | const int ROUTE_TABLE_LEGACY = RouteController::ROUTE_TABLE_OFFSET_FROM_INDEX - 902; |
| 43 | |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 44 | uint32_t getRouteTableForInterface(const char* interface) { |
Sreeram Ramachandran | a481180 | 2014-04-10 12:10:24 -0700 | [diff] [blame] | 45 | uint32_t index = if_nametoindex(interface); |
| 46 | return index ? index + RouteController::ROUTE_TABLE_OFFSET_FROM_INDEX : 0; |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 49 | // Adds or removes a routing rule for IPv4 and IPv6. |
| 50 | // |
| 51 | // + If |table| is non-zero, the rule points at the specified routing table. Otherwise, the rule |
| 52 | // returns ENETUNREACH. |
| 53 | // + If |mask| is non-zero, the rule matches the specified fwmark and mask. Otherwise, |fwmark| is |
| 54 | // ignored. |
| 55 | // + If |interface| is non-NULL, the rule matches the specified outgoing interface. |
| 56 | bool runIpRuleCommand(const char* action, uint32_t priority, uint32_t table, uint32_t fwmark, |
| 57 | uint32_t mask, const char* interface) { |
Lorenzo Colitti | a10ac32 | 2014-04-11 18:26:17 +0900 | [diff] [blame] | 58 | char priorityString[UINT32_STRLEN]; |
Lorenzo Colitti | a10ac32 | 2014-04-11 18:26:17 +0900 | [diff] [blame] | 59 | snprintf(priorityString, sizeof(priorityString), "%u", priority); |
Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 60 | |
| 61 | char tableString[UINT32_STRLEN]; |
Lorenzo Colitti | a10ac32 | 2014-04-11 18:26:17 +0900 | [diff] [blame] | 62 | snprintf(tableString, sizeof(tableString), "%u", table); |
| 63 | |
| 64 | char fwmarkString[sizeof("0x12345678/0x12345678")]; |
| 65 | snprintf(fwmarkString, sizeof(fwmarkString), "0x%x/0x%x", fwmark, mask); |
| 66 | |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 67 | const char* version[] = {"-4", "-6"}; |
| 68 | for (size_t i = 0; i < ARRAY_SIZE(version); ++i) { |
| 69 | int argc = 0; |
| 70 | const char* argv[16]; |
| 71 | |
| 72 | argv[argc++] = IP_PATH; |
| 73 | argv[argc++] = version[i]; |
| 74 | argv[argc++] = "rule"; |
| 75 | argv[argc++] = action; |
| 76 | argv[argc++] = "priority"; |
Lorenzo Colitti | a10ac32 | 2014-04-11 18:26:17 +0900 | [diff] [blame] | 77 | argv[argc++] = priorityString; |
Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 78 | if (table) { |
| 79 | argv[argc++] = "table"; |
| 80 | argv[argc++] = tableString; |
| 81 | } else { |
| 82 | argv[argc++] = "unreachable"; |
| 83 | } |
Lorenzo Colitti | a10ac32 | 2014-04-11 18:26:17 +0900 | [diff] [blame] | 84 | if (mask) { |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 85 | argv[argc++] = "fwmark"; |
Lorenzo Colitti | a10ac32 | 2014-04-11 18:26:17 +0900 | [diff] [blame] | 86 | argv[argc++] = fwmarkString; |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 87 | } |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 88 | if (interface) { |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 89 | argv[argc++] = "oif"; |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 90 | argv[argc++] = interface; |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 91 | } |
| 92 | if (android_fork_execvp(argc, const_cast<char**>(argv), NULL, false, false)) { |
| 93 | return false; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return true; |
| 98 | } |
| 99 | |
Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 100 | bool runIpRouteCommand(const char* action, uint32_t table, const char* interface, |
| 101 | const char* destination, const char* nexthop) { |
| 102 | char tableString[UINT32_STRLEN]; |
| 103 | snprintf(tableString, sizeof(tableString), "%u", table); |
| 104 | |
| 105 | int argc = 0; |
| 106 | const char* argv[16]; |
| 107 | |
| 108 | argv[argc++] = IP_PATH; |
| 109 | argv[argc++] = "route"; |
| 110 | argv[argc++] = action; |
| 111 | argv[argc++] = "table"; |
| 112 | argv[argc++] = tableString; |
| 113 | if (destination) { |
| 114 | argv[argc++] = destination; |
| 115 | argv[argc++] = "dev"; |
| 116 | argv[argc++] = interface; |
| 117 | if (nexthop) { |
| 118 | argv[argc++] = "via"; |
| 119 | argv[argc++] = nexthop; |
| 120 | } |
| 121 | } |
| 122 | |
Sreeram Ramachandran | a79f618 | 2014-04-24 15:55:26 -0700 | [diff] [blame] | 123 | return !android_fork_execvp(argc, const_cast<char**>(argv), NULL, false, false); |
Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 126 | bool modifyPerNetworkRules(unsigned netId, const char* interface, Permission permission, bool add, |
| 127 | bool modifyIptables) { |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 128 | uint32_t table = getRouteTableForInterface(interface); |
| 129 | if (!table) { |
| 130 | return false; |
| 131 | } |
| 132 | |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 133 | const char* action = add ? ADD : DEL; |
| 134 | |
Sreeram Ramachandran | 122f581 | 2014-05-11 20:29:49 -0700 | [diff] [blame] | 135 | Fwmark fwmark; |
| 136 | fwmark.permission = permission; |
| 137 | |
| 138 | Fwmark mask; |
| 139 | mask.permission = permission; |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 140 | |
| 141 | // A rule to route traffic based on a chosen outgoing interface. |
| 142 | // |
| 143 | // Supports apps that use SO_BINDTODEVICE or IP_PKTINFO options and the kernel that already |
| 144 | // knows the outgoing interface (typically for link-local communications). |
Sreeram Ramachandran | 122f581 | 2014-05-11 20:29:49 -0700 | [diff] [blame] | 145 | if (!runIpRuleCommand(action, RULE_PRIORITY_PER_NETWORK_INTERFACE, table, fwmark.intValue, |
| 146 | mask.intValue, interface)) { |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 147 | return false; |
| 148 | } |
| 149 | |
| 150 | // A rule to route traffic based on the chosen network. |
| 151 | // |
| 152 | // This is for sockets that have not explicitly requested a particular network, but have been |
| 153 | // bound to one when they called connect(). This ensures that sockets connected on a particular |
| 154 | // network stay on that network even if the default network changes. |
Sreeram Ramachandran | 122f581 | 2014-05-11 20:29:49 -0700 | [diff] [blame] | 155 | fwmark.netId = netId; |
| 156 | mask.netId = FWMARK_NET_ID_MASK; |
| 157 | if (!runIpRuleCommand(action, RULE_PRIORITY_PER_NETWORK_NORMAL, table, fwmark.intValue, |
| 158 | mask.intValue, NULL)) { |
| 159 | return false; |
| 160 | } |
| 161 | |
| 162 | // A rule to route traffic based on an explicitly chosen network. |
| 163 | // |
| 164 | // Supports apps that use the multinetwork APIs to restrict their traffic to a network. |
| 165 | // |
| 166 | // We don't really need to check the permission bits of the fwmark here, as they would've been |
| 167 | // checked at the time the netId was set into the fwmark, but we do so to be consistent. |
| 168 | fwmark.explicitlySelected = true; |
| 169 | mask.explicitlySelected = true; |
| 170 | if (!runIpRuleCommand(action, RULE_PRIORITY_PER_NETWORK_EXPLICIT, table, fwmark.intValue, |
| 171 | mask.intValue, NULL)) { |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 172 | return false; |
| 173 | } |
| 174 | |
| 175 | // An iptables rule to mark incoming packets on a network with the netId of the network. |
| 176 | // |
| 177 | // This is so that the kernel can: |
| 178 | // + Use the right fwmark for (and thus correctly route) replies (e.g.: TCP RST, ICMP errors, |
Sreeram Ramachandran | a481180 | 2014-04-10 12:10:24 -0700 | [diff] [blame] | 179 | // ping replies). |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 180 | // + Mark sockets that accept connections from this interface so that the connection stays on |
| 181 | // the same interface. |
Sreeram Ramachandran | 379bd33 | 2014-04-10 19:58:06 -0700 | [diff] [blame] | 182 | if (modifyIptables) { |
| 183 | action = add ? "-A" : "-D"; |
| 184 | char markString[UINT32_HEX_STRLEN]; |
| 185 | snprintf(markString, sizeof(markString), "0x%x", netId); |
| 186 | if (execIptables(V4V6, "-t", "mangle", action, "INPUT", "-i", interface, "-j", "MARK", |
| 187 | "--set-mark", markString, NULL)) { |
| 188 | return false; |
| 189 | } |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | return true; |
| 193 | } |
| 194 | |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 195 | bool modifyDefaultNetworkRules(const char* interface, Permission permission, const char* action) { |
| 196 | uint32_t table = getRouteTableForInterface(interface); |
| 197 | if (!table) { |
| 198 | return false; |
| 199 | } |
| 200 | |
Sreeram Ramachandran | 122f581 | 2014-05-11 20:29:49 -0700 | [diff] [blame] | 201 | Fwmark fwmark; |
| 202 | fwmark.netId = 0; |
| 203 | fwmark.permission = permission; |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 204 | |
Sreeram Ramachandran | 122f581 | 2014-05-11 20:29:49 -0700 | [diff] [blame] | 205 | Fwmark mask; |
| 206 | mask.netId = FWMARK_NET_ID_MASK; |
| 207 | mask.permission = permission; |
| 208 | |
| 209 | return runIpRuleCommand(action, RULE_PRIORITY_DEFAULT_NETWORK, table, fwmark.intValue, |
| 210 | mask.intValue, NULL); |
Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Sreeram Ramachandran | c921337 | 2014-04-16 12:32:18 -0700 | [diff] [blame] | 213 | bool modifyRoute(const char* interface, const char* destination, const char* nexthop, |
Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 214 | const char* action, RouteController::TableType tableType, unsigned /* uid */) { |
| 215 | uint32_t table = 0; |
| 216 | switch (tableType) { |
| 217 | case RouteController::INTERFACE: { |
| 218 | table = getRouteTableForInterface(interface); |
| 219 | break; |
| 220 | } |
| 221 | case RouteController::LEGACY: { |
| 222 | // TODO: Use the UID to assign a unique table per UID instead of this fixed table. |
| 223 | table = ROUTE_TABLE_LEGACY; |
| 224 | break; |
| 225 | } |
| 226 | case RouteController::PRIVILEGED_LEGACY: { |
| 227 | // TODO: Use the UID to assign a unique table per UID instead of this fixed table. |
| 228 | table = ROUTE_TABLE_PRIVILEGED_LEGACY; |
| 229 | break; |
| 230 | } |
| 231 | } |
Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 232 | if (!table) { |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 233 | return false; |
| 234 | } |
| 235 | |
Sreeram Ramachandran | c921337 | 2014-04-16 12:32:18 -0700 | [diff] [blame] | 236 | if (!runIpRouteCommand(action, table, interface, destination, nexthop)) { |
| 237 | return false; |
| 238 | } |
| 239 | |
| 240 | // If there's no nexthop, this is a directly connected route. Add it to the main table also, to |
| 241 | // let the kernel find it when validating nexthops when global routes are added. Don't do this |
| 242 | // for IPv6, since all directly-connected routes in v6 are link-local and should already be in |
| 243 | // the main table. |
Sreeram Ramachandran | fd6424f | 2014-04-24 16:23:35 -0700 | [diff] [blame] | 244 | // TODO: A failure here typically means that the route already exists in the main table, so we |
| 245 | // ignore it. It's wrong to ignore other kinds of failures, but we have no way to distinguish |
| 246 | // them based on the return status of the 'ip' command. Fix this situation by ignoring errors |
| 247 | // only when action == ADD && error == EEXIST. |
| 248 | if (!nexthop && !strchr(destination, ':')) { |
| 249 | runIpRouteCommand(action, RT_TABLE_MAIN, interface, destination, NULL); |
Sreeram Ramachandran | c921337 | 2014-04-16 12:32:18 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | return true; |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Sreeram Ramachandran | 92b66c4 | 2014-04-15 14:28:55 -0700 | [diff] [blame] | 255 | bool flushRoutes(const char* interface) { |
| 256 | uint32_t table = getRouteTableForInterface(interface); |
| 257 | if (!table) { |
| 258 | return false; |
| 259 | } |
| 260 | |
| 261 | return runIpRouteCommand("flush", table, NULL, NULL, NULL); |
| 262 | } |
| 263 | |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 264 | } // namespace |
| 265 | |
Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 266 | void RouteController::Init() { |
| 267 | // Add a new rule to look up the 'main' table, with the same selectors as the "default network" |
| 268 | // rule, but with a lower priority. Since the default network rule points to a table with a |
| 269 | // default route, the rule we're adding will never be used for normal routing lookups. However, |
| 270 | // the kernel may fall-through to it to find directly-connected routes when it validates that a |
| 271 | // nexthop (in a route being added) is reachable. |
Sreeram Ramachandran | 122f581 | 2014-05-11 20:29:49 -0700 | [diff] [blame] | 272 | Fwmark fwmark; |
| 273 | fwmark.netId = 0; |
| 274 | |
| 275 | Fwmark mask; |
| 276 | mask.netId = FWMARK_NET_ID_MASK; |
| 277 | |
| 278 | runIpRuleCommand(ADD, RULE_PRIORITY_MAIN, RT_TABLE_MAIN, fwmark.intValue, mask.intValue, NULL); |
Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 279 | |
Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 280 | // Add rules to allow lookup of legacy routes. |
| 281 | // |
| 282 | // TODO: Remove these once the kernel supports UID-based routing. Instead, add them on demand |
| 283 | // when routes are added. |
| 284 | fwmark.netId = 0; |
| 285 | mask.netId = 0; |
| 286 | |
| 287 | fwmark.explicitlySelected = false; |
| 288 | mask.explicitlySelected = true; |
| 289 | |
| 290 | runIpRuleCommand(ADD, RULE_PRIORITY_LEGACY, ROUTE_TABLE_LEGACY, fwmark.intValue, mask.intValue, |
| 291 | NULL); |
| 292 | |
| 293 | fwmark.permission = PERMISSION_CONNECTIVITY_INTERNAL; |
| 294 | mask.permission = PERMISSION_CONNECTIVITY_INTERNAL; |
| 295 | |
| 296 | runIpRuleCommand(ADD, RULE_PRIORITY_PRIVILEGED_LEGACY, ROUTE_TABLE_PRIVILEGED_LEGACY, |
| 297 | fwmark.intValue, mask.intValue, NULL); |
| 298 | |
Sreeram Ramachandran | 8fe9c8e | 2014-04-16 12:08:05 -0700 | [diff] [blame] | 299 | // TODO: Uncomment once we are sure everything works. |
| 300 | #if 0 |
| 301 | // Add a rule to preempt the pre-defined "from all lookup main" rule. This ensures that packets |
| 302 | // that are already marked with a specific NetId don't fall-through to the main table. |
| 303 | runIpRuleCommand(ADD, RULE_PRIORITY_UNREACHABLE, 0, 0, 0, NULL); |
| 304 | #endif |
| 305 | } |
| 306 | |
Paul Jensen | ae37e8a | 2014-04-28 10:35:51 -0400 | [diff] [blame] | 307 | bool RouteController::addInterfaceToNetwork(unsigned netId, const char* interface, |
| 308 | Permission permission) { |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 309 | return modifyPerNetworkRules(netId, interface, permission, true, true); |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 310 | } |
| 311 | |
Paul Jensen | ae37e8a | 2014-04-28 10:35:51 -0400 | [diff] [blame] | 312 | bool RouteController::removeInterfaceFromNetwork(unsigned netId, const char* interface, |
| 313 | Permission permission) { |
Sreeram Ramachandran | 92b66c4 | 2014-04-15 14:28:55 -0700 | [diff] [blame] | 314 | return modifyPerNetworkRules(netId, interface, permission, false, true) && |
| 315 | flushRoutes(interface); |
Sreeram Ramachandran | 379bd33 | 2014-04-10 19:58:06 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | bool RouteController::modifyNetworkPermission(unsigned netId, const char* interface, |
| 319 | Permission oldPermission, Permission newPermission) { |
| 320 | // Add the new rules before deleting the old ones, to avoid race conditions. |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 321 | return modifyPerNetworkRules(netId, interface, newPermission, true, false) && |
| 322 | modifyPerNetworkRules(netId, interface, oldPermission, false, false); |
| 323 | } |
| 324 | |
Sreeram Ramachandran | 7260407 | 2014-05-21 13:19:43 -0700 | [diff] [blame] | 325 | bool RouteController::addToDefaultNetwork(const char* interface, Permission permission) { |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 326 | return modifyDefaultNetworkRules(interface, permission, ADD); |
| 327 | } |
| 328 | |
Sreeram Ramachandran | 7260407 | 2014-05-21 13:19:43 -0700 | [diff] [blame] | 329 | bool RouteController::removeFromDefaultNetwork(const char* interface, Permission permission) { |
Sreeram Ramachandran | 9c0d313 | 2014-04-10 20:35:04 -0700 | [diff] [blame] | 330 | return modifyDefaultNetworkRules(interface, permission, DEL); |
Sreeram Ramachandran | 5c181bf | 2014-04-07 14:10:04 -0700 | [diff] [blame] | 331 | } |
Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 332 | |
| 333 | bool RouteController::addRoute(const char* interface, const char* destination, |
Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 334 | const char* nexthop, TableType tableType, unsigned uid) { |
| 335 | return modifyRoute(interface, destination, nexthop, ADD, tableType, uid); |
Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | bool RouteController::removeRoute(const char* interface, const char* destination, |
Sreeram Ramachandran | 38b7af1 | 2014-05-22 14:21:49 -0700 | [diff] [blame] | 339 | const char* nexthop, TableType tableType, unsigned uid) { |
| 340 | return modifyRoute(interface, destination, nexthop, DEL, tableType, uid); |
Sreeram Ramachandran | 7619e1b | 2014-04-15 14:23:08 -0700 | [diff] [blame] | 341 | } |