Jeff Sharkey | d8c6402 | 2012-07-13 18:04:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 _FIREWALL_CONTROLLER_H |
| 18 | #define _FIREWALL_CONTROLLER_H |
| 19 | |
| 20 | #include <string> |
| 21 | |
Amith Yamasani | 390e4ea | 2015-04-25 19:08:57 -0700 | [diff] [blame^] | 22 | enum FirewallRule { DENY, ALLOW }; |
| 23 | |
| 24 | // WHITELIST means the firewall denies all by default, uids must be explicitly ALLOWed |
| 25 | // BLACKLIST means the firewall allows all by default, uids must be explicitly DENYed |
| 26 | |
| 27 | enum FirewallType { WHITELIST, BLACKLIST }; |
Jeff Sharkey | d8c6402 | 2012-07-13 18:04:07 -0700 | [diff] [blame] | 28 | |
| 29 | #define PROTOCOL_TCP 6 |
| 30 | #define PROTOCOL_UDP 17 |
| 31 | |
| 32 | /* |
| 33 | * Simple firewall that drops all packets except those matching explicitly |
| 34 | * defined ALLOW rules. |
| 35 | */ |
| 36 | class FirewallController { |
| 37 | public: |
| 38 | FirewallController(); |
| 39 | |
| 40 | int setupIptablesHooks(void); |
| 41 | |
Amith Yamasani | 390e4ea | 2015-04-25 19:08:57 -0700 | [diff] [blame^] | 42 | int enableFirewall(FirewallType); |
Jeff Sharkey | d8c6402 | 2012-07-13 18:04:07 -0700 | [diff] [blame] | 43 | int disableFirewall(void); |
| 44 | int isFirewallEnabled(void); |
| 45 | |
| 46 | /* Match traffic going in/out over the given iface. */ |
| 47 | int setInterfaceRule(const char*, FirewallRule); |
| 48 | /* Match traffic coming-in-to or going-out-from given address. */ |
| 49 | int setEgressSourceRule(const char*, FirewallRule); |
| 50 | /* Match traffic coming-in-from or going-out-to given address, port, and protocol. */ |
| 51 | int setEgressDestRule(const char*, int, int, FirewallRule); |
| 52 | /* Match traffic owned by given UID. */ |
| 53 | int setUidRule(int, FirewallRule); |
| 54 | |
| 55 | static const char* LOCAL_INPUT; |
| 56 | static const char* LOCAL_OUTPUT; |
| 57 | static const char* LOCAL_FORWARD; |
| 58 | |
Amith Yamasani | 390e4ea | 2015-04-25 19:08:57 -0700 | [diff] [blame^] | 59 | private: |
| 60 | FirewallType firewallType; |
Jeff Sharkey | d8c6402 | 2012-07-13 18:04:07 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | #endif |