@@ -113,30 +113,38 @@ def rsd_info(service_provider: RemoteServiceDiscoveryService):
113
113
114
114
115
115
async def tunnel_task (
116
- service , secrets : Optional [TextIO ] = None , script_mode : bool = False ,
116
+ service , secrets : Optional [TextIO ] = None , script_mode : bool = False , userspace_host : Optional [ str ] = None ,
117
117
max_idle_timeout : float = MAX_IDLE_TIMEOUT , protocol : TunnelProtocol = TunnelProtocol .DEFAULT ) -> None :
118
118
async with start_tunnel (
119
- service , secrets = secrets , max_idle_timeout = max_idle_timeout , protocol = protocol ) as tunnel_result :
119
+ service , secrets = secrets , max_idle_timeout = max_idle_timeout ,
120
+ protocol = protocol , userspace_host = userspace_host ) as tunnel_result :
120
121
logger .info ('tunnel created' )
122
+ use_userspace = userspace_host is not None
121
123
if script_mode :
122
- print (f'{ tunnel_result .address } { tunnel_result .port } ' )
124
+ if userspace_host :
125
+ print (f'{ tunnel_result .address } { tunnel_result .port } { tunnel_result .interface } ' )
126
+ else :
127
+ print (f'{ tunnel_result .address } { tunnel_result .port } ' )
123
128
else :
129
+ interface_name = "Userspace TUN" if use_userspace else tunnel_result .interface
130
+ userspace_param = f"--userspace-wrapper { tunnel_result .interface } " if use_userspace else ""
124
131
if user_requested_colored_output ():
125
132
if secrets is not None :
126
133
print (click .style ('Secrets: ' , bold = True , fg = 'magenta' ) +
127
134
click .style (secrets .name , bold = True , fg = 'white' ))
128
135
print (click .style ('Identifier: ' , bold = True , fg = 'yellow' ) +
129
136
click .style (service .remote_identifier , bold = True , fg = 'white' ))
130
137
print (click .style ('Interface: ' , bold = True , fg = 'yellow' ) +
131
- click .style (tunnel_result . interface , bold = True , fg = 'white' ))
138
+ click .style (interface_name , bold = True , fg = 'white' ))
132
139
print (click .style ('Protocol: ' , bold = True , fg = 'yellow' ) +
133
140
click .style (tunnel_result .protocol , bold = True , fg = 'white' ))
134
141
print (click .style ('RSD Address: ' , bold = True , fg = 'yellow' ) +
135
142
click .style (tunnel_result .address , bold = True , fg = 'white' ))
136
143
print (click .style ('RSD Port: ' , bold = True , fg = 'yellow' ) +
137
144
click .style (tunnel_result .port , bold = True , fg = 'white' ))
138
145
print (click .style ('Use the follow connection option:\n ' , bold = True , fg = 'yellow' ) +
139
- click .style (f'--rsd { tunnel_result .address } { tunnel_result .port } ' , bold = True , fg = 'cyan' ))
146
+ click .style (userspace_param + f'--rsd { tunnel_result .address } { tunnel_result .port } ' ,
147
+ bold = True , fg = 'cyan' ))
140
148
else :
141
149
if secrets is not None :
142
150
print (f'Secrets: { secrets .name } ' )
@@ -145,16 +153,17 @@ async def tunnel_task(
145
153
print (f'Protocol: { tunnel_result .protocol } ' )
146
154
print (f'RSD Address: { tunnel_result .address } ' )
147
155
print (f'RSD Port: { tunnel_result .port } ' )
148
- print (f 'Use the follow connection option:\n '
149
- f'--rsd { tunnel_result .address } { tunnel_result .port } ' )
156
+ print ('Use the follow connection option:\n ' +
157
+ userspace_param + f'--rsd { tunnel_result .address } { tunnel_result .port } ' )
150
158
sys .stdout .flush ()
151
159
await tunnel_result .client .wait_closed ()
152
160
logger .info ('tunnel was closed' )
153
161
154
162
155
163
async def start_tunnel_task (
156
164
connection_type : ConnectionType , secrets : TextIO , udid : Optional [str ] = None , script_mode : bool = False ,
157
- max_idle_timeout : float = MAX_IDLE_TIMEOUT , protocol : TunnelProtocol = TunnelProtocol .DEFAULT ) -> None :
165
+ max_idle_timeout : float = MAX_IDLE_TIMEOUT , protocol : TunnelProtocol = TunnelProtocol .DEFAULT ,
166
+ userspace_host : Optional [str ] = None ) -> None :
158
167
if start_tunnel is None :
159
168
raise NotImplementedError ('failed to start the tunnel on your platform' )
160
169
get_tunnel_services = {
@@ -173,13 +182,14 @@ async def start_tunnel_task(
173
182
service = prompt_device_list (tunnel_services )
174
183
175
184
await tunnel_task (service , secrets = secrets , script_mode = script_mode , max_idle_timeout = max_idle_timeout ,
176
- protocol = protocol )
185
+ protocol = protocol , userspace_host = userspace_host )
177
186
178
187
179
188
@remote_cli .command ('start-tunnel' , cls = BaseCommand )
180
189
@click .option ('-t' , '--connection-type' , type = click .Choice ([e .value for e in ConnectionType ], case_sensitive = False ),
181
190
default = ConnectionType .USB .value )
182
191
@click .option ('--udid' , help = 'UDID for a specific device to look for' )
192
+ @click .option ('--userspace-host' , help = 'Specify a host to listen on to enable userspace TUN' )
183
193
@click .option ('--secrets' , type = click .File ('wt' ), help = 'TLS keyfile for decrypting with Wireshark' )
184
194
@click .option ('--script-mode' , is_flag = True ,
185
195
help = 'Show only HOST and port number to allow easy parsing from external shell scripts' )
@@ -188,17 +198,17 @@ async def start_tunnel_task(
188
198
@click .option ('-p' , '--protocol' ,
189
199
type = click .Choice ([e .value for e in TunnelProtocol ], case_sensitive = False ),
190
200
default = TunnelProtocol .DEFAULT .value )
191
- @sudo_required
201
+ # @sudo_required
192
202
def cli_start_tunnel (
193
- connection_type : ConnectionType , udid : Optional [str ], secrets : TextIO , script_mode : bool ,
194
- max_idle_timeout : float , protocol : str ) -> None :
203
+ connection_type : ConnectionType , udid : Optional [str ], userspace_host : Optional [ str ] ,
204
+ secrets : TextIO , script_mode : bool , max_idle_timeout : float , protocol : str ) -> None :
195
205
""" start tunnel """
196
206
if not verify_tunnel_imports ():
197
207
return
198
208
asyncio .run (
199
209
start_tunnel_task (
200
210
ConnectionType (connection_type ), secrets , udid , script_mode , max_idle_timeout = max_idle_timeout ,
201
- protocol = TunnelProtocol (protocol )), debug = True )
211
+ protocol = TunnelProtocol (protocol ), userspace_host = userspace_host ), debug = True )
202
212
203
213
204
214
@dataclasses .dataclass
0 commit comments