summaryrefslogtreecommitdiff
path: root/tests/test-create-xfrmi.c
diff options
context:
space:
mode:
authorEyal Birger <eyal.birger@gmail.com>2019-04-07 17:09:34 +0300
committerThomas Haller <thaller@redhat.com>2019-09-01 14:24:52 +0200
commitd147019c4bbb856be13042d89e95b859f01c808d (patch)
tree130c345e0b1ae464bcdf45dd7d699828f69613bc /tests/test-create-xfrmi.c
parent4b9370c6c994659360e5b14ef80f6afec75422f8 (diff)
downloadlibnl-d147019c4bbb856be13042d89e95b859f01c808d.tar.gz
xfrmi: introduce XFRM interfaces support
XFRM interfaces were introduced in kernel 4.19. This commit adds link support for these interfaces. Signed-off-by: Eyal Birger <eyal.birger@gmail.com>
Diffstat (limited to 'tests/test-create-xfrmi.c')
-rw-r--r--tests/test-create-xfrmi.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test-create-xfrmi.c b/tests/test-create-xfrmi.c
new file mode 100644
index 00000000..3a01a4ff
--- /dev/null
+++ b/tests/test-create-xfrmi.c
@@ -0,0 +1,49 @@
+#include <netlink/route/link/xfrmi.h>
+#include <netlink-private/netlink.h>
+
+int main(int argc, char *argv[])
+{
+ struct nl_cache *link_cache;
+ struct rtnl_link *link;
+ 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, "eth0");
+ if (!if_index) {
+ fprintf(stderr, "Unable to lookup eth0");
+ return -1;
+ }
+
+ link = rtnl_link_xfrmi_alloc();
+ if (!link) {
+ nl_perror(err, "Unable to allocate link");
+ return -1;
+
+ }
+
+ rtnl_link_set_name(link, "ipsec0");
+ rtnl_link_xfrmi_set_link(link, if_index);
+ rtnl_link_xfrmi_set_if_id(link, 16);
+
+ 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;
+}