summaryrefslogtreecommitdiffstats
path: root/src/server.c
diff options
context:
space:
mode:
authorArturo Borrero Gonzalez <arturo.borrero.glez@gmail.com>2014-05-06 13:28:33 +0200
committerArturo Borrero Gonzalez <aborrero@cica.es>2014-05-07 17:09:29 +0200
commitcaa1cf2960db0d0a01e707f5a82a05d0718ff498 (patch)
treedaad2ad6efadd88271a9351b52e7ee50049ac555 /src/server.c
parentc179ee88d91a84fc75dc4602cca500e8fa72ed66 (diff)
nft-sync: complete --fetch operation
This patch complete the --fetch operation in the server side. By now, the format of the ruleset is XML. In further patches we can include additional config options to let the admin choose one of XML/JSON. Signed-off-by: Arturo Borrero Gonzalez <arturo.borrero.glez@gmail.com> Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/server.c')
-rw-r--r--src/server.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/server.c b/src/server.c
index cd4ac0a..1b6e0d8 100644
--- a/src/server.c
+++ b/src/server.c
@@ -22,24 +22,31 @@
#include "proto.h"
#include "config.h"
#include "proto.h"
+#include "mnl.h"
+#include "utils.h"
static int send_ruleset(struct nft_fd *nfd)
{
struct msg_buff *msgb;
struct nft_sync_hdr *hdr;
- /* TODO: send real ruleset in json/xml format here, replace this
- * code with the real libnftnl code.
- */
- const char *ruleset = "this is the ruleset in XML/JSON format";
- int ret, ruleset_len = strlen(ruleset);
+ int ret, ruleset_len;
+ const char *ruleset = netlink_dump_ruleset(nfts_inst.nl_query_sock);
+
+ if (ruleset == NULL)
+ return 0;
+
+ ruleset_len = strlen(ruleset);
msgb = msgb_alloc(sizeof(struct nft_sync_hdr) + ruleset_len);
- if (msgb == NULL)
+ if (msgb == NULL) {
+ xfree(ruleset);
return -1;
+ }
hdr = msgb_put(msgb, sizeof(struct nft_sync_hdr) + ruleset_len);
hdr->len = htonl(sizeof(struct nft_sync_hdr) + ruleset_len);
memcpy(hdr->data, ruleset, ruleset_len);
+ xfree(ruleset);
ret = send(nfd->fd, msgb_data(msgb), msgb_len(msgb), 0);
msgb_free(msgb);