mirror of
https://github.com/bol-van/zapret.git
synced 2025-05-17 19:02:57 +03:00
Compare commits
6 Commits
182b6a3c02
...
dd10ac1f97
Author | SHA1 | Date | |
---|---|---|---|
|
dd10ac1f97 | ||
|
c69a92f901 | ||
|
aba1fdeb04 | ||
|
02c76a4fb6 | ||
|
2ff6ec03aa | ||
|
92ba6b439e |
@ -448,3 +448,6 @@ blockcheck: override all dialog questions and enable batch mode
|
||||
blockcheck: parallel attempts
|
||||
nfqws: weaken wireguard initiation recognition. use len=148 and data[0]=1 signature
|
||||
nfqws: apply split+seqovl only to the first reasm fragment
|
||||
install_easy: dnf packager support
|
||||
nfqws,tpws: hostlist/ipset track not only file mod time but also file size
|
||||
nfqws,tpws,ipset: return lists reload on HUP
|
||||
|
@ -965,7 +965,8 @@ If you need "all except" mode you dont have to delete zapret-hosts-users.txt. Ju
|
||||
|
||||
Subdomains auto apply. For example, "ru" in the list affects "*.ru" .
|
||||
|
||||
**tpws** and **nfqws** automatically reload lists if their modification date is changed.
|
||||
**tpws** and **nfqws** automatically reload lists if their modification time or file size is changed.
|
||||
HUP signal forcibly reloads all lists.
|
||||
|
||||
When filtering by domain name, daemons should run without filtering by ipset.
|
||||
When using large regulator lists estimate the amount of RAM on the router !
|
||||
|
@ -1303,7 +1303,8 @@ ipset/get_refilter_domains.sh
|
||||
```
|
||||
Он кладется в `ipset/zapret-hosts.txt.gz`.
|
||||
|
||||
При изменении времени модификации файлов списки перечитываются автоматически.
|
||||
При изменении времени модификации или размера файлов списки перечитываются автоматически.
|
||||
После неатомарных операций изменения можно послать tpws/nfqws сигнал HUP для принудительной перечитки всех листов.
|
||||
|
||||
При фильтрации по именам доменов демон должен запускаться без фильтрации по ipset.
|
||||
tpws и nfqws решают нужно ли применять дурение в зависимости от хоста, полученного из протокола прикладного уровня (http, tls, quic).
|
||||
|
12
ipset/def.sh
12
ipset/def.sh
@ -267,3 +267,15 @@ getipban()
|
||||
_get_ipban
|
||||
return 0
|
||||
}
|
||||
|
||||
hup_zapret_daemons()
|
||||
{
|
||||
echo forcing zapret daemons to reload their hostlist
|
||||
if exists killall; then
|
||||
killall -HUP tpws nfqws dvtws 2>/dev/null
|
||||
elif exists pkill; then
|
||||
pkill -HUP ^tpws$ ^nfqws$ ^dvtws$
|
||||
else
|
||||
echo no mass killer available ! cant HUP zapret daemons
|
||||
fi
|
||||
}
|
||||
|
40
ipset/get_antifilter_domains.sh
Normal file
40
ipset/get_antifilter_domains.sh
Normal file
@ -0,0 +1,40 @@
|
||||
#!/bin/sh
|
||||
|
||||
IPSET_DIR="$(dirname "$0")"
|
||||
IPSET_DIR="$(cd "$IPSET_DIR"; pwd)"
|
||||
|
||||
. "$IPSET_DIR/def.sh"
|
||||
|
||||
TMPLIST="$TMPDIR/list.txt"
|
||||
|
||||
URL="https://antifilter.download/list/domains.lst"
|
||||
|
||||
dl()
|
||||
{
|
||||
# $1 - url
|
||||
# $2 - file
|
||||
# $3 - minsize
|
||||
# $4 - maxsize
|
||||
curl -L -H "Accept-Encoding: gzip" -k --fail --max-time 60 --connect-timeout 10 --retry 4 --max-filesize 251658240 -o "$TMPLIST" "$1" ||
|
||||
{
|
||||
echo list download failed : $1
|
||||
exit 2
|
||||
}
|
||||
dlsize=$(LANG=C wc -c "$TMPLIST" | xargs | cut -f 1 -d ' ')
|
||||
if test $dlsize -lt $3; then
|
||||
echo list is too small : $dlsize bytes. can be bad.
|
||||
exit 2
|
||||
fi
|
||||
zzcat "$TMPLIST" | tr -d '\015' | zz "$2"
|
||||
rm -f "$TMPLIST"
|
||||
}
|
||||
|
||||
# useful in case ipban set is used in custom scripts
|
||||
FAIL=
|
||||
getipban || FAIL=1
|
||||
"$IPSET_DIR/create_ipset.sh"
|
||||
[ -n "$FAIL" ] && exit
|
||||
|
||||
dl "$URL" "$ZHOSTLIST" 32768 4194304
|
||||
|
||||
exit 0
|
@ -31,4 +31,6 @@ sort -u "$ZDOM" | zz "$ZHOSTLIST"
|
||||
|
||||
rm -f "$ZDOM"
|
||||
|
||||
hup_zapret_daemons
|
||||
|
||||
exit 0
|
||||
|
@ -58,6 +58,8 @@ rm -f "$ZREESTR"
|
||||
[ "$DISABLE_IPV6" != "1" ] && $AWK '/^([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4}($|(\/[0-9]{2,3}$))/' "$IPB" | cut_local6 | ip2net6 | zz "$ZIPLIST_IPBAN6"
|
||||
rm -f "$IPB"
|
||||
|
||||
hup_zapret_daemons
|
||||
|
||||
ipban_fin
|
||||
|
||||
exit 0
|
||||
|
@ -34,6 +34,8 @@ dl()
|
||||
|
||||
dl "$URL" "$ZHOSTLIST" 65536 67108864
|
||||
|
||||
hup_zapret_daemons
|
||||
|
||||
[ "$DISABLE_IPV4" != "1" ] && dl "$IPB4" "$ZIPLIST_IPBAN" 8192 1048576
|
||||
[ "$DISABLE_IPV6" != "1" ] && dl "$IPB6" "$ZIPLIST_IPBAN6" 128 1048576
|
||||
|
||||
|
@ -37,4 +37,6 @@ getipban || FAIL=1
|
||||
|
||||
dl "$URL" "$ZHOSTLIST" 32768 4194304
|
||||
|
||||
hup_zapret_daemons
|
||||
|
||||
exit 0
|
||||
|
@ -367,7 +367,8 @@ static void auto_hostlist_failed(struct desync_profile *dp, const char *hostname
|
||||
DLOG_PERROR("write to auto hostlist:");
|
||||
return;
|
||||
}
|
||||
dp->hostlist_auto->mod_time = file_mod_time(dp->hostlist_auto->filename);
|
||||
if (!file_mod_signature(dp->hostlist_auto->filename, &dp->hostlist_auto->mod_sig))
|
||||
DLOG_PERROR("file_mod_signature");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -300,6 +300,14 @@ time_t file_mod_time(const char *filename)
|
||||
struct stat st;
|
||||
return stat(filename,&st)==-1 ? 0 : st.st_mtime;
|
||||
}
|
||||
bool file_mod_signature(const char *filename, file_mod_sig *ms)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(filename,&st)==-1) return false;
|
||||
ms->mod_time=st.st_mtime;
|
||||
ms->size=st.st_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pf_in_range(uint16_t port, const port_filter *pf)
|
||||
{
|
||||
|
@ -60,6 +60,14 @@ void fill_pattern(uint8_t *buf,size_t bufsize,const void *pattern,size_t patsize
|
||||
|
||||
int fprint_localtime(FILE *F);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
time_t mod_time;
|
||||
off_t size;
|
||||
} file_mod_sig;
|
||||
#define FILE_MOD_COMPARE(ms1,ms2) (((ms1)->mod_time==(ms2)->mod_time) && ((ms1)->size==(ms2)->size))
|
||||
#define FILE_MOD_RESET(ms) memset(ms,0,sizeof(file_mod_sig))
|
||||
bool file_mod_signature(const char *filename, file_mod_sig *ms);
|
||||
time_t file_mod_time(const char *filename);
|
||||
|
||||
typedef struct
|
||||
|
@ -105,21 +105,21 @@ static bool LoadHostList(struct hostlist_file *hfile)
|
||||
{
|
||||
if (hfile->filename)
|
||||
{
|
||||
time_t t = file_mod_time(hfile->filename);
|
||||
if (!t)
|
||||
file_mod_sig fsig;
|
||||
if (!file_mod_signature(hfile->filename, &fsig))
|
||||
{
|
||||
// stat() error
|
||||
DLOG_ERR("cannot access hostlist file '%s'. in-memory content remains unchanged.\n",hfile->filename);
|
||||
return true;
|
||||
}
|
||||
if (t==hfile->mod_time) return true; // up to date
|
||||
if (FILE_MOD_COMPARE(&hfile->mod_sig,&fsig)) return true; // up to date
|
||||
StrPoolDestroy(&hfile->hostlist);
|
||||
if (!AppendHostList(&hfile->hostlist, hfile->filename))
|
||||
{
|
||||
StrPoolDestroy(&hfile->hostlist);
|
||||
return false;
|
||||
}
|
||||
hfile->mod_time=t;
|
||||
hfile->mod_sig=fsig;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -13,3 +13,5 @@ bool HostlistCheck(const struct desync_profile *dp,const char *host, bool *exclu
|
||||
struct hostlist_file *RegisterHostlist(struct desync_profile *dp, bool bExclude, const char *filename);
|
||||
bool HostlistsReloadCheckForProfile(const struct desync_profile *dp);
|
||||
void HostlistsDebug();
|
||||
|
||||
#define ResetAllHostlistsModTime() hostlist_files_reset_modtime(¶ms.hostlists)
|
||||
|
@ -126,21 +126,21 @@ static bool LoadIpset(struct ipset_file *hfile)
|
||||
{
|
||||
if (hfile->filename)
|
||||
{
|
||||
time_t t = file_mod_time(hfile->filename);
|
||||
if (!t)
|
||||
file_mod_sig fsig;
|
||||
if (!file_mod_signature(hfile->filename, &fsig))
|
||||
{
|
||||
// stat() error
|
||||
DLOG_ERR("cannot access ipset file '%s'. in-memory content remains unchanged.\n",hfile->filename);
|
||||
return true;
|
||||
}
|
||||
if (t==hfile->mod_time) return true; // up to date
|
||||
if (FILE_MOD_COMPARE(&hfile->mod_sig,&fsig)) return true; // up to date
|
||||
ipsetDestroy(&hfile->ipset);
|
||||
if (!AppendIpset(&hfile->ipset, hfile->filename))
|
||||
{
|
||||
ipsetDestroy(&hfile->ipset);
|
||||
return false;
|
||||
}
|
||||
hfile->mod_time=t;
|
||||
hfile->mod_sig=fsig;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -10,3 +10,5 @@ bool IpsetCheck(const struct desync_profile *dp, const struct in_addr *ipv4, con
|
||||
struct ipset_file *RegisterIpset(struct desync_profile *dp, bool bExclude, const char *filename);
|
||||
void IpsetsDebug();
|
||||
bool AppendIpsetItem(ipset *ips, char *ip);
|
||||
|
||||
#define ResetAllIpsetModTime() ipset_files_reset_modtime(¶ms.ipsets)
|
||||
|
29
nfq/nfqws.c
29
nfq/nfqws.c
@ -49,14 +49,34 @@
|
||||
#define MAX_CONFIG_FILE_SIZE 16384
|
||||
|
||||
struct params_s params;
|
||||
static bool bReload=false;
|
||||
#ifdef __CYGWIN__
|
||||
bool bQuit=false;
|
||||
#endif
|
||||
|
||||
static void onhup(int sig)
|
||||
{
|
||||
printf("HUP received !\n");
|
||||
// do not do anything. lists auto reload themselves based on file time.
|
||||
printf("HUP received ! Lists will be reloaded.\n");
|
||||
bReload=true;
|
||||
}
|
||||
static void ReloadCheck()
|
||||
{
|
||||
if (bReload)
|
||||
{
|
||||
ResetAllHostlistsModTime();
|
||||
if (!LoadAllHostLists())
|
||||
{
|
||||
DLOG_ERR("hostlists load failed. this is fatal.\n");
|
||||
exit(1);
|
||||
}
|
||||
ResetAllIpsetModTime();
|
||||
if (!LoadAllIpsets())
|
||||
{
|
||||
DLOG_ERR("ipset load failed. this is fatal.\n");
|
||||
exit(1);
|
||||
}
|
||||
bReload=false;
|
||||
}
|
||||
}
|
||||
|
||||
static void onusr1(int sig)
|
||||
@ -251,6 +271,7 @@ static int nfq_main(void)
|
||||
{
|
||||
while ((rd = recv(fd, buf, sizeof(buf), 0)) >= 0)
|
||||
{
|
||||
ReloadCheck();
|
||||
if (rd)
|
||||
{
|
||||
int r = nfq_handle_packet(h, (char *)buf, (int)rd);
|
||||
@ -371,6 +392,8 @@ static int dvt_main(void)
|
||||
uint8_t verdict;
|
||||
size_t len = rd;
|
||||
|
||||
ReloadCheck();
|
||||
|
||||
DLOG("packet: id=%u len=%zu\n", id, len);
|
||||
verdict = processPacketData(&mark, NULL, buf, &len);
|
||||
switch (verdict & VERDICT_MASK)
|
||||
@ -489,6 +512,8 @@ static int win_main(const char *windivert_filter)
|
||||
return w_win32_error;
|
||||
}
|
||||
|
||||
ReloadCheck();
|
||||
|
||||
*ifout=0;
|
||||
if (wa.Outbound) snprintf(ifout,sizeof(ifout),"%u.%u", wa.Network.IfIdx, wa.Network.SubIfIdx);
|
||||
DLOG("packet: id=%u len=%zu %s IPv6=%u IPChecksum=%u TCPChecksum=%u UDPChecksum=%u IfIdx=%u.%u\n", id, len, wa.Outbound ? "outbound" : "inbound", wa.IPv6, wa.IPChecksum, wa.TCPChecksum, wa.UDPChecksum, wa.Network.IfIdx, wa.Network.SubIfIdx);
|
||||
|
19
nfq/pools.c
19
nfq/pools.c
@ -154,7 +154,6 @@ void strlist_destroy(struct str_list_head *head)
|
||||
|
||||
|
||||
|
||||
|
||||
struct hostlist_file *hostlist_files_add(struct hostlist_files_head *head, const char *filename)
|
||||
{
|
||||
struct hostlist_file *entry = malloc(sizeof(struct hostlist_file));
|
||||
@ -170,7 +169,7 @@ struct hostlist_file *hostlist_files_add(struct hostlist_files_head *head, const
|
||||
}
|
||||
else
|
||||
entry->filename = NULL;
|
||||
entry->mod_time = 0;
|
||||
FILE_MOD_RESET(&entry->mod_sig);
|
||||
entry->hostlist = NULL;
|
||||
LIST_INSERT_HEAD(head, entry, next);
|
||||
}
|
||||
@ -202,6 +201,13 @@ struct hostlist_file *hostlist_files_search(struct hostlist_files_head *head, co
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
void hostlist_files_reset_modtime(struct hostlist_files_head *list)
|
||||
{
|
||||
struct hostlist_file *hfile;
|
||||
|
||||
LIST_FOREACH(hfile, list, next)
|
||||
FILE_MOD_RESET(&hfile->mod_sig);
|
||||
}
|
||||
|
||||
struct hostlist_item *hostlist_collection_add(struct hostlist_collection_head *head, struct hostlist_file *hfile)
|
||||
{
|
||||
@ -384,7 +390,7 @@ struct ipset_file *ipset_files_add(struct ipset_files_head *head, const char *fi
|
||||
}
|
||||
else
|
||||
entry->filename = NULL;
|
||||
entry->mod_time = 0;
|
||||
FILE_MOD_RESET(&entry->mod_sig);
|
||||
memset(&entry->ipset,0,sizeof(entry->ipset));
|
||||
LIST_INSERT_HEAD(head, entry, next);
|
||||
}
|
||||
@ -416,6 +422,13 @@ struct ipset_file *ipset_files_search(struct ipset_files_head *head, const char
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
void ipset_files_reset_modtime(struct ipset_files_head *list)
|
||||
{
|
||||
struct ipset_file *hfile;
|
||||
|
||||
LIST_FOREACH(hfile, list, next)
|
||||
FILE_MOD_RESET(&hfile->mod_sig);
|
||||
}
|
||||
|
||||
struct ipset_item *ipset_collection_add(struct ipset_collection_head *head, struct ipset_file *hfile)
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ void strlist_destroy(struct str_list_head *head);
|
||||
|
||||
struct hostlist_file {
|
||||
char *filename;
|
||||
time_t mod_time;
|
||||
file_mod_sig mod_sig;
|
||||
strpool *hostlist;
|
||||
LIST_ENTRY(hostlist_file) next;
|
||||
};
|
||||
@ -59,6 +59,7 @@ LIST_HEAD(hostlist_files_head, hostlist_file);
|
||||
struct hostlist_file *hostlist_files_add(struct hostlist_files_head *head, const char *filename);
|
||||
void hostlist_files_destroy(struct hostlist_files_head *head);
|
||||
struct hostlist_file *hostlist_files_search(struct hostlist_files_head *head, const char *filename);
|
||||
void hostlist_files_reset_modtime(struct hostlist_files_head *list);
|
||||
|
||||
struct hostlist_item {
|
||||
struct hostlist_file *hfile;
|
||||
@ -111,7 +112,7 @@ void ipsetPrint(ipset *ipset);
|
||||
|
||||
struct ipset_file {
|
||||
char *filename;
|
||||
time_t mod_time;
|
||||
file_mod_sig mod_sig;
|
||||
ipset ipset;
|
||||
LIST_ENTRY(ipset_file) next;
|
||||
};
|
||||
@ -120,6 +121,7 @@ LIST_HEAD(ipset_files_head, ipset_file);
|
||||
struct ipset_file *ipset_files_add(struct ipset_files_head *head, const char *filename);
|
||||
void ipset_files_destroy(struct ipset_files_head *head);
|
||||
struct ipset_file *ipset_files_search(struct ipset_files_head *head, const char *filename);
|
||||
void ipset_files_reset_modtime(struct ipset_files_head *list);
|
||||
|
||||
struct ipset_item {
|
||||
struct ipset_file *hfile;
|
||||
|
@ -314,6 +314,14 @@ time_t file_mod_time(const char *filename)
|
||||
struct stat st;
|
||||
return stat(filename, &st) == -1 ? 0 : st.st_mtime;
|
||||
}
|
||||
bool file_mod_signature(const char *filename, file_mod_sig *ms)
|
||||
{
|
||||
struct stat st;
|
||||
if (stat(filename,&st)==-1) return false;
|
||||
ms->mod_time=st.st_mtime;
|
||||
ms->size=st.st_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pf_in_range(uint16_t port, const port_filter *pf)
|
||||
{
|
||||
|
@ -62,6 +62,14 @@ static inline void phton16(uint8_t *p, uint16_t v) {
|
||||
|
||||
int fprint_localtime(FILE *F);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
time_t mod_time;
|
||||
off_t size;
|
||||
} file_mod_sig;
|
||||
#define FILE_MOD_COMPARE(ms1,ms2) (((ms1)->mod_time==(ms2)->mod_time) && ((ms1)->size==(ms2)->size))
|
||||
#define FILE_MOD_RESET(ms) memset(ms,0,sizeof(file_mod_sig))
|
||||
bool file_mod_signature(const char *filename, file_mod_sig *ms);
|
||||
time_t file_mod_time(const char *filename);
|
||||
|
||||
typedef struct
|
||||
|
@ -105,21 +105,21 @@ static bool LoadHostList(struct hostlist_file *hfile)
|
||||
{
|
||||
if (hfile->filename)
|
||||
{
|
||||
time_t t = file_mod_time(hfile->filename);
|
||||
if (!t)
|
||||
file_mod_sig fsig;
|
||||
if (!file_mod_signature(hfile->filename, &fsig))
|
||||
{
|
||||
// stat() error
|
||||
DLOG_ERR("cannot access hostlist file '%s'. in-memory content remains unchanged.\n",hfile->filename);
|
||||
return true;
|
||||
}
|
||||
if (t==hfile->mod_time) return true; // up to date
|
||||
if (FILE_MOD_COMPARE(&hfile->mod_sig,&fsig)) return true; // up to date
|
||||
StrPoolDestroy(&hfile->hostlist);
|
||||
if (!AppendHostList(&hfile->hostlist, hfile->filename))
|
||||
{
|
||||
StrPoolDestroy(&hfile->hostlist);
|
||||
return false;
|
||||
}
|
||||
hfile->mod_time=t;
|
||||
hfile->mod_sig=fsig;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -13,3 +13,5 @@ bool HostlistCheck(const struct desync_profile *dp,const char *host, bool *exclu
|
||||
struct hostlist_file *RegisterHostlist(struct desync_profile *dp, bool bExclude, const char *filename);
|
||||
bool HostlistsReloadCheckForProfile(const struct desync_profile *dp);
|
||||
void HostlistsDebug();
|
||||
|
||||
#define ResetAllHostlistsModTime() hostlist_files_reset_modtime(¶ms.hostlists)
|
||||
|
@ -126,21 +126,21 @@ static bool LoadIpset(struct ipset_file *hfile)
|
||||
{
|
||||
if (hfile->filename)
|
||||
{
|
||||
time_t t = file_mod_time(hfile->filename);
|
||||
if (!t)
|
||||
file_mod_sig fsig;
|
||||
if (!file_mod_signature(hfile->filename, &fsig))
|
||||
{
|
||||
// stat() error
|
||||
DLOG_ERR("cannot access ipset file '%s'. in-memory content remains unchanged.\n",hfile->filename);
|
||||
return true;
|
||||
}
|
||||
if (t==hfile->mod_time) return true; // up to date
|
||||
if (FILE_MOD_COMPARE(&hfile->mod_sig,&fsig)) return true; // up to date
|
||||
ipsetDestroy(&hfile->ipset);
|
||||
if (!AppendIpset(&hfile->ipset, hfile->filename))
|
||||
{
|
||||
ipsetDestroy(&hfile->ipset);
|
||||
return false;
|
||||
}
|
||||
hfile->mod_time=t;
|
||||
hfile->mod_sig=fsig;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -10,3 +10,5 @@ bool IpsetCheck(const struct desync_profile *dp, const struct in_addr *ipv4, con
|
||||
struct ipset_file *RegisterIpset(struct desync_profile *dp, bool bExclude, const char *filename);
|
||||
void IpsetsDebug();
|
||||
bool AppendIpsetItem(ipset *ips, char *ip);
|
||||
|
||||
#define ResetAllIpsetModTime() ipset_files_reset_modtime(¶ms.ipsets)
|
||||
|
18
tpws/pools.c
18
tpws/pools.c
@ -169,7 +169,7 @@ struct hostlist_file *hostlist_files_add(struct hostlist_files_head *head, const
|
||||
}
|
||||
else
|
||||
entry->filename = NULL;
|
||||
entry->mod_time = 0;
|
||||
FILE_MOD_RESET(&entry->mod_sig);
|
||||
entry->hostlist = NULL;
|
||||
LIST_INSERT_HEAD(head, entry, next);
|
||||
}
|
||||
@ -201,6 +201,13 @@ struct hostlist_file *hostlist_files_search(struct hostlist_files_head *head, co
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
void hostlist_files_reset_modtime(struct hostlist_files_head *list)
|
||||
{
|
||||
struct hostlist_file *hfile;
|
||||
|
||||
LIST_FOREACH(hfile, list, next)
|
||||
FILE_MOD_RESET(&hfile->mod_sig);
|
||||
}
|
||||
|
||||
struct hostlist_item *hostlist_collection_add(struct hostlist_collection_head *head, struct hostlist_file *hfile)
|
||||
{
|
||||
@ -383,7 +390,7 @@ struct ipset_file *ipset_files_add(struct ipset_files_head *head, const char *fi
|
||||
}
|
||||
else
|
||||
entry->filename = NULL;
|
||||
entry->mod_time = 0;
|
||||
FILE_MOD_RESET(&entry->mod_sig);
|
||||
memset(&entry->ipset,0,sizeof(entry->ipset));
|
||||
LIST_INSERT_HEAD(head, entry, next);
|
||||
}
|
||||
@ -415,6 +422,13 @@ struct ipset_file *ipset_files_search(struct ipset_files_head *head, const char
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
void ipset_files_reset_modtime(struct ipset_files_head *list)
|
||||
{
|
||||
struct ipset_file *hfile;
|
||||
|
||||
LIST_FOREACH(hfile, list, next)
|
||||
FILE_MOD_RESET(&hfile->mod_sig);
|
||||
}
|
||||
|
||||
struct ipset_item *ipset_collection_add(struct ipset_collection_head *head, struct ipset_file *hfile)
|
||||
{
|
||||
|
@ -50,7 +50,7 @@ void strlist_destroy(struct str_list_head *head);
|
||||
|
||||
struct hostlist_file {
|
||||
char *filename;
|
||||
time_t mod_time;
|
||||
file_mod_sig mod_sig;
|
||||
strpool *hostlist;
|
||||
LIST_ENTRY(hostlist_file) next;
|
||||
};
|
||||
@ -59,6 +59,7 @@ LIST_HEAD(hostlist_files_head, hostlist_file);
|
||||
struct hostlist_file *hostlist_files_add(struct hostlist_files_head *head, const char *filename);
|
||||
void hostlist_files_destroy(struct hostlist_files_head *head);
|
||||
struct hostlist_file *hostlist_files_search(struct hostlist_files_head *head, const char *filename);
|
||||
void hostlist_files_reset_modtime(struct hostlist_files_head *list);
|
||||
|
||||
struct hostlist_item {
|
||||
struct hostlist_file *hfile;
|
||||
@ -111,7 +112,7 @@ void ipsetPrint(ipset *ipset);
|
||||
|
||||
struct ipset_file {
|
||||
char *filename;
|
||||
time_t mod_time;
|
||||
file_mod_sig mod_sig;
|
||||
ipset ipset;
|
||||
LIST_ENTRY(ipset_file) next;
|
||||
};
|
||||
@ -120,6 +121,7 @@ LIST_HEAD(ipset_files_head, ipset_file);
|
||||
struct ipset_file *ipset_files_add(struct ipset_files_head *head, const char *filename);
|
||||
void ipset_files_destroy(struct ipset_files_head *head);
|
||||
struct ipset_file *ipset_files_search(struct ipset_files_head *head, const char *filename);
|
||||
void ipset_files_reset_modtime(struct ipset_files_head *list);
|
||||
|
||||
struct ipset_item {
|
||||
struct ipset_file *hfile;
|
||||
|
@ -443,7 +443,8 @@ static void auto_hostlist_failed(struct desync_profile *dp, const char *hostname
|
||||
DLOG_PERROR("write to auto hostlist:");
|
||||
return;
|
||||
}
|
||||
dp->hostlist_auto->mod_time = file_mod_time(dp->hostlist_auto->filename);
|
||||
if (!file_mod_signature(dp->hostlist_auto->filename, &dp->hostlist_auto->mod_sig))
|
||||
DLOG_PERROR("file_mod_signature");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
23
tpws/tpws.c
23
tpws/tpws.c
@ -50,10 +50,31 @@
|
||||
#define MAX_CONFIG_FILE_SIZE 16384
|
||||
|
||||
struct params_s params;
|
||||
static bool bReload=false;
|
||||
|
||||
static void onhup(int sig)
|
||||
{
|
||||
printf("HUP received !\n");
|
||||
printf("HUP received ! Lists will be reloaded.\n");
|
||||
bReload=true;
|
||||
}
|
||||
void ReloadCheck()
|
||||
{
|
||||
if (bReload)
|
||||
{
|
||||
ResetAllHostlistsModTime();
|
||||
if (!LoadAllHostLists())
|
||||
{
|
||||
DLOG_ERR("hostlists load failed. this is fatal.\n");
|
||||
exit(1);
|
||||
}
|
||||
ResetAllIpsetModTime();
|
||||
if (!LoadAllIpsets())
|
||||
{
|
||||
DLOG_ERR("ipset load failed. this is fatal.\n");
|
||||
exit(1);
|
||||
}
|
||||
bReload=false;
|
||||
}
|
||||
}
|
||||
|
||||
static void onusr2(int sig)
|
||||
|
@ -6,4 +6,4 @@
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
void dohup(void);
|
||||
void ReloadCheck();
|
||||
|
@ -1544,6 +1544,8 @@ int event_loop(const int *listen_fd, size_t listen_fd_ct)
|
||||
|
||||
for(;;)
|
||||
{
|
||||
ReloadCheck();
|
||||
|
||||
DBGPRINT("epoll_wait\n");
|
||||
|
||||
if ((num_events = epoll_wait(efd, events, MAX_EPOLL_EVENTS, -1)) == -1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user