Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | #ifndef _SECONDARY_TABLE_CONTROLLER_H |
| 18 | #define _SECONDARY_TABLE_CONTROLLER_H |
| 19 | |
| 20 | #include <sysutils/FrameworkListener.h> |
| 21 | |
Elliott Hughes | 970274a | 2012-09-11 18:56:36 -0700 | [diff] [blame] | 22 | #include <net/if.h> |
Jaime A Lopez-Sollano | d14fd4f | 2012-01-11 16:29:28 -0800 | [diff] [blame] | 23 | |
| 24 | #ifndef IFNAMSIZ |
| 25 | #define IFNAMSIZ 16 |
| 26 | #endif |
| 27 | |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 28 | static const int INTERFACES_TRACKED = 10; |
| 29 | static const int BASE_TABLE_NUMBER = 60; |
| 30 | static int MAX_TABLE_NUMBER = BASE_TABLE_NUMBER + INTERFACES_TRACKED; |
| 31 | |
| 32 | class SecondaryTableController { |
| 33 | |
| 34 | public: |
| 35 | SecondaryTableController(); |
| 36 | virtual ~SecondaryTableController(); |
| 37 | |
| 38 | int addRoute(SocketClient *cli, char *iface, char *dest, int prefixLen, char *gateway); |
| 39 | int removeRoute(SocketClient *cli, char *iface, char *dest, int prefixLen, char *gateway); |
| 40 | int findTableNumber(const char *iface); |
Robert Greenwalt | c462177 | 2012-01-31 12:46:45 -0800 | [diff] [blame] | 41 | int modifyFromRule(int tableIndex, const char *action, const char *addr); |
| 42 | int modifyLocalRoute(int tableIndex, const char *action, const char *iface, const char *addr); |
Chad Brubaker | 9a50889 | 2013-05-31 20:51:46 -0700 | [diff] [blame] | 43 | int addUidRule(const char *iface, const char *uid); |
| 44 | int removeUidRule(const char *iface, const char *uid); |
Chad Brubaker | 7a6ce4b | 2013-06-06 21:42:53 -0700 | [diff] [blame^] | 45 | int addFwmarkRule(const char *iface); |
| 46 | int removeFwmarkRule(const char *iface); |
Chad Brubaker | 9a50889 | 2013-05-31 20:51:46 -0700 | [diff] [blame] | 47 | |
| 48 | static const char* LOCAL_MANGLE_OUTPUT; |
Chad Brubaker | 7a6ce4b | 2013-06-06 21:42:53 -0700 | [diff] [blame^] | 49 | static const char* LOCAL_NAT_POSTROUTING; |
Chad Brubaker | 9a50889 | 2013-05-31 20:51:46 -0700 | [diff] [blame] | 50 | |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 51 | |
| 52 | private: |
Chad Brubaker | 9a50889 | 2013-05-31 20:51:46 -0700 | [diff] [blame] | 53 | int setUidRule(const char* iface, const char *uid, bool add); |
Chad Brubaker | 7a6ce4b | 2013-06-06 21:42:53 -0700 | [diff] [blame^] | 54 | int setFwmarkRule(const char *iface, bool add); |
Robert Greenwalt | c462177 | 2012-01-31 12:46:45 -0800 | [diff] [blame] | 55 | int modifyRoute(SocketClient *cli, const char *action, char *iface, char *dest, int prefix, |
Robert Greenwalt | 063af32 | 2011-11-18 15:32:13 -0800 | [diff] [blame] | 56 | char *gateway, int tableIndex); |
| 57 | |
Jaime A Lopez-Sollano | d14fd4f | 2012-01-11 16:29:28 -0800 | [diff] [blame] | 58 | char mInterfaceTable[INTERFACES_TRACKED][IFNAMSIZ + 1]; |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 59 | int mInterfaceRuleCount[INTERFACES_TRACKED]; |
Robert Greenwalt | c462177 | 2012-01-31 12:46:45 -0800 | [diff] [blame] | 60 | void modifyRuleCount(int tableIndex, const char *action); |
| 61 | int verifyTableIndex(int tableIndex); |
| 62 | const char *getVersion(const char *addr); |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 63 | |
Rom Lemarchand | 001f0a4 | 2013-01-31 12:41:03 -0800 | [diff] [blame] | 64 | int runCmd(int argc, const char **argv); |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | #endif |