2 p_nsdp=Proto("nsdp", "Netgear Switch Description Protocol")
4 local f_version=ProtoField.uint8("nsdp.version", "Version", base.DEC)
5 local f_code=ProtoField.uint8("nsdp.code", "Operation Code", base.DEC)
6 local f_error=ProtoField.uint8("nsdp.error", "Error Code", base.DEC)
7 local f_errattr=ProtoField.uint16("nsdp.errattr", "Erroneous Attribute", base.HEX)
8 local f_clientmac=ProtoField.ether("nsdp.clientmac", "Client MAC")
9 local f_switchmac=ProtoField.ether("nsdp.switchmac", "Switch MAC")
10 local f_seqnum=ProtoField.uint32("nsdp.seqnum", "Sequence Number", base.DEC)
13 f_version, f_code, f_error, f_errattr, f_clientmac, f_switchmac, f_seqnum
31 [7]="Invalid Password"
42 local bitrates_codes={
58 local vlan_type_codes={
66 local qos_type_codes={
82 local function dissect_port_statistics (buffer, offset, subtree)
84 subtree:add(buffer(offset+4, 1), string.format("Port: %i", buffer(offset+4, 1):uint()))
85 subtree:add(buffer(offset+4+1+8*0, 8), "Received:", tostring(buffer(offset+4+1+8*0, 8):uint64()))
86 subtree:add(buffer(offset+4+1+8*1, 8), "Sent: ", tostring(buffer(offset+4+1+8*1, 8):uint64()))
87 subtree:add(buffer(offset+4+1+8*5, 8), "CRC Errors:", tostring(buffer(offset+4+1+8*5, 8):uint64()))
93 local function dissect_port_status (buffer, offset, subtree)
95 local st=buffer(offset+5, 1):uint()
96 subtree:add(buffer(offset+4, 1), string.format("Port: %i", buffer(offset+4, 1):uint()))
97 subtree:add(buffer(offset+5, 1), string.format("Status: %i (%s)", st, status_codes[st] or "unk"))
103 local function dissect_bitrate (buffer, offset, subtree)
105 local sp=buffer(offset+5, 4):uint()
106 subtree:add(buffer(offset+4, 1), string.format("Port: %i", buffer(offset+4, 1):uint()))
107 subtree:add(buffer(offset+5, 4), string.format("Speed: %i (%s)", sp, bitrates_codes[sp] or "unk"))
112 local function dissect_vlan_type (buffer, offset, subtree)
114 local vt=buffer(offset+4, 1):uint()
115 subtree:add(buffer(offset+4, 1), string.format("VLAN Type: %i (%s)", vt, vlan_type_codes[vt] or "unk"))
120 local function parse_ports (val)
128 val=math.floor(val/2)
136 local function dissect_vlan_8021q_conf (buffer, offset, subtree)
138 subtree:add(buffer(offset+4, 2), string.format("VLAN: %u", buffer(offset+4, 2):uint()))
140 if ( buffer(offset+2, 2):uint()>=4 ) then
141 subtree:add(buffer(offset+6, 1), "Ports:", parse_ports(buffer(offset+6, 1):uint()))
142 subtree:add(buffer(offset+7, 1), "Tagged Ports:", parse_ports(buffer(offset+7, 1):uint()))
148 local function dissect_vlan_pvid (buffer, offset, subtree)
150 subtree:add(buffer(offset+4, 1), string.format("Port: %i", buffer(offset+4, 1):uint()))
151 subtree:add(buffer(offset+5, 2), string.format("VLAN: %u", buffer(offset+5, 2):uint()))
157 local function dissect_mirror (buffer, offset, subtree)
159 local op=buffer(offset+4, 1):uint()
162 subtree:add(buffer(offset+4, 1), "Disabled")
164 subtree:add(buffer(offset+4, 1), "Output Port:", op)
165 subtree:add(buffer(offset+6, 1), "Ports:", parse_ports(buffer(offset+6, 1):uint()))
173 [0x0001]={name="Product", dissect="string"},
174 [0x0003]={name="Name", dissect="string"},
175 [0x0004]={name="MAC", dissect="ether"},
176 [0x0006]={name="IP", dissect="ipv4"},
177 [0x0007]={name="Mask", dissect="ipv4"},
178 [0x0008]={name="Gateway", dissect="ipv4"},
179 [0x0009]={name="New Password", dissect="string"},
180 [0x000A]={name="Password", dissect="string"},
181 [0x000B]={name="DHCP", dissect="uint"},
182 [0x000D]={name="Firmware Version", dissect="string"},
183 [0x0013]={name="Restart", dissect="uint"},
184 [0x0400]={name="Defaults", dissect="uint"},
185 [0x0C00]={name="Port Status", dissect=dissect_port_status},
186 [0x1000]={name="Port Statistics", dissect=dissect_port_statistics},
187 [0x1400]={name="Reset Ports Statistics", dissect="uint"},
188 [0x1800]={name="Cabletest Do", dissect=nil},
189 [0x1C00]={name="Cabletest Result", dissect=nil},
190 [0x2000]={name="VLAN Type", dissect=dissect_vlan_type},
191 [0x2400]={name="VLAN Port Conf", dissect=nil},
192 [0x2800]={name="VLAN 802.1Q Conf", dissect=dissect_vlan_8021q_conf},
193 [0x2C00]={name="Destroy VLAN", dissect="uint"},
194 [0x3000]={name="VLAN PVID", dissect=dissect_vlan_pvid},
195 [0x3400]={name="QoS Type", dissect=nil},
196 [0x3800]={name="QoS Config", dissect=nil},
197 [0x4C00]={name="Input Bitrate", dissect=dissect_bitrate},
198 [0x5000]={name="Output Bitrate", dissect=dissect_bitrate},
199 [0x5400]={name="Broadcast Filtering State", dissect="uint"},
200 [0x5800]={name="Broadcast Filtering Bitrate", dissect=dissect_bitrate},
201 [0x5C00]={name="Mirror", dissect=dissect_mirror},
202 [0x6000]={name="Ports Count", dissect="uint"},
203 [0x6800]={name="IGMP Enable & VLAN", dissect=nil},
204 [0x6C00]={name="Block Unknown IGMP Addresses", dissect="uint"},
205 [0x7000]={name="Validate IGMPv3 Headers", dissect="uint"},
206 [0xFFFF]={name="End", dissect=nil}
214 local function dissect_header (buffer, subtree)
216 subtree:add(f_version, buffer(0, 1))
218 subtree:add(f_code, buffer(1, 1)):append_text(" ("..(op_codes[buffer(1, 1):uint()] or "unknown")..")")
220 local errcode=buffer(2, 1):uint()
221 subtree:add(f_error, buffer(2, 1)):append_text(" ("..(error_codes[errcode] or "unknown")..")")
223 -- add the erroneous attribute only if an error occurred
224 if ( errcode~=0 ) then
225 local atf=attributes[buffer(4, 2):uint()]
226 subtree:add(f_errattr, buffer(4, 2)):append_text(" ("..(atf and atf.name or "unk")..")")
229 subtree:add(f_clientmac, buffer(8, 6))
231 subtree:add(f_switchmac, buffer(14, 6))
233 subtree:add(f_seqnum, buffer(20, 4))
240 local function dissect_attributes (buffer, subtree)
244 while ( offset<buffer:len() ) do
246 if ( offset+4>buffer:len() ) then
247 -- no room for an attribute header, it is an error
248 subtree:add(buffer(offset), "Junk"):set_expert_flags(PI_MALFORMED, PI_ERROR)
252 local code=buffer(offset, 2):uint()
253 local len=buffer(offset+2, 2):uint()
254 local atf=attributes[code]
256 local attr=subtree:add(buffer(offset, math.min(4+len, buffer:len()-offset)), string.format("Attribute: 0x%04X (%s)", code, atf and atf.name or "unk"))
257 attr:add(buffer(offset, 2), string.format("Code: 0x%04X", code))
258 attr:add(buffer(offset+2, 2), string.format("Length: %u", len))
260 if ( offset+4+len>buffer:len() ) then
261 -- attribute length is bigger than remaining packet size, it is an error
262 attr:append_text(" [malformed]")
263 attr:set_expert_flags(PI_MALFORMED, PI_ERROR)
269 -- no data, display nothing
270 elseif ( atf==nil or atf.dissect==nil ) then
271 -- unknown attribute, display raw bytes
272 attr:add(buffer(offset+4, len), "Data:", tostring(buffer(offset+4, len):bytes()))
273 elseif ( type(atf.dissect)=="function" ) then
274 -- custom sub-dissector for complex type
275 atf.dissect(buffer, offset, attr)
277 -- simple type, directly show it
278 local func=assert(loadstring("return function(buffer, offset, len) return tostring(buffer(offset+4, len):"..atf.dissect.."()) end"))() -- ugly, isn't it ?
279 attr:add(buffer(offset+4, len), atf.name..":", func(buffer, offset, len))
290 function p_nsdp.dissector (buffer, pinfo, tree)
292 pinfo.cols.protocol=p_nsdp.name
293 local subtree=tree:add(p_nsdp, buffer())
295 -- stop if the packet is too small to be valid
296 if ( buffer:len()<32 ) then return end
298 dissect_header(buffer, subtree)
300 -- stop if it is just a header
301 if ( buffer:len()==32 ) then return end
303 local attr_list=subtree:add(buffer(32), "Attributes list")
304 dissect_attributes(buffer, attr_list)
310 function p_nsdp.init ()
315 local udp_dissector_table=DissectorTable.get("udp.port")
316 dissector=udp_dissector_table:get_dissector(63322)
317 udp_dissector_table:add(63322, p_nsdp)