Permalink
Browse files

add type specs

  • Loading branch information...
1 parent e9794d6 commit 8911e5890b616ca6ef7ad886be68590b33a5adf3 @RoadRunnr RoadRunnr committed Aug 4, 2011
Showing with 38 additions and 11 deletions.
  1. +33 −10 include/netlink.hrl
  2. +5 −1 src/netlink.erl
View
@@ -22,18 +22,41 @@
-define(NETLINK_SCSITRANSPORT, 18).
-define(NETLINK_ECRYPTFS, 19).
+-type flags() :: list(atom()).
+-type family() :: atom().
+-type protocol() :: atom().
+-type arphdr() :: atom().
+-type ifindex() :: non_neg_integer().
+-type resid() :: non_neg_integer().
+-type nla() :: list({atom(),term()}).
+-type ctnetlink_msg() :: {family(),non_neg_integer(),non_neg_integer(),list()}.
+-type rtnetlink_neigh() :: {family(),ifindex(),non_neg_integer(),flags(),non_neg_integer(),nla()}.
+-type rtnetlink_route() :: {family(),non_neg_integer(),non_neg_integer(),non_neg_integer(),non_neg_integer(),protocol(),non_neg_integer(),non_neg_integer(),flags(),nla()}.
+-type rtnetlink_addr() :: {family(),non_neg_integer(),flags(),non_neg_integer(),non_neg_integer(),nla()}.
+-type rtnetlink_link() :: {family(),arphdr(),non_neg_integer(),flags(),flags(),nla()}.
+-type rtnetlink_prefix() :: {family(),ifindex(),non_neg_integer(),non_neg_integer(),flags(),nla()}.
+-type rtnetlink_msg() :: rtnetlink_neigh() | rtnetlink_route() | rtnetlink_addr() | rtnetlink_link() | rtnetlink_prefix().
+
+-record(rtnetlink, {
+ type ::atom(),
+ flags ::list(atom()),
+ seq ::non_neg_integer(),
+ pid ::non_neg_integer(),
+ msg ::rtnetlink_msg()
+ }).
+
-record(ctnetlink, {
- type,
- flags,
- seq,
- pid,
- msg
+ type ::'new'|'get'|'delete'|'get_ctrzero',
+ flags ::flags(),
+ seq ::non_neg_integer(),
+ pid ::non_neg_integer(),
+ msg ::ctnetlink_msg()
}).
-record(ctnetlink_exp, {
- type,
- flags,
- seq,
- pid,
- msg
+ type ::'new'|'get'|'delete'|'get_ctrzero',
+ flags ::flags(),
+ seq ::non_neg_integer(),
+ pid ::non_neg_integer(),
+ msg ::ctnetlink_msg()
}).
View
@@ -659,6 +659,8 @@ ipctnl_msg(SubSys, Type) ->
sockaddr_nl(Family, Pid, Groups) ->
sockaddr_nl({Family, Pid, Groups}).
+-spec sockaddr_nl({atom()|integer(),integer(),integer()}) -> binary();
+ (binary()) -> {atom()|integer(),integer(),integer()}.
sockaddr_nl({Family, Pid, Groups}) when is_atom(Family) ->
sockaddr_nl({gen_socket:family(Family), Pid, Groups});
sockaddr_nl({Family, Pid, Groups}) ->
@@ -988,6 +990,7 @@ nlmsg_ok(DataLen, MsgLen) ->
nl_ct_dec_udp(<< _IpHdr:5/bytes, Data/binary >>) ->
nl_ct_dec(Data).
+-spec nl_ct_dec(binary()) -> [{'error',_} | #ctnetlink{} | #ctnetlink_exp{}].
nl_ct_dec(Msg) ->
nl_ct_dec(Msg, []).
@@ -1015,6 +1018,7 @@ nl_ct_dec(<< >>, Acc) ->
nl_rt_dec_udp(<< _IpHdr:5/bytes, Data/binary >>) ->
nl_rt_dec(Data).
+-spec nl_rt_dec(binary()) -> [{'error',_} | #rtnetlink{}].
nl_rt_dec(Msg) ->
nl_rt_dec(Msg, []).
@@ -1096,7 +1100,7 @@ nl_ct_enc({SubSys, MsgType, Flags, Seq, Pid, PayLoad})
when is_atom(SubSys), is_integer(MsgType) ->
Data = nl_enc_payload({SubSys}, MsgType, PayLoad),
Type = (nfnl_subsys(SubSys) bsl 8) bor MsgType,
- Flags0 = case MsgType of
+ Flags0 = case ipctnl_msg(SubSys, MsgType) of
new -> enc_flags(nlm_new_flags, Flags);
_ -> enc_flags(nlm_get_flags, Flags)
end,

0 comments on commit 8911e58

Please sign in to comment.