From: Felix Fietkau Date: Tue, 5 Dec 2023 11:52:42 +0000 (+0100) Subject: socket: change debug callbacks to pass struct nl_msg X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=HEAD;p=project%2Flibnl-tiny.git socket: change debug callbacks to pass struct nl_msg This allows checking the netlink protocol in the callback Signed-off-by: Felix Fietkau --- diff --git a/include/netlink/socket.h b/include/netlink/socket.h index 9ddd42c..1ca19b0 100644 --- a/include/netlink/socket.h +++ b/include/netlink/socket.h @@ -26,8 +26,9 @@ extern "C" { #define NL_NO_AUTO_ACK (1<<4) struct nl_cb; +struct nl_msg; -typedef void (*nl_debug_cb)(void *priv, const void *data, size_t len); +typedef void (*nl_debug_cb)(void *priv, struct nl_msg *msg); struct nl_sock { struct sockaddr_nl s_local; diff --git a/nl.c b/nl.c index b0f43e2..7ab8822 100644 --- a/nl.c +++ b/nl.c @@ -192,9 +192,6 @@ int nl_sendto(struct nl_sock *sk, void *buf, size_t size) { int ret; - if (sk->s_debug_tx_cb) - sk->s_debug_tx_cb(sk->s_debug_tx_priv, buf, size); - ret = sendto(sk->s_fd, buf, size, 0, (struct sockaddr *) &sk->s_peer, sizeof(sk->s_peer)); if (ret < 0) @@ -230,8 +227,10 @@ int nl_sendmsg(struct nl_sock *sk, struct nl_msg *msg, struct msghdr *hdr) if (nl_cb_call(cb, NL_CB_MSG_OUT, msg) != NL_OK) return 0; - if (sk->s_debug_tx_cb) - sk->s_debug_tx_cb(sk->s_debug_tx_priv, iov.iov_base, iov.iov_len); + if (sk->s_debug_tx_cb) { + nlmsg_set_proto(msg, sk->s_proto); + sk->s_debug_tx_cb(sk->s_debug_tx_priv, msg); + } ret = sendmsg(sk->s_fd, hdr, 0); if (ret < 0) @@ -533,14 +532,14 @@ continue_reading: goto out; } - if (sk->s_debug_rx_cb) - sk->s_debug_rx_cb(sk->s_debug_rx_priv, hdr, hdr->nlmsg_len); - nlmsg_set_proto(msg, sk->s_proto); nlmsg_set_src(msg, &nla); if (creds) nlmsg_set_creds(msg, creds); + if (sk->s_debug_rx_cb) + sk->s_debug_rx_cb(sk->s_debug_rx_priv, msg); + /* Raw callback is the first, it gives the most control * to the user and he can do his very own parsing. */ if (cb->cb_set[NL_CB_MSG_IN])