bind with link down

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

bind with link down

Massimiliano Cialdi-2
I have a process that polls the PHY to find out if the link is up or
down. It calls netif_set_link_up()/netif_set_link_down(). I also have
the link callback calling netif_set_up()/netif_set_down().

I wonder what happens if the functions:
  conn = netconn_new(NETCONN_UDP);
  netconn_bind(conn, IP_ADDR_ANY, 7);
are called when netif is still down. This happens because, for
example, the udpecho_thread() process starts before the netif is up.

Then when the link goes down while
   err = netconn_recv(conn, &buf);
is waiting, it doesn't exit with an error. Is that correct?

best regards
Max
--
Et nunc, auxilium solis, vincam!
Oppugnatio solaris!
VIS!

Massimiliano Cialdi
[hidden email]

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: bind with link down

goldsimon@gmx.de


On 31.03.2020 21:34, Massimiliano Cialdi wrote:
> I have a process that polls the PHY to find out if the link is up or
> down. It calls netif_set_link_up()/netif_set_link_down(). I also have
> the link callback calling netif_set_up()/netif_set_down().

You're mixing link state with admin state here. That might work, but
might not work in some situations.

>
> I wonder what happens if the functions:
>    conn = netconn_new(NETCONN_UDP);
>    netconn_bind(conn, IP_ADDR_ANY, 7);
> are called when netif is still down. This happens because, for
> example, the udpecho_thread() process starts before the netif is up.
>
> Then when the link goes down while
>     err = netconn_recv(conn, &buf);
> is waiting, it doesn't exit with an error. Is that correct?

Correct or not depends on how you define it. There's currently no code
in lwIP to unblock on link loss. That could only work if you're bound to
a netif. I'm not sure if what you think of works in other stacks.

Regards,
Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: bind with link down

Massimiliano Cialdi-2
On Tue, Mar 31, 2020 at 10:11 PM Simon Goldschmidt <[hidden email]> wrote:
> You're mixing link state with admin state here. That might work, but
> might not work in some situations.
It's not so clear to me.
Which pattern should I adopt to keep the link status under control?
What do you mean by 'admin state'?
How should the admin state be affected by the link state?


> > Then when the link goes down while
> >     err = netconn_recv(conn, &buf);
> > is waiting, it doesn't exit with an error. Is that correct?
> Correct or not depends on how you define it. There's currently no code
When you say "depends on how you define it.", what are you talking about?

> in lwIP to unblock on link loss. That could only work if you're bound to
> a netif. I'm not sure if what you think of works in other stacks.
What other stacks? Stacks other than lwip?

best regards
Max



--
Et nunc, auxilium solis, vincam!
Oppugnatio solaris!
VIS!

Massimiliano Cialdi
[hidden email]

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: bind with link down

goldsimon@gmx.de
Am 31.03.2020 um 22:47 schrieb Massimiliano Cialdi:
> On Tue, Mar 31, 2020 at 10:11 PM Simon Goldschmidt <[hidden email]> wrote:
>> You're mixing link state with admin state here. That might work, but
>> might not work in some situations.
> It's not so clear to me.
> Which pattern should I adopt to keep the link status under control?
> What do you mean by 'admin state'?

"Admin state" is "netif_set_up()".

> How should the admin state be affected by the link state?

Not at all. Just call "netif_set_link_up()" or down when you found out a
state change. Leave "netif_set_up()" as it is.

Regards,
Simon

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: bind with link down

Massimiliano Cialdi-2
On Thu, Apr 2, 2020 at 8:33 PM [hidden email] <[hidden email]> wrote:
> "Admin state" is "netif_set_up()".
>
> > How should the admin state be affected by the link state?
> Not at all. Just call "netif_set_link_up()" or down when you found out a
> state change. Leave "netif_set_up()" as it is.
what's the linux equivalent of 'admin state'? Which command could be
used to change it? This might help me figure out what admin state is
and what admin state is for.
I only know
ip link set <if> up/down
This should be the equivalent of netif_set_link_up()/netif_set_link_down()

After which events should I call netif_set_up()/netif_set_down()?

I copied this pattern from the examples found in the ST SDKs (hoping
they'd know more about it than I do.):
https://github.com/STMicroelectronics/STM32CubeF7/blob/master/Projects/STM32756G_EVAL/Applications/LwIP/LwIP_UDPTCP_Echo_Server_Netconn_RTOS

where I find comments that contradict what you're telling me
(https://github.com/STMicroelectronics/STM32CubeF7/blob/master/Projects/STM32756G_EVAL/Applications/LwIP/LwIP_UDPTCP_Echo_Server_Netconn_RTOS/Src/app_ethernet.c#L153):
/* When the netif link is down this function must be called.*/
netif_set_down(netif);

and also the call netif_set_up() in the link_callback when the link is up:
https://github.com/STMicroelectronics/STM32CubeF7/blob/master/Projects/STM32756G_EVAL/Applications/LwIP/LwIP_UDPTCP_Echo_Server_Netconn_RTOS/Src/app_ethernet.c#L144


best regards
Max

--
Et nunc, auxilium solis, vincam!
Oppugnatio solaris!
VIS!

Massimiliano Cialdi
[hidden email]

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: bind with link down

Sylvain Rochet
Hi Massimiliano,

On Thu, Apr 02, 2020 at 11:17:36PM +0200, Massimiliano Cialdi wrote:

> On Thu, Apr 2, 2020 at 8:33 PM [hidden email] <[hidden email]> wrote:
> > "Admin state" is "netif_set_up()".
> >
> > > How should the admin state be affected by the link state?
> > Not at all. Just call "netif_set_link_up()" or down when you found out a
> > state change. Leave "netif_set_up()" as it is.
> what's the linux equivalent of 'admin state'? Which command could be
> used to change it? This might help me figure out what admin state is
> and what admin state is for.
> I only know
> ip link set <if> up/down
> This should be the equivalent of netif_set_link_up()/netif_set_link_down()
"ip link set <if> up/down" is interface administrative state.

Link state is whether the cable is plugged or unplugged, i.e. "ethtool"
for linux equivalent.

Sylvain

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: bind with link down

Massimiliano Cialdi-2
On Thu, Apr 2, 2020 at 11:25 PM Sylvain Rochet <[hidden email]> wrote:
> "ip link set <if> up/down" is interface administrative state.
>
> Link state is whether the cable is plugged or unplugged, i.e. "ethtool"
> for linux equivalent.
This answer confuses me.

I tried: on linux the link state and the admin state *are* related to
each other.
with the cable connected both ip and ethtool report the states up
max@jarvis:~$ ip link show enx0050b6e9a99e && ethtool enx0050b6e9a99e | tail -n2
5: enx0050b6e9a99e: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 00:50:b6:e9:a9:9e brd ff:ff:ff:ff:ff:ff
Cannot get wake-on-lan settings: Operation not permitted
                   drv probe link
    Link detected: yes

and even with the cable disconnected they both say down:
max@jarvis:~$ ip link show enx0050b6e9a99e && ethtool enx0050b6e9a99e | tail -n2
5: enx0050b6e9a99e: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc
fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether 00:50:b6:e9:a9:9e brd ff:ff:ff:ff:ff:ff
Cannot get wake-on-lan settings: Operation not permitted
                   drv probe link
    Link detected: no

but you said:
> "Admin state" is "netif_set_up()".
>
> > How should the admin state be affected by the link state?
> Not at all. Just call "netif_set_link_up()" or down when you found out a
> state change. Leave "netif_set_up()" as it is.
From this I understand that the links state and admin state are not
related. I may have (and you say so) links down but admin state up.
Tell me if I understand correctly.

So I find myself forced to ask you the question again: on linux how
can I have admin state up and link down?

the last thing: you say that "ip link set <if> up/down" is interface
administrative state.
But if I force down the "admin state" with the cable connected, both
ip and ethtool tell me the link is down. And once again, that seems
contrary to what you say (link and admin state are not related).

best regards
Max


--
Et nunc, auxilium solis, vincam!
Oppugnatio solaris!
VIS!

Massimiliano Cialdi
[hidden email]

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: bind with link down

Sylvain Rochet
rHi Massimiliano,

On Fri, Apr 03, 2020 at 12:40:43AM +0200, Massimiliano Cialdi wrote:
> On Thu, Apr 2, 2020 at 11:25 PM Sylvain Rochet <[hidden email]> wrote:
> > "ip link set <if> up/down" is interface administrative state.
> >
> > Link state is whether the cable is plugged or unplugged, i.e. "ethtool"
> > for linux equivalent.
> This answer confuses me.
>
> I tried: on linux the link state and the admin state *are* related to
> each other.

I don't agree, administrative state is always UP in your example:


> with the cable connected both ip and ethtool report the states up
> max@jarvis:~$ ip link show enx0050b6e9a99e && ethtool enx0050b6e9a99e | tail -n2
> 5: enx0050b6e9a99e: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
                                           ^^ ^^^^^^^^
                         administrative state    link state


> fq_codel state UP mode DEFAULT group default qlen 1000
>     link/ether 00:50:b6:e9:a9:9e brd ff:ff:ff:ff:ff:ff
> Cannot get wake-on-lan settings: Operation not permitted
>                    drv probe link
>     Link detected: yes
>
> and even with the cable disconnected they both say down:
> max@jarvis:~$ ip link show enx0050b6e9a99e && ethtool enx0050b6e9a99e | tail -n2
> 5: enx0050b6e9a99e: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc
                       ^^^^^^^^^^                     ^^
                        link state          administrative state


> fq_codel state DOWN mode DEFAULT group default qlen 1000
>     link/ether 00:50:b6:e9:a9:9e brd ff:ff:ff:ff:ff:ff
> Cannot get wake-on-lan settings: Operation not permitted
>                    drv probe link
>     Link detected: no
>
> but you said:
> > "Admin state" is "netif_set_up()".
> >
> > > How should the admin state be affected by the link state?
> > Not at all. Just call "netif_set_link_up()" or down when you found out a
> > state change. Leave "netif_set_up()" as it is.
> From this I understand that the links state and admin state are not
> related. I may have (and you say so) links down but admin state up.
> Tell me if I understand correctly.
They are not related at all.

netif_set_up() and netif_set_down() is a software switch telling the
lwIP stack if you want the interface to be active or silent. If you
don't need to disable an interface at runtime (with only one interface,
you never need that!), you only have to call netif_set_up() once at
init.

netif_set_link_up() and netif_set_link_down() may be called when cable
is plugged or unplugged. Calling netif_set_link_down() then
netif_set_link_up() is optional and only meant to speed up DHCP recover,
IPv6 discovery, or such. If you don't care about speeding up things on
cable connection you only have to call netif_set_link_up() once at init.


> So I find myself forced to ask you the question again: on linux how
> can I have admin state up and link down?

You only have to unplug the cable to do so :-)


> the last thing: you say that "ip link set <if> up/down" is interface
> administrative state.
> But if I force down the "admin state" with the cable connected, both
> ip and ethtool tell me the link is down. And once again, that seems
> contrary to what you say (link and admin state are not related).

This is because Linux power down the network interface when you set it
administratively down, effectively removing the carrier signal.
 

Sylvain

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users

signature.asc (188 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: bind with link down

Massimiliano Cialdi-2
On Fri, Apr 3, 2020 at 1:28 AM Sylvain Rochet <[hidden email]> wrote:

> netif_set_up() and netif_set_down() is a software switch telling the
> lwIP stack if you want the interface to be active or silent. If you
> don't need to disable an interface at runtime (with only one interface,
> you never need that!), you only have to call netif_set_up() once at
> init.
>
> netif_set_link_up() and netif_set_link_down() may be called when cable
> is plugged or unplugged. Calling netif_set_link_down() then
> netif_set_link_up() is optional and only meant to speed up DHCP recover,
> IPv6 discovery, or such. If you don't care about speeding up things on
> cable connection you only have to call netif_set_link_up() once at init.
I confess my lack of knowledge on these matters.
I didn't know that if I have just one interface, I never need to put it down.
And I wouldn't know after which events to put the interfaces up/down
in case I had more than one.
And, if I understand correctly, when the ip is static I don't even
need to set the link down when cable is unconnected.
Where could I find documents or books to increase my know-how on these topics?

best regards
Max

--
Et nunc, auxilium solis, vincam!
Oppugnatio solaris!
VIS!

Massimiliano Cialdi
[hidden email]

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: bind with link down

goldsimon@gmx.de
Am 03.04.2020 um 12:46 schrieb Massimiliano Cialdi:

> On Fri, Apr 3, 2020 at 1:28 AM Sylvain Rochet <[hidden email]> wrote:
>> netif_set_up() and netif_set_down() is a software switch telling the
>> lwIP stack if you want the interface to be active or silent. If you
>> don't need to disable an interface at runtime (with only one interface,
>> you never need that!), you only have to call netif_set_up() once at
>> init.
>>
>> netif_set_link_up() and netif_set_link_down() may be called when cable
>> is plugged or unplugged. Calling netif_set_link_down() then
>> netif_set_link_up() is optional and only meant to speed up DHCP recover,
>> IPv6 discovery, or such. If you don't care about speeding up things on
>> cable connection you only have to call netif_set_link_up() once at init.
> I confess my lack of knowledge on these matters.
> I didn't know that if I have just one interface, I never need to put it down.
> And I wouldn't know after which events to put the interfaces up/down
> in case I had more than one.
> And, if I understand correctly, when the ip is static I don't even
> need to set the link down when cable is unconnected.

No, you should still set the link down if you can detect it. It's not
required, but it might improve *some* things if that is known.

Regards,
Simon

> Where could I find documents or books to increase my know-how on these topics?
>
> best regards
> Max
>


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: bind with link down

Massimiliano Cialdi-2
On Fri, Apr 3, 2020 at 12:55 PM [hidden email] <[hidden email]> wrote:
> > And, if I understand correctly, when the ip is static I don't even
> > need to set the link down when cable is unconnected.
> No, you should still set the link down if you can detect it. It's not
> required, but it might improve *some* things if that is known.
This proves once again my ignorance on these matters so...

> > Where could I find documents or books to increase my know-how on these topics?
...this question remains more valid than ever.

best regards
Max


--
Et nunc, auxilium solis, vincam!
Oppugnatio solaris!
VIS!

Massimiliano Cialdi
[hidden email]

_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users
Reply | Threaded
Open this post in threaded view
|

Re: bind with link down

goldsimon@gmx.de
Am 03.04.2020 um 15:42 schrieb Massimiliano Cialdi:
> On Fri, Apr 3, 2020 at 12:55 PM [hidden email] <[hidden email]> wrote:
>>> And, if I understand correctly, when the ip is static I don't even
>>> need to set the link down when cable is unconnected.
>> No, you should still set the link down if you can detect it. It's not
>> required, but it might improve *some* things if that is known.
> This proves once again my ignorance on these matters so...
>
>>> Where could I find documents or books to increase my know-how on these topics?
> ...this question remains more valid than ever.

Sorry, I can't help you there.

Regards,
Simon

>
> best regards
> Max
>
>


_______________________________________________
lwip-users mailing list
[hidden email]
https://lists.nongnu.org/mailman/listinfo/lwip-users