Skip to content

Commit b60d7a8

Browse files
serrislewSerris Lew
andauthored
Support UDS path for prefetch and esi plugin (#12156)
* Prefetch plugin support UDS path * support uds in esi --------- Co-authored-by: Serris Lew <lserris@apple.com>
1 parent cf93613 commit b60d7a8

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

plugins/esi/fetcher/HttpDataFetcherImpl.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ HttpDataFetcherImpl::HttpDataFetcherImpl(TSCont contp, sockaddr const *client_ad
6565
memcpy(&_client_addr, client_addr, sizeof(sockaddr_in));
6666
} else if (client_addr->sa_family == AF_INET6) {
6767
memcpy(&_client_addr, client_addr, sizeof(sockaddr_in6));
68+
} else if (client_addr->sa_family == AF_UNIX) {
69+
memcpy(&_client_addr, client_addr, sizeof(sockaddr_un));
6870
} else {
6971
memcpy(&_client_addr, &sin, sizeof(sin));
7072
TSError("[HttpDataFetcherImpl] Unknown address family %d", client_addr->sa_family);

plugins/esi/fetcher/HttpDataFetcherImpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <list>
2828
#include <vector>
2929
#include <netinet/in.h>
30+
#include <sys/un.h>
3031

3132
#include "ts/ts.h"
3233
#include "StringHash.h"

plugins/prefetch/fetch.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
#include <netinet/ip.h>
2828
#include <cstring>
2929
#include <sys/socket.h>
30+
#include <sys/un.h>
3031
#include <cinttypes>
3132

3233
#include "ts/ts.h" /* ATS API */
3334
#include "fetch.h"
3435
#include "headers.h"
36+
#include "tscore/ink_inet.h"
3537

3638
namespace
3739
{
@@ -437,6 +439,8 @@ BgFetch::saveIp(TSHttpTxn txnp)
437439
memcpy(&client_ip, ip, sizeof(sockaddr_in));
438440
} else if (ip->sa_family == AF_INET6) {
439441
memcpy(&client_ip, ip, sizeof(sockaddr_in6));
442+
} else if (ip->sa_family == AF_UNIX) {
443+
memcpy(&client_ip, ip, sizeof(sockaddr_un));
440444
} else {
441445
PrefetchError("unknown address family %d", ip->sa_family);
442446
}
@@ -685,6 +689,11 @@ BgFetch::handler(TSCont contp, TSEvent event, void * /* edata ATS_UNUSED */)
685689
inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)sockaddress)->sin6_addr), buf, INET6_ADDRSTRLEN);
686690
PrefetchDebug("client IPv6 = %s", buf);
687691
break;
692+
case AF_UNIX:
693+
char path[TS_UNIX_SIZE];
694+
strncpy(path, ats_unix_cast(sockaddress)->sun_path, TS_UNIX_SIZE);
695+
PrefetchDebug("client UDS = %s", path);
696+
break;
688697
default:
689698
TSError("[%s] Unknown address family %d", PLUGIN_NAME, sockaddress->sa_family);
690699
break;

0 commit comments

Comments
 (0)