diff mbox series

[iproute2-next] tipc: add support for the netlink extack

Message ID 20210325015653.7112-1-hoang.h.le@dektech.com.au (mailing list archive)
State Changes Requested
Delegated to: David Ahern
Headers show
Series [iproute2-next] tipc: add support for the netlink extack | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Hoang Huu Le March 25, 2021, 1:56 a.m. UTC
Add support extack in tipc to dump the netlink extack error messages
(i.e -EINVAL) sent from kernel.

Acked-by: Jon Maloy <jmaloy@redhat.com>
Signed-off-by: Hoang Le <hoang.h.le@dektech.com.au>
---
 tipc/msg.c | 29 ++++++++++++++++++++++-------
 1 file changed, 22 insertions(+), 7 deletions(-)

Comments

David Ahern March 25, 2021, 3:07 a.m. UTC | #1
On 3/24/21 7:56 PM, Hoang Le wrote:
> Add support extack in tipc to dump the netlink extack error messages
> (i.e -EINVAL) sent from kernel.
> 
> Acked-by: Jon Maloy <jmaloy@redhat.com>
> Signed-off-by: Hoang Le <hoang.h.le@dektech.com.au>
> ---
>  tipc/msg.c | 29 ++++++++++++++++++++++-------
>  1 file changed, 22 insertions(+), 7 deletions(-)
> 

tipc should be converted to use the library functions in lib/mnl_utils.c.
Hoang Huu Le March 25, 2021, 7:25 a.m. UTC | #2
> -----Original Message-----
> From: David Ahern <dsahern@gmail.com>
> Sent: Thursday, March 25, 2021 10:08 AM
> To: Hoang Huu Le <hoang.h.le@dektech.com.au>; netdev@vger.kernel.org; tipc-discussion@lists.sourceforge.net;
> jmaloy@redhat.com; maloy@donjonn.com; ying.xue@windriver.com; Tuan Anh Vo <tuan.a.vo@dektech.com.au>; Tung Quang
> Nguyen <tung.q.nguyen@dektech.com.au>
> Subject: Re: [iproute2-next] tipc: add support for the netlink extack
> 
> On 3/24/21 7:56 PM, Hoang Le wrote:
> > Add support extack in tipc to dump the netlink extack error messages
> > (i.e -EINVAL) sent from kernel.
> >
> > Acked-by: Jon Maloy <jmaloy@redhat.com>
> > Signed-off-by: Hoang Le <hoang.h.le@dektech.com.au>
> > ---
> >  tipc/msg.c | 29 ++++++++++++++++++++++-------
> >  1 file changed, 22 insertions(+), 7 deletions(-)
> >
> 
> tipc should be converted to use the library functions in lib/mnl_utils.c.

It's really a big change. So, we will do in next commit.
diff mbox series

Patch

diff --git a/tipc/msg.c b/tipc/msg.c
index dc09d05048f3..f29b2f8d35ad 100644
--- a/tipc/msg.c
+++ b/tipc/msg.c
@@ -18,6 +18,7 @@ 
 #include <linux/genetlink.h>
 #include <libmnl/libmnl.h>
 
+#include "libnetlink.h"
 #include "msg.h"
 
 int parse_attrs(const struct nlattr *attr, void *data)
@@ -49,6 +50,7 @@  static struct mnl_socket *msg_send(struct nlmsghdr *nlh)
 {
 	int ret;
 	struct mnl_socket *nl;
+	int one = 1;
 
 	nl = mnl_socket_open(NETLINK_GENERIC);
 	if (nl == NULL) {
@@ -56,6 +58,8 @@  static struct mnl_socket *msg_send(struct nlmsghdr *nlh)
 		return NULL;
 	}
 
+	/* support to get extended ACK */
+	mnl_socket_setsockopt(nl, NETLINK_EXT_ACK, &one, sizeof(one));
 	ret = mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID);
 	if (ret < 0) {
 		perror("mnl_socket_bind");
@@ -73,21 +77,32 @@  static struct mnl_socket *msg_send(struct nlmsghdr *nlh)
 
 static int msg_recv(struct mnl_socket *nl, mnl_cb_t callback, void *data, int seq)
 {
-	int ret;
 	unsigned int portid;
 	char buf[MNL_SOCKET_BUFFER_SIZE];
+	struct nlmsghdr *h;
+	size_t num_bytes;
+	int is_err = 0;
+	int ret = 0;
 
 	portid = mnl_socket_get_portid(nl);
 
-	ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
-	while (ret > 0) {
-		ret = mnl_cb_run(buf, ret, seq, portid, callback, data);
+	num_bytes = mnl_socket_recvfrom(nl, buf, sizeof(buf));
+	while (num_bytes > 0) {
+		ret = mnl_cb_run(buf, num_bytes, seq, portid, callback, data);
 		if (ret <= 0)
 			break;
-		ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
+		num_bytes = mnl_socket_recvfrom(nl, buf, sizeof(buf));
+	}
+
+	if (ret == -1) {
+		if (num_bytes > 0) {
+			h = (struct nlmsghdr *)buf;
+			is_err = nl_dump_ext_ack(h, NULL);
+		}
+
+		if (!is_err)
+			perror("error");
 	}
-	if (ret == -1)
-		perror("error");
 
 	mnl_socket_close(nl);