daily pastebin goal
22%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 178 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From 828996c831ee96947b785cfb8f376752ea02b69a Mon Sep 17 00:00:00 2001
  2. From: JuanJo Ciarlante <jjo@google.com>
  3. Date: Sun, 13 Sep 2009 13:43:04 +0200
  4. Subject: [PATCH] * rebased openvpn-2.1_rc1b.jjo.20061206.d.patch
  5.  * passes {udp,tcp}x{v4,v6} loopback tests
  6.  * passes {udp,tcp}x{v6} remote tests
  7.  
  8. ---
  9.  buffer.c     |   13 ++
  10.  configure.ac |   16 ++
  11.  init.c       |   36 ++--
  12.  manage.c     |   10 +-
  13.  mroute.c     |   60 ++++++-
  14.  mtcp.c       |    1 +
  15.  multi.c      |   17 ++-
  16.  occ.c        |    2 +-
  17.  options.c    |   42 +++--
  18.  ps.c         |    6 +-
  19.  socket.c     |  597 +++++++++++++++++++++++++++++++++++++++++++++++-----------
  20.  socket.h     |  233 ++++++++++++++++++++---
  21.  socks.c      |   18 +-
  22.  13 files changed, 857 insertions(+), 194 deletions(-)
  23.  
  24. diff --git a/buffer.c b/buffer.c
  25. index 15ab776..1bef7d8 100644
  26. --- a/buffer.c
  27. +++ b/buffer.c
  28. @@ -215,6 +215,19 @@ buf_printf (struct buffer *buf, const char *format, ...)
  29.    return ret;
  30.  }
  31.  
  32. +void buf_puts(struct buffer *buf, const char *str)
  33. +{
  34. +  uint8_t *ptr = BEND (buf);
  35. +  int cap = buf_forward_capacity (buf);
  36. +  if (cap > 0)
  37. +    {
  38. +      strncpynt ((char *)ptr,str, cap);
  39. +      *(buf->data + buf->capacity - 1) = 0; /* windows vsnprintf needs this */
  40. +      buf->len += (int) strlen ((char *)ptr);
  41. +    }
  42. +}
  43. +
  44. +
  45.  /*
  46.   * This is necessary due to certain buggy implementations of snprintf,
  47.   * that don't guarantee null termination for size > 0.
  48. diff --git a/configure.ac b/configure.ac
  49. index 116ff7c..6864783 100644
  50. --- a/configure.ac
  51. +++ b/configure.ac
  52. @@ -135,6 +135,12 @@ AC_ARG_ENABLE(multihome,
  53.     [MULTIHOME="yes"]
  54.  )
  55.  
  56. +AC_ARG_ENABLE(ipv6,
  57. +   [  --disable-ipv6          Disable UDP/IPv6 support],
  58. +   [PF_INET6="$enableval"],
  59. +   [PF_INET6="yes"]
  60. +)
  61. +
  62.  AC_ARG_ENABLE(port-share,
  63.     [  --disable-port-share    Disable TCP server port-share support (--port-share)],
  64.     [PORT_SHARE="$enableval"],
  65. @@ -550,6 +556,16 @@ LDFLAGS="$LDFLAGS -Wl,--fatal-warnings"
  66.  AC_CHECK_FUNC(epoll_create, AC_DEFINE(HAVE_EPOLL_CREATE, 1, [epoll_create function is defined]))
  67.  LDFLAGS="$OLDLDFLAGS"
  68.  
  69. +dnl ipv6 support
  70. +if test "$PF_INET6" = "yes"; then
  71. +  AC_CHECKING([for struct sockaddr_in6 for IPv6 support])
  72. +  AC_CHECK_TYPE(
  73. +      [struct sockaddr_in6],
  74. +      [AC_DEFINE(USE_PF_INET6, 1, [struct sockaddr_in6 is needed for IPv6 peer support])],
  75. +      [],
  76. +      [#include "syshead.h"])
  77. +fi
  78. +
  79.  dnl
  80.  dnl check for valgrind tool
  81.  dnl
  82. diff --git a/init.c b/init.c
  83. index 80b2849..57ebad0 100644
  84. --- a/init.c
  85. +++ b/init.c
  86. @@ -94,7 +94,7 @@ update_options_ce_post (struct options *options)
  87.     */
  88.    if (options->pull
  89.        && options->ping_rec_timeout_action == PING_UNDEF
  90. -      && options->ce.proto == PROTO_UDPv4)
  91. +      && proto_is_dgram(options->ce.proto))
  92.      {
  93.        options->ping_rec_timeout = PRE_PULL_INITIAL_PING_RESTART;
  94.        options->ping_rec_timeout_action = PING_RESTART;
  95. @@ -928,7 +928,7 @@ initialization_sequence_completed (struct context *c, const unsigned int flags)
  96.        const char *detail = "SUCCESS";
  97.        if (c->c1.tuntap)
  98.     tun_local = c->c1.tuntap->local;
  99. -      tun_remote = htonl (c->c1.link_socket_addr.actual.dest.sa.sin_addr.s_addr);
  100. +      tun_remote = htonl (c->c1.link_socket_addr.actual.dest.addr.in4.sin_addr.s_addr);
  101.        if (flags & ISC_ERRORS)
  102.     detail = "ERROR";
  103.        management_set_state (management,
  104. @@ -1333,7 +1333,7 @@ do_deferred_options (struct context *c, const unsigned int found)
  105.  #ifdef ENABLE_OCC
  106.    if (found & OPT_P_EXPLICIT_NOTIFY)
  107.      {
  108. -      if (c->options.ce.proto != PROTO_UDPv4 && c->options.explicit_exit_notification)
  109. +      if (!proto_is_udp(c->options.ce.proto) && c->options.explicit_exit_notification)
  110.     {
  111.       msg (D_PUSH, "OPTIONS IMPORT: --explicit-exit-notify can only be used with --proto udp");
  112.       c->options.explicit_exit_notification = 0;
  113. @@ -1428,13 +1428,22 @@ socket_restart_pause (struct context *c)
  114.    switch (c->options.ce.proto)
  115.      {
  116.      case PROTO_UDPv4:
  117. +#ifdef USE_PF_INET6
  118. +    case PROTO_UDPv6:
  119. +#endif
  120.        if (proxy)
  121.     sec = c->options.ce.connect_retry_seconds;
  122.        break;
  123.      case PROTO_TCPv4_SERVER:
  124. +#ifdef USE_PF_INET6
  125. +    case PROTO_TCPv6_SERVER:
  126. +#endif
  127.        sec = 1;
  128.        break;
  129.      case PROTO_TCPv4_CLIENT:
  130. +#ifdef USE_PF_INET6
  131. +    case PROTO_TCPv6_CLIENT:
  132. +#endif
  133.        sec = c->options.ce.connect_retry_seconds;
  134.        break;
  135.      }
  136. @@ -2565,7 +2574,7 @@ do_setup_fast_io (struct context *c)
  137.  #ifdef WIN32
  138.        msg (M_INFO, "NOTE: --fast-io is disabled since we are running on Windows");
  139.  #else
  140. -      if (c->options.ce.proto != PROTO_UDPv4)
  141. +      if (!proto_is_udp(c->options.ce.proto))
  142.     msg (M_INFO, "NOTE: --fast-io is disabled since we are not using UDP");
  143.        else
  144.     {
  145. @@ -2827,7 +2836,11 @@ init_instance (struct context *c, const struct env_set *env, const unsigned int
  146.    /* link_socket_mode allows CM_CHILD_TCP
  147.       instances to inherit acceptable fds
  148.       from a top-level parent */
  149. +#ifdef USE_PF_INET6
  150. +  if (c->options.ce.proto == PROTO_TCPv4_SERVER || c->options.ce.proto == PROTO_TCPv6_SERVER)
  151. +#else
  152.    if (c->options.ce.proto == PROTO_TCPv4_SERVER)
  153. +#endif
  154.      {
  155.        if (c->mode == CM_TOP)
  156.     link_socket_mode = LS_MODE_TCP_LISTEN;
  157. @@ -3110,17 +3123,8 @@ inherit_context_child (struct context *dest,
  158.  {
  159.    CLEAR (*dest);
  160.  
  161. -  switch (src->options.ce.proto)
  162. -    {
  163. -    case PROTO_UDPv4:
  164. -      dest->mode = CM_CHILD_UDP;
  165. -      break;
  166. -    case PROTO_TCPv4_SERVER:
  167. -      dest->mode = CM_CHILD_TCP;
  168. -      break;
  169. -    default:
  170. -      ASSERT (0);
  171. -    }
  172. +  /* proto_is_dgram will ASSERT(0) if proto is invalid */
  173. +  dest->mode = proto_is_dgram(src->options.ce.proto)? CM_CHILD_UDP : CM_CHILD_TCP;
  174.  
  175.    dest->gc = gc_new ();
  176.  
  177. @@ -3226,7 +3230,7 @@ inherit_context_top (struct context *dest,
  178.    dest->c2.es_owned = false;
  179.  
  180.    dest->c2.event_set = NULL;
  181. -  if (src->options.ce.proto == PROTO_UDPv4)
  182. +  if (proto_is_dgram(src->options.ce.proto))
  183.      do_event_set_init (dest, false);
  184.  }
  185.  
  186. diff --git a/manage.c b/manage.c
  187. index 97d69b4..7a1dddf 100644
  188. --- a/manage.c
  189. +++ b/manage.c
  190. @@ -1874,9 +1874,9 @@ man_settings_init (struct man_settings *ms,
  191.       /*
  192.        * Initialize socket address
  193.        */
  194. -     ms->local.sa.sin_family = AF_INET;
  195. -     ms->local.sa.sin_addr.s_addr = 0;
  196. -     ms->local.sa.sin_port = htons (port);
  197. +     ms->local.addr.in4.sin_family = AF_INET;
  198. +     ms->local.addr.in4.sin_addr.s_addr = 0;
  199. +     ms->local.addr.in4.sin_port = htons (port);
  200.  
  201.       /*
  202.        * Run management over tunnel, or
  203. @@ -1888,7 +1888,7 @@ man_settings_init (struct man_settings *ms,
  204.         }
  205.       else
  206.         {
  207. -         ms->local.sa.sin_addr.s_addr = getaddr
  208. +         ms->local.addr.in4.sin_addr.s_addr = getaddr
  209.         (GETADDR_RESOLVE|GETADDR_WARN_ON_SIGNAL|GETADDR_FATAL, addr, 0, NULL, NULL);
  210.         }
  211.     }
  212. @@ -2255,7 +2255,7 @@ management_post_tunnel_open (struct management *man, const in_addr_t tun_local_i
  213.        && man->connection.state == MS_INITIAL)
  214.      {
  215.        /* listen on our local TUN/TAP IP address */
  216. -      man->settings.local.sa.sin_addr.s_addr = htonl (tun_local_ip);
  217. +      man->settings.local.addr.in4.sin_addr.s_addr = htonl (tun_local_ip);
  218.        man_connection_init (man);
  219.      }
  220.  
  221. diff --git a/mroute.c b/mroute.c
  222. index 9d8fa66..e4abdad 100644
  223. --- a/mroute.c
  224. +++ b/mroute.c
  225. @@ -226,25 +226,47 @@ bool mroute_extract_openvpn_sockaddr (struct mroute_addr *addr,
  226.                       const struct openvpn_sockaddr *osaddr,
  227.                       bool use_port)
  228.  {
  229. -  if (osaddr->sa.sin_family == AF_INET)
  230. +  switch (osaddr->addr.sa.sa_family)
  231. +  {
  232. +    case AF_INET:
  233.      {
  234.        if (use_port)
  235.     {
  236.       addr->type = MR_ADDR_IPV4 | MR_WITH_PORT;
  237.       addr->netbits = 0;
  238.       addr->len = 6;
  239. -     memcpy (addr->addr, &osaddr->sa.sin_addr.s_addr, 4);
  240. -     memcpy (addr->addr + 4, &osaddr->sa.sin_port, 2);
  241. +     memcpy (addr->addr, &osaddr->addr.in4.sin_addr.s_addr, 4);
  242. +     memcpy (addr->addr + 4, &osaddr->addr.in4.sin_port, 2);
  243.     }
  244.        else
  245.     {
  246.       addr->type = MR_ADDR_IPV4;
  247.       addr->netbits = 0;
  248.       addr->len = 4;
  249. -     memcpy (addr->addr, &osaddr->sa.sin_addr.s_addr, 4);
  250. +     memcpy (addr->addr, &osaddr->addr.in4.sin_addr.s_addr, 4);
  251.     }
  252.        return true;
  253.      }
  254. +#ifdef USE_PF_INET6
  255. +    case AF_INET6:
  256. +      if (use_port)
  257. +   {
  258. +     addr->type = MR_ADDR_IPV6 | MR_WITH_PORT;
  259. +     addr->netbits = 0;
  260. +     addr->len = 18;
  261. +     memcpy (addr->addr, &osaddr->addr.in6.sin6_addr, 16);
  262. +     memcpy (addr->addr + 16, &osaddr->addr.in6.sin6_port, 2);
  263. +   }
  264. +      else
  265. +   {
  266. +     addr->type = MR_ADDR_IPV6;
  267. +     addr->netbits = 0;
  268. +     addr->len = 16;
  269. +     memcpy (addr->addr, &osaddr->addr.in6.sin6_addr, 16);
  270. +   }
  271. +      return true;
  272. +#endif
  273. +  }
  274.    return false;
  275.  }
  276.  
  277. @@ -337,7 +359,37 @@ mroute_addr_print_ex (const struct mroute_addr *ma,
  278.       }
  279.       break;
  280.     case MR_ADDR_IPV6:
  281. +#ifdef USE_PF_INET6
  282. +          {
  283. +       struct buffer buf;
  284. +       struct sockaddr_in6 sin6;
  285. +       int port;
  286. +       char buf6[INET6_ADDRSTRLEN] = "";
  287. +       memset(&sin6, 0, sizeof sin6);
  288. +       sin6.sin6_family = AF_INET6;
  289. +       buf_set_read (&buf, maddr.addr, maddr.len);
  290. +            if (buf_read(&buf, &sin6.sin6_addr, sizeof (sin6.sin6_addr)))
  291. +            {
  292. +              if (getnameinfo((struct sockaddr *)&sin6, sizeof (struct sockaddr_in6),
  293. +                                      buf6, sizeof (buf6), NULL, 0, NI_NUMERICHOST) != 0)
  294. +                {
  295. +                  buf_printf (&out, "MR_ADDR_IPV6 getnameinfo() err");
  296. +                  break;
  297. +       }
  298. +              buf_puts (&out, buf6);
  299. +         if (maddr.type & MR_WITH_NETBITS)
  300. +           buf_printf (&out, "/%d", maddr.netbits);
  301. +              if (maddr.type & MR_WITH_PORT)
  302. +                {
  303. +                  port = buf_read_u16 (&buf);
  304. +                  if (port >= 0)
  305. +                    buf_printf (&out, ":%d", port);
  306. +                }
  307. +       }
  308. +          }
  309. +#else /* old pre IPV6 1-line code: */
  310.       buf_printf (&out, "IPV6");
  311. +#endif
  312.       break;
  313.     default:
  314.       buf_printf (&out, "UNKNOWN");
  315. diff --git a/mtcp.c b/mtcp.c
  316. index 72c9618..f578429 100644
  317. --- a/mtcp.c
  318. +++ b/mtcp.c
  319. @@ -153,6 +153,7 @@ multi_tcp_instance_specific_init (struct multi_context *m, struct multi_instance
  320.    ASSERT (mi->context.c2.link_socket);
  321.    ASSERT (mi->context.c2.link_socket->info.lsa);
  322.    ASSERT (mi->context.c2.link_socket->mode == LS_MODE_TCP_ACCEPT_FROM);
  323. +  ASSERT (mi->context.c2.link_socket->info.lsa->actual.dest.addr.sa.sa_family == AF_INET);
  324.    if (!mroute_extract_openvpn_sockaddr (&mi->real, &mi->context.c2.link_socket->info.lsa->actual.dest, true))
  325.      {
  326.        msg (D_MULTI_ERRORS, "MULTI TCP: TCP client address is undefined");
  327. diff --git a/multi.c b/multi.c
  328. index f62563c..f89814a 100644
  329. --- a/multi.c
  330. +++ b/multi.c
  331. @@ -1066,8 +1066,8 @@ multi_learn_in_addr_t (struct multi_context *m,
  332.    struct mroute_addr addr;
  333.  
  334.    CLEAR (remote_si);
  335. -  remote_si.sa.sin_family = AF_INET;
  336. -  remote_si.sa.sin_addr.s_add
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top