Loading tpws/helpers.c +55 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,61 @@ void expand_bits(void *target, const void *source, unsigned int source_bitlen, u if ((bitlen &= 7)) ((uint8_t*)target)[bytelen] = ((uint8_t*)source)[bytelen] & (~((1 << (8-bitlen)) - 1)); } // " [fd00::1]" => "fd00::1" // "[fd00::1]:8000" => "fd00::1" // "127.0.0.1" => "127.0.0.1" // " 127.0.0.1:8000" => "127.0.0.1" // " vk.com:8000" => "vk.com" // return value: true - host is ip addr bool strip_host_to_ip(char *host) { size_t l; char *h,*p; uint8_t addr[16]; for (h = host ; *h==' ' || *h=='\t' ; h++); l = strlen(h); if (l>=2) { if (*h=='[') { // ipv6 ? for (p=++h ; *p && *p!=']' ; p++); if (*p==']') { l = p-h; memmove(host,h,l); host[l]=0; return inet_pton(AF_INET6, host, addr)>0; } } else { if (inet_pton(AF_INET6, h, addr)>0) { // ipv6 ? if (host!=h) { l = strlen(h); memmove(host,h,l); host[l]=0; } return true; } else { // ipv4 ? for (p=h ; *p && *p!=':' ; p++); l = p-h; if (host!=h) memmove(host,h,l); host[l]=0; return inet_pton(AF_INET, host, addr)>0; } } } return false; } void ntop46(const struct sockaddr *sa, char *str, size_t len) { if (!len) return; Loading tpws/helpers.h +2 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ bool append_to_list_file(const char *filename, const char *s); void expand_bits(void *target, const void *source, unsigned int source_bitlen, unsigned int target_bytelen); bool strip_host_to_ip(char *host); void ntop46(const struct sockaddr *sa, char *str, size_t len); void ntop46_port(const struct sockaddr *sa, char *str, size_t len); void print_sockaddr(const struct sockaddr *sa); Loading tpws/hostlist.c +7 −6 Original line number Diff line number Diff line Loading @@ -170,7 +170,7 @@ bool LoadAllHostLists() static bool SearchHostList(hostlist_pool *hostlist, const char *host) static bool SearchHostList(hostlist_pool *hostlist, const char *host, bool no_match_subdomains) { if (hostlist) { Loading @@ -195,6 +195,7 @@ static bool SearchHostList(hostlist_pool *hostlist, const char *host) } else VPRINT("negative\n"); if (no_match_subdomains) break; p = strchr(p, '.'); if (p) p++; bHostFull = false; Loading @@ -220,7 +221,7 @@ bool HostlistsReloadCheckForProfile(const struct desync_profile *dp) return HostlistsReloadCheck(&dp->hl_collection) && HostlistsReloadCheck(&dp->hl_collection_exclude); } // return : true = apply fooling, false = do not apply static bool HostlistCheck_(const struct hostlist_collection_head *hostlists, const struct hostlist_collection_head *hostlists_exclude, const char *host, bool *excluded, bool bSkipReloadCheck) static bool HostlistCheck_(const struct hostlist_collection_head *hostlists, const struct hostlist_collection_head *hostlists_exclude, const char *host, bool no_match_subdomains, bool *excluded, bool bSkipReloadCheck) { struct hostlist_item *item; Loading @@ -233,7 +234,7 @@ static bool HostlistCheck_(const struct hostlist_collection_head *hostlists, con LIST_FOREACH(item, hostlists_exclude, next) { VPRINT("[%s] exclude ", item->hfile->filename ? item->hfile->filename : "fixed"); if (SearchHostList(item->hfile->hostlist, host)) if (SearchHostList(item->hfile->hostlist, host, no_match_subdomains)) { if (excluded) *excluded = true; return false; Loading @@ -245,7 +246,7 @@ static bool HostlistCheck_(const struct hostlist_collection_head *hostlists, con LIST_FOREACH(item, hostlists, next) { VPRINT("[%s] include ", item->hfile->filename ? item->hfile->filename : "fixed"); if (SearchHostList(item->hfile->hostlist, host)) if (SearchHostList(item->hfile->hostlist, host, no_match_subdomains)) return true; } return false; Loading @@ -255,10 +256,10 @@ static bool HostlistCheck_(const struct hostlist_collection_head *hostlists, con // return : true = apply fooling, false = do not apply bool HostlistCheck(const struct desync_profile *dp, const char *host, bool *excluded, bool bSkipReloadCheck) bool HostlistCheck(const struct desync_profile *dp, const char *host, bool no_match_subdomains, bool *excluded, bool bSkipReloadCheck) { VPRINT("* hostlist check for profile %d\n",dp->n); return HostlistCheck_(&dp->hl_collection, &dp->hl_collection_exclude, host, excluded, bSkipReloadCheck); return HostlistCheck_(&dp->hl_collection, &dp->hl_collection_exclude, host, no_match_subdomains, excluded, bSkipReloadCheck); } Loading tpws/hostlist.h +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ bool AppendHostList(hostlist_pool **hostlist, const char *filename); bool LoadAllHostLists(); bool NonEmptyHostlist(hostlist_pool **hostlist); // return : true = apply fooling, false = do not apply bool HostlistCheck(const struct desync_profile *dp,const char *host, bool *excluded, bool bSkipReloadCheck); bool HostlistCheck(const struct desync_profile *dp,const char *host, bool no_match_subdomains, bool *excluded, bool bSkipReloadCheck); struct hostlist_file *RegisterHostlist(struct desync_profile *dp, bool bExclude, const char *filename); bool HostlistsReloadCheckForProfile(const struct desync_profile *dp); void HostlistsDebug(); Loading tpws/pools.c +3 −2 Original line number Diff line number Diff line Loading @@ -616,6 +616,7 @@ static void ipcache_item_init(ip_cache_item *item) { ipcache_item_touch(item); item->hostname = NULL; item->hostname_is_ip = false; } static void ipcache_item_destroy(ip_cache_item *item) { Loading Loading @@ -675,7 +676,7 @@ static void ipcache4Print(ip_cache4 *ipcache) { *s_ip=0; inet_ntop(AF_INET, &ipc->key.addr, s_ip, sizeof(s_ip)); printf("%s : hostname=%s now=last+%llu\n", s_ip, ipc->data.hostname ? ipc->data.hostname : "", (unsigned long long)(now-ipc->data.last)); printf("%s : hostname=%s hostname_is_ip=%u now=last+%llu\n", s_ip, ipc->data.hostname ? ipc->data.hostname : "", ipc->data.hostname_is_ip, (unsigned long long)(now-ipc->data.last)); } } Loading Loading @@ -732,7 +733,7 @@ static void ipcache6Print(ip_cache6 *ipcache) { *s_ip=0; inet_ntop(AF_INET6, &ipc->key.addr, s_ip, sizeof(s_ip)); printf("%s : hostname=%s now=last+%llu\n", s_ip, ipc->data.hostname ? ipc->data.hostname : "", (unsigned long long)(now-ipc->data.last)); printf("%s : hostname=%s hostname_is_ip=%u now=last+%llu\n", s_ip, ipc->data.hostname ? ipc->data.hostname : "", ipc->data.hostname_is_ip, (unsigned long long)(now-ipc->data.last)); } } Loading Loading
tpws/helpers.c +55 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,61 @@ void expand_bits(void *target, const void *source, unsigned int source_bitlen, u if ((bitlen &= 7)) ((uint8_t*)target)[bytelen] = ((uint8_t*)source)[bytelen] & (~((1 << (8-bitlen)) - 1)); } // " [fd00::1]" => "fd00::1" // "[fd00::1]:8000" => "fd00::1" // "127.0.0.1" => "127.0.0.1" // " 127.0.0.1:8000" => "127.0.0.1" // " vk.com:8000" => "vk.com" // return value: true - host is ip addr bool strip_host_to_ip(char *host) { size_t l; char *h,*p; uint8_t addr[16]; for (h = host ; *h==' ' || *h=='\t' ; h++); l = strlen(h); if (l>=2) { if (*h=='[') { // ipv6 ? for (p=++h ; *p && *p!=']' ; p++); if (*p==']') { l = p-h; memmove(host,h,l); host[l]=0; return inet_pton(AF_INET6, host, addr)>0; } } else { if (inet_pton(AF_INET6, h, addr)>0) { // ipv6 ? if (host!=h) { l = strlen(h); memmove(host,h,l); host[l]=0; } return true; } else { // ipv4 ? for (p=h ; *p && *p!=':' ; p++); l = p-h; if (host!=h) memmove(host,h,l); host[l]=0; return inet_pton(AF_INET, host, addr)>0; } } } return false; } void ntop46(const struct sockaddr *sa, char *str, size_t len) { if (!len) return; Loading
tpws/helpers.h +2 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,8 @@ bool append_to_list_file(const char *filename, const char *s); void expand_bits(void *target, const void *source, unsigned int source_bitlen, unsigned int target_bytelen); bool strip_host_to_ip(char *host); void ntop46(const struct sockaddr *sa, char *str, size_t len); void ntop46_port(const struct sockaddr *sa, char *str, size_t len); void print_sockaddr(const struct sockaddr *sa); Loading
tpws/hostlist.c +7 −6 Original line number Diff line number Diff line Loading @@ -170,7 +170,7 @@ bool LoadAllHostLists() static bool SearchHostList(hostlist_pool *hostlist, const char *host) static bool SearchHostList(hostlist_pool *hostlist, const char *host, bool no_match_subdomains) { if (hostlist) { Loading @@ -195,6 +195,7 @@ static bool SearchHostList(hostlist_pool *hostlist, const char *host) } else VPRINT("negative\n"); if (no_match_subdomains) break; p = strchr(p, '.'); if (p) p++; bHostFull = false; Loading @@ -220,7 +221,7 @@ bool HostlistsReloadCheckForProfile(const struct desync_profile *dp) return HostlistsReloadCheck(&dp->hl_collection) && HostlistsReloadCheck(&dp->hl_collection_exclude); } // return : true = apply fooling, false = do not apply static bool HostlistCheck_(const struct hostlist_collection_head *hostlists, const struct hostlist_collection_head *hostlists_exclude, const char *host, bool *excluded, bool bSkipReloadCheck) static bool HostlistCheck_(const struct hostlist_collection_head *hostlists, const struct hostlist_collection_head *hostlists_exclude, const char *host, bool no_match_subdomains, bool *excluded, bool bSkipReloadCheck) { struct hostlist_item *item; Loading @@ -233,7 +234,7 @@ static bool HostlistCheck_(const struct hostlist_collection_head *hostlists, con LIST_FOREACH(item, hostlists_exclude, next) { VPRINT("[%s] exclude ", item->hfile->filename ? item->hfile->filename : "fixed"); if (SearchHostList(item->hfile->hostlist, host)) if (SearchHostList(item->hfile->hostlist, host, no_match_subdomains)) { if (excluded) *excluded = true; return false; Loading @@ -245,7 +246,7 @@ static bool HostlistCheck_(const struct hostlist_collection_head *hostlists, con LIST_FOREACH(item, hostlists, next) { VPRINT("[%s] include ", item->hfile->filename ? item->hfile->filename : "fixed"); if (SearchHostList(item->hfile->hostlist, host)) if (SearchHostList(item->hfile->hostlist, host, no_match_subdomains)) return true; } return false; Loading @@ -255,10 +256,10 @@ static bool HostlistCheck_(const struct hostlist_collection_head *hostlists, con // return : true = apply fooling, false = do not apply bool HostlistCheck(const struct desync_profile *dp, const char *host, bool *excluded, bool bSkipReloadCheck) bool HostlistCheck(const struct desync_profile *dp, const char *host, bool no_match_subdomains, bool *excluded, bool bSkipReloadCheck) { VPRINT("* hostlist check for profile %d\n",dp->n); return HostlistCheck_(&dp->hl_collection, &dp->hl_collection_exclude, host, excluded, bSkipReloadCheck); return HostlistCheck_(&dp->hl_collection, &dp->hl_collection_exclude, host, no_match_subdomains, excluded, bSkipReloadCheck); } Loading
tpws/hostlist.h +1 −1 Original line number Diff line number Diff line Loading @@ -9,7 +9,7 @@ bool AppendHostList(hostlist_pool **hostlist, const char *filename); bool LoadAllHostLists(); bool NonEmptyHostlist(hostlist_pool **hostlist); // return : true = apply fooling, false = do not apply bool HostlistCheck(const struct desync_profile *dp,const char *host, bool *excluded, bool bSkipReloadCheck); bool HostlistCheck(const struct desync_profile *dp,const char *host, bool no_match_subdomains, bool *excluded, bool bSkipReloadCheck); struct hostlist_file *RegisterHostlist(struct desync_profile *dp, bool bExclude, const char *filename); bool HostlistsReloadCheckForProfile(const struct desync_profile *dp); void HostlistsDebug(); Loading
tpws/pools.c +3 −2 Original line number Diff line number Diff line Loading @@ -616,6 +616,7 @@ static void ipcache_item_init(ip_cache_item *item) { ipcache_item_touch(item); item->hostname = NULL; item->hostname_is_ip = false; } static void ipcache_item_destroy(ip_cache_item *item) { Loading Loading @@ -675,7 +676,7 @@ static void ipcache4Print(ip_cache4 *ipcache) { *s_ip=0; inet_ntop(AF_INET, &ipc->key.addr, s_ip, sizeof(s_ip)); printf("%s : hostname=%s now=last+%llu\n", s_ip, ipc->data.hostname ? ipc->data.hostname : "", (unsigned long long)(now-ipc->data.last)); printf("%s : hostname=%s hostname_is_ip=%u now=last+%llu\n", s_ip, ipc->data.hostname ? ipc->data.hostname : "", ipc->data.hostname_is_ip, (unsigned long long)(now-ipc->data.last)); } } Loading Loading @@ -732,7 +733,7 @@ static void ipcache6Print(ip_cache6 *ipcache) { *s_ip=0; inet_ntop(AF_INET6, &ipc->key.addr, s_ip, sizeof(s_ip)); printf("%s : hostname=%s now=last+%llu\n", s_ip, ipc->data.hostname ? ipc->data.hostname : "", (unsigned long long)(now-ipc->data.last)); printf("%s : hostname=%s hostname_is_ip=%u now=last+%llu\n", s_ip, ipc->data.hostname ? ipc->data.hostname : "", ipc->data.hostname_is_ip, (unsigned long long)(now-ipc->data.last)); } } Loading