1 // Copyright 2015 The Chromium 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.
5 #ifndef CHROMEOS_NETWORK_FIREWALL_HOLE_H_
6 #define CHROMEOS_NETWORK_FIREWALL_HOLE_H_
11 #include "base/callback_forward.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chromeos/chromeos_export.h"
21 // This class works with the Chrome OS permission broker to open a port in the
22 // system firewall. It is closed on destruction.
23 class CHROMEOS_EXPORT FirewallHole
{
30 typedef base::Callback
<void(scoped_ptr
<FirewallHole
>)> OpenCallback
;
32 // This provides a simple way to pass around file descriptors since they must
33 // be closed on a thread that is allowed to perform I/O.
34 struct FileDescriptorDeleter
{
35 void CHROMEOS_EXPORT
operator()(dbus::FileDescriptor
* fd
);
37 typedef scoped_ptr
<dbus::FileDescriptor
, FileDescriptorDeleter
>
40 // Opens a port on the system firewall for the given network interface (or all
41 // interfaces if |interface| is ""). The hole will be closed when the object
42 // provided to the callback is destroyed.
43 static void Open(PortType type
,
45 const std::string
& interface
,
46 const OpenCallback
& callback
);
51 static void RequestPortAccess(PortType type
,
53 const std::string
& interface
,
54 ScopedFileDescriptor lifeline_local
,
55 ScopedFileDescriptor lifeline_remote
,
56 const OpenCallback
& callback
);
58 static void PortAccessGranted(PortType type
,
60 const std::string
& interface
,
61 ScopedFileDescriptor lifeline_fd
,
62 const FirewallHole::OpenCallback
& callback
,
65 FirewallHole(PortType type
,
67 const std::string
& interface
,
68 ScopedFileDescriptor lifeline_fd
);
72 const std::string interface_
;
74 // A file descriptor used by firewalld to track the lifetime of this process.
75 ScopedFileDescriptor lifeline_fd_
;
78 } // namespace chromeos
80 #endif // CHROMEOS_NETWORK_FIREWALL_HOLE_H_