@@ -31,6 +31,22 @@ impl TunInterface {
3131 self . server . wait_closed ( py)
3232 }
3333
34+ /// Returns a `str` describing why tun mode is unavailable, or `None` if TUN mode is available.
35+ ///
36+ /// Reasons for unavailability may be an unsupported platform, or missing privileges.
37+ #[ staticmethod]
38+ pub fn unavailable_reason ( ) -> Option < String > {
39+ #[ cfg( target_os = "linux" ) ]
40+ if !unistd:: geteuid ( ) . is_root ( ) {
41+ Some ( String :: from ( "mitmproxy is not running as root" ) )
42+ } else {
43+ None
44+ }
45+
46+ #[ cfg( not( target_os = "linux" ) ) ]
47+ Some ( String :: from ( "OS not supported for TUN proxy mode" ) )
48+ }
49+
3450 pub fn __repr__ ( & self ) -> String {
3551 format ! ( "TunInterface({})" , self . tun_name)
3652 }
@@ -62,22 +78,6 @@ pub fn create_tun_interface(
6278 }
6379 #[ cfg( not( target_os = "linux" ) ) ]
6480 Err ( pyo3:: exceptions:: PyNotImplementedError :: new_err (
65- unavailable_reason ( ) ,
81+ TunInterface :: unavailable_reason ( ) ,
6682 ) )
6783}
68-
69- /// Returns a `str` describing why tun mode is unavailable, or `None` if TUN mode is available.
70- ///
71- /// Reasons for unavailability may be an unsupported platform, or missing privileges.
72- #[ pyfunction]
73- pub fn unavailable_reason ( ) -> Option < String > {
74- #[ cfg( target_os = "linux" ) ]
75- if !unistd:: geteuid ( ) . is_root ( ) {
76- Some ( String :: from ( "mitmproxy is not running as root" ) )
77- } else {
78- None
79- }
80-
81- #[ cfg( not( target_os = "linux" ) ) ]
82- Some ( String :: from ( "OS not supported for TUN proxy mode" ) )
83- }
0 commit comments