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> |
Chad Brubaker | d261793 | 2013-06-21 15:26:35 -0700 | [diff] [blame] | 23 | #include "UidMarkMap.h" |
Chad Brubaker | 2251c0f | 2013-06-27 17:20:39 -0700 | [diff] [blame] | 24 | #include "NetdConstants.h" |
Jaime A Lopez-Sollano | d14fd4f | 2012-01-11 16:29:28 -0800 | [diff] [blame] | 25 | |
| 26 | #ifndef IFNAMSIZ |
| 27 | #define IFNAMSIZ 16 |
| 28 | #endif |
| 29 | |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 30 | static const int INTERFACES_TRACKED = 10; |
| 31 | static const int BASE_TABLE_NUMBER = 60; |
| 32 | static int MAX_TABLE_NUMBER = BASE_TABLE_NUMBER + INTERFACES_TRACKED; |
Chad Brubaker | 2251c0f | 2013-06-27 17:20:39 -0700 | [diff] [blame] | 33 | static const int PROTECT_MARK = 0x1; |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 34 | |
| 35 | class SecondaryTableController { |
| 36 | |
| 37 | public: |
Chad Brubaker | d261793 | 2013-06-21 15:26:35 -0700 | [diff] [blame] | 38 | SecondaryTableController(UidMarkMap *map); |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 39 | virtual ~SecondaryTableController(); |
| 40 | |
| 41 | int addRoute(SocketClient *cli, char *iface, char *dest, int prefixLen, char *gateway); |
| 42 | int removeRoute(SocketClient *cli, char *iface, char *dest, int prefixLen, char *gateway); |
| 43 | int findTableNumber(const char *iface); |
Robert Greenwalt | c462177 | 2012-01-31 12:46:45 -0800 | [diff] [blame] | 44 | int modifyFromRule(int tableIndex, const char *action, const char *addr); |
| 45 | int modifyLocalRoute(int tableIndex, const char *action, const char *iface, const char *addr); |
Chad Brubaker | 8830b94 | 2013-06-12 10:51:55 -0700 | [diff] [blame] | 46 | int addUidRule(const char *iface, int uid_start, int uid_end); |
| 47 | int removeUidRule(const char *iface, int uid_start, int uid_end); |
Chad Brubaker | 7a6ce4b | 2013-06-06 21:42:53 -0700 | [diff] [blame] | 48 | int addFwmarkRule(const char *iface); |
| 49 | int removeFwmarkRule(const char *iface); |
Chad Brubaker | 2251c0f | 2013-06-27 17:20:39 -0700 | [diff] [blame] | 50 | int addFwmarkRoute(const char* iface, const char *dest, int prefix); |
| 51 | int removeFwmarkRoute(const char* iface, const char *dest, int prefix); |
Chad Brubaker | 4a94609 | 2013-07-10 12:08:08 -0700 | [diff] [blame] | 52 | int addHostExemption(const char *host); |
| 53 | int removeHostExemption(const char *host); |
Chad Brubaker | da7df7c | 2013-07-11 12:05:39 -0700 | [diff] [blame^] | 54 | void getUidMark(SocketClient *cli, int uid); |
| 55 | void getProtectMark(SocketClient *cli); |
Chad Brubaker | 2251c0f | 2013-06-27 17:20:39 -0700 | [diff] [blame] | 56 | |
| 57 | int setupIptablesHooks(); |
Chad Brubaker | 9a50889 | 2013-05-31 20:51:46 -0700 | [diff] [blame] | 58 | |
| 59 | static const char* LOCAL_MANGLE_OUTPUT; |
Chad Brubaker | 4a94609 | 2013-07-10 12:08:08 -0700 | [diff] [blame] | 60 | static const char* LOCAL_MANGLE_EXEMPT; |
Chad Brubaker | 2251c0f | 2013-06-27 17:20:39 -0700 | [diff] [blame] | 61 | static const char* LOCAL_MANGLE_IFACE_FORMAT; |
Chad Brubaker | 7a6ce4b | 2013-06-06 21:42:53 -0700 | [diff] [blame] | 62 | static const char* LOCAL_NAT_POSTROUTING; |
Chad Brubaker | 2251c0f | 2013-06-27 17:20:39 -0700 | [diff] [blame] | 63 | static const char* LOCAL_FILTER_OUTPUT; |
Chad Brubaker | 9a50889 | 2013-05-31 20:51:46 -0700 | [diff] [blame] | 64 | |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 65 | |
| 66 | private: |
Chad Brubaker | d261793 | 2013-06-21 15:26:35 -0700 | [diff] [blame] | 67 | UidMarkMap *mUidMarkMap; |
| 68 | |
Chad Brubaker | 8830b94 | 2013-06-12 10:51:55 -0700 | [diff] [blame] | 69 | int setUidRule(const char* iface, int uid_start, int uid_end, bool add); |
Chad Brubaker | 7a6ce4b | 2013-06-06 21:42:53 -0700 | [diff] [blame] | 70 | int setFwmarkRule(const char *iface, bool add); |
Chad Brubaker | 2251c0f | 2013-06-27 17:20:39 -0700 | [diff] [blame] | 71 | int setFwmarkRoute(const char* iface, const char *dest, int prefix, bool add); |
Chad Brubaker | 4a94609 | 2013-07-10 12:08:08 -0700 | [diff] [blame] | 72 | int setHostExemption(const char *host, bool add); |
Robert Greenwalt | c462177 | 2012-01-31 12:46:45 -0800 | [diff] [blame] | 73 | 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] | 74 | char *gateway, int tableIndex); |
| 75 | |
Jaime A Lopez-Sollano | d14fd4f | 2012-01-11 16:29:28 -0800 | [diff] [blame] | 76 | char mInterfaceTable[INTERFACES_TRACKED][IFNAMSIZ + 1]; |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 77 | int mInterfaceRuleCount[INTERFACES_TRACKED]; |
Robert Greenwalt | c462177 | 2012-01-31 12:46:45 -0800 | [diff] [blame] | 78 | void modifyRuleCount(int tableIndex, const char *action); |
| 79 | int verifyTableIndex(int tableIndex); |
| 80 | const char *getVersion(const char *addr); |
Chad Brubaker | 2251c0f | 2013-06-27 17:20:39 -0700 | [diff] [blame] | 81 | IptablesTarget getIptablesTarget(const char *addr); |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 82 | |
Rom Lemarchand | 001f0a4 | 2013-01-31 12:41:03 -0800 | [diff] [blame] | 83 | int runCmd(int argc, const char **argv); |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | #endif |