Compare commits

...

6 Commits

Author SHA1 Message Date
Lorekin
dd10ac1f97
Merge 92ba6b439e6aed8557a315ebfcd350016159be52 into c69a92f9015a5d144d12b29e83482dd11f1262d1 2025-01-24 12:59:26 +03:00
bol-van
c69a92f901 update readme 2025-01-24 12:55:16 +03:00
bol-van
aba1fdeb04 tpws,nfqws: track file size in addition to mod time 2025-01-24 12:50:17 +03:00
bol-van
02c76a4fb6 ipset: return HUP reload 2025-01-24 11:39:13 +03:00
bol-van
2ff6ec03aa tpws,nfqws: return lists reload on HUP 2025-01-24 11:12:56 +03:00
Lorekin
92ba6b439e
Add script to get antifilter domains 2024-11-27 23:58:54 +03:00
31 changed files with 219 additions and 33 deletions

View File

@ -448,3 +448,6 @@ blockcheck: override all dialog questions and enable batch mode
blockcheck: parallel attempts blockcheck: parallel attempts
nfqws: weaken wireguard initiation recognition. use len=148 and data[0]=1 signature nfqws: weaken wireguard initiation recognition. use len=148 and data[0]=1 signature
nfqws: apply split+seqovl only to the first reasm fragment 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

View File

@ -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" . 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 filtering by domain name, daemons should run without filtering by ipset.
When using large regulator lists estimate the amount of RAM on the router ! When using large regulator lists estimate the amount of RAM on the router !

View File

@ -1303,7 +1303,8 @@ ipset/get_refilter_domains.sh
``` ```
Он кладется в `ipset/zapret-hosts.txt.gz`. Он кладется в `ipset/zapret-hosts.txt.gz`.
При изменении времени модификации файлов списки перечитываются автоматически. При изменении времени модификации или размера файлов списки перечитываются автоматически.
После неатомарных операций изменения можно послать tpws/nfqws сигнал HUP для принудительной перечитки всех листов.
При фильтрации по именам доменов демон должен запускаться без фильтрации по ipset. При фильтрации по именам доменов демон должен запускаться без фильтрации по ipset.
tpws и nfqws решают нужно ли применять дурение в зависимости от хоста, полученного из протокола прикладного уровня (http, tls, quic). tpws и nfqws решают нужно ли применять дурение в зависимости от хоста, полученного из протокола прикладного уровня (http, tls, quic).

View File

@ -267,3 +267,15 @@ getipban()
_get_ipban _get_ipban
return 0 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
}

View 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

View File

@ -31,4 +31,6 @@ sort -u "$ZDOM" | zz "$ZHOSTLIST"
rm -f "$ZDOM" rm -f "$ZDOM"
hup_zapret_daemons
exit 0 exit 0

View File

@ -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" [ "$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" rm -f "$IPB"
hup_zapret_daemons
ipban_fin ipban_fin
exit 0 exit 0

View File

@ -34,6 +34,8 @@ dl()
dl "$URL" "$ZHOSTLIST" 65536 67108864 dl "$URL" "$ZHOSTLIST" 65536 67108864
hup_zapret_daemons
[ "$DISABLE_IPV4" != "1" ] && dl "$IPB4" "$ZIPLIST_IPBAN" 8192 1048576 [ "$DISABLE_IPV4" != "1" ] && dl "$IPB4" "$ZIPLIST_IPBAN" 8192 1048576
[ "$DISABLE_IPV6" != "1" ] && dl "$IPB6" "$ZIPLIST_IPBAN6" 128 1048576 [ "$DISABLE_IPV6" != "1" ] && dl "$IPB6" "$ZIPLIST_IPBAN6" 128 1048576

View File

@ -37,4 +37,6 @@ getipban || FAIL=1
dl "$URL" "$ZHOSTLIST" 32768 4194304 dl "$URL" "$ZHOSTLIST" 32768 4194304
hup_zapret_daemons
exit 0 exit 0

View File

@ -367,7 +367,8 @@ static void auto_hostlist_failed(struct desync_profile *dp, const char *hostname
DLOG_PERROR("write to auto hostlist:"); DLOG_PERROR("write to auto hostlist:");
return; 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 else
{ {

View File

@ -300,6 +300,14 @@ time_t file_mod_time(const char *filename)
struct stat st; struct stat st;
return stat(filename,&st)==-1 ? 0 : st.st_mtime; 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) bool pf_in_range(uint16_t port, const port_filter *pf)
{ {

View File

@ -60,6 +60,14 @@ void fill_pattern(uint8_t *buf,size_t bufsize,const void *pattern,size_t patsize
int fprint_localtime(FILE *F); 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); time_t file_mod_time(const char *filename);
typedef struct typedef struct

View File

@ -105,21 +105,21 @@ static bool LoadHostList(struct hostlist_file *hfile)
{ {
if (hfile->filename) if (hfile->filename)
{ {
time_t t = file_mod_time(hfile->filename); file_mod_sig fsig;
if (!t) if (!file_mod_signature(hfile->filename, &fsig))
{ {
// stat() error // stat() error
DLOG_ERR("cannot access hostlist file '%s'. in-memory content remains unchanged.\n",hfile->filename); DLOG_ERR("cannot access hostlist file '%s'. in-memory content remains unchanged.\n",hfile->filename);
return true; 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); StrPoolDestroy(&hfile->hostlist);
if (!AppendHostList(&hfile->hostlist, hfile->filename)) if (!AppendHostList(&hfile->hostlist, hfile->filename))
{ {
StrPoolDestroy(&hfile->hostlist); StrPoolDestroy(&hfile->hostlist);
return false; return false;
} }
hfile->mod_time=t; hfile->mod_sig=fsig;
} }
return true; return true;
} }

View File

@ -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); struct hostlist_file *RegisterHostlist(struct desync_profile *dp, bool bExclude, const char *filename);
bool HostlistsReloadCheckForProfile(const struct desync_profile *dp); bool HostlistsReloadCheckForProfile(const struct desync_profile *dp);
void HostlistsDebug(); void HostlistsDebug();
#define ResetAllHostlistsModTime() hostlist_files_reset_modtime(&params.hostlists)

View File

@ -126,21 +126,21 @@ static bool LoadIpset(struct ipset_file *hfile)
{ {
if (hfile->filename) if (hfile->filename)
{ {
time_t t = file_mod_time(hfile->filename); file_mod_sig fsig;
if (!t) if (!file_mod_signature(hfile->filename, &fsig))
{ {
// stat() error // stat() error
DLOG_ERR("cannot access ipset file '%s'. in-memory content remains unchanged.\n",hfile->filename); DLOG_ERR("cannot access ipset file '%s'. in-memory content remains unchanged.\n",hfile->filename);
return true; 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); ipsetDestroy(&hfile->ipset);
if (!AppendIpset(&hfile->ipset, hfile->filename)) if (!AppendIpset(&hfile->ipset, hfile->filename))
{ {
ipsetDestroy(&hfile->ipset); ipsetDestroy(&hfile->ipset);
return false; return false;
} }
hfile->mod_time=t; hfile->mod_sig=fsig;
} }
return true; return true;
} }

View File

@ -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); struct ipset_file *RegisterIpset(struct desync_profile *dp, bool bExclude, const char *filename);
void IpsetsDebug(); void IpsetsDebug();
bool AppendIpsetItem(ipset *ips, char *ip); bool AppendIpsetItem(ipset *ips, char *ip);
#define ResetAllIpsetModTime() ipset_files_reset_modtime(&params.ipsets)

View File

@ -49,14 +49,34 @@
#define MAX_CONFIG_FILE_SIZE 16384 #define MAX_CONFIG_FILE_SIZE 16384
struct params_s params; struct params_s params;
static bool bReload=false;
#ifdef __CYGWIN__ #ifdef __CYGWIN__
bool bQuit=false; bool bQuit=false;
#endif #endif
static void onhup(int sig) static void onhup(int sig)
{ {
printf("HUP received !\n"); printf("HUP received ! Lists will be reloaded.\n");
// do not do anything. lists auto reload themselves based on file time. 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) static void onusr1(int sig)
@ -251,6 +271,7 @@ static int nfq_main(void)
{ {
while ((rd = recv(fd, buf, sizeof(buf), 0)) >= 0) while ((rd = recv(fd, buf, sizeof(buf), 0)) >= 0)
{ {
ReloadCheck();
if (rd) if (rd)
{ {
int r = nfq_handle_packet(h, (char *)buf, (int)rd); int r = nfq_handle_packet(h, (char *)buf, (int)rd);
@ -371,6 +392,8 @@ static int dvt_main(void)
uint8_t verdict; uint8_t verdict;
size_t len = rd; size_t len = rd;
ReloadCheck();
DLOG("packet: id=%u len=%zu\n", id, len); DLOG("packet: id=%u len=%zu\n", id, len);
verdict = processPacketData(&mark, NULL, buf, &len); verdict = processPacketData(&mark, NULL, buf, &len);
switch (verdict & VERDICT_MASK) switch (verdict & VERDICT_MASK)
@ -489,6 +512,8 @@ static int win_main(const char *windivert_filter)
return w_win32_error; return w_win32_error;
} }
ReloadCheck();
*ifout=0; *ifout=0;
if (wa.Outbound) snprintf(ifout,sizeof(ifout),"%u.%u", wa.Network.IfIdx, wa.Network.SubIfIdx); 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); 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);

View File

@ -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 *hostlist_files_add(struct hostlist_files_head *head, const char *filename)
{ {
struct hostlist_file *entry = malloc(sizeof(struct hostlist_file)); 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 else
entry->filename = NULL; entry->filename = NULL;
entry->mod_time = 0; FILE_MOD_RESET(&entry->mod_sig);
entry->hostlist = NULL; entry->hostlist = NULL;
LIST_INSERT_HEAD(head, entry, next); LIST_INSERT_HEAD(head, entry, next);
} }
@ -202,6 +201,13 @@ struct hostlist_file *hostlist_files_search(struct hostlist_files_head *head, co
} }
return NULL; 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) 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 else
entry->filename = NULL; entry->filename = NULL;
entry->mod_time = 0; FILE_MOD_RESET(&entry->mod_sig);
memset(&entry->ipset,0,sizeof(entry->ipset)); memset(&entry->ipset,0,sizeof(entry->ipset));
LIST_INSERT_HEAD(head, entry, next); 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; 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) struct ipset_item *ipset_collection_add(struct ipset_collection_head *head, struct ipset_file *hfile)
{ {

View File

@ -50,7 +50,7 @@ void strlist_destroy(struct str_list_head *head);
struct hostlist_file { struct hostlist_file {
char *filename; char *filename;
time_t mod_time; file_mod_sig mod_sig;
strpool *hostlist; strpool *hostlist;
LIST_ENTRY(hostlist_file) next; 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); struct hostlist_file *hostlist_files_add(struct hostlist_files_head *head, const char *filename);
void hostlist_files_destroy(struct hostlist_files_head *head); void hostlist_files_destroy(struct hostlist_files_head *head);
struct hostlist_file *hostlist_files_search(struct hostlist_files_head *head, const char *filename); 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_item {
struct hostlist_file *hfile; struct hostlist_file *hfile;
@ -111,7 +112,7 @@ void ipsetPrint(ipset *ipset);
struct ipset_file { struct ipset_file {
char *filename; char *filename;
time_t mod_time; file_mod_sig mod_sig;
ipset ipset; ipset ipset;
LIST_ENTRY(ipset_file) next; 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); struct ipset_file *ipset_files_add(struct ipset_files_head *head, const char *filename);
void ipset_files_destroy(struct ipset_files_head *head); void ipset_files_destroy(struct ipset_files_head *head);
struct ipset_file *ipset_files_search(struct ipset_files_head *head, const char *filename); 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_item {
struct ipset_file *hfile; struct ipset_file *hfile;

View File

@ -314,6 +314,14 @@ time_t file_mod_time(const char *filename)
struct stat st; struct stat st;
return stat(filename, &st) == -1 ? 0 : st.st_mtime; 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) bool pf_in_range(uint16_t port, const port_filter *pf)
{ {

View File

@ -62,6 +62,14 @@ static inline void phton16(uint8_t *p, uint16_t v) {
int fprint_localtime(FILE *F); 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); time_t file_mod_time(const char *filename);
typedef struct typedef struct

View File

@ -105,21 +105,21 @@ static bool LoadHostList(struct hostlist_file *hfile)
{ {
if (hfile->filename) if (hfile->filename)
{ {
time_t t = file_mod_time(hfile->filename); file_mod_sig fsig;
if (!t) if (!file_mod_signature(hfile->filename, &fsig))
{ {
// stat() error // stat() error
DLOG_ERR("cannot access hostlist file '%s'. in-memory content remains unchanged.\n",hfile->filename); DLOG_ERR("cannot access hostlist file '%s'. in-memory content remains unchanged.\n",hfile->filename);
return true; 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); StrPoolDestroy(&hfile->hostlist);
if (!AppendHostList(&hfile->hostlist, hfile->filename)) if (!AppendHostList(&hfile->hostlist, hfile->filename))
{ {
StrPoolDestroy(&hfile->hostlist); StrPoolDestroy(&hfile->hostlist);
return false; return false;
} }
hfile->mod_time=t; hfile->mod_sig=fsig;
} }
return true; return true;
} }

View File

@ -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); struct hostlist_file *RegisterHostlist(struct desync_profile *dp, bool bExclude, const char *filename);
bool HostlistsReloadCheckForProfile(const struct desync_profile *dp); bool HostlistsReloadCheckForProfile(const struct desync_profile *dp);
void HostlistsDebug(); void HostlistsDebug();
#define ResetAllHostlistsModTime() hostlist_files_reset_modtime(&params.hostlists)

View File

@ -126,21 +126,21 @@ static bool LoadIpset(struct ipset_file *hfile)
{ {
if (hfile->filename) if (hfile->filename)
{ {
time_t t = file_mod_time(hfile->filename); file_mod_sig fsig;
if (!t) if (!file_mod_signature(hfile->filename, &fsig))
{ {
// stat() error // stat() error
DLOG_ERR("cannot access ipset file '%s'. in-memory content remains unchanged.\n",hfile->filename); DLOG_ERR("cannot access ipset file '%s'. in-memory content remains unchanged.\n",hfile->filename);
return true; 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); ipsetDestroy(&hfile->ipset);
if (!AppendIpset(&hfile->ipset, hfile->filename)) if (!AppendIpset(&hfile->ipset, hfile->filename))
{ {
ipsetDestroy(&hfile->ipset); ipsetDestroy(&hfile->ipset);
return false; return false;
} }
hfile->mod_time=t; hfile->mod_sig=fsig;
} }
return true; return true;
} }

View File

@ -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); struct ipset_file *RegisterIpset(struct desync_profile *dp, bool bExclude, const char *filename);
void IpsetsDebug(); void IpsetsDebug();
bool AppendIpsetItem(ipset *ips, char *ip); bool AppendIpsetItem(ipset *ips, char *ip);
#define ResetAllIpsetModTime() ipset_files_reset_modtime(&params.ipsets)

View File

@ -169,7 +169,7 @@ struct hostlist_file *hostlist_files_add(struct hostlist_files_head *head, const
} }
else else
entry->filename = NULL; entry->filename = NULL;
entry->mod_time = 0; FILE_MOD_RESET(&entry->mod_sig);
entry->hostlist = NULL; entry->hostlist = NULL;
LIST_INSERT_HEAD(head, entry, next); LIST_INSERT_HEAD(head, entry, next);
} }
@ -201,6 +201,13 @@ struct hostlist_file *hostlist_files_search(struct hostlist_files_head *head, co
} }
return NULL; 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) 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 else
entry->filename = NULL; entry->filename = NULL;
entry->mod_time = 0; FILE_MOD_RESET(&entry->mod_sig);
memset(&entry->ipset,0,sizeof(entry->ipset)); memset(&entry->ipset,0,sizeof(entry->ipset));
LIST_INSERT_HEAD(head, entry, next); 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; 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) struct ipset_item *ipset_collection_add(struct ipset_collection_head *head, struct ipset_file *hfile)
{ {

View File

@ -50,7 +50,7 @@ void strlist_destroy(struct str_list_head *head);
struct hostlist_file { struct hostlist_file {
char *filename; char *filename;
time_t mod_time; file_mod_sig mod_sig;
strpool *hostlist; strpool *hostlist;
LIST_ENTRY(hostlist_file) next; 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); struct hostlist_file *hostlist_files_add(struct hostlist_files_head *head, const char *filename);
void hostlist_files_destroy(struct hostlist_files_head *head); void hostlist_files_destroy(struct hostlist_files_head *head);
struct hostlist_file *hostlist_files_search(struct hostlist_files_head *head, const char *filename); 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_item {
struct hostlist_file *hfile; struct hostlist_file *hfile;
@ -111,7 +112,7 @@ void ipsetPrint(ipset *ipset);
struct ipset_file { struct ipset_file {
char *filename; char *filename;
time_t mod_time; file_mod_sig mod_sig;
ipset ipset; ipset ipset;
LIST_ENTRY(ipset_file) next; 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); struct ipset_file *ipset_files_add(struct ipset_files_head *head, const char *filename);
void ipset_files_destroy(struct ipset_files_head *head); void ipset_files_destroy(struct ipset_files_head *head);
struct ipset_file *ipset_files_search(struct ipset_files_head *head, const char *filename); 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_item {
struct ipset_file *hfile; struct ipset_file *hfile;

View File

@ -443,7 +443,8 @@ static void auto_hostlist_failed(struct desync_profile *dp, const char *hostname
DLOG_PERROR("write to auto hostlist:"); DLOG_PERROR("write to auto hostlist:");
return; 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 else
{ {

View File

@ -50,10 +50,31 @@
#define MAX_CONFIG_FILE_SIZE 16384 #define MAX_CONFIG_FILE_SIZE 16384
struct params_s params; struct params_s params;
static bool bReload=false;
static void onhup(int sig) 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) static void onusr2(int sig)

View File

@ -6,4 +6,4 @@
#include <sys/param.h> #include <sys/param.h>
void dohup(void); void ReloadCheck();

View File

@ -1544,6 +1544,8 @@ int event_loop(const int *listen_fd, size_t listen_fd_ct)
for(;;) for(;;)
{ {
ReloadCheck();
DBGPRINT("epoll_wait\n"); DBGPRINT("epoll_wait\n");
if ((num_events = epoll_wait(efd, events, MAX_EPOLL_EVENTS, -1)) == -1) if ((num_events = epoll_wait(efd, events, MAX_EPOLL_EVENTS, -1)) == -1)