Author: amc
Date: Thu Nov 3 01:39:44 2011
New Revision: 1196916
URL: http://svn.apache.org/viewvc?rev=1196916&view=rev
Log:
TS-989: IPv6 compatible logging.
Modified:
trafficserver/traffic/trunk/CHANGES
trafficserver/traffic/trunk/proxy/logging/Log.cc
trafficserver/traffic/trunk/proxy/logging/LogAccess.cc
trafficserver/traffic/trunk/proxy/logging/LogAccess.h
trafficserver/traffic/trunk/proxy/logging/LogAccessHttp.cc
trafficserver/traffic/trunk/proxy/logging/LogAccessICP.cc
trafficserver/traffic/trunk/proxy/logging/LogAccessTest.cc
trafficserver/traffic/trunk/proxy/logging/LogField.h
Modified: trafficserver/traffic/trunk/CHANGES
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/CHANGES?rev=1196916&r1=1196915&r2=1196916&view=diff
==============================================================================
--- trafficserver/traffic/trunk/CHANGES (original)
+++ trafficserver/traffic/trunk/CHANGES Thu Nov 3 01:39:44 2011
@@ -1,7 +1,8 @@
-*- coding: utf-8 -*-
Changes with Apache Traffic Server 3.1.1
- *) TS-1009 Disable starting ICP continuations if ICP is not
- enabled.
+ *) TS-989 Logging is now IPv6 compatible.
+
+ *) TS-1009 Disable starting ICP continuations if ICP is not enabled.
*) TS-1005 Use traffic_line for reload option with RC script.
Author: Jan-Frode Myklebust.
Modified: trafficserver/traffic/trunk/proxy/logging/Log.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/Log.cc?rev=1196916&r1=1196915&r2=1196916&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/Log.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/Log.cc Thu Nov 3 01:39:44 2011
@@ -348,17 +348,17 @@ Log::init_fields()
// client -> proxy fields
Ptr<LogFieldAliasIP> ip_map = NEW(new LogFieldAliasIP);
field = NEW(new LogField("client_host_ip", "chi",
- LogField::STRING,
+ LogField::IP,
&LogAccess::marshal_client_host_ip,
- &LogAccess::unmarshal_str));
+ &LogAccess::unmarshal_ip_to_str));
global_field_list.add(field, false);
ink_hash_table_insert(field_symbol_hash, "chi", field);
Ptr<LogFieldAliasIPhex> ip_map_hex = NEW(new LogFieldAliasIPhex);
field = NEW(new LogField("client_host_ip_hex", "chih",
- LogField::sINT,
+ LogField::IP,
&LogAccess::marshal_client_host_ip,
- &LogAccess::unmarshal_ip, (Ptr<LogFieldAliasMap>)
ip_map_hex));
+ &LogAccess::unmarshal_ip_to_hex));
global_field_list.add(field, false);
ink_hash_table_insert(field_symbol_hash, "chih", field);
@@ -670,9 +670,9 @@ Log::init_fields()
ink_hash_table_insert(field_symbol_hash, "pqsn", field);
field = NEW(new LogField("proxy_req_server_ip", "pqsi",
- LogField::sINT,
+ LogField::IP,
&LogAccess::marshal_proxy_req_server_ip,
- &LogAccess::unmarshal_ip, (Ptr<LogFieldAliasMap>)
ip_map));
+ &LogAccess::unmarshal_ip_to_str));
global_field_list.add(field, false);
ink_hash_table_insert(field_symbol_hash, "pqsi", field);
@@ -730,9 +730,9 @@ Log::init_fields()
ink_hash_table_insert(field_symbol_hash, "phn", field);
field = NEW(new LogField("proxy_host_ip", "phi",
- LogField::STRING,
+ LogField::IP,
&LogAccess::marshal_proxy_host_ip,
- &LogAccess::unmarshal_str));
+ &LogAccess::unmarshal_ip_to_str));
global_field_list.add(field, false);
ink_hash_table_insert(field_symbol_hash, "phi", field);
@@ -748,9 +748,10 @@ Log::init_fields()
// server -> proxy fields
field = NEW(new LogField("server_host_ip", "shi",
- LogField::sINT,
+ LogField::IP,
&LogAccess::marshal_server_host_ip,
- &LogAccess::unmarshal_ip, (Ptr<LogFieldAliasMap>)
ip_map));
+ &LogAccess::unmarshal_ip_to_str));
+
global_field_list.add(field, false);
ink_hash_table_insert(field_symbol_hash, "shi", field);
Modified: trafficserver/traffic/trunk/proxy/logging/LogAccess.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogAccess.cc?rev=1196916&r1=1196915&r2=1196916&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogAccess.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogAccess.cc Thu Nov 3 01:39:44
2011
@@ -80,7 +80,7 @@ LogAccess::init()
int
LogAccess::marshal_client_host_ip(char *buf)
{
- DEFAULT_STR_FIELD;
+ DEFAULT_IP_FIELD;
}
/*-------------------------------------------------------------------------
@@ -339,7 +339,7 @@ LogAccess::marshal_proxy_req_server_name
int
LogAccess::marshal_proxy_req_server_ip(char *buf)
{
- DEFAULT_INT_FIELD;
+ DEFAULT_IP_FIELD;
}
/*-------------------------------------------------------------------------
@@ -387,18 +387,7 @@ LogAccess::marshal_proxy_host_name(char
int
LogAccess::marshal_proxy_host_ip(char *buf)
{
- char *str = NULL;
- Machine *machine = Machine::instance();
- int len = 0;
-
- if (machine) {
- str = machine->ip_string;
- len = LogAccess::strlen(str);
- }
- if (buf) {
- marshal_str(buf, str, len);
- }
- return len;
+ return marshal_ip(buf, &Machine::instance()->ip.sa);
}
@@ -408,7 +397,7 @@ LogAccess::marshal_proxy_host_ip(char *b
int
LogAccess::marshal_server_host_ip(char *buf)
{
- DEFAULT_INT_FIELD;
+ DEFAULT_IP_FIELD;
}
/*-------------------------------------------------------------------------
@@ -795,6 +784,35 @@ LogAccess::marshal_mem(char *dest, const
#endif
}
+/*-------------------------------------------------------------------------
+ LogAccess::marshal_ip
+
+ Marshal an IP address in a reasonably compact way. If the address isn't
+ valid (NULL or not IP) then marshal an invalid address record.
+ -------------------------------------------------------------------------*/
+
+int
+LogAccess::marshal_ip(char* dest, sockaddr const* ip) {
+ LogFieldIp data;
+ int len = sizeof(data);
+ if (ink_inet_is_ip4(ip)) {
+ LogFieldIp4* ip4 = static_cast<LogFieldIp4*>(&data);
+ ip4->_family = AF_INET;
+ ip4->_addr = ink_inet_ip4_addr_cast(ip);
+ len = sizeof(*ip4);
+ } else if (ink_inet_is_ip6(ip)) {
+ LogFieldIp6* ip6 = static_cast<LogFieldIp6*>(&data);
+ ip6->_family = AF_INET6;
+ ip6->_addr = ink_inet_ip6_addr_cast(ip);
+ len = sizeof(*ip6);
+ } else {
+ data._family = AF_UNSPEC;
+ }
+
+ if (dest) memcpy(dest, &data, len);
+ return INK_ALIGN_DEFAULT(len);
+}
+
inline int
LogAccess::unmarshal_with_map(int64_t code, char *dest, int len,
Ptr<LogFieldAliasMap> map, const char *msg)
{
@@ -1116,19 +1134,65 @@ LogAccess::unmarshal_http_status(char **
/*-------------------------------------------------------------------------
LogAccess::unmarshal_ip
- Retrieve the int pointed at by the buffer and treat as an IP address.
- Convert to a string and return the string. Advance the buffer pointer.
- String has the form "ddd.ddd.ddd.ddd".
+ Retrieve an IP address directly.
-------------------------------------------------------------------------*/
-
int
-LogAccess::unmarshal_ip(char **buf, char *dest, int len, Ptr<LogFieldAliasMap>
map)
+LogAccess::unmarshal_ip(char **buf, ts_ip_endpoint* dest)
{
+ int len = sizeof(LogFieldIp); // of object processed.
+
ink_assert(buf != NULL);
ink_assert(*buf != NULL);
ink_assert(dest != NULL);
- return (LogAccess::unmarshal_with_map(unmarshal_int(buf), dest, len, map));
+ LogFieldIp* raw = reinterpret_cast<LogFieldIp*>(*buf);
+ if (AF_INET == raw->_family) {
+ LogFieldIp4* ip4 = static_cast<LogFieldIp4*>(raw);
+ ink_inet_ip4_set(dest, ip4->_addr);
+ len = sizeof(*ip4);
+ } else if (AF_INET6 == raw->_family) {
+ LogFieldIp6* ip6 = static_cast<LogFieldIp6*>(raw);
+ ink_inet_ip6_set(dest, ip6->_addr);
+ len = sizeof(*ip6);
+ } else {
+ ink_inet_invalidate(dest);
+ }
+ len = INK_ALIGN_DEFAULT(len);
+ *buf += len;
+ return len;
+}
+
+/*-------------------------------------------------------------------------
+ LogAccess::unmarshal_ip_to_str
+
+ Retrieve the IP addresspointed at by the buffer and convert to a
+ string in standard format. The string is written to @a dest and its
+ length (not including nul) is returned. @a *buf is advanced.
+ -------------------------------------------------------------------------*/
+
+int
+LogAccess::unmarshal_ip_to_str(char **buf, char *dest, int len)
+{
+ ts_ip_endpoint ip;
+
+ unmarshal_ip(buf, &ip);
+ return ink_inet_ntop(&ip, dest, len) ? ::strlen(dest) : -1;
+}
+
+/*-------------------------------------------------------------------------
+ LogAccess::unmarshal_ip_to_hex
+
+ Retrieve the int pointed at by the buffer and treat as an IP
+ address. Convert to a string in byte oriented hexadeciaml and
+ return the string. Advance the buffer pointer.
+ -------------------------------------------------------------------------*/
+
+int
+LogAccess::unmarshal_ip_to_hex(char **buf, char *dest, int len)
+{
+ ts_ip_endpoint ip;
+ unmarshal_ip(buf, &ip);
+ return ink_inet_to_hex(&ip.sa, dest, len);
}
/*-------------------------------------------------------------------------
Modified: trafficserver/traffic/trunk/proxy/logging/LogAccess.h
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogAccess.h?rev=1196916&r1=1196915&r2=1196916&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogAccess.h (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogAccess.h Thu Nov 3 01:39:44
2011
@@ -112,6 +112,14 @@
return len; \
}
+#define DEFAULT_IP_FIELD {\
+ int len = sizeof(LogFieldIp); \
+ if (buf) { \
+ len = marshal_ip (buf, NULL); \
+ } \
+ return len; \
+}
+
// should be at least 22 bytes to always accomodate a converted
// MgmtInt, MgmtIntCounter or MgmtFloat. 22 bytes is enough for 64 bit
// ints + sign + eos, and enough for %e floating point representation
@@ -270,7 +278,9 @@ public:
static int unmarshal_http_version(char **buf, char *dest, int len);
static int unmarshal_http_text(char **buf, char *dest, int len);
static int unmarshal_http_status(char **buf, char *dest, int len);
- static int unmarshal_ip(char **buf, char *dest, int len,
Ptr<LogFieldAliasMap> map);
+ static int unmarshal_ip(char** buf, ts_ip_endpoint* dest);
+ static int unmarshal_ip_to_str(char **buf, char *dest, int len);
+ static int unmarshal_ip_to_hex(char** buf, char* dest, int len);
static int unmarshal_hierarchy(char **buf, char *dest, int len,
Ptr<LogFieldAliasMap> map);
static int unmarshal_finish_status(char **buf, char *dest, int len,
Ptr<LogFieldAliasMap> map);
static int unmarshal_cache_code(char **buf, char *dest, int len,
Ptr<LogFieldAliasMap> map);
@@ -286,12 +296,13 @@ public:
// so that there are no alignment problems with the int values.
//
static int round_strlen(int len);
- static int strlen(char *str);
+ static int strlen(char const* str);
public:
inkcoreapi static void marshal_int(char *dest, int64_t source);
inkcoreapi static void marshal_str(char *dest, const char *source, int
padded_len);
inkcoreapi static void marshal_mem(char *dest, const char *source, int
actual_len, int padded_len);
+ inkcoreapi static int marshal_ip(char *dest, sockaddr const* ip);
bool initialized;
@@ -315,7 +326,7 @@ LogAccess::round_strlen(int len)
-------------------------------------------------------------------------*/
inline int
-LogAccess::strlen(char *str)
+LogAccess::strlen(char const* str)
{
if (str == NULL || str[0] == 0) {
return round_strlen(sizeof(DEFAULT_STR));
Modified: trafficserver/traffic/trunk/proxy/logging/LogAccessHttp.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogAccessHttp.cc?rev=1196916&r1=1196915&r2=1196916&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogAccessHttp.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogAccessHttp.cc Thu Nov 3
01:39:44 2011
@@ -140,17 +140,7 @@ LogAccessHttp::init()
int
LogAccessHttp::marshal_client_host_ip(char *buf)
{
- char *str = NULL;
- int len = INK_MIN_ALIGN;
- char buffer[INET6_ADDRSTRLEN];
-
- str = const_cast<char*>(ink_inet_ntop(((struct sockaddr
*)&(m_http_sm->t_state.client_info.addr)), buffer, sizeof(buffer)));
- len = LogAccess::strlen(str);
-
- if (buf) {
- marshal_str (buf, str, len);
- }
- return len;
+ return marshal_ip(buf, &m_http_sm->t_state.client_info.addr.sa);
}
/*-------------------------------------------------------------------------
@@ -673,17 +663,7 @@ LogAccessHttp::marshal_proxy_hierarchy_r
int
LogAccessHttp::marshal_server_host_ip(char *buf)
{
- if (buf) {
- unsigned int val = 0;
- val = ink_inet_ip4_addr_cast(&m_http_sm->t_state.server_info.addr);
- if (val == 0) {
- if (m_http_sm->t_state.current.server != NULL) {
- val = ink_inet_ip4_addr_cast(&m_http_sm->t_state.current.server->addr);
- }
- }
- marshal_int(buf, (int64_t)ntohl(val));
- }
- return INK_MIN_ALIGN;
+ return marshal_ip(buf, &m_http_sm->t_state.server_info.addr.sa);
}
Modified: trafficserver/traffic/trunk/proxy/logging/LogAccessICP.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogAccessICP.cc?rev=1196916&r1=1196915&r2=1196916&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogAccessICP.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogAccessICP.cc Thu Nov 3
01:39:44 2011
@@ -68,12 +68,7 @@ LogAccessICP::~LogAccessICP()
int
LogAccessICP::marshal_client_host_ip(char *buf)
{
- if (buf) {
- int64_t ip = ink_inet_ip4_addr_cast(m_icp_log->GetClientIP());
- // ip is already in network order
- marshal_int(buf, (int64_t)ntohl(ip));
- }
- return INK_MIN_ALIGN;
+ return marshal_ip(buf, m_icp_log->GetClientIP());
}
/*-------------------------------------------------------------------------
Modified: trafficserver/traffic/trunk/proxy/logging/LogAccessTest.cc
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogAccessTest.cc?rev=1196916&r1=1196915&r2=1196916&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogAccessTest.cc (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogAccessTest.cc Thu Nov 3
01:39:44 2011
@@ -67,11 +67,9 @@ LogAccessTest::~LogAccessTest()
int
LogAccessTest::marshal_client_host_ip(char *buf)
{
- if (buf) {
- int64_t val = 0;
- marshal_int(buf, val);
- }
- return sizeof(int64_t);
+ ts_ip_endpoint lo;
+ ink_inet_ip4_set(&lo, INADDR_LOOPBACK);
+ return marshal_ip(buf, &lo.sa);
}
/*-------------------------------------------------------------------------
@@ -80,7 +78,7 @@ LogAccessTest::marshal_client_host_ip(ch
int
LogAccessTest::marshal_client_auth_user_name(char *buf)
{
- static char *str = "major tom";
+ static char const* str = "major tom";
int len = LogAccess::strlen(str);
if (buf) {
marshal_str(buf, str, len);
@@ -94,7 +92,7 @@ LogAccessTest::marshal_client_auth_user_
int
LogAccessTest::marshal_client_req_text(char *buf)
{
- static char *str = "GET http://www.foobar.com/ HTTP/1.0";
+ static char const* str = "GET http://www.foobar.com/ HTTP/1.0";
int len = LogAccess::strlen(str);
if (buf) {
marshal_str(buf, str, len);
@@ -121,7 +119,7 @@ LogAccessTest::marshal_client_req_http_m
int
LogAccessTest::marshal_client_req_url(char *buf)
{
- static char *str = "http://www.foobar.com/";
+ static char const* str = "http://www.foobar.com/";
int len = LogAccess::strlen(str);
if (buf) {
marshal_str(buf, str, len);
@@ -187,7 +185,7 @@ LogAccessTest::marshal_client_finish_sta
int
LogAccessTest::marshal_proxy_resp_content_type(char *buf)
{
- static char *str = "text/html";
+ static char const* str = "text/html";
int len = LogAccess::strlen(str);
if (buf) {
marshal_str(buf, str, len);
@@ -331,7 +329,7 @@ LogAccessTest::marshal_server_host_ip(ch
int
LogAccessTest::marshal_server_host_name(char *buf)
{
- static char *str = "www.foobar.com";
+ static char const* str = "www.foobar.com";
int len = LogAccess::strlen(str);
if (buf) {
marshal_str(buf, str, len);
Modified: trafficserver/traffic/trunk/proxy/logging/LogField.h
URL:
http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/logging/LogField.h?rev=1196916&r1=1196915&r2=1196916&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/logging/LogField.h (original)
+++ trafficserver/traffic/trunk/proxy/logging/LogField.h Thu Nov 3 01:39:44
2011
@@ -55,6 +55,7 @@ public:
sINT = 0,
dINT,
STRING,
+ IP, ///< IP Address.
N_TYPES
};
@@ -202,4 +203,24 @@ private:
LogFieldList & operator=(const LogFieldList & rhs);
};
+/** Base IP address data.
+ To unpack an IP address, the generic memory is first cast to
+ this type to get the family. That pointer can then be static_cast
+ to the appropriate subtype to get the actual address data.
+
+ @note We don't use our own enum for the family. Instead we use
+ @c AF_INET and @c AF_INET6.
+*/
+struct LogFieldIp {
+ uint16_t _family; ///< IP address family.
+};
+/// IPv4 address as log field.
+struct LogFieldIp4 : public LogFieldIp {
+ in_addr_t _addr; ///< IPv4 address.
+};
+/// IPv6 address as log field.
+struct LogFieldIp6 : public LogFieldIp {
+ in6_addr _addr; ///< IPv6 address.
+};
+
#endif