mirror of
https://github.com/bol-van/zapret2.git
synced 2026-03-14 06:13:09 +00:00
AI inspired fixes
This commit is contained in:
@@ -49,7 +49,7 @@ static int ucmp(const void * a, const void * b, void *arg)
|
|||||||
}
|
}
|
||||||
static uint32_t mask_from_bitcount(uint32_t zct)
|
static uint32_t mask_from_bitcount(uint32_t zct)
|
||||||
{
|
{
|
||||||
return zct<32 ? ~((1 << zct) - 1) : 0;
|
return zct<32 ? ~((1u << zct) - 1) : 0;
|
||||||
}
|
}
|
||||||
// make presorted array unique. return number of unique items.
|
// make presorted array unique. return number of unique items.
|
||||||
// 1,1,2,3,3,0,0,0 (ct=8) => 1,2,3,0 (ct=4)
|
// 1,1,2,3,3,0,0,0 (ct=8) => 1,2,3,0 (ct=4)
|
||||||
@@ -138,7 +138,7 @@ static void mask_from_bitcount6_make(uint32_t zct, struct in6_addr *a)
|
|||||||
int32_t n = (127 - zct) >> 3;
|
int32_t n = (127 - zct) >> 3;
|
||||||
memset(a->s6_addr,0xFF,n);
|
memset(a->s6_addr,0xFF,n);
|
||||||
memset(a->s6_addr+n,0x00,16-n);
|
memset(a->s6_addr+n,0x00,16-n);
|
||||||
a->s6_addr[n] = ~((1 << (zct & 7)) - 1);
|
a->s6_addr[n] = ~((1u << (zct & 7)) - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static struct in6_addr ip6_mask[129];
|
static struct in6_addr ip6_mask[129];
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ static bool dom_valid(char *dom)
|
|||||||
static void invalid_domain_beautify(char *dom)
|
static void invalid_domain_beautify(char *dom)
|
||||||
{
|
{
|
||||||
for (int i = 0; *dom && i < 64; i++, dom++)
|
for (int i = 0; *dom && i < 64; i++, dom++)
|
||||||
if (*dom < 0x20 || *dom>0x7F) *dom = '?';
|
if (*dom < 0x20 || *dom<0) *dom = '?';
|
||||||
if (*dom) *dom = 0;
|
if (*dom) *dom = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#define UNIQ_SORT \
|
#define UNIQ_SORT \
|
||||||
{ \
|
{ \
|
||||||
int i, j, u; \
|
size_t i, j, u; \
|
||||||
for (i = j = 0; j < ct; i++) \
|
for (i = j = 0; j < ct; i++) \
|
||||||
{ \
|
{ \
|
||||||
u = pu[j++]; \
|
u = pu[j++]; \
|
||||||
@@ -642,42 +642,13 @@ bool set_env_exedir(const char *argv0)
|
|||||||
if ((s = strdup(argv0)))
|
if ((s = strdup(argv0)))
|
||||||
{
|
{
|
||||||
if ((d = dirname(s)))
|
if ((d = dirname(s)))
|
||||||
setenv("EXEDIR",s,1);
|
bOK = !setenv("EXEDIR",d,1);
|
||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
return bOK;
|
return bOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void mask_from_preflen6_make(uint8_t plen, struct in6_addr *a)
|
|
||||||
{
|
|
||||||
if (plen >= 128)
|
|
||||||
memset(a->s6_addr,0xFF,16);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
uint8_t n = plen >> 3;
|
|
||||||
memset(a->s6_addr,0xFF,n);
|
|
||||||
memset(a->s6_addr+n,0x00,16-n);
|
|
||||||
a->s6_addr[n] = (uint8_t)(0xFF00 >> (plen & 7));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
struct in6_addr ip6_mask[129];
|
|
||||||
void mask_from_preflen6_prepare(void)
|
|
||||||
{
|
|
||||||
for (int plen=0;plen<=128;plen++) mask_from_preflen6_make(plen, ip6_mask+plen);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(__GNUC__) && !defined(__llvm__)
|
|
||||||
__attribute__((optimize ("no-strict-aliasing")))
|
|
||||||
#endif
|
|
||||||
void ip6_and(const struct in6_addr * restrict a, const struct in6_addr * restrict b, struct in6_addr * restrict result)
|
|
||||||
{
|
|
||||||
// int128 requires 16-bit alignment. in struct sockaddr_in6.sin6_addr is 8-byte aligned.
|
|
||||||
// it causes segfault on x64 arch with latest compiler. it can cause misalign slowdown on other archs
|
|
||||||
// use 64-bit AND
|
|
||||||
((uint64_t*)result->s6_addr)[0] = ((uint64_t*)a->s6_addr)[0] & ((uint64_t*)b->s6_addr)[0];
|
|
||||||
((uint64_t*)result->s6_addr)[1] = ((uint64_t*)a->s6_addr)[1] & ((uint64_t*)b->s6_addr)[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
void str_cidr4(char *s, size_t s_len, const struct cidr4 *cidr)
|
void str_cidr4(char *s, size_t s_len, const struct cidr4 *cidr)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -139,15 +139,3 @@ bool parse_cidr4(char *s, struct cidr4 *cidr);
|
|||||||
bool parse_cidr6(char *s, struct cidr6 *cidr);
|
bool parse_cidr6(char *s, struct cidr6 *cidr);
|
||||||
|
|
||||||
bool parse_int16(const char *p, int16_t *v);
|
bool parse_int16(const char *p, int16_t *v);
|
||||||
|
|
||||||
static inline uint32_t mask_from_preflen(uint32_t preflen)
|
|
||||||
{
|
|
||||||
return preflen ? preflen<32 ? ~((1 << (32-preflen)) - 1) : 0xFFFFFFFF : 0;
|
|
||||||
}
|
|
||||||
void ip6_and(const struct in6_addr * restrict a, const struct in6_addr * restrict b, struct in6_addr * restrict result);
|
|
||||||
extern struct in6_addr ip6_mask[129];
|
|
||||||
void mask_from_preflen6_prepare(void);
|
|
||||||
static inline const struct in6_addr *mask_from_preflen6(uint8_t preflen)
|
|
||||||
{
|
|
||||||
return ip6_mask+preflen;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1732,7 +1732,6 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
srandom(time(NULL));
|
srandom(time(NULL));
|
||||||
aes_init_keygen_tables(); // required for aes
|
aes_init_keygen_tables(); // required for aes
|
||||||
mask_from_preflen6_prepare();
|
|
||||||
set_env_exedir(argv[0]);
|
set_env_exedir(argv[0]);
|
||||||
set_console_io_buffering();
|
set_console_io_buffering();
|
||||||
#ifdef __CYGWIN__
|
#ifdef __CYGWIN__
|
||||||
|
|||||||
Reference in New Issue
Block a user