netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* HSR: How to set IF_OPER_LOWERLAYERDOWN?
@ 2012-06-26 22:28 Arvid Brodin
  2012-06-26 22:33 ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Arvid Brodin @ 2012-06-26 22:28 UTC (permalink / raw)
  To: netdev, Stephen Hemminger; +Cc: Javier Boticario, Bruno Ferreira

Hi,

According to Documentation/networking/operstates.txt a network interface have an
operational state and an administrative state.

If I understand things correctly the administrative state is the desired state set by
userspace, and the operational state is the actual state which depends on things like the
administrative state, whether a carrier is present, or (for virtual interfaces lite VLAN)
whether the lower interface is available.


In the driver I'm writing (for the "HSR" redundancy protocol) a hsr (virtual) interface is
useable as long as any of its (physical) slaves are useable. I.e. the operstate of a hsr
device might be set like this:

void hsr_set_operstate()
{
	if (!is_admin_up(hsr_dev)) /* Check IFF_UP */ {
		set_operstate(hsr_dev, IF_OPER_DOWN);
		return;
	}

	if (is_operstate_up(slave1) || is_operstate_up(slave2)) /* Check IF_OPER_UP */
		set_operstate(hsr_dev, IF_OPER_UP);
	else
		set_operstate(hsr_dev, IF_OPER_LOWERLAYERDOWN);
}

However, the function set_operstate() (in net/core/rtnetlink.c) only accept transitions to
IF_OPER_UP and IF_OPER_DORMANT - other transitions are ignored. (There is a function
rfc2863_policy() (net/core/link_watch.c) that may return IF_OPER_LOWERLAYERDOWN iff
(!netif_carrier_ok(dev) && (dev->ifindex != dev->iflink)), but I don't know what that means.)

So how do I signal my interface as being IF_OPER_LOWERLAYERDOWN?


In another, related matter, I'm wondering if I should set the carrier state of my virtual
interface so that it shows netif_carrier_ok() when it is possible to get the interface to
IF_OPER_UP:

void hsr_set_carrier()
{
	if (is_operstate_up(slave1) || is_operstate_up(slave2))
		netif_carrier_on(hsr_dev);
	else
		netif_carrier_off(hsr_dev);
}


Thanks,
-- 
Arvid Brodin | Consultant (Linux)
XDIN AB | Jan Stenbecks Torg 17 | SE-164 40 Kista | Sweden | xdin.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: HSR: How to set IF_OPER_LOWERLAYERDOWN?
  2012-06-26 22:28 HSR: How to set IF_OPER_LOWERLAYERDOWN? Arvid Brodin
@ 2012-06-26 22:33 ` Stephen Hemminger
  2012-06-27  1:42   ` Arvid Brodin
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2012-06-26 22:33 UTC (permalink / raw)
  To: Arvid Brodin; +Cc: netdev, Javier Boticario, Bruno Ferreira

On Tue, 26 Jun 2012 22:28:51 +0000
Arvid Brodin <Arvid.Brodin@xdin.com> wrote:

> Hi,
> 
> According to Documentation/networking/operstates.txt a network interface have an
> operational state and an administrative state.
> 
> If I understand things correctly the administrative state is the desired state set by
> userspace, and the operational state is the actual state which depends on things like the
> administrative state, whether a carrier is present, or (for virtual interfaces lite VLAN)
> whether the lower interface is available.
> 
> 
> In the driver I'm writing (for the "HSR" redundancy protocol) a hsr (virtual) interface is
> useable as long as any of its (physical) slaves are useable. I.e. the operstate of a hsr
> device might be set like this:
> 
> void hsr_set_operstate()
> {
> 	if (!is_admin_up(hsr_dev)) /* Check IFF_UP */ {
> 		set_operstate(hsr_dev, IF_OPER_DOWN);
> 		return;
> 	}
> 
> 	if (is_operstate_up(slave1) || is_operstate_up(slave2)) /* Check IF_OPER_UP */
> 		set_operstate(hsr_dev, IF_OPER_UP);
> 	else
> 		set_operstate(hsr_dev, IF_OPER_LOWERLAYERDOWN);
> }


According to 802.1X example in documentation to set it down you need to set IF_OPER_DORMANT
not IF_OPER_LOWERLAYERDOWN.  Probably a kernel bug in there somwhere.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: HSR: How to set IF_OPER_LOWERLAYERDOWN?
  2012-06-26 22:33 ` Stephen Hemminger
@ 2012-06-27  1:42   ` Arvid Brodin
  2012-06-27 15:40     ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Arvid Brodin @ 2012-06-27  1:42 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, Javier Boticario, Bruno Ferreira

On 2012-06-27 00:33, Stephen Hemminger wrote:
> On Tue, 26 Jun 2012 22:28:51 +0000
> Arvid Brodin <Arvid.Brodin@xdin.com> wrote:
> 
>> Hi,
>>
>> According to Documentation/networking/operstates.txt a network interface have an
>> operational state and an administrative state.
>>
>> If I understand things correctly the administrative state is the desired state set by
>> userspace, and the operational state is the actual state which depends on things like the
>> administrative state, whether a carrier is present, or (for virtual interfaces lite VLAN)
>> whether the lower interface is available.
>>
>>
>> In the driver I'm writing (for the "HSR" redundancy protocol) a hsr (virtual) interface is
>> useable as long as any of its (physical) slaves are useable. I.e. the operstate of a hsr
>> device might be set like this:
>>
>> void hsr_set_operstate()
>> {
>> 	if (!is_admin_up(hsr_dev)) /* Check IFF_UP */ {
>> 		set_operstate(hsr_dev, IF_OPER_DOWN);
>> 		return;
>> 	}
>>
>> 	if (is_operstate_up(slave1) || is_operstate_up(slave2)) /* Check IF_OPER_UP */
>> 		set_operstate(hsr_dev, IF_OPER_UP);
>> 	else
>> 		set_operstate(hsr_dev, IF_OPER_LOWERLAYERDOWN);
>> }
> 
> 
> According to 802.1X example in documentation to set it down you need to set IF_OPER_DORMANT
> not IF_OPER_LOWERLAYERDOWN.  Probably a kernel bug in there somwhere.
> 

Hmm... if you're referring to the example in Documentation/networking/operstates.txt it
seems to me that the usage of IF_OPER_DORMANT there is in compliance with RFC2863 - i.e.
the device is waiting for some kind of handshake to finish. I don't think it has anything
to do with taking the device down?

Oh, and I see now that set_operstate() is called from do_setlink() in
net/core/rtnetlink.c, which means this function is used to set operstate from userspace.
The limitations then fits with the description in operstates.txt, and this function is
probably not meant to set an interface's operational state from within the kernel. I wrote
my own hsr_set_operstate that accepts any values, and it seems to work... (?)


Is there a way to get notifications when an interface's operational state change?
NETDEV_CHANGE seems to trigger on carrier change, and NETDEV_UP/DOWN triggers when the
administrative state changes - is there something similar for operational state?

(Unfortunately NETDEV_UP/DOWN triggers before the operational state for the interface in
question changes accordingly, so it's not possible to just check dev->operstate in the
handler for these messages. NETDEV_CHANGE seems to trigger after the interface's
operational state has been changed, though.)

-- 
Arvid Brodin | Consultant (Linux)
XDIN AB | Jan Stenbecks Torg 17 | SE-164 40 Kista | Sweden | xdin.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: HSR: How to set IF_OPER_LOWERLAYERDOWN?
  2012-06-27  1:42   ` Arvid Brodin
@ 2012-06-27 15:40     ` Stephen Hemminger
  0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2012-06-27 15:40 UTC (permalink / raw)
  To: Arvid Brodin; +Cc: netdev, Javier Boticario, Bruno Ferreira

On Wed, 27 Jun 2012 01:42:12 +0000
Arvid Brodin <Arvid.Brodin@xdin.com> wrote:

> On 2012-06-27 00:33, Stephen Hemminger wrote:
> > On Tue, 26 Jun 2012 22:28:51 +0000
> > Arvid Brodin <Arvid.Brodin@xdin.com> wrote:
> > 
> >> Hi,
> >>
> >> According to Documentation/networking/operstates.txt a network interface have an
> >> operational state and an administrative state.
> >>
> >> If I understand things correctly the administrative state is the desired state set by
> >> userspace, and the operational state is the actual state which depends on things like the
> >> administrative state, whether a carrier is present, or (for virtual interfaces lite VLAN)
> >> whether the lower interface is available.
> >>
> >>
> >> In the driver I'm writing (for the "HSR" redundancy protocol) a hsr (virtual) interface is
> >> useable as long as any of its (physical) slaves are useable. I.e. the operstate of a hsr
> >> device might be set like this:
> >>
> >> void hsr_set_operstate()
> >> {
> >> 	if (!is_admin_up(hsr_dev)) /* Check IFF_UP */ {
> >> 		set_operstate(hsr_dev, IF_OPER_DOWN);
> >> 		return;
> >> 	}
> >>
> >> 	if (is_operstate_up(slave1) || is_operstate_up(slave2)) /* Check IF_OPER_UP */
> >> 		set_operstate(hsr_dev, IF_OPER_UP);
> >> 	else
> >> 		set_operstate(hsr_dev, IF_OPER_LOWERLAYERDOWN);
> >> }
> > 
> > 
> > According to 802.1X example in documentation to set it down you need to set IF_OPER_DORMANT
> > not IF_OPER_LOWERLAYERDOWN.  Probably a kernel bug in there somwhere.
> > 
> 
> Hmm... if you're referring to the example in Documentation/networking/operstates.txt it
> seems to me that the usage of IF_OPER_DORMANT there is in compliance with RFC2863 - i.e.
> the device is waiting for some kind of handshake to finish. I don't think it has anything
> to do with taking the device down?
> 
> Oh, and I see now that set_operstate() is called from do_setlink() in
> net/core/rtnetlink.c, which means this function is used to set operstate from userspace.
> The limitations then fits with the description in operstates.txt, and this function is
> probably not meant to set an interface's operational state from within the kernel. I wrote
> my own hsr_set_operstate that accepts any values, and it seems to work... (?)
> 
> 
> Is there a way to get notifications when an interface's operational state change?
> NETDEV_CHANGE seems to trigger on carrier change, and NETDEV_UP/DOWN triggers when the
> administrative state changes - is there something similar for operational state?
> 
> (Unfortunately NETDEV_UP/DOWN triggers before the operational state for the interface in
> question changes accordingly, so it's not possible to just check dev->operstate in the
> handler for these messages. NETDEV_CHANGE seems to trigger after the interface's
> operational state has been changed, though.)
> 

I think the original intention was for kernel drivers to use
netif_carrier_on/off rather than manipulating operstate directly.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-06-27 15:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-26 22:28 HSR: How to set IF_OPER_LOWERLAYERDOWN? Arvid Brodin
2012-06-26 22:33 ` Stephen Hemminger
2012-06-27  1:42   ` Arvid Brodin
2012-06-27 15:40     ` Stephen Hemminger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).