Ticket #328: 328-socks-proxy-timeout.patch

File 328-socks-proxy-timeout.patch, 4.1 KB (added by anon_tor_user, 6 years ago)

Patch to allow configuration of the socks proxy timeout

  • src/openvpn/init.c

    diff --git a/src/openvpn/init.c b/src/openvpn/init.c
    index c2907cd..1d7b51e 100644
    a b init_proxy_dowork (struct context *c) 
    493493      c->c1.socks_proxy = socks_proxy_new (c->options.ce.socks_proxy_server,
    494494                                           c->options.ce.socks_proxy_port,
    495495                                           c->options.ce.socks_proxy_authfile,
    496                                            c->options.ce.socks_proxy_retry);
     496                                           c->options.ce.socks_proxy_retry,
     497                                           c->options.ce.socks_proxy_timeout);
    497498      if (c->c1.socks_proxy)
    498499        {
    499500          c->c1.socks_proxy_owned = true;
  • src/openvpn/options.c

    diff --git a/src/openvpn/options.c b/src/openvpn/options.c
    index 18cb354..f6cad1b 100644
    a b static const char usage_message[] = 
    163163  "                  up is a file containing username/password on 2 lines, or\n"
    164164  "                  'stdin' to prompt for console.\n"
    165165  "--socks-proxy-retry : Retry indefinitely on Socks proxy errors.\n"
     166  "--socks-proxy-timeout n : Proxy timeout in seconds, default=5.\n"
    166167#endif
    167168  "--resolv-retry n: If hostname resolve fails for --remote, retry\n"
    168169  "                  resolve for n seconds before failing (disabled by default).\n"
    add_option (struct options *options, 
    51265127      VERIFY_PERMISSION (OPT_P_GENERAL|OPT_P_CONNECTION);
    51275128      options->ce.socks_proxy_retry = true;
    51285129    }
     5130  else if (streq (p[0], "socks-proxy-timeout") && p[1])
     5131    {
     5132      VERIFY_PERMISSION (OPT_P_GENERAL|OPT_P_CONNECTION);
     5133      options->ce.socks_proxy_timeout = positive_atoi (p[1]);
     5134    }
    51295135#endif
    51305136  else if (streq (p[0], "keepalive") && p[1] && p[2])
    51315137    {
  • src/openvpn/options.h

    diff --git a/src/openvpn/options.h b/src/openvpn/options.h
    index ec1d091..8371764 100644
    a b struct connection_entry 
    108108  const char *socks_proxy_port;
    109109  const char *socks_proxy_authfile;
    110110  bool socks_proxy_retry;
     111  int socks_proxy_timeout;
    111112#endif
    112113
    113114  int tun_mtu;           /* MTU of tun device */
  • src/openvpn/socks.c

    diff --git a/src/openvpn/socks.c b/src/openvpn/socks.c
    index 6e29e7a..d0bda39 100644
    a b struct socks_proxy_info * 
    6363socks_proxy_new (const char *server,
    6464                 const char *port,
    6565                 const char *authfile,
    66                  bool retry)
     66                 bool retry,
     67                 int timeout)
    6768{
    6869  struct socks_proxy_info *p;
    6970
    socks_proxy_new (const char *server, 
    8283
    8384  p->retry = retry;
    8485  p->defined = true;
     86  if (timeout)
     87    p->timeout = timeout;
     88  else
     89    p->timeout = 5; // default value
    8590
    8691  return p;
    8792}
    socks_handshake (struct socks_proxy_info *p, 
    294299static bool
    295300recv_socks_reply (socket_descriptor_t sd,
    296301                  struct openvpn_sockaddr *addr,
    297                   volatile int *signal_received)
     302                  volatile int *signal_received,
     303                  int timeout_sec)
    298304{
    299305  char atyp = '\0';
    300306  int alen = 0;
    301307  int len = 0;
    302308  char buf[22];
    303   const int timeout_sec = 5;
    304309
    305310  if (addr != NULL)
    306311    {
    establish_socks_proxy_passthru (struct socks_proxy_info *p, 
    463468
    464469
    465470  /* receive reply from Socks proxy and discard */
    466   if (!recv_socks_reply (sd, NULL, signal_received))
     471  if (!recv_socks_reply (sd, NULL, signal_received, p->timeout))
    467472    goto error;
    468473
    469474  return;
    establish_socks_proxy_udpassoc (struct socks_proxy_info *p, 
    501506
    502507  /* receive reply from Socks proxy */
    503508  CLEAR (*relay_addr);
    504   if (!recv_socks_reply (ctrl_sd, relay_addr, signal_received))
     509  if (!recv_socks_reply (ctrl_sd, relay_addr, signal_received, p->timeout))
    505510    goto error;
    506511
    507512  return;
  • src/openvpn/socks.h

    diff --git a/src/openvpn/socks.h b/src/openvpn/socks.h
    index 30b957d..c4c96c4 100644
    a b struct link_socket_actual; 
    4040struct socks_proxy_info {
    4141  bool defined;
    4242  bool retry;
     43  int  timeout;
    4344
    4445  char server[128];
    4546  const char *port;
    void socks_adjust_frame_parameters (struct frame *frame, int proto); 
    5152struct socks_proxy_info *socks_proxy_new (const char *server,
    5253                                          const char *port,
    5354                                          const char *authfile,
    54                                           bool retry);
     55                                          bool retry,
     56                                          int timeout);
    5557
    5658void socks_proxy_close (struct socks_proxy_info *sp);
    5759