Phonet: basic routing support
Subsystems (3)
cover Phonet: basic routing support
Hello,
This small patch series adds simplistic routing support to the Phonet stack. Usually, there is an "upstream" interface to the Phonet modem. However, if Linux runs on an embedded USB gadget, we have two interfaces in the same namespace:
- an internal interface to the modem (e.g. OMAP SSI bus), and
- an external interface to the USB host (CDC Phonet).
Patches follow.
include/linux/phonet.h | 1 include/net/phonet/pn_dev.h | 6 ++ net/phonet/af_phonet.c | 55 ++++++++++++++++-- net/phonet/pn_dev.c | 131 +++++++++++++++++++++++++++++++++++++++++--- net/phonet/pn_netlink.c | 130 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 312 insertions(+), 11 deletions(-)
I am not sure if feature patches are still allowed. If not, I can just repost this at a more convenient time.
Signature · 1 line
Rémi Denis-Courmont
PATCH 1/5 Phonet: error on broadcast sending (unimplemented)
From: Rémi Denis-Courmont <[email protected]>
From: Rémi Denis-Courmont <[email protected]>
--- include/linux/phonet.h | 1 + net/phonet/af_phonet.c | 6 ++++++ 2 files changed, 7 insertions(+), 0 deletions(-)
include/linux/phonet.h +1 -0
@@ -38,6 +38,7 @@#define PNPIPE_IFINDEX 2#define PNADDR_ANY 0 +#define PNADDR_BROADCAST 0xFC#define PNPORT_RESOURCE_ROUTING 0/* Values for PNPIPE_ENCAP option */
net/phonet/af_phonet.c +6 -0
@@ -168,6 +168,12 @@ static int pn_send(struct sk_buff *skb, struct net_device *dev, goto drop; } +/* Broadcast sending is not implemented */ +if (pn_addr (dst) ==PNADDR_BROADCAST ) { + err = -EOPNOTSUPP ; + goto drop; + } +skb_reset_transport_header (skb);WARN_ON (skb_headroom (skb) &1 );/* HW assumes word alignment */ skb_push (skb,sizeof (struct phonethdr ));
Signature · 1 line
1.6.0.4
PATCH 2/5 Phonet: routing table backend
From: Rémi Denis-Courmont <[email protected]>
From: Rémi Denis-Courmont <[email protected]>
The Phonet "universe" only has 64 addresses, so we keep a trivial flat routing table.
--- include/net/phonet/pn_dev.h | 5 ++ net/phonet/pn_dev.c | 100 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 99 insertions(+), 6 deletions(-)
include/net/phonet/pn_dev.h +5 -0
@@ -47,6 +47,11 @@ u8 phonet_address_get(struct net_device *dev, u8 addr);int phonet_address_lookup (struct net *net,u8 addr);void phonet_address_notify (int event,struct net_device *dev,u8 addr); +int phonet_route_add (struct net_device *dev,u8 daddr); +int phonet_route_del (struct net_device *dev,u8 daddr); +struct net_device *phonet_route_get (struct net *net,u8 daddr); +struct net_device *phonet_route_output (struct net *net,u8 daddr); +#define PN_NO_ADDR 0xffextern const struct file_operations pn_sock_seq_fops;
net/phonet/pn_dev.c +94 -6
140 lines not on this page · raw message
Signature · 1 line
1.6.0.4
PATCH 3/5 Phonet: routing table Netlink interface
From: Rémi Denis-Courmont <[email protected]>
From: Rémi Denis-Courmont <[email protected]>
--- include/net/phonet/pn_dev.h | 1 + net/phonet/pn_dev.c | 31 ++++++++++ net/phonet/pn_netlink.c | 130 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+), 0 deletions(-)
include/net/phonet/pn_dev.h +1 -0
@@ -49,6 +49,7 @@ void phonet_address_notify(int event, struct net_device *dev, u8 addr);int phonet_route_add (struct net_device *dev,u8 daddr);int phonet_route_del (struct net_device *dev,u8 daddr); +void rtm_phonet_notify (int event,struct net_device *dev,u8 dst);struct net_device *phonet_route_get (struct net *net,u8 daddr);struct net_device *phonet_route_output (struct net *net,u8 daddr);
net/phonet/pn_dev.c +31 -0
@@ -240,6 +240,27 @@ static int phonet_device_autoconf(struct net_device *dev)return 0 ; } +static void phonet_route_autodel (struct net_device *dev) +{ +struct phonet_net *pnn =net_generic (dev_net (dev), phonet_net_id); +unsigned i; +DECLARE_BITMAP (deleted,64 ); + +/* Remove left-over Phonet routes */ +bitmap_zero (deleted,64 ); +spin_lock_bh (&pnn->routes.lock); +for (i =0 ; i <64 ; i++) +if (dev == pnn->routes.table[i]) { +set_bit (i, deleted); + pnn->routes.table[i] =NULL ; +dev_put (dev); + } +spin_unlock_bh (&pnn->routes.lock); +for (i =find_first_bit (deleted,64 ); i <64 ; + i =find_next_bit (deleted,64 , i +1 )) +rtm_phonet_notify (RTM_DELROUTE , dev, i); +} +/* notify Phonet of device events */ static int phonet_device_notify (struct notifier_block *me,unsigned long what,void *arg)
@@ -253,6 +274,7 @@ static int phonet_device_notify(struct notifier_block *me, unsigned long what,break ;case NETDEV_UNREGISTER :phonet_device_destroy (dev); +phonet_route_autodel (dev);break ; }return 0 ;
@@ -287,10 +309,19 @@ static void phonet_exit_net(struct net *net) {struct phonet_net *pnn =net_generic (net, phonet_net_id);struct net_device *dev; +unsigned i;rtnl_lock ();for_each_netdev (net, dev)phonet_device_destroy (dev); + +for (i =0 ; i <64 ; i++) { + dev = pnn->routes.table[i]; +if (dev) { +rtm_phonet_notify (RTM_DELROUTE , dev, i); +dev_put (dev); + } + }rtnl_unlock ();proc_net_remove (net,"phonet" );
net/phonet/pn_netlink.c +130 -0
147 lines not on this page · raw message
Signature · 1 line
1.6.0.4
PATCH 4/5 Phonet: route outgoing packets
From: Rémi Denis-Courmont <[email protected]>
From: Rémi Denis-Courmont <[email protected]>
--- net/phonet/af_phonet.c | 17 ++++++++++++----- 1 files changed, 12 insertions(+), 5 deletions(-)
net/phonet/af_phonet.c +12 -5
@@ -190,9 +190,8 @@ static int pn_send(struct sk_buff *skb, struct net_device *dev, skb->priority =0 ; skb->dev = dev; -if (pn_addr (src) ==pn_addr (dst)) { +if (skb->pkt_type ==PACKET_LOOPBACK ) {skb_reset_mac_header (skb); - skb->pkt_type =PACKET_LOOPBACK ;skb_orphan (skb);if (irq)netif_rx (skb);
@@ -222,6 +221,9 @@ static int pn_raw_send(const void *data, int len, struct net_device *dev,if (skb ==NULL )return -ENOMEM ; +if (phonet_address_lookup (dev_net (dev),pn_addr (dst)) ==0 ) + skb->pkt_type =PACKET_LOOPBACK ; +skb_reserve (skb,MAX_PHONET_HEADER );__skb_put (skb, len);skb_copy_to_linear_data (skb, data, len);
@@ -235,6 +237,7 @@ static int pn_raw_send(const void *data, int len, struct net_device *dev,int pn_skb_send (struct sock *sk,struct sk_buff *skb,const struct sockaddr_pn *target) { +struct net *net =sock_net (sk);struct net_device *dev;struct pn_sock *pn =pn_sk (sk);int err;
@@ -243,9 +246,13 @@ int pn_skb_send(struct sock *sk, struct sk_buff *skb, err = -EHOSTUNREACH ;if (sk->sk_bound_dev_if) - dev =dev_get_by_index (sock_net (sk), sk->sk_bound_dev_if); -else - dev =phonet_device_get (sock_net (sk)); + dev =dev_get_by_index (net, sk->sk_bound_dev_if); +else if (phonet_address_lookup (net, daddr) ==0 ) { + dev =phonet_device_get (net); + skb->pkt_type =PACKET_LOOPBACK ; + }else + dev =phonet_route_output (net, daddr); +if (!dev || !(dev->flags &IFF_UP )) goto drop;
Signature · 1 line
1.6.0.4
PATCH 5/5 Phonet: forward incoming packets
From: Rémi Denis-Courmont <[email protected]>
From: Rémi Denis-Courmont <[email protected]>
--- net/phonet/af_phonet.c | 32 ++++++++++++++++++++++++++++++++ 1 files changed, 32 insertions(+), 0 deletions(-)
net/phonet/af_phonet.c +32 -0
@@ -394,8 +394,40 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,send_obj_unreachable (skb);send_reset_indications (skb); } + }else if (unlikely (skb->pkt_type ==PACKET_LOOPBACK )) + goto out;/* Race between address deletion and loopback */ +else { +/* Phonet packet routing */ +struct net_device *out_dev; + + out_dev =phonet_route_output (net,pn_sockaddr_get_addr (&sa)); +if (!out_dev) { +LIMIT_NETDEBUG (KERN_WARNING "No Phonet route to %02X\n" , +pn_sockaddr_get_addr (&sa)); + goto out; + } + +__skb_push (skb,sizeof (struct phonethdr )); + skb->dev = out_dev; +if (out_dev == dev) { +LIMIT_NETDEBUG (KERN_ERR "Phonet loop to %02X on %s\n" , +pn_sockaddr_get_addr (&sa), dev->name); + goto out_dev; + } +/* Some drivers (e.g. TUN) do not allocate HW header space */ +if (skb_cow_head (skb, out_dev->hard_header_len)) + goto out_dev; + +if (dev_hard_header (skb, out_dev,ETH_P_PHONET ,NULL ,NULL , + skb->len) <0 ) + goto out_dev; +dev_queue_xmit (skb); +dev_put (out_dev); +return NET_RX_SUCCESS ; } +out_dev: +dev_put (skb->dev); out:kfree_skb (skb);return NET_RX_DROP ;
Signature · 1 line
1.6.0.4
David Miller
maintainerFrom: Rémi Denis-Courmont <[email protected]>
Date: Tue, 15 Sep 2009 13:30:19 +0200
Quoted 2 lines
I am not sure if feature patches are still allowed. If not, I can just repost this at a more convenient time.
Please resend these when net-next-2.6 opens back up.
Thank you.