Skip to content

Commit

Permalink
HevSocks5Tunnel: Cleanup DNS server.
Browse files Browse the repository at this point in the history
  • Loading branch information
heiher committed May 11, 2021
1 parent 2476180 commit 4551970
Showing 1 changed file with 0 additions and 40 deletions.
40 changes: 0 additions & 40 deletions src/hev-socks5-tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ static int event_fds[2];
static struct netif netif;
static struct tcp_pcb *tcp;
static struct udp_pcb *udp;
static struct udp_pcb *dns;

static HevTaskMutex mutex;
static HevTask *task_event;
Expand All @@ -61,8 +60,6 @@ static void session_manager_task_entry (void *data);
static err_t tcp_accept_handler (void *arg, struct tcp_pcb *pcb, err_t err);
static void udp_recv_handler (void *arg, struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *addr, u16_t port);
static void dns_recv_handler (void *arg, struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *addr, u16_t port);

int
hev_socks5_tunnel_init (int tunfd)
Expand Down Expand Up @@ -146,7 +143,6 @@ hev_socks5_tunnel_init (int tunfd)
exit_free_task_event:
hev_task_unref (task_event);
exit_free_gateway:
udp_remove (dns);
udp_remove (udp);
tcp_close (tcp);
netif_remove (&netif);
Expand All @@ -169,7 +165,6 @@ hev_socks5_tunnel_fini (void)
hev_task_unref (task_lwip_io);
hev_task_unref (task_event);

udp_remove (dns);
udp_remove (udp);
tcp_close (tcp);
netif_remove (&netif);
Expand Down Expand Up @@ -332,11 +327,9 @@ static int
gateway_init (void)
{
const char *ipv4, *ipv6;
unsigned int port;

ipv4 = hev_config_get_tunnel_ipv4_gateway ();
ipv6 = hev_config_get_tunnel_ipv6_gateway ();
port = hev_config_get_tunnel_dns_port ();

if (!netif_add_noaddr (&netif, NULL, netif_init_handler, ip_input)) {
LOG_E ("Create lwip net interface failed!");
Expand Down Expand Up @@ -390,20 +383,6 @@ gateway_init (void)

tcp_accept (tcp, tcp_accept_handler);

dns = udp_new ();
if (!dns) {
LOG_E ("Create UDP failed!");
goto exit_free_tcp;
}

udp_bind_netif (dns, &netif);
if (udp_bind (dns, IP_ANY_TYPE, port) != ERR_OK) {
LOG_E ("UDP bind failed!");
goto exit_free_dns;
}

udp_recv (dns, dns_recv_handler, NULL);

udp = udp_new_ip_type (IPADDR_TYPE_ANY);
if (!udp) {
LOG_E ("Create UDP failed!");
Expand All @@ -420,8 +399,6 @@ gateway_init (void)

return 0;

exit_free_dns:
udp_remove (dns);
exit_free_udp:
udp_remove (udp);
exit_free_tcp:
Expand Down Expand Up @@ -617,20 +594,3 @@ udp_recv_handler (void *arg, struct udp_pcb *pcb, struct pbuf *p,
session_manager_insert_session (session);
hev_socks5_session_run (session);
}

static void
dns_recv_handler (void *arg, struct udp_pcb *pcb, struct pbuf *p,
const ip_addr_t *addr, u16_t port)
{
HevSocks5Session *session;

session = hev_socks5_session_new_dns (pcb, p, addr, port, &mutex,
session_close_handler);
if (!session) {
pbuf_free (p);
return;
}

session_manager_insert_session (session);
hev_socks5_session_run (session);
}

0 comments on commit 4551970

Please sign in to comment.