!29 add a test:test add route

Merge pull request !29 from pojunxing/master
This commit is contained in:
openeuler-ci-bot 2021-12-18 03:16:36 +00:00 committed by Gitee
commit 6207488533
2 changed files with 52 additions and 1 deletions

View File

@ -0,0 +1,44 @@
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

View File

@ -1,6 +1,6 @@
Name: libnl3
Version: 3.5.0
Release: 4
Release: 5
Summary: Providing APIs to netlink protocol based Linux kernel interfaces
License: LGPLv2
URL: http://www.infradead.org/~tgr/libnl/
@ -13,6 +13,7 @@ Patch6003: backport-route-link-Check-for-null-pointer-in-macvlan.patch
Patch6004: backport-rtnl-link-fix-leaking-rtnl_link_af_ops-in-link_msg_parser.patch
Patch6005: backport-rtnl-route-fix-NLE_NOMEM-handling-in-parse_multipath.patch
Patch9000: solve-redefinition-of-struct-ipv6_mreq.patch
Patch9001: add-a-test-test-add-route.patch
BuildRequires: flex bison libtool autoconf automake swig
Requires: %{name} = %{version}-%{release}
@ -97,6 +98,12 @@ cd python
%{python3_sitearch}/netlink-*.egg-info
%changelog
* Thu Dec 16 2021 chengyechun <chengyechun1@huawei.com> - 3.5.0-5
- Type:bugfix
- ID:NA
- SUG:NA
- DES:add a test:test add route
* Wed Mar 10 2021 zengwefeng <zwfeng@huawei.com> - 3.5.0-4
- Type:bugfix
- ID:NA