Transparent IPV6

This commit is contained in:
ruti 2024-09-17 22:51:39 +03:00
parent 5e5dec60f2
commit a9ecc83932
2 changed files with 13 additions and 5 deletions

2
main.c
View File

@ -23,7 +23,7 @@
#define close(fd) closesocket(fd)
#endif
#define VERSION "14"
#define VERSION "14.1"
char ip_option[1] = "\0";

12
proxy.c
View File

@ -35,6 +35,9 @@
#ifdef __linux__
/* For SO_ORIGINAL_DST only (which is 0x50) */
#include "linux/netfilter_ipv4.h"
#ifndef IP6T_SO_ORIGINAL_DST
#define IP6T_SO_ORIGINAL_DST SO_ORIGINAL_DST
#endif
#endif
#endif
@ -129,6 +132,7 @@ int resolve(char *host, int len,
char rchar = host[len];
host[len] = '\0';
LOG(LOG_S, "resolve: %s\n", host);
if (getaddrinfo(host, 0, &hints, &res) || !res) {
host[len] = rchar;
@ -543,11 +547,15 @@ static inline int transp_conn(struct poolhd *pool, struct eval *val)
{
struct sockaddr_ina remote, self;
socklen_t rlen = sizeof(remote), slen = sizeof(self);
if (getsockopt(val->fd,
IPPROTO_IP, SO_ORIGINAL_DST, &remote, &rlen) != 0) {
if (getsockopt(val->fd, IPPROTO_IP,
SO_ORIGINAL_DST, &remote, &rlen) != 0)
{
if (getsockopt(val->fd, IPPROTO_IPV6,
IP6T_SO_ORIGINAL_DST, &remote, &rlen) != 0) {
uniperror("getsockopt SO_ORIGINAL_DST");
return -1;
}
}
if (getsockname(val->fd, &self.sa, &slen) < 0) {
uniperror("getsockname");
return -1;