From patchwork Wed Aug 24 02:59:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Ding X-Patchwork-Id: 1669563 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.133; helo=smtp2.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from smtp2.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4MC9w75gQKz1yhC for ; Wed, 24 Aug 2022 13:05:59 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by smtp2.osuosl.org (Postfix) with ESMTP id F267F409FA; Wed, 24 Aug 2022 03:05:57 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org F267F409FA X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp2.osuosl.org ([127.0.0.1]) by localhost (smtp2.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rw4Q-LyO7gli; Wed, 24 Aug 2022 03:05:57 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [IPv6:2605:bc80:3010:104::8cd3:938]) by smtp2.osuosl.org (Postfix) with ESMTPS id 2285B4020B; Wed, 24 Aug 2022 03:05:56 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp2.osuosl.org 2285B4020B Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id DE5C1C0033; Wed, 24 Aug 2022 03:05:55 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from smtp1.osuosl.org (smtp1.osuosl.org [IPv6:2605:bc80:3010::138]) by lists.linuxfoundation.org (Postfix) with ESMTP id D6DCEC002D for ; Wed, 24 Aug 2022 03:05:54 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id A458281401 for ; Wed, 24 Aug 2022 03:05:54 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org A458281401 X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j-51p9Gc0uPe for ; Wed, 24 Aug 2022 03:05:53 +0000 (UTC) X-Greylist: delayed 00:06:10 by SQLgrey-1.8.0 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp1.osuosl.org DB576813F7 Received: from mail-m2837.qiye.163.com (mail-m2837.qiye.163.com [103.74.28.37]) by smtp1.osuosl.org (Postfix) with ESMTPS id DB576813F7 for ; Wed, 24 Aug 2022 03:05:52 +0000 (UTC) Received: from WINDOWS-PC3SSGC (unknown [218.94.118.90]) by mail-m2837.qiye.163.com (Hmail) with ESMTPA id 165356000E4 for ; Wed, 24 Aug 2022 10:59:36 +0800 (CST) Date: Wed, 24 Aug 2022 10:59:35 +0800 From: "Daniel Ding" To: dev X-Priority: 3 X-GUID: 1F6016A2-56B0-40EE-B392-F78D56950C57 X-Has-Attach: no X-Mailer: Foxmail 7.2.22.194[cn] Mime-Version: 1.0 Message-ID: <2022082410483683341426@easystack.cn> X-HM-Spam-Status: e1kfGhgUHx5ZQUtXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFJQjdXWS1ZQUlXWQ8JGhUIEh9ZQVlDTE9JVkhOGkkaTk9OQ0tKS1UZERMWGhIXJBQOD1 lXWRgSC1lBWUlKQ1VCT1VKSkNVQktZV1kWGg8SFR0UWUFZT0tIVUpKS0hOSFVLWQY+ X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6Py46OAw6AjILEgNRLVEXAlYK KxAaCxlVSlVKTU1KSEtCQkxNTk9LVTMWGhIXVQETEhMOElUfEhUcOx4aCAIIDxoYEFUYFUVZV1kS C1lBWUlKQ1VCT1VKSkNVQktZV1kIAVlBTkxJSjcG X-HM-Tid: 0a82cdca7e41841fkuqw165356000e4 X-Content-Filtered-By: Mailman/MimeDel 2.1.15 Subject: [ovs-dev] [PATCH] utilities/ovs-tcpdump.in: Fix not destroy mirror (Daniel Ding) X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" 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. Signed-off-by: Daniel Ding --- utilities/ovs-tcpdump.in | 12 ++++++++++++ 1 file changed, 12 insertions(+) --- Best regards, Daniel Ding diff --git a/utilities/ovs-tcpdump.in b/utilities/ovs-tcpdump.in index 7fd26e405..211d50fc5 100755 --- a/utilities/ovs-tcpdump.in +++ b/utilities/ovs-tcpdump.in @@ -17,6 +17,7 @@ import os import pwd from random import randint +import signal import subprocess import sys import time @@ -489,6 +490,17 @@ def main(): print("ERROR: Mirror port (%s) exists for port %s." % (mirror_interface, interface)) sys.exit(1) + + def signal_handler(_signo, _stack_frame): + ovsdb.destroy_mirror(interface, ovsdb.port_bridge(interface)) + ovsdb.destroy_port(mirror_interface, ovsdb.port_bridge(interface)) + + sys.exit(0) + + if sys.platform in ['linux', 'linux2']: + signal.signal(signal.SIGHUP, signal_handler) + signal.signal(signal.SIGTERM, signal_handler) + try: ovsdb.make_port(mirror_interface, ovsdb.port_bridge(interface)) ovsdb.bridge_mirror(interface, mirror_interface,