Phonet: hook resource routing to userspace via ioctl()'s
authorRémi Denis-Courmont <remi.denis-courmont@nokia.com>
Wed, 15 Sep 2010 12:30:12 +0000 (12:30 +0000)
committerDavid S. Miller <davem@davemloft.net>
Thu, 16 Sep 2010 04:31:32 +0000 (21:31 -0700)
I wish we could use something cleaner, such as bind(). But that would
not work since resource subscription is orthogonal/in addition to the
normal object ID allocated via bind(). This is similar to multicasting
which also uses ioctl()'s.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/phonet.h
net/phonet/datagram.c
net/phonet/socket.c

index 76edadf046d3d3b68215c23ef2a30ce18a86992a..85e14a83283b6a15d791adcf8e830a22fac6f8b7 100644 (file)
@@ -47,6 +47,8 @@
 
 /* ioctls */
 #define SIOCPNGETOBJECT                (SIOCPROTOPRIVATE + 0)
+#define SIOCPNADDRESOURCE      (SIOCPROTOPRIVATE + 14)
+#define SIOCPNDELRESOURCE      (SIOCPROTOPRIVATE + 15)
 
 /* Phonet protocol header */
 struct phonethdr {
index 1bd38db4fe1e996df47396d43acd296e9811fa1b..2f032381bd4554226cd7d30a4bd104777caa5758 100644 (file)
@@ -52,6 +52,19 @@ static int pn_ioctl(struct sock *sk, int cmd, unsigned long arg)
                answ = skb ? skb->len : 0;
                release_sock(sk);
                return put_user(answ, (int __user *)arg);
+
+       case SIOCPNADDRESOURCE:
+       case SIOCPNDELRESOURCE: {
+                       u32 res;
+                       if (get_user(res, (u32 __user *)arg))
+                               return -EFAULT;
+                       if (res >= 256)
+                               return -EINVAL;
+                       if (cmd == SIOCPNADDRESOURCE)
+                               return pn_sock_bind_res(sk, res);
+                       else
+                               return pn_sock_unbind_res(sk, res);
+               }
        }
 
        return -ENOIOCTLCMD;
index 4c29a23e900752f100bcbcbafc4764328eb0d430..d4f41afc05833fbe360aa1be57e45989e52a4353 100644 (file)
@@ -158,6 +158,7 @@ void pn_sock_unhash(struct sock *sk)
        spin_lock_bh(&pnsocks.lock);
        sk_del_node_init(sk);
        spin_unlock_bh(&pnsocks.lock);
+       pn_sock_unbind_all_res(sk);
 }
 EXPORT_SYMBOL(pn_sock_unhash);