Skip to contentSkip to conversation

Phonet resource routing

PATCH In review Rémi Denis-Courmont 2 participants 7 messages Sep 15, 2010 – Sep 16, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover Phonet resource routing

Hello,

This patch series adds support for implement Phonet services ("servers") on Linux. So far, this was only possible on the Phonet modem attached; i.e. Linux processes could only act as a "client".

Comments welcome. (Or did I again miss the new feature deadline?)

 Documentation/networking/phonet.txt |   16 +++
 include/linux/phonet.h              |    2 
 include/net/phonet/phonet.h         |    5 
 include/net/phonet/pn_dev.h         |    1 
 net/phonet/af_phonet.c              |   17 +++
 net/phonet/datagram.c               |   13 ++
 net/phonet/pn_dev.c                 |    2 
 net/phonet/socket.c                 |  185
++++++++++++++++++++++++++++++++++++
 8 files changed, 241 insertions(+)
Signature · 3 lines
Rémi Denis-Courmont
http://www.remlab.net
http://fi.linkedin.com/in/remidenis
#1 lore raw

PATCH 1/1 Phonet: resource routing backend

From: Rémi Denis-Courmont <[email protected]>

When both destination device and object are nul, Phonet routes the packet according to the resource field. In fact, this is the most common pattern when sending Phonet "request" packets. In this case, the packet is delivered to whichever endpoint (socket) has registered the resource.

This adds a new table so that Linux processes can register their Phonet sockets to Phonet resources, if they have adequate privileges.

(Namespace support is not implemented at the moment.)

---
 include/net/phonet/phonet.h |    5 ++
 net/phonet/socket.c         |   88 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 93 insertions(+), 0 deletions(-)
include/net/phonet/phonet.h +5 -0
index 7b11407..d5df797 100644
@@ -54,6 +54,11 @@ void pn_sock_hash(struct sock *sk);
 void pn_sock_unhash(struct sock *sk);
 int pn_sock_get_port(struct sock *sk, unsigned short sport);
 
+struct sock *pn_find_sock_by_res(struct net *net, u8 res);
+int pn_sock_bind_res(struct sock *sock, u8 res);
+int pn_sock_unbind_res(struct sock *sk, u8 res);
+void pn_sock_unbind_all_res(struct sock *sk);
+
 int pn_skb_send(struct sock *sk, struct sk_buff *skb,
 		const struct sockaddr_pn *target);
 
net/phonet/socket.c +88 -0

91 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#2 lore raw

PATCH 1/1 Phonet: hook resource routing to userspace via ioctl()'s

From: Rémi Denis-Courmont <[email protected]>

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.

---
 include/linux/phonet.h |    2 ++
 net/phonet/datagram.c  |   13 +++++++++++++
 net/phonet/socket.c    |    1 +
 3 files changed, 16 insertions(+), 0 deletions(-)
include/linux/phonet.h +2 -0
index 76edadf..85e14a8 100644
@@ -47,6 +47,8 @@
 
 /* ioctls */
 #define SIOCPNGETOBJECT		(SIOCPROTOPRIVATE + 0)
+#define SIOCPNADDRESOURCE	(SIOCPROTOPRIVATE + 14)
+#define SIOCPNDELRESOURCE	(SIOCPROTOPRIVATE + 15)
 
 /* Phonet protocol header */
 struct phonethdr {
net/phonet/datagram.c +13 -0
index 1bd38db..2f03238 100644
@@ -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;
net/phonet/socket.c +1 -0
index 4c29a23..d4f41af 100644
@@ -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);
 
Signature · 1 line
1.7.0.4
#3 lore raw

PATCH 1/1 Phonet: look up the resource routing table when forwarding

From: Rémi Denis-Courmont <[email protected]>

---
 net/phonet/af_phonet.c |   17 +++++++++++++++++
 1 files changed, 17 insertions(+), 0 deletions(-)
net/phonet/af_phonet.c +17 -0
index 73aee7f..fd95beb 100644
@@ -251,6 +251,16 @@ int pn_skb_send(struct sock *sk, struct sk_buff *skb,
 	else if (phonet_address_lookup(net, daddr) == 0) {
 		dev = phonet_device_get(net);
 		skb->pkt_type = PACKET_LOOPBACK;
+	} else if (pn_sockaddr_get_object(target) == 0) {
+		/* Resource routing (small race until phonet_rcv()) */
+		struct sock *sk = pn_find_sock_by_res(net,
+							target->spn_resource);
+		if (sk)	{
+			sock_put(sk);
+			dev = phonet_device_get(net);
+			skb->pkt_type = PACKET_LOOPBACK;
+		} else
+			dev = phonet_route_output(net, daddr);
 	} else
 		dev = phonet_route_output(net, daddr);
 
@@ -383,6 +393,13 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
 		goto out;
 	}
 
+	/* resource routing */
+	if (pn_sockaddr_get_object(&sa) == 0) {
+		struct sock *sk = pn_find_sock_by_res(net, sa.spn_resource);
+		if (sk)
+			return sk_receive_skb(sk, skb, 0);
+	}
+
 	/* check if we are the destination */
 	if (phonet_address_lookup(net, pn_sockaddr_get_addr(&sa)) == 0) {
 		/* Phonet packet input */
Signature · 1 line
1.7.0.4
#4 lore raw

PATCH 1/1 Phonet: list subscribed resources via proc_fs

From: Rémi Denis-Courmont <[email protected]>

---
 include/net/phonet/pn_dev.h |    1 +
 net/phonet/pn_dev.c         |    2 +
 net/phonet/socket.c         |   96 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 99 insertions(+), 0 deletions(-)
include/net/phonet/pn_dev.h +1 -0
index 2d16783..13649eb 100644
@@ -57,5 +57,6 @@ struct net_device *phonet_route_output(struct net *net, u8 daddr);
 #define PN_NO_ADDR	0xff
 
 extern const struct file_operations pn_sock_seq_fops;
+extern const struct file_operations pn_res_seq_fops;
 
 #endif
net/phonet/pn_dev.c +2 -0
index d0a4294..947038d 100644
@@ -373,6 +373,7 @@ int __init phonet_device_init(void)
 	if (err)
 		return err;
 
+	proc_net_fops_create(&init_net, "pnresource", 0, &pn_res_seq_fops);
 	register_netdevice_notifier(&phonet_device_notifier);
 	err = phonet_netlink_register();
 	if (err)
@@ -385,6 +386,7 @@ void phonet_device_exit(void)
 	rtnl_unregister_all(PF_PHONET);
 	unregister_netdevice_notifier(&phonet_device_notifier);
 	unregister_pernet_device(&phonet_net_ops);
+	proc_net_remove(&init_net, "pnresource");
 }
 
 int phonet_route_add(struct net_device *dev, u8 daddr)
net/phonet/socket.c +96 -0

99 lines not on this page · raw message

Signature · 1 line
1.7.0.4
#5 lore raw

PATCH 1/1 Phonet: resource routing documentation

From: Rémi Denis-Courmont <[email protected]>

---
 Documentation/networking/phonet.txt |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
Documentation/networking/phonet.txt +16 -0
index 6e8ce09..cf76608 100644
@@ -112,6 +112,22 @@ However, connect() and getpeername() are not supported, as they did
 not seem useful with Phonet usages (could be added easily).
 
 
+Resource subscription
+---------------------
+
+A Phonet datagram socket can be subscribed to any number of 8-bits
+Phonet resources, as follow:
+
+  uint32_t res = 0xXX;
+  ioctl(fd, SIOCPNADDRESOURCE, &res);
+
+Subscription is similarly cancelled using the SIOCPNDELRESOURCE I/O
+control request, or when the socket is closed.
+
+Note that no more than one socket can be subcribed to any given
+resource at a time. If not, ioctl() will return EBUSY.
+
+
 Phonet Pipe protocol
 --------------------
 
Signature · 1 line
1.7.0.4
maintainer
#6 lore raw
In reply to Rémi Denis-Courmont

From: Rémi Denis-Courmont <[email protected]>
Date: Thu, 16 Sep 2010 00:29:35 +0200

Quoted 5 lines

This patch series adds support for implement Phonet services ("servers") on Linux. So far, this was only possible on the Phonet modem attached; i.e. Linux processes could only act as a "client".

Comments welcome. (Or did I again miss the new feature deadline?)

All applied to net-next-2.6, but please properly number your patches in your subject lines next time.