]> git.karo-electronics.de Git - linux-beck.git/commitdiff
Bluetooth: Add support for per socket msg_name callback
authorMarcel Holtmann <marcel@holtmann.org>
Sun, 13 Oct 2013 19:55:28 +0000 (12:55 -0700)
committerJohan Hedberg <johan.hedberg@intel.com>
Sun, 13 Oct 2013 20:10:33 +0000 (23:10 +0300)
This allows to add a per socket msg_name callback that can be used
for updating the msg_name information for recvmsg() system calls.

This feature is used by another patch to support address information
on L2CAP connectionless channels.

Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
include/net/bluetooth/bluetooth.h
net/bluetooth/af_bluetooth.c

index 1d6e484e08ef9f1e6de6e8acb9de8498dd7f7a5b..896aad80bc4dbffb84c7e2a61b84b8d946830fc7 100644 (file)
@@ -221,6 +221,7 @@ struct bt_sock {
        struct list_head accept_q;
        struct sock *parent;
        unsigned long flags;
+       void (*skb_msg_name)(struct sk_buff *, void *, int *);
 };
 
 enum {
index 9c7e4edc650404776d43aa6846c8a2b6d1210b71..f0aadeac4455f1f2bf9014ca4606414966a3b06b 100644 (file)
@@ -221,12 +221,12 @@ int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
        if (flags & (MSG_OOB))
                return -EOPNOTSUPP;
 
-       msg->msg_namelen = 0;
-
        skb = skb_recv_datagram(sk, flags, noblock, &err);
        if (!skb) {
-               if (sk->sk_shutdown & RCV_SHUTDOWN)
+               if (sk->sk_shutdown & RCV_SHUTDOWN) {
+                       msg->msg_namelen = 0;
                        return 0;
+               }
                return err;
        }
 
@@ -238,9 +238,16 @@ int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
 
        skb_reset_transport_header(skb);
        err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
-       if (err == 0)
+       if (err == 0) {
                sock_recv_ts_and_drops(msg, sk, skb);
 
+               if (bt_sk(sk)->skb_msg_name)
+                       bt_sk(sk)->skb_msg_name(skb, msg->msg_name,
+                                               &msg->msg_namelen);
+               else
+                       msg->msg_namelen = 0;
+       }
+
        skb_free_datagram(sk, skb);
 
        return err ? : copied;