I am making Lua script to dissect BGP protocol. It has many path attributes and within each other values...: I can dissect all writing if conditions, but I think there is a easier and effectively way to dissect all values. BGP reference: https://tools.ietf.org/html/rfc4271 asked 11 May '16, 03:53 javiguembe |
One Answer:
You may want to read the part of Lua manual which deals with data types named Tables, and make use of the Wireshark's Lua API's ability to use Lua tables as number to string translation vocabularies. An example from one of my ad hoc Lua dissectors:
As for dealing with the higher 4 bits of the MSB, a forged example of what you could do for two bits, X and Y, where each value of each bit has to be translated to a string and the values of the bits do not affect each other, you can translate all four numeric combinations to concatenations of strings which you then split using a separator character:
answered 11 May ‘16, 09:52 sindy Thanks for answer !! Is a god answer, but I know that I can make tables to dissect a lot of posible values. In fact, I use it to dissect Attribute types using Attribute type codes (see picture above). Althougth, my question is; How to dissect Attribute Values (the last column) effectively. I said that because Attribute Values depends on fields before it: Attribute type, class and attribute value code. So I have to make if conditionals like: if(attribute_type_cod ==1 && flag_o ==0) then subtree:add (attr_values1_withtable,buf(x,x)) end I need to do 10 conditionals like this, other there is another way to do? (12 May ‘16, 02:00) javiguembe
Well, the quality of the question has a large impact on the quality of the answer :-) So rather than pasting the screenshot of a table (which seems inconsistent until you look into the RFC you’ve given a link to), it would have been better to write that you need to translate numeric values of protocol field A to text ones in several different ways, choosing the appropriate way up to the numeric value of protocol field B. For Lua in general, there is a page suggesting several possible implementations of “case” (Pascal) or “switch” (C, Java) replacement of a bunch of “if” statements to choose a branch of algorithm to be executed. But as we talk about Wireshark’s Lua API here, we’d like to have the possibility to use Lua tables to translate the numeric values of parameters to text names so that they could be used for filtering, printing using tshark etc. I haven’t tested that yet, but as the “values” in a Lua table may be variables (of any type, even other tables), it should be possible to do the following (example simplified to illustrative minimum):
(12 May ‘16, 12:31) sindy …continuation: As a Lua table may contain another table, you can also individually extract the values of bits O, T, P, E and use them as additional key values as shown below, provided that you create a corresponding hierarchy of tables.
While you can define tables (of tables) using a compact notation, like
, doing so will automatically generate the keys as monotonous sequences of numeric values starting from of 1, so you’ll get the following values:
Therefore, you have to construct the individual levels of the tables “manually”, which will allow you to specify the keys as necessary (O,T,P,E values chosen randomly):
While the Wireshark’s Lua API will handle translation of a key for which no value is given in the table referred to in the protocol field specification very simply, by displaying “Unknown” in the packet dissection pane, things won’t go that easy if you ask TreeItem:add to add a non-existent protocol field. Therefore, you’ll likely want to check first whether attr_type_table[TypeCode][O][T][P][E] returns a value (a variable holding a reference to a protocol field descriptor), and only execute the TreeItem:add if it does. (12 May ‘16, 14:24) sindy |
Is there an issue with the existing c-based BGP dissector?
No, but I want to do it to practice.