virt_db, multi: relays Z39.50 client-IP.
sru_z3950: converts X-Forwarded-For header to Z39.50 client-IP.
zoom: uses Client-IP or origin address (prefer Client-IP).
frontend_net: Strips tcp: from peer address (so that it is no longer
printed and stripped in zoom filter).
z3950_client: builds client-IP list - combining immediate peer address
as returned by COMSTACK and existing client-IP list (if avaiable).
The Origin only printes first X-Forwarded address.
unsigned int m_origin_id;
int m_max_sockets;
std::string m_custom_session;
+ std::string get_forward_address() const;
};
}
const char *peername = PDU_Observable->getpeername();
if (!peername)
peername = "unknown";
+ else
+ {
+ const char *cp = strchr(peername, ':');
+ if (cp)
+ peername = cp + 1;
+ }
m_origin.set_tcpip_address(std::string(peername), m_session.id());
timeout(m_p->m_session_timeout);
}
#include <yaz/otherinfo.h>
#include <yaz/diagbib1.h>
#include <yaz/match_glob.h>
+#include <yaz/oid_db.h>
#include <vector>
#include <algorithm>
*breq->preferredMessageSize = *req->preferredMessageSize;
*breq->maximumRecordSize = *req->maximumRecordSize;
+
+ const char *peer_name = yaz_oi_get_string_oid(
+ &req->otherInfo, yaz_oid_userinfo_client_ip, 1, 0);
+ if (peer_name)
+ yaz_oi_set_string_oid(&breq->otherInfo, odr,
+ yaz_oid_userinfo_client_ip, 1, peer_name);
+
ODR_MASK_SET(breq->options, Z_Options_search);
ODR_MASK_SET(breq->options, Z_Options_present);
ODR_MASK_SET(breq->options, Z_Options_namedResultSets);
#include <yaz/pquery.h>
#include <yaz/oid_db.h>
#include <yaz/log.h>
+#include <yaz/otherinfo.h>
#if YAZ_VERSIONL >= 0x50000
#include <yaz/facet.h>
#endif
mp_util::set_vhost_otherinfo(&init_req->otherInfo, odr_en, host, 1);
}
+ Z_GDU *zgdu_req = package.request().get();
+ if (zgdu_req->which == Z_GDU_HTTP_Request)
+ {
+ Z_HTTP_Request *hreq = zgdu_req->u.HTTP_Request;
+ const char *peer_name =
+ z_HTTP_header_lookup(hreq->headers, "X-Forwarded-For");
+ if (peer_name)
+ {
+ yaz_oi_set_string_oid(&init_req->otherInfo, odr_en,
+ yaz_oid_userinfo_client_ip, 1, peer_name);
+ }
+ }
+
z3950_package.request() = apdu;
// send Z3950 package
#include <yaz/diagbib1.h>
#include <yaz/match_glob.h>
#include <yaz/log.h>
+#include <yaz/oid_db.h>
#include <map>
#include <iostream>
Z_GDU *org_gdu = m_init_gdu.get();
Z_InitRequest *org_init = org_gdu->u.z3950->u.initRequest;
+
+ const char *peer_name = yaz_oi_get_string_oid(
+ &org_init->otherInfo, yaz_oid_userinfo_client_ip, 1, 0);
+ if (peer_name)
+ yaz_oi_set_string_oid(&init_apdu->u.initRequest->otherInfo, odr,
+ yaz_oid_userinfo_client_ip, 1, peer_name);
+
req->idAuthentication = org_init->idAuthentication;
req->implementationId = org_init->implementationId;
req->implementationName = org_init->implementationName;
#include <yaz/log.h>
#include <yaz/otherinfo.h>
#include <yaz/diagbib1.h>
+#include <yaz/oid_db.h>
#include <yazpp/socket-manager.h>
#include <yazpp/pdu-assoc.h>
if (gdu->u.z3950->which == Z_APDU_close)
c->m_has_closed = true;
+ Z_APDU *apdu = gdu->u.z3950;
+
// prepare connect
c->m_time_elapsed = 0;
c->m_waiting = true;
{
return;
}
-
+ const char *peer_name2 = package.origin().get_address().c_str();
+ mp::odr odr;
+ if (apdu->which == Z_APDU_initRequest && peer_name2)
+ {
+ Z_OtherInformation **oi = &apdu->u.initRequest->otherInfo;
+ char *peer_name1 =
+ yaz_oi_get_string_oid(oi, yaz_oid_userinfo_client_ip, 1, 1);
+ char *pcomb = (char *)
+ odr_malloc(odr, (peer_name1 ? strlen(peer_name1) : 0)
+ + strlen(peer_name2) + 4);
+ strcpy(pcomb, "");
+ if (peer_name1)
+ {
+ strcat(pcomb, peer_name1);
+ strcat(pcomb, ", ");
+ }
+ strcat(pcomb, peer_name2);
+ yaz_oi_set_string_oid(&apdu->u.initRequest->otherInfo,
+ odr, yaz_oid_userinfo_client_ip,
+ 1, pcomb);
+ }
// prepare response
c->m_time_elapsed = 0;
c->m_waiting = true;
#include <yaz/sortspec.h>
#include <yaz/tokenizer.h>
#include <yaz/zoom.h>
+#include <yaz/otherinfo.h>
namespace mp = metaproxy_1;
namespace yf = mp::filter;
}
}
- std::string ip = package.origin().get_address();
- yaz_log(YLOG_LOG, "IP=%s", ip.c_str());
+ Z_OtherInformation **oi = &req->otherInfo;
+ const char *ip =
+ yaz_oi_get_string_oid(oi, yaz_oid_userinfo_client_ip, 1, 0);
+ if (!ip)
+ ip = package.origin().get_address().c_str();
+
+ yaz_log(YLOG_LOG, "IP=%s", ip);
std::string torus_query;
int failure_code;
}
else
{
- const char *ip_cstr = ip.c_str();
- const char *cp = strchr(ip_cstr, ':');
- if (cp)
- ip_cstr = cp + 1;
-
torus_query = "ip encloses/net.ipaddress \"";
- torus_query += escape_cql_term(std::string(ip_cstr));
+ torus_query += escape_cql_term(std::string(ip));
torus_query += "\"";
failure_code = YAZ_BIB1_INIT_AC_BLOCKED_NETWORK_ADDRESS;
}
#include "config.hpp"
#include <metaproxy/origin.hpp>
-
+#include <yaz/log.h>
#include <iostream>
namespace mp = metaproxy_1;
void mp::Origin::set_tcpip_address(std::string addr, unsigned long s)
{
+ // assume first call is immediate reverse IP: cs_addrstr(COMSTACK)
+ // 2nd call might be X-Forwarded .. we use that for logging
+ std::string tmp = m_address;
m_address = addr;
+ if (tmp.length())
+ {
+ m_address.append(" ");
+ m_address.append(tmp);
+ }
m_origin_id = s;
}
m_custom_session = s;
}
+std::string mp::Origin::get_forward_address() const
+{
+ // return first component of address
+ // That's either first part of X-Forwarded component
+ size_t pos = m_address.find(' ');
+ if (pos != std::string::npos)
+ return m_address.substr(0, pos);
+ else
+ return m_address;
+}
+
std::string mp::Origin::get_address()
{
- return m_address;
+ // return last component of address
+ size_t pos = m_address.rfind(' ');
+ if (pos != std::string::npos)
+ return m_address.substr(pos + 1);
+ else
+ return m_address;
}
std::ostream& std::operator<<(std::ostream& os, const mp::Origin& o)
{
- if (o.m_address.length())
- os << o.m_address;
+ // print first component of address
+ std::string a = o.get_forward_address();
+ if (a.length())
+ os << a;
else
os << "0";
os << ":" << o.m_origin_id;