From 2de85b4d25146b6fa5b056b8137eeef21dc7dc4b Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Tue, 11 Dec 2018 19:56:23 +1300 Subject: [PATCH 01/13] Disabled stdout buffering. --- replayd.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/replayd.c b/replayd.c index 04357e8..baa9dd9 100644 --- a/replayd.c +++ b/replayd.c @@ -63,6 +63,8 @@ netsnmp_variable_list *parse_reply(char *name) { netsnmp_variable_list *list = NULL; netsnmp_variable_list *lptr = NULL; + setbuf(stdout, NULL); + fname = malloc(strlen(directory) + strlen(name) + 2); sprintf(fname, "%s/%s", directory, name); fr = fopen(fname, "r"); From 89c157d3d0e88ef71326c929c35c70f876d72834 Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Thu, 13 Dec 2018 08:52:36 +1300 Subject: [PATCH 02/13] Add IP Address support. --- replayd.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/replayd.c b/replayd.c index baa9dd9..c072c9c 100644 --- a/replayd.c +++ b/replayd.c @@ -144,6 +144,14 @@ netsnmp_variable_list *parse_reply(char *name) { snmp_parse_oid(value, lptr->val.objid, &(lptr->val_len)); lptr->val_len *= sizeof(oid); break; + case ASN_IPADDRESS: + lptr->val.integer = malloc(sizeof(struct in_addr)); + + if (inet_aton(value, lptr->val.integer) == 0) { + fprintf(stderr, "Invalid address: %s\n", value); + } + lptr->val_len = sizeof(struct in_addr); + break; } } From 65db6a37cff6be4d419d3de2d9aba0961c583d6f Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Thu, 13 Dec 2018 08:53:06 +1300 Subject: [PATCH 03/13] Print an error on unparsable types. --- replayd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/replayd.c b/replayd.c index c072c9c..4472761 100644 --- a/replayd.c +++ b/replayd.c @@ -152,6 +152,9 @@ netsnmp_variable_list *parse_reply(char *name) { } lptr->val_len = sizeof(struct in_addr); break; + default: + fprintf(stderr, "Don't know how to parse %s\n", type_str); + break; } } From 026d09ded82b8f2b1ae0dba8ce8d7e23d3fce933 Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Thu, 13 Dec 2018 08:53:47 +1300 Subject: [PATCH 04/13] Add Docker support. --- Dockerfile | 20 ++++++++++++++++++++ bootstrap.sh | 3 +++ 2 files changed, 23 insertions(+) create mode 100644 Dockerfile create mode 100755 bootstrap.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d811ead --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM debian:jessie +# copy the data in + +RUN apt-get update +RUN apt-get -y install build-essential autoconf libtool-bin libsnmp-dev + +COPY . . + +RUN ./autogen.sh + +RUN ./configure + +RUN make + +# convinience +RUN apt-get install snmp + +EXPOSE 1661:1661/udp + +CMD [ "./replayd", "-d", "replays", "-v", "-v", "-v" ] diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..b22deea --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker build -t replayd . && docker run -P replayd From a5163d7ab3186f9fc027d5c212b716bd2f32040e Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Thu, 13 Dec 2018 08:58:18 +1300 Subject: [PATCH 05/13] Bump container to debian:stretch. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d811ead..470ac1b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM debian:jessie +FROM debian:stretch # copy the data in RUN apt-get update From b40e60ebd80077f4b46274dd9a9e943987158524 Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Thu, 13 Dec 2018 09:31:00 +1300 Subject: [PATCH 06/13] Fix compilation warnings. --- replayd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/replayd.c b/replayd.c index 4472761..a3cf5c9 100644 --- a/replayd.c +++ b/replayd.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -147,7 +148,7 @@ netsnmp_variable_list *parse_reply(char *name) { case ASN_IPADDRESS: lptr->val.integer = malloc(sizeof(struct in_addr)); - if (inet_aton(value, lptr->val.integer) == 0) { + if (inet_aton(value, (struct in_addr *)lptr->val.integer) == 0) { fprintf(stderr, "Invalid address: %s\n", value); } lptr->val_len = sizeof(struct in_addr); From fc7679a5ae0a8453ed21f348182a704539528462 Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Thu, 13 Dec 2018 09:36:16 +1300 Subject: [PATCH 07/13] Add IP Address examples to unittest file. --- replays/unittest | 2 ++ 1 file changed, 2 insertions(+) diff --git a/replays/unittest b/replays/unittest index 2b1cd3e..88046ce 100644 --- a/replays/unittest +++ b/replays/unittest @@ -29,6 +29,8 @@ .1.3.6.1.2.1.1.9.1.4.6 = Timeticks: (2) 0:00:00.02 .1.3.6.1.2.1.1.9.1.4.7 = Timeticks: (2) 0:00:00.02 .1.3.6.1.2.1.1.9.1.4.8 = Timeticks: (2) 0:00:00.02 +.1.3.6.1.2.1.15.3.1.7.0.0.0.0 = IpAddress: 0.0.0.0 +.1.3.6.1.2.1.15.3.1.7.10.1.159.251 = IpAddress: 10.1.159.251 .1.3.6.1.4.1.31865.9999.42.2.1 = INTEGER: test(1) .1.3.6.1.4.1.31865.9999.42.2.2 = INTEGER: test(-2) .1.3.6.1.4.1.31865.9999.42.2.4 = INTEGER: 4 From 5fa568ba8cdb616ab58e8e6523395a70f4503cbb Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Thu, 13 Dec 2018 11:57:42 +1300 Subject: [PATCH 08/13] Use inet_pton as that seems to be standard throughout netsnmp. Also supports IPv6. --- replayd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/replayd.c b/replayd.c index a3cf5c9..ca648e1 100644 --- a/replayd.c +++ b/replayd.c @@ -148,7 +148,7 @@ netsnmp_variable_list *parse_reply(char *name) { case ASN_IPADDRESS: lptr->val.integer = malloc(sizeof(struct in_addr)); - if (inet_aton(value, (struct in_addr *)lptr->val.integer) == 0) { + if (inet_pton(AF_INET, value, (struct in_addr *)lptr->val.integer) != 1){ fprintf(stderr, "Invalid address: %s\n", value); } lptr->val_len = sizeof(struct in_addr); From 39ea16ad94579a3980cf4bb7f84ed33626da1a58 Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Thu, 13 Dec 2018 12:11:59 +1300 Subject: [PATCH 09/13] Fix exposing daemon port on host. --- Dockerfile | 2 +- bootstrap.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 470ac1b..b48084e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,6 @@ RUN make # convinience RUN apt-get install snmp -EXPOSE 1661:1661/udp +EXPOSE 1661/udp CMD [ "./replayd", "-d", "replays", "-v", "-v", "-v" ] diff --git a/bootstrap.sh b/bootstrap.sh index b22deea..0ddd5fa 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,3 +1,3 @@ #!/bin/sh -docker build -t replayd . && docker run -P replayd +docker build -t replayd . && docker run -p 1661:1661/udp replayd From a81d8a7650da309eeb15a572133aa8b3e0fa61da Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Fri, 14 Dec 2018 09:22:58 +1300 Subject: [PATCH 10/13] Follow Docker standards for apt-get lines. --- Dockerfile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b48084e..2e1afcc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,7 @@ FROM debian:stretch # copy the data in -RUN apt-get update -RUN apt-get -y install build-essential autoconf libtool-bin libsnmp-dev +RUN apt-get update && apt-get -y install build-essential autoconf libtool-bin libsnmp-dev && rm -rf /var/lib/apt/lists/* COPY . . From 0ea61d368d18a22701290e992b7da7a163009c2d Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Fri, 14 Dec 2018 09:23:09 +1300 Subject: [PATCH 11/13] Remove unnecessary package. --- Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2e1afcc..04cc8f6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,9 +11,6 @@ RUN ./configure RUN make -# convinience -RUN apt-get install snmp - EXPOSE 1661/udp CMD [ "./replayd", "-d", "replays", "-v", "-v", "-v" ] From cf4460b98aa661f2130779bcc7a0768b04b570ab Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Thu, 29 Oct 2020 22:37:40 +1300 Subject: [PATCH 12/13] Disable output buffering. --- replayd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/replayd.c b/replayd.c index ca648e1..b30aa97 100644 --- a/replayd.c +++ b/replayd.c @@ -240,6 +240,9 @@ int main(int argc, char *argv[]) { struct dirent *dEnt; replay_entry *rEnt; + // disable output buffering + setbuf(stdout, NULL); + // Process options while ((arg = getopt(argc, argv, "vd:L::")) != EOF) { switch (arg) { From 3745b33c13fd1aa0823befcdd3ca4415d95952fb Mon Sep 17 00:00:00 2001 From: Nathan Overall Date: Thu, 29 Oct 2020 23:15:32 +1300 Subject: [PATCH 13/13] Add support for Counter64. --- parse_type.c | 1 + replayd.c | 1 + 2 files changed, 2 insertions(+) diff --git a/parse_type.c b/parse_type.c index 1ec604c..23c0f62 100644 --- a/parse_type.c +++ b/parse_type.c @@ -37,6 +37,7 @@ type_atoi type_map[] = { {"Timeticks", ASN_TIMETICKS}, {"Gauge32", ASN_GAUGE}, {"Counter32", ASN_COUNTER}, + {"Counter64", ASN_COUNTER64}, {"IpAddress", ASN_IPADDRESS}, {"NULL", ASN_NULL}, {NULL, 0}, // Array end marker diff --git a/replayd.c b/replayd.c index b30aa97..7f6b818 100644 --- a/replayd.c +++ b/replayd.c @@ -106,6 +106,7 @@ netsnmp_variable_list *parse_reply(char *name) { case ASN_TIMETICKS: case ASN_GAUGE: case ASN_COUNTER: + case ASN_COUNTER64: lptr->val.integer = malloc(sizeof(long)); if (strchr(value, (int)'(')) { value = strchr(value, (int)'(');