|
Lines 40-48
Link Here
|
| 40 |
#include <linux/types.h> |
40 |
#include <linux/types.h> |
| 41 |
#include <linux/netfilter_ipv4.h> |
41 |
#include <linux/netfilter_ipv4.h> |
| 42 |
#endif |
42 |
#endif |
| 43 |
#if LINUX_TPROXY |
|
|
| 44 |
#include <linux/netfilter_ipv4/ip_tproxy.h> |
| 45 |
#endif |
| 46 |
|
43 |
|
| 47 |
static PSC fwdStartComplete; |
44 |
static PSC fwdStartComplete; |
| 48 |
static void fwdDispatch(FwdState *); |
45 |
static void fwdDispatch(FwdState *); |
|
Lines 523-531
Link Here
|
| 523 |
int ftimeout = Config.Timeout.forward - (squid_curtime - fwdState->start); |
520 |
int ftimeout = Config.Timeout.forward - (squid_curtime - fwdState->start); |
| 524 |
struct in_addr outgoing; |
521 |
struct in_addr outgoing; |
| 525 |
unsigned short tos; |
522 |
unsigned short tos; |
| 526 |
#if LINUX_TPROXY |
523 |
int flags; |
| 527 |
struct in_tproxy itp; |
|
|
| 528 |
#endif |
| 529 |
int idle = -1; |
524 |
int idle = -1; |
| 530 |
|
525 |
|
| 531 |
assert(fs); |
526 |
assert(fs); |
|
Lines 576-584
Link Here
|
| 576 |
fwdRestart(fwdState); |
571 |
fwdRestart(fwdState); |
| 577 |
return; |
572 |
return; |
| 578 |
} |
573 |
} |
| 579 |
#if LINUX_TPROXY |
574 |
#if LINUX_NETFILTER |
| 580 |
if (fd == -1 && fwdState->request->flags.tproxy) |
575 |
if (fd == -1 && fwdState->request->flags.tproxy) |
| 581 |
fd = pconnPop(name, port, domain, &fwdState->request->client_addr, 0, NULL); |
576 |
fd = pconnPop(name, port, domain, &fwdState->request->client_addr, 0, NULL); |
|
|
577 |
else |
| 582 |
#endif |
578 |
#endif |
| 583 |
if (fd == -1) { |
579 |
if (fd == -1) { |
| 584 |
fd = pconnPop(name, port, domain, NULL, 0, &idle); |
580 |
fd = pconnPop(name, port, domain, NULL, 0, &idle); |
|
Lines 630-640
Link Here
|
| 630 |
|
626 |
|
| 631 |
debug(17, 3) ("fwdConnectStart: got addr %s, tos %d\n", |
627 |
debug(17, 3) ("fwdConnectStart: got addr %s, tos %d\n", |
| 632 |
inet_ntoa(outgoing), tos); |
628 |
inet_ntoa(outgoing), tos); |
|
|
629 |
|
| 630 |
flags = COMM_NONBLOCKING; |
| 631 |
#if LINUX_NETFILTER |
| 632 |
if ((outgoing.s_addr == INADDR_ANY) && fwdState->request->flags.tproxy) { |
| 633 |
outgoing = fwdState->request->client_addr; |
| 634 |
flags |= COMM_TRANSPARENT; |
| 635 |
debug(17,3)("fwdConnectStart: setting outgoing.s_addr=%08X (will set TRANSPARENT)\n", |
| 636 |
outgoing.s_addr); |
| 637 |
} |
| 638 |
#endif |
| 633 |
fd = comm_openex(SOCK_STREAM, |
639 |
fd = comm_openex(SOCK_STREAM, |
| 634 |
IPPROTO_TCP, |
640 |
IPPROTO_TCP, |
| 635 |
outgoing, |
641 |
outgoing, |
| 636 |
0, |
642 |
0, |
| 637 |
COMM_NONBLOCKING, |
643 |
flags, |
| 638 |
tos, |
644 |
tos, |
| 639 |
url); |
645 |
url); |
| 640 |
if (fd < 0) { |
646 |
if (fd < 0) { |
|
Lines 667-698
Link Here
|
| 667 |
if (fs->peer) { |
673 |
if (fs->peer) { |
| 668 |
hierarchyNote(&fwdState->request->hier, fs->code, fs->peer->name); |
674 |
hierarchyNote(&fwdState->request->hier, fs->code, fs->peer->name); |
| 669 |
} else { |
675 |
} else { |
| 670 |
#if LINUX_TPROXY |
|
|
| 671 |
if (fwdState->request->flags.tproxy) { |
| 672 |
|
| 673 |
itp.v.addr.faddr.s_addr = fwdState->src.sin_addr.s_addr; |
| 674 |
itp.v.addr.fport = 0; |
| 675 |
|
| 676 |
/* If these syscalls fail then we just fallback to connecting |
| 677 |
* normally by simply ignoring the errors... |
| 678 |
*/ |
| 679 |
itp.op = TPROXY_ASSIGN; |
| 680 |
if (setsockopt(fd, SOL_IP, IP_TPROXY, &itp, sizeof(itp)) == -1) { |
| 681 |
debug(20, 1) ("tproxy ip=%s,0x%x,port=%d ERROR ASSIGN\n", |
| 682 |
inet_ntoa(itp.v.addr.faddr), |
| 683 |
itp.v.addr.faddr.s_addr, |
| 684 |
itp.v.addr.fport); |
| 685 |
} else { |
| 686 |
itp.op = TPROXY_FLAGS; |
| 687 |
itp.v.flags = ITP_CONNECT; |
| 688 |
if (setsockopt(fd, SOL_IP, IP_TPROXY, &itp, sizeof(itp)) == -1) { |
| 689 |
debug(20, 1) ("tproxy ip=%x,port=%d ERROR CONNECT\n", |
| 690 |
itp.v.addr.faddr.s_addr, |
| 691 |
itp.v.addr.fport); |
| 692 |
} |
| 693 |
} |
| 694 |
} |
| 695 |
#endif |
| 696 |
hierarchyNote(&fwdState->request->hier, fs->code, fwdState->request->host); |
676 |
hierarchyNote(&fwdState->request->hier, fs->code, fwdState->request->host); |
| 697 |
} |
677 |
} |
| 698 |
commConnectStart(fd, host, port, fwdConnectDone, fwdState); |
678 |
commConnectStart(fd, host, port, fwdConnectDone, fwdState); |
|
Lines 953-959
Link Here
|
| 953 |
fwdState->start = squid_curtime; |
933 |
fwdState->start = squid_curtime; |
| 954 |
fwdState->orig_entry_flags = e->flags; |
934 |
fwdState->orig_entry_flags = e->flags; |
| 955 |
|
935 |
|
| 956 |
#if LINUX_TPROXY |
936 |
#if LINUX_NETFILTER |
| 957 |
/* If we need to transparently proxy the request |
937 |
/* If we need to transparently proxy the request |
| 958 |
* then we need the client source address and port */ |
938 |
* then we need the client source address and port */ |
| 959 |
fwdState->src.sin_family = AF_INET; |
939 |
fwdState->src.sin_family = AF_INET; |