summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Graf <tgraf@redhat.com>2012-11-08 13:19:07 +0100
committerThomas Graf <tgraf@redhat.com>2012-11-08 13:19:07 +0100
commitfd6f205f8a14e8bf7288e65be435641d5ee2956a (patch)
tree7e6274ec69e15f57dea783b36f77804083066345
parentb132ee7e27899b07f30e9a53dd6ce5f09efd8bf6 (diff)
downloadlibnl-fd6f205f8a14e8bf7288e65be435641d5ee2956a.tar.gz
nl: Allow to overwrite nl_send()
Up to now only calls to nl_send_auto() could be overwritten with nl_cb_overwrite_send(). This patch extends the capability to nl_send() Signed-off-by: Thomas Graf <tgraf@redhat.com>
-rw-r--r--lib/nl.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/lib/nl.c b/lib/nl.c
index 5f4ab94..efdd095 100644
--- a/lib/nl.c
+++ b/lib/nl.c
@@ -331,6 +331,10 @@ int nl_send_iovec(struct nl_sock *sk, struct nl_msg *msg, struct iovec *iov, uns
* If present in the `msg`, credentials set by the nlmsg_set_creds() function
* are added to the control buffer of the message.
*
+ * @par Overwriting Capability:
+ * Calls to this function can be overwritten by providing an alternative using
+ * the nl_cb_overwrite_send() function.
+ *
* @callback This function triggers the `NL_CB_MSG_OUT` callback.
*
* @attention
@@ -343,17 +347,24 @@ int nl_send_iovec(struct nl_sock *sk, struct nl_msg *msg, struct iovec *iov, uns
* @see nl_socket_set_peer_groups()
* @see nlmsg_set_dst()
* @see nlmsg_set_creds()
+ * @see nl_cb_overwrite_send()
*
* @return Number of bytes sent on success or a negative error code.
*/
int nl_send(struct nl_sock *sk, struct nl_msg *msg)
{
- struct iovec iov = {
- .iov_base = (void *) nlmsg_hdr(msg),
- .iov_len = nlmsg_hdr(msg)->nlmsg_len,
- };
+ struct nl_cb *cb = sk->s_cb;
+
+ if (cb->cb_send_ow)
+ return cb->cb_send_ow(sk, msg);
+ else {
+ struct iovec iov = {
+ .iov_base = (void *) nlmsg_hdr(msg),
+ .iov_len = nlmsg_hdr(msg)->nlmsg_len,
+ };
- return nl_send_iovec(sk, msg, &iov, 1);
+ return nl_send_iovec(sk, msg, &iov, 1);
+ }
}
/**
@@ -411,14 +422,9 @@ void nl_complete_msg(struct nl_sock *sk, struct nl_msg *msg)
*/
int nl_send_auto(struct nl_sock *sk, struct nl_msg *msg)
{
- struct nl_cb *cb = sk->s_cb;
-
nl_complete_msg(sk, msg);
- if (cb->cb_send_ow)
- return cb->cb_send_ow(sk, msg);
- else
- return nl_send(sk, msg);
+ return nl_send(sk, msg);
}
/**