RFC : Wireless Netlink events
Hi, Somebody asked me if it was possible to monitor wireless
configuration change on 802.11 interfaces.
Looking into the kernel, I noticed that RTnetlink was the
prefered way to export events related to interface changes. So, I quickly hacked some RTnetlink Wireless Events, and it basically work the way I want.
Now, I've got some questions :
o Have I done it the right way ? Is there anything I forgot ?
o Is there a way to do a reverse of SIOCGIFINDEX ? If you have
an interface index, how do you get its name ?
o Should I put the full interface name in the event ? That
would make events larger but help query the interface when receiving the event.
o Any other comments ?
My plan is to continue experimenting with this patch a few
days and collect comments, and then do a new update of Wireless Extensions with this patch.
Regards,
Jean
Quoted 18 lines · jt
Hi, Somebody asked me if it was possible to monitor wirelessconfiguration change on 802.11 interfaces.
Looking into the kernel, I noticed that RTnetlink was the
prefered way to export events related to interface changes. So, I quickly hacked some RTnetlink Wireless Events, and it basically work the way I want.Now, I've got some questions :
o Have I done it the right way ? Is there anything I forgot ?
o Is there a way to do a reverse of SIOCGIFINDEX ? If you have
an interface index, how do you get its name ?
o Should I put the full interface name in the event ? That
would make events larger but help query the interface when receiving the event.
o Any other comments ?
Quoted 6 lines
My plan is to continue experimenting with this patch a few
days and collect comments, and then do a new update of Wireless Extensions with this patch.
Regards,Jean
I'll probably get more comments if I attach the patch, isn't
it ?
Jean
include/linux/wireless.h renamed from include/linux/wireless.w12.h +23 -0
@@ -567,4 +567,27 @@ struct iw_priv_args char name[IFNAMSIZ]; /* Name of the extension */ }; +/* ---------------------- RTNETLINK SUPPORT ---------------------- */ +/* +* RTnetlink (or routing socket) is a raw socket where a user app can +* listen to various selected events from the netowrking layer. +*/ + +/* +* This is how a Wireless Event will appear on this socket... +* Apart from the generic stuff, we just pass the IOCTL number of +* the command triggering the event. The user can then just query +* (the same IOCTL | 0x1) to get the new state of the interface... +* This way, we can keep our events short and efficients... +*/ +struct iwinfomsg +{ +__u8 ifi_family; +__u8 __ifi_pad; +__u16 ifi_type;/* ARPHRD_* */ +__s32 ifi_index;/* Link index */ +__u32 iwi_command;/* Wireless IOCTL */ +/* Maybe I should add 'char name[IFNAMSIZ]' around here... */ +}; +#endif /* _LINUX_WIRELESS_H */
include/linux/rtnetlink.h renamed from include/linux/rtnetlink.w12.h +9 -1
@@ -46,7 +46,10 @@#define RTM_DELTFILTER (RTM_BASE+29)#define RTM_GETTFILTER (RTM_BASE+30) -#define RTM_MAX (RTM_BASE+31) +/* Reconfiguration of a Wireless Interface - see wireless.h - Jean II */ +#define RTM_SETWIRELESS (RTM_BASE+32) + +#define RTM_MAX (RTM_BASE+33)/* Generic structure for encapsulation optional route information.
@@ -568,9 +571,14 @@ extern void __rta_fill(struct sk_buff *sextern void rtmsg_ifinfo (int type,struct net_device *dev,unsigned change); +#if defined(CONFIG_NET_RADIO ) || defined(CONFIG_NET_PCMCIA_RADIO ) +extern void rtmsg_iwinfo (int type,struct net_device *dev,unsigned command); +#endif /* CONFIG_NET_RADIO || CONFIG_NET_PCMCIA_RADIO */ +#else #define rtmsg_ifinfo (a,b,c) do { } while (0) +#define rtmsg_iwinfo (a,b,c) do { } while (0)#endif
net/core/dev.c renamed from net/core/dev.w12.c +14 -1
@@ -2242,7 +2242,20 @@ static int dev_ifsioc(struct ifreq *ifr,if (dev->do_ioctl) {if (!netif_device_present (dev))return -ENODEV ; -return dev->do_ioctl (dev, ifr, cmd); +/* Ask the driver to do its job */ + err = dev->do_ioctl (dev, ifr, cmd); +/* If the device is up, we generate +* a Wireless RTnetlink event on a few +* interesting configuration change */ +if ((!err) && (dev->flags &IFF_UP ) && + ((cmd ==SIOCSIWNWID ) || + (cmd ==SIOCSIWESSID ) || + (cmd ==SIOCSIWMODE ) || + (cmd ==SIOCSIWFREQ ))) { +rtmsg_iwinfo (RTM_SETWIRELESS , + dev, cmd); + } +return err; }return -EOPNOTSUPP ; }
net/core/rtnetlink.c renamed from net/core/rtnetlink.w12.c +34 -0
@@ -49,6 +49,9 @@#include <net/udp.h> #include <net/sock.h> #include <net/pkt_sched.h> +#if defined(CONFIG_NET_RADIO ) || defined(CONFIG_NET_PCMCIA_RADIO ) +#include <linux/wireless.h> /* Note : will define WIRELESS_EXT */ +#endif /* CONFIG_NET_RADIO || CONFIG_NET_PCMCIA_RADIO */ DECLARE_MUTEX (rtnl_sem);
@@ -266,6 +269,37 @@ void rtmsg_ifinfo(int type, struct net_dNETLINK_CB (skb).dst_groups =RTMGRP_LINK ;netlink_broadcast (rtnl, skb,0 ,RTMGRP_LINK ,GFP_KERNEL ); } + +#ifdef WIRELESS_EXT +void rtmsg_iwinfo (int type,struct net_device *dev,unsigned command) +{ +struct sk_buff *skb; +int size =NLMSG_GOODSIZE ; +struct iwinfomsg *r;/* Defined in wireless.h */ +struct nlmsghdr *nlh; + + skb =alloc_skb (size,GFP_KERNEL ); +if (!skb) +return ; + +/* Set up our event */ + nlh =NLMSG_PUT (skb,0 ,0 , type,sizeof (*r)); + r =NLMSG_DATA (nlh); + r->ifi_family =AF_UNSPEC ; + r->ifi_type = dev->type; + r->ifi_index = dev->ifindex; + r->iwi_command = command; + +/* Send it to all listeners */ +NETLINK_CB (skb).dst_groups =RTMGRP_LINK ; +netlink_broadcast (rtnl, skb,0 ,RTMGRP_LINK ,GFP_KERNEL ); + +return ; +nlmsg_failure: +kfree_skb (skb); +return ; +} +#endif /* WIRELESS_EXT */ static int rtnetlink_done (struct netlink_callback *cb) {
Hello!
Quoted 2 lines
o Is there a way to do a reverse of SIOCGIFINDEX ? If you have
an interface index, how do you get its name ?
SIOCGIFNAME.
But this does not matter, applications using rtnetlink should not use these ioctls. They have all the information from rtnetlink.
Quoted 3 lines
o Should I put the full interface name in the event ? That
would make events larger but help query the interface when receiving the event.
Never. They are known from context.
Quoted 1 line
o Any other comments ?
I am not sure that it is right and in right place. I would not create one more message type for such... mmm... special case.
Probably, you could add a new attribute to RTM_*LINK sort of IFLA_MISC and to send ifinfo messages.
But I see logical flaw: no way to _retrieve_ information about state on demand. Hence no right application cannot rely only on these messages. Hence you should go all the way and to allow to dump this and, probably, to add statistics shown in /proc/net/wireless.
Alexey
Quoted 6 lines · On Wed, Oct 10, 2001 at 09:49:52PM +0400, [email protected] wrote:
Hello!
Quoted 2 lines
o Is there a way to do a reverse of SIOCGIFINDEX ? If you have
an interface index, how do you get its name ?SIOCGIFNAME.
Err... I feel stupid...
Quoted 2 lines
But this does not matter, applications using rtnetlink should not use these ioctls. They have all the information from rtnetlink.
That would not be the case of Wireless Events, the event would
just contain the type of change and the interface index. See reasons for that below.
Quoted 6 lines
Quoted 1 line
o Any other comments ?
I am not sure that it is right and in right place. I would not create one more message type for such... mmm... special case.
Probably, you could add a new attribute to RTM_*LINK sort ofIFLA_MISCand to send ifinfo messages.
The problem is that I need to propagate the "command" field
(the ioctl number leading to the event), and there is no space for that in the ifinfo structure. None of the flags in the ifinfo structure would change when those ioctls are called.
I don't mind adding a new attribute to struct ifinfo, but that
will break existing netlink apps (unless I missed something).
Quoted 2 lines
But I see logical flaw: no way to _retrieve_ information about state on demand.
Hu ? Just query any of the Wireless IOCTLs, and you get the
info you need. Check iwconfig.c on how to do that. I don't see the need of duplicating the ioctl functionality in netlink, especially that those ioctl can be big (encryption key, iwspy), complex (power management) and have a variable geometry.
The IOCTLs have been working to satisfaction, and I don't want
to duplicate this code. What I want is just a channel to propagate an event.
Quoted 3 lines
Hence no right application cannot rely only on these messages. Hence you should go all the way and to allow to dump this and, probably, to add statistics shown in
/proc/net/wireless.
On the contrary. The app get the event and can query the
related ioctl to see what has changed. I want those event to be *very* lightweigth so that it is minimal overhead for the vast majority of applications that could not care less about them and will end up discarding them anyway.
The whole Wireless configuration is in the order of 624 bytes
(including /proc/net/wireless, excluding iwspy/aplist and assuming only one encryption key). You surely don't want me to push that with every event ?
The idea is like select() + read(). Select gives you the basic
event, you need to use read to get the data.
Quoted 1 line
Alexey
It seems to me that what you are implying is that RTnetlink is
not the right place for me to propagate events. Any idea of what mechanism might be better to propagate those events ? Maybe I should create my own event channel.
Thanks for the comments !
Jean
Hello!
Quoted 3 lines
That would not be the case of Wireless Events, the event would
just contain the type of change and the interface index. See reasons for that below.
See below. :-)
Quoted 11 lines
Quoted 4 lines
I am not sure that it is right and in right place. I would not create one more message type for such... mmm... special case.
Probably, you could add a new attribute to RTM_*LINK sort ofIFLA_MISCand to send ifinfo messages.The problem is that I need to propagate the "command" field
(the ioctl number leading to the event), and there is no space for that in the ifinfo structure. None of the flags in the ifinfo structure would change when those ioctls are called.
I don't mind adding a new attribute to struct ifinfo, but that
will break existing netlink apps (unless I missed something).
You missed.
All the rtnetlink messages contain a minimal fix part, followed by variable attributes. New attributes can be added any time not breaking anything.
Quoted 1 line
Hu ? Just query any of the Wireless IOCTLs,
OK. I see.
Quoted 4 lines
The whole Wireless configuration is in the order of 624 bytes
(including/proc/net/wireless, excluding iwspy/aplist and assuming only one encryption key). You surely don't want me to push that with every event ?
624? Not a big deal.
Quoted 2 lines
The idea is like
select()+read(). Select gives you the basic
event, you need to use read to get the data.
Sorry, I am inclined against issuing lots of sequences of ioctls to get information. This approach is fragile because you never
get a self-consistent state when state is subject to change.
Logic of rtnetlink is a bit different: you get atomic pieces of information, which are meaningfull itself.
Quoted 2 lines
It seems to me that what you are implying is that RTnetlink is
not the right place for me to propagate events.
Not at all.
But approach which you outlined really contradicts to logic of rtnetlink yet. It is not a select(), it is real read(). :-)
Quoted 3 lines
Any idea of what
mechanism might be better to propagate those events ? Maybe I should create my own event channel.
Probably. There lots of unused channels. Well, choose the best approach.
Alexey
Quoted 1 line · On Wed, Oct 10, 2001 at 10:48:22PM +0400, [email protected] wrote:
Hello!
Second try...
I'm now using RTM_NEWLINK and pass the full and complete
wireless event in a RTA structure (therefore, there is no need to query the ioctl after the event).
Ready for more comments...
Jean
include/linux/wireless.h renamed from include/linux/wireless.w12.h +17 -0
@@ -567,4 +567,21 @@ struct iw_priv_args char name[IFNAMSIZ]; /* Name of the extension */ }; +/* ---------------------- RTNETLINK SUPPORT ---------------------- */ +/* +* RTnetlink (or routing socket) is a raw socket where a user app can +* listen to various selected events from the netowrking layer. +*/ + +/* +* This is how a Wireless Event will appear on this socket... +* This will be an optional field (RTA) of the NEWLINK message +*/ +struct rta_ifla_wireless +{ +__u32 command;/* Wireless IOCTL */ +struct iwreq data;/* IOCTL fixed payload */ +char option[0 ];/* Optional data */ +}; +#endif /* _LINUX_WIRELESS_H */
include/linux/rtnetlink.h renamed from include/linux/rtnetlink.w12.h +10 -2
@@ -440,12 +440,14 @@ enum#define IFLA_COST IFLA_COST IFLA_PRIORITY,#define IFLA_PRIORITY IFLA_PRIORITY - IFLA_MASTER + IFLA_MASTER,#define IFLA_MASTER IFLA_MASTER + IFLA_WIRELESS /* Wireless Extension event - see wireless.h */ +#define IFLA_WIRELESS IFLA_WIRELESS }; -#define IFLA_MAX IFLA_MASTER +#define IFLA_MAX IFLA_WIRELESS#define IFLA_RTA (r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))#define IFLA_PAYLOAD (n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
@@ -568,9 +570,15 @@ extern void __rta_fill(struct sk_buff *sextern void rtmsg_ifinfo (int type,struct net_device *dev,unsigned change); +#if defined(CONFIG_NET_RADIO ) || defined(CONFIG_NET_PCMCIA_RADIO ) +extern void rtmsg_iwinfo (int type,struct net_device *dev,struct ifreq *ifr, +unsigned command); +#endif /* CONFIG_NET_RADIO || CONFIG_NET_PCMCIA_RADIO */ +#else #define rtmsg_ifinfo (a,b,c) do { } while (0) +#define rtmsg_iwinfo (a,b,c) do { } while (0)#endif
net/core/dev.c renamed from net/core/dev.w12.c +15 -1
@@ -2242,7 +2242,21 @@ static int dev_ifsioc(struct ifreq *ifr,if (dev->do_ioctl) {if (!netif_device_present (dev))return -ENODEV ; -return dev->do_ioctl (dev, ifr, cmd); +/* Ask the driver to do its job */ + err = dev->do_ioctl (dev, ifr, cmd); +/* If the device is up, we generate +* a Wireless RTnetlink event on a few +* interesting configuration change */ +if ((!err) && (dev->flags &IFF_UP ) && + ((cmd ==SIOCSIWNWID ) || + (cmd ==SIOCSIWESSID ) || + (cmd ==SIOCSIWMODE ) || + (cmd ==SIOCSIWFREQ ) || + (cmd ==SIOCSIWENCODE ))) { +rtmsg_iwinfo (RTM_NEWLINK , + dev, ifr, cmd); + } +return err; }return -EOPNOTSUPP ; }
net/core/rtnetlink.c renamed from net/core/rtnetlink.w12.c +94 -0
106 lines not on this page · raw message