aboutsummaryrefslogtreecommitdiff
path: root/tests/sys/netgraph/util.c
diff options
context:
space:
mode:
authorLutz Donnerhacke <donner@FreeBSD.org>2021-06-05 22:37:22 +0000
committerLutz Donnerhacke <donner@FreeBSD.org>2021-06-08 10:49:04 +0000
commit09307dbfb888a98232096c751a96ecb3344aa77c (patch)
treef7eecba549e38359414624dea58944f287aeb153 /tests/sys/netgraph/util.c
parentf102b61d0ecffc6d9cc322fa7a48e0927391421b (diff)
downloadsrc-09307dbfb888a98232096c751a96ecb3344aa77c.tar.gz
src-09307dbfb888a98232096c751a96ecb3344aa77c.zip
tests/netgraph: Allow receiving answers to messages
Add msg_handler in order to receive messages from netgraph nodes to be tested. Reviewed by: kp MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D30657
Diffstat (limited to 'tests/sys/netgraph/util.c')
-rw-r--r--tests/sys/netgraph/util.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/tests/sys/netgraph/util.c b/tests/sys/netgraph/util.c
index 37d005393e91..450a176971a7 100644
--- a/tests/sys/netgraph/util.c
+++ b/tests/sys/netgraph/util.c
@@ -34,7 +34,6 @@
#include <atf-c.h>
#include <errno.h>
#include <stdlib.h>
-#include <stdio.h>
#include <string.h>
#include <sys/select.h>
@@ -59,9 +58,10 @@ struct data_handler {
SLIST_ENTRY(data_handler) next;
};
static SLIST_HEAD(, data_handler) data_head = SLIST_HEAD_INITIALIZER(data_head);
+static ng_msg_handler_t msg_handler = NULL;
static void handle_data(void *ctx);
-static void handle_msg(void);
+static void handle_msg(void *ctx);
void
ng_connect(char const *path1, char const *hook1,
@@ -143,14 +143,21 @@ ng_send_data(char const *hook,
CHECK(, -1 != NgSendData(ds, hook, data, len));
}
+void
+ng_register_msg(ng_msg_handler_t proc) {
+ msg_handler = proc;
+}
+
static void
-handle_msg(void) {
+handle_msg(void *ctx) {
struct ng_mesg *m;
char path[NG_PATHSIZ];
ATF_REQUIRE(-1 != NgAllocRecvMsg(cs, &m, path));
- printf("Got message from %s\n", path);
+ if(msg_handler != NULL)
+ (*msg_handler)(path, m, ctx);
+
free(m);
}
@@ -191,7 +198,7 @@ retry:
return 0;
default: /* something to do */
if (FD_ISSET(cs, &fds))
- handle_msg();
+ handle_msg(context);
if (FD_ISSET(ds, &fds))
handle_data(context);
return 1;