masque_udp_proxy_handler (masque v0.7.0)
View SourceBuilt-in MASQUE handler that bridges a CONNECT-UDP tunnel to a real UDP flow on the server.
For every accepted tunnel the handler opens a gen_udp socket bound to ephemeral port and a specific family, resolves the target hostname, and relays bytes in both directions:
- Client-to-target:
handle_packet/2sends the payload to the resolved target on the UDP socket. - Target-to-client:
{udp, Socket, _, _, Bytes}messages arrive on the session process and are emitted assendactions back through the tunnel.
Configure policy via handler_opts:
allow => fun(target()) -> boolean()- gate on host+port.resolver => fun(binary()) -> {ok, inet:ip_address()} | {error, term()}- override the defaultinet:getaddr/2resolver.family => inet | inet6 | auto(defaultauto).socket_opts => [gen_udp:option()]- extra options merged on top of[binary, {active, true}].port => inet:port_number()- bind the local UDP socket to a fixed port. Default0(kernel-assigned ephemeral). Useful for firewall rules; conflicts with concurrent tunnels that share a listener.
Summary
Functions
-spec accept(masque_handler:req()) -> masque_handler:accept_result().
-spec handle_info(term(), #state{socket :: gen_udp:socket(), target_ip :: inet:ip_address(), target_port :: 1..65535}) -> {ok, #state{socket :: gen_udp:socket(), target_ip :: inet:ip_address(), target_port :: 1..65535}} | {ok, #state{socket :: gen_udp:socket(), target_ip :: inet:ip_address(), target_port :: 1..65535}, [term()]} | {stop, term(), #state{socket :: gen_udp:socket(), target_ip :: inet:ip_address(), target_port :: 1..65535}}.
-spec handle_packet(binary(), #state{socket :: gen_udp:socket(), target_ip :: inet:ip_address(), target_port :: 1..65535}) -> {ok, #state{socket :: gen_udp:socket(), target_ip :: inet:ip_address(), target_port :: 1..65535}} | {stop, term(), #state{socket :: gen_udp:socket(), target_ip :: inet:ip_address(), target_port :: 1..65535}}.
-spec init(masque_handler:req(), term()) -> {ok, #state{socket :: gen_udp:socket(), target_ip :: inet:ip_address(), target_port :: 1..65535}} | {stop, term()}.
-spec terminate(term(), #state{socket :: gen_udp:socket(), target_ip :: inet:ip_address(), target_port :: 1..65535}) -> ok.