summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Graf <tgr@plip.localdomain>2008-08-20 12:01:50 +0200
committerThomas Graf <tgr@plip.localdomain>2008-08-20 12:01:50 +0200
commit562c5323af89b4386eabf90aaf47bb67dca0fb6e (patch)
tree2817ecf39a42bf4d2e5685c86d4477297232e83e
parent7211a835258a3c8ce1b7f98bbddd89d5b972158a (diff)
downloadlibnl-562c5323af89b4386eabf90aaf47bb67dca0fb6e.tar.gz
test updates
-rw-r--r--tests/Makefile2
-rw-r--r--tests/test-cache-mngr.c59
-rw-r--r--tests/test-genl.c58
-rw-r--r--tests/test-nf-cache-mngr.c10
4 files changed, 47 insertions, 82 deletions
diff --git a/tests/Makefile b/tests/Makefile
index b5cec34..168eeeb 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -23,7 +23,7 @@ $(TOOLS): ../src/utils.o
test-%: test-%.c
@echo " LD $@"; \
- $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
+ $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) -lnl-genl
clean:
@echo " CLEAN src"; \
diff --git a/tests/test-cache-mngr.c b/tests/test-cache-mngr.c
index 9a3da2d..777bce8 100644
--- a/tests/test-cache-mngr.c
+++ b/tests/test-cache-mngr.c
@@ -7,7 +7,7 @@ static void change_cb(struct nl_cache *cache, struct nl_object *obj,
int action)
{
struct nl_dump_params dp = {
- .dp_type = NL_DUMP_BRIEF,
+ .dp_type = NL_DUMP_LINE,
.dp_fd = stdout,
};
@@ -30,55 +30,42 @@ int main(int argc, char *argv[])
{
struct nl_cache_mngr *mngr;
struct nl_cache *lc, *nc, *ac, *rc;
- struct nl_handle *handle;
+ struct nl_sock *sock;
+ int err;
signal(SIGINT, sigint);
- nltool_init(argc, argv);
+ sock = nlt_alloc_socket();
+ err = nl_cache_mngr_alloc(sock, NETLINK_ROUTE, NL_AUTO_PROVIDE, &mngr);
+ if (err < 0)
+ fatal(err, "Unable to allocate cache manager: %s",
+ nl_geterror(err));
- handle = nltool_alloc_handle();
+ if ((err = nl_cache_mngr_add(mngr, "route/link", &change_cb, &lc)) < 0)
+ fatal(err, "Unable to add cache route/link: %s",
+ nl_geterror(err));
- mngr = nl_cache_mngr_alloc(handle, NETLINK_ROUTE, NL_AUTO_PROVIDE);
- if (!mngr) {
- nl_perror("nl_cache_mngr_alloc");
- return -1;
- }
-
- lc = nl_cache_mngr_add(mngr, "route/link", &change_cb);
- if (lc == NULL) {
- nl_perror("nl_cache_mngr_add(route/link");
- return -1;
- }
+ if ((err = nl_cache_mngr_add(mngr, "route/neigh", &change_cb, &nc)) < 0)
+ fatal(err, "Unable to add cache route/neigh: %s",
+ nl_geterror(err));
- nc = nl_cache_mngr_add(mngr, "route/neigh", &change_cb);
- if (nc == NULL) {
- nl_perror("nl_cache_mngr_add(route/neigh");
- return -1;
- }
+ if ((err = nl_cache_mngr_add(mngr, "route/addr", &change_cb, &ac)) < 0)
+ fatal(err, "Unable to add cache route/addr: %s",
+ nl_geterror(err));
- ac = nl_cache_mngr_add(mngr, "route/addr", &change_cb);
- if (ac == NULL) {
- nl_perror("nl_cache_mngr_add(route/addr");
- return -1;
- }
-
- rc = nl_cache_mngr_add(mngr, "route/route", &change_cb);
- if (rc == NULL) {
- nl_perror("nl_cache_mngr_add(route/route");
- return -1;
- }
+ if ((err = nl_cache_mngr_add(mngr, "route/route", &change_cb, &rc)) < 0)
+ fatal(err, "Unable to add cache route/route: %s",
+ nl_geterror(err));
while (!quit) {
int err = nl_cache_mngr_poll(mngr, 5000);
- if (err < 0 && err != -EINTR) {
- nl_perror("nl_cache_mngr_poll()");
- return -1;
- }
+ if (err < 0 && err != -NLE_INTR)
+ fatal(err, "Polling failed: %s", nl_geterror(err));
}
nl_cache_mngr_free(mngr);
- nl_handle_destroy(handle);
+ nl_socket_free(sock);
return 0;
}
diff --git a/tests/test-genl.c b/tests/test-genl.c
index e44b3fb..8bf60c5 100644
--- a/tests/test-genl.c
+++ b/tests/test-genl.c
@@ -2,55 +2,35 @@
int main(int argc, char *argv[])
{
- struct nl_handle *h;
+ struct nl_sock *sock;
struct nl_msg *msg;
void *hdr;
+ int err;
- if (nltool_init(argc, argv) < 0)
- return -1;
-
- h = nltool_alloc_handle();
- if (!h) {
- nl_perror("nl_handle_alloc");
- return -1;
- }
-
- if (genl_connect(h) < 0) {
- nl_perror("genl_connect");
- return -1;
- }
+ sock = nlt_alloc_socket();
+ nlt_connect(sock, NETLINK_GENERIC);
msg = nlmsg_alloc();
- if (msg == NULL) {
- nl_perror("nlmsg_alloc");
- return -1;
- }
+ if (msg == NULL)
+ fatal(NLE_NOMEM, "Unable to allocate netlink message");
hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, GENL_ID_CTRL,
0, 0, CTRL_CMD_GETFAMILY, 1);
- if (hdr == NULL) {
- nl_perror("genlmsg_put");
- return -1;
- }
-
- if (nla_put_u32(msg, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL) < 0) {
- nl_perror("nla_put_u32(CTRL_ATTR_FAMILY_ID)");
- return -1;
- }
-
- if (nl_send_auto_complete(h, msg) < 0) {
- nl_perror("nl_send_auto_complete");
- return -1;
- }
-
- if (nl_recvmsgs_default(h) < 0) {
- nl_perror("nl_recvmsgs_def");
- return -1;
- }
+ if (hdr == NULL)
+ fatal(ENOMEM, "Unable to write genl header");
- nlmsg_free(msg);
+ if ((err = nla_put_u32(msg, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL)) < 0)
+ fatal(err, "Unable to add attribute: %s", nl_geterror(err));
- nl_close(h);
+ if ((err = nl_send_auto_complete(sock, msg)) < 0)
+ fatal(err, "Unable to send message: %s", nl_geterror(err));
+
+ if ((err = nl_recvmsgs_default(sock)) < 0)
+ fatal(err, "Unable to receive message: %s", nl_geterror(err));
+
+ nlmsg_free(msg);
+ nl_close(sock);
+ nl_socket_free(sock);
return 0;
}
diff --git a/tests/test-nf-cache-mngr.c b/tests/test-nf-cache-mngr.c
index 86cbabb..05485bf 100644
--- a/tests/test-nf-cache-mngr.c
+++ b/tests/test-nf-cache-mngr.c
@@ -12,7 +12,7 @@ static void change_cb(struct nl_cache *cache, struct nl_object *obj,
if (!nl_addr_cmp(hack, nfnl_ct_get_src(ct, 1)) ||
!nl_addr_cmp(hack, nfnl_ct_get_dst(ct, 1))) {
struct nl_dump_params dp = {
- .dp_type = NL_DUMP_BRIEF,
+ .dp_type = NL_DUMP_LINE,
.dp_fd = stdout,
};
@@ -24,14 +24,12 @@ static void change_cb(struct nl_cache *cache, struct nl_object *obj,
int main(int argc, char *argv[])
{
struct nl_cache_mngr *mngr;
- struct nl_handle *handle;
+ struct nl_sock *sock;
struct nl_cache *ct;
- nltool_init(argc, argv);
+ sock = nlt_socket_alloc();
- handle = nltool_alloc_handle();
-
- mngr = nl_cache_mngr_alloc(handle, NETLINK_NETFILTER, NL_AUTO_PROVIDE);
+ mngr = nl_cache_mngr_alloc(sock, NETLINK_NETFILTER, NL_AUTO_PROVIDE);
if (!mngr) {
nl_perror("nl_cache_mngr_alloc");
return -1;