Permalink
Browse files

Move the tuntap interface to a separate repository

  • Loading branch information...
1 parent 639408a commit 9439916860bbbd47837c4cd1dee6fe27f4d21371 @msantos committed May 13, 2011
Showing with 0 additions and 150 deletions.
  1. +0 −1 ebin/procket.app
  2. +0 −56 include/tuntap.hrl
  3. +0 −93 src/tuntap.erl
View
@@ -7,7 +7,6 @@
procket_ioctl,
packet,
bpf,
- tuntap,
mktmp,
icmp,
echo
View
@@ -1,56 +0,0 @@
-%% Copyright (c) 2011, Michael Santos <michael.santos@gmail.com>
-%% All rights reserved.
-%%
-%% Redistribution and use in source and binary forms, with or without
-%% modification, are permitted provided that the following conditions
-%% are met:
-%%
-%% Redistributions of source code must retain the above copyright
-%% notice, this list of conditions and the following disclaimer.
-%%
-%% Redistributions in binary form must reproduce the above copyright
-%% notice, this list of conditions and the following disclaimer in the
-%% documentation and/or other materials provided with the distribution.
-%%
-%% Neither the name of the author nor the names of its contributors
-%% may be used to endorse or promote products derived from this software
-%% without specific prior written permission.
-%%
-%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-%% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-%% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-%% FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-%% COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-%% INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-%% BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-%% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-%% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-%% LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-%% ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-%% POSSIBILITY OF SUCH DAMAGE.
-
--define(SIZEOF_INT, 4).
--define(SIZEOF_UNSIGNED_INT, ?SIZEOF_INT).
-
-% Ioctl defines
--define(TUNSETNOCSUM, ?IOW($T, 200, ?SIZEOF_INT)).
--define(TUNSETDEBUG, ?IOW($T, 201, ?SIZEOF_INT)).
--define(TUNSETIFF, ?IOW($T, 202, ?SIZEOF_INT)).
--define(TUNSETPERSIST, ?IOW($T, 203, ?SIZEOF_INT)).
--define(TUNSETOWNER, ?IOW($T, 204, ?SIZEOF_INT)).
--define(TUNSETLINK, ?IOW($T, 205, ?SIZEOF_INT)).
--define(TUNSETGROUP, ?IOW($T, 206, ?SIZEOF_INT)).
--define(TUNGETFEATURES, ?IOR($T, 207, ?SIZEOF_UNSIGNED_INT)).
--define(TUNSETOFFLOAD, ?IOW($T, 208, ?SIZEOF_UNSIGNED_INT)).
--define(TUNSETTXFILTER, ?IOW($T, 209, ?SIZEOF_UNSIGNED_INT)).
--define(TUNGETIFF, ?IOR($T, 210, ?SIZEOF_UNSIGNED_INT)).
--define(TUNGETSNDBUF, ?IOR($T, 211, ?SIZEOF_INT)).
--define(TUNSETSNDBUF, ?IOW($T, 212, ?SIZEOF_INT)).
-
-% TUNSETIFF ifr flags
--define(IFF_TUN, 16#0001).
--define(IFF_TAP, 16#0002).
--define(IFF_NO_PI, 16#1000).
--define(IFF_ONE_QUEUE, 16#2000).
--define(IFF_VNET_HDR, 16#4000).
--define(IFF_TUN_EXCL, 16#8000).
View
@@ -1,93 +0,0 @@
-%% Copyright (c) 2011, Michael Santos <michael.santos@gmail.com>
-%% All rights reserved.
-%%
-%% Redistribution and use in source and binary forms, with or without
-%% modification, are permitted provided that the following conditions
-%% are met:
-%%
-%% Redistributions of source code must retain the above copyright
-%% notice, this list of conditions and the following disclaimer.
-%%
-%% Redistributions in binary form must reproduce the above copyright
-%% notice, this list of conditions and the following disclaimer in the
-%% documentation and/or other materials provided with the distribution.
-%%
-%% Neither the name of the author nor the names of its contributors
-%% may be used to endorse or promote products derived from this software
-%% without specific prior written permission.
-%%
-%% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-%% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-%% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-%% FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-%% COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-%% INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-%% BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-%% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-%% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-%% LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-%% ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-%% POSSIBILITY OF SUCH DAMAGE.
--module(tuntap).
-
--include("ioctl.hrl").
--include("tuntap.hrl").
-
--export([
- create/0, create/1, create/2,
- persist/2, destroy/1,
- owner/2, group/2
- ]).
-
-
-create() ->
- create(<<0:(15*8)>>, [tap, no_pi]).
-create(Ifname) ->
- create(Ifname, [tap, no_pi]).
-
-create(Ifname, Opt) when is_list(Ifname) ->
- create(list_to_binary(Ifname), Opt);
-create(Ifname, Opt) when byte_size(Ifname) < 16, is_list(Opt) ->
- Flags = lists:foldl(fun(N, F) -> F bor flag(N) end, 0, Opt),
-
- {ok, FD} = procket:dev("net/tun"),
- {ok, Dev} = procket:ioctl(FD, ?TUNSETIFF,
- <<Ifname/binary, 0:((15*8) - (byte_size(Ifname)*8)), 0:8, % ifrn_name[IFNAMSIZ]: interface name
- Flags:2/native-signed-integer-unit:8, % ifru_flags
- 0:(14*8)>>),
- {ok, FD, hd(binary:split(Dev, <<0>>))}.
-
-persist(FD, Bool) when is_integer(FD) ->
- ioctl(FD, ?TUNSETPERSIST, bool(Bool)).
-
-destroy(FD) when is_integer(FD) ->
- persist(FD, false).
-
-owner(FD, Owner) when is_integer(FD), is_integer(Owner) ->
- ioctl(FD, ?TUNSETOWNER, int_to_bin(Owner)).
-
-group(FD, Group) when is_integer(FD), is_integer(Group) ->
- ioctl(FD, ?TUNSETGROUP, int_to_bin(Group)).
-
-
-%%-------------------------------------------------------------------------
-%%% Internal functions
-%%-------------------------------------------------------------------------
-ioctl(FD, Request, Opt) ->
- case procket:ioctl(FD, Request, Opt) of
- {ok, _} -> ok;
- Error -> Error
- end.
-
-flag(tun) -> ?IFF_TUN;
-flag(tap) -> ?IFF_TAP;
-flag(no_pi) -> ?IFF_NO_PI;
-flag(one_queue) -> ?IFF_ONE_QUEUE;
-flag(vnet_hdr) -> ?IFF_VNET_HDR;
-flag(tun_excl) -> ?IFF_TUN_EXCL.
-
-int_to_bin(Int) ->
- <<Int:4/native-integer-unsigned-unit:8>>.
-
-bool(true) -> <<1:4/native-integer-unsigned-unit:8>>;
-bool(false) -> <<0:4/native-integer-unsigned-unit:8>>.

0 comments on commit 9439916

Please sign in to comment.