Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

sut_fw: return error from filter fun

If the filter dropped the packet (returned anything other than ok), the
firewall process would crash, rather than returning the value to the
caller.
  • Loading branch information...
commit de50fa82bd26610b40c8402c60de6d6227b45505 1 parent 3f20786
@msantos authored
Showing with 22 additions and 20 deletions.
  1. +22 −20 src/sut_fw.erl
View
42 src/sut_fw.erl
@@ -38,32 +38,34 @@
%% tun device -> socket
-out(Packet, #sut_state{
- filter_out = Fun,
- error_out = FunErr,
+out(Packet, #sut_state{filter_out = Fun} = State) ->
+ case Fun(Packet, State) of
+ ok -> to_sock(Packet, State);
+ {ok, NPacket} -> to_sock(NPacket, State);
+ Error -> Error
+ end.
+
+to_sock(Packet, #sut_state{
s = Socket,
+ error_out = FunErr,
serverv4 = Server
- } = State) ->
- {ok, Packet1} = case Fun(Packet, State) of
- ok -> {ok, Packet};
- {ok, N} -> {ok, N};
- Error -> Error
- end,
- ok = FunErr(gen_udp:send(Socket, Server, 0, Packet1)).
+ }) ->
+ ok = FunErr(gen_udp:send(Socket, Server, 0, Packet)).
%% socket -> tun device
-in(Packet, #sut_state{
- filter_in = Fun,
- error_in = FunErr,
- dev = Dev
- } = State) ->
+in(Packet, #sut_state{filter_in = Fun} = State) ->
ok = valid(Packet),
- {ok, Packet1} = case Fun(Packet, State) of
- ok -> {ok, Packet};
- {ok, N} -> {ok, N};
+ case Fun(Packet, State) of
+ ok -> to_tun(Packet, State);
+ {ok, NPacket} -> to_tun(NPacket, State);
Error -> Error
- end,
- ok = FunErr(tuncer:send(Dev, Packet1)).
+ end.
+
+to_tun(Packet, #sut_state{
+ dev = Dev,
+ error_in = FunErr
+ }) ->
+ ok = FunErr(tuncer:send(Dev, Packet)).
%%
Please sign in to comment.
Something went wrong with that request. Please try again.