diff options
author | Daniel Ding <zhihui.ding@easystack.cn> | 2022-09-13 23:36:11 +0800 |
---|---|---|
committer | Ilya Maximets <i.maximets@ovn.org> | 2022-11-02 17:54:31 +0100 |
commit | eb86c28ddcdb7922974def08749076c8bf2c5635 (patch) | |
tree | 18e4178b888d251975f0c683a58c27b6317f1472 /utilities | |
parent | c98762d91b578b5d8290077af4de0b6e3d95c3ce (diff) | |
download | openvswitch-eb86c28ddcdb7922974def08749076c8bf2c5635.tar.gz |
ovs-tcpdump: Cleanup mirror port on SIGHUP/SIGTERM.
If ovs-tcpdump received HUP or TERM signal, mirror and mirror
interface should be destroyed. This often happens, when
controlling terminal is closed, like ssh session closed, and
other users use kill to terminate it.
Acked-by: Mike Pattrick <mkp@redhat.com>
Signed-off-by: Daniel Ding <zhihui.ding@easystack.cn>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Diffstat (limited to 'utilities')
-rwxr-xr-x | utilities/ovs-tcpdump.in | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/utilities/ovs-tcpdump.in b/utilities/ovs-tcpdump.in index e12bab889..a49ec9f94 100755 --- a/utilities/ovs-tcpdump.in +++ b/utilities/ovs-tcpdump.in @@ -44,6 +44,7 @@ try: from ovs import jsonrpc from ovs.poller import Poller from ovs.stream import Stream + from ovs.fatal_signal import add_hook except Exception: print("ERROR: Please install the correct Open vSwitch python support") print(" libraries (version @VERSION@).") @@ -412,6 +413,24 @@ def py_which(executable): for path in os.environ["PATH"].split(os.pathsep)) +def teardown(db_sock, interface, mirror_interface, tap_created): + def cleanup_mirror(): + try: + ovsdb = OVSDB(db_sock) + ovsdb.destroy_mirror(interface, ovsdb.port_bridge(interface)) + ovsdb.destroy_port(mirror_interface, ovsdb.port_bridge(interface)) + if tap_created is True: + _del_taps[sys.platform](mirror_interface) + except Exception: + print("Unable to tear down the ports and mirrors.") + print("Please use ovs-vsctl to remove the ports and mirrors" + " created.") + print(" ex: ovs-vsctl --db=%s del-port %s" % (db_sock, + mirror_interface)) + + add_hook(cleanup_mirror, None, True) + + def main(): rundir = os.environ.get('OVS_RUNDIR', '@RUNDIR@') db_sock = 'unix:%s' % os.path.join(rundir, "db.sock") @@ -496,6 +515,9 @@ def main(): print("ERROR: Mirror port (%s) exists for port %s." % (mirror_interface, interface)) sys.exit(1) + + teardown(db_sock, interface, mirror_interface, tap_created) + try: ovsdb.make_port(mirror_interface, ovsdb.port_bridge(interface)) ovsdb.bridge_mirror(interface, mirror_interface, @@ -503,12 +525,6 @@ def main(): mirror_select_all) except OVSDBException as oe: print("ERROR: Unable to properly setup the mirror: %s." % str(oe)) - try: - ovsdb.destroy_port(mirror_interface, ovsdb.port_bridge(interface)) - if tap_created is True: - _del_taps[sys.platform](mirror_interface) - except Exception: - pass sys.exit(1) ovsdb.close_idl() @@ -525,18 +541,6 @@ def main(): if pipes.poll() is None: pipes.terminate() - ovsdb = OVSDB(db_sock) - ovsdb.destroy_mirror(interface, ovsdb.port_bridge(interface)) - ovsdb.destroy_port(mirror_interface, ovsdb.port_bridge(interface)) - if tap_created is True: - _del_taps[sys.platform](mirror_interface) - except Exception: - print("Unable to tear down the ports and mirrors.") - print("Please use ovs-vsctl to remove the ports and mirrors created.") - print(" ex: ovs-vsctl --db=%s del-port %s" % (db_sock, - mirror_interface)) - sys.exit(1) - sys.exit(0) |