@@ -17,32 +17,38 @@ pub enum RedirType {
1717 /// For not supported platforms
1818 NotSupported ,
1919
20- /// For Linux-like systems' Netfilter `REDIRECT`. Only for TCP connections.
21- /// This is supported from Linux 2.4 Kernel. Document: <https://www.netfilter.org/documentation/index.html#documentation-howto>
22- /// NOTE: Filter rule `REDIRECT` can only be applied to TCP connections.
20+ /// For Linux-like systems' Netfilter `REDIRECT`. Only for TCP connections.
21+ ///
22+ /// This is supported from Linux 2.4 Kernel. Document: <https://www.netfilter.org/documentation/index.html#documentation-howto>
23+ ///
24+ /// NOTE: Filter rule `REDIRECT` can only be applied to TCP connections.
2325 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
2426 Redirect ,
2527
26- /// For Linux-like systems' Netfilter TPROXY rule.
27- /// NOTE: Filter rule `TPROXY` can be applied to TCP and UDP connections.
28+ /// For Linux-like systems' Netfilter TPROXY rule.
29+ ///
30+ /// NOTE: Filter rule `TPROXY` can be applied to TCP and UDP connections.
2831 #[ cfg( any( target_os = "linux" , target_os = "android" ) ) ]
2932 TProxy ,
3033
31- /// Packet Filter (pf)
32- /// Supported by OpenBSD 3.0+, FreeBSD 5.3+, NetBSD 3.0+, Solaris 11.3+, macOS 10.7+, iOS, QNX
33- /// Document: <https://www.freebsd.org/doc/handbook/firewalls-pf.html>
34+ /// Packet Filter (pf)
35+ ///
36+ /// Supported by OpenBSD 3.0+, FreeBSD 5.3+, NetBSD 3.0+, Solaris 11.3+, macOS 10.7+, iOS, QNX
37+ ///
38+ /// Document: <https://www.freebsd.org/doc/handbook/firewalls-pf.html>
3439 #[ cfg( any(
35- target_os = "openbsd" ,
3640 target_os = "freebsd" ,
37- target_os = "netbsd " ,
41+ target_os = "openbsd " ,
3842 target_os = "macos" ,
3943 target_os = "ios"
4044 ) ) ]
4145 PacketFilter ,
4246
43- /// IPFW
44- /// Supported by FreeBSD, macOS 10.6- (Have been removed completely on macOS 10.10)
45- /// Document: https://www.freebsd.org/doc/handbook/firewalls-ipfw.html
47+ /// IPFW
48+ ///
49+ /// Supported by FreeBSD, macOS 10.6- (Have been removed completely on macOS 10.10)
50+ ///
51+ /// Document: https://www.freebsd.org/doc/handbook/firewalls-ipfw.html
4652 #[ cfg( any( target_os = "freebsd" , target_os = "macos" , target_os = "ios" ) ) ]
4753 IpFirewall ,
4854}
@@ -56,46 +62,127 @@ impl RedirType {
5662 }
5763
5864 /// Available TCP transparent proxy types
65+ #[ doc( hidden) ]
5966 pub fn tcp_available_types( ) -> & ' static [ & ' static str ] {
6067 const AVAILABLE_TYPES : & [ & str ] = & [ RedirType :: Redirect . name( ) , RedirType :: TProxy . name( ) ] ;
6168 AVAILABLE_TYPES
6269 }
63- } else if #[ cfg( any( target_os = "openbsd" , target_os = "freebsd" ) ) ] {
70+
71+ /// Default UDP transparent proxy solution on this platform
72+ pub const fn udp_default( ) -> RedirType {
73+ RedirType :: TProxy
74+ }
75+
76+ /// Available UDP transparent proxy types
77+ #[ doc( hidden) ]
78+ pub fn udp_available_types( ) -> & ' static [ & ' static str ] {
79+ const AVAILABLE_TYPES : & [ & str ] = & [ RedirType :: TProxy . name( ) ] ;
80+ AVAILABLE_TYPES
81+ }
82+ } else if #[ cfg( any( target_os = "freebsd" ) ) ] {
6483 /// Default TCP transparent proxy solution on this platform
6584 pub fn tcp_default( ) -> RedirType {
6685 RedirType :: PacketFilter
6786 }
6887
6988 /// Available TCP transparent proxy types
89+ #[ doc( hidden) ]
7090 pub fn tcp_available_types( ) -> & ' static [ & ' static str ] {
7191 const AVAILABLE_TYPES : & [ & str ] = & [ RedirType :: PacketFilter . name( ) , RedirType :: IpFirewall . name( ) ] ;
7292 AVAILABLE_TYPES
7393 }
74- } else if #[ cfg( any( target_os = "netbsd" , target_os = "macos" , target_os = "ios" ) ) ] {
94+
95+ /// Default UDP transparent proxy solution on this platform
96+ pub fn udp_default( ) -> RedirType {
97+ RedirType :: PacketFilter
98+ }
99+
100+ /// Available UDP transparent proxy types
101+ #[ doc( hidden) ]
102+ pub const fn udp_available_types( ) -> & ' static [ & ' static str ] {
103+ const AVAILABLE_TYPES : & [ & str ] = & [ RedirType :: PacketFilter . name( ) , RedirType :: IpFirewall . name( ) ] ;
104+ AVAILABLE_TYPES
105+ }
106+ } else if #[ cfg( target_os = "openbsd" ) ] {
75107 /// Default TCP transparent proxy solution on this platform
76108 pub fn tcp_default( ) -> RedirType {
77109 RedirType :: PacketFilter
78110 }
79111
80112 /// Available TCP transparent proxy types
113+ #[ doc( hidden) ]
114+ pub fn tcp_available_types( ) -> & ' static [ & ' static str ] {
115+ const AVAILABLE_TYPES : & [ & str ] = & [ RedirType :: PacketFilter . name( ) ] ;
116+ AVAILABLE_TYPES
117+ }
118+
119+ /// Default UDP transparent proxy solution on this platform
120+ pub fn udp_default( ) -> RedirType {
121+ RedirType :: PacketFilter
122+ }
123+
124+ /// Available UDP transparent proxy types
125+ #[ doc( hidden) ]
126+ pub const fn udp_available_types( ) -> & ' static [ & ' static str ] {
127+ const AVAILABLE_TYPES : & [ & str ] = & [ RedirType :: PacketFilter . name( ) ] ;
128+ AVAILABLE_TYPES
129+ }
130+ } else if #[ cfg( any( target_os = "macos" , target_os = "ios" ) ) ] {
131+ /// Default TCP transparent proxy solution on this platform
132+ pub fn tcp_default( ) -> RedirType {
133+ RedirType :: PacketFilter
134+ }
135+
136+ /// Available TCP transparent proxy types
137+ #[ doc( hidden) ]
81138 pub const fn tcp_available_types( ) -> & ' static [ & ' static str ] {
82139 const AVAILABLE_TYPES : & [ & str ] = & [ RedirType :: PacketFilter . name( ) , RedirType :: IpFirewall . name( ) ] ;
83140 AVAILABLE_TYPES
84141 }
142+
143+ /// Default UDP transparent proxy solution on this platform
144+ pub fn udp_default( ) -> RedirType {
145+ RedirType :: PacketFilter
146+ }
147+
148+ /// Available UDP transparent proxy types
149+ #[ doc( hidden) ]
150+ pub const fn udp_available_types( ) -> & ' static [ & ' static str ] {
151+ const AVAILABLE_TYPES : & [ & str ] = & [ RedirType :: PacketFilter . name( ) ] ;
152+ AVAILABLE_TYPES
153+ }
85154 } else {
86155 /// Default TCP transparent proxy solution on this platform
87156 pub fn tcp_default( ) -> RedirType {
88157 RedirType :: NotSupported
89158 }
90159
91160 /// Available TCP transparent proxy types
161+ #[ doc( hidden) ]
92162 pub const fn tcp_available_types( ) -> & ' static [ & ' static str ] {
93163 const AVAILABLE_TYPES : & [ & str ] = & [ ] ;
94164 AVAILABLE_TYPES
95165 }
166+
167+ /// Default UDP transparent proxy solution on this platform
168+ pub fn udp_default( ) -> RedirType {
169+ RedirType :: NotSupported
170+ }
171+
172+ /// Available UDP transparent proxy types
173+ #[ doc( hidden) ]
174+ pub const fn udp_available_types( ) -> & ' static [ & ' static str ] {
175+ const AVAILABLE_TYPES : & [ & str ] = & [ ] ;
176+ AVAILABLE_TYPES
177+ }
96178 }
97179 }
98180
181+ /// Check if transparent proxy is supported on this platform
182+ pub fn is_supported ( self ) -> bool {
183+ self != RedirType :: NotSupported
184+ }
185+
99186 /// Name of redirect type (transparent proxy type)
100187 pub const fn name ( self ) -> & ' static str {
101188 match self {
@@ -109,9 +196,8 @@ impl RedirType {
109196 RedirType :: TProxy => "tproxy" ,
110197
111198 #[ cfg( any(
112- target_os = "openbsd" ,
113199 target_os = "freebsd" ,
114- target_os = "netbsd " ,
200+ target_os = "openbsd " ,
115201 target_os = "macos" ,
116202 target_os = "ios"
117203 ) ) ]
@@ -153,21 +239,14 @@ impl FromStr for RedirType {
153239 "tproxy" => Ok ( RedirType :: TProxy ) ,
154240
155241 #[ cfg( any(
156- target_os = "openbsd" ,
157242 target_os = "freebsd" ,
158- target_os = "netbsd" ,
159- target_os = "solaris" ,
243+ target_os = "openbsd" ,
160244 target_os = "macos" ,
161245 target_os = "ios" ,
162246 ) ) ]
163247 "pf" => Ok ( RedirType :: PacketFilter ) ,
164248
165- #[ cfg( any(
166- target_os = "freebsd" ,
167- target_os = "macos" ,
168- target_os = "ios" ,
169- target_os = "dragonfly"
170- ) ) ]
249+ #[ cfg( any( target_os = "freebsd" , target_os = "macos" , target_os = "ios" , ) ) ]
171250 "ipfw" => Ok ( RedirType :: IpFirewall ) ,
172251
173252 _ => Err ( InvalidRedirType ) ,
0 commit comments