Skip to content

Commit

Permalink
Fix BSD NULL (loopback) IPv6 protocol decode
Browse files Browse the repository at this point in the history
The NULL linktype used by the loopback interface on BSD systems uses
the PF_* value to indicate the next data type. For IPv6, the value of
PF_INET6 was (amusingly) hardcoded to the value on linux systems and so
decoding of IPv6 NULL packets has always been broken.

The NULL linktype is unusual because it depends on runtime values: the
protocol family, which differs by OS and the native host endianness for
packing the protocol family. Deal with this by looking up the protocol
family and endianness at runtime. Note this means that IPv6 BSD NULL
packets cannot be decoded on other OS'es (the PF_INET6 value may differ)
or on architectures of the opposite endianness.

Reported in:

#23

Thanks to 2b-as for reporting the problem!
  • Loading branch information
msantos committed Jan 29, 2015
1 parent caa8da5 commit 5b1424a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/pkt.app.src
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{application, pkt, [
{description, "Network packet parsing library"},
{vsn, "0.4.2"},
{vsn, "0.4.3"},
{applications, [kernel, stdlib]}
]}.
10 changes: 8 additions & 2 deletions src/pkt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,15 @@ proto(N) ->
ipproto(N) ->
pkt_ipproto:codec(N).

%% Protocol families
%% Protocol families: BSD NULL (loopback) linktype
family(?PF_INET) -> ipv4;
family(?PF_INET6) -> ipv6.
family(Family) ->
case {os:type(), Family} of
{{unix,darwin}, 30} -> inet6;
{{unix,freebsd}, 28} -> inet6;
{{unix,netbsd}, 24} -> inet6;
{{unix,openbsd}, 24} -> inet6
end.

%%
%% Utility functions
Expand Down

0 comments on commit 5b1424a

Please sign in to comment.