@@ -315,21 +315,25 @@ def monitor_command(self, command, arguments={}):
315315 "Can't use monitor command on non-running target" )
316316 return self .qmp .execute (command , arguments )
317317
318- def _add_port_forward (self , proto , local_address , local_port , remote_address , remote_port ):
318+ def _add_port_forward (self , proto , local_address , local_port , remote_address , remote_port , netdev ):
319+ command = ("hostfwd_add" , netdev , f"{ proto } :{ local_address } :{ local_port } -{ remote_address } :{ remote_port } " )
320+ command = filter (None , command )
319321 self .monitor_command (
320322 "human-monitor-command" ,
321- {"command-line" : f"hostfwd_add { proto } : { local_address } : { local_port } - { remote_address } : { remote_port } " },
323+ {"command-line" : " " . join ( command ) },
322324 )
323325
324- def add_port_forward (self , proto , local_address , local_port , remote_address , remote_port ):
325- self ._add_port_forward (proto , local_address , local_port , remote_address , remote_port )
326- self ._forwarded_ports [(proto , local_address , local_port )] = (proto , local_address , local_port , remote_address , remote_port )
326+ def add_port_forward (self , proto , local_address , local_port , remote_address , remote_port , netdev = "" ):
327+ self ._add_port_forward (proto , local_address , local_port , remote_address , remote_port , netdev )
328+ self ._forwarded_ports [(proto , local_address , local_port , netdev )] = (proto , local_address , local_port , remote_address , remote_port , netdev )
327329
328- def remove_port_forward (self , proto , local_address , local_port ):
329- del self ._forwarded_ports [(proto , local_address , local_port )]
330+ def remove_port_forward (self , proto , local_address , local_port , netdev = "" ):
331+ del self ._forwarded_ports [(proto , local_address , local_port , netdev )]
332+ command = ("hostfwd_remove" , netdev , f"{ proto } :{ local_address } :{ local_port } " )
333+ command = filter (None , command )
330334 self .monitor_command (
331335 "human-monitor-command" ,
332- {"command-line" : f"hostfwd_remove { proto } : { local_address } : { local_port } " },
336+ {"command-line" : " " . join ( command ) },
333337 )
334338
335339 def _read (self , size = 1 , timeout = 10 , max_size = None ):
0 commit comments