netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] lib: move rtnl_echo_talk from libnetlink to utils
@ 2023-07-11  7:31 Hangbin Liu
  2023-07-11 16:00 ` Stephen Hemminger
  0 siblings, 1 reply; 5+ messages in thread
From: Hangbin Liu @ 2023-07-11  7:31 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Stephen Hemminger, Andrea Claudi, Hangbin Liu,
	Ying Xu

In commit 6c09257f1bf6 ("rtnetlink: add new function rtnl_echo_talk()"),
some json obj functions were exported in libnetlink. Which cause build
error like:
    /usr/bin/ld: /tmp/cc6YaGBM.o: in function `rtnl_echo_talk':
    libnetlink.c:(.text+0x25bd): undefined reference to `new_json_obj'
    /usr/bin/ld: libnetlink.c:(.text+0x25c7): undefined reference to `open_json_object'
    /usr/bin/ld: libnetlink.c:(.text+0x25e3): undefined reference to `close_json_object'
    /usr/bin/ld: libnetlink.c:(.text+0x25e8): undefined reference to `delete_json_obj'
    collect2: error: ld returned 1 exit status

Commit 6d68d7f85d8a ("testsuite: fix build failure") only fixed this issue
for iproute building. But if other applications include the libnetlink.a,
they still have this problem, because libutil.a is not exported to the
LDLIBS. So let's move the rtnl_echo_talk() from libnetlink.c to utils.c
to avoid this issue.

After the fix, we can also remove the update by c0a06885b944 ("testsuite: fix
testsuite build failure when iproute build without libcap-devel").

Reported-by: Ying Xu <yinxu@redhat.com>
Fixes: 6c09257f1bf6 ("rtnetlink: add new function rtnl_echo_talk()")
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 include/libnetlink.h     |  3 ---
 include/utils.h          |  3 +++
 lib/libnetlink.c         | 22 ----------------------
 lib/utils.c              | 22 ++++++++++++++++++++++
 testsuite/tools/Makefile |  8 ++------
 5 files changed, 27 insertions(+), 31 deletions(-)

diff --git a/include/libnetlink.h b/include/libnetlink.h
index 39ed87a7..1c4557e8 100644
--- a/include/libnetlink.h
+++ b/include/libnetlink.h
@@ -171,9 +171,6 @@ int rtnl_dump_filter_errhndlr_nc(struct rtnl_handle *rth,
 #define rtnl_dump_filter_errhndlr(rth, filter, farg, errhndlr, earg) \
 	rtnl_dump_filter_errhndlr_nc(rth, filter, farg, errhndlr, earg, 0)
 
-int rtnl_echo_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, int json,
-		   int (*print_info)(struct nlmsghdr *n, void *arg))
-	__attribute__((warn_unused_result));
 int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
 	      struct nlmsghdr **answer)
 	__attribute__((warn_unused_result));
diff --git a/include/utils.h b/include/utils.h
index 0b5d86a2..841c2547 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -385,4 +385,7 @@ int proto_a2n(unsigned short *id, const char *buf,
 const char *proto_n2a(unsigned short id, char *buf, int len,
 		      const struct proto *proto_tb, size_t tb_len);
 
+int rtnl_echo_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, int json,
+		   int (*print_info)(struct nlmsghdr *n, void *arg))
+	__attribute__((warn_unused_result));
 #endif /* __UTILS_H__ */
diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index 7edcd285..55a8e135 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -1140,28 +1140,6 @@ static int __rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
 	return __rtnl_talk_iov(rtnl, &iov, 1, answer, show_rtnl_err, errfn);
 }
 
-int rtnl_echo_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, int json,
-		   int (*print_info)(struct nlmsghdr *n, void *arg))
-{
-	struct nlmsghdr *answer;
-	int ret;
-
-	n->nlmsg_flags |= NLM_F_ECHO | NLM_F_ACK;
-
-	ret = rtnl_talk(rtnl, n, &answer);
-	if (ret)
-		return ret;
-
-	new_json_obj(json);
-	open_json_object(NULL);
-	print_info(answer, stdout);
-	close_json_object();
-	delete_json_obj();
-	free(answer);
-
-	return 0;
-}
-
 int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n,
 	      struct nlmsghdr **answer)
 {
diff --git a/lib/utils.c b/lib/utils.c
index b1f27305..8b89052c 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -1952,3 +1952,25 @@ int proto_a2n(unsigned short *id, const char *buf,
 
 	return 0;
 }
+
+int rtnl_echo_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, int json,
+		   int (*print_info)(struct nlmsghdr *n, void *arg))
+{
+	struct nlmsghdr *answer;
+	int ret;
+
+	n->nlmsg_flags |= NLM_F_ECHO | NLM_F_ACK;
+
+	ret = rtnl_talk(rtnl, n, &answer);
+	if (ret)
+		return ret;
+
+	new_json_obj(json);
+	open_json_object(NULL);
+	print_info(answer, stdout);
+	close_json_object();
+	delete_json_obj();
+	free(answer);
+
+	return 0;
+}
diff --git a/testsuite/tools/Makefile b/testsuite/tools/Makefile
index 0356ddae..56d7a71c 100644
--- a/testsuite/tools/Makefile
+++ b/testsuite/tools/Makefile
@@ -1,13 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0
 CFLAGS=
-LDLIBS=
 include ../../config.mk
-ifeq ($(HAVE_CAP),y)
-LDLIBS+= -lcap
-endif
 
-generate_nlmsg: generate_nlmsg.c ../../lib/libnetlink.a ../../lib/libutil.a
-	$(QUIET_CC)$(CC) $(CPPFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) -I../../include -I../../include/uapi -include../../include/uapi/linux/netlink.h -o $@ $^ -lmnl $(LDLIBS)
+generate_nlmsg: generate_nlmsg.c ../../lib/libnetlink.a
+	$(QUIET_CC)$(CC) $(CPPFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) -I../../include -I../../include/uapi -include../../include/uapi/linux/netlink.h -o $@ $^ -lmnl
 
 clean:
 	rm -f generate_nlmsg
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-14  3:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-11  7:31 [PATCH iproute2] lib: move rtnl_echo_talk from libnetlink to utils Hangbin Liu
2023-07-11 16:00 ` Stephen Hemminger
2023-07-12  3:11   ` Hangbin Liu
2023-07-13 22:28     ` Stephen Hemminger
2023-07-14  3:28       ` Hangbin Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).