Support IPv6 subnets in parent extip

This commit is contained in:
z3apa3a 2021-04-21 20:39:57 +03:00
parent 36f16fb899
commit bad85a3d51
4 changed files with 30 additions and 8 deletions

View File

@ -253,6 +253,24 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
if(cur->type == R_EXTIP){
param->sinsl = cur->addr;
if(SAISNULL(&param->sinsl))param->sinsl = param->sincr;
#ifndef NOIPV6
else if(cur->cidr && *SAFAMILY(&param->sinsl) == AF_INET6){
char c;
int i;
for(i = 0; i < 16; i++){
if(i%8)myrand(&param->sincr, sizeof(param->sincr));
else if(i%4) myrand(&param->req, sizeof(param->req));
if(i*8 >= cur->cidr) ((char *)SAADDR(&param->sinsl))[i] = rand();
else if ((i+1)*8 > cur->cidr){
c = rand();
c >>= (cur->cidr - (i*8));
((char *)SAADDR(&param->sinsl))[i] |= c;
}
}
}
#endif
if(cur->next)continue;
return 0;
}

View File

@ -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();

View File

@ -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]);

View File

@ -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 {