diff options
author | JuanJo Ciarlante <jjo@google.com> | 2009-09-15 16:48:46 +0200 |
---|---|---|
committer | JuanJo Ciarlante <juanjosec@gmail.com> | 2011-03-25 13:30:29 +0100 |
commit | 51afc8b8865fe09f76b81ae341e693a5b16199f2 (patch) | |
tree | 7a7dca20b2c3bd00bf2ca8ab1bddd6db32297488 | |
parent | * socket.c: use USE_PF_INET6 in switch constructs to actually toss them out, (diff) | |
download | openvpn-51afc8b8865fe09f76b81ae341e693a5b16199f2.tar.xz |
* support --disable-ipv6 build properly:
- tests now are pass (and fail) properly for ipv6/4 builds
* more GNU indenting
-rw-r--r-- | init.c | 6 | ||||
-rw-r--r-- | mroute.c | 2 | ||||
-rw-r--r-- | multi.c | 21 | ||||
-rw-r--r-- | options.c | 44 | ||||
-rw-r--r-- | socket.c | 59 | ||||
-rw-r--r-- | socket.h | 15 |
6 files changed, 86 insertions, 61 deletions
@@ -3095,11 +3095,11 @@ init_instance (struct context *c, const struct env_set *env, const unsigned int /* link_socket_mode allows CM_CHILD_TCP instances to inherit acceptable fds from a top-level parent */ + if (c->options.ce.proto == PROTO_TCPv4_SERVER #ifdef USE_PF_INET6 - if (c->options.ce.proto == PROTO_TCPv4_SERVER || c->options.ce.proto == PROTO_TCPv6_SERVER) -#else - if (c->options.ce.proto == PROTO_TCPv4_SERVER) + || c->options.ce.proto == PROTO_TCPv6_SERVER #endif + ) { if (c->mode == CM_TOP) link_socket_mode = LS_MODE_TCP_LISTEN; @@ -387,7 +387,7 @@ mroute_addr_print_ex (const struct mroute_addr *ma, } } } -#else /* old pre IPV6 1-line code: */ +#else /* old, pre USE_PF_INET6 code */ buf_printf (&out, "IPV6"); #endif break; @@ -2681,16 +2681,17 @@ tunnel_server (struct context *top) else tunnel_server_tcp(top); #else - switch (top->options.ce.proto) { - case PROTO_UDPv4: - tunnel_server_udp (top); - break; - case PROTO_TCPv4_SERVER: - tunnel_server_tcp (top); - break; - default: - ASSERT (0); - } + switch (top->options.ce.proto) + { + case PROTO_UDPv4: + tunnel_server_udp (top); + break; + case PROTO_TCPv4_SERVER: + tunnel_server_tcp (top); + break; + default: + ASSERT (0); + } #endif } @@ -108,7 +108,7 @@ static const char usage_message[] = " p = udp (default), tcp-server, or tcp-client\n" "--proto-force p : only consider protocol p in list of connection profiles.\n" #ifdef USE_PF_INET6 - " p = udp6, tcp6-server, or tcp6-client (IPv6)\n" + " p = udp6, tcp6-server, or tcp6-client (ipv6)\n" #endif "--connect-retry n : For --proto tcp-client, number of seconds to wait\n" " between connection retries (default=%d).\n" @@ -1703,10 +1703,18 @@ options_postprocess_verify_ce (const struct options *options, const struct conne * Sanity check on TCP mode options */ - if (ce->connect_retry_defined && ce->proto != PROTO_TCPv4_CLIENT && ce->proto != PROTO_TCPv6_CLIENT) + if (ce->connect_retry_defined && ce->proto != PROTO_TCPv4_CLIENT +#ifdef USE_PF_INET6 + && ce->proto != PROTO_TCPv6_CLIENT +#endif + ) msg (M_USAGE, "--connect-retry doesn't make sense unless also used with --proto tcp-client"); - if (ce->connect_timeout_defined && ce->proto != PROTO_TCPv4_CLIENT && ce->proto != PROTO_TCPv6_CLIENT) + if (ce->connect_timeout_defined && ce->proto != PROTO_TCPv4_CLIENT +#ifdef USE_PF_INET6 + && ce->proto != PROTO_TCPv6_CLIENT +#endif + ) msg (M_USAGE, "--connect-timeout doesn't make sense unless also used with --proto tcp-client"); /* @@ -1804,7 +1812,11 @@ options_postprocess_verify_ce (const struct options *options, const struct conne msg (M_USAGE, "--explicit-exit-notify can only be used with --proto udp"); #endif - if (!ce->remote && (ce->proto == PROTO_TCPv4_CLIENT || ce->proto == PROTO_TCPv6_CLIENT)) + if (!ce->remote && (ce->proto == PROTO_TCPv4_CLIENT +#ifdef USE_PF_INET6 + || ce->proto == PROTO_TCPv6_CLIENT +#endif + )) msg (M_USAGE, "--remote MUST be used in TCP Client mode"); #ifdef ENABLE_HTTP_PROXY @@ -1822,7 +1834,11 @@ options_postprocess_verify_ce (const struct options *options, const struct conne msg (M_USAGE, "--socks-proxy can not be used in TCP Server mode"); #endif - if ((ce->proto == PROTO_TCPv4_SERVER || ce->proto == PROTO_TCPv6_SERVER) + if ((ce->proto == PROTO_TCPv4_SERVER +#ifdef USE_PF_INET6 + || ce->proto == PROTO_TCPv6_SERVER +#endif + ) && connection_list_defined (options)) msg (M_USAGE, "TCP server mode allows at most one --remote address"); @@ -1837,11 +1853,19 @@ options_postprocess_verify_ce (const struct options *options, const struct conne msg (M_USAGE, "--mode server only works with --dev tun or --dev tap"); if (options->pull) msg (M_USAGE, "--pull cannot be used with --mode server"); - if (!(proto_is_udp(ce->proto) || ce->proto == PROTO_TCPv4_SERVER || ce->proto == PROTO_TCPv6_SERVER)) + if (!(proto_is_udp(ce->proto) || ce->proto == PROTO_TCPv4_SERVER +#ifdef USE_PF_INET6 + || ce->proto == PROTO_TCPv6_SERVER +#endif + )) msg (M_USAGE, "--mode server currently only supports --proto udp or --proto tcp-server"); #if PORT_SHARE if ((options->port_share_host || options->port_share_port) && - (ce->proto != PROTO_TCPv4_SERVER && ce->proto != PROTO_TCPv6_SERVER)) + (ce->proto != PROTO_TCPv4_SERVER +#ifdef USE_PF_INET6 + && ce->proto != PROTO_TCPv6_SERVER +#endif + )) msg (M_USAGE, "--port-share only works in TCP server mode (--proto tcp-server)"); #endif if (!options->tls_server) @@ -1870,7 +1894,11 @@ options_postprocess_verify_ce (const struct options *options, const struct conne msg (M_USAGE, "--inetd cannot be used with --mode server"); if (options->ipchange) msg (M_USAGE, "--ipchange cannot be used with --mode server (use --client-connect instead)"); - if (!(proto_is_dgram(ce->proto) || ce->proto == PROTO_TCPv4_SERVER || ce->proto == PROTO_TCPv6_SERVER )) + if (!(proto_is_dgram(ce->proto) || ce->proto == PROTO_TCPv4_SERVER +#ifdef USE_PF_INET6 + || ce->proto == PROTO_TCPv6_SERVER +#endif + )) msg (M_USAGE, "--mode server currently only supports --proto udp or --proto tcp-server"); if (!proto_is_udp(ce->proto) && (options->cf_max || options->cf_per)) msg (M_USAGE, "--connect-freq only works with --mode server --proto udp. Try --max-clients instead."); @@ -1316,10 +1316,12 @@ resolve_bind_local (struct link_socket *sock) /* resolve local address if undefined */ if (!addr_defined (&sock->info.lsa->local)) { +#ifdef USE_PF_INET6 /* may return AF_{INET|INET6} guessed from local_host */ switch(addr_guess_family(sock->info.proto, sock->local_host)) { case AF_INET: +#endif sock->info.lsa->local.addr.in4.sin_family = AF_INET; sock->info.lsa->local.addr.in4.sin_addr.s_addr = (sock->local_host ? getaddr (GETADDR_RESOLVE | GETADDR_WARN_ON_SIGNAL | GETADDR_FATAL, @@ -1329,8 +1331,8 @@ resolve_bind_local (struct link_socket *sock) NULL) : htonl (INADDR_ANY)); sock->info.lsa->local.addr.in4.sin_port = htons (sock->local_port); - break; #ifdef USE_PF_INET6 + break; case AF_INET6: { int success; @@ -1360,8 +1362,8 @@ resolve_bind_local (struct link_socket *sock) sock->info.lsa->local.addr.in6.sin6_port = htons (sock->local_port); } break; -#endif } +#endif /* USE_PF_INET6 */ } /* bind to local address/port */ @@ -1756,7 +1758,7 @@ link_socket_init_phase2 (struct link_socket *sock, /* TCP client/server */ if (sock->info.proto == PROTO_TCPv4_SERVER #ifdef USE_PF_INET6 - ||sock->info.proto == PROTO_TCPv6_SERVER + ||sock->info.proto == PROTO_TCPv6_SERVER #endif ) { @@ -1795,7 +1797,7 @@ link_socket_init_phase2 (struct link_socket *sock, } else if (sock->info.proto == PROTO_TCPv4_CLIENT #ifdef USE_PF_INET6 - ||sock->info.proto == PROTO_TCPv6_CLIENT + ||sock->info.proto == PROTO_TCPv6_CLIENT #endif ) { @@ -2122,7 +2124,7 @@ link_socket_current_remote (const struct link_socket_info *info) * by now just ignore it * */ -#if defined ( USE_PF_INET6 ) +#ifdef USE_PF_INET6 if(lsa->actual.dest.addr.sa.sa_family != AF_INET) return 0; #else @@ -2435,17 +2437,19 @@ print_link_socket_actual_ex (const struct link_socket_actual *act, #if ENABLE_IP_PKTINFO if ((flags & PS_SHOW_PKTINFO) && addr_defined_ipi(act)) { +#ifdef USE_PF_INET6 switch(act->dest.addr.sa.sa_family) { case AF_INET: +#endif { struct openvpn_sockaddr sa; CLEAR (sa); sa.addr.in4.sin_addr = act->pi.in4.ipi_spec_dst; buf_printf (&out, " (via %s)", print_sockaddr_ex (&sa, separator, 0, gc)); } - break; #ifdef USE_PF_INET6 + break; case AF_INET6: { struct sockaddr_in6 sin6; @@ -2462,8 +2466,8 @@ print_link_socket_actual_ex (const struct link_socket_actual *act, } } break; -#endif } +#endif /* USE_PF_INET6 */ } #endif @@ -2663,33 +2667,36 @@ int addr_guess_family(int proto, const char *name) { sa_family_t ret; - if (proto) { - return proto_sa_family(proto); /* already stamped */ - } + if (proto) + { + return proto_sa_family(proto); /* already stamped */ + } #ifdef USE_PF_INET6 - else { - struct addrinfo hints , *ai; - int err; - memset(&hints, 0, sizeof hints); - hints.ai_flags=AI_NUMERICHOST; - err = getaddrinfo(name, NULL, &hints, &ai); - if ( 0 == err ) - { - ret=ai->ai_family; - freeaddrinfo(ai); - return ret; - } - } + else + { + struct addrinfo hints , *ai; + int err; + memset(&hints, 0, sizeof hints); + hints.ai_flags=AI_NUMERICHOST; + err = getaddrinfo(name, NULL, &hints, &ai); + if ( 0 == err ) + { + ret=ai->ai_family; + freeaddrinfo(ai); + return ret; + } + } #endif return AF_INET; /* default */ } const char * addr_family_name (int af) { - switch (af) { - case AF_INET: return "AF_INET"; + switch (af) + { + case AF_INET: return "AF_INET"; case AF_INET6: return "AF_INET6"; - } + } return "AF_UNSPEC"; } @@ -491,19 +491,6 @@ in_addr_t getaddr_multi (unsigned int flags, * Transport protocol naming and other details. */ -#if 0 /* PRE UDPv6/TCPv6 code */ -#define PROTO_NONE 0 /* catch for uninitialized */ -#define PROTO_UDPv4 1 -#define PROTO_TCPv4_SERVER 2 -#define PROTO_TCPv4_CLIENT 3 -#define PROTO_TCPv4 4 -#define PROTO_UDPv6 5 -#define PROTO_TCPv6_SERVER 6 -#define PROTO_TCPv6_CLIENT 7 -#define PROTO_TCPv6 8 -#define PROTO_N 9 -#endif /* if 0 */ - /* * Use enum's instead of #define to allow for easier * optional proto support @@ -514,10 +501,12 @@ enum proto_num { PROTO_TCPv4_SERVER, PROTO_TCPv4_CLIENT, PROTO_TCPv4, +#ifdef USE_PF_INET6 PROTO_UDPv6, PROTO_TCPv6_SERVER, PROTO_TCPv6_CLIENT, PROTO_TCPv6, +#endif PROTO_N }; |