Skip to content

Commit

Permalink
Issue 47: Handle unknown LLDP PDUs gracefully
Browse files Browse the repository at this point in the history
When an unknown TLV is received, whose type does not match any of the ones that are currently handled, even though the PDU is good, pkt_lldp crashes as such a packet is not handled. Wireshark shows that packet as unknown TLV. Doing the same here.
  • Loading branch information
vasu-dasari committed Apr 24, 2019
1 parent e208c72 commit e0611f7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion include/pkt_lldp.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@
-record(organizationally_specific, { value = <<>> :: binary() }).
-type organizationally_specific() :: #organizationally_specific{}.

-record(unknown_lldp_tlv,{type = 0:: integer(), value = <<>> :: binary()}).
-type unknown_lldp_tlv() :: #unknown_lldp_tlv{}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% LLDP Frame Format
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand All @@ -153,7 +156,8 @@
| system_desc()
| system_capability()
| management_address()
| organizationally_specific().
| organizationally_specific()
| unknown_lldp_tlv().

-record(lldp, { pdus = [] :: [pdu()] }).
-type lldp() :: #lldp{}.
4 changes: 4 additions & 0 deletions src/pkt_lldp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ decode(<<?MANAGEMENT_ADDRESS:7, Length:9,
decode(<<?ORGANIZATIONALLY_SPECIFIC:7, Length:9,
Value:Length/bytes, Rest/bytes>>, Acc) ->
Pdu = #organizationally_specific{ value = Value },
decode(Rest, [Pdu | Acc]);
decode(<<Type:7, Length:9,
Value:Length/bytes, Rest/bytes>>, Acc) ->
Pdu = #unknown_lldp_tlv{ type = Type, value = Value },
decode(Rest, [Pdu | Acc]).

encode([], Binary) -> Binary;
Expand Down

0 comments on commit e0611f7

Please sign in to comment.