blob: 8051a736648c563f8aa2d64979eaa03b7ee808d6 [file] [log] [blame]
Jeff Sharkeyd8c64022012-07-13 18:04:07 -07001/*
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 Yamasani390e4ea2015-04-25 19:08:57 -070022enum 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
27enum FirewallType { WHITELIST, BLACKLIST };
Jeff Sharkeyd8c64022012-07-13 18:04:07 -070028
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 */
36class FirewallController {
37public:
38 FirewallController();
39
40 int setupIptablesHooks(void);
41
Amith Yamasani390e4ea2015-04-25 19:08:57 -070042 int enableFirewall(FirewallType);
Jeff Sharkeyd8c64022012-07-13 18:04:07 -070043 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 Yamasani390e4ea2015-04-25 19:08:57 -070059private:
60 FirewallType firewallType;
Jeff Sharkeyd8c64022012-07-13 18:04:07 -070061};
62
63#endif