Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

freebsd: add support for multi-af mode

multi-af mode is similar to the protocol info on linux. Force the BSD
interface to be similar the linux interface:

* if no options are passed to the tun device, protocol info is enabled

* no_pi is a default option

* flags is always 0 (FreeBSD and Mac OS X)

* protocol is 4 bytes (2 bytes on Linux)

* on FreeBSD, only tun devices support multi-af mode
  • Loading branch information...
commit 070116033a0e1f949eac5edb610115a803657a33 1 parent a3cf932
@msantos authored
View
1  include/tuntap.hrl
@@ -32,6 +32,7 @@
-define(SIZEOF_INT, 4).
-define(SIZEOF_UNSIGNED_INT, ?SIZEOF_INT).
-define(UINT16, 2/native-unsigned-integer-unit:8).
+-define(UINT32, 4/native-unsigned-integer-unit:8).
% ifconfig
-define(IFF_RUNNING, 16#40).
View
5 src/tunctl.erl
@@ -90,8 +90,9 @@ down(Dev) when byte_size(Dev) < ?IFNAMSIZ ->
Module:down(Dev).
-header(<<Flags:?UINT16, Proto:?UINT16, Buf/binary>>) ->
- {tun_pi, Flags, Proto, Buf}.
+header(Packet) ->
+ Module = os(),
+ Module:header(Packet).
%%--------------------------------------------------------------------
View
8 src/tunctl_darwin.erl
@@ -38,7 +38,9 @@
create/2,
persist/2,
owner/2, group/2,
- up/2, down/1
+ up/2, down/1,
+
+ header/1
]).
-define(TUNSIFHEAD, ?IOW($t, 96, ?SIZEOF_INT)).
@@ -102,6 +104,10 @@ down(Dev) when byte_size(Dev) < ?IFNAMSIZ ->
end.
+header(<<Proto:?UINT32, Buf/binary>>) ->
+ {tun_pi, 0, Proto, Buf}.
+
+
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
View
27 src/tunctl_freebsd.erl
@@ -41,16 +41,17 @@
create/2,
persist/2,
owner/2, group/2,
- up/2, down/1
+ up/2, down/1,
+
+ header/1
]).
-define(SIZEOF_STRUCT_IFALIASREQ, 64).
-define(SIOCAIFADDR, ?IOW($i, 26, ?SIZEOF_STRUCT_IFALIASREQ)).
--define(TAPGIFNAME, ?IOR('t', 93, ?SIZEOF_STRUCT_IFREQ)).
-
--define(TUNDEV, "tap").
+-define(TAPGIFNAME, ?IOR($t, 93, ?SIZEOF_STRUCT_IFREQ)).
+-define(TUNSIFHEAD, ?IOW($t, 96, ?SIZEOF_INT)).
%%--------------------------------------------------------------------
@@ -60,14 +61,24 @@ create(<<>>, Opt) ->
create(<<"tap0">>, Opt);
%% Ignore the options for now
-create(Ifname, _Opt) when byte_size(Ifname) < ?IFNAMSIZ ->
+create(Ifname, Opt) when byte_size(Ifname) < ?IFNAMSIZ ->
case procket:dev(binary_to_list(Ifname)) of
{ok, FD} ->
- {ok, FD, Ifname};
+ create_1(FD, Ifname, Opt);
Error ->
Error
end.
+create_1(FD, Ifname, Opt) ->
+ case {Ifname, proplists:get_bool(no_pi, Opt)} of
+ {<<"tun", _/binary>>, false} ->
+ ok = tunctl:ioctl(FD, ?TUNSIFHEAD, 1);
+ _ ->
+ % TUNSIFHEAD isn't supported by tap devices
+ ok
+ end,
+ {ok, FD, Ifname}.
+
%% N/A
persist(_FD, _Status) ->
@@ -98,6 +109,10 @@ down(Dev) when byte_size(Dev) < ?IFNAMSIZ ->
end.
+header(<<Proto:?UINT32, Buf/binary>>) ->
+ {tun_pi, 0, Proto, Buf}.
+
+
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
View
8 src/tunctl_linux.erl
@@ -38,7 +38,9 @@
create/2,
persist/2,
owner/2, group/2,
- up/2, down/1
+ up/2, down/1,
+
+ header/1
]).
@@ -131,6 +133,10 @@ down(Dev) when byte_size(Dev) < ?IFNAMSIZ ->
Res.
+header(<<Flags:?UINT16, Proto:?UINT16, Buf/binary>>) ->
+ {tun_pi, Flags, Proto, Buf}.
+
+
%%--------------------------------------------------------------------
%%% Internal functions
%%--------------------------------------------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.