Thrift: Add support for expert info on exceptions in sub-dissectors
While working on some sub-dissector, it occurred to me that there was no easy way for sub-dissector to mark the exceptions with specific expert info. In fact, in some of the example sub-dissectors in the wiki, I had to use some workaround to mark the exceptions with expert info.
The first commit is there only to separate the documentation-related changes (comments only) that I saw since last update, I’ll squash everything before the merge.
The second commit is the real deal:
- New field in the public structure
thrift_member_t
to hold a pointer to possible expert info related to astruct
(whichexception
s really are). - New public
dissect_thrift_t_exception()
function with one more parameter (comparing to struct). -
dissect_thrift_t_struct()
implementation becomes just a call to the new function with the last parameter set toNULL
. - In the implementation, we attach the expert info (if provided) to the structure.
The third commit implement the changes suggested by point 3 below.
Now, I still have several points that might be worth discussing regarding the whole thing:
- The new expert info field is only available for structures but to all structures, including unions. Would it be pertinent to make it available for all types in case the sub-dissector has the use for it?
- All
dissect_thrift_t_<type>()
would have to be doubled or rather the new parameter would have to be added everywhere. -
❌ I would argue against it and consider the sub-dissectors to use this feature for exceptions only.
- All
- All existing sub-dissectors will have to update their code to handle this new element when dealing with structure. Do you think it’s safe enough this way?
- The risk I see is that the uninitialized field leads to a crash if it happens to result in a non-NULL value but only for the sub-dissector which would have to be recompiled.
- The change remains quite straightforward and is taken care of with
:%s/\({ \)\(\.members = \w\+\)\( }\)/\1.s\2, .s.expert_info = NULL\3/g
in Vim. It will of course change depending on the editor used but the point is that a global automatic replacement does the work. - Note: If we decide to generalize (first question), part of it can be taken care of in the
TMFILL
definition but containers,binary
,string
, andstruct
s will still need some changes. -
✅ Since the change will only happen in a major version (hopefully 4.1/4.2 but it might be short so probably 4.3/4.4), the sub-dissectors will have to be recompiled anyway.
- Using
dissect_thrift_t_exception()
directly does not seem practical, do you think it would be better to keep it internal?- Since the exception are always exclusive to each others and to the result, it seems much easier to use them through the definition of a
union
as demonstrated in the wiki page and the example sub-dissectors. - If the sub-dissector wanted to do it anyway, they would have to add a switch on the field id of the reply (available in
thrift_opt->reply_field_id
as demonstrated in the firstTCustom
toy example. This switch would have to be done everywhere, which quickly become tedious. - If made internal, I would probably rename it (dissect_thrift_t_struct_expert or something like that).
-
✅ I would think it’s better to keep it internal for simplicity.
- Since the exception are always exclusive to each others and to the result, it seems much easier to use them through the definition of a
- Since
thrift_opt->reply_field_id
would no longer be necessary given the new feature, do you think it would be pertinent to remove it in the process?- While it would slightly simplify the code in
dissect_thrift_common()
by removing a block and reduce the size ofthrift_option_t
, it might break existing sub-dissectors (theTCustom
sample does not really count). -
❌ I don’t think the gain is enough to break existing sub-dissectors (the change is much bigger than a replace-all).
- While it would slightly simplify the code in
- Do you know if there is any merged Thrift-based sub-dissector I should update in the process?
-
✅ I did not find any while searching forpacket-thrift.h
inepan
andplugin/epan
directories so I think it’s fine.
-
- Do you have any other remark/question/improvement proposal?
Everything is fine on my side, I started using the new capability in my sub-dissectors.
Edited by Triton Circonflexe