Permalink
Browse files

TS-679: Make Plugin API IPv6 compatible

git-svn-id: https://svn.apache.org/repos/asf/trafficserver/traffic/trunk@1127742 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 0adc8bf commit b1cc94b7cbe203797dd3e4a8516b2266f749e80a @SolidWallOfCode SolidWallOfCode committed May 26, 2011
View
@@ -1,6 +1,10 @@
-*- coding: utf-8 -*-
Changes with Apache Traffic Server 2.1.9
+ *) [TS-679] The external API was changed to make it IPv6 compliant
+ (although it doesn't actually work with IPv6). Old API functions
+ were deprecated but not removed.
+
*) [TS-797] Wrong delete used in stats processor.
*) [TS-769] Fixed infinite loop when getting a 505 response from the
@@ -1384,7 +1384,7 @@ ClusterHandler::dump_write_msg(int res)
// Debug support for inter cluster message trace
unsigned char x[4];
memset(x, 0, sizeof(x));
- *(uint32_t *) & x = (uint32_t) ((struct sockaddr_in *)&(net_vc->get_remote_addr()))->sin_addr.s_addr;
+ *(uint32_t *) & x = (uint32_t) ((struct sockaddr_in *)(net_vc->get_remote_addr()))->sin_addr.s_addr;
fprintf(stderr,
"[W] %hhu.%hhu.%hhu.%hhu SeqNo=%u, Cnt=%d, CntlCnt=%d Todo=%d, Res=%d\n",
@@ -1403,7 +1403,7 @@ ClusterHandler::dump_read_msg()
// Debug support for inter cluster message trace
unsigned char x[4];
memset(x, 0, sizeof(x));
- *(uint32_t *) & x = (uint32_t) ((struct sockaddr_in *)&(net_vc->get_remote_addr()))->sin_addr.s_addr;
+ *(uint32_t *) & x = (uint32_t) ((struct sockaddr_in *)(net_vc->get_remote_addr()))->sin_addr.s_addr;
fprintf(stderr, "[R] %hhu.%hhu.%hhu.%hhu SeqNo=%u, Cnt=%d, CntlCnt=%d\n",
x[0], x[1], x[2], x[3], read.sequence_number, read.msg.count, read.msg.control_bytes);
@@ -267,6 +267,8 @@ struct HostDBInfo
uint64_t md5_high;
+ sockaddr_in6 ip6;
+
bool failed() {
return !ip();
}
@@ -369,7 +369,7 @@ class NetVConnection:public VConnection
virtual ink_hrtime get_inactivity_timeout() = 0;
/** Returns local sockaddr storage. */
- const struct sockaddr_storage &get_local_addr();
+ sockaddr_storage const* get_local_addr();
/** Returns local ip. */
unsigned int get_local_ip();
@@ -378,7 +378,7 @@ class NetVConnection:public VConnection
int get_local_port();
/** Returns remote sockaddr storage. */
- const struct sockaddr_storage &get_remote_addr();
+ sockaddr_storage const* get_remote_addr();
/** Returns remote ip. */
unsigned int get_remote_ip();
@@ -23,22 +23,22 @@
#include "I_NetVConnection.h"
-TS_INLINE const struct sockaddr_storage &
+TS_INLINE sockaddr_storage const*
NetVConnection::get_remote_addr()
{
if (!got_remote_addr) {
set_remote_addr();
got_remote_addr = 1;
}
- return remote_addr;
+ return &remote_addr;
}
TS_INLINE unsigned int
NetVConnection::get_remote_ip()
{
- switch (get_remote_addr().ss_family) {
+ switch (get_remote_addr()->ss_family) {
case AF_INET:
- return (unsigned int)((struct sockaddr_in *)&(get_remote_addr()))->sin_addr.s_addr;
+ return (unsigned int)((struct sockaddr_in *)(get_remote_addr()))->sin_addr.s_addr;
default:
return 0;
}
@@ -48,42 +48,42 @@ NetVConnection::get_remote_ip()
TS_INLINE int
NetVConnection::get_remote_port()
{
- switch (get_remote_addr().ss_family) {
+ switch (get_remote_addr()->ss_family) {
case AF_INET:
- return ntohs(((struct sockaddr_in *)&(get_remote_addr()))->sin_port);
+ return ntohs(((struct sockaddr_in *)(get_remote_addr()))->sin_port);
case AF_INET6:
- return ntohs(((struct sockaddr_in6 *)&(get_remote_addr()))->sin6_port);
+ return ntohs(((struct sockaddr_in6 *)(get_remote_addr()))->sin6_port);
default:
return 0;
}
}
-TS_INLINE const struct sockaddr_storage &
+TS_INLINE sockaddr_storage const*
NetVConnection::get_local_addr()
{
if (!got_local_addr) {
set_local_addr();
switch (local_addr.ss_family) {
case AF_INET:
- if (((struct sockaddr_in *)&(local_addr))->sin_addr.s_addr || ((struct sockaddr_in *)&(local_addr))->sin_port) {
+ if (((struct sockaddr_in *)(&local_addr))->sin_addr.s_addr || ((struct sockaddr_in *)&(local_addr))->sin_port) {
got_local_addr = 1;
}
break;
case AF_INET6:
- if (((struct sockaddr_in6 *)&(local_addr))->sin6_addr.s6_addr || ((struct sockaddr_in6 *)&(local_addr))->sin6_port) {
+ if (((struct sockaddr_in6 *)(&local_addr))->sin6_addr.s6_addr || ((struct sockaddr_in6 *)(&local_addr))->sin6_port) {
got_local_addr = 1;
}
}
}
- return local_addr;
+ return &local_addr;
}
TS_INLINE unsigned int
NetVConnection::get_local_ip()
{
- switch (get_local_addr().ss_family) {
+ switch (get_local_addr()->ss_family) {
case AF_INET:
- return (unsigned int)((struct sockaddr_in *)&(get_local_addr()))->sin_addr.s_addr;
+ return (unsigned int)((struct sockaddr_in *)(get_local_addr()))->sin_addr.s_addr;
default:
return 0;
}
@@ -92,11 +92,11 @@ NetVConnection::get_local_ip()
TS_INLINE int
NetVConnection::get_local_port()
{
- switch (get_local_addr().ss_family) {
+ switch (get_local_addr()->ss_family) {
case AF_INET:
- return ntohs(((struct sockaddr_in *)&(get_local_addr()))->sin_port);
+ return ntohs(((struct sockaddr_in *)(get_local_addr()))->sin_port);
case AF_INET6:
- return ntohs(((struct sockaddr_in6 *)&(get_local_addr()))->sin6_port);
+ return ntohs(((struct sockaddr_in6 *)(get_local_addr()))->sin6_port);
default:
return 0;
}
View
@@ -91,4 +91,182 @@ inkcoreapi uint32_t ink_inet_addr(const char *s);
const char *ink_inet_ntop(const struct sockaddr *addr, char *dst, size_t size);
uint16_t ink_inet_port(const struct sockaddr *addr);
+/// Reset an address to invalid.
+/// Convenience overload.
+/// @note Useful for marking a member as not yet set.
+inline void ink_inet_invalidate(sockaddr_storage* addr) {
+ addr->ss_family = AF_UNSPEC;
+}
+
+/// Set to all zero.
+inline void ink_inet_init(sockaddr_storage* addr) {
+ memset(addr, 0, sizeof(addr));
+ ink_inet_invalidate(addr);
+}
+
+/// @return @a a cast to @c sockaddr_storage*.
+inline sockaddr_storage* ink_inet_ss_cast(sockaddr* a) {
+ return static_cast<sockaddr_storage*>(static_cast<void*>(a));
+}
+/// @return @a a cast to @c sockaddr_storage const*.
+inline sockaddr_storage const* ink_inet_ss_cast(sockaddr const* a) {
+ return static_cast<sockaddr_storage const*>(static_cast<void const*>(a));
+}
+/// @return @a a cast to @c sockaddr_storage const*.
+inline sockaddr_storage* ink_inet_ss_cast(sockaddr_in6* a) {
+ return reinterpret_cast<sockaddr_storage*>(a);
+}
+/// @return @a a cast to @c sockaddr_storage const*.
+inline sockaddr_storage const* ink_inet_ss_cast(sockaddr_in6 const* a) {
+ return reinterpret_cast<sockaddr_storage const*>(a);
+}
+/// @return @a a cast to @c sockaddr*.
+inline sockaddr* ink_inet_sa_cast(sockaddr_storage* a) {
+ return reinterpret_cast<sockaddr*>(a);
+}
+/// @return @a a cast to sockaddr const*.
+inline sockaddr const* ink_inet_sa_cast(sockaddr_storage const* a) {
+ return reinterpret_cast<sockaddr const*>(a);
+}
+/// @return @a a cast to sockaddr const*.
+inline sockaddr const* ink_inet_sa_cast(sockaddr_in6 const* a) {
+ return reinterpret_cast<sockaddr const*>(a);
+}
+
+/// Test for IPv4 protocol.
+/// @return @c true if the address is IPv4, @c false otherwise.
+inline bool ink_inet_is_ip4(sockaddr_storage const* addr) {
+ return AF_INET == addr->ss_family;
+}
+/// Test for IPv4 protocol.
+/// @return @c true if the address is IPv4, @c false otherwise.
+inline bool ink_inet_is_ip4(sockaddr const* addr) {
+ return AF_INET == addr->sa_family;
+}
+/// Test for IPv6 protocol.
+/// Convenience overload.
+/// @return @c true if the address is IPv6, @c false otherwise.
+inline bool ink_inet_is_ip6(sockaddr_storage const* addr) {
+ return AF_INET6 == addr->ss_family;
+}
+
+/// IPv4 cast.
+/// @return @a a cast to a @c sockaddr_in*
+inline sockaddr_in* ink_inet_ip4_cast(
+ sockaddr_storage* a ///< Address structure.
+) {
+ return static_cast<sockaddr_in*>(static_cast<void*>(a));
+}
+/// IPv4 cast.
+/// @return @a a cast to a @c sockaddr_in*
+inline sockaddr_in const* ink_inet_ip4_cast(
+ sockaddr_storage const* a ///< Address structure.
+) {
+ return static_cast<sockaddr_in const*>(static_cast<void const*>(a));
+}
+/// IPv4 cast.
+/// @return @a a cast to a @c sockaddr_in*
+inline sockaddr_in const* ink_inet_ip4_cast(
+ sockaddr const* a ///< Address structure.
+) {
+ return reinterpret_cast<sockaddr_in const*>(a);
+}
+/// IPv6 cast.
+/// @return @a a cast to a @c sockaddr_in6*
+inline sockaddr_in6* ink_inet_ip6_cast(sockaddr_storage* a) {
+ return static_cast<sockaddr_in6*>(static_cast<void*>(a));
+}
+/// IPv6 cast.
+/// @return @a a cast to a @c sockaddr_in6*
+inline sockaddr_in6 const* ink_inet_ip6_cast(sockaddr_storage const* a) {
+ return static_cast<sockaddr_in6 const*>(static_cast<void const*>(a));
+}
+
+/** Get a reference to the port in an address.
+ @note Because this is direct access, the port value is in network order.
+ @see ink_inet_get_port for host order copy.
+ @return A reference to the port value in an IPv4 or IPv6 address.
+ @internal This is primarily for internal use but it might be handy for
+ clients so it is exposed.
+*/
+inline uint16_t& ink_inet_port_cast(sockaddr_storage* ss) {
+ static uint16_t dummy = 0;
+ return AF_INET == ss->ss_family
+ ? ink_inet_ip4_cast(ss)->sin_port
+ : AF_INET6 == ss->ss_family
+ ? ink_inet_ip6_cast(ss)->sin6_port
+ : (dummy = 0)
+ ;
+}
+/** Get a reference to the port in an address.
+ @note Because this is direct access, the port value is in network order.
+ @see ink_inet_get_port for host order copy.
+ @return A reference to the port value in an IPv4 or IPv6 address.
+ @internal This is primarily for internal use but it might be handy for
+ clients so it is exposed.
+*/
+inline uint16_t const& ink_inet_port_cast(sockaddr_storage const* ss) {
+ return ink_inet_port_cast(const_cast<sockaddr_storage*>(ss));
+}
+/** Get a reference to the port in an address.
+ @note Because this is direct access, the port value is in network order.
+ @see ink_inet_get_port for host order copy.
+ @return A reference to the port value in an IPv4 or IPv6 address.
+ @internal This is primarily for internal use but it might be handy for
+ clients so it is exposed.
+*/
+inline uint16_t const& ink_inet_port_cast(sockaddr const* sa) {
+ return ink_inet_port_cast(ink_inet_ss_cast(sa));
+}
+
+/** Access the IPv4 address.
+
+ If @a addr is not IPv4 the results are indeterminate.
+
+ @note This is direct access to the address so it will be in
+ network order.
+
+ @return A reference to the IPv4 address in @a addr.
+*/
+inline in_addr_t& ink_inet_ip4_addr_cast(sockaddr_storage* addr) {
+ return ink_inet_ip4_cast(addr)->sin_addr.s_addr;
+}
+/** Access the IPv4 address.
+
+ If @a addr is not IPv4 the results are indeterminate.
+
+ @note This is direct access to the address so it will be in
+ network order.
+
+ @return A reference to the IPv4 address in @a addr.
+*/
+inline in_addr_t const& ink_inet_ip4_addr_cast(sockaddr_storage const* addr) {
+ return ink_inet_ip4_cast(addr)->sin_addr.s_addr;
+}
+/** Access the IPv4 address.
+
+ If @a addr is not IPv4 the results are indeterminate.
+
+ @note This is direct access to the address so it will be in
+ network order.
+
+ @return A reference to the IPv4 address in @a addr.
+*/
+inline in_addr_t const& ink_inet_ip4_addr_cast(sockaddr const* addr) {
+ return ink_inet_ip4_cast(addr)->sin_addr.s_addr;
+}
+
+/// Write IPv4 data to a @c sockaddr_storage.
+inline void ink_inet_ip4_set(
+ sockaddr_storage* ss, ///< Destination storage.
+ in_addr_t ip4, ///< address, IPv4 network order.
+ uint16_t port = 0 ///< port, network order.
+) {
+ sockaddr_in* sin = ink_inet_ip4_cast(ss);
+ memset(sin, 0, sizeof(*sin));
+ sin->sin_family = AF_INET;
+ memcpy(&(sin->sin_addr), &ip4, sizeof(ip4));
+ sin->sin_port = port;
+}
+
#endif // _ink_inet.h
@@ -23,16 +23,3 @@
#include "ink_unused.h" /* MAGIC_EDITING_TAG */
#include "IPRange.h"
-
-char *
-SocksParser(int fd)
-{
- IPRange ip_range;
- return ip_range.read_table_from_file(fd, "no_socks");
-}
-
-char *
-SocksParser(FILE * fp)
-{
- return (SocksParser(fileno(fp)));
-}
View
@@ -33,8 +33,8 @@
char *parseStorageFile(FILE * fp);
char *parseStorageFile(int fd);
-char *SocksParser(FILE * fp);
-char *SocksParser(int fd);
+//char *SocksParser(FILE * fp);
+//char *SocksParser(int fd);
char *parseRemapFile(FILE * fp);
char *parseRemapFile(int fd);
View
@@ -52,7 +52,9 @@ void
FetchSM::httpConnect()
{
Debug(DEBUG_TAG, "[%s] calling httpconnect write", __FUNCTION__);
- http_vc = TSHttpConnect(_ip, _port);
+ sockaddr_storage addr;
+ ink_inet_ip4_set(&addr, _ip, _port);
+ http_vc = TSHttpConnect(ink_inet_sa_cast(&addr));
PluginVC *vc = (PluginVC *) http_vc;
Oops, something went wrong.

0 comments on commit b1cc94b

Please sign in to comment.