Compare commits
10 Commits
46ec537afa
...
65b59cbe33
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
65b59cbe33 | ||
|
|
979b22012a | ||
|
|
c5c442d95d | ||
|
|
8730c0aa69 | ||
|
|
c33045b9b6 | ||
|
|
68a2cd5a41 | ||
|
|
6d6d75f3f4 | ||
|
|
9b8250a873 | ||
|
|
85cb15fe9a | ||
|
|
daccafc74c |
@ -1,44 +0,0 @@
|
||||
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
|
||||
|
||||
@ -1,533 +0,0 @@
|
||||
From f595a06ee2e7048b02bbdd4d69a9dd160f1819ef Mon Sep 17 00:00:00 2001
|
||||
From: chengyechun <chengyechun1@huawei.com>
|
||||
Date: Sat, 18 Dec 2021 22:03:11 +0800
|
||||
Subject: [PATCH] add some tests
|
||||
|
||||
---
|
||||
test-add-rule.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++
|
||||
test-addr-add.c | 23 ++++++++++++++++++++
|
||||
test-addr-delete.c | 23 ++++++++++++++++++++
|
||||
test-class-add.c | 40 +++++++++++++++++++++++++++++++++++
|
||||
test-class-delete.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
test-genl-connect.c | 29 ++++++++++++++++++++++++++
|
||||
test-link.c | 50 ++++++++++++++++++++++++++++++++++++++++++++
|
||||
test-neigh-add.c | 26 +++++++++++++++++++++++
|
||||
test-neigh-delete.c | 26 +++++++++++++++++++++++
|
||||
test-qdisc-add.c | 35 +++++++++++++++++++++++++++++++
|
||||
test-qdisc-delete.c | 35 +++++++++++++++++++++++++++++++
|
||||
test-route-delete.c | 25 ++++++++++++++++++++++
|
||||
13 files changed, 434 insertions(+), 1 deletion(-)
|
||||
create mode 100644 test-add-rule.c
|
||||
create mode 100644 test-addr-add.c
|
||||
create mode 100644 test-addr-delete.c
|
||||
create mode 100644 test-class-add.c
|
||||
create mode 100644 test-class-delete.c
|
||||
create mode 100644 test-genl-connect.c
|
||||
create mode 100644 test-link.c
|
||||
create mode 100644 test-neigh-add.c
|
||||
create mode 100644 test-neigh-delete.c
|
||||
create mode 100644 test-qdisc-add.c
|
||||
create mode 100644 test-qdisc-delete.c
|
||||
create mode 100644 test-route-delete.c
|
||||
|
||||
diff --git a/test-add-rule.c b/test-add-rule.c
|
||||
new file mode 100644
|
||||
index 0000000..f18a520
|
||||
--- /dev/null
|
||||
+++ b/test-add-rule.c
|
||||
@@ -0,0 +1,54 @@
|
||||
+#include <netlink/route/rule.h>
|
||||
+#include <netlink/netlink.h>
|
||||
+#include <linux/netlink.h>
|
||||
+
|
||||
+
|
||||
+#define IPv6
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sk;
|
||||
+ struct rtnl_rule *rule;
|
||||
+ struct nl_addr *src, *dst;
|
||||
+ char baddr[4] = { 0x1, 0x2, 0x3, 0x4 };
|
||||
+ char baddr2[6] = { 0x1, 0x2, 0x3, 0x4, 0x5, 0x6 };
|
||||
+ int err;
|
||||
+
|
||||
+ src = nl_addr_build(AF_UNSPEC, baddr, 4);
|
||||
+ dst = nl_addr_build(AF_UNSPEC, baddr2, 6);
|
||||
+
|
||||
+ sk = nl_socket_alloc();
|
||||
+ if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) {
|
||||
+ nl_perror(err, "Unable to connect socket");
|
||||
+ return err;
|
||||
+ }
|
||||
+ rule = rtnl_rule_alloc();
|
||||
+ rtnl_rule_set_family(rule, AF_INET);
|
||||
+ rtnl_rule_set_prio(rule, 12);
|
||||
+ rtnl_rule_set_mark(rule, 12);
|
||||
+ rtnl_rule_set_mask(rule, 16);
|
||||
+ rtnl_rule_set_table(rule, 254);
|
||||
+ rtnl_rule_set_dsfield(rule, 4);
|
||||
+ rtnl_rule_set_src(rule, src);
|
||||
+ rtnl_rule_set_dst(rule, dst);
|
||||
+ rtnl_rule_set_iif(rule, "enp2s2");
|
||||
+ rtnl_rule_set_oif(rule, "enp2s7")
|
||||
+ rtnl_rule_set_action(rule, 2);
|
||||
+ rtnl_rule_set_l3mdev(rule, 1);
|
||||
+ rtnl_rule_set_protocol(rule, 4);
|
||||
+ rtnl_rule_get_family(rule);
|
||||
+ rtnl_rule_get_prio(rule);
|
||||
+ rtnl_rule_get_mark(rule);
|
||||
+ rtnl_rule_get_mask(rule);
|
||||
+ rtnl_rule_get_table(rule);
|
||||
+ rtnl_rule_get_dsfield(rule);
|
||||
+ rtnl_rule_get_src(rule);
|
||||
+ rtnl_rule_get_dst(rule);
|
||||
+ rtnl_rule_get_iif(rule);
|
||||
+ rtnl_rule_get_oif(rule)
|
||||
+ rtnl_rule_get_action(rule);
|
||||
+ rtnl_rule_get_l3mdev(rule);
|
||||
+ rtnl_rule_get_protocol(rule);
|
||||
+ rtnl_rule_add(sk, rule, 4);
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/test-addr-add.c b/test-addr-add.c
|
||||
new file mode 100644
|
||||
index 0000000..e7a8483
|
||||
--- /dev/null
|
||||
+++ b/test-addr-add.c
|
||||
@@ -0,0 +1,23 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/addr.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <linux/netlink.h>
|
||||
+
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sock;
|
||||
+ struct rtnl_addr *addr;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ int err, nlflags = NLM_F_CREATE;
|
||||
+ sock = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sock, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sock);
|
||||
+ addr = nl_cli_addr_alloc();
|
||||
+ nl_cli_addr_parse_local(addr, "10.10.16.2");
|
||||
+ nl_cli_addr_parse_dev(addr, link_cache, "eth0");
|
||||
+ nl_cli_addr_parse_family(addr, "AF_INET");
|
||||
+ if ((err = rtnl_addr_add(sock, addr, nlflags)) < 0)
|
||||
+ nl_cli_fatal(err, "Unable to add address: %s", nl_geterror(err));
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/test-addr-delete.c b/test-addr-delete.c
|
||||
new file mode 100644
|
||||
index 0000000..e1e392b
|
||||
--- /dev/null
|
||||
+++ b/test-addr-delete.c
|
||||
@@ -0,0 +1,23 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/addr.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <linux/netlink.h>
|
||||
+
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sock;
|
||||
+ struct rtnl_addr *addr;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ int err, nlflags = NLM_F_CREATE;
|
||||
+ sock = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sock, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sock);
|
||||
+ addr = nl_cli_addr_alloc();
|
||||
+ nl_cli_addr_parse_local(addr, "10.10.16.2");
|
||||
+ nl_cli_addr_parse_dev(addr, link_cache, "eth0");
|
||||
+ nl_cli_addr_parse_family(addr, "AF_INET");
|
||||
+ if ((err = rtnl_addr_delete(sock, addr, nlflags)) < 0)
|
||||
+ nl_cli_fatal(err, "Unable to delete address: %s", nl_geterror(err));
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/test-class-add.c b/test-class-add.c
|
||||
new file mode 100644
|
||||
index 0000000..3ab3449
|
||||
--- /dev/null
|
||||
+++ b/test-class-add.c
|
||||
@@ -0,0 +1,40 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/tc.h>
|
||||
+#include <netlink/cli/qdisc.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <netlink-private/route/tc-api.h>
|
||||
+#include <linux/netlink.h>
|
||||
+
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sk;
|
||||
+ struct rtnl_class *class;
|
||||
+ struct rtnl_tc *tc;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ struct nl_cli_tc_module *tm;
|
||||
+ struct rtnl_tc_ops *ops;
|
||||
+ int err, flags = NLM_C_CREATE | NLM_F_EXCL;
|
||||
+ char kind[] = "htb";
|
||||
+ char *rate[] = {"--rate=100mbit"};
|
||||
+ sk = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ class = nl_cli_class_alloc();
|
||||
+ tc = (struct rtnl_tc *) class;
|
||||
+ nl_cli_tc_prase_dev(tc, link_cache, "eth0");
|
||||
+ nl_cli_tc_parse_parent(tc, "root");
|
||||
+ if (!rtnl_tc_get_ifindex(tc))
|
||||
+ nl_cli_fatal(EINVAL, "You must specify a network device XXX");
|
||||
+ if (!rtnl_tc_get_parent(tc))
|
||||
+ nl_cli_fatal(EINVAL, "You must specify a parent XXX");
|
||||
+ rtnl_tc_set_kind(tc, kind);
|
||||
+ if (!(ops = rtnl_tc_get_ops(tc)))
|
||||
+ nl_cli_fatal(ENOENT, "Unknown class %s", kind);
|
||||
+ if (!(tm = nl_cli_tc_lookup(ops)))
|
||||
+ nl_cli_fatal(ENOTSUP, "class type %s not supported", kind);
|
||||
+ tm->tm_parse_argv(tc, 1, rate);
|
||||
+ if ((err = rtnl_class_add(sk, class, flags)) < 0)
|
||||
+ nl_cli_fatal(EINVAL, "Unable to add class: %s", nl_geterror(err));
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/test-class-delete.c b/test-class-delete.c
|
||||
new file mode 100644
|
||||
index 0000000..0443b96
|
||||
--- /dev/null
|
||||
+++ b/test-class-delete.c
|
||||
@@ -0,0 +1,60 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/tc.h>
|
||||
+#include <netlink/cli/qdisc.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <netlink-private/route/tc-api.h>
|
||||
+#include <linux/netlink.h>
|
||||
+
|
||||
+
|
||||
+static int quiet = 0, default_yes = 0, deleted = 0, interactive = 0;
|
||||
+static struct nl_sock *sock;
|
||||
+
|
||||
+
|
||||
+static void delete_cb(struct nl_object *obj, void *arg)
|
||||
+{
|
||||
+ struct rtnl_class *class = nl_object_priv(obj);
|
||||
+ struct nl_dump_params params = {
|
||||
+ .dp_type = NL_DUMP_LIVE,
|
||||
+ .pd_fd = stdout,
|
||||
+ };
|
||||
+ int err;
|
||||
+ if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes));
|
||||
+ return;
|
||||
+ if ((err = rtnl_class_delete(sock, class)) < 0)
|
||||
+ nl_cli_fatal(err, "Unable to delete class :%s\n", nl_geterror(err));
|
||||
+ if (!quiet){
|
||||
+ printf("deleted\n");
|
||||
+ nl_object_dump(obj, ¶ms);
|
||||
+ };
|
||||
+ deleted++;
|
||||
+}
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sk;
|
||||
+ struct rtnl_class *class;
|
||||
+ struct rtnl_tc *tc;
|
||||
+ struct nl_cache *link_cache, class_cache;
|
||||
+ struct rtnl_tc_ops *ops;
|
||||
+ struct nl_cli_tc_module *tm;
|
||||
+ char kind[] = "htb";
|
||||
+ sk = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ class = nl_cli_class_alloc();
|
||||
+ tc = (struct rtnl_tc *) class;
|
||||
+ nl_cli_tc_prase_dev(tc, link_cache, "eth0");
|
||||
+ nl_cli_tc_parse_parent(tc, "root");
|
||||
+ if (!rtnl_tc_get_ifindex(tc))
|
||||
+ nl_cli_fatal(EINVAL, "You must specify a network device XXX");
|
||||
+ if (!rtnl_tc_get_parent(tc))
|
||||
+ nl_cli_fatal(EINVAL, "You must specify a parent XXX");
|
||||
+ rtnl_tc_set_kind(tc, kind);
|
||||
+ if (!(ops = rtnl_tc_get_ops(tc)))
|
||||
+ nl_cli_fatal(ENOENT, "Unknown class %s", kind);
|
||||
+ if (!(tm = nl_cli_tc_lookup(ops)))
|
||||
+ nl_cli_fatal(ENOTSUP, "class type %s not supported", kind);
|
||||
+ class_cache = nl_cli_class_alloc(sk, rtnl_tc_get_ifindex(tc));
|
||||
+ nl_cache_foreach_filter(class_cache, OBJ_CAST(class), delete_b, NULL);
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/test-genl-connect.c b/test-genl-connect.c
|
||||
new file mode 100644
|
||||
index 0000000..f1d9690
|
||||
--- /dev/null
|
||||
+++ b/test-genl-connect.c
|
||||
@@ -0,0 +1,29 @@
|
||||
+#include <linux/genetlink.h>
|
||||
+#include <netlink/socket.h>
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <stdio.h>
|
||||
+
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sk;
|
||||
+ struct nl_cache *family_cache;
|
||||
+ struct nl_dump_params params = {
|
||||
+ .dp_type = NL_DUMP_LINE,
|
||||
+ .dp_fd = stdout,
|
||||
+ };
|
||||
+ int err;
|
||||
+
|
||||
+ sk = nl_socket_alloc();
|
||||
+ if ((err = genl_connect(sk)) < 0)
|
||||
+ printf("Unable create socket: %s", nl_geterror(err));
|
||||
+ nl_socket_enable_auto_ack(sk);
|
||||
+ nl_socket_disable_auto_ack(sk);
|
||||
+ nl_socket_set_buffer_size(sk, 2000, 2000);
|
||||
+ nl_socket_get_fd(sk);
|
||||
+ if ((err = nl_socket_add_membership(sk, 3456)) < 0)
|
||||
+ printf("Unable join group 3456 %s", nl_geterror(err));
|
||||
+ family_cache = nl_cli_alloc_cache(sk, "generic netlink family", genl_ctrl_alloc_cache);
|
||||
+ nl_cache_dump(family_cache, ¶ms);
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/test-link.c b/test-link.c
|
||||
new file mode 100644
|
||||
index 0000000..87af00f
|
||||
--- /dev/null
|
||||
+++ b/test-link.c
|
||||
@@ -0,0 +1,50 @@
|
||||
+#include <netlink/socket.h>
|
||||
+#include <netlink/netlink.h>
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <netlink/route/link.h>
|
||||
+#include <unistd.h>
|
||||
+
|
||||
+static int self_def_cb = NL_CB_DEBUG
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sk;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ struct rtnl_link *link;
|
||||
+ struct nl_addr *addr;
|
||||
+ struct nl_cb *cb;
|
||||
+ int err, ifindex, pid;
|
||||
+ char *buf;
|
||||
+ cb = nl_cb_alloc(self_def_cb);
|
||||
+ if (!(sk = nl_socket_alloc_cb(cb)))
|
||||
+ nl_cli_fatal(ENOBUFS, "Unable to allocate netlink socket");
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ nl_socket_disable_seq_check(sk);
|
||||
+ nl_socket_disable_auto_ack(sk);
|
||||
+ pid = getpid();
|
||||
+ nl_socket_set_local_port(sk, pid);
|
||||
+ nl_join_groups(sk, pid);
|
||||
+ nl_socket_drop_membership(sk, pid);
|
||||
+ nl_socket_set_peer_port(sk, 0);
|
||||
+ if (err = nl_socket_get_peer_port(sk))
|
||||
+ printf("peer_port:%d", err);
|
||||
+ if (err = nl_socket_use_seq(sk))
|
||||
+ printf("sk->s_seq_next:%d", err);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ link = nl_cli_link_alloc();
|
||||
+ if ((ifindex = rntl_link_get_ifindex(link)) == 0){
|
||||
+ printf("ifindex is not set, %d", ifindex);
|
||||
+ rtnl_link_set_ifindex(link, 1);
|
||||
+ };
|
||||
+ if (rtnl_link_get(link_cache, 1)){
|
||||
+ printf("now, link is cached");
|
||||
+ }else{
|
||||
+ nl_cache_add(link_cache, (struct nl_object *)link);
|
||||
+ };
|
||||
+ rtnl_link_add(sk, link, AF_INET);
|
||||
+ addr = rtnl_link_get_addr(link);
|
||||
+ rtnl_link_get_type(link);
|
||||
+ rtnl_link_put(link);
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/test-neigh-add.c b/test-neigh-add.c
|
||||
new file mode 100644
|
||||
index 0000000..185edb4
|
||||
--- /dev/null
|
||||
+++ b/test-neigh-add.c
|
||||
@@ -0,0 +1,26 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/neigh.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <linux/netlink.h>
|
||||
+
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sk;
|
||||
+ struct rtnl_neigh *neigh;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ int err, 0k = 0, nlflags = NLM_F_REPLACE | NLM_F_CREATE;
|
||||
+ char dst_addr[] = "10.0.0.1";
|
||||
+ char dev[] = "eth0";
|
||||
+ char lladdr[] = "AA:BB:CC:DD:EE:FF";
|
||||
+ sk = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ neigh = nl_cli_neigh_alloc();
|
||||
+ nl_cli_neigh_parse_dst(neigh, dst_addr);
|
||||
+ nl_cli_neigh_parse_lladdr(neigh, lladdr);
|
||||
+ nl_cli_neigh_parse_dev(neigh, link_cache, dev);
|
||||
+ if ((err = rtnl_neigh_add(sk, neigh, nlflags)) < 0)
|
||||
+ nl_cli_fatal(err, "Unable to add neighbour: %s", nl_geterror(rrr));
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/test-neigh-delete.c b/test-neigh-delete.c
|
||||
new file mode 100644
|
||||
index 0000000..e4eeb4e
|
||||
--- /dev/null
|
||||
+++ b/test-neigh-delete.c
|
||||
@@ -0,0 +1,26 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/neigh.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <linux/netlink.h>
|
||||
+
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sk;
|
||||
+ struct rtnl_neigh *neigh;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ int err, 0k = 0, nlflags = NLM_F_REPLACE | NLM_F_CREATE;
|
||||
+ char dst_addr[] = "10.0.0.1";
|
||||
+ char dev[] = "eth0";
|
||||
+ char lladdr[] = "AA:BB:CC:DD:EE:FF";
|
||||
+ sk = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ neigh = nl_cli_neigh_alloc();
|
||||
+ nl_cli_neigh_parse_dst(neigh, dst_addr);
|
||||
+ nl_cli_neigh_parse_lladdr(neigh, lladdr);
|
||||
+ nl_cli_neigh_parse_dev(neigh, link_cache, dev);
|
||||
+ if ((err = rtnl_neigh_delete(sk, neigh, nlflags)) < 0)
|
||||
+ nl_cli_fatal(err, "Unable to add neighbour: %s", nl_geterror(rrr));
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/test-qdisc-add.c b/test-qdisc-add.c
|
||||
new file mode 100644
|
||||
index 0000000..2e48ef5
|
||||
--- /dev/null
|
||||
+++ b/test-qdisc-add.c
|
||||
@@ -0,0 +1,35 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/tc.h>
|
||||
+#include <netlink/cli/qdisc.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <netlink-private/route/tc-api.h>
|
||||
+#include <linux/netlink.h>
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nlk_sock *sk;
|
||||
+ struct rtnl_qdisc *qdisc;
|
||||
+ struct rtnl_tc *tc;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ int err, flags = NLM_F_CREATE | NLM_F_EXCL;
|
||||
+ struct nl_cli_tc_module *tm;
|
||||
+ struct rtnl_tc_ops *ops;
|
||||
+ char kind[] = "htb";
|
||||
+ sk = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ qdisc = nl_cli_qdisc_alloc();
|
||||
+ tc = (struct rtnl_tc *) qdisc;
|
||||
+ nl_cli_tc_parse_dev(tc, link_cache, "eth0");
|
||||
+ nl_cli_tc_parse_parent(tc, "root");
|
||||
+ rtnl_tc_get_ifindex(tc);
|
||||
+ rtnl_tc_get_handle(tc);
|
||||
+ rtnl_tc_set_kind(tc, kind);
|
||||
+ if (!(ops = rtnl_tc_get_ops(tc)))
|
||||
+ nl_cli_fatal(ENOENT, "Unknown qdisc %s", kind);
|
||||
+ if (!(tm - nl_cli_tc_lookup(ops)))
|
||||
+ nl_cli_fatal(ENOTSUP, "qdisc type %s not supported", kind);
|
||||
+ if ((err = rtnl_qdisc_add(sk, qdisc, flags)) < 0)
|
||||
+ nl_cli_fatal(EINVAL, "Unable to add qdisc %s", nl_geterror(err));
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/test-qdisc-delete.c b/test-qdisc-delete.c
|
||||
new file mode 100644
|
||||
index 0000000..ab170e1
|
||||
--- /dev/null
|
||||
+++ b/test-qdisc-delete.c
|
||||
@@ -0,0 +1,35 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/tc.h>
|
||||
+#include <netlink/cli/qdisc.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <netlink-private/route/tc-api.h>
|
||||
+#include <linux/netlink.h>
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nlk_sock *sk;
|
||||
+ struct rtnl_qdisc *qdisc;
|
||||
+ struct rtnl_tc *tc;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ int err, flags = NLM_F_CREATE | NLM_F_EXCL;
|
||||
+ struct nl_cli_tc_module *tm;
|
||||
+ struct rtnl_tc_ops *ops;
|
||||
+ char kind[] = "htb";
|
||||
+ sk = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ qdisc = nl_cli_qdisc_alloc();
|
||||
+ tc = (struct rtnl_tc *) qdisc;
|
||||
+ nl_cli_tc_parse_dev(tc, link_cache, "eth0");
|
||||
+ nl_cli_tc_parse_parent(tc, "root");
|
||||
+ rtnl_tc_get_ifindex(tc);
|
||||
+ rtnl_tc_get_handle(tc);
|
||||
+ rtnl_tc_set_kind(tc, kind);
|
||||
+ if (!(ops = rtnl_tc_get_ops(tc)))
|
||||
+ nl_cli_fatal(ENOENT, "Unknown qdisc %s", kind);
|
||||
+ if (!(tm - nl_cli_tc_lookup(ops)))
|
||||
+ nl_cli_fatal(ENOTSUP, "qdisc type %s not supported", kind);
|
||||
+ if ((err = rtnl_qdisc_delete(sk, qdisc)) < 0)
|
||||
+ nl_cli_fatal(EINVAL, "Unable to delete qdisc %s", nl_geterror(err));
|
||||
+ return 0;
|
||||
+}
|
||||
diff --git a/test-route-delete.c b/test-route-delete.c
|
||||
new file mode 100644
|
||||
index 0000000..a3b76c2
|
||||
--- /dev/null
|
||||
+++ b/test-route-delete.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;
|
||||
+ char dst_addr[] = "10.10.16.0/23";
|
||||
+ char nexthop[] = "dev=eth0,via=10.10.16.1";
|
||||
+ int err;
|
||||
+
|
||||
+ sk = nl_cli_allco_socket();
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ link_cahce = nl_cli_link_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_delete(sk, route, NLM_F_EXCL)) < 0)
|
||||
+ nl_cli_fatal(err, "Unable to add route: %s", nl_geterror(err));
|
||||
+ return 0;
|
||||
+}
|
||||
--
|
||||
1.8.3.1
|
||||
|
||||
@ -0,0 +1,38 @@
|
||||
From 6af26981e727149e2e3fdfac85e2ef86b3828b11 Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Wed, 26 Jul 2023 16:17:18 +0200
|
||||
Subject: [PATCH] lib: accept NULL argument in nla_nest_cancel() for robustness
|
||||
|
||||
Previously, a NULL argument would most likely also do thing, but it also
|
||||
hits undefined behavior.
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/6af26981e727149e2e3fdfac85e2ef86b3828b11
|
||||
|
||||
---
|
||||
lib/attr.c | 9 +++++++++
|
||||
1 file changed, 9 insertions(+)
|
||||
|
||||
diff --git a/lib/attr.c b/lib/attr.c
|
||||
index a4f5852..2b2d538 100644
|
||||
--- a/lib/attr.c
|
||||
+++ b/lib/attr.c
|
||||
@@ -996,6 +996,15 @@ void nla_nest_cancel(struct nl_msg *msg, const struct nlattr *attr)
|
||||
{
|
||||
ssize_t len;
|
||||
|
||||
+ if (!attr) {
|
||||
+ /* For robustness, allow a NULL attr to do nothing. NULL is also
|
||||
+ * what nla_nest_start() when out of buffer space.
|
||||
+ *
|
||||
+ * Warning, before libnl-3.8, the function did not accept NULL!
|
||||
+ * If you care, catch NULL yourself. */
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
len = (char *) nlmsg_tail(msg->nm_nlh) - (char *) attr;
|
||||
if (len < 0)
|
||||
BUG();
|
||||
--
|
||||
2.33.0
|
||||
|
||||
609
backport-add-some-tests-about-addr-class-rule-neigh-qdisc.patch
Normal file
609
backport-add-some-tests-about-addr-class-rule-neigh-qdisc.patch
Normal file
@ -0,0 +1,609 @@
|
||||
From 6b39fd0906c4f572b39c538b60790bd6ffe94341 Mon Sep 17 00:00:00 2001
|
||||
From: chengyechun <chengyechun1@huawei.com>
|
||||
Date: Tue, 21 Nov 2023 10:11:00 +0800
|
||||
Subject: [PATCH] backport-add-some-tests-about-addr-class-rule-neigh-qdisc
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://gitee.com/src-openeuler/libnl3/commit/cbf611d151d1ceb63331041e35a5a54184a51eaf/https://gitee.com/src-openeuler/libnl3/commit/501d5c2bec60070e78024bb98917970d207de06b
|
||||
|
||||
---
|
||||
tests/params.h | 5 ++
|
||||
tests/test-add-delete-addr.c | 39 +++++++++
|
||||
tests/test-add-delete-class.c | 142 +++++++++++++++++++++++++++++++
|
||||
tests/test-add-delete-neigh.c | 41 +++++++++
|
||||
tests/test-add-delete-qdisc.c | 156 ++++++++++++++++++++++++++++++++++
|
||||
tests/test-add-delete-route.c | 43 ++++++++++
|
||||
tests/test-genl-connect.c | 37 ++++++++
|
||||
tests/test-link.c | 68 +++++++++++++++
|
||||
8 files changed, 531 insertions(+)
|
||||
create mode 100644 tests/params.h
|
||||
create mode 100644 tests/test-add-delete-addr.c
|
||||
create mode 100644 tests/test-add-delete-class.c
|
||||
create mode 100644 tests/test-add-delete-neigh.c
|
||||
create mode 100644 tests/test-add-delete-qdisc.c
|
||||
create mode 100644 tests/test-add-delete-route.c
|
||||
create mode 100644 tests/test-genl-connect.c
|
||||
create mode 100644 tests/test-link.c
|
||||
|
||||
diff --git a/tests/params.h b/tests/params.h
|
||||
new file mode 100644
|
||||
index 0000000..e3cab17
|
||||
--- /dev/null
|
||||
+++ b/tests/params.h
|
||||
@@ -0,0 +1,5 @@
|
||||
+#define DST_ADDR "addr"
|
||||
+#define IP "ip"
|
||||
+#define NEXTHOP "dev=1,via=2"
|
||||
+#define DEV_NAME "dev_name"
|
||||
+
|
||||
diff --git a/tests/test-add-delete-addr.c b/tests/test-add-delete-addr.c
|
||||
new file mode 100644
|
||||
index 0000000..3fc4c5c
|
||||
--- /dev/null
|
||||
+++ b/tests/test-add-delete-addr.c
|
||||
@@ -0,0 +1,39 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/addr.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <linux/netlink.h>
|
||||
+#include <stdio.h>
|
||||
+#include <params.h>
|
||||
+
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sock;
|
||||
+ struct rtnl_addr *addr;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ int err = 0, nlflags = NLM_F_CREATE;
|
||||
+
|
||||
+ sock = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sock, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sock);
|
||||
+ addr = nl_cli_addr_alloc();
|
||||
+
|
||||
+ nl_cli_addr_parse_local(addr, IP);
|
||||
+ nl_cli_addr_parse_dev(addr, link_cache, DEV_NAME);
|
||||
+
|
||||
+ if ((err = rtnl_addr_add(sock, addr, nlflags)) < 0) {
|
||||
+ printf("Unable to add route: %s", nl_geterror(err));
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+ if ((err = rtnl_addr_delete(sock, addr, nlflags)) < 0) {
|
||||
+ printf("Unable to add route: %s", nl_geterror(err));
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+END:
|
||||
+ rtnl_addr_put(addr);
|
||||
+ nl_cache_put(link_cache);
|
||||
+ nl_socket_free(sock);
|
||||
+ return err;
|
||||
+}
|
||||
diff --git a/tests/test-add-delete-class.c b/tests/test-add-delete-class.c
|
||||
new file mode 100644
|
||||
index 0000000..6ee0e16
|
||||
--- /dev/null
|
||||
+++ b/tests/test-add-delete-class.c
|
||||
@@ -0,0 +1,142 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/tc.h>
|
||||
+#include <netlink/cli/class.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <netlink-private/route/tc-api.h>
|
||||
+#include <linux/netlink.h>
|
||||
+#include <stdio.h>
|
||||
+#include <params.h>
|
||||
+
|
||||
+static int default_yes = 0, deleted = 0, interactive = 0;
|
||||
+static struct nl_sock *sk;
|
||||
+
|
||||
+static int test_add_class()
|
||||
+{
|
||||
+ struct rtnl_class *class;
|
||||
+ struct rtnl_tc *tc;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ struct nl_cli_tc_module *tm;
|
||||
+ struct rtnl_tc_ops *ops;
|
||||
+ int err = 0, flags = NLM_F_CREATE | NLM_F_EXCL;
|
||||
+ char kind[] = "htb";
|
||||
+ char *rate[] = {DEV_NAME, "root", "htb", "--rate=100mbit"};
|
||||
+
|
||||
+ sk = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ class = nl_cli_class_alloc();
|
||||
+ tc = (struct rtnl_tc *) class;
|
||||
+
|
||||
+ nl_cli_tc_parse_dev(tc, link_cache, DEV_NAME);
|
||||
+ nl_cli_tc_parse_parent(tc, "root");
|
||||
+ if (!rtnl_tc_get_ifindex(tc)) {
|
||||
+ printf("You must specify a network device (--dev=XXX)\n");
|
||||
+ err = -1;
|
||||
+ goto END;
|
||||
+ }
|
||||
+ if (!rtnl_tc_get_parent(tc)) {
|
||||
+ printf("You must specify a parent (--parent=XXX)\n");
|
||||
+ err = -1;
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+ rtnl_tc_set_kind(tc, kind);
|
||||
+ if (!(ops = rtnl_tc_get_ops(tc))) {
|
||||
+ printf("Unknown class \"%s\"\n", kind);
|
||||
+ err = -1;
|
||||
+ goto END;
|
||||
+ }
|
||||
+ if (!(tm = nl_cli_tc_lookup(ops))) {
|
||||
+ printf("class type \"%s\" not supported.\n", kind);
|
||||
+ err = -1;
|
||||
+ goto END;
|
||||
+ }
|
||||
+ tm->tm_parse_argv(tc, 4, rate);
|
||||
+
|
||||
+ if ((err = rtnl_class_add(sk, class, flags)) < 0) {
|
||||
+ printf("Unable to add class: %s\n", nl_geterror(err));
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+END:
|
||||
+ nl_cache_mngt_unprovide(link_cache);
|
||||
+ nl_cache_put(link_cache);
|
||||
+ rtnl_class_put(class);
|
||||
+ nl_socket_free(sk);
|
||||
+ return err;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+static void delete_cb(struct nl_object *obj, void *arg)
|
||||
+{
|
||||
+ struct rtnl_class *class = nl_object_priv(obj);
|
||||
+ struct nl_dump_params params = {
|
||||
+ .dp_type = NL_DUMP_LINE,
|
||||
+ .dp_fd = stdout,
|
||||
+ };
|
||||
+ int err;
|
||||
+
|
||||
+ if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
|
||||
+ return;
|
||||
+
|
||||
+ if ((err = rtnl_class_delete(sk, class)) < 0)
|
||||
+ nl_cli_fatal(err, "Unable to delete class: %s\n", nl_geterror(err));
|
||||
+
|
||||
+ deleted++;
|
||||
+}
|
||||
+
|
||||
+static int test_delete_class()
|
||||
+{
|
||||
+ struct rtnl_class *class;
|
||||
+ struct rtnl_tc *tc;
|
||||
+ struct nl_cache *link_cache, *class_cache;
|
||||
+ struct nl_cli_tc_module *tm;
|
||||
+ struct rtnl_tc_ops *ops;
|
||||
+ char kind[] = "htb";
|
||||
+ int err = 0;
|
||||
+
|
||||
+ sk = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ class = nl_cli_class_alloc();
|
||||
+ tc = (struct rtnl_tc *) class;
|
||||
+
|
||||
+ nl_cli_tc_parse_dev(tc, link_cache, DEV_NAME);
|
||||
+ nl_cli_tc_parse_parent(tc, "root");
|
||||
+ if (!rtnl_tc_get_ifindex(tc)) {
|
||||
+ printf("You must specify a network device (--dev=XXX)\n");
|
||||
+ err = -1;
|
||||
+ goto END;
|
||||
+ }
|
||||
+ if (!rtnl_tc_get_parent(tc)) {
|
||||
+ printf("You must specify a parent (--parent=XXX)\n");
|
||||
+ err = -1;
|
||||
+ goto END;
|
||||
+ }
|
||||
+ rtnl_tc_set_kind(tc, kind);
|
||||
+ if (!(ops = rtnl_tc_get_ops(tc))) {
|
||||
+ printf("Unknown class \"%s\"\n", kind);
|
||||
+ err = -1;
|
||||
+ goto END;
|
||||
+ }
|
||||
+ class_cache = nl_cli_class_alloc_cache(sk, rtnl_tc_get_ifindex(tc));
|
||||
+ nl_cache_foreach_filter(class_cache, OBJ_CAST(class), delete_cb, NULL);
|
||||
+
|
||||
+END:
|
||||
+ nl_cache_put(link_cache);
|
||||
+ nl_socket_free(sk);
|
||||
+ rtnl_class_put(class);
|
||||
+ return err;
|
||||
+}
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ int err = 0;
|
||||
+ if ((err = test_add_class()) < 0) {
|
||||
+ printf("Unable to add class\n");
|
||||
+ }
|
||||
+ if ((err = test_delete_class()) < 0) {
|
||||
+ printf("Unable to delete class");
|
||||
+ }
|
||||
+ return err;
|
||||
+}
|
||||
diff --git a/tests/test-add-delete-neigh.c b/tests/test-add-delete-neigh.c
|
||||
new file mode 100644
|
||||
index 0000000..e4bc63a
|
||||
--- /dev/null
|
||||
+++ b/tests/test-add-delete-neigh.c
|
||||
@@ -0,0 +1,41 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/neigh.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <linux/netlink.h>
|
||||
+#include <stdio.h>
|
||||
+#include <params.h>
|
||||
+
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sk;
|
||||
+ struct rtnl_neigh *neigh;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ int err = 0, ok = 0, nlflags = NLM_F_REPLACE | NLM_F_CREATE;
|
||||
+ char lladdr[] = "AA:BB:CC:DD:EE:FF";
|
||||
+
|
||||
+ sk = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ neigh = nl_cli_neigh_alloc();
|
||||
+
|
||||
+ nl_cli_neigh_parse_dst(neigh, DST_ADDR);
|
||||
+ nl_cli_neigh_parse_lladdr(neigh, lladdr);
|
||||
+ nl_cli_neigh_parse_dev(neigh, link_cache, DEV_NAME);
|
||||
+
|
||||
+ if ((err = rtnl_neigh_add(sk, neigh, nlflags)) < 0){
|
||||
+ printf("Unable to add neighbour: %s\n",nl_geterror(err));
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+ if ((err = rtnl_neigh_delete(sk, neigh, nlflags)) < 0){
|
||||
+ printf("Unable to add neighbour: %s\n",nl_geterror(err));
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+END:
|
||||
+ nl_socket_free(sk);
|
||||
+ nl_cache_put(link_cache);
|
||||
+ rtnl_neigh_put(neigh);
|
||||
+ return err;
|
||||
+}
|
||||
diff --git a/tests/test-add-delete-qdisc.c b/tests/test-add-delete-qdisc.c
|
||||
new file mode 100644
|
||||
index 0000000..29502db
|
||||
--- /dev/null
|
||||
+++ b/tests/test-add-delete-qdisc.c
|
||||
@@ -0,0 +1,156 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/tc.h>
|
||||
+#include <netlink/cli/qdisc.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <netlink-private/route/tc-api.h>
|
||||
+#include <linux/netlink.h>
|
||||
+#include <stdio.h>
|
||||
+#include <params.h>
|
||||
+
|
||||
+
|
||||
+static int default_yes = 0, deleted = 0, interactive = 0;
|
||||
+static struct nl_sock *sk;
|
||||
+
|
||||
+static void delete_cb(struct nl_object *obj, void *arg)
|
||||
+{
|
||||
+ struct rtnl_qdisc *qdisc = nl_object_priv(obj);
|
||||
+ struct nl_dump_params params = {
|
||||
+ .dp_type = NL_DUMP_LINE,
|
||||
+ .dp_fd = stdout,
|
||||
+ };
|
||||
+ int err;
|
||||
+
|
||||
+ /* Ignore default qdiscs, unable to delete */
|
||||
+ if (rtnl_tc_get_handle((struct rtnl_tc *) qdisc) == 0)
|
||||
+ return;
|
||||
+
|
||||
+ if (interactive && !nl_cli_confirm(obj, ¶ms, default_yes))
|
||||
+ return;
|
||||
+
|
||||
+ if ((err = rtnl_qdisc_delete(sk, qdisc)) < 0) {
|
||||
+ nl_cli_fatal(err, "Unable to delete qdisc: %s\n", nl_geterror(err));
|
||||
+ }
|
||||
+ deleted++;
|
||||
+}
|
||||
+
|
||||
+static int test_delete_qdisc()
|
||||
+{
|
||||
+ struct rtnl_qdisc *qdisc;
|
||||
+ struct rtnl_tc *tc;
|
||||
+ struct nl_cache *link_cache, *qdisc_cache;
|
||||
+ struct nl_cli_tc_module *tm;
|
||||
+ struct rtnl_tc_ops *ops;
|
||||
+ char kind[] = "htb";
|
||||
+ int err = 0;
|
||||
+
|
||||
+ sk = nl_cli_alloc_socket();
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ qdisc_cache = nl_cli_qdisc_alloc_cache(sk);
|
||||
+ qdisc = nl_cli_qdisc_alloc();
|
||||
+ tc = (struct rtnl_tc *) qdisc;
|
||||
+ nl_cli_tc_parse_dev(tc, link_cache, DEV_NAME);
|
||||
+ nl_cli_tc_parse_parent(tc, "root");
|
||||
+
|
||||
+ if (!rtnl_tc_get_ifindex(tc)) {
|
||||
+ printf("You must specify a network device (--dev=XXX)");
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+ if (!rtnl_tc_get_parent(tc)) {
|
||||
+ printf("You must specify a parent");
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+ rtnl_tc_set_kind(tc, kind);
|
||||
+ if (!(ops = rtnl_tc_get_ops(tc))) {
|
||||
+ printf("Unknown qdisc \"%s\"", kind);
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+ if (!(tm = nl_cli_tc_lookup(ops))) {
|
||||
+ nl_cli_fatal(ENOTSUP, "Qdisc type \"%s\" not supported.", kind);
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+
|
||||
+ nl_cache_foreach_filter(qdisc_cache, OBJ_CAST(qdisc), delete_cb, NULL);
|
||||
+
|
||||
+END:
|
||||
+ nl_cache_put(link_cache);
|
||||
+ nl_cache_put(qdisc_cache);
|
||||
+ rtnl_qdisc_put(qdisc);
|
||||
+ nl_socket_free(sk);
|
||||
+ return err;
|
||||
+}
|
||||
+
|
||||
+static int test_add_qdisc()
|
||||
+{
|
||||
+ struct rtnl_qdisc *qdisc;
|
||||
+ struct rtnl_tc *tc;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ struct nl_cli_tc_module *tm;
|
||||
+ struct rtnl_tc_ops *ops;
|
||||
+ char kind[] = "htb";
|
||||
+ int err = 0, flags = NLM_F_CREATE | NLM_F_EXCL;
|
||||
+
|
||||
+ if (!(sk = nl_socket_alloc())){
|
||||
+ printf("Unable to allocate netlink socket\n");
|
||||
+ return -1;
|
||||
+ }
|
||||
+ if ((err = nl_connect(sk, NETLINK_ROUTE)) < 0) {
|
||||
+ printf("Unable to connect netlink socket: %s\n", nl_geterror(err));
|
||||
+ nl_socket_free(sk);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ qdisc = nl_cli_qdisc_alloc();
|
||||
+ tc = (struct rtnl_tc *) qdisc;
|
||||
+
|
||||
+ nl_cli_tc_parse_dev(tc, link_cache, DEV_NAME);
|
||||
+ nl_cli_tc_parse_parent(tc, "root");
|
||||
+
|
||||
+ if (!rtnl_tc_get_ifindex(tc)){
|
||||
+ printf("You must specify a network device (--dev=XXX)\n");
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+ if (!rtnl_tc_get_parent(tc)){
|
||||
+ printf("You must specify a parent\n");
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+ rtnl_tc_set_kind(tc, kind);
|
||||
+ if (!(ops = rtnl_tc_get_ops(tc))){
|
||||
+ printf("Unknown qdisc \"%s\"\n", kind);
|
||||
+ goto END;
|
||||
+ }
|
||||
+ if (!(tm = nl_cli_tc_lookup(ops))){
|
||||
+ nl_cli_fatal(ENOTSUP, "Qdisc type \"%s\" not supported.\n", kind);
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+ if ((err = rtnl_qdisc_add(sk, qdisc, flags)) < 0){
|
||||
+ printf("Unable to add qdisc: %s\n", nl_geterror(err));
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+END:
|
||||
+ nl_cache_mngt_unprovide(link_cache);
|
||||
+ nl_cache_put(link_cache);
|
||||
+ rtnl_qdisc_put(qdisc);
|
||||
+ nl_socket_free(sk);
|
||||
+ return err;
|
||||
+}
|
||||
+
|
||||
+int main(int args, char *argv[])
|
||||
+{
|
||||
+ int err = 0;
|
||||
+ if ((err = test_add_qdisc()) < 0) {
|
||||
+ printf("Unable to add qdisc:%s", nl_geterror(err));
|
||||
+ }
|
||||
+ if ((err = test_delete_qdisc()) < 0) {
|
||||
+ printf("Unable to delete qdisc:%s", nl_geterror(err));
|
||||
+ }
|
||||
+ return err;
|
||||
+}
|
||||
diff --git a/tests/test-add-delete-route.c b/tests/test-add-delete-route.c
|
||||
new file mode 100644
|
||||
index 0000000..756fb46
|
||||
--- /dev/null
|
||||
+++ b/tests/test-add-delete-route.c
|
||||
@@ -0,0 +1,43 @@
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/route.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <linux/netlink.h>
|
||||
+#include <stdio.h>
|
||||
+#include <params.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[] = DST_ADDR;
|
||||
+ char nexthop[] = NEXTHOP;
|
||||
+ int err = 0;
|
||||
+
|
||||
+ 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, 0);
|
||||
+ 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) {
|
||||
+ printf("Unable to add route: %s", nl_geterror(err));
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+ if ((err = rtnl_route_delete(sk, route, NLM_F_EXCL)) < 0) {
|
||||
+ printf("Unable to delete route: %s", nl_geterror(err));
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+END:
|
||||
+ rtnl_route_put(route);
|
||||
+ nl_cache_put(link_cache);
|
||||
+ nl_cache_put(route_cache);
|
||||
+ nl_socket_free(sk);
|
||||
+ return err;
|
||||
+}
|
||||
diff --git a/tests/test-genl-connect.c b/tests/test-genl-connect.c
|
||||
new file mode 100644
|
||||
index 0000000..9522e1f
|
||||
--- /dev/null
|
||||
+++ b/tests/test-genl-connect.c
|
||||
@@ -0,0 +1,37 @@
|
||||
+#include <linux/genetlink.h>
|
||||
+#include <netlink/socket.h>
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <stdio.h>
|
||||
+
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sk;
|
||||
+ struct nl_cache *family_cache;
|
||||
+ struct nl_dump_params params = {
|
||||
+ .dp_type = NL_DUMP_LINE,
|
||||
+ .dp_fd = stdout,
|
||||
+ };
|
||||
+ int err = 0;
|
||||
+
|
||||
+ sk = nl_socket_alloc();
|
||||
+ if ((err = genl_connect(sk)) < 0) {
|
||||
+ printf("Unable create socket: %s\n", nl_geterror(err));
|
||||
+ goto END;
|
||||
+ }
|
||||
+ nl_socket_enable_auto_ack(sk);
|
||||
+
|
||||
+ if (nl_socket_get_fd(sk) < 0) {
|
||||
+ printf("vaild socket\n");
|
||||
+ err = -1;
|
||||
+ goto END;
|
||||
+ }
|
||||
+ nl_socket_set_buffer_size(sk, 32655, 32655);
|
||||
+ family_cache = nl_cli_alloc_cache(sk, "generic netlink family", genl_ctrl_alloc_cache);
|
||||
+ nl_cache_dump(family_cache, ¶ms);
|
||||
+
|
||||
+END:
|
||||
+ nl_socket_free(sk);
|
||||
+ nl_cache_put(family_cache);
|
||||
+ return err;
|
||||
+}
|
||||
diff --git a/tests/test-link.c b/tests/test-link.c
|
||||
new file mode 100644
|
||||
index 0000000..e5c415e
|
||||
--- /dev/null
|
||||
+++ b/tests/test-link.c
|
||||
@@ -0,0 +1,68 @@
|
||||
+#include <netlink/socket.h>
|
||||
+#include <netlink/netlink.h>
|
||||
+#include <netlink/cli/utils.h>
|
||||
+#include <netlink/cli/link.h>
|
||||
+#include <netlink/route/link.h>
|
||||
+#include <unistd.h>
|
||||
+
|
||||
+
|
||||
+static int self_def_cb = NL_CB_DEBUG;
|
||||
+
|
||||
+
|
||||
+int main(int argc, char *argv[])
|
||||
+{
|
||||
+ struct nl_sock *sk;
|
||||
+ struct nl_cache *link_cache;
|
||||
+ struct rtnl_link *link;
|
||||
+ struct nl_addr *addr;
|
||||
+ struct nl_cb *cb;
|
||||
+ int err = 0, ifindex, pid;
|
||||
+ char *buf;
|
||||
+
|
||||
+ cb = nl_cb_alloc(self_def_cb);
|
||||
+ pid = getpid();
|
||||
+
|
||||
+ if (!(sk = nl_socket_alloc_cb(cb))) {
|
||||
+ nl_cli_fatal(ENOBUFS, "Unable to allocate netlink socket\n");
|
||||
+ }
|
||||
+ nl_cli_connect(sk, NETLINK_ROUTE);
|
||||
+ nl_socket_disable_seq_check(sk);
|
||||
+ nl_socket_disable_auto_ack(sk);
|
||||
+ nl_socket_set_local_port(sk, pid);
|
||||
+ nl_join_groups(sk, pid);
|
||||
+ nl_socket_drop_membership(sk, pid);
|
||||
+ nl_socket_set_peer_port(sk, 0);
|
||||
+
|
||||
+ link_cache = nl_cli_link_alloc_cache(sk);
|
||||
+ link = nl_cli_link_alloc();
|
||||
+
|
||||
+ if (err = nl_socket_get_peer_port(sk)){
|
||||
+ printf("peer_port %d\n", err);
|
||||
+ goto END;
|
||||
+ }
|
||||
+ if (err = nl_socket_use_seq(sk))
|
||||
+ printf("sk->s_seq_next %d\n", err);
|
||||
+
|
||||
+ if ((ifindex = rtnl_link_get_ifindex(link)) == 0){
|
||||
+ printf("ifindex is not set, %d\n", ifindex);
|
||||
+ rtnl_link_set_ifindex(link, 1);
|
||||
+ };
|
||||
+
|
||||
+ if (rtnl_link_get(link_cache, 1)){
|
||||
+ printf("now link is cached\n");
|
||||
+ }else{
|
||||
+ nl_cache_add(link_cache, (struct nl_object *)link);
|
||||
+ };
|
||||
+
|
||||
+ if ((err = rtnl_link_add(sk, link, AF_INET)) < 0){
|
||||
+ printf("Unable to add link %s\n", nl_geterror(err));
|
||||
+ goto END;
|
||||
+ }
|
||||
+
|
||||
+END:
|
||||
+ nl_cb_put(cb);
|
||||
+ nl_socket_free(sk);
|
||||
+ nl_cache_put(link_cache);
|
||||
+ rtnl_link_put(link);
|
||||
+ return err;
|
||||
+}
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,46 @@
|
||||
From acd05d6e8066f775474cbcf00b85b4743efe896e Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Mon, 4 Dec 2023 12:13:40 +0100
|
||||
Subject: [PATCH] route/tc: avoid integer overflow in rtnl_tc_calc_cell_log()
|
||||
|
||||
Coverity doesn't like this. Workaround.
|
||||
|
||||
Error: CPPCHECK_WARNING (CWE-190): [#def97]
|
||||
libnl-3.8.0/lib/route/tc.c:681: error[integerOverflow]: Signed integer overflow for expression '1<<i'.
|
||||
# 679|
|
||||
# 680| for (i = 0; i < 32; i++)
|
||||
# 681|-> if ((1 << i) == cell_size)
|
||||
# 682| return i;
|
||||
# 683|
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/acd05d6e8066f775474cbcf00b85b4743efe896e
|
||||
|
||||
---
|
||||
lib/route/tc.c | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/lib/route/tc.c b/lib/route/tc.c
|
||||
index a06a478..764b7f7 100644
|
||||
--- a/lib/route/tc.c
|
||||
+++ b/lib/route/tc.c
|
||||
@@ -666,14 +666,14 @@ int rtnl_tc_calc_bufsize(int txtime, int rate)
|
||||
/**
|
||||
* Calculate the binary logarithm for a specific cell size
|
||||
* @arg cell_size Size of cell, must be a power of two.
|
||||
- * @return Binary logirhtm of cell size or a negative error code.
|
||||
+ * @return Binary logarithm of cell size or a negative error code.
|
||||
*/
|
||||
int rtnl_tc_calc_cell_log(int cell_size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 32; i++)
|
||||
- if ((1 << i) == cell_size)
|
||||
+ if ((((uint32_t)1u) << i) == cell_size)
|
||||
return i;
|
||||
|
||||
return -NLE_INVAL;
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
From 664f8f1bea7f3c46bdfcd637e694e2c3c627fa7b Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Egerer <thomas.egerer@secunet.com>
|
||||
Date: Tue, 17 Oct 2023 11:10:26 +0000
|
||||
Subject: [PATCH] xfrm: clear XFRM_SP_ATTR_TMPL when removing the last template
|
||||
from a policy
|
||||
|
||||
Leaving XFRM_SP_ATTR_TMPL active in the mask may not impose a problem
|
||||
but, when removing the last template from a policy, the value signifying
|
||||
attached templates should be cleared.
|
||||
|
||||
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/664f8f1bea7f3c46bdfcd637e694e2c3c627fa7b
|
||||
|
||||
---
|
||||
lib/xfrm/sp.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/lib/xfrm/sp.c b/lib/xfrm/sp.c
|
||||
index 30f9182..ab7cf89 100644
|
||||
--- a/lib/xfrm/sp.c
|
||||
+++ b/lib/xfrm/sp.c
|
||||
@@ -1317,6 +1317,8 @@ void xfrmnl_sp_remove_usertemplate(struct xfrmnl_sp *sp, struct xfrmnl_user_tmpl
|
||||
if (sp->ce_mask & XFRM_SP_ATTR_TMPL) {
|
||||
sp->nr_user_tmpl--;
|
||||
nl_list_del(&utmpl->utmpl_list);
|
||||
+ if (sp->nr_user_tmpl == 0)
|
||||
+ sp->ce_mask &= ~XFRM_SP_ATTR_TMPL;
|
||||
}
|
||||
}
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
||||
39
backport-do-not-use-static-array-indices-for-buffer.patch
Normal file
39
backport-do-not-use-static-array-indices-for-buffer.patch
Normal file
@ -0,0 +1,39 @@
|
||||
From 65ab16f23b553ba09b168a961a0b77de341f470d Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Fri, 1 Dec 2023 17:11:07 +0100
|
||||
Subject: [PATCH] base: don't use static array indices for buffer argument of _nl_inet_ntop()
|
||||
|
||||
Seems the static array indices can confuse coverity. I think coverity is wrong
|
||||
here, regardless, change it.
|
||||
|
||||
libnl-3.8.0/include/base/nl-base-utils.h:683: overrun-buffer-arg: Overrunning buffer pointed to by "buf" of 16 bytes by passing it to a function which accesses it at byte offset 45 using argument "(addr_family == 2) ? 16 : 46" (which evaluates to 46).
|
||||
# 681| * and a suitably large buffer, it cannot. Assert for that. */
|
||||
# 682|
|
||||
# 683|-> r = (char *)inet_ntop(addr_family, addr, buf,
|
||||
# 684| (addr_family == AF_INET) ? INET_ADDRSTRLEN :
|
||||
# 685| INET6_ADDRSTRLEN);
|
||||
---
|
||||
|
||||
Conflict:Before libnl3.8 is reconstructed, the _nl_inet_ntop function is in utils.h. Therefore, the incorporated patch is different from the 65ab16f modification file.
|
||||
Reference:https://github.com/thom311/libnl/commit/65ab16f23b553ba09b168a961a0b77de341f470d
|
||||
|
||||
include/netlink-private/utils.h | 3 +--
|
||||
1 file changed, 1 insertion(+), 2 deletions(-)
|
||||
|
||||
diff --git a/include/netlink-private/utils.h b/include/netlink-private/utils.h
|
||||
index 93a04c9..5540144 100644
|
||||
--- a/include/netlink-private/utils.h
|
||||
+++ b/include/netlink-private/utils.h
|
||||
@@ -361,8 +361,7 @@ typedef union {
|
||||
struct in6_addr a6;
|
||||
} _NLIPAddr;
|
||||
|
||||
-static inline char *_nl_inet_ntop(int addr_family, const void *addr,
|
||||
- char buf[static INET_ADDRSTRLEN])
|
||||
+static inline char *_nl_inet_ntop(int addr_family, const void *addr, char *buf)
|
||||
{
|
||||
char *r;
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
||||
66
backport-fix-IPv6-ecmp-route-deleted-nexthop-matching.patch
Normal file
66
backport-fix-IPv6-ecmp-route-deleted-nexthop-matching.patch
Normal file
@ -0,0 +1,66 @@
|
||||
From 2301992be667fa51084b40ac6ad4a4155a09aeb1 Mon Sep 17 00:00:00 2001
|
||||
From: Jonas Gorski <jonas.gorski@bisdn.de>
|
||||
Date: Tue, 30 Apr 2024 14:05:33 +0200
|
||||
Subject: [PATCH] route: fix IPv6 ecmp route deleted nexthop matching
|
||||
|
||||
When the kernel sends a ECMP route update with just the deleted nexthop,
|
||||
the nexthop will have no associated weight, and its flags may indicate
|
||||
that it is dead:
|
||||
|
||||
route_update: RTM_DELROUTE
|
||||
new route:
|
||||
inet6 default table main type unicast <DEAD,>
|
||||
scope global priority 0x400 protocol 0x9
|
||||
nexthop via fe80::b226:28ff:fe62:8841 dev port4 <dead,>
|
||||
old route:
|
||||
inet6 default table main type unicast
|
||||
scope global priority 0x400 protocol 0x9
|
||||
nexthop via fe80::b226:28ff:fe62:8841 dev port4 weight 0 <>
|
||||
nexthop via fe80::fa8e:a1ff:fee0:8344 dev port49 weight 0 <>
|
||||
nexthop via fe80::b226:28ff:fe62:d400 dev port3 weight 0 <>
|
||||
nexthop via fe80::fa8e:a1ff:fee0:8349 dev port54 weight 0 <>
|
||||
|
||||
Since we are comparing the nexthops strictly with all attributes, we can
|
||||
never match the deleted nexthop. This causes libnl to fail to remove the
|
||||
deleted nexthop from the route, and consequently send out a nop-update
|
||||
and a desync of the route in the cache and in the kernel.
|
||||
|
||||
Fix this by ignoring NH_ATTR_FLAGS (0x1) and NH_ATTR_WEIGHT (0x2) when
|
||||
comparing nexthops to properly match the deleted one.
|
||||
|
||||
Fixes: 29b71371e764 ("route cache: Fix handling of ipv6 multipath routes")
|
||||
Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
|
||||
|
||||
https://github.com/thom311/libnl/pull/382
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/2301992be667fa51084b40ac6ad4a4155a09aeb1
|
||||
|
||||
---
|
||||
lib/route/route_obj.c | 10 +++++++++-
|
||||
1 file changed, 9 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/route/route_obj.c b/lib/route/route_obj.c
|
||||
index 9441b77..0ae029d 100644
|
||||
--- a/lib/route/route_obj.c
|
||||
+++ b/lib/route/route_obj.c
|
||||
@@ -547,7 +547,15 @@ static int route_update(struct nl_object *old_obj, struct nl_object *new_obj)
|
||||
*/
|
||||
nl_list_for_each_entry(old_nh, &old_route->rt_nexthops,
|
||||
rtnh_list) {
|
||||
- if (!rtnl_route_nh_compare(old_nh, new_nh, ~0, 0)) {
|
||||
+ /*
|
||||
+ * Since the new route has only one nexthop, it's not
|
||||
+ * an ECMP route and the nexthop won't have a weight.
|
||||
+ * Similarily, the nexthop might have been marked as
|
||||
+ * DEAD in its flags if it was deleted.
|
||||
+ * Therefore ignore NH_ATTR_FLAGS (= 0x1) and
|
||||
+ * NH_ATTR_WEIGHT (= 0x2) while comparing nexthops.
|
||||
+ */
|
||||
+ if (!rtnl_route_nh_compare(old_nh, new_nh, ~0x3, 0)) {
|
||||
|
||||
rtnl_route_remove_nexthop(old_route, old_nh);
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
||||
27
backport-fix-bridge-info-parsing.patch
Normal file
27
backport-fix-bridge-info-parsing.patch
Normal file
@ -0,0 +1,27 @@
|
||||
From 143cee1d381753c3ff01d51b39d7717d5c59bd2 Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thom311@redhat.com>
|
||||
Date: Tue, 25 Jul 2023 02:09:46 AM GMT+0800
|
||||
Subject: [PATCH] fix bridge info parsing
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/143cee1d381753c3ff01d51b39d7717d5c59bd2
|
||||
|
||||
---
|
||||
lib/route/link/bridge.c | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/lib/route/link/bridge.c b/lib/route/link/bridge.c
|
||||
index bd04253..919828f 100644
|
||||
--- a/lib/route/link/bridge.c
|
||||
+++ b/lib/route/link/bridge.c
|
||||
@@ -189,6 +189,7 @@ static int bridge_parse_af_full(struct rtnl_link *link, struct nlattr *attr_full
|
||||
if (nla_type(attr) == IFLA_BRIDGE_MODE) {
|
||||
bd->b_hwmode = nla_get_u16(attr);
|
||||
bd->ce_mask |= BRIDGE_ATTR_HWMODE;
|
||||
+ continue;
|
||||
} else if (nla_type(attr) != IFLA_BRIDGE_VLAN_INFO)
|
||||
continue;
|
||||
|
||||
--
|
||||
2.23.0
|
||||
|
||||
234
backport-fix-crashes-in-case-of-ENOMEM.patch
Normal file
234
backport-fix-crashes-in-case-of-ENOMEM.patch
Normal file
@ -0,0 +1,234 @@
|
||||
From 49c20efaa783449dca424cc50e4ee4b2fc5351cc Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Mon, 27 Nov 2023 21:15:06 +0100
|
||||
Subject: [PATCH] xfrm: fix crashes in case of ENOMEM
|
||||
|
||||
Conflict:The pre-optimization patch 9e7b5c8 is not integrated. As a result, context adaptation occurs.
|
||||
Reference:https://github.com/thom311/libnl/commit/49c20efaa783449dca424cc50e4ee4b2fc5351cc
|
||||
|
||||
---
|
||||
lib/xfrm/ae.c | 11 +++++++--
|
||||
lib/xfrm/sa.c | 64 ++++++++++++++++++++++++++++++++++++++++-----------
|
||||
lib/xfrm/sp.c | 40 +++++++++++++++++++++++++-------
|
||||
3 files changed, 91 insertions(+), 24 deletions(-)
|
||||
|
||||
diff --git a/lib/xfrm/ae.c b/lib/xfrm/ae.c
|
||||
index 69c8e7e..44c43ed 100644
|
||||
--- a/lib/xfrm/ae.c
|
||||
+++ b/lib/xfrm/ae.c
|
||||
@@ -506,11 +506,18 @@ int xfrmnl_ae_parse(struct nlmsghdr *n, struct xfrmnl_ae **result)
|
||||
if (err < 0)
|
||||
goto errout;
|
||||
|
||||
- ae->sa_id.daddr = nl_addr_build(ae_id->sa_id.family, &ae_id->sa_id.daddr, sizeof (ae_id->sa_id.daddr));
|
||||
+ if (!(ae->sa_id.daddr = nl_addr_build(ae_id->sa_id.family, &ae_id->sa_id.daddr,
|
||||
+ sizeof (ae_id->sa_id.daddr)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
ae->sa_id.family= ae_id->sa_id.family;
|
||||
ae->sa_id.spi = ntohl(ae_id->sa_id.spi);
|
||||
ae->sa_id.proto = ae_id->sa_id.proto;
|
||||
- ae->saddr = nl_addr_build(ae_id->sa_id.family, &ae_id->saddr, sizeof (ae_id->saddr));
|
||||
+ if (!(ae->saddr = nl_addr_build(ae_id->sa_id.family, &ae_id->saddr, sizeof (ae_id->saddr)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
ae->reqid = ae_id->reqid;
|
||||
ae->flags = ae_id->flags;
|
||||
ae->ce_mask |= (XFRM_AE_ATTR_DADDR | XFRM_AE_ATTR_FAMILY | XFRM_AE_ATTR_SPI |
|
||||
diff --git a/lib/xfrm/sa.c b/lib/xfrm/sa.c
|
||||
index 90b6335..ea0d333 100644
|
||||
--- a/lib/xfrm/sa.c
|
||||
+++ b/lib/xfrm/sa.c
|
||||
@@ -718,9 +718,15 @@ int xfrmnl_sa_parse(struct nlmsghdr *n, struct xfrmnl_sa **result)
|
||||
goto errout;
|
||||
|
||||
if (sa_info->sel.family == AF_INET)
|
||||
- addr = nl_addr_build (sa_info->sel.family, &sa_info->sel.daddr.a4, sizeof (sa_info->sel.daddr.a4));
|
||||
+ if (!(addr = nl_addr_build (sa_info->sel.family, &sa_info->sel.daddr.a4, sizeof (sa_info->sel.daddr.a4)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
else
|
||||
- addr = nl_addr_build (sa_info->sel.family, &sa_info->sel.daddr.a6, sizeof (sa_info->sel.daddr.a6));
|
||||
+ if (!(addr = nl_addr_build (sa_info->sel.family, &sa_info->sel.daddr.a6, sizeof (sa_info->sel.daddr.a6)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
nl_addr_set_prefixlen (addr, sa_info->sel.prefixlen_d);
|
||||
xfrmnl_sel_set_daddr (sa->sel, addr);
|
||||
/* Drop the reference count from the above set operation */
|
||||
@@ -728,9 +734,15 @@ int xfrmnl_sa_parse(struct nlmsghdr *n, struct xfrmnl_sa **result)
|
||||
xfrmnl_sel_set_prefixlen_d (sa->sel, sa_info->sel.prefixlen_d);
|
||||
|
||||
if (sa_info->sel.family == AF_INET)
|
||||
- addr = nl_addr_build (sa_info->sel.family, &sa_info->sel.saddr.a4, sizeof (sa_info->sel.saddr.a4));
|
||||
+ if (!(addr = nl_addr_build (sa_info->sel.family, &sa_info->sel.saddr.a4, sizeof (sa_info->sel.saddr.a4)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
else
|
||||
- addr = nl_addr_build (sa_info->sel.family, &sa_info->sel.saddr.a6, sizeof (sa_info->sel.saddr.a6));
|
||||
+ if (!(addr = nl_addr_build (sa_info->sel.family, &sa_info->sel.saddr.a6, sizeof (sa_info->sel.saddr.a6)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
nl_addr_set_prefixlen (addr, sa_info->sel.prefixlen_s);
|
||||
xfrmnl_sel_set_saddr (sa->sel, addr);
|
||||
/* Drop the reference count from the above set operation */
|
||||
@@ -748,17 +760,29 @@ int xfrmnl_sa_parse(struct nlmsghdr *n, struct xfrmnl_sa **result)
|
||||
sa->ce_mask |= XFRM_SA_ATTR_SEL;
|
||||
|
||||
if (sa_info->family == AF_INET)
|
||||
- sa->id.daddr = nl_addr_build (sa_info->family, &sa_info->id.daddr.a4, sizeof (sa_info->id.daddr.a4));
|
||||
+ if (!(sa->id.daddr = nl_addr_build (sa_info->family, &sa_info->id.daddr.a4, sizeof (sa_info->id.daddr.a4)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
else
|
||||
- sa->id.daddr = nl_addr_build (sa_info->family, &sa_info->id.daddr.a6, sizeof (sa_info->id.daddr.a6));
|
||||
+ if (!(sa->id.daddr = nl_addr_build (sa_info->family, &sa_info->id.daddr.a6, sizeof (sa_info->id.daddr.a6)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
sa->id.spi = ntohl(sa_info->id.spi);
|
||||
sa->id.proto = sa_info->id.proto;
|
||||
sa->ce_mask |= (XFRM_SA_ATTR_DADDR | XFRM_SA_ATTR_SPI | XFRM_SA_ATTR_PROTO);
|
||||
|
||||
if (sa_info->family == AF_INET)
|
||||
- sa->saddr = nl_addr_build (sa_info->family, &sa_info->saddr.a4, sizeof (sa_info->saddr.a4));
|
||||
+ if (!(sa->saddr = nl_addr_build (sa_info->family, &sa_info->saddr.a4, sizeof (sa_info->saddr.a4)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
else
|
||||
- sa->saddr = nl_addr_build (sa_info->family, &sa_info->saddr.a6, sizeof (sa_info->saddr.a6));
|
||||
+ if (!(sa->saddr = nl_addr_build (sa_info->family, &sa_info->saddr.a6, sizeof (sa_info->saddr.a6)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
sa->ce_mask |= XFRM_SA_ATTR_SADDR;
|
||||
|
||||
sa->lft->soft_byte_limit = sa_info->lft.soft_byte_limit;
|
||||
@@ -866,9 +890,15 @@ int xfrmnl_sa_parse(struct nlmsghdr *n, struct xfrmnl_sa **result)
|
||||
sa->encap->encap_sport = ntohs(encap->encap_sport);
|
||||
sa->encap->encap_dport = ntohs(encap->encap_dport);
|
||||
if (sa_info->family == AF_INET)
|
||||
- sa->encap->encap_oa = nl_addr_build (sa_info->family, &encap->encap_oa.a4, sizeof (encap->encap_oa.a4));
|
||||
+ if (!(sa->encap->encap_oa = nl_addr_build (sa_info->family, &encap->encap_oa.a4, sizeof (encap->encap_oa.a4)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
else
|
||||
- sa->encap->encap_oa = nl_addr_build (sa_info->family, &encap->encap_oa.a6, sizeof (encap->encap_oa.a6));
|
||||
+ if (!(sa->encap->encap_oa = nl_addr_build (sa_info->family, &encap->encap_oa.a6, sizeof (encap->encap_oa.a6)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
sa->ce_mask |= XFRM_SA_ATTR_ENCAP;
|
||||
}
|
||||
|
||||
@@ -880,13 +910,19 @@ int xfrmnl_sa_parse(struct nlmsghdr *n, struct xfrmnl_sa **result)
|
||||
if (tb[XFRMA_COADDR]) {
|
||||
if (sa_info->family == AF_INET)
|
||||
{
|
||||
- sa->coaddr = nl_addr_build(sa_info->family, nla_data(tb[XFRMA_COADDR]),
|
||||
- sizeof (uint32_t));
|
||||
+ if (!(sa->coaddr = nl_addr_build(
|
||||
+ sa_info->family, nla_data(tb[XFRMA_COADDR]), sizeof (uint32_t)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
}
|
||||
else
|
||||
{
|
||||
- sa->coaddr = nl_addr_build(sa_info->family, nla_data(tb[XFRMA_COADDR]),
|
||||
- sizeof (uint32_t) * 4);
|
||||
+ if (!(sa->coaddr = nl_addr_build(
|
||||
+ sa_info->family, nla_data(tb[XFRMA_COADDR]), sizeof (uint32_t) * 4))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
}
|
||||
sa->ce_mask |= XFRM_SA_ATTR_COADDR;
|
||||
}
|
||||
diff --git a/lib/xfrm/sp.c b/lib/xfrm/sp.c
|
||||
index d3d9778..38002da 100644
|
||||
--- a/lib/xfrm/sp.c
|
||||
+++ b/lib/xfrm/sp.c
|
||||
@@ -558,9 +558,15 @@ int xfrmnl_sp_parse(struct nlmsghdr *n, struct xfrmnl_sp **result)
|
||||
}
|
||||
|
||||
if (sp_info->sel.family == AF_INET)
|
||||
- addr = nl_addr_build (sp_info->sel.family, &sp_info->sel.daddr.a4, sizeof (sp_info->sel.daddr.a4));
|
||||
+ if (!(addr = nl_addr_build (sp_info->sel.family, &sp_info->sel.daddr.a4, sizeof (sp_info->sel.daddr.a4)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
else
|
||||
- addr = nl_addr_build (sp_info->sel.family, &sp_info->sel.daddr.a6, sizeof (sp_info->sel.daddr.a6));
|
||||
+ if (!(addr = nl_addr_build (sp_info->sel.family, &sp_info->sel.daddr.a6, sizeof (sp_info->sel.daddr.a6)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
nl_addr_set_prefixlen (addr, sp_info->sel.prefixlen_d);
|
||||
xfrmnl_sel_set_daddr (sp->sel, addr);
|
||||
/* Drop the reference count from the above set operation */
|
||||
@@ -568,9 +574,15 @@ int xfrmnl_sp_parse(struct nlmsghdr *n, struct xfrmnl_sp **result)
|
||||
xfrmnl_sel_set_prefixlen_d (sp->sel, sp_info->sel.prefixlen_d);
|
||||
|
||||
if (sp_info->sel.family == AF_INET)
|
||||
- addr = nl_addr_build (sp_info->sel.family, &sp_info->sel.saddr.a4, sizeof (sp_info->sel.saddr.a4));
|
||||
+ if (!(addr = nl_addr_build (sp_info->sel.family, &sp_info->sel.saddr.a4, sizeof (sp_info->sel.saddr.a4)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
else
|
||||
- addr = nl_addr_build (sp_info->sel.family, &sp_info->sel.saddr.a6, sizeof (sp_info->sel.saddr.a6));
|
||||
+ if (!(addr = nl_addr_build (sp_info->sel.family, &sp_info->sel.saddr.a6, sizeof (sp_info->sel.saddr.a6)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
nl_addr_set_prefixlen (addr, sp_info->sel.prefixlen_s);
|
||||
xfrmnl_sel_set_saddr (sp->sel, addr);
|
||||
/* Drop the reference count from the above set operation */
|
||||
@@ -647,9 +659,15 @@ int xfrmnl_sp_parse(struct nlmsghdr *n, struct xfrmnl_sp **result)
|
||||
}
|
||||
|
||||
if (tmpl->family == AF_INET)
|
||||
- addr = nl_addr_build(tmpl->family, &tmpl->id.daddr.a4, sizeof (tmpl->id.daddr.a4));
|
||||
+ if (!(addr = nl_addr_build(tmpl->family, &tmpl->id.daddr.a4, sizeof (tmpl->id.daddr.a4)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
else
|
||||
- addr = nl_addr_build(tmpl->family, &tmpl->id.daddr.a6, sizeof (tmpl->id.daddr.a6));
|
||||
+ if (!(addr = nl_addr_build(tmpl->family, &tmpl->id.daddr.a6, sizeof (tmpl->id.daddr.a6)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
xfrmnl_user_tmpl_set_daddr (sputmpl, addr);
|
||||
/* Drop the reference count from the above set operation */
|
||||
nl_addr_put(addr);
|
||||
@@ -658,9 +676,15 @@ int xfrmnl_sp_parse(struct nlmsghdr *n, struct xfrmnl_sp **result)
|
||||
xfrmnl_user_tmpl_set_family (sputmpl, tmpl->family);
|
||||
|
||||
if (tmpl->family == AF_INET)
|
||||
- addr = nl_addr_build(tmpl->family, &tmpl->saddr.a4, sizeof (tmpl->saddr.a4));
|
||||
+ if (!(addr = nl_addr_build(tmpl->family, &tmpl->saddr.a4, sizeof (tmpl->saddr.a4)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
else
|
||||
- addr = nl_addr_build(tmpl->family, &tmpl->saddr.a6, sizeof (tmpl->saddr.a6));
|
||||
+ if (!(addr = nl_addr_build(tmpl->family, &tmpl->saddr.a6, sizeof (tmpl->saddr.a6)))) {
|
||||
+ err = -NLE_NOMEM;
|
||||
+ goto errout;
|
||||
+ }
|
||||
xfrmnl_user_tmpl_set_saddr (sputmpl, addr);
|
||||
/* Drop the reference count from the above set operation */
|
||||
nl_addr_put(addr);
|
||||
--
|
||||
2.33.0
|
||||
|
||||
28
backport-fix-error-handling-in-nl_str2ip_protos.patch
Normal file
28
backport-fix-error-handling-in-nl_str2ip_protos.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From 8ee8b05ff59999fd88b8a6faae40e7777ccf8c98 Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Fri, 18 Aug 2023 11:56:58 +0200
|
||||
Subject: [PATCH] lib: fix error handling in nl_str2ip_proto()
|
||||
|
||||
Conflict:Deleted the test case because the check-direct test case does not exist in the current version because it is not integrated into the pre-installation patch bae11ec.
|
||||
Reference:https://github.com/thom311/libnl/commit/8ee8b05ff59999fd88b8a6faae40e7777ccf8c98
|
||||
|
||||
---
|
||||
lib/utils.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/utils.c b/lib/utils.c
|
||||
index 496bf3b..9795b42 100644
|
||||
--- a/lib/utils.c
|
||||
+++ b/lib/utils.c
|
||||
@@ -887,7 +887,7 @@ int nl_str2ip_proto(const char *name)
|
||||
return p->p_proto;
|
||||
|
||||
l = strtoul(name, &end, 0);
|
||||
- if (l == ULONG_MAX || *end != '\0')
|
||||
+ if (name == end || *end != '\0' || l > (unsigned long)INT_MAX)
|
||||
return -NLE_OBJ_NOTFOUND;
|
||||
|
||||
return (int) l;
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
From 7912b4f90668afab9b7cb7054434d341826b8c54 Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Fri, 1 Dec 2023 19:51:41 +0100
|
||||
Subject: [PATCH] route/cls: fix leak in error handling of
|
||||
rtnl_flower_append_action()
|
||||
|
||||
Using rtnl_act_append() correctly is hard.
|
||||
|
||||
Fixes: ef46de143206 ('route/cls: add flower classifier')
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/7912b4f90668afab9b7cb7054434d341826b8c54
|
||||
|
||||
---
|
||||
lib/route/cls/flower.c | 6 +++++-
|
||||
1 file changed, 5 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/route/cls/flower.c b/lib/route/cls/flower.c
|
||||
index 11bd709..65f0ccf 100644
|
||||
--- a/lib/route/cls/flower.c
|
||||
+++ b/lib/route/cls/flower.c
|
||||
@@ -787,6 +787,7 @@ int rtnl_flower_get_ipv4_dst(struct rtnl_cls *cls, in_addr_t *out_addr,
|
||||
int rtnl_flower_append_action(struct rtnl_cls *cls, struct rtnl_act *act)
|
||||
{
|
||||
struct rtnl_flower *f;
|
||||
+ int err;
|
||||
|
||||
if (!act)
|
||||
return 0;
|
||||
@@ -796,8 +797,11 @@ int rtnl_flower_append_action(struct rtnl_cls *cls, struct rtnl_act *act)
|
||||
|
||||
f->cf_mask |= FLOWER_ATTR_ACTION;
|
||||
|
||||
+ if ((err = rtnl_act_append(&f->cf_act, act)) < 0)
|
||||
+ return err;
|
||||
+
|
||||
rtnl_act_get(act);
|
||||
- return rtnl_act_append(&f->cf_act, act);
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
--
|
||||
2.33.0
|
||||
|
||||
60
backport-fix-leaking-usertemplate-in-xfrmnl_sp_parse.patch
Normal file
60
backport-fix-leaking-usertemplate-in-xfrmnl_sp_parse.patch
Normal file
@ -0,0 +1,60 @@
|
||||
From d8a1ff30c4864bd57c2d895ef88df8a2d138a17d Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Mon, 4 Dec 2023 11:36:16 +0100
|
||||
Subject: [PATCH] xfrm: fix leaking usertemplate in xfrmnl_sp_parse()
|
||||
|
||||
Conflict:The libnl-3.8 version is reconstructed. The nl-xfrm.h file is modified based on the _nl-auto.h file. Therefore, the modified files are inconsistent, and context adaptation is required.
|
||||
Reference:https://github.com/thom311/libnl/commit/d8a1ff30c4864bd57c2d895ef88df8a2d138a17d
|
||||
|
||||
---
|
||||
include/netlink-private/nl-auto.h | 7 +++++++
|
||||
lib/xfrm/sp.c | 4 ++--
|
||||
2 files changed, 9 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/include/netlink-private/nl-auto.h b/include/netlink-private/nl-auto.h
|
||||
index 4092782..0ff3791 100644
|
||||
--- a/include/netlink-private/nl-auto.h
|
||||
+++ b/include/netlink-private/nl-auto.h
|
||||
@@ -99,4 +99,11 @@ void nl_socket_free(struct nl_sock *);
|
||||
#define _nl_auto_nl_socket _nl_auto(_nl_auto_nl_socket_fcn)
|
||||
_NL_AUTO_DEFINE_FCN_TYPED0(struct nl_sock *, _nl_auto_nl_socket_fcn, nl_socket_free);
|
||||
|
||||
+struct xfrmnl_user_tmpl;
|
||||
+void xfrmnl_user_tmpl_free(struct xfrmnl_user_tmpl *utmpl);
|
||||
+#define _nl_auto_xfrmnl_user_tmpl _nl_auto(_nl_auto_xfrmnl_user_tmpl_fcn)
|
||||
+_NL_AUTO_DEFINE_FCN_TYPED0(struct xfrmnl_user_tmpl *,
|
||||
+ _nl_auto_xfrmnl_user_tmpl_fcn,
|
||||
+ xfrmnl_user_tmpl_free);
|
||||
+
|
||||
#endif /* NETLINK_NL_AUTO_H_ */
|
||||
diff --git a/lib/xfrm/sp.c b/lib/xfrm/sp.c
|
||||
index d38daef..d3d9778 100644
|
||||
--- a/lib/xfrm/sp.c
|
||||
+++ b/lib/xfrm/sp.c
|
||||
@@ -633,13 +633,13 @@ int xfrmnl_sp_parse(struct nlmsghdr *n, struct xfrmnl_sp **result)
|
||||
|
||||
if (tb[XFRMA_TMPL]) {
|
||||
struct xfrm_user_tmpl* tmpl = nla_data(tb[XFRMA_TMPL]);
|
||||
- struct xfrmnl_user_tmpl* sputmpl;
|
||||
uint32_t i;
|
||||
uint32_t num_tmpls = nla_len(tb[XFRMA_TMPL]) / sizeof (*tmpl);
|
||||
struct nl_addr* addr;
|
||||
|
||||
for (i = 0; (i < num_tmpls) && (tmpl); i ++, tmpl++)
|
||||
{
|
||||
+ _nl_auto_xfrmnl_user_tmpl struct xfrmnl_user_tmpl *sputmpl = NULL;
|
||||
if ((sputmpl = xfrmnl_user_tmpl_alloc ()) == NULL)
|
||||
{
|
||||
err = -NLE_NOMEM;
|
||||
@@ -672,7 +672,7 @@ int xfrmnl_sp_parse(struct nlmsghdr *n, struct xfrmnl_sp **result)
|
||||
xfrmnl_user_tmpl_set_aalgos (sputmpl, tmpl->aalgos);
|
||||
xfrmnl_user_tmpl_set_ealgos (sputmpl, tmpl->ealgos);
|
||||
xfrmnl_user_tmpl_set_calgos (sputmpl, tmpl->calgos);
|
||||
- xfrmnl_sp_add_usertemplate (sp, sputmpl);
|
||||
+ xfrmnl_sp_add_usertemplate (sp, _nl_steal_pointer(&sputmpl));
|
||||
|
||||
sp->ce_mask |= XFRM_SP_ATTR_TMPL;
|
||||
}
|
||||
--
|
||||
2.33.0
|
||||
|
||||
43
backport-fix-new-object-in-callback-v2-on-update-obj.patch
Normal file
43
backport-fix-new-object-in-callback-v2-on-update-obj.patch
Normal file
@ -0,0 +1,43 @@
|
||||
From 3a43faa1aa8e9fb98ae8bc41496ceabc4c0838f1 Mon Sep 17 00:00:00 2001
|
||||
From: Jonas Gorski <jonas.gorski@bisdn.de>
|
||||
Date: Fri, 26 Apr 2024 16:32:21 +0200
|
||||
Subject: [PATCH] cache: fix new object in callback v2 on updated objects
|
||||
|
||||
When calling the callback v2 for objects that were updated, we pass the
|
||||
update ("obj") instead of the updated object ("old") as new.
|
||||
|
||||
Presumably this wasn't intended, so pass the updated object as new.
|
||||
|
||||
This avoids weird updates where the new object is significantly smaller
|
||||
than the old one. E.g. for IPv6 multipath route updates, old would be
|
||||
the full route with all nexthops, while new would be a partial route
|
||||
with only the added/removed nexthop.
|
||||
|
||||
Fixes: 66d032ad443a ("cache_mngr: add include callback v2")
|
||||
Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
|
||||
|
||||
https://github.com/thom311/libnl/pull/381
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/3a43faa1aa8e9fb98ae8bc41496ceabc4c0838f1
|
||||
|
||||
---
|
||||
lib/cache.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/cache.c b/lib/cache.c
|
||||
index eadce57..8e423e5 100644
|
||||
--- a/lib/cache.c
|
||||
+++ b/lib/cache.c
|
||||
@@ -802,7 +802,7 @@ static int cache_include(struct nl_cache *cache, struct nl_object *obj,
|
||||
*/
|
||||
if (nl_object_update(old, obj) == 0) {
|
||||
if (cb_v2) {
|
||||
- cb_v2(cache, clone, obj, diff,
|
||||
+ cb_v2(cache, clone, old, diff,
|
||||
NL_ACT_CHANGE, data);
|
||||
nl_object_put(clone);
|
||||
} else if (cb)
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,67 @@
|
||||
From c4c22d267117900b9582d5c2e934c107419c9603 Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Egerer <thomas.egerer@secunet.com>
|
||||
Date: Mon, 27 Nov 2023 15:58:19 +0100
|
||||
Subject: [PATCH] xfrm/sp: fix reference counters of sa selector/tmpl addresses
|
||||
|
||||
It's a similar issue as in commit 3f4f1dda, when calling
|
||||
xfrmnl_sp_parse, the refcount of the addresses for selectors and
|
||||
templates increases to two, as xfrmnl_sel_set_[s|d]addr and
|
||||
xfrmnl_user_tmpl_set_[s|d]addr add another reference to the address
|
||||
object. As only one of those refs is dropped in sel_destroy or
|
||||
xfrmnl_user_tmpl_free respectively the address objects' refcount
|
||||
will never drop to zero, causing a leak.
|
||||
|
||||
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
|
||||
|
||||
Fixes: 917154470895 ('xfrm: add xfrm support')
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/c4c22d267117900b9582d5c2e934c107419c9603
|
||||
|
||||
---
|
||||
lib/xfrm/sp.c | 8 ++++++++
|
||||
1 file changed, 8 insertions(+)
|
||||
|
||||
diff --git a/lib/xfrm/sp.c b/lib/xfrm/sp.c
|
||||
index ab7cf89..d38daef 100644
|
||||
--- a/lib/xfrm/sp.c
|
||||
+++ b/lib/xfrm/sp.c
|
||||
@@ -563,6 +563,8 @@ int xfrmnl_sp_parse(struct nlmsghdr *n, struct xfrmnl_sp **result)
|
||||
addr = nl_addr_build (sp_info->sel.family, &sp_info->sel.daddr.a6, sizeof (sp_info->sel.daddr.a6));
|
||||
nl_addr_set_prefixlen (addr, sp_info->sel.prefixlen_d);
|
||||
xfrmnl_sel_set_daddr (sp->sel, addr);
|
||||
+ /* Drop the reference count from the above set operation */
|
||||
+ nl_addr_put(addr);
|
||||
xfrmnl_sel_set_prefixlen_d (sp->sel, sp_info->sel.prefixlen_d);
|
||||
|
||||
if (sp_info->sel.family == AF_INET)
|
||||
@@ -571,6 +573,8 @@ int xfrmnl_sp_parse(struct nlmsghdr *n, struct xfrmnl_sp **result)
|
||||
addr = nl_addr_build (sp_info->sel.family, &sp_info->sel.saddr.a6, sizeof (sp_info->sel.saddr.a6));
|
||||
nl_addr_set_prefixlen (addr, sp_info->sel.prefixlen_s);
|
||||
xfrmnl_sel_set_saddr (sp->sel, addr);
|
||||
+ /* Drop the reference count from the above set operation */
|
||||
+ nl_addr_put(addr);
|
||||
xfrmnl_sel_set_prefixlen_s (sp->sel, sp_info->sel.prefixlen_s);
|
||||
|
||||
xfrmnl_sel_set_dport (sp->sel, ntohs (sp_info->sel.dport));
|
||||
@@ -647,6 +651,8 @@ int xfrmnl_sp_parse(struct nlmsghdr *n, struct xfrmnl_sp **result)
|
||||
else
|
||||
addr = nl_addr_build(tmpl->family, &tmpl->id.daddr.a6, sizeof (tmpl->id.daddr.a6));
|
||||
xfrmnl_user_tmpl_set_daddr (sputmpl, addr);
|
||||
+ /* Drop the reference count from the above set operation */
|
||||
+ nl_addr_put(addr);
|
||||
xfrmnl_user_tmpl_set_spi (sputmpl, ntohl(tmpl->id.spi));
|
||||
xfrmnl_user_tmpl_set_proto (sputmpl, tmpl->id.proto);
|
||||
xfrmnl_user_tmpl_set_family (sputmpl, tmpl->family);
|
||||
@@ -656,6 +662,8 @@ int xfrmnl_sp_parse(struct nlmsghdr *n, struct xfrmnl_sp **result)
|
||||
else
|
||||
addr = nl_addr_build(tmpl->family, &tmpl->saddr.a6, sizeof (tmpl->saddr.a6));
|
||||
xfrmnl_user_tmpl_set_saddr (sputmpl, addr);
|
||||
+ /* Drop the reference count from the above set operation */
|
||||
+ nl_addr_put(addr);
|
||||
|
||||
xfrmnl_user_tmpl_set_reqid (sputmpl, tmpl->reqid);
|
||||
xfrmnl_user_tmpl_set_mode (sputmpl, tmpl->mode);
|
||||
--
|
||||
2.33.0
|
||||
|
||||
30
backport-fix-signed-overflow-warning-in-nl_object_diff.patch
Normal file
30
backport-fix-signed-overflow-warning-in-nl_object_diff.patch
Normal file
@ -0,0 +1,30 @@
|
||||
From aea3f9f2d8b6ecf6b69df12ba4e99ca44d6813fb Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Fri, 1 Dec 2023 20:06:36 +0100
|
||||
Subject: [PATCH] lib: fix signed overflow warning in nl_object_diff()
|
||||
|
||||
Coverity warns "Signed integer overflow for expression '1<<31'".
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/aea3f9f2d8b6ecf6b69df12ba4e99ca44d6813fb
|
||||
|
||||
---
|
||||
lib/object.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/object.c b/lib/object.c
|
||||
index bef0b6f..cca4c48 100644
|
||||
--- a/lib/object.c
|
||||
+++ b/lib/object.c
|
||||
@@ -392,7 +392,7 @@ uint32_t nl_object_diff(struct nl_object *a, struct nl_object *b)
|
||||
diff = nl_object_diff64(a, b);
|
||||
|
||||
return (diff & ~((uint64_t) 0xFFFFFFFF))
|
||||
- ? (uint32_t) diff | (1 << 31)
|
||||
+ ? (uint32_t) diff | (((uint32_t ) 1u) << 31)
|
||||
: (uint32_t) diff;
|
||||
}
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
||||
32
backport-fix-ubsan-complaint-about-incorrect.patch
Normal file
32
backport-fix-ubsan-complaint-about-incorrect.patch
Normal file
@ -0,0 +1,32 @@
|
||||
From 46cae1bfc2ee435fed7c73a15d0b6979fe6d43a3 Mon Sep 17 00:00:00 2001
|
||||
From: "Ilya A. Evenbach" <ievenbach@aurora.tech>
|
||||
Date: Mon, 22 Apr 2024 05:39:24 -0700
|
||||
Subject: [PATCH] socket: fix ubsan complaint about incorrect left-shift in
|
||||
generate_local_port()
|
||||
|
||||
n needs to be uint32_t to fit left shift by 22 bits
|
||||
|
||||
https://github.com/thom311/libnl/pull/379
|
||||
Conflict:NA
|
||||
Reference:https:/github.com/thom311/libnl/commit/46cae1bfc2ee435fed7c73a15d0b6979fe6d43a3
|
||||
|
||||
---
|
||||
lib/socket.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/socket.c b/lib/socket.c
|
||||
index 2ca14f6..21a53bd 100644
|
||||
--- a/lib/socket.c
|
||||
+++ b/lib/socket.c
|
||||
@@ -78,7 +78,7 @@ static NL_RW_LOCK(port_map_lock);
|
||||
static uint32_t generate_local_port(void)
|
||||
{
|
||||
int i, j, m;
|
||||
- uint16_t n;
|
||||
+ uint32_t n;
|
||||
static uint16_t idx_state = 0;
|
||||
uint32_t pid = getpid() & 0x3FFFFF;
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
||||
44
backport-handle-negative-and-zero-size-in-nla_memcpy.patch
Normal file
44
backport-handle-negative-and-zero-size-in-nla_memcpy.patch
Normal file
@ -0,0 +1,44 @@
|
||||
From ca34ad524ec7a9f0e24bb5975b178a3e70268f0f Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Fri, 28 Jul 2023 11:24:26 +0200
|
||||
Subject: [PATCH] lib: handle negative and zero size in nla_memcpy()
|
||||
|
||||
a negative count is a bug in the caller. Still, handle it better than
|
||||
just crashing. Maybe we should assert, but it doesn't seem best to
|
||||
assert against user input.
|
||||
|
||||
Also, if count is zero, don't call memcpy(). Calling memcpy() requires
|
||||
that the source and destination pointers are valid, otherwise it's
|
||||
undefined behavior. I think if the caller tells us to copy zero bytes,
|
||||
we should never look at the destination pointer.
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/ca34ad524ec7a9f0e24bb5975b178a3e70268f0f
|
||||
|
||||
---
|
||||
lib/attr.c | 7 +++++--
|
||||
1 file changed, 5 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/lib/attr.c b/lib/attr.c
|
||||
index 2b2d538..23619c7 100644
|
||||
--- a/lib/attr.c
|
||||
+++ b/lib/attr.c
|
||||
@@ -357,10 +357,13 @@ int nla_memcpy(void *dest, const struct nlattr *src, int count)
|
||||
|
||||
if (!src)
|
||||
return 0;
|
||||
-
|
||||
+
|
||||
minlen = min_t(int, count, nla_len(src));
|
||||
- memcpy(dest, nla_data(src), minlen);
|
||||
|
||||
+ if (minlen <= 0)
|
||||
+ return 0;
|
||||
+
|
||||
+ memcpy(dest, nla_data(src), minlen);
|
||||
return minlen;
|
||||
}
|
||||
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,53 @@
|
||||
From 64fad14bc9c5b594f9ffcd1aa0ca7e00042d8350 Mon Sep 17 00:00:00 2001
|
||||
From: Jonas Gorski <jonas.gorski@bisdn.de>
|
||||
Date: Tue, 16 Jul 2024 16:01:27 +0200
|
||||
Subject: [PATCH] link: link_msg_parser(): keep link info instead of release
|
||||
and reacquire
|
||||
|
||||
Calling release_link_info() will call io_free() for rtnl_link::l_info
|
||||
was allocated just a few lines before as a side effect of
|
||||
rtnl_link_set_type().
|
||||
|
||||
Apart from doing needless memory churn, this will also leave the link
|
||||
with l_info set to NULL if the link type does not provide a io_parse()
|
||||
function.
|
||||
|
||||
Assuming the memory leak mentioned in bfee88b8b0a9 ("route: fix memory
|
||||
leak of l_info_ops in link_msg_parser()") was a double reference taken
|
||||
by calling rtnl_link_info_ops_lookup() twice, once via
|
||||
rtnl_link_set_type(), and once directly, replace the lookup() /
|
||||
release() lookup() with a single lookup() and then reuse the populated
|
||||
rtnl_link::l_info_ops pointer.
|
||||
|
||||
Fixes: bfee88b8b0a9 ("route: fix memory leak of l_info_ops in link_msg_parser()")
|
||||
Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
|
||||
|
||||
https://github.com/thom311/libnl/pull/396
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/64fad14bc9c5b594f9ffcd1aa0ca7e00042d8350
|
||||
|
||||
---
|
||||
lib/route/link.c | 6 +-----
|
||||
1 file changed, 1 insertion(+), 5 deletions(-)
|
||||
|
||||
diff --git a/lib/route/link.c b/lib/route/link.c
|
||||
index e3f657b..09635cb 100644
|
||||
--- a/lib/route/link.c
|
||||
+++ b/lib/route/link.c
|
||||
@@ -674,11 +674,7 @@ static int link_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
|
||||
tb[IFLA_PROTINFO] = (struct nlattr *)link->l_af_ops->ao_protinfo_policy;
|
||||
}
|
||||
|
||||
- if (link->l_info_ops)
|
||||
- release_link_info(link);
|
||||
-
|
||||
- ops = rtnl_link_info_ops_lookup(kind);
|
||||
- link->l_info_ops = ops;
|
||||
+ ops = link->l_info_ops;
|
||||
|
||||
if (ops) {
|
||||
if (ops->io_parse &&
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -1,123 +0,0 @@
|
||||
From abb7391f38893af7d6108f97ac8597468f113a41 Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Wed, 15 Apr 2020 12:42:05 +0200
|
||||
Subject: [PATCH] lib: add "include/netlink-private/nl-auto.h" header
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/abb7391f38893af7d6108f97ac8597468f113a41
|
||||
|
||||
---
|
||||
Makefile.am | 1 +
|
||||
include/netlink-private/nl-auto.h | 60 +++++++++++++++++++++++++++++++
|
||||
include/netlink-private/utils.h | 14 ++------
|
||||
3 files changed, 63 insertions(+), 12 deletions(-)
|
||||
create mode 100644 include/netlink-private/nl-auto.h
|
||||
|
||||
diff --git a/Makefile.am b/Makefile.am
|
||||
index b2e87379..085da53f 100644
|
||||
--- a/Makefile.am
|
||||
+++ b/Makefile.am
|
||||
@@ -261,6 +261,7 @@ noinst_HEADERS = \
|
||||
include/netlink-private/cache-api.h \
|
||||
include/netlink-private/genl.h \
|
||||
include/netlink-private/netlink.h \
|
||||
+ include/netlink-private/nl-auto.h \
|
||||
include/netlink-private/object-api.h \
|
||||
include/netlink-private/route/link/api.h \
|
||||
include/netlink-private/route/link/sriov.h \
|
||||
diff --git a/include/netlink-private/nl-auto.h b/include/netlink-private/nl-auto.h
|
||||
new file mode 100644
|
||||
index 00000000..7b923f26
|
||||
--- /dev/null
|
||||
+++ b/include/netlink-private/nl-auto.h
|
||||
@@ -0,0 +1,60 @@
|
||||
+// SPDX-License-Identifier: LGPL-2.1+
|
||||
+
|
||||
+#ifndef NETLINK_NL_AUTO_H_
|
||||
+#define NETLINK_NL_AUTO_H_
|
||||
+
|
||||
+#define _nl_auto(fcn) __attribute__ ((__cleanup__(fcn)))
|
||||
+
|
||||
+#define _NL_AUTO_DEFINE_FCN_VOID0(CastType, name, func) \
|
||||
+static inline void name(void *v) \
|
||||
+{ \
|
||||
+ if (*((CastType *) v)) \
|
||||
+ func(*((CastType *) v)); \
|
||||
+}
|
||||
+
|
||||
+#define _NL_AUTO_DEFINE_FCN_TYPED0(CastType, name, func) \
|
||||
+static inline void name(CastType *v) \
|
||||
+{ \
|
||||
+ if (*v) \
|
||||
+ func(*v); \
|
||||
+}
|
||||
+
|
||||
+#define _nl_auto_free _nl_auto(_nl_auto_free_fcn)
|
||||
+_NL_AUTO_DEFINE_FCN_VOID0(void *, _nl_auto_free_fcn, free)
|
||||
+
|
||||
+struct nl_addr;
|
||||
+void nl_addr_put(struct nl_addr *);
|
||||
+#define _nl_auto_nl_addr _nl_auto(_nl_auto_nl_addr_fcn)
|
||||
+_NL_AUTO_DEFINE_FCN_TYPED0(struct nl_addr *, _nl_auto_nl_addr_fcn, nl_addr_put)
|
||||
+
|
||||
+struct nl_msg;
|
||||
+void nlmsg_free(struct nl_msg *);
|
||||
+#define _nl_auto_nl_msg _nl_auto(_nl_auto_nl_msg_fcn)
|
||||
+_NL_AUTO_DEFINE_FCN_TYPED0(struct nl_msg *, _nl_auto_nl_msg_fcn, nlmsg_free)
|
||||
+
|
||||
+struct rtnl_link;
|
||||
+void rtnl_link_put(struct rtnl_link *);
|
||||
+#define _nl_auto_rtnl_link _nl_auto(_nl_auto_rtnl_link_fcn)
|
||||
+_NL_AUTO_DEFINE_FCN_TYPED0(struct rtnl_link *, _nl_auto_rtnl_link_fcn, rtnl_link_put)
|
||||
+
|
||||
+struct rtnl_route;
|
||||
+void rtnl_route_put(struct rtnl_route *);
|
||||
+#define _nl_auto_rtnl_route _nl_auto(_nl_auto_rtnl_route_fcn)
|
||||
+_NL_AUTO_DEFINE_FCN_TYPED0(struct rtnl_route *, _nl_auto_rtnl_route_fcn, rtnl_route_put)
|
||||
+
|
||||
+struct rtnl_nexthop;
|
||||
+void rtnl_route_nh_free(struct rtnl_nexthop *);
|
||||
+#define _nl_auto_rtnl_nexthop _nl_auto(_nl_auto_rtnl_nexthop_fcn)
|
||||
+_NL_AUTO_DEFINE_FCN_TYPED0(struct rtnl_nexthop *, _nl_auto_rtnl_nexthop_fcn, rtnl_route_nh_free)
|
||||
+
|
||||
+struct nl_cache;
|
||||
+void nl_cache_put(struct nl_cache *);
|
||||
+#define _nl_auto_nl_cache _nl_auto(_nl_auto_nl_cache_fcn)
|
||||
+_NL_AUTO_DEFINE_FCN_TYPED0(struct nl_cache *, _nl_auto_nl_cache_fcn, nl_cache_put)
|
||||
+
|
||||
+struct rtnl_link_af_ops;
|
||||
+void rtnl_link_af_ops_put(struct rtnl_link_af_ops *);
|
||||
+#define _nl_auto_rtnl_link_af_ops _nl_auto(_nl_auto_rtnl_link_af_ops_fcn)
|
||||
+_NL_AUTO_DEFINE_FCN_TYPED0(struct rtnl_link_af_ops *, _nl_auto_rtnl_link_af_ops_fcn, rtnl_link_af_ops_put)
|
||||
+
|
||||
+#endif /* NETLINK_NL_AUTO_H_ */
|
||||
diff --git a/include/netlink-private/utils.h b/include/netlink-private/utils.h
|
||||
index 9c5a3d82..46e77451 100644
|
||||
--- a/include/netlink-private/utils.h
|
||||
+++ b/include/netlink-private/utils.h
|
||||
@@ -85,18 +85,6 @@
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
-#define _NL_AUTO_DEFINE_FCN_VOID0(CastType, name, func) \
|
||||
-static inline void name (void *v) \
|
||||
-{ \
|
||||
- if (*((CastType *) v)) \
|
||||
- func (*((CastType *) v)); \
|
||||
-}
|
||||
-
|
||||
-#define _nl_auto_free _nl_auto(_nl_auto_free_fcn)
|
||||
-_NL_AUTO_DEFINE_FCN_VOID0 (void *, _nl_auto_free_fcn, free)
|
||||
-
|
||||
-/*****************************************************************************/
|
||||
-
|
||||
extern const char *nl_strerror_l(int err);
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -222,4 +210,6 @@ _nl_strncpy(char *dst, const char *src, size_t len)
|
||||
return dst;
|
||||
}
|
||||
|
||||
+#include "nl-auto.h"
|
||||
+
|
||||
#endif
|
||||
@ -1,29 +0,0 @@
|
||||
From f9d0181ceb2fc7c54abf89eff4c6b57e8fe6dd97 Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Fri, 17 Apr 2020 16:31:10 +0200
|
||||
Subject: [PATCH] lib: use proper int type for id attributes in
|
||||
nl_object_identical()
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/f9d0181ceb2fc7c54abf89eff4c6b57e8fe6dd97
|
||||
|
||||
---
|
||||
lib/object.c | 5 +++--
|
||||
1 file changed, 3 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/lib/object.c b/lib/object.c
|
||||
index d15cd152..07a21d22 100644
|
||||
--- a/lib/object.c
|
||||
+++ b/lib/object.c
|
||||
@@ -314,8 +314,9 @@ int nl_object_identical(struct nl_object *a, struct nl_object *b)
|
||||
return 0;
|
||||
|
||||
if (ops->oo_id_attrs_get) {
|
||||
- int req_attrs_a = ops->oo_id_attrs_get(a);
|
||||
- int req_attrs_b = ops->oo_id_attrs_get(b);
|
||||
+ uint32_t req_attrs_a = ops->oo_id_attrs_get(a);
|
||||
+ uint32_t req_attrs_b = ops->oo_id_attrs_get(b);
|
||||
+
|
||||
if (req_attrs_a != req_attrs_b)
|
||||
return 0;
|
||||
req_attrs = req_attrs_a;
|
||||
28
backport-prevent-segfault-in-af_request_type.patch
Normal file
28
backport-prevent-segfault-in-af_request_type.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From 6519a9173f900b364f014a2321a17aa6bf652e6d Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thom311@redhat.com>
|
||||
Date: Tue, 25 Jul 2023 01:38:44 AM GMT+0800
|
||||
Subject: [PATCH] prevent segfault in af_request_type
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/6519a9173f900b364f014a2321a17aa6bf652e6d
|
||||
|
||||
---
|
||||
lib/route/link.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/route/link.c b/lib/route/link.c
|
||||
index df8ea5b..e3f657b 100644
|
||||
--- a/lib/route/link.c
|
||||
+++ b/lib/route/link.c
|
||||
@@ -115,7 +115,7 @@ static int af_request_type(int af_type, struct rtnl_link *changes)
|
||||
struct rtnl_link_af_ops *ops;
|
||||
|
||||
ops = rtnl_link_af_ops_lookup(af_type);
|
||||
- if (ops && ops->ao_override_rtm(changes))
|
||||
+ if (ops && ops->ao_override_rtm && ops->ao_override_rtm(changes))
|
||||
return RTM_SETLINK;
|
||||
|
||||
return RTM_NEWLINK;
|
||||
--
|
||||
2.23.0
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
From 01ea9a6224b77292e8506bf179729aeeaac30398 Mon Sep 17 00:00:00 2001
|
||||
From: Jan Slomski <jan.slomski@westermo.se>
|
||||
Date: Wed, 21 Mar 2018 10:23:57 +0100
|
||||
Subject: [PATCH] route/link: Check for null pointer in macvlan
|
||||
|
||||
In cases where link->l_info is not set, a null-ptr-exception
|
||||
will be invoked.
|
||||
|
||||
https://github.com/thom311/libnl/pull/238
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/01ea9a6224b77292e8506bf179729aeeaac30398
|
||||
Reference:https://github.com/thom311/libnl/commit/9cc38dcaeb55b5729c6c97b47884cebbda72b693
|
||||
---
|
||||
lib/route/link/macvlan.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/lib/route/link/macvlan.c b/lib/route/link/macvlan.c
|
||||
index a23fe6d8..3ccebf45 100644
|
||||
--- a/lib/route/link/macvlan.c
|
||||
+++ b/lib/route/link/macvlan.c
|
||||
@@ -149,6 +149,8 @@ static void macvlan_free(struct rtnl_link *link)
|
||||
uint32_t i;
|
||||
|
||||
mvi = link->l_info;
|
||||
+ if (!mvi)
|
||||
+ return;
|
||||
|
||||
for (i = 0; i < mvi->mvi_maccount; i++)
|
||||
nl_addr_put(mvi->mvi_macaddr[i]);
|
||||
@ -1,66 +0,0 @@
|
||||
From bab9e77c87d3b596e77d669b0a827b50e725bb62 Mon Sep 17 00:00:00 2001
|
||||
From: Ilya Pronin <ipronin@twitter.com>
|
||||
Date: Fri, 3 Apr 2020 20:00:37 -0700
|
||||
Subject: [PATCH] route/link: add RTNL_LINK_REASM_OVERLAPS stat
|
||||
|
||||
The new stat exposes IPSTATS_MIB_REASM_OVERLAPS link stat. However, the
|
||||
original motivation for this change was fixing the issue with missing RX
|
||||
packets link stat.
|
||||
|
||||
The regression was introduced in version 3.5.0 with commit 73c1d047,
|
||||
that added a new enum constant IPSTATS_MIB_REASM_OVERLAPS. Without this
|
||||
patch, IPSTATS_MIB_REASM_OVERLAPS is missing from
|
||||
map_stat_id_from_IPSTATS_MIB_v2 and is mapped by it to 0. This tricks
|
||||
inet6_parse_protinfo() into erroneously overwriting RTNL_LINK_RX_PACKETS
|
||||
stat, which happens to have value 0, when it tries to set
|
||||
IPSTATS_MIB_REASM_OVERLAPS.
|
||||
|
||||
Fixes: 73c1d0479643 ('Sync linux headers to 4.19.66')
|
||||
|
||||
https://github.com/thom311/libnl/pull/235
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/bab9e77c87d3b596e77d669b0a827b50e725bb62
|
||||
|
||||
---
|
||||
include/netlink/route/link.h | 1 +
|
||||
lib/route/link.c | 1 +
|
||||
lib/route/link/inet6.c | 1 +
|
||||
3 files changed, 3 insertions(+)
|
||||
|
||||
diff --git a/include/netlink/route/link.h b/include/netlink/route/link.h
|
||||
index 516d8e16..d0d6d2b5 100644
|
||||
--- a/include/netlink/route/link.h
|
||||
+++ b/include/netlink/route/link.h
|
||||
@@ -93,6 +93,7 @@ typedef enum {
|
||||
RTNL_LINK_IP6_ECT0PKTS, /*!< IPv6 SNMP InECT0Pkts */
|
||||
RTNL_LINK_IP6_CEPKTS, /*!< IPv6 SNMP InCEPkts */
|
||||
RTNL_LINK_RX_NOHANDLER, /*!< Received packets dropped on inactive device */
|
||||
+ RTNL_LINK_REASM_OVERLAPS, /*!< SNMP ReasmOverlaps */
|
||||
__RTNL_LINK_STATS_MAX,
|
||||
} rtnl_link_stat_id_t;
|
||||
|
||||
diff --git a/lib/route/link.c b/lib/route/link.c
|
||||
index 9439fe6d..ed6f4558 100644
|
||||
--- a/lib/route/link.c
|
||||
+++ b/lib/route/link.c
|
||||
@@ -3007,6 +3007,7 @@ static const struct trans_tbl link_stats[] = {
|
||||
__ADD(RTNL_LINK_IP6_ECT0PKTS, Ip6_InECT0Pkts),
|
||||
__ADD(RTNL_LINK_IP6_CEPKTS, Ip6_InCEPkts),
|
||||
__ADD(RTNL_LINK_RX_NOHANDLER, rx_nohandler),
|
||||
+ __ADD(RTNL_LINK_REASM_OVERLAPS, ReasmOverlaps),
|
||||
};
|
||||
|
||||
char *rtnl_link_stat2str(int st, char *buf, size_t len)
|
||||
diff --git a/lib/route/link/inet6.c b/lib/route/link/inet6.c
|
||||
index c977b617..1ad49bf1 100644
|
||||
--- a/lib/route/link/inet6.c
|
||||
+++ b/lib/route/link/inet6.c
|
||||
@@ -135,6 +135,7 @@ static const uint8_t map_stat_id_from_IPSTATS_MIB_v2[__IPSTATS_MIB_MAX] = {
|
||||
[33] = RTNL_LINK_IP6_ECT1PKTS, /* IPSTATS_MIB_ECT1PKTS */
|
||||
[34] = RTNL_LINK_IP6_ECT0PKTS, /* IPSTATS_MIB_ECT0PKTS */
|
||||
[35] = RTNL_LINK_IP6_CEPKTS, /* IPSTATS_MIB_CEPKTS */
|
||||
+ [36] = RTNL_LINK_REASM_OVERLAPS, /* IPSTATS_MIB_REASM_OVERLAPS */
|
||||
};
|
||||
|
||||
static int inet6_parse_protinfo(struct rtnl_link *link, struct nlattr *attr,
|
||||
@ -1,25 +0,0 @@
|
||||
From 2957d8f6c8bf1189545a7b0c1a49c4ccb26984a1 Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Wed, 15 Apr 2020 14:01:09 +0200
|
||||
Subject: [PATCH] rtnl/link: fix leaking rtnl_link_af_ops in link_msg_parser()
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/2957d8f6c8bf1189545a7b0c1a49c4ccb26984a1
|
||||
|
||||
---
|
||||
lib/route/link.c | 2 ++
|
||||
1 file changed, 2 insertions(+)
|
||||
|
||||
diff --git a/lib/route/link.c b/lib/route/link.c
|
||||
index 0ce4b0ab..b73a8c5f 100644
|
||||
--- a/lib/route/link.c
|
||||
+++ b/lib/route/link.c
|
||||
@@ -722,6 +722,8 @@ static int link_msg_parser(struct nl_cache_ops *ops, struct sockaddr_nl *who,
|
||||
int remaining;
|
||||
|
||||
nla_for_each_nested(af_attr, tb[IFLA_AF_SPEC], remaining) {
|
||||
+ _nl_auto_rtnl_link_af_ops struct rtnl_link_af_ops *af_ops = NULL;
|
||||
+
|
||||
af_ops = af_lookup_and_alloc(link, nla_type(af_attr));
|
||||
if (af_ops && af_ops->ao_parse_af) {
|
||||
char *af_data = link->l_af_data[nla_type(af_attr)];
|
||||
@ -1,40 +0,0 @@
|
||||
From fca338b9f453295037f96e8fe9236ebb4763dd25 Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Wed, 15 Apr 2020 13:17:40 +0200
|
||||
Subject: [PATCH] rtnl/route: fix NLE_NOMEM handling in parse_multipath()
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/fca338b9f453295037f96e8fe9236ebb4763dd25
|
||||
|
||||
---
|
||||
lib/route/route_obj.c | 8 ++++++--
|
||||
1 file changed, 6 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/lib/route/route_obj.c b/lib/route/route_obj.c
|
||||
index b5cc4ed4..de56a76b 100644
|
||||
--- a/lib/route/route_obj.c
|
||||
+++ b/lib/route/route_obj.c
|
||||
@@ -1072,8 +1072,10 @@ static int parse_multipath(struct rtnl_route *route, struct nlattr *attr)
|
||||
|
||||
addr = nl_addr_alloc_attr(ntb[RTA_NEWDST],
|
||||
route->rt_family);
|
||||
- if (!addr)
|
||||
+ if (!addr) {
|
||||
+ err = -NLE_NOMEM;
|
||||
goto errout;
|
||||
+ }
|
||||
|
||||
err = rtnl_route_nh_set_newdst(nh, addr);
|
||||
nl_addr_put(addr);
|
||||
@@ -1085,8 +1087,10 @@ static int parse_multipath(struct rtnl_route *route, struct nlattr *attr)
|
||||
struct nl_addr *addr;
|
||||
|
||||
addr = rtnl_route_parse_via(ntb[RTA_VIA]);
|
||||
- if (!addr)
|
||||
+ if (!addr) {
|
||||
+ err = -NLE_NOMEM;
|
||||
goto errout;
|
||||
+ }
|
||||
|
||||
err = rtnl_route_nh_set_via(nh, addr);
|
||||
nl_addr_put(addr);
|
||||
@ -0,0 +1,36 @@
|
||||
From 326882017876bc22f9d16508a44a8ef98a53d220 Mon Sep 17 00:00:00 2001
|
||||
From: Jonas Gorski <jonas.gorski@bisdn.de>
|
||||
Date: Wed, 29 May 2024 09:45:24 +0200
|
||||
Subject: [PATCH] route: treat routes with via nexthops as universe scoped as
|
||||
well
|
||||
|
||||
RTA_VIA is a RTA_GATEWAY with added address family, so we should treat
|
||||
them them equivalent for guessing the scope.
|
||||
|
||||
Signed-off-by: Jonas Gorski <jonas.gorski@bisdn.de>
|
||||
|
||||
https://github.com/thom311/libnl/pull/389
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/326882017876bc22f9d16508a44a8ef98a53d220
|
||||
|
||||
---
|
||||
lib/route/route_obj.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/route/route_obj.c b/lib/route/route_obj.c
|
||||
index 0ae029d..2d4a4b8 100644
|
||||
--- a/lib/route/route_obj.c
|
||||
+++ b/lib/route/route_obj.c
|
||||
@@ -983,7 +983,7 @@ int rtnl_route_guess_scope(struct rtnl_route *route)
|
||||
* is not directly connected
|
||||
*/
|
||||
nl_list_for_each_entry(nh, &route->rt_nexthops, rtnh_list) {
|
||||
- if (nh->rtnh_gateway)
|
||||
+ if (nh->rtnh_gateway || nh->rtnh_via)
|
||||
return RT_SCOPE_UNIVERSE;
|
||||
}
|
||||
}
|
||||
--
|
||||
2.33.0
|
||||
|
||||
107
backport-use-thread-safe-gmtime_r-instead-of-gmtime.patch
Normal file
107
backport-use-thread-safe-gmtime_r-instead-of-gmtime.patch
Normal file
@ -0,0 +1,107 @@
|
||||
From f520471cb6e2340309028e0400b8186db3635e0f Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Fri, 18 Aug 2023 14:04:21 +0200
|
||||
Subject: [PATCH] lib/xfrm: use thread-safe gmtime_r() instead of gmtime()
|
||||
|
||||
Conflict:NA
|
||||
Reference:https://github.com/thom311/libnl/commit/f520471cb6e2340309028e0400b8186db3635e0f
|
||||
|
||||
---
|
||||
lib/xfrm/ae.c | 5 +++--
|
||||
lib/xfrm/sa.c | 5 +++--
|
||||
lib/xfrm/sp.c | 5 +++--
|
||||
3 files changed, 9 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/lib/xfrm/ae.c b/lib/xfrm/ae.c
|
||||
index a56cd87..522cef0 100644
|
||||
--- a/lib/xfrm/ae.c
|
||||
+++ b/lib/xfrm/ae.c
|
||||
@@ -299,6 +299,7 @@ static void xfrm_ae_dump_line(struct nl_object *a, struct nl_dump_params *p)
|
||||
char flags[128], buf[128];
|
||||
time_t add_time, use_time;
|
||||
struct tm *add_time_tm, *use_time_tm;
|
||||
+ struct tm tm_buf;
|
||||
|
||||
nl_dump_line(p, "src %s dst %s \n", nl_addr2str(ae->saddr, src, sizeof(src)),
|
||||
nl_addr2str(ae->sa_id.daddr, dst, sizeof(dst)));
|
||||
@@ -317,7 +318,7 @@ static void xfrm_ae_dump_line(struct nl_object *a, struct nl_dump_params *p)
|
||||
if (ae->lifetime_cur.add_time != 0)
|
||||
{
|
||||
add_time = ae->lifetime_cur.add_time;
|
||||
- add_time_tm = gmtime (&add_time);
|
||||
+ add_time_tm = gmtime_r (&add_time, &tm_buf);
|
||||
strftime (flags, 128, "%Y-%m-%d %H-%M-%S", add_time_tm);
|
||||
}
|
||||
else
|
||||
@@ -328,7 +329,7 @@ static void xfrm_ae_dump_line(struct nl_object *a, struct nl_dump_params *p)
|
||||
if (ae->lifetime_cur.use_time != 0)
|
||||
{
|
||||
use_time = ae->lifetime_cur.use_time;
|
||||
- use_time_tm = gmtime (&use_time);
|
||||
+ use_time_tm = gmtime_r (&use_time, &tm_buf);
|
||||
strftime (buf, 128, "%Y-%m-%d %H-%M-%S", use_time_tm);
|
||||
}
|
||||
else
|
||||
diff --git a/lib/xfrm/sa.c b/lib/xfrm/sa.c
|
||||
index 6b3daf4..63a13ba 100644
|
||||
--- a/lib/xfrm/sa.c
|
||||
+++ b/lib/xfrm/sa.c
|
||||
@@ -411,6 +411,7 @@ static void xfrm_sa_dump_line(struct nl_object *a, struct nl_dump_params *p)
|
||||
char flags[128], mode[128];
|
||||
time_t add_time, use_time;
|
||||
struct tm *add_time_tm, *use_time_tm;
|
||||
+ struct tm tm_buf;
|
||||
|
||||
nl_dump_line(p, "src %s dst %s family: %s\n", nl_addr2str(sa->saddr, src, sizeof(src)),
|
||||
nl_addr2str(sa->id.daddr, dst, sizeof(dst)),
|
||||
@@ -454,7 +455,7 @@ static void xfrm_sa_dump_line(struct nl_object *a, struct nl_dump_params *p)
|
||||
if (sa->curlft.add_time != 0)
|
||||
{
|
||||
add_time = sa->curlft.add_time;
|
||||
- add_time_tm = gmtime (&add_time);
|
||||
+ add_time_tm = gmtime_r (&add_time, &tm_buf);
|
||||
strftime (flags, 128, "%Y-%m-%d %H-%M-%S", add_time_tm);
|
||||
}
|
||||
else
|
||||
@@ -465,7 +466,7 @@ static void xfrm_sa_dump_line(struct nl_object *a, struct nl_dump_params *p)
|
||||
if (sa->curlft.use_time != 0)
|
||||
{
|
||||
use_time = sa->curlft.use_time;
|
||||
- use_time_tm = gmtime (&use_time);
|
||||
+ use_time_tm = gmtime_r (&use_time, &tm_buf);
|
||||
strftime (mode, 128, "%Y-%m-%d %H-%M-%S", use_time_tm);
|
||||
}
|
||||
else
|
||||
diff --git a/lib/xfrm/sp.c b/lib/xfrm/sp.c
|
||||
index 3943469..1984099 100644
|
||||
--- a/lib/xfrm/sp.c
|
||||
+++ b/lib/xfrm/sp.c
|
||||
@@ -325,6 +325,7 @@ static void xfrm_sp_dump_line(struct nl_object *a, struct nl_dump_params *p)
|
||||
char dst[INET6_ADDRSTRLEN+5], src[INET6_ADDRSTRLEN+5];
|
||||
time_t add_time, use_time;
|
||||
struct tm *add_time_tm, *use_time_tm;
|
||||
+ struct tm tm_buf;
|
||||
|
||||
nl_addr2str(xfrmnl_sel_get_saddr (sp->sel), src, sizeof(src));
|
||||
nl_addr2str (xfrmnl_sel_get_daddr (sp->sel), dst, sizeof (dst));
|
||||
@@ -375,7 +376,7 @@ static void xfrm_sp_dump_line(struct nl_object *a, struct nl_dump_params *p)
|
||||
if (sp->curlft.add_time != 0)
|
||||
{
|
||||
add_time = sp->curlft.add_time;
|
||||
- add_time_tm = gmtime (&add_time);
|
||||
+ add_time_tm = gmtime_r (&add_time, &tm_buf);
|
||||
strftime (dst, INET6_ADDRSTRLEN+5, "%Y-%m-%d %H-%M-%S", add_time_tm);
|
||||
}
|
||||
else
|
||||
@@ -386,7 +387,7 @@ static void xfrm_sp_dump_line(struct nl_object *a, struct nl_dump_params *p)
|
||||
if (sp->curlft.use_time != 0)
|
||||
{
|
||||
use_time = sp->curlft.use_time;
|
||||
- use_time_tm = gmtime (&use_time);
|
||||
+ use_time_tm = gmtime_r (&use_time, &tm_buf);
|
||||
strftime (src, INET6_ADDRSTRLEN+5, "%Y-%m-%d %H-%M-%S", use_time_tm);
|
||||
}
|
||||
else
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -0,0 +1,86 @@
|
||||
From 4fcb075720ed3beea4ceee3f679305caacd0f51b Mon Sep 17 00:00:00 2001
|
||||
From: Thomas Haller <thaller@redhat.com>
|
||||
Date: Mon, 4 Dec 2023 11:22:38 +0100
|
||||
Subject: [PATCH] socket: workaround coverity warning about time_t handling
|
||||
|
||||
Coverity really wants to warn if a time_t is cast to 32 bits.
|
||||
We use time() here to get (some very bad) randomness. The loss
|
||||
of the upper bits is the least of the problems.
|
||||
|
||||
Work around the coverity warning by also the higher bits.
|
||||
|
||||
Error: Y2K38_SAFETY (CWE-197): [#def12]
|
||||
libnl-3.8.0/lib/socket.c:76: store_truncates_time_t: A "time_t" value is stored in an integer with too few bits to accommodate it. The expression "time(NULL)" is cast to "uint32_t".
|
||||
# 74|
|
||||
# 75| if (idx_state == 0) {
|
||||
# 76|-> uint32_t t = (uint32_t) time(NULL);
|
||||
# 77|
|
||||
# 78| /* from time to time (on average each 2^15 calls), the idx_state will
|
||||
|
||||
Error: Y2K38_SAFETY (CWE-197): [#def13]
|
||||
libnl-3.8.0/lib/socket.c:193: store_truncates_time_t: A "time_t" value is stored in an integer with too few bits to accommodate it. The expression "time(NULL)" is cast to "unsigned int".
|
||||
# 191| sk->s_local.nl_family = AF_NETLINK;
|
||||
# 192| sk->s_peer.nl_family = AF_NETLINK;
|
||||
# 193|-> sk->s_seq_next = (unsigned int) time(NULL);
|
||||
# 194| sk->s_seq_expect = sk->s_seq_next;
|
||||
# 195|
|
||||
|
||||
Conflict:patch for explicitly cast time() to uint32_t at 57e0170 is not incorporated
|
||||
Reference:https://github.com/thom311/libnl/commit/4fcb075720ed3beea4ceee3f679305caacd0f51b
|
||||
|
||||
|
||||
---
|
||||
lib/socket.c | 23 +++++++++++++++++++++--
|
||||
1 file changed, 21 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/lib/socket.c b/lib/socket.c
|
||||
index 99cd36d..778230b 100644
|
||||
--- a/lib/socket.c
|
||||
+++ b/lib/socket.c
|
||||
@@ -54,6 +54,24 @@ static void __init init_default_cb(void)
|
||||
}
|
||||
}
|
||||
|
||||
+static uint32_t _badrandom_from_time(void)
|
||||
+{
|
||||
+ uint32_t result;
|
||||
+ uint64_t v64;
|
||||
+ time_t t;
|
||||
+
|
||||
+ t = time(NULL);
|
||||
+ v64 = (uint64_t)t;
|
||||
+ result = (uint32_t)v64;
|
||||
+
|
||||
+ /* XOR with the upper bits. Otherwise, coverity warns about only
|
||||
+ * considering 32 bit from time_t. Use the inverse, so that for the
|
||||
+ * most part the bits don't change. */
|
||||
+ result ^= (~(v64 >> 32));
|
||||
+
|
||||
+ return result;
|
||||
+}
|
||||
+
|
||||
static uint32_t used_ports_map[32];
|
||||
static NL_RW_LOCK(port_map_lock);
|
||||
|
||||
@@ -67,7 +85,7 @@ static uint32_t generate_local_port(void)
|
||||
nl_write_lock(&port_map_lock);
|
||||
|
||||
if (idx_state == 0) {
|
||||
- uint32_t t = time(NULL);
|
||||
+ uint32_t t = _badrandom_from_time();
|
||||
|
||||
/* from time to time (on average each 2^15 calls), the idx_state will
|
||||
* be zero again. No problem, just "seed" anew with time(). */
|
||||
@@ -184,7 +202,8 @@ static struct nl_sock *__alloc_socket(struct nl_cb *cb)
|
||||
sk->s_cb = nl_cb_get(cb);
|
||||
sk->s_local.nl_family = AF_NETLINK;
|
||||
sk->s_peer.nl_family = AF_NETLINK;
|
||||
- sk->s_seq_expect = sk->s_seq_next = time(NULL);
|
||||
+ sk->s_seq_next = _badrandom_from_time();
|
||||
+ sk->s_seq_expect = sk->s_seq_next;
|
||||
|
||||
/* the port is 0 (unspecified), meaning NL_OWN_PORT */
|
||||
sk->s_flags = NL_OWN_PORT;
|
||||
--
|
||||
2.33.0
|
||||
|
||||
Binary file not shown.
BIN
libnl-3.7.0.tar.gz
Normal file
BIN
libnl-3.7.0.tar.gz
Normal file
Binary file not shown.
68
libnl3.spec
68
libnl3.spec
@ -1,20 +1,35 @@
|
||||
Name: libnl3
|
||||
Version: 3.5.0
|
||||
Release: 6
|
||||
Version: 3.7.0
|
||||
Release: 5
|
||||
Summary: Providing APIs to netlink protocol based Linux kernel interfaces
|
||||
License: LGPLv2
|
||||
URL: http://www.infradead.org/~tgr/libnl/
|
||||
Source: https://github.com/thom311/libnl/releases/download/libnl3_5_0/libnl-3.5.0.tar.gz
|
||||
Source: https://github.com/thom311/libnl/releases/download/libnl3_7_0/libnl-3.7.0.tar.gz
|
||||
|
||||
Patch6000: backport-prevent-segfault-in-af_request_type.patch
|
||||
Patch6001: backport-fix-bridge-info-parsing.patch
|
||||
|
||||
Patch6000: backport-lib-add-include-netlink-private-nl-auto-h-header.patch
|
||||
Patch6001: backport-lib-use-proper-int-type-for-id-attributes-in-nl_object_identical.patch
|
||||
Patch6002: backport-route-link-add-RTNL_LINK_REASM_OVERLAPS-stat.patch
|
||||
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
|
||||
Patch9002: add-some-tests-about-addr-class-rule-neigh-qdisc.patch
|
||||
|
||||
patch6002: backport-add-some-tests-about-addr-class-rule-neigh-qdisc.patch
|
||||
patch6003: backport-clear-XFRM_SP_ATTR_TMPL-when-removing-the-last-template.patch
|
||||
patch6004: backport-fix-reference-counters-of-sa-selector-addresses.patch
|
||||
patch6005: backport-do-not-use-static-array-indices-for-buffer.patch
|
||||
patch6006: backport-fix-leak-in-error-handling-of-rtnl_flower_append_action.patch
|
||||
patch6007: backport-fix-signed-overflow-warning-in-nl_object_diff.patch
|
||||
patch6008: backport-workaround-coverity-warning-about-time_t-handling.patch
|
||||
patch6009: backport-fix-leaking-usertemplate-in-xfrmnl_sp_parse.patch
|
||||
patch6010: backport-avoid-integer-overflow-in-rtnl_tc_calc_cell_log.patch
|
||||
patch6011: backport-fix-crashes-in-case-of-ENOMEM.patch
|
||||
patch6012: backport-accept-NULL-argument-in-nla_nest_cancel-for-robustness.patch
|
||||
patch6013: backport-fix-error-handling-in-nl_str2ip_protos.patch
|
||||
patch6014: backport-handle-negative-and-zero-size-in-nla_memcpy.patch
|
||||
patch6015: backport-use-thread-safe-gmtime_r-instead-of-gmtime.patch
|
||||
Patch6016: backport-fix-ubsan-complaint-about-incorrect.patch
|
||||
Patch6017: backport-fix-new-object-in-callback-v2-on-update-obj.patch
|
||||
Patch6018: backport-fix-IPv6-ecmp-route-deleted-nexthop-matching.patch
|
||||
Patch6019: backport-treat-routes-with-via-nexthops-as-univers-scoped.patch
|
||||
Patch6020: backport-keep-link-info-instead-of-release-and-reacquire.patch
|
||||
|
||||
BuildRequires: flex bison libtool autoconf automake swig
|
||||
Requires: %{name} = %{version}-%{release}
|
||||
@ -99,6 +114,37 @@ cd python
|
||||
%{python3_sitearch}/netlink-*.egg-info
|
||||
|
||||
%changelog
|
||||
* Mon Nov 11 2024 chengyechun <chengyechun1@huawei.com> - 3.7.0-5
|
||||
- Type:bugfix
|
||||
- CVE:NA
|
||||
- SUG:NA
|
||||
- DESC:sync some pathes from upstream
|
||||
|
||||
* Thu Apr 25 2024 sunhai <sunhai10@huawei.com> - 3.7.0-4
|
||||
- Type:bugfix
|
||||
- ID:NA
|
||||
- SUG:NA
|
||||
- DESC:sync some pathes from upstream
|
||||
|
||||
* Fri Jan 12 2024 chengyechun <chengyechun1@huawei.com> - 3.7.0-3
|
||||
- Type:bugfix
|
||||
- ID:NA
|
||||
- SUG:NA
|
||||
- DESC:Use the user-mode IPv6 header file
|
||||
|
||||
* Mon Aug 14 2023 chengyechun <chengyechun1@huawei.com> - 3.7.0-2
|
||||
- Type:bugfix
|
||||
- ID:NA
|
||||
- SUG:NA
|
||||
- DESC:prevent segfault in af_request_type
|
||||
fix bridge info parsing
|
||||
|
||||
* Wed Nov 9 2022 chengyechun <chengyechun1@huawei.com> - 3.7.0-1
|
||||
- Type:enhancement
|
||||
- ID:NA
|
||||
- SUG:NA
|
||||
- DESC:update to libnl-3.7.0
|
||||
|
||||
* Sat Dec 18 2021 chengyechun <chengyechun1@huawei.com> - 3.5.0-6
|
||||
- Type:bugfix
|
||||
- ID:NA
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user