Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ff491a73 authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso Committed by David S. Miller
Browse files

netlink: change return-value logic of netlink_broadcast()



Currently, netlink_broadcast() reports errors to the caller if no
messages at all were delivered:

1) If, at least, one message has been delivered correctly, returns 0.
2) Otherwise, if no messages at all were delivered due to skb_clone()
   failure, return -ENOBUFS.
3) Otherwise, if there are no listeners, return -ESRCH.

With this patch, the caller knows if the delivery of any of the
messages to the listeners have failed:

1) If it fails to deliver any message (for whatever reason), return
   -ENOBUFS.
2) Otherwise, if all messages were delivered OK, returns 0.
3) Otherwise, if no listeners, return -ESRCH.

In the current ctnetlink code and in Netfilter in general, we can add
reliable logging and connection tracking event delivery by dropping the
packets whose events were not successfully delivered over Netlink. Of
course, this option would be settable via /proc as this approach reduces
performance (in terms of filtered connections per seconds by a stateful
firewall) but providing reliable logging and event delivery (for
conntrackd) in return.

This patch also changes some clients of netlink_broadcast() that
may report ENOBUFS errors via printk. This error handling is not
of any help. Instead, the userspace daemons that are listening to
those netlink messages should resync themselves with the kernel-side
if they hit ENOBUFS.

BTW, netlink_broadcast() clients include those that call
cn_netlink_send(), nlmsg_multicast() and genlmsg_multicast() since they
internally call netlink_broadcast() and return its error value.

Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 612e244c
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -235,11 +235,7 @@ int acpi_bus_generate_netlink_event(const char *device_class,
		return result;
	}

	result =
	genlmsg_multicast(skb, 0, acpi_event_mcgrp.id, GFP_ATOMIC);
	if (result)
		ACPI_DEBUG_PRINT((ACPI_DB_INFO,
				  "Failed to send a Genetlink message!\n"));
	return 0;
}

+4 −12
Original line number Diff line number Diff line
@@ -533,12 +533,8 @@ fc_host_post_event(struct Scsi_Host *shost, u32 event_number,
	event->event_code = event_code;
	event->event_data = event_data;

	err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS,
	nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS,
			GFP_KERNEL);
	if (err && (err != -ESRCH))	/* filter no recipient errors */
		/* nlmsg_multicast already kfree_skb'd */
		goto send_fail;

	return;

send_fail_skb:
@@ -607,12 +603,8 @@ fc_host_post_vendor_event(struct Scsi_Host *shost, u32 event_number,
	event->event_code = FCH_EVT_VENDOR_UNIQUE;
	memcpy(&event->event_data, data_buf, data_len);

	err = nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS,
	nlmsg_multicast(scsi_nl_sock, skb, 0, SCSI_NL_GRP_FC_EVENTS,
			GFP_KERNEL);
	if (err && (err != -ESRCH))	/* filter no recipient errors */
		/* nlmsg_multicast already kfree_skb'd */
		goto send_vendor_fail;

	return;

send_vendor_fail_skb:
+2 −10
Original line number Diff line number Diff line
@@ -966,15 +966,7 @@ iscsi_if_transport_lookup(struct iscsi_transport *tt)
static int
iscsi_broadcast_skb(struct sk_buff *skb, gfp_t gfp)
{
	int rc;

	rc = netlink_broadcast(nls, skb, 0, 1, gfp);
	if (rc < 0) {
		printk(KERN_ERR "iscsi: can not broadcast skb (%d)\n", rc);
		return rc;
	}

	return 0;
	return netlink_broadcast(nls, skb, 0, 1, gfp);
}

static int
@@ -1207,7 +1199,7 @@ int iscsi_session_event(struct iscsi_cls_session *session,
	 * the user and when the daemon is restarted it will handle it
	 */
	rc = iscsi_broadcast_skb(skb, GFP_KERNEL);
	if (rc < 0)
	if (rc == -ESRCH)
		iscsi_cls_session_printk(KERN_ERR, session,
					 "Cannot notify userspace of session "
					 "event %u. Check iscsi daemon\n",
+4 −1
Original line number Diff line number Diff line
@@ -204,8 +204,11 @@ static int uvesafb_exec(struct uvesafb_ktask *task)
		} else {
			v86d_started = 1;
			err = cn_netlink_send(m, 0, gfp_any());
			if (err == -ENOBUFS)
				err = 0;
		}
	}
	} else if (err == -ENOBUFS)
		err = 0;

	if (!err && !(task->t.flags & TF_EXIT))
		err = !wait_for_completion_timeout(task->done,
+1 −4
Original line number Diff line number Diff line
@@ -1057,10 +1057,7 @@ static void send_warning(const struct dquot *dquot, const char warntype)
		goto attr_err_out;
	genlmsg_end(skb, msg_head);

	ret = genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS);
	if (ret < 0 && ret != -ESRCH)
		printk(KERN_ERR
			"VFS: Failed to send notification message: %d\n", ret);
	genlmsg_multicast(skb, 0, quota_genl_family.id, GFP_NOFS);
	return;
attr_err_out:
	printk(KERN_ERR "VFS: Not enough space to compose quota message!\n");
Loading