San Mehat | 9ff78fb | 2010-01-19 12:59:15 -0800 | [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 _NAT_CONTROLLER_H |
| 18 | #define _NAT_CONTROLLER_H |
| 19 | |
| 20 | #include <linux/in.h> |
JP Abgrall | f3cc83f | 2013-09-11 20:01:59 -0700 | [diff] [blame] | 21 | #include <list> |
Paul Jensen | 17de4f0 | 2014-04-04 00:04:39 -0400 | [diff] [blame] | 22 | #include <string> |
San Mehat | 9ff78fb | 2010-01-19 12:59:15 -0800 | [diff] [blame] | 23 | |
Lorenzo Colitti | 4fcb4a0 | 2017-02-03 14:08:37 +0900 | [diff] [blame] | 24 | #include "NetdConstants.h" |
| 25 | |
San Mehat | 9ff78fb | 2010-01-19 12:59:15 -0800 | [diff] [blame] | 26 | class NatController { |
San Mehat | 9ff78fb | 2010-01-19 12:59:15 -0800 | [diff] [blame] | 27 | public: |
Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 28 | NatController(); |
San Mehat | 9ff78fb | 2010-01-19 12:59:15 -0800 | [diff] [blame] | 29 | virtual ~NatController(); |
| 30 | |
Sreeram Ramachandran | 87475a1 | 2014-07-15 16:20:28 -0700 | [diff] [blame] | 31 | int enableNat(const char* intIface, const char* extIface); |
| 32 | int disableNat(const char* intIface, const char* extIface); |
JP Abgrall | 0031cea | 2012-04-17 16:38:23 -0700 | [diff] [blame] | 33 | int setupIptablesHooks(); |
San Mehat | 9ff78fb | 2010-01-19 12:59:15 -0800 | [diff] [blame] | 34 | |
Jeff Sharkey | 8e188ed | 2012-07-12 18:32:03 -0700 | [diff] [blame] | 35 | static const char* LOCAL_FORWARD; |
Lorenzo Colitti | e8164dd | 2014-10-02 20:46:23 +0900 | [diff] [blame] | 36 | static const char* LOCAL_MANGLE_FORWARD; |
Jeff Sharkey | 8e188ed | 2012-07-12 18:32:03 -0700 | [diff] [blame] | 37 | static const char* LOCAL_NAT_POSTROUTING; |
Lorenzo Colitti | 8917e45 | 2016-08-01 16:47:50 +0900 | [diff] [blame] | 38 | static const char* LOCAL_RAW_PREROUTING; |
JP Abgrall | baeccc4 | 2013-06-25 09:44:10 -0700 | [diff] [blame] | 39 | static const char* LOCAL_TETHER_COUNTERS_CHAIN; |
Jeff Sharkey | 8e188ed | 2012-07-12 18:32:03 -0700 | [diff] [blame] | 40 | |
JP Abgrall | f3cc83f | 2013-09-11 20:01:59 -0700 | [diff] [blame] | 41 | // List of strings of interface pairs. |
| 42 | std::list<std::string> ifacePairList; |
| 43 | |
San Mehat | 9ff78fb | 2010-01-19 12:59:15 -0800 | [diff] [blame] | 44 | private: |
Robert Greenwalt | 1caafe6 | 2010-03-24 15:43:00 -0700 | [diff] [blame] | 45 | int natCount; |
| 46 | |
JP Abgrall | f3cc83f | 2013-09-11 20:01:59 -0700 | [diff] [blame] | 47 | bool checkTetherCountingRuleExist(const char *pair_name); |
| 48 | |
San Mehat | 9ff78fb | 2010-01-19 12:59:15 -0800 | [diff] [blame] | 49 | int setDefaults(); |
Rom Lemarchand | 001f0a4 | 2013-01-31 12:41:03 -0800 | [diff] [blame] | 50 | int runCmd(int argc, const char **argv); |
Robert Greenwalt | fc97b82 | 2011-11-02 16:48:36 -0700 | [diff] [blame] | 51 | int setForwardRules(bool set, const char *intIface, const char *extIface); |
JP Abgrall | baeccc4 | 2013-06-25 09:44:10 -0700 | [diff] [blame] | 52 | int setTetherCountingRules(bool add, const char *intIface, const char *extIface); |
Lorenzo Colitti | 8e1cee9 | 2016-07-09 14:24:08 +0900 | [diff] [blame] | 53 | |
| 54 | // For testing. |
| 55 | friend class NatControllerTest; |
| 56 | static int (*execFunction)(int, char **, int *, bool, bool); |
Lorenzo Colitti | 4fcb4a0 | 2017-02-03 14:08:37 +0900 | [diff] [blame] | 57 | static int (*iptablesRestoreFunction)(IptablesTarget, const std::string&); |
San Mehat | 9ff78fb | 2010-01-19 12:59:15 -0800 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | #endif |