blob: 6e5b43d3cf506afcd8447e8559bf6b715a077ef2 [file] [log] [blame]
Peter Qiu326b6cf2015-09-02 11:11:42 -07001//
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 Qiu1810c012015-02-05 14:35:41 -080016
17#ifndef APMANAGER_FIREWALL_MANAGER_H_
18#define APMANAGER_FIREWALL_MANAGER_H_
19
Peter Qiu943cf3a2015-02-24 10:59:17 -080020#include <set>
Peter Qiu1810c012015-02-05 14:35:41 -080021#include <string>
22
23#include <base/macros.h>
Peter Qiu9b2ecc42015-09-17 14:37:22 -070024#include <base/memory/weak_ptr.h>
Peter Qiu1810c012015-02-05 14:35:41 -080025
Peter Qiu9b2ecc42015-09-17 14:37:22 -070026#include "apmanager/firewall_proxy_interface.h"
Peter Qiu1810c012015-02-05 14:35:41 -080027
28// Class for managing required firewall rules for apmanager.
29namespace apmanager {
30
Peter Qiube128822015-10-13 13:55:03 -070031class ControlInterface;
32
Peter Qiu1810c012015-02-05 14:35:41 -080033class FirewallManager final {
34 public:
35 FirewallManager();
36 ~FirewallManager();
37
Peter Qiube128822015-10-13 13:55:03 -070038 void Init(ControlInterface* control_interface);
Peter Qiu943cf3a2015-02-24 10:59:17 -080039
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 Qiu1810c012015-02-05 14:35:41 -080043
44 private:
Peter Qiu9b2ecc42015-09-17 14:37:22 -070045 // Invoked when remote firewall service appeared/vanished.
46 void OnFirewallServiceAppeared();
47 void OnFirewallServiceVanished();
Peter Qiu1810c012015-02-05 14:35:41 -080048
Peter Qiu9b2ecc42015-09-17 14:37:22 -070049 // 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 Qiu943cf3a2015-02-24 10:59:17 -080052 void RequestAllPortsAccess();
Peter Qiu1810c012015-02-05 14:35:41 -080053
Peter Qiu9b2ecc42015-09-17 14:37:22 -070054 std::unique_ptr<FirewallProxyInterface> firewall_proxy_;
Peter Qiu1810c012015-02-05 14:35:41 -080055
Peter Qiu943cf3a2015-02-24 10:59:17 -080056 // List of interfaces with DHCP port access.
57 std::set<std::string> dhcp_access_interfaces_;
58
Peter Qiu9b2ecc42015-09-17 14:37:22 -070059 base::WeakPtrFactory<FirewallManager> weak_factory_{this};
Peter Qiu1810c012015-02-05 14:35:41 -080060 DISALLOW_COPY_AND_ASSIGN(FirewallManager);
61};
62
63} // namespace apmanager
64
65#endif // APMANAGER_FIREWALL_MANAGER_H_