config sanity check that there is at least one target protocol for each family that we listen to (fix #336)

This commit is contained in:
yrutschle 2022-07-10 21:16:41 +02:00
parent b36486bb6d
commit a4db163a69
3 changed files with 44 additions and 5 deletions

View File

@ -168,11 +168,6 @@ static void config_protocols()
void config_sanity_check(struct sslhcfg_item* cfg) {
if (!cfg->protocols_len) {
print_message(msg_config_error, "At least one target protocol must be specified.\n");
exit(2);
}
/* If compiling with systemd socket support no need to require listen address */
#ifndef SYSTEMD
if (!cfg->listen_len && !cfg->inetd) {

View File

@ -70,7 +70,29 @@ static void tcp_protocol_list_init(void)
}
}
/* Configuration sanity check for TCP:
* - If there is a listening socket, there must be at least one target
*/
static void tcp_sanity_check(void)
{
int tcp_present = 0;
for (int i = 0; i < cfg.listen_len; i++) {
struct sslhcfg_listen_item* p = &cfg.listen[i];
if (!p->is_udp) {
tcp_present = 1;
break;
}
}
if (tcp_present && !tcp_protocols_len) {
print_message(msg_config_error, "At least one TCP target protocol must be specified.\n");
exit(2);
}
}
void tcp_init(void)
{
tcp_protocol_list_init();
tcp_sanity_check();
}

View File

@ -91,6 +91,27 @@ static void udp_protocol_list_init(void)
}
}
/* Configuration sanity check for UDP:
* - If there is a listening addres, there must be at least one target
*/
static void udp_sanity_check(void)
{
int udp_present = 0;
for (int i = 0; i < cfg.listen_len; i++) {
struct sslhcfg_listen_item* p = &cfg.listen[i];
if (p->is_udp) {
udp_present = 1;
break;
}
}
if (udp_present && !udp_protocols_len) {
print_message(msg_config_error, "At least one UDP target protocol must be specified.\n");
exit(2);
}
}
/* Init the UDP subsystem.
* - Initialise the hash
* - that's all, folks
@ -100,6 +121,7 @@ void udp_init(struct loop_info* fd_info)
fd_info->hash_sources = hash_init(cfg.udp_max_connections, &hash_make_key, &cnx_cmp);
udp_protocol_list_init();
udp_sanity_check();
}