Phonet: back-end for autoconfigured addresses
Subsystems (4)
PATCH 1/2 Phonet: back-end for autoconfigured addresses
From: Rémi Denis-Courmont <[email protected]>
In some cases, the network device driver knows what layer-3 address the device should have. This adds support for the Phonet stack to automatically request from the driver and add that address to the network device.
--- include/linux/phonet.h | 17 +++++++++++++++++ net/phonet/pn_dev.c | 26 +++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletions(-)
include/linux/phonet.h +17 -0
@@ -170,4 +170,21 @@ static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn) return spn->spn_resource; } +/* Phonet device ioctl requests */ +#ifdef __KERNEL__ +#define SIOCPNGAUTOCONF (SIOCDEVPRIVATE + 0) + +struct if_phonet_autoconf { +uint8_t device; +}; + +struct if_phonet_req { +char ifr_phonet_name[16 ]; +union { +struct if_phonet_autoconf ifru_phonet_autoconf; + } ifr_ifru; +}; +#define ifr_phonet_autoconf ifr_ifru.ifru_phonet_autoconf +#endif /* __KERNEL__ */ +#endif
net/phonet/pn_dev.c +25 -1
@@ -28,6 +28,7 @@#include <linux/netdevice.h> #include <linux/phonet.h> #include <linux/proc_fs.h> +#include <linux/if_arp.h> #include <net/sock.h> #include <net/netns/generic.h> #include <net/phonet/pn_dev.h>
@@ -195,14 +196,37 @@ found:return err; } +/* automatically configure a Phonet device, if supported */ +static int phonet_device_autoconf (struct net_device *dev) +{ +struct if_phonet_req req; +int ret; + +if (!dev->netdev_ops->ndo_do_ioctl) +return -EOPNOTSUPP ; + + ret = dev->netdev_ops->ndo_do_ioctl (dev, (struct ifreq *)&req, +SIOCPNGAUTOCONF ); +if (ret <0 ) +return ret; +return phonet_address_add (dev, req.ifr_phonet_autoconf.device); +} +/* notify Phonet of device events */ static int phonet_device_notify (struct notifier_block *me,unsigned long what,void *arg) {struct net_device *dev = arg; -if (what ==NETDEV_UNREGISTER ) +switch (what) { +case NETDEV_REGISTER : +if (dev->type ==ARPHRD_PHONET ) +phonet_device_autoconf (dev); +break ; +case NETDEV_UNREGISTER :phonet_device_destroy (dev); +break ; + }return 0 ; }
Signature · 1 line
1.6.0.4
PATCH 2/2 cdc-phonet: autoconfigure Phonet address
From: Rémi Denis-Courmont <[email protected]>
--- drivers/net/usb/cdc-phonet.c | 15 +++++++++++++++ include/linux/phonet.h | 3 +++ 2 files changed, 18 insertions(+), 0 deletions(-)
drivers/net/usb/cdc-phonet.c +15 -0
@@ -27,6 +27,7 @@#include <linux/netdevice.h> #include <linux/if_arp.h> #include <linux/if_phonet.h> +#include <linux/phonet.h> #define PN_MEDIA_USB 0x1B
@@ -256,6 +257,19 @@ static int usbpn_close(struct net_device *dev)return usb_set_interface (pnd->usb, num, !pnd->active_setting); } +static int usbpn_ioctl (struct net_device *dev,struct ifreq *ifr,int cmd) +{ +struct if_phonet_req *req = (struct if_phonet_req *)ifr; + +switch (cmd) { +case SIOCPNGAUTOCONF : + req->ifr_phonet_autoconf.device =PN_DEV_PC ; +printk (KERN_CRIT "device is PN_DEV_PC\n" ); +return 0 ; + } +return -ENOIOCTLCMD ; +} +static int usbpn_set_mtu (struct net_device *dev,int new_mtu) {if ((new_mtu <PHONET_MIN_MTU ) || (new_mtu >PHONET_MAX_MTU ))
@@ -269,6 +283,7 @@ static const struct net_device_ops usbpn_ops = { .ndo_open = usbpn_open, .ndo_stop = usbpn_close, .ndo_start_xmit = usbpn_xmit, + .ndo_do_ioctl = usbpn_ioctl, .ndo_change_mtu = usbpn_set_mtu, };
include/linux/phonet.h +3 -0
@@ -99,6 +99,9 @@ struct sockaddr_pn {__u8 spn_zero[sizeof (struct sockaddr ) -sizeof (sa_family_t) -3 ]; } __attribute__ ((packed)); +/* Well known address */ +#define PN_DEV_PC 0x10 +static inline __u16 pn_object (__u8 addr,__u16 port) {return (addr <<8 ) | (port &0x3ff );
Signature · 1 line
1.6.0.4
Re: [PATCH 2/2] cdc-phonet: autoconfigure Phonet address
Hi Remi,
Quoted 23 lines
drivers/net/usb/cdc-phonet.c | 15 +++++++++++++++ include/linux/phonet.h | 3 +++ 2 files changed, 18 insertions(+), 0 deletions(-)drivers/net/usb/cdc-phonet.c +4
-0@@ -27,6 +27,7 @@#include <linux/netdevice.h> #include <linux/if_arp.h> #include <linux/if_phonet.h> +#include <linux/phonet.h> #define PN_MEDIA_USB 0x1B@@ -256,6 +257,19 @@ static int usbpn_close(struct net_device *dev)return usb_set_interface (pnd->usb, num, !pnd->active_setting); } +static int usbpn_ioctl (struct net_device *dev,struct ifreq *ifr,int cmd) +{ +struct if_phonet_req *req = (struct if_phonet_req *)ifr;
drivers/net/usb/cdc-phonet.c static int usbpn_close(struct net_device *dev) · line 272
Quoted 10 lines
drivers/net/usb/cdc-phonet.c +10
-0+ +switch (cmd) { +case SIOCPNGAUTOCONF : + req->ifr_phonet_autoconf.device =PN_DEV_PC ; +printk (KERN_CRIT "device is PN_DEV_PC\n" ); +return 0 ; + } +return -ENOIOCTLCMD ; +} +
am I understanding this correctly, that even for the USB ones we still have to execute that ioctl() and can not just auto configure them all the time? For the USB ones, I would expect to should plug them in and they are getting configured right away.
Regards
Marcel
Re: [PATCH 2/2] cdc-phonet: autoconfigure Phonet address
Quoted 4 lines · Marcel Holtmann
am I understanding this correctly, that even for the USB ones we still have to execute that
ioctl()and can not just auto configure them all the time? For the USB ones, I would expect to should plug them in and they are getting configured right away.
The other patch makes the stack use the ioctl() internally. But now I see that I forgot some debug statement :(
Still, something needs to ifconfig up/ip link set up.
Signature · 1 line
Rémi Denis-Courmont
Re: [PATCH 2/2] cdc-phonet: autoconfigure Phonet address
Hi Remi,
Quoted 9 lines
Quoted 4 lines
am I understanding this correctly, that even for the USB ones we still have to execute that
ioctl()and can not just auto configure them all the time? For the USB ones, I would expect to should plug them in and they are getting configured right away.The other patch makes the stack use the
ioctl()internally. But now I see that I forgot some debug statement :(Still, something needs to ifconfig up/ip link set up.
the ifup/ifdown is fine. And if the addresses get set when I plug the device in, that looks good to me.
Regards
Marcel
Re: [PATCH 2/2] cdc-phonet: autoconfigure Phonet address
In reply to Rémi Denis-CourmontFrom: Rémi Denis-Courmont <[email protected]>
Date: Wed, 9 Sep 2009 13:00:06 +0300
Quoted 3 lines
From: Rémi Denis-Courmont <[email protected]>
Signed-off-by Rémi Denis-Courmont <[email protected]>
Applied.
Re: [PATCH 2/2] cdc-phonet: autoconfigure Phonet address
Le vendredi 11 septembre 2009 22:38:35 David Miller, vous avez écrit :
Quoted 8 lines
From: Rémi Denis-Courmont <[email protected]>
Date: Wed, 9 Sep 2009 13:00:06 +0300Quoted 3 lines
From: Rémi Denis-Courmont <[email protected]>
Signed-off-by Rémi Denis-Courmont <[email protected]>Applied.
THanks and oops, I just had an updated patch set coming. I guess I will rebase it then.
Signature · 2 lines
Rémi Denis-Courmont http://www.remlab.net/
From: Rémi Denis-Courmont <[email protected]>
Date: Wed, 9 Sep 2009 13:00:05 +0300
Quoted 8 lines
From: Rémi Denis-Courmont <[email protected]>
In some cases, the network device driver knows what layer-3 address the device should have. This adds support for the Phonet stack to automatically request from the driver and add that address to the network device.
Signed-off-by Rémi Denis-Courmont <[email protected]>
Applied.