blob: 401aca433fcd59fd510577a023ba083b52ca0f31 [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/ref_counted.h>
25#include <base/memory/weak_ptr.h>
26#include <dbus/bus.h>
Peter Qiu1810c012015-02-05 14:35:41 -080027
Peter Qiu9b2ecc42015-09-17 14:37:22 -070028#include "apmanager/firewall_proxy_interface.h"
Peter Qiu1810c012015-02-05 14:35:41 -080029
30// Class for managing required firewall rules for apmanager.
31namespace apmanager {
32
33class FirewallManager final {
34 public:
35 FirewallManager();
36 ~FirewallManager();
37
Peter Qiu943cf3a2015-02-24 10:59:17 -080038 void Init(const scoped_refptr<dbus::Bus>& bus);
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 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_