2002-10-21 11:11:59

by David Woodhouse

[permalink] [raw]
Subject: rtnetlink interface state monitoring problems.

I'm playing with userspace applications which want to monitor the status of
IrDA and Bluetooth devices. Rather than polling for the interface state
(this is a handheld device and polling wastes CPU and battery), I want to
use netlink.

I have two problems:

1. I appear to need CAP_NET_ADMIN to bind to the netlink groups which give
me this information. I can poll for it just fine, but need
elevated privs to be notified. Why is this, and is there a workaround?

2. Even root doesn't get notification of state changes for Bluetooth
interfaces, because they're not treated as 'normal' network devices
like IrDA devices are. I can see the logic behind that -- by why
is it done differently from IrDA? Is there a way to get notification
of BT interface state changes?


--
dwmw2



2002-10-21 13:05:43

by jamal

[permalink] [raw]
Subject: Re: rtnetlink interface state monitoring problems.



On Mon, 21 Oct 2002, David Woodhouse wrote:

> I'm playing with userspace applications which want to monitor the status of
> IrDA and Bluetooth devices. Rather than polling for the interface state
> (this is a handheld device and polling wastes CPU and battery), I want to
> use netlink.
>
> I have two problems:
>
> 1. I appear to need CAP_NET_ADMIN to bind to the netlink groups which give
> me this information. I can poll for it just fine, but need
> elevated privs to be notified. Why is this, and is there a workaround?
>

Alexey should be able to give you a better comment.
If you can get the status via ioctl there should be no reason why you
shouldnt get it via netlink. The change maybe a little involved
(look at:net/netlink/af_netlink.c::netlink_bind()) since
there are some valid reasons to block non-admin from receiving certain
messages. I think the LSM people may have been trying to do this, cant
remember details.

> 2. Even root doesn't get notification of state changes for Bluetooth
> interfaces, because they're not treated as 'normal' network devices
> like IrDA devices are. I can see the logic behind that -- by why
> is it done differently from IrDA? Is there a way to get notification
> of BT interface state changes?

I cant see anything on netlink and irda; i am also not very familiar with
either IrDA or Bluetooth.
Regardless, you dont need to be a net device to use netlink. Its a
messaging system and you can use it both within the kernel as well as
kernel<->userspace. If you get stuck writting the interface ping me
privately.

cheers,
jamal

2002-10-21 13:42:07

by James Morris

[permalink] [raw]
Subject: Re: rtnetlink interface state monitoring problems.

On Mon, 21 Oct 2002, James Morris wrote:

> Andi Kleen implemented a simple and effective workaround this for 2.4
> which has gone into the tree (see netlink_set_nonroot() in rtnetlink.c).
>

Forgot to add that it might be possible to get Andi's solution into 2.6.


- James
--
James Morris
<[email protected]>


2002-10-21 13:40:31

by James Morris

[permalink] [raw]
Subject: Re: rtnetlink interface state monitoring problems.

On Mon, 21 Oct 2002, David Woodhouse wrote:

> 1. I appear to need CAP_NET_ADMIN to bind to the netlink groups which give
> me this information. I can poll for it just fine, but need
> elevated privs to be notified. Why is this, and is there a workaround?

Andi Kleen implemented a simple and effective workaround this for 2.4
which has gone into the tree (see netlink_set_nonroot() in rtnetlink.c).

Another more complicated solution was partially developed for 2.5, but is
unlikely to make it in by Halloween.


- James
--
James Morris
<[email protected]>


2002-10-21 16:50:27

by David S. Miller

[permalink] [raw]
Subject: Re: rtnetlink interface state monitoring problems.

On Mon, 2002-10-21 at 06:48, James Morris wrote:
> Forgot to add that it might be possible to get Andi's solution into 2.6.

Send me the patch for 2.5.x

It not being there is by accident, usually when I make a 2.4.x
patch I do 2.5.x in parallel.

2002-10-21 18:52:23

by David Woodhouse

[permalink] [raw]
Subject: Re: rtnetlink interface state monitoring problems.


[email protected] said:
> I cant see anything on netlink and irda; i am also not very familiar
> with either IrDA or Bluetooth. Regardless, you dont need to be a net
> device to use netlink.

IrDA devices are network devices. The core network code sends a RTM_NETLINK
message when they go up or down. All is well, and once the permission fix
gets into the kernel I'm using, my irda monitor applet no longer needs to
poll the state of the interface.

But Bluetooth devices are not network devices, it seems. There exists no
current mechanism for notifying anyone of state changes. Should we invent a
new method of notification using netlink, or should Bluetooth interfaces in
fact be normal network devices just like IrDA devices are?

--
dwmw2


2002-10-22 17:10:21

by Jean Tourrilhes

[permalink] [raw]
Subject: Re: rtnetlink interface state monitoring problems.

David Woodhouse wrote :
>
> IrDA devices are network devices. The core network code sends a RTM_NETLINK
> message when they go up or down. All is well, and once the permission fix
> gets into the kernel I'm using, my irda monitor applet no longer needs to
> poll the state of the interface.

Actually, I'm not 100% happy with the IrDA situation. I would
not mind someone exporting more events to RtNetlink, very similar to
the functionality/events I already provide in the IrNET control
channel (discovery/expiry/link blocked/...).
Note that if you are only interested in IrNET, then the IrNET
control channel gives you everything you need, and you don't really
need to use RtNetlink. Personally, I think the future of IrDA is
IrNET, so that's why I don't bother with the rest.
In any case, send me a link to you applet, I'll add that on my
web page.

> But Bluetooth devices are not network devices, it seems. There exists no
> current mechanism for notifying anyone of state changes. Should we invent a
> new method of notification using netlink, or should Bluetooth interfaces in
> fact be normal network devices just like IrDA devices are?

Check this thread :
http://sourceforge.net/mailarchive/forum.php?thread_id=1165868&forum_id=1881
Basically, you need to check the code in hcid.c (in utils) to
know how to collect this events. I've coded this and it works
perfect. Yeah, it's another socket to manage.

> --
> dwmw2

Have fun...

Jean

2002-10-23 01:00:41

by jamal

[permalink] [raw]
Subject: Re: rtnetlink interface state monitoring problems.



On Mon, 21 Oct 2002, David Woodhouse wrote:

>
> [email protected] said:
> > I cant see anything on netlink and irda; i am also not very familiar
> > with either IrDA or Bluetooth. Regardless, you dont need to be a net
> > device to use netlink.
>
> IrDA devices are network devices. The core network code sends a RTM_NETLINK
> message when they go up or down. All is well, and once the permission fix
> gets into the kernel I'm using, my irda monitor applet no longer needs to
> poll the state of the interface.
>

Ah, ok. I see what you mean - for a moment i thought IrDA was doing
something clever with netlink.

> But Bluetooth devices are not network devices, it seems. There exists no
> current mechanism for notifying anyone of state changes. Should we invent a
> new method of notification using netlink, or should Bluetooth interfaces in
> fact be normal network devices just like IrDA devices are?
>

I think the only time you should go netdev is when it makes sense to run
IP. Is there IP over bluttooth? Then you could take advantage of all the
nice features provided by netdevices (other than being IP devices;->).
If not, it probably time for someone to write a generic notification
scheme via netlink.

cheers,
jamal

2002-10-23 01:38:39

by Tim Hockin

[permalink] [raw]
Subject: Re: rtnetlink interface state monitoring problems.

> If not, it probably time for someone to write a generic notification
> scheme via netlink.

How generic? I need to pay some attention to cleaning up the next version
of the link-changes via netlink patch that was discussed last week or the
week before.

What kind of generic are you thinking about? :)

2002-10-23 03:18:33

by jamal

[permalink] [raw]
Subject: Re: rtnetlink interface state monitoring problems.



On Tue, 22 Oct 2002, Tim Hockin wrote:

> > If not, it probably time for someone to write a generic notification
> > scheme via netlink.
>
> How generic? I need to pay some attention to cleaning up the next version
> of the link-changes via netlink patch that was discussed last week or the
> week before.

The patch posted by Stefan seems good to me and ready to merge.

>
> What kind of generic are you thinking about? :)
>

netlink is a messaging system; so what i am thinking is creating
a event notifier for other devices other than network devices.
Something other non-network devices could use (eg bluetooth).
Given that netlink packetizes the data, this facilitates a distributed
control type of environment.

cheers,
jamal

2002-10-23 19:36:53

by Max Krasnyansky

[permalink] [raw]
Subject: Re: rtnetlink interface state monitoring problems.


>netlink is a messaging system; so what i am thinking is creating
>a event notifier for other devices other than network devices.
>Something other non-network devices could use (eg bluetooth).
What kind of events are we taking about ?

Max

2002-10-23 19:35:33

by Max Krasnyansky

[permalink] [raw]
Subject: Re: rtnetlink interface state monitoring problems.

Hi Jamal,

>> But Bluetooth devices are not network devices, it seems. There exists no
>> current mechanism for notifying anyone of state changes. Should we invent a
>> new method of notification using netlink, or should Bluetooth interfaces in
>> fact be normal network devices just like IrDA devices are?
>>
>
>I think the only time you should go netdev is when it makes sense to run IP.
Totally agree.

>Is there IP over bluttooth?
Yep. It's called BNEP (Bluetooth Network Encapsulation Protocol) which is bascially
an Ethernet emulation. That thing is the netdev of course.

>Then you could take advantage of all the nice features provided by netdevices (other
>than being IP devices;->).
>If not, it probably time for someone to write a generic notification
>scheme via netlink.
Might be interesting.

Max

2002-10-28 12:36:13

by jamal

[permalink] [raw]
Subject: Re: rtnetlink interface state monitoring problems.



On Wed, 23 Oct 2002, Maksim (Max) Krasnyanskiy wrote:

>
> >netlink is a messaging system; so what i am thinking is creating
> >a event notifier for other devices other than network devices.
> >Something other non-network devices could use (eg bluetooth).
>
> What kind of events are we taking about ?
>

Currently, for net events, notifier_call_chain() calls from the same
routines which also send netlink announcements. I am thinking actually
having notifier_call_chain make the netlink advertisements.
There are not that many subsystems that use notifier block calls (seems
the network subsytem is their best customer ;->)
i think it is the best async notification scheme in the kernel. Too bad
someone had to invent hotplug the way it is right now.
As i said earlier, the advantage with netlink is that you could easily
add a distributed event notification scheme since it is already in packet
format.

cheers,
jamal