[libvirt] [PATCH 2/5] tools: Keep wireshark plugin registration code in git

Michal Privoznik mprivozn at redhat.com
Fri Feb 8 11:23:25 UTC 2019


In order to be able to dissect libvirt protocol the wireshark
plugin needs to be registered. So far this plugin registration
code was generated on every build using a script that was copied
over from wireshark's tools/ directory.

This is suboptimal, because the way that plugins register changes
across wireshark releases. Therefore, let's keep the generated
file in the git, put the command line used to generate the file
into a comment and remove the script.

This solution allows us to put different registration mechanism
into one file (under #ifdef-s) and thus compile with wider range
of wireshark releases.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 .gitignore                              |   1 -
 tools/Makefile.am                       |  15 +-
 tools/wireshark/src/plugin.c            |  45 ++++++
 tools/wireshark/util/make-dissector-reg | 205 ------------------------
 4 files changed, 48 insertions(+), 218 deletions(-)
 create mode 100644 tools/wireshark/src/plugin.c
 delete mode 100755 tools/wireshark/util/make-dissector-reg

diff --git a/.gitignore b/.gitignore
index df0ac8e3d4..3303eed411 100644
--- a/.gitignore
+++ b/.gitignore
@@ -190,7 +190,6 @@
 /tools/virt-admin
 /tools/virt-*-validate
 /tools/virt-sanlock-cleanup
-/tools/wireshark/src/plugin.c
 /tools/wireshark/src/libvirt
 /update.log
 GPATH
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 613c9a77f0..f2f84f7852 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -444,9 +444,7 @@ uninstall-bash-completion:
 endif ! WITH_BASH_COMPLETION
 
 
-EXTRA_DIST += \
-	wireshark/util/genxdrstub.pl \
-	wireshark/util/make-dissector-reg
+EXTRA_DIST += wireshark/util/genxdrstub.pl
 
 if WITH_WIRESHARK_DISSECTOR
 
@@ -454,19 +452,14 @@ ws_plugin_LTLIBRARIES = wireshark/src/libvirt.la
 wireshark_src_libvirt_la_CFLAGS = \
 	-I wireshark/src $(WIRESHARK_DISSECTOR_CFLAGS) $(XDR_CFLAGS)
 wireshark_src_libvirt_la_LDFLAGS = -avoid-version -module
-nodist_wireshark_src_libvirt_la_SOURCES = wireshark/src/plugin.c
 wireshark_src_libvirt_la_SOURCES = \
 	wireshark/src/packet-libvirt.h \
-	wireshark/src/packet-libvirt.c
+	wireshark/src/packet-libvirt.c \
+	wireshark/src/plugin.c
 
 wireshark/src/packet-libvirt.c: wireshark/src/packet-libvirt.h \
 		wireshark/src/libvirt/protocol.h
 
-wireshark/src/plugin.c: wireshark/src/packet-libvirt.c
-	$(AM_V_GEN)cd wireshark/src && \
-		$(abs_top_srcdir)/tools/wireshark/util/make-dissector-reg \
-		. plugin packet-libvirt.c
-
 WS_DISSECTOR_PROTO_FILES  = \
   $(abs_top_srcdir)/src/remote/remote_protocol.x \
   $(abs_top_srcdir)/src/remote/qemu_protocol.x \
@@ -481,8 +474,6 @@ wireshark/src/libvirt/protocol.h: wireshark/util/genxdrstub.pl \
 		  $(PERL) $(abs_top_srcdir)/tools/wireshark/util/genxdrstub.pl \
 		  $(WS_DISSECTOR_PROTO_FILES)
 
-CLEANFILES += wireshark/src/plugin.c
-
 endif WITH_WIRESHARK_DISSECTOR
 
 if WITH_BSD_NSS
diff --git a/tools/wireshark/src/plugin.c b/tools/wireshark/src/plugin.c
new file mode 100644
index 0000000000..2a85688f43
--- /dev/null
+++ b/tools/wireshark/src/plugin.c
@@ -0,0 +1,45 @@
+/*
+ * plugin.c: Wireshark's plugin registration
+ *
+ * The registration routines were generated using wireshark's
+ * make-dissector-reg script (found under wirshark.git/tools/):
+ *
+ * libvirt.git/tools/wireshark/src $ \
+ *   /path/to/wireshark.git/tools/make-dissector-reg \
+ *   . plugin packet-libvirt.c
+ *
+ */
+
+#include <config.h>
+
+#include <gmodule.h>
+
+/* plugins are DLLs */
+#define WS_BUILD_DLL
+#include <wireshark/ws_symbol_export.h>
+
+#include "packet-libvirt.h"
+
+/* In 1.12 wireshark WS_DLL_PUBLIC_NOEXTERN was substitued with
+ * WS_DLL_PUBLIC_DEF. See wireshark's commit
+ * 5d87a8c46171f572568db5a47c093423482e342f for more info. */
+#ifndef WS_DLL_PUBLIC_NOEXTERN
+# define WS_DLL_PUBLIC_NOEXTERN WS_DLL_PUBLIC_DEF
+#endif
+
+#ifndef ENABLE_STATIC
+WS_DLL_PUBLIC_NOEXTERN const gchar version[] = VERSION;
+
+/* Start the functions we need for the plugin stuff */
+
+WS_DLL_PUBLIC_NOEXTERN void
+plugin_register(void)
+{
+  proto_register_libvirt();
+}
+WS_DLL_PUBLIC_NOEXTERN void
+plugin_reg_handoff(void)
+{
+  proto_reg_handoff_libvirt();
+}
+#endif
diff --git a/tools/wireshark/util/make-dissector-reg b/tools/wireshark/util/make-dissector-reg
deleted file mode 100755
index 6fa25c1eed..0000000000
--- a/tools/wireshark/util/make-dissector-reg
+++ /dev/null
@@ -1,205 +0,0 @@
-#! /bin/sh
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <http://www.gnu.org/licenses/>.
-#
-# Copied from Wireshark(http://www.wireshark.org/)
-
-#
-# The first argument is the directory in which the source files live.
-#
-srcdir="$1"
-shift
-
-#
-# The second argument is either "plugin" or "dissectors"; if it's
-# "plugin", we build a plugin.c for a plugin, and if it's
-# "dissectors", we build a register.c for libwireshark.
-#
-registertype="$1"
-shift
-if [ "$registertype" = plugin ]
-then
-	outfile="plugin.c"
-elif [ "$registertype" = dissectors ]
-then
-	outfile="register.c"
-else
-	echo "Unknown output type '$registertype'" 1>&2
-	exit 1
-fi
-
-#
-# All subsequent arguments are the files to scan.
-#
-rm -f ${outfile}-tmp
-echo '/* Do not modify this file.  */' >${outfile}-tmp
-echo '/* It is created automatically by the Makefile. */'>>${outfile}-tmp
-if [ "$registertype" = plugin ]
-then
-	cat <<"EOF" >>${outfile}-tmp
-#include "config.h"
-
-#include <gmodule.h>
-
-/* plugins are DLLs */
-#define WS_BUILD_DLL
-#include "ws_symbol_export.h"
-
-/* In 1.12 wireshark WS_DLL_PUBLIC_NOEXTERN was substitued with
- * WS_DLL_PUBLIC_DEF. See wireshark's commit
- * 5d87a8c46171f572568db5a47c093423482e342f for more info. */
-#ifndef WS_DLL_PUBLIC_NOEXTERN
-# define WS_DLL_PUBLIC_NOEXTERN WS_DLL_PUBLIC_DEF
-#endif
-
-#ifndef ENABLE_STATIC
-WS_DLL_PUBLIC_NOEXTERN const gchar version[] = VERSION;
-
-/* Start the functions we need for the plugin stuff */
-
-WS_DLL_PUBLIC_NOEXTERN void
-plugin_register (void)
-{
-EOF
-#
-# Build code to call all the protocol registration routines.
-#
-for f in "$@"
-do
-	if [ -f $f ]
-	then
-		srcfile=$f
-	else
-		srcfile=$srcdir/$f
-	fi
-	grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
-done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
-for f in "$@"
-do
-	if [ -f $f ]
-	then
-		srcfile=$f
-	else
-		srcfile=$srcdir/$f
-	fi
-	grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
-done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
-else
-	cat <<"EOF" >>${outfile}-tmp
-#include "register.h"
-void
-register_all_protocols(register_cb cb, gpointer client_data)
-{
-EOF
-#
-# Build code to call all the protocol registration routines.
-#
-for f in "$@"
-do
-	if [ -f $f ]
-	then
-		srcfile=$f
-	else
-		srcfile=$srcdir/$f
-	fi
-	grep '^proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
-done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/  {extern void \1 (void); if(cb) (*cb)(RA_REGISTER, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp
-for f in "$@"
-do
-	if [ -f $f ]
-	then
-		srcfile=$f
-	else
-		srcfile=$srcdir/$f
-	fi
-	grep '^void proto_register_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
-done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/  {extern void \1 (void); if(cb) (*cb)(RA_REGISTER, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp
-
-fi
-echo '}' >>${outfile}-tmp
-
-
-#
-# Build code to call all the protocol handoff registration routines.
-#
-if [ "$registertype" = plugin ]
-then
-	cat <<"EOF" >>${outfile}-tmp
-WS_DLL_PUBLIC_NOEXTERN void
-plugin_reg_handoff(void)
-{
-EOF
-for f in "$@"
-do
-	if [ -f $f ]
-	then
-		srcfile=$f
-	else
-		srcfile=$srcdir/$f
-	fi
-	grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
-done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
-for f in "$@"
-do
-	if [ -f $f ]
-	then
-		srcfile=$f
-	else
-		srcfile=$srcdir/$f
-	fi
-	grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
-done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/  {extern void \1 (void); \1 ();}/' >>${outfile}-tmp
-else
-	cat <<"EOF" >>${outfile}-tmp
-void
-register_all_protocol_handoffs(register_cb cb, gpointer client_data)
-{
-EOF
-for f in "$@"
-do
-	if [ -f $f ]
-	then
-		srcfile=$f
-	else
-		srcfile=$srcdir/$f
-	fi
-	grep '^proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
-done | sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/  {extern void \1 (void); if(cb) (*cb)(RA_HANDOFF, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp
-for f in "$@"
-do
-	if [ -f $f ]
-	then
-		srcfile=$f
-	else
-		srcfile=$srcdir/$f
-	fi
-	grep '^void proto_reg_handoff_[a-z_0-9A-Z]* *(' $srcfile 2>/dev/null | grep -v ';'
-done | sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/  {extern void \1 (void); if(cb) (*cb)(RA_HANDOFF, \"\1\", client_data); \1 ();}/' >>${outfile}-tmp
-fi
-echo '}' >>${outfile}-tmp
-if [ "$registertype" = plugin ]
-then
-	echo '#endif' >>${outfile}-tmp
-else
-	cat <<"EOF" >>${outfile}-tmp
-gulong register_count(void)
-{
-EOF
-	proto_regs=`grep RA_REGISTER ${outfile}-tmp | wc -l`
-	handoff_regs=`grep RA_HANDOFF ${outfile}-tmp | wc -l`
-	echo "  return $proto_regs + $handoff_regs;" >>${outfile}-tmp
-	echo '}' >>${outfile}-tmp
-fi
-
-# Only overwrite outfile if it differs from newly generated file
-mv ${outfile}-tmp ${outfile}
-- 
2.19.2




More information about the libvir-list mailing list