From caa1cf2960db0d0a01e707f5a82a05d0718ff498 Mon Sep 17 00:00:00 2001 From: Arturo Borrero Gonzalez Date: Tue, 6 May 2014 13:28:33 +0200 Subject: 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 Acked-by: Pablo Neira Ayuso --- src/server.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/server.c') 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); -- cgit v1.2.3