summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Fietkau2023-12-05 11:52:42 +0000
committerFelix Fietkau2023-12-05 11:52:43 +0000
commit965c4bf49658342ced0bd6e7cb069571b4a1ddff (patch)
tree18e2b83ef1e3caa830a48f23f78ea513ba098e31
parent785e11aee7ddf1ce302e7c91d6207ec777ea13c6 (diff)
downloadlibnl-tiny-965c4bf49658342ced0bd6e7cb069571b4a1ddff.tar.gz
socket: change debug callbacks to pass struct nl_msg
This allows checking the netlink protocol in the callback Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--include/netlink/socket.h3
-rw-r--r--nl.c15
2 files changed, 9 insertions, 9 deletions
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])