Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: chromeos/network/firewall_hole.h

Issue 965613002: Open a firewall hole when a TCP server or UDP socket is bound. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add firewall_hole_unittest.cc. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef CHROMEOS_NETWORK_FIREWALL_HOLE_H_
6 #define CHROMEOS_NETWORK_FIREWALL_HOLE_H_
7
8 #include <stdint.h>
9 #include <string>
10
11 #include "base/callback_forward.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "chromeos/chromeos_export.h"
14
15 namespace dbus {
16 class FileDescriptor;
17 }
18
19 namespace chromeos {
20
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 {
24 public:
25 enum class PortType {
26 UDP,
27 TCP,
28 };
29
30 typedef base::Callback<void(scoped_ptr<FirewallHole>)> OpenCallback;
31
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);
36 };
37 typedef scoped_ptr<dbus::FileDescriptor, FileDescriptorDeleter>
38 ScopedFileDescriptor;
39
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,
44 uint16_t port,
45 const std::string& interface,
46 const OpenCallback& callback);
47
48 ~FirewallHole();
49
50 private:
51 static void RequestPortAccess(PortType type,
52 uint16_t port,
53 const std::string& interface,
54 ScopedFileDescriptor lifeline_local,
55 ScopedFileDescriptor lifeline_remote,
56 const OpenCallback& callback);
57
58 static void PortAccessGranted(PortType type,
59 uint16_t port,
60 const std::string& interface,
61 ScopedFileDescriptor lifeline_fd,
62 const FirewallHole::OpenCallback& callback,
63 bool success);
64
65 FirewallHole(PortType type,
66 uint16_t port,
67 const std::string& interface,
68 ScopedFileDescriptor lifeline_fd);
69
70 const PortType type_;
71 const uint16_t port_;
72 const std::string interface_;
73
74 // A file descriptor used by firewalld to track the lifetime of this process.
75 ScopedFileDescriptor lifeline_fd_;
76 };
77
78 } // namespace chromeos
79
80 #endif // CHROMEOS_NETWORK_FIREWALL_HOLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698