summaryrefslogtreecommitdiff
path: root/tests/test-create-ipgretap.c
diff options
context:
space:
mode:
authorHaishuang Yan <yanhaishuang@cmss.chinamobile.com>2016-04-01 18:18:50 +0800
committerThomas Haller <thaller@redhat.com>2016-04-15 16:18:41 +0200
commiteec318f0260f4f081355e802aaa4844b07557d5b (patch)
tree2b44e74a5096a9bee3ea94ba059bcbf60aee1e2d /tests/test-create-ipgretap.c
parent6b9134b7fd5aa2e29b12de2985ed4e85fa7fc9a4 (diff)
downloadlibnl-eec318f0260f4f081355e802aaa4844b07557d5b.tar.gz
ipgre: add support for gretap tunnel
Since kernel support both gre/gretap tunnel, so add support for gretap appropriately. Signed-off-by: Haishuang Yan <yanhaishuang@cmss.chinamobile.com> Signed-off-by: Thomas Haller <thaller@redhat.com> [thaller@redhat.com: modified original patch to move symbols in libnl-route-3.sym to proper section] http://lists.infradead.org/pipermail/libnl/2016-April/002102.html
Diffstat (limited to 'tests/test-create-ipgretap.c')
-rw-r--r--tests/test-create-ipgretap.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/test-create-ipgretap.c b/tests/test-create-ipgretap.c
new file mode 100644
index 00000000..1fe82313
--- /dev/null
+++ b/tests/test-create-ipgretap.c
@@ -0,0 +1,56 @@
+#include <netlink/route/link/ipgre.h>
+#include <netlink-private/netlink.h>
+
+int main(int argc, char *argv[])
+{
+ struct nl_cache *link_cache;
+ struct rtnl_link *link;
+ struct in_addr addr;
+ struct nl_sock *sk;
+ int err, if_index;
+
+ sk = nl_socket_alloc();
+ if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) {
+ nl_perror(err, "Unable to connect socket");
+ return err;
+ }
+
+ err = rtnl_link_alloc_cache(sk, AF_UNSPEC, &link_cache);
+ if ( err < 0) {
+ nl_perror(err, "Unable to allocate cache");
+ return err;
+ }
+
+ if_index = rtnl_link_name2i(link_cache, "enp0s5");
+ if (!if_index) {
+ fprintf(stderr, "Unable to lookup enp0s5");
+ return -1;
+ }
+
+ link = rtnl_link_ipgretap_alloc();
+ if(!link) {
+ nl_perror(err, "Unable to allocate link");
+ return -1;
+
+ }
+ rtnl_link_set_name(link, "ipgre-tap");
+ rtnl_link_ipgre_set_link(link, if_index);
+
+ inet_pton(AF_INET, "10.211.55.10", &addr.s_addr);
+ rtnl_link_ipgre_set_local(link, addr.s_addr);
+
+ inet_pton(AF_INET, "10.133.6.33", &addr.s_addr);
+ rtnl_link_ipgre_set_remote(link, addr.s_addr);
+
+ rtnl_link_ipgre_set_ttl(link, 64);
+ err = rtnl_link_add(sk, link, NLM_F_CREATE);
+ if (err < 0) {
+ nl_perror(err, "Unable to add link");
+ return err;
+ }
+
+ rtnl_link_put(link);
+ nl_close(sk);
+
+ return 0;
+}