mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-07 00:50:50 +00:00
netlink: avoid putting empty mbufs on the socket queue
When processing incoming Netlink messages in nl_process_nbuf() kernel always allocates a writer with a buffer to put generated reply to. However, certain messages aren't replied. That makes nlmsg_flush() to put an empty buffer to the socket. Avoid doing that because avoiding is much easier than dealing with empty buffers on the receiver side.
This commit is contained in:
parent
e6f4c31460
commit
f75d7fac10
|
@ -740,12 +740,7 @@ nl_soreceive(struct socket *so, struct sockaddr **psa, struct uio *uio,
|
||||||
TAILQ_FOREACH(nb, &sb->nl_queue, tailq) {
|
TAILQ_FOREACH(nb, &sb->nl_queue, tailq) {
|
||||||
u_int offset;
|
u_int offset;
|
||||||
|
|
||||||
/*
|
MPASS(nb->offset < nb->datalen);
|
||||||
* XXXGL: zero length buffer may be at the tail of a queue
|
|
||||||
* when a writer overflows socket buffer. When this is
|
|
||||||
* improved, use MPASS(nb->offset < nb->datalen).
|
|
||||||
*/
|
|
||||||
MPASS(nb->offset <= nb->datalen);
|
|
||||||
offset = nb->offset;
|
offset = nb->offset;
|
||||||
while (offset < nb->datalen) {
|
while (offset < nb->datalen) {
|
||||||
hdr = (struct nlmsghdr *)&nb->data[offset];
|
hdr = (struct nlmsghdr *)&nb->data[offset];
|
||||||
|
|
|
@ -201,6 +201,8 @@ nl_send(struct nl_writer *nw, struct nlpcb *nlp)
|
||||||
struct nl_buf *nb;
|
struct nl_buf *nb;
|
||||||
|
|
||||||
MPASS(nw->hdr == NULL);
|
MPASS(nw->hdr == NULL);
|
||||||
|
MPASS(nw->buf != NULL);
|
||||||
|
MPASS(nw->buf->datalen > 0);
|
||||||
|
|
||||||
IF_DEBUG_LEVEL(LOG_DEBUG2) {
|
IF_DEBUG_LEVEL(LOG_DEBUG2) {
|
||||||
struct nlmsghdr *hdr = (struct nlmsghdr *)nw->buf->data;
|
struct nlmsghdr *hdr = (struct nlmsghdr *)nw->buf->data;
|
||||||
|
|
|
@ -100,6 +100,7 @@ _nlmsg_ignore_limit(struct nl_writer *nw)
|
||||||
bool
|
bool
|
||||||
_nlmsg_flush(struct nl_writer *nw)
|
_nlmsg_flush(struct nl_writer *nw)
|
||||||
{
|
{
|
||||||
|
bool result;
|
||||||
|
|
||||||
if (__predict_false(nw->hdr != NULL)) {
|
if (__predict_false(nw->hdr != NULL)) {
|
||||||
/* Last message has not been completed, skip it. */
|
/* Last message has not been completed, skip it. */
|
||||||
|
@ -109,8 +110,14 @@ _nlmsg_flush(struct nl_writer *nw)
|
||||||
nw->hdr = NULL;
|
nw->hdr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
NL_LOG(LOG_DEBUG2, "OUT");
|
if (nw->buf->datalen == 0) {
|
||||||
bool result = nw->cb(nw);
|
MPASS(nw->num_messages == 0);
|
||||||
|
nl_buf_free(nw->buf);
|
||||||
|
nw->buf = NULL;
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = nw->cb(nw);
|
||||||
nw->num_messages = 0;
|
nw->num_messages = 0;
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
|
Loading…
Reference in a new issue