summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2011-08-11 14:30:24 +0200
committerThomas Graf <tgraf@suug.ch>2011-08-11 14:30:24 +0200
commitf1c8d5b0a3a1baa87a773feb34866ca51e0989bb (patch)
tree0fa3765ed3d131011c578b08b9f2fef62d9855d7 /tests
parent70c93717607a15d37b60d7caefb58e78d28c5e59 (diff)
downloadlibnl-f1c8d5b0a3a1baa87a773feb34866ca51e0989bb.tar.gz
3.1 release
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile14
-rw-r--r--tests/test-create-bond.c33
-rw-r--r--tests/test-create-vlan.c48
-rw-r--r--tests/test-delete-link.c28
4 files changed, 114 insertions, 9 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 8494eea..d072ddb 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -13,25 +13,21 @@ ifeq ($(shell [ ! -r ../Makefile.opts ] && echo 1),)
include ../Makefile.opts
endif
-LDFLAGS += -L../lib -lnl ../src/utils.o
+LDFLAGS += -L../lib -lnl -lnl-genl -lnl-route
CIN := $(wildcard test-*.c)
-TOOLS := $(CIN:%.c=%)
+TESTS := $(CIN:%.c=%)
-all: $(TOOLS)
-
-$(TOOLS): ../src/utils.o
+all: $(TESTS)
test-%: test-%.c
@echo " LD $@"; \
- $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) -lnl-genl -lnl-route
+ $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
clean:
@echo " CLEAN src"; \
- rm -f $(TOOLS)
+ rm -f $(TESTS)
distclean: clean
install:
@true
-
-include ../Makefile.rules
diff --git a/tests/test-create-bond.c b/tests/test-create-bond.c
new file mode 100644
index 0000000..99166aa
--- /dev/null
+++ b/tests/test-create-bond.c
@@ -0,0 +1,33 @@
+#include <netlink/netlink.h>
+#include <netlink/route/link.h>
+
+int main(int argc, char *argv[])
+{
+ struct rtnl_link *link;
+ struct nl_sock *sk;
+ int err;
+
+ sk = nl_socket_alloc();
+ if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) {
+ nl_perror(err, "Unable to connect socket");
+ return err;
+ }
+
+ link = rtnl_link_alloc();
+ rtnl_link_set_name(link, "my_bond");
+
+ if ((err = rtnl_link_set_info_type(link, "bond")) < 0) {
+ nl_perror(err, "Unable to set link info type");
+ return err;
+ }
+
+ if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) {
+ nl_perror(err, "Unable to add link");
+ return err;
+ }
+
+ rtnl_link_put(link);
+ nl_close(sk);
+
+ return 0;
+}
diff --git a/tests/test-create-vlan.c b/tests/test-create-vlan.c
new file mode 100644
index 0000000..00a4d91
--- /dev/null
+++ b/tests/test-create-vlan.c
@@ -0,0 +1,48 @@
+#include <netlink/netlink.h>
+#include <netlink/route/link.h>
+#include <netlink/route/link/vlan.h>
+
+int main(int argc, char *argv[])
+{
+ struct rtnl_link *link;
+ struct nl_cache *link_cache;
+ struct nl_sock *sk;
+ int err, master_index;
+
+ sk = nl_socket_alloc();
+ if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) {
+ nl_perror(err, "Unable to connect socket");
+ return err;
+ }
+
+ if ((err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache)) < 0) {
+ nl_perror(err, "Unable to allocate cache");
+ return err;
+ }
+
+ if (!(master_index = rtnl_link_name2i(link_cache, "eth0"))) {
+ fprintf(stderr, "Unable to lookup eth0");
+ return -1;
+ }
+
+ link = rtnl_link_alloc();
+
+ rtnl_link_set_link(link, master_index);
+
+ if ((err = rtnl_link_set_type(link, "vlan")) < 0) {
+ nl_perror(err, "Unable to set link info type");
+ return err;
+ }
+
+ rtnl_link_vlan_set_id(link, 10);
+
+ if ((err = rtnl_link_add(sk, link, NLM_F_CREATE)) < 0) {
+ nl_perror(err, "Unable to add link");
+ return err;
+ }
+
+ rtnl_link_put(link);
+ nl_close(sk);
+
+ return 0;
+}
diff --git a/tests/test-delete-link.c b/tests/test-delete-link.c
new file mode 100644
index 0000000..9cf1034
--- /dev/null
+++ b/tests/test-delete-link.c
@@ -0,0 +1,28 @@
+#include <netlink/netlink.h>
+#include <netlink/route/link.h>
+
+int main(int argc, char *argv[])
+{
+ struct rtnl_link *link;
+ struct nl_sock *sk;
+ int err;
+
+ sk = nl_socket_alloc();
+ if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) {
+ nl_perror(err, "Unable to connect socket");
+ return err;
+ }
+
+ link = rtnl_link_alloc();
+ rtnl_link_set_name(link, "my_bond");
+
+ if ((err = rtnl_link_delete(sk, link)) < 0) {
+ nl_perror(err, "Unable to delete link");
+ return err;
+ }
+
+ rtnl_link_put(link);
+ nl_close(sk);
+
+ return 0;
+}