From bad85a3d51ee03522190283d3d699b382bec075e Mon Sep 17 00:00:00 2001 From: z3apa3a <3proxy@3proxy.ru> Date: Wed, 21 Apr 2021 20:39:57 +0300 Subject: [PATCH] Support IPv6 subnets in parent extip --- src/auth.c | 18 ++++++++++++++++++ src/common.c | 6 +++--- src/conf.c | 11 +++++++---- src/structures.h | 3 ++- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/auth.c b/src/auth.c index 3dbbbfb..3c06efd 100644 --- a/src/auth.c +++ b/src/auth.c @@ -253,6 +253,24 @@ int handleredirect(struct clientparam * param, struct ace * acentry){ if(cur->type == R_EXTIP){ param->sinsl = cur->addr; if(SAISNULL(¶m->sinsl))param->sinsl = param->sincr; +#ifndef NOIPV6 + else if(cur->cidr && *SAFAMILY(¶m->sinsl) == AF_INET6){ + char c; + int i; + + for(i = 0; i < 16; i++){ + if(i%8)myrand(¶m->sincr, sizeof(param->sincr)); + else if(i%4) myrand(¶m->req, sizeof(param->req)); + + if(i*8 >= cur->cidr) ((char *)SAADDR(¶m->sinsl))[i] = rand(); + else if ((i+1)*8 > cur->cidr){ + c = rand(); + c >>= (cur->cidr - (i*8)); + ((char *)SAADDR(¶m->sinsl))[i] |= c; + } + } + } +#endif if(cur->next)continue; return 0; } diff --git a/src/common.c b/src/common.c index 7b2d29c..001a4a7 100644 --- a/src/common.c +++ b/src/common.c @@ -137,13 +137,13 @@ char* NULLADDR="\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; int myrand(void * entropy, int len){ int i; - unsigned short init; + uint16_t init; init = randomizer; for(i=0; i < len/2; i++){ - init ^= ((unsigned short *)entropy)[i]; + init ^= ((uint16_t *)entropy)[i]; } - srand(init); + srand(rand()+init); randomizer = rand(); return rand(); diff --git a/src/conf.c b/src/conf.c index d1ebec1..fcdecdc 100644 --- a/src/conf.c +++ b/src/conf.c @@ -710,6 +710,7 @@ static int h_monitor(int argc, unsigned char **argv){ static int h_parent(int argc, unsigned char **argv){ struct ace *acl = NULL; struct chain *chains; + char * cidr; acl = conf.acl; while(acl && acl->next) acl = acl->next; @@ -748,13 +749,15 @@ static int h_parent(int argc, unsigned char **argv){ fprintf(stderr, "Chaining error: bad chain type (%s)\n", argv[2]); return(4); } -#ifndef NOIPV6 - if(!getip46(46, argv[3], (struct sockaddr *)&chains->addr)) return 5; -#else + cidr = strchr(argv[3], '/'); + if(cidr) *cidr = 0; getip46(46, argv[3], (struct sockaddr *)&chains->addr); -#endif chains->exthost = (unsigned char *)mystrdup((char *)argv[3]); if(!chains->exthost) return 21; + if(cidr){ + *cidr = '/'; + chains->cidr = atoi(cidr + 1); + } *SAPORT(&chains->addr) = htons((unsigned short)atoi((char *)argv[4])); if(argc > 5) chains->extuser = (unsigned char *)mystrdup((char *)argv[5]); if(argc > 6) chains->extpass = (unsigned char *)mystrdup((char *)argv[6]); diff --git a/src/structures.h b/src/structures.h index a8a2698..61a4f31 100644 --- a/src/structures.h +++ b/src/structures.h @@ -286,10 +286,11 @@ struct chain { #else struct sockaddr_in addr; #endif - unsigned short weight; unsigned char * exthost; unsigned char * extuser; unsigned char * extpass; + unsigned short weight; + unsigned short cidr; }; struct period {