Peter Qiu | 1810c01 | 2015-02-05 14:35:41 -0800 | [diff] [blame] | 1 | // Copyright 2015 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef APMANAGER_FIREWALL_MANAGER_H_ |
| 6 | #define APMANAGER_FIREWALL_MANAGER_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include <base/macros.h> |
| 11 | #include <base/memory/scoped_ptr.h> |
| 12 | |
| 13 | #include "permission_broker/dbus-proxies.h" |
| 14 | |
| 15 | // Class for managing required firewall rules for apmanager. |
| 16 | namespace apmanager { |
| 17 | |
| 18 | class FirewallManager final { |
| 19 | public: |
| 20 | FirewallManager(); |
| 21 | ~FirewallManager(); |
| 22 | |
| 23 | void Start(const scoped_refptr<dbus::Bus>& bus); |
| 24 | |
| 25 | private: |
| 26 | // Setup lifeline pipe to allow the remote firewall server |
| 27 | // (permission_broker) to monitor this process, so it can remove the firewall |
| 28 | // rules in case this process crashes. |
| 29 | bool SetupLifelinePipe(); |
| 30 | |
| 31 | void OnServiceAvailable(bool service_available); |
| 32 | void OnServiceNameChanged(const std::string& old_owner, |
| 33 | const std::string& new_owner); |
| 34 | |
| 35 | // Add all required firewall rules for apmanager. |
| 36 | void AddFirewallRules(); |
| 37 | void AddUdpPortRule(uint16_t port); |
| 38 | |
| 39 | // DBus proxy for shill manager. |
| 40 | std::unique_ptr<org::chromium::PermissionBrokerProxy> |
| 41 | permission_broker_proxy_; |
| 42 | // File descriptors for the two end of the pipe use for communicating with |
| 43 | // remote firewall server (permission_broker), where the remote firewall |
| 44 | // server will use the read end of the pipe to detect when this process exits. |
| 45 | int lifeline_read_fd_; |
| 46 | int lifeline_write_fd_; |
| 47 | |
| 48 | DISALLOW_COPY_AND_ASSIGN(FirewallManager); |
| 49 | }; |
| 50 | |
| 51 | } // namespace apmanager |
| 52 | |
| 53 | #endif // APMANAGER_FIREWALL_MANAGER_H_ |