Move the majority of the packet-libvirt.h content into packet-libvirt.c and expose only register functions which are the only ones that are not static. The rationale behind is that packet-libvirt.h will be included from packet.c and therefore the header file needs to be as clean as possible. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- cfg.mk | 2 +- tools/wireshark/src/packet-libvirt.c | 69 ++++++++++++++++++++- tools/wireshark/src/packet-libvirt.h | 93 +--------------------------- 3 files changed, 71 insertions(+), 93 deletions(-) diff --git a/cfg.mk b/cfg.mk index 5b6ea2504c..c2524de5fc 100644 --- a/cfg.mk +++ b/cfg.mk @@ -1283,7 +1283,7 @@ exclude_file_name_regexp--sc_correct_id_types = \ exclude_file_name_regexp--sc_m4_quote_check = m4/virt-lib.m4 exclude_file_name_regexp--sc_prohibit_include_public_headers_quote = \ - ^(src/internal\.h$$|tools/wireshark/src/packet-libvirt.h$$) + ^(src/internal\.h$$|tools/wireshark/src/packet-libvirt.c$$) exclude_file_name_regexp--sc_prohibit_include_public_headers_brackets = \ ^(tools/|examples/|include/libvirt/(virterror|libvirt(-(admin|qemu|lxc))?)\.h$$) diff --git a/tools/wireshark/src/packet-libvirt.c b/tools/wireshark/src/packet-libvirt.c index a71ad9f812..e759e81bae 100644 --- a/tools/wireshark/src/packet-libvirt.c +++ b/tools/wireshark/src/packet-libvirt.c @@ -29,6 +29,19 @@ #include "packet-libvirt.h" #include "internal.h" +#ifndef LIBVIRT_PORT +# define LIBVIRT_PORT 16509 +#endif + +#define VIR_HEADER_LEN 28 + +#ifdef DEBUG +# define dbg(fmt, ...) \ + g_print("[LIBVIRT] " fmt " at " __FILE__ " line %d\n", ##__VA_ARGS__, __LINE__) +#else +# define dbg(fmt, ...) +#endif + /* Wireshark 1.12 brings API change */ #define WIRESHARK_VERSION \ ((VERSION_MAJOR * 1000 * 1000) + \ @@ -80,6 +93,58 @@ XDR_PRIMITIVE_DISSECTOR(float, gfloat, float) XDR_PRIMITIVE_DISSECTOR(double, gdouble, double) XDR_PRIMITIVE_DISSECTOR(bool, bool_t, boolean) +typedef gboolean (*vir_xdr_dissector_t)(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); + +typedef struct vir_dissector_index vir_dissector_index_t; +struct vir_dissector_index { + guint32 proc; + vir_xdr_dissector_t args; + vir_xdr_dissector_t ret; + vir_xdr_dissector_t msg; +}; + +enum vir_net_message_type { + VIR_NET_CALL = 0, + VIR_NET_REPLY = 1, + VIR_NET_MESSAGE = 2, + VIR_NET_STREAM = 3, + VIR_NET_CALL_WITH_FDS = 4, + VIR_NET_REPLY_WITH_FDS = 5, + VIR_NET_STREAM_HOLE = 6, +}; + +enum vir_net_message_status { + VIR_NET_OK = 0, + VIR_NET_ERROR = 1, + VIR_NET_CONTINUE = 2, +}; + +enum vir_program_data_index { + VIR_PROGRAM_PROCHFVAR, + VIR_PROGRAM_PROCSTRINGS, + VIR_PROGRAM_DISSECTORS, + VIR_PROGRAM_DISSECTORS_LEN, + VIR_PROGRAM_LAST, +}; + +static const value_string type_strings[] = { + { VIR_NET_CALL, "CALL" }, + { VIR_NET_REPLY, "REPLY" }, + { VIR_NET_MESSAGE, "MESSAGE" }, + { VIR_NET_STREAM, "STREAM" }, + { VIR_NET_CALL_WITH_FDS, "CALL_WITH_FDS" }, + { VIR_NET_REPLY_WITH_FDS, "REPLY_WITH_FDS" }, + { VIR_NET_STREAM_HOLE, "STREAM_HOLE" }, + { -1, NULL } +}; + +static const value_string status_strings[] = { + { VIR_NET_OK, "OK" }, + { VIR_NET_ERROR, "ERROR" }, + { VIR_NET_CONTINUE, "CONTINUE" }, + { -1, NULL } +}; + static gboolean dissect_xdr_string(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, guint32 maxlen) @@ -357,6 +422,8 @@ dissect_xdr_stream_hole(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf) return TRUE; } +#include "libvirt/protocol.h" + static void dissect_libvirt_payload(tvbuff_t *tvb, proto_tree *tree, guint32 prog, guint32 proc, guint32 type, guint32 status) @@ -374,7 +441,7 @@ dissect_libvirt_payload(tvbuff_t *tvb, proto_tree *tree, goto unknown; dissect_libvirt_payload_xdr_data(tvb, tree, payload_length, status, xd); } else if (status == VIR_NET_ERROR) { - dissect_libvirt_payload_xdr_data(tvb, tree, payload_length, status, VIR_ERROR_MESSAGE_DISSECTOR); + dissect_libvirt_payload_xdr_data(tvb, tree, payload_length, status, dissect_xdr_remote_error); } else if (type == VIR_NET_STREAM) { /* implicitly, status == VIR_NET_CONTINUE */ dissect_libvirt_stream(tvb, tree, payload_length); } else if (type == VIR_NET_STREAM_HOLE) { diff --git a/tools/wireshark/src/packet-libvirt.h b/tools/wireshark/src/packet-libvirt.h index 4f2a275ba6..3b7a0f054d 100644 --- a/tools/wireshark/src/packet-libvirt.h +++ b/tools/wireshark/src/packet-libvirt.h @@ -20,96 +20,7 @@ #ifndef LIBVIRT_PACKET_LIBVIRT_H # define LIBVIRT_PACKET_LIBVIRT_H -# include "libvirt/libvirt.h" - -# ifndef LIBVIRT_PORT -# define LIBVIRT_PORT 16509 -# endif - -# define VIR_HEADER_LEN 28 - -# ifdef DEBUG -# define dbg(fmt, ...) \ - g_print("[LIBVIRT] " fmt " at " __FILE__ " line %d\n", ##__VA_ARGS__, __LINE__) -# else -# define dbg(fmt, ...) -# endif - -typedef gboolean (*vir_xdr_dissector_t)(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); - -typedef struct vir_dissector_index vir_dissector_index_t; -struct vir_dissector_index { - guint32 proc; - vir_xdr_dissector_t args; - vir_xdr_dissector_t ret; - vir_xdr_dissector_t msg; -}; - -enum vir_net_message_type { - VIR_NET_CALL = 0, - VIR_NET_REPLY = 1, - VIR_NET_MESSAGE = 2, - VIR_NET_STREAM = 3, - VIR_NET_CALL_WITH_FDS = 4, - VIR_NET_REPLY_WITH_FDS = 5, - VIR_NET_STREAM_HOLE = 6, -}; - -enum vir_net_message_status { - VIR_NET_OK = 0, - VIR_NET_ERROR = 1, - VIR_NET_CONTINUE = 2, -}; - -enum vir_program_data_index { - VIR_PROGRAM_PROCHFVAR, - VIR_PROGRAM_PROCSTRINGS, - VIR_PROGRAM_DISSECTORS, - VIR_PROGRAM_DISSECTORS_LEN, - VIR_PROGRAM_LAST, -}; - -static const value_string type_strings[] = { - { VIR_NET_CALL, "CALL" }, - { VIR_NET_REPLY, "REPLY" }, - { VIR_NET_MESSAGE, "MESSAGE" }, - { VIR_NET_STREAM, "STREAM" }, - { VIR_NET_CALL_WITH_FDS, "CALL_WITH_FDS" }, - { VIR_NET_REPLY_WITH_FDS, "REPLY_WITH_FDS" }, - { VIR_NET_STREAM_HOLE, "STREAM_HOLE" }, - { -1, NULL } -}; - -static const value_string status_strings[] = { - { VIR_NET_OK, "OK" }, - { VIR_NET_ERROR, "ERROR" }, - { VIR_NET_CONTINUE, "CONTINUE" }, - { -1, NULL } -}; - -# define VIR_ERROR_MESSAGE_DISSECTOR dissect_xdr_remote_error - -static gboolean dissect_xdr_int(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); -static gboolean dissect_xdr_u_int(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); -static gboolean dissect_xdr_short(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); -static gboolean dissect_xdr_u_short(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); -static gboolean dissect_xdr_char(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); -static gboolean dissect_xdr_u_char(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); -static gboolean dissect_xdr_hyper(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); -static gboolean dissect_xdr_u_hyper(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); -static gboolean dissect_xdr_float(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); -static gboolean dissect_xdr_double(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); -static gboolean dissect_xdr_bool(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf); -static gboolean dissect_xdr_string(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, guint32 maxlen); -static gboolean dissect_xdr_opaque(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, guint32 size); -static gboolean dissect_xdr_bytes(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, guint32 maxlen); -static gboolean dissect_xdr_pointer(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, - vir_xdr_dissector_t dp); -static gboolean dissect_xdr_vector(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, gint ett, - int rhf, const gchar *rtype, guint32 size, vir_xdr_dissector_t dp); -static gboolean dissect_xdr_array(tvbuff_t *tvb, proto_tree *tree, XDR *xdrs, int hf, gint ett, - int rhf, const gchar *rtype, guint32 maxlen, vir_xdr_dissector_t dp); - -# include "libvirt/protocol.h" +void proto_register_libvirt(void); +void proto_reg_handoff_libvirt(void); #endif /* LIBVIRT_PACKET_LIBVIRT_H */ -- 2.19.2