libnl3/add-a-test-test-add-route.patch
2021-12-16 22:32:30 +08:00

45 lines
1.3 KiB
Diff

From 92d64e75d74aa7343769f9923d0a9294caa0cadd Mon Sep 17 00:00:00 2001
From: chengyechun <chengyechun1@huawei.com>
Date: Thu, 16 Dec 2021 22:13:04 +0800
Subject: [PATCH] add a test:test add route
---
tests/test-add-route.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
create mode 100644 tests/test-add-route.c
diff --git a/tests/test-add-route.c b/tests/test-add-route.c
new file mode 100644
index 0000000..b93db60
--- /dev/null
+++ b/tests/test-add-route.c
@@ -0,0 +1,25 @@
+#include <netlink/cli/utils.h>
+#include <netlink/cli/route.h>
+#include <netlink/cli/link.h>
+#include <linux/netlink.h>
+
+
+int main(int argc, char *argv[])
+{
+ struct nl_sock *sk;
+ struct rtnl_route *route;
+ struct nl_cache *link_cache, *route_cache;
+ char dst_addr[] = "10.10.10.0/23";
+ char nexthop[] = "dev=eth0, via=10.10.10.10.1";
+ int err;
+ sk = nl_cli_alloc_socket();
+ nl_cli_connect(sk, NETLINK_ROUTE);
+ link_cache = nl_cli_link_alloc_cache(sk);
+ route_cache = nl_cli_route_alloc_cache(sk);
+ route = nl_cli_route_alloc();
+ nl_Cli_route_parse_dst(route, dst_addr);
+ nl_cli_route_parse_nexthop(route, nexthop, link_cache);
+ if ((err = rtnl_route_add(sk, route, NLM_F_EXCL)) < 0)
+ nl_cli_fatal(err, "Unable to add route: %s", nl_geterror(err));
+ return 0;
+}
--
2.23.0