diff options
author | Haishuang Yan <yanhaishuang@cmss.chinamobile.com> | 2016-04-01 10:18:50 (GMT) |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-04-15 14:18:41 (GMT) |
commit | eec318f0260f4f081355e802aaa4844b07557d5b (patch) | |
tree | 2b44e74a5096a9bee3ea94ba059bcbf60aee1e2d /tests | |
parent | 6b9134b7fd5aa2e29b12de2985ed4e85fa7fc9a4 (diff) | |
download | libnl-eec318f0260f4f081355e802aaa4844b07557d5b.zip libnl-eec318f0260f4f081355e802aaa4844b07557d5b.tar.gz libnl-eec318f0260f4f081355e802aaa4844b07557d5b.tar.bz2 |
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')
-rw-r--r-- | tests/.gitignore | 1 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/test-create-ipgretap.c | 56 |
3 files changed, 58 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore index d11450b..9666f27 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -10,6 +10,7 @@ /test-create-ifb /test-create-ip6tnl /test-create-ipgre +/test-create-ipgretap /test-create-ipip /test-create-ipvlan /test-create-ipvti diff --git a/tests/Makefile.am b/tests/Makefile.am index e764635..5cf43e9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -32,6 +32,7 @@ check_PROGRAMS = \ test-create-bridge \ test-create-ip6tnl \ test-create-ipgre \ + test-create-ipgretap \ test-create-ipip \ test-create-ipvti \ test-create-macvlan \ diff --git a/tests/test-create-ipgretap.c b/tests/test-create-ipgretap.c new file mode 100644 index 0000000..1fe8231 --- /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; +} |