Peter Qiu | 326b6cf | 2015-09-02 11:11:42 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2015 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 | // |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 16 | |
| 17 | #ifndef APMANAGER_FIREWALL_MANAGER_H_ |
| 18 | #define APMANAGER_FIREWALL_MANAGER_H_ |
| 19 | |
Peter Qiu | 943cf3a | 2015-02-24 10:59:17 -0800 | [diff] [blame] | 20 | #include <set> |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 21 | #include <string> |
| 22 | |
| 23 | #include <base/macros.h> |
Peter Qiu | 9b2ecc4 | 2015-09-17 14:37:22 -0700 | [diff] [blame] | 24 | #include <base/memory/weak_ptr.h> |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 25 | |
Peter Qiu | 9b2ecc4 | 2015-09-17 14:37:22 -0700 | [diff] [blame] | 26 | #include "apmanager/firewall_proxy_interface.h" |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 27 | |
| 28 | // Class for managing required firewall rules for apmanager. |
| 29 | namespace apmanager { |
| 30 | |
Peter Qiu | be12882 | 2015-10-13 13:55:03 -0700 | [diff] [blame] | 31 | class ControlInterface; |
| 32 | |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 33 | class FirewallManager final { |
| 34 | public: |
| 35 | FirewallManager(); |
| 36 | ~FirewallManager(); |
| 37 | |
Peter Qiu | be12882 | 2015-10-13 13:55:03 -0700 | [diff] [blame] | 38 | void Init(ControlInterface* control_interface); |
Peter Qiu | 943cf3a | 2015-02-24 10:59:17 -0800 | [diff] [blame] | 39 | |
| 40 | // Request/release DHCP port access for the specified interface. |
| 41 | void RequestDHCPPortAccess(const std::string& interface); |
| 42 | void ReleaseDHCPPortAccess(const std::string& interface); |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 43 | |
| 44 | private: |
Peter Qiu | 9b2ecc4 | 2015-09-17 14:37:22 -0700 | [diff] [blame] | 45 | // Invoked when remote firewall service appeared/vanished. |
| 46 | void OnFirewallServiceAppeared(); |
| 47 | void OnFirewallServiceVanished(); |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 48 | |
Peter Qiu | 9b2ecc4 | 2015-09-17 14:37:22 -0700 | [diff] [blame] | 49 | // This is called when a new instance of firewall proxy is detected. Since |
| 50 | // the new instance doesn't have any knowledge of previous port access |
| 51 | // requests, re-issue those requests to the proxy to get in sync. |
Peter Qiu | 943cf3a | 2015-02-24 10:59:17 -0800 | [diff] [blame] | 52 | void RequestAllPortsAccess(); |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 53 | |
Peter Qiu | 9b2ecc4 | 2015-09-17 14:37:22 -0700 | [diff] [blame] | 54 | std::unique_ptr<FirewallProxyInterface> firewall_proxy_; |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 55 | |
Peter Qiu | 943cf3a | 2015-02-24 10:59:17 -0800 | [diff] [blame] | 56 | // List of interfaces with DHCP port access. |
| 57 | std::set<std::string> dhcp_access_interfaces_; |
| 58 | |
Peter Qiu | 9b2ecc4 | 2015-09-17 14:37:22 -0700 | [diff] [blame] | 59 | base::WeakPtrFactory<FirewallManager> weak_factory_{this}; |
Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 60 | DISALLOW_COPY_AND_ASSIGN(FirewallManager); |
| 61 | }; |
| 62 | |
| 63 | } // namespace apmanager |
| 64 | |
| 65 | #endif // APMANAGER_FIREWALL_MANAGER_H_ |