Merge commit 'c9908cfd53dd4d2e71d528ba9e019325e7409d70' into dora

This commit is contained in:
Harald Welte 2015-05-21 17:52:32 +02:00
commit 0d60036748
5 changed files with 20 additions and 54 deletions

View File

@ -1,4 +1,4 @@
From aefba0f03444345dd5384631203f61647637175d Mon Sep 17 00:00:00 2001
From 83745c87b294166ff4dbee4a781e7eb5d4f568b8 Mon Sep 17 00:00:00 2001
From: Harald Welte <laforge@gnumonks.org>
Date: Tue, 19 May 2015 22:12:06 +0200
Subject: [PATCH] Add JSON output formatting to nfacct utility
@ -6,8 +6,8 @@ Subject: [PATCH] Add JSON output formatting to nfacct utility
This is based on the JSON support patch of libnetfilter_acct.
---
nfacct.8 | 2 ++
src/nfacct.c | 87 ++++++++++++++++++++++++++++++++++++++++++++----------------
2 files changed, 66 insertions(+), 23 deletions(-)
src/nfacct.c | 89 ++++++++++++++++++++++++++++++++++++++++++++----------------
2 files changed, 68 insertions(+), 23 deletions(-)
diff --git a/nfacct.8 b/nfacct.8
index 0c3249c..bf563ae 100644
@ -23,7 +23,7 @@ index 0c3249c..bf563ae 100644
.SH SEE ALSO
.BR iptables (8)
diff --git a/src/nfacct.c b/src/nfacct.c
index 2546a6e..a55655a 100644
index 2546a6e..d46ee91 100644
--- a/src/nfacct.c
+++ b/src/nfacct.c
@@ -137,13 +137,13 @@ int main(int argc, char *argv[])
@ -42,7 +42,7 @@ index 2546a6e..a55655a 100644
nfacct = nfacct_alloc();
if (nfacct == NULL) {
@@ -156,17 +156,36 @@ static int nfacct_cb(const struct nlmsghdr *nlh, void *data)
@@ -156,17 +156,38 @@ static int nfacct_cb(const struct nlmsghdr *nlh, void *data)
goto err_free;
}
@ -60,7 +60,9 @@ index 2546a6e..a55655a 100644
+ break;
+ case NFACCT_SNPRINTF_T_JSON:
+ if (!fmt_header) {
+ printf("{ \"nfacct_counters\" : [\n");
+ printf("{ \"timestamp\" : %lld, \n"
+ " \"nfacct_counters\" : [\n",
+ (long long) time(NULL));
+ fmt_header = true;
+ } else
+ printf(",\n");
@ -87,7 +89,7 @@ index 2546a6e..a55655a 100644
err_free:
nfacct_free(nfacct);
@@ -174,9 +193,26 @@ err:
@@ -174,9 +195,26 @@ err:
return MNL_CB_OK;
}
@ -115,7 +117,7 @@ index 2546a6e..a55655a 100644
struct mnl_socket *nl;
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
@@ -190,9 +226,13 @@ static int nfacct_cmd_list(int argc, char *argv[])
@@ -190,9 +228,13 @@ static int nfacct_cmd_list(int argc, char *argv[])
duparg(argv[i]);
zeroctr = true;
} else if (strncmp(argv[i], "xml", strlen(argv[i])) == 0) {
@ -131,7 +133,7 @@ index 2546a6e..a55655a 100644
} else if (strncmp(argv[i], "counters", strlen(argv[i])) == 0) {
if (mask || value)
duparg(argv[i]);
@@ -251,7 +291,7 @@ static int nfacct_cmd_list(int argc, char *argv[])
@@ -251,7 +293,7 @@ static int nfacct_cmd_list(int argc, char *argv[])
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
while (ret > 0) {
@ -140,7 +142,7 @@ index 2546a6e..a55655a 100644
if (ret <= 0)
break;
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
@@ -262,8 +302,7 @@ static int nfacct_cmd_list(int argc, char *argv[])
@@ -262,8 +304,7 @@ static int nfacct_cmd_list(int argc, char *argv[])
}
mnl_socket_close(nl);
@ -150,7 +152,7 @@ index 2546a6e..a55655a 100644
return 0;
}
@@ -444,7 +483,8 @@ static int nfacct_cmd_delete(int argc, char *argv[])
@@ -444,7 +485,8 @@ static int nfacct_cmd_delete(int argc, char *argv[])
static int nfacct_cmd_get(int argc, char *argv[])
{
@ -160,7 +162,7 @@ index 2546a6e..a55655a 100644
struct mnl_socket *nl;
char buf[MNL_SOCKET_BUFFER_SIZE];
struct nlmsghdr *nlh;
@@ -460,7 +500,9 @@ static int nfacct_cmd_get(int argc, char *argv[])
@@ -460,7 +502,9 @@ static int nfacct_cmd_get(int argc, char *argv[])
if (strncmp(argv[i], "reset", strlen(argv[i])) == 0) {
zeroctr = true;
} else if (strncmp(argv[i], "xml", strlen(argv[i])) == 0) {
@ -171,7 +173,7 @@ index 2546a6e..a55655a 100644
} else {
nfacct_perror("unknown argument");
return -1;
@@ -503,7 +545,7 @@ static int nfacct_cmd_get(int argc, char *argv[])
@@ -503,7 +547,7 @@ static int nfacct_cmd_get(int argc, char *argv[])
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
while (ret > 0) {
@ -180,7 +182,7 @@ index 2546a6e..a55655a 100644
if (ret <= 0)
break;
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
@@ -514,8 +556,7 @@ static int nfacct_cmd_get(int argc, char *argv[])
@@ -514,8 +558,7 @@ static int nfacct_cmd_get(int argc, char *argv[])
}
mnl_socket_close(nl);
@ -190,7 +192,7 @@ index 2546a6e..a55655a 100644
return 0;
}
@@ -660,7 +701,7 @@ static int nfacct_cmd_restore(int argc, char *argv[])
@@ -660,7 +703,7 @@ static int nfacct_cmd_restore(int argc, char *argv[])
static int nfacct_cmd_monitor(int argc, char *argv[])
{
struct mnl_socket *nl;
@ -199,7 +201,7 @@ index 2546a6e..a55655a 100644
char buf[MNL_SOCKET_BUFFER_SIZE];
int ret, option = NFNLGRP_ACCT_QUOTA;
@@ -685,7 +726,7 @@ static int nfacct_cmd_monitor(int argc, char *argv[])
@@ -685,7 +728,7 @@ static int nfacct_cmd_monitor(int argc, char *argv[])
break;
}

View File

@ -4,6 +4,8 @@ LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://COPYING;md5=8ca43cbc842c2336e835926c2166c28b"
PV="1.0.1+git${SRCPV}"
PR="r1"
DEPENDS = "libmnl libnetfilter-acct"
SRC_URI = "git://git.netfilter.org/nfacct;branch=master \

View File

@ -1,17 +0,0 @@
SUMMARY = "Module needed by libjson-xs-perl"
DESCRIPTION = ""
HOMEPAGE = "http://search.cpan.org/~mlehmann/common-sense-3.73/sense.pod"
SECTION = "libs"
LICENSE = "Artistic-1.0 | GPL-1.0+"
LIC_FILES_CHKSUM = "file://LICENSE;md5=043dba8b278e1db1b0ef93f30140b02b"
SRC_URI = "http://search.cpan.org/CPAN/authors/id/M/ML/MLEHMANN/common-sense-${PV}.tar.gz"
SRC_URI[md5sum] = "6da7455a43ab60ed21c2a5e3b3ddeda8"
SRC_URI[sha256sum] = "8110c5e472641e0c218f8e023cecc1612ef66f9a1b313261fe219862efe3fd10"
S = "${WORKDIR}/common-sense-${PV}"
inherit cpan
BBCLASSEXTEND = "native"

View File

@ -6,7 +6,6 @@ LICENSE = "Artistic-1.0 | GPL-1.0+"
RDEPENDS_${PN} = " perl-module-carp \
perl-module-overload \
perl-module-constant \
libjson-xs-perl \
"
LIC_FILES_CHKSUM = "file://MYMETA.yml;md5=109a8b45192a65e7f220dd0bf3bdfbad"

View File

@ -1,20 +0,0 @@
SUMMARY = "The Perl JSON API"
DESCRIPTION = ""
HOMEPAGE = "http://search.cpan.org/~makamaka/JSON-2.90/lib/JSON.pm"
SECTION = "libs"
LICENSE = "Artistic-1.0 | GPL-1.0+"
RDEPENDS_${PN} = " perl-module-encoding \
libcommon-sense-perl \
"
LIC_FILES_CHKSUM = "file://COPYING;md5=043dba8b278e1db1b0ef93f30140b02b"
SRC_URI = "http://search.cpan.org/CPAN/authors/id/M/ML/MLEHMANN/JSON-XS-${PV}.tar.gz"
SRC_URI[md5sum] = "b7be65295baf6dd9233c6494782c1153"
SRC_URI[sha256sum] = "4e8df3256a5aa9ed304ce1bbcd9140737deef31ba847bff9f4c15480c88c71ab"
S = "${WORKDIR}/JSON-XS-${PV}"
inherit cpan
BBCLASSEXTEND = "native"