You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2011/03/08 19:03:06 UTC
svn commit: r1079455 - in /trafficserver/traffic/trunk/proxy: InkAPI.cc
api/ts/ts.h.in http/HttpConfig.cc http/HttpConfig.h http/HttpSM.cc
http/HttpTransact.h
Author: zwoop
Date: Tue Mar 8 18:03:05 2011
New Revision: 1079455
URL: http://svn.apache.org/viewvc?rev=1079455&view=rev
Log:
TS-692 Add an "experimental" API to modify the outgoing IP address.
This interface should be stable, but the underlying implementation
might change. For now, only the s_addr (IP) is used, and we only
support IPv4.
This also shows a "proof of concept" how I think our API interfaces
related to IP Get/Set should look like. Under the hood (in the core)
we should (going forward) use struct sockaddr_storage instead of
unsigned int's for IP (plus an int for port).
Modified:
trafficserver/traffic/trunk/proxy/InkAPI.cc
trafficserver/traffic/trunk/proxy/api/ts/ts.h.in
trafficserver/traffic/trunk/proxy/http/HttpConfig.cc
trafficserver/traffic/trunk/proxy/http/HttpConfig.h
trafficserver/traffic/trunk/proxy/http/HttpSM.cc
trafficserver/traffic/trunk/proxy/http/HttpTransact.h
Modified: trafficserver/traffic/trunk/proxy/InkAPI.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/InkAPI.cc?rev=1079455&r1=1079454&r2=1079455&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/InkAPI.cc (original)
+++ trafficserver/traffic/trunk/proxy/InkAPI.cc Tue Mar 8 18:03:05 2011
@@ -421,6 +421,7 @@ _TSAssert(const char *text, const char *
(void)((EX) || (_TSReleaseAssert(#EX, __FILE__, __LINE__)))
#endif
+
////////////////////////////////////////////////////////////////////
//
// SDK Interoperability Support
@@ -5118,6 +5119,34 @@ TSHttpTxnServerIPGet(TSHttpTxn txnp)
return sm->t_state.server_info.ip;
}
+// This API does currently not use or honor the port specified in the sockaddr.
+// This could change in a future version, but for now, leave it at 0 (or undef).
+TSReturnCode
+TSHttpTxnOutgoingIPSet(TSHttpTxn txnp, const struct sockaddr *addr, socklen_t addrlen)
+{
+ sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS);
+ HttpSM *sm = (HttpSM *) txnp;
+
+ sm->t_state.setup_per_txn_configs(); // Make sure the txn_conf struct is setup
+
+ // TODO: For now only, we really ought to make all "internal" IP representations
+ // use struct sockaddr_storage.
+ switch (addr->sa_family) {
+ case AF_INET:
+ {
+ sdk_assert(addrlen >= sizeof(struct sockaddr_in));
+ const struct sockaddr_in *v4addr = reinterpret_cast<const struct sockaddr_in *>(addr);
+ sm->t_state.txn_conf->outgoing_ip_to_bind_saddr = v4addr->sin_addr.s_addr;
+
+ return TS_SUCCESS;
+ }
+ break;
+ case AF_INET6:
+ break;
+ }
+ return TS_ERROR;
+}
+
unsigned int
TSHttpTxnNextHopIPGet(TSHttpTxn txnp)
{
@@ -7321,11 +7350,7 @@ TSHttpTxnConfigIntSet(TSHttpTxn txnp, TS
HttpSM *s = reinterpret_cast<HttpSM*>(txnp);
- // If this is the first time we're trying to modify a transaction config, copy it.
- if (s->t_state.txn_conf != &s->t_state.my_txn_conf) {
- memcpy(&s->t_state.my_txn_conf, &s->t_state.http_config_param->oride, sizeof(s->t_state.my_txn_conf));
- s->t_state.txn_conf = &s->t_state.my_txn_conf;
- }
+ s->t_state.setup_per_txn_configs();
OverridableDataType type;
TSMgmtInt *dest = static_cast<TSMgmtInt*>(_conf_to_memberp(conf, s, &type));
@@ -7369,11 +7394,7 @@ TSHttpTxnConfigFloatSet(TSHttpTxn txnp,
HttpSM *s = reinterpret_cast<HttpSM*>(txnp);
OverridableDataType type;
- // If this is the first time we're trying to modify a transaction config, copy it.
- if (s->t_state.txn_conf != &s->t_state.my_txn_conf) {
- memcpy(&s->t_state.my_txn_conf, &s->t_state.http_config_param->oride, sizeof(s->t_state.my_txn_conf));
- s->t_state.txn_conf = &s->t_state.my_txn_conf;
- }
+ s->t_state.setup_per_txn_configs();
TSMgmtFloat* dest = static_cast<TSMgmtFloat*>(_conf_to_memberp(conf, s, &type));
@@ -7419,11 +7440,7 @@ TSHttpTxnConfigStringSet(TSHttpTxn txnp,
HttpSM *s = (HttpSM*) txnp;
- // If this is the first time we're trying to modify a transaction config, copy it.
- if (s->t_state.txn_conf != &s->t_state.my_txn_conf) {
- memcpy(&s->t_state.my_txn_conf, &s->t_state.http_config_param->oride, sizeof(s->t_state.my_txn_conf));
- s->t_state.txn_conf = &s->t_state.my_txn_conf;
- }
+ s->t_state.setup_per_txn_configs();
switch (conf) {
case TS_CONFIG_HTTP_RESPONSE_SERVER_STR:
Modified: trafficserver/traffic/trunk/proxy/api/ts/ts.h.in
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/api/ts/ts.h.in?rev=1079455&r1=1079454&r2=1079455&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/api/ts/ts.h.in (original)
+++ trafficserver/traffic/trunk/proxy/api/ts/ts.h.in Tue Mar 8 18:03:05 2011
@@ -36,12 +36,12 @@
*
*/
-#include <sys/types.h>
#include <stdint.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
#define tsapi
-#define tsexp
-#define tsimp
#ifdef __cplusplus
extern "C"
@@ -637,7 +637,7 @@ extern "C"
plugin.config.
*/
- extern tsexp void TSPluginInit(int argc, const char* argv[]);
+ extern tsapi void TSPluginInit(int argc, const char* argv[]);
/* --------------------------------------------------------------------------
License */
@@ -652,7 +652,7 @@ extern "C"
@return Zero if no license is required. Returns 1 if a license
is required.
*/
- extern tsexp int TSPluginLicenseRequired(void);
+ extern tsapi int TSPluginLicenseRequired(void);
/* --------------------------------------------------------------------------
URL schemes */
@@ -2107,6 +2107,7 @@ extern "C"
tsapi unsigned int TSHttpTxnServerIPGet(TSHttpTxn txnp);
tsapi unsigned int TSHttpTxnNextHopIPGet(TSHttpTxn txnp);
tsapi int TSHttpTxnNextHopPortGet(TSHttpTxn txnp);
+ tsapi TSReturnCode TSHttpTxnOutgoingIPSet(TSHttpTxn txnp, const struct sockaddr *addr, socklen_t addrlen);
tsapi void TSHttpTxnErrorBodySet(TSHttpTxn txnp, char* buf, int buflength, char* mimetype);
Modified: trafficserver/traffic/trunk/proxy/http/HttpConfig.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpConfig.cc?rev=1079455&r1=1079454&r2=1079455&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpConfig.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpConfig.cc Tue Mar 8 18:03:05 2011
@@ -1138,7 +1138,7 @@ HttpConfig::startup()
if (c.outgoing_ip_to_bind) {
Debug("ip_binding", "outgoing_ip_to_bind: %s", c.outgoing_ip_to_bind);
- c.outgoing_ip_to_bind_saddr = inet_addr(c.outgoing_ip_to_bind);
+ c.oride.outgoing_ip_to_bind_saddr = inet_addr(c.outgoing_ip_to_bind);
}
HttpEstablishStaticConfigLongLong(c.server_max_connections, "proxy.config.http.server_max_connections");
@@ -1425,7 +1425,7 @@ HttpConfig::reconfigure()
params = NEW(new HttpConfigParams);
params->incoming_ip_to_bind_saddr = m_master.incoming_ip_to_bind_saddr;
- params->outgoing_ip_to_bind_saddr = m_master.outgoing_ip_to_bind_saddr;
+ params->oride.outgoing_ip_to_bind_saddr = m_master.oride.outgoing_ip_to_bind_saddr;
params->proxy_hostname = xstrdup(m_master.proxy_hostname);
params->proxy_hostname_len = (params->proxy_hostname) ? strlen(params->proxy_hostname) : 0;
params->no_dns_forward_to_parent = INT_TO_BOOL(m_master.no_dns_forward_to_parent);
Modified: trafficserver/traffic/trunk/proxy/http/HttpConfig.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpConfig.h?rev=1079455&r1=1079454&r2=1079455&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpConfig.h (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpConfig.h Tue Mar 8 18:03:05 2011
@@ -432,7 +432,8 @@ struct OverridableHttpConfigParams {
// Strings / floats must come last
proxy_response_server_string(NULL), proxy_response_server_string_len(0),
- cache_heuristic_lm_factor(0.0), freshness_fuzz_prob(0.0)
+ cache_heuristic_lm_factor(0.0), freshness_fuzz_prob(0.0),
+ outgoing_ip_to_bind_saddr(0)
{ }
// IMPORTANT: All MgmtInt configs should come before any other string / float
@@ -549,6 +550,11 @@ struct OverridableHttpConfigParams {
float cache_heuristic_lm_factor;
float freshness_fuzz_prob;
+
+ ////////////////////////
+ // Source IP //
+ ////////////////////////
+ unsigned int outgoing_ip_to_bind_saddr; // This is kinda ugly for now, whatever ...
};
@@ -588,7 +594,6 @@ public:
unsigned int incoming_ip_to_bind_saddr;
char *outgoing_ip_to_bind;
- unsigned int outgoing_ip_to_bind_saddr;
MgmtInt server_max_connections;
MgmtInt origin_min_keep_alive_connections; // TODO: This one really ought to be overridable, but difficult right now.
@@ -900,7 +905,6 @@ HttpConfigParams::HttpConfigParams()
incoming_ip_to_bind(0),
incoming_ip_to_bind_saddr(0),
outgoing_ip_to_bind(0),
- outgoing_ip_to_bind_saddr(0),
server_max_connections(0),
origin_min_keep_alive_connections(0),
parent_proxy_routing_enable(false),
Modified: trafficserver/traffic/trunk/proxy/http/HttpSM.cc
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpSM.cc?rev=1079455&r1=1079454&r2=1079455&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpSM.cc (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpSM.cc Tue Mar 8 18:03:05 2011
@@ -4070,9 +4070,9 @@ HttpSM::do_http_server_open(bool raw)
t_state.txn_conf->sock_send_buffer_size_out,
t_state.txn_conf->sock_option_flag_out);
- if (t_state.http_config_param->outgoing_ip_to_bind_saddr) {
+ if (t_state.txn_conf->outgoing_ip_to_bind_saddr) {
opt.addr_binding = NetVCOptions::INTF_ADDR;
- opt.local_addr = t_state.http_config_param->outgoing_ip_to_bind_saddr;
+ opt.local_addr = t_state.txn_conf->outgoing_ip_to_bind_saddr;
} else if (t_state.server_info.is_transparent) {
opt.addr_binding = NetVCOptions::FOREIGN_ADDR;
opt.local_addr = t_state.client_info.ip;
Modified: trafficserver/traffic/trunk/proxy/http/HttpTransact.h
URL: http://svn.apache.org/viewvc/trafficserver/traffic/trunk/proxy/http/HttpTransact.h?rev=1079455&r1=1079454&r2=1079455&view=diff
==============================================================================
--- trafficserver/traffic/trunk/proxy/http/HttpTransact.h (original)
+++ trafficserver/traffic/trunk/proxy/http/HttpTransact.h Tue Mar 8 18:03:05 2011
@@ -1056,7 +1056,6 @@ public:
OverridableHttpConfigParams *txn_conf;
OverridableHttpConfigParams my_txn_conf; // Storage for plugins, to avoid malloc
-
// Methods
void
init()
@@ -1236,6 +1235,18 @@ public:
pristine_url.clear();
return;
}
+
+ // Little helper function to setup the per-transaction configuration copy
+ void
+ setup_per_txn_configs()
+ {
+ if (txn_conf != &my_txn_conf) {
+ // Make sure we copy it first.
+ memcpy(&my_txn_conf, &http_config_param->oride, sizeof(my_txn_conf));
+ txn_conf = &my_txn_conf;
+ }
+ }
+
}; // End of State struct.