diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2014-04-27 15:04:07 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2014-05-02 18:31:13 +0200 |
commit | c179ee88d91a84fc75dc4602cca500e8fa72ed66 (patch) | |
tree | b6b149622e02c81265a673145d6b9a260776f799 /src/event.c |
initial commit
This patch bootstrap the new nft-sync software. Basically, this
software aims to support two different setups:
1) Rule-set repository server. The software serves the nft rule-set to
clients that request the ruleset.
Basically from the system that acts as repository, you have to run:
# nft-sync -c ../contrib/nft-sync.conf.server
Then, from the client:
# nft-sync -c ../contrib/nft-sync.conf.client --fetch
Which displays the nft rule-set in the standard output, so you
can inspect the nft rule-set.
Alternatively, the client can also retrieve and apply the nft
rule-set using the pull command instead:
# nft-sync -c ../contrib/nft-sync.conf.client --pull
[ Note that this command above does not work in this bootstrap yet ]
2) Rule-set synchronization: In case of primary-backup and multiprimary
firewall configurations, the software makes sure that the firewall
cluster is deploying the same filtering policy. In this case, you have
to launch the process:
# nft-sync -c ../contrib/nft-sync.conf --sync
[ Note that this command above does not work in this bootstrap yet ]
This bootstrap provides the basic infrastructure as a proof-of-concept.
Many of the necessary features are still lacking:
* Implement --sync and --pull commands.
* Interaction with nft through libnftnl, which allows the software to
retrieve the local nft rule-set, as well as to parse it and apply it.
* SSL support, specifically the repository mode needs it to make sure
nobody can steal your filtering policy from the network.
* IPv6 support.
* Allow to serve different rule-sets in the repository mode.
And many others that will be added progressively.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/event.c')
-rw-r--r-- | src/event.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/event.c b/src/event.c new file mode 100644 index 0000000..464b689 --- /dev/null +++ b/src/event.c @@ -0,0 +1,79 @@ +/* + * (C) 2014 by Pablo Neira Ayuso <pablo@netfilter.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + */ +#include <stdio.h> +#include <stdlib.h> +#include <event.h> + +#include "init.h" +#include "logging.h" + +static int sigtype; +static struct event_base *ev_base; +static struct event sigterm_event, sigusr1_event, sigint_event; + +static void sigterm_callback(int fd, short event, void *data) +{ + sigtype = SIGTERM; +} + +static void sigint_callback(int fd, short event, void *data) +{ + sigtype = SIGINT; +} + +static void sigusr1_callback(int fd, short event, void *data) +{ + sigtype = SIGUSR1; +} + +int nft_sync_event_init(void) +{ + ev_base = event_init(); + if (ev_base == NULL) + return -1; + + signal_set(&sigint_event, SIGINT, sigint_callback, NULL); + signal_add(&sigint_event, NULL); + signal_set(&sigterm_event, SIGTERM, sigterm_callback, NULL); + signal_add(&sigterm_event, NULL); + signal_set(&sigusr1_event, SIGUSR1, sigusr1_callback, NULL); + signal_add(&sigusr1_event, NULL); + + return 0; +} + +void nft_sync_event_loop(void) +{ + while (!sigtype && !nfts_inst.stop) + event_loop(EVLOOP_ONCE); + + switch (sigtype) { + case SIGINT: + nfts_log(NFTS_LOG_NOTICE, "Received SIGINT, closing."); + break; + case SIGTERM: + nfts_log(NFTS_LOG_NOTICE, "Received SIGTERM, closing."); + break; + case SIGUSR1: + nfts_log(NFTS_LOG_NOTICE, "Received SIGUSR1"); + /* TODO: reload configuration file */ + break; + default: + nfts_log(NFTS_LOG_INFO, "Closing process"); + break; + } +} + +void nft_sync_event_fini(void) +{ + signal_del(&sigterm_event); + signal_del(&sigusr1_event); + signal_del(&sigint_event); + event_base_free(ev_base); +} |