diff options
author | Karl Hiramoto <karl@hiramoto.org> | 2010-02-24 21:29:13 +0100 |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2010-03-10 16:01:46 +0100 |
commit | 27c505eb89f7a689416f822e26c0ccea0b351ba3 (patch) | |
tree | 428ce3353b908319b64a4bdd1ddb205190d2f9f5 /lib | |
parent | 8808743839b0f459394ecd00cb0f7c1896c0ab7a (diff) | |
download | libnl-27c505eb89f7a689416f822e26c0ccea0b351ba3.tar.gz |
new feature nl_send_iovec(), nl_auto_complete() and code refactoring.
Create new function nl_send_iovec() to be used to send multiple 'struct iovec'
through the netlink socket. This will be used for NF_QUEUE, to send
packet payload of a modified packet.
Refactor nl_send() to use nl_send_iovec() sending a single struct iovec.
Create new function nl_auto_complete() by refactoring nl_send_auto_complete(),
so other functions that call nl_send may also use nl_auto_complete()
Signed-off-by: Karl Hiramoto <karl@hiramoto.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nl.c | 69 |
1 files changed, 45 insertions, 24 deletions
@@ -207,14 +207,6 @@ int nl_sendmsg(struct nl_sock *sk, struct nl_msg *msg, struct msghdr *hdr) struct nl_cb *cb; int ret; - struct iovec iov = { - .iov_base = (void *) nlmsg_hdr(msg), - .iov_len = nlmsg_hdr(msg)->nlmsg_len, - }; - - hdr->msg_iov = &iov; - hdr->msg_iovlen = 1; - nlmsg_set_src(msg, &sk->s_local); cb = sk->s_cb; @@ -226,6 +218,7 @@ int nl_sendmsg(struct nl_sock *sk, struct nl_msg *msg, struct msghdr *hdr) if (ret < 0) return -nl_syserr2nlerr(errno); + NL_DBG(4, "sent %d bytes\n", ret); return ret; } @@ -234,17 +227,20 @@ int nl_sendmsg(struct nl_sock *sk, struct nl_msg *msg, struct msghdr *hdr) * Send netlink message. * @arg sk Netlink socket. * @arg msg Netlink message to be sent. + * @arg iov iovec to be sent. + * @arg iovlen number of struct iovec to be sent. * @see nl_sendmsg() * @return Number of characters sent on success or a negative error code. */ -int nl_send(struct nl_sock *sk, struct nl_msg *msg) +int nl_send_iovec(struct nl_sock *sk, struct nl_msg *msg, const struct iovec *iov, unsigned iovlen) { struct sockaddr_nl *dst; struct ucred *creds; - struct msghdr hdr = { .msg_name = (void *) &sk->s_peer, .msg_namelen = sizeof(struct sockaddr_nl), + .msg_iov = iov, + .msg_iovlen = iovlen, }; /* Overwrite destination if specified in the message itself, defaults @@ -273,22 +269,28 @@ int nl_send(struct nl_sock *sk, struct nl_msg *msg) return nl_sendmsg(sk, msg, &hdr); } + + /** - * Send netlink message and check & extend header values as needed. - * @arg sk Netlink socket. - * @arg msg Netlink message to be sent. - * - * Checks the netlink message \c nlh for completness and extends it - * as required before sending it out. Checked fields include pid, - * sequence nr, and flags. - * - * @see nl_send() - * @return Number of characters sent or a negative error code. - */ -int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg) +* Send netlink message. +* @arg sk Netlink socket. +* @arg msg Netlink message to be sent. +* @see nl_sendmsg() +* @return Number of characters 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, + }; + + return nl_send_iovec(sk, msg, &iov, 1); +} + +void nl_auto_complete(struct nl_sock *sk, struct nl_msg *msg) { struct nlmsghdr *nlh; - struct nl_cb *cb = sk->s_cb; nlh = nlmsg_hdr(msg); if (nlh->nlmsg_pid == 0) @@ -299,11 +301,30 @@ int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg) if (msg->nm_protocol == -1) msg->nm_protocol = sk->s_proto; - + nlh->nlmsg_flags |= NLM_F_REQUEST; if (!(sk->s_flags & NL_NO_AUTO_ACK)) nlh->nlmsg_flags |= NLM_F_ACK; +} + +/** + * Send netlink message and check & extend header values as needed. + * @arg sk Netlink socket. + * @arg msg Netlink message to be sent. + * + * Checks the netlink message \c nlh for completness and extends it + * as required before sending it out. Checked fields include pid, + * sequence nr, and flags. + * + * @see nl_send() + * @return Number of characters sent or a negative error code. + */ +int nl_send_auto_complete(struct nl_sock *sk, struct nl_msg *msg) +{ + struct nl_cb *cb = sk->s_cb; + + nl_auto_complete(sk, msg); if (cb->cb_send_ow) return cb->cb_send_ow(sk, msg); |