From 625cbb195bed237fae3a27f68dd229ae85840ea1 Mon Sep 17 00:00:00 2001 From: Ed Kellett Date: Thu, 29 Oct 2020 16:59:37 +0000 Subject: [PATCH] Refactor clear_out_address_conf* --- include/hostmask.h | 9 +++++++-- ircd/bandbi.c | 2 +- ircd/hostmask.c | 46 +++++++++------------------------------------- ircd/s_conf.c | 2 +- 4 files changed, 18 insertions(+), 41 deletions(-) diff --git a/include/hostmask.h b/include/hostmask.h index 2eb2a16d..33b0e5f6 100644 --- a/include/hostmask.h +++ b/include/hostmask.h @@ -33,6 +33,12 @@ enum HM_IPV6, }; +enum aconf_category +{ + AC_CONFIG, + AC_BANDB, +}; + int parse_netmask(const char *, struct rb_sockaddr_storage *, int *); int parse_netmask_strict(const char *, struct rb_sockaddr_storage *, int *); struct ConfItem *find_conf_by_address(const char *host, const char *sockhost, @@ -42,8 +48,7 @@ struct ConfItem *find_exact_conf_by_address(const char *address, int type, const char *username); void add_conf_by_address(const char *, int, const char *, const char *, struct ConfItem *); void delete_one_address_conf(const char *, struct ConfItem *); -void clear_out_address_conf(void); -void clear_out_address_conf_bans(void); +void clear_out_address_conf(enum aconf_category); void init_host_hash(void); struct ConfItem *find_address_conf(const char *host, const char *sockhost, const char *, const char *, struct sockaddr *, diff --git a/ircd/bandbi.c b/ircd/bandbi.c index dfb4f73d..2b17e5d6 100644 --- a/ircd/bandbi.c +++ b/ircd/bandbi.c @@ -327,7 +327,7 @@ bandb_handle_finish(void) struct ConfItem *aconf; rb_dlink_node *ptr, *next_ptr; - clear_out_address_conf_bans(); + clear_out_address_conf(AC_BANDB); clear_s_newconf_bans(); RB_DLINK_FOREACH_SAFE(ptr, next_ptr, bandb_pending.head) diff --git a/ircd/hostmask.c b/ircd/hostmask.c index 67d26b51..1a154130 100644 --- a/ircd/hostmask.c +++ b/ircd/hostmask.c @@ -631,7 +631,7 @@ delete_one_address_conf(const char *address, struct ConfItem *aconf) * them, otherwise sets them as illegal. */ void -clear_out_address_conf(void) +clear_out_address_conf(enum aconf_category clear_type) { int i; struct AddressRec **store_next; @@ -642,11 +642,17 @@ clear_out_address_conf(void) store_next = &atable[i]; for (arec = atable[i]; arec; arec = arecn) { + enum aconf_category cur_type; arecn = arec->next; + + if (arec->type == CONF_CLIENT || arec->type == CONF_EXEMPTDLINE || arec->type == CONF_SECURE) + cur_type = AC_CONFIG; + else + cur_type = AC_BANDB; + /* We keep the temporary K-lines and destroy the * permanent ones, just to be confusing :) -A1kmm */ - if(arec->aconf->flags & CONF_FLAGS_TEMPORARY || - (arec->type != CONF_CLIENT && arec->type != CONF_EXEMPTDLINE && arec->type != CONF_SECURE)) + if (arec->aconf->flags & CONF_FLAGS_TEMPORARY || cur_type != clear_type) { *store_next = arec; store_next = &arec->next; @@ -663,40 +669,6 @@ clear_out_address_conf(void) } } -void -clear_out_address_conf_bans(void) -{ - int i; - struct AddressRec **store_next; - struct AddressRec *arec, *arecn; - - for (i = 0; i < ATABLE_SIZE; i++) - { - store_next = &atable[i]; - for (arec = atable[i]; arec; arec = arecn) - { - arecn = arec->next; - /* We keep the temporary K-lines and destroy the - * permanent ones, just to be confusing :) -A1kmm */ - if(arec->aconf->flags & CONF_FLAGS_TEMPORARY || - (arec->type == CONF_CLIENT || arec->type == CONF_EXEMPTDLINE || arec->type == CONF_SECURE)) - { - *store_next = arec; - store_next = &arec->next; - } - else - { - arec->aconf->status |= CONF_ILLEGAL; - if(!arec->aconf->clients) - free_conf(arec->aconf); - rb_free(arec); - } - } - *store_next = NULL; - } -} - - /* * show_iline_prefix() * diff --git a/ircd/s_conf.c b/ircd/s_conf.c index 346fe363..b67d2388 100644 --- a/ircd/s_conf.c +++ b/ircd/s_conf.c @@ -1491,7 +1491,7 @@ clear_out_old_conf(void) MaxUsers(cltmp) = -1; } - clear_out_address_conf(); + clear_out_address_conf(AC_CONFIG); clear_s_newconf(); /* clean out module paths */