add signal handling code to UDP server mode
This commit is contained in:
parent
aa2492bba2
commit
5db3a12763
@ -180,13 +180,18 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
/* If we are to acquire SPA data via a UDP socket, start it up here.
|
/* If we are to acquire SPA data via a UDP socket, start it up here.
|
||||||
*/
|
*/
|
||||||
if(1 || strncasecmp(opts.config[CONF_ENABLE_UDP_SERVER], "Y", 1) == 0)
|
if(opts.enable_udp_server ||
|
||||||
|
strncasecmp(opts.config[CONF_ENABLE_UDP_SERVER], "Y", 1) == 0)
|
||||||
{
|
{
|
||||||
if(run_udp_server(&opts) < 0)
|
if(run_udp_server(&opts) < 0)
|
||||||
{
|
{
|
||||||
log_msg(LOG_ERR, "Fatal run_udp_server() error");
|
log_msg(LOG_ERR, "Fatal run_udp_server() error");
|
||||||
clean_exit(&opts, FW_CLEANUP, EXIT_FAILURE);
|
clean_exit(&opts, FW_CLEANUP, EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the TCP server option was set, fire it up here. Note that in
|
/* If the TCP server option was set, fire it up here. Note that in
|
||||||
@ -395,7 +400,7 @@ static int handle_signals(fko_srv_options_t *opts)
|
|||||||
|
|
||||||
if(got_sighup)
|
if(got_sighup)
|
||||||
{
|
{
|
||||||
log_msg(LOG_WARNING, "Got SIGHUP. Re-reading configs.");
|
log_msg(LOG_WARNING, "Got SIGHUP. Re-reading configs.");
|
||||||
free_configs(opts);
|
free_configs(opts);
|
||||||
kill(opts->tcp_server_pid, SIGTERM);
|
kill(opts->tcp_server_pid, SIGTERM);
|
||||||
usleep(1000000);
|
usleep(1000000);
|
||||||
@ -404,12 +409,12 @@ static int handle_signals(fko_srv_options_t *opts)
|
|||||||
}
|
}
|
||||||
else if(got_sigint)
|
else if(got_sigint)
|
||||||
{
|
{
|
||||||
log_msg(LOG_WARNING, "Got SIGINT. Exiting...");
|
log_msg(LOG_WARNING, "Got SIGINT. Exiting...");
|
||||||
got_sigint = 0;
|
got_sigint = 0;
|
||||||
}
|
}
|
||||||
else if(got_sigterm)
|
else if(got_sigterm)
|
||||||
{
|
{
|
||||||
log_msg(LOG_WARNING, "Got SIGTERM. Exiting...");
|
log_msg(LOG_WARNING, "Got SIGTERM. Exiting...");
|
||||||
got_sigterm = 0;
|
got_sigterm = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -422,13 +427,13 @@ static int handle_signals(fko_srv_options_t *opts)
|
|||||||
&& opts->packet_ctr >= opts->packet_ctr_limit)
|
&& opts->packet_ctr >= opts->packet_ctr_limit)
|
||||||
{
|
{
|
||||||
log_msg(LOG_INFO,
|
log_msg(LOG_INFO,
|
||||||
"Packet count limit (%d) reached. Exiting...",
|
"Packet count limit (%d) reached. Exiting...",
|
||||||
opts->packet_ctr_limit);
|
opts->packet_ctr_limit);
|
||||||
}
|
}
|
||||||
else /* got_signal was not set (should be if we are here) */
|
else /* got_signal was not set (should be if we are here) */
|
||||||
{
|
{
|
||||||
log_msg(LOG_WARNING,
|
log_msg(LOG_WARNING,
|
||||||
"Capture ended without signal. Exiting...");
|
"Capture ended without signal. Exiting...");
|
||||||
}
|
}
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,7 +36,6 @@
|
|||||||
#include "fwknopd_common.h"
|
#include "fwknopd_common.h"
|
||||||
#include "pcap_capture.h"
|
#include "pcap_capture.h"
|
||||||
#include "process_packet.h"
|
#include "process_packet.h"
|
||||||
#include "sig_handler.h"
|
|
||||||
#include "fw_util.h"
|
#include "fw_util.h"
|
||||||
#include "log_msg.h"
|
#include "log_msg.h"
|
||||||
#include "fwknopd_errors.h"
|
#include "fwknopd_errors.h"
|
||||||
|
|||||||
@ -29,6 +29,7 @@
|
|||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
*/
|
*/
|
||||||
#include "fwknopd_common.h"
|
#include "fwknopd_common.h"
|
||||||
|
#include "sig_handler.h"
|
||||||
#include "incoming_spa.h"
|
#include "incoming_spa.h"
|
||||||
#include "log_msg.h"
|
#include "log_msg.h"
|
||||||
#include "fw_util.h"
|
#include "fw_util.h"
|
||||||
@ -116,10 +117,36 @@ run_udp_server(fko_srv_options_t *opts)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Initialize our signal handlers. You can check the return value for
|
||||||
|
* the number of signals that were *not* set. Those that were not set
|
||||||
|
* will be listed in the log/stderr output.
|
||||||
|
*/
|
||||||
|
if(set_sig_handlers() > 0)
|
||||||
|
log_msg(LOG_ERR, "Errors encountered when setting signal handlers.");
|
||||||
|
|
||||||
/* Now loop and receive SPA packets
|
/* Now loop and receive SPA packets
|
||||||
*/
|
*/
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
|
/* Any signal except USR1, USR2, and SIGCHLD mean break the loop.
|
||||||
|
*/
|
||||||
|
if(got_signal != 0)
|
||||||
|
{
|
||||||
|
if(got_sigint || got_sigterm || got_sighup)
|
||||||
|
{
|
||||||
|
close(s_sock);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if(got_sigusr1 || got_sigusr2)
|
||||||
|
{
|
||||||
|
/* Not doing anything with these yet.
|
||||||
|
*/
|
||||||
|
got_sigusr1 = got_sigusr2 = 0;
|
||||||
|
got_signal = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
got_signal = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check for any expired firewall rules and deal with them.
|
/* Check for any expired firewall rules and deal with them.
|
||||||
*/
|
*/
|
||||||
@ -165,7 +192,8 @@ run_udp_server(fko_srv_options_t *opts)
|
|||||||
{
|
{
|
||||||
memset(sipbuf, 0x0, MAX_IPV4_STR_LEN);
|
memset(sipbuf, 0x0, MAX_IPV4_STR_LEN);
|
||||||
inet_ntop(AF_INET, &(caddr.sin_addr.s_addr), sipbuf, MAX_IPV4_STR_LEN);
|
inet_ntop(AF_INET, &(caddr.sin_addr.s_addr), sipbuf, MAX_IPV4_STR_LEN);
|
||||||
log_msg(LOG_INFO, "udp_server: Got UDP connection from %s.", sipbuf);
|
log_msg(LOG_INFO, "udp_server: Got UDP datagram (%d bytes) from: %s",
|
||||||
|
pkt_len, sipbuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Expect the data to not be too large
|
/* Expect the data to not be too large
|
||||||
@ -187,6 +215,7 @@ run_udp_server(fko_srv_options_t *opts)
|
|||||||
|
|
||||||
} /* infinite while loop */
|
} /* infinite while loop */
|
||||||
|
|
||||||
|
close(s_sock);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user