mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Fix remote packet capture and make sure packet capture is stopped when deleting an NIO. Fixes https://github.com/GNS3/gns3-gui/issues/2753
This commit is contained in:
1 parent
f01706e9e6
commit
4cc5dbc228
18 files changed
+73
-4
No files matched your search
@@ -41,6 +41,7 @@ class NIO:
|
||||
self._name = name
|
||||
self._filters = {}
|
||||
self._suspended = False
|
||||
self._capturing = False
|
||||
self._bandwidth = None # no bandwidth constraint by default
|
||||
self._input_filter = None # no input filter applied by default
|
||||
self._output_filter = None # no output filter applied by default
|
||||
@@ -115,6 +116,9 @@ class NIO:
|
||||
self._input_filter = filter_name
|
||||
self._output_filter = filter_name
|
||||
|
||||
if filter_name == "capture":
|
||||
self._capturing = True
|
||||
|
||||
async def unbind_filter(self, direction):
|
||||
"""
|
||||
Removes packet filter for this NIO.
|
||||
@@ -136,6 +140,7 @@ class NIO:
|
||||
elif direction == "both":
|
||||
self._input_filter = None
|
||||
self._output_filter = None
|
||||
self._capturing = False
|
||||
|
||||
async def setup_filter(self, direction, options):
|
||||
"""
|
||||
@@ -269,6 +274,15 @@ class NIO:
|
||||
assert isinstance(new_filters, dict)
|
||||
self._filters = new_filters
|
||||
|
||||
@property
|
||||
def capturing(self):
|
||||
"""
|
||||
Returns either a capture is configured on this NIO.
|
||||
:returns: boolean
|
||||
"""
|
||||
|
||||
return self._capturing
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
NIO string representation.
|
||||
|
||||
@@ -181,6 +181,7 @@ class ATMSwitch(Device):
|
||||
if port_number not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port_number))
|
||||
|
||||
await self.stop_capture(port_number)
|
||||
# remove VCs mapped with the port
|
||||
for source, destination in self._active_mappings.copy().items():
|
||||
if len(source) == 3 and len(destination) == 3:
|
||||
@@ -466,6 +467,8 @@ class ATMSwitch(Device):
|
||||
"""
|
||||
|
||||
nio = self.get_nio(port_number)
|
||||
if not nio.capturing:
|
||||
return
|
||||
await nio.unbind_filter("both")
|
||||
log.info('ATM switch "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
|
||||
@@ -162,6 +162,7 @@ class EthernetHub(Bridge):
|
||||
if port_number not in self._mappings:
|
||||
raise DynamipsError("Port {} is not allocated".format(port_number))
|
||||
|
||||
await self.stop_capture(port_number)
|
||||
nio = self._mappings[port_number]
|
||||
if isinstance(nio, NIOUDP):
|
||||
self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
||||
@@ -226,6 +227,8 @@ class EthernetHub(Bridge):
|
||||
"""
|
||||
|
||||
nio = self.get_nio(port_number)
|
||||
if not nio.capturing:
|
||||
return
|
||||
await nio.unbind_filter("both")
|
||||
log.info('Ethernet hub "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
|
||||
@@ -283,6 +283,7 @@ class EthernetSwitch(Device):
|
||||
if port_number not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port_number))
|
||||
|
||||
await self.stop_capture(port_number)
|
||||
nio = self._nios[port_number]
|
||||
if isinstance(nio, NIOUDP):
|
||||
self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
||||
@@ -455,6 +456,8 @@ class EthernetSwitch(Device):
|
||||
"""
|
||||
|
||||
nio = self.get_nio(port_number)
|
||||
if not nio.capturing:
|
||||
return
|
||||
await nio.unbind_filter("both")
|
||||
log.info('Ethernet switch "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
|
||||
@@ -183,6 +183,7 @@ class FrameRelaySwitch(Device):
|
||||
if port_number not in self._nios:
|
||||
raise DynamipsError("Port {} is not allocated".format(port_number))
|
||||
|
||||
await self.stop_capture(port_number)
|
||||
# remove VCs mapped with the port
|
||||
for source, destination in self._active_mappings.copy().items():
|
||||
source_port, source_dlci = source
|
||||
@@ -352,6 +353,8 @@ class FrameRelaySwitch(Device):
|
||||
"""
|
||||
|
||||
nio = self.get_nio(port_number)
|
||||
if not nio.capturing:
|
||||
return
|
||||
await nio.unbind_filter("both")
|
||||
log.info('Frame relay switch "{name}" [{id}]: stopping packet capture on port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
|
||||
@@ -1324,6 +1324,7 @@ class Router(BaseNode):
|
||||
raise DynamipsError("Port {port_number} does not exist on adapter {adapter}".format(adapter=adapter,
|
||||
port_number=port_number))
|
||||
|
||||
await self.stop_capture(slot_number, port_number)
|
||||
await self.slot_disable_nio(slot_number, port_number)
|
||||
await self._hypervisor.send('vm slot_remove_nio_binding "{name}" {slot_number} {port_number}'.format(name=self._name,
|
||||
slot_number=slot_number,
|
||||
@@ -1477,6 +1478,8 @@ class Router(BaseNode):
|
||||
raise DynamipsError("Port {slot_number}/{port_number} is not connected".format(slot_number=slot_number,
|
||||
port_number=port_number))
|
||||
|
||||
if not nio.capturing:
|
||||
return
|
||||
await nio.unbind_filter("both")
|
||||
|
||||
log.info('Router "{name}" [{id}]: stopping packet capture on port {slot_number}/{port_number}'.format(name=self._name,
|
||||
|
||||
Reference in new issue
Block a user