Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Let the caller handle send errors

For the moment, ignore any send errors in both directions. Error messages
are printed to the shell if there is an error (badmatch).

Likely the caller wants the tunnel to stay up for transient issues, for
example if the interface goes down ({error,enetunreach}) and might come
up again. In the case of fatal issues (bad fd, ...), we should shutdown
the tunnel.

There are 2 problems:

* the message flow will not be in one direction, e.g.,

    socket -> filter -> tun

  Instead the filter would call into the socket/tun and shut down the
  gen_server killing the tunnel. This makes the system hard to
  understand.

* tuncer:send/2 is a wrapper around erlang:port_command/2. Not sure what
  values it returns. The documentation says badarg. tuncer wraps the
  port_command in a try/catch and returns an error tuple.

  gen_udp:send returns {error, posix()}. tuncer should do the same.
  • Loading branch information...
commit 28aaeaccab858843259a8bbabcb3a90a8870e2f6 1 parent 1666044
@msantos authored
Showing with 8 additions and 9 deletions.
  1. +0 −5 README.md
  2. +4 −0 include/sut.hrl
  3. +4 −4 src/sut_fw.erl
View
5 README.md
@@ -108,9 +108,4 @@ sut, an IPv6 in IPv4 Userlspace Tunnel (RFC 4213)
* Support other checks required by RFC
-* Decide how to handle write failures to the network and tun device
-
- * possible packets may fail before interface is fully configured
- (routes set up, etc)
-
* Make a firewall ruleset to Erlang compiler
View
4 include/sut.hrl
@@ -44,9 +44,13 @@
serverv4,
clientv4,
clientv6,
+
filter_out = fun(_Packet, _State) -> ok end,
filter_in = fun(_Packet, _State) -> ok end,
+ error_out = fun(ok) -> ok; (Error) -> Error end,
+ error_in = fun(ok) -> ok; (Error) -> Error end,
+
s,
fd,
dev
View
8 src/sut_fw.erl
@@ -37,11 +37,10 @@
]).
-%% XXX send failures are ignored
-
%% tun device -> socket
out(Packet, #sut_state{
filter_out = Fun,
+ error_out = Err,
s = Socket,
serverv4 = Server
} = State) ->
@@ -50,11 +49,12 @@ out(Packet, #sut_state{
{ok, N} -> {ok, N};
Err -> Err
end,
- ok = gen_udp:send(Socket, Server, 0, Packet1).
+ ok = Err(gen_udp:send(Socket, Server, 0, Packet1)).
%% socket -> tun device
in(Packet, #sut_state{
filter_in = Fun,
+ error_in = Err,
dev = Dev
} = State) ->
ok = valid(Packet),
@@ -63,7 +63,7 @@ in(Packet, #sut_state{
{ok, N} -> {ok, N};
Err -> Err
end,
- ok = tuncer:send(Dev, Packet1).
+ ok = Err(tuncer:send(Dev, Packet1)).
%%
Please sign in to comment.
Something went wrong with that request. Please try again.