diff mbox series

[6/9] wmediumd: fix RX message with cookie

Message ID 20200625150754.f1b8860bb95b.Ifb8f79b3edacce8832697ca796861aad92b2ce7b@changeid
State New
Headers show
Series [1/9] wmediumd: add -lstdc++ for SANITIZE=1 | expand

Commit Message

Johannes Berg June 25, 2020, 1:08 p.m. UTC
From: Johannes Berg <johannes.berg@intel.com>

The cookie message needs to be built properly, fix the code to
do this, otherwise a client with WMEDIUMD_CTL_RX_ALL_FRAMES
doesn't know its own messages. The code was just completely
broken in all kinds of ways.

---
 wmediumd/wmediumd.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/wmediumd/wmediumd.c b/wmediumd/wmediumd.c
index aa169e1602be..afc4f16d9ae9 100644
--- a/wmediumd/wmediumd.c
+++ b/wmediumd/wmediumd.c
@@ -606,11 +606,12 @@  static void send_cloned_frame_msg(struct wmediumd *ctx, struct client *src,
 
 	list_for_each_entry(client, &ctx->clients, list) {
 		if (client->flags & WMEDIUMD_CTL_RX_ALL_FRAMES) {
-			if (!cmsg) {
-				cmsg = nlmsg_convert(nlmsg_hdr(msg));
-				if (!cmsg)
-					continue;
-				nla_put_u64(msg, HWSIM_ATTR_COOKIE, cookie);
+			if (src == client && !cmsg) {
+				struct nlmsghdr *nlh = nlmsg_hdr(msg);
+
+				cmsg = nlmsg_inherit(nlh);
+				nlmsg_append(cmsg, nlmsg_data(nlh), nlmsg_datalen(nlh), 0);
+				assert(nla_put_u64(cmsg, HWSIM_ATTR_COOKIE, cookie) == 0);
 			}
 			wmediumd_send_to_client(ctx, client,
 						src == client ? cmsg : msg);