[Spice-devel] [PATCH v4 28/41] dissector: Allows to have two type with different size to point to same field name
Frediano Ziglio
fziglio at redhat.com
Thu Jul 23 08:54:45 PDT 2015
This is used sometimes to make possible to specify a wireshark filter.
Let say for instance that an initial size of a specific id is 16 bit.
Then on a later version new messages are added were the id to the same
type is added as 32 bit. Allowing different sizes on the same field name
(for instance a "image_id") allows to specify a simpler wireshark filter
(could be something like "spice.image_id == 76").
Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
python_modules/dissector.py | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/python_modules/dissector.py b/python_modules/dissector.py
index d03224f..6898a13 100644
--- a/python_modules/dissector.py
+++ b/python_modules/dissector.py
@@ -46,17 +46,14 @@ class HF:
hf_writer.variable_def("static int", "%s = -1" % self.hf_name)
def create(self):
- other = self.fields.get(self.ws_name)
+ other = self.fields.get(self.hf_name)
if other:
- for f in 'hf_name desc ws_name base vals mask'.split():
+ for f in 'hf_name desc ws_name f_type base vals mask'.split():
if other.__dict__[f] != self.__dict__[f]:
raise Exception('HF Field different from previous for\n\t%s\n\t%s' % (other, self))
- if other.f_type != self.f_type:
- if other.f_type[:7] != 'FT_UINT' or self.f_type[:7] != 'FT_UINT':
- raise Exception('HF Field different from previous for\n\t%s\n\t%s' % (other, self))
return
- self.fields[self.ws_name] = self
+ self.fields[self.hf_name] = self
self.add_wireshark_field()
@@ -296,6 +293,8 @@ def write_wireshark_field(writer, container, member, t, ws, tree, size, encoding
assert(member and container)
+ size_name = ''
+
# compute proper type
f_type = 'FT_NONE'
base = 'BASE_NONE'
@@ -304,6 +303,7 @@ def write_wireshark_field(writer, container, member, t, ws, tree, size, encoding
assert(t.is_primitive())
base = 'BASE_DEC'
f_type = get_primitive_ft_type(t)
+ size_name = str(t.get_fixed_nw_size() * 8)
if isinstance(t, ptypes.FlagsType):
# show flag as hexadecimal for now
base = 'BASE_HEX'
@@ -341,7 +341,7 @@ def write_wireshark_field(writer, container, member, t, ws, tree, size, encoding
hf_name = member_hf_name(container, member)
ws_name = 'auto.' + hf_name[3:]
else:
- hf_name = 'hf_%s' % ws_name.replace('.', '_')
+ hf_name = 'hf_%s%s' % (ws_name.replace('.', '_'), size_name)
writer.statement("%sproto_tree_add_item(%s, %s, glb->tvb, offset, %s, %s)" %
(prefix, tree, hf_name, size, encoding))
--
2.1.0
More information about the Spice-devel
mailing list