OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 void AddRule(bool allow, FirewallProtocol p = FP_ANY, | 51 void AddRule(bool allow, FirewallProtocol p = FP_ANY, |
52 FirewallDirection d = FD_ANY, | 52 FirewallDirection d = FD_ANY, |
53 const SocketAddress& addr = SocketAddress()); | 53 const SocketAddress& addr = SocketAddress()); |
54 void AddRule(bool allow, FirewallProtocol p, | 54 void AddRule(bool allow, FirewallProtocol p, |
55 const SocketAddress& src, const SocketAddress& dst); | 55 const SocketAddress& src, const SocketAddress& dst); |
56 void ClearRules(); | 56 void ClearRules(); |
57 | 57 |
58 bool Check(FirewallProtocol p, | 58 bool Check(FirewallProtocol p, |
59 const SocketAddress& src, const SocketAddress& dst); | 59 const SocketAddress& src, const SocketAddress& dst); |
60 | 60 |
| 61 // Set the IP addresses for which Bind will fail. By default this list is |
| 62 // empty. This can be used to simulate a real OS that refuses to bind to |
| 63 // addresses under various circumstances. |
| 64 // |
| 65 // No matter how many addresses are added (including INADDR_ANY), the server |
| 66 // will still allow creating outgoing TCP connections, since they don't |
| 67 // require explicitly binding a socket. |
| 68 void SetUnbindableIps(const std::vector<rtc::IPAddress>& unbindable_ips); |
| 69 bool IsBindableIp(const rtc::IPAddress& ip); |
| 70 |
61 Socket* CreateSocket(int type) override; | 71 Socket* CreateSocket(int type) override; |
62 Socket* CreateSocket(int family, int type) override; | 72 Socket* CreateSocket(int family, int type) override; |
63 | 73 |
64 AsyncSocket* CreateAsyncSocket(int type) override; | 74 AsyncSocket* CreateAsyncSocket(int type) override; |
65 AsyncSocket* CreateAsyncSocket(int family, int type) override; | 75 AsyncSocket* CreateAsyncSocket(int family, int type) override; |
66 | 76 |
67 void SetMessageQueue(MessageQueue* queue) override; | 77 void SetMessageQueue(MessageQueue* queue) override; |
68 bool Wait(int cms, bool process_io) override; | 78 bool Wait(int cms, bool process_io) override; |
69 void WakeUp() override; | 79 void WakeUp() override; |
70 | 80 |
71 Socket * WrapSocket(Socket * sock, int type); | 81 Socket * WrapSocket(Socket * sock, int type); |
72 AsyncSocket * WrapSocket(AsyncSocket * sock, int type); | 82 AsyncSocket * WrapSocket(AsyncSocket * sock, int type); |
73 | 83 |
74 private: | 84 private: |
75 SocketServer * server_; | 85 SocketServer * server_; |
76 FirewallManager * manager_; | 86 FirewallManager * manager_; |
77 CriticalSection crit_; | 87 CriticalSection crit_; |
78 struct Rule { | 88 struct Rule { |
79 bool allow; | 89 bool allow; |
80 FirewallProtocol p; | 90 FirewallProtocol p; |
81 FirewallDirection d; | 91 FirewallDirection d; |
82 SocketAddress src; | 92 SocketAddress src; |
83 SocketAddress dst; | 93 SocketAddress dst; |
84 }; | 94 }; |
85 std::vector<Rule> rules_; | 95 std::vector<Rule> rules_; |
| 96 std::vector<rtc::IPAddress> unbindable_ips_; |
86 bool should_delete_server_; | 97 bool should_delete_server_; |
87 bool udp_sockets_enabled_; | 98 bool udp_sockets_enabled_; |
88 bool tcp_sockets_enabled_; | 99 bool tcp_sockets_enabled_; |
89 bool tcp_listen_enabled_; | 100 bool tcp_listen_enabled_; |
90 }; | 101 }; |
91 | 102 |
92 // FirewallManager allows you to manage firewalls in multiple threads together | 103 // FirewallManager allows you to manage firewalls in multiple threads together |
93 | 104 |
94 class FirewallManager { | 105 class FirewallManager { |
95 public: | 106 public: |
96 FirewallManager(); | 107 FirewallManager(); |
97 ~FirewallManager(); | 108 ~FirewallManager(); |
98 | 109 |
99 void AddServer(FirewallSocketServer * server); | 110 void AddServer(FirewallSocketServer * server); |
100 void RemoveServer(FirewallSocketServer * server); | 111 void RemoveServer(FirewallSocketServer * server); |
101 | 112 |
102 void AddRule(bool allow, FirewallProtocol p = FP_ANY, | 113 void AddRule(bool allow, FirewallProtocol p = FP_ANY, |
103 FirewallDirection d = FD_ANY, | 114 FirewallDirection d = FD_ANY, |
104 const SocketAddress& addr = SocketAddress()); | 115 const SocketAddress& addr = SocketAddress()); |
105 void ClearRules(); | 116 void ClearRules(); |
106 | 117 |
107 private: | 118 private: |
108 CriticalSection crit_; | 119 CriticalSection crit_; |
109 std::vector<FirewallSocketServer *> servers_; | 120 std::vector<FirewallSocketServer *> servers_; |
110 }; | 121 }; |
111 | 122 |
112 } // namespace rtc | 123 } // namespace rtc |
113 | 124 |
114 #endif // WEBRTC_BASE_FIREWALLSOCKETSERVER_H_ | 125 #endif // WEBRTC_BASE_FIREWALLSOCKETSERVER_H_ |
OLD | NEW |