The current behaviour around NLM_F_ECHO is inconsistent
and spread all around in various subsystems and doesn't
represent what it was meant for.

This patch handles NLM_F_ECHO in netlink_rcv_skb() to
handle it in a central point. Most subsystems currently
interpret NLM_F_ECHO as to just unicast events to the
originator of the change while the real meaning of the
flag is to echo the request.

Signed-off-by: Thomas Graf <[EMAIL PROTECTED]>

Index: net-2.6.19.git/net/netlink/af_netlink.c
===================================================================
--- net-2.6.19.git.orig/net/netlink/af_netlink.c
+++ net-2.6.19.git/net/netlink/af_netlink.c
@@ -1430,6 +1430,28 @@ int netlink_dump_start(struct sock *ssk,
        return 0;
 }
 
+static void netlink_echo(struct sk_buff *in_skb, struct nlmsghdr *orig)
+{
+       struct sk_buff *skb;
+       struct nlmsghdr *nlh;
+       int payload = nlmsg_len(orig);
+
+       skb = nlmsg_new(nlmsg_total_size(payload), GFP_KERNEL);
+       if (skb == NULL)
+               return;
+
+       /*
+        * Return original header with pid set to 0 (from kernel) and
+        * NLM_F_REQUEST flag removed to indicate this is not a request
+        * for an echo but the reply.
+        */
+       nlh = __nlmsg_put(skb, 0, orig->nlmsg_seq, orig->nlmsg_type,
+                         payload, orig->nlmsg_flags & ~NLM_F_REQUEST);
+       memcpy(nlmsg_data(nlh), nlmsg_data(orig), payload);
+
+       nlmsg_unicast(in_skb->sk, skb, NETLINK_CB(in_skb).pid);
+}
+
 void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err)
 {
        struct sk_buff *skb;
@@ -1476,6 +1498,9 @@ static int netlink_rcv_skb(struct sk_buf
                if (nlh->nlmsg_len < NLMSG_HDRLEN || skb->len < nlh->nlmsg_len)
                        return 0;
 
+               if (nlh->nlmsg_flags & NLM_F_ECHO)
+                       netlink_echo(skb, nlh);
+
                if (cb(skb, nlh, &err) < 0) {
                        /* Not an error, but we have to interrupt processing
                         * here. Note: that in this case we do not pull

-
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to